mfd: arizona: Various improvements and refactoring
Subsystems (2)
cover mfd: arizona: Various improvements and refactoring
This selection of patches fixes review comments from the CS47L24 driver review that were requests for changes in the general Arizona code, plus a couple of preparatory patches that factor out some code into functions.
I will rebase the CS47L24 driver patch on top of these.
This patch set is based on Lee Jones's for-mfd-next branch
Richard Fitzgerald (6):
mfd: arizona: factor out DCVDD isolation control
mfd: arizona: factor out checking of jack detection state
mfd: arizona: Downgrade type mismatch messages to dev_warn()
mfd: arizona: Simplify adding subdevices
mfd: arizona: Remove use of codec build config #ifdefs
mfd: arizona: use correct type ID for device tree config
drivers/mfd/arizona-core.c | 228 +++++++++++++++++++++++++++------------------ drivers/mfd/arizona-i2c.c | 33 +++---- drivers/mfd/arizona-spi.c | 23 +++-- 3 files changed, 166 insertions(+), 118 deletions(-)
Signature · 1 line
1.9.1
PATCH RESEND 1/6 mfd: arizona: factor out DCVDD isolation control
Currently DCVDD isolation is enabled and disabled for runtime_suspend and runtime_resume. Future codecs will not have the isolation control so to prepare for these codecs this patch factors out the isolation control allowing it to be called as needed in the existing codec-specific switch cases.
--- drivers/mfd/arizona-core.c | 108 ++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 46 deletions(-)
drivers/mfd/arizona-core.c +62 -46
@@ -462,6 +462,33 @@ static int wm5102_clear_write_sequencer(struct arizona *arizona) }#ifdef CONFIG_PM +static int arizona_isolate_dcvdd (struct arizona *arizona) +{ +int ret; + + ret =regmap_update_bits (arizona->regmap, +ARIZONA_ISOLATION_CONTROL , +ARIZONA_ISOLATE_DCVDD1 , +ARIZONA_ISOLATE_DCVDD1 ); +if (ret !=0 ) +dev_err (arizona->dev,"Failed to isolate DCVDD: %d\n" , ret); + +return ret; +} + +static int arizona_connect_dcvdd (struct arizona *arizona) +{ +int ret; + + ret =regmap_update_bits (arizona->regmap, +ARIZONA_ISOLATION_CONTROL , +ARIZONA_ISOLATE_DCVDD1 ,0 ); +if (ret !=0 ) +dev_err (arizona->dev,"Failed to connect DCVDD: %d\n" , ret); + +return ret; +} +static int arizona_runtime_resume (struct device *dev) {struct arizona *arizona =dev_get_drvdata (dev);
@@ -501,14 +528,9 @@ static int arizona_runtime_resume(struct device *dev)switch (arizona->type) {case WM5102 :if (arizona->external_dcvdd) { - ret =regmap_update_bits (arizona->regmap, -ARIZONA_ISOLATION_CONTROL , -ARIZONA_ISOLATE_DCVDD1 ,0 ); -if (ret !=0 ) { -dev_err (arizona->dev, -"Failed to connect DCVDD: %d\n" , ret); + ret =arizona_connect_dcvdd (arizona); +if (ret !=0 ) goto err; - } } ret =wm5102_patch (arizona);
@@ -533,14 +555,9 @@ static int arizona_runtime_resume(struct device *dev) goto err;if (arizona->external_dcvdd) { - ret =regmap_update_bits (arizona->regmap, -ARIZONA_ISOLATION_CONTROL , -ARIZONA_ISOLATE_DCVDD1 ,0 ); -if (ret) { -dev_err (arizona->dev, -"Failed to connect DCVDD: %d\n" , ret); + ret =arizona_connect_dcvdd (arizona); +if (ret !=0 ) goto err; - } }else {/* * As this is only called for the internal regulator
@@ -571,14 +588,9 @@ static int arizona_runtime_resume(struct device *dev) goto err;if (arizona->external_dcvdd) { - ret =regmap_update_bits (arizona->regmap, -ARIZONA_ISOLATION_CONTROL , -ARIZONA_ISOLATE_DCVDD1 ,0 ); -if (ret !=0 ) { -dev_err (arizona->dev, -"Failed to connect DCVDD: %d\n" , ret); + ret =arizona_connect_dcvdd (arizona); +if (ret !=0 ) goto err; - } }break ; }
@@ -611,37 +623,36 @@ static int arizona_runtime_suspend(struct device *dev)return ret; } -if (arizona->external_dcvdd) { - ret =regmap_update_bits (arizona->regmap, -ARIZONA_ISOLATION_CONTROL , -ARIZONA_ISOLATE_DCVDD1 , -ARIZONA_ISOLATE_DCVDD1 ); -if (ret !=0 ) { -dev_err (arizona->dev,"Failed to isolate DCVDD: %d\n" , - ret); -return ret; - } - } -switch (arizona->type) {case WM5110 :case WM8280 : -if (arizona->external_dcvdd) -break ; - -/* -* As this is only called for the internal regulator -* (where we know voltage ranges available) it is ok -* to request an exact range. -*/ - ret =regulator_set_voltage (arizona->dcvdd,1175000 ,1175000 ); -if (ret <0 ) { -dev_err (arizona->dev, -"Failed to set suspend voltage: %d\n" , ret); -return ret; +if (arizona->external_dcvdd) { + ret =arizona_isolate_dcvdd (arizona); +if (ret !=0 ) +return ret; + }else { +/* +* As this is only called for the internal regulator +* (where we know voltage ranges available) it is ok +* to request an exact range. +*/ + ret =regulator_set_voltage (arizona->dcvdd, +1175000 ,1175000 ); +if (ret <0 ) { +dev_err (arizona->dev, +"Failed to set suspend voltage: %d\n" , + ret); +return ret; + } }break ;case WM5102 : +if (arizona->external_dcvdd) { + ret =arizona_isolate_dcvdd (arizona); +if (ret !=0 ) +return ret; + } +if (!(val &ARIZONA_JD1_ENA )) { ret =regmap_write (arizona->regmap,ARIZONA_WRITE_SEQUENCER_CTRL_3 ,0x0 );
@@ -654,6 +665,11 @@ static int arizona_runtime_suspend(struct device *dev) }break ;default : +if (arizona->external_dcvdd) { + ret =arizona_isolate_dcvdd (arizona); +if (ret !=0 ) +return ret; + }break ; }
Signature · 1 line
1.9.1
PATCH RESEND 2/6 mfd: arizona: factor out checking of jack detection state
In reply to Richard FitzgeraldCurrently runtime_suspend will fully power off the codec if the jack detection is not enabled. Not all future codecs will have jack detection so to prepare for these codecs this patch factors out the check so that it be called as needed in the existing codec-specific switch cases.
--- drivers/mfd/arizona-core.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-)
drivers/mfd/arizona-core.c +32 -9
@@ -489,6 +489,23 @@ static int arizona_connect_dcvdd(struct arizona *arizona)return ret; } +static int arizona_is_jack_det_active (struct arizona *arizona) +{ +unsigned int val; +int ret; + + ret =regmap_read (arizona->regmap,ARIZONA_JACK_DETECT_ANALOGUE , &val); +if (ret) { +dev_err (arizona->dev, +"Failed to check jack det status: %d\n" , ret); +return ret; + }else if (val &ARIZONA_JD1_ENA ) { +return 1 ; + }else { +return 0 ; + } +} +static int arizona_runtime_resume (struct device *dev) {struct arizona *arizona =dev_get_drvdata (dev);
@@ -612,20 +629,18 @@ err:static int arizona_runtime_suspend (struct device *dev) {struct arizona *arizona =dev_get_drvdata (dev); -unsigned int val; +unsigned int jd_active =0 ;int ret;dev_dbg (arizona->dev,"Entering AoD mode\n" ); - ret =regmap_read (arizona->regmap,ARIZONA_JACK_DETECT_ANALOGUE , &val); -if (ret) { -dev_err (dev,"Failed to check jack det status: %d\n" , ret); -return ret; - } -switch (arizona->type) {case WM5110 :case WM8280 : + jd_active =arizona_is_jack_det_active (arizona); +if (jd_active <0 ) +return jd_active; +if (arizona->external_dcvdd) { ret =arizona_isolate_dcvdd (arizona);if (ret !=0 )
@@ -647,13 +662,17 @@ static int arizona_runtime_suspend(struct device *dev) }break ;case WM5102 : + jd_active =arizona_is_jack_det_active (arizona); +if (jd_active <0 ) +return jd_active; +if (arizona->external_dcvdd) { ret =arizona_isolate_dcvdd (arizona);if (ret !=0 )return ret; } -if (!(val &ARIZONA_JD1_ENA )) { +if (!jd_active) { ret =regmap_write (arizona->regmap,ARIZONA_WRITE_SEQUENCER_CTRL_3 ,0x0 );if (ret) {
@@ -665,6 +684,10 @@ static int arizona_runtime_suspend(struct device *dev) }break ;default : + jd_active =arizona_is_jack_det_active (arizona); +if (jd_active <0 ) +return jd_active; +if (arizona->external_dcvdd) { ret =arizona_isolate_dcvdd (arizona);if (ret !=0 )
@@ -678,7 +701,7 @@ static int arizona_runtime_suspend(struct device *dev)regulator_disable (arizona->dcvdd);/* Allow us to completely power down if no jack detection */ -if (!(val &ARIZONA_JD1_ENA )) { +if (!jd_active) {dev_dbg (arizona->dev,"Fully powering off\n" ); arizona->has_fully_powered_off = true;
Signature · 1 line
1.9.1
PATCH RESEND 3/6 mfd: arizona: Downgrade type mismatch messages to dev_warn
In reply to Richard FitzgeraldIf the declared codec type doesn't match the detected type we issue a log message but carry on registering the device, so a dev_warn() is appropriate rather than a dev_err()
--- drivers/mfd/arizona-core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/mfd/arizona-core.c +8 -8
@@ -1132,8 +1132,8 @@ int arizona_dev_init(struct arizona *arizona)case 0x5102 : type_name ="WM5102" ;if (arizona->type !=WM5102 ) { -dev_err (arizona->dev,"WM5102 registered as %d\n" , - arizona->type); +dev_warn (arizona->dev,"WM5102 registered as %d\n" , + arizona->type); arizona->type =WM5102 ; } apply_patch = wm5102_patch;
@@ -1151,8 +1151,8 @@ int arizona_dev_init(struct arizona *arizona)break ;default : type_name ="WM5110" ; -dev_err (arizona->dev,"WM5110 registered as %d\n" , - arizona->type); +dev_warn (arizona->dev,"WM5110 registered as %d\n" , + arizona->type); arizona->type =WM5110 ;break ; }
@@ -1163,8 +1163,8 @@ int arizona_dev_init(struct arizona *arizona)case 0x8997 : type_name ="WM8997" ;if (arizona->type !=WM8997 ) { -dev_err (arizona->dev,"WM8997 registered as %d\n" , - arizona->type); +dev_warn (arizona->dev,"WM8997 registered as %d\n" , + arizona->type); arizona->type =WM8997 ; } apply_patch = wm8997_patch;
@@ -1183,8 +1183,8 @@ int arizona_dev_init(struct arizona *arizona)default : type_name ="WM8998" ; -dev_err (arizona->dev,"WM8998 registered as %d\n" , - arizona->type); +dev_warn (arizona->dev,"WM8998 registered as %d\n" , + arizona->type); arizona->type =WM8998 ; }
Signature · 1 line
1.9.1
Re: [PATCH 3/6 RESEND] mfd: arizona: Downgrade type mismatch messages to dev_warn
Quoted 8 lines · Richard Fitzgerald
If the declared codec type doesn't match the detected type we issue a log message but carry on registering the device, so a
dev_warn()is appropriate rather than adev_err()Signed-off-by Richard Fitzgerald <[email protected]>--- drivers/mfd/arizona-core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
For my own reference:
Quoted 48 lines
drivers/mfd/arizona-core.c +8
-8@@ -1132,8 +1132,8 @@ int arizona_dev_init(struct arizona *arizona)case 0x5102 : type_name ="WM5102" ;if (arizona->type !=WM5102 ) { -dev_err (arizona->dev,"WM5102 registered as %d\n" , - arizona->type); +dev_warn (arizona->dev,"WM5102 registered as %d\n" , + arizona->type); arizona->type =WM5102 ; } apply_patch = wm5102_patch;@@ -1151,8 +1151,8 @@ int arizona_dev_init(struct arizona *arizona)break ;default : type_name ="WM5110" ; -dev_err (arizona->dev,"WM5110 registered as %d\n" , - arizona->type); +dev_warn (arizona->dev,"WM5110 registered as %d\n" , + arizona->type); arizona->type =WM5110 ;break ; }@@ -1163,8 +1163,8 @@ int arizona_dev_init(struct arizona *arizona)case 0x8997 : type_name ="WM8997" ;if (arizona->type !=WM8997 ) { -dev_err (arizona->dev,"WM8997 registered as %d\n" , - arizona->type); +dev_warn (arizona->dev,"WM8997 registered as %d\n" , + arizona->type); arizona->type =WM8997 ; } apply_patch = wm8997_patch;@@ -1183,8 +1183,8 @@ int arizona_dev_init(struct arizona *arizona)default : type_name ="WM8998" ; -dev_err (arizona->dev,"WM8998 registered as %d\n" , - arizona->type); +dev_warn (arizona->dev,"WM8998 registered as %d\n" , + arizona->type); arizona->type =WM8998 ; }
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH RESEND 4/6 mfd: arizona: Simplify adding subdevices
In reply to Richard FitzgeraldThe code was using a switch on the code type to execute one of several mfd_add_devices() calls. We're already switching on the code type earlier in the function to select the correct patch function so we can roll selection of the mfd device table into the same switch.
--- drivers/mfd/arizona-core.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-)
drivers/mfd/arizona-core.c +14 -22
@@ -24,6 +24,7 @@#include <linux/regulator/consumer.h> #include <linux/regulator/machine.h> #include <linux/slab.h> +#include <linux/platform_device.h> #include <linux/mfd/arizona/core.h> #include <linux/mfd/arizona/registers.h>
@@ -967,7 +968,8 @@ int arizona_dev_init(struct arizona *arizona)const char *type_name;unsigned int reg, val, mask;int (*apply_patch)(struct arizona *) =NULL ; -int ret, i; +const struct mfd_cell *subdevs =NULL ; +int n_subdevs, ret, i;dev_set_drvdata (arizona->dev, arizona);mutex_init (&arizona->clk_lock);
@@ -1138,6 +1140,8 @@ int arizona_dev_init(struct arizona *arizona) } apply_patch = wm5102_patch; arizona->rev &=0x7 ; + subdevs = wm5102_devs; + n_subdevs =ARRAY_SIZE (wm5102_devs);break ;#endif #ifdef CONFIG_MFD_WM5110
@@ -1157,6 +1161,8 @@ int arizona_dev_init(struct arizona *arizona) break; } apply_patch = wm5110_patch; + subdevs = wm5110_devs; + n_subdevs =ARRAY_SIZE (wm5110_devs);break ;#endif #ifdef CONFIG_MFD_WM8997
@@ -1168,6 +1174,8 @@ int arizona_dev_init(struct arizona *arizona) arizona->type = WM8997; } apply_patch = wm8997_patch; + subdevs = wm8997_devs; + n_subdevs =ARRAY_SIZE (wm8997_devs);break ;#endif #ifdef CONFIG_MFD_WM8998
@@ -1189,6 +1197,8 @@ int arizona_dev_init(struct arizona *arizona) } apply_patch = wm8998_patch; + subdevs = wm8998_devs; + n_subdevs =ARRAY_SIZE (wm8998_devs);break ;#endif default :
@@ -1379,28 +1389,10 @@ int arizona_dev_init(struct arizona *arizona)arizona_request_irq (arizona,ARIZONA_IRQ_UNDERCLOCKED ,"Underclocked" , arizona_underclocked, arizona); -switch (arizona->type) { -case WM5102 : - ret =mfd_add_devices (arizona->dev,-1 , wm5102_devs, -ARRAY_SIZE (wm5102_devs),NULL ,0 ,NULL ); -break ; -case WM5110 : -case WM8280 : - ret =mfd_add_devices (arizona->dev,-1 , wm5110_devs, -ARRAY_SIZE (wm5110_devs),NULL ,0 ,NULL ); -break ; -case WM8997 : - ret =mfd_add_devices (arizona->dev,-1 , wm8997_devs, -ARRAY_SIZE (wm8997_devs),NULL ,0 ,NULL ); -break ; -case WM8998 : -case WM1814 : - ret =mfd_add_devices (arizona->dev,-1 , wm8998_devs, -ARRAY_SIZE (wm8998_devs),NULL ,0 ,NULL ); -break ; - } + ret =mfd_add_devices (arizona->dev,PLATFORM_DEVID_NONE , + subdevs, n_subdevs,NULL ,0 ,NULL ); -if (ret !=0 ) { +if (ret) {dev_err (arizona->dev,"Failed to add subdevices: %d\n" , ret); goto err_irq; }
Signature · 1 line
1.9.1
Re: [PATCH 4/6 RESEND] mfd: arizona: Simplify adding subdevices
Quoted 10 lines · Richard Fitzgerald
The code was using a switch on the code type to execute one of several
mfd_add_devices()calls. We're already switching on the code type earlier in the function to select the correct patch function so we can roll selection of the mfd device table into the same switch.Signed-off-by Richard Fitzgerald <[email protected]>--- drivers/mfd/arizona-core.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-)
For my own reference:
Quoted 90 lines
drivers/mfd/arizona-core.c +14
-22@@ -24,6 +24,7 @@#include <linux/regulator/consumer.h> #include <linux/regulator/machine.h> #include <linux/slab.h> +#include <linux/platform_device.h> #include <linux/mfd/arizona/core.h> #include <linux/mfd/arizona/registers.h> @@ -967,7 +968,8 @@ int arizona_dev_init(struct arizona *arizona)const char *type_name;unsigned int reg, val, mask;int (*apply_patch)(struct arizona *) =NULL ; -int ret, i; +const struct mfd_cell *subdevs =NULL ; +int n_subdevs, ret, i;dev_set_drvdata (arizona->dev, arizona);mutex_init (&arizona->clk_lock);@@ -1138,6 +1140,8 @@ int arizona_dev_init(struct arizona *arizona) } apply_patch = wm5102_patch; arizona->rev &=0x7 ; + subdevs = wm5102_devs; + n_subdevs =ARRAY_SIZE (wm5102_devs);break ;#endif #ifdef CONFIG_MFD_WM5110 @@ -1157,6 +1161,8 @@ int arizona_dev_init(struct arizona *arizona) break; } apply_patch = wm5110_patch; + subdevs = wm5110_devs; + n_subdevs =ARRAY_SIZE (wm5110_devs);break ;#endif #ifdef CONFIG_MFD_WM8997 @@ -1168,6 +1174,8 @@ int arizona_dev_init(struct arizona *arizona) arizona->type = WM8997; } apply_patch = wm8997_patch; + subdevs = wm8997_devs; + n_subdevs =ARRAY_SIZE (wm8997_devs);break ;#endif #ifdef CONFIG_MFD_WM8998 @@ -1189,6 +1197,8 @@ int arizona_dev_init(struct arizona *arizona) } apply_patch = wm8998_patch; + subdevs = wm8998_devs; + n_subdevs =ARRAY_SIZE (wm8998_devs);break ;#endif default :@@ -1379,28 +1389,10 @@ int arizona_dev_init(struct arizona *arizona)arizona_request_irq (arizona,ARIZONA_IRQ_UNDERCLOCKED ,"Underclocked" , arizona_underclocked, arizona); -switch (arizona->type) { -case WM5102 : - ret =mfd_add_devices (arizona->dev,-1 , wm5102_devs, -ARRAY_SIZE (wm5102_devs),NULL ,0 ,NULL ); -break ; -case WM5110 : -case WM8280 : - ret =mfd_add_devices (arizona->dev,-1 , wm5110_devs, -ARRAY_SIZE (wm5110_devs),NULL ,0 ,NULL ); -break ; -case WM8997 : - ret =mfd_add_devices (arizona->dev,-1 , wm8997_devs, -ARRAY_SIZE (wm8997_devs),NULL ,0 ,NULL ); -break ; -case WM8998 : -case WM1814 : - ret =mfd_add_devices (arizona->dev,-1 , wm8998_devs, -ARRAY_SIZE (wm8998_devs),NULL ,0 ,NULL ); -break ; - } + ret =mfd_add_devices (arizona->dev,PLATFORM_DEVID_NONE , + subdevs, n_subdevs,NULL ,0 ,NULL ); -if (ret !=0 ) { +if (ret) {dev_err (arizona->dev,"Failed to add subdevices: %d\n" , ret); goto err_irq; }
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH RESEND 5/6 mfd: arizona: Remove use of codec build config #ifdefs
In reply to Richard FitzgeraldRemove the use of #ifdefs around each case statement of the chip ID and type validation switches.
We must ensure that the contained code still compiles to nothing if support for that codec was not built into the kernel, to prevent creation of link references to missing functions. So the ifdefs are replaced with a use of the IS_ENABLED() macro.
--- drivers/mfd/arizona-core.c | 29 +++++++++++++++++++++-------- drivers/mfd/arizona-i2c.c | 28 +++++++++++++++------------- drivers/mfd/arizona-spi.c | 18 +++++++++++------- 3 files changed, 47 insertions(+), 28 deletions(-)
drivers/mfd/arizona-core.c +21 -8
@@ -1130,22 +1130,26 @@ int arizona_dev_init(struct arizona *arizona) arizona->rev &=ARIZONA_DEVICE_REVISION_MASK ;switch (reg) { -#ifdef CONFIG_MFD_WM5102 case 0x5102 : +if (!IS_ENABLED (CONFIG_MFD_WM5102 )) +break ; + type_name ="WM5102" ;if (arizona->type !=WM5102 ) {dev_warn (arizona->dev,"WM5102 registered as %d\n" , arizona->type); arizona->type =WM5102 ; } + apply_patch = wm5102_patch; arizona->rev &=0x7 ; subdevs = wm5102_devs; n_subdevs =ARRAY_SIZE (wm5102_devs);break ; -#endif -#ifdef CONFIG_MFD_WM5110 case 0x5110 : +if (!IS_ENABLED (CONFIG_MFD_WM5110 )) +break ; +switch (arizona->type) {case WM5110 : type_name ="WM5110" ;
@@ -1160,26 +1164,30 @@ int arizona_dev_init(struct arizona *arizona) arizona->type =WM5110 ;break ; } + apply_patch = wm5110_patch; subdevs = wm5110_devs; n_subdevs =ARRAY_SIZE (wm5110_devs);break ; -#endif -#ifdef CONFIG_MFD_WM8997 case 0x8997 : +if (!IS_ENABLED (CONFIG_MFD_WM8997 )) +break ; + type_name ="WM8997" ;if (arizona->type !=WM8997 ) {dev_warn (arizona->dev,"WM8997 registered as %d\n" , arizona->type); arizona->type =WM8997 ; } + apply_patch = wm8997_patch; subdevs = wm8997_devs; n_subdevs =ARRAY_SIZE (wm8997_devs);break ; -#endif -#ifdef CONFIG_MFD_WM8998 case 0x6349 : +if (!IS_ENABLED (CONFIG_MFD_WM8998 )) +break ; +switch (arizona->type) {case WM8998 : type_name ="WM8998" ;
@@ -1200,12 +1208,17 @@ int arizona_dev_init(struct arizona *arizona) subdevs = wm8998_devs; n_subdevs =ARRAY_SIZE (wm8998_devs);break ; -#endif default :dev_err (arizona->dev,"Unknown device ID %x\n" , reg); goto err_reset; } +if (!subdevs) { +dev_err (arizona->dev, +"No kernel support for device ID %x\n" , reg); + goto err_reset; + } +dev_info (dev,"%s revision %c\n" , type_name, arizona->rev +'A' );if (apply_patch) {
drivers/mfd/arizona-i2c.c +15 -13
@@ -27,7 +27,7 @@ static int arizona_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) {struct arizona *arizona; -const struct regmap_config *regmap_config; +const struct regmap_config *regmap_config =NULL ;unsigned long type;int ret;
@@ -37,34 +37,36 @@ static int arizona_i2c_probe(struct i2c_client *i2c, type = id->driver_data;switch (type) { -#ifdef CONFIG_MFD_WM5102 case WM5102 : - regmap_config = &wm5102_i2c_regmap; +if (IS_ENABLED (CONFIG_MFD_WM5102 )) + regmap_config = &wm5102_i2c_regmap;break ; -#endif -#ifdef CONFIG_MFD_WM5110 case WM5110 :case WM8280 : - regmap_config = &wm5110_i2c_regmap; +if (IS_ENABLED (CONFIG_MFD_WM5110 )) + regmap_config = &wm5110_i2c_regmap;break ; -#endif -#ifdef CONFIG_MFD_WM8997 case WM8997 : - regmap_config = &wm8997_i2c_regmap; +if (IS_ENABLED (CONFIG_MFD_WM8997 )) + regmap_config = &wm8997_i2c_regmap;break ; -#endif -#ifdef CONFIG_MFD_WM8998 case WM8998 :case WM1814 : - regmap_config = &wm8998_i2c_regmap; +if (IS_ENABLED (CONFIG_MFD_WM8998 )) + regmap_config = &wm8998_i2c_regmap;break ; -#endif default :dev_err (&i2c->dev,"Unknown device type %ld\n" , id->driver_data);return -EINVAL ; } +if (!regmap_config) { +dev_err (&i2c->dev, +"No kernel support for device type %ld\n" , type); +return -EINVAL ; + } + arizona =devm_kzalloc (&i2c->dev,sizeof (*arizona),GFP_KERNEL );if (arizona ==NULL )return -ENOMEM ;
drivers/mfd/arizona-spi.c +11 -7
@@ -27,7 +27,7 @@ static int arizona_spi_probe(struct spi_device *spi) {const struct spi_device_id *id =spi_get_device_id (spi);struct arizona *arizona; -const struct regmap_config *regmap_config; +const struct regmap_config *regmap_config =NULL ;unsigned long type;int ret;
@@ -37,23 +37,27 @@ static int arizona_spi_probe(struct spi_device *spi) type = id->driver_data;switch (type) { -#ifdef CONFIG_MFD_WM5102 case WM5102 : - regmap_config = &wm5102_spi_regmap; +if (IS_ENABLED (CONFIG_MFD_WM5102 )) + regmap_config = &wm5102_spi_regmap;break ; -#endif -#ifdef CONFIG_MFD_WM5110 case WM5110 :case WM8280 : - regmap_config = &wm5110_spi_regmap; +if (IS_ENABLED (CONFIG_MFD_WM5110 )) + regmap_config = &wm5110_spi_regmap;break ; -#endif default :dev_err (&spi->dev,"Unknown device type %ld\n" , id->driver_data);return -EINVAL ; } +if (!regmap_config) { +dev_err (&spi->dev, +"No kernel support for device type %ld\n" , type); +return -EINVAL ; + } + arizona =devm_kzalloc (&spi->dev,sizeof (*arizona),GFP_KERNEL );if (arizona ==NULL )return -ENOMEM ;
Signature · 1 line
1.9.1
Re: [PATCH 5/6 RESEND] mfd: arizona: Remove use of codec build config #ifdefs
Quoted 20 lines · Richard Fitzgerald
Remove the use of #ifdefs around each case statement of the chip ID and type validation switches.
We must ensure that the contained code still compiles to nothing if support for that codec was not built into the kernel, to prevent creation of link references to missing functions. So the ifdefs are replaced with a use of the
IS_ENABLED()macro.Signed-off-by Richard Fitzgerald <[email protected]>--- drivers/mfd/arizona-core.c | 29 +++++++++++++++++++++-------- drivers/mfd/arizona-i2c.c | 28 +++++++++++++++------------- drivers/mfd/arizona-spi.c | 18 +++++++++++------- 3 files changed, 47 insertions(+), 28 deletions(-)drivers/mfd/arizona-core.c +0
-0
drivers/mfd/arizona-core.c int arizona_dev_init(struct arizona *arizona) · line 1136
Quoted 8 lines
drivers/mfd/arizona-core.c +3
-1@@ -1130,22 +1130,26 @@ int arizona_dev_init(struct arizona *arizona) arizona->rev &=ARIZONA_DEVICE_REVISION_MASK ;switch (reg) { -#ifdef CONFIG_MFD_WM5102 case 0x5102 : +if (!IS_ENABLED (CONFIG_MFD_WM5102 )) +break ; +
Are you sure this statement effects the code below?
I'm not sure it will. How have you tested it?
Quoted 184 lines
drivers/mfd/arizona-core.c +18
-7type_name ="WM5102" ;if (arizona->type !=WM5102 ) {dev_warn (arizona->dev,"WM5102 registered as %d\n" , arizona->type); arizona->type =WM5102 ; } + apply_patch = wm5102_patch; arizona->rev &=0x7 ; subdevs = wm5102_devs; n_subdevs =ARRAY_SIZE (wm5102_devs);break ; -#endif -#ifdef CONFIG_MFD_WM5110 case 0x5110 : +if (!IS_ENABLED (CONFIG_MFD_WM5110 )) +break ; +switch (arizona->type) {case WM5110 : type_name ="WM5110" ;@@ -1160,26 +1164,30 @@ int arizona_dev_init(struct arizona *arizona) arizona->type =WM5110 ;break ; } + apply_patch = wm5110_patch; subdevs = wm5110_devs; n_subdevs =ARRAY_SIZE (wm5110_devs);break ; -#endif -#ifdef CONFIG_MFD_WM8997 case 0x8997 : +if (!IS_ENABLED (CONFIG_MFD_WM8997 )) +break ; + type_name ="WM8997" ;if (arizona->type !=WM8997 ) {dev_warn (arizona->dev,"WM8997 registered as %d\n" , arizona->type); arizona->type =WM8997 ; } + apply_patch = wm8997_patch; subdevs = wm8997_devs; n_subdevs =ARRAY_SIZE (wm8997_devs);break ; -#endif -#ifdef CONFIG_MFD_WM8998 case 0x6349 : +if (!IS_ENABLED (CONFIG_MFD_WM8998 )) +break ; +switch (arizona->type) {case WM8998 : type_name ="WM8998" ;@@ -1200,12 +1208,17 @@ int arizona_dev_init(struct arizona *arizona) subdevs = wm8998_devs; n_subdevs =ARRAY_SIZE (wm8998_devs);break ; -#endif default :dev_err (arizona->dev,"Unknown device ID %x\n" , reg); goto err_reset; } +if (!subdevs) { +dev_err (arizona->dev, +"No kernel support for device ID %x\n" , reg); + goto err_reset; + } +dev_info (dev,"%s revision %c\n" , type_name, arizona->rev +'A' );if (apply_patch) {drivers/mfd/arizona-i2c.c +15
-13@@ -27,7 +27,7 @@ static int arizona_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) {struct arizona *arizona; -const struct regmap_config *regmap_config; +const struct regmap_config *regmap_config =NULL ;unsigned long type;int ret;@@ -37,34 +37,36 @@ static int arizona_i2c_probe(struct i2c_client *i2c, type = id->driver_data;switch (type) { -#ifdef CONFIG_MFD_WM5102 case WM5102 : - regmap_config = &wm5102_i2c_regmap; +if (IS_ENABLED (CONFIG_MFD_WM5102 )) + regmap_config = &wm5102_i2c_regmap;break ; -#endif -#ifdef CONFIG_MFD_WM5110 case WM5110 :case WM8280 : - regmap_config = &wm5110_i2c_regmap; +if (IS_ENABLED (CONFIG_MFD_WM5110 )) + regmap_config = &wm5110_i2c_regmap;break ; -#endif -#ifdef CONFIG_MFD_WM8997 case WM8997 : - regmap_config = &wm8997_i2c_regmap; +if (IS_ENABLED (CONFIG_MFD_WM8997 )) + regmap_config = &wm8997_i2c_regmap;break ; -#endif -#ifdef CONFIG_MFD_WM8998 case WM8998 :case WM1814 : - regmap_config = &wm8998_i2c_regmap; +if (IS_ENABLED (CONFIG_MFD_WM8998 )) + regmap_config = &wm8998_i2c_regmap;break ; -#endif default :dev_err (&i2c->dev,"Unknown device type %ld\n" , id->driver_data);return -EINVAL ; } +if (!regmap_config) { +dev_err (&i2c->dev, +"No kernel support for device type %ld\n" , type); +return -EINVAL ; + } + arizona =devm_kzalloc (&i2c->dev,sizeof (*arizona),GFP_KERNEL );if (arizona ==NULL )return -ENOMEM ;drivers/mfd/arizona-spi.c +11
-7@@ -27,7 +27,7 @@ static int arizona_spi_probe(struct spi_device *spi) {const struct spi_device_id *id =spi_get_device_id (spi);struct arizona *arizona; -const struct regmap_config *regmap_config; +const struct regmap_config *regmap_config =NULL ;unsigned long type;int ret;@@ -37,23 +37,27 @@ static int arizona_spi_probe(struct spi_device *spi) type = id->driver_data;switch (type) { -#ifdef CONFIG_MFD_WM5102 case WM5102 : - regmap_config = &wm5102_spi_regmap; +if (IS_ENABLED (CONFIG_MFD_WM5102 )) + regmap_config = &wm5102_spi_regmap;break ; -#endif -#ifdef CONFIG_MFD_WM5110 case WM5110 :case WM8280 : - regmap_config = &wm5110_spi_regmap; +if (IS_ENABLED (CONFIG_MFD_WM5110 )) + regmap_config = &wm5110_spi_regmap;break ; -#endif default :dev_err (&spi->dev,"Unknown device type %ld\n" , id->driver_data);return -EINVAL ; } +if (!regmap_config) { +dev_err (&spi->dev, +"No kernel support for device type %ld\n" , type); +return -EINVAL ; + } + arizona =devm_kzalloc (&spi->dev,sizeof (*arizona),GFP_KERNEL );if (arizona ==NULL )return -ENOMEM ;
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH 5/6 RESEND] mfd: arizona: Remove use of codec build config #ifdefs
Quoted 33 lines · Lee Jones
Quoted 20 lines · Richard Fitzgerald
Remove the use of #ifdefs around each case statement of the chip ID and type validation switches.
We must ensure that the contained code still compiles to nothing if support for that codec was not built into the kernel, to prevent creation of link references to missing functions. So the ifdefs are replaced with a use of the
IS_ENABLED()macro.Signed-off-by Richard Fitzgerald <[email protected]>--- drivers/mfd/arizona-core.c | 29 +++++++++++++++++++++-------- drivers/mfd/arizona-i2c.c | 28 +++++++++++++++------------- drivers/mfd/arizona-spi.c | 18 +++++++++++------- 3 files changed, 47 insertions(+), 28 deletions(-)drivers/mfd/arizona-core.c +0
-0drivers/mfd/arizona-core.c int arizona_dev_init(struct arizona *arizona) · line 1136
Quoted 8 lines
drivers/mfd/arizona-core.c +3
-1@@ -1130,22 +1130,26 @@ int arizona_dev_init(struct arizona *arizona) arizona->rev &=ARIZONA_DEVICE_REVISION_MASK ;switch (reg) { -#ifdef CONFIG_MFD_WM5102 case 0x5102 : +if (!IS_ENABLED (CONFIG_MFD_WM5102 )) +break ; +Are you sure this statement effects the code below?
Quoted 1 line
I'm not sure it will. How have you tested it?
Yeah looking at that again I am not sure that is going to cause that code to be elimated either. Richard is on holiday this week and next. I will try to find time to have a look at this today.
Thanks,
Charles
PATCH RESEND 6/6 mfd: arizona: use correct type ID for device tree config
In reply to Richard FitzgeraldIn the case of a device tree config the code uses the device ID from the DT entry to check which codec is required but when storing the ID into struct arizona it was always using the non-DT SPI device table to get an ID.
This patch changes the code to store the correct ID into struct arizona.
--- drivers/mfd/arizona-i2c.c | 5 ++--- drivers/mfd/arizona-spi.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
drivers/mfd/arizona-i2c.c +2 -3
@@ -56,8 +56,7 @@ static int arizona_i2c_probe(struct i2c_client *i2c, regmap_config = &wm8998_i2c_regmap;break ;default : -dev_err (&i2c->dev,"Unknown device type %ld\n" , - id->driver_data); +dev_err (&i2c->dev,"Unknown device type %ld\n" , type);return -EINVAL ; }
@@ -79,7 +78,7 @@ static int arizona_i2c_probe(struct i2c_client *i2c,return ret; } - arizona->type = id->driver_data; + arizona->type = type; arizona->dev = &i2c->dev; arizona->irq = i2c->irq;
drivers/mfd/arizona-spi.c +2 -3
@@ -47,8 +47,7 @@ static int arizona_spi_probe(struct spi_device *spi) regmap_config = &wm5110_spi_regmap;break ;default : -dev_err (&spi->dev,"Unknown device type %ld\n" , - id->driver_data); +dev_err (&spi->dev,"Unknown device type %ld\n" , type);return -EINVAL ; }
@@ -70,7 +69,7 @@ static int arizona_spi_probe(struct spi_device *spi)return ret; } - arizona->type = id->driver_data; + arizona->type = type; arizona->dev = &spi->dev; arizona->irq = spi->irq;
Signature · 1 line
1.9.1
Re: [PATCH 6/6 RESEND] mfd: arizona: use correct type ID for device tree config
Quoted 5 lines · Richard Fitzgerald
In the case of a device tree config the code uses the device ID from the DT entry to check which codec is required but when storing the ID into struct arizona it was always using the non-DT SPI device table to get an ID.
Quoted 7 lines
This patch changes the code to store the correct ID into struct arizona.
Signed-off-by Richard Fitzgerald <[email protected]>--- drivers/mfd/arizona-i2c.c | 5 ++--- drivers/mfd/arizona-spi.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-)
For my own reference:
Quoted 46 lines
drivers/mfd/arizona-i2c.c +2
-3@@ -56,8 +56,7 @@ static int arizona_i2c_probe(struct i2c_client *i2c, regmap_config = &wm8998_i2c_regmap;break ;default : -dev_err (&i2c->dev,"Unknown device type %ld\n" , - id->driver_data); +dev_err (&i2c->dev,"Unknown device type %ld\n" , type);return -EINVAL ; }@@ -79,7 +78,7 @@ static int arizona_i2c_probe(struct i2c_client *i2c,return ret; } - arizona->type = id->driver_data; + arizona->type = type; arizona->dev = &i2c->dev; arizona->irq = i2c->irq;drivers/mfd/arizona-spi.c +2
-3@@ -47,8 +47,7 @@ static int arizona_spi_probe(struct spi_device *spi) regmap_config = &wm5110_spi_regmap;break ;default : -dev_err (&spi->dev,"Unknown device type %ld\n" , - id->driver_data); +dev_err (&spi->dev,"Unknown device type %ld\n" , type);return -EINVAL ; }@@ -70,7 +69,7 @@ static int arizona_spi_probe(struct spi_device *spi)return ret; } - arizona->type = id->driver_data; + arizona->type = type; arizona->dev = &spi->dev; arizona->irq = spi->irq;
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog