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

2019-10-04 Thread Guenter Roeck
On Thu, Oct 03, 2019 at 06:34:17PM +, Tremblay, Eric wrote:
> hwmon: Add driver for Texas Instruments TMP512/513 sensor chips.
> 
> 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   | 102 +++
>  MAINTAINERS  |   7 +
>  drivers/hwmon/Kconfig|  10 +
>  drivers/hwmon/Makefile   |   1 +
>  drivers/hwmon/tmp513.c   | 901 +++
>  include/linux/platform_data/tmp513.h |  28 +
>  6 files changed, 1049 insertions(+)
>  create mode 100644 Documentation/hwmon/tmp513.rst
>  create mode 100644 drivers/hwmon/tmp513.c
>  create mode 100644 include/linux/platform_data/tmp513.h
> 
> diff --git a/Documentation/hwmon/tmp513.rst b/Documentation/hwmon/tmp513.rst
> new file mode 100644
> index ..b3837748ca7e
> --- /dev/null
> +++ b/Documentation/hwmon/tmp513.rst
> @@ -0,0 +1,102 @@
> +.. 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 degrees with a resolution of 0.0625 degree C.
> +
> +For hysteresis value, only the first channel is writable. Writing to it
> +will affect all other values since each channels are sharing the same
> +hysteresis value. The hysteresis is in degrees Celsius with a range of
> +0 to 127.5 degrees with a resolution of 0.5 degree.
> +
> +The driver exports the temperature values via the following sysfs files:
> +
> +**temp[1-4]_input**
> +
> +**temp[1-4]_crit**
> +
> +**temp[1-4]_crit_alarm**
> +
> +**temp[1-4]_crit_hyst**
> +
> +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 and the pga_gain value.
> 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 

Re: [PATCH 09/10] hwmon: (lm70) Avoid undefined reference to match table

2019-10-04 Thread Guenter Roeck
On Fri, Oct 04, 2019 at 02:43:33PM -0700, Stephen Boyd wrote:
> We're going to remove of_match_ptr() from the definition of
> of_match_device() when CONFIG_OF=n. This way we can always be certain
> that of_match_device() acts the same when CONFIG_OF is set and when it
> isn't. Add of_match_ptr() here so that this doesn't break when that
> change is made to the of_match_device() API.
> 
> Cc: Arnd Bergmann 
> Cc: Geert Uytterhoeven 
> Cc: Jean Delvare 
> Cc: Guenter Roeck 
> Cc: Rob Herring 
> Cc: Frank Rowand 
> Cc: 
> Signed-off-by: Stephen Boyd 

Acked-by: Guenter Roeck 

> ---
> 
> Please ack or pick for immediate merge so the last patch can be merged.
> 
>  drivers/hwmon/lm70.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c
> index 4122e59f0bb4..57480dada955 100644
> --- a/drivers/hwmon/lm70.c
> +++ b/drivers/hwmon/lm70.c
> @@ -155,7 +155,7 @@ static int lm70_probe(struct spi_device *spi)
>   struct lm70 *p_lm70;
>   int chip;
>  
> - match = of_match_device(lm70_of_ids, >dev);
> + match = of_match_device(of_match_ptr(lm70_of_ids), >dev);
>   if (match)
>   chip = (int)(uintptr_t)match->data;
>   else
> -- 
> Sent by a computer through tubes
> 


[PATCH 09/10] hwmon: (lm70) Avoid undefined reference to match table

2019-10-04 Thread Stephen Boyd
We're going to remove of_match_ptr() from the definition of
of_match_device() when CONFIG_OF=n. This way we can always be certain
that of_match_device() acts the same when CONFIG_OF is set and when it
isn't. Add of_match_ptr() here so that this doesn't break when that
change is made to the of_match_device() API.

Cc: Arnd Bergmann 
Cc: Geert Uytterhoeven 
Cc: Jean Delvare 
Cc: Guenter Roeck 
Cc: Rob Herring 
Cc: Frank Rowand 
Cc: 
Signed-off-by: Stephen Boyd 
---

Please ack or pick for immediate merge so the last patch can be merged.

 drivers/hwmon/lm70.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c
index 4122e59f0bb4..57480dada955 100644
--- a/drivers/hwmon/lm70.c
+++ b/drivers/hwmon/lm70.c
@@ -155,7 +155,7 @@ static int lm70_probe(struct spi_device *spi)
struct lm70 *p_lm70;
int chip;
 
