[PATCH v2 1/2] hwmon: Add MAX31760 fan controller driver.

2017-04-11 Thread John Muir
Add a driver for the Maxim Integrated MAX31760 Precision Fan
Speed Controller.

v2:
- Fixup open firmware code.
- Add a few comments.

Signed-off-by: John Muir <j...@jmuir.com>
---
 Documentation/hwmon/max31760 |   41 ++
 drivers/hwmon/Kconfig|   10 +
 drivers/hwmon/Makefile   |1 +
 drivers/hwmon/max31760.c | 1461 ++
 4 files changed, 1513 insertions(+)
 create mode 100644 Documentation/hwmon/max31760
 create mode 100644 drivers/hwmon/max31760.c

diff --git a/Documentation/hwmon/max31760 b/Documentation/hwmon/max31760
new file mode 100644
index ..6f53ac6112a5
--- /dev/null
+++ b/Documentation/hwmon/max31760
@@ -0,0 +1,41 @@
+Kernel driver max31760
+==
+
+Supported chips:
+  * Maxim Integrated MAX31760
+Prefix: 'max31760'
+Addresses scanned: none
+Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31760.pdf
+
+Author:
+   John Muir <j...@jmuir.com>
+
+Description
+---
+
+The MAX31760 integrates temperature sensing along with precision PWM fan
+control. Please read the datasheet referenced above for a comprehensive
+description of this device.
+
+This device driver's hwmon integration provides the common sysfs interfaces to
+manage two fans and two temperature sensors, and pwm controls for the fan 
speed.
+A temperature to pwm lookup table is exposed via a series of 'auto_point'
+configuration files. See Documentation/hwmon/sysfs-interface for more
+information.
+
+The following custom controls are defined (in the custom sub-directory):
+
+control- Accepts control commands:
+ "reset"   - Execute a soft reset of the device.
+ "clearff" - Clear the fan fault.
+
+eeprom_read- Read from the EEPROM into registers.
+eeprom_write- Write register contents to the EEPROM.
+ Write "0" to these to read or write the entire register
+ contents. Write a bit-field as per the datasheet to write a
+ portion of the register contents.
+
+pwm1_fan_fault  - PWM value in the range of 0 to 255 used when a fan is faulty.
+
+pwm1_ramp_rate  - PWM increment per second when the PWM value is changed.
+ Accepted values are 8, 16, 32, or 255 (instantaneous).
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 337e9078df0a..83c9b46a3876 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -895,6 +895,16 @@ config SENSORS_MAX6697
  This driver can also be built as a module.  If so, the module
  will be called max6697.
 
+config SENSORS_MAX31760
+   tristate "Maxim MAX31760 fan controller"
+   depends on I2C
+   help
+ If you say yes here you get support for the Maxim Integrated
+ MAX31760 Precision Fan-Speed Controller.
+
+ This driver can also be built as a module.  If so, the module
+ will be called max31760.
+
 config SENSORS_MAX31790
tristate "Maxim MAX31790 sensor chip"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index d2bdccc000e6..e0ab73e0caa6 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -120,6 +120,7 @@ obj-$(CONFIG_SENSORS_MAX6639)   += max6639.o
 obj-$(CONFIG_SENSORS_MAX6642)  += max6642.o
 obj-$(CONFIG_SENSORS_MAX6650)  += max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)  += max6697.o
+obj-$(CONFIG_SENSORS_MAX31760)  += max31760.o
 obj-$(CONFIG_SENSORS_MAX31790) += max31790.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
 obj-$(CONFIG_SENSORS_MCP3021)  += mcp3021.o
diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c
new file mode 100644
index ..f3de3526d802
--- /dev/null
+++ b/drivers/hwmon/max31760.c
@@ -0,0 +1,1461 @@
+/* Maxim Integrated MAX31760 Precision Fan-Speed Controller driver
+ *
+ * Copyright (C) 2017 Google, Inc.
+ * Author: muirj
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME "max31760"
+
+/*
+ * MAX31760 registers.
+ * Indentation helps identify how these constants apply:
+ *  Register number.
+ *  Per-register bit fields.
+ *  Values for multi-bit fields.
+ */
+#define MAX31760_REG_CR1   0x00 /* Control Register 1 */
+#define MAX31760_CR1_TIS0x01 /* Temperature Index Source */
+#defi

[PATCH v2 2/2] devicetree: Document the max31760 device binding.

2017-04-11 Thread John Muir
v2:
- Fixup based on comments.

Signed-off-by: John Muir <j...@jmuir.com>
---
 .../devicetree/bindings/hwmon/max31760.txt | 72 ++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/max31760.txt

diff --git a/Documentation/devicetree/bindings/hwmon/max31760.txt 
b/Documentation/devicetree/bindings/hwmon/max31760.txt
new file mode 100644
index ..760fdf0b55e0
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/max31760.txt
@@ -0,0 +1,72 @@
+MAX31760 fan controller
+---
+
+This device supports I2C only. Fan sub-nodes must be defined in order to enable
+the fan tachometer input. See also the datasheet:
+https://datasheets.maximintegrated.com/en/ds/MAX31760.pdf
+
+Required node properties:
+ - compatible: "maxim,max31760"
+ - reg: The I2C address of the device. This is 0x50 - 0x57 depending on the
+   hardware configuration.
+ - #address-cells: Must be 1.
+ - #size-cells: Must be 0.
+
+Optional node properties:
+ - maxim,fan-fail-full-only: Boolean; Assert a fan failure only when the PWM is
+   at 100%.
+ - maxim,fan-rd-signal: Boolean; Fans provide a rotation detection (RD) signal
+   instead of generating square-wave pulses.
+ - maxim,fan-rd-polarity-high: Boolean; RD is high when the fan is running, not
+   low. Only relevant when fan-rd-signal is true.
+ - maxim,fan-signal-enabled: Boolean; Externally driving FF/FS low should force
+   PWM output to 100%.
+ - maxim,fan-spin-up-enabled: Boolean; For fan startup set the PWM to 100% 
until
+   tach is detected or two seconds have passed before reducing to the target
+   value.
+ - maxim,pwm-polarity-negative: Boolean; 100% PWM is when PWM is low, not high.
+ - maxim,pwm-pulse-stretch-enabled: Boolean; Enable PWM pulse stretching.
+ - maxim,pwm-zero-fan-can-fail: Boolean; Enable fan failure detection while
+   ramping to 0% PWM.
+
+Fan sub-nodes must be present in order to enable the fan.
+
+Required fan sub-node properties:
+ - reg: Fan address. Must be <0x00> or <0x01>.
+
+Optional fan sub-node properties:
+ - label: String; Assigned to the hwmon fanX_label property.
+
+Temperature sub-nodes are optional.
+
+Required temp sub-node properties:
+ - reg: Temperature sensor address. Must be <0x00> or <0x01>.
+
+Optional temp sub-node properties:
+ - label: String; Assigned to the hwmon tempX_label property.
+ - ideality: For temperature node with reg 1 only: Set ideality factor for the
+   remote temperature sensor. Integer with range 0 to 63, representing a
+   multiplication factor of 0.9844 to 1.0489. Default: 24 (1.0080).
+
+Example:
+   max31760@50 {
+   compatible = "maxim,max31760";
+   reg = <0x50>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   maxim,fan-spin-up-enabled;
+
+   fan@0 {
+   reg = <0x00>;
+   label = "Left";
+   };
+   fan@1 {
+   reg = <0x01>;
+   label = "Right";
+   };
+   temp@1 {
+   reg = <0x01>;
+   label = "CPU";
+   };
+   };
-- 
2.12.2.715.g7642488e1d-goog

