* [PATCH v5 0/3] i2c: mt7621: add Airoha AN7589 support
@ 2026-12-02 18:04 John Crispin
2026-12-02 18:04 ` [PATCH v5 1/3] i2c: mt7621: assert and deassert the reset line John Crispin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: John Crispin @ 2026-12-02 18:04 UTC (permalink / raw)
To: Stefan Roese, Andi Shyti, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Philipp Zabel
Cc: Christian Marangi, devicetree, lei.dong, Linqi.zhang,
linux-arm-kernel, linux-i2c, linux-kernel, linux-mediatek,
Rajeev.kumar, upstream, Weifeng.xu, zhengping.zhang
The Airoha AN7589 carries the MT7621 I2C controller with a second
control register that holds a 16 bit clock divider. Like the AN7581,
it runs without SCL stretching.
Patch 1 resets the controller with reset_control_assert() and
reset_control_deassert() instead of device_reset(), as the EN7581 and
AN7589 reset controller has no .reset operation. Patch 2 adds the
compatible, with mediatek,mt7621-i2c as the fallback. Patch 3 adds the
AN7589 match data and uses the wider divider for bus rates down to
about 3 kHz.
The series applies to next-20261201 and has no dependencies. Sorry for
the V5, I forgot to rebase prior to sending V4.
Changes in v5:
- Rebased on next-20261201, which has the AN7581 support of Christian:
commit fa3fd2c10a8f ("dt-bindings: i2c: mt7621: Document an7581 compatible")
commit 036099c2e588 ("i2c: mt7621: limit SCL_STRETCH only to Mediatek SoC")
- Patch 2: the compatible is a oneOf of the existing enum and the
AN7589 entry.
- Patch 3: use the match data and the SCL stretch flag that came with
the AN7581 support, add the flag for the extended divider to it.
- Patch 1 is unchanged.
- Link to v4: https://lore.kernel.org/r/20261201183145.2953089-1-john@phrozen.org
Changes in v4:
- Patch 3: read the clock rate after the declarations, fail the probe
for a clock rate of 0 and round the AN7589 divider up (Andi).
- Patches 1 and 2 are unchanged.
- Link to v3: https://lore.kernel.org/r/20261116175343.344425-1-john@phrozen.org
Changes in v3:
- Patch 1: add the Reviewed-by of Philipp.
- Patch 2: add the Acked-by of Conor.
- Patch 3: compute the AN7589 divider with constant limits, so a clock
rate below 1 MHz cannot wrap it (kernel test robot, sashiko).
- Link to v2: https://lore.kernel.org/r/20261112185820.1315718-1-john@phrozen.org
Changes in v2:
- Add patch 1. It replaces "clk: en7523: add a reset operation" from
the clk series, as Philipp suggested.
- Patch 2: add mediatek,mt7621-i2c as the fallback compatible (Conor).
- Patch 3: the extended divider supports bus rates down to about 3 kHz.
Set it up before the controller is enabled.
- Link to v1: https://lore.kernel.org/r/20261111093941.691801-1-john@phrozen.org
John Crispin (3):
i2c: mt7621: assert and deassert the reset line
dt-bindings: i2c: mt7621: add Airoha AN7589
i2c: mt7621: add support for Airoha AN7589
.../bindings/i2c/mediatek,mt7621-i2c.yaml | 14 ++++-
drivers/i2c/busses/i2c-mt7621.c | 62 ++++++++++++++++---
2 files changed, 64 insertions(+), 12 deletions(-)
base-commit: d138596e9f822033490b2e577ec2ea64f2aa246c
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v5 1/3] i2c: mt7621: assert and deassert the reset line
2026-12-02 18:04 [PATCH v5 0/3] i2c: mt7621: add Airoha AN7589 support John Crispin
@ 2026-12-02 18:04 ` John Crispin
2026-12-02 18:04 ` [PATCH v5 2/3] dt-bindings: i2c: mt7621: add Airoha AN7589 John Crispin
2026-12-02 18:04 ` [PATCH v5 3/3] i2c: mt7621: add support for " John Crispin
2 siblings, 0 replies; 4+ messages in thread
From: John Crispin @ 2026-12-02 18:04 UTC (permalink / raw)
To: Stefan Roese, Andi Shyti, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Philipp Zabel
Cc: Christian Marangi, devicetree, lei.dong, Linqi.zhang,
linux-arm-kernel, linux-i2c, linux-kernel, linux-mediatek,
Rajeev.kumar, upstream, Weifeng.xu, zhengping.zhang
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 <p.zabel@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: John Crispin <john@phrozen.org>
---
Changes in v5:
- Rebased on next-20261201, no change.
Changes in v4:
- None.
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/0c96f978571c569de6552fc11131e45b55cada1b.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-mt7621.c
index e4fd2709fcbe..67b053d3f57e 100644
--- a/drivers/i2c/busses/i2c-mt7621.c
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -70,6 +70,7 @@ struct mtk_i2c {
u32 clk_div;
u32 flags;
struct clk *clk;
+ struct reset_control *rst;
};
static int mtk_i2c_wait_idle(struct mtk_i2c *i2c)
@@ -91,7 +92,9 @@ static void mtk_i2c_reset(struct mtk_i2c *i2c)
u32 reg;
int ret;
- ret = device_reset(i2c->adap.dev.parent);
+ ret = reset_control_assert(i2c->rst);
+ if (!ret)
+ ret = reset_control_deassert(i2c->rst);
if (ret)
dev_err(i2c->dev, "I2C reset failed!\n");
@@ -306,6 +309,11 @@ static int mtk_i2c_probe(struct platform_device *pdev)
return PTR_ERR(i2c->clk);
}
+ i2c->rst = 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 = &pdev->dev;
i2c->data = device_get_match_data(&pdev->dev);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v5 2/3] dt-bindings: i2c: mt7621: add Airoha AN7589
2026-12-02 18:04 [PATCH v5 0/3] i2c: mt7621: add Airoha AN7589 support John Crispin
2026-12-02 18:04 ` [PATCH v5 1/3] i2c: mt7621: assert and deassert the reset line John Crispin
@ 2026-12-02 18:04 ` John Crispin
2026-12-02 18:04 ` [PATCH v5 3/3] i2c: mt7621: add support for " John Crispin
2 siblings, 0 replies; 4+ messages in thread
From: John Crispin @ 2026-12-02 18:04 UTC (permalink / raw)
To: Stefan Roese, Andi Shyti, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Philipp Zabel
Cc: Christian Marangi, devicetree, lei.dong, Linqi.zhang,
linux-arm-kernel, linux-i2c, linux-kernel, linux-mediatek,
Rajeev.kumar, upstream, Weifeng.xu, zhengping.zhang, Conor Dooley
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 <conor.dooley@microchip.com>
Signed-off-by: John Crispin <john@phrozen.org>
---
Changes in v5:
- Rebased on next-20261201, which has commit fa3fd2c10a8f
("dt-bindings: i2c: mt7621: Document an7581 compatible"). The
compatible is now a oneOf of the existing enum and the AN7589 entry.
I kept the Acked-by of Conor, the AN7589 entry itself is unchanged.
Changes in v4:
- None.
Changes in v3:
- Add the Acked-by of Conor.
Changes in v2:
- Add mediatek,mt7621-i2c as the fallback compatible (Conor).
.../bindings/i2c/mediatek,mt7621-i2c.yaml | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/Documentation/devicetree/bindings/i2c/mediatek,mt7621-i2c.yaml b/Documentation/devicetree/bindings/i2c/mediatek,mt7621-i2c.yaml
index e6ea5bc1c681..7defbb89cd48 100644
--- a/Documentation/devicetree/bindings/i2c/mediatek,mt7621-i2c.yaml
+++ b/Documentation/devicetree/bindings/i2c/mediatek,mt7621-i2c.yaml
@@ -9,14 +9,22 @@ maintainers:
title: Mediatek MT7621/MT7628 I2C master controller
+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#
properties:
compatible:
- enum:
- - airoha,an7581-i2c
- - mediatek,mt7621-i2c
+ oneOf:
+ - enum:
+ - airoha,an7581-i2c
+ - mediatek,mt7621-i2c
+ - items:
+ - const: airoha,an7589-i2c
+ - const: mediatek,mt7621-i2c
reg:
maxItems: 1
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v5 3/3] i2c: mt7621: add support for Airoha AN7589
2026-12-02 18:04 [PATCH v5 0/3] i2c: mt7621: add Airoha AN7589 support John Crispin
2026-12-02 18:04 ` [PATCH v5 1/3] i2c: mt7621: assert and deassert the reset line John Crispin
2026-12-02 18:04 ` [PATCH v5 2/3] dt-bindings: i2c: mt7621: add Airoha AN7589 John Crispin
@ 2026-12-02 18:04 ` John Crispin
2 siblings, 0 replies; 4+ messages in thread
From: John Crispin @ 2026-12-02 18:04 UTC (permalink / raw)
To: Stefan Roese, Andi Shyti, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Philipp Zabel
Cc: Christian Marangi, devicetree, lei.dong, Linqi.zhang,
linux-arm-kernel, linux-i2c, linux-kernel, linux-mediatek,
Rajeev.kumar, upstream, Weifeng.xu, zhengping.zhang
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. Like the AN7581, the AN7589 runs without SCL stretching.
Add match data for the AN7589 with a flag for 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 <john@phrozen.org>
---
Changes in v5:
- Rebased on next-20261201, which has commit 036099c2e588 ("i2c:
mt7621: limit SCL_STRETCH only to Mediatek SoC"). The match data and
the SCL stretch flag come from that commit now, so this patch only
adds the flag for the extended divider and the AN7589 entry.
Changes in v4:
- Read the clock rate after the declarations (Andi).
- Fail the probe for a clock rate of 0. The divider wrapped before
(Andi).
- Round the AN7589 divider up, so the bus never runs faster than
clock-frequency. The dividers for 100 kHz, 400 kHz and 1 MHz with
the 200 MHz clock do not change (Andi).
- Link to the review: https://lore.kernel.org/r/aw7RHNwER6VvW7Is@zenone.zhora.eu
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.p9TnfxBF-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 | 52 ++++++++++++++++++++++++++++-----
1 file changed, 44 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
index 67b053d3f57e..a0da5e522288 100644
--- a/drivers/i2c/busses/i2c-mt7621.c
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -10,6 +10,7 @@
* (C) 2014 Sittisak <sittisaks@hotmail.com>
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/i2c.h>
@@ -18,6 +19,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#include <linux/reset.h>
#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
/* REG_SM0CFG2_REG */
#define SM0CFG2_IS_AUTOMODE BIT(0)
@@ -54,11 +57,18 @@
#define SM0CTL1_MODE_MASK (0x7 << 4)
#define SM0CTL1_TRI BIT(0)
+/* 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
struct mtk_i2c_data {
bool have_scl_stretch;
+ bool ext_clk_div;
};
struct mtk_i2c {
@@ -102,7 +112,13 @@ 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.
*/
- reg = ((i2c->clk_div << 16) & SM0CTL0_CLK_DIV_MASK) | SM0CTL0_EN;
+ reg = SM0CTL0_EN;
+ if (i2c->data->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
+ reg |= (i2c->clk_div << 16) & SM0CTL0_CLK_DIV_MASK;
if (i2c->data->have_scl_stretch)
reg |= SM0CTL0_SCL_STRETCH;
@@ -270,23 +286,41 @@ static const struct mtk_i2c_data i2c_an7581_data = {
.have_scl_stretch = false,
};
+static const struct mtk_i2c_data i2c_an7589_data = {
+ .have_scl_stretch = false,
+ .ext_clk_div = true,
+};
+
static const struct of_device_id i2c_mtk_dt_ids[] = {
{ .compatible = "mediatek,mt7621-i2c", .data = &i2c_mt7621_data },
{ .compatible = "airoha,an7581-i2c", .data = &i2c_an7581_data },
+ { .compatible = "airoha,an7589-i2c", .data = &i2c_an7589_data },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, i2c_mtk_dt_ids);
-static void mtk_i2c_init(struct mtk_i2c *i2c)
+static int mtk_i2c_init(struct mtk_i2c *i2c)
{
- i2c->clk_div = clk_get_rate(i2c->clk) / i2c->bus_freq - 1;
- if (i2c->clk_div < 99)
- i2c->clk_div = 99;
- if (i2c->clk_div > SM0CTL0_CLK_DIV_MAX)
- i2c->clk_div = SM0CTL0_CLK_DIV_MAX;
+ u32 bus_freq = i2c->bus_freq;
+ unsigned long rate;
+
+ rate = clk_get_rate(i2c->clk);
+ if (!rate)
+ return -EINVAL;
+
+ if (i2c->data->ext_clk_div) {
+ bus_freq = min(bus_freq, I2C_MAX_FAST_MODE_PLUS_FREQ);
+ i2c->clk_div = min(DIV_ROUND_UP_ULL(rate, bus_freq) - 1,
+ FIELD_MAX(SM0CTL2_CLK_DIV_EXT));
+ } else {
+ i2c->clk_div = clamp(rate / bus_freq - 1, 99,
+ SM0CTL0_CLK_DIV_MAX);
+ }
mtk_i2c_reset(i2c);
+
+ return 0;
}
static int mtk_i2c_probe(struct platform_device *pdev)
@@ -337,7 +371,9 @@ static int mtk_i2c_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, i2c);
- mtk_i2c_init(i2c);
+ ret = mtk_i2c_init(i2c);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Invalid clock rate\n");
ret = i2c_add_adapter(adap);
if (ret < 0)
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 18:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 18:04 [PATCH v5 0/3] i2c: mt7621: add Airoha AN7589 support John Crispin
2026-12-02 18:04 ` [PATCH v5 1/3] i2c: mt7621: assert and deassert the reset line John Crispin
2026-12-02 18:04 ` [PATCH v5 2/3] dt-bindings: i2c: mt7621: add Airoha AN7589 John Crispin
2026-12-02 18:04 ` [PATCH v5 3/3] i2c: mt7621: add support for " John Crispin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox