i2c: designware: Use devm_platform_ioremap_resource() to simplify code
Subsystems (3)
Andy Shevchenko
reviewerPATCH v2 1/5 i2c: designware: Use devm_platform_ioremap_resource() to simplify code
Use devm_platform_ioremap_resource() instead of platform_get_resource() + devm_ioremap_resource().
---
v2: new patch
drivers/i2c/busses/i2c-designware-platdrv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +2 -6
@@ -157,12 +157,10 @@ static int mscc_twi_set_sda_hold_time(struct dw_i2c_dev *dev)static int dw_i2c_of_configure (struct platform_device *pdev) {struct dw_i2c_dev *dev =platform_get_drvdata (pdev); -struct resource *mem;switch (dev->flags &MODEL_MASK ) {case MODEL_MSCC_OCELOT : - mem =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); - dev->ext =devm_ioremap_resource (&pdev->dev, mem); + dev->ext =devm_platform_ioremap_resource (pdev,1 );if (!IS_ERR (dev->ext)) dev->set_sda_hold_time = mscc_twi_set_sda_hold_time;break ;
@@ -241,7 +239,6 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;struct i2c_timings *t;u32 acpi_speed; -struct resource *mem;int i, irq, ret; irq =platform_get_irq (pdev,0 );
@@ -252,8 +249,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)if (!dev)return -ENOMEM ; - mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - dev->base =devm_ioremap_resource (&pdev->dev, mem); + dev->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (dev->base))return PTR_ERR (dev->base);
Signature · 1 line
2.26.2
Andy Shevchenko
reviewerPATCH v2 2/5 i2c: designware: Move configuration routines to respective modules
Move configuration routines to respective modules, i.e. master and slave.
---
v2: no changes
drivers/i2c/busses/i2c-designware-core.h | 12 +++++++ drivers/i2c/busses/i2c-designware-master.c | 24 +++++++++++++ drivers/i2c/busses/i2c-designware-platdrv.c | 38 +-------------------- drivers/i2c/busses/i2c-designware-slave.c | 11 ++++++ 4 files changed, 48 insertions(+), 37 deletions(-)
drivers/i2c/busses/i2c-designware-core.h +12 -0
@@ -314,13 +314,25 @@ static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev)void __i2c_dw_disable (struct dw_i2c_dev *dev); +extern void i2c_dw_configure_master (struct dw_i2c_dev *dev);extern int i2c_dw_probe (struct dw_i2c_dev *dev); +#if IS_ENABLED (CONFIG_I2C_DESIGNWARE_SLAVE ) +extern void i2c_dw_configure_slave (struct dw_i2c_dev *dev);extern int i2c_dw_probe_slave (struct dw_i2c_dev *dev);#else +static inline void i2c_dw_configure_slave (struct dw_i2c_dev *dev) { }static inline int i2c_dw_probe_slave (struct dw_i2c_dev *dev) {return -EINVAL ; }#endif +static inline void i2c_dw_configure (struct dw_i2c_dev *dev) +{ +if (i2c_detect_slave_mode (dev->dev)) +i2c_dw_configure_slave (dev); +else +i2c_dw_configure_master (dev); +} +#if IS_ENABLED (CONFIG_I2C_DESIGNWARE_BAYTRAIL )extern int i2c_dw_probe_lock_support (struct dw_i2c_dev *dev);#else
drivers/i2c/busses/i2c-designware-master.c +24 -0
@@ -657,6 +657,30 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)return IRQ_HANDLED ; } +void i2c_dw_configure_master (struct dw_i2c_dev *dev) +{ +struct i2c_timings *t = &dev->timings; + + dev->functionality =I2C_FUNC_10BIT_ADDR |DW_IC_DEFAULT_FUNCTIONALITY ; + + dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | +DW_IC_CON_RESTART_EN ; + + dev->mode =DW_IC_MASTER ; + +switch (t->bus_freq_hz) { +case I2C_MAX_STANDARD_MODE_FREQ : + dev->master_cfg |=DW_IC_CON_SPEED_STD ; +break ; +case I2C_MAX_HIGH_SPEED_MODE_FREQ : + dev->master_cfg |=DW_IC_CON_SPEED_HIGH ; +break ; +default : + dev->master_cfg |=DW_IC_CON_SPEED_FAST ; + } +} +EXPORT_SYMBOL_GPL (i2c_dw_configure_master); +static void i2c_dw_prepare_recovery (struct i2c_adapter *adap) {struct dw_i2c_dev *dev =i2c_get_adapdata (adap);
drivers/i2c/busses/i2c-designware-platdrv.c +1 -37
@@ -184,39 +184,6 @@ static inline int dw_i2c_of_configure(struct platform_device *pdev) }#endif -static void i2c_dw_configure_master (struct dw_i2c_dev *dev) -{ -struct i2c_timings *t = &dev->timings; - - dev->functionality =I2C_FUNC_10BIT_ADDR |DW_IC_DEFAULT_FUNCTIONALITY ; - - dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN ; - - dev->mode =DW_IC_MASTER ; - -switch (t->bus_freq_hz) { -case I2C_MAX_STANDARD_MODE_FREQ : - dev->master_cfg |=DW_IC_CON_SPEED_STD ; -break ; -case I2C_MAX_HIGH_SPEED_MODE_FREQ : - dev->master_cfg |=DW_IC_CON_SPEED_HIGH ; -break ; -default : - dev->master_cfg |=DW_IC_CON_SPEED_FAST ; - } -} - -static void i2c_dw_configure_slave (struct dw_i2c_dev *dev) -{ - dev->functionality =I2C_FUNC_SLAVE |DW_IC_DEFAULT_FUNCTIONALITY ; - - dev->slave_cfg =DW_IC_CON_RX_FIFO_FULL_HLD_CTRL | -DW_IC_CON_RESTART_EN |DW_IC_CON_STOP_DET_IFADDRESSED ; - - dev->mode =DW_IC_SLAVE ; -} -static void dw_i2c_plat_pm_cleanup (struct dw_i2c_dev *dev) {pm_runtime_disable (dev->dev);
@@ -319,10 +286,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)if (ret) goto exit_reset; -if (i2c_detect_slave_mode (&pdev->dev)) -i2c_dw_configure_slave (dev); -else -i2c_dw_configure_master (dev); +i2c_dw_configure (dev);/* Optional interface clock */ dev->pclk =devm_clk_get_optional (&pdev->dev,"pclk" );
drivers/i2c/busses/i2c-designware-slave.c +11 -0
@@ -241,6 +241,17 @@ static const struct i2c_algorithm i2c_dw_algo = { .unreg_slave = i2c_dw_unreg_slave, }; +void i2c_dw_configure_slave (struct dw_i2c_dev *dev) +{ + dev->functionality =I2C_FUNC_SLAVE |DW_IC_DEFAULT_FUNCTIONALITY ; + + dev->slave_cfg =DW_IC_CON_RX_FIFO_FULL_HLD_CTRL | +DW_IC_CON_RESTART_EN |DW_IC_CON_STOP_DET_IFADDRESSED ; + + dev->mode =DW_IC_SLAVE ; +} +EXPORT_SYMBOL_GPL (i2c_dw_configure_slave); +int i2c_dw_probe_slave (struct dw_i2c_dev *dev) {struct i2c_adapter *adap = &dev->adapter;
Signature · 1 line
2.26.2
Andy Shevchenko
reviewerPATCH v2 5/5 i2c: designware: Allow slave mode for PCI enumerated devices
In reply to Andy ShevchenkoAllow slave mode for PCI enumerated devices by calling a common i2c_dw_probe() instead of i2c_dw_probe_master().
While dropping dependency to platform driver in slave module, move its configuration section above, closer to core.
---
v2: new patch
drivers/i2c/busses/Kconfig | 21 ++++++++++----------- drivers/i2c/busses/i2c-designware-pcidrv.c | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-)
drivers/i2c/busses/Kconfig +10 -11
@@ -527,6 +527,16 @@ config I2C_DAVINCI config I2C_DESIGNWARE_CORE tristate +config I2C_DESIGNWARE_SLAVE + bool "Synopsys DesignWare Slave" + select I2C_SLAVE + help + If you say yes to this option, support will be included for the + Synopsys DesignWare I2C slave adapter. + + This is not a standalone module, this module compiles together with + i2c-designware-core. + config I2C_DESIGNWARE_PLATFORM tristate "Synopsys DesignWare Platform" select I2C_DESIGNWARE_CORE
@@ -538,17 +548,6 @@ config I2C_DESIGNWARE_PLATFORM This driver can also be built as a module. If so, the module will be called i2c-designware-platform. -config I2C_DESIGNWARE_SLAVE - bool "Synopsys DesignWare Slave" - select I2C_SLAVE - depends on I2C_DESIGNWARE_PLATFORM - help - If you say yes to this option, support will be included for the - Synopsys DesignWare I2C slave adapter. - - This is not a standalone module, this module compiles together with - i2c-designware-core. - config I2C_DESIGNWARE_PCI tristate "Synopsys DesignWare PCI" depends on PCI
drivers/i2c/busses/i2c-designware-pcidrv.c +2 -2
@@ -251,7 +251,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev, } } -i2c_dw_configure_master (dev); +i2c_dw_configure (dev);if (controller->scl_sda_cfg) { cfg = controller->scl_sda_cfg;
@@ -271,7 +271,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,ACPI_COMPANION_SET (&adap->dev,ACPI_COMPANION (&pdev->dev)); adap->nr = controller->bus_num; - r =i2c_dw_probe_master (dev); + r =i2c_dw_probe (dev);if (r) {pci_free_irq_vectors (pdev);return r;
Signature · 1 line
2.26.2
Andy Shevchenko
reviewerPATCH v2 4/5 i2c: designware: Rename i2c_dw_probe() to i2c_dw_probe_master()
In reply to Andy ShevchenkoAs a preparatory patch to support slave mode for PCI enumerated devices rename i2c_dw_probe() to i2c_dw_probe_master() and split common i2c_dw_probe() as inline helper.
---
v2: drop MASTER module optional choice (Jarkko, Wolfram)
drivers/i2c/busses/Makefile | 3 ++- drivers/i2c/busses/i2c-designware-core.h | 15 ++++++++++++++- drivers/i2c/busses/i2c-designware-master.c | 4 ++-- drivers/i2c/busses/i2c-designware-pcidrv.c | 2 +- drivers/i2c/busses/i2c-designware-platdrv.c | 6 +----- 5 files changed, 20 insertions(+), 10 deletions(-)
drivers/i2c/busses/Makefile +2 -1
@@ -49,7 +49,8 @@ obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o obj-$(CONFIG_I2C_CPM) += i2c-cpm.o obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o obj-$(CONFIG_I2C_DESIGNWARE_CORE) += i2c-designware-core.o -i2c-designware-core-objs := i2c-designware-common.o i2c-designware-master.o +i2c-designware-core-objs := i2c-designware-common.o +i2c-designware-core-objs += i2c-designware-master.o ifeq ($(CONFIG_I2C_DESIGNWARE_SLAVE),y) i2c-designware-core-objs += i2c-designware-slave.o endif
drivers/i2c/busses/i2c-designware-core.h +14 -1
@@ -315,7 +315,7 @@ static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev)void __i2c_dw_disable (struct dw_i2c_dev *dev);extern void i2c_dw_configure_master (struct dw_i2c_dev *dev); -extern int i2c_dw_probe (struct dw_i2c_dev *dev); +extern int i2c_dw_probe_master (struct dw_i2c_dev *dev);#if IS_ENABLED (CONFIG_I2C_DESIGNWARE_SLAVE )extern void i2c_dw_configure_slave (struct dw_i2c_dev *dev);
@@ -325,6 +325,19 @@ static inline void i2c_dw_configure_slave(struct dw_i2c_dev *dev) { }static inline int i2c_dw_probe_slave (struct dw_i2c_dev *dev) {return -EINVAL ; }#endif +static inline int i2c_dw_probe (struct dw_i2c_dev *dev) +{ +switch (dev->mode) { +case DW_IC_SLAVE : +return i2c_dw_probe_slave (dev); +case DW_IC_MASTER : +return i2c_dw_probe_master (dev); +default : +dev_err (dev->dev,"Wrong operation mode: %d\n" , dev->mode); +return -EINVAL ; + } +} +static inline void i2c_dw_configure (struct dw_i2c_dev *dev) {if (i2c_detect_slave_mode (dev->dev))
drivers/i2c/busses/i2c-designware-master.c +2 -2
@@ -727,7 +727,7 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)return 0 ; } -int i2c_dw_probe (struct dw_i2c_dev *dev) +int i2c_dw_probe_master (struct dw_i2c_dev *dev) {struct i2c_adapter *adap = &dev->adapter;unsigned long irq_flags;
@@ -794,7 +794,7 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)return ret; } -EXPORT_SYMBOL_GPL (i2c_dw_probe); +EXPORT_SYMBOL_GPL (i2c_dw_probe_master);MODULE_DESCRIPTION ("Synopsys DesignWare I2C bus master adapter" );MODULE_LICENSE ("GPL" );
drivers/i2c/busses/i2c-designware-pcidrv.c +1 -1
@@ -271,7 +271,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,ACPI_COMPANION_SET (&adap->dev,ACPI_COMPANION (&pdev->dev)); adap->nr = controller->bus_num; - r =i2c_dw_probe (dev); + r =i2c_dw_probe_master (dev);if (r) {pci_free_irq_vectors (pdev);return r;
drivers/i2c/busses/i2c-designware-platdrv.c +1 -5
@@ -337,11 +337,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)pm_runtime_enable (&pdev->dev); -if (dev->mode ==DW_IC_SLAVE ) - ret =i2c_dw_probe_slave (dev); -else - ret =i2c_dw_probe (dev); - + ret =i2c_dw_probe (dev);if (ret) goto exit_probe;
Signature · 1 line
2.26.2
Andy Shevchenko
reviewerPATCH v2 3/5 i2c: designware: Switch PCI driver to use i2c_dw_configure_master()
In reply to Andy ShevchenkoSince we have available helper to configure master mode, let's use it in the PCI driver instead of spread open-coded variant.
---
v2: new patch
drivers/i2c/busses/i2c-designware-pcidrv.c | 33 +++++----------------- 1 file changed, 7 insertions(+), 26 deletions(-)
drivers/i2c/busses/i2c-designware-pcidrv.c +7 -26
@@ -46,20 +46,14 @@ struct dw_scl_sda_cfg {struct dw_pci_controller {u32 bus_num; -u32 bus_cfg;u32 tx_fifo_depth;u32 rx_fifo_depth;u32 clk_khz; -u32 functionality;u32 flags;struct dw_scl_sda_cfg *scl_sda_cfg;int (*setup)(struct pci_dev *pdev,struct dw_pci_controller *c); }; -#define INTEL_MID_STD_CFG (DW_IC_CON_MASTER | \ - DW_IC_CON_SLAVE_DISABLE | \ - DW_IC_CON_RESTART_EN) -/* Merrifield HCNT/LCNT/SDA hold time */ static struct dw_scl_sda_cfg mrfld_config = { .ss_hcnt =0x2f8 ,
@@ -88,10 +82,11 @@ static struct dw_scl_sda_cfg hsw_config = {static int mfld_setup (struct pci_dev *pdev,struct dw_pci_controller *c) { +struct dw_i2c_dev *dev =dev_get_drvdata (&pdev->dev); +switch (pdev->device) {case 0x0817 : - c->bus_cfg &= ~DW_IC_CON_SPEED_MASK ; - c->bus_cfg |=DW_IC_CON_SPEED_STD ; + dev->timings.bus_freq_hz =I2C_MAX_STANDARD_MODE_FREQ ;/* fall through */ case 0x0818 :case 0x0819 :
@@ -128,53 +123,41 @@ static int mrfld_setup(struct pci_dev *pdev, struct dw_pci_controller *c)static struct dw_pci_controller dw_pci_controllers[] = { [medfield] = { .bus_num =-1 , - .bus_cfg =INTEL_MID_STD_CFG |DW_IC_CON_SPEED_FAST , .tx_fifo_depth =32 , .rx_fifo_depth =32 , - .functionality =I2C_FUNC_10BIT_ADDR , .clk_khz =25000 , .setup = mfld_setup, }, [merrifield] = { .bus_num =-1 , - .bus_cfg =INTEL_MID_STD_CFG |DW_IC_CON_SPEED_FAST , .tx_fifo_depth =64 , .rx_fifo_depth =64 , - .functionality =I2C_FUNC_10BIT_ADDR , .scl_sda_cfg = &mrfld_config, .setup = mrfld_setup, }, [baytrail] = { .bus_num =-1 , - .bus_cfg =INTEL_MID_STD_CFG |DW_IC_CON_SPEED_FAST , .tx_fifo_depth =32 , .rx_fifo_depth =32 , - .functionality =I2C_FUNC_10BIT_ADDR , .scl_sda_cfg = &byt_config, }, [haswell] = { .bus_num =-1 , - .bus_cfg =INTEL_MID_STD_CFG |DW_IC_CON_SPEED_FAST , .tx_fifo_depth =32 , .rx_fifo_depth =32 , - .functionality =I2C_FUNC_10BIT_ADDR , .scl_sda_cfg = &hsw_config, }, [cherrytrail] = { .bus_num =-1 , - .bus_cfg =INTEL_MID_STD_CFG |DW_IC_CON_SPEED_FAST , .tx_fifo_depth =32 , .rx_fifo_depth =32 , - .functionality =I2C_FUNC_10BIT_ADDR , .flags =MODEL_CHERRYTRAIL , .scl_sda_cfg = &byt_config, }, [elkhartlake] = { .bus_num =-1 , - .bus_cfg =INTEL_MID_STD_CFG |DW_IC_CON_SPEED_FAST , .tx_fifo_depth =32 , .rx_fifo_depth =32 , - .functionality =I2C_FUNC_10BIT_ADDR , .clk_khz =100000 , }, };
@@ -250,14 +233,16 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,if (r <0 )return r; - dev->clk =NULL ; dev->controller = controller; dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; + dev->timings.bus_freq_hz =I2C_MAX_FAST_MODE_FREQ ; dev->base =pcim_iomap_table (pdev)[0 ]; dev->dev = &pdev->dev; dev->irq =pci_irq_vector (pdev,0 ); dev->flags |= controller->flags; +pci_set_drvdata (pdev, dev); +if (controller->setup) { r = controller->setup (pdev, controller);if (r) {
@@ -266,10 +251,8 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev, } } - dev->functionality = controller->functionality | -DW_IC_DEFAULT_FUNCTIONALITY ; +i2c_dw_configure_master (dev); - dev->master_cfg = controller->bus_cfg;if (controller->scl_sda_cfg) { cfg = controller->scl_sda_cfg; dev->ss_hcnt = cfg->ss_hcnt;
@@ -279,8 +262,6 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev, dev->sda_hold_time = cfg->sda_hold; } -pci_set_drvdata (pdev, dev); - dev->tx_fifo_depth = controller->tx_fifo_depth; dev->rx_fifo_depth = controller->rx_fifo_depth;
Signature · 1 line
2.26.2
Re: [PATCH v2 5/5] i2c: designware: Allow slave mode for PCI enumerated devices
In reply to Andy ShevchenkoQuoted 6 lines · Andy Shevchenko
Allow slave mode for PCI enumerated devices by calling a common
i2c_dw_probe()instead ofi2c_dw_probe_master().While dropping dependency to platform driver in slave module, move its configuration section above, closer to core.
Quoted 7 lines
Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchdrivers/i2c/busses/Kconfig | 21 ++++++++++----------- drivers/i2c/busses/i2c-designware-pcidrv.c | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-)
To all 5 patches
Re: [PATCH v2 5/5] i2c: designware: Allow slave mode for PCI enumerated devices
Quoted 14 lines · Jarkko Nikula
Quoted 6 lines · Andy Shevchenko
Allow slave mode for PCI enumerated devices by calling a common
i2c_dw_probe()instead ofi2c_dw_probe_master().While dropping dependency to platform driver in slave module, move its configuration section above, closer to core.
Quoted 7 lines
Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchdrivers/i2c/busses/Kconfig | 21 ++++++++++----------- drivers/i2c/busses/i2c-designware-pcidrv.c | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-)
Quoted 3 lines
To all 5 patches
Acked-by Jarkko Nikula <[email protected]>
And all applied to for-next, thanks!
Andy Shevchenko
reviewerRe: [PATCH v2 5/5] i2c: designware: Allow slave mode for PCI enumerated devices
Quoted 15 lines · Wolfram Sang
Quoted 14 lines · Jarkko Nikula
Quoted 13 lines · Andy Shevchenko
Allow slave mode for PCI enumerated devices by calling a common
i2c_dw_probe()instead ofi2c_dw_probe_master().While dropping dependency to platform driver in slave module, move its configuration section above, closer to core.
Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchdrivers/i2c/busses/Kconfig | 21 ++++++++++----------- drivers/i2c/busses/i2c-designware-pcidrv.c | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-)
Quoted 5 lines
Quoted 3 lines
To all 5 patches
Acked-by Jarkko Nikula <[email protected]>And all applied to for-next, thanks!
Wolfram, I do not see them in your tree. Neither Linux next has them. Something should I do?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 5/5] i2c: designware: Allow slave mode for PCI enumerated devices
Quoted 5 lines
Quoted 2 lines
And all applied to for-next, thanks!
Wolfram, I do not see them in your tree. Neither Linux next has them. Something should I do?
Sorry, Andy. I lost them when I was not correctly syncing from my secondary machine. Pushed them out now.