From: Wei Ni <wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Cc: "linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org"
<linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>,
"thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"
<thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org"
<lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org>,
"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH v3 1/4] hwmon: (lm90) split set&show temp as common codes
Date: Mon, 15 Jul 2013 14:05:08 +0800 [thread overview]
Message-ID: <51E39114.505@nvidia.com> (raw)
In-Reply-To: <20130712152615.23464a6b-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
On 07/12/2013 09:26 PM, Jean Delvare wrote:
> Hi Wei, Guenter,
>
> Guenter, thanks for reviewing the previous version of this patch.
>
> Wei, thanks for incorporating review feedback and posting updated
> patches so quickly, this is very appreciated, even though I'm too busy
> these days to be that fast on my end, sorry about that.
>
> On Fri, 12 Jul 2013 15:48:04 +0800, Wei Ni wrote:
>> Split set&show temp codes as common functions, so we can use it directly when
>> implement linux thermal framework.
>
> Can I see a recent version of the code which will need this change? It
> makes no sense to apply this first part which makes the code more
> complex with no benefit, without the second part which needs it, so
> they should be applied together or not at all.
In my RFC patches, there had many codes about thermal fw, which need
this patch, so I put them together.
And now I split the RFC patches, this series is preparing to use the
thermal fw.
As you said, I want to register lm90 as the thermal zone device, it need
to hook some callback, such as .get_temp. if apply this patch, I can
write the .get_temp simply, something like:
+static int lm90_read_temp2_temp(struct thermal_zone_device *thz,
unsigned long *temp)
+{
+ struct lm90_data *data = thz->devdata;
+ struct i2c_client *client = to_i2c_client(data->hwmon_dev->parent);
+ struct device *dev = &client->dev;+
+
+ *temp = (long)read_temp11(dev, TEMP11_REMOTE_TEMP);
+
+ return 0;
+}
+
+static struct thermal_zone_device_ops remote_ops = {
+ .get_temp = lm90_read_temp2_temp,
+};
If without this patch, I have to rewrite the lm90_read_temp2_temp(),
which almost same as the show_temp11(), I think it's not good. When use
this patch and following 3/3 patch, the code will be more readable and
clear.
Anyway, if you want, I can send this patch as a separate one. :)
>
> One thing I am a little worried about (but maybe I'm wrong) is that I
> seem to understand you want to register every LM90-like chip as both a
> hwmon device and two thermal devices. I seem to recall that every
> thermal device is also exposed automatically as a virtual hwmon
> device, is that correct? If so we will be presenting the same values
> twice to libsensors, which would be confusing.
>
>> Signed-off-by: Wei Ni <wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>> ---
>> drivers/hwmon/lm90.c | 112 +++++++++++++++++++++++++++++++-------------------
>> 1 file changed, 69 insertions(+), 43 deletions(-)
>
> The code changes look good, however I have one suggestion for
> improvement (plus a minor cleanup request):
>
>> diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
>> index 8eeb141..5f30f90 100644
>> --- a/drivers/hwmon/lm90.c
>> +++ b/drivers/hwmon/lm90.c
>> (...)
>> -static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
>> - const char *buf, size_t count)
>> (...)
>> +static void write_temp8(struct device *dev, int index, long val)
>> {
>> static const u8 reg[8] = {
>> LM90_REG_W_LOCAL_LOW,
>> @@ -737,60 +742,73 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
>> MAX6659_REG_W_REMOTE_EMERG,
>> };
>>
>> - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>> struct i2c_client *client = to_i2c_client(dev);
>> struct lm90_data *data = i2c_get_clientdata(client);
>> - int nr = attr->index;
>> - long val;
>> - int err;
>> -
>> - err = kstrtol(buf, 10, &val);
>> - if (err < 0)
>> - return err;
>>
>> /* +16 degrees offset for temp2 for the LM99 */
>> - if (data->kind == lm99 && attr->index == 3)
>> + if (data->kind == lm99 && index == 3)
>> val -= 16000;
>>
>> mutex_lock(&data->update_lock);
>> if (data->kind == adt7461)
>> - data->temp8[nr] = temp_to_u8_adt7461(data, val);
>> + data->temp8[index] = temp_to_u8_adt7461(data, val);
>> else if (data->kind == max6646)
>> - data->temp8[nr] = temp_to_u8(val);
>> + data->temp8[index] = temp_to_u8(val);
>> else
>> - data->temp8[nr] = temp_to_s8(val);
>> + data->temp8[index] = temp_to_s8(val);
>>
>> - lm90_select_remote_channel(client, data, nr >= 6);
>> - i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
>> + lm90_select_remote_channel(client, data, index >= 6);
>> + i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]);
>
> This write could fail. So far the lm90 driver has failed to handle
> register write errors at all, and I will take the blame for that. But
> if we want to integrate properly with the thermal subsystem, I suspect
> we will have to properly report errors. So it might be the right time
> to catch and return write errors here. Then set_temp8() below could
> return it to user-space (either in this patch or in a separate patch,
> as you prefer.)
Ok, I will add error handler in my next version.
>
> And then as a next step, lm90_select_remote_channel should return
> errors as they happen as well, so that they can be transmitted to the
> caller.
>
>> lm90_select_remote_channel(client, data, 0);
>>
>> mutex_unlock(&data->update_lock);
>> +}
>> +
>> +static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
>> + const char *buf, size_t count)
>> +{
>> + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>> + int index = attr->index;
>> + long val;
>> + int err;
>> +
>> + err = kstrtol(buf, 10, &val);
>> + if (err < 0)
>> + return err;
>> +
>> + write_temp8(dev, index, val);
>> +
>> return count;
>> }
>>
>> -static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
>> - char *buf)
>> +static int read_temp11(struct device *dev, int index)
>> {
>> - struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
>> struct lm90_data *data = lm90_update_device(dev);
>> int temp;
>>
>> if (data->kind == adt7461)
>> - temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
>> + temp = temp_from_u16_adt7461(data, data->temp11[index]);
>> else if (data->kind == max6646)
>> - temp = temp_from_u16(data->temp11[attr->index]);
>> + temp = temp_from_u16(data->temp11[index]);
>> else
>> - temp = temp_from_s16(data->temp11[attr->index]);
>> + temp = temp_from_s16(data->temp11[index]);
>>
>> /* +16 degrees offset for temp2 for the LM99 */
>> - if (data->kind == lm99 && attr->index <= 2)
>> + if (data->kind == lm99 && index <= 2)
>
> There's a doubled space on this line. It isn't added by your patch, it
> was already there before, but please fix it while you're here.
Oh, you are so carefully, I will fix it :)
>
>> temp += 16000;
>>
>> - return sprintf(buf, "%d\n", temp);
>> + return temp;
>> }
>>
>> -static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> - const char *buf, size_t count)
>> (...)
>> +static void write_temp11(struct device *dev, int nr, int index, long val)
>
> Here too I would suggest returning errors from the I2C layer, and
> handling them in set_temp11() now or later.
>
>> {
>> struct {
>> u8 high;
>> @@ -804,17 +822,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
>> };
>>
>> - struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
>> struct i2c_client *client = to_i2c_client(dev);
>> struct lm90_data *data = i2c_get_clientdata(client);
>> - int nr = attr->nr;
>> - int index = attr->index;
>> - long val;
>> - int err;
>> -
>> - err = kstrtol(buf, 10, &val);
>> - if (err < 0)
>> - return err;
>>
>> /* +16 degrees offset for temp2 for the LM99 */
>> if (data->kind == lm99 && index <= 2)
>> @@ -839,6 +848,23 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> lm90_select_remote_channel(client, data, 0);
>>
>> mutex_unlock(&data->update_lock);
>> +}
>> +
>> +static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> + const char *buf, size_t count)
>> +{
>> + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
>> + int nr = attr->nr;
>> + int index = attr->index;
>> + long val;
>> + int err;
>> +
>> + err = kstrtol(buf, 10, &val);
>> + if (err < 0)
>> + return err;
>> +
>> + write_temp11(dev, nr, index, val);
>> +
>> return count;
>> }
>>
>
WARNING: multiple messages have this Message-ID (diff)
From: Wei Ni <wni@nvidia.com>
To: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Cc: "linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org"
<linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>,
"thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"
<thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org"
<lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org>,
"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [lm-sensors] [PATCH v3 1/4] hwmon: (lm90) split set&show temp as common codes
Date: Mon, 15 Jul 2013 06:05:08 +0000 [thread overview]
Message-ID: <51E39114.505@nvidia.com> (raw)
In-Reply-To: <20130712152615.23464a6b-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
On 07/12/2013 09:26 PM, Jean Delvare wrote:
> Hi Wei, Guenter,
>
> Guenter, thanks for reviewing the previous version of this patch.
>
> Wei, thanks for incorporating review feedback and posting updated
> patches so quickly, this is very appreciated, even though I'm too busy
> these days to be that fast on my end, sorry about that.
>
> On Fri, 12 Jul 2013 15:48:04 +0800, Wei Ni wrote:
>> Split set&show temp codes as common functions, so we can use it directly when
>> implement linux thermal framework.
>
> Can I see a recent version of the code which will need this change? It
> makes no sense to apply this first part which makes the code more
> complex with no benefit, without the second part which needs it, so
> they should be applied together or not at all.
In my RFC patches, there had many codes about thermal fw, which need
this patch, so I put them together.
And now I split the RFC patches, this series is preparing to use the
thermal fw.
As you said, I want to register lm90 as the thermal zone device, it need
to hook some callback, such as .get_temp. if apply this patch, I can
write the .get_temp simply, something like:
+static int lm90_read_temp2_temp(struct thermal_zone_device *thz,
unsigned long *temp)
+{
+ struct lm90_data *data = thz->devdata;
+ struct i2c_client *client = to_i2c_client(data->hwmon_dev->parent);
+ struct device *dev = &client->dev;+
+
+ *temp = (long)read_temp11(dev, TEMP11_REMOTE_TEMP);
+
+ return 0;
+}
+
+static struct thermal_zone_device_ops remote_ops = {
+ .get_temp = lm90_read_temp2_temp,
+};
If without this patch, I have to rewrite the lm90_read_temp2_temp(),
which almost same as the show_temp11(), I think it's not good. When use
this patch and following 3/3 patch, the code will be more readable and
clear.
Anyway, if you want, I can send this patch as a separate one. :)
>
> One thing I am a little worried about (but maybe I'm wrong) is that I
> seem to understand you want to register every LM90-like chip as both a
> hwmon device and two thermal devices. I seem to recall that every
> thermal device is also exposed automatically as a virtual hwmon
> device, is that correct? If so we will be presenting the same values
> twice to libsensors, which would be confusing.
>
>> Signed-off-by: Wei Ni <wni@nvidia.com>
>> ---
>> drivers/hwmon/lm90.c | 112 +++++++++++++++++++++++++++++++-------------------
>> 1 file changed, 69 insertions(+), 43 deletions(-)
>
> The code changes look good, however I have one suggestion for
> improvement (plus a minor cleanup request):
>
>> diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
>> index 8eeb141..5f30f90 100644
>> --- a/drivers/hwmon/lm90.c
>> +++ b/drivers/hwmon/lm90.c
>> (...)
>> -static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
>> - const char *buf, size_t count)
>> (...)
>> +static void write_temp8(struct device *dev, int index, long val)
>> {
>> static const u8 reg[8] = {
>> LM90_REG_W_LOCAL_LOW,
>> @@ -737,60 +742,73 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
>> MAX6659_REG_W_REMOTE_EMERG,
>> };
>>
>> - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>> struct i2c_client *client = to_i2c_client(dev);
>> struct lm90_data *data = i2c_get_clientdata(client);
>> - int nr = attr->index;
>> - long val;
>> - int err;
>> -
>> - err = kstrtol(buf, 10, &val);
>> - if (err < 0)
>> - return err;
>>
>> /* +16 degrees offset for temp2 for the LM99 */
>> - if (data->kind = lm99 && attr->index = 3)
>> + if (data->kind = lm99 && index = 3)
>> val -= 16000;
>>
>> mutex_lock(&data->update_lock);
>> if (data->kind = adt7461)
>> - data->temp8[nr] = temp_to_u8_adt7461(data, val);
>> + data->temp8[index] = temp_to_u8_adt7461(data, val);
>> else if (data->kind = max6646)
>> - data->temp8[nr] = temp_to_u8(val);
>> + data->temp8[index] = temp_to_u8(val);
>> else
>> - data->temp8[nr] = temp_to_s8(val);
>> + data->temp8[index] = temp_to_s8(val);
>>
>> - lm90_select_remote_channel(client, data, nr >= 6);
>> - i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
>> + lm90_select_remote_channel(client, data, index >= 6);
>> + i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]);
>
> This write could fail. So far the lm90 driver has failed to handle
> register write errors at all, and I will take the blame for that. But
> if we want to integrate properly with the thermal subsystem, I suspect
> we will have to properly report errors. So it might be the right time
> to catch and return write errors here. Then set_temp8() below could
> return it to user-space (either in this patch or in a separate patch,
> as you prefer.)
Ok, I will add error handler in my next version.
>
> And then as a next step, lm90_select_remote_channel should return
> errors as they happen as well, so that they can be transmitted to the
> caller.
>
>> lm90_select_remote_channel(client, data, 0);
>>
>> mutex_unlock(&data->update_lock);
>> +}
>> +
>> +static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
>> + const char *buf, size_t count)
>> +{
>> + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>> + int index = attr->index;
>> + long val;
>> + int err;
>> +
>> + err = kstrtol(buf, 10, &val);
>> + if (err < 0)
>> + return err;
>> +
>> + write_temp8(dev, index, val);
>> +
>> return count;
>> }
>>
>> -static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
>> - char *buf)
>> +static int read_temp11(struct device *dev, int index)
>> {
>> - struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
>> struct lm90_data *data = lm90_update_device(dev);
>> int temp;
>>
>> if (data->kind = adt7461)
>> - temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
>> + temp = temp_from_u16_adt7461(data, data->temp11[index]);
>> else if (data->kind = max6646)
>> - temp = temp_from_u16(data->temp11[attr->index]);
>> + temp = temp_from_u16(data->temp11[index]);
>> else
>> - temp = temp_from_s16(data->temp11[attr->index]);
>> + temp = temp_from_s16(data->temp11[index]);
>>
>> /* +16 degrees offset for temp2 for the LM99 */
>> - if (data->kind = lm99 && attr->index <= 2)
>> + if (data->kind = lm99 && index <= 2)
>
> There's a doubled space on this line. It isn't added by your patch, it
> was already there before, but please fix it while you're here.
Oh, you are so carefully, I will fix it :)
>
>> temp += 16000;
>>
>> - return sprintf(buf, "%d\n", temp);
>> + return temp;
>> }
>>
>> -static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> - const char *buf, size_t count)
>> (...)
>> +static void write_temp11(struct device *dev, int nr, int index, long val)
>
> Here too I would suggest returning errors from the I2C layer, and
> handling them in set_temp11() now or later.
>
>> {
>> struct {
>> u8 high;
>> @@ -804,17 +822,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
>> };
>>
>> - struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
>> struct i2c_client *client = to_i2c_client(dev);
>> struct lm90_data *data = i2c_get_clientdata(client);
>> - int nr = attr->nr;
>> - int index = attr->index;
>> - long val;
>> - int err;
>> -
>> - err = kstrtol(buf, 10, &val);
>> - if (err < 0)
>> - return err;
>>
>> /* +16 degrees offset for temp2 for the LM99 */
>> if (data->kind = lm99 && index <= 2)
>> @@ -839,6 +848,23 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> lm90_select_remote_channel(client, data, 0);
>>
>> mutex_unlock(&data->update_lock);
>> +}
>> +
>> +static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> + const char *buf, size_t count)
>> +{
>> + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
>> + int nr = attr->nr;
>> + int index = attr->index;
>> + long val;
>> + int err;
>> +
>> + err = kstrtol(buf, 10, &val);
>> + if (err < 0)
>> + return err;
>> +
>> + write_temp11(dev, nr, index, val);
>> +
>> return count;
>> }
>>
>
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
WARNING: multiple messages have this Message-ID (diff)
From: Wei Ni <wni@nvidia.com>
To: Jean Delvare <khali@linux-fr.org>
Cc: "linux@roeck-us.net" <linux@roeck-us.net>,
"thierry.reding@gmail.com" <thierry.reding@gmail.com>,
"lm-sensors@lm-sensors.org" <lm-sensors@lm-sensors.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>
Subject: Re: [PATCH v3 1/4] hwmon: (lm90) split set&show temp as common codes
Date: Mon, 15 Jul 2013 14:05:08 +0800 [thread overview]
Message-ID: <51E39114.505@nvidia.com> (raw)
In-Reply-To: <20130712152615.23464a6b@endymion.delvare>
On 07/12/2013 09:26 PM, Jean Delvare wrote:
> Hi Wei, Guenter,
>
> Guenter, thanks for reviewing the previous version of this patch.
>
> Wei, thanks for incorporating review feedback and posting updated
> patches so quickly, this is very appreciated, even though I'm too busy
> these days to be that fast on my end, sorry about that.
>
> On Fri, 12 Jul 2013 15:48:04 +0800, Wei Ni wrote:
>> Split set&show temp codes as common functions, so we can use it directly when
>> implement linux thermal framework.
>
> Can I see a recent version of the code which will need this change? It
> makes no sense to apply this first part which makes the code more
> complex with no benefit, without the second part which needs it, so
> they should be applied together or not at all.
In my RFC patches, there had many codes about thermal fw, which need
this patch, so I put them together.
And now I split the RFC patches, this series is preparing to use the
thermal fw.
As you said, I want to register lm90 as the thermal zone device, it need
to hook some callback, such as .get_temp. if apply this patch, I can
write the .get_temp simply, something like:
+static int lm90_read_temp2_temp(struct thermal_zone_device *thz,
unsigned long *temp)
+{
+ struct lm90_data *data = thz->devdata;
+ struct i2c_client *client = to_i2c_client(data->hwmon_dev->parent);
+ struct device *dev = &client->dev;+
+
+ *temp = (long)read_temp11(dev, TEMP11_REMOTE_TEMP);
+
+ return 0;
+}
+
+static struct thermal_zone_device_ops remote_ops = {
+ .get_temp = lm90_read_temp2_temp,
+};
If without this patch, I have to rewrite the lm90_read_temp2_temp(),
which almost same as the show_temp11(), I think it's not good. When use
this patch and following 3/3 patch, the code will be more readable and
clear.
Anyway, if you want, I can send this patch as a separate one. :)
>
> One thing I am a little worried about (but maybe I'm wrong) is that I
> seem to understand you want to register every LM90-like chip as both a
> hwmon device and two thermal devices. I seem to recall that every
> thermal device is also exposed automatically as a virtual hwmon
> device, is that correct? If so we will be presenting the same values
> twice to libsensors, which would be confusing.
>
>> Signed-off-by: Wei Ni <wni@nvidia.com>
>> ---
>> drivers/hwmon/lm90.c | 112 +++++++++++++++++++++++++++++++-------------------
>> 1 file changed, 69 insertions(+), 43 deletions(-)
>
> The code changes look good, however I have one suggestion for
> improvement (plus a minor cleanup request):
>
>> diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
>> index 8eeb141..5f30f90 100644
>> --- a/drivers/hwmon/lm90.c
>> +++ b/drivers/hwmon/lm90.c
>> (...)
>> -static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
>> - const char *buf, size_t count)
>> (...)
>> +static void write_temp8(struct device *dev, int index, long val)
>> {
>> static const u8 reg[8] = {
>> LM90_REG_W_LOCAL_LOW,
>> @@ -737,60 +742,73 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
>> MAX6659_REG_W_REMOTE_EMERG,
>> };
>>
>> - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>> struct i2c_client *client = to_i2c_client(dev);
>> struct lm90_data *data = i2c_get_clientdata(client);
>> - int nr = attr->index;
>> - long val;
>> - int err;
>> -
>> - err = kstrtol(buf, 10, &val);
>> - if (err < 0)
>> - return err;
>>
>> /* +16 degrees offset for temp2 for the LM99 */
>> - if (data->kind == lm99 && attr->index == 3)
>> + if (data->kind == lm99 && index == 3)
>> val -= 16000;
>>
>> mutex_lock(&data->update_lock);
>> if (data->kind == adt7461)
>> - data->temp8[nr] = temp_to_u8_adt7461(data, val);
>> + data->temp8[index] = temp_to_u8_adt7461(data, val);
>> else if (data->kind == max6646)
>> - data->temp8[nr] = temp_to_u8(val);
>> + data->temp8[index] = temp_to_u8(val);
>> else
>> - data->temp8[nr] = temp_to_s8(val);
>> + data->temp8[index] = temp_to_s8(val);
>>
>> - lm90_select_remote_channel(client, data, nr >= 6);
>> - i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
>> + lm90_select_remote_channel(client, data, index >= 6);
>> + i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]);
>
> This write could fail. So far the lm90 driver has failed to handle
> register write errors at all, and I will take the blame for that. But
> if we want to integrate properly with the thermal subsystem, I suspect
> we will have to properly report errors. So it might be the right time
> to catch and return write errors here. Then set_temp8() below could
> return it to user-space (either in this patch or in a separate patch,
> as you prefer.)
Ok, I will add error handler in my next version.
>
> And then as a next step, lm90_select_remote_channel should return
> errors as they happen as well, so that they can be transmitted to the
> caller.
>
>> lm90_select_remote_channel(client, data, 0);
>>
>> mutex_unlock(&data->update_lock);
>> +}
>> +
>> +static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
>> + const char *buf, size_t count)
>> +{
>> + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>> + int index = attr->index;
>> + long val;
>> + int err;
>> +
>> + err = kstrtol(buf, 10, &val);
>> + if (err < 0)
>> + return err;
>> +
>> + write_temp8(dev, index, val);
>> +
>> return count;
>> }
>>
>> -static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
>> - char *buf)
>> +static int read_temp11(struct device *dev, int index)
>> {
>> - struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
>> struct lm90_data *data = lm90_update_device(dev);
>> int temp;
>>
>> if (data->kind == adt7461)
>> - temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
>> + temp = temp_from_u16_adt7461(data, data->temp11[index]);
>> else if (data->kind == max6646)
>> - temp = temp_from_u16(data->temp11[attr->index]);
>> + temp = temp_from_u16(data->temp11[index]);
>> else
>> - temp = temp_from_s16(data->temp11[attr->index]);
>> + temp = temp_from_s16(data->temp11[index]);
>>
>> /* +16 degrees offset for temp2 for the LM99 */
>> - if (data->kind == lm99 && attr->index <= 2)
>> + if (data->kind == lm99 && index <= 2)
>
> There's a doubled space on this line. It isn't added by your patch, it
> was already there before, but please fix it while you're here.
Oh, you are so carefully, I will fix it :)
>
>> temp += 16000;
>>
>> - return sprintf(buf, "%d\n", temp);
>> + return temp;
>> }
>>
>> -static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> - const char *buf, size_t count)
>> (...)
>> +static void write_temp11(struct device *dev, int nr, int index, long val)
>
> Here too I would suggest returning errors from the I2C layer, and
> handling them in set_temp11() now or later.
>
>> {
>> struct {
>> u8 high;
>> @@ -804,17 +822,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
>> };
>>
>> - struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
>> struct i2c_client *client = to_i2c_client(dev);
>> struct lm90_data *data = i2c_get_clientdata(client);
>> - int nr = attr->nr;
>> - int index = attr->index;
>> - long val;
>> - int err;
>> -
>> - err = kstrtol(buf, 10, &val);
>> - if (err < 0)
>> - return err;
>>
>> /* +16 degrees offset for temp2 for the LM99 */
>> if (data->kind == lm99 && index <= 2)
>> @@ -839,6 +848,23 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> lm90_select_remote_channel(client, data, 0);
>>
>> mutex_unlock(&data->update_lock);
>> +}
>> +
>> +static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
>> + const char *buf, size_t count)
>> +{
>> + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
>> + int nr = attr->nr;
>> + int index = attr->index;
>> + long val;
>> + int err;
>> +
>> + err = kstrtol(buf, 10, &val);
>> + if (err < 0)
>> + return err;
>> +
>> + write_temp11(dev, nr, index, val);
>> +
>> return count;
>> }
>>
>
next prev parent reply other threads:[~2013-07-15 6:05 UTC|newest]
Thread overview: 126+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-12 7:48 [PATCH v3 0/4] Lm90 Enhancements Wei Ni
2013-07-12 7:48 ` Wei Ni
2013-07-12 7:48 ` [lm-sensors] " Wei Ni
2013-07-12 7:48 ` [PATCH v3 1/4] hwmon: (lm90) split set&show temp as common codes Wei Ni
2013-07-12 7:48 ` Wei Ni
2013-07-12 7:48 ` [lm-sensors] " Wei Ni
[not found] ` <1373615287-18502-2-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-12 13:26 ` Jean Delvare
2013-07-12 13:26 ` Jean Delvare
2013-07-12 13:26 ` [lm-sensors] " Jean Delvare
[not found] ` <20130712152615.23464a6b-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-07-12 13:50 ` Guenter Roeck
2013-07-12 13:50 ` Guenter Roeck
2013-07-12 13:50 ` [lm-sensors] " Guenter Roeck
[not found] ` <20130712135000.GA3386-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2013-07-12 14:30 ` Jean Delvare
2013-07-12 14:30 ` Jean Delvare
2013-07-12 14:30 ` [lm-sensors] " Jean Delvare
2013-07-12 14:40 ` Guenter Roeck
2013-07-12 14:40 ` [lm-sensors] " Guenter Roeck
2013-07-15 6:25 ` Wei Ni
2013-07-15 6:25 ` Wei Ni
2013-07-15 6:25 ` [lm-sensors] " Wei Ni
2013-07-15 7:24 ` Jean Delvare
2013-07-15 7:24 ` Jean Delvare
2013-07-15 7:24 ` [lm-sensors] " Jean Delvare
[not found] ` <20130715092415.6d082aa2-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-07-15 9:14 ` Wei Ni
2013-07-15 9:14 ` Wei Ni
2013-07-15 9:14 ` [lm-sensors] " Wei Ni
[not found] ` <51E3BD5F.6060806-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-15 17:52 ` Jean Delvare
2013-07-15 17:52 ` Jean Delvare
2013-07-15 17:52 ` [lm-sensors] " Jean Delvare
2013-07-17 4:26 ` Thierry Reding
2013-07-17 4:26 ` [lm-sensors] " Thierry Reding
2013-07-17 5:14 ` Guenter Roeck
2013-07-17 5:14 ` [lm-sensors] " Guenter Roeck
2013-07-17 6:26 ` Wei Ni
2013-07-17 6:26 ` [lm-sensors] " Wei Ni
2013-07-17 9:11 ` Jean Delvare
2013-07-17 9:11 ` [lm-sensors] " Jean Delvare
2013-07-17 9:54 ` Wei Ni
2013-07-17 9:54 ` [lm-sensors] " Wei Ni
2013-07-15 6:05 ` Wei Ni [this message]
2013-07-15 6:05 ` Wei Ni
2013-07-15 6:05 ` [lm-sensors] " Wei Ni
[not found] ` <51E39114.505-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-15 7:29 ` Jean Delvare
2013-07-15 7:29 ` Jean Delvare
2013-07-15 7:29 ` [lm-sensors] " Jean Delvare
[not found] ` <1373615287-18502-1-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-12 7:48 ` [PATCH v3 2/4] hwmon: (lm90) use macro defines for the status bit Wei Ni
2013-07-12 7:48 ` Wei Ni
2013-07-12 7:48 ` [lm-sensors] " Wei Ni
2013-07-15 16:57 ` Jean Delvare
2013-07-15 16:57 ` Jean Delvare
2013-07-15 16:57 ` [lm-sensors] " Jean Delvare
[not found] ` <20130715185727.4ebde8c4-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-07-15 17:33 ` Guenter Roeck
2013-07-15 17:33 ` Guenter Roeck
2013-07-15 17:33 ` [lm-sensors] " Guenter Roeck
[not found] ` <20130715173322.GA20484-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2013-10-30 15:33 ` Jean Delvare
2013-10-30 15:33 ` Jean Delvare
2013-10-30 15:33 ` [lm-sensors] " Jean Delvare
[not found] ` <20131030163326.4e7e0cfc-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-10-30 16:11 ` Guenter Roeck
2013-10-30 16:11 ` Guenter Roeck
2013-10-30 16:11 ` [lm-sensors] " Guenter Roeck
2013-10-30 16:56 ` Guenter Roeck
2013-10-30 16:56 ` Guenter Roeck
2013-10-30 16:56 ` [lm-sensors] " Guenter Roeck
2013-07-17 7:03 ` Wei Ni
2013-07-17 7:03 ` Wei Ni
2013-07-17 7:03 ` [lm-sensors] " Wei Ni
2013-07-17 7:09 ` Wei Ni
2013-07-17 7:09 ` [lm-sensors] " Wei Ni
[not found] ` <51E641C7.4000107-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-17 8:28 ` Jean Delvare
2013-07-17 8:28 ` Jean Delvare
2013-07-17 8:28 ` [lm-sensors] " Jean Delvare
2013-07-17 9:29 ` Wei Ni
2013-07-17 9:29 ` [lm-sensors] " Wei Ni
[not found] ` <51E663FC.5050209-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-17 9:46 ` Jean Delvare
2013-07-17 9:46 ` Jean Delvare
2013-07-17 9:46 ` [lm-sensors] " Jean Delvare
2013-07-12 7:48 ` [PATCH v3 3/4] hwmon: (lm90) add support to handle IRQ Wei Ni
2013-07-12 7:48 ` Wei Ni
2013-07-12 7:48 ` [lm-sensors] " Wei Ni
2013-07-18 15:58 ` Jean Delvare
2013-07-18 15:58 ` Jean Delvare
2013-07-18 15:58 ` [lm-sensors] " Jean Delvare
[not found] ` <20130718175822.62c358bf-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-07-19 6:41 ` Wei Ni
2013-07-19 6:41 ` Wei Ni
2013-07-19 6:41 ` [lm-sensors] " Wei Ni
[not found] ` <51E8DFB2.9070701-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-24 7:46 ` Wei Ni
2013-07-24 7:46 ` Wei Ni
2013-07-24 7:46 ` [lm-sensors] " Wei Ni
2013-07-24 8:08 ` Jean Delvare
2013-07-24 8:08 ` [lm-sensors] " Jean Delvare
2013-07-27 15:02 ` Jean Delvare
2013-07-27 15:02 ` [lm-sensors] " Jean Delvare
2013-07-29 10:14 ` Wei Ni
2013-07-29 10:14 ` [lm-sensors] " Wei Ni
[not found] ` <51F640A0.4040809-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-29 15:58 ` Jean Delvare
2013-07-29 15:58 ` Jean Delvare
2013-07-29 15:58 ` [lm-sensors] " Jean Delvare
[not found] ` <20130729175835.795dba2b-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-07-30 8:18 ` Wei Ni
2013-07-30 8:18 ` Wei Ni
2013-07-30 8:18 ` [lm-sensors] " Wei Ni
[not found] ` <51F776DB.3060104-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-09-16 12:34 ` Jean Delvare
2013-09-16 12:34 ` Jean Delvare
2013-09-16 12:34 ` [lm-sensors] " Jean Delvare
2013-07-12 7:48 ` [PATCH v3 4/4] hwmon: (lm90) use enums for the indexes of temp8 and temp11 Wei Ni
2013-07-12 7:48 ` Wei Ni
2013-07-12 7:48 ` [lm-sensors] " Wei Ni
[not found] ` <1373615287-18502-5-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-27 15:38 ` Jean Delvare
2013-07-27 15:38 ` Jean Delvare
2013-07-27 15:38 ` [lm-sensors] " Jean Delvare
[not found] ` <20130727173830.14cb5b21-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-07-29 11:15 ` Wei Ni
2013-07-29 11:15 ` Wei Ni
2013-07-29 11:15 ` [lm-sensors] " Wei Ni
[not found] ` <51F64EC0.800-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-07-29 15:48 ` Jean Delvare
2013-07-29 15:48 ` Jean Delvare
2013-07-29 15:48 ` [lm-sensors] " Jean Delvare
-- strict thread matches above, loose matches on Subject: below --
2014-08-25 6:29 [PATCH v3 0/4] expose lm90 to thermal fw Wei Ni
[not found] ` <1408948188-4181-1-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-25 6:29 ` [PATCH v3 1/4] hwmon: (lm90) split set&show temp as common codes Wei Ni
2014-08-25 6:29 ` Wei Ni
[not found] ` <1408948188-4181-2-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-25 12:23 ` Mikko Perttunen
2014-08-25 12:23 ` Mikko Perttunen
[not found] ` <53FB2AAA.30601-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-26 2:27 ` Wei Ni
2014-08-26 2:27 ` Wei Ni
[not found] ` <53FBF09F.8050502-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-26 12:17 ` Eduardo Valentin
2014-08-26 12:17 ` Eduardo Valentin
2014-08-26 16:37 ` Stephen Warren
[not found] ` <53FCB7C6.8000503-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2014-08-27 2:25 ` Wei Ni
2014-08-27 2:25 ` Wei Ni
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=51E39114.505@nvidia.com \
--to=wni-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
--cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
--cc=linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org \
--cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.