Skip to contentSkip to conversation

dt-bindings: hwmon: add MAX31827

PATCH Superseded Daniel Matyas 2 participants 3 messages May 8, 2023 – May 11, 2023

Subsystems (3)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/2 dt-bindings: hwmon: add MAX31827

MAX31827 is a low-power temperature switch with I2C interface.

The device is a ±1°C accuracy from -40°C to +125°C (12 bits) local temperature switch and sensor with I2C/SM- Bus interface. The combination of small 6-bump wafer-lev- el package (WLP) and high accuracy makes this temper- ature sensor/switch ideal for a wide range of applications.

---
 .../bindings/hwmon/adi,max31827.yaml          | 54 +++++++++++++++++++
 MAINTAINERS                                   |  7 +++
 2 files changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adi,max31827.yaml
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml new file +54 -0
new file mode 100644
index 000000000000..2dc8b07b4d3b
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/adi,max31827.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX31827, MAX31828, MAX31829 Low-Power Temperature Switch
+
+maintainers:
+  - Daniel Matyas <[email protected]>
+
+description: |
+  Analog Devices MAX31827, MAX31828, MAX31829 Low-Power Temperature Switch with
+  I2C Interface
+  https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31827-MAX31829.pdf
+
+properties:
+  compatible:
+    oneOf:
+      - const: adi,max31827
+      - items:
+          - enum:
+              - adi,max31828
+              - adi,max31829
+          - const: adi,max31827
+
+  reg:
+    maxItems: 1
+
+  vref-supply:
+    description:
+      Must have values in the interval (1.6V; 3.6V) in order for the device to
+      function correctly.
+
+required:
+  - compatible
+  - reg
+  - vref-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        temperature-sensor@42 {
+            compatible = "adi,max31827";
+            reg = <0x42>;
+            vref-supply = <&reg_vdd>;
+        };
+    };
+...
MAINTAINERS +7 -0
index c0cde28c62c6..91de1e95f11d 100644
@@ -12618,6 +12618,13 @@ F:	Documentation/userspace-api/media/drivers/max2175.rst
 F:	drivers/media/i2c/max2175*
 F:	include/uapi/linux/max2175.h
 
+MAX31827 TEMPERATURE SWITCH DRIVER
+M:	Daniel Matyas <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	http://ez.analog.com/community/linux-device-drivers
+F:	Documentation/devicetree/bindings/hwmon/adi,max31827.yaml
+
 MAX6650 HARDWARE MONITOR AND FAN CONTROLLER DRIVER
 L:	[email protected]
 S:	Orphan
Signature · 1 line
2.34.1
#1 lore raw

PATCH v7 2/2 hwmon: max31827: add MAX31827 driver

MAX31827 is a low-power temperature switch with I2C interface.

The device is a ±1°C accuracy from -40°C to +125°C (12 bits) local temperature switch and sensor with I2C/SM- Bus interface. The combination of small 6-bump wafer-lev- el package (WLP) and high accuracy makes this temper- ature sensor/switch ideal for a wide range of applications.

---

v6 -> v7 : Used goto instead of return in write_alarm_val function. Unlocked mutex in goto label.

Used mutex for enable.

Now update_interval can only be modified if the device is enabled. I did this, b.c. modifying the update interval, when the device is in shutdown mode, automatically enables the device.

 Documentation/hwmon/index.rst    |   1 +
 Documentation/hwmon/max31827.rst |  90 ++++++
 MAINTAINERS                      |   2 +
 drivers/hwmon/Kconfig            |  11 +
 drivers/hwmon/Makefile           |   2 +-
 drivers/hwmon/max31827.c         | 466 +++++++++++++++++++++++++++++++
 6 files changed, 571 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/hwmon/max31827.rst
 create mode 100644 drivers/hwmon/max31827.c
Documentation/hwmon/index.rst +1 -0
index fa1208c62855..8cc0922f3b36 100644
@@ -140,6 +140,7 @@ Hardware Monitoring Kernel Drivers
    max31760
    max31785
    max31790
+   max31827
    max34440
    max6620
    max6639
Documentation/hwmon/max31827.rst new file +90 -0

90 lines not on this page · raw message

