Skip to contentSkip to conversation

i3c: mipi-i3c-hci: derive SAMA7D65 SCL timings from gclk

PATCH In review Manikandan Muralidharan 3 participants 10 messages Dec 4 I3C

lore
Share & tools
lore
#0 lore raw

cover i3c: mipi-i3c-hci: derive SAMA7D65 SCL timings from gclk

The Microchip SAMA7D65 I3C controller support merged in v7.2 [1] relies on two AMD quirks: HCI_QUIRK_OD_PP_TIMING, which programs fixed OD/PP timing values tuned for the AMD core clock, and HCI_QUIRK_RESP_BUF_THLD, which clears the response buffer threshold once after the PIO init.

This series replaces both with Microchip specific handling:

- Patch 1 moves the OD/PP timing register offsets to hci.h so that both vendor quirk files can use them. No functional change.

- Patch 2 adds hci_quirks_mchp.c, which derives the push-pull, open-drain, SDR1..SDR4 extended low count and bus free timings from the gclk rate and the configured I3C/I2C SCL rates. The gclk is the second clock of the existing binding, taken from the clocks already acquired in probe, so the device tree ABI is unchanged. The timings are programmed in bus_init() and restored whenever the controller is reset.

- Patch 3 selects the response buffer threshold in __hci_pio_init(), so that it stays in sync with the cached QUEUE_THLD_CTRL value and is not reverted by IBI threshold updates or a controller reset and restore.

Tested on the SAMA7D65 Curiosity board with an LSM6DSV IMU on the I3C bus (SETDASA, private transfers through the IIO driver). With the 125 MHz gclk, the controller runs push-pull at 12.5 MHz and open-drain at 1 MHz, and the bus keeps working after standby and suspend-to-RAM.

[1] https://lore.kernel.org/all/[email protected]/

Manikandan Muralidharan (3):
i3c: mipi-i3c-hci: move shared SCL timing register offsets to hci.h
i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk
i3c: mipi-i3c-hci: add Microchip quirk to set response buffer
threshold

 drivers/i3c/master/mipi-i3c-hci/Makefile      |   2 +-
 drivers/i3c/master/mipi-i3c-hci/core.c        |  23 +++-
 drivers/i3c/master/mipi-i3c-hci/hci.h         |   9 ++
 drivers/i3c/master/mipi-i3c-hci/hci_quirks.c  |   3 -
 .../i3c/master/mipi-i3c-hci/hci_quirks_mchp.c | 124 ++++++++++++++++++
 drivers/i3c/master/mipi-i3c-hci/pio.c         |   8 +-
 6 files changed, 159 insertions(+), 10 deletions(-)
 create mode 100644 drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/3 i3c: mipi-i3c-hci: move shared SCL timing register offsets to hci.h

HCI_SCL_I3C_OD_TIMING and HCI_SCL_I3C_PP_TIMING are vendor-specific registers that will be programmed by both the AMD and Microchip quirk code. Move them from hci_quirks.c to hci.h to avoid duplicate definitions.

No functional change.

---
 drivers/i3c/master/mipi-i3c-hci/hci.h        | 4 ++++
 drivers/i3c/master/mipi-i3c-hci/hci_quirks.c | 3 ---
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/i3c/master/mipi-i3c-hci/hci.h +4 -0
index 4288a1b5b491..6a5b1f9875e1 100644
@@ -179,6 +179,10 @@ struct i3c_hci_dev_data {
 #define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET	BIT(8)  /* Do PIO queue SW resets after DMA abort */
 #define HCI_QUIRK_DMA_REQUIRES_HC_ABORT		BIT(9)  /* Use HC_CONTROL ABORT to abort DMA */
 
+/* Vendor-specific SCL timing registers shared by the quirk files */
+#define HCI_SCL_I3C_OD_TIMING		0x214
+#define HCI_SCL_I3C_PP_TIMING		0x218
+
 /* global functions */
 void mipi_i3c_hci_resume(struct i3c_hci *hci);
 void mipi_i3c_hci_abort(struct i3c_hci *hci);
drivers/i3c/master/mipi-i3c-hci/hci_quirks.c +0 -3
index 3b9c6e76c536..646de0d9f5c5 100644
@@ -11,9 +11,6 @@
 #include <linux/i3c/master.h>
 #include "hci.h"
 
-/* Timing registers */
-#define HCI_SCL_I3C_OD_TIMING          0x214
-#define HCI_SCL_I3C_PP_TIMING          0x218
 #define HCI_SDA_HOLD_SWITCH_DLY_TIMING 0x230
 
 /* Timing values to configure 9MHz frequency */
Signature · 7 lines
2.43.0


-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#3 lore raw

PATCH 2/3 i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk

In reply to Manikandan Muralidharan

The SAMA7D65 I3C controller currently reuses the AMD OD/PP timing quirk, which the register values tuned for the AMD core clock.Introduce hci_quirks_mchp.c with mchp_cfg_od_pp_timing(), which derives the push-pull, open-drain, SDR1..SDR4 extended low count and bus free timings from the gclk rate and the bus I3C/I2C SCL rates, and gate it with a new HCI_QUIRK_MCHP_OD_PP_TIMING quirk.

The timings are programmed from bus_init(), once the SCL rates are known, and from i3c_hci_reset_and_init() so that they are restored whenever the controller is reset.

---
 drivers/i3c/master/mipi-i3c-hci/Makefile      |   2 +-
 drivers/i3c/master/mipi-i3c-hci/core.c        |  21 ++-
 drivers/i3c/master/mipi-i3c-hci/hci.h         |   4 +
 .../i3c/master/mipi-i3c-hci/hci_quirks_mchp.c | 124 ++++++++++++++++++
 4 files changed, 147 insertions(+), 4 deletions(-)
 create mode 100644 drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c
drivers/i3c/master/mipi-i3c-hci/Makefile +1 -1
index e3d3ef757035..8139d3a049c0 100644
@@ -4,5 +4,5 @@ obj-$(CONFIG_MIPI_I3C_HCI)		+= mipi-i3c-hci.o
 mipi-i3c-hci-y				:= core.o ext_caps.o pio.o dma.o \
 					   cmd_v1.o cmd_v2.o \
 					   dat_v1.o dct_v1.o \
-					   hci_quirks.o
+					   hci_quirks.o hci_quirks_mchp.o
 obj-$(CONFIG_MIPI_I3C_HCI_PCI)		+= mipi-i3c-hci-pci.o
drivers/i3c/master/mipi-i3c-hci/core.c +18 -3
index 23853ca134fb..bc71871be2f0 100644
@@ -183,6 +183,13 @@ static int i3c_hci_bus_init(struct i3c_master_controller *m)
 	if (hci->quirks & HCI_QUIRK_RESP_BUF_THLD)
 		amd_set_resp_buf_thld(hci);
 
+	/* Configure OD and PP timings once the bus SCL rates are known */
+	if (hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) {
+		ret = mchp_cfg_od_pp_timing(hci);
+		if (ret)
+			return ret;
+	}
+
 	scoped_guard(spinlock_irqsave, &hci->lock)
 		hci->irq_inactive = false;
 
@@ -961,6 +968,10 @@ static int i3c_hci_reset_and_init(struct i3c_hci *hci)
 	if (hci->quirks & HCI_QUIRK_OD_PP_TIMING)
 		amd_set_od_pp_timing(hci);
 
+	/* Configure OD and PP timings from the gclk rate for Microchip platforms */
+	if (hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING)
+		return mchp_cfg_od_pp_timing(hci);
+
 	return 0;
 }
 
