public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Looijmans <mike.looijmans@topic.nl>
To: Frans Klaver <fransklaver@gmail.com>
Cc: <linux-hwmon@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Guenter Roeck <linux@roeck-us.net>, <jdelvare@suse.com>
Subject: Re: [PATCH] hwmon: Add LTC2471/LTC2473 driver
Date: Thu, 29 Jun 2017 14:08:17 +0200	[thread overview]
Message-ID: <e23ac8fb-e43e-39be-aced-d83cf8e31d87@topic.nl> (raw)
In-Reply-To: <CAH6sp9O1oaNqAWbSBhgNZtBafFi2YmnJ0jB15DZ4CFu8zT-Rrw@mail.gmail.com>

On 29-06-17 13:38, Frans Klaver wrote:
> On Thu, Jun 29, 2017 at 1:30 PM, Mike Looijmans <mike.looijmans@topic.nl> wrote:
>> On 29-06-17 13:18, Frans Klaver wrote:
>>>
>>> On Thu, Jun 29, 2017 at 12:45 PM, Mike Looijmans
>>> <mike.looijmans@topic.nl> wrote:
>>>>
>>>> The LTC2741 and LTC2473 are single voltage monitoring chips. The LTC2473
>>>> is similar to the LTC2471 but outputs a signed differential value.
>>>>
>>>> Datasheet:
>>>>     http://cds.linear.com/docs/en/datasheet/24713fb.pdf
>>>>
>>>> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
>>>> ---
>>>>    drivers/hwmon/Kconfig   |  10 ++++
>>>>    drivers/hwmon/Makefile  |   1 +
>>>>    drivers/hwmon/ltc2471.c | 127
>>>> ++++++++++++++++++++++++++++++++++++++++++++++++
>>>>    3 files changed, 138 insertions(+)
>>>>    create mode 100644 drivers/hwmon/ltc2471.c
>>>>
>>>> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
>>>> index fbde226..c9a2a87 100644
>>>> --- a/drivers/hwmon/Kconfig
>>>> +++ b/drivers/hwmon/Kconfig
>>>> @@ -673,6 +673,16 @@ config SENSORS_LINEAGE
>>>>             This driver can also be built as a module.  If so, the module
>>>>             will be called lineage-pem.
>>>>
>>>> +config SENSORS_LTC2471
>>>> +       tristate "Linear Technology LTC2471 and LTC2473"
>>>> +       depends on I2C
>>>> +       help
>>>> +         If you say yes here you get support for Linear Technology
>>>> LTC2471
>>>> +         and LTC2473 voltage monitors.
>>>> +
>>>> +         This driver can also be built as a module. If so, the module
>>>> will
>>>> +         be called ltc2471.
>>>> +
>>>>    config SENSORS_LTC2945
>>>>           tristate "Linear Technology LTC2945"
>>>>           depends on I2C
>>>> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
>>>> index 58cc3ac..6f60fe7 100644
>>>> --- a/drivers/hwmon/Makefile
>>>> +++ b/drivers/hwmon/Makefile
>>>> @@ -99,6 +99,7 @@ obj-$(CONFIG_SENSORS_LM93)    += lm93.o
>>>>    obj-$(CONFIG_SENSORS_LM95234)  += lm95234.o
>>>>    obj-$(CONFIG_SENSORS_LM95241)  += lm95241.o
>>>>    obj-$(CONFIG_SENSORS_LM95245)  += lm95245.o
>>>> +obj-$(CONFIG_SENSORS_LTC2471)  += ltc2471.o
>>>>    obj-$(CONFIG_SENSORS_LTC2945)  += ltc2945.o
>>>>    obj-$(CONFIG_SENSORS_LTC2990)  += ltc2990.o
>>>>    obj-$(CONFIG_SENSORS_LTC4151)  += ltc4151.o
>>>> diff --git a/drivers/hwmon/ltc2471.c b/drivers/hwmon/ltc2471.c
>>>> new file mode 100644
>>>> index 0000000..17eaad8
>>>> --- /dev/null
>>>> +++ b/drivers/hwmon/ltc2471.c
>>>> @@ -0,0 +1,127 @@
>>>> +/*
>>>> + * Driver for Linear Technology LTC2471 and LTC2473 voltage monitors
>>>> + * The LTC2473 is identical to the 2471, but reports a differential
>>>> signal.
>>>> + *
>>>> + * Copyright (C) 2017 Topic Embedded Products
>>>> + * Author: Mike Looijmans <mike.looijmans@topic.nl>
>>>> + *
>>>> + * License: GPLv2
>>>> + */
>>>> +
>>>> +#include <linux/err.h>
>>>> +#include <linux/hwmon.h>
>>>> +#include <linux/hwmon-sysfs.h>
>>>> +#include <linux/i2c.h>
>>>> +#include <linux/kernel.h>
>>>> +#include <linux/module.h>
>>>> +
>>>> +enum chips {
>>>> +       ltc2471,
>>>> +       ltc2473
>>>> +};
>>>> +
>>>> +struct ltc2471_data {
>>>> +       struct i2c_client *i2c;
>>>> +       bool differential;
>>>> +};
>>>
>>>
>>> I haven't checked if there are similar drivers, but how about
>>> ltc247x_data? It's a bit odd to tie all naming in this driver to one
>>> chip and then support another one as well.
>>
>>
>> Did a query on the linear site, found the LTC2470 and LTC2472 which appear
>> to be the SPI versions of the same chip. So yes, using "ltc247x" may cause
>> confusion when other drivers arrive. Linear solves this by naming the
>> datasheet "ltc24712" but I think that'd be even more confusing.
> 
> OK.
> 
> 
>>>
>>>> +
>>>> +/* Reference voltage is 1.25V */
>>>> +#define LTC2471_VREF 1250
>>>> +
>>>> +/* Read two bytes from the I2C bus to obtain the ADC result */
>>>> +static int ltc2471_get_value(struct i2c_client *i2c)
>>>> +{
>>>> +       int ret;
>>>> +       __be16 buf;
>>>> +
>>>> +       ret = i2c_master_recv(i2c, (char *)&buf, 2);
>>>> +       if (ret < 0)
>>>> +               return ret;
>>>> +       if (ret != 2)
>>>> +               return -EIO;
>>>> +
>>>> +       /* MSB first */
>>>> +       return be16_to_cpu(buf);
>>>> +}
>>>> +
>>>> +static ssize_t ltc2471_show_value(struct device *dev,
>>>> +                                 struct device_attribute *da, char *buf)
>>>> +{
>>>> +       struct ltc2471_data *data = dev_get_drvdata(dev);
>>>> +       int value;
>>>> +
>>>> +       value = ltc2471_get_value(data->i2c);
>>>> +       if (unlikely(value < 0))
>>>> +               return value;
>>>> +
>>>> +       if (data->differential)
>>>> +               /* Ranges from -VREF to +VREF with "0" at 0x8000 */
>>>> +               value = ((s32)LTC2471_VREF * (s32)(value - 0x8000)) >>
>>>> 15;
>>>> +       else
>>>> +               /* Ranges from 0 to +VREF */
>>>> +               value = ((u32)LTC2471_VREF * (u32)value) >> 16;
>>>> +
>>>> +       return snprintf(buf, PAGE_SIZE, "%d\n", value);
>>>> +}
>>>> +
>>>> +static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, ltc2471_show_value, NULL,
>>>> 0);
>>>
>>>
>>> Octal permissions are preferred over S_IRUGO and such.
>>
>>
>> Uh, can elaborate on that, or give an example on what you mean by that
>> remark?
>>
>> A quick grep reveils that most (if not all) hwmon devices are currently
>> using "S_IRUGO" and such.
> 
> I am aware of the fact that lots of drivers use these .Linus filed an
> executive decision that octals are preferred over symbols when it
> comes to permissions. checkpatch.pl should warn about it nowadays.