--
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/2] devicetree: Document the max31760 device binding.

2017-04-04 Thread John Muir
Signed-off-by: John Muir <j...@jmuir.com>
---
 .../devicetree/bindings/hwmon/max31760.txt | 58 ++
 1 file changed, 58 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/max31760.txt

diff --git a/Documentation/devicetree/bindings/hwmon/max31760.txt 
b/Documentation/devicetree/bindings/hwmon/max31760.txt
new file mode 100644
index ..43787a77c322
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/max31760.txt
@@ -0,0 +1,58 @@
+MAX31760 fan controller
+---
+
+This device supports I2C only. Many properties of this device are configurable
+thorugh the hwmon interface. See also Documentation/hwmon/max31760.
+
+Required node properties:
+- compatible : "maxim,max31760"
+- reg : The I2C address of the device. This is 0x50 - 0x57 depending on the
+   hardware configuration.
+
+Optional node properties:
+- maxim,fan1-enabled   - 1 to enable, 0 to disable. Default: 1.
+- maxim,fan2-enabled   - 1 to enable, 0 to disable. Default: 1.
+- maxim,fan1-label - String: Hwmon fan1_label.
+- maxim,fan2-label - String: Hwmon fan2_label.
+- maxim,fan-fail-full-only - Set to 1 to assert a fan failure only when the
+ PWM is at 100%. Default: 0.
+- maxim,fan-rd-signal  - Set to 1 if fan(s) provide a rotation
+ detection (RD) signal, or 0 if the fan
+ generates square-wave pulses. Default: 0.
+- maxim,fan-rd-polarity- 0: RD is low when the fan is running.
+ 1: RD is high when the fan is running.
+ Only relevant when fan-rd-signal is 1.
+ Default: 0.
+- maxim,fan-signal-enabled - Set to 1 if externally driving FF/FS low
+ should force PWM output to 100%. Default: 0.
+- maxim,fan-spin-up-enabled - For fan startup: Set to 1 to set the PWM to
+ 100% until tach is detected or two seconds
+ have passed before reducing to the target
+ value. Default: 0.
+- maxim,pwm-polarity   - 0: 100% PWM is when PWM is high.
+ 1: 100% PWM is when PWM is low.
+ Default: 0.
+- maxim,pwm-pulse-stretch-enabled
+   - 1 to enable PWM pulse stretching, 0 to
+ disable. Default: 0.
+- maxim,pwm-zero-fan-can-fail  - 0: Fan failure detection disabled when PWM is
+ramping to 0%.
+ 1: Fan failure detection enabled for all PWM
+values.
+ Default: 0.
+- maxim,temp1-label- String: Hwmon temp1_label.
+- maxim,temp2-label- String: Hwmon temp2_label.
+- maxim,temp2-ideality - Set ideality factor for the remote temperature
+ sensor. Integer with range 0 to 63,
+ representing a multiplication factor of 0.9844
+ to 1.0489. Default: 24 (1.0080).
+
+Example:
+   max31760@50 {
+   compatible = "maxim,max31760";
+   reg = <0x50>;
+   maxim,fan1-label = "Left";
+   maxim,fan2-label = "Right";
+   maxim,fan-spin-up-enabled = <1>;
+   maxim,temp2-label = "CPU";
+   };
-- 
2.12.2.715.g7642488e1d-goog

--
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/2] hwmon: Add MAX31760 fan controller driver.

2017-04-04 Thread John Muir
Add a driver for the Maxim Integrated MAX31760 Precision Fan
Speed Controller.

Signed-off-by: John Muir <j...@jmuir.com>
---
 Documentation/hwmon/max31760 |   41 ++
 drivers/hwmon/Kconfig|   10 +
 drivers/hwmon/Makefile   |1 +
 drivers/hwmon/max31760.c | 1430 ++
 4 files changed, 1482 insertions(+)
 create mode 100644 Documentation/hwmon/max31760
 create mode 100644 drivers/hwmon/max31760.c

diff --git a/Documentation/hwmon/max31760 b/Documentation/hwmon/max31760
new file mode 100644
index ..95937844ed18
--- /dev/null
+++ b/Documentation/hwmon/max31760
@@ -0,0 +1,41 @@
+Kernel driver max31760
+==
+
+Supported chips:
+  * Maxim Integrated MAX31760
+Prefix: 'max31760'
+Addresses scanned: none
+Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31760.pdf
+
+Author:
+   John Muir <j...@jmuir.com>
+
+Description
+---
+
+The MAX31760 integrates temperature sensing along with precision PWM fan
+control. Please read the datasheet referenced above for a comprehensive
+description of this device.
+
+This device driver's hwmon integration provides the common sysfs interfaces to
+manage two fans and two temperature sensors, and pwm controls for the fan 
speed.
+A temperature to pwm lookup table is exposed via a series of 'auto_point'
+configuration files. See Documentation/hwmon/sysfs-interface for more
+information.
+
+The following custom controls are defined (in the custom sub-directory):
+
+control- Accepts control commands:
+ "reset"   - Execute a soft reset of the device.
+ "clearff" - Clear the fan fault.
+
+eeprom_read- Read from the EEPROM into registers.
+eeprom_write- Write register contents to the EEPROM.
+ Write "0" to these to read or write the entire register
+ contents. Write a bit-field as per the data-sheet to write a
+ portion of the register contents.
+
+pwm1_fan_fault  - PWM value in the range of 0 to 255 used when a fan is faulty.
+
+pwm1_ramp_rate  - PWM increment per second when the PWM value is changed.
+ Accepted values are 8, 16, 32, or 255 (instantaneous).
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 2d5447bebab6..3aef5c07f1c3 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -849,6 +849,16 @@ config SENSORS_MAX6697
  This driver can also be built as a module.  If so, the module
  will be called max6697.
 
