Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3734452rdb; Thu, 14 Sep 2023 00:26:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXVLeFAasCD9500uyS1a6MSUMpJ2SioiL/zpZ1TK88R5DzTNwiCZSTN3dIZUnlkzx6GoYk X-Received: by 2002:a05:6870:548c:b0:1d0:f921:2096 with SMTP id f12-20020a056870548c00b001d0f9212096mr5489063oan.29.1694676399308; Thu, 14 Sep 2023 00:26:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676399; cv=none; d=google.com; s=arc-20160816; b=I+zoCZMGC/JJ9YzJFAF/i0EM0DR3VvRJtVOvsV+gimaaahZgZAIhZGOnMBEImB07gR tA3Mapm/snweevOA+IscwRuscCOR+sCDFV1wZCRtLouYDkZc1Alk52Pq7RScjwgOXe0+ an3IlJsCkca32eGxoTQ4qUTrFvquUG77NpxsgsZ6hk//xD8353l8xEykZ9k6SBkuajJR 6TuwErD/F+mRlgXtsn/mdgEVYqlMCgUSTFyF53AlMsvuwvm1Lm2gKDud4TKxJZtThgqX OUbI2/EtboenaHAvxyflluC1pih2x88mJJRxlgpqG6mFM7RQcgIKatTDQ3sGTbz3adzz vCPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OjN5VJ4QM7OhyI3wmGDWXLIjFnf1/VnezDm+qLQZSgg=; fh=wjTpYJMKk0ah9JYBzwOlg5KwVWfcbCYKukWNFNTTriA=; b=0B6zIhsZbBYuCgc7F/LkVjuWFzdPDNgjNez4eyAWSW3rPyVDy4B3Vvjxv2QuCiMceu JfLKoK8GblZJKU1oGjP7VfWTo8rX54ElcekiWLUnvgO8pIw9TfKyTjaL8Blv+TEo0Lqm dzCDAkfEYSwUOn3AoEOPV68wdZh5QZuuM5Iy95F4SUdNSBJkgBGtGi8qRMEW7OMDZwLV chMyzUernUakKL6B/l6d0PBasIDEshAS/e4Hmw8IBkIigUmqsROuiASMPwUAnpl5YQAH XV6DleNx1lx3HjXDE1P4HAuiMiML7u6N6nqLLZppgOcJ6TreA13WkwwxrlNU+rLoNLzL qfBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sang-engineering.com header.s=k1 header.b=DzLroddQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id r131-20020a632b89000000b00573f837821fsi880242pgr.689.2023.09.14.00.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:26:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@sang-engineering.com header.s=k1 header.b=DzLroddQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6105E8024ADB; Wed, 13 Sep 2023 13:33:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232603AbjIMUc6 (ORCPT + 99 others); Wed, 13 Sep 2023 16:32:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232547AbjIMUc4 (ORCPT ); Wed, 13 Sep 2023 16:32:56 -0400 Received: from mail.zeus03.de (www.zeus03.de [194.117.254.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 567391BD0 for ; Wed, 13 Sep 2023 13:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=OjN5VJ4QM7OhyI3wmGDWXLIjFnf1/VnezDm+qLQZSgg=; b=DzLrod dQ1Ib357owC5tehUe++9ulGPTDn02OnChHkAzXWpWvM5ldero61RZFgC3P83eJkQ 3t5oA2+qJ/U5EQMEQYdC9XPCKrEhJXt4eniKAZdwVwJR7DISJPPDJI0HVkuAvaWU 6BFAkU5uwJyP19cNALjGO5FzXvrSZ6PVJpoqnruVIpq8Q/hWBr5LmWzyhlXb16xr ZTDlXkr599/ejcNstL6gZpAMngnFed6htZ+Ljg04wI7Gzg3GytSwEka84zJ+EzvI 4VRnX25v/4k+nnsSgFBBvzCHY2jpOr8G+DBvM7yA8/wc6oFn5bWjR8VSQtDNDiU9 GDz0RCS0/ktDjMzg== Received: (qmail 715875 invoked from network); 13 Sep 2023 22:32:49 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 13 Sep 2023 22:32:49 +0200 X-UD-Smtp-Session: l3s3148p1@P9h8dkMFPqIujnuS From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Yoshihiro Shimoda , Wolfram Sang , Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] i2c: rcar: add FastMode+ support for Gen4 Date: Wed, 13 Sep 2023 22:32:41 +0200 Message-Id: <20230913203242.31505-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230913203242.31505-1-wsa+renesas@sang-engineering.com> References: <20230913203242.31505-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Sep 2023 13:33:20 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email To support FM+, we mainly need to turn the SMD constant into a parameter and set it accordingly. Then, activating the enable bit for FM+ is all we need to do. Tested with a Renesas Falcon board using R-Car V3U. Signed-off-by: Wolfram Sang --- drivers/i2c/busses/i2c-rcar.c | 52 +++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 5aa6fd777276..9cc8d6ba0c78 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -89,6 +89,7 @@ #define TMDMAE BIT(0) /* DMA Master Transmitted Enable */ /* ICCCR2 */ +#define FMPE BIT(7) /* Fast Mode Plus Enable */ #define CDFD BIT(2) /* CDF Disable */ #define HLSE BIT(1) /* HIGH/LOW Separate Control Enable */ #define SME BIT(0) /* SCL Mask Enable */ @@ -122,11 +123,12 @@ #define ID_NACK BIT(4) #define ID_EPROTO BIT(5) /* persistent flags */ +#define ID_P_FMPLUS BIT(27) #define ID_P_NOT_ATOMIC BIT(28) #define ID_P_HOST_NOTIFY BIT(29) #define ID_P_NO_RXDMA BIT(30) /* HW forbids RXDMA sometimes */ #define ID_P_PM_BLOCKED BIT(31) -#define ID_P_MASK GENMASK(31, 28) +#define ID_P_MASK GENMASK(31, 27) enum rcar_i2c_type { I2C_RCAR_GEN1, @@ -148,6 +150,7 @@ struct rcar_i2c_priv { int pos; u32 icccr; u32 scl_gran; + u8 smd; u8 recovery_icmcr; /* protected by adapter lock */ enum rcar_i2c_type devtype; struct i2c_client *slave; @@ -239,9 +242,14 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv) if (priv->devtype < I2C_RCAR_GEN3) { rcar_i2c_write(priv, ICCCR, priv->icccr); } else { - rcar_i2c_write(priv, ICCCR2, CDFD | HLSE | SME); + u32 icccr2 = CDFD | HLSE | SME; + + if (priv->flags & ID_P_FMPLUS) + icccr2 |= FMPE; + + rcar_i2c_write(priv, ICCCR2, icccr2); rcar_i2c_write(priv, ICCCR, priv->icccr); - rcar_i2c_write(priv, ICMPR, RCAR_DEFAULT_SMD); + rcar_i2c_write(priv, ICMPR, priv->smd); rcar_i2c_write(priv, ICHPR, RCAR_SCHD_RATIO * priv->scl_gran); rcar_i2c_write(priv, ICLPR, RCAR_SCLD_RATIO * priv->scl_gran); rcar_i2c_write(priv, ICFBSCR, TCYC17); @@ -278,6 +286,8 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) /* Fall back to previously used values if not supplied */ i2c_parse_fw_timings(dev, &t, false); + priv->smd = RCAR_DEFAULT_SMD; + rate = clk_get_rate(priv->clk); /* * calculate SCL clock @@ -297,11 +307,18 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) * clkp : peripheral_clk * F[] : integer up-valuation */ - rate = clk_get_rate(priv->clk); - cdf = rate / 20000000; - cdf_width = (priv->devtype == I2C_RCAR_GEN1) ? 2 : 3; - if (cdf >= 1U << cdf_width) - goto err_no_val; + if (t.bus_freq_hz > I2C_MAX_FAST_MODE_FREQ && priv->devtype >= I2C_RCAR_GEN4) { + priv->flags |= ID_P_FMPLUS; + /* FM+ needs lower SMD and no filters */ + priv->smd /= 2; + cdf = 0; + } else { + priv->flags &= ~ID_P_FMPLUS; + cdf = rate / 20000000; + cdf_width = (priv->devtype == I2C_RCAR_GEN1) ? 2 : 3; + if (cdf >= 1U << cdf_width) + goto err_no_val; + } /* On Gen3+, we use cdf only for the filters, not as a SCL divider */ ick = rate / (priv->devtype < I2C_RCAR_GEN3 ? (cdf + 1) : 1); @@ -344,26 +361,25 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) * x as a base value for the SCLD/SCHD ratio: * * SCL = clkp / (8 + 2 * SMD + SCLD + SCHD + F[(ticf + tr + intd) * clkp]) - * SCL = clkp / (8 + 2 * RCAR_DEFAULT_SMD + RCAR_SCLD_RATIO * x + * SCL = clkp / (8 + 2 * SMD + RCAR_SCLD_RATIO * x * + RCAR_SCHD_RATIO * x + F[...]) * * with: sum_ratio = RCAR_SCLD_RATIO + RCAR_SCHD_RATIO - * and: smd = 2 * RCAR_DEFAULT_SMD * - * SCL = clkp / (8 + smd + sum_ratio * x + F[...]) - * 8 + smd + sum_ratio * x + F[...] = SCL / clkp - * x = ((SCL / clkp) - 8 - smd - F[...]) / sum_ratio + * SCL = clkp / (8 + 2 * smd + sum_ratio * x + F[...]) + * 8 + 2 * smd + sum_ratio * x + F[...] = clkp / SCL + * x = ((clkp / SCL) - 8 - 2 * smd - F[...]) / sum_ratio */ x = DIV_ROUND_UP(rate, t.bus_freq_hz ?: 1); - x = DIV_ROUND_UP(x - 8 - 2 * RCAR_DEFAULT_SMD - round, sum_ratio); - scl = rate / (8 + 2 * RCAR_DEFAULT_SMD + sum_ratio * x + round); + x = DIV_ROUND_UP(x - 8 - 2 * priv->smd - round, sum_ratio); + scl = rate / (8 + 2 * priv->smd + sum_ratio * x + round); /* Bail out if values don't fit into 16 bit or SMD became too large */ - if (x * RCAR_SCLD_RATIO > 0xffff || RCAR_DEFAULT_SMD > x * RCAR_SCHD_RATIO) + if (x * RCAR_SCLD_RATIO > 0xffff || priv->smd > x * RCAR_SCHD_RATIO) goto err_no_val; - dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u SCL gran %u\n", - scl, t.bus_freq_hz, rate, round, cdf, x); + dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u SMD %u SCL gran %u\n", + scl, t.bus_freq_hz, rate, round, cdf, priv->smd, x); priv->icccr = cdf; priv->scl_gran = x; -- 2.35.1