i2c: viai2c: turn common code into a proper module
PATCH 1/1 i2c: viai2c: turn common code into a proper module
From: Arnd Bergmann <[email protected]>
The i2c-viai2c-common.c file is used by two drivers, but is not a proper abstraction and can get linked into both modules in the same configuration, which results in a warning:
scripts/Makefile.build:236: drivers/i2c/busses/Makefile: i2c-viai2c-common.o is added to multiple modules: i2c-wmt i2c-zhaoxin
The other problems with this include the incorrect use of a __weak function when both are built-in, and the fact that the "common" module is sprinked with 'if (i2c->plat == ...)' checks that have knowledge about the differences between the drivers using it.
Avoid the link time warning by making the common driver a proper module with MODULE_LICENCE()/MODULE_AUTHOR() tags, and remove the __weak function by slightly rearranging the code.
This adds a little more duplication between the two main drivers, but those versions get more readable in the process.
--- drivers/i2c/busses/Makefile | 6 +- drivers/i2c/busses/i2c-viai2c-common.c | 71 ++------------- drivers/i2c/busses/i2c-viai2c-common.h | 2 +- drivers/i2c/busses/i2c-viai2c-wmt.c | 37 ++++++++ drivers/i2c/busses/i2c-viai2c-zhaoxin.c | 113 +++++++++++++++++++----- 5 files changed, 140 insertions(+), 89 deletions(-)
drivers/i2c/busses/Makefile +2 -4
@@ -29,8 +29,7 @@ obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o obj-$(CONFIG_I2C_VIA) += i2c-via.o obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o -i2c-zhaoxin-objs := i2c-viai2c-zhaoxin.o i2c-viai2c-common.o -obj-$(CONFIG_I2C_ZHAOXIN) += i2c-zhaoxin.o +obj-$(CONFIG_I2C_ZHAOXIN) += i2c-viai2c-zhaoxin.o i2c-viai2c-common.o # Mac SMBus host controller drivers obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o
@@ -120,8 +119,7 @@ obj-$(CONFIG_I2C_TEGRA_BPMP) += i2c-tegra-bpmp.o obj-$(CONFIG_I2C_UNIPHIER) += i2c-uniphier.o obj-$(CONFIG_I2C_UNIPHIER_F) += i2c-uniphier-f.o obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o -i2c-wmt-objs := i2c-viai2c-wmt.o i2c-viai2c-common.o -obj-$(CONFIG_I2C_WMT) += i2c-wmt.o +obj-$(CONFIG_I2C_WMT) += i2c-viai2c-wmt.o i2c-viai2c-common.o i2c-octeon-objs := i2c-octeon-core.o i2c-octeon-platdrv.o obj-$(CONFIG_I2C_OCTEON) += i2c-octeon.o i2c-thunderx-objs := i2c-octeon-core.o i2c-thunderx-pcidrv.o
drivers/i2c/busses/i2c-viai2c-common.c +9 -62
110 lines not on this page · raw message
drivers/i2c/busses/i2c-viai2c-common.h +1 -1
@@ -80,6 +80,6 @@ struct viai2c {int viai2c_wait_bus_not_busy (struct viai2c *i2c);int viai2c_xfer (struct i2c_adapter *adap,struct i2c_msg msgs[],int num);int viai2c_init (struct platform_device *pdev,struct viai2c **pi2c,int plat); -int viai2c_fifo_irq_xfer (struct viai2c *i2c,bool irq); +int viai2c_irq_xfer (struct viai2c *i2c);#endif
drivers/i2c/busses/i2c-viai2c-wmt.c +37 -0
@@ -72,6 +72,33 @@ static int wmt_i2c_reset_hardware(struct viai2c *i2c)return 0 ; } +static irqreturn_t wmt_i2c_isr (int irq,void *data) +{ +struct viai2c *i2c = data; +u8 status; + +/* save the status and write-clear it */ + status =readw (i2c->base +VIAI2C_REG_ISR ); +writew (status, i2c->base +VIAI2C_REG_ISR ); + + i2c->ret =0 ; +if (status &VIAI2C_ISR_NACK_ADDR ) + i2c->ret = -EIO ; + +if (status &VIAI2C_ISR_SCL_TIMEOUT ) + i2c->ret = -ETIMEDOUT ; + +if (!i2c->ret) + i2c->ret =viai2c_irq_xfer (i2c); + +/* All the data has been successfully transferred or error occurred */ +if (i2c->ret) +complete (&i2c->complete); + +return IRQ_HANDLED ; +} + +static int wmt_i2c_probe (struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node;
@@ -84,6 +111,16 @@ static int wmt_i2c_probe(struct platform_device *pdev)if (err)return err; + i2c->irq =platform_get_irq (pdev,0 ); +if (i2c->irq <0 ) +return i2c->irq; + + err =devm_request_irq (&pdev->dev, i2c->irq, wmt_i2c_isr, +0 , pdev->name, i2c); +if (err) +return dev_err_probe (&pdev->dev, err, +"failed to request irq %i\n" , i2c->irq); + i2c->clk =of_clk_get (np,0 );if (IS_ERR (i2c->clk)) {dev_err (&pdev->dev,"unable to request clock\n" );
drivers/i2c/busses/i2c-viai2c-zhaoxin.c +91 -22
153 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH 1/1 i2c: viai2c: turn common code into a proper module
In reply to a message not in the archiveHi Arnd,
Quoted 14 lines
From: Arnd Bergmann <[email protected]>
The
i2c-viai2c-common.cfile is used by two drivers, but is not a proper abstraction and can get linked into both modules in the same configuration, which results in a warning:
scripts/Makefile.build:236:drivers/i2c/busses/Makefile: i2c-viai2c-common.o is added to multiple modules: i2c-wmt i2c-zhaoxinThe other problems with this include the incorrect use of a
__weakfunction when both are built-in, and the fact that the "common" module is sprinked with 'if (i2c->plat== ...)' checks that have knowledge about the differences between the drivers using it.Avoid the link time warning by making the common driver a proper module with MODULE_LICENCE()/MODULE_AUTHOR() tags, and remove the
__weakfunction by slightly rearranging the code.This adds a little more duplication between the two main drivers, but those versions get more readable in the process.
Fixes a06b80e83011 ("i2c: add zhaoxin i2c controller driver")Signed-off-by Arnd Bergmann <[email protected]>
Quoted 7 lines
--- drivers/i2c/busses/Makefile | 6 +- drivers/i2c/busses/i2c-viai2c-common.c | 71 ++------------- drivers/i2c/busses/i2c-viai2c-common.h | 2 +- drivers/i2c/busses/i2c-viai2c-wmt.c | 37 ++++++++ drivers/i2c/busses/i2c-viai2c-zhaoxin.c | 113 +++++++++++++++++++----- 5 files changed, 140 insertions(+), 89 deletions(-)
I tested this patch and it works fine, so I am OK with it.
Hans
Quoted 17 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The
i2c-viai2c-common.cfile is used by two drivers, but is not a proper abstraction and can get linked into both modules in the same configuration, which results in a warning:
scripts/Makefile.build:236:drivers/i2c/busses/Makefile: i2c-viai2c-common.o is added to multiple modules: i2c-wmt i2c-zhaoxinThe other problems with this include the incorrect use of a
__weakfunction when both are built-in, and the fact that the "common" module is sprinked with 'if (i2c->plat== ...)' checks that have knowledge about the differences between the drivers using it.Avoid the link time warning by making the common driver a proper module with MODULE_LICENCE()/MODULE_AUTHOR() tags, and remove the
__weakfunction by slightly rearranging the code.
Quoted 5 lines
This adds a little more duplication between the two main drivers, but those versions get more readable in the process.
Fixes a06b80e83011 ("i2c: add zhaoxin i2c controller driver")Signed-off-by Arnd Bergmann <[email protected]>
Andi, I am tempted to include this in my for-current pull request this week. Are you okay with this or do you want to review it more closely?
Quoted 18 lines · Wolfram Sang
Quoted 17 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The
i2c-viai2c-common.cfile is used by two drivers, but is not a proper abstraction and can get linked into both modules in the same configuration, which results in a warning:
scripts/Makefile.build:236:drivers/i2c/busses/Makefile: i2c-viai2c-common.o is added to multiple modules: i2c-wmt i2c-zhaoxinThe other problems with this include the incorrect use of a
__weakfunction when both are built-in, and the fact that the "common" module is sprinked with 'if (i2c->plat== ...)' checks that have knowledge about the differences between the drivers using it.Avoid the link time warning by making the common driver a proper module with MODULE_LICENCE()/MODULE_AUTHOR() tags, and remove the
__weakfunction by slightly rearranging the code.
Quoted 8 lines
Quoted 5 lines
This adds a little more duplication between the two main drivers, but those versions get more readable in the process.
Fixes a06b80e83011 ("i2c: add zhaoxin i2c controller driver")Signed-off-by Arnd Bergmann <[email protected]>Andi, I am tempted to include this in my for-current pull request this week. Are you okay with this or do you want to review it more closely?
Meh, I forgot about it. Andi, do you plan a PR for rc6?
Andi Shyti
maintainerQuoted 22 lines · Wolfram Sang
Quoted 21 lines · Wolfram Sang
Quoted 20 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The
i2c-viai2c-common.cfile is used by two drivers, but is not a proper abstraction and can get linked into both modules in the same configuration, which results in a warning:
scripts/Makefile.build:236:drivers/i2c/busses/Makefile: i2c-viai2c-common.o is added to multiple modules: i2c-wmt i2c-zhaoxinThe other problems with this include the incorrect use of a
__weakfunction when both are built-in, and the fact that the "common" module is sprinked with 'if (i2c->plat== ...)' checks that have knowledge about the differences between the drivers using it.Avoid the link time warning by making the common driver a proper module with MODULE_LICENCE()/MODULE_AUTHOR() tags, and remove the
__weakfunction by slightly rearranging the code.This adds a little more duplication between the two main drivers, but those versions get more readable in the process.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Fixes a06b80e83011 ("i2c: add zhaoxin i2c controller driver")Signed-off-by Arnd Bergmann <[email protected]>Andi, I am tempted to include this in my for-current pull request this week. Are you okay with this or do you want to review it more closely?
Meh, I forgot about it. Andi, do you plan a PR for rc6?
yes, sorry, will take it.
Sorry for having missed it.
Andi
Andi Shyti
maintainerHi,
...
drivers/i2c/busses/i2c-viai2c-common.c int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c, int plat) · line 202
Quoted 4 lines
drivers/i2c/busses/i2c-viai2c-common.c +4
-0+EXPORT_SYMBOL_GPL (viai2c_init); + +MODULE_DESCRIPTION ("Via/Wondermedia/Zhaoxin I2C master-mode bus adapter" ); +MODULE_AUTHOR ("Tony Prisk <[email protected]>" );
Do we want to add also Hans here?
Quoted 1 line
+MODULE_LICENSE("GPL");
...
Quoted 2 lines
drivers/i2c/busses/i2c-viai2c-wmt.c +2
-0+static irqreturn_t wmt_i2c_isr (int irq,void *data) +{
...
drivers/i2c/busses/i2c-viai2c-wmt.c static int wmt_i2c_reset_hardware(struct viai2c *i2c) · line 101
Quoted 8 lines
drivers/i2c/busses/i2c-viai2c-wmt.c +8
-0+/* All the data has been successfully transferred or error occurred */ +if (i2c->ret) +complete (&i2c->complete); + +return IRQ_HANDLED ; +} + +
I took the freedom to remove this double blank line.
Quoted 3 lines
static int
wmt_i2c_probe(struct platform_device *pdev){
structdevice_node*np =pdev->dev.of_node;
...
drivers/i2c/busses/i2c-viai2c-zhaoxin.c static int zxi2c_probe(struct platform_device *pdev) · line 306
Quoted 10 lines
drivers/i2c/busses/i2c-viai2c-zhaoxin.c +6
-0@@ -239,6 +298,16 @@ static int zxi2c_probe(struct platform_device *pdev)if (error)return error; + i2c->irq =platform_get_irq (pdev,0 ); +if (i2c->irq <0 ) +return i2c->irq; + + error =devm_request_irq (&pdev->dev, i2c->irq, zxi2c_isr, +IRQF_SHARED , pdev->name, i2c);
I took the freedom of re-alligning here.
Queued to i2c/i2c-host-fixes with Tested-by Hans.
Thanks,
Andi