* [PATCH v2] eeprom: at24: fix I2C device selection for runtime PM
@ 2017-12-01 18:37 Sven Van Asbroeck
2017-12-02 14:48 ` Sakari Ailus
0 siblings, 1 reply; 3+ messages in thread
From: Sven Van Asbroeck @ 2017-12-01 18:37 UTC (permalink / raw)
To: svendev, linux-kernel, linux-i2c; +Cc: divagar.mohandass, sakari.ailus, brgl
From: Sakari Ailus <sakari.ailus@linux.intel.com>
The at24 driver creates dummy I2C devices to access offsets in the chip
that are outside the area supported using a single I2C address. It is not
meaningful to use runtime PM to such devices; the system firmware (ACPI)
does not know about these devices nor runtime PM was enabled for them.
Always use the real device instead of the dummy ones.
Fixes: 98e8201039af ("eeprom: at24: enable runtime pm support")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Tested-by: Sven Van Asbroeck on a 24AA16/24LC16B <svendev@arcx.com>
[Bartosz: rebased on top of previous fixes for 4.15, tweaked the
commit message]
[Sven: fixed Bartosz's rebase]
Signed-off-by: Sven Van Asbroeck <svendev@arcx.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
drivers/misc/eeprom/at24.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 305a7a4..20b4f26 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -562,7 +562,7 @@ static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf,
static int at24_read(void *priv, unsigned int off, void *val, size_t count)
{
struct at24_data *at24 = priv;
- struct i2c_client *client;
+ struct device *dev = &at24->client[0]->dev;
char *buf = val;
int ret;
@@ -572,11 +572,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
if (off + count > at24->chip.byte_len)
return -EINVAL;
- client = at24_translate_offset(at24, &off);
-
- ret = pm_runtime_get_sync(&client->dev);
+ ret = pm_runtime_get_sync(dev);
if (ret < 0) {
- pm_runtime_put_noidle(&client->dev);
+ pm_runtime_put_noidle(dev);
return ret;
}
@@ -592,7 +590,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
status = at24->read_func(at24, buf, off, count);
if (status < 0) {
mutex_unlock(&at24->lock);
- pm_runtime_put(&client->dev);
+ pm_runtime_put(dev);
return status;
}
buf += status;
@@ -602,7 +600,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
mutex_unlock(&at24->lock);
- pm_runtime_put(&client->dev);
+ pm_runtime_put(dev);
return 0;
}
@@ -610,7 +608,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
static int at24_write(void *priv, unsigned int off, void *val, size_t count)
{
struct at24_data *at24 = priv;
- struct i2c_client *client;
+ struct device *dev = &at24->client[0]->dev;
char *buf = val;
int ret;
@@ -620,11 +618,9 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
if (off + count > at24->chip.byte_len)
return -EINVAL;
- client = at24_translate_offset(at24, &off);
-
- ret = pm_runtime_get_sync(&client->dev);
+ ret = pm_runtime_get_sync(dev);
if (ret < 0) {
- pm_runtime_put_noidle(&client->dev);
+ pm_runtime_put_noidle(dev);
return ret;
}
@@ -640,7 +636,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
status = at24->write_func(at24, buf, off, count);
if (status < 0) {
mutex_unlock(&at24->lock);
- pm_runtime_put(&client->dev);
+ pm_runtime_put(dev);
return status;
}
buf += status;
@@ -650,7 +646,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
mutex_unlock(&at24->lock);
- pm_runtime_put(&client->dev);
+ pm_runtime_put(dev);
return 0;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] eeprom: at24: fix I2C device selection for runtime PM
2017-12-01 18:37 [PATCH v2] eeprom: at24: fix I2C device selection for runtime PM Sven Van Asbroeck
@ 2017-12-02 14:48 ` Sakari Ailus
2017-12-03 19:59 ` Bartosz Golaszewski
0 siblings, 1 reply; 3+ messages in thread
From: Sakari Ailus @ 2017-12-02 14:48 UTC (permalink / raw)
To: Sven Van Asbroeck; +Cc: linux-kernel, linux-i2c, divagar.mohandass, brgl
Hi,
On Fri, Dec 01, 2017 at 01:37:12PM -0500, Sven Van Asbroeck wrote:
> From: Sakari Ailus <sakari.ailus@linux.intel.com>
>
> The at24 driver creates dummy I2C devices to access offsets in the chip
> that are outside the area supported using a single I2C address. It is not
> meaningful to use runtime PM to such devices; the system firmware (ACPI)
> does not know about these devices nor runtime PM was enabled for them.
> Always use the real device instead of the dummy ones.
>
> Fixes: 98e8201039af ("eeprom: at24: enable runtime pm support")
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> Tested-by: Sven Van Asbroeck on a 24AA16/24LC16B <svendev@arcx.com>
> [Bartosz: rebased on top of previous fixes for 4.15, tweaked the
> commit message]
> [Sven: fixed Bartosz's rebase]
> Signed-off-by: Sven Van Asbroeck <svendev@arcx.com>
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
I presume this is the final one. Yeah, the client variable was effectively
unused in the earlier version. Seems good to me.
> ---
> drivers/misc/eeprom/at24.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index 305a7a4..20b4f26 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -562,7 +562,7 @@ static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf,
> static int at24_read(void *priv, unsigned int off, void *val, size_t count)
> {
> struct at24_data *at24 = priv;
> - struct i2c_client *client;
> + struct device *dev = &at24->client[0]->dev;
> char *buf = val;
> int ret;
>
> @@ -572,11 +572,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
> if (off + count > at24->chip.byte_len)
> return -EINVAL;
>
> - client = at24_translate_offset(at24, &off);
> -
> - ret = pm_runtime_get_sync(&client->dev);
> + ret = pm_runtime_get_sync(dev);
> if (ret < 0) {
> - pm_runtime_put_noidle(&client->dev);
> + pm_runtime_put_noidle(dev);
> return ret;
> }
>
> @@ -592,7 +590,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
> status = at24->read_func(at24, buf, off, count);
> if (status < 0) {
> mutex_unlock(&at24->lock);
> - pm_runtime_put(&client->dev);
> + pm_runtime_put(dev);
> return status;
> }
> buf += status;
> @@ -602,7 +600,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
>
> mutex_unlock(&at24->lock);
>
> - pm_runtime_put(&client->dev);
> + pm_runtime_put(dev);
>
> return 0;
> }
> @@ -610,7 +608,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
> static int at24_write(void *priv, unsigned int off, void *val, size_t count)
> {
> struct at24_data *at24 = priv;
> - struct i2c_client *client;
> + struct device *dev = &at24->client[0]->dev;
> char *buf = val;
> int ret;
>
> @@ -620,11 +618,9 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
> if (off + count > at24->chip.byte_len)
> return -EINVAL;
>
> - client = at24_translate_offset(at24, &off);
> -
> - ret = pm_runtime_get_sync(&client->dev);
> + ret = pm_runtime_get_sync(dev);
> if (ret < 0) {
> - pm_runtime_put_noidle(&client->dev);
> + pm_runtime_put_noidle(dev);
> return ret;
> }
>
> @@ -640,7 +636,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
> status = at24->write_func(at24, buf, off, count);
> if (status < 0) {
> mutex_unlock(&at24->lock);
> - pm_runtime_put(&client->dev);
> + pm_runtime_put(dev);
> return status;
> }
> buf += status;
> @@ -650,7 +646,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
>
> mutex_unlock(&at24->lock);
>
> - pm_runtime_put(&client->dev);
> + pm_runtime_put(dev);
>
> return 0;
> }
> --
> 1.9.1
>
--
Sakari Ailus
sakari.ailus@linux.intel.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] eeprom: at24: fix I2C device selection for runtime PM
2017-12-02 14:48 ` Sakari Ailus
@ 2017-12-03 19:59 ` Bartosz Golaszewski
0 siblings, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2017-12-03 19:59 UTC (permalink / raw)
To: Sakari Ailus
Cc: Sven Van Asbroeck, linux-kernel, linux-i2c, divagar.mohandass
2017-12-02 15:48 GMT+01:00 Sakari Ailus <sakari.ailus@linux.intel.com>:
> Hi,
>
> On Fri, Dec 01, 2017 at 01:37:12PM -0500, Sven Van Asbroeck wrote:
>> From: Sakari Ailus <sakari.ailus@linux.intel.com>
>>
>> The at24 driver creates dummy I2C devices to access offsets in the chip
>> that are outside the area supported using a single I2C address. It is not
>> meaningful to use runtime PM to such devices; the system firmware (ACPI)
>> does not know about these devices nor runtime PM was enabled for them.
>> Always use the real device instead of the dummy ones.
>>
>> Fixes: 98e8201039af ("eeprom: at24: enable runtime pm support")
>> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
>> Tested-by: Sven Van Asbroeck on a 24AA16/24LC16B <svendev@arcx.com>
>> [Bartosz: rebased on top of previous fixes for 4.15, tweaked the
>> commit message]
>> [Sven: fixed Bartosz's rebase]
>> Signed-off-by: Sven Van Asbroeck <svendev@arcx.com>
>> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
>
> I presume this is the final one. Yeah, the client variable was effectively
> unused in the earlier version. Seems good to me.
>
>> ---
>> drivers/misc/eeprom/at24.c | 24 ++++++++++--------------
>> 1 file changed, 10 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
>> index 305a7a4..20b4f26 100644
>> --- a/drivers/misc/eeprom/at24.c
>> +++ b/drivers/misc/eeprom/at24.c
>> @@ -562,7 +562,7 @@ static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf,
>> static int at24_read(void *priv, unsigned int off, void *val, size_t count)
>> {
>> struct at24_data *at24 = priv;
>> - struct i2c_client *client;
>> + struct device *dev = &at24->client[0]->dev;
>> char *buf = val;
>> int ret;
>>
>> @@ -572,11 +572,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
>> if (off + count > at24->chip.byte_len)
>> return -EINVAL;
>>
>> - client = at24_translate_offset(at24, &off);
>> -
>> - ret = pm_runtime_get_sync(&client->dev);
>> + ret = pm_runtime_get_sync(dev);
>> if (ret < 0) {
>> - pm_runtime_put_noidle(&client->dev);
>> + pm_runtime_put_noidle(dev);
>> return ret;
>> }
>>
>> @@ -592,7 +590,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
>> status = at24->read_func(at24, buf, off, count);
>> if (status < 0) {
>> mutex_unlock(&at24->lock);
>> - pm_runtime_put(&client->dev);
>> + pm_runtime_put(dev);
>> return status;
>> }
>> buf += status;
>> @@ -602,7 +600,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
>>
>> mutex_unlock(&at24->lock);
>>
>> - pm_runtime_put(&client->dev);
>> + pm_runtime_put(dev);
>>
>> return 0;
>> }
>> @@ -610,7 +608,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
>> static int at24_write(void *priv, unsigned int off, void *val, size_t count)
>> {
>> struct at24_data *at24 = priv;
>> - struct i2c_client *client;
>> + struct device *dev = &at24->client[0]->dev;
>> char *buf = val;
>> int ret;
>>
>> @@ -620,11 +618,9 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
>> if (off + count > at24->chip.byte_len)
>> return -EINVAL;
>>
>> - client = at24_translate_offset(at24, &off);
>> -
>> - ret = pm_runtime_get_sync(&client->dev);
>> + ret = pm_runtime_get_sync(dev);
>> if (ret < 0) {
>> - pm_runtime_put_noidle(&client->dev);
>> + pm_runtime_put_noidle(dev);
>> return ret;
>> }
>>
>> @@ -640,7 +636,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
>> status = at24->write_func(at24, buf, off, count);
>> if (status < 0) {
>> mutex_unlock(&at24->lock);
>> - pm_runtime_put(&client->dev);
>> + pm_runtime_put(dev);
>> return status;
>> }
>> buf += status;
>> @@ -650,7 +646,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
>>
>> mutex_unlock(&at24->lock);
>>
>> - pm_runtime_put(&client->dev);
>> + pm_runtime_put(dev);
>>
>> return 0;
>> }
>> --
>> 1.9.1
>>
>
> --
> Sakari Ailus
> sakari.ailus@linux.intel.com
Sven informed me in private that the bug was actually triggered by a
HW issue on the board he was using and not the code itself, but I
believe this fix makes sense nevertheless, so I queued it for
4.15-rc3. Thanks!
Bartosz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-12-03 20:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-01 18:37 [PATCH v2] eeprom: at24: fix I2C device selection for runtime PM Sven Van Asbroeck
2017-12-02 14:48 ` Sakari Ailus
2017-12-03 19:59 ` Bartosz Golaszewski
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).