Commit | Line | Data |
---|---|---|
dac6831e KT |
1 | /* |
2 | * emc1403.c - SMSC Thermal Driver | |
3 | * | |
4 | * Copyright (C) 2008 Intel Corp | |
5 | * | |
6 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; version 2 of the License. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along | |
18 | * with this program; if not, write to the Free Software Foundation, Inc., | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
20 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
dac6831e KT |
21 | */ |
22 | ||
23 | #include <linux/module.h> | |
24 | #include <linux/init.h> | |
25 | #include <linux/slab.h> | |
26 | #include <linux/i2c.h> | |
27 | #include <linux/hwmon.h> | |
28 | #include <linux/hwmon-sysfs.h> | |
29 | #include <linux/err.h> | |
30 | #include <linux/sysfs.h> | |
31 | #include <linux/mutex.h> | |
4cab259f | 32 | #include <linux/regmap.h> |
dac6831e KT |
33 | |
34 | #define THERMAL_PID_REG 0xfd | |
35 | #define THERMAL_SMSC_ID_REG 0xfe | |
36 | #define THERMAL_REVISION_REG 0xff | |
37 | ||
be7f5c4d JG |
38 | enum emc1403_chip { emc1402, emc1403, emc1404 }; |
39 | ||
dac6831e | 40 | struct thermal_data { |
4cab259f | 41 | struct regmap *regmap; |
dac6831e | 42 | struct mutex mutex; |
4cab259f | 43 | const struct attribute_group *groups[4]; |
dac6831e KT |
44 | }; |
45 | ||
46 | static ssize_t show_temp(struct device *dev, | |
47 | struct device_attribute *attr, char *buf) | |
48 | { | |
dac6831e | 49 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
454aee17 | 50 | struct thermal_data *data = dev_get_drvdata(dev); |
4cab259f | 51 | unsigned int val; |
454aee17 | 52 | int retval; |
dac6831e | 53 | |
4cab259f | 54 | retval = regmap_read(data->regmap, sda->index, &val); |
dac6831e KT |
55 | if (retval < 0) |
56 | return retval; | |
4cab259f | 57 | return sprintf(buf, "%d000\n", val); |
dac6831e KT |
58 | } |
59 | ||
60 | static ssize_t show_bit(struct device *dev, | |
61 | struct device_attribute *attr, char *buf) | |
62 | { | |
dac6831e | 63 | struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); |
454aee17 | 64 | struct thermal_data *data = dev_get_drvdata(dev); |
4cab259f | 65 | unsigned int val; |
454aee17 | 66 | int retval; |
dac6831e | 67 | |
4cab259f | 68 | retval = regmap_read(data->regmap, sda->nr, &val); |
dac6831e KT |
69 | if (retval < 0) |
70 | return retval; | |
4cab259f | 71 | return sprintf(buf, "%d\n", !!(val & sda->index)); |
dac6831e KT |
72 | } |
73 | ||
74 | static ssize_t store_temp(struct device *dev, | |
75 | struct device_attribute *attr, const char *buf, size_t count) | |
76 | { | |
77 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | |
454aee17 | 78 | struct thermal_data *data = dev_get_drvdata(dev); |
dac6831e KT |
79 | unsigned long val; |
80 | int retval; | |
81 | ||
179c4fdb | 82 | if (kstrtoul(buf, 10, &val)) |
dac6831e | 83 | return -EINVAL; |
4cab259f GR |
84 | retval = regmap_write(data->regmap, sda->index, |
85 | DIV_ROUND_CLOSEST(val, 1000)); | |
dac6831e KT |
86 | if (retval < 0) |
87 | return retval; | |
88 | return count; | |
89 | } | |
90 | ||
960f12f4 AC |
91 | static ssize_t store_bit(struct device *dev, |
92 | struct device_attribute *attr, const char *buf, size_t count) | |
93 | { | |
960f12f4 | 94 | struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); |
454aee17 | 95 | struct thermal_data *data = dev_get_drvdata(dev); |
960f12f4 AC |
96 | unsigned long val; |
97 | int retval; | |
98 | ||
179c4fdb | 99 | if (kstrtoul(buf, 10, &val)) |
960f12f4 AC |
100 | return -EINVAL; |
101 | ||
4cab259f GR |
102 | retval = regmap_update_bits(data->regmap, sda->nr, sda->index, |
103 | val ? sda->index : 0); | |
960f12f4 | 104 | if (retval < 0) |
4cab259f GR |
105 | return retval; |
106 | return count; | |
960f12f4 AC |
107 | } |
108 | ||
dac6831e KT |
109 | static ssize_t show_hyst(struct device *dev, |
110 | struct device_attribute *attr, char *buf) | |
111 | { | |
dac6831e | 112 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
454aee17 | 113 | struct thermal_data *data = dev_get_drvdata(dev); |
4cab259f GR |
114 | struct regmap *regmap = data->regmap; |
115 | unsigned int limit; | |
116 | unsigned int hyst; | |
dac6831e | 117 | int retval; |
dac6831e | 118 | |
4cab259f | 119 | retval = regmap_read(regmap, sda->index, &limit); |
dac6831e KT |
120 | if (retval < 0) |
121 | return retval; | |
122 | ||
4cab259f GR |
123 | retval = regmap_read(regmap, 0x21, &hyst); |
124 | if (retval < 0) | |
125 | return retval; | |
126 | ||
127 | return sprintf(buf, "%d000\n", limit - hyst); | |
dac6831e KT |
128 | } |
129 | ||
130 | static ssize_t store_hyst(struct device *dev, | |
131 | struct device_attribute *attr, const char *buf, size_t count) | |
132 | { | |
dac6831e | 133 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
454aee17 | 134 | struct thermal_data *data = dev_get_drvdata(dev); |
4cab259f GR |
135 | struct regmap *regmap = data->regmap; |
136 | unsigned int limit; | |
dac6831e KT |
137 | int retval; |
138 | int hyst; | |
139 | unsigned long val; | |
140 | ||
179c4fdb | 141 | if (kstrtoul(buf, 10, &val)) |
dac6831e KT |
142 | return -EINVAL; |
143 | ||
144 | mutex_lock(&data->mutex); | |
4cab259f | 145 | retval = regmap_read(regmap, sda->index, &limit); |
dac6831e KT |
146 | if (retval < 0) |
147 | goto fail; | |
148 | ||
4cab259f | 149 | hyst = limit * 1000 - val; |
dac6831e KT |
150 | hyst = DIV_ROUND_CLOSEST(hyst, 1000); |
151 | if (hyst < 0 || hyst > 255) { | |
152 | retval = -ERANGE; | |
153 | goto fail; | |
154 | } | |
155 | ||
4cab259f GR |
156 | retval = regmap_write(regmap, 0x21, hyst); |
157 | if (retval == 0) | |
dac6831e | 158 | retval = count; |
dac6831e KT |
159 | fail: |
160 | mutex_unlock(&data->mutex); | |
161 | return retval; | |
162 | } | |
163 | ||
164 | /* | |
165 | * Sensors. We pass the actual i2c register to the methods. | |
166 | */ | |
167 | ||
168 | static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, | |
169 | show_temp, store_temp, 0x06); | |
170 | static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, | |
171 | show_temp, store_temp, 0x05); | |
172 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR, | |
173 | show_temp, store_temp, 0x20); | |
174 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0x00); | |
175 | static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, S_IRUGO, | |
176 | show_bit, NULL, 0x36, 0x01); | |
177 | static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO, | |
178 | show_bit, NULL, 0x35, 0x01); | |
179 | static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, | |
180 | show_bit, NULL, 0x37, 0x01); | |
181 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO | S_IWUSR, | |
182 | show_hyst, store_hyst, 0x20); | |
183 | ||
184 | static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO | S_IWUSR, | |
185 | show_temp, store_temp, 0x08); | |
186 | static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, | |
187 | show_temp, store_temp, 0x07); | |
188 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO | S_IWUSR, | |
189 | show_temp, store_temp, 0x19); | |
190 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0x01); | |
d8850c19 | 191 | static SENSOR_DEVICE_ATTR_2(temp2_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x02); |
dac6831e KT |
192 | static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO, |
193 | show_bit, NULL, 0x36, 0x02); | |
194 | static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO, | |
195 | show_bit, NULL, 0x35, 0x02); | |
196 | static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO, | |
197 | show_bit, NULL, 0x37, 0x02); | |
198 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO | S_IWUSR, | |
199 | show_hyst, store_hyst, 0x19); | |
200 | ||
201 | static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO | S_IWUSR, | |
202 | show_temp, store_temp, 0x16); | |
203 | static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR, | |
204 | show_temp, store_temp, 0x15); | |
205 | static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO | S_IWUSR, | |
206 | show_temp, store_temp, 0x1A); | |
207 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 0x23); | |
d8850c19 | 208 | static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x04); |
dac6831e KT |
209 | static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO, |
210 | show_bit, NULL, 0x36, 0x04); | |
211 | static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO, | |
212 | show_bit, NULL, 0x35, 0x04); | |
213 | static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, | |
214 | show_bit, NULL, 0x37, 0x04); | |
215 | static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO | S_IWUSR, | |
216 | show_hyst, store_hyst, 0x1A); | |
217 | ||
0011ddfe GR |
218 | static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO | S_IWUSR, |
219 | show_temp, store_temp, 0x2D); | |
220 | static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO | S_IWUSR, | |
221 | show_temp, store_temp, 0x2C); | |
222 | static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO | S_IWUSR, | |
223 | show_temp, store_temp, 0x30); | |
224 | static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 0x2A); | |
d8850c19 | 225 | static SENSOR_DEVICE_ATTR_2(temp4_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x08); |
0011ddfe GR |
226 | static SENSOR_DEVICE_ATTR_2(temp4_min_alarm, S_IRUGO, |
227 | show_bit, NULL, 0x36, 0x08); | |
228 | static SENSOR_DEVICE_ATTR_2(temp4_max_alarm, S_IRUGO, | |
229 | show_bit, NULL, 0x35, 0x08); | |
230 | static SENSOR_DEVICE_ATTR_2(temp4_crit_alarm, S_IRUGO, | |
231 | show_bit, NULL, 0x37, 0x08); | |
232 | static SENSOR_DEVICE_ATTR(temp4_crit_hyst, S_IRUGO | S_IWUSR, | |
233 | show_hyst, store_hyst, 0x30); | |
234 | ||
960f12f4 AC |
235 | static SENSOR_DEVICE_ATTR_2(power_state, S_IRUGO | S_IWUSR, |
236 | show_bit, store_bit, 0x03, 0x40); | |
237 | ||
be7f5c4d | 238 | static struct attribute *emc1402_attrs[] = { |
dac6831e KT |
239 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
240 | &sensor_dev_attr_temp1_max.dev_attr.attr, | |
241 | &sensor_dev_attr_temp1_crit.dev_attr.attr, | |
242 | &sensor_dev_attr_temp1_input.dev_attr.attr, | |
dac6831e | 243 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
be7f5c4d | 244 | |
dac6831e KT |
245 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
246 | &sensor_dev_attr_temp2_max.dev_attr.attr, | |
247 | &sensor_dev_attr_temp2_crit.dev_attr.attr, | |
248 | &sensor_dev_attr_temp2_input.dev_attr.attr, | |
be7f5c4d JG |
249 | &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, |
250 | ||
251 | &sensor_dev_attr_power_state.dev_attr.attr, | |
252 | NULL | |
253 | }; | |
254 | ||
255 | static const struct attribute_group emc1402_group = { | |
256 | .attrs = emc1402_attrs, | |
257 | }; | |
258 | ||
259 | static struct attribute *emc1403_attrs[] = { | |
260 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, | |
261 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | |
262 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, | |
263 | ||
d8850c19 | 264 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
dac6831e KT |
265 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
266 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | |
267 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | |
be7f5c4d | 268 | |
dac6831e KT |
269 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
270 | &sensor_dev_attr_temp3_max.dev_attr.attr, | |
271 | &sensor_dev_attr_temp3_crit.dev_attr.attr, | |
272 | &sensor_dev_attr_temp3_input.dev_attr.attr, | |
d8850c19 | 273 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
dac6831e KT |
274 | &sensor_dev_attr_temp3_min_alarm.dev_attr.attr, |
275 | &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, | |
276 | &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, | |
277 | &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr, | |
278 | NULL | |
279 | }; | |
0011ddfe GR |
280 | |
281 | static const struct attribute_group emc1403_group = { | |
282 | .attrs = emc1403_attrs, | |
283 | }; | |
284 | ||
285 | static struct attribute *emc1404_attrs[] = { | |
286 | &sensor_dev_attr_temp4_min.dev_attr.attr, | |
287 | &sensor_dev_attr_temp4_max.dev_attr.attr, | |
288 | &sensor_dev_attr_temp4_crit.dev_attr.attr, | |
289 | &sensor_dev_attr_temp4_input.dev_attr.attr, | |
d8850c19 | 290 | &sensor_dev_attr_temp4_fault.dev_attr.attr, |
0011ddfe GR |
291 | &sensor_dev_attr_temp4_min_alarm.dev_attr.attr, |
292 | &sensor_dev_attr_temp4_max_alarm.dev_attr.attr, | |
293 | &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr, | |
294 | &sensor_dev_attr_temp4_crit_hyst.dev_attr.attr, | |
295 | NULL | |
296 | }; | |
297 | ||
298 | static const struct attribute_group emc1404_group = { | |
299 | .attrs = emc1404_attrs, | |
300 | }; | |
dac6831e | 301 | |
03f49f64 GR |
302 | /* |
303 | * EMC14x2 uses a different register and different bits to report alarm and | |
304 | * fault status. For simplicity, provide a separate attribute group for this | |
305 | * chip series. | |
306 | * Since we can not re-use the same attribute names, create a separate attribute | |
307 | * array. | |
308 | */ | |
309 | static struct sensor_device_attribute_2 emc1402_alarms[] = { | |
310 | SENSOR_ATTR_2(temp1_min_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x20), | |
311 | SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x40), | |
312 | SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x01), | |
313 | ||
314 | SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_bit, NULL, 0x02, 0x04), | |
315 | SENSOR_ATTR_2(temp2_min_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x08), | |
316 | SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x10), | |
317 | SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x02), | |
318 | }; | |
319 | ||
320 | static struct attribute *emc1402_alarm_attrs[] = { | |
321 | &emc1402_alarms[0].dev_attr.attr, | |
322 | &emc1402_alarms[1].dev_attr.attr, | |
323 | &emc1402_alarms[2].dev_attr.attr, | |
324 | &emc1402_alarms[3].dev_attr.attr, | |
325 | &emc1402_alarms[4].dev_attr.attr, | |
326 | &emc1402_alarms[5].dev_attr.attr, | |
327 | &emc1402_alarms[6].dev_attr.attr, | |
328 | NULL, | |
329 | }; | |
330 | ||
331 | static const struct attribute_group emc1402_alarm_group = { | |
332 | .attrs = emc1402_alarm_attrs, | |
333 | }; | |
334 | ||
dac6831e KT |
335 | static int emc1403_detect(struct i2c_client *client, |
336 | struct i2c_board_info *info) | |
337 | { | |
338 | int id; | |
7a1b76f2 | 339 | /* Check if thermal chip is SMSC and EMC1403 or EMC1423 */ |
dac6831e KT |
340 | |
341 | id = i2c_smbus_read_byte_data(client, THERMAL_SMSC_ID_REG); | |
342 | if (id != 0x5d) | |
343 | return -ENODEV; | |
344 | ||
7a1b76f2 JL |
345 | id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG); |
346 | switch (id) { | |
be7f5c4d JG |
347 | case 0x20: |
348 | strlcpy(info->type, "emc1402", I2C_NAME_SIZE); | |
349 | break; | |
7a1b76f2 JL |
350 | case 0x21: |
351 | strlcpy(info->type, "emc1403", I2C_NAME_SIZE); | |
352 | break; | |
be7f5c4d JG |
353 | case 0x22: |
354 | strlcpy(info->type, "emc1422", I2C_NAME_SIZE); | |
355 | break; | |
7a1b76f2 JL |
356 | case 0x23: |
357 | strlcpy(info->type, "emc1423", I2C_NAME_SIZE); | |
358 | break; | |
0011ddfe GR |
359 | case 0x25: |
360 | strlcpy(info->type, "emc1404", I2C_NAME_SIZE); | |
361 | break; | |
362 | case 0x27: | |
363 | strlcpy(info->type, "emc1424", I2C_NAME_SIZE); | |
364 | break; | |
7a1b76f2 | 365 | default: |
dac6831e | 366 | return -ENODEV; |
7a1b76f2 | 367 | } |
dac6831e KT |
368 | |
369 | id = i2c_smbus_read_byte_data(client, THERMAL_REVISION_REG); | |
3a18e139 | 370 | if (id < 0x01 || id > 0x04) |
dac6831e KT |
371 | return -ENODEV; |
372 | ||
dac6831e KT |
373 | return 0; |
374 | } | |
375 | ||
4cab259f GR |
376 | static bool emc1403_regmap_is_volatile(struct device *dev, unsigned int reg) |
377 | { | |
378 | switch (reg) { | |
379 | case 0x00: /* internal diode high byte */ | |
380 | case 0x01: /* external diode 1 high byte */ | |
381 | case 0x02: /* status */ | |
382 | case 0x10: /* external diode 1 low byte */ | |
383 | case 0x1b: /* external diode fault */ | |
384 | case 0x23: /* external diode 2 high byte */ | |
385 | case 0x24: /* external diode 2 low byte */ | |
386 | case 0x29: /* internal diode low byte */ | |
387 | case 0x2a: /* externl diode 3 high byte */ | |
388 | case 0x2b: /* external diode 3 low byte */ | |
389 | case 0x35: /* high limit status */ | |
390 | case 0x36: /* low limit status */ | |
391 | case 0x37: /* therm limit status */ | |
392 | return true; | |
393 | default: | |
394 | return false; | |
395 | } | |
396 | } | |
397 | ||
398 | static struct regmap_config emc1403_regmap_config = { | |
399 | .reg_bits = 8, | |
400 | .val_bits = 8, | |
401 | .cache_type = REGCACHE_RBTREE, | |
402 | .volatile_reg = emc1403_regmap_is_volatile, | |
403 | }; | |
404 | ||
dac6831e KT |
405 | static int emc1403_probe(struct i2c_client *client, |
406 | const struct i2c_device_id *id) | |
407 | { | |
dac6831e | 408 | struct thermal_data *data; |
454aee17 | 409 | struct device *hwmon_dev; |
dac6831e | 410 | |
7b52eefe GR |
411 | data = devm_kzalloc(&client->dev, sizeof(struct thermal_data), |
412 | GFP_KERNEL); | |
413 | if (data == NULL) | |
dac6831e | 414 | return -ENOMEM; |
dac6831e | 415 | |
4cab259f GR |
416 | data->regmap = devm_regmap_init_i2c(client, &emc1403_regmap_config); |
417 | if (IS_ERR(data->regmap)) | |
418 | return PTR_ERR(data->regmap); | |
419 | ||
dac6831e | 420 | mutex_init(&data->mutex); |
dac6831e | 421 | |
be7f5c4d JG |
422 | switch (id->driver_data) { |
423 | case emc1404: | |
424 | data->groups[2] = &emc1404_group; | |
425 | case emc1403: | |
426 | data->groups[1] = &emc1403_group; | |
427 | case emc1402: | |
428 | data->groups[0] = &emc1402_group; | |
429 | } | |
0011ddfe | 430 | |
03f49f64 GR |
431 | if (id->driver_data == emc1402) |
432 | data->groups[1] = &emc1402_alarm_group; | |
433 | ||
8759f904 JD |
434 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, |
435 | client->name, data, | |
436 | data->groups); | |
454aee17 GR |
437 | if (IS_ERR(hwmon_dev)) |
438 | return PTR_ERR(hwmon_dev); | |
dac6831e | 439 | |
0011ddfe | 440 | dev_info(&client->dev, "%s Thermal chip found\n", id->name); |
dac6831e KT |
441 | return 0; |
442 | } | |
443 | ||
444 | static const unsigned short emc1403_address_list[] = { | |
be7f5c4d | 445 | 0x18, 0x1c, 0x29, 0x4c, 0x4d, 0x5c, I2C_CLIENT_END |
dac6831e KT |
446 | }; |
447 | ||
be7f5c4d | 448 | /* Last digit of chip name indicates number of channels */ |
dac6831e | 449 | static const struct i2c_device_id emc1403_idtable[] = { |
be7f5c4d JG |
450 | { "emc1402", emc1402 }, |
451 | { "emc1403", emc1403 }, | |
452 | { "emc1404", emc1404 }, | |
453 | { "emc1422", emc1402 }, | |
454 | { "emc1423", emc1403 }, | |
455 | { "emc1424", emc1404 }, | |
dac6831e KT |
456 | { } |
457 | }; | |
458 | MODULE_DEVICE_TABLE(i2c, emc1403_idtable); | |
459 | ||
460 | static struct i2c_driver sensor_emc1403 = { | |
461 | .class = I2C_CLASS_HWMON, | |
462 | .driver = { | |
463 | .name = "emc1403", | |
464 | }, | |
465 | .detect = emc1403_detect, | |
466 | .probe = emc1403_probe, | |
dac6831e KT |
467 | .id_table = emc1403_idtable, |
468 | .address_list = emc1403_address_list, | |
469 | }; | |
470 | ||
f0967eea | 471 | module_i2c_driver(sensor_emc1403); |
dac6831e KT |
472 | |
473 | MODULE_AUTHOR("Kalhan Trisal <kalhan.trisal@intel.com"); | |
474 | MODULE_DESCRIPTION("emc1403 Thermal Driver"); | |
475 | MODULE_LICENSE("GPL v2"); |