i2c: designware: Generic polling mode code
Subsystems (3)
v2 cover i2c: designware: Generic polling mode code
Hi
This is mostly the same than the first version implementing generic polling mode code for the i2c-designware except three more patches added before them.
Andy had an idea we should have more consistency to platform flags naming and the first three patches are around that. Michael started the conversion so I took his patch from an internal set and put first. Since this version touches Intel PUNIT semaphore code I Cc'ed Hans.
Andy and Andi had comments to "Uniform initialization flow for polling mode" but I decided to not implement a separate helpter function for interrupt request as it in my opinnion does not make code any easier to read.
I also wanted to retain single return point in the i2c_dw_wait_transfer() implemented by the last patch since I had some debug code there when doing the first version.
v1:
https://lore.kernel.org/linux-i2c/[email protected]/
Jarkko Nikula (8):
i2c: designware: Convert arbitration semaphore flag as semaphore type
i2c: designware: Convert shared_with_punit boolean as semaphore type
i2c: designware: Uniform initialization flow for polling mode
i2c: designware: Do not enable interrupts shortly in polling mode
i2c: designware: Use accessors to DW_IC_INTR_MASK register
i2c: designware: Move interrupt handling functions before
i2c_dw_xfer()
i2c: designware: Fix RX FIFO depth define on Wangxun 10Gb NIC
i2c: designware: Implement generic polling mode code for Wangxun 10Gb
NIC
Michael J. Ruhl (1):
i2c: designware: Add some flexiblity to the model info
drivers/i2c/busses/i2c-designware-amdpsp.c | 2 +- drivers/i2c/busses/i2c-designware-baytrail.c | 2 +- drivers/i2c/busses/i2c-designware-common.c | 2 +- drivers/i2c/busses/i2c-designware-core.h | 38 +- drivers/i2c/busses/i2c-designware-master.c | 417 ++++++++----------- drivers/i2c/busses/i2c-designware-pcidrv.c | 2 +- drivers/i2c/busses/i2c-designware-platdrv.c | 12 +- 7 files changed, 223 insertions(+), 252 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/9 i2c: designware: Add some flexiblity to the model info
From: "Michael J. Ruhl" <[email protected]>
Currently the way to identify a model is via a bit field, of which 4 bits are currently defined.
Use a shifted value to that more models can be defined.
--- drivers/i2c/busses/i2c-designware-core.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-designware-core.h +4 -4
@@ -304,10 +304,10 @@ struct dw_i2c_dev {#define ACCESS_NO_IRQ_SUSPEND BIT(1)#define ARBITRATION_SEMAPHORE BIT(2) -#define MODEL_MSCC_OCELOT BIT(8) -#define MODEL_BAIKAL_BT1 BIT(9) -#define MODEL_AMD_NAVI_GPU BIT(10) -#define MODEL_WANGXUN_SP BIT(11) +#define MODEL_MSCC_OCELOT (1 << 8) +#define MODEL_BAIKAL_BT1 (2 << 8) +#define MODEL_AMD_NAVI_GPU (3 << 8) +#define MODEL_WANGXUN_SP (4 << 8)#define MODEL_MASK GENMASK(11, 8)/*
Signature · 1 line
2.43.0
Andy Shevchenko
reviewerRe: [PATCH v2 1/9] i2c: designware: Add some flexiblity to the model info
Quoted 9 lines · Jarkko Nikula
From: "Michael J. Ruhl" <[email protected]>
Currently the way to identify a model is via a bit field, of which 4 bits are currently defined.
Use a shifted value to that more models can be defined.
Reviewed-by Andy Shevchenko <[email protected]>Suggested-by Andy Shevchenko <[email protected]>
While this is true review, internally we're still discussing the possibility of moving to plain numbers and shift, so we may add arrays which are indexed in model-based way.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 1/9] i2c: designware: Add some flexiblity to the model info
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Jarkko Nikula
From: "Michael J. Ruhl" <[email protected]>
Currently the way to identify a model is via a bit field, of which 4 bits are currently defined.
Quoted 9 lines
Quoted 4 lines
Use a shifted value to that more models can be defined.
Reviewed-by Andy Shevchenko <[email protected]>Suggested-by Andy Shevchenko <[email protected]>While this is true review, internally we're still discussing the possibility of moving to plain numbers and shift, so we may add arrays which are indexed in model-based way.
I was thinking I'll drop these first 3 patches in the next version and go back to v1 version. IMHO it's better this patchset to focus implementing generic polling only and not mix with cleaning up the semaphore or other random stuff.
So planning to go back to v1 version and take your notes for v2 7/9 and 9/9. What would you think?
Andy Shevchenko
reviewerRe: [PATCH v2 1/9] i2c: designware: Add some flexiblity to the model info
Quoted 1 line · Jarkko Nikula
On 2/6/24 17:30, Andy Shevchenko wrote:
...
Quoted 7 lines
I was thinking I'll drop these first 3 patches in the next version and go back to v1 version. IMHO it's better this patchset to focus implementing generic polling only and not mix with cleaning up the semaphore or other random stuff.
So planning to go back to v1 version and take your notes for v2 7/9 and 9/9. What would you think?
I'm fine with that.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 2/9 i2c: designware: Convert arbitration semaphore flag as semaphore type
In reply to Jarkko NikulaMake AMD PSP I2C bus arbitration semaphore flag as a type and add a related flag bit mask. Only one bus semaphore implementation can be active at a time so no need to reserve one flag bit for each of them.
Chosen mask size of 4-bits is large considering currently there is only two semaphore implementations but there is no lack of free flag bits either.
--- drivers/i2c/busses/i2c-designware-amdpsp.c | 2 +- drivers/i2c/busses/i2c-designware-core.h | 4 +++- drivers/i2c/busses/i2c-designware-platdrv.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-designware-amdpsp.c +1 -1
@@ -284,7 +284,7 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)if (!dev)return -ENODEV ; -if (!(dev->flags &ARBITRATION_SEMAPHORE )) +if ((dev->flags &SEMAPHORE_MASK ) !=SEMAPHORE_AMD_PSP )return -ENODEV ;/* Allow to bind only one instance of a driver */
drivers/i2c/busses/i2c-designware-core.h +3 -1
@@ -302,7 +302,9 @@ struct dw_i2c_dev {#define ACCESS_INTR_MASK BIT(0)#define ACCESS_NO_IRQ_SUSPEND BIT(1) -#define ARBITRATION_SEMAPHORE BIT(2) + +#define SEMAPHORE_AMD_PSP (1 << 4) +#define SEMAPHORE_MASK GENMASK(7, 4)#define MODEL_MSCC_OCELOT (1 << 8)#define MODEL_BAIKAL_BT1 (2 << 8)
drivers/i2c/busses/i2c-designware-platdrv.c +1 -1
@@ -50,7 +50,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = { { "808622C1", ACCESS_NO_IRQ_SUSPEND }, { "AMD0010", ACCESS_INTR_MASK }, { "AMDI0010", ACCESS_INTR_MASK }, - { "AMDI0019", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, + { "AMDI0019", ACCESS_INTR_MASK | SEMAPHORE_AMD_PSP }, { "AMDI0510", 0 }, { "APMC0D0F", 0 }, { "HISI02A1", 0 },
Signature · 1 line
2.43.0
PATCH v2 3/9 i2c: designware: Convert shared_with_punit boolean as semaphore type
In reply to Jarkko NikulaRemove the shared_with_punit member variable from the struct dw_i2c_dev and make it one semaphore type. Idea is to make code more uniform when there is need to differentiate between bus semaphores.
--- drivers/i2c/busses/i2c-designware-baytrail.c | 2 +- drivers/i2c/busses/i2c-designware-core.h | 3 +-- drivers/i2c/busses/i2c-designware-platdrv.c | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-designware-baytrail.c +1 -1
@@ -38,7 +38,7 @@ int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev)dev_info (dev->dev,"I2C bus managed by PUNIT\n" ); dev->acquire_lock = iosf_mbi_block_punit_i2c_access; dev->release_lock = iosf_mbi_unblock_punit_i2c_access; - dev->shared_with_punit = true; + dev->flags |=SEMAPHORE_INTEL_PUNIT ;return 0 ; }
drivers/i2c/busses/i2c-designware-core.h +1 -2
@@ -235,7 +235,6 @@ struct reset_control;* @release_lock: function to release a hardware lock on the bus * @semaphore_idx: Index of table with semaphore type attached to the bus. It's * -1 if there is no semaphore. -* @shared_with_punit: true if this bus is shared with the SoCs PUNIT * @disable: function to disable the controller * @init: function to initialize the I2C hardware * @set_sda_hold_time: callback to retrieve IP specific SDA hold timing
@@ -292,7 +291,6 @@ struct dw_i2c_dev {int (*acquire_lock)(void );void (*release_lock)(void );int semaphore_idx; -bool shared_with_punit;void (*disable)(struct dw_i2c_dev *dev);int (*init)(struct dw_i2c_dev *dev);int (*set_sda_hold_time)(struct dw_i2c_dev *dev);
@@ -304,6 +302,7 @@ struct dw_i2c_dev {#define ACCESS_NO_IRQ_SUSPEND BIT(1)#define SEMAPHORE_AMD_PSP (1 << 4) +#define SEMAPHORE_INTEL_PUNIT (2 << 4)#define SEMAPHORE_MASK GENMASK(7, 4)#define MODEL_MSCC_OCELOT (1 << 8)
drivers/i2c/busses/i2c-designware-platdrv.c +4 -4
@@ -181,7 +181,7 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) {pm_runtime_disable (dev->dev); -if (dev->shared_with_punit) +if ((dev->flags &SEMAPHORE_MASK ) ==SEMAPHORE_INTEL_PUNIT )pm_runtime_put_noidle (dev->dev); }
@@ -381,7 +381,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)pm_runtime_use_autosuspend (&pdev->dev);pm_runtime_set_active (&pdev->dev); -if (dev->shared_with_punit) +if ((dev->flags &SEMAPHORE_MASK ) ==SEMAPHORE_INTEL_PUNIT )pm_runtime_get_noresume (&pdev->dev);pm_runtime_enable (&pdev->dev);
@@ -433,7 +433,7 @@ static int dw_i2c_plat_runtime_suspend(struct device *dev) {struct dw_i2c_dev *i_dev =dev_get_drvdata (dev); -if (i_dev->shared_with_punit) +if ((i_dev->flags &SEMAPHORE_MASK ) ==SEMAPHORE_INTEL_PUNIT )return 0 ; i_dev->disable (i_dev);
@@ -455,7 +455,7 @@ static int dw_i2c_plat_runtime_resume(struct device *dev) {struct dw_i2c_dev *i_dev =dev_get_drvdata (dev); -if (!i_dev->shared_with_punit) +if ((i_dev->flags &SEMAPHORE_MASK ) !=SEMAPHORE_INTEL_PUNIT )i2c_dw_prepare_clk (i_dev, true); i_dev->init (i_dev);
Signature · 1 line
2.43.0
PATCH v2 4/9 i2c: designware: Uniform initialization flow for polling mode
In reply to Jarkko NikulaCurrently initialization flow in i2c_dw_probe_master() skips a few steps and has code duplication for polling mode implementation.
Simplify this by adding a new ACCESS_POLLING flag that is set for those two platforms that currently use polling mode and use it to skip interrupt handler setup.
--- drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-master.c | 42 ++++----------------- drivers/i2c/busses/i2c-designware-pcidrv.c | 2 +- drivers/i2c/busses/i2c-designware-platdrv.c | 2 +- 4 files changed, 11 insertions(+), 36 deletions(-)
drivers/i2c/busses/i2c-designware-core.h +1 -0
@@ -300,6 +300,7 @@ struct dw_i2c_dev {#define ACCESS_INTR_MASK BIT(0)#define ACCESS_NO_IRQ_SUSPEND BIT(1) +#define ACCESS_POLLING BIT(3)#define SEMAPHORE_AMD_PSP (1 << 4)#define SEMAPHORE_INTEL_PUNIT (2 << 4)
drivers/i2c/busses/i2c-designware-master.c +8 -34
60 lines not on this page · raw message
drivers/i2c/busses/i2c-designware-pcidrv.c +1 -1
@@ -154,7 +154,7 @@ static int navi_amd_setup(struct pci_dev *pdev, struct dw_pci_controller *c) {struct dw_i2c_dev *dev =dev_get_drvdata (&pdev->dev); - dev->flags |=MODEL_AMD_NAVI_GPU ; + dev->flags |=MODEL_AMD_NAVI_GPU |ACCESS_POLLING ; dev->timings.bus_freq_hz =I2C_MAX_STANDARD_MODE_FREQ ;return 0 ; }
drivers/i2c/busses/i2c-designware-platdrv.c +1 -1
@@ -290,7 +290,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) dev->flags = (uintptr_t )device_get_match_data (&pdev->dev);if (device_property_present (&pdev->dev,"wx,i2c-snps-model" )) - dev->flags =MODEL_WANGXUN_SP ; + dev->flags =MODEL_WANGXUN_SP |ACCESS_POLLING ; dev->dev = &pdev->dev; dev->irq = irq;
Signature · 1 line
2.43.0
Andy Shevchenko
reviewerRe: [PATCH v2 4/9] i2c: designware: Uniform initialization flow for polling mode
Quoted 6 lines · Jarkko Nikula
Currently initialization flow in
i2c_dw_probe_master()skips a few steps and has code duplication for polling mode implementation.Simplify this by adding a new
ACCESS_POLLINGflag that is set for those two platforms that currently use polling mode and use it to skip interrupt handler setup.
...
Quoted 3 lines
#define
ACCESS_INTR_MASKBIT(0)
#defineACCESS_NO_IRQ_SUSPENDBIT(1)
+#defineACCESS_POLLINGBIT(3)
Bit 2 is free now, no?
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 5/9 i2c: designware: Do not enable interrupts shortly in polling mode
In reply to Jarkko NikulaI was testing the polling mode txgbe_i2c_dw_xfer_quirk() on a HW where the i2c-designware has interrupt connected and shared with other device. I noticed there is a bogus interrupt for each transfer.
Reason for this that both polling mode functions call the i2c_dw_xfer_init() which enable interrupts then followed by immediate disable by the same polling mode functions. This is enough to trigger TX_EMPTY interrupt.
Fix this by introducing a __i2c_dw_write_intr_mask() helper that unmasks interrupts conditionally and use it in i2c_dw_xfer_init().
--- drivers/i2c/busses/i2c-designware-core.h | 8 ++++++++ drivers/i2c/busses/i2c-designware-master.c | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-designware-core.h +8 -0
@@ -353,6 +353,14 @@ static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev) dev->status &= ~STATUS_ACTIVE ; } +static inline void __i2c_dw_write_intr_mask (struct dw_i2c_dev *dev, +unsigned int intr_mask) +{ +unsigned int val = dev->flags &ACCESS_POLLING ?0 : intr_mask; + +regmap_write (dev->map,DW_IC_INTR_MASK , val); +} +void __i2c_dw_disable (struct dw_i2c_dev *dev);extern void i2c_dw_configure_master (struct dw_i2c_dev *dev);
drivers/i2c/busses/i2c-designware-master.c +1 -3
@@ -250,7 +250,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)/* Clear and enable interrupts */ regmap_read (dev->map,DW_IC_CLR_INTR , &dummy); -regmap_write (dev->map,DW_IC_INTR_MASK ,DW_IC_INTR_MASTER_MASK ); +__i2c_dw_write_intr_mask (dev,DW_IC_INTR_MASTER_MASK ); }static int i2c_dw_check_stopbit (struct dw_i2c_dev *dev)
@@ -300,7 +300,6 @@ static int amd_i2c_dw_xfer_quirk(struct i2c_adapter *adap, struct i2c_msg *msgs, dev->msgs = msgs; dev->msgs_num = num_msgs;i2c_dw_xfer_init (dev); -regmap_write (dev->map,DW_IC_INTR_MASK ,0 );/* Initiate messages read/write transaction */ for (msg_wrt_idx =0 ; msg_wrt_idx < num_msgs; msg_wrt_idx++) {
@@ -384,7 +383,6 @@ static int txgbe_i2c_dw_xfer_quirk(struct i2c_adapter *adap, struct i2c_msg *msg dev->msgs = msgs; dev->msgs_num = num_msgs;i2c_dw_xfer_init (dev); -regmap_write (dev->map,DW_IC_INTR_MASK ,0 );for (msg_idx =0 ; msg_idx < num_msgs; msg_idx++) { buf = msgs[msg_idx].buf;
Signature · 1 line
2.43.0
PATCH v2 6/9 i2c: designware: Use accessors to DW_IC_INTR_MASK register
In reply to Jarkko NikulaConvert access to DW_IC_INTR_MASK register using the existing __i2c_dw_write_intr_mask() and a __i2c_dw_read_intr_mask() introduced here. Motivation to this is to prepare for generic polling mode code where polling mode will use a SW mask instead of DW_IC_INTR_MASK.
--- drivers/i2c/busses/i2c-designware-common.c | 2 +- drivers/i2c/busses/i2c-designware-core.h | 7 +++++++ drivers/i2c/busses/i2c-designware-master.c | 22 ++++++++++++---------- 3 files changed, 20 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-designware-common.c +1 -1
@@ -648,7 +648,7 @@ void i2c_dw_disable(struct dw_i2c_dev *dev)__i2c_dw_disable (dev);/* Disable all interrupts */ -regmap_write (dev->map,DW_IC_INTR_MASK ,0 ); +__i2c_dw_write_intr_mask (dev,0 );regmap_read (dev->map,DW_IC_CLR_INTR , &dummy);i2c_dw_release_lock (dev);
drivers/i2c/busses/i2c-designware-core.h +7 -0
@@ -361,6 +361,13 @@ static inline void __i2c_dw_write_intr_mask(struct dw_i2c_dev *dev,regmap_write (dev->map,DW_IC_INTR_MASK , val); } +static inline void __i2c_dw_read_intr_mask (struct dw_i2c_dev *dev, +unsigned int *intr_mask) +{ +if (!(dev->flags &ACCESS_POLLING )) +regmap_read (dev->map,DW_IC_INTR_MASK , intr_mask); +} +void __i2c_dw_disable (struct dw_i2c_dev *dev);extern void i2c_dw_configure_master (struct dw_i2c_dev *dev);
drivers/i2c/busses/i2c-designware-master.c +12 -10
@@ -240,7 +240,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) msgs[dev->msg_write_idx].addr | ic_tar);/* Enforce disabled interrupts (due to HW issues) */ -regmap_write (dev->map,DW_IC_INTR_MASK ,0 ); +__i2c_dw_write_intr_mask (dev,0 );/* Enable the adapter */ __i2c_dw_enable (dev);
@@ -544,7 +544,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)if (dev->msg_err) intr_mask =0 ; -regmap_write (dev->map,DW_IC_INTR_MASK , intr_mask); +__i2c_dw_write_intr_mask (dev, intr_mask); } static u8
@@ -552,6 +552,7 @@ i2c_dw_recv_len(struct dw_i2c_dev *dev, u8 len) {struct i2c_msg *msgs = dev->msgs;u32 flags = msgs[dev->msg_read_idx].flags; +unsigned int intr_mask;/* * Adjust the buffer length and mask the flag
@@ -566,8 +567,9 @@ i2c_dw_recv_len(struct dw_i2c_dev *dev, u8 len)* Received buffer length, re-enable TX_EMPTY interrupt * to resume the SMBUS transaction. */ -regmap_update_bits (dev->map,DW_IC_INTR_MASK ,DW_IC_INTR_TX_EMPTY , -DW_IC_INTR_TX_EMPTY ); +__i2c_dw_read_intr_mask (dev, &intr_mask); + intr_mask |=DW_IC_INTR_TX_EMPTY ; +__i2c_dw_write_intr_mask (dev, intr_mask);return len; }
@@ -827,7 +829,7 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)* interrupt really came from this HW (E.g. firmware has left * the HW active). */ -regmap_write (dev->map,DW_IC_INTR_MASK ,0 ); +__i2c_dw_write_intr_mask (dev,0 );return IRQ_HANDLED ; }
@@ -840,7 +842,7 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)* Anytime TX_ABRT is set, the contents of the tx/rx * buffers are flushed. Make sure to skip them. */ -regmap_write (dev->map,DW_IC_INTR_MASK ,0 ); +__i2c_dw_write_intr_mask (dev,0 ); goto tx_aborted; }
@@ -862,9 +864,9 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)complete (&dev->cmd_complete); else if (unlikely(dev->flags & ACCESS_INTR_MASK)) {/* Workaround to trigger pending interrupt */ -regmap_read (dev->map,DW_IC_INTR_MASK , &stat); -regmap_write (dev->map,DW_IC_INTR_MASK ,0 ); -regmap_write (dev->map,DW_IC_INTR_MASK , stat); +__i2c_dw_read_intr_mask (dev, &stat); +__i2c_dw_write_intr_mask (dev,0 ); +__i2c_dw_write_intr_mask (dev, stat); }return IRQ_HANDLED ;
@@ -1016,7 +1018,7 @@ int i2c_dw_probe_master(struct dw_i2c_dev *dev)if (ret)return ret; -regmap_write (dev->map,DW_IC_INTR_MASK ,0 ); +__i2c_dw_write_intr_mask (dev,0 );i2c_dw_release_lock (dev);if (!(dev->flags &ACCESS_POLLING )) {
Signature · 1 line
2.43.0
PATCH v2 7/9 i2c: designware: Move interrupt handling functions before i2c_dw_xfer()
In reply to Jarkko NikulaCode is more logically arranged when i2c_dw_read_clear_intrbits() and i2c_dw_isr() are located before i2c_dw_xfer().
Real reason for this is to prepare for more shared code between interrupt and polling mode code.
--- drivers/i2c/busses/i2c-designware-master.c | 226 ++++++++++----------- 1 file changed, 113 insertions(+), 113 deletions(-)
drivers/i2c/busses/i2c-designware-master.c +113 -113
@@ -633,119 +633,6 @@ i2c_dw_read(struct dw_i2c_dev *dev) } } -/* -* Prepare controller for a transaction and call i2c_dw_xfer_msg. -*/ -static int -i2c_dw_xfer (struct i2c_adapter *adap,struct i2c_msg msgs[],int num) -{ -struct dw_i2c_dev *dev =i2c_get_adapdata (adap); -int ret; - -dev_dbg (dev->dev,"%s: msgs: %d\n" , __func__, num); - -pm_runtime_get_sync (dev->dev); - -/* -* Initiate I2C message transfer when polling mode is enabled, -* As it is polling based transfer mechanism, which does not support -* interrupt based functionalities of existing DesignWare driver. -*/ -switch (dev->flags &MODEL_MASK ) { -case MODEL_AMD_NAVI_GPU : - ret =amd_i2c_dw_xfer_quirk (adap, msgs, num); - goto done_nolock; -case MODEL_WANGXUN_SP : - ret =txgbe_i2c_dw_xfer_quirk (adap, msgs, num); - goto done_nolock; -default : -break ; - } - -reinit_completion (&dev->cmd_complete); - dev->msgs = msgs; - dev->msgs_num = num; - dev->cmd_err =0 ; - dev->msg_write_idx =0 ; - dev->msg_read_idx =0 ; - dev->msg_err =0 ; - dev->status =0 ; - 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; - -/* Start the transfers */ -i2c_dw_xfer_init (dev); - -/* Wait for tx to complete */ -if (!wait_for_completion_timeout (&dev->cmd_complete, adap->timeout)) { -dev_err (dev->dev,"controller timed out\n" ); -/* i2c_dw_init implicitly disables the adapter */ -i2c_recover_bus (&dev->adapter); -i2c_dw_init_master (dev); - ret = -ETIMEDOUT ; - goto done; - } - -/* -* We must disable the adapter before returning and signaling the end -* of the current transfer. Otherwise the hardware might continue -* generating interrupts which in turn causes a race condition with -* the following transfer. Needs some more investigation if the -* additional interrupts are a hardware bug or this driver doesn't -* handle them correctly yet. -*/ -__i2c_dw_disable_nowait (dev); - -if (dev->msg_err) { - ret = dev->msg_err; - goto done; - } - -/* No error */ -if (likely (!dev->cmd_err && !dev->status)) { - ret = num; - goto done; - } - -/* We have an error */ -if (dev->cmd_err ==DW_IC_ERR_TX_ABRT ) { - ret =i2c_dw_handle_tx_abort (dev); - goto done; - } - -if (dev->status) -dev_err (dev->dev, -"transfer terminated early - interrupt latency too high?\n" ); - - ret = -EIO ; - -done: -i2c_dw_release_lock (dev); - -done_nolock: -pm_runtime_mark_last_busy (dev->dev); -pm_runtime_put_autosuspend (dev->dev); - -return ret; -} - -static const struct i2c_algorithm i2c_dw_algo = { - .master_xfer = i2c_dw_xfer, - .functionality = i2c_dw_func, -}; - -static const struct i2c_adapter_quirks i2c_dw_quirks = { - .flags =I2C_AQ_NO_ZERO_LEN , -}; -static u32 i2c_dw_read_clear_intrbits (struct dw_i2c_dev *dev) {unsigned int stat, dummy;
@@ -872,6 +759,119 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)return IRQ_HANDLED ; } +/* +* Prepare controller for a transaction and call i2c_dw_xfer_msg. +*/ +static int +i2c_dw_xfer (struct i2c_adapter *adap,struct i2c_msg msgs[],int num) +{ +struct dw_i2c_dev *dev =i2c_get_adapdata (adap); +int ret; + +dev_dbg (dev->dev,"%s: msgs: %d\n" , __func__, num); + +pm_runtime_get_sync (dev->dev); + +/* +* Initiate I2C message transfer when polling mode is enabled, +* As it is polling based transfer mechanism, which does not support +* interrupt based functionalities of existing DesignWare driver. +*/ +switch (dev->flags &MODEL_MASK ) { +case MODEL_AMD_NAVI_GPU : + ret =amd_i2c_dw_xfer_quirk (adap, msgs, num); + goto done_nolock; +case MODEL_WANGXUN_SP : + ret =txgbe_i2c_dw_xfer_quirk (adap, msgs, num); + goto done_nolock; +default : +break ; + } + +reinit_completion (&dev->cmd_complete); + dev->msgs = msgs; + dev->msgs_num = num; + dev->cmd_err =0 ; + dev->msg_write_idx =0 ; + dev->msg_read_idx =0 ; + dev->msg_err =0 ; + dev->status =0 ; + 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; + +/* Start the transfers */ +i2c_dw_xfer_init (dev); + +/* Wait for tx to complete */ +if (!wait_for_completion_timeout (&dev->cmd_complete, adap->timeout)) { +dev_err (dev->dev,"controller timed out\n" ); +/* i2c_dw_init implicitly disables the adapter */ +i2c_recover_bus (&dev->adapter); +i2c_dw_init_master (dev); + ret = -ETIMEDOUT ; + goto done; + } + +/* +* We must disable the adapter before returning and signaling the end +* of the current transfer. Otherwise the hardware might continue +* generating interrupts which in turn causes a race condition with +* the following transfer. Needs some more investigation if the +* additional interrupts are a hardware bug or this driver doesn't +* handle them correctly yet. +*/ +__i2c_dw_disable_nowait (dev); + +if (dev->msg_err) { + ret = dev->msg_err; + goto done; + } + +/* No error */ +if (likely (!dev->cmd_err && !dev->status)) { + ret = num; + goto done; + } + +/* We have an error */ +if (dev->cmd_err ==DW_IC_ERR_TX_ABRT ) { + ret =i2c_dw_handle_tx_abort (dev); + goto done; + } + +if (dev->status) +dev_err (dev->dev, +"transfer terminated early - interrupt latency too high?\n" ); + + ret = -EIO ; + +done: +i2c_dw_release_lock (dev); + +done_nolock: +pm_runtime_mark_last_busy (dev->dev); +pm_runtime_put_autosuspend (dev->dev); + +return ret; +} + +static const struct i2c_algorithm i2c_dw_algo = { + .master_xfer = i2c_dw_xfer, + .functionality = i2c_dw_func, +}; + +static const struct i2c_adapter_quirks i2c_dw_quirks = { + .flags =I2C_AQ_NO_ZERO_LEN , +}; +void i2c_dw_configure_master (struct dw_i2c_dev *dev) {struct i2c_timings *t = &dev->timings;
Signature · 1 line
2.43.0
Andy Shevchenko
reviewerRe: [PATCH v2 7/9] i2c: designware: Move interrupt handling functions before i2c_dw_xfer()
Quoted 5 lines · Jarkko Nikula
Code is more logically arranged when
i2c_dw_read_clear_intrbits()andi2c_dw_isr()are located beforei2c_dw_xfer().Real reason for this is to prepare for more shared code between interrupt and polling mode code.
...
drivers/i2c/busses/i2c-designware-master.c static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) · line 827
Quoted 5 lines
drivers/i2c/busses/i2c-designware-master.c +5
-0+/* +* We must disable the adapter before returning and signaling the end +* of the current transfer. Otherwise the hardware might continue +* generating interrupts which in turn causes a race condition with +* the following transfer. Needs some more investigation if the
While at it, you may make it consistent, i.e. by dropping an extra space.
Quoted 3 lines
drivers/i2c/busses/i2c-designware-master.c +3
-0+* additional interrupts are a hardware bug or this driver doesn't +* handle them correctly yet. +*/
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 8/9 i2c: designware: Fix RX FIFO depth define on Wangxun 10Gb NIC
In reply to Jarkko NikulaI believe RX FIFO depth define 0 is incorrect on Wangxun 10Gb NIC. It must be at least 1 since code is able to read received data from the DW_IC_DATA_CMD register.
For now this define is irrelevant since the txgbe_i2c_dw_xfer_quirk() doesn't use the rx_fifo_depth member variable of struct dw_i2c_dev but is needed when converting code into generic polling mode implementation.
--- drivers/i2c/busses/i2c-designware-core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-core.h +1 -1
@@ -320,7 +320,7 @@ struct dw_i2c_dev {#define AMD_UCSI_INTR_EN 0xd#define TXGBE_TX_FIFO_DEPTH 4 -#define TXGBE_RX_FIFO_DEPTH 0 +#define TXGBE_RX_FIFO_DEPTH 1struct i2c_dw_semaphore_callbacks {int (*probe)(struct dw_i2c_dev *dev);
Signature · 1 line
2.43.0
PATCH v2 9/9 i2c: designware: Implement generic polling mode code for Wangxun 10Gb NIC
In reply to Jarkko NikulaI got an idea the i2c-designware should not need duplicated state machines for the interrupt and polling modes. The IP is practically the same and state transitions happens in response to the events that can be observed from the DW_IC_RAW_INTR_STAT register. Either by interrupts or by polling.
Another reasons are the interrupt mode is the most tested, has handling for special cases as well as transmit abort handling and those are missing from two polling mode quirks.
Patch implements a generic polling mode by using existing code for interrupt mode. This is done by moving event handling from the i2c_dw_isr() into a new i2c_dw_process_transfer() that will be called both from the i2c_dw_isr() and a polling loop.
Polling loop is implemented in a new i2c_dw_wait_transfer() that is shared between both modes. In interrupt mode it waits for the completion object as before. In polling mode both completion object and DW_IC_RAW_INTR_STAT are polled to determine completed transfer and state transitions.
Loop tries to save power by sleeping "stetson guessed" range between 3 and 25 µS which falls between 10 cycles of High-speed mode 3.4 Mb/s and Fast mode 400 kHz. With it the CPU usage was reduced under heavy Fast mode I2C transfer without much increase in total transfer time but otherwise no more effort has been put to optimize this.
I decided to convert the txgbe_i2c_dw_xfer_quirk() straight to generic polling mode code in this patch. It doesn't have HW dependent quirks like the amd_i2c_dw_xfer_quirk() does have and without users this patch is needless.
--- drivers/i2c/busses/i2c-designware-core.h | 5 + drivers/i2c/busses/i2c-designware-master.c | 169 +++++++++------------ 2 files changed, 77 insertions(+), 97 deletions(-)
drivers/i2c/busses/i2c-designware-core.h +5 -0
@@ -212,6 +212,7 @@ struct reset_control;* @msg_err: error status of the current transfer * @status: i2c master status, one of STATUS_* * @abort_source: copy of the TX_ABRT_SOURCE register +* @sw_mask: SW mask of DW_IC_INTR_MASK used in polling mode * @irq: interrupt number for the i2c master * @flags: platform specific flags like type of IO accessors or model * @adapter: i2c subsystem adapter node
@@ -269,6 +270,7 @@ struct dw_i2c_dev {int msg_err;unsigned int status;unsigned int abort_source; +unsigned int sw_mask;int irq;u32 flags;struct i2c_adapter adapter;
@@ -359,6 +361,7 @@ static inline void __i2c_dw_write_intr_mask(struct dw_i2c_dev *dev,unsigned int val = dev->flags &ACCESS_POLLING ?0 : intr_mask;regmap_write (dev->map,DW_IC_INTR_MASK , val); + dev->sw_mask = intr_mask; } static inline void __i2c_dw_read_intr_mask(struct dw_i2c_dev *dev,
@@ -366,6 +369,8 @@ static inline void __i2c_dw_read_intr_mask(struct dw_i2c_dev *dev, {if (!(dev->flags &ACCESS_POLLING ))regmap_read (dev->map,DW_IC_INTR_MASK , intr_mask); +else + *intr_mask = dev->sw_mask; }void __i2c_dw_disable (struct dw_i2c_dev *dev);
drivers/i2c/busses/i2c-designware-master.c +72 -97
214 lines not on this page · raw message
Signature · 1 line
2.43.0
Andy Shevchenko
reviewerRe: [PATCH v2 9/9] i2c: designware: Implement generic polling mode code for Wangxun 10Gb NIC
Quoted 27 lines · Jarkko Nikula
I got an idea the i2c-designware should not need duplicated state machines for the interrupt and polling modes. The IP is practically the same and state transitions happens in response to the events that can be observed from the
DW_IC_RAW_INTR_STATregister. Either by interrupts or by polling.Another reasons are the interrupt mode is the most tested, has handling for special cases as well as transmit abort handling and those are missing from two polling mode quirks.
Patch implements a generic polling mode by using existing code for interrupt mode. This is done by moving event handling from the
i2c_dw_isr()into a newi2c_dw_process_transfer()that will be called both from thei2c_dw_isr()and a polling loop.Polling loop is implemented in a new
i2c_dw_wait_transfer()that is shared between both modes. In interrupt mode it waits for the completion object as before. In polling mode both completion object andDW_IC_RAW_INTR_STATare polled to determine completed transfer and state transitions.Loop tries to save power by sleeping "stetson guessed" range between 3 and 25 µS which falls between 10 cycles of High-speed mode 3.4 Mb/s and Fast mode 400 kHz. With it the CPU usage was reduced under heavy Fast mode I2C transfer without much increase in total transfer time but otherwise no more effort has been put to optimize this.
Quoted 4 lines
I decided to convert the
txgbe_i2c_dw_xfer_quirk()straight to generic polling mode code in this patch. It doesn't have HW dependent quirks like theamd_i2c_dw_xfer_quirk()does have and without users this patch is needless.
...
I believe even with a single point of out we may do better this one, see below.
drivers/i2c/busses/i2c-designware-master.c static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) · line 715
Quoted 6 lines
drivers/i2c/busses/i2c-designware-master.c +5
-0+static int i2c_dw_wait_transfer (struct dw_i2c_dev *dev) +{ +unsigned long timeout = dev->adapter.timeout; +unsigned int stat; +int ret =0 ;
int ret;
drivers/i2c/busses/i2c-designware-master.c static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) · line 719
Quoted 3 lines
drivers/i2c/busses/i2c-designware-master.c +3
-0+if (!(dev->flags &ACCESS_POLLING )) { + ret =wait_for_completion_timeout (&dev->cmd_complete, + timeout) ?0 : -ETIMEDOUT ;
ret = wait_for_completion_timeout(&dev->cmd_complete, timeout);
drivers/i2c/busses/i2c-designware-master.c static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) · line 724
Quoted 5 lines
drivers/i2c/busses/i2c-designware-master.c +5
-0+ }else { + timeout += jiffies; + do { + if (try_wait_for_completion(&dev->cmd_complete)) + goto out;
break;
drivers/i2c/busses/i2c-designware-master.c static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) · line 733
Quoted 9 lines
drivers/i2c/busses/i2c-designware-master.c +8
-0+ stat =i2c_dw_read_clear_intrbits (dev); +if (stat) +i2c_dw_process_transfer (dev, stat); +else +/* Try save some power */ +usleep_range (3 ,25 ); + }while (time_before (jiffies, timeout)); + ret =ETIMEDOUT ;
ret = time_before(jiffies, timeout);
drivers/i2c/busses/i2c-designware-master.c static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) · line 736
Quoted 3 lines
drivers/i2c/busses/i2c-designware-master.c +2
-0+ } +out:
if (ret) return 0; return -ETIMEDOUT;
drivers/i2c/busses/i2c-designware-master.c static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) · line 738
Quoted 2 lines
drivers/i2c/busses/i2c-designware-master.c +2
-0+return ret; +}
This will make same error code for both branches without need to synchronise, meaning better maintenance.
Signature · 2 lines
With Best Regards, Andy Shevchenko