@@ -1186,7 +1197,6 @@ static int i3c_hci_init(struct i3c_hci *hci)
 static int i3c_hci_probe(struct platform_device *pdev)
 {
 	const struct mipi_i3c_hci_platform_data *pdata = pdev->dev.platform_data;
-	struct clk_bulk_data *clks;
 	struct i3c_hci *hci;
 	int irq, ret;
 
@@ -1222,10 +1232,15 @@ static int i3c_hci_probe(struct platform_device *pdev)
 	if (!hci->quirks && platform_get_device_id(pdev))
 		hci->quirks = platform_get_device_id(pdev)->driver_data;
 
-	ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &clks);
+	ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &hci->clks);
 	if (ret < 0)
 		return dev_err_probe(&pdev->dev, ret,
 				     "Failed to get clocks\n");
+	hci->num_clks = ret;
+
+	/* Microchip SCL timings are derived from the second (gclk) clock */
+	if ((hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) && hci->num_clks < 2)
+		return dev_err_probe(&pdev->dev, -EINVAL, "Missing gclk\n");
 
 	ret = i3c_hci_init(hci);
 	if (ret)
@@ -1268,7 +1283,7 @@ static void i3c_hci_remove(struct platform_device *pdev)
 static const __maybe_unused struct of_device_id i3c_hci_of_match[] = {
 	{ .compatible = "mipi-i3c-hci", },
 	{ .compatible = "microchip,sama7d65-i3c-hci",
-	  .data = (void *)(ulong)(HCI_QUIRK_PIO_MODE | HCI_QUIRK_OD_PP_TIMING |
+	  .data = (void *)(ulong)(HCI_QUIRK_PIO_MODE | HCI_QUIRK_MCHP_OD_PP_TIMING |
 				  HCI_QUIRK_RESP_BUF_THLD) },
 	{},
 };
drivers/i3c/master/mipi-i3c-hci/hci.h +4 -0
index 6a5b1f9875e1..0137c91e84cf 100644
@@ -53,6 +53,8 @@ struct i3c_hci {
 	void __iomem *EXTCAPS_regs;
 	void __iomem *AUTOCMD_regs;
 	void __iomem *DEBUG_regs;
+	struct clk_bulk_data *clks;
+	int num_clks;
 	const struct hci_io_ops *io;
 	void *io_data;
 	const struct hci_cmd_ops *cmd;
@@ -178,6 +180,7 @@ struct i3c_hci_dev_data {
 #define HCI_QUIRK_RPM_PARENT_MANAGED	BIT(7)  /* Runtime PM managed by parent device */
 #define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET	BIT(8)  /* Do PIO queue SW resets after DMA abort */
 #define HCI_QUIRK_DMA_REQUIRES_HC_ABORT		BIT(9)  /* Use HC_CONTROL ABORT to abort DMA */
+#define HCI_QUIRK_MCHP_OD_PP_TIMING	BIT(10) /* Set OD and PP timings from gclk for Microchip */
 
 /* Vendor-specific SCL timing registers shared by the quirk files */
 #define HCI_SCL_I3C_OD_TIMING		0x214
@@ -191,6 +194,7 @@ void mipi_i3c_hci_pio_reset_all_queues(struct i3c_hci *hci);
 void mipi_i3c_hci_dct_index_reset(struct i3c_hci *hci);
 void amd_set_od_pp_timing(struct i3c_hci *hci);
 void amd_set_resp_buf_thld(struct i3c_hci *hci);
+int mchp_cfg_od_pp_timing(struct i3c_hci *hci);
 void i3c_hci_sync_irq_inactive(struct i3c_hci *hci);
 int i3c_hci_process_xfer(struct i3c_hci *hci, struct hci_xfer *xfer, int n);
 
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.43.0
#7 lore raw

PATCH 3/3 i3c: mipi-i3c-hci: add Microchip quirk to set response buffer threshold

In reply to Manikandan Muralidharan

The SAMA7D65 I3C controller interprets RESP_BUF_THLD in QUEUE_THLD_CTRL as N+1 entries, so the default threshold of 1 delays the response interrupt until two responses are queued. It must be set to 0 to get an interrupt after every transfer completion.

Add HCI_QUIRK_MCHP_RESP_BUF_THLD and select the response threshold directly in __hci_pio_init(), so that the register and its cached copy stay consistent across IBI threshold updates, runtime resume and controller reset and restore.

---
 drivers/i3c/master/mipi-i3c-hci/core.c | 2 +-
 drivers/i3c/master/mipi-i3c-hci/hci.h  | 1 +
 drivers/i3c/master/mipi-i3c-hci/pio.c  | 8 ++++++--
 3 files changed, 8 insertions(+), 3 deletions(-)
drivers/i3c/master/mipi-i3c-hci/core.c +1 -1
index bc71871be2f0..159645b21362 100644
@@ -1284,7 +1284,7 @@ static const __maybe_unused struct of_device_id i3c_hci_of_match[] = {
 	{ .compatible = "mipi-i3c-hci", },
 	{ .compatible = "microchip,sama7d65-i3c-hci",
 	  .data = (void *)(ulong)(HCI_QUIRK_PIO_MODE | HCI_QUIRK_MCHP_OD_PP_TIMING |
-				  HCI_QUIRK_RESP_BUF_THLD) },
+				  HCI_QUIRK_MCHP_RESP_BUF_THLD) },
 	{},
 };
 MODULE_DEVICE_TABLE(of, i3c_hci_of_match);
drivers/i3c/master/mipi-i3c-hci/hci.h +1 -0
index 0137c91e84cf..10015a43cc7e 100644
@@ -181,6 +181,7 @@ struct i3c_hci_dev_data {
 #define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET	BIT(8)  /* Do PIO queue SW resets after DMA abort */
 #define HCI_QUIRK_DMA_REQUIRES_HC_ABORT		BIT(9)  /* Use HC_CONTROL ABORT to abort DMA */
 #define HCI_QUIRK_MCHP_OD_PP_TIMING	BIT(10) /* Set OD and PP timings from gclk for Microchip */
+#define HCI_QUIRK_MCHP_RESP_BUF_THLD	BIT(11) /* Set resp buf thld to 0 for Microchip platforms */
 
 /* Vendor-specific SCL timing registers shared by the quirk files */
 #define HCI_SCL_I3C_OD_TIMING		0x214
drivers/i3c/master/mipi-i3c-hci/pio.c +6 -2
index 439578a6eb54..cf6e97711ea2 100644
@@ -146,7 +146,7 @@ struct hci_pio_data {
 
 static void __hci_pio_init(struct i3c_hci *hci, u32 *size_val_ptr)
 {
-	u32 val, size_val, rx_thresh, tx_thresh, ibi_val;
+	u32 val, size_val, rx_thresh, tx_thresh, resp_thresh, ibi_val;
 	struct hci_pio_data *pio = hci->io_data;
 
 	size_val = pio_reg_read(QUEUE_SIZE);
@@ -192,9 +192,13 @@ static void __hci_pio_init(struct i3c_hci *hci, u32 *size_val_ptr)
 	}
 
 	pio->max_ibi_thresh = clamp_val(ibi_val/2, 1, 63);
+
+	/* Microchip encodes RESP_BUF_THLD as N+1, so 0 means one response */
+	resp_thresh = (hci->quirks & HCI_QUIRK_MCHP_RESP_BUF_THLD) ? 0 : 1;
+
 	val = FIELD_PREP(QUEUE_IBI_STATUS_THLD, 1) |
 	      FIELD_PREP(QUEUE_IBI_DATA_THLD, pio->max_ibi_thresh) |
-	      FIELD_PREP(QUEUE_RESP_BUF_THLD, 1) |
+	      FIELD_PREP(QUEUE_RESP_BUF_THLD, resp_thresh) |
 	      FIELD_PREP(QUEUE_CMD_EMPTY_BUF_THLD, 1);
 	pio_reg_write(QUEUE_THLD_CTRL, val);
 	pio->reg_queue_thresh = val;
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH 3/3] i3c: mipi-i3c-hci: add Microchip quirk to set response buffer threshold

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] i3c: mipi-i3c-hci: duplicate HCI_QUIRK_MCHP_RESP_BUF_THLD quirk --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] i3c: mipi-i3c-hci: duplicate HCI_QUIRK_MCHP_RESP_BUF_THLD quirk --

