Re: [PATCH v2 1/2] hwmon: Add driver for Texas Instruments TMP512/513 sensor chips

2019-10-01 Thread Guenter Roeck
On Tue, Oct 01, 2019 at 05:49:52PM +, Tremblay, Eric wrote:
> hwmon: Add driver for Texas Instruments TMP512/513 sensor
> 
> TI's TMP512/513 are I2C/SMBus system monitor chips. These chips
> monitor the supply voltage, supply current, power consumption
> and provide one local and up to three (TMP513) remote temperature sensors.
> 
> It has been tested using a TI TMP513 development kit (TMP513EVM)
> 
> Signed-off-by: Eric Tremblay 
> ---
>  Documentation/hwmon/tmp513.rst |  98 
>  MAINTAINERS|   7 +
>  drivers/hwmon/Kconfig  |  10 +
>  drivers/hwmon/Makefile |   1 +
>  drivers/hwmon/tmp513.c | 800 +
>  5 files changed, 916 insertions(+)
>  create mode 100644 Documentation/hwmon/tmp513.rst
>  create mode 100644 drivers/hwmon/tmp513.c
> 
> diff --git a/Documentation/hwmon/tmp513.rst b/Documentation/hwmon/tmp513.rst
> new file mode 100644
> index ..3ba6f6f14220
> --- /dev/null
> +++ b/Documentation/hwmon/tmp513.rst
> @@ -0,0 +1,98 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +Kernel driver tmp513
> +
> +
> +Supported chips:
> +
> +  * Texas Instruments TMP512
> +
> +Prefix: 'tmp512'
> +
> +Datasheet: http://www.ti.com/lit/ds/symlink/tmp512.pdf
> +
> +  * Texas Instruments TMP513
> +
> +Prefix: 'tmp513'
> +
> +Datasheet: http://www.ti.com/lit/ds/symlink/tmp513.pdf
> +
> +Authors:
> +
> + Eric Tremblay 
> +
> +Description
> +---
> +
> +This driver implements support for Texas Instruments TMP512, and TMP513
> +temperature and power supply sensor chips. These chips implement one
> +local and up to three (TMP513) temperature sensors. The chips also implement
> +power supply monitoring such as shunt voltage, shunt current, bus voltage
> +and power consumption.
> +
> +The temperatures are measured in degrees Celsius with a range of
> +-40 to + 125 degress Celcius with a resolution of 0.0625 degree C.
> +
> +The driver exports the temperature values via the following sysfs files:
> +
> +**temp[1-4]_input**
> +
> +**temp[1-4]_crit**
> +
> +**temp[1-4]_crit_alarm**
> +
> +The shunt voltage is measured in micro volts. There are four configurable
> +range: 320mV, 160mV, 80mV and 40mV all of them with a resolution of 10 uV.
> +The range depends on the pga gain specified in the device tree
> +with "pga-gain" (default to 8). The range will be equal to pga gain
> +multiply by 40mV.
> +
> +The driver exports the shunt voltage values via the following sysFs files:
> +
> +**in0_input**
> +
> +**in0_lcrit**
> +
> +**in0_lcrit_alarm**
> +
> +**in0_crit**
> +
> +**in0_crit_alarm**
> +
> +The bus voltage is measured in milli volts. There are two configuable
> +range: 32V and 16V both with a resolution of 4mV. It can be configured in the
> +device tree with "bus-voltage-range" (default to 32V);
> +
> +The driver exports the bus voltage values via the following sysFs files:
> +
> +**in0_input**
> +
> +**in0_lcrit**
> +
> +**in0_lcrit_alarm**
> +
> +**in0_crit**
> +
> +**in0_crit_alarm**
> +
> +The power and the currents range and resolution depends on the calibration
> +register value. Those values are calculate by the hardware using those
> +formula:
> +
> +Current = (ShuntVoltage * CalibrationRegister) / 4096
> +Power   = (Current * BusVoltage) / 5000
> +
> +The driver exports the current and power values via the following sysFs 
> files:
> +
> +**curr0_input**
> +
> +**power1_input**
> +
> +**power1_crit**
> +
> +**power1_crit_alarm**
> +
> +The calibration process follow the procedure of the datasheet (without 
> overflow)
> +and depend on the shunt resistor value, needed in the device tree 
> "shunt-resistor-mohm".
> +It also depends on the pga gain and the maximum expected current, also 
> specified from
> +the device tree "max-expected-current-ma". If not specified it default to 
> the maximum
> +possible current depending on the pga gain.
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 296de2b51c83..1d13e5be6661 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -16369,6 +16369,13 @@ S:   Maintained
>  F:   Documentation/hwmon/tmp401.rst
>  F:   drivers/hwmon/tmp401.c
>  
> +TMP513 HARDWARE MONITOR DRIVER
> +M:   Eric Tremblay 
> +L:   linux-hwmon@vger.kernel.org
> +S:   Maintained
> +F:   Documentation/hwmon/tmp513.rst
> +F:   drivers/hwmon/tmp513.c
> +
>  TMPFS (SHMEM FILESYSTEM)
>  M:   Hugh Dickins 
>  L:   linux...@kvack.org
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 13a6b4afb4b3..926e3c98dbdf 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -1709,6 +1709,16 @@ config SENSORS_TMP421
> This driver can also be built as a module. If so, the module
> will be called tmp421.
>  
> +config SENSORS_TMP513
> + tristate "Texas Instruments TMP513 and compatibles"
> + depends on I2C
> + help
> +   If you say yes here you get support for Texas Instruments TMP512,
> +   and TMP513 temperature and power supply 

