[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230211150749.GA202703@roeck-us.net>
Date: Sat, 11 Feb 2023 07:07:49 -0800
From: Guenter Roeck <linux@...ck-us.net>
To: Naresh Solanki <naresh.solanki@...ements.com>
Cc: Jean Delvare <jdelvare@...e.com>, linux-hwmon@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/4] hwmon: (pmbus/core) Generalise pmbus get status
On Tue, Feb 07, 2023 at 01:02:39PM +0100, Naresh Solanki wrote:
> Add function pmbus get status that can be used to get both pmbus
> specific status & regulator status
>
> Signed-off-by: Naresh Solanki <Naresh.Solanki@...ements.com>
> ...
> Changes in V2:
> - Add __maybe_unused attribute for pmbus_get_status function
> - Remove unrelated changes
> ---
> drivers/hwmon/pmbus/pmbus_core.c | 118 +++++++++++++++++--------------
> 1 file changed, 66 insertions(+), 52 deletions(-)
>
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index 1b70cf3be313..5ccae8126a56 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -2735,61 +2735,14 @@ static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[]
> },
> };
>
> -#if IS_ENABLED(CONFIG_REGULATOR)
> -static int pmbus_regulator_is_enabled(struct regulator_dev *rdev)
> -{
> - struct device *dev = rdev_get_dev(rdev);
> - struct i2c_client *client = to_i2c_client(dev->parent);
> - struct pmbus_data *data = i2c_get_clientdata(client);
> - u8 page = rdev_get_id(rdev);
> - int ret;
> -
> - mutex_lock(&data->update_lock);
> - ret = _pmbus_read_byte_data(client, page, PMBUS_OPERATION);
> - mutex_unlock(&data->update_lock);
> -
> - if (ret < 0)
> - return ret;
> -
> - return !!(ret & PB_OPERATION_CONTROL_ON);
> -}
> -
> -static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable)
> -{
> - struct device *dev = rdev_get_dev(rdev);
> - struct i2c_client *client = to_i2c_client(dev->parent);
> - struct pmbus_data *data = i2c_get_clientdata(client);
> - u8 page = rdev_get_id(rdev);
> - int ret;
> -
> - mutex_lock(&data->update_lock);
> - ret = pmbus_update_byte_data(client, page, PMBUS_OPERATION,
> - PB_OPERATION_CONTROL_ON,
> - enable ? PB_OPERATION_CONTROL_ON : 0);
> - mutex_unlock(&data->update_lock);
> -
> - return ret;
> -}
> -
> -static int pmbus_regulator_enable(struct regulator_dev *rdev)
> -{
> - return _pmbus_regulator_on_off(rdev, 1);
> -}
> -
> -static int pmbus_regulator_disable(struct regulator_dev *rdev)
> -{
> - return _pmbus_regulator_on_off(rdev, 0);
> -}
>
> -static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags)
> +static int __maybe_unused pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flags)
> {
> - int i, status;
> + int i, status, ret;
> 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);
> - u8 page = rdev_get_id(rdev);
> + struct device *dev = data->dev;
> + struct i2c_client *client = to_i2c_client(dev);
> int func = data->info->func[page];
>
> *flags = 0;
> @@ -2827,7 +2780,13 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned
> if (status < 0)
> return status;
>
> - if (pmbus_regulator_is_enabled(rdev)) {
> + mutex_lock(&data->update_lock);
> + ret = _pmbus_read_byte_data(client, page, PMBUS_OPERATION);
> + mutex_unlock(&data->update_lock);
> + if (ret < 0)
> + return status;
> +
> + if (ret & PB_OPERATION_CONTROL_ON) {
This code is now executed twice. Please keep the original function,
just rename it to pmbus_is_enabled() or similar, then call it from
pmbus_regulator_is_enabled() which then just needs to adjust the
parameter (and maybe pass 'dev' as argument).
> if (status & PB_STATUS_OFF)
> *flags |= REGULATOR_ERROR_FAIL;
>
> @@ -2855,6 +2814,61 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned
> return 0;
> }
>
> +#if IS_ENABLED(CONFIG_REGULATOR)
> +static int pmbus_regulator_is_enabled(struct regulator_dev *rdev)
> +{
> + struct device *dev = rdev_get_dev(rdev);
> + struct i2c_client *client = to_i2c_client(dev->parent);
> + struct pmbus_data *data = i2c_get_clientdata(client);
> + u8 page = rdev_get_id(rdev);
> + int ret;
> +
> + mutex_lock(&data->update_lock);
> + ret = _pmbus_read_byte_data(client, page, PMBUS_OPERATION);
> + mutex_unlock(&data->update_lock);
> +
> + if (ret < 0)
> + return ret;
> +
> + return !!(ret & PB_OPERATION_CONTROL_ON);
This could then be as simple as
return pmbus_is_enabled(rdev_get_dev(rdev));
Thanks,
Guenter
> +}
> +
> +static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable)
> +{
> + struct device *dev = rdev_get_dev(rdev);
> + struct i2c_client *client = to_i2c_client(dev->parent);
> + struct pmbus_data *data = i2c_get_clientdata(client);
> + u8 page = rdev_get_id(rdev);
> + int ret;
> +
> + mutex_lock(&data->update_lock);
> + ret = pmbus_update_byte_data(client, page, PMBUS_OPERATION,
> + PB_OPERATION_CONTROL_ON,
> + enable ? PB_OPERATION_CONTROL_ON : 0);
> + mutex_unlock(&data->update_lock);
> +
> + return ret;
> +}
> +
> +static int pmbus_regulator_enable(struct regulator_dev *rdev)
> +{
> + return _pmbus_regulator_on_off(rdev, 1);
> +}
> +
> +static int pmbus_regulator_disable(struct regulator_dev *rdev)
> +{
> + return _pmbus_regulator_on_off(rdev, 0);
> +}
> +
> +static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags)
> +{
> + struct device *dev = rdev_get_dev(rdev);
> + struct i2c_client *client = to_i2c_client(dev->parent);
> + struct pmbus_data *data = i2c_get_clientdata(client);
> +
> + return pmbus_get_flags(data, rdev_get_id(rdev), flags);
> +}
> +
> static int pmbus_regulator_get_status(struct regulator_dev *rdev)
> {
> struct device *dev = rdev_get_dev(rdev);
Powered by blists - more mailing lists