commit 6f42f923623195ae52b4eb176df9cb4bca2f0339
Author: Manikandan Muralidharan <[email protected]>

i3c: mipi-i3c-hci: add Microchip quirk to set response buffer threshold

This commit adds a new HCI_QUIRK_MCHP_RESP_BUF_THLD quirk for Microchip SAMA7D65 and uses it in __hci_pio_init() to program QUEUE_RESP_BUF_THLD to 0 instead of 1.

[ ... ]

drivers/i3c/master/mipi-i3c-hci/hci.h struct i3c_hci_dev_data { · line 184

Quoted 9 lines
drivers/i3c/master/mipi-i3c-hci/hci.h +1 -0
index 0137c91e84cf3..10015a43cc7e8 100644
@@ -181,6 +181,7 @@ struct i3c_hci_dev_data {
 #define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET	BIT(8)  /* Do PIO queue SW resets after DMA abort */
 #define HCI_QUIRK_DMA_REQUIRES_HC_ABORT		BIT(9)  /* Use HC_CONTROL ABORT to abort DMA */
 #define HCI_QUIRK_MCHP_OD_PP_TIMING	BIT(10) /* Set OD and PP timings from gclk for Microchip */
+#define HCI_QUIRK_MCHP_RESP_BUF_THLD	BIT(11) /* Set resp buf thld to 0 for Microchip platforms */

[Severity: Low]
Can this reuse the existing HCI_QUIRK_RESP_BUF_THLD instead of adding HCI_QUIRK_MCHP_RESP_BUF_THLD?

HCI_QUIRK_RESP_BUF_THLD from commit ced86959d28c ("i3c: mipi-i3c-hci: Add a quirk to set Response buffer threshold") already covers the same behavior (programming QUEUE_RESP_BUF_THLD to 0 for controllers that interpret it as N+1), and microchip,sama7d65-i3c-hci used it prior to this patch.

Checking HCI_QUIRK_RESP_BUF_THLD directly in __hci_pio_init() would avoid duplicating the quirk bit, keep reg_queue_thresh consistent for AMDI5017 as well, and allow removing amd_set_resp_buf_thld() and its call in i3c_hci_bus_init().

If a separate Microchip quirk is still needed, the commit message should explain why HCI_QUIRK_RESP_BUF_THLD could not be reused.

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3

-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#4 lore raw

Re: [PATCH 2/3] i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk

In reply to Manikandan Muralidharan
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] i3c: mipi-i3c-hci: missing hci->io->cleanup() on error in i3c_hci_bus_init() - [Medium] i3c…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] i3c: mipi-i3c-hci: missing hci->io->cleanup() on error in i3c_hci_bus_init()
- [Medium] i3c: mchp_cfg_od_pp_timing() violates FM tBUF/tLOW and truncates slow counts
- [Medium] i3c: mchp_cfg_od_pp_timing() allows SCL counts below DW minimum of 5
--

commit 99cd11959d0217e78c304d9c0456f9fa47ba3f6c
Author: Manikandan Muralidharan <[email protected]>

i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk

This commit adds a Microchip-specific quirk and timing helper to compute push-pull, open-drain, SDR1..SDR4 extended low count, and bus-free SCL timings from the gclk rate and bus SCL rates instead of reusing the AMD hardcoded timing quirk on SAMA7D65.

