Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (lm70) add device tree support

Allow the lm70 to be probed from a device tree.

Signed-off-by: Rabin Vincent <rabin@rab.in>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Rabin Vincent and committed by
Guenter Roeck
a1dc86eb aeaa4d9f

+54 -1
+21
Documentation/devicetree/bindings/hwmon/lm70.txt
··· 1 + * LM70/TMP121/LM71/LM74 thermometer. 2 + 3 + Required properties: 4 + - compatible: one of 5 + "ti,lm70" 6 + "ti,tmp121" 7 + "ti,lm71" 8 + "ti,lm74" 9 + 10 + See Documentation/devicetree/bindings/spi/spi-bus.txt for more required and 11 + optional properties. 12 + 13 + Example: 14 + 15 + spi_master { 16 + temperature-sensor@0 { 17 + compatible = "ti,lm70"; 18 + reg = <0>; 19 + spi-max-frequency = <1000000>; 20 + }; 21 + };
+33 -1
drivers/hwmon/lm70.c
··· 37 37 #include <linux/mod_devicetable.h> 38 38 #include <linux/spi/spi.h> 39 39 #include <linux/slab.h> 40 + #include <linux/of_device.h> 40 41 41 42 42 43 #define DRVNAME "lm70" ··· 131 130 132 131 /*----------------------------------------------------------------------*/ 133 132 133 + #ifdef CONFIG_OF 134 + static const struct of_device_id lm70_of_ids[] = { 135 + { 136 + .compatible = "ti,lm70", 137 + .data = (void *) LM70_CHIP_LM70, 138 + }, 139 + { 140 + .compatible = "ti,tmp121", 141 + .data = (void *) LM70_CHIP_TMP121, 142 + }, 143 + { 144 + .compatible = "ti,lm71", 145 + .data = (void *) LM70_CHIP_LM71, 146 + }, 147 + { 148 + .compatible = "ti,lm74", 149 + .data = (void *) LM70_CHIP_LM74, 150 + }, 151 + {}, 152 + }; 153 + MODULE_DEVICE_TABLE(of, lm70_of_ids); 154 + #endif 155 + 134 156 static int lm70_probe(struct spi_device *spi) 135 157 { 136 - int chip = spi_get_device_id(spi)->driver_data; 158 + const struct of_device_id *match; 137 159 struct device *hwmon_dev; 138 160 struct lm70 *p_lm70; 161 + int chip; 162 + 163 + match = of_match_device(lm70_of_ids, &spi->dev); 164 + if (match) 165 + chip = (int)(uintptr_t)match->data; 166 + else 167 + chip = spi_get_device_id(spi)->driver_data; 139 168 140 169 /* signaling is SPI_MODE_0 */ 141 170 if (spi->mode & (SPI_CPOL | SPI_CPHA)) ··· 200 169 .driver = { 201 170 .name = "lm70", 202 171 .owner = THIS_MODULE, 172 + .of_match_table = of_match_ptr(lm70_of_ids), 203 173 }, 204 174 .id_table = lm70_ids, 205 175 .probe = lm70_probe,