-   match = of_match_device(lm70_of_ids, >dev);
+   match = of_match_device(of_match_ptr(lm70_of_ids), >dev);
if (match)
chip = (int)(uintptr_t)match->data;
else
-- 
Sent by a computer through tubes



[PATCH 00/10] Stop NULLifying match pointer in of_match_device()

2019-10-04 Thread Stephen Boyd
of_match_device() uses of_match_ptr() to make the match table argument
NULL via the pre-processor when CONFIG_OF=n. This makes life harder for
compilers who think that match tables are never used and warn about
unused variables when CONFIG_OF=n. This series changes various callers
to use of_device_get_match_data() instead, which doesn't have this
problem, and removes the of_match_ptr() usage from of_match_device() so
that the compiler can stop complaining about unused variables. It will
do dead code elimination instead and remove the match table if it isn't
actually used.

Huge Cc list!

Cc: Alessandro Zummo 
Cc: Alexandre Belloni 
Cc: Alexandre Torgue 
Cc: 
Cc: Andrew Lunn 
Cc: Arnd Bergmann 
Cc: Dan Murphy 
Cc: "David S. Miller" 
Cc: Frank Rowand 
Cc: Geert Uytterhoeven 
Cc: Greg Kroah-Hartman 
Cc: Gregory Clement 
Cc: Grygorii Strashko 
Cc: Guenter Roeck 
Cc: Jacek Anaszewski 
Cc: Jacopo Mondi 
Cc: Jaroslav Kysela 
Cc: Jason Cooper 
Cc: Jean Delvare 
Cc: Jiri Slaby 
Cc: Liam Girdwood 
Cc: 
Cc: 
Cc: 
Cc: 
Cc: 
Cc: 
Cc: 
Cc: 
Cc: 
Cc: Mark Brown 
Cc: Mauro Carvalho Chehab 
Cc: Maxime Coquelin 
Cc: Paul Cercueil 
Cc: Pavel Machek 
Cc: Richard Leitner 
Cc: Riku Voipio 
Cc: Rob Herring 
Cc: Sebastian Hesselbarth 
Cc: Takashi Iwai 

Stephen Boyd (10):
  leds: pca953x: Use of_device_get_match_data()
  media: renesas-ceu: Use of_device_get_match_data()
  rtc: armada38x: Use of_device_get_match_data()
  drivers: net: davinci_mdio: Use of_device_get_match_data()
  serial: stm32: Use of_device_get_match_data()
  usb: usb251xb: Use of_device_get_match_data()
  ASoC: jz4740: Use of_device_get_match_data()
  spi: gpio: Look for a device node instead of match
  hwmon: (lm70) Avoid undefined reference to match table
  of/device: Don't NULLify match table in of_match_device() with
CONFIG_OF=n

 drivers/hwmon/lm70.c   |  2 +-
 drivers/leds/leds-pca9532.c| 14 +
 drivers/media/platform/renesas-ceu.c   |  2 +-
 drivers/net/ethernet/ti/davinci_mdio.c | 12 ++---
 drivers/rtc/rtc-armada38x.c| 10 ++--
 drivers/spi/spi-gpio.c |  5 +-
 drivers/tty/serial/stm32-usart.c   | 71 --
 drivers/tty/serial/stm32-usart.h   |  2 +-
 drivers/usb/misc/usb251xb.c| 12 ++---
 include/linux/of_device.h  |  4 +-
 sound/soc/jz4740/jz4740-i2s.c  |  5 +-
 11 files changed, 55 insertions(+), 84 deletions(-)


base-commit: 54ecb8f7028c5eb3d740bb82b0f1d90f2df63c5c
-- 
Sent by a computer through tubes


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

2019-10-04 Thread Guenter Roeck
On Thu, Oct 03, 2019 at 06:34:41PM +, Tremblay, Eric wrote:
> hwmon: Add DT bindings for TMP513 driver
> 
$subject is misleading.

> Signed-off-by: Eric Tremblay 
> ---
>  .../devicetree/bindings/hwmon/tmp513.txt  | 33 +++
>  1 file changed, 33 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/hwmon/tmp513.txt
> 
> diff --git a/Documentation/devicetree/bindings/hwmon/tmp513.txt 
> b/Documentation/devicetree/bindings/hwmon/tmp513.txt
> new file mode 100644
> index ..341c764e9173
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/tmp513.txt
> @@ -0,0 +1,33 @@
> +TMP513 system monitor sensor
> +-
> +
> +Require node properties:
> +- compatible: one of
> + "ti,tmp512"
> + "ti,tmp513"
> +- reg : the I2C address of the device. This is 0x5c, 0x5d, 0x5e, or 0x5f.
> +
> +Optional properties:
> +- shunt-resistor-uohm : The shunt resistor value in uOhm. If 0, the 
> calibration process
> + will be skiped and the current and power measurement engine 
> will not work.
> + Temperature and voltage measurement will continue to work. The 
> shunt value also
> + need to respect : rshunt <= pga-gain * 40 * 1000 * 1000. If 
> not, it's not possible
> + to compute a valid calibration value.

