linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: ainux.wang@gmail.com, jdelvare@suse.com, corbet@lwn.net
Cc: linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
	sterlingteng@gmail.com, chenhuacai@kernel.org,
	chenhuacai@loongson.cn
Subject: Re: [PATCH v6 2/2] hwmon: (pmbus) Try use read_status() to read status register
Date: Fri, 2 Jul 2021 07:59:39 -0700	[thread overview]
Message-ID: <63862f18-ecdb-68e6-f859-20e10583e71e@roeck-us.net> (raw)
In-Reply-To: <20210702073142.15166-3-ainux.wang@gmail.com>

On 7/2/21 12:31 AM, ainux.wang@gmail.com wrote:
> From: "Ainux.Wang" <ainux.wang@gmail.com>
> 
> There is a case(like MP2949A) that the chip do not support STATUS_WORD
> and STATUS_BYTE command, but return some random data when reading.
> 
> So we should call read_status() instead of i2c_smbus_read_word_data()
> and i2c_smbus_read_byte_data(), and the chip driver should implement a
> read_word_data() function and a read_byte_data() function to return
> -ENXIO.

No, the chip driver needs to simulate at least one of the commands. That makes most
of the changes below unnecessary. We should limit complexity to where it is needed,
meaning the chip driver.

> 
> Signed-off-by: Ainux.Wang <ainux.wang@gmail.com>
> ---
>   drivers/hwmon/pmbus/pmbus_core.c | 20 +++++++++++++++-----
>   1 file changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index 776ee2237be2..d3273a20e76e 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -503,6 +503,9 @@ static int pmbus_check_status_cml(struct i2c_client *client)
>   	struct pmbus_data *data = i2c_get_clientdata(client);
>   	int status, status2;
>   
> +	if (!data->read_status)
> +		return -EINVAL;
> +

Unnecessary.

>   	status = data->read_status(client, -1);
>   	if (status < 0 || (status & PB_STATUS_CML)) {
>   		status2 = _pmbus_read_byte_data(client, -1, PMBUS_STATUS_CML);
> @@ -534,6 +537,9 @@ static bool pmbus_check_status_register(struct i2c_client *client, int page)
>   	int status;
>   	struct pmbus_data *data = i2c_get_clientdata(client);
>   
> +	if (!data->read_status)
> +		return false;
> +

Unnecessary.

>   	status = data->read_status(client, page);
>   	if (status >= 0 && !(data->flags & PMBUS_SKIP_STATUS_CHECK) &&
>   	    (status & PB_STATUS_CML)) {
> @@ -573,6 +579,8 @@ static int pmbus_get_status(struct i2c_client *client, int page, int reg)
>   
>   	switch (reg) {
>   	case PMBUS_STATUS_WORD:
> +		if (!data->read_status)
> +			return -EINVAL;

Unnecessary.

>   		status = data->read_status(client, page);
>   		break;
>   	default:
> @@ -2306,16 +2314,15 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
>   	/*
>   	 * Some PMBus chips don't support PMBUS_STATUS_WORD, so try
>   	 * to use PMBUS_STATUS_BYTE instead if that is the case.
> -	 * Bail out if both registers are not supported.
>   	 */
>   	data->read_status = pmbus_read_status_word;
> -	ret = i2c_smbus_read_word_data(client, PMBUS_STATUS_WORD);
> +	ret = data->read_status(client, -1);

This ...

>   	if (ret < 0 || ret == 0xffff) {
>   		data->read_status = pmbus_read_status_byte;
> -		ret = i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE);
> +		ret = data->read_status(client, -1);

and this are the only two changes needed.

>   		if (ret < 0 || ret == 0xff) {
> -			dev_err(dev, "PMBus status register not found\n");
> -			return -ENODEV;
> +			/* Both registers are not supported. */
> +			data->read_status = NULL;

Unnecessary.

>   		}
>   	} else {
>   		data->has_status_word = true;
> @@ -2484,6 +2491,9 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
>   	struct pmbus_debugfs_entry *entry = data;
>   	struct pmbus_data *pdata = i2c_get_clientdata(entry->client);
>   
> +	if (!pdata->read_status)
> +		return -EINVAL;
> +
Unnecessary.

>   	rc = pdata->read_status(entry->client, entry->page);
>   	if (rc < 0)
>   		return rc;
> 


      reply	other threads:[~2021-07-02 14:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-02  7:31 [PATCH v6 0/2] hwmon: (pmbus) Add support for MPS MP2949A ainux.wang
2021-07-02  7:31 ` [PATCH v6 1/2] " ainux.wang
2021-07-02 14:59   ` Guenter Roeck
2021-07-02  7:31 ` [PATCH v6 2/2] hwmon: (pmbus) Try use read_status() to read status register ainux.wang
2021-07-02 14:59   ` Guenter Roeck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=63862f18-ecdb-68e6-f859-20e10583e71e@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=ainux.wang@gmail.com \
    --cc=chenhuacai@kernel.org \
    --cc=chenhuacai@loongson.cn \
    --cc=corbet@lwn.net \
    --cc=jdelvare@suse.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sterlingteng@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).