+config SENSORS_MAX31760
+   tristate "Maxim MAX31760 fan controller"
+   depends on I2C
+   help
+ If you say yes here you get support for the Maxim Integrated
+ MAX31760 Precision Fan-Speed Controller.
+
+ This driver can also be built as a module.  If so, the module
+ will be called max31760.
+
 config SENSORS_MAX31790
tristate "Maxim MAX31790 sensor chip"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 76e1456ddf2f..7b08f069d5a4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -116,6 +116,7 @@ obj-$(CONFIG_SENSORS_MAX6639)   += max6639.o
 obj-$(CONFIG_SENSORS_MAX6642)  += max6642.o
 obj-$(CONFIG_SENSORS_MAX6650)  += max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)  += max6697.o
+obj-$(CONFIG_SENSORS_MAX31760)  += max31760.o
 obj-$(CONFIG_SENSORS_MAX31790) += max31790.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
 obj-$(CONFIG_SENSORS_MCP3021)  += mcp3021.o
diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c
new file mode 100644
index ..735b4fe9a510
--- /dev/null
+++ b/drivers/hwmon/max31760.c
@@ -0,0 +1,1430 @@
+/* Maxim Integrated MAX31760 Precision Fan-Speed Controller driver
+ *
+ * Copyright (C) 2017 John Muir <j...@jmuir.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME "max31760"
+
+#define MAX31760_REG_CR1   0x00 /* Control Register 1 */
+#define MAX31760_CR1_TIS0x01 /* Temperature Index Source */
+#define MAX31760_CR1_MTI0x02 /* Maximum Temperature Index */
+#define MAX31760_CR1_PPS0x04 /* PWM Polarity */
+#define MAX31760_CR1_DRV0x18 /* PWM Frequency */
+#define MAX31760_DRV_33HZ   0x00
+#define MAX31760_DRV_150HZ  0x08

[PATCH 0/2] Add Maxim Integrated MAX31760 fan controller driver.

2017-04-04 Thread John Muir
Add a device driver for the MAX31760 I2C device with a hwmon interface and
a few open firmware device properties.

John Muir (2):
  hwmon: Add MAX31760 fan controller driver.
  devicetree: Document the max31760 device binding.

 .../devicetree/bindings/hwmon/max31760.txt |   58 +
 Documentation/hwmon/max31760   |   41 +
 drivers/hwmon/Kconfig  |   10 +
 drivers/hwmon/Makefile |1 +
 drivers/hwmon/max31760.c   | 1430 
 5 files changed, 1540 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/max31760.txt
 create mode 100644 Documentation/hwmon/max31760
 create mode 100644 drivers/hwmon/max31760.c

-- 
2.12.2.715.g7642488e1d-goog

--
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] devicetree: hwmon: Add documentation for TMP108 driver.

2016-12-01 Thread John Muir
Simple hwmon binding documentation.

Signed-off-by: John Muir <j...@jmuir.com>
---
 Documentation/devicetree/bindings/hwmon/tmp108.txt | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/tmp108.txt

diff --git a/Documentation/devicetree/bindings/hwmon/tmp108.txt 
b/Documentation/devicetree/bindings/hwmon/tmp108.txt
new file mode 100644
index 000..8c4b10d
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/tmp108.txt
@@ -0,0 +1,14 @@
+TMP108 temperature sensor
+-
+
+This device supports I2C only.
+
+Requires node properties:
+- compatible : "ti,tmp108"
+- reg : the I2C address of the device. This is 0x48, 0x49, 0x4a, or 0x4b.
+
+Example:
+   tmp108@48 {
+   compatible = "ti,tmp108";
+   reg = <0x48>;
+   };
-- 
2.8.0.rc3.226.g39d4020

--
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: Add Texas Instruments TMP108 temperature sensor driver.

2016-12-01 Thread John Muir
Add support for the TI TMP108 temperature sensor with some device
configuration parameters.

Signed-off-by: John Muir <j...@jmuir.com>
---
 Documentation/hwmon/tmp108 |  36 
 drivers/hwmon/Kconfig  |  11 ++
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/tmp108.c | 466 +
 4 files changed, 514 insertions(+)
 create mode 100644 Documentation/hwmon/tmp108
 create mode 100644 drivers/hwmon/tmp108.c

diff --git a/Documentation/hwmon/tmp108 b/Documentation/hwmon/tmp108
new file mode 100644
index 000..25802df
--- /dev/null
+++ b/Documentation/hwmon/tmp108
@@ -0,0 +1,36 @@
+Kernel driver tmp108
+
+
+Supported chips:
+  * Texas Instruments TMP108
+Prefix: 'tmp108'
+Addresses scanned: none
+Datasheet: http://www.ti.com/product/tmp108
+
+Author:
+   John Muir <j...@jmuir.com>
+
+Description
+---
+
+The Texas Instruments TMP108 implements one temperature sensor. An alert pin
+can be set when temperatures exceed minimum or maximum values plus or minus a
+hysteresis value. (This driver does not support interrupts for the alert pin,
+and the device runs in comparator mode.)
+
+The sensor is accurate to 0.75C over the range of -25 to +85 C, and to 1.0
+degree from -40 to +125 C. Resolution of the sensor is 0.0625 degree. The
+operating temperature has a minimum of -55 C and a maximum of +150 C.
+Hysteresis values can be set to 0, 1, 2, or 4C.
+
+The TMP108 has a programmable update rate that can select between 8, 4, 1, and
+0.5 Hz.
+
+By default the TMP108 reads the temperature continuously. To conserve power,
+the TMP108 has a one-shot mode where the device is normally shut-down. When a
+one shot is requested the temperature is read, the result can be retrieved,
+and then the device is shut down automatically. (This driver only supports
+continuous mode.)
+
+The driver provides the common sysfs-interface for temperatures (see
+Documentation/hwmon/sysfs-interface under Temperatures).
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 45cef3d..4c173de 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1591,6 +1591,17 @@ config SENSORS_TMP103
  This driver can also be built as a module.  If so, the module
  will be called tmp103.
 
+config SENSORS_TMP108
+   tristate "Texas Instruments TMP108"
+   depends on I2C
+   select REGMAP_I2C
+   help
+ If you say yes here you get support for Texas Instruments TMP108
+ sensor chips.
+
+ This driver can also be built as a module.  If so, the module
+ will be called tmp108.
+
 config SENSORS_TMP401
tristate "Texas Instruments TMP401 and compatibles"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index aecf4ba..51e5256 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -152,6 +152,7 @@ obj-$(CONFIG_SENSORS_TC74)  += tc74.o
 obj-$(CONFIG_SENSORS_THMC50)   += thmc50.o
 obj-$(CONFIG_SENSORS_TMP102)   += tmp102.o
 obj-$(CONFIG_SENSORS_TMP103)   += tmp103.o