rebased on current master and checkpatch now indeed suggests to use "0444" 
instead. I'll submit a v2 with changes as suggested.


Kind regards,

Mike Looijmans
System Expert

TOPIC Products
Materiaalweg 4, NL-5681 RJ Best
Postbus 440, NL-5680 AK Best
Telefoon: +31 (0) 499 33 69 79
E-mail: mike.looijmans@topicproducts.com
Website: www.topicproducts.com

Please consider the environment before printing this e-mail

  reply	other threads:[~2017-06-29 12:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29 10:45 [PATCH] hwmon: Add LTC2471/LTC2473 driver Mike Looijmans
2017-06-29 11:18 ` Frans Klaver
2017-06-29 11:30   ` Mike Looijmans
2017-06-29 11:38     ` Frans Klaver
2017-06-29 12:08       ` Mike Looijmans [this message]
2017-06-29 13:37   ` Guenter Roeck
2017-06-29 12:13 ` [PATCH v2] " Mike Looijmans
2017-06-29 12:30   ` Lars-Peter Clausen
2017-06-29 13:22     ` Mike Looijmans
2017-06-29 13:41       ` Guenter Roeck
2017-06-29 13:40     ` Guenter Roeck
2017-06-29 14:11       ` Mike Looijmans
2017-06-29 15:08         ` Guenter Roeck
2017-06-29 15:30         ` Lars-Peter Clausen
2017-06-29 13:34 ` [PATCH] " Guenter Roeck
2017-07-01  9:58   ` Jonathan Cameron

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=e23ac8fb-e43e-39be-aced-d83cf8e31d87@topic.nl \
    --to=mike.looijmans@topic.nl \
    --cc=fransklaver@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /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