diff options
author | Rabin Vincent <rabin@rab.in> | 2015-07-18 18:29:14 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2015-08-09 16:44:27 -0400 |
commit | a1dc86ebd2f2eb6652c8be9311c16acccd1708f8 (patch) | |
tree | b037c01de0062470ce69eede5eb3dfa99e7ec761 | |
parent | aeaa4d9f812bfd841643b37f65c6b6597045be37 (diff) |
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>
-rw-r--r-- | Documentation/devicetree/bindings/hwmon/lm70.txt | 21 | ||||
-rw-r--r-- | drivers/hwmon/lm70.c | 34 |
2 files changed, 54 insertions, 1 deletions
diff --git a/Documentation/devicetree/bindings/hwmon/lm70.txt b/Documentation/devicetree/bindings/hwmon/lm70.txt new file mode 100644 index 000000000000..e7fd921aa4f1 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/lm70.txt | |||
@@ -0,0 +1,21 @@ | |||
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 | }; | ||
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c index 97204dce162d..9296e9daf774 100644 --- a/drivers/hwmon/lm70.c +++ b/drivers/hwmon/lm70.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/mod_devicetable.h> | 37 | #include <linux/mod_devicetable.h> |
38 | #include <linux/spi/spi.h> | 38 | #include <linux/spi/spi.h> |
39 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
40 | #include <linux/of_device.h> | ||
40 | 41 | ||
41 | 42 | ||
42 | #define DRVNAME "lm70" | 43 | #define DRVNAME "lm70" |
@@ -130,11 +131,41 @@ ATTRIBUTE_GROUPS(lm70); | |||
130 | 131 | ||
131 | /*----------------------------------------------------------------------*/ | 132 | /*----------------------------------------------------------------------*/ |
132 | 133 | ||
134 | #ifdef CONFIG_OF | ||
135 | static const struct of_device_id lm70_of_ids[] = { | ||
136 | { | ||
137 | .compatible = "ti,lm70", | ||
138 | .data = (void *) LM70_CHIP_LM70, | ||
139 | }, | ||
140 | { | ||
141 | .compatible = "ti,tmp121", | ||
142 | .data = (void *) LM70_CHIP_TMP121, | ||
143 | }, | ||
144 | { | ||
145 | .compatible = "ti,lm71", | ||
146 | .data = (void *) LM70_CHIP_LM71, | ||
147 | }, | ||
148 | { | ||
149 | .compatible = "ti,lm74", | ||
150 | .data = (void *) LM70_CHIP_LM74, | ||
151 | }, | ||
152 | {}, | ||
153 | }; | ||
154 | MODULE_DEVICE_TABLE(of, lm70_of_ids); | ||
155 | #endif | ||
156 | |||
133 | static int lm70_probe(struct spi_device *spi) | 157 | static int lm70_probe(struct spi_device *spi) |
134 | { | 158 | { |
135 | int chip = spi_get_device_id(spi)->driver_data; | 159 | const struct of_device_id *match; |
136 | struct device *hwmon_dev; | 160 | struct device *hwmon_dev; |
137 | struct lm70 *p_lm70; | 161 | struct lm70 *p_lm70; |
162 | int chip; | ||
163 | |||
164 | match = of_match_device(lm70_of_ids, &spi->dev); | ||
165 | if (match) | ||
166 | chip = (int)(uintptr_t)match->data; | ||
167 | else | ||
168 | chip = spi_get_device_id(spi)->driver_data; | ||
138 | 169 | ||
139 | /* signaling is SPI_MODE_0 */ | 170 | /* signaling is SPI_MODE_0 */ |
140 | if (spi->mode & (SPI_CPOL | SPI_CPHA)) | 171 | if (spi->mode & (SPI_CPOL | SPI_CPHA)) |
@@ -169,6 +200,7 @@ static struct spi_driver lm70_driver = { | |||
169 | .driver = { | 200 | .driver = { |
170 | .name = "lm70", | 201 | .name = "lm70", |
171 | .owner = THIS_MODULE, | 202 | .owner = THIS_MODULE, |
203 | .of_match_table = of_match_ptr(lm70_of_ids), | ||
172 | }, | 204 | }, |
173 | .id_table = lm70_ids, | 205 | .id_table = lm70_ids, |
174 | .probe = lm70_probe, | 206 | .probe = lm70_probe, |