+obj-$(CONFIG_SENSORS_TMP108)   += tmp108.o
 obj-$(CONFIG_SENSORS_TMP401)   += tmp401.o
 obj-$(CONFIG_SENSORS_TMP421)   += tmp421.o
 obj-$(CONFIG_SENSORS_TWL4030_MADC)+= twl4030-madc-hwmon.o
diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c
new file mode 100644
index 000..895ae82
--- /dev/null
+++ b/drivers/hwmon/tmp108.c
@@ -0,0 +1,466 @@
+/* Texas Instruments TMP108 SMBus temperature sensor driver
+ *
+ * Copyright (C) 2016 John Muir <j...@jmuir.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#defineDRIVER_NAME "tmp108"
+
+#defineTMP108_REG_TEMP 0x00
+#defineTMP108_REG_CONF 0x01
+#defineTMP108_REG_TLOW 0x02
+#defineTMP108_REG_THIGH0x03
+
+#define TMP108_TEMP_MIN_MC -5 /* Minimum millicelcius. */
+#define TMP108_TEMP_MAX_MC 127937 /* Maximum millicelcius. */
+
+/* Configuration register bits.
+ * Note: these bit definitions are byte swapped.
+ */
+#define TMP108_CONF_M0 0x0100 /* Sensor mode. */
+#define TMP108_CONF_M1 0x0200
+#define TMP108_CONF_TM 0x0400 /* Thermostat mode. */
+#define TMP108_CONF_FL 0x0800 /* Watchdog flag - TLOW */
+#define TMP108_CONF_FH 0x1000 /* W

[PATCH v3 0/2] Texas Instruments TMP108 temperature sensor driver.

2016-12-01 Thread John Muir
This adds a device driver for the Texas Instruments TMP108 temperature
sensor. The driver provides support to read the temperature, read or modify
the update interval, min and max temperature and hysteresis values, as well
as read current alarm status. Support for alarm interrupts will come in a
future patch.

John Muir (2):
  hwmon: Add Texas Instruments TMP108 temperature sensor driver.
  devicetree: hwmon: Add documentation for TMP108 driver.

 Documentation/devicetree/bindings/hwmon/tmp108.txt |  14 +
 Documentation/hwmon/tmp108 |  36 ++
 drivers/hwmon/Kconfig  |  11 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/tmp108.c | 466 +
 5 files changed, 528 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/tmp108.txt
 create mode 100644 Documentation/hwmon/tmp108
 create mode 100644 drivers/hwmon/tmp108.c

-- 
2.8.0.rc3.226.g39d4020

--
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/2] hwmon: Add Texas Instruments TMP108 temperature sensor driver.

2016-12-01 Thread John Muir
Hi Guenter,

On Dec 1, 2016, at 2:08 PM, Guenter Roeck  wrote:
> 
>> 
>> Should we be concerned about restoring the configuration here?
>> 
> Interesting question. If the chip was really powered off, you would
> have to restore the entire configuration, not just the configuration
> register. Given that, I think it is sufficient to just restore the
> operational mode, ie the value changed when entering suspend.
> 
OK. Will do.

> Where did you find regmap_sync() ? It seems to be hiding from me.

Sorry, I meant regcache_sync().

John.
--
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/2] hwmon: Add Texas Instruments TMP108 temperature sensor driver.

2016-12-01 Thread John Muir
Hi Guenter,

On Dec 1, 2016, at 7:19 AM, Guenter Roeck  wrote:
> 
>> +/* convert 12-bit TMP108 register value to milliCelsius */
>> +static inline int tmp108_temp_reg_to_mC(s16 val)
>> +{
>> +return (val & ~0x01) * 1000 / 256;
> 
> Why ~0x01 and not ~0x0f ? The lower 4 bits are supposed to be 0.

I can probably change it: I will reevaluate this.

>> +tmp108->orig_config = regval;
>> +config = regval;
>> +
> 
> Nitpick, but a separate 'regval' variable is not really necessary.
> Just make config an u32 and use it directly (this actually makes the code
> more efficient on many architectures, since cpu registers tend to be
> at least 32 bit wide and 16 bit accesses result in extra masking).

OK.

>> +if (device_property_read_bool(dev, "ti,thermostat-mode-comparator"))
>> +config &= ~TMP108_CONF_TM;
>> +else
>> +config |= TMP108_CONF_TM;
>> +
> As suggested separately, I would suggest to drop this and always select 
> comparator mode.

Yep.

>> +hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
>> + tmp108,
>> + _chip_info,
>> + NULL);
>> +if (IS_ERR(hwmon_dev)) {
>> +err = PTR_ERR(hwmon_dev);
>> +dev_err(dev, "unable to register hwmon device: %d", err);
>> +return err;
>> +}
> 
> Overall I prefer a simeple
>   return PTR_ERR_OR_ZERO(hwmon_dev);

Ack.


>> +static int __maybe_unused tmp108_resume(struct device *dev)
>> +{
>> +struct tmp108 *tmp108 = dev_get_drvdata(dev);
>> +int err;
>> +
>> +err = regmap_write(tmp108->regmap, TMP108_REG_CONF,
>> +   tmp108->curr_config);
>> +
>> +tmp108->ready_time = jiffies;
>> +if (tmp108->curr_config & TMP108_MODE_CONTINUOUS)
> 
> Since only continuous mode is supported, and it is somewhat unlikely
> that we'll ever support one-shot mode, I think it would be better to
> unconditionally set continuous mode and the delay here and drop
> curr_config entirely. curr_config adds quite some complexity to the
> driver with no real gain.

OK. Due to my ignorance I was assuming that the could would need to restore the 
current configuration during resume, and also the previous versions (that you 
did not see) of this code was not using regmap. In fact I see that there is 
also a function called ‘regmap_sync’ which is used (mainly by audio codecs) to 
do this (i.e.; as part of device reset but there are examples in resume()). The 
configuration register is now marked volatile so it would be skipped by 
regmap_sync anyway.

Should we be concerned about restoring the configuration here?

Thanks for your advice,

John.

--
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/2] devicetree: hwmon: Add documentation for TMP108 driver.

2016-11-30 Thread John Muir
Hi Guenter,

