2 * w83795.c - Linux kernel driver for hardware monitoring
3 * Copyright (C) 2008 Nuvoton Technology Corp.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation - version 2.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * Supports following chips:
22 * Chip #vin #fanin #pwm #temp #dts wchipid vendid i2c ISA
23 * w83795g 21 14 8 6 8 0x79 0x5ca3 yes no
24 * w83795adg 18 14 2 6 8 0x79 0x5ca3 yes no
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <linux/i2c.h>
32 #include <linux/hwmon.h>
33 #include <linux/hwmon-sysfs.h>
34 #include <linux/err.h>
35 #include <linux/mutex.h>
36 #include <linux/delay.h>
38 /* Addresses to scan */
39 static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
43 module_param(reset, bool, 0);
44 MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
47 #define W83795_REG_BANKSEL 0x00
48 #define W83795_REG_VENDORID 0xfd
49 #define W83795_REG_CHIPID 0xfe
50 #define W83795_REG_DEVICEID 0xfb
52 #define W83795_REG_I2C_ADDR 0xfc
53 #define W83795_REG_CONFIG 0x01
54 #define W83795_REG_CONFIG_CONFIG48 0x04
56 /* Multi-Function Pin Ctrl Registers */
57 #define W83795_REG_VOLT_CTRL1 0x02
58 #define W83795_REG_VOLT_CTRL2 0x03
59 #define W83795_REG_TEMP_CTRL1 0x04
60 #define W83795_REG_TEMP_CTRL2 0x05
61 #define W83795_REG_FANIN_CTRL1 0x06
62 #define W83795_REG_FANIN_CTRL2 0x07
63 #define W83795_REG_VMIGB_CTRL 0x08
65 #define TEMP_CTRL_DISABLE 0
66 #define TEMP_CTRL_TD 1
67 #define TEMP_CTRL_VSEN 2
68 #define TEMP_CTRL_TR 3
69 #define TEMP_CTRL_SHIFT 4
70 #define TEMP_CTRL_HASIN_SHIFT 5
71 /* temp mode may effect VSEN17-12 (in20-15) */
72 static u16 W83795_REG_TEMP_CTRL[][6] = {
73 /* Disable, TD, VSEN, TR, register shift value, has_in shift num */
74 {0x00, 0x01, 0x02, 0x03, 0, 17}, /* TR1 */
75 {0x00, 0x04, 0x08, 0x0C, 2, 18}, /* TR2 */
76 {0x00, 0x10, 0x20, 0x30, 4, 19}, /* TR3 */
77 {0x00, 0x40, 0x80, 0xC0, 6, 20}, /* TR4 */
78 {0x00, 0x00, 0x02, 0x03, 0, 15}, /* TR5 */
79 {0x00, 0x00, 0x08, 0x0C, 2, 16}, /* TR6 */
84 #define TEMP_CRIT_HYST 2
86 #define TEMP_WARN_HYST 4
87 /* only crit and crit_hyst affect real-time alarm status
88 * current crit crit_hyst warn warn_hyst */
89 static u16 W83795_REG_TEMP[][5] = {
90 {0x21, 0x96, 0x97, 0x98, 0x99}, /* TD1/TR1 */
91 {0x22, 0x9a, 0x9b, 0x9c, 0x9d}, /* TD2/TR2 */
92 {0x23, 0x9e, 0x9f, 0xa0, 0xa1}, /* TD3/TR3 */
93 {0x24, 0xa2, 0xa3, 0xa4, 0xa5}, /* TD4/TR4 */
94 {0x1f, 0xa6, 0xa7, 0xa8, 0xa9}, /* TR5 */
95 {0x20, 0xaa, 0xab, 0xac, 0xad}, /* TR6 */
101 static const u16 W83795_REG_IN[][3] = {
102 /* Current, HL, LL */
103 {0x10, 0x70, 0x71}, /* VSEN1 */
104 {0x11, 0x72, 0x73}, /* VSEN2 */
105 {0x12, 0x74, 0x75}, /* VSEN3 */
106 {0x13, 0x76, 0x77}, /* VSEN4 */
107 {0x14, 0x78, 0x79}, /* VSEN5 */
108 {0x15, 0x7a, 0x7b}, /* VSEN6 */
109 {0x16, 0x7c, 0x7d}, /* VSEN7 */
110 {0x17, 0x7e, 0x7f}, /* VSEN8 */
111 {0x18, 0x80, 0x81}, /* VSEN9 */
112 {0x19, 0x82, 0x83}, /* VSEN10 */
113 {0x1A, 0x84, 0x85}, /* VSEN11 */
114 {0x1B, 0x86, 0x87}, /* VTT */
115 {0x1C, 0x88, 0x89}, /* 3VDD */
116 {0x1D, 0x8a, 0x8b}, /* 3VSB */
117 {0x1E, 0x8c, 0x8d}, /* VBAT */
118 {0x1F, 0xa6, 0xa7}, /* VSEN12 */
119 {0x20, 0xaa, 0xab}, /* VSEN13 */
120 {0x21, 0x96, 0x97}, /* VSEN14 */
121 {0x22, 0x9a, 0x9b}, /* VSEN15 */
122 {0x23, 0x9e, 0x9f}, /* VSEN16 */
123 {0x24, 0xa2, 0xa3}, /* VSEN17 */
125 #define W83795_REG_VRLSB 0x3C
126 #define VRLSB_SHIFT 6
128 static const u8 W83795_REG_IN_HL_LSB[] = {
132 0x94, /* VTT, 3VDD, 3VSB, 3VBAT */
141 #define IN_LSB_REG(index, type) \
142 (((type) == 1) ? W83795_REG_IN_HL_LSB[(index)] \
143 : (W83795_REG_IN_HL_LSB[(index)] + 1))
145 #define IN_LSB_REG_NUM 10
147 #define IN_LSB_SHIFT 0
149 static const u8 IN_LSB_SHIFT_IDX[][2] = {
150 /* High/Low LSB shift, LSB No. */
151 {0x00, 0x00}, /* VSEN1 */
152 {0x02, 0x00}, /* VSEN2 */
153 {0x04, 0x00}, /* VSEN3 */
154 {0x06, 0x00}, /* VSEN4 */
155 {0x00, 0x01}, /* VSEN5 */
156 {0x02, 0x01}, /* VSEN6 */
157 {0x04, 0x01}, /* VSEN7 */
158 {0x06, 0x01}, /* VSEN8 */
159 {0x00, 0x02}, /* VSEN9 */
160 {0x02, 0x02}, /* VSEN10 */
161 {0x04, 0x02}, /* VSEN11 */
162 {0x00, 0x03}, /* VTT */
163 {0x02, 0x03}, /* 3VDD */
164 {0x04, 0x03}, /* 3VSB */
165 {0x06, 0x03}, /* VBAT */
166 {0x06, 0x04}, /* VSEN12 */
167 {0x06, 0x05}, /* VSEN13 */
168 {0x06, 0x06}, /* VSEN14 */
169 {0x06, 0x07}, /* VSEN15 */
170 {0x06, 0x08}, /* VSEN16 */
171 {0x06, 0x09}, /* VSEN17 */
175 /* 3VDD, 3VSB, VBAT * 0.006 */
176 #define REST_VLT_BEGIN 12 /* the 13th volt to 15th */
177 #define REST_VLT_END 14 /* the 13th volt to 15th */
179 #define W83795_REG_FAN(index) (0x2E + (index))
180 #define W83795_REG_FAN_MIN_HL(index) (0xB6 + (index))
181 #define W83795_REG_FAN_MIN_LSB(index) (0xC4 + (index) / 2)
182 #define W83795_REG_FAN_MIN_LSB_SHIFT(index) \
183 (((index) % 1) ? 4 : 0)
185 #define W83795_REG_VID_CTRL 0x6A
187 #define ALARM_BEEP_REG_NUM 6
188 #define W83795_REG_ALARM(index) (0x41 + (index))
189 #define W83795_REG_BEEP(index) (0x50 + (index))
191 #define W83795_REG_CLR_CHASSIS 0x4D
194 #define W83795_REG_TEMP_NUM 6
195 #define W83795_REG_FCMS1 0x201
196 #define W83795_REG_FCMS2 0x208
197 #define W83795_REG_TFMR(index) (0x202 + (index))
198 #define W83795_REG_FOMC 0x20F
199 #define W83795_REG_FOPFP(index) (0x218 + (index))
201 #define W83795_REG_TSS(index) (0x209 + (index))
205 #define PWM_NONSTOP 2
206 #define PWM_STOP_TIME 3
208 #define W83795_REG_PWM(index, nr) \
209 (((nr) == 0 ? 0x210 : \
210 (nr) == 1 ? 0x220 : \
211 (nr) == 2 ? 0x228 : \
212 (nr) == 3 ? 0x230 : 0x218) + (index))
214 #define W83795_REG_FOPFP_DIV(index) \
215 (((index) < 8) ? ((index) + 1) : \
216 ((index) == 8) ? 12 : \
217 (16 << ((index) - 9)))
219 #define W83795_REG_FTSH(index) (0x240 + (index) * 2)
220 #define W83795_REG_FTSL(index) (0x241 + (index) * 2)
221 #define W83795_REG_TFTS 0x250
223 #define TEMP_PWM_TTTI 0
224 #define TEMP_PWM_CTFS 1
225 #define TEMP_PWM_HCT 2
226 #define TEMP_PWM_HOT 3
227 #define W83795_REG_TTTI(index) (0x260 + (index))
228 #define W83795_REG_CTFS(index) (0x268 + (index))
229 #define W83795_REG_HT(index) (0x270 + (index))
233 #define W83795_REG_SF4_TEMP(temp_num, index) \
234 (0x280 + 0x10 * (temp_num) + (index))
235 #define W83795_REG_SF4_PWM(temp_num, index) \
236 (0x288 + 0x10 * (temp_num) + (index))
238 #define W83795_REG_DTSC 0x301
239 #define W83795_REG_DTSE 0x302
240 #define W83795_REG_DTS(index) (0x26 + (index))
243 #define DTS_CRIT_HYST 1
245 #define DTS_WARN_HYST 3
246 #define W83795_REG_DTS_EXT(index) (0xB2 + (index))
248 #define SETUP_PWM_DEFAULT 0
249 #define SETUP_PWM_UPTIME 1
250 #define SETUP_PWM_DOWNTIME 2
251 #define W83795_REG_SETUP_PWM(index) (0x20C + (index))
253 static inline u16 in_from_reg(u8 index, u16 val)
255 if ((index >= REST_VLT_BEGIN) && (index <= REST_VLT_END))
261 static inline u16 in_to_reg(u8 index, u16 val)
263 if ((index >= REST_VLT_BEGIN) && (index <= REST_VLT_END))
269 static inline unsigned long fan_from_reg(u16 val)
271 if ((val >= 0xff0) || (val == 0))
273 return 1350000UL / val;
276 static inline u16 fan_to_reg(long rpm)
280 return SENSORS_LIMIT((1350000 + (rpm >> 1)) / rpm, 1, 0xffe);
283 static inline unsigned long time_from_reg(u8 reg)
288 static inline u8 time_to_reg(unsigned long val)
290 return SENSORS_LIMIT((val + 50) / 100, 0, 0xff);
293 static inline long temp_from_reg(s8 reg)
298 static inline s8 temp_to_reg(long val, s8 min, s8 max)
300 return SENSORS_LIMIT((val < 0 ? -val : val) / 1000, min, max);
304 enum chip_types {w83795g, w83795adg};
307 struct device *hwmon_dev;
308 struct mutex update_lock;
309 unsigned long last_updated; /* In jiffies */
310 enum chip_types chip_type;
314 u32 has_in; /* Enable monitor VIN or not */
315 u16 in[21][3]; /* Register value, read/high/low */
316 u8 in_lsb[10][3]; /* LSB Register value, high/low */
317 u8 has_gain; /* has gain: in17-20 * 8 */
319 u16 has_fan; /* Enable fan14-1 or not */
320 u16 fan[14]; /* Register value combine */
321 u16 fan_min[14]; /* Register value combine */
323 u8 has_temp; /* Enable monitor temp6-1 or not */
324 u8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */
325 u8 temp_read_vrlsb[6];
326 u8 temp_mode; /* bit 0: TR mode, bit 1: TD mode */
327 u8 temp_src[3]; /* Register value */
329 u8 enable_dts; /* Enable PECI and SB-TSI,
330 * bit 0: =1 enable, =0 disable,
331 * bit 1: =1 AMD SB-TSI, =0 Intel PECI */
332 u8 has_dts; /* Enable monitor DTS temp */
333 u8 dts[8]; /* Register value */
334 u8 dts_read_vrlsb[8]; /* Register value */
335 u8 dts_ext[4]; /* Register value */
337 u8 has_pwm; /* 795g supports 8 pwm, 795adg only supports 2,
338 * no config register, only affected by chip
340 u8 pwm[8][5]; /* Register value, output, start, non stop, stop
342 u8 pwm_fcms[2]; /* Register value */
343 u8 pwm_tfmr[6]; /* Register value */
344 u8 pwm_fomc; /* Register value */
346 u16 target_speed[8]; /* Register value, target speed for speed
348 u8 tol_speed; /* tolerance of target speed */
349 u8 pwm_temp[6][4]; /* TTTI, CTFS, HCT, HOT */
350 u8 sf4_reg[6][2][7]; /* 6 temp, temp/dcpwm, 7 registers */
352 u8 setup_pwm[3]; /* Register value */
354 u8 alarms[6]; /* Register value */
355 u8 beeps[6]; /* Register value */
365 /* Ignore the possibility that somebody change bank outside the driver
366 * Must be called with data->update_lock held, except during initialization */
367 static u8 w83795_read(struct i2c_client *client, u16 reg)
369 struct w83795_data *data = i2c_get_clientdata(client);
371 u8 new_bank = reg >> 8;
373 new_bank |= data->bank & 0xfc;
374 if (data->bank != new_bank) {
375 if (i2c_smbus_write_byte_data
376 (client, W83795_REG_BANKSEL, new_bank) >= 0)
377 data->bank = new_bank;
379 dev_err(&client->dev,
380 "set bank to %d failed, fall back "
381 "to bank %d, read reg 0x%x error\n",
382 new_bank, data->bank, reg);
383 res = 0x0; /* read 0x0 from the chip */
387 res = i2c_smbus_read_byte_data(client, reg & 0xff);
392 /* Must be called with data->update_lock held, except during initialization */
393 static int w83795_write(struct i2c_client *client, u16 reg, u8 value)
395 struct w83795_data *data = i2c_get_clientdata(client);
397 u8 new_bank = reg >> 8;
399 new_bank |= data->bank & 0xfc;
400 if (data->bank != new_bank) {
401 res = i2c_smbus_write_byte_data(client, W83795_REG_BANKSEL,
404 data->bank = new_bank;
406 dev_err(&client->dev,
407 "set bank to %d failed, fall back "
408 "to bank %d, write reg 0x%x error\n",
409 new_bank, data->bank, reg);
414 res = i2c_smbus_write_byte_data(client, reg & 0xff, value);
419 static struct w83795_data *w83795_update_device(struct device *dev)
421 struct i2c_client *client = to_i2c_client(dev);
422 struct w83795_data *data = i2c_get_clientdata(client);
426 mutex_lock(&data->update_lock);
428 if (!(time_after(jiffies, data->last_updated + HZ * 2)
432 /* Update the voltages value */
433 for (i = 0; i < ARRAY_SIZE(data->in); i++) {
434 if (!(data->has_in & (1 << i)))
436 tmp = w83795_read(client, W83795_REG_IN[i][IN_READ]) << 2;
437 tmp |= (w83795_read(client, W83795_REG_VRLSB)
438 >> VRLSB_SHIFT) & 0x03;
439 data->in[i][IN_READ] = tmp;
443 for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
444 if (!(data->has_fan & (1 << i)))
446 data->fan[i] = w83795_read(client, W83795_REG_FAN(i)) << 4;
448 (w83795_read(client, W83795_REG_VRLSB >> 4)) & 0x0F;
451 /* Update temperature */
452 for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
453 /* even stop monitor, register still keep value, just read out
455 if (!(data->has_temp & (1 << i))) {
456 data->temp[i][TEMP_READ] = 0;
457 data->temp_read_vrlsb[i] = 0;
460 data->temp[i][TEMP_READ] =
461 w83795_read(client, W83795_REG_TEMP[i][TEMP_READ]);
462 data->temp_read_vrlsb[i] =
463 w83795_read(client, W83795_REG_VRLSB);
466 /* Update dts temperature */
467 if (data->enable_dts != 0) {
468 for (i = 0; i < ARRAY_SIZE(data->dts); i++) {
469 if (!(data->has_dts & (1 << i)))
472 w83795_read(client, W83795_REG_DTS(i));
473 data->dts_read_vrlsb[i] =
474 w83795_read(client, W83795_REG_VRLSB);
478 /* Update pwm output */
479 for (i = 0; i < data->has_pwm; i++) {
480 data->pwm[i][PWM_OUTPUT] =
481 w83795_read(client, W83795_REG_PWM(i, PWM_OUTPUT));
485 for (i = 0; i < ALARM_BEEP_REG_NUM; i++)
486 data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i));
488 data->last_updated = jiffies;
492 mutex_unlock(&data->update_lock);
500 #define ALARM_STATUS 0
501 #define BEEP_ENABLE 1
503 show_alarm_beep(struct device *dev, struct device_attribute *attr, char *buf)
505 struct w83795_data *data = w83795_update_device(dev);
506 struct sensor_device_attribute_2 *sensor_attr =
507 to_sensor_dev_attr_2(attr);
508 int nr = sensor_attr->nr;
509 int index = sensor_attr->index >> 3;
510 int bit = sensor_attr->index & 0x07;
513 if (ALARM_STATUS == nr) {
514 val = (data->alarms[index] >> (bit)) & 1;
515 } else { /* BEEP_ENABLE */
516 val = (data->beeps[index] >> (bit)) & 1;
519 return sprintf(buf, "%u\n", val);
523 store_beep(struct device *dev, struct device_attribute *attr,
524 const char *buf, size_t count)
526 struct i2c_client *client = to_i2c_client(dev);
527 struct w83795_data *data = i2c_get_clientdata(client);
528 struct sensor_device_attribute_2 *sensor_attr =
529 to_sensor_dev_attr_2(attr);
530 int index = sensor_attr->index >> 3;
531 int shift = sensor_attr->index & 0x07;
532 u8 beep_bit = 1 << shift;
535 if (strict_strtoul(buf, 10, &val) < 0)
537 if (val != 0 && val != 1)
540 mutex_lock(&data->update_lock);
541 data->beeps[index] = w83795_read(client, W83795_REG_BEEP(index));
542 data->beeps[index] &= ~beep_bit;
543 data->beeps[index] |= val << shift;
544 w83795_write(client, W83795_REG_BEEP(index), data->beeps[index]);
545 mutex_unlock(&data->update_lock);
551 show_beep_enable(struct device *dev, struct device_attribute *attr, char *buf)
553 struct i2c_client *client = to_i2c_client(dev);
554 struct w83795_data *data = i2c_get_clientdata(client);
555 return sprintf(buf, "%u\n", data->beep_enable);
559 store_beep_enable(struct device *dev, struct device_attribute *attr,
560 const char *buf, size_t count)
562 struct i2c_client *client = to_i2c_client(dev);
563 struct w83795_data *data = i2c_get_clientdata(client);
567 if (strict_strtoul(buf, 10, &val) < 0)
569 if (val != 0 && val != 1)
572 mutex_lock(&data->update_lock);
573 data->beep_enable = val;
574 tmp = w83795_read(client, W83795_REG_BEEP(5));
577 w83795_write(client, W83795_REG_BEEP(5), tmp);
578 mutex_unlock(&data->update_lock);
583 /* Write any value to clear chassis alarm */
585 store_chassis_clear(struct device *dev,
586 struct device_attribute *attr, const char *buf,
589 struct i2c_client *client = to_i2c_client(dev);
590 struct w83795_data *data = i2c_get_clientdata(client);
593 mutex_lock(&data->update_lock);
594 val = w83795_read(client, W83795_REG_CLR_CHASSIS);
596 w83795_write(client, W83795_REG_CLR_CHASSIS, val);
597 mutex_unlock(&data->update_lock);
604 show_fan(struct device *dev, struct device_attribute *attr, char *buf)
606 struct sensor_device_attribute_2 *sensor_attr =
607 to_sensor_dev_attr_2(attr);
608 int nr = sensor_attr->nr;
609 int index = sensor_attr->index;
610 struct w83795_data *data = w83795_update_device(dev);
614 val = data->fan[index] & 0x0fff;
616 val = data->fan_min[index] & 0x0fff;
618 return sprintf(buf, "%lu\n", fan_from_reg(val));
622 store_fan_min(struct device *dev, struct device_attribute *attr,
623 const char *buf, size_t count)
625 struct sensor_device_attribute_2 *sensor_attr =
626 to_sensor_dev_attr_2(attr);
627 int index = sensor_attr->index;
628 struct i2c_client *client = to_i2c_client(dev);
629 struct w83795_data *data = i2c_get_clientdata(client);
632 if (strict_strtoul(buf, 10, &val))
634 val = fan_to_reg(val);
636 mutex_lock(&data->update_lock);
637 data->fan_min[index] = val;
638 w83795_write(client, W83795_REG_FAN_MIN_HL(index), (val >> 4) & 0xff);
642 val |= w83795_read(client, W83795_REG_FAN_MIN_LSB(index))
645 val |= w83795_read(client, W83795_REG_FAN_MIN_LSB(index))
648 w83795_write(client, W83795_REG_FAN_MIN_LSB(index), val & 0xff);
649 mutex_unlock(&data->update_lock);
655 show_pwm(struct device *dev, struct device_attribute *attr, char *buf)
657 struct w83795_data *data = w83795_update_device(dev);
658 struct sensor_device_attribute_2 *sensor_attr =
659 to_sensor_dev_attr_2(attr);
660 int nr = sensor_attr->nr;
661 int index = sensor_attr->index;
666 val = time_from_reg(data->pwm[index][nr]);
669 val = W83795_REG_FOPFP_DIV(data->pwm[index][nr] & 0x0f);
672 val = data->pwm[index][nr];
676 return sprintf(buf, "%u\n", val);
680 store_pwm(struct device *dev, struct device_attribute *attr,
681 const char *buf, size_t count)
683 struct i2c_client *client = to_i2c_client(dev);
684 struct w83795_data *data = i2c_get_clientdata(client);
685 struct sensor_device_attribute_2 *sensor_attr =
686 to_sensor_dev_attr_2(attr);
687 int nr = sensor_attr->nr;
688 int index = sensor_attr->index;
692 if (strict_strtoul(buf, 10, &val) < 0)
695 mutex_lock(&data->update_lock);
698 val = time_to_reg(val);
701 for (i = 0; i < 16; i++) {
702 if (W83795_REG_FOPFP_DIV(i) == val) {
709 val |= w83795_read(client, W83795_REG_PWM(index, nr)) & 0x80;
712 val = SENSORS_LIMIT(val, 0, 0xff);
715 w83795_write(client, W83795_REG_PWM(index, nr), val);
716 data->pwm[index][nr] = val & 0xff;
717 mutex_unlock(&data->update_lock);
720 mutex_unlock(&data->update_lock);
725 show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
727 struct sensor_device_attribute_2 *sensor_attr =
728 to_sensor_dev_attr_2(attr);
729 struct i2c_client *client = to_i2c_client(dev);
730 struct w83795_data *data = i2c_get_clientdata(client);
731 int index = sensor_attr->index;
734 if (1 == (data->pwm_fcms[0] & (1 << index))) {
738 for (tmp = 0; tmp < 6; tmp++) {
739 if (data->pwm_tfmr[tmp] & (1 << index)) {
744 if (data->pwm_fomc & (1 << index))
750 return sprintf(buf, "%u\n", tmp);
754 store_pwm_enable(struct device *dev, struct device_attribute *attr,
755 const char *buf, size_t count)
757 struct i2c_client *client = to_i2c_client(dev);
758 struct w83795_data *data = i2c_get_clientdata(client);
759 struct sensor_device_attribute_2 *sensor_attr =
760 to_sensor_dev_attr_2(attr);
761 int index = sensor_attr->index;
765 if (strict_strtoul(buf, 10, &val) < 0)
770 mutex_lock(&data->update_lock);
774 data->pwm_fcms[0] &= ~(1 << index);
775 w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]);
776 for (i = 0; i < 6; i++) {
777 data->pwm_tfmr[i] &= ~(1 << index);
778 w83795_write(client, W83795_REG_TFMR(i),
781 data->pwm_fomc |= 1 << index;
782 data->pwm_fomc ^= val << index;
783 w83795_write(client, W83795_REG_FOMC, data->pwm_fomc);
786 data->pwm_fcms[0] |= (1 << index);
787 w83795_write(client, W83795_REG_FCMS1, data->pwm_fcms[0]);
790 mutex_unlock(&data->update_lock);
795 show_temp_src(struct device *dev, struct device_attribute *attr, char *buf)
797 struct sensor_device_attribute_2 *sensor_attr =
798 to_sensor_dev_attr_2(attr);
799 struct i2c_client *client = to_i2c_client(dev);
800 struct w83795_data *data = i2c_get_clientdata(client);
801 int index = sensor_attr->index;
803 u8 tmp = data->temp_src[val];
812 return sprintf(buf, "%u\n", tmp);
816 store_temp_src(struct device *dev, struct device_attribute *attr,
817 const char *buf, size_t count)
819 struct i2c_client *client = to_i2c_client(dev);
820 struct w83795_data *data = i2c_get_clientdata(client);
821 struct sensor_device_attribute_2 *sensor_attr =
822 to_sensor_dev_attr_2(attr);
823 int index = sensor_attr->index;
827 if (strict_strtoul(buf, 10, &tmp) < 0)
829 tmp = SENSORS_LIMIT(tmp, 0, 15);
831 mutex_lock(&data->update_lock);
834 data->temp_src[val] &= 0x0f;
836 data->temp_src[val] &= 0xf0;
838 data->temp_src[val] |= tmp;
839 w83795_write(client, W83795_REG_TSS(val), data->temp_src[val]);
840 mutex_unlock(&data->update_lock);
845 #define TEMP_PWM_ENABLE 0
846 #define TEMP_PWM_FAN_MAP 1
848 show_temp_pwm_enable(struct device *dev, struct device_attribute *attr,
851 struct i2c_client *client = to_i2c_client(dev);
852 struct w83795_data *data = i2c_get_clientdata(client);
853 struct sensor_device_attribute_2 *sensor_attr =
854 to_sensor_dev_attr_2(attr);
855 int nr = sensor_attr->nr;
856 int index = sensor_attr->index;
860 case TEMP_PWM_ENABLE:
861 tmp = (data->pwm_fcms[1] >> index) & 1;
867 case TEMP_PWM_FAN_MAP:
868 tmp = data->pwm_tfmr[index];
872 return sprintf(buf, "%u\n", tmp);
876 store_temp_pwm_enable(struct device *dev, struct device_attribute *attr,
877 const char *buf, size_t count)
879 struct i2c_client *client = to_i2c_client(dev);
880 struct w83795_data *data = i2c_get_clientdata(client);
881 struct sensor_device_attribute_2 *sensor_attr =
882 to_sensor_dev_attr_2(attr);
883 int nr = sensor_attr->nr;
884 int index = sensor_attr->index;
887 if (strict_strtoul(buf, 10, &tmp) < 0)
891 case TEMP_PWM_ENABLE:
892 if ((tmp != 3) && (tmp != 4))
895 mutex_lock(&data->update_lock);
896 data->pwm_fcms[1] &= ~(1 << index);
897 data->pwm_fcms[1] |= tmp << index;
898 w83795_write(client, W83795_REG_FCMS2, data->pwm_fcms[1]);
899 mutex_unlock(&data->update_lock);
901 case TEMP_PWM_FAN_MAP:
902 mutex_lock(&data->update_lock);
903 tmp = SENSORS_LIMIT(tmp, 0, 0xff);
904 w83795_write(client, W83795_REG_TFMR(index), tmp);
905 data->pwm_tfmr[index] = tmp;
906 mutex_unlock(&data->update_lock);
912 #define FANIN_TARGET 0
915 show_fanin(struct device *dev, struct device_attribute *attr, char *buf)
917 struct i2c_client *client = to_i2c_client(dev);
918 struct w83795_data *data = i2c_get_clientdata(client);
919 struct sensor_device_attribute_2 *sensor_attr =
920 to_sensor_dev_attr_2(attr);
921 int nr = sensor_attr->nr;
922 int index = sensor_attr->index;
927 tmp = fan_from_reg(data->target_speed[index]);
930 tmp = data->tol_speed;
934 return sprintf(buf, "%u\n", tmp);
938 store_fanin(struct device *dev, struct device_attribute *attr,
939 const char *buf, size_t count)
941 struct i2c_client *client = to_i2c_client(dev);
942 struct w83795_data *data = i2c_get_clientdata(client);
943 struct sensor_device_attribute_2 *sensor_attr =
944 to_sensor_dev_attr_2(attr);
945 int nr = sensor_attr->nr;
946 int index = sensor_attr->index;
949 if (strict_strtoul(buf, 10, &val) < 0)
952 mutex_lock(&data->update_lock);
955 val = fan_to_reg(SENSORS_LIMIT(val, 0, 0xfff));
956 w83795_write(client, W83795_REG_FTSH(index), (val >> 4) & 0xff);
957 w83795_write(client, W83795_REG_FTSL(index), (val << 4) & 0xf0);
958 data->target_speed[index] = val;
961 val = SENSORS_LIMIT(val, 0, 0x3f);
962 w83795_write(client, W83795_REG_TFTS, val);
963 data->tol_speed = val;
966 mutex_unlock(&data->update_lock);
973 show_temp_pwm(struct device *dev, struct device_attribute *attr, char *buf)
975 struct i2c_client *client = to_i2c_client(dev);
976 struct w83795_data *data = i2c_get_clientdata(client);
977 struct sensor_device_attribute_2 *sensor_attr =
978 to_sensor_dev_attr_2(attr);
979 int nr = sensor_attr->nr;
980 int index = sensor_attr->index;
981 long tmp = temp_from_reg(data->pwm_temp[index][nr]);
983 return sprintf(buf, "%ld\n", tmp);
987 store_temp_pwm(struct device *dev, struct device_attribute *attr,
988 const char *buf, size_t count)
990 struct i2c_client *client = to_i2c_client(dev);
991 struct w83795_data *data = i2c_get_clientdata(client);
992 struct sensor_device_attribute_2 *sensor_attr =
993 to_sensor_dev_attr_2(attr);
994 int nr = sensor_attr->nr;
995 int index = sensor_attr->index;
999 if (strict_strtoul(buf, 10, &val) < 0)
1003 mutex_lock(&data->update_lock);
1006 val = SENSORS_LIMIT(val, 0, 0x7f);
1007 w83795_write(client, W83795_REG_TTTI(index), val);
1010 val = SENSORS_LIMIT(val, 0, 0x7f);
1011 w83795_write(client, W83795_REG_CTFS(index), val);
1014 val = SENSORS_LIMIT(val, 0, 0x0f);
1015 tmp = w83795_read(client, W83795_REG_HT(index));
1017 tmp |= (val << 4) & 0xf0;
1018 w83795_write(client, W83795_REG_HT(index), tmp);
1021 val = SENSORS_LIMIT(val, 0, 0x0f);
1022 tmp = w83795_read(client, W83795_REG_HT(index));
1025 w83795_write(client, W83795_REG_HT(index), tmp);
1028 data->pwm_temp[index][nr] = val;
1029 mutex_unlock(&data->update_lock);
1035 show_sf4_pwm(struct device *dev, struct device_attribute *attr, char *buf)
1037 struct i2c_client *client = to_i2c_client(dev);
1038 struct w83795_data *data = i2c_get_clientdata(client);
1039 struct sensor_device_attribute_2 *sensor_attr =
1040 to_sensor_dev_attr_2(attr);
1041 int nr = sensor_attr->nr;
1042 int index = sensor_attr->index;
1044 return sprintf(buf, "%u\n", data->sf4_reg[index][SF4_PWM][nr]);
1048 store_sf4_pwm(struct device *dev, struct device_attribute *attr,
1049 const char *buf, size_t count)
1051 struct i2c_client *client = to_i2c_client(dev);
1052 struct w83795_data *data = i2c_get_clientdata(client);
1053 struct sensor_device_attribute_2 *sensor_attr =
1054 to_sensor_dev_attr_2(attr);
1055 int nr = sensor_attr->nr;
1056 int index = sensor_attr->index;
1059 if (strict_strtoul(buf, 10, &val) < 0)
1062 mutex_lock(&data->update_lock);
1063 w83795_write(client, W83795_REG_SF4_PWM(index, nr), val);
1064 data->sf4_reg[index][SF4_PWM][nr] = val;
1065 mutex_unlock(&data->update_lock);
1071 show_sf4_temp(struct device *dev, struct device_attribute *attr, char *buf)
1073 struct i2c_client *client = to_i2c_client(dev);
1074 struct w83795_data *data = i2c_get_clientdata(client);
1075 struct sensor_device_attribute_2 *sensor_attr =
1076 to_sensor_dev_attr_2(attr);
1077 int nr = sensor_attr->nr;
1078 int index = sensor_attr->index;
1080 return sprintf(buf, "%u\n",
1081 (data->sf4_reg[index][SF4_TEMP][nr]) * 1000);
1085 store_sf4_temp(struct device *dev, struct device_attribute *attr,
1086 const char *buf, size_t count)
1088 struct i2c_client *client = to_i2c_client(dev);
1089 struct w83795_data *data = i2c_get_clientdata(client);
1090 struct sensor_device_attribute_2 *sensor_attr =
1091 to_sensor_dev_attr_2(attr);
1092 int nr = sensor_attr->nr;
1093 int index = sensor_attr->index;
1096 if (strict_strtoul(buf, 10, &val) < 0)
1100 mutex_lock(&data->update_lock);
1101 w83795_write(client, W83795_REG_SF4_TEMP(index, nr), val);
1102 data->sf4_reg[index][SF4_TEMP][nr] = val;
1103 mutex_unlock(&data->update_lock);
1110 show_temp(struct device *dev, struct device_attribute *attr, char *buf)
1112 struct sensor_device_attribute_2 *sensor_attr =
1113 to_sensor_dev_attr_2(attr);
1114 int nr = sensor_attr->nr;
1115 int index = sensor_attr->index;
1116 struct w83795_data *data = w83795_update_device(dev);
1117 long temp = temp_from_reg(data->temp[index][nr] & 0x7f);
1119 if (TEMP_READ == nr)
1120 temp += ((data->temp_read_vrlsb[index] >> VRLSB_SHIFT) & 0x03)
1122 if (data->temp[index][nr] & 0x80)
1124 return sprintf(buf, "%ld\n", temp);
1128 store_temp(struct device *dev, struct device_attribute *attr,
1129 const char *buf, size_t count)
1131 struct sensor_device_attribute_2 *sensor_attr =
1132 to_sensor_dev_attr_2(attr);
1133 int nr = sensor_attr->nr;
1134 int index = sensor_attr->index;
1135 struct i2c_client *client = to_i2c_client(dev);
1136 struct w83795_data *data = i2c_get_clientdata(client);
1139 if (strict_strtol(buf, 10, &tmp) < 0)
1142 mutex_lock(&data->update_lock);
1143 data->temp[index][nr] = temp_to_reg(tmp, -128, 127);
1144 w83795_write(client, W83795_REG_TEMP[index][nr], data->temp[index][nr]);
1145 mutex_unlock(&data->update_lock);
1151 show_dts_mode(struct device *dev, struct device_attribute *attr, char *buf)
1153 struct i2c_client *client = to_i2c_client(dev);
1154 struct w83795_data *data = i2c_get_clientdata(client);
1155 struct sensor_device_attribute_2 *sensor_attr =
1156 to_sensor_dev_attr_2(attr);
1157 int index = sensor_attr->index;
1160 if (data->enable_dts == 0)
1161 return sprintf(buf, "%d\n", 0);
1163 if ((data->has_dts >> index) & 0x01) {
1164 if (data->enable_dts & 2)
1172 return sprintf(buf, "%d\n", tmp);
1176 show_dts(struct device *dev, struct device_attribute *attr, char *buf)
1178 struct sensor_device_attribute_2 *sensor_attr =
1179 to_sensor_dev_attr_2(attr);
1180 int index = sensor_attr->index;
1181 struct w83795_data *data = w83795_update_device(dev);
1182 long temp = temp_from_reg(data->dts[index] & 0x7f);
1184 temp += ((data->dts_read_vrlsb[index] >> VRLSB_SHIFT) & 0x03) * 250;
1185 if (data->dts[index] & 0x80)
1187 return sprintf(buf, "%ld\n", temp);
1191 show_dts_ext(struct device *dev, struct device_attribute *attr, char *buf)
1193 struct sensor_device_attribute_2 *sensor_attr =
1194 to_sensor_dev_attr_2(attr);
1195 int nr = sensor_attr->nr;
1196 struct i2c_client *client = to_i2c_client(dev);
1197 struct w83795_data *data = i2c_get_clientdata(client);
1198 long temp = temp_from_reg(data->dts_ext[nr] & 0x7f);
1200 if (data->dts_ext[nr] & 0x80)
1202 return sprintf(buf, "%ld\n", temp);
1206 store_dts_ext(struct device *dev, struct device_attribute *attr,
1207 const char *buf, size_t count)
1209 struct sensor_device_attribute_2 *sensor_attr =
1210 to_sensor_dev_attr_2(attr);
1211 int nr = sensor_attr->nr;
1212 struct i2c_client *client = to_i2c_client(dev);
1213 struct w83795_data *data = i2c_get_clientdata(client);
1216 if (strict_strtol(buf, 10, &tmp) < 0)
1219 mutex_lock(&data->update_lock);
1220 data->dts_ext[nr] = temp_to_reg(tmp, -128, 127);
1221 w83795_write(client, W83795_REG_DTS_EXT(nr), data->dts_ext[nr]);
1222 mutex_unlock(&data->update_lock);
1228 Type 3: Thermal diode
1236 show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf)
1238 struct i2c_client *client = to_i2c_client(dev);
1239 struct w83795_data *data = i2c_get_clientdata(client);
1240 struct sensor_device_attribute_2 *sensor_attr =
1241 to_sensor_dev_attr_2(attr);
1242 int index = sensor_attr->index;
1245 if (data->has_temp >> index & 0x01) {
1246 if (data->temp_mode >> index & 0x01)
1254 return sprintf(buf, "%d\n", tmp);
1258 store_temp_mode(struct device *dev, struct device_attribute *attr,
1259 const char *buf, size_t count)
1261 struct i2c_client *client = to_i2c_client(dev);
1262 struct w83795_data *data = i2c_get_clientdata(client);
1263 struct sensor_device_attribute_2 *sensor_attr =
1264 to_sensor_dev_attr_2(attr);
1265 int index = sensor_attr->index;
1270 if (strict_strtoul(buf, 10, &val) < 0)
1272 if ((val != 4) && (val != 3))
1274 if ((index > 3) && (val == 3))
1277 mutex_lock(&data->update_lock);
1280 data->has_temp |= 1 << index;
1281 data->temp_mode |= 1 << index;
1282 } else if (val == 4) {
1284 data->has_temp |= 1 << index;
1286 data->temp_mode &= ~tmp;
1290 tmp = w83795_read(client, W83795_REG_TEMP_CTRL1);
1292 tmp = w83795_read(client, W83795_REG_TEMP_CTRL2);
1294 mask = 0x03 << W83795_REG_TEMP_CTRL[index][TEMP_CTRL_SHIFT];
1296 tmp |= W83795_REG_TEMP_CTRL[index][val];
1298 mask = 1 << W83795_REG_TEMP_CTRL[index][TEMP_CTRL_HASIN_SHIFT];
1299 data->has_in &= ~mask;
1302 w83795_write(client, W83795_REG_TEMP_CTRL1, tmp);
1304 w83795_write(client, W83795_REG_TEMP_CTRL2, tmp);
1306 mutex_unlock(&data->update_lock);
1311 /* show/store VIN */
1313 show_in(struct device *dev, struct device_attribute *attr, char *buf)
1315 struct sensor_device_attribute_2 *sensor_attr =
1316 to_sensor_dev_attr_2(attr);
1317 int nr = sensor_attr->nr;
1318 int index = sensor_attr->index;
1319 struct w83795_data *data = w83795_update_device(dev);
1320 u16 val = data->in[index][nr];
1325 /* calculate this value again by sensors as sensors3.conf */
1326 if ((index >= 17) &&
1327 ((data->has_gain >> (index - 17)) & 1))
1332 lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX];
1334 val |= (data->in_lsb[lsb_idx][nr] >>
1335 IN_LSB_SHIFT_IDX[lsb_idx][IN_LSB_SHIFT]) & 0x03;
1336 if ((index >= 17) &&
1337 ((data->has_gain >> (index - 17)) & 1))
1341 val = in_from_reg(index, val);
1343 return sprintf(buf, "%d\n", val);
1347 store_in(struct device *dev, struct device_attribute *attr,
1348 const char *buf, size_t count)
1350 struct sensor_device_attribute_2 *sensor_attr =
1351 to_sensor_dev_attr_2(attr);
1352 int nr = sensor_attr->nr;
1353 int index = sensor_attr->index;
1354 struct i2c_client *client = to_i2c_client(dev);
1355 struct w83795_data *data = i2c_get_clientdata(client);
1360 if (strict_strtoul(buf, 10, &val) < 0)
1362 val = in_to_reg(index, val);
1364 if ((index >= 17) &&
1365 ((data->has_gain >> (index - 17)) & 1))
1367 val = SENSORS_LIMIT(val, 0, 0x3FF);
1368 mutex_lock(&data->update_lock);
1370 lsb_idx = IN_LSB_SHIFT_IDX[index][IN_LSB_IDX];
1371 tmp = w83795_read(client, IN_LSB_REG(lsb_idx, nr));
1372 tmp &= ~(0x03 << IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT]);
1373 tmp |= (val & 0x03) << IN_LSB_SHIFT_IDX[index][IN_LSB_SHIFT];
1374 w83795_write(client, IN_LSB_REG(lsb_idx, nr), tmp);
1375 data->in_lsb[lsb_idx][nr] = tmp;
1377 tmp = (val >> 2) & 0xff;
1378 w83795_write(client, W83795_REG_IN[index][nr], tmp);
1379 data->in[index][nr] = tmp;
1381 mutex_unlock(&data->update_lock);
1387 show_sf_setup(struct device *dev, struct device_attribute *attr, char *buf)
1389 struct sensor_device_attribute_2 *sensor_attr =
1390 to_sensor_dev_attr_2(attr);
1391 int nr = sensor_attr->nr;
1392 struct i2c_client *client = to_i2c_client(dev);
1393 struct w83795_data *data = i2c_get_clientdata(client);
1394 u16 val = data->setup_pwm[nr];
1397 case SETUP_PWM_UPTIME:
1398 case SETUP_PWM_DOWNTIME:
1399 val = time_from_reg(val);
1403 return sprintf(buf, "%d\n", val);
1407 store_sf_setup(struct device *dev, struct device_attribute *attr,
1408 const char *buf, size_t count)
1410 struct sensor_device_attribute_2 *sensor_attr =
1411 to_sensor_dev_attr_2(attr);
1412 int nr = sensor_attr->nr;
1413 struct i2c_client *client = to_i2c_client(dev);
1414 struct w83795_data *data = i2c_get_clientdata(client);
1417 if (strict_strtoul(buf, 10, &val) < 0)
1421 case SETUP_PWM_DEFAULT:
1422 val = SENSORS_LIMIT(val, 0, 0xff);
1424 case SETUP_PWM_UPTIME:
1425 case SETUP_PWM_DOWNTIME:
1426 val = time_to_reg(val);
1432 mutex_lock(&data->update_lock);
1433 data->setup_pwm[nr] = val;
1434 w83795_write(client, W83795_REG_SETUP_PWM(nr), val);
1435 mutex_unlock(&data->update_lock);
1442 #define SENSOR_ATTR_IN(index) \
1443 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \
1445 SENSOR_ATTR_2(in##index##_max, S_IRUGO | S_IWUSR, show_in, \
1446 store_in, IN_MAX, index), \
1447 SENSOR_ATTR_2(in##index##_min, S_IRUGO | S_IWUSR, show_in, \
1448 store_in, IN_LOW, index), \
1449 SENSOR_ATTR_2(in##index##_alarm, S_IRUGO, show_alarm_beep, \
1450 NULL, ALARM_STATUS, index + ((index > 14) ? 1 : 0)), \
1451 SENSOR_ATTR_2(in##index##_beep, S_IWUSR | S_IRUGO, \
1452 show_alarm_beep, store_beep, BEEP_ENABLE, \
1453 index + ((index > 14) ? 1 : 0))
1455 #define SENSOR_ATTR_FAN(index) \
1456 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \
1457 NULL, FAN_INPUT, index - 1), \
1458 SENSOR_ATTR_2(fan##index##_min, S_IWUSR | S_IRUGO, \
1459 show_fan, store_fan_min, FAN_MIN, index - 1), \
1460 SENSOR_ATTR_2(fan##index##_alarm, S_IRUGO, show_alarm_beep, \
1461 NULL, ALARM_STATUS, index + 31), \
1462 SENSOR_ATTR_2(fan##index##_beep, S_IWUSR | S_IRUGO, \
1463 show_alarm_beep, store_beep, BEEP_ENABLE, index + 31)
1465 #define SENSOR_ATTR_PWM(index) \
1466 SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm, \
1467 store_pwm, PWM_OUTPUT, index - 1), \
1468 SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO, \
1469 show_pwm, store_pwm, PWM_NONSTOP, index - 1), \
1470 SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO, \
1471 show_pwm, store_pwm, PWM_START, index - 1), \
1472 SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO, \
1473 show_pwm, store_pwm, PWM_STOP_TIME, index - 1), \
1474 SENSOR_ATTR_2(fan##index##_div, S_IWUSR | S_IRUGO, \
1475 show_pwm, store_pwm, PWM_DIV, index - 1), \
1476 SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \
1477 show_pwm_enable, store_pwm_enable, NOT_USED, index - 1)
1479 #define SENSOR_ATTR_FANIN_TARGET(index) \
1480 SENSOR_ATTR_2(speed_cruise##index##_target, S_IWUSR | S_IRUGO, \
1481 show_fanin, store_fanin, FANIN_TARGET, index - 1)
1483 #define SENSOR_ATTR_DTS(index) \
1484 SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \
1485 show_dts_mode, NULL, NOT_USED, index - 7), \
1486 SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_dts, \
1487 NULL, NOT_USED, index - 7), \
1488 SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_dts_ext, \
1489 store_dts_ext, DTS_CRIT, NOT_USED), \
1490 SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \
1491 show_dts_ext, store_dts_ext, DTS_CRIT_HYST, NOT_USED), \
1492 SENSOR_ATTR_2(temp##index##_warn, S_IRUGO | S_IWUSR, show_dts_ext, \
1493 store_dts_ext, DTS_WARN, NOT_USED), \
1494 SENSOR_ATTR_2(temp##index##_warn_hyst, S_IRUGO | S_IWUSR, \
1495 show_dts_ext, store_dts_ext, DTS_WARN_HYST, NOT_USED), \
1496 SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \
1497 show_alarm_beep, NULL, ALARM_STATUS, index + 17), \
1498 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
1499 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17)
1501 #define SENSOR_ATTR_TEMP(index) \
1502 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | S_IWUSR, \
1503 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \
1504 SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \
1505 NULL, TEMP_READ, index - 1), \
1506 SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_temp, \
1507 store_temp, TEMP_CRIT, index - 1), \
1508 SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \
1509 show_temp, store_temp, TEMP_CRIT_HYST, index - 1), \
1510 SENSOR_ATTR_2(temp##index##_warn, S_IRUGO | S_IWUSR, show_temp, \
1511 store_temp, TEMP_WARN, index - 1), \
1512 SENSOR_ATTR_2(temp##index##_warn_hyst, S_IRUGO | S_IWUSR, \
1513 show_temp, store_temp, TEMP_WARN_HYST, index - 1), \
1514 SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \
1515 show_alarm_beep, NULL, ALARM_STATUS, \
1516 index + (index > 4 ? 11 : 17)), \
1517 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
1518 show_alarm_beep, store_beep, BEEP_ENABLE, \
1519 index + (index > 4 ? 11 : 17)), \
1520 SENSOR_ATTR_2(temp##index##_source_sel, S_IWUSR | S_IRUGO, \
1521 show_temp_src, store_temp_src, NOT_USED, index - 1), \
1522 SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \
1523 show_temp_pwm_enable, store_temp_pwm_enable, \
1524 TEMP_PWM_ENABLE, index - 1), \
1525 SENSOR_ATTR_2(temp##index##_auto_channels_pwm, S_IWUSR | S_IRUGO, \
1526 show_temp_pwm_enable, store_temp_pwm_enable, \
1527 TEMP_PWM_FAN_MAP, index - 1), \
1528 SENSOR_ATTR_2(thermal_cruise##index, S_IWUSR | S_IRUGO, \
1529 show_temp_pwm, store_temp_pwm, TEMP_PWM_TTTI, index - 1), \
1530 SENSOR_ATTR_2(temp##index##_crit, S_IWUSR | S_IRUGO, \
1531 show_temp_pwm, store_temp_pwm, TEMP_PWM_CTFS, index - 1), \
1532 SENSOR_ATTR_2(temp##index##_crit_hyst, S_IWUSR | S_IRUGO, \
1533 show_temp_pwm, store_temp_pwm, TEMP_PWM_HCT, index - 1), \
1534 SENSOR_ATTR_2(temp##index##_operation_hyst, S_IWUSR | S_IRUGO, \
1535 show_temp_pwm, store_temp_pwm, TEMP_PWM_HOT, index - 1), \
1536 SENSOR_ATTR_2(temp##index##_auto_point1_pwm, S_IRUGO | S_IWUSR, \
1537 show_sf4_pwm, store_sf4_pwm, 0, index - 1), \
1538 SENSOR_ATTR_2(temp##index##_auto_point2_pwm, S_IRUGO | S_IWUSR, \
1539 show_sf4_pwm, store_sf4_pwm, 1, index - 1), \
1540 SENSOR_ATTR_2(temp##index##_auto_point3_pwm, S_IRUGO | S_IWUSR, \
1541 show_sf4_pwm, store_sf4_pwm, 2, index - 1), \
1542 SENSOR_ATTR_2(temp##index##_auto_point4_pwm, S_IRUGO | S_IWUSR, \
1543 show_sf4_pwm, store_sf4_pwm, 3, index - 1), \
1544 SENSOR_ATTR_2(temp##index##_auto_point5_pwm, S_IRUGO | S_IWUSR, \
1545 show_sf4_pwm, store_sf4_pwm, 4, index - 1), \
1546 SENSOR_ATTR_2(temp##index##_auto_point6_pwm, S_IRUGO | S_IWUSR, \
1547 show_sf4_pwm, store_sf4_pwm, 5, index - 1), \
1548 SENSOR_ATTR_2(temp##index##_auto_point7_pwm, S_IRUGO | S_IWUSR, \
1549 show_sf4_pwm, store_sf4_pwm, 6, index - 1), \
1550 SENSOR_ATTR_2(temp##index##_auto_point1_temp, S_IRUGO | S_IWUSR,\
1551 show_sf4_temp, store_sf4_temp, 0, index - 1), \
1552 SENSOR_ATTR_2(temp##index##_auto_point2_temp, S_IRUGO | S_IWUSR,\
1553 show_sf4_temp, store_sf4_temp, 1, index - 1), \
1554 SENSOR_ATTR_2(temp##index##_auto_point3_temp, S_IRUGO | S_IWUSR,\
1555 show_sf4_temp, store_sf4_temp, 2, index - 1), \
1556 SENSOR_ATTR_2(temp##index##_auto_point4_temp, S_IRUGO | S_IWUSR,\
1557 show_sf4_temp, store_sf4_temp, 3, index - 1), \
1558 SENSOR_ATTR_2(temp##index##_auto_point5_temp, S_IRUGO | S_IWUSR,\
1559 show_sf4_temp, store_sf4_temp, 4, index - 1), \
1560 SENSOR_ATTR_2(temp##index##_auto_point6_temp, S_IRUGO | S_IWUSR,\
1561 show_sf4_temp, store_sf4_temp, 5, index - 1), \
1562 SENSOR_ATTR_2(temp##index##_auto_point7_temp, S_IRUGO | S_IWUSR,\
1563 show_sf4_temp, store_sf4_temp, 6, index - 1)
1566 static struct sensor_device_attribute_2 w83795_in[] = {
1590 static struct sensor_device_attribute_2 w83795_fan[] = {
1600 SENSOR_ATTR_FAN(10),
1601 SENSOR_ATTR_FAN(11),
1602 SENSOR_ATTR_FAN(12),
1603 SENSOR_ATTR_FAN(13),
1604 SENSOR_ATTR_FAN(14),
1607 static struct sensor_device_attribute_2 w83795_temp[] = {
1608 SENSOR_ATTR_TEMP(1),
1609 SENSOR_ATTR_TEMP(2),
1610 SENSOR_ATTR_TEMP(3),
1611 SENSOR_ATTR_TEMP(4),
1612 SENSOR_ATTR_TEMP(5),
1613 SENSOR_ATTR_TEMP(6),
1616 static struct sensor_device_attribute_2 w83795_dts[] = {
1620 SENSOR_ATTR_DTS(10),
1621 SENSOR_ATTR_DTS(11),
1622 SENSOR_ATTR_DTS(12),
1623 SENSOR_ATTR_DTS(13),
1624 SENSOR_ATTR_DTS(14),
1627 static struct sensor_device_attribute_2 w83795_static[] = {
1628 SENSOR_ATTR_FANIN_TARGET(1),
1629 SENSOR_ATTR_FANIN_TARGET(2),
1630 SENSOR_ATTR_FANIN_TARGET(3),
1631 SENSOR_ATTR_FANIN_TARGET(4),
1632 SENSOR_ATTR_FANIN_TARGET(5),
1633 SENSOR_ATTR_FANIN_TARGET(6),
1634 SENSOR_ATTR_FANIN_TARGET(7),
1635 SENSOR_ATTR_FANIN_TARGET(8),
1640 /* all registers existed in 795g than 795adg,
1641 * like PWM3 - PWM8 */
1642 static struct sensor_device_attribute_2 w83795_left_reg[] = {
1651 static struct sensor_device_attribute_2 sda_single_files[] = {
1652 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep,
1653 store_chassis_clear, ALARM_STATUS, 46),
1654 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable,
1655 store_beep_enable, NOT_USED, NOT_USED),
1656 SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin,
1657 store_fanin, FANIN_TOL, NOT_USED),
1658 SENSOR_ATTR_2(pwm_default, S_IWUSR | S_IRUGO, show_sf_setup,
1659 store_sf_setup, SETUP_PWM_DEFAULT, NOT_USED),
1660 SENSOR_ATTR_2(pwm_uptime, S_IWUSR | S_IRUGO, show_sf_setup,
1661 store_sf_setup, SETUP_PWM_UPTIME, NOT_USED),
1662 SENSOR_ATTR_2(pwm_downtime, S_IWUSR | S_IRUGO, show_sf_setup,
1663 store_sf_setup, SETUP_PWM_DOWNTIME, NOT_USED),
1670 static void w83795_init_client(struct i2c_client *client)
1673 w83795_write(client, W83795_REG_CONFIG, 0x80);
1675 /* Start monitoring */
1676 w83795_write(client, W83795_REG_CONFIG,
1677 w83795_read(client, W83795_REG_CONFIG) | 0x01);
1680 /* Return 0 if detection is successful, -ENODEV otherwise */
1681 static int w83795_detect(struct i2c_client *client,
1682 struct i2c_board_info *info)
1685 struct i2c_adapter *adapter = client->adapter;
1686 unsigned short address = client->addr;
1687 const char *chip_name;
1689 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1691 bank = i2c_smbus_read_byte_data(client, W83795_REG_BANKSEL);
1693 tmp = bank & 0x80 ? 0x5c : 0xa3;
1694 /* Check Nuvoton vendor ID */
1695 if (tmp != i2c_smbus_read_byte_data(client,
1696 W83795_REG_VENDORID)) {
1697 pr_debug("w83795: Detection failed at check "
1702 /* If Nuvoton chip, address of chip and W83795_REG_I2C_ADDR
1704 if ((bank & 0x07) == 0
1705 && (i2c_smbus_read_byte_data(client, W83795_REG_I2C_ADDR) & 0x7f) !=
1707 pr_debug("w83795: Detection failed at check "
1712 /* Determine the chip type now */
1713 if (0x79 != i2c_smbus_read_byte_data(client,
1714 W83795_REG_CHIPID)) {
1715 pr_debug("w83795: Detection failed at check "
1720 /* Check 795 chip type: 795G or 795ADG
1721 Usually we don't write to chips during detection, but here we don't
1722 quite have the choice; hopefully it's OK, we are about to return
1724 if ((bank & 0x07) != 0)
1725 i2c_smbus_write_byte_data(client, W83795_REG_BANKSEL,
1727 if (W83795_REG_CONFIG_CONFIG48 &
1728 i2c_smbus_read_byte_data(client, W83795_REG_CONFIG)) {
1729 chip_name = "w83795adg";
1731 chip_name = "w83795g";
1734 strlcpy(info->type, chip_name, I2C_NAME_SIZE);
1739 static int w83795_probe(struct i2c_client *client,
1740 const struct i2c_device_id *id)
1744 struct device *dev = &client->dev;
1745 struct w83795_data *data;
1748 data = kzalloc(sizeof(struct w83795_data), GFP_KERNEL);
1754 i2c_set_clientdata(client, data);
1755 data->chip_type = id->driver_data;
1756 data->bank = i2c_smbus_read_byte_data(client, W83795_REG_BANKSEL);
1757 mutex_init(&data->update_lock);
1759 /* Initialize the chip */
1760 w83795_init_client(client);
1762 data->has_in = w83795_read(client, W83795_REG_VOLT_CTRL1);
1763 data->has_in |= w83795_read(client, W83795_REG_VOLT_CTRL2) << 8;
1764 /* VSEN11-9 not for 795adg */
1765 if (data->chip_type == w83795adg)
1766 data->has_in &= 0xf8ff;
1767 data->has_fan = w83795_read(client, W83795_REG_FANIN_CTRL1);
1768 data->has_fan |= w83795_read(client, W83795_REG_FANIN_CTRL2) << 8;
1770 /* VDSEN12-17 and TR1-6, TD1-4 use same register */
1771 tmp = w83795_read(client, W83795_REG_TEMP_CTRL1);
1773 data->enable_dts = 1;
1775 data->enable_dts = 0;
1777 data->temp_mode = 0;
1780 data->has_temp |= 0x20;
1782 data->has_in |= 0x10000;
1786 data->has_temp |= 0x10;
1788 data->has_in |= 0x8000;
1790 tmp = w83795_read(client, W83795_REG_TEMP_CTRL2);
1792 data->has_temp |= 0x08;
1794 data->temp_mode |= 0x08;
1795 } else if (tmp & 0x80) {
1796 data->has_in |= 0x100000;
1799 data->has_temp |= 0x04;
1801 data->temp_mode |= 0x04;
1802 } else if (tmp & 0x20) {
1803 data->has_in |= 0x80000;
1806 data->has_temp |= 0x02;
1808 data->temp_mode |= 0x02;
1809 } else if (tmp & 0x08) {
1810 data->has_in |= 0x40000;
1813 data->has_temp |= 0x01;
1815 data->temp_mode |= 0x01;
1816 } else if (tmp & 0x02) {
1817 data->has_in |= 0x20000;
1820 /* Check DTS enable status */
1821 if (data->enable_dts == 0) {
1824 if (1 & w83795_read(client, W83795_REG_DTSC))
1825 data->enable_dts |= 2;
1826 data->has_dts = w83795_read(client, W83795_REG_DTSE);
1829 /* First update the voltages measured value and limits */
1830 for (i = 0; i < ARRAY_SIZE(data->in); i++) {
1831 if (!(data->has_in & (1 << i)))
1833 data->in[i][IN_MAX] =
1834 w83795_read(client, W83795_REG_IN[i][IN_MAX]);
1835 data->in[i][IN_LOW] =
1836 w83795_read(client, W83795_REG_IN[i][IN_LOW]);
1837 tmp = w83795_read(client, W83795_REG_IN[i][IN_READ]) << 2;
1838 tmp |= (w83795_read(client, W83795_REG_VRLSB)
1839 >> VRLSB_SHIFT) & 0x03;
1840 data->in[i][IN_READ] = tmp;
1842 for (i = 0; i < IN_LSB_REG_NUM; i++) {
1843 data->in_lsb[i][IN_MAX] =
1844 w83795_read(client, IN_LSB_REG(i, IN_MAX));
1845 data->in_lsb[i][IN_LOW] =
1846 w83795_read(client, IN_LSB_REG(i, IN_LOW));
1848 data->has_gain = w83795_read(client, W83795_REG_VMIGB_CTRL) & 0x0f;
1850 /* First update fan and limits */
1851 for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
1852 if (!(data->has_fan & (1 << i)))
1855 w83795_read(client, W83795_REG_FAN_MIN_HL(i)) << 4;
1857 (w83795_read(client, W83795_REG_FAN_MIN_LSB(i) >>
1858 W83795_REG_FAN_MIN_LSB_SHIFT(i))) & 0x0F;
1859 data->fan[i] = w83795_read(client, W83795_REG_FAN(i)) << 4;
1861 (w83795_read(client, W83795_REG_VRLSB >> 4)) & 0x0F;
1864 /* temperature and limits */
1865 for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
1866 if (!(data->has_temp & (1 << i)))
1868 data->temp[i][TEMP_CRIT] =
1869 w83795_read(client, W83795_REG_TEMP[i][TEMP_CRIT]);
1870 data->temp[i][TEMP_CRIT_HYST] =
1871 w83795_read(client, W83795_REG_TEMP[i][TEMP_CRIT_HYST]);
1872 data->temp[i][TEMP_WARN] =
1873 w83795_read(client, W83795_REG_TEMP[i][TEMP_WARN]);
1874 data->temp[i][TEMP_WARN_HYST] =
1875 w83795_read(client, W83795_REG_TEMP[i][TEMP_WARN_HYST]);
1876 data->temp[i][TEMP_READ] =
1877 w83795_read(client, W83795_REG_TEMP[i][TEMP_READ]);
1878 data->temp_read_vrlsb[i] =
1879 w83795_read(client, W83795_REG_VRLSB);
1882 /* dts temperature and limits */
1883 if (data->enable_dts != 0) {
1884 data->dts_ext[DTS_CRIT] =
1885 w83795_read(client, W83795_REG_DTS_EXT(DTS_CRIT));
1886 data->dts_ext[DTS_CRIT_HYST] =
1887 w83795_read(client, W83795_REG_DTS_EXT(DTS_CRIT_HYST));
1888 data->dts_ext[DTS_WARN] =
1889 w83795_read(client, W83795_REG_DTS_EXT(DTS_WARN));
1890 data->dts_ext[DTS_WARN_HYST] =
1891 w83795_read(client, W83795_REG_DTS_EXT(DTS_WARN_HYST));
1892 for (i = 0; i < ARRAY_SIZE(data->dts); i++) {
1893 if (!(data->has_dts & (1 << i)))
1895 data->dts[i] = w83795_read(client, W83795_REG_DTS(i));
1896 data->dts_read_vrlsb[i] =
1897 w83795_read(client, W83795_REG_VRLSB);
1901 /* First update temp source selction */
1902 for (i = 0; i < 3; i++)
1903 data->temp_src[i] = w83795_read(client, W83795_REG_TSS(i));
1905 /* pwm and smart fan */
1906 if (data->chip_type == w83795g)
1910 data->pwm_fcms[0] = w83795_read(client, W83795_REG_FCMS1);
1911 data->pwm_fcms[1] = w83795_read(client, W83795_REG_FCMS2);
1912 /* w83795adg only support pwm2-0 */
1913 for (i = 0; i < W83795_REG_TEMP_NUM; i++)
1914 data->pwm_tfmr[i] = w83795_read(client, W83795_REG_TFMR(i));
1915 data->pwm_fomc = w83795_read(client, W83795_REG_FOMC);
1916 for (i = 0; i < data->has_pwm; i++) {
1917 for (tmp = 0; tmp < 5; tmp++) {
1919 w83795_read(client, W83795_REG_PWM(i, tmp));
1922 for (i = 0; i < 8; i++) {
1923 data->target_speed[i] =
1924 w83795_read(client, W83795_REG_FTSH(i)) << 4;
1925 data->target_speed[i] |=
1926 w83795_read(client, W83795_REG_FTSL(i)) >> 4;
1928 data->tol_speed = w83795_read(client, W83795_REG_TFTS) & 0x3f;
1930 for (i = 0; i < W83795_REG_TEMP_NUM; i++) {
1931 data->pwm_temp[i][TEMP_PWM_TTTI] =
1932 w83795_read(client, W83795_REG_TTTI(i)) & 0x7f;
1933 data->pwm_temp[i][TEMP_PWM_CTFS] =
1934 w83795_read(client, W83795_REG_CTFS(i));
1935 tmp = w83795_read(client, W83795_REG_HT(i));
1936 data->pwm_temp[i][TEMP_PWM_HCT] = (tmp >> 4) & 0x0f;
1937 data->pwm_temp[i][TEMP_PWM_HOT] = tmp & 0x0f;
1939 for (i = 0; i < W83795_REG_TEMP_NUM; i++) {
1940 for (tmp = 0; tmp < 7; tmp++) {
1941 data->sf4_reg[i][SF4_TEMP][tmp] =
1943 W83795_REG_SF4_TEMP(i, tmp));
1944 data->sf4_reg[i][SF4_PWM][tmp] =
1945 w83795_read(client, W83795_REG_SF4_PWM(i, tmp));
1949 /* Setup PWM Register */
1950 for (i = 0; i < 3; i++) {
1951 data->setup_pwm[i] =
1952 w83795_read(client, W83795_REG_SETUP_PWM(i));
1955 /* alarm and beep */
1956 for (i = 0; i < ALARM_BEEP_REG_NUM; i++) {
1957 data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i));
1958 data->beeps[i] = w83795_read(client, W83795_REG_BEEP(i));
1961 (w83795_read(client, W83795_REG_BEEP(5)) >> 7) & 0x01;
1963 /* Register sysfs hooks */
1964 for (i = 0; i < ARRAY_SIZE(w83795_in); i++) {
1965 if (!(data->has_in & (1 << (i / 6))))
1967 err = device_create_file(dev, &w83795_in[i].dev_attr);
1972 for (i = 0; i < ARRAY_SIZE(w83795_fan); i++) {
1973 if (!(data->has_fan & (1 << (i / 5))))
1975 err = device_create_file(dev, &w83795_fan[i].dev_attr);
1980 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
1981 err = device_create_file(dev, &sda_single_files[i].dev_attr);
1986 for (i = 0; i < ARRAY_SIZE(w83795_temp); i++) {
1987 if (!(data->has_temp & (1 << (i / 29))))
1989 err = device_create_file(dev, &w83795_temp[i].dev_attr);
1994 if (data->enable_dts != 0) {
1995 for (i = 0; i < ARRAY_SIZE(w83795_dts); i++) {
1996 if (!(data->has_dts & (1 << (i / 8))))
1998 err = device_create_file(dev, &w83795_dts[i].dev_attr);
2004 if (data->chip_type == w83795g) {
2005 for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++) {
2006 err = device_create_file(dev,
2007 &w83795_left_reg[i].dev_attr);
2013 for (i = 0; i < ARRAY_SIZE(w83795_static); i++) {
2014 err = device_create_file(dev, &w83795_static[i].dev_attr);
2019 data->hwmon_dev = hwmon_device_register(dev);
2020 if (IS_ERR(data->hwmon_dev)) {
2021 err = PTR_ERR(data->hwmon_dev);
2027 /* Unregister sysfs hooks */
2029 for (i = 0; i < ARRAY_SIZE(w83795_in); i++)
2030 device_remove_file(dev, &w83795_in[i].dev_attr);
2032 for (i = 0; i < ARRAY_SIZE(w83795_fan); i++)
2033 device_remove_file(dev, &w83795_fan[i].dev_attr);
2035 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
2036 device_remove_file(dev, &sda_single_files[i].dev_attr);
2038 if (data->chip_type == w83795g) {
2039 for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++)
2040 device_remove_file(dev, &w83795_left_reg[i].dev_attr);
2043 for (i = 0; i < ARRAY_SIZE(w83795_temp); i++)
2044 device_remove_file(dev, &w83795_temp[i].dev_attr);
2046 for (i = 0; i < ARRAY_SIZE(w83795_dts); i++)
2047 device_remove_file(dev, &w83795_dts[i].dev_attr);
2049 for (i = 0; i < ARRAY_SIZE(w83795_static); i++)
2050 device_remove_file(dev, &w83795_static[i].dev_attr);
2057 static int w83795_remove(struct i2c_client *client)
2059 struct w83795_data *data = i2c_get_clientdata(client);
2060 struct device *dev = &client->dev;
2063 hwmon_device_unregister(data->hwmon_dev);
2065 for (i = 0; i < ARRAY_SIZE(w83795_in); i++)
2066 device_remove_file(dev, &w83795_in[i].dev_attr);
2068 for (i = 0; i < ARRAY_SIZE(w83795_fan); i++)
2069 device_remove_file(dev, &w83795_fan[i].dev_attr);
2071 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
2072 device_remove_file(dev, &sda_single_files[i].dev_attr);
2074 if (data->chip_type == w83795g) {
2075 for (i = 0; i < ARRAY_SIZE(w83795_left_reg); i++)
2076 device_remove_file(dev, &w83795_left_reg[i].dev_attr);
2079 for (i = 0; i < ARRAY_SIZE(w83795_temp); i++)
2080 device_remove_file(dev, &w83795_temp[i].dev_attr);
2082 for (i = 0; i < ARRAY_SIZE(w83795_dts); i++)
2083 device_remove_file(dev, &w83795_dts[i].dev_attr);
2085 for (i = 0; i < ARRAY_SIZE(w83795_static); i++)
2086 device_remove_file(dev, &w83795_static[i].dev_attr);
2094 static const struct i2c_device_id w83795_id[] = {
2095 { "w83795g", w83795g },
2096 { "w83795adg", w83795adg },
2099 MODULE_DEVICE_TABLE(i2c, w83795_id);
2101 static struct i2c_driver w83795_driver = {
2105 .probe = w83795_probe,
2106 .remove = w83795_remove,
2107 .id_table = w83795_id,
2109 .class = I2C_CLASS_HWMON,
2110 .detect = w83795_detect,
2111 .address_list = normal_i2c,
2114 static int __init sensors_w83795_init(void)
2116 return i2c_add_driver(&w83795_driver);
2119 static void __exit sensors_w83795_exit(void)
2121 i2c_del_driver(&w83795_driver);
2124 MODULE_AUTHOR("Wei Song");
2125 MODULE_DESCRIPTION("W83795G/ADG hardware monitoring driver");
2126 MODULE_LICENSE("GPL");
2128 module_init(sensors_w83795_init);
2129 module_exit(sensors_w83795_exit);