Quoted 5 lines
drivers/i3c/master/mipi-i3c-hci/core.c +0 -0
index 23853ca134fbc..bc71871be2f06 100644

drivers/i3c/master/mipi-i3c-hci/core.c static int i3c_hci_bus_init(struct i3c_master_controller *m) · line 192

Quoted 10 lines
drivers/i3c/master/mipi-i3c-hci/core.c +7 -0
@@ -183,6 +183,13 @@ static int i3c_hci_bus_init(struct i3c_master_controller *m)
 	if (hci->quirks & HCI_QUIRK_RESP_BUF_THLD)
 		amd_set_resp_buf_thld(hci);
 
+	/* Configure OD and PP timings once the bus SCL rates are known */
+	if (hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) {
+		ret = mchp_cfg_od_pp_timing(hci);
+		if (ret)
+			return ret;
+	}
+

[Severity: Medium]
Should this error path call hci->io->cleanup(hci) before returning, or run mchp_cfg_od_pp_timing() before hci->io->init(hci)?

When bus_init() fails, i3c_master_bus_init() skips bus_cleanup(), so a failure here (for example if clk_get_rate() returns 0) leaves PIO interrupts and queues enabled after probe failure, or active DMA rings pointing at freed buffers if DMA mode is ever used with this quirk.

[ ... ]

Quoted 5 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +0 -0
new file mode 100644
index 0000000000000..dff319d6287f5

[ ... ]

Quoted 12 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +12 -0
+#define MCHP_SCL_CNT_MIN		1
+#define MCHP_SCL_CNT_MAX		0xff	/* each count field is 8 bits */
+
+/*
+ * Cycles for one half of an SCL period.
+ *
+ * @core_rate: I3C peripheral (generic) clock rate
+ * @scl_rate:  target rate for the phase/mode being programmed
+ * @base:      cycles already used by the opposite half of the period
+ *
+ * Returns round_up(core_rate / scl_rate) - base, clamped to a non-zero
+ * 8-bit count. Shared by the PP low, OD high, and SDR1..4 extended low counts.

drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c line 65

Quoted 10 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +10 -0
+ */
+static u8 mchp_scl_cnt(unsigned long core_rate, unsigned long scl_rate, u8 base)
+{
+	u32 period = DIV_ROUND_UP(core_rate, scl_rate);
+
+	if (period <= base)
+		return MCHP_SCL_CNT_MIN;
+
+	return min_t(u32, period - base, MCHP_SCL_CNT_MAX);
+}

[Severity: Medium]
Does the SAMA7D65 I3CC timing block share the DesignWare minimum SCL count of 5?

The vendor timing registers match drivers/i3c/master/dw-i3c-master.c shifted by 0x160, where SCL_I3C_TIMING_CNT_MIN is 5. With MCHP_SCL_CNT_MIN at 1, a 100 MHz gclk at the default 12.5 MHz I3C SCL rate computes hcnt = 4 and lcnt = 4, which can violate that minimum.

If MCHP_SCL_CNT_MIN is raised above 1, mchp_scl_cnt() also needs to clamp period - base against MCHP_SCL_CNT_MIN rather than only checking period <= base.

[ ... ]

Quoted 7 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +7 -0
+	hcnt = clamp_t(u32, DIV_ROUND_UP_ULL((u64)I3C_BUS_THIGH_MIXED_MAX_NS * core_rate,
+					     NSEC_PER_SEC) - 1,
+		       MCHP_SCL_CNT_MIN, MCHP_SCL_CNT_MAX);
+	lcnt = mchp_scl_cnt(core_rate, bus->scl_rate.i3c, hcnt);
+	reg_write(HCI_SCL_I3C_PP_TIMING,
+		  FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) |
+		  FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt));

[ ... ]

drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c line 121

Quoted 9 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +9 -0
+	/* Open-drain timing, ~50% duty derived from the I2C SCL rate */
+	lcnt = mchp_scl_cnt(core_rate, 2 * i2c_rate, 0);
+	hcnt = mchp_scl_cnt(core_rate, i2c_rate, lcnt);
+	reg_write(HCI_SCL_I3C_OD_TIMING,
+		  FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) |
+		  FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt));
+
+	/* Bus-free time matches the open-drain low period */
+	reg_write(MCHP_BUS_FREE_TIMING, FIELD_PREP(MCHP_BUS_I3C_MST_FREE, lcnt));

[Severity: Medium]
Can this open-drain and bus-free timing calculation violate the I2C Fast-Mode tLOW/tBUF minimum and silently overclock slower bus modes?

On a mixed bus with a 400 kHz Fast-Mode I2C device, a 50% duty cycle gives an open-drain low and bus-free period of 1250 ns (1256 ns at 125 MHz gclk). That is below the 1300 ns I2C Fast-Mode tLOW and I3C_BUS_TBUF_MIXED_FM_MIN_NS minimums and can cause I2C bus errors.

At 100 kHz Standard Mode and 125 MHz gclk, mchp_scl_cnt() silently clamps both lcnt and hcnt to 0xff (~245 kHz) and writes that 8-bit lcnt to the 16-bit MCHP_BUS_I3C_MST_FREE field (2040 ns vs 4700 ns tBUF).

In I3C_BUS_MODE_MIXED_SLOW at 400 kHz and 125 MHz gclk, push-pull lcnt is similarly clamped to 0xff (~481 kHz instead of <= 400 kHz).

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2

-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] i3c: mipi-i3c-hci: move shared SCL timing register offsets to hci.h

In reply to Manikandan Muralidharan
Quoted 9 lines · Manikandan Muralidharan

HCI_SCL_I3C_OD_TIMING and HCI_SCL_I3C_PP_TIMING are vendor-specific registers that will be programmed by both the AMD and Microchip quirk code. Move them from hci_quirks.c to hci.h to avoid duplicate definitions.

No functional change.

---