On Nov 30, 2016, at 4:42 PM, Guenter Roeck  wrote:
> 
>> +Optional node properties:
>> +- ti,thermostat-mode-comparator : (boolean) select the comparator mode for 
>> the
>> +  thermostat rather than the default interrupt-mode.
>> +
> I keep arguing with myself over this. Ultimately, I think it is not needed,
> for a simple reason: As currently written, using the driver in anything but
> comparator mode does not really make sense (because the alert status bits
> will be reset after reading them in interrupt mode). Second, interrupt mode
> can be determined automatically, based on the presence of SMBus alert support.
> Given that, I wonder if it would make more sense to drop this property and
> always put the chip into comparator mode for the time being. At a later time,
> if and when alert support is added, we can discuss the best approach to
> determine how it should be enabled (ie how do we know that the SMBus adapter
> supports handling alerts, or would we assume that it always does ?).
> 
> What do you think ?

I did find myself putting the device into comparator mode in order to test the 
FL and FH bits, so I agree that it can be the default for now. When I can test 
the Alert pin, we can discuss adding interrupt and SMBus alert support.

Once you have finished reviewing the other patch, I will make that change and 
re-send.

Thanks,

John.

--
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/2] devicetree: hwmon: Add documentation for TMP108 driver.

2016-11-30 Thread John Muir
Simple hwmon binding documentation.

Signed-off-by: John Muir <j...@jmuir.com>
---
 Documentation/devicetree/bindings/hwmon/tmp108.txt | 24 ++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/tmp108.txt

diff --git a/Documentation/devicetree/bindings/hwmon/tmp108.txt 
b/Documentation/devicetree/bindings/hwmon/tmp108.txt
new file mode 100644
index 000..7ba08c4
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/tmp108.txt
@@ -0,0 +1,24 @@
+TMP108 temperature sensor
+-
+
+This device supports I2C only.
+
+Requires node properties:
+- compatible : "ti,tmp108"
+- reg : the I2C address of the device. This is 0x48, 0x49, 0x4a, or 0x4b.
+
+Optional node properties:
+- ti,thermostat-mode-comparator : (boolean) select the comparator mode for the
+  thermostat rather than the default interrupt-mode.
+
+Example:
+   tmp108@48 {
+   compatible = "ti,tmp108";
+   reg = <0x48>;
+   ti,thermostat-mode-comparator;
+   };
+
+   tmp108@49 {
+   compatible = "ti,tmp108";
+   reg = <0x49>;
+   };
-- 
2.8.0.rc3.226.g39d4020

--
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/2] hwmon: Add Texas Instruments TMP108 temperature sensor driver.

2016-11-30 Thread John Muir
Add support for the TI TMP108 temperature sensor with some device
configuration parameters.

Signed-off-by: John Muir <j...@jmuir.com>
---
 Documentation/hwmon/tmp108 |  38 
 drivers/hwmon/Kconfig  |  11 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/tmp108.c | 495 +
 4 files changed, 545 insertions(+)
 create mode 100644 Documentation/hwmon/tmp108
 create mode 100644 drivers/hwmon/tmp108.c

diff --git a/Documentation/hwmon/tmp108 b/Documentation/hwmon/tmp108
new file mode 100644
index 000..ef2e9a3
--- /dev/null
+++ b/Documentation/hwmon/tmp108
@@ -0,0 +1,38 @@
+Kernel driver tmp108
+
+
+Supported chips:
+  * Texas Instruments TMP108
+Prefix: 'tmp108'
+Addresses scanned: none
+Datasheet: http://www.ti.com/product/tmp108
+
+Author:
+   John Muir <j...@jmuir.com>
+
+Description
+---
+
+The Texas Instruments TMP108 implements one temperature sensor. An alert pin
+can be set when temperatures exceed minimum or maximum values plus or minus a
+hysteresis value.
+
+The sensor is accurate to 0.75C over the range of -25 to +85 C, and to 1.0
+degree from -40 to +125 C. Resolution of the sensor is 0.0625 degree. The
+operating temperature has a minimum of -55 C and a maximum of +150 C.
+Hysteresis values can be set to 0, 1, 2, or 4C.
+
+The TMP108 has a programmable update rate that can select between 8, 4, 1, and
+0.5 Hz.
+
+By default the TMP108 reads the temperature continuously. To conserve power,
+the TMP108 has a one-shot mode where the device is normally shut-down. When a
+one shot is requested the temperature is read, the result can be retrieved,
+and then the device is shut down automatically. (This driver only supports
+continuous mode.)
+
+The driver provides the common sysfs-interface for temperatures (see
+Documentation/hwmon/sysfs-interface under Temperatures).
+
+See Documentation/devicetree/bindings/hwmon/tmp108.txt for configuration
+properties.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 45cef3d..4c173de 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1591,6 +1591,17 @@ config SENSORS_TMP103
  This driver can also be built as a module.  If so, the module
  will be called tmp103.
 
+config SENSORS_TMP108
+   tristate "Texas Instruments TMP108"
+   depends on I2C
+   select REGMAP_I2C
+   help
+ If you say yes here you get support for Texas Instruments TMP108
+ sensor chips.
+
+ This driver can also be built as a module.  If so, the module
+ will be called tmp108.
+
 config SENSORS_TMP401
tristate "Texas Instruments TMP401 and compatibles"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index aecf4ba..51e5256 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -152,6 +152,7 @@ obj-$(CONFIG_SENSORS_TC74)  += tc74.o
 obj-$(CONFIG_SENSORS_THMC50)   += thmc50.o
 obj-$(CONFIG_SENSORS_TMP102)   += tmp102.o
 obj-$(CONFIG_SENSORS_TMP103)   += tmp103.o
+obj-$(CONFIG_SENSORS_TMP108)   += tmp108.o
 obj-$(CONFIG_SENSORS_TMP401)   += tmp401.o
 obj-$(CONFIG_SENSORS_TMP421)   += tmp421.o
 obj-$(CONFIG_SENSORS_TWL4030_MADC)+= twl4030-madc-hwmon.o
diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c
new file mode 100644
index 000..35d598d
--- /dev/null
+++ b/drivers/hwmon/tmp108.c
@@ -0,0 +1,495 @@
+/* Texas Instruments TMP108 SMBus temperature sensor driver
+ *
+ * Copyright (C) 2016 John Muir <j...@jmuir.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#defineDRIVER_NAME "tmp108"
+
+#defineTMP108_REG_TEMP 0x00
+#defineTMP108_REG_CONF 0x01
+#defineTMP108_REG_TLOW 0x02
+#defineTMP108_REG_THIGH0x03
+
+#define TMP108_TEMP_MIN_MC -5 /* Minimum millicelcius. */
+#define TMP108_TEMP_MAX_MC 127937 /* Maximum millicelcius. */
+
+/* Configuration register bits.
+ * Note: these bit definitions are byte swapped.
+ */
+#define TMP108_CONF_M0 0x0100 /* Sensor mode. */
+#define TMP108_CONF_M1 0x0200
+#define TMP108_CONF_TM 0x0400 /* Thermostat mode. */
+#define TMP108_CONF_FL 0x0800 /* Watchdog flag - TLOW */
+#define TMP108_CONF_FH 0x1000 /* Watchdog flag - THIGH *