MAINTAINERS +2 -0
index 91de1e95f11d..40504fc94db5 100644
@@ -12624,6 +12624,8 @@ L:	[email protected]
 S:	Supported
 W:	http://ez.analog.com/community/linux-device-drivers
 F:	Documentation/devicetree/bindings/hwmon/adi,max31827.yaml
+F:	Documentation/hwmon/max31827.rst
+F:	drivers/hwmon/max31827.c
 
 MAX6650 HARDWARE MONITOR AND FAN CONTROLLER DRIVER
 L:	[email protected]
drivers/hwmon/Kconfig +11 -0
index fc640201a2de..12bd17075dc4 100644
@@ -1097,6 +1097,17 @@ config SENSORS_MAX31760
 	  This driver can also be built as a module. If so, the module
 	  will be called max31760.
 
+config MAX31827
+	tristate "MAX31827 low-power temperature switch and similar devices"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  If you say yes here you get support for MAX31827, MAX31828 and
+	  MAX31829 low-power temperature switches and sensors connected with I2C.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called max31827.
+
 config SENSORS_MAX6620
 	tristate "Maxim MAX6620 fan controller"
 	depends on I2C
drivers/hwmon/Makefile +1 -1
index cd8c568c80a9..8a8021f9ca9e 100644
@@ -149,6 +149,7 @@ obj-$(CONFIG_SENSORS_MAX6642)	+= max6642.o
 obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
 obj-$(CONFIG_SENSORS_MAX31790)	+= max31790.o
+obj-$(CONFIG_MAX31827) += max31827.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
 obj-$(CONFIG_SENSORS_MC34VR500)	+= mc34vr500.o
 obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
@@ -224,4 +225,3 @@ obj-$(CONFIG_SENSORS_PECI)	+= peci/
 obj-$(CONFIG_PMBUS)		+= pmbus/
 
 ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG
-
drivers/hwmon/max31827.c new file +466 -0

466 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v7 2/2] hwmon: max31827: add MAX31827 driver

kernel test robot noticed the following build warnings:

Hi Daniel,

kernel test robot noticed the following build warnings:

[auto build test WARNING on groeck-staging/hwmon-next]
[also build test WARNING on robh/for-next linus/master v6.4-rc1 next-20230511] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Daniel-Matyas/hwmon-max31827-add-MAX31827-driver/20230508-222643
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
patch link:    https://lore.kernel.org/r/20230508172427.23915-2-daniel.matyas%40analog.com
patch subject: [PATCH v7 2/2] hwmon: max31827: add MAX31827 driver
config: hexagon-allyesconfig (https://download.01.org/0day-ci/archive/20230511/[email protected]/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project b0fb98227c90adf2536c9ad644a74d5e92961111)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/89289262b54eadd8ac5f955bd358ed6d9a51908a
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Daniel-Matyas/hwmon-max31827-add-MAX31827-driver/20230508-222643 git checkout 89289262b54eadd8ac5f955bd358ed6d9a51908a
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/hwmon/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from drivers/hwmon/max31827.c:12:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:9:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
                                                     ^
   In file included from drivers/hwmon/max31827.c:12:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
                                                     ^
   In file included from drivers/hwmon/max31827.c:12:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
>> drivers/hwmon/max31827.c:238:7: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
                   if (attr == hwmon_chip_update_interval) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hwmon/max31827.c:280:9: note: uninitialized use occurs here
           return ret;
                  ^~~
   drivers/hwmon/max31827.c:238:3: note: remove the 'if' if its condition is always true
                   if (attr == hwmon_chip_update_interval) {
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hwmon/max31827.c:134:9: note: initialize the variable 'ret' to silence this warning
           int ret;
                  ^
                   = 0

7 warnings generated.

vim +238 drivers/hwmon/max31827.c

128
129 static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
130 u32 attr, int channel, long *val)
131 {
132 struct max31827_state *st = dev_get_drvdata(dev);
133 unsigned int uval;
134 int ret;
135
136 switch (type) {
137 case hwmon_temp:
138 switch (attr) {
139 case hwmon_temp_enable:
140 ret = regmap_read(st->regmap,
141 MAX31827_CONFIGURATION_REG, &uval);
142 if (ret)
143 break;
144
145 uval = FIELD_GET(MAX31827_CONFIGURATION_1SHOT_MASK |
146 MAX31827_CONFIGURATION_CNV_RATE_MASK,
147 uval);
148 *val = !!uval;
149
150 break;
151 case hwmon_temp_input:
152 mutex_lock(&st->lock);
153
154 if (!st->enable) {
155 /*
156 * This operation requires mutex protection,
157 * because the chip configuration should not
158 * be changed during the conversion process.
159 */
160
161 ret = regmap_update_bits(st->regmap,
162 MAX31827_CONFIGURATION_REG,
163 MAX31827_CONFIGURATION_1SHOT_MASK,
164 1);
165 if (ret) {
166 mutex_unlock(&st->lock);
167 return ret;
168 }
169
170 msleep(MAX31827_12_BIT_CNV_TIME);
171 }
172 ret = regmap_read(st->regmap, MAX31827_T_REG, &uval);
173
174 mutex_unlock(&st->lock);
175
176 if (ret)
177 break;
178
179 *val = MAX31827_16_BIT_TO_M_DGR(uval);
180
181 break;
182 case hwmon_temp_max:
183 ret = regmap_read(st->regmap, MAX31827_TH_REG, &uval);
184 if (ret)
185 break;
186
187 *val = MAX31827_16_BIT_TO_M_DGR(uval);
188 break;
189 case hwmon_temp_max_hyst:
190 ret = regmap_read(st->regmap, MAX31827_TH_HYST_REG,
191 &uval);
192 if (ret)
193 break;
194
195 *val = MAX31827_16_BIT_TO_M_DGR(uval);
196 break;
197 case hwmon_temp_max_alarm:
198 ret = regmap_read(st->regmap,
199 MAX31827_CONFIGURATION_REG, &uval);
200 if (ret)
201 break;
202
203 *val = FIELD_GET(MAX31827_CONFIGURATION_O_TEMP_STAT_MASK,
204 uval);
205 break;
206 case hwmon_temp_min:
207 ret = regmap_read(st->regmap, MAX31827_TL_REG, &uval);
208 if (ret)
209 break;
210
211 *val = MAX31827_16_BIT_TO_M_DGR(uval);
212 break;
213 case hwmon_temp_min_hyst:
214 ret = regmap_read(st->regmap, MAX31827_TL_HYST_REG,
215 &uval);
216 if (ret)
217 break;
218
219 *val = MAX31827_16_BIT_TO_M_DGR(uval);
220 break;
221 case hwmon_temp_min_alarm:
222 ret = regmap_read(st->regmap,
223 MAX31827_CONFIGURATION_REG, &uval);
224 if (ret)
225 break;
226
227 *val = FIELD_GET(MAX31827_CONFIGURATION_U_TEMP_STAT_MASK,
228 uval);
229 break;
230 default:
231 ret = -EOPNOTSUPP;
232 break;
233 }
234
235 break;
236
237 case hwmon_chip:

 > 238			if (attr == hwmon_chip_update_interval) {

239 ret = regmap_read(st->regmap,
240 MAX31827_CONFIGURATION_REG, &uval);
241 if (ret)
242 break;
243
244 uval = FIELD_GET(MAX31827_CONFIGURATION_CNV_RATE_MASK,
245 uval);
246 switch (uval) {
247 case MAX31827_CNV_1_DIV_64_HZ:
248 *val = 64000;
249 break;
250 case MAX31827_CNV_1_DIV_32_HZ:
251 *val = 32000;
252 break;
253 case MAX31827_CNV_1_DIV_16_HZ:
254 *val = 16000;
255 break;
256 case MAX31827_CNV_1_DIV_4_HZ:
257 *val = 4000;
258 break;
259 case MAX31827_CNV_1_HZ:
260 *val = 1000;
261 break;
262 case MAX31827_CNV_4_HZ:
263 *val = 250;
264 break;
265 case MAX31827_CNV_8_HZ:
266 *val = 125;
267 break;
268 default:
269 *val = 0;
270 break;
271 }
272 }
273 break;
274
275 default:
276 ret = -EOPNOTSUPP;
277 break;
278 }
279
280 return ret;
281 }
282

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests