From: Jean Delvare <khali@linux-fr.org>
To: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
lm-sensors@lm-sensors.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/7] hwmon: (lm90) Introduce device feature bits
Date: Mon, 13 Sep 2010 21:30:30 +0200 [thread overview]
Message-ID: <20100913213030.3573aab7@hyperion.delvare> (raw)
In-Reply-To: <1284038750-8833-3-git-send-email-guenter.roeck@ericsson.com>
On Thu, 9 Sep 2010 06:25:45 -0700, Guenter Roeck wrote:
> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
> ---
> drivers/hwmon/lm90.c | 38 +++++++++++++++++++++++++-------------
> 1 files changed, 25 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
> index aafed28..a81a053 100644
> --- a/drivers/hwmon/lm90.c
> +++ b/drivers/hwmon/lm90.c
> @@ -142,7 +142,11 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646,
> /*
> * Device flags
> */
> -#define LM90_FLAG_ADT7461_EXT 0x01 /* ADT7461 extended mode */
> +#define LM90_FLAG_ADT7461_EXT 0x01 /* ADT7461 extended mode */
> +/* Device features */
> +#define LM90_HAVE_OFFSET 0x02 /* temperature offset register */
> +#define LM90_HAVE_LOCAL_EXT 0x04 /* extended local temperature */
> +#define LM90_HAVE_REM_LIMIT_EXT 0x08 /* extended remote limit */
Please always use a space, not a tab, between #define and the symbol
name.
When defining bit values, I suggest using the following notation:
#define LM90_HAVE_OFFSET (1 << 2) /* temperature offset register */
#define LM90_HAVE_LOCAL_EXT (1 << 3) /* extended local temperature */
It is more immediately obvious that you have a bit vector.
>
> /*
> * Functions declaration
> @@ -462,17 +466,16 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
> mutex_lock(&data->update_lock);
> if (data->kind == adt7461)
> data->temp11[nr] = temp_to_u16_adt7461(data, val);
> - else if (data->kind == max6657 || data->kind == max6680)
> - data->temp11[nr] = temp_to_s8(val) << 8;
> else if (data->kind == max6646)
> data->temp11[nr] = temp_to_u8(val) << 8;
> + else if (!(data->flags & LM90_HAVE_REM_LIMIT_EXT))
It would be more efficient to swap the last two statements to avoid the
negation.
> + data->temp11[nr] = temp_to_s8(val) << 8;
> else
> data->temp11[nr] = temp_to_s16(val);
>
> i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
> data->temp11[nr] >> 8);
> - if (data->kind != max6657 && data->kind != max6680
> - && data->kind != max6646)
> + if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
> i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
> data->temp11[nr] & 0xff);
> mutex_unlock(&data->update_lock);
> @@ -847,6 +850,17 @@ static int lm90_probe(struct i2c_client *new_client,
> break;
> }
>
> + /* Set chip capabilities */
> + if (data->kind != max6657 && data->kind != max6646)
> + data->flags |= LM90_HAVE_OFFSET;
> +
> + if (data->kind == max6657 || data->kind == max6646)
> + data->flags |= LM90_HAVE_LOCAL_EXT;
> +
> + if (data->kind != max6657 && data->kind != max6646
> + && data->kind != max6680)
> + data->flags |= LM90_HAVE_REM_LIMIT_EXT;
> +
> /* Initialize the LM90 chip */
> lm90_init_client(new_client);
>
> @@ -859,7 +873,7 @@ static int lm90_probe(struct i2c_client *new_client,
> if (err)
> goto exit_remove_files;
> }
> - if (data->kind != max6657 && data->kind != max6646) {
> + if (data->flags & LM90_HAVE_OFFSET) {
> err = device_create_file(&new_client->dev,
> &sensor_dev_attr_temp2_offset.dev_attr);
> if (err)
> @@ -925,7 +939,7 @@ static int lm90_remove(struct i2c_client *client)
> hwmon_device_unregister(data->hwmon_dev);
> sysfs_remove_group(&client->dev.kobj, &lm90_group);
> device_remove_file(&client->dev, &dev_attr_pec);
> - if (data->kind != max6657 && data->kind != max6646)
> + if (data->flags & LM90_HAVE_OFFSET)
> device_remove_file(&client->dev,
> &sensor_dev_attr_temp2_offset.dev_attr);
>
> @@ -1019,7 +1033,7 @@ static struct lm90_data *lm90_update_device(struct device *dev)
> lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]);
> lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
>
> - if (data->kind == max6657 || data->kind == max6646) {
> + if (data->flags & LM90_HAVE_LOCAL_EXT) {
> lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
> MAX6657_REG_R_LOCAL_TEMPL,
> &data->temp11[4]);
> @@ -1033,22 +1047,20 @@ static struct lm90_data *lm90_update_device(struct device *dev)
>
> if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
> data->temp11[1] = h << 8;
> - if (data->kind != max6657 && data->kind != max6680
> - && data->kind != max6646
> + if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
> && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
> &l) == 0)
> data->temp11[1] |= l;
> }
> if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
> data->temp11[2] = h << 8;
> - if (data->kind != max6657 && data->kind != max6680
> - && data->kind != max6646
> + if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
> && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
> &l) == 0)
> data->temp11[2] |= l;
> }
>
> - if (data->kind != max6657 && data->kind != max6646) {
> + if (data->flags & LM90_HAVE_OFFSET) {
> if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH,
> &h) == 0
> && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,
Other than these minor implementation details, the changes look good, I
like them.
--
Jean Delvare
next prev parent reply other threads:[~2010-09-13 19:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-09 13:25 [PATCH v2 0/7] hwmon: Add support for MAX6695/6696 to lm90 driver Guenter Roeck
2010-09-09 13:25 ` [PATCH v2 1/7] hwmon: Add tempX_emergency_alarm attribute to sysfs ABI Guenter Roeck
2010-09-13 16:17 ` Jean Delvare
2010-09-13 16:54 ` Guenter Roeck
2010-09-09 13:25 ` [PATCH v2 2/7] hwmon: (lm90) Introduce device feature bits Guenter Roeck
2010-09-13 19:30 ` Jean Delvare [this message]
2010-09-13 20:32 ` Guenter Roeck
2010-09-09 13:25 ` [PATCH v2 3/7] hwmon: (lm90) Introduce function to delete sysfs files Guenter Roeck
2010-09-13 19:48 ` Jean Delvare
2010-09-09 13:25 ` [PATCH v2 4/7] hwmon: (lm90) Simplify set_temp11 register calculations Guenter Roeck
2010-09-14 9:18 ` Jean Delvare
2010-09-09 13:25 ` [PATCH v2 5/7] hwmon: (lm90) Introduce 3rd set of upper temperature limits Guenter Roeck
2010-09-14 10:51 ` Jean Delvare
2010-09-14 11:46 ` Guenter Roeck
2010-09-14 11:46 ` [lm-sensors] " Jean Delvare
2010-09-14 12:38 ` Guenter Roeck
2010-09-09 13:25 ` [PATCH v2 6/7] hwmon: (lm90) Add support for additional features of max6659 Guenter Roeck
2010-09-14 11:52 ` Jean Delvare
2010-09-14 16:08 ` Guenter Roeck
2010-09-09 13:25 ` [PATCH v2 7/7] hwmon: (lm90) Add support for max6695 and max6696 Guenter Roeck
2010-09-15 11:20 ` Jean Delvare
2010-09-15 14:29 ` Guenter Roeck
2010-09-15 14:34 ` Jean Delvare
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=20100913213030.3573aab7@hyperion.delvare \
--to=khali@linux-fr.org \
--cc=akpm@linux-foundation.org \
--cc=guenter.roeck@ericsson.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox