xref: /openbmc/linux/drivers/hwmon/lm85.c (revision 3fc41476)
1 /*
2  * lm85.c - Part of lm_sensors, Linux kernel modules for hardware
3  *	    monitoring
4  * Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
5  * Copyright (c) 2002, 2003  Philip Pokorny <ppokorny@penguincomputing.com>
6  * Copyright (c) 2003        Margit Schubert-While <margitsw@t-online.de>
7  * Copyright (c) 2004        Justin Thiessen <jthiessen@penguincomputing.com>
8  * Copyright (C) 2007--2014  Jean Delvare <jdelvare@suse.de>
9  *
10  * Chip details at	      <http://www.national.com/ds/LM/LM85.pdf>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  */
26 
27 #include <linux/module.h>
28 #include <linux/of_device.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <linux/jiffies.h>
32 #include <linux/i2c.h>
33 #include <linux/hwmon.h>
34 #include <linux/hwmon-vid.h>
35 #include <linux/hwmon-sysfs.h>
36 #include <linux/err.h>
37 #include <linux/mutex.h>
38 #include <linux/util_macros.h>
39 
40 /* Addresses to scan */
41 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
42 
43 enum chips {
44 	lm85, lm96000,
45 	adm1027, adt7463, adt7468,
46 	emc6d100, emc6d102, emc6d103, emc6d103s
47 };
48 
49 /* The LM85 registers */
50 
51 #define LM85_REG_IN(nr)			(0x20 + (nr))
52 #define LM85_REG_IN_MIN(nr)		(0x44 + (nr) * 2)
53 #define LM85_REG_IN_MAX(nr)		(0x45 + (nr) * 2)
54 
55 #define LM85_REG_TEMP(nr)		(0x25 + (nr))
56 #define LM85_REG_TEMP_MIN(nr)		(0x4e + (nr) * 2)
57 #define LM85_REG_TEMP_MAX(nr)		(0x4f + (nr) * 2)
58 
59 /* Fan speeds are LSB, MSB (2 bytes) */
60 #define LM85_REG_FAN(nr)		(0x28 + (nr) * 2)
61 #define LM85_REG_FAN_MIN(nr)		(0x54 + (nr) * 2)
62 
63 #define LM85_REG_PWM(nr)		(0x30 + (nr))
64 
65 #define LM85_REG_COMPANY		0x3e
66 #define LM85_REG_VERSTEP		0x3f
67 
68 #define ADT7468_REG_CFG5		0x7c
69 #define ADT7468_OFF64			(1 << 0)
70 #define ADT7468_HFPWM			(1 << 1)
71 #define IS_ADT7468_OFF64(data)		\
72 	((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64))
73 #define IS_ADT7468_HFPWM(data)		\
74 	((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM))
75 
76 /* These are the recognized values for the above regs */
77 #define LM85_COMPANY_NATIONAL		0x01
78 #define LM85_COMPANY_ANALOG_DEV		0x41
79 #define LM85_COMPANY_SMSC		0x5c
80 #define LM85_VERSTEP_LM85C		0x60
81 #define LM85_VERSTEP_LM85B		0x62
82 #define LM85_VERSTEP_LM96000_1		0x68
83 #define LM85_VERSTEP_LM96000_2		0x69
84 #define LM85_VERSTEP_ADM1027		0x60
85 #define LM85_VERSTEP_ADT7463		0x62
86 #define LM85_VERSTEP_ADT7463C		0x6A
87 #define LM85_VERSTEP_ADT7468_1		0x71
88 #define LM85_VERSTEP_ADT7468_2		0x72
89 #define LM85_VERSTEP_EMC6D100_A0        0x60
90 #define LM85_VERSTEP_EMC6D100_A1        0x61
91 #define LM85_VERSTEP_EMC6D102		0x65
92 #define LM85_VERSTEP_EMC6D103_A0	0x68
93 #define LM85_VERSTEP_EMC6D103_A1	0x69
94 #define LM85_VERSTEP_EMC6D103S		0x6A	/* Also known as EMC6D103:A2 */
95 
96 #define LM85_REG_CONFIG			0x40
97 
98 #define LM85_REG_ALARM1			0x41
99 #define LM85_REG_ALARM2			0x42
100 
101 #define LM85_REG_VID			0x43
102 
103 /* Automated FAN control */
104 #define LM85_REG_AFAN_CONFIG(nr)	(0x5c + (nr))
105 #define LM85_REG_AFAN_RANGE(nr)		(0x5f + (nr))
106 #define LM85_REG_AFAN_SPIKE1		0x62
107 #define LM85_REG_AFAN_MINPWM(nr)	(0x64 + (nr))
108 #define LM85_REG_AFAN_LIMIT(nr)		(0x67 + (nr))
109 #define LM85_REG_AFAN_CRITICAL(nr)	(0x6a + (nr))
110 #define LM85_REG_AFAN_HYST1		0x6d
111 #define LM85_REG_AFAN_HYST2		0x6e
112 
113 #define ADM1027_REG_EXTEND_ADC1		0x76
114 #define ADM1027_REG_EXTEND_ADC2		0x77
115 
116 #define EMC6D100_REG_ALARM3             0x7d
117 /* IN5, IN6 and IN7 */
118 #define EMC6D100_REG_IN(nr)             (0x70 + ((nr) - 5))
119 #define EMC6D100_REG_IN_MIN(nr)         (0x73 + ((nr) - 5) * 2)
120 #define EMC6D100_REG_IN_MAX(nr)         (0x74 + ((nr) - 5) * 2)
121 #define EMC6D102_REG_EXTEND_ADC1	0x85
122 #define EMC6D102_REG_EXTEND_ADC2	0x86
123 #define EMC6D102_REG_EXTEND_ADC3	0x87
124 #define EMC6D102_REG_EXTEND_ADC4	0x88
125 
126 /*
127  * Conversions. Rounding and limit checking is only done on the TO_REG
128  * variants. Note that you should be a bit careful with which arguments
129  * these macros are called: arguments may be evaluated more than once.
130  */
131 
132 /* IN are scaled according to built-in resistors */
133 static const int lm85_scaling[] = {  /* .001 Volts */
134 	2500, 2250, 3300, 5000, 12000,
135 	3300, 1500, 1800 /*EMC6D100*/
136 };
137 #define SCALE(val, from, to)	(((val) * (to) + ((from) / 2)) / (from))
138 
139 #define INS_TO_REG(n, val)	\
140 		SCALE(clamp_val(val, 0, 255 * lm85_scaling[n] / 192), \
141 		      lm85_scaling[n], 192)
142 
143 #define INSEXT_FROM_REG(n, val, ext)	\
144 		SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
145 
146 #define INS_FROM_REG(n, val)	SCALE((val), 192, lm85_scaling[n])
147 
148 /* FAN speed is measured using 90kHz clock */
149 static inline u16 FAN_TO_REG(unsigned long val)
150 {
151 	if (!val)
152 		return 0xffff;
153 	return clamp_val(5400000 / val, 1, 0xfffe);
154 }
155 #define FAN_FROM_REG(val)	((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
156 				 5400000 / (val))
157 
158 /* Temperature is reported in .001 degC increments */
159 #define TEMP_TO_REG(val)	\
160 		DIV_ROUND_CLOSEST(clamp_val((val), -127000, 127000), 1000)
161 #define TEMPEXT_FROM_REG(val, ext)	\
162 		SCALE(((val) << 4) + (ext), 16, 1000)
163 #define TEMP_FROM_REG(val)	((val) * 1000)
164 
165 #define PWM_TO_REG(val)			clamp_val(val, 0, 255)
166 #define PWM_FROM_REG(val)		(val)
167 
168 /*
169  * ZONEs have the following parameters:
170  *    Limit (low) temp,           1. degC
171  *    Hysteresis (below limit),   1. degC (0-15)
172  *    Range of speed control,     .1 degC (2-80)
173  *    Critical (high) temp,       1. degC
174  *
175  * FAN PWMs have the following parameters:
176  *    Reference Zone,                 1, 2, 3, etc.
177  *    Spinup time,                    .05 sec
178  *    PWM value at limit/low temp,    1 count
179  *    PWM Frequency,                  1. Hz
180  *    PWM is Min or OFF below limit,  flag
181  *    Invert PWM output,              flag
182  *
183  * Some chips filter the temp, others the fan.
184  *    Filter constant (or disabled)   .1 seconds
185  */
186 
187 /* These are the zone temperature range encodings in .001 degree C */
188 static const int lm85_range_map[] = {
189 	2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000,
190 	13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
191 };
192 
193 static int RANGE_TO_REG(long range)
194 {
195 	return find_closest(range, lm85_range_map, ARRAY_SIZE(lm85_range_map));
196 }
197 #define RANGE_FROM_REG(val)	lm85_range_map[(val) & 0x0f]
198 
199 /* These are the PWM frequency encodings */
200 static const int lm85_freq_map[] = { /* 1 Hz */
201 	10, 15, 23, 30, 38, 47, 61, 94
202 };
203 
204 static const int lm96000_freq_map[] = { /* 1 Hz */
205 	10, 15, 23, 30, 38, 47, 61, 94,
206 	22500, 24000, 25700, 25700, 27700, 27700, 30000, 30000
207 };
208 
209 static const int adm1027_freq_map[] = { /* 1 Hz */
210 	11, 15, 22, 29, 35, 44, 59, 88
211 };
212 
213 static int FREQ_TO_REG(const int *map,
214 		       unsigned int map_size, unsigned long freq)
215 {
216 	return find_closest(freq, map, map_size);
217 }
218 
219 static int FREQ_FROM_REG(const int *map, unsigned int map_size, u8 reg)
220 {
221 	return map[reg % map_size];
222 }
223 
224 /*
225  * Since we can't use strings, I'm abusing these numbers
226  *   to stand in for the following meanings:
227  *      1 -- PWM responds to Zone 1
228  *      2 -- PWM responds to Zone 2
229  *      3 -- PWM responds to Zone 3
230  *     23 -- PWM responds to the higher temp of Zone 2 or 3
231  *    123 -- PWM responds to highest of Zone 1, 2, or 3
232  *      0 -- PWM is always at 0% (ie, off)
233  *     -1 -- PWM is always at 100%
234  *     -2 -- PWM responds to manual control
235  */
236 
237 static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
238 #define ZONE_FROM_REG(val)	lm85_zone_map[(val) >> 5]
239 
240 static int ZONE_TO_REG(int zone)
241 {
242 	int i;
243 
244 	for (i = 0; i <= 7; ++i)
245 		if (zone == lm85_zone_map[i])
246 			break;
247 	if (i > 7)   /* Not found. */
248 		i = 3;  /* Always 100% */
249 	return i << 5;
250 }
251 
252 #define HYST_TO_REG(val)	clamp_val(((val) + 500) / 1000, 0, 15)
253 #define HYST_FROM_REG(val)	((val) * 1000)
254 
255 /*
256  * Chip sampling rates
257  *
258  * Some sensors are not updated more frequently than once per second
259  *    so it doesn't make sense to read them more often than that.
260  *    We cache the results and return the saved data if the driver
261  *    is called again before a second has elapsed.
262  *
263  * Also, there is significant configuration data for this chip
264  *    given the automatic PWM fan control that is possible.  There
265  *    are about 47 bytes of config data to only 22 bytes of actual
266  *    readings.  So, we keep the config data up to date in the cache
267  *    when it is written and only sample it once every 1 *minute*
268  */
269 #define LM85_DATA_INTERVAL  (HZ + HZ / 2)
270 #define LM85_CONFIG_INTERVAL  (1 * 60 * HZ)
271 
272 /*
273  * LM85 can automatically adjust fan speeds based on temperature
274  * This structure encapsulates an entire Zone config.  There are
275  * three zones (one for each temperature input) on the lm85
276  */
277 struct lm85_zone {
278 	s8 limit;	/* Low temp limit */
279 	u8 hyst;	/* Low limit hysteresis. (0-15) */
280 	u8 range;	/* Temp range, encoded */
281 	s8 critical;	/* "All fans ON" temp limit */
282 	u8 max_desired; /*
283 			 * Actual "max" temperature specified.  Preserved
284 			 * to prevent "drift" as other autofan control
285 			 * values change.
286 			 */
287 };
288 
289 struct lm85_autofan {
290 	u8 config;	/* Register value */
291 	u8 min_pwm;	/* Minimum PWM value, encoded */
292 	u8 min_off;	/* Min PWM or OFF below "limit", flag */
293 };
294 
295 /*
296  * For each registered chip, we need to keep some data in memory.
297  * The structure is dynamically allocated.
298  */
299 struct lm85_data {
300 	struct i2c_client *client;
301 	const struct attribute_group *groups[6];
302 	const int *freq_map;
303 	unsigned int freq_map_size;
304 
305 	enum chips type;
306 
307 	bool has_vid5;	/* true if VID5 is configured for ADT7463 or ADT7468 */
308 
309 	struct mutex update_lock;
310 	int valid;		/* !=0 if following fields are valid */
311 	unsigned long last_reading;	/* In jiffies */
312 	unsigned long last_config;	/* In jiffies */
313 
314 	u8 in[8];		/* Register value */
315 	u8 in_max[8];		/* Register value */
316 	u8 in_min[8];		/* Register value */
317 	s8 temp[3];		/* Register value */
318 	s8 temp_min[3];		/* Register value */
319 	s8 temp_max[3];		/* Register value */
320 	u16 fan[4];		/* Register value */
321 	u16 fan_min[4];		/* Register value */
322 	u8 pwm[3];		/* Register value */
323 	u8 pwm_freq[3];		/* Register encoding */
324 	u8 temp_ext[3];		/* Decoded values */
325 	u8 in_ext[8];		/* Decoded values */
326 	u8 vid;			/* Register value */
327 	u8 vrm;			/* VRM version */
328 	u32 alarms;		/* Register encoding, combined */
329 	u8 cfg5;		/* Config Register 5 on ADT7468 */
330 	struct lm85_autofan autofan[3];
331 	struct lm85_zone zone[3];
332 };
333 
334 static int lm85_read_value(struct i2c_client *client, u8 reg)
335 {
336 	int res;
337 
338 	/* What size location is it? */
339 	switch (reg) {
340 	case LM85_REG_FAN(0):  /* Read WORD data */
341 	case LM85_REG_FAN(1):
342 	case LM85_REG_FAN(2):
343 	case LM85_REG_FAN(3):
344 	case LM85_REG_FAN_MIN(0):
345 	case LM85_REG_FAN_MIN(1):
346 	case LM85_REG_FAN_MIN(2):
347 	case LM85_REG_FAN_MIN(3):
348 	case LM85_REG_ALARM1:	/* Read both bytes at once */
349 		res = i2c_smbus_read_byte_data(client, reg) & 0xff;
350 		res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
351 		break;
352 	default:	/* Read BYTE data */
353 		res = i2c_smbus_read_byte_data(client, reg);
354 		break;
355 	}
356 
357 	return res;
358 }
359 
360 static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
361 {
362 	switch (reg) {
363 	case LM85_REG_FAN(0):  /* Write WORD data */
364 	case LM85_REG_FAN(1):
365 	case LM85_REG_FAN(2):
366 	case LM85_REG_FAN(3):
367 	case LM85_REG_FAN_MIN(0):
368 	case LM85_REG_FAN_MIN(1):
369 	case LM85_REG_FAN_MIN(2):
370 	case LM85_REG_FAN_MIN(3):
371 	/* NOTE: ALARM is read only, so not included here */
372 		i2c_smbus_write_byte_data(client, reg, value & 0xff);
373 		i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
374 		break;
375 	default:	/* Write BYTE data */
376 		i2c_smbus_write_byte_data(client, reg, value);
377 		break;
378 	}
379 }
380 
381 static struct lm85_data *lm85_update_device(struct device *dev)
382 {
383 	struct lm85_data *data = dev_get_drvdata(dev);
384 	struct i2c_client *client = data->client;
385 	int i;
386 
387 	mutex_lock(&data->update_lock);
388 
389 	if (!data->valid ||
390 	     time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
391 		/* Things that change quickly */
392 		dev_dbg(&client->dev, "Reading sensor values\n");
393 
394 		/*
395 		 * Have to read extended bits first to "freeze" the
396 		 * more significant bits that are read later.
397 		 * There are 2 additional resolution bits per channel and we
398 		 * have room for 4, so we shift them to the left.
399 		 */
400 		if (data->type == adm1027 || data->type == adt7463 ||
401 		    data->type == adt7468) {
402 			int ext1 = lm85_read_value(client,
403 						   ADM1027_REG_EXTEND_ADC1);
404 			int ext2 =  lm85_read_value(client,
405 						    ADM1027_REG_EXTEND_ADC2);
406 			int val = (ext1 << 8) + ext2;
407 
408 			for (i = 0; i <= 4; i++)
409 				data->in_ext[i] =
410 					((val >> (i * 2)) & 0x03) << 2;
411 
412 			for (i = 0; i <= 2; i++)
413 				data->temp_ext[i] =
414 					(val >> ((i + 4) * 2)) & 0x0c;
415 		}
416 
417 		data->vid = lm85_read_value(client, LM85_REG_VID);
418 
419 		for (i = 0; i <= 3; ++i) {
420 			data->in[i] =
421 			    lm85_read_value(client, LM85_REG_IN(i));
422 			data->fan[i] =
423 			    lm85_read_value(client, LM85_REG_FAN(i));
424 		}
425 
426 		if (!data->has_vid5)
427 			data->in[4] = lm85_read_value(client, LM85_REG_IN(4));
428 
429 		if (data->type == adt7468)
430 			data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5);
431 
432 		for (i = 0; i <= 2; ++i) {
433 			data->temp[i] =
434 			    lm85_read_value(client, LM85_REG_TEMP(i));
435 			data->pwm[i] =
436 			    lm85_read_value(client, LM85_REG_PWM(i));
437 
438 			if (IS_ADT7468_OFF64(data))
439 				data->temp[i] -= 64;
440 		}
441 
442 		data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
443 
444 		if (data->type == emc6d100) {
445 			/* Three more voltage sensors */
446 			for (i = 5; i <= 7; ++i) {
447 				data->in[i] = lm85_read_value(client,
448 							EMC6D100_REG_IN(i));
449 			}
450 			/* More alarm bits */
451 			data->alarms |= lm85_read_value(client,
452 						EMC6D100_REG_ALARM3) << 16;
453 		} else if (data->type == emc6d102 || data->type == emc6d103 ||
454 			   data->type == emc6d103s) {
455 			/*
456 			 * Have to read LSB bits after the MSB ones because
457 			 * the reading of the MSB bits has frozen the
458 			 * LSBs (backward from the ADM1027).
459 			 */
460 			int ext1 = lm85_read_value(client,
461 						   EMC6D102_REG_EXTEND_ADC1);
462 			int ext2 = lm85_read_value(client,
463 						   EMC6D102_REG_EXTEND_ADC2);
464 			int ext3 = lm85_read_value(client,
465 						   EMC6D102_REG_EXTEND_ADC3);
466 			int ext4 = lm85_read_value(client,
467 						   EMC6D102_REG_EXTEND_ADC4);
468 			data->in_ext[0] = ext3 & 0x0f;
469 			data->in_ext[1] = ext4 & 0x0f;
470 			data->in_ext[2] = ext4 >> 4;
471 			data->in_ext[3] = ext3 >> 4;
472 			data->in_ext[4] = ext2 >> 4;
473 
474 			data->temp_ext[0] = ext1 & 0x0f;
475 			data->temp_ext[1] = ext2 & 0x0f;
476 			data->temp_ext[2] = ext1 >> 4;
477 		}
478 
479 		data->last_reading = jiffies;
480 	}  /* last_reading */
481 
482 	if (!data->valid ||
483 	     time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
484 		/* Things that don't change often */
485 		dev_dbg(&client->dev, "Reading config values\n");
486 
487 		for (i = 0; i <= 3; ++i) {
488 			data->in_min[i] =
489 			    lm85_read_value(client, LM85_REG_IN_MIN(i));
490 			data->in_max[i] =
491 			    lm85_read_value(client, LM85_REG_IN_MAX(i));
492 			data->fan_min[i] =
493 			    lm85_read_value(client, LM85_REG_FAN_MIN(i));
494 		}
495 
496 		if (!data->has_vid5)  {
497 			data->in_min[4] = lm85_read_value(client,
498 					  LM85_REG_IN_MIN(4));
499 			data->in_max[4] = lm85_read_value(client,
500 					  LM85_REG_IN_MAX(4));
501 		}
502 
503 		if (data->type == emc6d100) {
504 			for (i = 5; i <= 7; ++i) {
505 				data->in_min[i] = lm85_read_value(client,
506 						EMC6D100_REG_IN_MIN(i));
507 				data->in_max[i] = lm85_read_value(client,
508 						EMC6D100_REG_IN_MAX(i));
509 			}
510 		}
511 
512 		for (i = 0; i <= 2; ++i) {
513 			int val;
514 
515 			data->temp_min[i] =
516 			    lm85_read_value(client, LM85_REG_TEMP_MIN(i));
517 			data->temp_max[i] =
518 			    lm85_read_value(client, LM85_REG_TEMP_MAX(i));
519 
520 			data->autofan[i].config =
521 			    lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
522 			val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
523 			data->pwm_freq[i] = val % data->freq_map_size;
524 			data->zone[i].range = val >> 4;
525 			data->autofan[i].min_pwm =
526 			    lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
527 			data->zone[i].limit =
528 			    lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
529 			data->zone[i].critical =
530 			    lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
531 
532 			if (IS_ADT7468_OFF64(data)) {
533 				data->temp_min[i] -= 64;
534 				data->temp_max[i] -= 64;
535 				data->zone[i].limit -= 64;
536 				data->zone[i].critical -= 64;
537 			}
538 		}
539 
540 		if (data->type != emc6d103s) {
541 			i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
542 			data->autofan[0].min_off = (i & 0x20) != 0;
543 			data->autofan[1].min_off = (i & 0x40) != 0;
544 			data->autofan[2].min_off = (i & 0x80) != 0;
545 
546 			i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
547 			data->zone[0].hyst = i >> 4;
548 			data->zone[1].hyst = i & 0x0f;
549 
550 			i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
551 			data->zone[2].hyst = i >> 4;
552 		}
553 
554 		data->last_config = jiffies;
555 	}  /* last_config */
556 
557 	data->valid = 1;
558 
559 	mutex_unlock(&data->update_lock);
560 
561 	return data;
562 }
563 
564 /* 4 Fans */
565 static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
566 			char *buf)
567 {
568 	int nr = to_sensor_dev_attr(attr)->index;
569 	struct lm85_data *data = lm85_update_device(dev);
570 	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr]));
571 }
572 
573 static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
574 			    char *buf)
575 {
576 	int nr = to_sensor_dev_attr(attr)->index;
577 	struct lm85_data *data = lm85_update_device(dev);
578 	return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr]));
579 }
580 
581 static ssize_t fan_min_store(struct device *dev,
582 			     struct device_attribute *attr, const char *buf,
583 			     size_t count)
584 {
585 	int nr = to_sensor_dev_attr(attr)->index;
586 	struct lm85_data *data = dev_get_drvdata(dev);
587 	struct i2c_client *client = data->client;
588 	unsigned long val;
589 	int err;
590 
591 	err = kstrtoul(buf, 10, &val);
592 	if (err)
593 		return err;
594 
595 	mutex_lock(&data->update_lock);
596 	data->fan_min[nr] = FAN_TO_REG(val);
597 	lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
598 	mutex_unlock(&data->update_lock);
599 	return count;
600 }
601 
602 static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
603 static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
604 static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
605 static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
606 static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2);
607 static SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2);
608 static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3);
609 static SENSOR_DEVICE_ATTR_RW(fan4_min, fan_min, 3);
610 
611 /* vid, vrm, alarms */
612 
613 static ssize_t cpu0_vid_show(struct device *dev,
614 			     struct device_attribute *attr, char *buf)
615 {
616 	struct lm85_data *data = lm85_update_device(dev);
617 	int vid;
618 
619 	if (data->has_vid5) {
620 		/* 6-pin VID (VRM 10) */
621 		vid = vid_from_reg(data->vid & 0x3f, data->vrm);
622 	} else {
623 		/* 5-pin VID (VRM 9) */
624 		vid = vid_from_reg(data->vid & 0x1f, data->vrm);
625 	}
626 
627 	return sprintf(buf, "%d\n", vid);
628 }
629 
630 static DEVICE_ATTR_RO(cpu0_vid);
631 
632 static ssize_t vrm_show(struct device *dev, struct device_attribute *attr,
633 			char *buf)
634 {
635 	struct lm85_data *data = dev_get_drvdata(dev);
636 	return sprintf(buf, "%ld\n", (long) data->vrm);
637 }
638 
639 static ssize_t vrm_store(struct device *dev, struct device_attribute *attr,
640 			 const char *buf, size_t count)
641 {
642 	struct lm85_data *data = dev_get_drvdata(dev);
643 	unsigned long val;
644 	int err;
645 
646 	err = kstrtoul(buf, 10, &val);
647 	if (err)
648 		return err;
649 
650 	if (val > 255)
651 		return -EINVAL;
652 
653 	data->vrm = val;
654 	return count;
655 }
656 
657 static DEVICE_ATTR_RW(vrm);
658 
659 static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
660 			   char *buf)
661 {
662 	struct lm85_data *data = lm85_update_device(dev);
663 	return sprintf(buf, "%u\n", data->alarms);
664 }
665 
666 static DEVICE_ATTR_RO(alarms);
667 
668 static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
669 			  char *buf)
670 {
671 	int nr = to_sensor_dev_attr(attr)->index;
672 	struct lm85_data *data = lm85_update_device(dev);
673 	return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
674 }
675 
676 static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
677 static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
678 static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
679 static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
680 static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8);
681 static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 18);
682 static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 16);
683 static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 17);
684 static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
685 static SENSOR_DEVICE_ATTR_RO(temp1_fault, alarm, 14);
686 static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5);
687 static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 6);
688 static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 15);
689 static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 10);
690 static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 11);
691 static SENSOR_DEVICE_ATTR_RO(fan3_alarm, alarm, 12);
692 static SENSOR_DEVICE_ATTR_RO(fan4_alarm, alarm, 13);
693 
694 /* pwm */
695 
696 static ssize_t pwm_show(struct device *dev, struct device_attribute *attr,
697 			char *buf)
698 {
699 	int nr = to_sensor_dev_attr(attr)->index;
700 	struct lm85_data *data = lm85_update_device(dev);
701 	return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
702 }
703 
704 static ssize_t pwm_store(struct device *dev, struct device_attribute *attr,
705 			 const char *buf, size_t count)
706 {
707 	int nr = to_sensor_dev_attr(attr)->index;
708 	struct lm85_data *data = dev_get_drvdata(dev);
709 	struct i2c_client *client = data->client;
710 	unsigned long val;
711 	int err;
712 
713 	err = kstrtoul(buf, 10, &val);
714 	if (err)
715 		return err;
716 
717 	mutex_lock(&data->update_lock);
718 	data->pwm[nr] = PWM_TO_REG(val);
719 	lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
720 	mutex_unlock(&data->update_lock);
721 	return count;
722 }
723 
724 static ssize_t pwm_enable_show(struct device *dev,
725 			       struct device_attribute *attr, char *buf)
726 {
727 	int nr = to_sensor_dev_attr(attr)->index;
728 	struct lm85_data *data = lm85_update_device(dev);
729 	int pwm_zone, enable;
730 
731 	pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
732 	switch (pwm_zone) {
733 	case -1:	/* PWM is always at 100% */
734 		enable = 0;
735 		break;
736 	case 0:		/* PWM is always at 0% */
737 	case -2:	/* PWM responds to manual control */
738 		enable = 1;
739 		break;
740 	default:	/* PWM in automatic mode */
741 		enable = 2;
742 	}
743 	return sprintf(buf, "%d\n", enable);
744 }
745 
746 static ssize_t pwm_enable_store(struct device *dev,
747 				struct device_attribute *attr,
748 				const char *buf, size_t count)
749 {
750 	int nr = to_sensor_dev_attr(attr)->index;
751 	struct lm85_data *data = dev_get_drvdata(dev);
752 	struct i2c_client *client = data->client;
753 	u8 config;
754 	unsigned long val;
755 	int err;
756 
757 	err = kstrtoul(buf, 10, &val);
758 	if (err)
759 		return err;
760 
761 	switch (val) {
762 	case 0:
763 		config = 3;
764 		break;
765 	case 1:
766 		config = 7;
767 		break;
768 	case 2:
769 		/*
770 		 * Here we have to choose arbitrarily one of the 5 possible
771 		 * configurations; I go for the safest
772 		 */
773 		config = 6;
774 		break;
775 	default:
776 		return -EINVAL;
777 	}
778 
779 	mutex_lock(&data->update_lock);
780 	data->autofan[nr].config = lm85_read_value(client,
781 		LM85_REG_AFAN_CONFIG(nr));
782 	data->autofan[nr].config = (data->autofan[nr].config & ~0xe0)
783 		| (config << 5);
784 	lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
785 		data->autofan[nr].config);
786 	mutex_unlock(&data->update_lock);
787 	return count;
788 }
789 
790 static ssize_t pwm_freq_show(struct device *dev,
791 			     struct device_attribute *attr, char *buf)
792 {
793 	int nr = to_sensor_dev_attr(attr)->index;
794 	struct lm85_data *data = lm85_update_device(dev);
795 	int freq;
796 
797 	if (IS_ADT7468_HFPWM(data))
798 		freq = 22500;
799 	else
800 		freq = FREQ_FROM_REG(data->freq_map, data->freq_map_size,
801 				     data->pwm_freq[nr]);
802 
803 	return sprintf(buf, "%d\n", freq);
804 }
805 
806 static ssize_t pwm_freq_store(struct device *dev,
807 			      struct device_attribute *attr, const char *buf,
808 			      size_t count)
809 {
810 	int nr = to_sensor_dev_attr(attr)->index;
811 	struct lm85_data *data = dev_get_drvdata(dev);
812 	struct i2c_client *client = data->client;
813 	unsigned long val;
814 	int err;
815 
816 	err = kstrtoul(buf, 10, &val);
817 	if (err)
818 		return err;
819 
820 	mutex_lock(&data->update_lock);
821 	/*
822 	 * The ADT7468 has a special high-frequency PWM output mode,
823 	 * where all PWM outputs are driven by a 22.5 kHz clock.
824 	 * This might confuse the user, but there's not much we can do.
825 	 */
826 	if (data->type == adt7468 && val >= 11300) {	/* High freq. mode */
827 		data->cfg5 &= ~ADT7468_HFPWM;
828 		lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
829 	} else {					/* Low freq. mode */
830 		data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map,
831 						 data->freq_map_size, val);
832 		lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
833 				 (data->zone[nr].range << 4)
834 				 | data->pwm_freq[nr]);
835 		if (data->type == adt7468) {
836 			data->cfg5 |= ADT7468_HFPWM;
837 			lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
838 		}
839 	}
840 	mutex_unlock(&data->update_lock);
841 	return count;
842 }
843 
844 static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0);
845 static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_enable, 0);
846 static SENSOR_DEVICE_ATTR_RW(pwm1_freq, pwm_freq, 0);
847 static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1);
848 static SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_enable, 1);
849 static SENSOR_DEVICE_ATTR_RW(pwm2_freq, pwm_freq, 1);
850 static SENSOR_DEVICE_ATTR_RW(pwm3, pwm, 2);
851 static SENSOR_DEVICE_ATTR_RW(pwm3_enable, pwm_enable, 2);
852 static SENSOR_DEVICE_ATTR_RW(pwm3_freq, pwm_freq, 2);
853 
854 /* Voltages */
855 
856 static ssize_t in_show(struct device *dev, struct device_attribute *attr,
857 		       char *buf)
858 {
859 	int nr = to_sensor_dev_attr(attr)->index;
860 	struct lm85_data *data = lm85_update_device(dev);
861 	return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr],
862 						    data->in_ext[nr]));
863 }
864 
865 static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
866 			   char *buf)
867 {
868 	int nr = to_sensor_dev_attr(attr)->index;
869 	struct lm85_data *data = lm85_update_device(dev);
870 	return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
871 }
872 
873 static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
874 			    const char *buf, size_t count)
875 {
876 	int nr = to_sensor_dev_attr(attr)->index;
877 	struct lm85_data *data = dev_get_drvdata(dev);
878 	struct i2c_client *client = data->client;
879 	long val;
880 	int err;
881 
882 	err = kstrtol(buf, 10, &val);
883 	if (err)
884 		return err;
885 
886 	mutex_lock(&data->update_lock);
887 	data->in_min[nr] = INS_TO_REG(nr, val);
888 	lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
889 	mutex_unlock(&data->update_lock);
890 	return count;
891 }
892 
893 static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
894 			   char *buf)
895 {
896 	int nr = to_sensor_dev_attr(attr)->index;
897 	struct lm85_data *data = lm85_update_device(dev);
898 	return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
899 }
900 
901 static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
902 			    const char *buf, size_t count)
903 {
904 	int nr = to_sensor_dev_attr(attr)->index;
905 	struct lm85_data *data = dev_get_drvdata(dev);
906 	struct i2c_client *client = data->client;
907 	long val;
908 	int err;
909 
910 	err = kstrtol(buf, 10, &val);
911 	if (err)
912 		return err;
913 
914 	mutex_lock(&data->update_lock);
915 	data->in_max[nr] = INS_TO_REG(nr, val);
916 	lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
917 	mutex_unlock(&data->update_lock);
918 	return count;
919 }
920 
921 static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
922 static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
923 static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
924 static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
925 static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
926 static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
927 static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
928 static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
929 static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
930 static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
931 static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
932 static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
933 static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
934 static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
935 static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
936 static SENSOR_DEVICE_ATTR_RO(in5_input, in, 5);
937 static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5);
938 static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5);
939 static SENSOR_DEVICE_ATTR_RO(in6_input, in, 6);
940 static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6);
941 static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6);
942 static SENSOR_DEVICE_ATTR_RO(in7_input, in, 7);
943 static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7);
944 static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7);
945 
946 /* Temps */
947 
948 static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
949 			 char *buf)
950 {
951 	int nr = to_sensor_dev_attr(attr)->index;
952 	struct lm85_data *data = lm85_update_device(dev);
953 	return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr],
954 						     data->temp_ext[nr]));
955 }
956 
957 static ssize_t temp_min_show(struct device *dev,
958 			     struct device_attribute *attr, char *buf)
959 {
960 	int nr = to_sensor_dev_attr(attr)->index;
961 	struct lm85_data *data = lm85_update_device(dev);
962 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
963 }
964 
965 static ssize_t temp_min_store(struct device *dev,
966 			      struct device_attribute *attr, const char *buf,
967 			      size_t count)
968 {
969 	int nr = to_sensor_dev_attr(attr)->index;
970 	struct lm85_data *data = dev_get_drvdata(dev);
971 	struct i2c_client *client = data->client;
972 	long val;
973 	int err;
974 
975 	err = kstrtol(buf, 10, &val);
976 	if (err)
977 		return err;
978 
979 	if (IS_ADT7468_OFF64(data))
980 		val += 64;
981 
982 	mutex_lock(&data->update_lock);
983 	data->temp_min[nr] = TEMP_TO_REG(val);
984 	lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
985 	mutex_unlock(&data->update_lock);
986 	return count;
987 }
988 
989 static ssize_t temp_max_show(struct device *dev,
990 			     struct device_attribute *attr, char *buf)
991 {
992 	int nr = to_sensor_dev_attr(attr)->index;
993 	struct lm85_data *data = lm85_update_device(dev);
994 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
995 }
996 
997 static ssize_t temp_max_store(struct device *dev,
998 			      struct device_attribute *attr, const char *buf,
999 			      size_t count)
1000 {
1001 	int nr = to_sensor_dev_attr(attr)->index;
1002 	struct lm85_data *data = dev_get_drvdata(dev);
1003 	struct i2c_client *client = data->client;
1004 	long val;
1005 	int err;
1006 
1007 	err = kstrtol(buf, 10, &val);
1008 	if (err)
1009 		return err;
1010 
1011 	if (IS_ADT7468_OFF64(data))
1012 		val += 64;
1013 
1014 	mutex_lock(&data->update_lock);
1015 	data->temp_max[nr] = TEMP_TO_REG(val);
1016 	lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
1017 	mutex_unlock(&data->update_lock);
1018 	return count;
1019 }
1020 
1021 static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
1022 static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
1023 static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
1024 static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
1025 static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
1026 static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
1027 static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
1028 static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
1029 static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
1030 
1031 /* Automatic PWM control */
1032 
1033 static ssize_t pwm_auto_channels_show(struct device *dev,
1034 				      struct device_attribute *attr,
1035 				      char *buf)
1036 {
1037 	int nr = to_sensor_dev_attr(attr)->index;
1038 	struct lm85_data *data = lm85_update_device(dev);
1039 	return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config));
1040 }
1041 
1042 static ssize_t pwm_auto_channels_store(struct device *dev,
1043 				       struct device_attribute *attr,
1044 				       const char *buf, size_t count)
1045 {
1046 	int nr = to_sensor_dev_attr(attr)->index;
1047 	struct lm85_data *data = dev_get_drvdata(dev);
1048 	struct i2c_client *client = data->client;
1049 	long val;
1050 	int err;
1051 
1052 	err = kstrtol(buf, 10, &val);
1053 	if (err)
1054 		return err;
1055 
1056 	mutex_lock(&data->update_lock);
1057 	data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
1058 		| ZONE_TO_REG(val);
1059 	lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
1060 		data->autofan[nr].config);
1061 	mutex_unlock(&data->update_lock);
1062 	return count;
1063 }
1064 
1065 static ssize_t pwm_auto_pwm_min_show(struct device *dev,
1066 				     struct device_attribute *attr, char *buf)
1067 {
1068 	int nr = to_sensor_dev_attr(attr)->index;
1069 	struct lm85_data *data = lm85_update_device(dev);
1070 	return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
1071 }
1072 
1073 static ssize_t pwm_auto_pwm_min_store(struct device *dev,
1074 				      struct device_attribute *attr,
1075 				      const char *buf, size_t count)
1076 {
1077 	int nr = to_sensor_dev_attr(attr)->index;
1078 	struct lm85_data *data = dev_get_drvdata(dev);
1079 	struct i2c_client *client = data->client;
1080 	unsigned long val;
1081 	int err;
1082 
1083 	err = kstrtoul(buf, 10, &val);
1084 	if (err)
1085 		return err;
1086 
1087 	mutex_lock(&data->update_lock);
1088 	data->autofan[nr].min_pwm = PWM_TO_REG(val);
1089 	lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
1090 		data->autofan[nr].min_pwm);
1091 	mutex_unlock(&data->update_lock);
1092 	return count;
1093 }
1094 
1095 static ssize_t pwm_auto_pwm_minctl_show(struct device *dev,
1096 					struct device_attribute *attr,
1097 					char *buf)
1098 {
1099 	int nr = to_sensor_dev_attr(attr)->index;
1100 	struct lm85_data *data = lm85_update_device(dev);
1101 	return sprintf(buf, "%d\n", data->autofan[nr].min_off);
1102 }
1103 
1104 static ssize_t pwm_auto_pwm_minctl_store(struct device *dev,
1105 					 struct device_attribute *attr,
1106 					 const char *buf, size_t count)
1107 {
1108 	int nr = to_sensor_dev_attr(attr)->index;
1109 	struct lm85_data *data = dev_get_drvdata(dev);
1110 	struct i2c_client *client = data->client;
1111 	u8 tmp;
1112 	long val;
1113 	int err;
1114 
1115 	err = kstrtol(buf, 10, &val);
1116 	if (err)
1117 		return err;
1118 
1119 	mutex_lock(&data->update_lock);
1120 	data->autofan[nr].min_off = val;
1121 	tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
1122 	tmp &= ~(0x20 << nr);
1123 	if (data->autofan[nr].min_off)
1124 		tmp |= 0x20 << nr;
1125 	lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp);
1126 	mutex_unlock(&data->update_lock);
1127 	return count;
1128 }
1129 
1130 static SENSOR_DEVICE_ATTR_RW(pwm1_auto_channels, pwm_auto_channels, 0);
1131 static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_min, pwm_auto_pwm_min, 0);
1132 static SENSOR_DEVICE_ATTR_RW(pwm1_auto_pwm_minctl, pwm_auto_pwm_minctl, 0);
1133 static SENSOR_DEVICE_ATTR_RW(pwm2_auto_channels, pwm_auto_channels, 1);
1134 static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_min, pwm_auto_pwm_min, 1);
1135 static SENSOR_DEVICE_ATTR_RW(pwm2_auto_pwm_minctl, pwm_auto_pwm_minctl, 1);
1136 static SENSOR_DEVICE_ATTR_RW(pwm3_auto_channels, pwm_auto_channels, 2);
1137 static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_min, pwm_auto_pwm_min, 2);
1138 static SENSOR_DEVICE_ATTR_RW(pwm3_auto_pwm_minctl, pwm_auto_pwm_minctl, 2);
1139 
1140 /* Temperature settings for automatic PWM control */
1141 
1142 static ssize_t temp_auto_temp_off_show(struct device *dev,
1143 				       struct device_attribute *attr,
1144 				       char *buf)
1145 {
1146 	int nr = to_sensor_dev_attr(attr)->index;
1147 	struct lm85_data *data = lm85_update_device(dev);
1148 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
1149 		HYST_FROM_REG(data->zone[nr].hyst));
1150 }
1151 
1152 static ssize_t temp_auto_temp_off_store(struct device *dev,
1153 					struct device_attribute *attr,
1154 					const char *buf, size_t count)
1155 {
1156 	int nr = to_sensor_dev_attr(attr)->index;
1157 	struct lm85_data *data = dev_get_drvdata(dev);
1158 	struct i2c_client *client = data->client;
1159 	int min;
1160 	long val;
1161 	int err;
1162 
1163 	err = kstrtol(buf, 10, &val);
1164 	if (err)
1165 		return err;
1166 
1167 	mutex_lock(&data->update_lock);
1168 	min = TEMP_FROM_REG(data->zone[nr].limit);
1169 	data->zone[nr].hyst = HYST_TO_REG(min - val);
1170 	if (nr == 0 || nr == 1) {
1171 		lm85_write_value(client, LM85_REG_AFAN_HYST1,
1172 			(data->zone[0].hyst << 4)
1173 			| data->zone[1].hyst);
1174 	} else {
1175 		lm85_write_value(client, LM85_REG_AFAN_HYST2,
1176 			(data->zone[2].hyst << 4));
1177 	}
1178 	mutex_unlock(&data->update_lock);
1179 	return count;
1180 }
1181 
1182 static ssize_t temp_auto_temp_min_show(struct device *dev,
1183 				       struct device_attribute *attr,
1184 				       char *buf)
1185 {
1186 	int nr = to_sensor_dev_attr(attr)->index;
1187 	struct lm85_data *data = lm85_update_device(dev);
1188 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit));
1189 }
1190 
1191 static ssize_t temp_auto_temp_min_store(struct device *dev,
1192 					struct device_attribute *attr,
1193 					const char *buf, size_t count)
1194 {
1195 	int nr = to_sensor_dev_attr(attr)->index;
1196 	struct lm85_data *data = dev_get_drvdata(dev);
1197 	struct i2c_client *client = data->client;
1198 	long val;
1199 	int err;
1200 
1201 	err = kstrtol(buf, 10, &val);
1202 	if (err)
1203 		return err;
1204 
1205 	mutex_lock(&data->update_lock);
1206 	data->zone[nr].limit = TEMP_TO_REG(val);
1207 	lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
1208 		data->zone[nr].limit);
1209 
1210 /* Update temp_auto_max and temp_auto_range */
1211 	data->zone[nr].range = RANGE_TO_REG(
1212 		TEMP_FROM_REG(data->zone[nr].max_desired) -
1213 		TEMP_FROM_REG(data->zone[nr].limit));
1214 	lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
1215 		((data->zone[nr].range & 0x0f) << 4)
1216 		| data->pwm_freq[nr]);
1217 
1218 	mutex_unlock(&data->update_lock);
1219 	return count;
1220 }
1221 
1222 static ssize_t temp_auto_temp_max_show(struct device *dev,
1223 				       struct device_attribute *attr,
1224 				       char *buf)
1225 {
1226 	int nr = to_sensor_dev_attr(attr)->index;
1227 	struct lm85_data *data = lm85_update_device(dev);
1228 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
1229 		RANGE_FROM_REG(data->zone[nr].range));
1230 }
1231 
1232 static ssize_t temp_auto_temp_max_store(struct device *dev,
1233 					struct device_attribute *attr,
1234 					const char *buf, size_t count)
1235 {
1236 	int nr = to_sensor_dev_attr(attr)->index;
1237 	struct lm85_data *data = dev_get_drvdata(dev);
1238 	struct i2c_client *client = data->client;
1239 	int min;
1240 	long val;
1241 	int err;
1242 
1243 	err = kstrtol(buf, 10, &val);
1244 	if (err)
1245 		return err;
1246 
1247 	mutex_lock(&data->update_lock);
1248 	min = TEMP_FROM_REG(data->zone[nr].limit);
1249 	data->zone[nr].max_desired = TEMP_TO_REG(val);
1250 	data->zone[nr].range = RANGE_TO_REG(
1251 		val - min);
1252 	lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
1253 		((data->zone[nr].range & 0x0f) << 4)
1254 		| data->pwm_freq[nr]);
1255 	mutex_unlock(&data->update_lock);
1256 	return count;
1257 }
1258 
1259 static ssize_t temp_auto_temp_crit_show(struct device *dev,
1260 					struct device_attribute *attr,
1261 					char *buf)
1262 {
1263 	int nr = to_sensor_dev_attr(attr)->index;
1264 	struct lm85_data *data = lm85_update_device(dev);
1265 	return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical));
1266 }
1267 
1268 static ssize_t temp_auto_temp_crit_store(struct device *dev,
1269 					 struct device_attribute *attr,
1270 					 const char *buf, size_t count)
1271 {
1272 	int nr = to_sensor_dev_attr(attr)->index;
1273 	struct lm85_data *data = dev_get_drvdata(dev);
1274 	struct i2c_client *client = data->client;
1275 	long val;
1276 	int err;
1277 
1278 	err = kstrtol(buf, 10, &val);
1279 	if (err)
1280 		return err;
1281 
1282 	mutex_lock(&data->update_lock);
1283 	data->zone[nr].critical = TEMP_TO_REG(val);
1284 	lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
1285 		data->zone[nr].critical);
1286 	mutex_unlock(&data->update_lock);
1287 	return count;
1288 }
1289 
1290 static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_off, temp_auto_temp_off, 0);
1291 static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_min, temp_auto_temp_min, 0);
1292 static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_max, temp_auto_temp_max, 0);
1293 static SENSOR_DEVICE_ATTR_RW(temp1_auto_temp_crit, temp_auto_temp_crit, 0);
1294 static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_off, temp_auto_temp_off, 1);
1295 static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_min, temp_auto_temp_min, 1);
1296 static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_max, temp_auto_temp_max, 1);
1297 static SENSOR_DEVICE_ATTR_RW(temp2_auto_temp_crit, temp_auto_temp_crit, 1);
1298 static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_off, temp_auto_temp_off, 2);
1299 static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_min, temp_auto_temp_min, 2);
1300 static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_max, temp_auto_temp_max, 2);
1301 static SENSOR_DEVICE_ATTR_RW(temp3_auto_temp_crit, temp_auto_temp_crit, 2);
1302 
1303 static struct attribute *lm85_attributes[] = {
1304 	&sensor_dev_attr_fan1_input.dev_attr.attr,
1305 	&sensor_dev_attr_fan2_input.dev_attr.attr,
1306 	&sensor_dev_attr_fan3_input.dev_attr.attr,
1307 	&sensor_dev_attr_fan4_input.dev_attr.attr,
1308 	&sensor_dev_attr_fan1_min.dev_attr.attr,
1309 	&sensor_dev_attr_fan2_min.dev_attr.attr,
1310 	&sensor_dev_attr_fan3_min.dev_attr.attr,
1311 	&sensor_dev_attr_fan4_min.dev_attr.attr,
1312 	&sensor_dev_attr_fan1_alarm.dev_attr.attr,
1313 	&sensor_dev_attr_fan2_alarm.dev_attr.attr,
1314 	&sensor_dev_attr_fan3_alarm.dev_attr.attr,
1315 	&sensor_dev_attr_fan4_alarm.dev_attr.attr,
1316 
1317 	&sensor_dev_attr_pwm1.dev_attr.attr,
1318 	&sensor_dev_attr_pwm2.dev_attr.attr,
1319 	&sensor_dev_attr_pwm3.dev_attr.attr,
1320 	&sensor_dev_attr_pwm1_enable.dev_attr.attr,
1321 	&sensor_dev_attr_pwm2_enable.dev_attr.attr,
1322 	&sensor_dev_attr_pwm3_enable.dev_attr.attr,
1323 	&sensor_dev_attr_pwm1_freq.dev_attr.attr,
1324 	&sensor_dev_attr_pwm2_freq.dev_attr.attr,
1325 	&sensor_dev_attr_pwm3_freq.dev_attr.attr,
1326 
1327 	&sensor_dev_attr_in0_input.dev_attr.attr,
1328 	&sensor_dev_attr_in1_input.dev_attr.attr,
1329 	&sensor_dev_attr_in2_input.dev_attr.attr,
1330 	&sensor_dev_attr_in3_input.dev_attr.attr,
1331 	&sensor_dev_attr_in0_min.dev_attr.attr,
1332 	&sensor_dev_attr_in1_min.dev_attr.attr,
1333 	&sensor_dev_attr_in2_min.dev_attr.attr,
1334 	&sensor_dev_attr_in3_min.dev_attr.attr,
1335 	&sensor_dev_attr_in0_max.dev_attr.attr,
1336 	&sensor_dev_attr_in1_max.dev_attr.attr,
1337 	&sensor_dev_attr_in2_max.dev_attr.attr,
1338 	&sensor_dev_attr_in3_max.dev_attr.attr,
1339 	&sensor_dev_attr_in0_alarm.dev_attr.attr,
1340 	&sensor_dev_attr_in1_alarm.dev_attr.attr,
1341 	&sensor_dev_attr_in2_alarm.dev_attr.attr,
1342 	&sensor_dev_attr_in3_alarm.dev_attr.attr,
1343 
1344 	&sensor_dev_attr_temp1_input.dev_attr.attr,
1345 	&sensor_dev_attr_temp2_input.dev_attr.attr,
1346 	&sensor_dev_attr_temp3_input.dev_attr.attr,
1347 	&sensor_dev_attr_temp1_min.dev_attr.attr,
1348 	&sensor_dev_attr_temp2_min.dev_attr.attr,
1349 	&sensor_dev_attr_temp3_min.dev_attr.attr,
1350 	&sensor_dev_attr_temp1_max.dev_attr.attr,
1351 	&sensor_dev_attr_temp2_max.dev_attr.attr,
1352 	&sensor_dev_attr_temp3_max.dev_attr.attr,
1353 	&sensor_dev_attr_temp1_alarm.dev_attr.attr,
1354 	&sensor_dev_attr_temp2_alarm.dev_attr.attr,
1355 	&sensor_dev_attr_temp3_alarm.dev_attr.attr,
1356 	&sensor_dev_attr_temp1_fault.dev_attr.attr,
1357 	&sensor_dev_attr_temp3_fault.dev_attr.attr,
1358 
1359 	&sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
1360 	&sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
1361 	&sensor_dev_attr_pwm3_auto_channels.dev_attr.attr,
1362 	&sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
1363 	&sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
1364 	&sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
1365 
1366 	&sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr,
1367 	&sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr,
1368 	&sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr,
1369 	&sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr,
1370 	&sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr,
1371 	&sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr,
1372 	&sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr,
1373 	&sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr,
1374 	&sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr,
1375 
1376 	&dev_attr_vrm.attr,
1377 	&dev_attr_cpu0_vid.attr,
1378 	&dev_attr_alarms.attr,
1379 	NULL
1380 };
1381 
1382 static const struct attribute_group lm85_group = {
1383 	.attrs = lm85_attributes,
1384 };
1385 
1386 static struct attribute *lm85_attributes_minctl[] = {
1387 	&sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr,
1388 	&sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr,
1389 	&sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr,
1390 	NULL
1391 };
1392 
1393 static const struct attribute_group lm85_group_minctl = {
1394 	.attrs = lm85_attributes_minctl,
1395 };
1396 
1397 static struct attribute *lm85_attributes_temp_off[] = {
1398 	&sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
1399 	&sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
1400 	&sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr,
1401 	NULL
1402 };
1403 
1404 static const struct attribute_group lm85_group_temp_off = {
1405 	.attrs = lm85_attributes_temp_off,
1406 };
1407 
1408 static struct attribute *lm85_attributes_in4[] = {
1409 	&sensor_dev_attr_in4_input.dev_attr.attr,
1410 	&sensor_dev_attr_in4_min.dev_attr.attr,
1411 	&sensor_dev_attr_in4_max.dev_attr.attr,
1412 	&sensor_dev_attr_in4_alarm.dev_attr.attr,
1413 	NULL
1414 };
1415 
1416 static const struct attribute_group lm85_group_in4 = {
1417 	.attrs = lm85_attributes_in4,
1418 };
1419 
1420 static struct attribute *lm85_attributes_in567[] = {
1421 	&sensor_dev_attr_in5_input.dev_attr.attr,
1422 	&sensor_dev_attr_in6_input.dev_attr.attr,
1423 	&sensor_dev_attr_in7_input.dev_attr.attr,
1424 	&sensor_dev_attr_in5_min.dev_attr.attr,
1425 	&sensor_dev_attr_in6_min.dev_attr.attr,
1426 	&sensor_dev_attr_in7_min.dev_attr.attr,
1427 	&sensor_dev_attr_in5_max.dev_attr.attr,
1428 	&sensor_dev_attr_in6_max.dev_attr.attr,
1429 	&sensor_dev_attr_in7_max.dev_attr.attr,
1430 	&sensor_dev_attr_in5_alarm.dev_attr.attr,
1431 	&sensor_dev_attr_in6_alarm.dev_attr.attr,
1432 	&sensor_dev_attr_in7_alarm.dev_attr.attr,
1433 	NULL
1434 };
1435 
1436 static const struct attribute_group lm85_group_in567 = {
1437 	.attrs = lm85_attributes_in567,
1438 };
1439 
1440 static void lm85_init_client(struct i2c_client *client)
1441 {
1442 	int value;
1443 
1444 	/* Start monitoring if needed */
1445 	value = lm85_read_value(client, LM85_REG_CONFIG);
1446 	if (!(value & 0x01)) {
1447 		dev_info(&client->dev, "Starting monitoring\n");
1448 		lm85_write_value(client, LM85_REG_CONFIG, value | 0x01);
1449 	}
1450 
1451 	/* Warn about unusual configuration bits */
1452 	if (value & 0x02)
1453 		dev_warn(&client->dev, "Device configuration is locked\n");
1454 	if (!(value & 0x04))
1455 		dev_warn(&client->dev, "Device is not ready\n");
1456 }
1457 
1458 static int lm85_is_fake(struct i2c_client *client)
1459 {
1460 	/*
1461 	 * Differenciate between real LM96000 and Winbond WPCD377I. The latter
1462 	 * emulate the former except that it has no hardware monitoring function
1463 	 * so the readings are always 0.
1464 	 */
1465 	int i;
1466 	u8 in_temp, fan;
1467 
1468 	for (i = 0; i < 8; i++) {
1469 		in_temp = i2c_smbus_read_byte_data(client, 0x20 + i);
1470 		fan = i2c_smbus_read_byte_data(client, 0x28 + i);
1471 		if (in_temp != 0x00 || fan != 0xff)
1472 			return 0;
1473 	}
1474 
1475 	return 1;
1476 }
1477 
1478 /* Return 0 if detection is successful, -ENODEV otherwise */
1479 static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
1480 {
1481 	struct i2c_adapter *adapter = client->adapter;
1482 	int address = client->addr;
1483 	const char *type_name = NULL;
1484 	int company, verstep;
1485 
1486 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1487 		/* We need to be able to do byte I/O */
1488 		return -ENODEV;
1489 	}
1490 
1491 	/* Determine the chip type */
1492 	company = lm85_read_value(client, LM85_REG_COMPANY);
1493 	verstep = lm85_read_value(client, LM85_REG_VERSTEP);
1494 
1495 	dev_dbg(&adapter->dev,
1496 		"Detecting device at 0x%02x with COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1497 		address, company, verstep);
1498 
1499 	if (company == LM85_COMPANY_NATIONAL) {
1500 		switch (verstep) {
1501 		case LM85_VERSTEP_LM85C:
1502 			type_name = "lm85c";
1503 			break;
1504 		case LM85_VERSTEP_LM85B:
1505 			type_name = "lm85b";
1506 			break;
1507 		case LM85_VERSTEP_LM96000_1:
1508 		case LM85_VERSTEP_LM96000_2:
1509 			/* Check for Winbond WPCD377I */
1510 			if (lm85_is_fake(client)) {
1511 				dev_dbg(&adapter->dev,
1512 					"Found Winbond WPCD377I, ignoring\n");
1513 				return -ENODEV;
1514 			}
1515 			type_name = "lm96000";
1516 			break;
1517 		}
1518 	} else if (company == LM85_COMPANY_ANALOG_DEV) {
1519 		switch (verstep) {
1520 		case LM85_VERSTEP_ADM1027:
1521 			type_name = "adm1027";
1522 			break;
1523 		case LM85_VERSTEP_ADT7463:
1524 		case LM85_VERSTEP_ADT7463C:
1525 			type_name = "adt7463";
1526 			break;
1527 		case LM85_VERSTEP_ADT7468_1:
1528 		case LM85_VERSTEP_ADT7468_2:
1529 			type_name = "adt7468";
1530 			break;
1531 		}
1532 	} else if (company == LM85_COMPANY_SMSC) {
1533 		switch (verstep) {
1534 		case LM85_VERSTEP_EMC6D100_A0:
1535 		case LM85_VERSTEP_EMC6D100_A1:
1536 			/* Note: we can't tell a '100 from a '101 */
1537 			type_name = "emc6d100";
1538 			break;
1539 		case LM85_VERSTEP_EMC6D102:
1540 			type_name = "emc6d102";
1541 			break;
1542 		case LM85_VERSTEP_EMC6D103_A0:
1543 		case LM85_VERSTEP_EMC6D103_A1:
1544 			type_name = "emc6d103";
1545 			break;
1546 		case LM85_VERSTEP_EMC6D103S:
1547 			type_name = "emc6d103s";
1548 			break;
1549 		}
1550 	}
1551 
1552 	if (!type_name)
1553 		return -ENODEV;
1554 
1555 	strlcpy(info->type, type_name, I2C_NAME_SIZE);
1556 
1557 	return 0;
1558 }
1559 
1560 static int lm85_probe(struct i2c_client *client, const struct i2c_device_id *id)
1561 {
1562 	struct device *dev = &client->dev;
1563 	struct device *hwmon_dev;
1564 	struct lm85_data *data;
1565 	int idx = 0;
1566 
1567 	data = devm_kzalloc(dev, sizeof(struct lm85_data), GFP_KERNEL);
1568 	if (!data)
1569 		return -ENOMEM;
1570 
1571 	data->client = client;
1572 	if (client->dev.of_node)
1573 		data->type = (enum chips)of_device_get_match_data(&client->dev);
1574 	else
1575 		data->type = id->driver_data;
1576 	mutex_init(&data->update_lock);
1577 
1578 	/* Fill in the chip specific driver values */
1579 	switch (data->type) {
1580 	case adm1027:
1581 	case adt7463:
1582 	case adt7468:
1583 	case emc6d100:
1584 	case emc6d102:
1585 	case emc6d103:
1586 	case emc6d103s:
1587 		data->freq_map = adm1027_freq_map;
1588 		data->freq_map_size = ARRAY_SIZE(adm1027_freq_map);
1589 		break;
1590 	case lm96000:
1591 		data->freq_map = lm96000_freq_map;
1592 		data->freq_map_size = ARRAY_SIZE(lm96000_freq_map);
1593 		break;
1594 	default:
1595 		data->freq_map = lm85_freq_map;
1596 		data->freq_map_size = ARRAY_SIZE(lm85_freq_map);
1597 	}
1598 
1599 	/* Set the VRM version */
1600 	data->vrm = vid_which_vrm();
1601 
1602 	/* Initialize the LM85 chip */
1603 	lm85_init_client(client);
1604 
1605 	/* sysfs hooks */
1606 	data->groups[idx++] = &lm85_group;
1607 
1608 	/* minctl and temp_off exist on all chips except emc6d103s */
1609 	if (data->type != emc6d103s) {
1610 		data->groups[idx++] = &lm85_group_minctl;
1611 		data->groups[idx++] = &lm85_group_temp_off;
1612 	}
1613 
1614 	/*
1615 	 * The ADT7463/68 have an optional VRM 10 mode where pin 21 is used
1616 	 * as a sixth digital VID input rather than an analog input.
1617 	 */
1618 	if (data->type == adt7463 || data->type == adt7468) {
1619 		u8 vid = lm85_read_value(client, LM85_REG_VID);
1620 		if (vid & 0x80)
1621 			data->has_vid5 = true;
1622 	}
1623 
1624 	if (!data->has_vid5)
1625 		data->groups[idx++] = &lm85_group_in4;
1626 
1627 	/* The EMC6D100 has 3 additional voltage inputs */
1628 	if (data->type == emc6d100)
1629 		data->groups[idx++] = &lm85_group_in567;
1630 
1631 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
1632 							   data, data->groups);
1633 	return PTR_ERR_OR_ZERO(hwmon_dev);
1634 }
1635 
1636 static const struct i2c_device_id lm85_id[] = {
1637 	{ "adm1027", adm1027 },
1638 	{ "adt7463", adt7463 },
1639 	{ "adt7468", adt7468 },
1640 	{ "lm85", lm85 },
1641 	{ "lm85b", lm85 },
1642 	{ "lm85c", lm85 },
1643 	{ "lm96000", lm96000 },
1644 	{ "emc6d100", emc6d100 },
1645 	{ "emc6d101", emc6d100 },
1646 	{ "emc6d102", emc6d102 },
1647 	{ "emc6d103", emc6d103 },
1648 	{ "emc6d103s", emc6d103s },
1649 	{ }
1650 };
1651 MODULE_DEVICE_TABLE(i2c, lm85_id);
1652 
1653 static const struct of_device_id __maybe_unused lm85_of_match[] = {
1654 	{
1655 		.compatible = "adi,adm1027",
1656 		.data = (void *)adm1027
1657 	},
1658 	{
1659 		.compatible = "adi,adt7463",
1660 		.data = (void *)adt7463
1661 	},
1662 	{
1663 		.compatible = "adi,adt7468",
1664 		.data = (void *)adt7468
1665 	},
1666 	{
1667 		.compatible = "national,lm85",
1668 		.data = (void *)lm85
1669 	},
1670 	{
1671 		.compatible = "national,lm85b",
1672 		.data = (void *)lm85
1673 	},
1674 	{
1675 		.compatible = "national,lm85c",
1676 		.data = (void *)lm85
1677 	},
1678 	{
1679 		.compatible = "ti,lm96000",
1680 		.data = (void *)lm96000
1681 	},
1682 	{
1683 		.compatible = "smsc,emc6d100",
1684 		.data = (void *)emc6d100
1685 	},
1686 	{
1687 		.compatible = "smsc,emc6d101",
1688 		.data = (void *)emc6d100
1689 	},
1690 	{
1691 		.compatible = "smsc,emc6d102",
1692 		.data = (void *)emc6d102
1693 	},
1694 	{
1695 		.compatible = "smsc,emc6d103",
1696 		.data = (void *)emc6d103
1697 	},
1698 	{
1699 		.compatible = "smsc,emc6d103s",
1700 		.data = (void *)emc6d103s
1701 	},
1702 	{ },
1703 };
1704 MODULE_DEVICE_TABLE(of, lm85_of_match);
1705 
1706 static struct i2c_driver lm85_driver = {
1707 	.class		= I2C_CLASS_HWMON,
1708 	.driver = {
1709 		.name   = "lm85",
1710 		.of_match_table = of_match_ptr(lm85_of_match),
1711 	},
1712 	.probe		= lm85_probe,
1713 	.id_table	= lm85_id,
1714 	.detect		= lm85_detect,
1715 	.address_list	= normal_i2c,
1716 };
1717 
1718 module_i2c_driver(lm85_driver);
1719 
1720 MODULE_LICENSE("GPL");
1721 MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1722 	"Margit Schubert-While <margitsw@t-online.de>, "
1723 	"Justin Thiessen <jthiessen@penguincomputing.com>");
1724 MODULE_DESCRIPTION("LM85-B, LM85-C driver");
1725