[PATCH v2 0/2] Texas Instruments TMP108 temperature sensor driver.

2016-11-30 Thread John Muir
This adds a device driver for the Texas Instruments TMP108 temperature
sensor. The driver provides support to read the temperature, read or modify
the update interval, min and max temperature and hysteresis values, as well
as read current alarm status. Support for alarm interrupts will come in a
future patch.

John Muir (2):
  hwmon: Add Texas Instruments TMP108 temperature sensor driver.
  devicetree: hwmon: Add documentation for TMP108 driver.

 Documentation/devicetree/bindings/hwmon/tmp108.txt |  24 +
 Documentation/hwmon/tmp108 |  38 ++
 drivers/hwmon/Kconfig  |  11 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/tmp108.c | 495 +
 5 files changed, 569 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/tmp108.txt
 create mode 100644 Documentation/hwmon/tmp108
 create mode 100644 drivers/hwmon/tmp108.c

-- 
2.8.0.rc3.226.g39d4020

--
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/3] hwmon: Add Texas Instruments TMP108 temperature sensor driver.

2016-11-28 Thread John Muir
On Nov 28, 2016, at 2:19 PM, Guenter Roeck  wrote:
> 
> The tmp102 driver adds the timeout if the device was in shutdown mode (SD=1).
> 
>   if (tmp102->config_orig & TMP102_CONF_SD) {
>   ...
>   tmp102->ready_time += msecs_to_jiffies(CONVERSION_TIME_MS);
>   }
> 
> Your code adds the timeout if the device was in continuous operation mode 
> (M1=1).
> 
>   if ((tmp108->config & TMP108_CONF_MODE_MASK)
>   == TMP108_MODE_CONTINUOUS) {
>   tmp108->ready_time +=
>   msecs_to_jiffies(TMP108_CONVERSION_TIME_MS);
>   }
> 
> Unless I am missing something, that is exactly the opposite.

Note that the TMP102 code is looking at ‘config_orig’ which was the initial 
device state, whereas in my proposed driver the code looks at the current 
configuration.

The update_ready_time function was only intended to be called AFTER the device 
has moved to a new mode. For the probe case I simply ignored the fact that it 
was already in continuous mode at startup and lazily re-used the 
update_ready_time function causing the code to run through a few extra 
instructions. I was attempting to re-use the logic in multiple cases.

I’ll update the code in my next patch series and you can re-review.

> Side note: Per datasheet, M0 is irrelevant if M1=1. The above check does not
> match M1=1, M0=1, but that condition would still reflect continuous mode.
> 

OK. Noted.

Thanks,

John.

--
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/3] hwmon: Add Texas Instruments TMP108 temperature sensor driver.

2016-11-28 Thread John Muir

> On Nov 28, 2016, at 11:58 AM, Guenter Roeck <li...@roeck-us.net> wrote:
> 
> On Mon, Nov 28, 2016 at 11:40:42AM -0800, John Muir wrote:
>>>> +static void tmp108_update_ready_time(struct tmp108 *tmp108)
>>>> +{
>>>> +  tmp108->ready_time = jiffies;
>>>> +  if ((tmp108->config & TMP108_CONF_MODE_MASK)
>>>> +  == TMP108_MODE_CONTINUOUS) {
>>> 
>>> Don't you want a "!" here ? Presumably the delay is only needed
>>> if the original configuration was not for continuous mode.
>>> 
>>>> +  tmp108->ready_time +=
>>>> +  msecs_to_jiffies(TMP108_CONVERSION_TIME_MS);
>>>> +  }
>>>> +}
>> The delay is required for both really. When the device is set into 
>> continuous mode it starts converting and the first temperature is ready 
>> (just under) 30ms later.
>> 
> 
> The datasheet states, though, that the chip will start converting as soon
> as the device powers up. The kernel would have to start really fast after that
> to have to wait another 30 ms.
> 
> The current code ends up waiting if it doesn't have to (because it waits
> if the chip was originally configured for continuous mode), and not waiting
> if it has to (because the chip was not configured for continuous mode),
> which doesn't seem to be such a good idea.

You are referring to the statement under “Conversion Rate” in the data sheet?

"After power-up or a general-call reset, the TMP108 immediately starts a 
conversion, as shown in Figure 9. The first result is available after 27 ms 
(typical).”

The datasheet also states that in ’shutdown’ mode, the device is only powering 
the serial interface (see "Mode Bits”). So, I assumed that the conversions 
weren’t happening during in that state, and that there would be the delay after 
moving from the ‘shutdown' state (as is described by the one-shot mode as well 
where the device state returns to ’shutdown’ when the conversion has taken 
place).

My intention was that the delay is enforced after PM resume, and for 
convenience I re-used the same function during probe to initialize the 
ready_time. I was assuming that the device could be in the shutdown state - for 
example if the module had previously been unloaded. I agree that this is not 
required at system startup time. Perhaps I should check to see if the previous 
configuration had the device in the ‘shutdown’ state, and in that instance 
apply the delay? In my opinion it doesn’t really matter either way.

FYI, this same logic exists in the TMP102 device driver. The TMP102 device is 
very similar.

> 
>> For the (unsupported at this time) one-shot mode, there would likewise be a 
>> delay, but I was envisioning having the requesting task sleep while waiting 
>> for the data to be ready, rather than get an -EAGAIN until the data is 
>> ready. 
>> 
> 
> We had that discussion before; the thermal subsystem doesn't like to be kept
> waiting. You would end up adding a lot of complexity for very little gain.
> It might make more sense to consider implementing runtime idle support
> instead of one-shot mode if power consumption is a concern.

OK thanks. I’ll leave this as unsupported for now.

> 
>>>> +  hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
>>>> +tmp108, tmp108_groups);
>>> 
>>> Please consider using the devm_ function here.
>>> 
>>>> +  if (IS_ERR(hwmon_dev)) {
>>>> +  dev_dbg(dev, "unable to register hwmon device\n");
>>>> +  return PTR_ERR(hwmon_dev);
>>>> +  }
>>>> +
>>>> +  tmp108->hwmon_dev = hwmon_dev;
>>>> +  tmp108->tz = thermal_zone_of_sensor_register(hwmon_dev, 0, hwmon_dev,
>>>> +   _of_thermal_ops);
>>>> +  if (IS_ERR(tmp108->tz))
>>>> +  return PTR_ERR(tmp108->tz);
>>> 
>>> hwmon device not unregistered here. That would be fixed by using the devm
>>> function above.
>>> 
>> For the above two registrations and .remove function, I was worried that 
>> there would be an order problem between the i2c->remove and the 
>> device-managed cleanup. I’ll get deeper into that code to determine if that 
>> is a problem.
>> 
> 
> The thermal sensor registration will be removed first (in the remove 
> function).
> devm_ functions are all unregistered / removed after the remove function was
> called (in the order of the devm_ call). Otherwise you would have trouble
> with devm_kzalloc() as well.

