From nobody Tue Nov 24 11:27:41 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=46.4.11.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794851640; b=y6wkO/e5Zz6plBmpKUclxD8KawW4yA6VpHv3rRa7io/zajFGlKzTmnk2HrEcmnc/zoAL fwmkxiSQ0fV/o7B/7Td/G/I/Zs5fKZhfyq/AcOmag/lQbznuWkbQ06AbdX0H5yEkf5FIG hnf6CwExdJ6TqBBv3LGiZd+k5KZDJvj3nMyzRSjLwRW67VTGbwInFGtmAv9hT7Ai2i2Nx DwpYP5o8MOpG4O/0csTiAIrX5xhYye7Huxi9pwhuRIAq23yQ/QednlOzi0X5hc3x6VuMH oFqSm2PMapY1x5jcO0sxKjt/3IhE/H6ntlQVuxEQoMHKqVOeO0Hvs2p21gCySwVwC3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794851640; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=htPpsj1ZCqMRn1NtlL8aj52+oY3mSts/TrS2vw7Er68=; b=5dtQUwCJtJ7JrxM2PveiQ4KbJEI17PSSlEP2UlRNkn19qH0osTrC0Vt2EnepWETvWaae JG70Gy9trsjkBhER/kGqVQndP5QwrHCsQLzASwASjOlRNJ4Ds4p17qdh/5S5WxuoS/CxO HnpXt9K8ScfIuKrmMFcL1+M9XxUO492XI916ZpV8WdKV0cwEpea7f7eE7PlvrokHUY6Bd Y1Z3houKP4A9SRvNFKgIChXjsF76sbZlZZsVmoIrq52oeEX3w6ytm3OE8EXGL6y8WrayE uokKWHd2v64NJeJP6JlI5lJcuzaLn2Di3llP5vp83eGDMv1z+JK1w0YUu7lIAhWUgDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=phrozen.org; spf=pass smtp.mailfrom=phrozen.org; arc=none smtp.remote-ip=46.4.11.11 Received: from nbd.name (nbd.name [46.4.11.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DBA9606A885; Mon, 16 Nov 2026 17:53:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1DBA9606A885 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=phrozen.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=phrozen.org Received: from [2a04:4540:1403:e6fc:5f71:2c1e:7d62:945f] (helo=bertha10..) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xT0tq-004GoI-03; Mon, 16 Nov 2026 18:53:50 +0100 From: John Crispin To: Stefan Roese , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Philipp Zabel Cc: Christian Marangi , devicetree@vger.kernel.org, lei.dong@airoha.com, Linqi.zhang@airoha.com, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Rajeev.kumar@airoha.com, upstream@airoha.com, Weifeng.xu@airoha.com, zhengping.zhang@airoha.com Subject: [PATCH v3 1/3] i2c: mt7621: assert and deassert the reset line Date: Mon, 16 Nov 2026 18:53:41 +0100 Message-Id: <20261116175343.344425-2-john@phrozen.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261116175343.344425-1-john@phrozen.org> References: <20261116175343.344425-1-john@phrozen.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The driver resets the controller with device_reset(), which needs a .reset operation in the reset controller. The EN7581 reset controller implements assert and deassert only, so there every call fails, logs "I2C reset failed!" and leaves the controller as it is, also after a transfer timeout. Get the optional reset line at probe and assert and deassert it. The MT7621 and MT7628 reset controller does the same in its .reset operation, with no delay in between, so nothing changes there. A board without a reset line no longer logs an error, and a reset controller that is not ready yet defers the probe. Suggested-by: Philipp Zabel Reviewed-by: Philipp Zabel Signed-off-by: John Crispin --- Changes in v3: - Add the Reviewed-by of Philipp. Changes in v2: - New patch. It replaces "clk: en7523: add a reset operation" from the clk series (Philipp). - Link to the discussion: https://lore.kernel.org/r/0c96f978571c569de6552fc= 11131e45b55cada1b.camel@pengutronix.de drivers/i2c/busses/i2c-mt7621.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt762= 1.c index 9ea5e3f9a763..7a31cc8b89ce 100644 --- a/drivers/i2c/busses/i2c-mt7621.c +++ b/drivers/i2c/busses/i2c-mt7621.c @@ -65,6 +65,7 @@ struct mtk_i2c { u32 clk_div; u32 flags; struct clk *clk; + struct reset_control *rst; }; =20 static int mtk_i2c_wait_idle(struct mtk_i2c *i2c) @@ -85,7 +86,9 @@ static void mtk_i2c_reset(struct mtk_i2c *i2c) { int ret; =20 - ret =3D device_reset(i2c->adap.dev.parent); + ret =3D reset_control_assert(i2c->rst); + if (!ret) + ret =3D reset_control_deassert(i2c->rst); if (ret) dev_err(i2c->dev, "I2C reset failed!\n"); =20 @@ -288,6 +291,11 @@ static int mtk_i2c_probe(struct platform_device *pdev) return PTR_ERR(i2c->clk); } =20 + i2c->rst =3D devm_reset_control_get_optional_exclusive(&pdev->dev, NULL); + if (IS_ERR(i2c->rst)) + return dev_err_probe(&pdev->dev, PTR_ERR(i2c->rst), + "Failed to get reset\n"); + i2c->dev =3D &pdev->dev; =20 if (of_property_read_u32(pdev->dev.of_node, "clock-frequency", --=20 2.34.1 From nobody Tue Nov 24 11:27:41 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=46.4.11.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794851640; b=40Qq2oBua78BMHrzNrenc/cz5bVgm+1aOXpEHRIJ+8M8k1AgEML4PFRPt33t6UEHjzAm X2zUnk3nQbgfXotu8aW5i8HJytzQ0DDa55uRPaTfnYC0iLeeJjMubBvtDtbDJRvOHuVDm 1eGH35Od6H9jOZdBiWK9NzL/VOQKA45sxS3TQMzRe1wq18xtlWa+Qu4lw/UjrVVK7J2YS sbZf9VJllqlduHS2XPrmOY/moyoe3JGpJW3B5xcA/E1my/+JrsWB+7MX05TsAgLyLmsr9 vfe5iEK/Ay2wy7lCxqUq/z0uB0yLqgtUZBi8nimCJGq6vX1vRwNFQTeO8soYj284GDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794851640; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=52QgrSKsfSH7NwDCbCOwCK+9x4DB/HxzeFNx2X6f/cc=; b=Sg+c+6oQhI26N4cvPqIlw41V28cow6HPdEd1G7+1jFbaumnxb5lBuxRfNgs2UsHjAQUN 4hqiakBeg9n/SHlaUqs9csUPm/KPOoWOsazJ3EkMfk34tftwfjL9yI5YFjnjSLUdgtnYD 1j5+KcYHo2SzQnj42W+LkqaLX4SKHfSsLF2S7UUiIqTLRVBZV48/EtOCx7/FpgAyEE1mp EeFuTZZ2zNAAm+0e0rvZrj/gZLYC8E35HeeVLBAdZMgOFTttrCMPY+JvcbLiACghECzfh 3Yy0VE28Omo4xWvR8jEa+4N2MbI9OwJSWoW0wDbZEMvhZTMiM27AMqgBPpylMpUVccQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=phrozen.org; spf=pass smtp.mailfrom=phrozen.org; arc=none smtp.remote-ip=46.4.11.11 Received: from nbd.name (nbd.name [46.4.11.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DB72606A884; Mon, 16 Nov 2026 17:53:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1DB72606A884 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=phrozen.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=phrozen.org Received: from [2a04:4540:1403:e6fc:5f71:2c1e:7d62:945f] (helo=bertha10..) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xT0tq-004GoI-1I; Mon, 16 Nov 2026 18:53:50 +0100 From: John Crispin To: Stefan Roese , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Philipp Zabel Cc: Christian Marangi , devicetree@vger.kernel.org, lei.dong@airoha.com, Linqi.zhang@airoha.com, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Rajeev.kumar@airoha.com, upstream@airoha.com, Weifeng.xu@airoha.com, zhengping.zhang@airoha.com, Conor Dooley Subject: [PATCH v3 2/3] dt-bindings: i2c: mt7621: add Airoha AN7589 Date: Mon, 16 Nov 2026 18:53:42 +0100 Message-Id: <20261116175343.344425-3-john@phrozen.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261116175343.344425-1-john@phrozen.org> References: <20261116175343.344425-1-john@phrozen.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Airoha AN7589 carries the MT7621 I2C controller with a second control register holding a wider clock divider. Out of reset the controller uses the MT7621 divider, so the MT7621 programming works and mediatek,mt7621-i2c serves as the fallback. Give the AN7589 a compatible of its own so the driver can use the wider divider. Acked-by: Conor Dooley Signed-off-by: John Crispin --- Changes in v3: - Add the Acked-by of Conor. Changes in v2: - Add mediatek,mt7621-i2c as the fallback compatible (Conor). .../devicetree/bindings/i2c/mediatek,mt7621-i2c.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/i2c/mediatek,mt7621-i2c.yaml= b/Documentation/devicetree/bindings/i2c/mediatek,mt7621-i2c.yaml index 118ec00fc190..ec42e72e267f 100644 --- a/Documentation/devicetree/bindings/i2c/mediatek,mt7621-i2c.yaml +++ b/Documentation/devicetree/bindings/i2c/mediatek,mt7621-i2c.yaml @@ -9,12 +9,20 @@ maintainers: =20 title: Mediatek MT7621/MT7628 I2C master controller =20 +description: + The same controller is used on Airoha SoCs. The AN7589 variant adds a + second control register with a wider clock divider. + allOf: - $ref: /schemas/i2c/i2c-controller.yaml# =20 properties: compatible: - const: mediatek,mt7621-i2c + oneOf: + - const: mediatek,mt7621-i2c + - items: + - const: airoha,an7589-i2c + - const: mediatek,mt7621-i2c =20 reg: maxItems: 1 --=20 2.34.1 From nobody Tue Nov 24 11:27:41 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=46.4.11.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794851639; b=cBFT0vJCbSYqyCGUZV3AqSvyNBZqz/ujOzNEMplanwH/5tbyf2KkUREZS8PLxHh536qT wmToHOQSVDOgkIP6ocz/ivY+jFZPmw/KyCq4UwPN037MSBx9NUC5r6dyCLYgwPsfUyDg5 JVAm1Zo+KYQijBuAf+anZ9m295abyrgLhf2irNIPTBSL/QuON5X1YciOkAJk7qIajhqA4 xqt5JcvcUAyM2HPrTLilYl/H1jN185J+XQLnP5xQt8X5vGQCk2IvvqFddi1HrqHh2xb3e FheGA4KYY8MvxNbkiQR8uQv0/az+1oU7Haqr97ByEWcJaGD7obMoWdK/sNmaVPelwhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794851639; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=NNv20ieaX4wZbuOOjfLaQxIZbiUJkwUImQSoKQ5uEkw=; b=UrnSwmhtJiFxJROJvrRNpFLHQT1DCnZi/InK/a2aN/pKHwXQotKqgYo7dl3IHbGWNOA+ O7E6TtUlRxLo9hQo/IQkVmo8nX4h1vMbYUhUnPbpbLYHi81smt1fhkpfgtQ+JXMmrKvhB hNMn3MFbq2fb5D5T10crfLX8sZvcvbqq+leGp4kZn7E+8xIDv57hZ1Nf8DBEy7NaEuikt RTj1VIueP9TX/0AbhTIAZ2GKw6kC2G0iMiB6e0EIArSHNccalJgfyV2VczQTaIp7fV2XG XVe11XTS6nU1gsSMlTWlNT9NSU1iNYwx4mBq1X1TkPrrB+ojTFxob3d4hYonI5NdJ/g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=phrozen.org; spf=pass smtp.mailfrom=phrozen.org; arc=none smtp.remote-ip=46.4.11.11 Received: from nbd.name (nbd.name [46.4.11.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DA86606A882; Mon, 16 Nov 2026 17:53:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1DA86606A882 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=phrozen.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=phrozen.org Received: from [2a04:4540:1403:e6fc:5f71:2c1e:7d62:945f] (helo=bertha10..) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xT0tq-004GoI-2W; Mon, 16 Nov 2026 18:53:50 +0100 From: John Crispin To: Stefan Roese , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Philipp Zabel Cc: Christian Marangi , devicetree@vger.kernel.org, lei.dong@airoha.com, Linqi.zhang@airoha.com, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Rajeev.kumar@airoha.com, upstream@airoha.com, Weifeng.xu@airoha.com, zhengping.zhang@airoha.com Subject: [PATCH v3 3/3] i2c: mt7621: add support for Airoha AN7589 Date: Mon, 16 Nov 2026 18:53:43 +0100 Message-Id: <20261116175343.344425-4-john@phrozen.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261116175343.344425-1-john@phrozen.org> References: <20261116175343.344425-1-john@phrozen.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Airoha AN7589 carries this controller with a second control register at 0x68. It holds a 16 bit clock divider selected by SM0CTL2_SCL_DIV_SEL, wider than the 11 bit field in SM0CTL0, and SDA wait control. The AN7589 also runs without SCL stretching. Describe the variants as match data: whether to set SCL_STRETCH, and whether to program the extended divider. The extended divider is set up before the controller is enabled, and the SM0CTL0 divider stays zero. With the extended divider and the 200 MHz clock the bus runs from fast mode plus down to about 3 kHz, where the SM0CTL0 divider stops at 97.7 kHz. Signed-off-by: John Crispin --- Changes in v3: - Cap the bus rate at 1 MHz instead of the divider from below, so the limits are constant and a clock rate below 1 MHz cannot wrap the divider. Same divider for every valid rate (kernel test robot, sashiko). - Link to the report: https://lore.kernel.org/oe-kbuild-all/202611140348.p9= TnfxBF-lkp@intel.com/ Changes in v2: - The extended divider supports bus rates down to about 3 kHz with the 200 MHz clock. The SM0CTL0 divider stops at 97.7 kHz. - Set up the extended divider before the controller is enabled. The SM0CTL0 divider stays zero. drivers/i2c/busses/i2c-mt7621.c | 60 ++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt762= 1.c index 7a31cc8b89ce..ec6fbb051bea 100644 --- a/drivers/i2c/busses/i2c-mt7621.c +++ b/drivers/i2c/busses/i2c-mt7621.c @@ -10,6 +10,7 @@ * (C) 2014 Sittisak */ =20 +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include =20 #define REG_SM0CFG2_REG 0x28 @@ -28,6 +30,7 @@ #define REG_PINTEN_REG 0x5c #define REG_PINTST_REG 0x60 #define REG_PINTCL_REG 0x64 +#define REG_SM0CTL2_REG 0x68 =20 /* REG_SM0CFG2_REG */ #define SM0CFG2_IS_AUTOMODE BIT(0) @@ -54,13 +57,25 @@ #define SM0CTL1_MODE_MASK (0x7 << 4) #define SM0CTL1_TRI BIT(0) =20 +/* REG_SM0CTL2_REG */ +#define SM0CTL2_DATA_WAIT_SDA BIT(18) +#define SM0CTL2_INIT_WAIT_SDA BIT(17) +#define SM0CTL2_SCL_DIV_SEL BIT(16) +#define SM0CTL2_CLK_DIV_EXT GENMASK(15, 0) + /* timeout waiting for I2C devices to respond */ #define TIMEOUT_MS 1000 =20 +struct mtk_i2c_soc_data { + bool scl_stretch; + bool ext_clk_div; +}; + struct mtk_i2c { void __iomem *base; struct device *dev; struct i2c_adapter adap; + const struct mtk_i2c_soc_data *soc; u32 bus_freq; u32 clk_div; u32 flags; @@ -84,6 +99,7 @@ static int mtk_i2c_wait_idle(struct mtk_i2c *i2c) =20 static void mtk_i2c_reset(struct mtk_i2c *i2c) { + u32 ctl0; int ret; =20 ret =3D reset_control_assert(i2c->rst); @@ -96,8 +112,17 @@ static void mtk_i2c_reset(struct mtk_i2c *i2c) * Don't set SM0CTL0_ODRAIN as its bit meaning is inverted. To * configure open-drain mode, this bit needs to be cleared. */ - iowrite32(((i2c->clk_div << 16) & SM0CTL0_CLK_DIV_MASK) | SM0CTL0_EN | - SM0CTL0_SCL_STRETCH, i2c->base + REG_SM0CTL0_REG); + ctl0 =3D SM0CTL0_EN; + if (i2c->soc->ext_clk_div) + iowrite32(SM0CTL2_SCL_DIV_SEL | SM0CTL2_DATA_WAIT_SDA | + FIELD_PREP(SM0CTL2_CLK_DIV_EXT, i2c->clk_div), + i2c->base + REG_SM0CTL2_REG); + else + ctl0 |=3D (i2c->clk_div << 16) & SM0CTL0_CLK_DIV_MASK; + if (i2c->soc->scl_stretch) + ctl0 |=3D SM0CTL0_SCL_STRETCH; + iowrite32(ctl0, i2c->base + REG_SM0CTL0_REG); + iowrite32(0, i2c->base + REG_SM0CFG2_REG); } =20 @@ -253,8 +278,17 @@ static const struct i2c_algorithm mtk_i2c_algo =3D { .functionality =3D mtk_i2c_func, }; =20 +static const struct mtk_i2c_soc_data mt7621_i2c_soc_data =3D { + .scl_stretch =3D true, +}; + +static const struct mtk_i2c_soc_data an7589_i2c_soc_data =3D { + .ext_clk_div =3D true, +}; + static const struct of_device_id i2c_mtk_dt_ids[] =3D { - { .compatible =3D "mediatek,mt7621-i2c" }, + { .compatible =3D "mediatek,mt7621-i2c", .data =3D &mt7621_i2c_soc_data }, + { .compatible =3D "airoha,an7589-i2c", .data =3D &an7589_i2c_soc_data }, { /* sentinel */ } }; =20 @@ -262,11 +296,17 @@ MODULE_DEVICE_TABLE(of, i2c_mtk_dt_ids); =20 static void mtk_i2c_init(struct mtk_i2c *i2c) { - i2c->clk_div =3D clk_get_rate(i2c->clk) / i2c->bus_freq - 1; - if (i2c->clk_div < 99) - i2c->clk_div =3D 99; - if (i2c->clk_div > SM0CTL0_CLK_DIV_MAX) - i2c->clk_div =3D SM0CTL0_CLK_DIV_MAX; + unsigned long rate =3D clk_get_rate(i2c->clk); + u32 bus_freq =3D i2c->bus_freq; + + if (i2c->soc->ext_clk_div) { + bus_freq =3D min(bus_freq, I2C_MAX_FAST_MODE_PLUS_FREQ); + i2c->clk_div =3D min(rate / bus_freq - 1, + FIELD_MAX(SM0CTL2_CLK_DIV_EXT)); + } else { + i2c->clk_div =3D clamp(rate / bus_freq - 1, 99, + SM0CTL0_CLK_DIV_MAX); + } =20 mtk_i2c_reset(i2c); } @@ -281,6 +321,10 @@ static int mtk_i2c_probe(struct platform_device *pdev) if (!i2c) return -ENOMEM; =20 + i2c->soc =3D device_get_match_data(&pdev->dev); + if (!i2c->soc) + return -EINVAL; + i2c->base =3D devm_platform_get_and_ioremap_resource(pdev, 0, NULL); if (IS_ERR(i2c->base)) return PTR_ERR(i2c->base); --=20 2.34.1