If this is not mandatory, I would suggest to declare a sensible default,
such as 1 mOhm / 1000 uOhm.

> +- bus-voltage-range: 32V or 16V, default to 32V.

Question for Rob: Does this need "-volt" as part of the name ?

> +- pga-gain: The gain value for the PGA function. This is 8, 4, 2 or 1. 
> Default to 8.

It might be useful to explain "pga".

> +- temp_2_nfactor: nFactor for remote channel 1. Value according to Table 11 
> in datasheet.
> +- temp_3_nfactor: nFactor for remote channel 2. Value according to Table 11 
> in datasheet.
> +- temp_4_nfactor: nFactor for remote channel 3. Value according to Table 11 
> in datasheet,

Maybe an array and temp-nfactor, with 0x0 meaning "use default" ?

> + TMP513 only.
> +
> +Example:
> + tmp513@5c {
> +   compatible = "ti,tmp513";
> +   reg = <0x5C>;
> +   shunt-resistor-uohm = <33>;
> +   bus-voltage-range = <32>;
> +   pga-gain = <8>;
> +   temp_2_nfactor = <0x01>;
> +   temp_3_nfactor = <0x02>;
> +   temp_4_nfactor = <0x03>;
> + };
> -- 
> 2.17.1
> 


RE: [PATCH v3 0/2] hwmon: Add driver for Texas Instruments TMP512/513 sensor chips

2019-10-04 Thread Tremblay, Eric
> On Thu, Oct 03, 2019 at 06:35:51PM +, Tremblay, Eric wrote:
> > > Version three of the driver for Texas Instruments TMP512/513 sensors.
> > >
> > > Thanks again for the review, I think we are getting close. I'm not
> > > in an easy position for now to test the driver without device tree.
> > > I can put the required effort to
> >
> > Sorry, I mean that I'm not in a good position to test it, but I can put the 
> > required effort to if needed.
> 
> All you would need to do is to use device_ API functions instead of 
> of_device_ API functions, so I can not entirely follow your logic.

I was clearly missing some piece of knowledge about the device API... I did 
some research and I was able to instantiate and test
the driver without using the of_device API. The version 3 work as expected with 
or without platform_data provided.

Eric 
> 
> Guenter
> 
> > >
> > > Main changes from version 2:
> > >   - Remove the neccessity to provide a shunt-resistor value
> > >   - Remove max-expected-current-ma configuration and always
> > > use max possible current for calibration
> > >   - Make sure calculation during calibration can't overflow
> > >   - Add value clamping for DT value and runtime parameters
> > >   - Support non DT system
> > >   - Move hysteresis from DT to standard attribute
> > >
> > > Main changes from version 1:
> > >   - Use the with_info API instead of sysfs attributes.
> > >   - Remove non-standard attributes and raw value.
> > >   - Move settings that were non-standard attributes to
> > > device tree, update documentation as well.
> > >   - Fix coding style issues
> > >
> > > Eric Tremblay (2):
> > >   Add driver for Texas Instruments TMP512/513 sensor chips.
> > >   Add DT bindings for TMP513 driver
> > >
> > >  .../devicetree/bindings/hwmon/tmp513.txt  |  33 +
> > >  Documentation/hwmon/tmp513.rst| 102 ++
> > >  MAINTAINERS   |   7 +
> > >  drivers/hwmon/Kconfig |  10 +
> > >  drivers/hwmon/Makefile|   1 +
> > >  drivers/hwmon/tmp513.c| 901 ++
> > >  include/linux/platform_data/tmp513.h  |  28 +
> > >  7 files changed, 1082 insertions(+)  create mode 100644
> > > Documentation/devicetree/bindings/hwmon/tmp513.txt
> > >  create mode 100644 Documentation/hwmon/tmp513.rst  create mode
> > > 100644 drivers/hwmon/tmp513.c  create mode 100644
> > > include/linux/platform_data/tmp513.h
> > >
> > > --
> > > 2.17.1
> >