hwmon: (pmbus/core): Generalize pmbus status flag map
PATCH 1/1 hwmon: (pmbus/core): Generalize pmbus status flag map
Move the PMBus status flag map (pmbus_regulator_status_flag_map) outside of the regulator #if block and update the associated variable/struct name to reflect a generic PMBus status. Also retain the regulator error flag for use in determining regulator specific error.
This will make the PMBus status flag map more versatile and easier to incorporate into different contexts and functions.
--- drivers/hwmon/pmbus/pmbus_core.c | 94 ++++++++++++++++---------------- 1 file changed, 47 insertions(+), 47 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +47 -47
@@ -2692,6 +2692,49 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,return 0 ; } +/* A PMBus status flag and the corresponding REGULATOR_ERROR_* flag */ +struct pmbus_status_assoc { +int pflag, rflag; +}; + +/* PMBus->regulator bit mappings for a PMBus status register */ +struct pmbus_status_category { +int func; +int reg; +const struct pmbus_status_assoc *bits;/* zero-terminated */ +}; + +static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[] = { + { + .func =PMBUS_HAVE_STATUS_VOUT , + .reg =PMBUS_STATUS_VOUT , + .bits = (const struct pmbus_status_assoc []) { + {PB_VOLTAGE_UV_WARNING ,REGULATOR_ERROR_UNDER_VOLTAGE_WARN }, + {PB_VOLTAGE_UV_FAULT ,REGULATOR_ERROR_UNDER_VOLTAGE }, + {PB_VOLTAGE_OV_WARNING ,REGULATOR_ERROR_OVER_VOLTAGE_WARN }, + {PB_VOLTAGE_OV_FAULT ,REGULATOR_ERROR_REGULATION_OUT }, + { }, + }, + }, { + .func =PMBUS_HAVE_STATUS_IOUT , + .reg =PMBUS_STATUS_IOUT , + .bits = (const struct pmbus_status_assoc []) { + {PB_IOUT_OC_WARNING ,REGULATOR_ERROR_OVER_CURRENT_WARN }, + {PB_IOUT_OC_FAULT ,REGULATOR_ERROR_OVER_CURRENT }, + {PB_IOUT_OC_LV_FAULT ,REGULATOR_ERROR_OVER_CURRENT }, + { }, + }, + }, { + .func =PMBUS_HAVE_STATUS_TEMP , + .reg =PMBUS_STATUS_TEMPERATURE , + .bits = (const struct pmbus_status_assoc []) { + {PB_TEMP_OT_WARNING ,REGULATOR_ERROR_OVER_TEMP_WARN }, + {PB_TEMP_OT_FAULT ,REGULATOR_ERROR_OVER_TEMP }, + { }, + }, + }, +}; +#if IS_ENABLED (CONFIG_REGULATOR )static int pmbus_regulator_is_enabled (struct regulator_dev *rdev) {
@@ -2738,54 +2781,11 @@ static int pmbus_regulator_disable(struct regulator_dev *rdev)return _pmbus_regulator_on_off (rdev,0 ); } -/* A PMBus status flag and the corresponding REGULATOR_ERROR_* flag */ -struct pmbus_regulator_status_assoc { -int pflag, rflag; -}; - -/* PMBus->regulator bit mappings for a PMBus status register */ -struct pmbus_regulator_status_category { -int func; -int reg; -const struct pmbus_regulator_status_assoc *bits;/* zero-terminated */ -}; - -static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] = { - { - .func =PMBUS_HAVE_STATUS_VOUT , - .reg =PMBUS_STATUS_VOUT , - .bits = (const struct pmbus_regulator_status_assoc []) { - {PB_VOLTAGE_UV_WARNING ,REGULATOR_ERROR_UNDER_VOLTAGE_WARN }, - {PB_VOLTAGE_UV_FAULT ,REGULATOR_ERROR_UNDER_VOLTAGE }, - {PB_VOLTAGE_OV_WARNING ,REGULATOR_ERROR_OVER_VOLTAGE_WARN }, - {PB_VOLTAGE_OV_FAULT ,REGULATOR_ERROR_REGULATION_OUT }, - { }, - }, - }, { - .func =PMBUS_HAVE_STATUS_IOUT , - .reg =PMBUS_STATUS_IOUT , - .bits = (const struct pmbus_regulator_status_assoc []) { - {PB_IOUT_OC_WARNING ,REGULATOR_ERROR_OVER_CURRENT_WARN }, - {PB_IOUT_OC_FAULT ,REGULATOR_ERROR_OVER_CURRENT }, - {PB_IOUT_OC_LV_FAULT ,REGULATOR_ERROR_OVER_CURRENT }, - { }, - }, - }, { - .func =PMBUS_HAVE_STATUS_TEMP , - .reg =PMBUS_STATUS_TEMPERATURE , - .bits = (const struct pmbus_regulator_status_assoc []) { - {PB_TEMP_OT_WARNING ,REGULATOR_ERROR_OVER_TEMP_WARN }, - {PB_TEMP_OT_FAULT ,REGULATOR_ERROR_OVER_TEMP }, - { }, - }, - }, -}; -static int pmbus_regulator_get_error_flags (struct regulator_dev *rdev,unsigned int *flags) {int i, status; -const struct pmbus_regulator_status_category *cat; -const struct pmbus_regulator_status_assoc *bit; +const struct pmbus_status_category *cat; +const struct pmbus_status_assoc *bit;struct device *dev =rdev_get_dev (rdev);struct i2c_client *client =to_i2c_client (dev->parent);struct pmbus_data *data =i2c_get_clientdata (client);
@@ -2796,8 +2796,8 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsignedmutex_lock (&data->update_lock); -for (i =0 ; i <ARRAY_SIZE (pmbus_regulator_flag_map); i++) { - cat = &pmbus_regulator_flag_map[i]; +for (i =0 ; i <ARRAY_SIZE (pmbus_status_flag_map); i++) { + cat = &pmbus_status_flag_map[i];if (!(func & cat->func))continue ;
base-commit: 774dccfe77dcd8cf1d82df1f61fe95a720dc76e4
Signature · 1 line
2.38.1
Guenter Roeck
maintainerQuoted 9 lines · Naresh Solanki
Move the PMBus status flag map (
pmbus_regulator_status_flag_map) outside of the regulator #if block and update the associated variable/struct name to reflect a generic PMBus status. Also retain the regulator error flag for use in determining regulator specific error.This will make the PMBus status flag map more versatile and easier to incorporate into different contexts and functions.
Signed-off-by Naresh Solanki <[email protected]>
Sorry, I don't see the point of moving a structure including regulator error codes outside regulator code.
Guenter
Quoted 128 lines
--- drivers/hwmon/pmbus/pmbus_core.c | 94 ++++++++++++++++---------------- 1 file changed, 47 insertions(+), 47 deletions(-)drivers/hwmon/pmbus/pmbus_core.c +47
-47@@ -2692,6 +2692,49 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,return 0 ; } +/* A PMBus status flag and the corresponding REGULATOR_ERROR_* flag */ +struct pmbus_status_assoc { +int pflag, rflag; +}; + +/* PMBus->regulator bit mappings for a PMBus status register */ +struct pmbus_status_category { +int func; +int reg; +const struct pmbus_status_assoc *bits;/* zero-terminated */ +}; + +static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[] = { + { + .func =PMBUS_HAVE_STATUS_VOUT , + .reg =PMBUS_STATUS_VOUT , + .bits = (const struct pmbus_status_assoc []) { + {PB_VOLTAGE_UV_WARNING ,REGULATOR_ERROR_UNDER_VOLTAGE_WARN }, + {PB_VOLTAGE_UV_FAULT ,REGULATOR_ERROR_UNDER_VOLTAGE }, + {PB_VOLTAGE_OV_WARNING ,REGULATOR_ERROR_OVER_VOLTAGE_WARN }, + {PB_VOLTAGE_OV_FAULT ,REGULATOR_ERROR_REGULATION_OUT }, + { }, + }, + }, { + .func =PMBUS_HAVE_STATUS_IOUT , + .reg =PMBUS_STATUS_IOUT , + .bits = (const struct pmbus_status_assoc []) { + {PB_IOUT_OC_WARNING ,REGULATOR_ERROR_OVER_CURRENT_WARN }, + {PB_IOUT_OC_FAULT ,REGULATOR_ERROR_OVER_CURRENT }, + {PB_IOUT_OC_LV_FAULT ,REGULATOR_ERROR_OVER_CURRENT }, + { }, + }, + }, { + .func =PMBUS_HAVE_STATUS_TEMP , + .reg =PMBUS_STATUS_TEMPERATURE , + .bits = (const struct pmbus_status_assoc []) { + {PB_TEMP_OT_WARNING ,REGULATOR_ERROR_OVER_TEMP_WARN }, + {PB_TEMP_OT_FAULT ,REGULATOR_ERROR_OVER_TEMP }, + { }, + }, + }, +}; +#if IS_ENABLED (CONFIG_REGULATOR )static int pmbus_regulator_is_enabled (struct regulator_dev *rdev) {@@ -2738,54 +2781,11 @@ static int pmbus_regulator_disable(struct regulator_dev *rdev)return _pmbus_regulator_on_off (rdev,0 ); } -/* A PMBus status flag and the corresponding REGULATOR_ERROR_* flag */ -struct pmbus_regulator_status_assoc { -int pflag, rflag; -}; - -/* PMBus->regulator bit mappings for a PMBus status register */ -struct pmbus_regulator_status_category { -int func; -int reg; -const struct pmbus_regulator_status_assoc *bits;/* zero-terminated */ -}; - -static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] = { - { - .func =PMBUS_HAVE_STATUS_VOUT , - .reg =PMBUS_STATUS_VOUT , - .bits = (const struct pmbus_regulator_status_assoc []) { - {PB_VOLTAGE_UV_WARNING ,REGULATOR_ERROR_UNDER_VOLTAGE_WARN }, - {PB_VOLTAGE_UV_FAULT ,REGULATOR_ERROR_UNDER_VOLTAGE }, - {PB_VOLTAGE_OV_WARNING ,REGULATOR_ERROR_OVER_VOLTAGE_WARN }, - {PB_VOLTAGE_OV_FAULT ,REGULATOR_ERROR_REGULATION_OUT }, - { }, - }, - }, { - .func =PMBUS_HAVE_STATUS_IOUT , - .reg =PMBUS_STATUS_IOUT , - .bits = (const struct pmbus_regulator_status_assoc []) { - {PB_IOUT_OC_WARNING ,REGULATOR_ERROR_OVER_CURRENT_WARN }, - {PB_IOUT_OC_FAULT ,REGULATOR_ERROR_OVER_CURRENT }, - {PB_IOUT_OC_LV_FAULT ,REGULATOR_ERROR_OVER_CURRENT }, - { }, - }, - }, { - .func =PMBUS_HAVE_STATUS_TEMP , - .reg =PMBUS_STATUS_TEMPERATURE , - .bits = (const struct pmbus_regulator_status_assoc []) { - {PB_TEMP_OT_WARNING ,REGULATOR_ERROR_OVER_TEMP_WARN }, - {PB_TEMP_OT_FAULT ,REGULATOR_ERROR_OVER_TEMP }, - { }, - }, - }, -}; -static int pmbus_regulator_get_error_flags (struct regulator_dev *rdev,unsigned int *flags) {int i, status; -const struct pmbus_regulator_status_category *cat; -const struct pmbus_regulator_status_assoc *bit; +const struct pmbus_status_category *cat; +const struct pmbus_status_assoc *bit;struct device *dev =rdev_get_dev (rdev);struct i2c_client *client =to_i2c_client (dev->parent);struct pmbus_data *data =i2c_get_clientdata (client);@@ -2796,8 +2796,8 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsignedmutex_lock (&data->update_lock); -for (i =0 ; i <ARRAY_SIZE (pmbus_regulator_flag_map); i++) { - cat = &pmbus_regulator_flag_map[i]; +for (i =0 ; i <ARRAY_SIZE (pmbus_status_flag_map); i++) { + cat = &pmbus_status_flag_map[i];if (!(func & cat->func))continue ;base-commit:
774dccfe77dcd8cf1d82df1f61fe95a720dc76e4
Hi Guenter,
Quoted 6 lines · Guenter Roeck
Quoted 5 lines · Naresh Solanki
Move the PMBus status flag map (
pmbus_regulator_status_flag_map) outside of the regulator #if block and update the associated variable/struct name to reflect a generic PMBus status. Also retain the regulator error flag for use in determining regulator specific error.
Quoted 7 lines
Quoted 4 lines
This will make the PMBus status flag map more versatile and easier to incorporate into different contexts and functions.
Signed-off-by Naresh Solanki <[email protected]>Sorry, I don't see the point of moving a structure including regulator error codes outside regulator code.
I'm working on adding pmbus irq handler.
Since irq handler is regulator independent, this change is needed.
Naresh
Quoted 139 lines
Guenter
Quoted 135 lines
---
drivers/hwmon/pmbus/pmbus_core.c| 94 ++++++++++++++++----------------1 file changed, 47 insertions(+), 47 deletions(-)drivers/hwmon/pmbus/pmbus_core.c +28
-0@@ -2692,6 +2692,49 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, return 0; } +/* A PMBus status flag and the corresponding REGULATOR_ERROR_* flag */ +struct pmbus_status_assoc { + int pflag, rflag; +}; + +/* PMBus->regulator bit mappings for a PMBus status register */ +struct pmbus_status_category { + int func; + int reg; + const struct pmbus_status_assoc *bits; /* zero-terminated */ +}; + +static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[] = { + { + .func = PMBUS_HAVE_STATUS_VOUT, + .reg = PMBUS_STATUS_VOUT, + .bits = (const struct pmbus_status_assoc[]) { + { PB_VOLTAGE_UV_WARNING,REGULATOR_ERROR_UNDER_VOLTAGE_WARN }, + { PB_VOLTAGE_UV_FAULT, REGULATOR_ERROR_UNDER_VOLTAGE }, + { PB_VOLTAGE_OV_WARNING,REGULATOR_ERROR_OVER_VOLTAGE_WARN }, + { PB_VOLTAGE_OV_FAULT, REGULATOR_ERROR_REGULATION_OUT }, + { }, + }, + }, { + .func = PMBUS_HAVE_STATUS_IOUT, + .reg = PMBUS_STATUS_IOUT, + .bits = (const struct pmbus_status_assoc[]) { + { PB_IOUT_OC_WARNING,
REGULATOR_ERROR_OVER_CURRENT_WARN},
+ { PB_IOUT_OC_FAULT,REGULATOR_ERROR_OVER_CURRENT}, + { PB_IOUT_OC_LV_FAULT,REGULATOR_ERROR_OVER_CURRENT}, + { },
+ },
+ }, {
+ .func =PMBUS_HAVE_STATUS_TEMP,
+ .reg =PMBUS_STATUS_TEMPERATURE,
+ .bits = (const struct pmbus_status_assoc[]) {
+ { PB_TEMP_OT_WARNING,REGULATOR_ERROR_OVER_TEMP_WARN}, + { PB_TEMP_OT_FAULT,REGULATOR_ERROR_OVER_TEMP}, + { },
+ },
+ },drivers/hwmon/pmbus/pmbus_core.c +2
-0+}; +#if
IS_ENABLED(CONFIG_REGULATOR)
static intpmbus_regulator_is_enabled(struct regulator_dev *rdev){drivers/hwmon/pmbus/pmbus_core.c +0
-10@@ -2738,54 +2781,11 @@ static int pmbus_regulator_disable(struct regulator_dev *rdev) return _pmbus_regulator_on_off(rdev, 0); } -/* A PMBus status flag and the corresponding REGULATOR_ERROR_* flag */ -struct pmbus_regulator_status_assoc { - int pflag, rflag; -}; - -/* PMBus->regulator bit mappings for a PMBus status register */ -struct pmbus_regulator_status_category { - int func; - int reg; - const struct pmbus_regulator_status_assoc *bits; /*zero-terminated */
drivers/hwmon/pmbus/pmbus_core.c +0
-3-}; - -static const struct pmbus_regulator_status_categorypmbus_regulator_flag_map[] = {
- {
- .func =PMBUS_HAVE_STATUS_VOUT,
- .reg =PMBUS_STATUS_VOUT,
- .bits = (const struct pmbus_regulator_status_assoc[]) { - {PB_VOLTAGE_UV_WARNING,REGULATOR_ERROR_UNDER_VOLTAGE_WARN},
- { PB_VOLTAGE_UV_FAULT,REGULATOR_ERROR_UNDER_VOLTAGE}, - {PB_VOLTAGE_OV_WARNING,REGULATOR_ERROR_OVER_VOLTAGE_WARN},
- { PB_VOLTAGE_OV_FAULT,REGULATOR_ERROR_REGULATION_OUT}, - { },
- },
- }, {
- .func =PMBUS_HAVE_STATUS_IOUT,
- .reg =PMBUS_STATUS_IOUT,
- .bits = (const struct pmbus_regulator_status_assoc[]) { - {PB_IOUT_OC_WARNING,REGULATOR_ERROR_OVER_CURRENT_WARN},
- { PB_IOUT_OC_FAULT,REGULATOR_ERROR_OVER_CURRENT}, - { PB_IOUT_OC_LV_FAULT,REGULATOR_ERROR_OVER_CURRENT}, - { },
- },
- }, {
- .func =PMBUS_HAVE_STATUS_TEMP,
- .reg =PMBUS_STATUS_TEMPERATURE,
- .bits = (const struct pmbus_regulator_status_assoc[]) { - { PB_TEMP_OT_WARNING,REGULATOR_ERROR_OVER_TEMP_WARN}, - { PB_TEMP_OT_FAULT,REGULATOR_ERROR_OVER_TEMP}, - { },
- },
- },drivers/hwmon/pmbus/pmbus_core.c +0
-2-}; -static int
pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags){
int i, status;
- const structpmbus_regulator_status_category*cat;
- const structpmbus_regulator_status_assoc*bit;
+ const structpmbus_status_category*cat;
+ const structpmbus_status_assoc*bit;
struct device *dev =rdev_get_dev(rdev);
structi2c_client*client =to_i2c_client(dev->parent);
structpmbus_data*data =i2c_get_clientdata(client);drivers/hwmon/pmbus/pmbus_core.c +0
-0@@ -2796,8 +2796,8 @@ static intpmbus_regulator_get_error_flags(struct
regulator_dev*rdev, unsignedmutex_lock(&data->update_lock);
- for (i = 0; i <ARRAY_SIZE(pmbus_regulator_flag_map); i++) { - cat = &pmbus_regulator_flag_map[i];
+ for (i = 0; i <ARRAY_SIZE(pmbus_status_flag_map); i++) { + cat = &pmbus_status_flag_map[i];
if (!(func &cat->func))
continue;base-commit:
774dccfe77dcd8cf1d82df1f61fe95a720dc76e4
Guenter Roeck
maintainerQuoted 12 lines · Naresh Solanki
Hi Guenter,
Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Naresh Solanki
Move the PMBus status flag map (
pmbus_regulator_status_flag_map) outside of the regulator #if block and update the associated variable/struct name to reflect a generic PMBus status. Also retain the regulator error flag for use in determining regulator specific error.This will make the PMBus status flag map more versatile and easier to incorporate into different contexts and functions.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Naresh Solanki <[email protected]>Sorry, I don't see the point of moving a structure including regulator error codes outside regulator code.
I'm working on adding pmbus irq handler.
Since irq handler is regulator independent, this change is needed.
Please submit the necessary patches together. I can not accept patches introducing structural changes like this without use case.
Thanks,
Guenter