i2c: designware: Do not complete i2c read without RX_FULL interrupt
Subsystems (3)
PATCH 1/6 i2c: designware: Do not complete i2c read without RX_FULL interrupt
From: Tamal Saha <[email protected]>
Intel Keem Bay platform supports multi-master operations over same i2c bus using Synopsys i2c DesignWare IP. When multi-masters initiate i2c operation simultaneously in a loop, SCL line is stucked low forever after few i2c operations. Following interrupt sequences are observed in:
working case: TX_EMPTY, RX_FULL and STOP_DET
non working case: TX_EMPTY, STOP_DET, RX_FULL.
DW_apb_i2c stretches the SCL line when the TX FIFO is empty or when RX FIFO is full. The DW_apb_i2c master will continue to hold the SCL line LOW until RX FIFO is read.
Linux kernel i2c DesignWare driver does not handle above non working sequence. TX_EMPTY, RX_FULL and STOP_DET routine execution are required in sequence although RX_FULL interrupt is raised after STOP_DET by hardware. Clear STOP_DET for the following conditions:
(STOP_DET ,RX_FULL, rx_outstanding)
Write Operation: (1, 0, 0)
Read Operation:
RX_FULL followed by STOP_DET: (0, 1, 1) -> (1, 0, 0)
STOP_DET followed by RX_FULL: (1, 0, 1) -> (1, 1, 0)
RX_FULL and STOP_DET together: (1, 1, 1)--- drivers/i2c/busses/i2c-designware-master.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-master.c +5 -2
@@ -701,7 +701,8 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)regmap_read (dev->map,DW_IC_CLR_RX_DONE , &dummy);if (stat &DW_IC_INTR_ACTIVITY )regmap_read (dev->map,DW_IC_CLR_ACTIVITY , &dummy); -if (stat &DW_IC_INTR_STOP_DET ) +if ((stat &DW_IC_INTR_STOP_DET ) && + ((dev->rx_outstanding ==0 ) || (stat &DW_IC_INTR_RX_FULL )))regmap_read (dev->map,DW_IC_CLR_STOP_DET , &dummy);if (stat &DW_IC_INTR_START_DET )regmap_read (dev->map,DW_IC_CLR_START_DET , &dummy);
@@ -723,6 +724,7 @@ static int i2c_dw_irq_handler_master(struct dw_i2c_dev *dev)if (stat &DW_IC_INTR_TX_ABRT ) { dev->cmd_err |=DW_IC_ERR_TX_ABRT ; dev->status =STATUS_IDLE ; + dev->rx_outstanding =0 ;/* * Anytime TX_ABRT is set, the contents of the tx/rx
@@ -745,7 +747,8 @@ static int i2c_dw_irq_handler_master(struct dw_i2c_dev *dev)*/ tx_aborted: -if ((stat & (DW_IC_INTR_TX_ABRT |DW_IC_INTR_STOP_DET )) || dev->msg_err) +if (((stat & (DW_IC_INTR_TX_ABRT |DW_IC_INTR_STOP_DET )) || dev->msg_err) && + (dev->rx_outstanding ==0 ))complete (&dev->cmd_complete);else if (unlikely (dev->flags &ACCESS_INTR_MASK )) {/* Workaround to trigger pending interrupt */
Signature · 1 line
2.34.1
PATCH 2/6 i2c: designware-pci: Fix to change data types of hcnt and lcnt parameters
From: Lakshmi Sowjanya D <[email protected]>
The data type of hcnt and lcnt in the struct dw_i2c_dev is of type u16. It's better to have same data type in struct dw_scl_sda_cfg as well.
--- drivers/i2c/busses/i2c-designware-pcidrv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +4 -4
@@ -39,10 +39,10 @@ enum dw_pci_ctl_id_t { };struct dw_scl_sda_cfg { -u32 ss_hcnt; -u32 fs_hcnt; -u32 ss_lcnt; -u32 fs_lcnt; +u16 ss_hcnt; +u16 fs_hcnt; +u16 ss_lcnt; +u16 fs_lcnt;u32 sda_hold; };
Signature · 1 line
2.34.1
Re: [PATCH 2/6] i2c: designware-pci: Fix to change data types of hcnt and lcnt parameters
Quoted 8 lines · Jarkko Nikula
From: Lakshmi Sowjanya D <[email protected]>
The data type of hcnt and lcnt in the struct
dw_i2c_devis of type u16. It's better to have same data type in structdw_scl_sda_cfgas well.Signed-off-by Lakshmi Sowjanya D <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Signed-off-by Jarkko Nikula <[email protected]>
Added my Reported-by and applied to for-next, thanks!
PATCH 3/6 i2c: designware-pci: Add a note about struct dw_scl_sda_cfg usage
In reply to Jarkko NikulaFrom: Andy Shevchenko <[email protected]>
Add a note about struct dw_scl_sda_cfg usage to discourage people of using this structure on new platforms. Instead they should try hard to put the needed information into firmware descriptions.
--- drivers/i2c/busses/i2c-designware-pcidrv.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/i2c/busses/i2c-designware-pcidrv.c +7 -0
@@ -38,6 +38,13 @@ enum dw_pci_ctl_id_t { navi_amd, }; +/* +* This is a legacy structure to describe the hardware counters +* to configure signal timings on the bus. For Device Tree platforms +* one should use the respective properties and for ACPI there is +* a set of ACPI methods that provide these counters. No new +* platform should use this structure. +*/ struct dw_scl_sda_cfg {u16 ss_hcnt;u16 fs_hcnt;
Signature · 1 line
2.34.1
Wolfram Sang
AppliedRe: [PATCH 3/6] i2c: designware-pci: Add a note about struct dw_scl_sda_cfg usage
Quoted 8 lines · Jarkko Nikula
From: Andy Shevchenko <[email protected]>
Add a note about struct
dw_scl_sda_cfgusage to discourage people of using this structure on new platforms. Instead they should try hard to put the needed information into firmware descriptions.Signed-off-by Andy Shevchenko <[email protected]>Signed-off-by Jarkko Nikula <[email protected]>
Applied to for-next, thanks!
PATCH 4/6 i2c: designware-pci: Group MODULE_*() macros
In reply to Jarkko NikulaFrom: Andy Shevchenko <[email protected]>
For better maintenance group MODULE_*() macros together.
--- drivers/i2c/busses/i2c-designware-pcidrv.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +3 -4
@@ -359,9 +359,6 @@ static void i2c_dw_pci_remove(struct pci_dev *pdev)pci_free_irq_vectors (pdev); } -/* work with hotplug and coldplug */ -MODULE_ALIAS ("i2c_designware-pci" ); -static const struct pci_device_id i2_designware_pci_ids[] = {/* Medfield */ {PCI_VDEVICE (INTEL ,0x0817 ), medfield },
@@ -418,9 +415,11 @@ static struct pci_driver dw_i2c_driver = { .pm = &i2c_dw_pm_ops, }, }; -module_pci_driver (dw_i2c_driver); +/* Work with hotplug and coldplug */ +MODULE_ALIAS ("i2c_designware-pci" ); +MODULE_AUTHOR ("Baruch Siach <[email protected]>" );MODULE_DESCRIPTION ("Synopsys DesignWare PCI I2C bus adapter" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.34.1
Re: [PATCH 4/6] i2c: designware-pci: Group MODULE_*() macros
Quoted 7 lines · Jarkko Nikula
From: Andy Shevchenko <[email protected]>
For better maintenance group MODULE_*() macros together.
Signed-off-by Andy Shevchenko <[email protected]>Signed-off-by Jarkko Nikula <[email protected]>---
Removed an empty line and applied to for-next, thanks!
drivers/i2c/busses/i2c-designware-pcidrv.c static struct pci_driver dw_i2c_driver = { · line 422
Quoted 2 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +2
-0+MODULE_ALIAS ("i2c_designware-pci" ); +
This one.
Quoted 1 line
MODULE_AUTHOR("Baruch Siach <[email protected]>");
Andy Shevchenko
reviewerRe: [PATCH 4/6] i2c: designware-pci: Group MODULE_*() macros
Quoted 6 lines · Wolfram Sang
Quoted 3 lines · Jarkko Nikula
From: Andy Shevchenko <[email protected]>
For better maintenance group MODULE_*() macros together.
Removed an empty line and applied to for-next, thanks!
Agree on the change and thanks!
Quoted 6 lines
drivers/i2c/busses/i2c-designware-pcidrv.c static struct pci_driver dw_i2c_driver = { · line 422
Quoted 2 lines
drivers/i2c/busses/i2c-designware-pcidrv.c +2
-0+MODULE_ALIAS ("i2c_designware-pci" ); +This one.
Quoted 1 line
MODULE_AUTHOR("Baruch Siach <[email protected]>");
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 5/6 i2c: designware-pci: use __maybe_unused for PM functions
In reply to Jarkko NikulaFrom: Andy Shevchenko <[email protected]>
Use __maybe_unused for PM functions instead of ifdeffery.
---
Jarkko: In my opinion this was worth to take before cleanups so hand edited to apply to currect code.
--- drivers/i2c/busses/i2c-designware-pcidrv.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +2 -4
@@ -213,8 +213,7 @@ static struct dw_pci_controller dw_pci_controllers[] = { }, }; -#ifdef CONFIG_PM -static int i2c_dw_pci_suspend (struct device *dev) +static int __maybe_unused i2c_dw_pci_suspend (struct device *dev) {struct dw_i2c_dev *i_dev =dev_get_drvdata (dev);
@@ -224,7 +223,7 @@ static int i2c_dw_pci_suspend(struct device *dev)return 0 ; } -static int i2c_dw_pci_resume (struct device *dev) +static int __maybe_unused i2c_dw_pci_resume (struct device *dev) {struct dw_i2c_dev *i_dev =dev_get_drvdata (dev);int ret;
@@ -234,7 +233,6 @@ static int i2c_dw_pci_resume(struct device *dev)return ret; } -#endif static UNIVERSAL_DEV_PM_OPS(i2c_dw_pm_ops, i2c_dw_pci_suspend, i2c_dw_pci_resume, NULL);
Signature · 1 line
2.34.1
Wolfram Sang
AppliedRe: [PATCH 5/6] i2c: designware-pci: use __maybe_unused for PM functions
Quoted 6 lines · Jarkko Nikula
From: Andy Shevchenko <[email protected]>
Use
__maybe_unusedfor PM functions instead of ifdeffery.Signed-off-by Andy Shevchenko <[email protected]>Signed-off-by Jarkko Nikula <[email protected]>
Applied to for-next, thanks!
PATCH 6/6 i2c: designware-pci: Convert to use dev_err_probe()
In reply to Jarkko NikulaFrom: Andy Shevchenko <[email protected]>
It's fine to call dev_err_probe() in ->probe() when error code is known. Convert the driver to use dev_err_probe().
---
Jarkko: In my opinion this was worth to take before cleanups so hand edited to apply to current code. I split the dev_err_probe() lines to have device pointer and error code in the first line and printable string in the next for shorter lines.
While at it, change "invalid" -> "Invalid" (was before Andy's change).
--- drivers/i2c/busses/i2c-designware-pcidrv.c | 24 +++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +10 -14
@@ -246,28 +246,24 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,struct dw_pci_controller *controller;struct dw_scl_sda_cfg *cfg; -if (id->driver_data >=ARRAY_SIZE (dw_pci_controllers)) { -dev_err (&pdev->dev,"%s: invalid driver data %ld\n" , __func__, - id->driver_data); -return -EINVAL ; - } +if (id->driver_data >=ARRAY_SIZE (dw_pci_controllers)) +return dev_err_probe (&pdev->dev, -EINVAL , +"Invalid driver data %ld\n" , + id->driver_data); controller = &dw_pci_controllers[id->driver_data]; r =pcim_enable_device (pdev); -if (r) { -dev_err (&pdev->dev,"Failed to enable I2C PCI device (%d)\n" , - r); -return r; - } +if (r) +return dev_err_probe (&pdev->dev, r, +"Failed to enable I2C PCI device\n" );pci_set_master (pdev); r =pcim_iomap_regions (pdev,1 <<0 ,pci_name (pdev)); -if (r) { -dev_err (&pdev->dev,"I/O memory remapping failed\n" ); -return r; - } +if (r) +return dev_err_probe (&pdev->dev, r, +"I/O memory remapping failed\n" ); dev =devm_kzalloc (&pdev->dev,sizeof (struct dw_i2c_dev ),GFP_KERNEL );if (!dev)
Signature · 1 line
2.34.1
Wolfram Sang
AppliedRe: [PATCH 6/6] i2c: designware-pci: Convert to use dev_err_probe()
Quoted 7 lines · Jarkko Nikula
From: Andy Shevchenko <[email protected]>
It's fine to call
dev_err_probe()in ->probe() when error code is known. Convert the driver to usedev_err_probe().Signed-off-by Andy Shevchenko <[email protected]>Signed-off-by Jarkko Nikula <[email protected]>
Applied to for-next, thanks!
Wolfram Sang
AppliedQuoted 19 lines · Jarkko Nikula
From: Tamal Saha <[email protected]>
Intel Keem Bay platform supports multi-master operations over same i2c bus using Synopsys i2c DesignWare IP. When multi-masters initiate i2c operation simultaneously in a loop, SCL line is stucked low forever after few i2c operations. Following interrupt sequences are observed in:
working case:TX_EMPTY,RX_FULLandSTOP_DET
non working case:TX_EMPTY,STOP_DET,RX_FULL.
DW_apb_i2cstretches the SCL line when the TX FIFO is empty or when RX FIFO is full. TheDW_apb_i2cmaster will continue to hold the SCL line LOW until RX FIFO is read.Linux kernel i2c DesignWare driver does not handle above non working sequence.
TX_EMPTY,RX_FULLandSTOP_DETroutine execution are required in sequence althoughRX_FULLinterrupt is raised afterSTOP_DETby hardware. ClearSTOP_DETfor the following conditions:
(STOP_DET,RX_FULL,rx_outstanding)
Quoted 8 lines
Write Operation: (1, 0, 0) Read Operation: RX_FULL followed by STOP_DET: (0, 1, 1) -> (1, 0, 0) STOP_DET followed by RX_FULL: (1, 0, 1) -> (1, 1, 0) RX_FULL and STOP_DET together: (1, 1, 1)Signed-off-by Tamal Saha <[email protected]>Signed-off-by Jarkko Nikula <[email protected]>
Applied to for-next, thanks!