Quoted 36 lines
 drivers/i3c/master/mipi-i3c-hci/hci.h        | 4 ++++
 drivers/i3c/master/mipi-i3c-hci/hci_quirks.c | 3 ---
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/i3c/master/mipi-i3c-hci/hci.h +4 -0
index 4288a1b5b491..6a5b1f9875e1 100644
@@ -179,6 +179,10 @@ struct i3c_hci_dev_data {
 #define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET	BIT(8)  /* Do PIO queue SW resets after DMA abort */
 #define HCI_QUIRK_DMA_REQUIRES_HC_ABORT		BIT(9)  /* Use HC_CONTROL ABORT to abort DMA */
 
+/* Vendor-specific SCL timing registers shared by the quirk files */
+#define HCI_SCL_I3C_OD_TIMING		0x214
+#define HCI_SCL_I3C_PP_TIMING		0x218
+
 /* global functions */
 void mipi_i3c_hci_resume(struct i3c_hci *hci);
 void mipi_i3c_hci_abort(struct i3c_hci *hci);
drivers/i3c/master/mipi-i3c-hci/hci_quirks.c +0 -4
index 3b9c6e76c536..646de0d9f5c5 100644
@@ -11,9 +11,6 @@
 #include <linux/i3c/master.h>
 #include "hci.h"
 
-/* Timing registers */
-#define HCI_SCL_I3C_OD_TIMING          0x214
-#define HCI_SCL_I3C_PP_TIMING          0x218
 #define HCI_SDA_HOLD_SWITCH_DLY_TIMING 0x230
 
 /* Timing values to configure 9MHz frequency */
--

2.43.0

#6 lore raw

Re: [PATCH 2/3] i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk

In reply to Manikandan Muralidharan
Quoted 152 lines · Manikandan Muralidharan

The SAMA7D65 I3C controller currently reuses the AMD OD/PP timing quirk, which the register values tuned for the AMD core clock.Introduce hci_quirks_mchp.c with mchp_cfg_od_pp_timing(), which derives the push-pull, open-drain, SDR1..SDR4 extended low count and bus free timings from the gclk rate and the bus I3C/I2C SCL rates, and gate it with a new HCI_QUIRK_MCHP_OD_PP_TIMING quirk.

The timings are programmed from bus_init(), once the SCL rates are known, and from i3c_hci_reset_and_init() so that they are restored whenever the controller is reset.

---
 drivers/i3c/master/mipi-i3c-hci/Makefile      |   2 +-
 drivers/i3c/master/mipi-i3c-hci/core.c        |  21 ++-
 drivers/i3c/master/mipi-i3c-hci/hci.h         |   4 +
 .../i3c/master/mipi-i3c-hci/hci_quirks_mchp.c | 124 ++++++++++++++++++
 4 files changed, 147 insertions(+), 4 deletions(-)
 create mode 100644 drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c
drivers/i3c/master/mipi-i3c-hci/Makefile +1 -1
index e3d3ef757035..8139d3a049c0 100644
@@ -4,5 +4,5 @@ obj-$(CONFIG_MIPI_I3C_HCI)		+= mipi-i3c-hci.o
 mipi-i3c-hci-y				:= core.o ext_caps.o pio.o dma.o \
 					   cmd_v1.o cmd_v2.o \
 					   dat_v1.o dct_v1.o \
-					   hci_quirks.o
+					   hci_quirks.o hci_quirks_mchp.o
 obj-$(CONFIG_MIPI_I3C_HCI_PCI)		+= mipi-i3c-hci-pci.o
drivers/i3c/master/mipi-i3c-hci/core.c +18 -3
index 23853ca134fb..bc71871be2f0 100644
@@ -183,6 +183,13 @@ static int i3c_hci_bus_init(struct i3c_master_controller *m)
 	if (hci->quirks & HCI_QUIRK_RESP_BUF_THLD)
 		amd_set_resp_buf_thld(hci);
 
+	/* Configure OD and PP timings once the bus SCL rates are known */
+	if (hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) {
+		ret = mchp_cfg_od_pp_timing(hci);
+		if (ret)
+			return ret;
+	}
+
 	scoped_guard(spinlock_irqsave, &hci->lock)
 		hci->irq_inactive = false;
 
@@ -961,6 +968,10 @@ static int i3c_hci_reset_and_init(struct i3c_hci *hci)
 	if (hci->quirks & HCI_QUIRK_OD_PP_TIMING)
 		amd_set_od_pp_timing(hci);
 
+	/* Configure OD and PP timings from the gclk rate for Microchip platforms */
+	if (hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING)
+		return mchp_cfg_od_pp_timing(hci);
+
 	return 0;
 }
 
@@ -1186,7 +1197,6 @@ static int i3c_hci_init(struct i3c_hci *hci)
 static int i3c_hci_probe(struct platform_device *pdev)
 {
 	const struct mipi_i3c_hci_platform_data *pdata = pdev->dev.platform_data;
-	struct clk_bulk_data *clks;
 	struct i3c_hci *hci;
 	int irq, ret;
 
@@ -1222,10 +1232,15 @@ static int i3c_hci_probe(struct platform_device *pdev)
 	if (!hci->quirks && platform_get_device_id(pdev))
 		hci->quirks = platform_get_device_id(pdev)->driver_data;
 
-	ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &clks);
+	ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &hci->clks);
 	if (ret < 0)
 		return dev_err_probe(&pdev->dev, ret,
 				     "Failed to get clocks\n");
+	hci->num_clks = ret;
+
+	/* Microchip SCL timings are derived from the second (gclk) clock */
+	if ((hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) && hci->num_clks < 2)
+		return dev_err_probe(&pdev->dev, -EINVAL, "Missing gclk\n");
 
 	ret = i3c_hci_init(hci);
 	if (ret)
