Re: [PATCH v5 1/1] hwmon: Add support for INA3221 Triple Current/Voltage Monitors

2016-06-24 Thread Andrew F. Davis
On 06/24/2016 11:46 AM, Guenter Roeck wrote:
> On Fri, Jun 24, 2016 at 10:02:51AM -0500, Andrew F. Davis wrote:
>> On 06/18/2016 10:16 AM, Guenter Roeck wrote:
>>>
>>> The chip registers are 16 bit. Can you repeat the command using the "w"
>>> option ?
>>>
>>
>> # i2cdump -y 2 0x40 w
>>  0,8  1,9  2,a  3,b  4,c  5,d  6,e  7,f
>> 00: 2771       f87f
>> 08: f87f f87f f87f f87f f87f  fe7f 0300
>> 10: 1027 2823      
>> 18:    f8f8   4954 2032
>> 20: 2771       f87f
>> 28: f87f f87f f87f f87f f87f  fe7f 0300
>> 30: 1027 2823      
>> 38:    f8f8   4954 2032
>> 40: 2771       f87f
>> 48: f87f f87f f87f f87f f87f  fe7f 0300
>> 50: 1027 2823      
>> 58:    f8f8   4954 2032
>> 60: 2771       f87f
>> 68: f87f f87f f87f f87f f87f  fe7f 0300
>> 70: 1027 2823      
>> 78:    f8f8   4954 2032
>> 80: 2771       f87f
>> 88: f87f f87f f87f f87f f87f  fe7f 0300
>> 90: 1027 2823      
>> 98:    f8f8   4954 2032
>> a0: 2771       f87f
>> a8: f87f f87f f87f f87f f87f  fe7f 0300
>> b0: 1027 2823      
>> b8:    f8f8   4954 2032
>> c0: 2771       f87f
>> c8: f87f f87f f87f f87f f87f  fe7f 0300
>> d0: 1027 2823      
>> d8:    f8f8   4954 2032
>> e0: 2771       f87f
>> e8: f87f f87f f87f f87f f87f  fe7f 0300
>> f0: 1027 2823      
>> f8:    f8f8   4954 2032
> 
> Thanks a lot!
> 

Feel free to completely ignore the first register dump I sent, I did it
for the wrong device anyway :).

I had just gotten done reading this:
https://lkml.org/lkml/2015/12/10/459
and accidentally got EVMs confused did the test for the TMP461, but it
does look like on startup register 0x16 can be used to differentiate the
parts, if the TMP461 hadn't gone into a different driver.

Andrew
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/1] hwmon: Add support for INA3221 Triple Current/Voltage Monitors

2016-06-17 Thread Andrew F. Davis
On 06/10/2016 11:44 AM, Guenter Roeck wrote:
> On Fri, Jun 10, 2016 at 10:32:33AM -0500, Andrew F. Davis wrote:
>> Add support for the the INA3221 26v capable, Triple channel,
>> Bi-Directional, Zero-Drift, Low-/High-Side, Current/Voltage Monitor
>> with I2C interface.
>>
>> Signed-off-by: Andrew F. Davis <a...@ti.com>
> 
> Applied to -next.
> 
> Can you by any chance send me a register dump ? I would like to write
> module test code for the chip.
> 

No problem:

# i2cdump -y 2 0x48
No size specified (using byte-data access)
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f0123456789abcdef
00: 18 16 80 00 08 7f 80 7f 80 00 00 00 00 00 00 00???.?...
10: e0 00 00 f0 00 00 03 00 00 7f 00 00 00 00 00 00?..?..?..?..
20: 7f 0a 01 00 00 XX 00 00 00 00 0e 00 00 00 40 00???..X?...@.
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 00..U.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/1] hwmon: (tmp401) Add support for TI TMP461

2016-06-08 Thread Andrew F. Davis
Signed-off-by: Andrew F. Davis <a...@ti.com>
---
Changes from v1:
 - Dropped n-factor correction until a generic solution is developed
 - Removed double empty line

 Documentation/hwmon/tmp401 | 14 --
 drivers/hwmon/Kconfig  |  2 +-
 drivers/hwmon/tmp401.c | 35 +--
 3 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/Documentation/hwmon/tmp401 b/Documentation/hwmon/tmp401
index 711f75e..2d9ca42 100644
--- a/Documentation/hwmon/tmp401
+++ b/Documentation/hwmon/tmp401
@@ -22,6 +22,9 @@ Supported chips:
 Prefix: 'tmp435'
 Addresses scanned: I2C 0x48 - 0x4f
 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp435.html
+  * Texas Instruments TMP461
+Prefix: 'tmp461'
+Datasheet: http://www.ti.com/product/tmp461
 
 Authors:
  Hans de Goede <hdego...@redhat.com>
@@ -31,8 +34,8 @@ Description
 ---
 
 This driver implements support for Texas Instruments TMP401, TMP411,
-TMP431, TMP432 and TMP435 chips. These chips implement one or two remote
-and one local temperature sensors. Temperature is measured in degrees
+TMP431, TMP432, TMP435, and TMP461 chips. These chips implement one or two
+remote and one local temperature sensors. Temperature is measured in degrees
 Celsius. Resolution of the remote sensor is 0.0625 degree. Local
 sensor resolution can be set to 0.5, 0.25, 0.125 or 0.0625 degree (not
 supported by the driver so far, so using the default resolution of 0.5
@@ -55,3 +58,10 @@ some additional features.
 
 TMP432 is compatible with TMP401 and TMP431. It supports two external
 temperature sensors.
+
+TMP461 is compatible with TMP401. It supports offset correction
+that is applied to the remote sensor.
+
+* Sensor offset values are temperature values
+
+  Exported via sysfs attribute tempX_offset
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index ff94007..c571dcf 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1561,7 +1561,7 @@ config SENSORS_TMP401
depends on I2C
help
  If you say yes here you get support for Texas Instruments TMP401,
- TMP411, TMP431, TMP432 and TMP435 temperature sensor chips.
+ TMP411, TMP431, TMP432, TMP435, and TMP461 temperature sensor chips.
 
  This driver can also be built as a module.  If so, the module
  will be called tmp401.
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index ccf4cff..d2c 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -47,7 +47,7 @@
 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4c, 0x4d,
0x4e, 0x4f, I2C_CLIENT_END };
 
-enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 };
+enum chips { tmp401, tmp411, tmp431, tmp432, tmp435, tmp461 };
 
 /*
  * The TMP401 registers, note some registers have different addresses for
@@ -62,31 +62,34 @@ enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 };
 #define TMP401_MANUFACTURER_ID_REG 0xFE
 #define TMP401_DEVICE_ID_REG   0xFF
 
-static const u8 TMP401_TEMP_MSB_READ[6][2] = {
+static const u8 TMP401_TEMP_MSB_READ[7][2] = {
{ 0x00, 0x01 }, /* temp */
{ 0x06, 0x08 }, /* low limit */
{ 0x05, 0x07 }, /* high limit */
{ 0x20, 0x19 }, /* therm (crit) limit */
{ 0x30, 0x34 }, /* lowest */
{ 0x32, 0x36 }, /* highest */
+   { 0, 0x11 },/* offset */
 };
 
