i2c: designware: Split out i2c_dw_validate_speed() helper
Subsystems (3)
Andy Shevchenko
reviewerPATCH 1/4 i2c: designware: Split out i2c_dw_validate_speed() helper
In order to export array supported speed for wider use, split out them along with i2c_dw_validate_speed() helper.
--- drivers/i2c/busses/i2c-designware-core.h | 31 +++++++++++++++++++++ drivers/i2c/busses/i2c-designware-platdrv.c | 29 ++++--------------- 2 files changed, 36 insertions(+), 24 deletions(-)
drivers/i2c/busses/i2c-designware-core.h +31 -0
@@ -9,6 +9,7 @@* Copyright (C) 2009 Provigent Ltd. */ +#include <linux/errno.h> #include <linux/i2c.h> #define DW_IC_DEFAULT_FUNCTIONALITY (I2C_FUNC_I2C | \
@@ -351,3 +352,33 @@ extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev);#else static inline int i2c_dw_probe_lock_support (struct dw_i2c_dev *dev) {return 0 ; }#endif + +static const u32 i2c_dw_supported_speeds[] = { +I2C_MAX_HIGH_SPEED_MODE_FREQ , +I2C_MAX_FAST_MODE_PLUS_FREQ , +I2C_MAX_FAST_MODE_FREQ , +I2C_MAX_STANDARD_MODE_FREQ , +}; + +static inline int i2c_dw_validate_speed (struct dw_i2c_dev *dev) +{ +struct i2c_timings *t = &dev->timings; +unsigned int i; + +/* +* Only standard mode at 100kHz, fast mode at 400kHz, +* fast mode plus at 1MHz and high speed mode at 3.4MHz are supported. +*/ +for (i =0 ; i <ARRAY_SIZE (i2c_dw_supported_speeds); i++) { +if (t->bus_freq_hz == i2c_dw_supported_speeds[i]) +break ; + } +if (i ==ARRAY_SIZE (i2c_dw_supported_speeds)) { +dev_err (dev->dev, +"%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n" , + t->bus_freq_hz); +return -EINVAL ; + } + +return 0 ; +}
drivers/i2c/busses/i2c-designware-platdrv.c +5 -24
@@ -192,13 +192,6 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev)pm_runtime_put_noidle (dev->dev); } -static const u32 supported_speeds[] = { -I2C_MAX_HIGH_SPEED_MODE_FREQ , -I2C_MAX_FAST_MODE_PLUS_FREQ , -I2C_MAX_FAST_MODE_FREQ , -I2C_MAX_STANDARD_MODE_FREQ , -}; -static int dw_i2c_plat_probe (struct platform_device *pdev) {struct dw_i2c_platform_data *pdata =dev_get_platdata (&pdev->dev);
@@ -241,11 +234,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)* Some DSTDs use a non standard speed, round down to the lowest * standard speed. */ -for (i =0 ; i <ARRAY_SIZE (supported_speeds); i++) { -if (acpi_speed >= supported_speeds[i]) +for (i =0 ; i <ARRAY_SIZE (i2c_dw_supported_speeds); i++) { +if (acpi_speed >= i2c_dw_supported_speeds[i])break ; } - acpi_speed = i <ARRAY_SIZE (supported_speeds) ? supported_speeds[i] :0 ; + acpi_speed = i <ARRAY_SIZE (i2c_dw_supported_speeds) ? i2c_dw_supported_speeds[i] :0 ;/* * Find bus speed from the "clock-frequency" device property, ACPI
@@ -266,21 +259,9 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)if (has_acpi_companion (&pdev->dev))dw_i2c_acpi_configure (pdev); -/* -* Only standard mode at 100kHz, fast mode at 400kHz, -* fast mode plus at 1MHz and high speed mode at 3.4MHz are supported. -*/ -for (i =0 ; i <ARRAY_SIZE (supported_speeds); i++) { -if (t->bus_freq_hz == supported_speeds[i]) -break ; - } -if (i ==ARRAY_SIZE (supported_speeds)) { -dev_err (&pdev->dev, -"%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n" , - t->bus_freq_hz); - ret = -EINVAL ; + ret =i2c_dw_validate_speed (dev); +if (ret) goto exit_reset; - } ret =i2c_dw_probe_lock_support (dev);if (ret)
Signature · 1 line
2.26.2
Andy Shevchenko
reviewerPATCH 2/4 i2c: designware: Split out OF parts into separate module
For better maintenance and possible code reuse in the future, split out OF parts into a separate module.
--- drivers/i2c/busses/Makefile | 3 ++ drivers/i2c/busses/i2c-designware-core.h | 6 +++ drivers/i2c/busses/i2c-designware-of.c | 50 ++++++++++++++++++ drivers/i2c/busses/i2c-designware-platdrv.c | 56 ++++----------------- 4 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 drivers/i2c/busses/i2c-designware-of.c
drivers/i2c/busses/Makefile +3 -0
@@ -50,6 +50,9 @@ 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 +ifeq ($(CONFIG_OF),y) +i2c-designware-core-objs += i2c-designware-of.o +endif i2c-designware-core-objs += i2c-designware-master.o ifeq ($(CONFIG_I2C_DESIGNWARE_SLAVE),y) i2c-designware-core-objs += i2c-designware-slave.o
drivers/i2c/busses/i2c-designware-core.h +6 -0
@@ -382,3 +382,9 @@ static inline int i2c_dw_validate_speed(struct dw_i2c_dev *dev)return 0 ; } + +#if IS_ENABLED (CONFIG_OF ) +int i2c_dw_of_configure (struct device *device); +#else +static inline int i2c_dw_of_configure (struct device *device) {return -ENODEV ; } +#endif
drivers/i2c/busses/i2c-designware-of.c new file +50 -0
50 lines not on this page · raw message
drivers/i2c/busses/i2c-designware-platdrv.c +9 -47
88 lines not on this page · raw message
Signature · 1 line
2.26.2
Andy Shevchenko
reviewerPATCH 3/4 i2c: designware: Split out ACPI parts into separate module
In reply to Andy ShevchenkoFor better maintenance and possible code reuse in the future, split out ACPI parts into a separate module.
--- drivers/i2c/busses/Makefile | 3 + drivers/i2c/busses/i2c-designware-acpi.c | 130 +++++++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 8 ++ drivers/i2c/busses/i2c-designware-platdrv.c | 151 +++----------------- 4 files changed, 163 insertions(+), 129 deletions(-) create mode 100644 drivers/i2c/busses/i2c-designware-acpi.c
drivers/i2c/busses/Makefile +3 -0
@@ -50,6 +50,9 @@ 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 +ifeq ($(CONFIG_ACPI),y) +i2c-designware-core-objs += i2c-designware-acpi.o +endif ifeq ($(CONFIG_OF),y) i2c-designware-core-objs += i2c-designware-of.o endif
drivers/i2c/busses/i2c-designware-acpi.c new file +130 -0
130 lines not on this page · raw message
drivers/i2c/busses/i2c-designware-core.h +8 -0
@@ -383,6 +383,14 @@ static inline int i2c_dw_validate_speed(struct dw_i2c_dev *dev)return 0 ; } +#if IS_ENABLED (CONFIG_ACPI ) +int i2c_dw_acpi_configure (struct device *device); +void i2c_dw_acpi_adjust_bus_speed (struct device *device); +#else +static inline int i2c_dw_acpi_configure (struct device *device) {return -ENODEV ; } +static inline void i2c_dw_acpi_adjust_bus_speed (struct device *device) {} +#endif +#if IS_ENABLED (CONFIG_OF )int i2c_dw_of_configure (struct device *device);#else
drivers/i2c/busses/i2c-designware-platdrv.c +22 -129
193 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v1 3/4] i2c: designware: Split out ACPI parts into separate module
Quoted 12 lines · Andy Shevchenko
For better maintenance and possible code reuse in the future, split out ACPI parts into a separate module.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/i2c/busses/Makefile | 3 + drivers/i2c/busses/i2c-designware-acpi.c | 130 +++++++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 8 ++ drivers/i2c/busses/i2c-designware-platdrv.c | 151 +++----------------- 4 files changed, 163 insertions(+), 129 deletions(-)create mode 100644
drivers/i2c/busses/i2c-designware-acpi.c
Comment to both of this and patch 2/4:
I'm not so fan of introducing even more i2c-designware modules. No any other drivers have so many files as i2c-designware in drivers/i2c/busses/*.c. Feeling a bit of hall of shame because of it :-)
What's the rationale here? Currently i2c-designware-platdrv.c is 512 lines of code so it's not too hard to maintain in my opinion.
Signature · 1 line
Jarkko
Andy Shevchenko
reviewerRe: [PATCH v1 3/4] i2c: designware: Split out ACPI parts into separate module
Quoted 13 lines · Jarkko Nikula
Quoted 12 lines · Andy Shevchenko
For better maintenance and possible code reuse in the future, split out ACPI parts into a separate module.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/i2c/busses/Makefile | 3 + drivers/i2c/busses/i2c-designware-acpi.c | 130 +++++++++++++++++ drivers/i2c/busses/i2c-designware-core.h | 8 ++ drivers/i2c/busses/i2c-designware-platdrv.c | 151 +++----------------- 4 files changed, 163 insertions(+), 129 deletions(-)create mode 100644
drivers/i2c/busses/i2c-designware-acpi.c
Quoted 8 lines
Comment to both of this and patch 2/4:
I'm not so fan of introducing even more i2c-designware modules. No any other drivers have so many files as i2c-designware in
drivers/i2c/busses/*.c. Feeling a bit of hall of shame because of it :-)What's the rationale here? Currently
i2c-designware-platdrv.cis 512 lines of code so it's not too hard to maintain in my opinion.
How to use same functionality in PCI and platform driver? Are you implying that the common.c is good enough? I would move there, of course.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerPATCH 4/4 i2c: designware: Read counters from ACPI for PCI driver
In reply to Andy ShevchenkoPCI devices may have been backed with ACPI handle which supplies an additional information to the drivers, such as counters.
Call for ACPI configuration from PCI driver in order to utilize counters provided by ACPI.
--- drivers/i2c/busses/i2c-designware-pcidrv.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/i2c/busses/i2c-designware-pcidrv.c +9 -0
@@ -251,6 +251,15 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev, } } +if (has_acpi_companion (&pdev->dev)) +i2c_dw_acpi_configure (&pdev->dev); + + r =i2c_dw_validate_speed (dev); +if (r) { +pci_free_irq_vectors (pdev); +return r; + } +i2c_dw_configure (dev);if (controller->scl_sda_cfg) {
Signature · 1 line
2.26.2
Quoted 45 lines · Andy Shevchenko
In order to export array supported speed for wider use, split out them along with
i2c_dw_validate_speed()helper.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/i2c/busses/i2c-designware-core.h | 31 +++++++++++++++++++++ drivers/i2c/busses/i2c-designware-platdrv.c | 29 ++++--------------- 2 files changed, 36 insertions(+), 24 deletions(-)drivers/i2c/busses/i2c-designware-core.h +21
-0@@ -9,6 +9,7 @@* Copyright (C) 2009 Provigent Ltd. */ +#include <linux/errno.h> #include <linux/i2c.h> #define DW_IC_DEFAULT_FUNCTIONALITY (I2C_FUNC_I2C | \@@ -351,3 +352,33 @@ extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev);#else static inline int i2c_dw_probe_lock_support (struct dw_i2c_dev *dev) {return 0 ; }#endif + +static const u32 i2c_dw_supported_speeds[] = { +I2C_MAX_HIGH_SPEED_MODE_FREQ , +I2C_MAX_FAST_MODE_PLUS_FREQ , +I2C_MAX_FAST_MODE_FREQ , +I2C_MAX_STANDARD_MODE_FREQ , +}; + +static inline int i2c_dw_validate_speed (struct dw_i2c_dev *dev) +{ +struct i2c_timings *t = &dev->timings; +unsigned int i; + +/* +* Only standard mode at 100kHz, fast mode at 400kHz, +* fast mode plus at 1MHz and high speed mode at 3.4MHz are supported. +*/ +for (i =0 ; i <ARRAY_SIZE (i2c_dw_supported_speeds); i++) { +if (t->bus_freq_hz == i2c_dw_supported_speeds[i]) +break ;
drivers/i2c/busses/i2c-designware-core.h extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev); · line 384
Quoted 10 lines
drivers/i2c/busses/i2c-designware-core.h +10
-0+ } +if (i ==ARRAY_SIZE (i2c_dw_supported_speeds)) { +dev_err (dev->dev, +"%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n" , + t->bus_freq_hz); +return -EINVAL ; + } + +return 0 ; +}
This header is included by every i2c-designware-*.c file and this inline function is not tiny. Would it be better to have this in i2c-designware-common.c instead?
Signature · 1 line
Jarkko
Andy Shevchenko
reviewerQuoted 50 lines · Jarkko Nikula
Quoted 49 lines · Andy Shevchenko
In order to export array supported speed for wider use, split out them along with
i2c_dw_validate_speed()helper.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/i2c/busses/i2c-designware-core.h | 31 +++++++++++++++++++++ drivers/i2c/busses/i2c-designware-platdrv.c | 29 ++++--------------- 2 files changed, 36 insertions(+), 24 deletions(-)drivers/i2c/busses/i2c-designware-core.h +27
-0@@ -9,6 +9,7 @@* Copyright (C) 2009 Provigent Ltd. */ +#include <linux/errno.h> #include <linux/i2c.h> #define DW_IC_DEFAULT_FUNCTIONALITY (I2C_FUNC_I2C | \@@ -351,3 +352,33 @@ extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev);#else static inline int i2c_dw_probe_lock_support (struct dw_i2c_dev *dev) {return 0 ; }#endif + +static const u32 i2c_dw_supported_speeds[] = { +I2C_MAX_HIGH_SPEED_MODE_FREQ , +I2C_MAX_FAST_MODE_PLUS_FREQ , +I2C_MAX_FAST_MODE_FREQ , +I2C_MAX_STANDARD_MODE_FREQ , +}; + +static inline int i2c_dw_validate_speed (struct dw_i2c_dev *dev) +{ +struct i2c_timings *t = &dev->timings; +unsigned int i; + +/* +* Only standard mode at 100kHz, fast mode at 400kHz, +* fast mode plus at 1MHz and high speed mode at 3.4MHz are supported. +*/ +for (i =0 ; i <ARRAY_SIZE (i2c_dw_supported_speeds); i++) { +if (t->bus_freq_hz == i2c_dw_supported_speeds[i]) +break ; + } +if (i ==ARRAY_SIZE (i2c_dw_supported_speeds)) { +dev_err (dev->dev, +"%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n" , + t->bus_freq_hz); +return -EINVAL ;
Quoted 8 lines
drivers/i2c/busses/i2c-designware-core.h extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev); · line 384
Quoted 4 lines
drivers/i2c/busses/i2c-designware-core.h +4
-0+ } + +return 0 ; +}This header is included by every i2c-designware-*.c file and this inline function is not tiny. Would it be better to have this in
i2c-designware-common.cinstead?
Yes, but then we will need to export i2c_dw_supported_speeds as well as its array size.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 60 lines · Andy Shevchenko
Quoted 50 lines · Jarkko Nikula
Quoted 49 lines · Andy Shevchenko
In order to export array supported speed for wider use, split out them along with
i2c_dw_validate_speed()helper.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/i2c/busses/i2c-designware-core.h | 31 +++++++++++++++++++++ drivers/i2c/busses/i2c-designware-platdrv.c | 29 ++++--------------- 2 files changed, 36 insertions(+), 24 deletions(-)drivers/i2c/busses/i2c-designware-core.h +27
-0@@ -9,6 +9,7 @@* Copyright (C) 2009 Provigent Ltd. */ +#include <linux/errno.h> #include <linux/i2c.h> #define DW_IC_DEFAULT_FUNCTIONALITY (I2C_FUNC_I2C | \@@ -351,3 +352,33 @@ extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev);#else static inline int i2c_dw_probe_lock_support (struct dw_i2c_dev *dev) {return 0 ; }#endif + +static const u32 i2c_dw_supported_speeds[] = { +I2C_MAX_HIGH_SPEED_MODE_FREQ , +I2C_MAX_FAST_MODE_PLUS_FREQ , +I2C_MAX_FAST_MODE_FREQ , +I2C_MAX_STANDARD_MODE_FREQ , +}; + +static inline int i2c_dw_validate_speed (struct dw_i2c_dev *dev) +{ +struct i2c_timings *t = &dev->timings; +unsigned int i; + +/* +* Only standard mode at 100kHz, fast mode at 400kHz, +* fast mode plus at 1MHz and high speed mode at 3.4MHz are supported. +*/ +for (i =0 ; i <ARRAY_SIZE (i2c_dw_supported_speeds); i++) { +if (t->bus_freq_hz == i2c_dw_supported_speeds[i]) +break ; + } +if (i ==ARRAY_SIZE (i2c_dw_supported_speeds)) { +dev_err (dev->dev, +"%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n" , + t->bus_freq_hz); +return -EINVAL ;Quoted 8 lines
drivers/i2c/busses/i2c-designware-core.h extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev); · line 384
Quoted 4 lines
drivers/i2c/busses/i2c-designware-core.h +4
-0+ } + +return 0 ; +}This header is included by every i2c-designware-*.c file and this inline function is not tiny. Would it be better to have this in
i2c-designware-common.cinstead?
Quoted 3 lines
Yes, but then we will need to export
i2c_dw_supported_speedsas well as its array size.
Would that not be needed if you move ACPI parts also into i2c-designware-common.c?
Signature · 1 line
Jarkko
Andy Shevchenko
reviewerQuoted 5 lines · Jarkko Nikula
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Jarkko Nikula
Quoted 2 lines · Andy Shevchenko
In order to export array supported speed for wider use, split out them along with
i2c_dw_validate_speed()helper.
...
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
This header is included by every i2c-designware-*.c file and this inline function is not tiny. Would it be better to have this in
i2c-designware-common.cinstead?Yes, but then we will need to export
i2c_dw_supported_speedsas well as its array size.Would that not be needed if you move ACPI parts also into
i2c-designware-common.c?
Yes, in the intermediate patch. I'm about to send v2, where you may see how it looks like.
Signature · 2 lines
With Best Regards, Andy Shevchenko