@@ -1268,7 +1283,7 @@ static void i3c_hci_remove(struct platform_device *pdev)
 static const __maybe_unused struct of_device_id i3c_hci_of_match[] = {
 	{ .compatible = "mipi-i3c-hci", },
 	{ .compatible = "microchip,sama7d65-i3c-hci",
-	  .data = (void *)(ulong)(HCI_QUIRK_PIO_MODE | HCI_QUIRK_OD_PP_TIMING |
+	  .data = (void *)(ulong)(HCI_QUIRK_PIO_MODE | HCI_QUIRK_MCHP_OD_PP_TIMING |
 				  HCI_QUIRK_RESP_BUF_THLD) },
 	{},
 };
drivers/i3c/master/mipi-i3c-hci/hci.h +4 -0
index 6a5b1f9875e1..0137c91e84cf 100644
@@ -53,6 +53,8 @@ struct i3c_hci {
 	void __iomem *EXTCAPS_regs;
 	void __iomem *AUTOCMD_regs;
 	void __iomem *DEBUG_regs;
+	struct clk_bulk_data *clks;
+	int num_clks;
 	const struct hci_io_ops *io;
 	void *io_data;
 	const struct hci_cmd_ops *cmd;
@@ -178,6 +180,7 @@ struct i3c_hci_dev_data {
 #define HCI_QUIRK_RPM_PARENT_MANAGED	BIT(7)  /* Runtime PM managed by parent device */
 #define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET	BIT(8)  /* Do PIO queue SW resets after DMA abort */
 #define HCI_QUIRK_DMA_REQUIRES_HC_ABORT		BIT(9)  /* Use HC_CONTROL ABORT to abort DMA */
+#define HCI_QUIRK_MCHP_OD_PP_TIMING	BIT(10) /* Set OD and PP timings from gclk for Microchip */
 
 /* Vendor-specific SCL timing registers shared by the quirk files */
 #define HCI_SCL_I3C_OD_TIMING		0x214
@@ -191,6 +194,7 @@ void mipi_i3c_hci_pio_reset_all_queues(struct i3c_hci *hci);
 void mipi_i3c_hci_dct_index_reset(struct i3c_hci *hci);
 void amd_set_od_pp_timing(struct i3c_hci *hci);
 void amd_set_resp_buf_thld(struct i3c_hci *hci);
+int mchp_cfg_od_pp_timing(struct i3c_hci *hci);
 void i3c_hci_sync_irq_inactive(struct i3c_hci *hci);
 int i3c_hci_process_xfer(struct i3c_hci *hci, struct hci_xfer *xfer, int n);
 
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +23 -0
new file mode 100644
index 000000000000..dff319d6287f
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * I3C HCI Microchip Quirks
+ *
+ * Copyright (C) 2026 Microchip Technology Inc. and its subsidiaries
+ *
+ * Author: Manikandan Muralidharan <[email protected]>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/i3c/master.h>
+#include <linux/math.h>
+#include <linux/minmax.h>
+#include <linux/time64.h>
+#include "hci.h"
+
+/* Clock order fixed by the binding: pclk, gclk */
+#define MCHP_GCLK_IDX			1
+
+#define SCL_I3C_TIMING_HCNT		W0_MASK(23, 16)
+#define SCL_I3C_TIMING_LCNT		W0_MASK(7, 0)
+

drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c line 33

Quoted 10 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +10 -0
+/*
+ * Microchip I3CC extended low-count timing (not part of the HCI standard).
+ * Each SDRx mode reuses the push-pull SCL-high count and stretches only the
+ * SCL-low period through its own field.
+ */
+#define MCHP_SCL_EXT_LCNT_TIMING	0x228
+#define MCHP_EXT_LCNT_SDR1		W0_MASK(7, 0)
+#define MCHP_EXT_LCNT_SDR2		W0_MASK(15, 8)
+#define MCHP_EXT_LCNT_SDR3		W0_MASK(23, 16)
+#define MCHP_EXT_LCNT_SDR4		W0_MASK(31, 24)

can you keep bit order consistent. previous define desc order.

Quoted 21 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +21 -0
+
+#define MCHP_BUS_FREE_TIMING		0x234
+#define MCHP_BUS_I3C_MST_FREE		W0_MASK(15, 0)
+
+/* SDR1..SDR4 target SCL rates (Hz) */
+#define MCHP_I3C_SDR1_SCL_RATE		8000000
+#define MCHP_I3C_SDR2_SCL_RATE		6000000
+#define MCHP_I3C_SDR3_SCL_RATE		4000000
+#define MCHP_I3C_SDR4_SCL_RATE		2000000
+
+#define MCHP_SCL_CNT_MIN		1
+#define MCHP_SCL_CNT_MAX		0xff	/* each count field is 8 bits */
+
+/*
+ * Cycles for one half of an SCL period.
+ *
+ * @core_rate: I3C peripheral (generic) clock rate
+ * @scl_rate:  target rate for the phase/mode being programmed
+ * @base:      cycles already used by the opposite half of the period
+ *
+ * Returns round_up(core_rate / scl_rate) - base, clamped to a non-zero

drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c line 64

Quoted 10 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +10 -0
+ * 8-bit count. Shared by the PP low, OD high, and SDR1..4 extended low counts.
+ */
+static u8 mchp_scl_cnt(unsigned long core_rate, unsigned long scl_rate, u8 base)
+{
+	u32 period = DIV_ROUND_UP(core_rate, scl_rate);
+
+	if (period <= base)
+		return MCHP_SCL_CNT_MIN;
+
+	return min_t(u32, period - base, MCHP_SCL_CNT_MAX);

now needn't min_t(), min() should work

Frank

Quoted 63 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +60 -1
+}
+
+int mchp_cfg_od_pp_timing(struct i3c_hci *hci)
+{
+	struct i3c_bus *bus = &hci->master.bus;
+	unsigned long core_rate, i2c_rate;
+	u32 ext_lcnt;
+	u8 hcnt, lcnt;
+
+	/* SCL rates are only known once the bus mode has been set */
+	if (!bus->scl_rate.i3c)
+		return 0;
+
+	core_rate = clk_get_rate(hci->clks[MCHP_GCLK_IDX].clk);
+	if (!core_rate)
+		return -EINVAL;
+
+	/* A pure I3C bus leaves the I2C rate unset, run open-drain at FM+ */
+	i2c_rate = bus->scl_rate.i2c ?: I3C_BUS_I2C_FM_PLUS_SCL_MAX_RATE;
+
+	/*
+	 * Push-pull timing. SCL-high is time-bounded (kept below the 50 ns I2C
+	 * spike-filter threshold so legacy I2C targets ignore the fast I3C
+	 * clock); the low half then fills the rest of the I3C SCL period.
+	 */
+	hcnt = clamp_t(u32, DIV_ROUND_UP_ULL((u64)I3C_BUS_THIGH_MIXED_MAX_NS * core_rate,
+					     NSEC_PER_SEC) - 1,
+		       MCHP_SCL_CNT_MIN, MCHP_SCL_CNT_MAX);
+	lcnt = mchp_scl_cnt(core_rate, bus->scl_rate.i3c, hcnt);
+	reg_write(HCI_SCL_I3C_PP_TIMING,
+		  FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) |
+		  FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt));
+
+	/*
+	 * SDR1..SDR4 extended low counts. The SCL-high count is reused
+	 * unchanged; EXT_LCNT_x is the total SDRx low count, so that
+	 * period = PP_HCNT + EXT_LCNT_x.
+	 */
+	ext_lcnt = FIELD_PREP(MCHP_EXT_LCNT_SDR1,
+			      mchp_scl_cnt(core_rate, MCHP_I3C_SDR1_SCL_RATE, hcnt)) |
+		   FIELD_PREP(MCHP_EXT_LCNT_SDR2,
+			      mchp_scl_cnt(core_rate, MCHP_I3C_SDR2_SCL_RATE, hcnt)) |
+		   FIELD_PREP(MCHP_EXT_LCNT_SDR3,
+			      mchp_scl_cnt(core_rate, MCHP_I3C_SDR3_SCL_RATE, hcnt)) |
+		   FIELD_PREP(MCHP_EXT_LCNT_SDR4,
+			      mchp_scl_cnt(core_rate, MCHP_I3C_SDR4_SCL_RATE, hcnt));
+	reg_write(MCHP_SCL_EXT_LCNT_TIMING, ext_lcnt);
+
+	/* Open-drain timing, ~50% duty derived from the I2C SCL rate */
+	lcnt = mchp_scl_cnt(core_rate, 2 * i2c_rate, 0);
+	hcnt = mchp_scl_cnt(core_rate, i2c_rate, lcnt);
+	reg_write(HCI_SCL_I3C_OD_TIMING,
+		  FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) |
+		  FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt));
+
+	/* Bus-free time matches the open-drain low period */
+	reg_write(MCHP_BUS_FREE_TIMING, FIELD_PREP(MCHP_BUS_I3C_MST_FREE, lcnt));
+
+	return 0;
+}
--