[PATCH v2 1/2] hwmon: Add driver for Texas Instruments TMP512/513 sensor chips

2019-10-01 Thread Tremblay, Eric
hwmon: Add driver for Texas Instruments TMP512/513 sensor

TI's TMP512/513 are I2C/SMBus system monitor chips. These chips
monitor the supply voltage, supply current, power consumption
and provide one local and up to three (TMP513) remote temperature sensors.

It has been tested using a TI TMP513 development kit (TMP513EVM)

Signed-off-by: Eric Tremblay 
---
 Documentation/hwmon/tmp513.rst |  98 
 MAINTAINERS|   7 +
 drivers/hwmon/Kconfig  |  10 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/tmp513.c | 800 +
 5 files changed, 916 insertions(+)
 create mode 100644 Documentation/hwmon/tmp513.rst
 create mode 100644 drivers/hwmon/tmp513.c

diff --git a/Documentation/hwmon/tmp513.rst b/Documentation/hwmon/tmp513.rst
new file mode 100644
index ..3ba6f6f14220
--- /dev/null
+++ b/Documentation/hwmon/tmp513.rst
@@ -0,0 +1,98 @@
+.. SPDX-License-Identifier: GPL-2.0
+Kernel driver tmp513
+
+
+Supported chips:
+
+  * Texas Instruments TMP512
+
+Prefix: 'tmp512'
+
+Datasheet: http://www.ti.com/lit/ds/symlink/tmp512.pdf
+
+  * Texas Instruments TMP513
+
+Prefix: 'tmp513'
+
+Datasheet: http://www.ti.com/lit/ds/symlink/tmp513.pdf
+
+Authors:
+
+   Eric Tremblay 
+
+Description
+---
+
+This driver implements support for Texas Instruments TMP512, and TMP513
+temperature and power supply sensor chips. These chips implement one
+local and up to three (TMP513) temperature sensors. The chips also implement
+power supply monitoring such as shunt voltage, shunt current, bus voltage
+and power consumption.
+
+The temperatures are measured in degrees Celsius with a range of
+-40 to + 125 degress Celcius with a resolution of 0.0625 degree C.
+
+The driver exports the temperature values via the following sysfs files:
+
+**temp[1-4]_input**
+
+**temp[1-4]_crit**
+
+**temp[1-4]_crit_alarm**
+
+The shunt voltage is measured in micro volts. There are four configurable
+range: 320mV, 160mV, 80mV and 40mV all of them with a resolution of 10 uV.
+The range depends on the pga gain specified in the device tree
+with "pga-gain" (default to 8). The range will be equal to pga gain
+multiply by 40mV.
+
+The driver exports the shunt voltage values via the following sysFs files:
+
+**in0_input**
+
+**in0_lcrit**
+
+**in0_lcrit_alarm**
+
+**in0_crit**
+
+**in0_crit_alarm**
+
+The bus voltage is measured in milli volts. There are two configuable
+range: 32V and 16V both with a resolution of 4mV. It can be configured in the
+device tree with "bus-voltage-range" (default to 32V);
+
+The driver exports the bus voltage values via the following sysFs files:
+
+**in0_input**
+
+**in0_lcrit**
+
+**in0_lcrit_alarm**
+
+**in0_crit**
+
+**in0_crit_alarm**
+
+The power and the currents range and resolution depends on the calibration
+register value. Those values are calculate by the hardware using those
+formula:
+
+Current = (ShuntVoltage * CalibrationRegister) / 4096
+Power   = (Current * BusVoltage) / 5000
+
+The driver exports the current and power values via the following sysFs files:
+
+**curr0_input**
+
+**power1_input**
+
+**power1_crit**
+
+**power1_crit_alarm**
+
+The calibration process follow the procedure of the datasheet (without 
overflow)
+and depend on the shunt resistor value, needed in the device tree 
"shunt-resistor-mohm".
+It also depends on the pga gain and the maximum expected current, also 
specified from
+the device tree "max-expected-current-ma". If not specified it default to the 
maximum
+possible current depending on the pga gain.
diff --git a/MAINTAINERS b/MAINTAINERS
index 296de2b51c83..1d13e5be6661 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16369,6 +16369,13 @@ S: Maintained
 F: Documentation/hwmon/tmp401.rst
 F: drivers/hwmon/tmp401.c
 
+TMP513 HARDWARE MONITOR DRIVER
+M: Eric Tremblay 
+L: linux-hwmon@vger.kernel.org
+S: Maintained
+F: Documentation/hwmon/tmp513.rst
+F: drivers/hwmon/tmp513.c
+
 TMPFS (SHMEM FILESYSTEM)
 M: Hugh Dickins 
 L: linux...@kvack.org
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 13a6b4afb4b3..926e3c98dbdf 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1709,6 +1709,16 @@ config SENSORS_TMP421
  This driver can also be built as a module. If so, the module
  will be called tmp421.
 
+config SENSORS_TMP513
+   tristate "Texas Instruments TMP513 and compatibles"
+   depends on I2C
+   help
+ If you say yes here you get support for Texas Instruments TMP512,
+ and TMP513 temperature and power supply sensor chips.
+
+ This driver can also be built as a module. If so, the module
+ will be called tmp513.
+
 config SENSORS_VEXPRESS
tristate "Versatile Express"
depends on VEXPRESS_CONFIG
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 40c036ea45e6..762642291914 100644
--- a/drivers/hwmon/Makefile