Great.

> Note that my followup-patch had a problem with the minimum hysteresis
> temperature; it needs to be higher than the lower limit, not lower.

I’ll keep that in mind.

Cheers,

John.

--
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/3] hwmon: Add Texas Instruments TMP108 temperature sensor driver.

2016-11-28 Thread John Muir

> On Nov 27, 2016, at 4:19 AM, Guenter Roeck <li...@roeck-us.net> wrote:
> 
> On 11/26/2016 09:15 PM, John Muir wrote:
>> Add support for the TI TMP108 temperature sensor with some device
>> configuration parameters.
>> +- ti,alert-active-high : (boolean) make the alert pin active-high instead of
>> +  the default active-low.
> 
> The driver doesn't support interrupts/alerts. Do those properties really add 
> value ?
Getting ahead of myself. I will create a patch for this in the future.

>> +static void tmp108_update_ready_time(struct tmp108 *tmp108)
>> +{
>> +tmp108->ready_time = jiffies;
>> +if ((tmp108->config & TMP108_CONF_MODE_MASK)
>> +== TMP108_MODE_CONTINUOUS) {
> 
> Don't you want a "!" here ? Presumably the delay is only needed
> if the original configuration was not for continuous mode.
> 
>> +tmp108->ready_time +=
>> +msecs_to_jiffies(TMP108_CONVERSION_TIME_MS);
>> +}
>> +}
The delay is required for both really. When the device is set into continuous 
mode it starts converting and the first temperature is ready (just under) 30ms 
later.

For the (unsupported at this time) one-shot mode, there would likewise be a 
delay, but I was envisioning having the requesting task sleep while waiting for 
the data to be ready, rather than get an -EAGAIN until the data is ready. 

>> +hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
>> +  tmp108, tmp108_groups);
> 
> Please consider using the devm_ function here.
> 
>> +if (IS_ERR(hwmon_dev)) {
>> +dev_dbg(dev, "unable to register hwmon device\n");
>> +return PTR_ERR(hwmon_dev);
>> +}
>> +
>> +tmp108->hwmon_dev = hwmon_dev;
>> +tmp108->tz = thermal_zone_of_sensor_register(hwmon_dev, 0, hwmon_dev,
>> + _of_thermal_ops);
>> +if (IS_ERR(tmp108->tz))
>> +return PTR_ERR(tmp108->tz);
> 
> hwmon device not unregistered here. That would be fixed by using the devm
> function above.
> 
For the above two registrations and .remove function, I was worried that there 
would be an order problem between the i2c->remove and the device-managed 
cleanup. I’ll get deeper into that code to determine if that is a problem.

For your other comments, I will make the necessary changes.

Thanks!

John.

--
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 3/3] hwmon: tmp108: Update driver to use hwmon_chip_info.

2016-11-27 Thread John Muir
> On 2016.11.27, at 15:00 , Guenter Roeck <li...@roeck-us.net> wrote:
> 
> On Sat, Nov 26, 2016 at 09:15:37PM -0800, John Muir wrote:
>> Move the tmp108 driver from hwmon attribute groups to
>> hwmon_chip_info.
>> 
>> Signed-off-by: John Muir <j...@jmuir.com>
>> ---
> 
> Hi John,
> 
> please have a look at the following patch.
> 
> Something else: Symbolic permissions are out of favor nowadays.
> You might instead just use 0644 / 0444. Not that I really care,
> but it prevents the inevitable follow-up patches.
> 

Hi Guenter,

Thank you for this patch. I will attempt to implement the same changes using 
the older interfaces in my 4.4 implementation. I will incorporate your changes 
and other comments as soon as I can (early this week) and re-send my patch 
series.

Cheers,

John.

--
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/3] hwmon: tmp108: Use devm variants of registration interfaces.

2016-11-26 Thread John Muir
From: John Muir <mu...@google.com>

Use the devm hwmon and thermal zone registration functions to
clean up the code and remove the need for an i2c_driver.remove
callback.

Signed-off-by: John Muir <j...@jmuir.com>
---
 drivers/hwmon/tmp108.c | 28 
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c
index da64517..b13d652 100644
--- a/drivers/hwmon/tmp108.c
+++ b/drivers/hwmon/tmp108.c
@@ -83,8 +83,6 @@
 
 struct tmp108 {
struct regmap *regmap;
-   struct device *hwmon_dev;
-   struct thermal_zone_device *tz;
u16 config;
unsigned long ready_time;
 };