2.43.0

#5 lore raw

Re: [PATCH 2/3] i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk

In reply to [email protected]
Quoted 6 lines · On Fri, Dec 04, 2026 at 08:57:42AM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] i3c: mipi-i3c-hci: missing hci->io->cleanup() on error in i3c_hci_bus_init()
- [Medium] i3c: mchp_cfg_od_pp_timing() violates FM tBUF/tLOW and truncates slow counts

Please check this one.

Frank

Quoted 130 lines

- [Medium] i3c: mchp_cfg_od_pp_timing() allows SCL counts below DW minimum of 5
--

commit 99cd11959d0217e78c304d9c0456f9fa47ba3f6c
Author: Manikandan Muralidharan <[email protected]>

i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk

This commit adds a Microchip-specific quirk and timing helper to compute push-pull, open-drain, SDR1..SDR4 extended low count, and bus-free SCL timings from the gclk rate and bus SCL rates instead of reusing the AMD hardcoded timing quirk on SAMA7D65.

Quoted 5 lines
drivers/i3c/master/mipi-i3c-hci/core.c +0 -0
index 23853ca134fbc..bc71871be2f06 100644

drivers/i3c/master/mipi-i3c-hci/core.c static int i3c_hci_bus_init(struct i3c_master_controller *m) · line 192

Quoted 10 lines
drivers/i3c/master/mipi-i3c-hci/core.c +7 -0
@@ -183,6 +183,13 @@ static int i3c_hci_bus_init(struct i3c_master_controller *m)
 	if (hci->quirks & HCI_QUIRK_RESP_BUF_THLD)
 		amd_set_resp_buf_thld(hci);
 
+	/* Configure OD and PP timings once the bus SCL rates are known */
+	if (hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) {
+		ret = mchp_cfg_od_pp_timing(hci);
+		if (ret)
+			return ret;
+	}
+

[Severity: Medium]
Should this error path call hci->io->cleanup(hci) before returning, or run mchp_cfg_od_pp_timing() before hci->io->init(hci)?

When bus_init() fails, i3c_master_bus_init() skips bus_cleanup(), so a failure here (for example if clk_get_rate() returns 0) leaves PIO interrupts and queues enabled after probe failure, or active DMA rings pointing at freed buffers if DMA mode is ever used with this quirk.

[ ... ]

Quoted 5 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +0 -0
new file mode 100644
index 0000000000000..dff319d6287f5

[ ... ]

Quoted 12 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +12 -0
+#define MCHP_SCL_CNT_MIN		1
+#define MCHP_SCL_CNT_MAX		0xff	/* each count field is 8 bits */
+
+/*
+ * Cycles for one half of an SCL period.
+ *
+ * @core_rate: I3C peripheral (generic) clock rate
+ * @scl_rate:  target rate for the phase/mode being programmed
+ * @base:      cycles already used by the opposite half of the period
+ *
+ * Returns round_up(core_rate / scl_rate) - base, clamped to a non-zero
+ * 8-bit count. Shared by the PP low, OD high, and SDR1..4 extended low counts.

drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c line 65

Quoted 10 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +10 -0
+ */
+static u8 mchp_scl_cnt(unsigned long core_rate, unsigned long scl_rate, u8 base)
+{
+	u32 period = DIV_ROUND_UP(core_rate, scl_rate);
+
+	if (period <= base)
+		return MCHP_SCL_CNT_MIN;
+
+	return min_t(u32, period - base, MCHP_SCL_CNT_MAX);
+}

[Severity: Medium]
Does the SAMA7D65 I3CC timing block share the DesignWare minimum SCL count of 5?

The vendor timing registers match drivers/i3c/master/dw-i3c-master.c shifted by 0x160, where SCL_I3C_TIMING_CNT_MIN is 5. With MCHP_SCL_CNT_MIN at 1, a 100 MHz gclk at the default 12.5 MHz I3C SCL rate computes hcnt = 4 and lcnt = 4, which can violate that minimum.

If MCHP_SCL_CNT_MIN is raised above 1, mchp_scl_cnt() also needs to clamp period - base against MCHP_SCL_CNT_MIN rather than only checking period <= base.

[ ... ]

Quoted 7 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +7 -0
+	hcnt = clamp_t(u32, DIV_ROUND_UP_ULL((u64)I3C_BUS_THIGH_MIXED_MAX_NS * core_rate,
+					     NSEC_PER_SEC) - 1,
+		       MCHP_SCL_CNT_MIN, MCHP_SCL_CNT_MAX);
+	lcnt = mchp_scl_cnt(core_rate, bus->scl_rate.i3c, hcnt);
+	reg_write(HCI_SCL_I3C_PP_TIMING,
+		  FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) |
+		  FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt));

[ ... ]

drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c line 121

