i2c: designware: Improve support of multi-messages transfer
Subsystems (4)
v6 cover i2c: designware: Improve support of multi-messages transfer
Add support for the I2C_M_STOP flag to the .xfer() function of the designware driver. This allows grouping multiple accesses in a single call and changing the target address after a STOP flag. This is achieved by splitting i2c_dw_xfer_common() in two functions. The core logic handling the transaction is now in __i2c_dw_xfer_one_part(), while i2c_dw_xfer_common() loops over the messages to search for the I2C_M_STOP flag and calls __i2c_dw_xfer_one_part().
Handle controllers that lack the ability to emit a RESTART when two consecutive messages have the same address and direction by aborting transfers that contain such a sequence of messages. For those controllers, we also check that we do not get any unwanted STOP caused by a Tx FIFO underrun, as they lack the ability to hold the clock during a transaction. And we set the irq as non-threaded to prevent underrun on PREEMPT-RT kernel when filling the FIFO.
The I2C controllers found in the EyeQ6Lplus and EyeQ7H SoCs from Mobileye lack such capability, so a compatible string is added because this cannot be detected at runtime. The corresponding DT bindings has already been merged and is available in v6.19-rc2:
d9b85d296f3a ("dt-bindings: i2c: dw: Add Mobileye I2C controllers")This patch series also simplifies runtime PM handling in i2c_dw_xfer_common() and amd_i2c_dw_xfer_quirk() with PM_RUNTIME_* macros.
To test I2C_M_STOP and other message modifier flags, I posted a patch series for i2c-tools[1]. With it, i2cdetect shows the support of the protocol mangling and repeated start skipping functionalities, and i2ctransfer can set the modifier flags to the I2C messages.
The series is now based on i2c-host tree and only contains the last three patches that have not been merged yet. The first and last patches are functionally identical to the one posted in the previous revision. Only the second patch contains modified code to use PM_RUNTIME_* macros instead of ACQUIRE()/ACQUIRE_ERR(). Thus I let Mika's Acked-by on the first and third patch, and dropped it from the second patch. I hope it was the correct thing to do.
[1]: https://lore.kernel.org/all/[email protected]/
---
Changes in v6:
- Rebased on i2c-host tree.
- Drop the first three cleanup patches of the series: already merged in i2c-host tree.
- Add/improve comments suggested by the last reviews.
- Use PM_RUNTIME_* macros instead of ACQUIRE()/ACQUIRE_ERR().
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Rebased on v6.19-rc6 and fully retested on EyeQ6Lplus.
- Drop dt-binding patch: already merged upstream in v6.19-rc2.
- From Andi Shyti's review:
- __i2c_dw_xfer_one_part() now returns 0 on success instead
of the number of messages transferred.
- Drop inline keyword from i2c_dw_msg_is_valid() declaration.
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Use a boolean property instead of a flag for handling controllers IC_EMPTYFIFO_HOLD_MASTER_EN.
- Reorder the patches so goto and runtime PM auto-cleanup are not mixed in i2c_dw_xfer().
- Drop goto in __i2c_dw_xfer_one_part() and use return.
- Tidy up comments for i2c_dw_msg_is_valid() and irq_flags.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Add a compatible entry for Mobileye EyeQ7H i2c controllers.
- Use runtime PM macro for auto-cleanup in i2c_dw_xfer().
- Add a dedicated i2c_algorithm for AMD NAVI controllers.
- Rename __i2c_dw_xfer_unlocked() as it is not about locking at all.
- Rework the validity check of i2c_msg.
- Flag the irq as non-threaded for controllers that cannot hold the clock to avoid underrun.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Add a single compatible for mobileye i2c controllers based in DesignWare IP.
- Handle the I2C_M_STOP flag instead of emitting a STOP on target address change.
- Abort transfer when it requires a RESTART on controller that cannot emit them.
- Detect FIFO underrun instead of disabling threaded interrupt on PREEMPT_RT kernel.
- Sort the compatible entries in a separate patch.
- Add a cleanup patch on flag reading in i2c_dw_read().
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Benoît Monin (3):
i2c: designware: Implement I2C_M_STOP support
i2c: designware: Use runtime PM macro for auto-cleanup
i2c: designware: Support of controller with IC_EMPTYFIFO_HOLD_MASTER disabled
drivers/i2c/busses/i2c-designware-common.c | 20 ++++ drivers/i2c/busses/i2c-designware-core.h | 3 + drivers/i2c/busses/i2c-designware-master.c | 162 ++++++++++++++++++++-------- drivers/i2c/busses/i2c-designware-platdrv.c | 1 + 4 files changed, 141 insertions(+), 45 deletions(-)
---
base-commit: 51e8ce3630878fa6083e1eec84f58f49ec85089b
change-id: 20251014-i2c-dw-da315f758296
Best regards,
Signature · 3 lines
Benoît Monin, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v6 1/3 i2c: designware: Implement I2C_M_STOP support
Add the support of the I2C_M_STOP flag in i2c_msg by splitting i2c_dw_xfer() in two: __i2c_dw_xfer_one_part() for the core transfer logic and i2c_dw_xfer() for handling the high-level transaction management.
In detail __i2c_dw_xfer_one_part() starts a transaction and wait for its completion, either with a STOP on the bus or an error. i2c_dw_xfer() loops over the messages to search for the I2C_M_STOP flag and calls __i2c_dw_xfer_one_part() for each part of the messages up to a STOP or the end of the messages array.
i2c_dw_xfer() takes care of runtime PM and holds the hardware lock on the bus while calling __i2c_dw_xfer_one_part(), this allows grouping multiple accesses to device that support a STOP in a transaction when done via i2c_dev I2C_RDWR ioctl.
Also, now that we have a lookup of the messages in i2c_dw_xfer() prior to each transaction, we use it to make sure the messages are valid for the transaction, via a new function i2c_dw_msg_is_valid(). We check that the target address does not change before starting the transaction instead of aborting the transfer while it is happening, as it was done in i2c_dw_xfer_msg(). The target address can only be changed after an I2C_M_STOP flag, i.e after a STOP on the i2c bus.
The I2C_FUNC_PROTOCOL_MANGLING flag is added to the list of functionalities supported by the controller, except for the AMD NAVI i2c controller which uses its own xfer() function and is left untouched.
--- drivers/i2c/busses/i2c-designware-master.c | 132 ++++++++++++++++++++--------- 1 file changed, 93 insertions(+), 39 deletions(-)
drivers/i2c/busses/i2c-designware-master.c +93 -39
@@ -377,7 +377,6 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)struct i2c_msg *msgs = dev->msgs;u32 intr_mask;int tx_limit, rx_limit; -u32 addr = msgs[dev->msg_write_idx].addr;u32 buf_len = dev->tx_buf_len;u8 *buf = dev->tx_buf;bool need_restart = false;
@@ -388,18 +387,6 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) {u32 flags = msgs[dev->msg_write_idx].flags; -/* -* If target address has changed, we need to -* reprogram the target address in the I2C -* adapter when we are done with this transfer. -*/ -if (msgs[dev->msg_write_idx].addr != addr) { -dev_err (dev->dev, -"%s: invalid target address\n" , __func__); - dev->msg_err = -EINVAL ; -break ; - } -if (!(dev->status &STATUS_WRITE_IN_PROGRESS )) {/* new i2c_msg */ buf = msgs[dev->msg_write_idx].buf;
@@ -746,17 +733,15 @@ static int i2c_dw_wait_transfer(struct dw_i2c_dev *dev) }/* -* Prepare controller for a transaction and call i2c_dw_xfer_msg. +* Prepare controller for a transaction, start the transfer of the @msgs +* and wait for completion, either a STOP or a error. +* Return: 0 or a negative error code. */ static int -i2c_dw_xfer_common (struct dw_i2c_dev *dev,struct i2c_msg msgs[],int num) +__i2c_dw_xfer_one_part (struct dw_i2c_dev *dev,struct i2c_msg *msgs,size_t num) {int ret; -dev_dbg (dev->dev,"%s: msgs: %d\n" , __func__, num); - -pm_runtime_get_sync (dev->dev); -reinit_completion (&dev->cmd_complete); dev->msgs = msgs; dev->msgs_num = num;
@@ -768,13 +753,9 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num) dev->abort_source =0 ; dev->rx_outstanding =0 ; - ret =i2c_dw_acquire_lock (dev); -if (ret) - goto done_nolock; - ret =i2c_dw_wait_bus_not_busy (dev);if (ret <0 ) - goto done; +return ret;/* Start the transfers */ i2c_dw_xfer_init (dev);
@@ -786,7 +767,7 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)/* i2c_dw_init() implicitly disables the adapter */ i2c_recover_bus (&dev->adapter);i2c_dw_init (dev); - goto done; +return ret; }/*
@@ -809,28 +790,95 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)*/ __i2c_dw_disable_nowait (dev); -if (dev->msg_err) { - ret = dev->msg_err; - goto done; - } +if (dev->msg_err) +return dev->msg_err;/* No error */ -if (likely (!dev->cmd_err && !dev->status)) { - ret = num; - goto done; - } +if (likely (!dev->cmd_err && !dev->status)) +return 0 ;/* We have an error */ -if (dev->cmd_err ==DW_IC_ERR_TX_ABRT ) { - ret =i2c_dw_handle_tx_abort (dev); - goto done; - } +if (dev->cmd_err ==DW_IC_ERR_TX_ABRT ) +return i2c_dw_handle_tx_abort (dev);if (dev->status)dev_err (dev->dev,"transfer terminated early - interrupt latency too high?\n" ); - ret = -EIO ; +return -EIO ; +} + +/* +* Verify that the message at index @idx can be processed as part +* of a single transaction. The @msgs array contains the messages +* of the transaction. The message is checked against its predecessor +* to ensure that it respects the limitation of the controller. +* Return: true if the message can be processed, false otherwise. +*/ +static bool +i2c_dw_msg_is_valid (struct dw_i2c_dev *dev,const struct i2c_msg *msgs,size_t idx) +{ +/* +* The first message of a transaction is valid, +* no constraints from a previous message. +*/ +if (!idx) +return true; + +/* +* We cannot change the target address during a transaction, so make +* sure the address is identical to the one of the previous message. +*/ +if (msgs[idx -1 ].addr != msgs[idx].addr) { +dev_err (dev->dev,"invalid target address\n" ); +return false; + } + +return true; +} + +static int +i2c_dw_xfer_common (struct dw_i2c_dev *dev,struct i2c_msg msgs[],int num) +{ +struct i2c_msg *msgs_part; +size_t cnt; +int ret; + +dev_dbg (dev->dev,"msgs: %d\n" , num); + +pm_runtime_get_sync (dev->dev); + + ret =i2c_dw_acquire_lock (dev); +if (ret) + goto done_nolock; + +/* +* If the I2C_M_STOP is present in some the messages, +* we do one transaction for each part up to the STOP. +*/ +for (msgs_part = msgs; msgs_part < msgs + num; msgs_part += cnt) { +/* +* Count the messages in a transaction, up to a STOP or +* the end of the msgs. The last if below guarantees that +* we check all messages and that msg_parts and cnt are +* in-bounds of msgs and num. +*/ +for (cnt =1 ; ; cnt++) { +if (!i2c_dw_msg_is_valid (dev, msgs_part, cnt -1 )) { + ret = -EINVAL ; + goto done; + } + +if ((msgs_part[cnt -1 ].flags &I2C_M_STOP ) || + (msgs_part + cnt == msgs + num)) +break ; + } + +/* transfer one part up to a STOP */ + ret =__i2c_dw_xfer_one_part (dev, msgs_part, cnt); +if (ret <0 ) +break ; + } done:i2c_dw_set_mode (dev,DW_IC_SLAVE );
@@ -840,7 +888,9 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num) done_nolock:pm_runtime_put_autosuspend (dev->dev); -return ret; +if (ret <0 ) +return ret; +return num; }int i2c_dw_xfer (struct i2c_adapter *adap,struct i2c_msg *msgs,int num)
@@ -859,6 +909,10 @@ void i2c_dw_configure_master(struct dw_i2c_dev *dev) dev->functionality |=I2C_FUNC_10BIT_ADDR |DW_IC_DEFAULT_FUNCTIONALITY ; +/* amd_i2c_dw_xfer_quirk() does not implement protocol mangling */ +if ((dev->flags &MODEL_MASK ) !=MODEL_AMD_NAVI_GPU ) + dev->functionality |=I2C_FUNC_PROTOCOL_MANGLING ; + dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE |DW_IC_CON_RESTART_EN ;
Signature · 1 line
2.52.0
PATCH v6 2/3 i2c: designware: Use runtime PM macro for auto-cleanup
In reply to Benoît MoninSimplify runtime PM handling in i2c_dw_xfer_common() by using the pm_runtime_active_auto_try guard. This adds the proper handling for runtime PM resume errors and allows us to get rid of the done and done_nolock labels.
Also use the dedicated PM_RUNTIME macros in amd_i2c_dw_xfer_quirk() instead of ACQUIRE()/ACQUIRE_ERR().
--- drivers/i2c/busses/i2c-designware-master.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/i2c/busses/i2c-designware-master.c +9 -9
@@ -296,8 +296,8 @@ static int amd_i2c_dw_xfer_quirk(struct dw_i2c_dev *dev, struct i2c_msg *msgs, iu8 *tx_buf;unsigned int val; -ACQUIRE (pm_runtime_active_auto_try, pm)(dev->dev); -if (ACQUIRE_ERR (pm_runtime_active_auto_try, &pm)) +PM_RUNTIME_ACQUIRE_AUTOSUSPEND (dev->dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ;/*
@@ -846,11 +846,13 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)dev_dbg (dev->dev,"msgs: %d\n" , num); -pm_runtime_get_sync (dev->dev); +PM_RUNTIME_ACQUIRE_AUTOSUSPEND (dev->dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm)) +return -ENXIO ; ret =i2c_dw_acquire_lock (dev);if (ret) - goto done_nolock; +return ret;/* * If the I2C_M_STOP is present in some the messages,
@@ -866,13 +868,15 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)for (cnt =1 ; ; cnt++) {if (!i2c_dw_msg_is_valid (dev, msgs_part, cnt -1 )) { ret = -EINVAL ; - goto done; +break ; }if ((msgs_part[cnt -1 ].flags &I2C_M_STOP ) || (msgs_part + cnt == msgs + num))break ; } +if (ret <0 ) +break ;/* transfer one part up to a STOP */ ret =__i2c_dw_xfer_one_part (dev, msgs_part, cnt);
@@ -880,14 +884,10 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)break ; } -done:i2c_dw_set_mode (dev,DW_IC_SLAVE );i2c_dw_release_lock (dev); -done_nolock: -pm_runtime_put_autosuspend (dev->dev); -if (ret <0 )return ret;return num;
Signature · 1 line
2.52.0
PATCH v6 3/3 i2c: designware: Support of controller with IC_EMPTYFIFO_HOLD_MASTER disabled
In reply to Benoît MoninIf IC_EMPTYFIFO_HOLD_MASTER_EN parameter is 0, "Stop" and "Repeated Start" bits in command register do not exist, thus it is impossible to send several consecutive write messages in a single hardware batch. The existing implementation worked with such configuration incorrectly:
all consecutive write messages are joined into a single message without any Start/Stop or Repeated Start conditions. For example, the following command:
i2ctransfer -y 0 w1@0x55 0x00 w1@0x55 0x01
does the same as
i2ctransfer -y 0 w2@0x55 0x00 0x01
In i2c_dw_msg_is_valid(), we ensure that we do not have such sequence of messages requiring a RESTART, aborting the transfer on controller that cannot emit them explicitly.
This behavior is activated by compatible entries because the state of the IC_EMPTYFIFO_HOLD_MASTER_EN parameter cannot be detected at runtime. The new flag emptyfifo_hold_master reflects the state of the parameter, it is set to true for all controllers except those found in Mobileye SoCs. For now, the controllers in Mobileye SoCs are the only ones known to need the workaround. The behavior of the driver is left unmodified for other controllers.
There is another possible problem with this controller configuration:
When the CPU is putting commands to the FIFO, this process must not be interrupted because if FIFO buffer gets empty, the controller finishes the I2C transaction and generates STOP condition on the bus.
If we continue writing the remainder of the message to the FIFO, the controller will start emitting a new transaction with those data. This turns a single message into multiple I2C transactions. To protect against FIFO underrun, two changes are done:
First we flag the interrupt with IRQF_NO_THREAD, to prevent it from running in a thread on PREEMPT-RT kernel. This ensures that we are not interrupted when filling the FIFO as it is very time-senstive. For example, being preempted after writing a single byte in the FIFO with a 1MHz bus gives us only 18µs before an underrun. DMA would allow us to keep the interrupt threaded but it is not available on Mobileye SoC for I2C.
Second in i2c_dw_process_transfer(), we abort if a STOP is detected while a read or a write is in progress. This can occur when processing a message larger than the FIFO. In that case the message is processed in parts, and rely on the TX EMPTY interrupt to refill the FIFO when it gets below a threshold. If servicing this interrupt is delayed for too long, it can trigger a FIFO underrun, thus an unwanted STOP.
--- drivers/i2c/busses/i2c-designware-common.c | 20 ++++++++++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 3 +++ drivers/i2c/busses/i2c-designware-master.c | 18 ++++++++++++++++++ drivers/i2c/busses/i2c-designware-platdrv.c | 1 + 4 files changed, 42 insertions(+)
drivers/i2c/busses/i2c-designware-common.c +20 -0
@@ -492,6 +492,12 @@ int i2c_dw_fw_parse_and_configure(struct dw_i2c_dev *dev) dev->clk_freq_optimized =device_property_read_bool (device,"snps,clk-freq-optimized" ); +/* Mobileye controllers do not hold the clock on empty FIFO */ +if (device_is_compatible (device,"mobileye,eyeq6lplus-i2c" )) + dev->emptyfifo_hold_master = false; +else + dev->emptyfifo_hold_master = true; +i2c_dw_adjust_bus_speed (dev);if (is_of_node (fwnode))
@@ -918,6 +924,20 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)else irq_flags =IRQF_SHARED |IRQF_COND_SUSPEND ; +/* +* The first writing to TX FIFO buffer causes transmission start. +* If IC_EMPTYFIFO_HOLD_MASTER_EN is not set, when TX FIFO gets +* empty, I2C controller finishes the transaction. If writing to +* FIFO is interrupted, FIFO can get empty and the transaction will +* be finished prematurely. FIFO buffer is filled in IRQ handler, +* but in PREEMPT_RT kernel IRQ handler by default is executed +* in thread that can be preempted with another higher priority +* thread or an interrupt. So, IRQF_NO_THREAD flag is required in +* order to prevent any preemption when filling the FIFO. +*/ +if (!dev->emptyfifo_hold_master) + irq_flags |=IRQF_NO_THREAD ; + ret =i2c_dw_acquire_lock (dev);if (ret)return ret;
drivers/i2c/busses/i2c-designware-core.h +3 -0
@@ -260,6 +260,8 @@ struct reset_control;* @clk_freq_optimized: if this value is true, it means the hardware reduces * its internal clock frequency by reducing the internal latency required * to generate the high period and low period of SCL line. +* @emptyfifo_hold_master: true if the controller acting as master holds +* the clock when the Tx FIFO is empty instead of emitting a stop. * * HCNT and LCNT parameters can be used if the platform knows more accurate * values than the one computed based only on the input clock frequency.
@@ -318,6 +320,7 @@ struct dw_i2c_dev {struct i2c_bus_recovery_info rinfo;u32 bus_capacitance_pF;bool clk_freq_optimized; +bool emptyfifo_hold_master; };#define ACCESS_INTR_MASK BIT(0)
drivers/i2c/busses/i2c-designware-master.c +18 -0
@@ -652,6 +652,14 @@ static void i2c_dw_process_transfer(struct dw_i2c_dev *dev, unsigned int stat)if (stat &DW_IC_INTR_TX_EMPTY )i2c_dw_xfer_msg (dev); +/* Abort if we detect a STOP in the middle of a read or a write */ +if ((stat &DW_IC_INTR_STOP_DET ) && + (dev->status & (STATUS_READ_IN_PROGRESS |STATUS_WRITE_IN_PROGRESS ))) { +dev_err (dev->dev,"spurious STOP detected\n" ); + dev->rx_outstanding =0 ; + dev->msg_err = -EIO ; + } +/* * No need to modify or disable the interrupt mask here. * i2c_dw_xfer_msg() will take care of it according to
@@ -834,6 +842,16 @@ i2c_dw_msg_is_valid(struct dw_i2c_dev *dev, const struct i2c_msg *msgs, size_t ireturn false; } +/* +* Make sure we don't need explicit RESTART between two messages +* in the same direction for controllers that cannot emit them. +*/ +if (!dev->emptyfifo_hold_master && + (msgs[idx -1 ].flags &I2C_M_RD ) == (msgs[idx].flags &I2C_M_RD )) { +dev_err (dev->dev,"cannot emit RESTART\n" ); +return false; + } +return true; }
drivers/i2c/busses/i2c-designware-platdrv.c +1 -0
@@ -267,6 +267,7 @@ static void dw_i2c_plat_remove(struct platform_device *pdev) }static const struct of_device_id dw_i2c_of_match[] = { + { .compatible ="mobileye,eyeq6lplus-i2c" }, { .compatible ="mscc,ocelot-i2c" }, { .compatible ="snps,designware-i2c" }, {}
Signature · 1 line
2.52.0
Re: [PATCH v6 3/3] i2c: designware: Support of controller with IC_EMPTYFIFO_HOLD_MASTER disabled
Hi all,
I don't have Keem Bay hardware, but reviewing this against the existing driver I think this hunk may regress the multi-master support added by commit f4e0ba52a89f ("i2c: designware: Do not complete i2c read without RX_FULL interrupt"):
/* Abort if we detect a STOP in the middle of a read or a write */ if ((stat & DW_IC_INTR_STOP_DET) &&
(dev->status & (STATUS_READ_IN_PROGRESS | STATUS_WRITE_IN_PROGRESS))) {
dev_err(dev->dev, "spurious STOP detected\n");
dev->rx_outstanding = 0;
dev->msg_err = -EIO;
}That commit handles the case where STOP_DET is observed before the final RX_FULL. The new check aborts on that intermediate state.
The sibling TX-side underrun check in i2c_dw_xfer_msg() is gated on !emptyfifo_hold_master; this one isn't. I couldn't find discussion of the interaction in the v1–v6 review history so flagging in case it was an oversight.
A minimal fix matching the TX-side gating:
- /* Abort if we detect a STOP in the middle of a read or a write */
- if ((stat & DW_IC_INTR_STOP_DET) &&
+ /*
+ * Abort if we detect a STOP in the middle of a read or a write on
+ * controllers that do not hold SCL on FIFO underrun.
+ */
+ if (!dev->emptyfifo_hold_master &&
+ (stat & DW_IC_INTR_STOP_DET) &&
(dev->status & (STATUS_READ_IN_PROGRESS | STATUS_WRITE_IN_PROGRESS))) {
dev_err(dev->dev, "spurious STOP detected\n");
dev->rx_outstanding = 0;Happy to send as a proper patch if that's the right direction, or to be corrected.
Thanks,
David
Re: [PATCH v6 3/3] i2c: designware: Support of controller with IC_EMPTYFIFO_HOLD_MASTER disabled
Hi David,
Quoted 30 lines · David LaPorte
Hi all,
I don't have Keem Bay hardware, but reviewing this against the existing driver I think this hunk may regress the multi-master support added by commit
f4e0ba52a89f("i2c: designware: Do not complete i2c read withoutRX_FULLinterrupt"):/* Abort if we detect a STOP in the middle of a read or a write */ if ((stat &
DW_IC_INTR_STOP_DET) &&(dev->status & (STATUS_READ_IN_PROGRESS | STATUS_WRITE_IN_PROGRESS))) { dev_err(dev->dev, "spurious STOP detected\n"); dev->rx_outstanding = 0; dev->msg_err = -EIO; }That commit handles the case where
STOP_DETis observed before the finalRX_FULL. The new check aborts on that intermediate state.The sibling TX-side underrun check in
i2c_dw_xfer_msg()is gated on !emptyfifo_hold_master; this one isn't. I couldn't find discussion of the interaction in the v1–v6 review history so flagging in case it was an oversight.A minimal fix matching the TX-side gating:
- /* Abort if we detect a STOP in the middle of a read or a write */
- if ((stat &DW_IC_INTR_STOP_DET) &&
+ /*(quoted diff) +5
-0+ * Abort if we detect a STOP in the middle of a read or a write on + * controllers that do not hold SCL on FIFO underrun. + */ + if (!dev->emptyfifo_hold_master && + (stat & DW_IC_INTR_STOP_DET) && (dev->status & (STATUS_READ_IN_PROGRESS | STATUS_WRITE_IN_PROGRESS))) { dev_err(dev->dev, "spurious STOP detected\n"); dev->rx_outstanding = 0;
Quoted 2 lines
Happy to send as a proper patch if that's the right direction, or to be corrected.
So Keem Bay hardware can get a STOP_DET interrupt while a read is in progress? If that's the case then yes it is not a spurious STOP and limiting the check to controllers that don't hold SCL on Tx FIFO underrun should fix that.
Best regards,
Signature · 3 lines
Benoît Monin, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 31 lines · Benoît Monin
Add support for the
I2C_M_STOPflag to the .xfer() function of the designware driver. This allows grouping multiple accesses in a single call and changing the target address after a STOP flag. This is achieved by splittingi2c_dw_xfer_common()in two functions. The core logic handling the transaction is now in__i2c_dw_xfer_one_part(), whilei2c_dw_xfer_common()loops over the messages to search for theI2C_M_STOPflag and calls__i2c_dw_xfer_one_part().Handle controllers that lack the ability to emit a RESTART when two consecutive messages have the same address and direction by aborting transfers that contain such a sequence of messages. For those controllers, we also check that we do not get any unwanted STOP caused by a Tx FIFO underrun, as they lack the ability to hold the clock during a transaction. And we set the irq as non-threaded to prevent underrun on PREEMPT-RT kernel when filling the FIFO.
The I2C controllers found in the EyeQ6Lplus and EyeQ7H SoCs from Mobileye lack such capability, so a compatible string is added because this cannot be detected at runtime. The corresponding DT bindings has already been merged and is available in v6.19-rc2:
d9b85d296f3a ("dt-bindings: i2c: dw: Add Mobileye I2C controllers")This patch series also simplifies runtime PM handling in
i2c_dw_xfer_common()andamd_i2c_dw_xfer_quirk()with PM_RUNTIME_* macros.To test
I2C_M_STOPand other message modifier flags, I posted a patch series for i2c-tools[1]. With it, i2cdetect shows the support of the protocol mangling and repeated start skipping functionalities, and i2ctransfer can set the modifier flags to the I2C messages.
Quoted 7 lines
The series is now based on i2c-host tree and only contains the last three patches that have not been merged yet. The first and last patches are functionally identical to the one posted in the previous revision. Only the second patch contains modified code to use PM_RUNTIME_* macros instead of ACQUIRE()/ACQUIRE_ERR(). Thus I let Mika's Acked-by on the first and third patch, and dropped it from the second patch. I hope it was the correct thing to do.
Looks good enough to me, and if anything, it may be fixed later on.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Benoit,
Quoted 4 lines
Benoît Monin (3):
i2c: designware: ImplementI2C_M_STOPsupport
i2c: designware: Use runtime PM macro for auto-cleanup
i2c: designware: Support of controller withIC_EMPTYFIFO_HOLD_MASTERdisabled
merged to i2c/i2c-host-2 for the second part of the merge window pull request.
Andi