@@ -245,6 +243,7 @@ static int tmp108_probe(struct i2c_client *client,
 {
struct device *dev = >dev;
struct device *hwmon_dev;
+   struct thermal_zone_device *tz;
struct tmp108 *tmp108;
unsigned int regval;
int err;
@@ -353,18 +352,18 @@ static int tmp108_probe(struct i2c_client *client,
if (err)
return err;
 
-   hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
- tmp108, tmp108_groups);
+   hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
+  tmp108,
+  tmp108_groups);
if (IS_ERR(hwmon_dev)) {
dev_dbg(dev, "unable to register hwmon device\n");
return PTR_ERR(hwmon_dev);
}
 
-   tmp108->hwmon_dev = hwmon_dev;
-   tmp108->tz = thermal_zone_of_sensor_register(hwmon_dev, 0, hwmon_dev,
-_of_thermal_ops);
-   if (IS_ERR(tmp108->tz))
-   return PTR_ERR(tmp108->tz);
+   tz = devm_thermal_zone_of_sensor_register(hwmon_dev, 0, hwmon_dev,
+ _of_thermal_ops);
+   if (IS_ERR(tz))
+   return PTR_ERR(tz);
 
dev_info(dev, "%s, alert: active %s, hyst: %uC, conv: %ucHz\n",
 (tmp108->config & TMP108_CONF_TM) != 0 ?
@@ -374,16 +373,6 @@ static int tmp108_probe(struct i2c_client *client,
return 0;
 }
 
-static int tmp108_remove(struct i2c_client *client)
-{
-   struct tmp108 *tmp108 = i2c_get_clientdata(client);
-
-   thermal_zone_of_sensor_unregister(tmp108->hwmon_dev, tmp108->tz);
-   hwmon_device_unregister(tmp108->hwmon_dev);
-
-   return 0;
-}
-
 #ifdef CONFIG_PM_SLEEP
 static int tmp108_suspend(struct device *dev)
 {
@@ -418,7 +407,6 @@ static struct i2c_driver tmp108_driver = {
.driver.name= DRIVER_NAME,
.driver.pm  = _dev_pm_ops,
.probe  = tmp108_probe,
-   .remove = tmp108_remove,
.id_table   = tmp108_id,
 };
 
-- 
2.8.0.rc3.226.g39d4020

--
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/3] hwmon: Add Texas Instruments TMP108 temperature sensor driver.

2016-11-26 Thread John Muir
Add support for the TI TMP108 temperature sensor with some device
configuration parameters.

Signed-off-by: John Muir <j...@jmuir.com>
---
 Documentation/devicetree/bindings/hwmon/tmp108.txt |  27 ++
 Documentation/hwmon/tmp108 |  38 ++
 drivers/hwmon/Kconfig  |  11 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/tmp108.c | 429 +
 5 files changed, 506 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/tmp108.txt
 create mode 100644 Documentation/hwmon/tmp108
 create mode 100644 drivers/hwmon/tmp108.c

diff --git a/Documentation/devicetree/bindings/hwmon/tmp108.txt 
b/Documentation/devicetree/bindings/hwmon/tmp108.txt
new file mode 100644
index 000..210af63
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/tmp108.txt
@@ -0,0 +1,27 @@
+TMP108 temperature sensor
+-
+
+This device supports I2C only.
+
+Requires node properties:
+- compatible : "ti,tmp108"
+- reg : the I2C address of the device. This is 0x48, 0x49, 0x4a, or 0x4b.
+
+Optional node properties:
+- ti,thermostat-mode-comparitor : (boolean) select the comparitor mode for the
+  thermostat rather than the default interrupt-mode.
+- ti,alert-active-high : (boolean) make the alert pin active-high instead of
+  the default active-low.
+- ti,conversion-rate-cHz : (integer, cHz) select the conversion frequency for
+  continuous mode, in centi-Hz: 25, 100 (default), 400, or 1600.
+- ti,hysteresis : (integer, C) select the hysteresis value: 0, 1, 2, or 4
+  (celcius).
+
+Example:
+   tmp108@48 {
+   compatible = "ti,tmp108";
+   reg = <0x48>;
+   ti,alert-active-high;
+   ti,hysteresis = <2>;
+   ti,conversion-rate-cHz = <25>;
+   };
diff --git a/Documentation/hwmon/tmp108 b/Documentation/hwmon/tmp108
new file mode 100644
index 000..ef2e9a3
--- /dev/null
+++ b/Documentation/hwmon/tmp108
@@ -0,0 +1,38 @@
+Kernel driver tmp108
+
+
+Supported chips:
+  * Texas Instruments TMP108
+Prefix: 'tmp108'
+Addresses scanned: none
+Datasheet: http://www.ti.com/product/tmp108
+
+Author:
+   John Muir <j...@jmuir.com>
+
+Description
+---
+
+The Texas Instruments TMP108 implements one temperature sensor. An alert pin
+can be set when temperatures exceed minimum or maximum values plus or minus a
+hysteresis value.
+
+The sensor is accurate to 0.75C over the range of -25 to +85 C, and to 1.0
+degree from -40 to +125 C. Resolution of the sensor is 0.0625 degree. The
+operating temperature has a minimum of -55 C and a maximum of +150 C.
+Hysteresis values can be set to 0, 1, 2, or 4C.
+
+The TMP108 has a programmable update rate that can select between 8, 4, 1, and
+0.5 Hz.
+
+By default the TMP108 reads the temperature continuously. To conserve power,
+the TMP108 has a one-shot mode where the device is normally shut-down. When a
+one shot is requested the temperature is read, the result can be retrieved,
+and then the device is shut down automatically. (This driver only supports
+continuous mode.)
+
+The driver provides the common sysfs-interface for temperatures (see
+Documentation/hwmon/sysfs-interface under Temperatures).
+
+See Documentation/devicetree/bindings/hwmon/tmp108.txt for configuration
+properties.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 45cef3d..4c173de 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1591,6 +1591,17 @@ config SENSORS_TMP103
  This driver can also be built as a module.  If so, the module
  will be called tmp103.
 
+config SENSORS_TMP108
+   tristate "Texas Instruments TMP108"
+   depends on I2C
+   select REGMAP_I2C
+   help
+ If you say yes here you get support for Texas Instruments TMP108
+ sensor chips.
+
+ This driver can also be built as a module.  If so, the module
+ will be called tmp108.
+
 config SENSORS_TMP401
tristate "Texas Instruments TMP401 and compatibles"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index aecf4ba..51e5256 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -152,6 +152,7 @@ obj-$(CONFIG_SENSORS_TC74)  += tc74.o
 obj-$(CONFIG_SENSORS_THMC50)   += thmc50.o
 obj-$(CONFIG_SENSORS_TMP102)   += tmp102.o
 obj-$(CONFIG_SENSORS_TMP103)   += tmp103.o
+obj-$(CONFIG_SENSORS_TMP108)   += tmp108.o
 obj-$(CONFIG_SENSORS_TMP401)   += tmp401.o
 obj-$(CONFIG_SENSORS_TMP421)   += tmp421.o
 obj-$(CONFIG_SENSORS_TWL4030_MADC)+= twl4030-madc-hwmon.o
diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c
new file mode 100644
index 000..da64517
--- /dev/null
+++ b/drivers/hwmon/tmp108.c
@@ -0,0 +1,429 @@
+/* Texas Instruments TMP108 SMBus temperature sensor driver
+ *

[PATCH 0/3] Texas Instruments TMP108 temperature sensor driver.

2016-11-26 Thread John Muir
This driver is split into three patches as it is being ported forward from
a Linux 4.4 implementation where it was tested. The final driver code uses
interfaces that are not available in 4.4.

John Muir (3):
  hwmon: Add Texas Instruments TMP108 temperature sensor driver.
  hwmon: tmp108: Use devm variants of registration interfaces.
  hwmon: tmp108: Update driver to use hwmon_chip_info.

 Documentation/devicetree/bindings/hwmon/tmp108.txt |  27 ++
 Documentation/hwmon/tmp108 |  38 ++
 drivers/hwmon/Kconfig  |  11 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/tmp108.c | 421 +
 5 files changed, 498 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/tmp108.txt
 create mode 100644 Documentation/hwmon/tmp108
 create mode 100644 drivers/hwmon/tmp108.c

-- 
2.8.0.rc3.226.g39d4020

--
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