Quoted 9 lines
drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file +9 -0
+	/* Open-drain timing, ~50% duty derived from the I2C SCL rate */
+	lcnt = mchp_scl_cnt(core_rate, 2 * i2c_rate, 0);
+	hcnt = mchp_scl_cnt(core_rate, i2c_rate, lcnt);
+	reg_write(HCI_SCL_I3C_OD_TIMING,
+		  FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) |
+		  FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt));
+
+	/* Bus-free time matches the open-drain low period */
+	reg_write(MCHP_BUS_FREE_TIMING, FIELD_PREP(MCHP_BUS_I3C_MST_FREE, lcnt));

[Severity: Medium]
Can this open-drain and bus-free timing calculation violate the I2C Fast-Mode tLOW/tBUF minimum and silently overclock slower bus modes?

On a mixed bus with a 400 kHz Fast-Mode I2C device, a 50% duty cycle gives an open-drain low and bus-free period of 1250 ns (1256 ns at 125 MHz gclk). That is below the 1300 ns I2C Fast-Mode tLOW and I3C_BUS_TBUF_MIXED_FM_MIN_NS minimums and can cause I2C bus errors.

At 100 kHz Standard Mode and 125 MHz gclk, mchp_scl_cnt() silently clamps both lcnt and hcnt to 0xff (~245 kHz) and writes that 8-bit lcnt to the 16-bit MCHP_BUS_I3C_MST_FREE field (2040 ns vs 4700 ns tBUF).

In I3C_BUS_MODE_MIXED_SLOW at 400 kHz and 125 MHz gclk, push-pull lcnt is similarly clamped to 0xff (~481 kHz instead of <= 400 kHz).

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2

--
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c

#9 lore raw

Re: [PATCH 3/3] i3c: mipi-i3c-hci: add Microchip quirk to set response buffer threshold

In reply to Manikandan Muralidharan
Quoted 22 lines · Manikandan Muralidharan

The SAMA7D65 I3C controller interprets RESP_BUF_THLD in QUEUE_THLD_CTRL as N+1 entries, so the default threshold of 1 delays the response interrupt until two responses are queued. It must be set to 0 to get an interrupt after every transfer completion.

Add HCI_QUIRK_MCHP_RESP_BUF_THLD and select the response threshold directly in __hci_pio_init(), so that the register and its cached copy stay consistent across IBI threshold updates, runtime resume and controller reset and restore.

---
 drivers/i3c/master/mipi-i3c-hci/core.c | 2 +-
 drivers/i3c/master/mipi-i3c-hci/hci.h  | 1 +
 drivers/i3c/master/mipi-i3c-hci/pio.c  | 8 ++++++--
 3 files changed, 8 insertions(+), 3 deletions(-)
drivers/i3c/master/mipi-i3c-hci/core.c +0 -0
index bc71871be2f0..159645b21362 100644

drivers/i3c/master/mipi-i3c-hci/core.c static const __maybe_unused struct of_device_id i3c_hci_of_match[] = { · line 1287

Quoted 5 lines
drivers/i3c/master/mipi-i3c-hci/core.c +1 -1
@@ -1284,7 +1284,7 @@ static const __maybe_unused struct of_device_id i3c_hci_of_match[] = {
 	{ .compatible = "mipi-i3c-hci", },
 	{ .compatible = "microchip,sama7d65-i3c-hci",
 	  .data = (void *)(ulong)(HCI_QUIRK_PIO_MODE | HCI_QUIRK_MCHP_OD_PP_TIMING |
-				  HCI_QUIRK_RESP_BUF_THLD) },
+				  HCI_QUIRK_MCHP_RESP_BUF_THLD) },

It worth to change to drvdata like

struct

{
	u32 flags;
	int buf_thld;
}

Frank

Quoted 46 lines
drivers/i3c/master/mipi-i3c-hci/core.c +0 -0
 	{},
 };
 MODULE_DEVICE_TABLE(of, i3c_hci_of_match);
drivers/i3c/master/mipi-i3c-hci/hci.h +1 -0
index 0137c91e84cf..10015a43cc7e 100644
@@ -181,6 +181,7 @@ struct i3c_hci_dev_data {
 #define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET	BIT(8)  /* Do PIO queue SW resets after DMA abort */
 #define HCI_QUIRK_DMA_REQUIRES_HC_ABORT		BIT(9)  /* Use HC_CONTROL ABORT to abort DMA */
 #define HCI_QUIRK_MCHP_OD_PP_TIMING	BIT(10) /* Set OD and PP timings from gclk for Microchip */
+#define HCI_QUIRK_MCHP_RESP_BUF_THLD	BIT(11) /* Set resp buf thld to 0 for Microchip platforms */
 
 /* Vendor-specific SCL timing registers shared by the quirk files */
 #define HCI_SCL_I3C_OD_TIMING		0x214
drivers/i3c/master/mipi-i3c-hci/pio.c +6 -3
index 439578a6eb54..cf6e97711ea2 100644
@@ -146,7 +146,7 @@ struct hci_pio_data {
 
 static void __hci_pio_init(struct i3c_hci *hci, u32 *size_val_ptr)
 {
-	u32 val, size_val, rx_thresh, tx_thresh, ibi_val;
+	u32 val, size_val, rx_thresh, tx_thresh, resp_thresh, ibi_val;
 	struct hci_pio_data *pio = hci->io_data;
 
 	size_val = pio_reg_read(QUEUE_SIZE);
@@ -192,9 +192,13 @@ static void __hci_pio_init(struct i3c_hci *hci, u32 *size_val_ptr)
 	}
 
 	pio->max_ibi_thresh = clamp_val(ibi_val/2, 1, 63);
+
+	/* Microchip encodes RESP_BUF_THLD as N+1, so 0 means one response */
+	resp_thresh = (hci->quirks & HCI_QUIRK_MCHP_RESP_BUF_THLD) ? 0 : 1;
+
 	val = FIELD_PREP(QUEUE_IBI_STATUS_THLD, 1) |
 	      FIELD_PREP(QUEUE_IBI_DATA_THLD, pio->max_ibi_thresh) |
-	      FIELD_PREP(QUEUE_RESP_BUF_THLD, 1) |
+	      FIELD_PREP(QUEUE_RESP_BUF_THLD, resp_thresh) |
 	      FIELD_PREP(QUEUE_CMD_EMPTY_BUF_THLD, 1);
 	pio_reg_write(QUEUE_THLD_CTRL, val);
 	pio->reg_queue_thresh = val;
--

2.43.0