-static const u8 TMP401_TEMP_MSB_WRITE[6][2] = {
+static const u8 TMP401_TEMP_MSB_WRITE[7][2] = {
{ 0, 0 },   /* temp (unused) */
{ 0x0C, 0x0E }, /* low limit */
{ 0x0B, 0x0D }, /* high limit */
{ 0x20, 0x19 }, /* therm (crit) limit */
{ 0x30, 0x34 }, /* lowest */
{ 0x32, 0x36 }, /* highest */
+   { 0, 0x11 },/* offset */
 };
 
-static const u8 TMP401_TEMP_LSB[6][2] = {
+static const u8 TMP401_TEMP_LSB[7][2] = {
{ 0x15, 0x10 }, /* temp */
{ 0x17, 0x14 }, /* low limit */
{ 0x16, 0x13 }, /* high limit */
{ 0, 0 },   /* therm (crit) limit (unused) */
{ 0x31, 0x35 }, /* lowest */
{ 0x33, 0x37 }, /* highest */
+   { 0, 0x12 },/* offset */
 };
 
 static const u8 TMP432_TEMP_MSB_READ[4][3] = {
@@ -149,6 +152,7 @@ static const struct i2c_device_id tmp401_id[] = {
{ "tmp431", tmp431 },
{ "tmp432", tmp432 },
{ "tmp435", tmp435 },
+   { "tmp461", tmp461 },
{ }
 };
 MODULE_DEVICE_TABLE(i2c, tmp401_id);
@@ -170,7 +174,7 @@ struct tmp401_data {
/* register values */
u8 status[4];
u8 config;
-   u16 temp[6][3];
+   u16 temp[7][3];
u8 temp_crit_hyst;
 };
 
@@ -613,6 +617,22 @@ static const struct attribute_group tmp432_group = {
 };
 
 /*
+ * Additional features of the TMP461 chip.
+ * The TMP461 temperature offset for the remote channel.
+ */
+static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, sho

Re: [PATCH] hwmon: (tmp401) Add support for TI TMP461

2016-06-08 Thread Andrew F. Davis
On 06/03/2016 11:41 PM, Guenter Roeck wrote:
> On 05/31/2016 09:27 AM, Andrew F. Davis wrote:
>> Signed-off-by: Andrew F. Davis <a...@ti.com>
>> ---
>>   Documentation/hwmon/tmp401 | 18 +--
>>   drivers/hwmon/Kconfig  |  2 +-
>>   drivers/hwmon/tmp401.c | 81
>> ++
>>   3 files changed, 92 insertions(+), 9 deletions(-)
>>
>> diff --git a/Documentation/hwmon/tmp401 b/Documentation/hwmon/tmp401
>> index 711f75e..eaa2d3b 100644
>> --- a/Documentation/hwmon/tmp401
>> +++ b/Documentation/hwmon/tmp401
>> @@ -22,6 +22,9 @@ Supported chips:
>>   Prefix: 'tmp435'
>>   Addresses scanned: I2C 0x48 - 0x4f
>>   Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp435.html
>> +  * Texas Instruments TMP461
>> +Prefix: 'tmp461'
>> +Datasheet: http://www.ti.com/product/tmp461
>>
>>   Authors:
>>Hans de Goede <hdego...@redhat.com>
>> @@ -31,8 +34,8 @@ Description
>>   ---
>>
>>   This driver implements support for Texas Instruments TMP401, TMP411,
>> -TMP431, TMP432 and TMP435 chips. These chips implement one or two remote
>> -and one local temperature sensors. Temperature is measured in degrees
>> +TMP431, TMP432, TMP435, and TMP461 chips. These chips implement one
>> or two
>> +remote and one local temperature sensors. Temperature is measured in
>> degrees
>>   Celsius. Resolution of the remote sensor is 0.0625 degree. Local
>>   sensor resolution can be set to 0.5, 0.25, 0.125 or 0.0625 degree (not
>>   supported by the driver so far, so using the default resolution of 0.5
>> @@ -55,3 +58,14 @@ some additional features.
>>
>>   TMP432 is compatible with TMP401 and TMP431. It supports two external
>>   temperature sensors.
>> +
>> +TMP461 is compatible with TMP401. It supports offset and n-factor
>> correction
>> +that is applied to the remote sensor.
>> +
>> +* Sensor offset values are temperature values
>> +
>> +  Exported via sysfs attribute tempX_offset
>> +
>> +* n-factor correction, values are in raw form as described in the
>> datasheet
>> +
> 
> If you don't mind, I would prefer if you would drop this attribute, at
> least
> for now, for a number of reasons. It should not really be controlled by
> a sysfs
> attribute, but either with devicetree data or platform data. Exposing a raw
> register value through sysfs isn't really desirable; sysfs is supposed
> to provide some kind of abstraction. It enables setting the n-factor,
> but not beta-compensation which is probably equally desirable.
> Last but not least, other chips supported by this driver, as well as
> other chips
> supported by hwmon, also support  n-factor correction and
> beta-compensation.
> If we provide this functionality we should provide it for all chips in a
> generic way. In short, this needs more discussion.
> 

Makes sense, will drop this attribute for now.

> Couple of additional additional comments below.
> 
> Thanks,
> Guenter
> 
> 
>> +  Exported via sysfs attribute tempX_nfactor
>> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
>> index ff94007..c571dcf 100644
>> --- a/drivers/hwmon/Kconfig
>> +++ b/drivers/hwmon/Kconfig
>> @@ -1561,7 +1561,7 @@ config SENSORS_TMP401
>>   depends on I2C
>>   help
>> If you say yes here you get support for Texas Instruments TMP401,
>> -  TMP411, TMP431, TMP432 and TMP435 temperature sensor chips.
>> +  TMP411, TMP431, TMP432, TMP435, and TMP461 temperature sensor
>> chips.
>>
>> This driver can also be built as a module.  If so, the module
>> will be called tmp401.
>> diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
>> index ccf4cff..280065b 100644
>> --- a/drivers/hwmon/tmp401.c
>> +++ b/drivers/hwmon/tmp401.c
>> @@ -47,7 +47,8 @@
>>   static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4c,
>> 0x4d,
>>   0x4e, 0x4f, I2C_CLIENT_END };
>>
>> -enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 };
>> +enum chips { tmp401, tmp411, tmp431, tmp432, tmp435, tmp461 };
>> +
>>
> Please no double empty lines.
> 

ACK

>>   /*
>>* The TMP401 registers, note some registers have different
>> addresses for
>> @@ -62,31 +63,37 @@ enum chips { tmp401, tmp411, tmp431, tmp432,
>> tmp435 };
>>   #define TMP401_MANUFACTURER_ID_REG0xFE
>>   #define TMP401_DEVICE_ID_REG0xFF
>>
>> -static const u8 TMP401_TEMP_MSB_READ[6

Re: [PATCH 2/3] iio: adc: ina3221: Add support for IIO ADC driver for TI INA3221

2016-06-08 Thread Andrew F. Davis
On 06/07/2016 05:30 PM, Guenter Roeck wrote:
> On Fri, Jun 03, 2016 at 10:17:55AM -0500, Andrew F. Davis wrote:
>> On 06/03/2016 09:14 AM, Laxman Dewangan wrote:
>>>
>>> On Friday 03 June 2016 06:59 PM, Guenter Roeck wrote:
>>>> On 06/03/2016 03:06 AM, Jonathan Cameron wrote:
>>>>> On 01/06/16 13:34, Laxman Dewangan wrote:
>>>>>> The INA3221 is a three-channel, high-side current and bus voltage
>>>>>> monitor
>>>>>> with an I2C interface from Texas Instruments. The INA3221 monitors both
>>>>>> shunt voltage drops and bus supply voltages in addition to having
>>>>>> programmable conversion times and averaging modes for these signals.
>>>>>> The INA3221 offers both critical and warning alerts to detect multiple
>>>>>> programmable out-of-range conditions for each channel.
>>>>>>
>>>>>> Add support for INA3221 SW driver via IIO ADC interface. The device is
>>>>>> register as iio-device and provides interface for voltage/current
>>>>>> and power
>>>>>> monitor. Also provide interface for setting oneshot/continuous mode and
>>>>>> critical/warning threshold for the shunt voltage drop.
>>>>>>
>>>>>> Signed-off-by: Laxman Dewangan <ldewan...@nvidia.com>
>>>>> Hi Laxman,
>>>>>
>>>>> As ever with any driver lying on the border of IIO and hwmon, please
>>>>> include
>>>>> a short justification of why you need an IIO driver and also cc the
>>>>> hwmon list + maintainers. (cc'd on this reply).
>>>>>
>>>>> I simply won't take a driver where the hwmon maintainers aren't happy.
>>>>> As it stands I'm not seeing obvious reasons in the code for why this
>>>>> should be an IIO device.
>>>>>
>>>>
>>>> Me not either.
>>>>
>>>> I have a hwmon driver for the same chip pending from Andrew Davis (TI)
>>>> which I am just about to accept. We had directed Andrew back in April
>>>> to write a hwmon driver for the chip, which he did.
>>>>
>>>
>>> Thanks Guenter,  I found the series
>>>
>>> [PATCH v2 0/2] Add support for INA3221 Triple Current/Voltage Monitors
>>> Looks fine to me. I can use the hwmon.
>>>
>>
>> If you search even further back you can see I originally went with an
>> IIO driver as well, comparing the IIO and hwmon version for the simple
>> use cases I needed the hwmod version turned out much simpler, so it was
>> probably the right framework for now.
>>
>>>
>>> However, some of the stuff from my patch are not there which I will add
>>> later once original patch applied:
>>> - Dynamic mode changes for continuous and one-shot from sysfs.
>>> - In one shot, when try to read voltage data, do conversion and then read.
>>>
>>
>> My attempt is rather minimal, to be honest I like your stab at this
>> driver better in some ways, especially relating to DT putting each
>> channel in its own node with labels, I think this is a bit more clean
>> and will be more extendable if/when new multi-channel monitor chips are
>> made.
>>
>>> Not sure whether exporting the following will help or not. Can you
>>> please confirm?
>>> - Oversampling time i.e. average sample
>>> - conversion time for bus voltage and shunt voltage if default is not
>>> suited for system.
>>>
>>>
>>
>> These can always be added as needed, but the DT changes are not as easy.
>> I would like it if this got in this cycle but if you think something
>> will be needed to help your improvements, that can not be added
>> incrementally, it would probably be best to get them into the initial DT
>> binding doc now.
>>
> Andrew,
> 
> with this, the hwmon driver is pretty much on hold. What do you want me to do 
> ?
> Should I wait for DT updates ?
> 

If Laxman would like to commit to making these changes I do not problem
waiting a bit to get this right the first time.

If we don't hear back soon then I'd just take it as is and anything
needing to be fixed can be later.

Andrew
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] iio: adc: ina3221: Add support for IIO ADC driver for TI INA3221

2016-06-03 Thread Andrew F. Davis
On 06/03/2016 09:14 AM, Laxman Dewangan wrote:
> 
> On Friday 03 June 2016 06:59 PM, Guenter Roeck wrote:
>> On 06/03/2016 03:06 AM, Jonathan Cameron wrote:
>>> On 01/06/16 13:34, Laxman Dewangan wrote:
 The INA3221 is a three-channel, high-side current and bus voltage
 monitor
 with an I2C interface from Texas Instruments. The INA3221 monitors both
 shunt voltage drops and bus supply voltages in addition to having
 programmable conversion times and averaging modes for these signals.
 The INA3221 offers both critical and warning alerts to detect multiple
 programmable out-of-range conditions for each channel.

 Add support for INA3221 SW driver via IIO ADC interface. The device is
 register as iio-device and provides interface for voltage/current
 and power
 monitor. Also provide interface for setting oneshot/continuous mode and
 critical/warning threshold for the shunt voltage drop.

 Signed-off-by: Laxman Dewangan 
>>> Hi Laxman,
>>>
>>> As ever with any driver lying on the border of IIO and hwmon, please
>>> include
>>> a short justification of why you need an IIO driver and also cc the
>>> hwmon list + maintainers. (cc'd on this reply).
>>>
>>> I simply won't take a driver where the hwmon maintainers aren't happy.
>>> As it stands I'm not seeing obvious reasons in the code for why this
>>> should be an IIO device.
>>>
>>
>> Me not either.
>>
>> I have a hwmon driver for the same chip pending from Andrew Davis (TI)
>> which I am just about to accept. We had directed Andrew back in April
>> to write a hwmon driver for the chip, which he did.
>>
> 
> Thanks Guenter,  I found the series
> 
> [PATCH v2 0/2] Add support for INA3221 Triple Current/Voltage Monitors
> Looks fine to me. I can use the hwmon.
> 

If you search even further back you can see I originally went with an
IIO driver as well, comparing the IIO and hwmon version for the simple
use cases I needed the hwmod version turned out much simpler, so it was
probably the right framework for now.

> 
> However, some of the stuff from my patch are not there which I will add
> later once original patch applied:
> - Dynamic mode changes for continuous and one-shot from sysfs.
> - In one shot, when try to read voltage data, do conversion and then read.
> 

My attempt is rather minimal, to be honest I like your stab at this
driver better in some ways, especially relating to DT putting each
channel in its own node with labels, I think this is a bit more clean
and will be more extendable if/when new multi-channel monitor chips are
made.

> Not sure whether exporting the following will help or not. Can you
> please confirm?
> - Oversampling time i.e. average sample
> - conversion time for bus voltage and shunt voltage if default is not
> suited for system.
> 
> 

These can always be added as needed, but the DT changes are not as easy.
I would like it if this got in this cycle but if you think something
will be needed to help your improvements, that can not be added
incrementally, it would probably be best to get them into the initial DT
binding doc now.

Thanks,
Andrew

> 
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] hwmon: (tmp401) Add support for TI TMP461

2016-05-31 Thread Andrew F. Davis
Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 Documentation/hwmon/tmp401 | 18 +--
 drivers/hwmon/Kconfig  |  2 +-
 drivers/hwmon/tmp401.c | 81 ++
 3 files changed, 92 insertions(+), 9 deletions(-)

diff --git a/Documentation/hwmon/tmp401 b/Documentation/hwmon/tmp401
index 711f75e..eaa2d3b 100644
--- a/Documentation/hwmon/tmp401
+++ b/Documentation/hwmon/tmp401
@@ -22,6 +22,9 @@ Supported chips:
 Prefix: 'tmp435'
 Addresses scanned: I2C 0x48 - 0x4f
 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp435.html
+  * Texas Instruments TMP461
+Prefix: 'tmp461'
+Datasheet: http://www.ti.com/product/tmp461
 
 Authors:
  Hans de Goede <hdego...@redhat.com>
@@ -31,8 +34,8 @@ Description
 ---
 
 This driver implements support for Texas Instruments TMP401, TMP411,
-TMP431, TMP432 and TMP435 chips. These chips implement one or two remote
-and one local temperature sensors. Temperature is measured in degrees
+TMP431, TMP432, TMP435, and TMP461 chips. These chips implement one or two
+remote and one local temperature sensors. Temperature is measured in degrees
 Celsius. Resolution of the remote sensor is 0.0625 degree. Local
 sensor resolution can be set to 0.5, 0.25, 0.125 or 0.0625 degree (not
 supported by the driver so far, so using the default resolution of 0.5
@@ -55,3 +58,14 @@ some additional features.
 
 TMP432 is compatible with TMP401 and TMP431. It supports two external
 temperature sensors.
+
+TMP461 is compatible with TMP401. It supports offset and n-factor correction
+that is applied to the remote sensor.
+
+* Sensor offset values are temperature values
+
+  Exported via sysfs attribute tempX_offset
+
+* n-factor correction, values are in raw form as described in the datasheet
+
+  Exported via sysfs attribute tempX_nfactor
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index ff94007..c571dcf 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1561,7 +1561,7 @@ config SENSORS_TMP401
depends on I2C
help
  If you say yes here you get support for Texas Instruments TMP401,
- TMP411, TMP431, TMP432 and TMP435 temperature sensor chips.
+ TMP411, TMP431, TMP432, TMP435, and TMP461 temperature sensor chips.
 
  This driver can also be built as a module.  If so, the module
  will be called tmp401.
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index ccf4cff..280065b 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -47,7 +47,8 @@
 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4c, 0x4d,
0x4e, 0x4f, I2C_CLIENT_END };
 
-enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 };
+enum chips { tmp401, tmp411, tmp431, tmp432, tmp435, tmp461 };
+
 
 /*
  * The TMP401 registers, note some registers have different addresses for
@@ -62,31 +63,37 @@ enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 };
 #define TMP401_MANUFACTURER_ID_REG 0xFE
 #define TMP401_DEVICE_ID_REG   0xFF
 
-static const u8 TMP401_TEMP_MSB_READ[6][2] = {
+static const u8 TMP401_TEMP_MSB_READ[8][2] = {
{ 0x00, 0x01 }, /* temp */
{ 0x06, 0x08 }, /* low limit */
{ 0x05, 0x07 }, /* high limit */
{ 0x20, 0x19 }, /* therm (crit) limit */
{ 0x30, 0x34 }, /* lowest */
{ 0x32, 0x36 }, /* highest */
+   { 0, 0x11 },/* offset */
+   { 0, 0x23 },/* nfactor */
 };
 
-static const u8 TMP401_TEMP_MSB_WRITE[6][2] = {
+static const u8 TMP401_TEMP_MSB_WRITE[8][2] = {
{ 0, 0 },   /* temp (unused) */
{ 0x0C, 0x0E }, /* low limit */
{ 0x0B, 0x0D }, /* high limit */
{ 0x20, 0x19 }, /* therm (crit) limit */
{ 0x30, 0x34 }, /* lowest */
{ 0x32, 0x36 }, /* highest */
+   { 0, 0x11 },/* offset */
+   { 0, 0x23 },/* nfactor */
 };
 
-static const u8 TMP401_TEMP_LSB[6][2] = {
+static const u8 TMP401_TEMP_LSB[8][2] = {
{ 0x15, 0x10 }, /* temp */
{ 0x17, 0x14 }, /* low limit */
{ 0x16, 0x13 }, /* high limit */
{ 0, 0 },   /* therm (crit) limit (unused) */
{ 0x31, 0x35 }, /* lowest */
{ 0x33, 0x37 }, /* highest */
+   { 0, 0x12 },/* offset */
+   { 0, 0 },   /* nfactor (unused) */
 };
 
 static const u8 TMP432_TEMP_MSB_READ[4][3] = {
@@ -149,6 +156,7 @@ static const struct i2c_device_id tmp401_id[] = {
{ "tmp431", tmp431 },
{ "tmp432", tmp432 },
{ "tmp435", tmp435 },
+   { "tmp461", tmp461 },
{ }
 };
 MODULE_DEVICE_TABLE(i2c, tmp401_id);
@@ -170,7 +178,7 @@ struct tmp401_data {
/* register values */
u8 status[4];
u8 config;
-   u16 temp[6][3];
+   u16 temp[8][3];
u8 temp_crit_hyst;
 };
 
@@ -445,6 +453,44 @@ static ssize_t reset_temp_history(struct device *dev,
return count;

[PATCH v2 1/4] rpmsg: add THIS_MODULE to rpmsg_driver in rpmsg core

2016-05-04 Thread Andrew F. Davis
Add register_rpmsg_driver helper macro that adds THIS_MODULE to
rpmsg_driver for the registering driver. We rename and modify
the existing register_rpmsg_driver to enable this.

Signed-off-by: Andrew F. Davis <a...@ti.com>
Acked-by: Suman Anna <s-a...@ti.com>
---
 drivers/rpmsg/virtio_rpmsg_bus.c | 8 +---
 include/linux/rpmsg.h| 6 +-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 1fcd27c..fe03b2a 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -436,17 +436,19 @@ static struct bus_type rpmsg_bus = {
 };
 
 /**
- * register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus
+ * __register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus
  * @rpdrv: pointer to a struct rpmsg_driver
+ * @owner: owning module/driver
  *
  * Returns 0 on success, and an appropriate error value on failure.
  */
-int register_rpmsg_driver(struct rpmsg_driver *rpdrv)
+int __register_rpmsg_driver(struct rpmsg_driver *rpdrv, struct module *owner)
 {
rpdrv->drv.bus = _bus;
+   rpdrv->drv.owner = owner;
return driver_register(>drv);
 }
-EXPORT_SYMBOL(register_rpmsg_driver);
+EXPORT_SYMBOL(__register_rpmsg_driver);
 
 /**
  * unregister_rpmsg_driver() - unregister an rpmsg driver from the rpmsg bus
diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h
index 82a6739..7ff5790 100644
--- a/include/linux/rpmsg.h
+++ b/include/linux/rpmsg.h
@@ -169,7 +169,7 @@ struct rpmsg_driver {
 
 int register_rpmsg_device(struct rpmsg_channel *dev);
 void unregister_rpmsg_device(struct rpmsg_channel *dev);
-int register_rpmsg_driver(struct rpmsg_driver *drv);
+int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner);
 void unregister_rpmsg_driver(struct rpmsg_driver *drv);
 void rpmsg_destroy_ept(struct rpmsg_endpoint *);
 struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_channel *,
@@ -177,6 +177,10 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct 
rpmsg_channel *,
 int
 rpmsg_send_offchannel_raw(struct rpmsg_channel *, u32, u32, void *, int, bool);
 
+/* use a macro to avoid include chaining to get THIS_MODULE */
+#define register_rpmsg_driver(drv) \
+   __register_rpmsg_driver(drv, THIS_MODULE)
+
 /**
  * rpmsg_send() - send a message across to the remote processor
  * @rpdev: the rpmsg channel
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/4] rpmsg: drop owner assignment from rpmsg_drivers

2016-05-04 Thread Andrew F. Davis
An rpmsg_driver does not need to set an owner, it will be populated by
the driver core.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 Documentation/rpmsg.txt | 1 -
 samples/rpmsg/rpmsg_client_sample.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/Documentation/rpmsg.txt b/Documentation/rpmsg.txt
index f7edc3a..1d88426 100644
--- a/Documentation/rpmsg.txt
+++ b/Documentation/rpmsg.txt
@@ -249,7 +249,6 @@ MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
 
 static struct rpmsg_driver rpmsg_sample_client = {
.drv.name   = KBUILD_MODNAME,
-   .drv.owner  = THIS_MODULE,
.id_table   = rpmsg_driver_sample_id_table,
.probe  = rpmsg_sample_probe,
.callback   = rpmsg_sample_cb,
diff --git a/samples/rpmsg/rpmsg_client_sample.c 
b/samples/rpmsg/rpmsg_client_sample.c
index 59b1344..82ed288 100644
--- a/samples/rpmsg/rpmsg_client_sample.c
+++ b/samples/rpmsg/rpmsg_client_sample.c
@@ -77,7 +77,6 @@ MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
 
 static struct rpmsg_driver rpmsg_sample_client = {
.drv.name   = KBUILD_MODNAME,
-   .drv.owner  = THIS_MODULE,
.id_table   = rpmsg_driver_sample_id_table,
.probe  = rpmsg_sample_probe,
.callback   = rpmsg_sample_cb,
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/4] rpmsg: add helper macro module_rpmsg_driver

2016-05-04 Thread Andrew F. Davis
This patch introduces the module_rpmsg_driver macro which is a
convenience macro for rpmsg driver modules similar to
module_platform_driver. It is intended to be used by drivers which
init/exit section does nothing but register/unregister the rpmsg driver.
By using this macro it is possible to eliminate a few lines of
boilerplate code per rpmsg driver.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 include/linux/rpmsg.h | 12 
 1 file changed, 12 insertions(+)

diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h
index 7ff5790..ada50ff 100644
--- a/include/linux/rpmsg.h
+++ b/include/linux/rpmsg.h
@@ -182,6 +182,18 @@ rpmsg_send_offchannel_raw(struct rpmsg_channel *, u32, 
u32, void *, int, bool);
__register_rpmsg_driver(drv, THIS_MODULE)
 
 /**
+ * module_rpmsg_driver() - Helper macro for registering an rpmsg driver
+ * @__rpmsg_driver: rpmsg_driver struct
+ *
+ * Helper macro for rpmsg drivers which do not do anything special in module
+ * init/exit. This eliminates a lot of boilerplate.  Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_rpmsg_driver(__rpmsg_driver) \
+   module_driver(__rpmsg_driver, register_rpmsg_driver, \
+   unregister_rpmsg_driver)
+
+/**
  * rpmsg_send() - send a message across to the remote processor
  * @rpdev: the rpmsg channel
  * @data: payload of message
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/4] rpmsg: drop owner assignment from spi_drivers

2016-05-04 Thread Andrew F. Davis
On 05/04/2016 01:55 PM, Suman Anna wrote:
> On 05/04/2016 01:34 PM, Andrew F. Davis wrote:
>> An rpmsg_driver does not need to set an owner, it will be populated by
>> the driver core.
> 
> spi_drivers in patch subject??
> 

copy/paste error, this is all based on my SPI patches that do this same
thing to that subsystem. Will fix.

Thanks,
Andrew

> regards
> Suman
> 
>>
>> Signed-off-by: Andrew F. Davis <a...@ti.com>
>> ---
>>  Documentation/rpmsg.txt | 1 -
>>  samples/rpmsg/rpmsg_client_sample.c | 1 -
>>  2 files changed, 2 deletions(-)
>>
>> diff --git a/Documentation/rpmsg.txt b/Documentation/rpmsg.txt
>> index f7edc3a..1d88426 100644
>> --- a/Documentation/rpmsg.txt
>> +++ b/Documentation/rpmsg.txt
>> @@ -249,7 +249,6 @@ MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
>>  
>>  static struct rpmsg_driver rpmsg_sample_client = {
>>  .drv.name   = KBUILD_MODNAME,
>> -.drv.owner  = THIS_MODULE,
>>  .id_table   = rpmsg_driver_sample_id_table,
>>  .probe  = rpmsg_sample_probe,
>>  .callback   = rpmsg_sample_cb,
>> diff --git a/samples/rpmsg/rpmsg_client_sample.c 
>> b/samples/rpmsg/rpmsg_client_sample.c
>> index 59b1344..82ed288 100644
>> --- a/samples/rpmsg/rpmsg_client_sample.c
>> +++ b/samples/rpmsg/rpmsg_client_sample.c
>> @@ -77,7 +77,6 @@ MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
>>  
>>  static struct rpmsg_driver rpmsg_sample_client = {
>>  .drv.name   = KBUILD_MODNAME,
>> -.drv.owner  = THIS_MODULE,
>>  .id_table   = rpmsg_driver_sample_id_table,
>>  .probe  = rpmsg_sample_probe,
>>  .callback   = rpmsg_sample_cb,
>>
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/4] rpmsg: use module_rpmsg_driver in existing drivers and examples

2016-05-04 Thread Andrew F. Davis
Existing drivers and examples are updated to use the
module_rpmsg_driver helper macro.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 Documentation/rpmsg.txt | 14 +-
 samples/rpmsg/rpmsg_client_sample.c | 13 +
 2 files changed, 2 insertions(+), 25 deletions(-)

diff --git a/Documentation/rpmsg.txt b/Documentation/rpmsg.txt
index 1d88426..b19700c 100644
--- a/Documentation/rpmsg.txt
+++ b/Documentation/rpmsg.txt
@@ -202,7 +202,6 @@ with the payload of the inbound message).
  a pointer to a previously-registered rpmsg_driver struct.
  Returns 0 on success, and an appropriate error value on failure.
 
-
 3. Typical usage
 
 The following is a simple rpmsg driver, that sends an "hello!" message
@@ -254,18 +253,7 @@ static struct rpmsg_driver rpmsg_sample_client = {
.callback   = rpmsg_sample_cb,
.remove = rpmsg_sample_remove,
 };
-
-static int __init init(void)
-{
-   return register_rpmsg_driver(_sample_client);
-}
-module_init(init);
-
-static void __exit fini(void)
-{
-   unregister_rpmsg_driver(_sample_client);
-}
-module_exit(fini);
+module_rpmsg_driver(rpmsg_sample_client);
 
 Note: a similar sample which can be built and loaded can be found
 in samples/rpmsg/.
diff --git a/samples/rpmsg/rpmsg_client_sample.c 
b/samples/rpmsg/rpmsg_client_sample.c
index 82ed288..d0e249c9 100644
--- a/samples/rpmsg/rpmsg_client_sample.c
+++ b/samples/rpmsg/rpmsg_client_sample.c
@@ -82,18 +82,7 @@ static struct rpmsg_driver rpmsg_sample_client = {
.callback   = rpmsg_sample_cb,
.remove = rpmsg_sample_remove,
 };
-
-static int __init rpmsg_client_sample_init(void)
-{
-   return register_rpmsg_driver(_sample_client);
-}
-module_init(rpmsg_client_sample_init);
-
-static void __exit rpmsg_client_sample_fini(void)
-{
-   unregister_rpmsg_driver(_sample_client);
-}
-module_exit(rpmsg_client_sample_fini);
+module_rpmsg_driver(rpmsg_sample_client);
 
 MODULE_DESCRIPTION("Remote processor messaging sample client driver");
 MODULE_LICENSE("GPL v2");
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/4] rpmsg: drop owner assignment from spi_drivers

2016-05-04 Thread Andrew F. Davis
An rpmsg_driver does not need to set an owner, it will be populated by
the driver core.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 Documentation/rpmsg.txt | 1 -
 samples/rpmsg/rpmsg_client_sample.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/Documentation/rpmsg.txt b/Documentation/rpmsg.txt
index f7edc3a..1d88426 100644
--- a/Documentation/rpmsg.txt
+++ b/Documentation/rpmsg.txt
@@ -249,7 +249,6 @@ MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
 
 static struct rpmsg_driver rpmsg_sample_client = {
.drv.name   = KBUILD_MODNAME,
-   .drv.owner  = THIS_MODULE,
.id_table   = rpmsg_driver_sample_id_table,
.probe  = rpmsg_sample_probe,
.callback   = rpmsg_sample_cb,
diff --git a/samples/rpmsg/rpmsg_client_sample.c 
b/samples/rpmsg/rpmsg_client_sample.c
index 59b1344..82ed288 100644
--- a/samples/rpmsg/rpmsg_client_sample.c
+++ b/samples/rpmsg/rpmsg_client_sample.c
@@ -77,7 +77,6 @@ MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
 
 static struct rpmsg_driver rpmsg_sample_client = {
.drv.name   = KBUILD_MODNAME,
-   .drv.owner  = THIS_MODULE,
.id_table   = rpmsg_driver_sample_id_table,
.probe  = rpmsg_sample_probe,
.callback   = rpmsg_sample_cb,
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] rpmsg: add THIS_MODULE to rpmsg_driver in rpmsg core

2016-05-04 Thread Andrew F. Davis
Add register_rpmsg_driver helper macro that adds THIS_MODULE to
rpmsg_driver for the registering driver. We rename and modify
the existing register_rpmsg_driver to enable this.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 drivers/rpmsg/virtio_rpmsg_bus.c | 8 +---
 include/linux/rpmsg.h| 8 +++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 1fcd27c..fe03b2a 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -436,17 +436,19 @@ static struct bus_type rpmsg_bus = {
 };
 
 /**
- * register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus
+ * __register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus
  * @rpdrv: pointer to a struct rpmsg_driver
+ * @owner: owning module/driver
  *
  * Returns 0 on success, and an appropriate error value on failure.
  */
-int register_rpmsg_driver(struct rpmsg_driver *rpdrv)
+int __register_rpmsg_driver(struct rpmsg_driver *rpdrv, struct module *owner)
 {
rpdrv->drv.bus = _bus;
+   rpdrv->drv.owner = owner;
return driver_register(>drv);
 }
-EXPORT_SYMBOL(register_rpmsg_driver);
+EXPORT_SYMBOL(__register_rpmsg_driver);
 
 /**
  * unregister_rpmsg_driver() - unregister an rpmsg driver from the rpmsg bus
diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h
index 82a6739..78e45ce 100644
--- a/include/linux/rpmsg.h
+++ b/include/linux/rpmsg.h
@@ -169,7 +169,7 @@ struct rpmsg_driver {
 
 int register_rpmsg_device(struct rpmsg_channel *dev);
 void unregister_rpmsg_device(struct rpmsg_channel *dev);
-int register_rpmsg_driver(struct rpmsg_driver *drv);
+int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner);
 void unregister_rpmsg_driver(struct rpmsg_driver *drv);
 void rpmsg_destroy_ept(struct rpmsg_endpoint *);
 struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_channel *,
@@ -177,6 +177,12 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct 
rpmsg_channel *,
 int
 rpmsg_send_offchannel_raw(struct rpmsg_channel *, u32, u32, void *, int, bool);
 
+/*
+ * use a macro to avoid include chaining to get THIS_MODULE
+ */
+#define register_rpmsg_driver(drv) \
+   __register_rpmsg_driver(drv, THIS_MODULE)
+
 /**
  * rpmsg_send() - send a message across to the remote processor
  * @rpdev: the rpmsg channel
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/2] hwmon: Add support for INA3221 Triple Current/Voltage Monitors

2016-04-25 Thread Andrew F. Davis
Add support for the the INA3221 26v capable, Triple channel,
Bi-Directional, Zero-Drift, Low-/High-Side, Current/Voltage Monitor
with I2C interface.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 Documentation/hwmon/ina3221 |  35 
 drivers/hwmon/Kconfig   |  11 ++
 drivers/hwmon/Makefile  |   1 +
 drivers/hwmon/ina3221.c | 423 
 4 files changed, 470 insertions(+)
 create mode 100644 Documentation/hwmon/ina3221
 create mode 100644 drivers/hwmon/ina3221.c

diff --git a/Documentation/hwmon/ina3221 b/Documentation/hwmon/ina3221
new file mode 100644
index 000..0ff7485
--- /dev/null
+++ b/Documentation/hwmon/ina3221
@@ -0,0 +1,35 @@
+Kernel driver ina3221
+=
+
+Supported chips:
+  * Texas Instruments INA3221
+Prefix: 'ina3221'
+Addresses: I2C 0x40 - 0x43
+Datasheet: Publicly available at the Texas Instruments website
+   http://www.ti.com/
+
+Author: Andrew F. Davis <a...@ti.com>
+
+Description
+---
+
+The Texas Instruments INA3221 monitors voltage, current, and power on the high
+side of up to three D.C. power supplies. The INA3221 monitors both shunt drop
+and supply voltage, with programmable conversion times and averaging, current
+and power are calculated host-side from these.
+
+Sysfs entries
+-
+
+in[123]_input   Bus voltage(mV) channels
+curr[123]_input Current(mA) measurement channels
+shunt[123]_resistor Shunt resistance(uOhm) channels
+curr[123]_crit  Critical alert current(mA) setting, activates the
+  corresponding alarm when the respective current
+  is above this value
+curr[123]_crit_alarmCritical alert current limit exceeded
+curr[123]_max   Warning alert current(mA) setting, activates the
+  corresponding alarm when the respective current
+  average is above this value.
+curr[123]_max_alarm Warning alert current limit exceeded
+in[456]_input   Shunt voltage(uV) for channels 1, 2, and 3 respectively
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5c2d13a..de08242 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1503,6 +1503,17 @@ config SENSORS_INA2XX
  This driver can also be built as a module.  If so, the module
  will be called ina2xx.
 
+config SENSORS_INA3221
+   tristate "Texas Instruments INA3221 Triple Power Monitor"
+   depends on I2C
+   select REGMAP_I2C
+   help
+ If you say yes here you get support for  the TI INA3221 Triple Power
+ Monitor.
+
+ This driver can also be built as a module.  If so, the module
+ will be called ina3221.
+
 config SENSORS_TC74
tristate "Microchip TC74"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 58cc3ac..83e8ab0 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
 obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
 obj-$(CONFIG_SENSORS_INA209)   += ina209.o
 obj-$(CONFIG_SENSORS_INA2XX)   += ina2xx.o
+obj-$(CONFIG_SENSORS_INA3221)  += ina3221.o
 obj-$(CONFIG_SENSORS_IT87) += it87.o
 obj-$(CONFIG_SENSORS_JC42) += jc42.o
 obj-$(CONFIG_SENSORS_JZ4740)   += jz4740-hwmon.o
diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
new file mode 100644
index 000..389a6ba
--- /dev/null
+++ b/drivers/hwmon/ina3221.c
@@ -0,0 +1,423 @@
+/*
+ * INA3221 Triple Current/Voltage Monitor
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
+ * Andrew F. Davis <a...@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define INA3221_DRIVER_NAME"ina3221"
+
+#define INA3221_CONFIG 0x00
+#define INA3221_SHUNT1 0x01
+#define INA3221_BUS1   0x02
+#define INA3221_SHUNT2 0x03
+#define INA3221_BUS2   0x04
+#define INA3221_SHUNT3 0x05
+#define INA3221_BUS3   0x06
+#define INA3221_CRIT1  0x07
+#define INA3221_WARN1  0x08
+#define INA3221_CRIT2  0x09
+#define INA3221_WARN2  0x0a
+#define INA3221_CRIT3  0x0b
+#define INA3221_WARN3  0x0c
+#define INA3221_MASK_ENABLE0x0f
+
+#defin

[PATCH v3 0/2] Add support for INA3221 Triple Current/Voltage Monitors

2016-04-25 Thread Andrew F. Davis
Hello all,

This series adds support for the INA3221 Triple Current/Voltage Monitor.

Changes from v2:
 - changed alarms to work on current
 - added of_match_table
 - other small fixups/typos

Changes from v1:
 - rearranged and renumbered sysfs enteries
 - added reading alert bits to sysfs
 - removed internal power calculation
 - added DT setting of shunt resistors
 - various other minor fixups

Thanks,
Andrew

Andrew F. Davis (2):
  hwmon: Define binding for the INA3221 hwmon driver
  hwmon: Add support for INA3221 Triple Current/Voltage Monitors

 .../devicetree/bindings/hwmon/ina3221.txt  |  19 +
 Documentation/hwmon/ina3221|  35 ++
 drivers/hwmon/Kconfig  |  11 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/ina3221.c| 423 +
 5 files changed, 489 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ina3221.txt
 create mode 100644 Documentation/hwmon/ina3221
 create mode 100644 drivers/hwmon/ina3221.c

-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/2] hwmon: Define binding for the INA3221 hwmon driver

2016-04-25 Thread Andrew F. Davis
Define a binding for the INA3221 Triple Current/Voltage Monitor.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 Documentation/devicetree/bindings/hwmon/ina3221.txt | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ina3221.txt

diff --git a/Documentation/devicetree/bindings/hwmon/ina3221.txt 
b/Documentation/devicetree/bindings/hwmon/ina3221.txt
new file mode 100644
index 000..8ec908b
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ina3221.txt
@@ -0,0 +1,19 @@
+Texas Instruments INA3221 Triple I2C Current/Voltage Monitor
+
+Required properties:
+ - compatible  : Should be "ti,ina3221".
+ - reg : I2C address of the device.
+
+Optional properties:
+ - shunt-resistors : Shunt resistor values in micro-Ohms for each channel.
+
+Example:
+
+ {
+   hw_monitor@40 {
+   compatible = "ti,ina3221";
+   reg = <0x40>;
+
+   shunt-resistors = <1000>, <2000>, <500>;
+   };
+};
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/2] hwmon: Add support for INA3221 Triple Current/Voltage Monitors

2016-04-25 Thread Andrew F. Davis
On 04/23/2016 11:53 AM, Guenter Roeck wrote:
> On 04/19/2016 11:28 AM, Andrew F. Davis wrote:
>> Add support for the the INA3221 26v capable, Triple channel,
>> Bi-Directional, Zero-Drift, Low-/High-Side, Current/Voltage Monitor
>> with I2C interface.
>>
>> Signed-off-by: Andrew F. Davis <a...@ti.com>
>> ---
>>   Documentation/hwmon/ina3221 |  35 
>>   drivers/hwmon/Kconfig   |  11 ++
>>   drivers/hwmon/Makefile  |   1 +
>>   drivers/hwmon/ina3221.c | 405
>> 
>>   4 files changed, 452 insertions(+)
>>   create mode 100644 Documentation/hwmon/ina3221
>>   create mode 100644 drivers/hwmon/ina3221.c
>>
>> diff --git a/Documentation/hwmon/ina3221 b/Documentation/hwmon/ina3221
>> new file mode 100644
>> index 000..82fd6b6
>> --- /dev/null
>> +++ b/Documentation/hwmon/ina3221
>> @@ -0,0 +1,35 @@
>> +Kernel driver ina3221
>> +=
>> +
>> +Supported chips:
>> +  * Texas Instruments INA3221
>> +Prefix: 'ina3221'
>> +Addresses: I2C 0x40 - 0x43
>> +Datasheet: Publicly available at the Texas Instruments website
>> +   http://www.ti.com/
>> +
>> +Author: Andrew F. Davis <a...@ti.com>
>> +
>> +Description
>> +---
>> +
>> +The Texas Instruments INA3221 monitors voltage, current, and power on
>> the high
>> +side of up to three D.C. power supplies. The INA3221 monitors both
>> shunt drop
>> +and supply voltage, with programmable conversion times and averaging,
>> current
>> +and power are calculated host-side from these.
>> +
>> +Sysfs entries
>> +-
>> +
>> +in[123]_input   Bus voltage(mV) channels
>> +curr[123]_input Current(mA) measurement channels
>> +shunt[123]_resistor Shunt resistance(uOhm) channels
>> +in[456]_input   Shunt voltage(uV) for channels 1, 2, and 3
>> respectively
>> +in[456]_critCritical alert shunt voltage(uV) setting,
>> activates the
>> +  corresponding alarm when the respective
>> shunt voltage
>> +  is above this value
>> +in[456]_crit_alarm  Critical alert shunt voltage limit exceeded
>> +in[456]_max Warning alert shunt voltage(uV) setting,
>> activates the
>> +  corresponding alarm when the respective
>> shunt voltage
>> +  average is above this value.
>> +in[456]_max_alarm   Warning alert shunt voltage limit exceeded
> 
> The primary use case for shunt resistor measurements is to report currents.
> Even the datasheets says so. The primary means to set and report warning
> and
> critical limits should therefore be the current attributes.
> 
> I accepted reporting the direct voltage values because, as it was
> pointed out
> to me earlier, it can be useful to know the voltage drop across the shunt
> resistors. I start to regret that :-(.
> 
> Please report alarms and limits with the current attributes.
> 

No problem, will rework this.

>> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
>> index 5c2d13a..de08242 100644
>> --- a/drivers/hwmon/Kconfig
>> +++ b/drivers/hwmon/Kconfig
>> @@ -1503,6 +1503,17 @@ config SENSORS_INA2XX
>> This driver can also be built as a module.  If so, the module
>> will be called ina2xx.
>>
>> +config SENSORS_INA3221
>> +tristate "Texas Instruments INA3221 Triple Power Monitor"
>> +depends on I2C
>> +select REGMAP_I2C
>> +help
>> +  If you say yes here you get support for  the TI INA3221 Triple
>> Power
>> +  Monitor.
>> +
>> +  This driver can also be built as a module.  If so, the module
>> +  will be called ina3221.
>> +
>>   config SENSORS_TC74
>>   tristate "Microchip TC74"
>>   depends on I2C
>> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
>> index 58cc3ac..83e8ab0 100644
>> --- a/drivers/hwmon/Makefile
>> +++ b/drivers/hwmon/Makefile
>> @@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
>>   obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
>>   obj-$(CONFIG_SENSORS_INA209)+= ina209.o
>>   obj-$(CONFIG_SENSORS_INA2XX)+= ina2xx.o
>> +obj-$(CONFIG_SENSORS_INA3221)+= ina3221.o
>>   obj-$(CONFIG_SENSORS_IT87)+= it87.o
>>   obj-$(CONFIG_SENSORS_JC42)+= jc42.o
>>   obj-$(CONFIG_SENSORS_JZ4740)+= jz4740-hwmon.o
>&g

[PATCH v2 2/2] hwmon: Add support for INA3221 Triple Current/Voltage Monitors

2016-04-19 Thread Andrew F. Davis
Add support for the the INA3221 26v capable, Triple channel,
Bi-Directional, Zero-Drift, Low-/High-Side, Current/Voltage Monitor
with I2C interface.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 Documentation/hwmon/ina3221 |  35 
 drivers/hwmon/Kconfig   |  11 ++
 drivers/hwmon/Makefile  |   1 +
 drivers/hwmon/ina3221.c | 405 
 4 files changed, 452 insertions(+)
 create mode 100644 Documentation/hwmon/ina3221
 create mode 100644 drivers/hwmon/ina3221.c

diff --git a/Documentation/hwmon/ina3221 b/Documentation/hwmon/ina3221
new file mode 100644
index 000..82fd6b6
--- /dev/null
+++ b/Documentation/hwmon/ina3221
@@ -0,0 +1,35 @@
+Kernel driver ina3221
+=
+
+Supported chips:
+  * Texas Instruments INA3221
+Prefix: 'ina3221'
+Addresses: I2C 0x40 - 0x43
+Datasheet: Publicly available at the Texas Instruments website
+   http://www.ti.com/
+
+Author: Andrew F. Davis <a...@ti.com>
+
+Description
+---
+
+The Texas Instruments INA3221 monitors voltage, current, and power on the high
+side of up to three D.C. power supplies. The INA3221 monitors both shunt drop
+and supply voltage, with programmable conversion times and averaging, current
+and power are calculated host-side from these.
+
+Sysfs entries
+-
+
+in[123]_input   Bus voltage(mV) channels
+curr[123]_input Current(mA) measurement channels
+shunt[123]_resistor Shunt resistance(uOhm) channels
+in[456]_input   Shunt voltage(uV) for channels 1, 2, and 3 respectively
+in[456]_critCritical alert shunt voltage(uV) setting, activates the
+  corresponding alarm when the respective shunt voltage
+  is above this value
+in[456]_crit_alarm  Critical alert shunt voltage limit exceeded
+in[456]_max Warning alert shunt voltage(uV) setting, activates the
+  corresponding alarm when the respective shunt voltage
+  average is above this value.
+in[456]_max_alarm   Warning alert shunt voltage limit exceeded
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5c2d13a..de08242 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1503,6 +1503,17 @@ config SENSORS_INA2XX
  This driver can also be built as a module.  If so, the module
  will be called ina2xx.
 
+config SENSORS_INA3221
+   tristate "Texas Instruments INA3221 Triple Power Monitor"
+   depends on I2C
+   select REGMAP_I2C
+   help
+ If you say yes here you get support for  the TI INA3221 Triple Power
+ Monitor.
+
+ This driver can also be built as a module.  If so, the module
+ will be called ina3221.
+
 config SENSORS_TC74
tristate "Microchip TC74"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 58cc3ac..83e8ab0 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
 obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
 obj-$(CONFIG_SENSORS_INA209)   += ina209.o
 obj-$(CONFIG_SENSORS_INA2XX)   += ina2xx.o
+obj-$(CONFIG_SENSORS_INA3221)  += ina3221.o
 obj-$(CONFIG_SENSORS_IT87) += it87.o
 obj-$(CONFIG_SENSORS_JC42) += jc42.o
 obj-$(CONFIG_SENSORS_JZ4740)   += jz4740-hwmon.o
diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
new file mode 100644
index 000..5350c28
--- /dev/null
+++ b/drivers/hwmon/ina3221.c
@@ -0,0 +1,405 @@
+/*
+ * INA3221 Triple Current/Voltage Monitor
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
+ * Andrew F. Davis <a...@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#define INA3221_DRIVER_NAME"ina3221"
+
+#define INA3221_CONFIG 0x00
+#define INA3221_SHUNT1 0x01
+#define INA3221_BUS1   0x02
+#define INA3221_SHUNT2 0x03
+#define INA3221_BUS2   0x04
+#define INA3221_SHUNT3 0x05
+#define INA3221_BUS3   0x06
+#define INA3221_CRIT1  0x07
+#define INA3221_WARN1  0x08
+#define INA3221_CRIT2  0x09
+#define INA3221_WARN2  0x0a
+#define INA3221_CRIT3  0x0b
+#define INA3221_WARN3  0x0c
+#define INA3221_SHUNT_SUM   

[PATCH v2 1/2] hwmon: Define binding for the INA3221 hwmon driver

2016-04-19 Thread Andrew F. Davis
Define a binding for the INA3221 Triple Current/Voltage Monitor.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 Documentation/devicetree/bindings/hwmon/ina3221.txt | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ina3221.txt

diff --git a/Documentation/devicetree/bindings/hwmon/ina3221.txt 
b/Documentation/devicetree/bindings/hwmon/ina3221.txt
new file mode 100644
index 000..8ec908b
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ina3221.txt
@@ -0,0 +1,19 @@
+Texas Instruments INA3221 Triple I2C Current/Voltage Monitor
+
+Required properties:
+ - compatible  : Should be "ti,ina3221".
+ - reg : I2C address of the device.
+
+Optional properties:
+ - shunt-resistors : Shunt resistor values in micro-Ohms for each channel.
+
+Example:
+
+ {
+   hw_monitor@40 {
+   compatible = "ti,ina3221";
+   reg = <0x40>;
+
+   shunt-resistors = <1000>, <2000>, <500>;
+   };
+};
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 0/2] Add support for INA3221 Triple Current/Voltage Monitors

2016-04-19 Thread Andrew F. Davis
Hello all,

This series adds support for the INA3221 Triple Current/Voltage Monitor.

Changes from v1:
 - rearranged and renumbered sysfs enteries
 - added reading alert bits to sysfs
 - removed internal power calculation
 - added DT setting of shunt resistors
 - various other minor fixups

Thanks,
Andrew

Andrew F. Davis (2):
  hwmon: Define binding for the INA3221 hwmon driver
  hwmon: Add support for INA3221 Triple Current/Voltage Monitors

 .../devicetree/bindings/hwmon/ina3221.txt  |  19 +
 Documentation/hwmon/ina3221|  35 ++
 drivers/hwmon/Kconfig  |  11 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/ina3221.c| 405 +
 5 files changed, 471 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ina3221.txt
 create mode 100644 Documentation/hwmon/ina3221
 create mode 100644 drivers/hwmon/ina3221.c

-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] hwmon: Add support for INA3221 Triple Current/Voltage Monitors

2016-04-19 Thread Andrew F. Davis
On 04/19/2016 09:09 AM, Guenter Roeck wrote:
> On 04/11/2016 01:50 PM, Andrew F. Davis wrote:
>> Add support for the the INA3221 26v capable, Triple channel,
>> Bi-Directional, Zero-Drift, Low-/High-Side, Current/Voltage Monitor
>> with I2C interface.
>>
>> Signed-off-by: Andrew F. Davis <a...@ti.com>
>> ---
>>   Documentation/hwmon/ina3221 |  32 
>>   drivers/hwmon/Kconfig   |  11 ++
>>   drivers/hwmon/Makefile  |   1 +
>>   drivers/hwmon/ina3221.c | 398
>> 
>>   4 files changed, 442 insertions(+)
>>   create mode 100644 Documentation/hwmon/ina3221
>>   create mode 100644 drivers/hwmon/ina3221.c
>>
>> diff --git a/Documentation/hwmon/ina3221 b/Documentation/hwmon/ina3221
>> new file mode 100644
>> index 000..3de3814
>> --- /dev/null
>> +++ b/Documentation/hwmon/ina3221
>> @@ -0,0 +1,32 @@
>> +Kernel driver ina3221
>> +=
>> +
>> +Supported chips:
>> +  * Texas Instruments INA3221
>> +Prefix: 'ina3221'
>> +Addresses: I2C 0x40 - 0x43
>> +Datasheet: Publicly available at the Texas Instruments website
>> +   http://www.ti.com/
>> +
>> +Author: Andrew F. Davis <a...@ti.com>
>> +
>> +Description
>> +---
>> +
>> +The Texas Instruments INA3221 monitors voltage, current, and power on
>> the high
>> +side of up to three D.C. power supplies. The INA3221 monitors both
>> shunt drop
>> +and supply voltage, with programmable conversion times and averaging,
>> current
>> +and power are calculated host-side from these.
>> +
>> +Sysfs entries
>> +-
>> +
>> +in[012]_input   Bus voltages(mV) for channels 1, 2, and 3
>> respectively
>> +in[345]_input   Shunt voltages(mV) for channels 1, 2, and 3
>> respectively
>> +curr[012]_input Current(mA) measurement for channels 1, 2,
>> and 3 respectively
> 
> Numbering for currents is [123], not [012].
> 

Okay, I'm guessing I should then change in to match?

>> +power[012]_inputPower(uW) measurement for channels 1, 2, and
>> 3 respectively
> 
> hwmon only reports what is there, and doesn't do calculations. The chip
> doesn't report
> the power, so please drop the power attributes.
> 

Sure

>> +shunt[012]_resistor Shunt resistance(uOhm) for channels 1, 2, and
>> 3 respectively
> 
> This should be a backup, if neither devicetree nor platform data are
> provided,
> not a primary means to provide the shunt resistor value. Also, there
> should be a default,
> to make sure the driver provides useful data even if nothing is configured.
> See ina2xx.c for an example.
> 

I'll add DT support for this.

>> +critical[012]_alarm Critical alert voltage(mV) setting, activated
>> when the
>> +respective shunt voltage is above this value.
>> +warning[012]_alarm  Warning alert voltage(mV) setting, activated
>> when the
>> +respective shunt voltage average is above
>> this value.
> 
> Alarm attributes report the alarm status, not voltages. Use in[012]_max and
> in[012]_crit attributes to set the limits. Report the alarm status with
> in[012]_max_alarm and in[012]_crit_alarm (from register 0x0f, bit 9-7 and
> 5-3).
> 

Will fix.

>> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
>> index 5c2d13a..de08242 100644
>> --- a/drivers/hwmon/Kconfig
>> +++ b/drivers/hwmon/Kconfig
>> @@ -1503,6 +1503,17 @@ config SENSORS_INA2XX
>> This driver can also be built as a module.  If so, the module
>> will be called ina2xx.
>>
>> +config SENSORS_INA3221
>> +tristate "Texas Instruments INA3221 Triple Power Monitor"
>> +depends on I2C
>> +select REGMAP_I2C
>> +help
>> +  If you say yes here you get support for  the TI INA3221 Triple
>> Power
>> +  Monitor.
>> +
>> +  This driver can also be built as a module.  If so, the module
>> +  will be called ina3221.
>> +
>>   config SENSORS_TC74
>>   tristate "Microchip TC74"
>>   depends on I2C
>> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
>> index 58cc3ac..83e8ab0 100644
>> --- a/drivers/hwmon/Makefile
>> +++ b/drivers/hwmon/Makefile
>> @@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
>>   obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
>>   obj-$(CONFIG_SENSORS_INA209)+= ina209.o
>>   o

[PATCH 1/1] hwmon: Add support for INA3221 Triple Current/Voltage Monitors

2016-04-11 Thread Andrew F. Davis
Add support for the the INA3221 26v capable, Triple channel,
Bi-Directional, Zero-Drift, Low-/High-Side, Current/Voltage Monitor
with I2C interface.

Signed-off-by: Andrew F. Davis <a...@ti.com>
---
 Documentation/hwmon/ina3221 |  32 
 drivers/hwmon/Kconfig   |  11 ++
 drivers/hwmon/Makefile  |   1 +
 drivers/hwmon/ina3221.c | 398 
 4 files changed, 442 insertions(+)
 create mode 100644 Documentation/hwmon/ina3221
 create mode 100644 drivers/hwmon/ina3221.c

diff --git a/Documentation/hwmon/ina3221 b/Documentation/hwmon/ina3221
new file mode 100644
index 000..3de3814
--- /dev/null
+++ b/Documentation/hwmon/ina3221
@@ -0,0 +1,32 @@
+Kernel driver ina3221
+=
+
+Supported chips:
+  * Texas Instruments INA3221
+Prefix: 'ina3221'
+Addresses: I2C 0x40 - 0x43
+Datasheet: Publicly available at the Texas Instruments website
+   http://www.ti.com/
+
+Author: Andrew F. Davis <a...@ti.com>
+
+Description
+---
+
+The Texas Instruments INA3221 monitors voltage, current, and power on the high
+side of up to three D.C. power supplies. The INA3221 monitors both shunt drop
+and supply voltage, with programmable conversion times and averaging, current
+and power are calculated host-side from these.
+
+Sysfs entries
+-
+
+in[012]_input   Bus voltages(mV) for channels 1, 2, and 3 respectively
+in[345]_input   Shunt voltages(mV) for channels 1, 2, and 3 
respectively
+curr[012]_input Current(mA) measurement for channels 1, 2, and 3 
respectively
+power[012]_inputPower(uW) measurement for channels 1, 2, and 3 
respectively
+shunt[012]_resistor Shunt resistance(uOhm) for channels 1, 2, and 3 
respectively
+critical[012]_alarm Critical alert voltage(mV) setting, activated when the
+respective shunt voltage is above this value.
+warning[012]_alarm  Warning alert voltage(mV) setting, activated when the
+respective shunt voltage average is above this value.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5c2d13a..de08242 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1503,6 +1503,17 @@ config SENSORS_INA2XX
  This driver can also be built as a module.  If so, the module
  will be called ina2xx.
 
+config SENSORS_INA3221
+   tristate "Texas Instruments INA3221 Triple Power Monitor"
+   depends on I2C
+   select REGMAP_I2C
+   help
+ If you say yes here you get support for  the TI INA3221 Triple Power
+ Monitor.
+
+ This driver can also be built as a module.  If so, the module
+ will be called ina3221.
+
 config SENSORS_TC74
tristate "Microchip TC74"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 58cc3ac..83e8ab0 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o
 obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
 obj-$(CONFIG_SENSORS_INA209)   += ina209.o
 obj-$(CONFIG_SENSORS_INA2XX)   += ina2xx.o
+obj-$(CONFIG_SENSORS_INA3221)  += ina3221.o
 obj-$(CONFIG_SENSORS_IT87) += it87.o
 obj-$(CONFIG_SENSORS_JC42) += jc42.o
 obj-$(CONFIG_SENSORS_JZ4740)   += jz4740-hwmon.o
diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
new file mode 100644
index 000..763e23b
--- /dev/null
+++ b/drivers/hwmon/ina3221.c
@@ -0,0 +1,398 @@
+/*
+ * INA3221 Triple Current/Voltage Monitor
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
+ * Andrew F. Davis <a...@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#define INA3221_DRIVER_NAME"ina3221"
+
+#define INA3221_CONFIG 0x00
+#define INA3221_SHUNT1 0x01
+#define INA3221_BUS1   0x02
+#define INA3221_SHUNT2 0x03
+#define INA3221_BUS2   0x04
+#define INA3221_SHUNT3 0x05
+#define INA3221_BUS3   0x06
+#define INA3221_CRIT1  0x07
+#define INA3221_WARN1  0x08
+#define INA3221_CRIT2  0x09
+#define INA3221_WARN2  0x0a
+#define INA3221_CRIT3  0x0b
+#define INA3221_WARN3  0x0c
+#define INA3221_SHUNT_SUM  0x0d
+#define INA3221_SHUNT_SUM_LIMIT0x0e
+#def