blob: 9ef84998c7f382b114cd11d1c4ea04e7c916dda4 [file] [log] [blame]
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001/*
2 * adt7475 - Thermal sensor driver for the ADT7475 chip and derivatives
3 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
5 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
Jean Delvare7c81c602014-01-29 20:40:08 +01006 * Copyright (C) 2009 Jean Delvare <jdelvare@suse.de>
Jean Delvare3d849982009-12-09 20:36:05 +01007 *
Jordan Crouse1c301fc2009-01-15 22:27:47 +01008 * Derived from the lm83 driver by Jean Delvare
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/module.h>
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -030016#include <linux/of_device.h>
Jordan Crouse1c301fc2009-01-15 22:27:47 +010017#include <linux/init.h>
18#include <linux/slab.h>
19#include <linux/i2c.h>
20#include <linux/hwmon.h>
21#include <linux/hwmon-sysfs.h>
Jean Delvare54fe4672009-12-09 20:36:08 +010022#include <linux/hwmon-vid.h>
Jordan Crouse1c301fc2009-01-15 22:27:47 +010023#include <linux/err.h>
Jean Delvaredcd8f392012-10-10 15:25:56 +020024#include <linux/jiffies.h>
Chris Packhame4651642017-05-11 15:45:21 +120025#include <linux/util_macros.h>
Jordan Crouse1c301fc2009-01-15 22:27:47 +010026
27/* Indexes for the sysfs hooks */
28
29#define INPUT 0
30#define MIN 1
31#define MAX 2
32#define CONTROL 3
33#define OFFSET 3
34#define AUTOMIN 4
35#define THERM 5
36#define HYSTERSIS 6
37
Guenter Roeck9ed5bc22012-01-19 11:02:15 -080038/*
39 * These are unique identifiers for the sysfs functions - unlike the
40 * numbers above, these are not also indexes into an array
41 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +010042
43#define ALARM 9
44#define FAULT 10
45
46/* 7475 Common Registers */
47
Jean Delvared07ca4a2009-12-09 20:36:07 +010048#define REG_DEVREV2 0x12 /* ADT7490 only */
49
Jean Delvare3d849982009-12-09 20:36:05 +010050#define REG_VTT 0x1E /* ADT7490 only */
51#define REG_EXTEND3 0x1F /* ADT7490 only */
52
Jean Delvarecffb9dd2009-12-09 20:36:03 +010053#define REG_VOLTAGE_BASE 0x20
Jordan Crouse1c301fc2009-01-15 22:27:47 +010054#define REG_TEMP_BASE 0x25
55#define REG_TACH_BASE 0x28
56#define REG_PWM_BASE 0x30
57#define REG_PWM_MAX_BASE 0x38
58
59#define REG_DEVID 0x3D
60#define REG_VENDID 0x3E
Jean Delvared656b6f2009-12-09 20:36:04 +010061#define REG_DEVID2 0x3F
Jordan Crouse1c301fc2009-01-15 22:27:47 +010062
Chris Packham4abdf382017-04-22 07:08:09 +120063#define REG_CONFIG1 0x40
64
Jordan Crouse1c301fc2009-01-15 22:27:47 +010065#define REG_STATUS1 0x41
66#define REG_STATUS2 0x42
67
Jean Delvared8d2ee02009-12-09 20:36:08 +010068#define REG_VID 0x43 /* ADT7476 only */
69
Jean Delvarecffb9dd2009-12-09 20:36:03 +010070#define REG_VOLTAGE_MIN_BASE 0x44
71#define REG_VOLTAGE_MAX_BASE 0x45
Jordan Crouse1c301fc2009-01-15 22:27:47 +010072
73#define REG_TEMP_MIN_BASE 0x4E
74#define REG_TEMP_MAX_BASE 0x4F
75
76#define REG_TACH_MIN_BASE 0x54
77
78#define REG_PWM_CONFIG_BASE 0x5C
79
80#define REG_TEMP_TRANGE_BASE 0x5F
81
Chris Packham1d58f5e2017-05-15 13:30:27 +120082#define REG_ENHANCE_ACOUSTICS1 0x62
83#define REG_ENHANCE_ACOUSTICS2 0x63
84
Jordan Crouse1c301fc2009-01-15 22:27:47 +010085#define REG_PWM_MIN_BASE 0x64
86
87#define REG_TEMP_TMIN_BASE 0x67
88#define REG_TEMP_THERM_BASE 0x6A
89
90#define REG_REMOTE1_HYSTERSIS 0x6D
91#define REG_REMOTE2_HYSTERSIS 0x6E
92
93#define REG_TEMP_OFFSET_BASE 0x70
94
Jean Delvareebfaf1f2009-12-09 20:36:07 +010095#define REG_CONFIG2 0x73
96
Jordan Crouse1c301fc2009-01-15 22:27:47 +010097#define REG_EXTEND1 0x76
98#define REG_EXTEND2 0x77
Jean Delvare378933c2009-12-09 20:36:06 +010099
100#define REG_CONFIG3 0x78
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100101#define REG_CONFIG5 0x7C
Jean Delvaref99318b2009-12-09 20:36:03 +0100102#define REG_CONFIG4 0x7D
103
Jean Delvare3d849982009-12-09 20:36:05 +0100104#define REG_STATUS4 0x81 /* ADT7490 only */
105
106#define REG_VTT_MIN 0x84 /* ADT7490 only */
107#define REG_VTT_MAX 0x86 /* ADT7490 only */
108
Jean Delvared8d2ee02009-12-09 20:36:08 +0100109#define VID_VIDSEL 0x80 /* ADT7476 only */
110
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100111#define CONFIG2_ATTN 0x20
112
Jean Delvare378933c2009-12-09 20:36:06 +0100113#define CONFIG3_SMBALERT 0x01
114#define CONFIG3_THERM 0x02
115
116#define CONFIG4_PINFUNC 0x03
Jean Delvaref99318b2009-12-09 20:36:03 +0100117#define CONFIG4_MAXDUTY 0x08
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100118#define CONFIG4_ATTN_IN10 0x30
119#define CONFIG4_ATTN_IN43 0xC0
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100120
121#define CONFIG5_TWOSCOMP 0x01
122#define CONFIG5_TEMPOFFSET 0x02
Jean Delvare54fe4672009-12-09 20:36:08 +0100123#define CONFIG5_VIDGPIO 0x10 /* ADT7476 only */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100124
125/* ADT7475 Settings */
126
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100127#define ADT7475_VOLTAGE_COUNT 5 /* Not counting Vtt */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100128#define ADT7475_TEMP_COUNT 3
129#define ADT7475_TACH_COUNT 4
130#define ADT7475_PWM_COUNT 3
131
132/* Macro to read the registers */
133
134#define adt7475_read(reg) i2c_smbus_read_byte_data(client, (reg))
135
136/* Macros to easily index the registers */
137
138#define TACH_REG(idx) (REG_TACH_BASE + ((idx) * 2))
139#define TACH_MIN_REG(idx) (REG_TACH_MIN_BASE + ((idx) * 2))
140
141#define PWM_REG(idx) (REG_PWM_BASE + (idx))
142#define PWM_MAX_REG(idx) (REG_PWM_MAX_BASE + (idx))
143#define PWM_MIN_REG(idx) (REG_PWM_MIN_BASE + (idx))
144#define PWM_CONFIG_REG(idx) (REG_PWM_CONFIG_BASE + (idx))
145
146#define VOLTAGE_REG(idx) (REG_VOLTAGE_BASE + (idx))
147#define VOLTAGE_MIN_REG(idx) (REG_VOLTAGE_MIN_BASE + ((idx) * 2))
148#define VOLTAGE_MAX_REG(idx) (REG_VOLTAGE_MAX_BASE + ((idx) * 2))
149
150#define TEMP_REG(idx) (REG_TEMP_BASE + (idx))
151#define TEMP_MIN_REG(idx) (REG_TEMP_MIN_BASE + ((idx) * 2))
152#define TEMP_MAX_REG(idx) (REG_TEMP_MAX_BASE + ((idx) * 2))
153#define TEMP_TMIN_REG(idx) (REG_TEMP_TMIN_BASE + (idx))
154#define TEMP_THERM_REG(idx) (REG_TEMP_THERM_BASE + (idx))
155#define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx))
156#define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx))
157
Jean Delvare918ee912010-10-28 20:31:50 +0200158static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100159
Jean Delvaree5e9f442009-12-14 21:17:27 +0100160enum chips { adt7473, adt7475, adt7476, adt7490 };
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100161
162static const struct i2c_device_id adt7475_id[] = {
Jean Delvareb180d052009-12-09 20:36:02 +0100163 { "adt7473", adt7473 },
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100164 { "adt7475", adt7475 },
Jean Delvared8d2ee02009-12-09 20:36:08 +0100165 { "adt7476", adt7476 },
Jean Delvare3d849982009-12-09 20:36:05 +0100166 { "adt7490", adt7490 },
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100167 { }
168};
169MODULE_DEVICE_TABLE(i2c, adt7475_id);
170
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -0300171static const struct of_device_id adt7475_of_match[] = {
172 {
173 .compatible = "adi,adt7473",
174 .data = (void *)adt7473
175 },
176 {
177 .compatible = "adi,adt7475",
178 .data = (void *)adt7475
179 },
180 {
181 .compatible = "adi,adt7476",
182 .data = (void *)adt7476
183 },
184 {
185 .compatible = "adi,adt7490",
186 .data = (void *)adt7490
187 },
188 { },
189};
190MODULE_DEVICE_TABLE(of, adt7475_of_match);
191
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100192struct adt7475_data {
193 struct device *hwmon_dev;
194 struct mutex lock;
195
196 unsigned long measure_updated;
197 unsigned long limits_updated;
198 char valid;
199
Jean Delvaref99318b2009-12-09 20:36:03 +0100200 u8 config4;
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100201 u8 config5;
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100202 u8 has_voltage;
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100203 u8 bypass_attn; /* Bypass voltage attenuator */
Jean Delvare378933c2009-12-09 20:36:06 +0100204 u8 has_pwm2:1;
205 u8 has_fan4:1;
Jean Delvare54fe4672009-12-09 20:36:08 +0100206 u8 has_vid:1;
Jean Delvare3d849982009-12-09 20:36:05 +0100207 u32 alarms;
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100208 u16 voltage[3][6];
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100209 u16 temp[7][3];
210 u16 tach[2][4];
211 u8 pwm[4][3];
212 u8 range[3];
213 u8 pwmctl[3];
214 u8 pwmchan[3];
Chris Packham1d58f5e2017-05-15 13:30:27 +1200215 u8 enh_acoustics[2];
Jean Delvare54fe4672009-12-09 20:36:08 +0100216
217 u8 vid;
218 u8 vrm;
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100219};
220
221static struct i2c_driver adt7475_driver;
222static struct adt7475_data *adt7475_update_device(struct device *dev);
223static void adt7475_read_hystersis(struct i2c_client *client);
224static void adt7475_read_pwm(struct i2c_client *client, int index);
225
226/* Given a temp value, convert it to register value */
227
228static inline u16 temp2reg(struct adt7475_data *data, long val)
229{
230 u16 ret;
231
232 if (!(data->config5 & CONFIG5_TWOSCOMP)) {
Guenter Roeck2a844c12013-01-09 08:09:34 -0800233 val = clamp_val(val, -64000, 191000);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100234 ret = (val + 64500) / 1000;
235 } else {
Guenter Roeck2a844c12013-01-09 08:09:34 -0800236 val = clamp_val(val, -128000, 127000);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100237 if (val < -500)
238 ret = (256500 + val) / 1000;
239 else
240 ret = (val + 500) / 1000;
241 }
242
243 return ret << 2;
244}
245
246/* Given a register value, convert it to a real temp value */
247
248static inline int reg2temp(struct adt7475_data *data, u16 reg)
249{
250 if (data->config5 & CONFIG5_TWOSCOMP) {
251 if (reg >= 512)
252 return (reg - 1024) * 250;
253 else
254 return reg * 250;
255 } else
256 return (reg - 256) * 250;
257}
258
259static inline int tach2rpm(u16 tach)
260{
261 if (tach == 0 || tach == 0xFFFF)
262 return 0;
263
264 return (90000 * 60) / tach;
265}
266
267static inline u16 rpm2tach(unsigned long rpm)
268{
269 if (rpm == 0)
270 return 0;
271
Guenter Roeck2a844c12013-01-09 08:09:34 -0800272 return clamp_val((90000 * 60) / rpm, 1, 0xFFFF);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100273}
274
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100275/* Scaling factors for voltage inputs, taken from the ADT7490 datasheet */
276static const int adt7473_in_scaling[ADT7475_VOLTAGE_COUNT + 1][2] = {
277 { 45, 94 }, /* +2.5V */
278 { 175, 525 }, /* Vccp */
279 { 68, 71 }, /* Vcc */
280 { 93, 47 }, /* +5V */
281 { 120, 20 }, /* +12V */
282 { 45, 45 }, /* Vtt */
283};
284
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100285static inline int reg2volt(int channel, u16 reg, u8 bypass_attn)
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100286{
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100287 const int *r = adt7473_in_scaling[channel];
288
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100289 if (bypass_attn & (1 << channel))
290 return DIV_ROUND_CLOSEST(reg * 2250, 1024);
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100291 return DIV_ROUND_CLOSEST(reg * (r[0] + r[1]) * 2250, r[1] * 1024);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100292}
293
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100294static inline u16 volt2reg(int channel, long volt, u8 bypass_attn)
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100295{
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100296 const int *r = adt7473_in_scaling[channel];
297 long reg;
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100298
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100299 if (bypass_attn & (1 << channel))
300 reg = (volt * 1024) / 2250;
301 else
302 reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250);
Guenter Roeck2a844c12013-01-09 08:09:34 -0800303 return clamp_val(reg, 0, 1023) & (0xff << 2);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100304}
305
306static u16 adt7475_read_word(struct i2c_client *client, int reg)
307{
308 u16 val;
309
310 val = i2c_smbus_read_byte_data(client, reg);
311 val |= (i2c_smbus_read_byte_data(client, reg + 1) << 8);
312
313 return val;
314}
315
316static void adt7475_write_word(struct i2c_client *client, int reg, u16 val)
317{
318 i2c_smbus_write_byte_data(client, reg + 1, val >> 8);
319 i2c_smbus_write_byte_data(client, reg, val & 0xFF);
320}
321
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100322static ssize_t show_voltage(struct device *dev, struct device_attribute *attr,
323 char *buf)
324{
325 struct adt7475_data *data = adt7475_update_device(dev);
326 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
327 unsigned short val;
328
329 switch (sattr->nr) {
330 case ALARM:
331 return sprintf(buf, "%d\n",
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100332 (data->alarms >> sattr->index) & 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100333 default:
334 val = data->voltage[sattr->nr][sattr->index];
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100335 return sprintf(buf, "%d\n",
336 reg2volt(sattr->index, val, data->bypass_attn));
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100337 }
338}
339
340static ssize_t set_voltage(struct device *dev, struct device_attribute *attr,
341 const char *buf, size_t count)
342{
343
344 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
345 struct i2c_client *client = to_i2c_client(dev);
346 struct adt7475_data *data = i2c_get_clientdata(client);
347 unsigned char reg;
348 long val;
349
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100350 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100351 return -EINVAL;
352
353 mutex_lock(&data->lock);
354
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100355 data->voltage[sattr->nr][sattr->index] =
356 volt2reg(sattr->index, val, data->bypass_attn);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100357
Jean Delvare3d849982009-12-09 20:36:05 +0100358 if (sattr->index < ADT7475_VOLTAGE_COUNT) {
359 if (sattr->nr == MIN)
360 reg = VOLTAGE_MIN_REG(sattr->index);
361 else
362 reg = VOLTAGE_MAX_REG(sattr->index);
363 } else {
364 if (sattr->nr == MIN)
365 reg = REG_VTT_MIN;
366 else
367 reg = REG_VTT_MAX;
368 }
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100369
370 i2c_smbus_write_byte_data(client, reg,
371 data->voltage[sattr->nr][sattr->index] >> 2);
372 mutex_unlock(&data->lock);
373
374 return count;
375}
376
377static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
378 char *buf)
379{
380 struct adt7475_data *data = adt7475_update_device(dev);
381 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
382 int out;
383
384 switch (sattr->nr) {
385 case HYSTERSIS:
386 mutex_lock(&data->lock);
387 out = data->temp[sattr->nr][sattr->index];
388 if (sattr->index != 1)
389 out = (out >> 4) & 0xF;
390 else
391 out = (out & 0xF);
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800392 /*
393 * Show the value as an absolute number tied to
394 * THERM
395 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100396 out = reg2temp(data, data->temp[THERM][sattr->index]) -
397 out * 1000;
398 mutex_unlock(&data->lock);
399 break;
400
401 case OFFSET:
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800402 /*
403 * Offset is always 2's complement, regardless of the
404 * setting in CONFIG5
405 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100406 mutex_lock(&data->lock);
407 out = (s8)data->temp[sattr->nr][sattr->index];
408 if (data->config5 & CONFIG5_TEMPOFFSET)
409 out *= 1000;
410 else
411 out *= 500;
412 mutex_unlock(&data->lock);
413 break;
414
415 case ALARM:
416 out = (data->alarms >> (sattr->index + 4)) & 1;
417 break;
418
419 case FAULT:
420 /* Note - only for remote1 and remote2 */
Jean Delvarecf312e02009-11-16 12:45:39 +0100421 out = !!(data->alarms & (sattr->index ? 0x8000 : 0x4000));
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100422 break;
423
424 default:
425 /* All other temp values are in the configured format */
426 out = reg2temp(data, data->temp[sattr->nr][sattr->index]);
427 }
428
429 return sprintf(buf, "%d\n", out);
430}
431
432static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
433 const char *buf, size_t count)
434{
435 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
436 struct i2c_client *client = to_i2c_client(dev);
437 struct adt7475_data *data = i2c_get_clientdata(client);
438 unsigned char reg = 0;
439 u8 out;
440 int temp;
441 long val;
442
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100443 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100444 return -EINVAL;
445
446 mutex_lock(&data->lock);
447
448 /* We need the config register in all cases for temp <-> reg conv. */
449 data->config5 = adt7475_read(REG_CONFIG5);
450
451 switch (sattr->nr) {
452 case OFFSET:
453 if (data->config5 & CONFIG5_TEMPOFFSET) {
Guenter Roeck2a844c12013-01-09 08:09:34 -0800454 val = clamp_val(val, -63000, 127000);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100455 out = data->temp[OFFSET][sattr->index] = val / 1000;
456 } else {
Guenter Roeck2a844c12013-01-09 08:09:34 -0800457 val = clamp_val(val, -63000, 64000);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100458 out = data->temp[OFFSET][sattr->index] = val / 500;
459 }
460 break;
461
462 case HYSTERSIS:
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800463 /*
464 * The value will be given as an absolute value, turn it
465 * into an offset based on THERM
466 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100467
468 /* Read fresh THERM and HYSTERSIS values from the chip */
469 data->temp[THERM][sattr->index] =
470 adt7475_read(TEMP_THERM_REG(sattr->index)) << 2;
471 adt7475_read_hystersis(client);
472
473 temp = reg2temp(data, data->temp[THERM][sattr->index]);
Guenter Roeck2a844c12013-01-09 08:09:34 -0800474 val = clamp_val(val, temp - 15000, temp);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100475 val = (temp - val) / 1000;
476
477 if (sattr->index != 1) {
478 data->temp[HYSTERSIS][sattr->index] &= 0xF0;
479 data->temp[HYSTERSIS][sattr->index] |= (val & 0xF) << 4;
480 } else {
481 data->temp[HYSTERSIS][sattr->index] &= 0x0F;
482 data->temp[HYSTERSIS][sattr->index] |= (val & 0xF);
483 }
484
485 out = data->temp[HYSTERSIS][sattr->index];
486 break;
487
488 default:
489 data->temp[sattr->nr][sattr->index] = temp2reg(data, val);
490
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800491 /*
492 * We maintain an extra 2 digits of precision for simplicity
493 * - shift those back off before writing the value
494 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100495 out = (u8) (data->temp[sattr->nr][sattr->index] >> 2);
496 }
497
498 switch (sattr->nr) {
499 case MIN:
500 reg = TEMP_MIN_REG(sattr->index);
501 break;
502 case MAX:
503 reg = TEMP_MAX_REG(sattr->index);
504 break;
505 case OFFSET:
506 reg = TEMP_OFFSET_REG(sattr->index);
507 break;
508 case AUTOMIN:
509 reg = TEMP_TMIN_REG(sattr->index);
510 break;
511 case THERM:
512 reg = TEMP_THERM_REG(sattr->index);
513 break;
514 case HYSTERSIS:
515 if (sattr->index != 2)
516 reg = REG_REMOTE1_HYSTERSIS;
517 else
518 reg = REG_REMOTE2_HYSTERSIS;
519
520 break;
521 }
522
523 i2c_smbus_write_byte_data(client, reg, out);
524
525 mutex_unlock(&data->lock);
526 return count;
527}
528
Chris Packham8f05bcc2017-05-15 13:30:28 +1200529/* Assuming CONFIG6[SLOW] is 0 */
530static const int ad7475_st_map[] = {
531 37500, 18800, 12500, 7500, 4700, 3100, 1600, 800,
532};
533
534static ssize_t show_temp_st(struct device *dev, struct device_attribute *attr,
535 char *buf)
536{
537 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
538 struct i2c_client *client = to_i2c_client(dev);
539 struct adt7475_data *data = i2c_get_clientdata(client);
540 long val;
541
542 switch (sattr->index) {
543 case 0:
544 val = data->enh_acoustics[0] & 0xf;
545 break;
546 case 1:
547 val = (data->enh_acoustics[1] >> 4) & 0xf;
548 break;
549 case 2:
550 default:
551 val = data->enh_acoustics[1] & 0xf;
552 break;
553 }
554
555 if (val & 0x8)
556 return sprintf(buf, "%d\n", ad7475_st_map[val & 0x7]);
557 else
558 return sprintf(buf, "0\n");
559}
560
561static ssize_t set_temp_st(struct device *dev, struct device_attribute *attr,
562 const char *buf, size_t count)
563{
564 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
565 struct i2c_client *client = to_i2c_client(dev);
566 struct adt7475_data *data = i2c_get_clientdata(client);
567 unsigned char reg;
568 int shift, idx;
569 ulong val;
570
571 if (kstrtoul(buf, 10, &val))
572 return -EINVAL;
573
574 switch (sattr->index) {
575 case 0:
576 reg = REG_ENHANCE_ACOUSTICS1;
577 shift = 0;
578 idx = 0;
579 break;
580 case 1:
581 reg = REG_ENHANCE_ACOUSTICS2;
582 shift = 0;
583 idx = 1;
584 break;
585 case 2:
586 default:
587 reg = REG_ENHANCE_ACOUSTICS2;
588 shift = 4;
589 idx = 1;
590 break;
591 }
592
593 if (val > 0) {
594 val = find_closest_descending(val, ad7475_st_map,
595 ARRAY_SIZE(ad7475_st_map));
596 val |= 0x8;
597 }
598
599 mutex_lock(&data->lock);
600
601 data->enh_acoustics[idx] &= ~(0xf << shift);
602 data->enh_acoustics[idx] |= (val << shift);
603
604 i2c_smbus_write_byte_data(client, reg, data->enh_acoustics[idx]);
605
606 mutex_unlock(&data->lock);
607
608 return count;
609}
610
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800611/*
612 * Table of autorange values - the user will write the value in millidegrees,
613 * and we'll convert it
614 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100615static const int autorange_table[] = {
616 2000, 2500, 3330, 4000, 5000, 6670, 8000,
617 10000, 13330, 16000, 20000, 26670, 32000, 40000,
618 53330, 80000
619};
620
621static ssize_t show_point2(struct device *dev, struct device_attribute *attr,
622 char *buf)
623{
624 struct adt7475_data *data = adt7475_update_device(dev);
625 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
626 int out, val;
627
628 mutex_lock(&data->lock);
629 out = (data->range[sattr->index] >> 4) & 0x0F;
630 val = reg2temp(data, data->temp[AUTOMIN][sattr->index]);
631 mutex_unlock(&data->lock);
632
633 return sprintf(buf, "%d\n", val + autorange_table[out]);
634}
635
636static ssize_t set_point2(struct device *dev, struct device_attribute *attr,
637 const char *buf, size_t count)
638{
639 struct i2c_client *client = to_i2c_client(dev);
640 struct adt7475_data *data = i2c_get_clientdata(client);
641 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
642 int temp;
643 long val;
644
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100645 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100646 return -EINVAL;
647
648 mutex_lock(&data->lock);
649
650 /* Get a fresh copy of the needed registers */
651 data->config5 = adt7475_read(REG_CONFIG5);
652 data->temp[AUTOMIN][sattr->index] =
653 adt7475_read(TEMP_TMIN_REG(sattr->index)) << 2;
654 data->range[sattr->index] =
655 adt7475_read(TEMP_TRANGE_REG(sattr->index));
656
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800657 /*
658 * The user will write an absolute value, so subtract the start point
659 * to figure the range
660 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100661 temp = reg2temp(data, data->temp[AUTOMIN][sattr->index]);
Guenter Roeck2a844c12013-01-09 08:09:34 -0800662 val = clamp_val(val, temp + autorange_table[0],
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100663 temp + autorange_table[ARRAY_SIZE(autorange_table) - 1]);
664 val -= temp;
665
666 /* Find the nearest table entry to what the user wrote */
Chris Packhame4651642017-05-11 15:45:21 +1200667 val = find_closest(val, autorange_table, ARRAY_SIZE(autorange_table));
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100668
669 data->range[sattr->index] &= ~0xF0;
670 data->range[sattr->index] |= val << 4;
671
672 i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),
673 data->range[sattr->index]);
674
675 mutex_unlock(&data->lock);
676 return count;
677}
678
679static ssize_t show_tach(struct device *dev, struct device_attribute *attr,
680 char *buf)
681{
682 struct adt7475_data *data = adt7475_update_device(dev);
683 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
684 int out;
685
686 if (sattr->nr == ALARM)
687 out = (data->alarms >> (sattr->index + 10)) & 1;
688 else
689 out = tach2rpm(data->tach[sattr->nr][sattr->index]);
690
691 return sprintf(buf, "%d\n", out);
692}
693
694static ssize_t set_tach(struct device *dev, struct device_attribute *attr,
695 const char *buf, size_t count)
696{
697
698 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
699 struct i2c_client *client = to_i2c_client(dev);
700 struct adt7475_data *data = i2c_get_clientdata(client);
701 unsigned long val;
702
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100703 if (kstrtoul(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100704 return -EINVAL;
705
706 mutex_lock(&data->lock);
707
708 data->tach[MIN][sattr->index] = rpm2tach(val);
709
710 adt7475_write_word(client, TACH_MIN_REG(sattr->index),
711 data->tach[MIN][sattr->index]);
712
713 mutex_unlock(&data->lock);
714 return count;
715}
716
717static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
718 char *buf)
719{
720 struct adt7475_data *data = adt7475_update_device(dev);
721 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
722
723 return sprintf(buf, "%d\n", data->pwm[sattr->nr][sattr->index]);
724}
725
726static ssize_t show_pwmchan(struct device *dev, struct device_attribute *attr,
727 char *buf)
728{
729 struct adt7475_data *data = adt7475_update_device(dev);
730 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
731
732 return sprintf(buf, "%d\n", data->pwmchan[sattr->index]);
733}
734
735static ssize_t show_pwmctrl(struct device *dev, struct device_attribute *attr,
736 char *buf)
737{
738 struct adt7475_data *data = adt7475_update_device(dev);
739 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
740
741 return sprintf(buf, "%d\n", data->pwmctl[sattr->index]);
742}
743
744static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
745 const char *buf, size_t count)
746{
747
748 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
749 struct i2c_client *client = to_i2c_client(dev);
750 struct adt7475_data *data = i2c_get_clientdata(client);
751 unsigned char reg = 0;
752 long val;
753
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100754 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100755 return -EINVAL;
756
757 mutex_lock(&data->lock);
758
759 switch (sattr->nr) {
760 case INPUT:
761 /* Get a fresh value for CONTROL */
762 data->pwm[CONTROL][sattr->index] =
763 adt7475_read(PWM_CONFIG_REG(sattr->index));
764
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800765 /*
766 * If we are not in manual mode, then we shouldn't allow
767 * the user to set the pwm speed
768 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100769 if (((data->pwm[CONTROL][sattr->index] >> 5) & 7) != 7) {
770 mutex_unlock(&data->lock);
771 return count;
772 }
773
774 reg = PWM_REG(sattr->index);
775 break;
776
777 case MIN:
778 reg = PWM_MIN_REG(sattr->index);
779 break;
780
781 case MAX:
782 reg = PWM_MAX_REG(sattr->index);
783 break;
784 }
785
Guenter Roeck2a844c12013-01-09 08:09:34 -0800786 data->pwm[sattr->nr][sattr->index] = clamp_val(val, 0, 0xFF);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100787 i2c_smbus_write_byte_data(client, reg,
788 data->pwm[sattr->nr][sattr->index]);
Chris Packham1d58f5e2017-05-15 13:30:27 +1200789 mutex_unlock(&data->lock);
790
791 return count;
792}
793
794static ssize_t show_stall_disable(struct device *dev,
795 struct device_attribute *attr, char *buf)
796{
797 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
798 struct i2c_client *client = to_i2c_client(dev);
799 struct adt7475_data *data = i2c_get_clientdata(client);
800 u8 mask = BIT(5 + sattr->index);
801
802 return sprintf(buf, "%d\n", !!(data->enh_acoustics[0] & mask));
803}
804
805static ssize_t set_stall_disable(struct device *dev,
806 struct device_attribute *attr, const char *buf,
807 size_t count)
808{
809 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
810 struct i2c_client *client = to_i2c_client(dev);
811 struct adt7475_data *data = i2c_get_clientdata(client);
812 long val;
813 u8 mask = BIT(5 + sattr->index);
814
815 if (kstrtol(buf, 10, &val))
816 return -EINVAL;
817
818 mutex_lock(&data->lock);
819
820 data->enh_acoustics[0] &= ~mask;
821 if (val)
822 data->enh_acoustics[0] |= mask;
823
824 i2c_smbus_write_byte_data(client, REG_ENHANCE_ACOUSTICS1,
825 data->enh_acoustics[0]);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100826
827 mutex_unlock(&data->lock);
828
829 return count;
830}
831
832/* Called by set_pwmctrl and set_pwmchan */
833
834static int hw_set_pwm(struct i2c_client *client, int index,
835 unsigned int pwmctl, unsigned int pwmchan)
836{
837 struct adt7475_data *data = i2c_get_clientdata(client);
838 long val = 0;
839
840 switch (pwmctl) {
841 case 0:
842 val = 0x03; /* Run at full speed */
843 break;
844 case 1:
845 val = 0x07; /* Manual mode */
846 break;
847 case 2:
848 switch (pwmchan) {
849 case 1:
850 /* Remote1 controls PWM */
851 val = 0x00;
852 break;
853 case 2:
854 /* local controls PWM */
855 val = 0x01;
856 break;
857 case 4:
858 /* remote2 controls PWM */
859 val = 0x02;
860 break;
861 case 6:
862 /* local/remote2 control PWM */
863 val = 0x05;
864 break;
865 case 7:
866 /* All three control PWM */
867 val = 0x06;
868 break;
869 default:
870 return -EINVAL;
871 }
872 break;
873 default:
874 return -EINVAL;
875 }
876
877 data->pwmctl[index] = pwmctl;
878 data->pwmchan[index] = pwmchan;
879
880 data->pwm[CONTROL][index] &= ~0xE0;
881 data->pwm[CONTROL][index] |= (val & 7) << 5;
882
883 i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index),
884 data->pwm[CONTROL][index]);
885
886 return 0;
887}
888
889static ssize_t set_pwmchan(struct device *dev, struct device_attribute *attr,
890 const char *buf, size_t count)
891{
892 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
893 struct i2c_client *client = to_i2c_client(dev);
894 struct adt7475_data *data = i2c_get_clientdata(client);
895 int r;
896 long val;
897
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100898 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100899 return -EINVAL;
900
901 mutex_lock(&data->lock);
902 /* Read Modify Write PWM values */
903 adt7475_read_pwm(client, sattr->index);
904 r = hw_set_pwm(client, sattr->index, data->pwmctl[sattr->index], val);
905 if (r)
906 count = r;
907 mutex_unlock(&data->lock);
908
909 return count;
910}
911
912static ssize_t set_pwmctrl(struct device *dev, struct device_attribute *attr,
913 const char *buf, size_t count)
914{
915 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
916 struct i2c_client *client = to_i2c_client(dev);
917 struct adt7475_data *data = i2c_get_clientdata(client);
918 int r;
919 long val;
920
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100921 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100922 return -EINVAL;
923
924 mutex_lock(&data->lock);
925 /* Read Modify Write PWM values */
926 adt7475_read_pwm(client, sattr->index);
927 r = hw_set_pwm(client, sattr->index, val, data->pwmchan[sattr->index]);
928 if (r)
929 count = r;
930 mutex_unlock(&data->lock);
931
932 return count;
933}
934
935/* List of frequencies for the PWM */
936static const int pwmfreq_table[] = {
Chris Packham3490c922017-05-15 13:30:29 +1200937 11, 14, 22, 29, 35, 44, 58, 88, 22500
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100938};
939
940static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
941 char *buf)
942{
943 struct adt7475_data *data = adt7475_update_device(dev);
944 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
Chris Packham3490c922017-05-15 13:30:29 +1200945 int i = clamp_val(data->range[sattr->index] & 0xf, 0,
946 ARRAY_SIZE(pwmfreq_table) - 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100947
Chris Packham3490c922017-05-15 13:30:29 +1200948 return sprintf(buf, "%d\n", pwmfreq_table[i]);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100949}
950
951static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
952 const char *buf, size_t count)
953{
954 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
955 struct i2c_client *client = to_i2c_client(dev);
956 struct adt7475_data *data = i2c_get_clientdata(client);
957 int out;
958 long val;
959
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100960 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100961 return -EINVAL;
962
Chris Packhame4651642017-05-11 15:45:21 +1200963 out = find_closest(val, pwmfreq_table, ARRAY_SIZE(pwmfreq_table));
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100964
965 mutex_lock(&data->lock);
966
967 data->range[sattr->index] =
968 adt7475_read(TEMP_TRANGE_REG(sattr->index));
Chris Packham3490c922017-05-15 13:30:29 +1200969 data->range[sattr->index] &= ~0xf;
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100970 data->range[sattr->index] |= out;
971
972 i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),
973 data->range[sattr->index]);
974
975 mutex_unlock(&data->lock);
976 return count;
977}
978
Julia Lawall1d05303c2016-12-22 13:05:33 +0100979static ssize_t pwm_use_point2_pwm_at_crit_show(struct device *dev,
980 struct device_attribute *devattr,
981 char *buf)
Jean Delvaref99318b2009-12-09 20:36:03 +0100982{
983 struct adt7475_data *data = adt7475_update_device(dev);
984 return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY));
985}
986
Julia Lawall1d05303c2016-12-22 13:05:33 +0100987static ssize_t pwm_use_point2_pwm_at_crit_store(struct device *dev,
988 struct device_attribute *devattr,
989 const char *buf, size_t count)
Jean Delvaref99318b2009-12-09 20:36:03 +0100990{
991 struct i2c_client *client = to_i2c_client(dev);
992 struct adt7475_data *data = i2c_get_clientdata(client);
993 long val;
994
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100995 if (kstrtol(buf, 10, &val))
Jean Delvaref99318b2009-12-09 20:36:03 +0100996 return -EINVAL;
997 if (val != 0 && val != 1)
998 return -EINVAL;
999
1000 mutex_lock(&data->lock);
1001 data->config4 = i2c_smbus_read_byte_data(client, REG_CONFIG4);
1002 if (val)
1003 data->config4 |= CONFIG4_MAXDUTY;
1004 else
1005 data->config4 &= ~CONFIG4_MAXDUTY;
1006 i2c_smbus_write_byte_data(client, REG_CONFIG4, data->config4);
1007 mutex_unlock(&data->lock);
1008
1009 return count;
1010}
1011
Julia Lawall1d05303c2016-12-22 13:05:33 +01001012static ssize_t vrm_show(struct device *dev, struct device_attribute *devattr,
Jean Delvare54fe4672009-12-09 20:36:08 +01001013 char *buf)
1014{
1015 struct adt7475_data *data = dev_get_drvdata(dev);
1016 return sprintf(buf, "%d\n", (int)data->vrm);
1017}
1018
Julia Lawall1d05303c2016-12-22 13:05:33 +01001019static ssize_t vrm_store(struct device *dev, struct device_attribute *devattr,
1020 const char *buf, size_t count)
Jean Delvare54fe4672009-12-09 20:36:08 +01001021{
1022 struct adt7475_data *data = dev_get_drvdata(dev);
1023 long val;
1024
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001025 if (kstrtol(buf, 10, &val))
Jean Delvare54fe4672009-12-09 20:36:08 +01001026 return -EINVAL;
1027 if (val < 0 || val > 255)
1028 return -EINVAL;
1029 data->vrm = val;
1030
1031 return count;
1032}
1033
Julia Lawall1d05303c2016-12-22 13:05:33 +01001034static ssize_t cpu0_vid_show(struct device *dev,
1035 struct device_attribute *devattr, char *buf)
Jean Delvare54fe4672009-12-09 20:36:08 +01001036{
1037 struct adt7475_data *data = adt7475_update_device(dev);
1038 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
1039}
1040
Jean Delvare3d849982009-12-09 20:36:05 +01001041static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_voltage, NULL, INPUT, 0);
1042static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_voltage,
1043 set_voltage, MAX, 0);
1044static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_voltage,
1045 set_voltage, MIN, 0);
1046static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, show_voltage, NULL, ALARM, 0);
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001047static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_voltage, NULL, INPUT, 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001048static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_voltage,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001049 set_voltage, MAX, 1);
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001050static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_voltage,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001051 set_voltage, MIN, 1);
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001052static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, show_voltage, NULL, ALARM, 1);
1053static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_voltage, NULL, INPUT, 2);
1054static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_voltage,
1055 set_voltage, MAX, 2);
1056static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_voltage,
1057 set_voltage, MIN, 2);
1058static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_voltage, NULL, ALARM, 2);
Jean Delvare3d849982009-12-09 20:36:05 +01001059static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_voltage, NULL, INPUT, 3);
1060static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_voltage,
1061 set_voltage, MAX, 3);
1062static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_voltage,
1063 set_voltage, MIN, 3);
1064static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, show_voltage, NULL, ALARM, 3);
1065static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_voltage, NULL, INPUT, 4);
1066static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_voltage,
1067 set_voltage, MAX, 4);
1068static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_voltage,
1069 set_voltage, MIN, 4);
1070static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, show_voltage, NULL, ALARM, 8);
1071static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_voltage, NULL, INPUT, 5);
1072static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_voltage,
1073 set_voltage, MAX, 5);
1074static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_voltage,
1075 set_voltage, MIN, 5);
1076static SENSOR_DEVICE_ATTR_2(in5_alarm, S_IRUGO, show_voltage, NULL, ALARM, 31);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001077static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, INPUT, 0);
1078static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, show_temp, NULL, ALARM, 0);
1079static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_temp, NULL, FAULT, 0);
1080static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1081 MAX, 0);
1082static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1083 MIN, 0);
1084static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
1085 set_temp, OFFSET, 0);
1086static SENSOR_DEVICE_ATTR_2(temp1_auto_point1_temp, S_IRUGO | S_IWUSR,
1087 show_temp, set_temp, AUTOMIN, 0);
1088static SENSOR_DEVICE_ATTR_2(temp1_auto_point2_temp, S_IRUGO | S_IWUSR,
1089 show_point2, set_point2, 0, 0);
1090static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
1091 THERM, 0);
1092static SENSOR_DEVICE_ATTR_2(temp1_crit_hyst, S_IRUGO | S_IWUSR, show_temp,
1093 set_temp, HYSTERSIS, 0);
Chris Packham8f05bcc2017-05-15 13:30:28 +12001094static SENSOR_DEVICE_ATTR_2(temp1_smoothing, S_IRUGO | S_IWUSR, show_temp_st,
1095 set_temp_st, 0, 0);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001096static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, INPUT, 1);
1097static SENSOR_DEVICE_ATTR_2(temp2_alarm, S_IRUGO, show_temp, NULL, ALARM, 1);
1098static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1099 MAX, 1);
1100static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1101 MIN, 1);
1102static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
1103 set_temp, OFFSET, 1);
1104static SENSOR_DEVICE_ATTR_2(temp2_auto_point1_temp, S_IRUGO | S_IWUSR,
1105 show_temp, set_temp, AUTOMIN, 1);
1106static SENSOR_DEVICE_ATTR_2(temp2_auto_point2_temp, S_IRUGO | S_IWUSR,
1107 show_point2, set_point2, 0, 1);
1108static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
1109 THERM, 1);
1110static SENSOR_DEVICE_ATTR_2(temp2_crit_hyst, S_IRUGO | S_IWUSR, show_temp,
1111 set_temp, HYSTERSIS, 1);
Chris Packham8f05bcc2017-05-15 13:30:28 +12001112static SENSOR_DEVICE_ATTR_2(temp2_smoothing, S_IRUGO | S_IWUSR, show_temp_st,
1113 set_temp_st, 0, 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001114static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, INPUT, 2);
1115static SENSOR_DEVICE_ATTR_2(temp3_alarm, S_IRUGO, show_temp, NULL, ALARM, 2);
1116static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_temp, NULL, FAULT, 2);
1117static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1118 MAX, 2);
1119static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1120 MIN, 2);
1121static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
1122 set_temp, OFFSET, 2);
1123static SENSOR_DEVICE_ATTR_2(temp3_auto_point1_temp, S_IRUGO | S_IWUSR,
1124 show_temp, set_temp, AUTOMIN, 2);
1125static SENSOR_DEVICE_ATTR_2(temp3_auto_point2_temp, S_IRUGO | S_IWUSR,
1126 show_point2, set_point2, 0, 2);
1127static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
1128 THERM, 2);
1129static SENSOR_DEVICE_ATTR_2(temp3_crit_hyst, S_IRUGO | S_IWUSR, show_temp,
1130 set_temp, HYSTERSIS, 2);
Chris Packham8f05bcc2017-05-15 13:30:28 +12001131static SENSOR_DEVICE_ATTR_2(temp3_smoothing, S_IRUGO | S_IWUSR, show_temp_st,
1132 set_temp_st, 0, 2);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001133static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_tach, NULL, INPUT, 0);
1134static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
1135 MIN, 0);
1136static SENSOR_DEVICE_ATTR_2(fan1_alarm, S_IRUGO, show_tach, NULL, ALARM, 0);
1137static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_tach, NULL, INPUT, 1);
1138static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
1139 MIN, 1);
1140static SENSOR_DEVICE_ATTR_2(fan2_alarm, S_IRUGO, show_tach, NULL, ALARM, 1);
1141static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_tach, NULL, INPUT, 2);
1142static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
1143 MIN, 2);
1144static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_tach, NULL, ALARM, 2);
1145static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_tach, NULL, INPUT, 3);
1146static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
1147 MIN, 3);
1148static SENSOR_DEVICE_ATTR_2(fan4_alarm, S_IRUGO, show_tach, NULL, ALARM, 3);
1149static SENSOR_DEVICE_ATTR_2(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT,
1150 0);
1151static SENSOR_DEVICE_ATTR_2(pwm1_freq, S_IRUGO | S_IWUSR, show_pwmfreq,
1152 set_pwmfreq, INPUT, 0);
1153static SENSOR_DEVICE_ATTR_2(pwm1_enable, S_IRUGO | S_IWUSR, show_pwmctrl,
1154 set_pwmctrl, INPUT, 0);
Jean Delvare84d2a312009-11-16 12:45:40 +01001155static SENSOR_DEVICE_ATTR_2(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001156 show_pwmchan, set_pwmchan, INPUT, 0);
1157static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
1158 set_pwm, MIN, 0);
1159static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
1160 set_pwm, MAX, 0);
Chris Packham1d58f5e2017-05-15 13:30:27 +12001161static SENSOR_DEVICE_ATTR_2(pwm1_stall_disable, S_IRUGO | S_IWUSR,
1162 show_stall_disable, set_stall_disable, 0, 0);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001163static SENSOR_DEVICE_ATTR_2(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT,
1164 1);
1165static SENSOR_DEVICE_ATTR_2(pwm2_freq, S_IRUGO | S_IWUSR, show_pwmfreq,
1166 set_pwmfreq, INPUT, 1);
1167static SENSOR_DEVICE_ATTR_2(pwm2_enable, S_IRUGO | S_IWUSR, show_pwmctrl,
1168 set_pwmctrl, INPUT, 1);
Jean Delvare84d2a312009-11-16 12:45:40 +01001169static SENSOR_DEVICE_ATTR_2(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001170 show_pwmchan, set_pwmchan, INPUT, 1);
1171static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
1172 set_pwm, MIN, 1);
1173static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
1174 set_pwm, MAX, 1);
Chris Packham1d58f5e2017-05-15 13:30:27 +12001175static SENSOR_DEVICE_ATTR_2(pwm2_stall_disable, S_IRUGO | S_IWUSR,
1176 show_stall_disable, set_stall_disable, 0, 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001177static SENSOR_DEVICE_ATTR_2(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT,
1178 2);
1179static SENSOR_DEVICE_ATTR_2(pwm3_freq, S_IRUGO | S_IWUSR, show_pwmfreq,
1180 set_pwmfreq, INPUT, 2);
1181static SENSOR_DEVICE_ATTR_2(pwm3_enable, S_IRUGO | S_IWUSR, show_pwmctrl,
1182 set_pwmctrl, INPUT, 2);
Jean Delvare84d2a312009-11-16 12:45:40 +01001183static SENSOR_DEVICE_ATTR_2(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001184 show_pwmchan, set_pwmchan, INPUT, 2);
1185static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
1186 set_pwm, MIN, 2);
1187static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
1188 set_pwm, MAX, 2);
Chris Packham1d58f5e2017-05-15 13:30:27 +12001189static SENSOR_DEVICE_ATTR_2(pwm3_stall_disable, S_IRUGO | S_IWUSR,
1190 show_stall_disable, set_stall_disable, 0, 2);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001191
Jean Delvaref99318b2009-12-09 20:36:03 +01001192/* Non-standard name, might need revisiting */
Julia Lawall1d05303c2016-12-22 13:05:33 +01001193static DEVICE_ATTR_RW(pwm_use_point2_pwm_at_crit);
Jean Delvaref99318b2009-12-09 20:36:03 +01001194
Julia Lawall1d05303c2016-12-22 13:05:33 +01001195static DEVICE_ATTR_RW(vrm);
1196static DEVICE_ATTR_RO(cpu0_vid);
Jean Delvare54fe4672009-12-09 20:36:08 +01001197
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001198static struct attribute *adt7475_attrs[] = {
1199 &sensor_dev_attr_in1_input.dev_attr.attr,
1200 &sensor_dev_attr_in1_max.dev_attr.attr,
1201 &sensor_dev_attr_in1_min.dev_attr.attr,
1202 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1203 &sensor_dev_attr_in2_input.dev_attr.attr,
1204 &sensor_dev_attr_in2_max.dev_attr.attr,
1205 &sensor_dev_attr_in2_min.dev_attr.attr,
1206 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1207 &sensor_dev_attr_temp1_input.dev_attr.attr,
1208 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1209 &sensor_dev_attr_temp1_fault.dev_attr.attr,
1210 &sensor_dev_attr_temp1_max.dev_attr.attr,
1211 &sensor_dev_attr_temp1_min.dev_attr.attr,
1212 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1213 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
1214 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
1215 &sensor_dev_attr_temp1_crit.dev_attr.attr,
1216 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
Chris Packham8f05bcc2017-05-15 13:30:28 +12001217 &sensor_dev_attr_temp1_smoothing.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001218 &sensor_dev_attr_temp2_input.dev_attr.attr,
1219 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1220 &sensor_dev_attr_temp2_max.dev_attr.attr,
1221 &sensor_dev_attr_temp2_min.dev_attr.attr,
1222 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1223 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
1224 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
1225 &sensor_dev_attr_temp2_crit.dev_attr.attr,
1226 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
Chris Packham8f05bcc2017-05-15 13:30:28 +12001227 &sensor_dev_attr_temp2_smoothing.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001228 &sensor_dev_attr_temp3_input.dev_attr.attr,
1229 &sensor_dev_attr_temp3_fault.dev_attr.attr,
1230 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1231 &sensor_dev_attr_temp3_max.dev_attr.attr,
1232 &sensor_dev_attr_temp3_min.dev_attr.attr,
1233 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1234 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
1235 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
1236 &sensor_dev_attr_temp3_crit.dev_attr.attr,
1237 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
Chris Packham8f05bcc2017-05-15 13:30:28 +12001238 &sensor_dev_attr_temp3_smoothing.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001239 &sensor_dev_attr_fan1_input.dev_attr.attr,
1240 &sensor_dev_attr_fan1_min.dev_attr.attr,
1241 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1242 &sensor_dev_attr_fan2_input.dev_attr.attr,
1243 &sensor_dev_attr_fan2_min.dev_attr.attr,
1244 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1245 &sensor_dev_attr_fan3_input.dev_attr.attr,
1246 &sensor_dev_attr_fan3_min.dev_attr.attr,
1247 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001248 &sensor_dev_attr_pwm1.dev_attr.attr,
1249 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1250 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
Jean Delvare84d2a312009-11-16 12:45:40 +01001251 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001252 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1253 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
Chris Packham1d58f5e2017-05-15 13:30:27 +12001254 &sensor_dev_attr_pwm1_stall_disable.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001255 &sensor_dev_attr_pwm3.dev_attr.attr,
1256 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
1257 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
Jean Delvare84d2a312009-11-16 12:45:40 +01001258 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001259 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1260 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
Chris Packham1d58f5e2017-05-15 13:30:27 +12001261 &sensor_dev_attr_pwm3_stall_disable.dev_attr.attr,
Jean Delvaref99318b2009-12-09 20:36:03 +01001262 &dev_attr_pwm_use_point2_pwm_at_crit.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001263 NULL,
1264};
1265
Jean Delvare378933c2009-12-09 20:36:06 +01001266static struct attribute *fan4_attrs[] = {
1267 &sensor_dev_attr_fan4_input.dev_attr.attr,
1268 &sensor_dev_attr_fan4_min.dev_attr.attr,
1269 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1270 NULL
1271};
1272
1273static struct attribute *pwm2_attrs[] = {
1274 &sensor_dev_attr_pwm2.dev_attr.attr,
1275 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1276 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1277 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1278 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1279 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
Chris Packham1d58f5e2017-05-15 13:30:27 +12001280 &sensor_dev_attr_pwm2_stall_disable.dev_attr.attr,
Jean Delvare378933c2009-12-09 20:36:06 +01001281 NULL
1282};
1283
Jean Delvare378933c2009-12-09 20:36:06 +01001284static struct attribute *in0_attrs[] = {
Jean Delvare3d849982009-12-09 20:36:05 +01001285 &sensor_dev_attr_in0_input.dev_attr.attr,
1286 &sensor_dev_attr_in0_max.dev_attr.attr,
1287 &sensor_dev_attr_in0_min.dev_attr.attr,
1288 &sensor_dev_attr_in0_alarm.dev_attr.attr,
Jean Delvare378933c2009-12-09 20:36:06 +01001289 NULL
1290};
1291
Jean Delvared8d2ee02009-12-09 20:36:08 +01001292static struct attribute *in3_attrs[] = {
Jean Delvare3d849982009-12-09 20:36:05 +01001293 &sensor_dev_attr_in3_input.dev_attr.attr,
1294 &sensor_dev_attr_in3_max.dev_attr.attr,
1295 &sensor_dev_attr_in3_min.dev_attr.attr,
1296 &sensor_dev_attr_in3_alarm.dev_attr.attr,
Jean Delvared8d2ee02009-12-09 20:36:08 +01001297 NULL
1298};
1299
1300static struct attribute *in4_attrs[] = {
Jean Delvare3d849982009-12-09 20:36:05 +01001301 &sensor_dev_attr_in4_input.dev_attr.attr,
1302 &sensor_dev_attr_in4_max.dev_attr.attr,
1303 &sensor_dev_attr_in4_min.dev_attr.attr,
1304 &sensor_dev_attr_in4_alarm.dev_attr.attr,
Jean Delvared8d2ee02009-12-09 20:36:08 +01001305 NULL
1306};
1307
1308static struct attribute *in5_attrs[] = {
Jean Delvare3d849982009-12-09 20:36:05 +01001309 &sensor_dev_attr_in5_input.dev_attr.attr,
1310 &sensor_dev_attr_in5_max.dev_attr.attr,
1311 &sensor_dev_attr_in5_min.dev_attr.attr,
1312 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1313 NULL
1314};
1315
Jean Delvare54fe4672009-12-09 20:36:08 +01001316static struct attribute *vid_attrs[] = {
1317 &dev_attr_cpu0_vid.attr,
1318 &dev_attr_vrm.attr,
1319 NULL
1320};
1321
Arvind Yadavf5397be2017-07-05 11:04:04 +05301322static const struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs };
1323static const struct attribute_group fan4_attr_group = { .attrs = fan4_attrs };
1324static const struct attribute_group pwm2_attr_group = { .attrs = pwm2_attrs };
1325static const struct attribute_group in0_attr_group = { .attrs = in0_attrs };
1326static const struct attribute_group in3_attr_group = { .attrs = in3_attrs };
1327static const struct attribute_group in4_attr_group = { .attrs = in4_attrs };
1328static const struct attribute_group in5_attr_group = { .attrs = in5_attrs };
1329static const struct attribute_group vid_attr_group = { .attrs = vid_attrs };
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001330
Jean Delvare310ec792009-12-14 21:17:23 +01001331static int adt7475_detect(struct i2c_client *client,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001332 struct i2c_board_info *info)
1333{
1334 struct i2c_adapter *adapter = client->adapter;
Jean Delvared656b6f2009-12-09 20:36:04 +01001335 int vendid, devid, devid2;
Jean Delvareb180d052009-12-09 20:36:02 +01001336 const char *name;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001337
1338 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1339 return -ENODEV;
1340
Jean Delvareb180d052009-12-09 20:36:02 +01001341 vendid = adt7475_read(REG_VENDID);
Jean Delvared656b6f2009-12-09 20:36:04 +01001342 devid2 = adt7475_read(REG_DEVID2);
1343 if (vendid != 0x41 || /* Analog Devices */
1344 (devid2 & 0xf8) != 0x68)
1345 return -ENODEV;
Jean Delvareb180d052009-12-09 20:36:02 +01001346
Jean Delvared656b6f2009-12-09 20:36:04 +01001347 devid = adt7475_read(REG_DEVID);
1348 if (devid == 0x73)
Jean Delvareb180d052009-12-09 20:36:02 +01001349 name = "adt7473";
Jean Delvared656b6f2009-12-09 20:36:04 +01001350 else if (devid == 0x75 && client->addr == 0x2e)
Jean Delvareb180d052009-12-09 20:36:02 +01001351 name = "adt7475";
Jean Delvared8d2ee02009-12-09 20:36:08 +01001352 else if (devid == 0x76)
1353 name = "adt7476";
Jean Delvare3d849982009-12-09 20:36:05 +01001354 else if ((devid2 & 0xfc) == 0x6c)
1355 name = "adt7490";
Jean Delvareb180d052009-12-09 20:36:02 +01001356 else {
1357 dev_dbg(&adapter->dev,
Jean Delvared8d2ee02009-12-09 20:36:08 +01001358 "Couldn't detect an ADT7473/75/76/90 part at "
Jean Delvareb180d052009-12-09 20:36:02 +01001359 "0x%02x\n", (unsigned int)client->addr);
Jean Delvare52df6442009-12-09 20:35:57 +01001360 return -ENODEV;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001361 }
1362
Jean Delvareb180d052009-12-09 20:36:02 +01001363 strlcpy(info->type, name, I2C_NAME_SIZE);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001364
1365 return 0;
1366}
1367
Jean Delvare0f144802009-12-09 20:36:06 +01001368static void adt7475_remove_files(struct i2c_client *client,
1369 struct adt7475_data *data)
1370{
1371 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group);
Jean Delvare378933c2009-12-09 20:36:06 +01001372 if (data->has_fan4)
1373 sysfs_remove_group(&client->dev.kobj, &fan4_attr_group);
1374 if (data->has_pwm2)
1375 sysfs_remove_group(&client->dev.kobj, &pwm2_attr_group);
1376 if (data->has_voltage & (1 << 0))
1377 sysfs_remove_group(&client->dev.kobj, &in0_attr_group);
Jean Delvared8d2ee02009-12-09 20:36:08 +01001378 if (data->has_voltage & (1 << 3))
1379 sysfs_remove_group(&client->dev.kobj, &in3_attr_group);
1380 if (data->has_voltage & (1 << 4))
1381 sysfs_remove_group(&client->dev.kobj, &in4_attr_group);
1382 if (data->has_voltage & (1 << 5))
1383 sysfs_remove_group(&client->dev.kobj, &in5_attr_group);
Jean Delvare54fe4672009-12-09 20:36:08 +01001384 if (data->has_vid)
1385 sysfs_remove_group(&client->dev.kobj, &vid_attr_group);
Jean Delvare0f144802009-12-09 20:36:06 +01001386}
1387
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001388static int adt7475_probe(struct i2c_client *client,
1389 const struct i2c_device_id *id)
1390{
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -03001391 enum chips chip;
Frans Meulenbroeks99b8c832012-01-08 19:34:08 +01001392 static const char * const names[] = {
Jean Delvared07ca4a2009-12-09 20:36:07 +01001393 [adt7473] = "ADT7473",
1394 [adt7475] = "ADT7475",
Jean Delvared8d2ee02009-12-09 20:36:08 +01001395 [adt7476] = "ADT7476",
Jean Delvared07ca4a2009-12-09 20:36:07 +01001396 [adt7490] = "ADT7490",
1397 };
1398
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001399 struct adt7475_data *data;
Jean Delvare378933c2009-12-09 20:36:06 +01001400 int i, ret = 0, revision;
Jean Delvareebfaf1f2009-12-09 20:36:07 +01001401 u8 config2, config3;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001402
Guenter Roecke3ecb2e2012-06-02 09:58:01 -07001403 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001404 if (data == NULL)
1405 return -ENOMEM;
1406
1407 mutex_init(&data->lock);
1408 i2c_set_clientdata(client, data);
1409
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -03001410 if (client->dev.of_node)
1411 chip = (enum chips)of_device_get_match_data(&client->dev);
1412 else
1413 chip = id->driver_data;
1414
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001415 /* Initialize device-specific values */
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -03001416 switch (chip) {
Jean Delvared8d2ee02009-12-09 20:36:08 +01001417 case adt7476:
1418 data->has_voltage = 0x0e; /* in1 to in3 */
1419 revision = adt7475_read(REG_DEVID2) & 0x07;
1420 break;
Jean Delvare3d849982009-12-09 20:36:05 +01001421 case adt7490:
Jean Delvare378933c2009-12-09 20:36:06 +01001422 data->has_voltage = 0x3e; /* in1 to in5 */
1423 revision = adt7475_read(REG_DEVID2) & 0x03;
Jean Delvared07ca4a2009-12-09 20:36:07 +01001424 if (revision == 0x03)
1425 revision += adt7475_read(REG_DEVREV2);
Jean Delvare3d849982009-12-09 20:36:05 +01001426 break;
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001427 default:
1428 data->has_voltage = 0x06; /* in1, in2 */
Jean Delvare378933c2009-12-09 20:36:06 +01001429 revision = adt7475_read(REG_DEVID2) & 0x07;
1430 }
1431
1432 config3 = adt7475_read(REG_CONFIG3);
1433 /* Pin PWM2 may alternatively be used for ALERT output */
1434 if (!(config3 & CONFIG3_SMBALERT))
1435 data->has_pwm2 = 1;
1436 /* Meaning of this bit is inverted for the ADT7473-1 */
1437 if (id->driver_data == adt7473 && revision >= 1)
1438 data->has_pwm2 = !data->has_pwm2;
1439
1440 data->config4 = adt7475_read(REG_CONFIG4);
1441 /* Pin TACH4 may alternatively be used for THERM */
1442 if ((data->config4 & CONFIG4_PINFUNC) == 0x0)
1443 data->has_fan4 = 1;
1444
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001445 /*
1446 * THERM configuration is more complex on the ADT7476 and ADT7490,
1447 * because 2 different pins (TACH4 and +2.5 Vin) can be used for
1448 * this function
1449 */
Jean Delvare378933c2009-12-09 20:36:06 +01001450 if (id->driver_data == adt7490) {
1451 if ((data->config4 & CONFIG4_PINFUNC) == 0x1 &&
1452 !(config3 & CONFIG3_THERM))
1453 data->has_fan4 = 1;
Jean Delvared8d2ee02009-12-09 20:36:08 +01001454 }
1455 if (id->driver_data == adt7476 || id->driver_data == adt7490) {
Jean Delvare378933c2009-12-09 20:36:06 +01001456 if (!(config3 & CONFIG3_THERM) ||
1457 (data->config4 & CONFIG4_PINFUNC) == 0x1)
1458 data->has_voltage |= (1 << 0); /* in0 */
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001459 }
1460
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001461 /*
1462 * On the ADT7476, the +12V input pin may instead be used as VID5,
1463 * and VID pins may alternatively be used as GPIO
1464 */
Jean Delvared8d2ee02009-12-09 20:36:08 +01001465 if (id->driver_data == adt7476) {
1466 u8 vid = adt7475_read(REG_VID);
1467 if (!(vid & VID_VIDSEL))
1468 data->has_voltage |= (1 << 4); /* in4 */
Jean Delvare54fe4672009-12-09 20:36:08 +01001469
1470 data->has_vid = !(adt7475_read(REG_CONFIG5) & CONFIG5_VIDGPIO);
Jean Delvared8d2ee02009-12-09 20:36:08 +01001471 }
1472
Jean Delvareebfaf1f2009-12-09 20:36:07 +01001473 /* Voltage attenuators can be bypassed, globally or individually */
1474 config2 = adt7475_read(REG_CONFIG2);
1475 if (config2 & CONFIG2_ATTN) {
1476 data->bypass_attn = (0x3 << 3) | 0x3;
1477 } else {
1478 data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) |
1479 ((data->config4 & CONFIG4_ATTN_IN43) >> 3);
1480 }
1481 data->bypass_attn &= data->has_voltage;
1482
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001483 /*
1484 * Call adt7475_read_pwm for all pwm's as this will reprogram any
1485 * pwm's which are disabled to manual mode with 0% duty cycle
1486 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001487 for (i = 0; i < ADT7475_PWM_COUNT; i++)
1488 adt7475_read_pwm(client, i);
1489
Chris Packham4abdf382017-04-22 07:08:09 +12001490 /* Start monitoring */
1491 switch (chip) {
1492 case adt7475:
1493 case adt7476:
1494 i2c_smbus_write_byte_data(client, REG_CONFIG1,
1495 adt7475_read(REG_CONFIG1) | 0x01);
1496 break;
1497 default:
1498 break;
1499 }
1500
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001501 ret = sysfs_create_group(&client->dev.kobj, &adt7475_attr_group);
1502 if (ret)
Guenter Roecke3ecb2e2012-06-02 09:58:01 -07001503 return ret;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001504
Jean Delvare378933c2009-12-09 20:36:06 +01001505 /* Features that can be disabled individually */
1506 if (data->has_fan4) {
1507 ret = sysfs_create_group(&client->dev.kobj, &fan4_attr_group);
1508 if (ret)
1509 goto eremove;
1510 }
1511 if (data->has_pwm2) {
1512 ret = sysfs_create_group(&client->dev.kobj, &pwm2_attr_group);
1513 if (ret)
1514 goto eremove;
1515 }
1516 if (data->has_voltage & (1 << 0)) {
1517 ret = sysfs_create_group(&client->dev.kobj, &in0_attr_group);
1518 if (ret)
1519 goto eremove;
1520 }
Jean Delvared8d2ee02009-12-09 20:36:08 +01001521 if (data->has_voltage & (1 << 3)) {
1522 ret = sysfs_create_group(&client->dev.kobj, &in3_attr_group);
1523 if (ret)
1524 goto eremove;
1525 }
1526 if (data->has_voltage & (1 << 4)) {
1527 ret = sysfs_create_group(&client->dev.kobj, &in4_attr_group);
1528 if (ret)
1529 goto eremove;
1530 }
1531 if (data->has_voltage & (1 << 5)) {
1532 ret = sysfs_create_group(&client->dev.kobj, &in5_attr_group);
1533 if (ret)
1534 goto eremove;
1535 }
Jean Delvare54fe4672009-12-09 20:36:08 +01001536 if (data->has_vid) {
1537 data->vrm = vid_which_vrm();
1538 ret = sysfs_create_group(&client->dev.kobj, &vid_attr_group);
1539 if (ret)
1540 goto eremove;
1541 }
Jean Delvare378933c2009-12-09 20:36:06 +01001542
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001543 data->hwmon_dev = hwmon_device_register(&client->dev);
1544 if (IS_ERR(data->hwmon_dev)) {
1545 ret = PTR_ERR(data->hwmon_dev);
1546 goto eremove;
1547 }
1548
Jean Delvared07ca4a2009-12-09 20:36:07 +01001549 dev_info(&client->dev, "%s device, revision %d\n",
1550 names[id->driver_data], revision);
Jean Delvared8d2ee02009-12-09 20:36:08 +01001551 if ((data->has_voltage & 0x11) || data->has_fan4 || data->has_pwm2)
Jean Delvare54fe4672009-12-09 20:36:08 +01001552 dev_info(&client->dev, "Optional features:%s%s%s%s%s\n",
Jean Delvared07ca4a2009-12-09 20:36:07 +01001553 (data->has_voltage & (1 << 0)) ? " in0" : "",
Jean Delvared8d2ee02009-12-09 20:36:08 +01001554 (data->has_voltage & (1 << 4)) ? " in4" : "",
Jean Delvared07ca4a2009-12-09 20:36:07 +01001555 data->has_fan4 ? " fan4" : "",
Jean Delvare54fe4672009-12-09 20:36:08 +01001556 data->has_pwm2 ? " pwm2" : "",
1557 data->has_vid ? " vid" : "");
Jean Delvareebfaf1f2009-12-09 20:36:07 +01001558 if (data->bypass_attn)
1559 dev_info(&client->dev, "Bypassing attenuators on:%s%s%s%s\n",
1560 (data->bypass_attn & (1 << 0)) ? " in0" : "",
1561 (data->bypass_attn & (1 << 1)) ? " in1" : "",
1562 (data->bypass_attn & (1 << 3)) ? " in3" : "",
1563 (data->bypass_attn & (1 << 4)) ? " in4" : "");
Jean Delvared07ca4a2009-12-09 20:36:07 +01001564
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001565 return 0;
1566
1567eremove:
Jean Delvare0f144802009-12-09 20:36:06 +01001568 adt7475_remove_files(client, data);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001569 return ret;
1570}
1571
1572static int adt7475_remove(struct i2c_client *client)
1573{
1574 struct adt7475_data *data = i2c_get_clientdata(client);
1575
1576 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare0f144802009-12-09 20:36:06 +01001577 adt7475_remove_files(client, data);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001578
1579 return 0;
1580}
1581
1582static struct i2c_driver adt7475_driver = {
1583 .class = I2C_CLASS_HWMON,
1584 .driver = {
1585 .name = "adt7475",
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -03001586 .of_match_table = of_match_ptr(adt7475_of_match),
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001587 },
1588 .probe = adt7475_probe,
1589 .remove = adt7475_remove,
1590 .id_table = adt7475_id,
1591 .detect = adt7475_detect,
Jean Delvarec3813d62009-12-14 21:17:25 +01001592 .address_list = normal_i2c,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001593};
1594
1595static void adt7475_read_hystersis(struct i2c_client *client)
1596{
1597 struct adt7475_data *data = i2c_get_clientdata(client);
1598
1599 data->temp[HYSTERSIS][0] = (u16) adt7475_read(REG_REMOTE1_HYSTERSIS);
1600 data->temp[HYSTERSIS][1] = data->temp[HYSTERSIS][0];
1601 data->temp[HYSTERSIS][2] = (u16) adt7475_read(REG_REMOTE2_HYSTERSIS);
1602}
1603
1604static void adt7475_read_pwm(struct i2c_client *client, int index)
1605{
1606 struct adt7475_data *data = i2c_get_clientdata(client);
1607 unsigned int v;
1608
1609 data->pwm[CONTROL][index] = adt7475_read(PWM_CONFIG_REG(index));
1610
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001611 /*
1612 * Figure out the internal value for pwmctrl and pwmchan
1613 * based on the current settings
1614 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001615 v = (data->pwm[CONTROL][index] >> 5) & 7;
1616
1617 if (v == 3)
1618 data->pwmctl[index] = 0;
1619 else if (v == 7)
1620 data->pwmctl[index] = 1;
1621 else if (v == 4) {
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001622 /*
1623 * The fan is disabled - we don't want to
1624 * support that, so change to manual mode and
1625 * set the duty cycle to 0 instead
1626 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001627 data->pwm[INPUT][index] = 0;
1628 data->pwm[CONTROL][index] &= ~0xE0;
1629 data->pwm[CONTROL][index] |= (7 << 5);
1630
1631 i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index),
1632 data->pwm[INPUT][index]);
1633
1634 i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index),
1635 data->pwm[CONTROL][index]);
1636
1637 data->pwmctl[index] = 1;
1638 } else {
1639 data->pwmctl[index] = 2;
1640
1641 switch (v) {
1642 case 0:
1643 data->pwmchan[index] = 1;
1644 break;
1645 case 1:
1646 data->pwmchan[index] = 2;
1647 break;
1648 case 2:
1649 data->pwmchan[index] = 4;
1650 break;
1651 case 5:
1652 data->pwmchan[index] = 6;
1653 break;
1654 case 6:
1655 data->pwmchan[index] = 7;
1656 break;
1657 }
1658 }
1659}
1660
1661static struct adt7475_data *adt7475_update_device(struct device *dev)
1662{
1663 struct i2c_client *client = to_i2c_client(dev);
1664 struct adt7475_data *data = i2c_get_clientdata(client);
Jean Delvare3d849982009-12-09 20:36:05 +01001665 u16 ext;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001666 int i;
1667
1668 mutex_lock(&data->lock);
1669
1670 /* Measurement values update every 2 seconds */
1671 if (time_after(jiffies, data->measure_updated + HZ * 2) ||
1672 !data->valid) {
1673 data->alarms = adt7475_read(REG_STATUS2) << 8;
1674 data->alarms |= adt7475_read(REG_STATUS1);
1675
Jean Delvare3d849982009-12-09 20:36:05 +01001676 ext = (adt7475_read(REG_EXTEND2) << 8) |
1677 adt7475_read(REG_EXTEND1);
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001678 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
1679 if (!(data->has_voltage & (1 << i)))
1680 continue;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001681 data->voltage[INPUT][i] =
1682 (adt7475_read(VOLTAGE_REG(i)) << 2) |
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001683 ((ext >> (i * 2)) & 3);
1684 }
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001685
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001686 for (i = 0; i < ADT7475_TEMP_COUNT; i++)
1687 data->temp[INPUT][i] =
1688 (adt7475_read(TEMP_REG(i)) << 2) |
Jean Delvare3d849982009-12-09 20:36:05 +01001689 ((ext >> ((i + 5) * 2)) & 3);
1690
1691 if (data->has_voltage & (1 << 5)) {
1692 data->alarms |= adt7475_read(REG_STATUS4) << 24;
1693 ext = adt7475_read(REG_EXTEND3);
1694 data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 |
1695 ((ext >> 4) & 3);
1696 }
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001697
Jean Delvare378933c2009-12-09 20:36:06 +01001698 for (i = 0; i < ADT7475_TACH_COUNT; i++) {
1699 if (i == 3 && !data->has_fan4)
1700 continue;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001701 data->tach[INPUT][i] =
1702 adt7475_read_word(client, TACH_REG(i));
Jean Delvare378933c2009-12-09 20:36:06 +01001703 }
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001704
1705 /* Updated by hw when in auto mode */
Jean Delvare378933c2009-12-09 20:36:06 +01001706 for (i = 0; i < ADT7475_PWM_COUNT; i++) {
1707 if (i == 1 && !data->has_pwm2)
1708 continue;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001709 data->pwm[INPUT][i] = adt7475_read(PWM_REG(i));
Jean Delvare378933c2009-12-09 20:36:06 +01001710 }
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001711
Jean Delvare54fe4672009-12-09 20:36:08 +01001712 if (data->has_vid)
1713 data->vid = adt7475_read(REG_VID) & 0x3f;
1714
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001715 data->measure_updated = jiffies;
1716 }
1717
1718 /* Limits and settings, should never change update every 60 seconds */
Jean Delvare56e35ee2009-11-16 12:45:40 +01001719 if (time_after(jiffies, data->limits_updated + HZ * 60) ||
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001720 !data->valid) {
Jean Delvaref99318b2009-12-09 20:36:03 +01001721 data->config4 = adt7475_read(REG_CONFIG4);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001722 data->config5 = adt7475_read(REG_CONFIG5);
1723
1724 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001725 if (!(data->has_voltage & (1 << i)))
1726 continue;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001727 /* Adjust values so they match the input precision */
1728 data->voltage[MIN][i] =
1729 adt7475_read(VOLTAGE_MIN_REG(i)) << 2;
1730 data->voltage[MAX][i] =
1731 adt7475_read(VOLTAGE_MAX_REG(i)) << 2;
1732 }
1733
Jean Delvare3d849982009-12-09 20:36:05 +01001734 if (data->has_voltage & (1 << 5)) {
1735 data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2;
1736 data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2;
1737 }
1738
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001739 for (i = 0; i < ADT7475_TEMP_COUNT; i++) {
1740 /* Adjust values so they match the input precision */
1741 data->temp[MIN][i] =
1742 adt7475_read(TEMP_MIN_REG(i)) << 2;
1743 data->temp[MAX][i] =
1744 adt7475_read(TEMP_MAX_REG(i)) << 2;
1745 data->temp[AUTOMIN][i] =
1746 adt7475_read(TEMP_TMIN_REG(i)) << 2;
1747 data->temp[THERM][i] =
1748 adt7475_read(TEMP_THERM_REG(i)) << 2;
1749 data->temp[OFFSET][i] =
1750 adt7475_read(TEMP_OFFSET_REG(i));
1751 }
1752 adt7475_read_hystersis(client);
1753
Jean Delvare378933c2009-12-09 20:36:06 +01001754 for (i = 0; i < ADT7475_TACH_COUNT; i++) {
1755 if (i == 3 && !data->has_fan4)
1756 continue;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001757 data->tach[MIN][i] =
1758 adt7475_read_word(client, TACH_MIN_REG(i));
Jean Delvare378933c2009-12-09 20:36:06 +01001759 }
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001760
1761 for (i = 0; i < ADT7475_PWM_COUNT; i++) {
Jean Delvare378933c2009-12-09 20:36:06 +01001762 if (i == 1 && !data->has_pwm2)
1763 continue;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001764 data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i));
1765 data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i));
1766 /* Set the channel and control information */
1767 adt7475_read_pwm(client, i);
1768 }
1769
1770 data->range[0] = adt7475_read(TEMP_TRANGE_REG(0));
1771 data->range[1] = adt7475_read(TEMP_TRANGE_REG(1));
1772 data->range[2] = adt7475_read(TEMP_TRANGE_REG(2));
1773
1774 data->limits_updated = jiffies;
1775 data->valid = 1;
1776 }
1777
1778 mutex_unlock(&data->lock);
1779
1780 return data;
1781}
1782
Axel Linf0967ee2012-01-20 15:38:18 +08001783module_i2c_driver(adt7475_driver);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001784
1785MODULE_AUTHOR("Advanced Micro Devices, Inc");
1786MODULE_DESCRIPTION("adt7475 driver");
1787MODULE_LICENSE("GPL");