From patchwork Thu Mar 30 19:47:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Zapolskiy X-Patchwork-Id: 668618 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp116569wrt; Thu, 30 Mar 2023 12:54:17 -0700 (PDT) X-Google-Smtp-Source: AKy350ZWoZ45WVq0QxOgGw/srR+1oq02GsFNNsS8fnNznx1Opb/Iut6hEphU1s4m55ihD9HacsPK X-Received: by 2002:a17:902:d04b:b0:1a1:bd50:a9e with SMTP id l11-20020a170902d04b00b001a1bd500a9emr18407963pll.47.1680206056987; Thu, 30 Mar 2023 12:54:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680206056; cv=none; d=google.com; s=arc-20160816; b=O87X04kC2rZ43EjTu+g1qJH8i2BR76ZE4qk9xJTaSIyfRdVg5mGj4eigWJTzWwGfA3 BojrCXRHQYN5rEArCIwHyumnTXfqSHQLNaNqKcgYu/pSeVxkBKdq7Zv6PAargzP4w3LZ gwmSbFX41xpwJhJqg/C5deJlIrAe0OQXy34Jv3FZb9oo4nQjZqfJ40+r5lGTEqJf1093 YwPbV9NG4Q6JtZ3erj0gc8Ra9HN//kXfNgUdHAlcEKRvpVctl2CM3SMvWzyxRqIKhbKt uBbv9G8jN8FjBViivQ02ctoXKv8STOs8u8AfszxpAifCbZWIPzt3Rb5sN0v0UqePwugM DnPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YcH8fPhA6R24B76yL7sF40/TUvb/Kw7zEvmOHZDG9Ec=; b=iYndXVoXp7CunEr+rYVmrv1RI+FNfzN8BBt5stw0DnzStGUSpMXAzLR/rGeRmL3jGh KEmONOSKR/BE0uWh3RNXS4BxVdltejZVNraxwr2BNecUx6oGZHpD9eFul51R0Rie8pQj zcqC3ApLVzWSZe7ApxMW8oxLjdLDuIb9J9BWA5i6rmP0KYrklI2thDp5SQkUJ0zJlzhK wwDp5ZKDpm5IbfrxtXhLcM0VkBYY5HJQRQZO+BDfT1bsYYGJYheC6LtOt/Icv5F8vwIA Tc0ba532KBONmIjJNGaiB0W6XXdMPUJRbPSmHTMEfsIKZ7VoOUclS0UfqNOGnzQkWlNV pDZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="w5AvDkQ/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id n5-20020a170902e54500b001a1c73d52ffsi335404plf.28.2023.03.30.12.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 12:54:16 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="w5AvDkQ/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0B4CF861A0; Thu, 30 Mar 2023 21:52:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="w5AvDkQ/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6060485E44; Thu, 30 Mar 2023 21:48:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C814685F2D for ; Thu, 30 Mar 2023 21:47:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=vladimir.zapolskiy@linaro.org Received: by mail-lj1-x22a.google.com with SMTP id e9so5539838ljq.4 for ; Thu, 30 Mar 2023 12:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680205669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YcH8fPhA6R24B76yL7sF40/TUvb/Kw7zEvmOHZDG9Ec=; b=w5AvDkQ/tnUza7KIye96/fdUkSkdq42LdvGFsxle7MoZRq9rhUV/w5aceks3EeHu9p fhCq7K+PSCzXZKf5HuwgxiieMZqRfA33uNEHzEsOACrO9V0S5FPndPCeODBef5wMw0Vb SItElGgAGWQXIZKwFjh1I5O3i3YmQsnp+Kp/olA2Wd0Xipa8NWVzUB8zpvwvEEMVd/jx sgZ8avApLekhv9BUHYdOAwJpaF2XLDGyrP3hlxKltorO8Ll6khK2tAg7NykgklKuzi4L IRoQTMCWvmFugWQRh+X+OruLFByKTEVduaxc2vROglCORyZl7MaWKiW6VEPnIQqXHjCd Iexw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680205669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YcH8fPhA6R24B76yL7sF40/TUvb/Kw7zEvmOHZDG9Ec=; b=oh6cRJ9WVxkRVDx8A7+KOi8v7vk3YO6RCCRSxX1sxRLt75JRJFfzwiZT5yOMlhQo+O ilzdgglgR2ByRRC5uO1pPw+FonIv1Npr/HzxZhc2/5PZHlqN8+qvN6XUOMlCZtm2Zpgg oE/sHE1TbZ0SScxJfnVLgp4lVlBneTMtlMvX/2MGbmBsvU4knLyEvgjuuxe/k2fNrP4v oBmoBxr+h1kCiPluLE+ZkmviXPGSdY7j/AgF9z0AqHnjs6mKrvB2oXSEd/Ufb9I57zbE lbQqVtbGd1rtq3ivEptoXHjRysYcTYZsOCRwRlv2BziXsV8qgJPxfAPUCS5cxnDQR3/f MWbw== X-Gm-Message-State: AAQBX9cFO1F8DgdvdAUAkw0lN7rqVtoPahysqHcZ6UnRK6sxSSdJ9tmx QneGk4eySfF2mvYOQX+kIfZkgQ== X-Received: by 2002:a2e:bd10:0:b0:293:2e06:8567 with SMTP id n16-20020a2ebd10000000b002932e068567mr1100964ljq.2.1680205668854; Thu, 30 Mar 2023 12:47:48 -0700 (PDT) Received: from localhost.localdomain (88-112-131-206.elisa-laajakaista.fi. [88.112.131.206]) by smtp.gmail.com with ESMTPSA id i19-20020a2e8093000000b0029f3e2efbb9sm46674ljg.90.2023.03.30.12.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 12:47:48 -0700 (PDT) From: Vladimir Zapolskiy To: Tom Rini , Simon Glass Cc: Ramon Fried , Konrad Dybcio , Bhupesh Sharma , u-boot@lists.denx.de Subject: [PATCH 6/6] serial: msm-geni: correct oversampling value based on QUP hardware revision Date: Thu, 30 Mar 2023 22:47:36 +0300 Message-Id: <20230330194736.2400593-7-vladimir.zapolskiy@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230330194736.2400593-1-vladimir.zapolskiy@linaro.org> References: <20230330194736.2400593-1-vladimir.zapolskiy@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 30 Mar 2023 21:50:39 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Starting from QUP v2.5 the value of oversampling is changed from 32 to 16, keeping the old value on newer platforms results on wrong set UART IP clock divider, thus the asked baudrate does not correspond to the actually set with all the consequencies for a user. The change links the driver to a new Qualcomm GENI SE QUP driver to get its hardware version and update the oversampling value. Deliberately the code under CONFIG_DEBUG_UART_MSM_GENI is not touched, since a wanted baudrate can be controlled by setting a modified CONFIG_DEBUG_UART_CLOCK build time variable. Signed-off-by: Vladimir Zapolskiy --- drivers/serial/serial_msm_geni.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/serial/serial_msm_geni.c b/drivers/serial/serial_msm_geni.c index 03fc704182d3..cdca7e83daa6 100644 --- a/drivers/serial/serial_msm_geni.c +++ b/drivers/serial/serial_msm_geni.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #define UART_OVERSAMPLING 32 @@ -110,6 +111,10 @@ #define TX_FIFO_DEPTH_MSK (GENMASK(21, 16)) #define TX_FIFO_DEPTH_SHFT 16 +/* GENI SE QUP Registers */ +#define QUP_HW_VER_REG 0x4 +#define QUP_SE_VERSION_2_5 0x20050000 + /* * Predefined packing configuration of the serial engine (CFG0, CFG1 regs) * for uart mode. @@ -127,6 +132,7 @@ DECLARE_GLOBAL_DATA_PTR; struct msm_serial_data { phys_addr_t base; u32 baud; + u32 oversampling; }; unsigned long root_freq[] = {7372800, 14745600, 19200000, 29491200, @@ -246,7 +252,7 @@ static int msm_serial_setbrg(struct udevice *dev, int baud) priv->baud = baud; - clk_rate = get_clk_div_rate(baud, UART_OVERSAMPLING, &clk_div); + clk_rate = get_clk_div_rate(baud, priv->oversampling, &clk_div); geni_serial_set_clock_rate(dev, clk_rate); geni_serial_baud(priv->base, clk_div, baud); @@ -480,6 +486,27 @@ static const struct dm_serial_ops msm_serial_ops = { .setbrg = msm_serial_setbrg, }; +static inline void geni_get_oversampling(struct udevice *dev) +{ + struct msm_serial_data *priv = dev_get_priv(dev); + struct udevice *parent_dev = dev_get_parent(dev); + u32 geni_se_version; + int ret; + + priv->oversampling = UART_OVERSAMPLING; + + /* + * It could happen that GENI SE QUP driver is disabled or GENI UART + * device tree node is a direct child of SoC device tree node. + */ + if (device_get_uclass_id(parent_dev) != UCLASS_MISC) + return; + + ret = misc_read(parent_dev, QUP_HW_VER_REG, &geni_se_version, 4); + if (!ret && geni_se_version >= QUP_SE_VERSION_2_5) + priv->oversampling /= 2; +} + static inline void geni_serial_init(struct udevice *dev) { struct msm_serial_data *priv = dev_get_priv(dev); @@ -523,6 +550,8 @@ static int msm_serial_probe(struct udevice *dev) { struct msm_serial_data *priv = dev_get_priv(dev); + geni_get_oversampling(dev); + /* No need to reinitialize the UART after relocation */ if (gd->flags & GD_FLG_RELOC) return 0; @@ -557,6 +586,7 @@ U_BOOT_DRIVER(serial_msm_geni) = { .priv_auto = sizeof(struct msm_serial_data), .probe = msm_serial_probe, .ops = &msm_serial_ops, + .flags = DM_FLAG_PRE_RELOC, }; #ifdef CONFIG_DEBUG_UART_MSM_GENI