blob: d90b31eb34722019ed773e389aeab1978bdca89a [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 Delvare7c81c60f2014-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;
Tokunori Ikegamib36fb172018-08-08 10:32:17 +0900197 bool valid;
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100198
Jean Delvaref99318b2009-12-09 20:36:03 +0100199 u8 config4;
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100200 u8 config5;
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100201 u8 has_voltage;
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100202 u8 bypass_attn; /* Bypass voltage attenuator */
Jean Delvare378933c2009-12-09 20:36:06 +0100203 u8 has_pwm2:1;
204 u8 has_fan4:1;
Jean Delvare54fe4672009-12-09 20:36:08 +0100205 u8 has_vid:1;
Jean Delvare3d849982009-12-09 20:36:05 +0100206 u32 alarms;
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100207 u16 voltage[3][6];
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100208 u16 temp[7][3];
209 u16 tach[2][4];
210 u8 pwm[4][3];
211 u8 range[3];
212 u8 pwmctl[3];
213 u8 pwmchan[3];
Chris Packham1d58f5e2017-05-15 13:30:27 +1200214 u8 enh_acoustics[2];
Jean Delvare54fe4672009-12-09 20:36:08 +0100215
216 u8 vid;
217 u8 vrm;
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100218};
219
220static struct i2c_driver adt7475_driver;
221static struct adt7475_data *adt7475_update_device(struct device *dev);
222static void adt7475_read_hystersis(struct i2c_client *client);
223static void adt7475_read_pwm(struct i2c_client *client, int index);
224
225/* Given a temp value, convert it to register value */
226
227static inline u16 temp2reg(struct adt7475_data *data, long val)
228{
229 u16 ret;
230
231 if (!(data->config5 & CONFIG5_TWOSCOMP)) {
Guenter Roeck2a844c12013-01-09 08:09:34 -0800232 val = clamp_val(val, -64000, 191000);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100233 ret = (val + 64500) / 1000;
234 } else {
Guenter Roeck2a844c12013-01-09 08:09:34 -0800235 val = clamp_val(val, -128000, 127000);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100236 if (val < -500)
237 ret = (256500 + val) / 1000;
238 else
239 ret = (val + 500) / 1000;
240 }
241
242 return ret << 2;
243}
244
245/* Given a register value, convert it to a real temp value */
246
247static inline int reg2temp(struct adt7475_data *data, u16 reg)
248{
249 if (data->config5 & CONFIG5_TWOSCOMP) {
250 if (reg >= 512)
251 return (reg - 1024) * 250;
252 else
253 return reg * 250;
254 } else
255 return (reg - 256) * 250;
256}
257
258static inline int tach2rpm(u16 tach)
259{
260 if (tach == 0 || tach == 0xFFFF)
261 return 0;
262
263 return (90000 * 60) / tach;
264}
265
266static inline u16 rpm2tach(unsigned long rpm)
267{
268 if (rpm == 0)
269 return 0;
270
Guenter Roeck2a844c12013-01-09 08:09:34 -0800271 return clamp_val((90000 * 60) / rpm, 1, 0xFFFF);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100272}
273
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100274/* Scaling factors for voltage inputs, taken from the ADT7490 datasheet */
275static const int adt7473_in_scaling[ADT7475_VOLTAGE_COUNT + 1][2] = {
276 { 45, 94 }, /* +2.5V */
277 { 175, 525 }, /* Vccp */
278 { 68, 71 }, /* Vcc */
279 { 93, 47 }, /* +5V */
280 { 120, 20 }, /* +12V */
281 { 45, 45 }, /* Vtt */
282};
283
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100284static inline int reg2volt(int channel, u16 reg, u8 bypass_attn)
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100285{
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100286 const int *r = adt7473_in_scaling[channel];
287
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100288 if (bypass_attn & (1 << channel))
289 return DIV_ROUND_CLOSEST(reg * 2250, 1024);
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100290 return DIV_ROUND_CLOSEST(reg * (r[0] + r[1]) * 2250, r[1] * 1024);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100291}
292
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100293static inline u16 volt2reg(int channel, long volt, u8 bypass_attn)
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100294{
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100295 const int *r = adt7473_in_scaling[channel];
296 long reg;
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100297
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100298 if (bypass_attn & (1 << channel))
299 reg = (volt * 1024) / 2250;
300 else
301 reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250);
Guenter Roeck2a844c12013-01-09 08:09:34 -0800302 return clamp_val(reg, 0, 1023) & (0xff << 2);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100303}
304
305static u16 adt7475_read_word(struct i2c_client *client, int reg)
306{
307 u16 val;
308
309 val = i2c_smbus_read_byte_data(client, reg);
310 val |= (i2c_smbus_read_byte_data(client, reg + 1) << 8);
311
312 return val;
313}
314
315static void adt7475_write_word(struct i2c_client *client, int reg, u16 val)
316{
317 i2c_smbus_write_byte_data(client, reg + 1, val >> 8);
318 i2c_smbus_write_byte_data(client, reg, val & 0xFF);
319}
320
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100321static ssize_t show_voltage(struct device *dev, struct device_attribute *attr,
322 char *buf)
323{
324 struct adt7475_data *data = adt7475_update_device(dev);
325 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
326 unsigned short val;
327
328 switch (sattr->nr) {
329 case ALARM:
330 return sprintf(buf, "%d\n",
Jean Delvarecffb9dd2009-12-09 20:36:03 +0100331 (data->alarms >> sattr->index) & 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100332 default:
333 val = data->voltage[sattr->nr][sattr->index];
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100334 return sprintf(buf, "%d\n",
335 reg2volt(sattr->index, val, data->bypass_attn));
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100336 }
337}
338
339static ssize_t set_voltage(struct device *dev, struct device_attribute *attr,
340 const char *buf, size_t count)
341{
342
343 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
344 struct i2c_client *client = to_i2c_client(dev);
345 struct adt7475_data *data = i2c_get_clientdata(client);
346 unsigned char reg;
347 long val;
348
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100349 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100350 return -EINVAL;
351
352 mutex_lock(&data->lock);
353
Jean Delvareebfaf1f2009-12-09 20:36:07 +0100354 data->voltage[sattr->nr][sattr->index] =
355 volt2reg(sattr->index, val, data->bypass_attn);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100356
Jean Delvare3d849982009-12-09 20:36:05 +0100357 if (sattr->index < ADT7475_VOLTAGE_COUNT) {
358 if (sattr->nr == MIN)
359 reg = VOLTAGE_MIN_REG(sattr->index);
360 else
361 reg = VOLTAGE_MAX_REG(sattr->index);
362 } else {
363 if (sattr->nr == MIN)
364 reg = REG_VTT_MIN;
365 else
366 reg = REG_VTT_MAX;
367 }
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100368
369 i2c_smbus_write_byte_data(client, reg,
370 data->voltage[sattr->nr][sattr->index] >> 2);
371 mutex_unlock(&data->lock);
372
373 return count;
374}
375
376static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
377 char *buf)
378{
379 struct adt7475_data *data = adt7475_update_device(dev);
380 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
381 int out;
382
383 switch (sattr->nr) {
384 case HYSTERSIS:
385 mutex_lock(&data->lock);
386 out = data->temp[sattr->nr][sattr->index];
387 if (sattr->index != 1)
388 out = (out >> 4) & 0xF;
389 else
390 out = (out & 0xF);
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800391 /*
392 * Show the value as an absolute number tied to
393 * THERM
394 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100395 out = reg2temp(data, data->temp[THERM][sattr->index]) -
396 out * 1000;
397 mutex_unlock(&data->lock);
398 break;
399
400 case OFFSET:
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800401 /*
402 * Offset is always 2's complement, regardless of the
403 * setting in CONFIG5
404 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100405 mutex_lock(&data->lock);
406 out = (s8)data->temp[sattr->nr][sattr->index];
407 if (data->config5 & CONFIG5_TEMPOFFSET)
408 out *= 1000;
409 else
410 out *= 500;
411 mutex_unlock(&data->lock);
412 break;
413
414 case ALARM:
415 out = (data->alarms >> (sattr->index + 4)) & 1;
416 break;
417
418 case FAULT:
419 /* Note - only for remote1 and remote2 */
Jean Delvarecf312e02009-11-16 12:45:39 +0100420 out = !!(data->alarms & (sattr->index ? 0x8000 : 0x4000));
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100421 break;
422
423 default:
424 /* All other temp values are in the configured format */
425 out = reg2temp(data, data->temp[sattr->nr][sattr->index]);
426 }
427
428 return sprintf(buf, "%d\n", out);
429}
430
431static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
432 const char *buf, size_t count)
433{
434 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
435 struct i2c_client *client = to_i2c_client(dev);
436 struct adt7475_data *data = i2c_get_clientdata(client);
437 unsigned char reg = 0;
438 u8 out;
439 int temp;
440 long val;
441
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100442 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100443 return -EINVAL;
444
445 mutex_lock(&data->lock);
446
447 /* We need the config register in all cases for temp <-> reg conv. */
448 data->config5 = adt7475_read(REG_CONFIG5);
449
450 switch (sattr->nr) {
451 case OFFSET:
452 if (data->config5 & CONFIG5_TEMPOFFSET) {
Guenter Roeck2a844c12013-01-09 08:09:34 -0800453 val = clamp_val(val, -63000, 127000);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100454 out = data->temp[OFFSET][sattr->index] = val / 1000;
455 } else {
Guenter Roeck2a844c12013-01-09 08:09:34 -0800456 val = clamp_val(val, -63000, 64000);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100457 out = data->temp[OFFSET][sattr->index] = val / 500;
458 }
459 break;
460
461 case HYSTERSIS:
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800462 /*
463 * The value will be given as an absolute value, turn it
464 * into an offset based on THERM
465 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100466
467 /* Read fresh THERM and HYSTERSIS values from the chip */
468 data->temp[THERM][sattr->index] =
469 adt7475_read(TEMP_THERM_REG(sattr->index)) << 2;
470 adt7475_read_hystersis(client);
471
472 temp = reg2temp(data, data->temp[THERM][sattr->index]);
Guenter Roeck2a844c12013-01-09 08:09:34 -0800473 val = clamp_val(val, temp - 15000, temp);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100474 val = (temp - val) / 1000;
475
476 if (sattr->index != 1) {
477 data->temp[HYSTERSIS][sattr->index] &= 0xF0;
478 data->temp[HYSTERSIS][sattr->index] |= (val & 0xF) << 4;
479 } else {
480 data->temp[HYSTERSIS][sattr->index] &= 0x0F;
481 data->temp[HYSTERSIS][sattr->index] |= (val & 0xF);
482 }
483
484 out = data->temp[HYSTERSIS][sattr->index];
485 break;
486
487 default:
488 data->temp[sattr->nr][sattr->index] = temp2reg(data, val);
489
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800490 /*
491 * We maintain an extra 2 digits of precision for simplicity
492 * - shift those back off before writing the value
493 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100494 out = (u8) (data->temp[sattr->nr][sattr->index] >> 2);
495 }
496
497 switch (sattr->nr) {
498 case MIN:
499 reg = TEMP_MIN_REG(sattr->index);
500 break;
501 case MAX:
502 reg = TEMP_MAX_REG(sattr->index);
503 break;
504 case OFFSET:
505 reg = TEMP_OFFSET_REG(sattr->index);
506 break;
507 case AUTOMIN:
508 reg = TEMP_TMIN_REG(sattr->index);
509 break;
510 case THERM:
511 reg = TEMP_THERM_REG(sattr->index);
512 break;
513 case HYSTERSIS:
514 if (sattr->index != 2)
515 reg = REG_REMOTE1_HYSTERSIS;
516 else
517 reg = REG_REMOTE2_HYSTERSIS;
518
519 break;
520 }
521
522 i2c_smbus_write_byte_data(client, reg, out);
523
524 mutex_unlock(&data->lock);
525 return count;
526}
527
Chris Packham8f05bcc2017-05-15 13:30:28 +1200528/* Assuming CONFIG6[SLOW] is 0 */
529static const int ad7475_st_map[] = {
530 37500, 18800, 12500, 7500, 4700, 3100, 1600, 800,
531};
532
533static ssize_t show_temp_st(struct device *dev, struct device_attribute *attr,
534 char *buf)
535{
536 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
537 struct i2c_client *client = to_i2c_client(dev);
538 struct adt7475_data *data = i2c_get_clientdata(client);
539 long val;
540
541 switch (sattr->index) {
542 case 0:
543 val = data->enh_acoustics[0] & 0xf;
544 break;
545 case 1:
546 val = (data->enh_acoustics[1] >> 4) & 0xf;
547 break;
548 case 2:
549 default:
550 val = data->enh_acoustics[1] & 0xf;
551 break;
552 }
553
554 if (val & 0x8)
555 return sprintf(buf, "%d\n", ad7475_st_map[val & 0x7]);
556 else
557 return sprintf(buf, "0\n");
558}
559
560static ssize_t set_temp_st(struct device *dev, struct device_attribute *attr,
561 const char *buf, size_t count)
562{
563 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
564 struct i2c_client *client = to_i2c_client(dev);
565 struct adt7475_data *data = i2c_get_clientdata(client);
566 unsigned char reg;
567 int shift, idx;
568 ulong val;
569
570 if (kstrtoul(buf, 10, &val))
571 return -EINVAL;
572
573 switch (sattr->index) {
574 case 0:
575 reg = REG_ENHANCE_ACOUSTICS1;
576 shift = 0;
577 idx = 0;
578 break;
579 case 1:
580 reg = REG_ENHANCE_ACOUSTICS2;
581 shift = 0;
582 idx = 1;
583 break;
584 case 2:
585 default:
586 reg = REG_ENHANCE_ACOUSTICS2;
587 shift = 4;
588 idx = 1;
589 break;
590 }
591
592 if (val > 0) {
593 val = find_closest_descending(val, ad7475_st_map,
594 ARRAY_SIZE(ad7475_st_map));
595 val |= 0x8;
596 }
597
598 mutex_lock(&data->lock);
599
600 data->enh_acoustics[idx] &= ~(0xf << shift);
601 data->enh_acoustics[idx] |= (val << shift);
602
603 i2c_smbus_write_byte_data(client, reg, data->enh_acoustics[idx]);
604
605 mutex_unlock(&data->lock);
606
607 return count;
608}
609
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800610/*
611 * Table of autorange values - the user will write the value in millidegrees,
612 * and we'll convert it
613 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100614static const int autorange_table[] = {
615 2000, 2500, 3330, 4000, 5000, 6670, 8000,
616 10000, 13330, 16000, 20000, 26670, 32000, 40000,
617 53330, 80000
618};
619
620static ssize_t show_point2(struct device *dev, struct device_attribute *attr,
621 char *buf)
622{
623 struct adt7475_data *data = adt7475_update_device(dev);
624 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
625 int out, val;
626
627 mutex_lock(&data->lock);
628 out = (data->range[sattr->index] >> 4) & 0x0F;
629 val = reg2temp(data, data->temp[AUTOMIN][sattr->index]);
630 mutex_unlock(&data->lock);
631
632 return sprintf(buf, "%d\n", val + autorange_table[out]);
633}
634
635static ssize_t set_point2(struct device *dev, struct device_attribute *attr,
636 const char *buf, size_t count)
637{
638 struct i2c_client *client = to_i2c_client(dev);
639 struct adt7475_data *data = i2c_get_clientdata(client);
640 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
641 int temp;
642 long val;
643
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100644 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100645 return -EINVAL;
646
647 mutex_lock(&data->lock);
648
649 /* Get a fresh copy of the needed registers */
650 data->config5 = adt7475_read(REG_CONFIG5);
651 data->temp[AUTOMIN][sattr->index] =
652 adt7475_read(TEMP_TMIN_REG(sattr->index)) << 2;
653 data->range[sattr->index] =
654 adt7475_read(TEMP_TRANGE_REG(sattr->index));
655
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800656 /*
657 * The user will write an absolute value, so subtract the start point
658 * to figure the range
659 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100660 temp = reg2temp(data, data->temp[AUTOMIN][sattr->index]);
Guenter Roeck2a844c12013-01-09 08:09:34 -0800661 val = clamp_val(val, temp + autorange_table[0],
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100662 temp + autorange_table[ARRAY_SIZE(autorange_table) - 1]);
663 val -= temp;
664
665 /* Find the nearest table entry to what the user wrote */
Chris Packhame4651642017-05-11 15:45:21 +1200666 val = find_closest(val, autorange_table, ARRAY_SIZE(autorange_table));
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100667
668 data->range[sattr->index] &= ~0xF0;
669 data->range[sattr->index] |= val << 4;
670
671 i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),
672 data->range[sattr->index]);
673
674 mutex_unlock(&data->lock);
675 return count;
676}
677
678static ssize_t show_tach(struct device *dev, struct device_attribute *attr,
679 char *buf)
680{
681 struct adt7475_data *data = adt7475_update_device(dev);
682 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
683 int out;
684
685 if (sattr->nr == ALARM)
686 out = (data->alarms >> (sattr->index + 10)) & 1;
687 else
688 out = tach2rpm(data->tach[sattr->nr][sattr->index]);
689
690 return sprintf(buf, "%d\n", out);
691}
692
693static ssize_t set_tach(struct device *dev, struct device_attribute *attr,
694 const char *buf, size_t count)
695{
696
697 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
698 struct i2c_client *client = to_i2c_client(dev);
699 struct adt7475_data *data = i2c_get_clientdata(client);
700 unsigned long val;
701
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100702 if (kstrtoul(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100703 return -EINVAL;
704
705 mutex_lock(&data->lock);
706
707 data->tach[MIN][sattr->index] = rpm2tach(val);
708
709 adt7475_write_word(client, TACH_MIN_REG(sattr->index),
710 data->tach[MIN][sattr->index]);
711
712 mutex_unlock(&data->lock);
713 return count;
714}
715
716static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
717 char *buf)
718{
719 struct adt7475_data *data = adt7475_update_device(dev);
720 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
721
722 return sprintf(buf, "%d\n", data->pwm[sattr->nr][sattr->index]);
723}
724
725static ssize_t show_pwmchan(struct device *dev, struct device_attribute *attr,
726 char *buf)
727{
728 struct adt7475_data *data = adt7475_update_device(dev);
729 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
730
731 return sprintf(buf, "%d\n", data->pwmchan[sattr->index]);
732}
733
734static ssize_t show_pwmctrl(struct device *dev, struct device_attribute *attr,
735 char *buf)
736{
737 struct adt7475_data *data = adt7475_update_device(dev);
738 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
739
740 return sprintf(buf, "%d\n", data->pwmctl[sattr->index]);
741}
742
743static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
744 const char *buf, size_t count)
745{
746
747 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
748 struct i2c_client *client = to_i2c_client(dev);
749 struct adt7475_data *data = i2c_get_clientdata(client);
750 unsigned char reg = 0;
751 long val;
752
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100753 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100754 return -EINVAL;
755
756 mutex_lock(&data->lock);
757
758 switch (sattr->nr) {
759 case INPUT:
760 /* Get a fresh value for CONTROL */
761 data->pwm[CONTROL][sattr->index] =
762 adt7475_read(PWM_CONFIG_REG(sattr->index));
763
Guenter Roeck9ed5bc22012-01-19 11:02:15 -0800764 /*
765 * If we are not in manual mode, then we shouldn't allow
766 * the user to set the pwm speed
767 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100768 if (((data->pwm[CONTROL][sattr->index] >> 5) & 7) != 7) {
769 mutex_unlock(&data->lock);
770 return count;
771 }
772
773 reg = PWM_REG(sattr->index);
774 break;
775
776 case MIN:
777 reg = PWM_MIN_REG(sattr->index);
778 break;
779
780 case MAX:
781 reg = PWM_MAX_REG(sattr->index);
782 break;
783 }
784
Guenter Roeck2a844c12013-01-09 08:09:34 -0800785 data->pwm[sattr->nr][sattr->index] = clamp_val(val, 0, 0xFF);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100786 i2c_smbus_write_byte_data(client, reg,
787 data->pwm[sattr->nr][sattr->index]);
Chris Packham1d58f5e2017-05-15 13:30:27 +1200788 mutex_unlock(&data->lock);
789
790 return count;
791}
792
793static ssize_t show_stall_disable(struct device *dev,
794 struct device_attribute *attr, char *buf)
795{
796 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
797 struct i2c_client *client = to_i2c_client(dev);
798 struct adt7475_data *data = i2c_get_clientdata(client);
799 u8 mask = BIT(5 + sattr->index);
800
801 return sprintf(buf, "%d\n", !!(data->enh_acoustics[0] & mask));
802}
803
804static ssize_t set_stall_disable(struct device *dev,
805 struct device_attribute *attr, const char *buf,
806 size_t count)
807{
808 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
809 struct i2c_client *client = to_i2c_client(dev);
810 struct adt7475_data *data = i2c_get_clientdata(client);
811 long val;
812 u8 mask = BIT(5 + sattr->index);
813
814 if (kstrtol(buf, 10, &val))
815 return -EINVAL;
816
817 mutex_lock(&data->lock);
818
819 data->enh_acoustics[0] &= ~mask;
820 if (val)
821 data->enh_acoustics[0] |= mask;
822
823 i2c_smbus_write_byte_data(client, REG_ENHANCE_ACOUSTICS1,
824 data->enh_acoustics[0]);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100825
826 mutex_unlock(&data->lock);
827
828 return count;
829}
830
831/* Called by set_pwmctrl and set_pwmchan */
832
833static int hw_set_pwm(struct i2c_client *client, int index,
834 unsigned int pwmctl, unsigned int pwmchan)
835{
836 struct adt7475_data *data = i2c_get_clientdata(client);
837 long val = 0;
838
839 switch (pwmctl) {
840 case 0:
841 val = 0x03; /* Run at full speed */
842 break;
843 case 1:
844 val = 0x07; /* Manual mode */
845 break;
846 case 2:
847 switch (pwmchan) {
848 case 1:
849 /* Remote1 controls PWM */
850 val = 0x00;
851 break;
852 case 2:
853 /* local controls PWM */
854 val = 0x01;
855 break;
856 case 4:
857 /* remote2 controls PWM */
858 val = 0x02;
859 break;
860 case 6:
861 /* local/remote2 control PWM */
862 val = 0x05;
863 break;
864 case 7:
865 /* All three control PWM */
866 val = 0x06;
867 break;
868 default:
869 return -EINVAL;
870 }
871 break;
872 default:
873 return -EINVAL;
874 }
875
876 data->pwmctl[index] = pwmctl;
877 data->pwmchan[index] = pwmchan;
878
879 data->pwm[CONTROL][index] &= ~0xE0;
880 data->pwm[CONTROL][index] |= (val & 7) << 5;
881
882 i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index),
883 data->pwm[CONTROL][index]);
884
885 return 0;
886}
887
888static ssize_t set_pwmchan(struct device *dev, struct device_attribute *attr,
889 const char *buf, size_t count)
890{
891 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
892 struct i2c_client *client = to_i2c_client(dev);
893 struct adt7475_data *data = i2c_get_clientdata(client);
894 int r;
895 long val;
896
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100897 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100898 return -EINVAL;
899
900 mutex_lock(&data->lock);
901 /* Read Modify Write PWM values */
902 adt7475_read_pwm(client, sattr->index);
903 r = hw_set_pwm(client, sattr->index, data->pwmctl[sattr->index], val);
904 if (r)
905 count = r;
906 mutex_unlock(&data->lock);
907
908 return count;
909}
910
911static ssize_t set_pwmctrl(struct device *dev, struct device_attribute *attr,
912 const char *buf, size_t count)
913{
914 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
915 struct i2c_client *client = to_i2c_client(dev);
916 struct adt7475_data *data = i2c_get_clientdata(client);
917 int r;
918 long val;
919
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100920 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100921 return -EINVAL;
922
923 mutex_lock(&data->lock);
924 /* Read Modify Write PWM values */
925 adt7475_read_pwm(client, sattr->index);
926 r = hw_set_pwm(client, sattr->index, val, data->pwmchan[sattr->index]);
927 if (r)
928 count = r;
929 mutex_unlock(&data->lock);
930
931 return count;
932}
933
934/* List of frequencies for the PWM */
935static const int pwmfreq_table[] = {
Chris Packham3490c922017-05-15 13:30:29 +1200936 11, 14, 22, 29, 35, 44, 58, 88, 22500
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100937};
938
939static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
940 char *buf)
941{
942 struct adt7475_data *data = adt7475_update_device(dev);
943 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
Chris Packham3490c922017-05-15 13:30:29 +1200944 int i = clamp_val(data->range[sattr->index] & 0xf, 0,
945 ARRAY_SIZE(pwmfreq_table) - 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100946
Chris Packham3490c922017-05-15 13:30:29 +1200947 return sprintf(buf, "%d\n", pwmfreq_table[i]);
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100948}
949
950static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
951 const char *buf, size_t count)
952{
953 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
954 struct i2c_client *client = to_i2c_client(dev);
955 struct adt7475_data *data = i2c_get_clientdata(client);
956 int out;
957 long val;
958
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100959 if (kstrtol(buf, 10, &val))
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100960 return -EINVAL;
961
Chris Packhame4651642017-05-11 15:45:21 +1200962 out = find_closest(val, pwmfreq_table, ARRAY_SIZE(pwmfreq_table));
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100963
964 mutex_lock(&data->lock);
965
966 data->range[sattr->index] =
967 adt7475_read(TEMP_TRANGE_REG(sattr->index));
Chris Packham3490c922017-05-15 13:30:29 +1200968 data->range[sattr->index] &= ~0xf;
Jordan Crouse1c301fc2009-01-15 22:27:47 +0100969 data->range[sattr->index] |= out;
970
971 i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),
972 data->range[sattr->index]);
973
974 mutex_unlock(&data->lock);
975 return count;
976}
977
Julia Lawall1d05303c2016-12-22 13:05:33 +0100978static ssize_t pwm_use_point2_pwm_at_crit_show(struct device *dev,
979 struct device_attribute *devattr,
980 char *buf)
Jean Delvaref99318b2009-12-09 20:36:03 +0100981{
982 struct adt7475_data *data = adt7475_update_device(dev);
983 return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY));
984}
985
Julia Lawall1d05303c2016-12-22 13:05:33 +0100986static ssize_t pwm_use_point2_pwm_at_crit_store(struct device *dev,
987 struct device_attribute *devattr,
988 const char *buf, size_t count)
Jean Delvaref99318b2009-12-09 20:36:03 +0100989{
990 struct i2c_client *client = to_i2c_client(dev);
991 struct adt7475_data *data = i2c_get_clientdata(client);
992 long val;
993
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100994 if (kstrtol(buf, 10, &val))
Jean Delvaref99318b2009-12-09 20:36:03 +0100995 return -EINVAL;
996 if (val != 0 && val != 1)
997 return -EINVAL;
998
999 mutex_lock(&data->lock);
1000 data->config4 = i2c_smbus_read_byte_data(client, REG_CONFIG4);
1001 if (val)
1002 data->config4 |= CONFIG4_MAXDUTY;
1003 else
1004 data->config4 &= ~CONFIG4_MAXDUTY;
1005 i2c_smbus_write_byte_data(client, REG_CONFIG4, data->config4);
1006 mutex_unlock(&data->lock);
1007
1008 return count;
1009}
1010
Julia Lawall1d05303c2016-12-22 13:05:33 +01001011static ssize_t vrm_show(struct device *dev, struct device_attribute *devattr,
Jean Delvare54fe4672009-12-09 20:36:08 +01001012 char *buf)
1013{
1014 struct adt7475_data *data = dev_get_drvdata(dev);
1015 return sprintf(buf, "%d\n", (int)data->vrm);
1016}
1017
Julia Lawall1d05303c2016-12-22 13:05:33 +01001018static ssize_t vrm_store(struct device *dev, struct device_attribute *devattr,
1019 const char *buf, size_t count)
Jean Delvare54fe4672009-12-09 20:36:08 +01001020{
1021 struct adt7475_data *data = dev_get_drvdata(dev);
1022 long val;
1023
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001024 if (kstrtol(buf, 10, &val))
Jean Delvare54fe4672009-12-09 20:36:08 +01001025 return -EINVAL;
1026 if (val < 0 || val > 255)
1027 return -EINVAL;
1028 data->vrm = val;
1029
1030 return count;
1031}
1032
Julia Lawall1d05303c2016-12-22 13:05:33 +01001033static ssize_t cpu0_vid_show(struct device *dev,
1034 struct device_attribute *devattr, char *buf)
Jean Delvare54fe4672009-12-09 20:36:08 +01001035{
1036 struct adt7475_data *data = adt7475_update_device(dev);
1037 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
1038}
1039
Jean Delvare3d849982009-12-09 20:36:05 +01001040static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_voltage, NULL, INPUT, 0);
1041static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_voltage,
1042 set_voltage, MAX, 0);
1043static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_voltage,
1044 set_voltage, MIN, 0);
1045static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, show_voltage, NULL, ALARM, 0);
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001046static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_voltage, NULL, INPUT, 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001047static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_voltage,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001048 set_voltage, MAX, 1);
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001049static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_voltage,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001050 set_voltage, MIN, 1);
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001051static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, show_voltage, NULL, ALARM, 1);
1052static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_voltage, NULL, INPUT, 2);
1053static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_voltage,
1054 set_voltage, MAX, 2);
1055static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_voltage,
1056 set_voltage, MIN, 2);
1057static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_voltage, NULL, ALARM, 2);
Jean Delvare3d849982009-12-09 20:36:05 +01001058static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_voltage, NULL, INPUT, 3);
1059static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_voltage,
1060 set_voltage, MAX, 3);
1061static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_voltage,
1062 set_voltage, MIN, 3);
1063static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, show_voltage, NULL, ALARM, 3);
1064static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_voltage, NULL, INPUT, 4);
1065static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_voltage,
1066 set_voltage, MAX, 4);
1067static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_voltage,
1068 set_voltage, MIN, 4);
1069static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, show_voltage, NULL, ALARM, 8);
1070static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_voltage, NULL, INPUT, 5);
1071static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_voltage,
1072 set_voltage, MAX, 5);
1073static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_voltage,
1074 set_voltage, MIN, 5);
1075static SENSOR_DEVICE_ATTR_2(in5_alarm, S_IRUGO, show_voltage, NULL, ALARM, 31);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001076static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, INPUT, 0);
1077static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, show_temp, NULL, ALARM, 0);
1078static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_temp, NULL, FAULT, 0);
1079static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1080 MAX, 0);
1081static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1082 MIN, 0);
1083static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
1084 set_temp, OFFSET, 0);
1085static SENSOR_DEVICE_ATTR_2(temp1_auto_point1_temp, S_IRUGO | S_IWUSR,
1086 show_temp, set_temp, AUTOMIN, 0);
1087static SENSOR_DEVICE_ATTR_2(temp1_auto_point2_temp, S_IRUGO | S_IWUSR,
1088 show_point2, set_point2, 0, 0);
1089static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
1090 THERM, 0);
1091static SENSOR_DEVICE_ATTR_2(temp1_crit_hyst, S_IRUGO | S_IWUSR, show_temp,
1092 set_temp, HYSTERSIS, 0);
Chris Packham8f05bcc2017-05-15 13:30:28 +12001093static SENSOR_DEVICE_ATTR_2(temp1_smoothing, S_IRUGO | S_IWUSR, show_temp_st,
1094 set_temp_st, 0, 0);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001095static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, INPUT, 1);
1096static SENSOR_DEVICE_ATTR_2(temp2_alarm, S_IRUGO, show_temp, NULL, ALARM, 1);
1097static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1098 MAX, 1);
1099static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1100 MIN, 1);
1101static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
1102 set_temp, OFFSET, 1);
1103static SENSOR_DEVICE_ATTR_2(temp2_auto_point1_temp, S_IRUGO | S_IWUSR,
1104 show_temp, set_temp, AUTOMIN, 1);
1105static SENSOR_DEVICE_ATTR_2(temp2_auto_point2_temp, S_IRUGO | S_IWUSR,
1106 show_point2, set_point2, 0, 1);
1107static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
1108 THERM, 1);
1109static SENSOR_DEVICE_ATTR_2(temp2_crit_hyst, S_IRUGO | S_IWUSR, show_temp,
1110 set_temp, HYSTERSIS, 1);
Chris Packham8f05bcc2017-05-15 13:30:28 +12001111static SENSOR_DEVICE_ATTR_2(temp2_smoothing, S_IRUGO | S_IWUSR, show_temp_st,
1112 set_temp_st, 0, 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001113static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, INPUT, 2);
1114static SENSOR_DEVICE_ATTR_2(temp3_alarm, S_IRUGO, show_temp, NULL, ALARM, 2);
1115static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_temp, NULL, FAULT, 2);
1116static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1117 MAX, 2);
1118static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1119 MIN, 2);
1120static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
1121 set_temp, OFFSET, 2);
1122static SENSOR_DEVICE_ATTR_2(temp3_auto_point1_temp, S_IRUGO | S_IWUSR,
1123 show_temp, set_temp, AUTOMIN, 2);
1124static SENSOR_DEVICE_ATTR_2(temp3_auto_point2_temp, S_IRUGO | S_IWUSR,
1125 show_point2, set_point2, 0, 2);
1126static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
1127 THERM, 2);
1128static SENSOR_DEVICE_ATTR_2(temp3_crit_hyst, S_IRUGO | S_IWUSR, show_temp,
1129 set_temp, HYSTERSIS, 2);
Chris Packham8f05bcc2017-05-15 13:30:28 +12001130static SENSOR_DEVICE_ATTR_2(temp3_smoothing, S_IRUGO | S_IWUSR, show_temp_st,
1131 set_temp_st, 0, 2);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001132static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_tach, NULL, INPUT, 0);
1133static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
1134 MIN, 0);
1135static SENSOR_DEVICE_ATTR_2(fan1_alarm, S_IRUGO, show_tach, NULL, ALARM, 0);
1136static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_tach, NULL, INPUT, 1);
1137static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
1138 MIN, 1);
1139static SENSOR_DEVICE_ATTR_2(fan2_alarm, S_IRUGO, show_tach, NULL, ALARM, 1);
1140static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_tach, NULL, INPUT, 2);
1141static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
1142 MIN, 2);
1143static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_tach, NULL, ALARM, 2);
1144static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_tach, NULL, INPUT, 3);
1145static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
1146 MIN, 3);
1147static SENSOR_DEVICE_ATTR_2(fan4_alarm, S_IRUGO, show_tach, NULL, ALARM, 3);
1148static SENSOR_DEVICE_ATTR_2(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT,
1149 0);
1150static SENSOR_DEVICE_ATTR_2(pwm1_freq, S_IRUGO | S_IWUSR, show_pwmfreq,
1151 set_pwmfreq, INPUT, 0);
1152static SENSOR_DEVICE_ATTR_2(pwm1_enable, S_IRUGO | S_IWUSR, show_pwmctrl,
1153 set_pwmctrl, INPUT, 0);
Jean Delvare84d2a312009-11-16 12:45:40 +01001154static SENSOR_DEVICE_ATTR_2(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001155 show_pwmchan, set_pwmchan, INPUT, 0);
1156static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
1157 set_pwm, MIN, 0);
1158static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
1159 set_pwm, MAX, 0);
Chris Packham1d58f5e2017-05-15 13:30:27 +12001160static SENSOR_DEVICE_ATTR_2(pwm1_stall_disable, S_IRUGO | S_IWUSR,
1161 show_stall_disable, set_stall_disable, 0, 0);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001162static SENSOR_DEVICE_ATTR_2(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT,
1163 1);
1164static SENSOR_DEVICE_ATTR_2(pwm2_freq, S_IRUGO | S_IWUSR, show_pwmfreq,
1165 set_pwmfreq, INPUT, 1);
1166static SENSOR_DEVICE_ATTR_2(pwm2_enable, S_IRUGO | S_IWUSR, show_pwmctrl,
1167 set_pwmctrl, INPUT, 1);
Jean Delvare84d2a312009-11-16 12:45:40 +01001168static SENSOR_DEVICE_ATTR_2(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001169 show_pwmchan, set_pwmchan, INPUT, 1);
1170static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
1171 set_pwm, MIN, 1);
1172static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
1173 set_pwm, MAX, 1);
Chris Packham1d58f5e2017-05-15 13:30:27 +12001174static SENSOR_DEVICE_ATTR_2(pwm2_stall_disable, S_IRUGO | S_IWUSR,
1175 show_stall_disable, set_stall_disable, 0, 1);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001176static SENSOR_DEVICE_ATTR_2(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT,
1177 2);
1178static SENSOR_DEVICE_ATTR_2(pwm3_freq, S_IRUGO | S_IWUSR, show_pwmfreq,
1179 set_pwmfreq, INPUT, 2);
1180static SENSOR_DEVICE_ATTR_2(pwm3_enable, S_IRUGO | S_IWUSR, show_pwmctrl,
1181 set_pwmctrl, INPUT, 2);
Jean Delvare84d2a312009-11-16 12:45:40 +01001182static SENSOR_DEVICE_ATTR_2(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001183 show_pwmchan, set_pwmchan, INPUT, 2);
1184static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
1185 set_pwm, MIN, 2);
1186static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
1187 set_pwm, MAX, 2);
Chris Packham1d58f5e2017-05-15 13:30:27 +12001188static SENSOR_DEVICE_ATTR_2(pwm3_stall_disable, S_IRUGO | S_IWUSR,
1189 show_stall_disable, set_stall_disable, 0, 2);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001190
Jean Delvaref99318b2009-12-09 20:36:03 +01001191/* Non-standard name, might need revisiting */
Julia Lawall1d05303c2016-12-22 13:05:33 +01001192static DEVICE_ATTR_RW(pwm_use_point2_pwm_at_crit);
Jean Delvaref99318b2009-12-09 20:36:03 +01001193
Julia Lawall1d05303c2016-12-22 13:05:33 +01001194static DEVICE_ATTR_RW(vrm);
1195static DEVICE_ATTR_RO(cpu0_vid);
Jean Delvare54fe4672009-12-09 20:36:08 +01001196
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001197static struct attribute *adt7475_attrs[] = {
1198 &sensor_dev_attr_in1_input.dev_attr.attr,
1199 &sensor_dev_attr_in1_max.dev_attr.attr,
1200 &sensor_dev_attr_in1_min.dev_attr.attr,
1201 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1202 &sensor_dev_attr_in2_input.dev_attr.attr,
1203 &sensor_dev_attr_in2_max.dev_attr.attr,
1204 &sensor_dev_attr_in2_min.dev_attr.attr,
1205 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1206 &sensor_dev_attr_temp1_input.dev_attr.attr,
1207 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1208 &sensor_dev_attr_temp1_fault.dev_attr.attr,
1209 &sensor_dev_attr_temp1_max.dev_attr.attr,
1210 &sensor_dev_attr_temp1_min.dev_attr.attr,
1211 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1212 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
1213 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
1214 &sensor_dev_attr_temp1_crit.dev_attr.attr,
1215 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
Chris Packham8f05bcc2017-05-15 13:30:28 +12001216 &sensor_dev_attr_temp1_smoothing.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001217 &sensor_dev_attr_temp2_input.dev_attr.attr,
1218 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1219 &sensor_dev_attr_temp2_max.dev_attr.attr,
1220 &sensor_dev_attr_temp2_min.dev_attr.attr,
1221 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1222 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
1223 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
1224 &sensor_dev_attr_temp2_crit.dev_attr.attr,
1225 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
Chris Packham8f05bcc2017-05-15 13:30:28 +12001226 &sensor_dev_attr_temp2_smoothing.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001227 &sensor_dev_attr_temp3_input.dev_attr.attr,
1228 &sensor_dev_attr_temp3_fault.dev_attr.attr,
1229 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1230 &sensor_dev_attr_temp3_max.dev_attr.attr,
1231 &sensor_dev_attr_temp3_min.dev_attr.attr,
1232 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1233 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
1234 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
1235 &sensor_dev_attr_temp3_crit.dev_attr.attr,
1236 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
Chris Packham8f05bcc2017-05-15 13:30:28 +12001237 &sensor_dev_attr_temp3_smoothing.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001238 &sensor_dev_attr_fan1_input.dev_attr.attr,
1239 &sensor_dev_attr_fan1_min.dev_attr.attr,
1240 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1241 &sensor_dev_attr_fan2_input.dev_attr.attr,
1242 &sensor_dev_attr_fan2_min.dev_attr.attr,
1243 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1244 &sensor_dev_attr_fan3_input.dev_attr.attr,
1245 &sensor_dev_attr_fan3_min.dev_attr.attr,
1246 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001247 &sensor_dev_attr_pwm1.dev_attr.attr,
1248 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1249 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
Jean Delvare84d2a312009-11-16 12:45:40 +01001250 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001251 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1252 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
Chris Packham1d58f5e2017-05-15 13:30:27 +12001253 &sensor_dev_attr_pwm1_stall_disable.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001254 &sensor_dev_attr_pwm3.dev_attr.attr,
1255 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
1256 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
Jean Delvare84d2a312009-11-16 12:45:40 +01001257 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001258 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1259 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
Chris Packham1d58f5e2017-05-15 13:30:27 +12001260 &sensor_dev_attr_pwm3_stall_disable.dev_attr.attr,
Jean Delvaref99318b2009-12-09 20:36:03 +01001261 &dev_attr_pwm_use_point2_pwm_at_crit.attr,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001262 NULL,
1263};
1264
Jean Delvare378933c2009-12-09 20:36:06 +01001265static struct attribute *fan4_attrs[] = {
1266 &sensor_dev_attr_fan4_input.dev_attr.attr,
1267 &sensor_dev_attr_fan4_min.dev_attr.attr,
1268 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1269 NULL
1270};
1271
1272static struct attribute *pwm2_attrs[] = {
1273 &sensor_dev_attr_pwm2.dev_attr.attr,
1274 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1275 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1276 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1277 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1278 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
Chris Packham1d58f5e2017-05-15 13:30:27 +12001279 &sensor_dev_attr_pwm2_stall_disable.dev_attr.attr,
Jean Delvare378933c2009-12-09 20:36:06 +01001280 NULL
1281};
1282
Jean Delvare378933c2009-12-09 20:36:06 +01001283static struct attribute *in0_attrs[] = {
Jean Delvare3d849982009-12-09 20:36:05 +01001284 &sensor_dev_attr_in0_input.dev_attr.attr,
1285 &sensor_dev_attr_in0_max.dev_attr.attr,
1286 &sensor_dev_attr_in0_min.dev_attr.attr,
1287 &sensor_dev_attr_in0_alarm.dev_attr.attr,
Jean Delvare378933c2009-12-09 20:36:06 +01001288 NULL
1289};
1290
Jean Delvared8d2ee02009-12-09 20:36:08 +01001291static struct attribute *in3_attrs[] = {
Jean Delvare3d849982009-12-09 20:36:05 +01001292 &sensor_dev_attr_in3_input.dev_attr.attr,
1293 &sensor_dev_attr_in3_max.dev_attr.attr,
1294 &sensor_dev_attr_in3_min.dev_attr.attr,
1295 &sensor_dev_attr_in3_alarm.dev_attr.attr,
Jean Delvared8d2ee02009-12-09 20:36:08 +01001296 NULL
1297};
1298
1299static struct attribute *in4_attrs[] = {
Jean Delvare3d849982009-12-09 20:36:05 +01001300 &sensor_dev_attr_in4_input.dev_attr.attr,
1301 &sensor_dev_attr_in4_max.dev_attr.attr,
1302 &sensor_dev_attr_in4_min.dev_attr.attr,
1303 &sensor_dev_attr_in4_alarm.dev_attr.attr,
Jean Delvared8d2ee02009-12-09 20:36:08 +01001304 NULL
1305};
1306
1307static struct attribute *in5_attrs[] = {
Jean Delvare3d849982009-12-09 20:36:05 +01001308 &sensor_dev_attr_in5_input.dev_attr.attr,
1309 &sensor_dev_attr_in5_max.dev_attr.attr,
1310 &sensor_dev_attr_in5_min.dev_attr.attr,
1311 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1312 NULL
1313};
1314
Jean Delvare54fe4672009-12-09 20:36:08 +01001315static struct attribute *vid_attrs[] = {
1316 &dev_attr_cpu0_vid.attr,
1317 &dev_attr_vrm.attr,
1318 NULL
1319};
1320
Arvind Yadavf5397be2017-07-05 11:04:04 +05301321static const struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs };
1322static const struct attribute_group fan4_attr_group = { .attrs = fan4_attrs };
1323static const struct attribute_group pwm2_attr_group = { .attrs = pwm2_attrs };
1324static const struct attribute_group in0_attr_group = { .attrs = in0_attrs };
1325static const struct attribute_group in3_attr_group = { .attrs = in3_attrs };
1326static const struct attribute_group in4_attr_group = { .attrs = in4_attrs };
1327static const struct attribute_group in5_attr_group = { .attrs = in5_attrs };
1328static const struct attribute_group vid_attr_group = { .attrs = vid_attrs };
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001329
Jean Delvare310ec792009-12-14 21:17:23 +01001330static int adt7475_detect(struct i2c_client *client,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001331 struct i2c_board_info *info)
1332{
1333 struct i2c_adapter *adapter = client->adapter;
Jean Delvared656b6f2009-12-09 20:36:04 +01001334 int vendid, devid, devid2;
Jean Delvareb180d052009-12-09 20:36:02 +01001335 const char *name;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001336
1337 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1338 return -ENODEV;
1339
Jean Delvareb180d052009-12-09 20:36:02 +01001340 vendid = adt7475_read(REG_VENDID);
Jean Delvared656b6f2009-12-09 20:36:04 +01001341 devid2 = adt7475_read(REG_DEVID2);
1342 if (vendid != 0x41 || /* Analog Devices */
1343 (devid2 & 0xf8) != 0x68)
1344 return -ENODEV;
Jean Delvareb180d052009-12-09 20:36:02 +01001345
Jean Delvared656b6f2009-12-09 20:36:04 +01001346 devid = adt7475_read(REG_DEVID);
1347 if (devid == 0x73)
Jean Delvareb180d052009-12-09 20:36:02 +01001348 name = "adt7473";
Jean Delvared656b6f2009-12-09 20:36:04 +01001349 else if (devid == 0x75 && client->addr == 0x2e)
Jean Delvareb180d052009-12-09 20:36:02 +01001350 name = "adt7475";
Jean Delvared8d2ee02009-12-09 20:36:08 +01001351 else if (devid == 0x76)
1352 name = "adt7476";
Jean Delvare3d849982009-12-09 20:36:05 +01001353 else if ((devid2 & 0xfc) == 0x6c)
1354 name = "adt7490";
Jean Delvareb180d052009-12-09 20:36:02 +01001355 else {
1356 dev_dbg(&adapter->dev,
Jean Delvared8d2ee02009-12-09 20:36:08 +01001357 "Couldn't detect an ADT7473/75/76/90 part at "
Jean Delvareb180d052009-12-09 20:36:02 +01001358 "0x%02x\n", (unsigned int)client->addr);
Jean Delvare52df6442009-12-09 20:35:57 +01001359 return -ENODEV;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001360 }
1361
Jean Delvareb180d052009-12-09 20:36:02 +01001362 strlcpy(info->type, name, I2C_NAME_SIZE);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001363
1364 return 0;
1365}
1366
Jean Delvare0f144802009-12-09 20:36:06 +01001367static void adt7475_remove_files(struct i2c_client *client,
1368 struct adt7475_data *data)
1369{
1370 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group);
Jean Delvare378933c2009-12-09 20:36:06 +01001371 if (data->has_fan4)
1372 sysfs_remove_group(&client->dev.kobj, &fan4_attr_group);
1373 if (data->has_pwm2)
1374 sysfs_remove_group(&client->dev.kobj, &pwm2_attr_group);
1375 if (data->has_voltage & (1 << 0))
1376 sysfs_remove_group(&client->dev.kobj, &in0_attr_group);
Jean Delvared8d2ee02009-12-09 20:36:08 +01001377 if (data->has_voltage & (1 << 3))
1378 sysfs_remove_group(&client->dev.kobj, &in3_attr_group);
1379 if (data->has_voltage & (1 << 4))
1380 sysfs_remove_group(&client->dev.kobj, &in4_attr_group);
1381 if (data->has_voltage & (1 << 5))
1382 sysfs_remove_group(&client->dev.kobj, &in5_attr_group);
Jean Delvare54fe4672009-12-09 20:36:08 +01001383 if (data->has_vid)
1384 sysfs_remove_group(&client->dev.kobj, &vid_attr_group);
Jean Delvare0f144802009-12-09 20:36:06 +01001385}
1386
Tokunori Ikegami5cf943e2018-08-08 10:32:16 +09001387static void adt7475_update_limits(struct i2c_client *client)
1388{
1389 struct adt7475_data *data = i2c_get_clientdata(client);
1390 int i;
1391
1392 data->config4 = adt7475_read(REG_CONFIG4);
1393 data->config5 = adt7475_read(REG_CONFIG5);
1394
1395 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
1396 if (!(data->has_voltage & (1 << i)))
1397 continue;
1398 /* Adjust values so they match the input precision */
1399 data->voltage[MIN][i] =
1400 adt7475_read(VOLTAGE_MIN_REG(i)) << 2;
1401 data->voltage[MAX][i] =
1402 adt7475_read(VOLTAGE_MAX_REG(i)) << 2;
1403 }
1404
1405 if (data->has_voltage & (1 << 5)) {
1406 data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2;
1407 data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2;
1408 }
1409
1410 for (i = 0; i < ADT7475_TEMP_COUNT; i++) {
1411 /* Adjust values so they match the input precision */
1412 data->temp[MIN][i] =
1413 adt7475_read(TEMP_MIN_REG(i)) << 2;
1414 data->temp[MAX][i] =
1415 adt7475_read(TEMP_MAX_REG(i)) << 2;
1416 data->temp[AUTOMIN][i] =
1417 adt7475_read(TEMP_TMIN_REG(i)) << 2;
1418 data->temp[THERM][i] =
1419 adt7475_read(TEMP_THERM_REG(i)) << 2;
1420 data->temp[OFFSET][i] =
1421 adt7475_read(TEMP_OFFSET_REG(i));
1422 }
1423 adt7475_read_hystersis(client);
1424
1425 for (i = 0; i < ADT7475_TACH_COUNT; i++) {
1426 if (i == 3 && !data->has_fan4)
1427 continue;
1428 data->tach[MIN][i] =
1429 adt7475_read_word(client, TACH_MIN_REG(i));
1430 }
1431
1432 for (i = 0; i < ADT7475_PWM_COUNT; i++) {
1433 if (i == 1 && !data->has_pwm2)
1434 continue;
1435 data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i));
1436 data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i));
1437 /* Set the channel and control information */
1438 adt7475_read_pwm(client, i);
1439 }
1440
1441 data->range[0] = adt7475_read(TEMP_TRANGE_REG(0));
1442 data->range[1] = adt7475_read(TEMP_TRANGE_REG(1));
1443 data->range[2] = adt7475_read(TEMP_TRANGE_REG(2));
1444}
1445
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001446static int adt7475_probe(struct i2c_client *client,
1447 const struct i2c_device_id *id)
1448{
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -03001449 enum chips chip;
Frans Meulenbroeks99b8c832012-01-08 19:34:08 +01001450 static const char * const names[] = {
Jean Delvared07ca4a2009-12-09 20:36:07 +01001451 [adt7473] = "ADT7473",
1452 [adt7475] = "ADT7475",
Jean Delvared8d2ee02009-12-09 20:36:08 +01001453 [adt7476] = "ADT7476",
Jean Delvared07ca4a2009-12-09 20:36:07 +01001454 [adt7490] = "ADT7490",
1455 };
1456
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001457 struct adt7475_data *data;
Jean Delvare378933c2009-12-09 20:36:06 +01001458 int i, ret = 0, revision;
Jean Delvareebfaf1f2009-12-09 20:36:07 +01001459 u8 config2, config3;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001460
Guenter Roecke3ecb2e2012-06-02 09:58:01 -07001461 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001462 if (data == NULL)
1463 return -ENOMEM;
1464
1465 mutex_init(&data->lock);
1466 i2c_set_clientdata(client, data);
1467
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -03001468 if (client->dev.of_node)
1469 chip = (enum chips)of_device_get_match_data(&client->dev);
1470 else
1471 chip = id->driver_data;
1472
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001473 /* Initialize device-specific values */
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -03001474 switch (chip) {
Jean Delvared8d2ee02009-12-09 20:36:08 +01001475 case adt7476:
1476 data->has_voltage = 0x0e; /* in1 to in3 */
1477 revision = adt7475_read(REG_DEVID2) & 0x07;
1478 break;
Jean Delvare3d849982009-12-09 20:36:05 +01001479 case adt7490:
Jean Delvare378933c2009-12-09 20:36:06 +01001480 data->has_voltage = 0x3e; /* in1 to in5 */
1481 revision = adt7475_read(REG_DEVID2) & 0x03;
Jean Delvared07ca4a2009-12-09 20:36:07 +01001482 if (revision == 0x03)
1483 revision += adt7475_read(REG_DEVREV2);
Jean Delvare3d849982009-12-09 20:36:05 +01001484 break;
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001485 default:
1486 data->has_voltage = 0x06; /* in1, in2 */
Jean Delvare378933c2009-12-09 20:36:06 +01001487 revision = adt7475_read(REG_DEVID2) & 0x07;
1488 }
1489
1490 config3 = adt7475_read(REG_CONFIG3);
1491 /* Pin PWM2 may alternatively be used for ALERT output */
1492 if (!(config3 & CONFIG3_SMBALERT))
1493 data->has_pwm2 = 1;
1494 /* Meaning of this bit is inverted for the ADT7473-1 */
1495 if (id->driver_data == adt7473 && revision >= 1)
1496 data->has_pwm2 = !data->has_pwm2;
1497
1498 data->config4 = adt7475_read(REG_CONFIG4);
1499 /* Pin TACH4 may alternatively be used for THERM */
1500 if ((data->config4 & CONFIG4_PINFUNC) == 0x0)
1501 data->has_fan4 = 1;
1502
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001503 /*
1504 * THERM configuration is more complex on the ADT7476 and ADT7490,
1505 * because 2 different pins (TACH4 and +2.5 Vin) can be used for
1506 * this function
1507 */
Jean Delvare378933c2009-12-09 20:36:06 +01001508 if (id->driver_data == adt7490) {
1509 if ((data->config4 & CONFIG4_PINFUNC) == 0x1 &&
1510 !(config3 & CONFIG3_THERM))
1511 data->has_fan4 = 1;
Jean Delvared8d2ee02009-12-09 20:36:08 +01001512 }
1513 if (id->driver_data == adt7476 || id->driver_data == adt7490) {
Jean Delvare378933c2009-12-09 20:36:06 +01001514 if (!(config3 & CONFIG3_THERM) ||
1515 (data->config4 & CONFIG4_PINFUNC) == 0x1)
1516 data->has_voltage |= (1 << 0); /* in0 */
Jean Delvarecffb9dd2009-12-09 20:36:03 +01001517 }
1518
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001519 /*
1520 * On the ADT7476, the +12V input pin may instead be used as VID5,
1521 * and VID pins may alternatively be used as GPIO
1522 */
Jean Delvared8d2ee02009-12-09 20:36:08 +01001523 if (id->driver_data == adt7476) {
1524 u8 vid = adt7475_read(REG_VID);
1525 if (!(vid & VID_VIDSEL))
1526 data->has_voltage |= (1 << 4); /* in4 */
Jean Delvare54fe4672009-12-09 20:36:08 +01001527
1528 data->has_vid = !(adt7475_read(REG_CONFIG5) & CONFIG5_VIDGPIO);
Jean Delvared8d2ee02009-12-09 20:36:08 +01001529 }
1530
Jean Delvareebfaf1f2009-12-09 20:36:07 +01001531 /* Voltage attenuators can be bypassed, globally or individually */
1532 config2 = adt7475_read(REG_CONFIG2);
1533 if (config2 & CONFIG2_ATTN) {
1534 data->bypass_attn = (0x3 << 3) | 0x3;
1535 } else {
1536 data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) |
1537 ((data->config4 & CONFIG4_ATTN_IN43) >> 3);
1538 }
1539 data->bypass_attn &= data->has_voltage;
1540
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001541 /*
1542 * Call adt7475_read_pwm for all pwm's as this will reprogram any
1543 * pwm's which are disabled to manual mode with 0% duty cycle
1544 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001545 for (i = 0; i < ADT7475_PWM_COUNT; i++)
1546 adt7475_read_pwm(client, i);
1547
Chris Packham4abdf382017-04-22 07:08:09 +12001548 /* Start monitoring */
1549 switch (chip) {
1550 case adt7475:
1551 case adt7476:
1552 i2c_smbus_write_byte_data(client, REG_CONFIG1,
1553 adt7475_read(REG_CONFIG1) | 0x01);
1554 break;
1555 default:
1556 break;
1557 }
1558
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001559 ret = sysfs_create_group(&client->dev.kobj, &adt7475_attr_group);
1560 if (ret)
Guenter Roecke3ecb2e2012-06-02 09:58:01 -07001561 return ret;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001562
Jean Delvare378933c2009-12-09 20:36:06 +01001563 /* Features that can be disabled individually */
1564 if (data->has_fan4) {
1565 ret = sysfs_create_group(&client->dev.kobj, &fan4_attr_group);
1566 if (ret)
1567 goto eremove;
1568 }
1569 if (data->has_pwm2) {
1570 ret = sysfs_create_group(&client->dev.kobj, &pwm2_attr_group);
1571 if (ret)
1572 goto eremove;
1573 }
1574 if (data->has_voltage & (1 << 0)) {
1575 ret = sysfs_create_group(&client->dev.kobj, &in0_attr_group);
1576 if (ret)
1577 goto eremove;
1578 }
Jean Delvared8d2ee02009-12-09 20:36:08 +01001579 if (data->has_voltage & (1 << 3)) {
1580 ret = sysfs_create_group(&client->dev.kobj, &in3_attr_group);
1581 if (ret)
1582 goto eremove;
1583 }
1584 if (data->has_voltage & (1 << 4)) {
1585 ret = sysfs_create_group(&client->dev.kobj, &in4_attr_group);
1586 if (ret)
1587 goto eremove;
1588 }
1589 if (data->has_voltage & (1 << 5)) {
1590 ret = sysfs_create_group(&client->dev.kobj, &in5_attr_group);
1591 if (ret)
1592 goto eremove;
1593 }
Jean Delvare54fe4672009-12-09 20:36:08 +01001594 if (data->has_vid) {
1595 data->vrm = vid_which_vrm();
1596 ret = sysfs_create_group(&client->dev.kobj, &vid_attr_group);
1597 if (ret)
1598 goto eremove;
1599 }
Jean Delvare378933c2009-12-09 20:36:06 +01001600
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001601 data->hwmon_dev = hwmon_device_register(&client->dev);
1602 if (IS_ERR(data->hwmon_dev)) {
1603 ret = PTR_ERR(data->hwmon_dev);
1604 goto eremove;
1605 }
1606
Jean Delvared07ca4a2009-12-09 20:36:07 +01001607 dev_info(&client->dev, "%s device, revision %d\n",
1608 names[id->driver_data], revision);
Jean Delvared8d2ee02009-12-09 20:36:08 +01001609 if ((data->has_voltage & 0x11) || data->has_fan4 || data->has_pwm2)
Jean Delvare54fe4672009-12-09 20:36:08 +01001610 dev_info(&client->dev, "Optional features:%s%s%s%s%s\n",
Jean Delvared07ca4a2009-12-09 20:36:07 +01001611 (data->has_voltage & (1 << 0)) ? " in0" : "",
Jean Delvared8d2ee02009-12-09 20:36:08 +01001612 (data->has_voltage & (1 << 4)) ? " in4" : "",
Jean Delvared07ca4a2009-12-09 20:36:07 +01001613 data->has_fan4 ? " fan4" : "",
Jean Delvare54fe4672009-12-09 20:36:08 +01001614 data->has_pwm2 ? " pwm2" : "",
1615 data->has_vid ? " vid" : "");
Jean Delvareebfaf1f2009-12-09 20:36:07 +01001616 if (data->bypass_attn)
1617 dev_info(&client->dev, "Bypassing attenuators on:%s%s%s%s\n",
1618 (data->bypass_attn & (1 << 0)) ? " in0" : "",
1619 (data->bypass_attn & (1 << 1)) ? " in1" : "",
1620 (data->bypass_attn & (1 << 3)) ? " in3" : "",
1621 (data->bypass_attn & (1 << 4)) ? " in4" : "");
Jean Delvared07ca4a2009-12-09 20:36:07 +01001622
Tokunori Ikegami5cf943e2018-08-08 10:32:16 +09001623 /* Limits and settings, should never change update more than once */
1624 adt7475_update_limits(client);
1625
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001626 return 0;
1627
1628eremove:
Jean Delvare0f144802009-12-09 20:36:06 +01001629 adt7475_remove_files(client, data);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001630 return ret;
1631}
1632
1633static int adt7475_remove(struct i2c_client *client)
1634{
1635 struct adt7475_data *data = i2c_get_clientdata(client);
1636
1637 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare0f144802009-12-09 20:36:06 +01001638 adt7475_remove_files(client, data);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001639
1640 return 0;
1641}
1642
1643static struct i2c_driver adt7475_driver = {
1644 .class = I2C_CLASS_HWMON,
1645 .driver = {
1646 .name = "adt7475",
Javier Martinez Canillas4e2496e2017-02-24 10:12:58 -03001647 .of_match_table = of_match_ptr(adt7475_of_match),
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001648 },
1649 .probe = adt7475_probe,
1650 .remove = adt7475_remove,
1651 .id_table = adt7475_id,
1652 .detect = adt7475_detect,
Jean Delvarec3813d62009-12-14 21:17:25 +01001653 .address_list = normal_i2c,
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001654};
1655
1656static void adt7475_read_hystersis(struct i2c_client *client)
1657{
1658 struct adt7475_data *data = i2c_get_clientdata(client);
1659
1660 data->temp[HYSTERSIS][0] = (u16) adt7475_read(REG_REMOTE1_HYSTERSIS);
1661 data->temp[HYSTERSIS][1] = data->temp[HYSTERSIS][0];
1662 data->temp[HYSTERSIS][2] = (u16) adt7475_read(REG_REMOTE2_HYSTERSIS);
1663}
1664
1665static void adt7475_read_pwm(struct i2c_client *client, int index)
1666{
1667 struct adt7475_data *data = i2c_get_clientdata(client);
1668 unsigned int v;
1669
1670 data->pwm[CONTROL][index] = adt7475_read(PWM_CONFIG_REG(index));
1671
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001672 /*
1673 * Figure out the internal value for pwmctrl and pwmchan
1674 * based on the current settings
1675 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001676 v = (data->pwm[CONTROL][index] >> 5) & 7;
1677
1678 if (v == 3)
1679 data->pwmctl[index] = 0;
1680 else if (v == 7)
1681 data->pwmctl[index] = 1;
1682 else if (v == 4) {
Guenter Roeck9ed5bc22012-01-19 11:02:15 -08001683 /*
1684 * The fan is disabled - we don't want to
1685 * support that, so change to manual mode and
1686 * set the duty cycle to 0 instead
1687 */
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001688 data->pwm[INPUT][index] = 0;
1689 data->pwm[CONTROL][index] &= ~0xE0;
1690 data->pwm[CONTROL][index] |= (7 << 5);
1691
1692 i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index),
1693 data->pwm[INPUT][index]);
1694
1695 i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index),
1696 data->pwm[CONTROL][index]);
1697
1698 data->pwmctl[index] = 1;
1699 } else {
1700 data->pwmctl[index] = 2;
1701
1702 switch (v) {
1703 case 0:
1704 data->pwmchan[index] = 1;
1705 break;
1706 case 1:
1707 data->pwmchan[index] = 2;
1708 break;
1709 case 2:
1710 data->pwmchan[index] = 4;
1711 break;
1712 case 5:
1713 data->pwmchan[index] = 6;
1714 break;
1715 case 6:
1716 data->pwmchan[index] = 7;
1717 break;
1718 }
1719 }
1720}
1721
Tokunori Ikegami5cf943e2018-08-08 10:32:16 +09001722static void adt7475_update_measure(struct device *dev)
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001723{
1724 struct i2c_client *client = to_i2c_client(dev);
1725 struct adt7475_data *data = i2c_get_clientdata(client);
Jean Delvare3d849982009-12-09 20:36:05 +01001726 u16 ext;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001727 int i;
1728
Tokunori Ikegami5cf943e2018-08-08 10:32:16 +09001729 data->alarms = adt7475_read(REG_STATUS2) << 8;
1730 data->alarms |= adt7475_read(REG_STATUS1);
1731
1732 ext = (adt7475_read(REG_EXTEND2) << 8) |
1733 adt7475_read(REG_EXTEND1);
1734 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
1735 if (!(data->has_voltage & (1 << i)))
1736 continue;
1737 data->voltage[INPUT][i] =
1738 (adt7475_read(VOLTAGE_REG(i)) << 2) |
1739 ((ext >> (i * 2)) & 3);
1740 }
1741
1742 for (i = 0; i < ADT7475_TEMP_COUNT; i++)
1743 data->temp[INPUT][i] =
1744 (adt7475_read(TEMP_REG(i)) << 2) |
1745 ((ext >> ((i + 5) * 2)) & 3);
1746
1747 if (data->has_voltage & (1 << 5)) {
1748 data->alarms |= adt7475_read(REG_STATUS4) << 24;
1749 ext = adt7475_read(REG_EXTEND3);
1750 data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 |
1751 ((ext >> 4) & 3);
1752 }
1753
1754 for (i = 0; i < ADT7475_TACH_COUNT; i++) {
1755 if (i == 3 && !data->has_fan4)
1756 continue;
1757 data->tach[INPUT][i] =
1758 adt7475_read_word(client, TACH_REG(i));
1759 }
1760
1761 /* Updated by hw when in auto mode */
1762 for (i = 0; i < ADT7475_PWM_COUNT; i++) {
1763 if (i == 1 && !data->has_pwm2)
1764 continue;
1765 data->pwm[INPUT][i] = adt7475_read(PWM_REG(i));
1766 }
1767
1768 if (data->has_vid)
1769 data->vid = adt7475_read(REG_VID) & 0x3f;
1770}
1771
1772static struct adt7475_data *adt7475_update_device(struct device *dev)
1773{
1774 struct i2c_client *client = to_i2c_client(dev);
1775 struct adt7475_data *data = i2c_get_clientdata(client);
1776
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001777 mutex_lock(&data->lock);
1778
1779 /* Measurement values update every 2 seconds */
1780 if (time_after(jiffies, data->measure_updated + HZ * 2) ||
1781 !data->valid) {
Tokunori Ikegami5cf943e2018-08-08 10:32:16 +09001782 adt7475_update_measure(dev);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001783 data->measure_updated = jiffies;
Tokunori Ikegamib36fb172018-08-08 10:32:17 +09001784 data->valid = true;
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001785 }
1786
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001787 mutex_unlock(&data->lock);
1788
1789 return data;
1790}
1791
Axel Linf0967ee2012-01-20 15:38:18 +08001792module_i2c_driver(adt7475_driver);
Jordan Crouse1c301fc2009-01-15 22:27:47 +01001793
1794MODULE_AUTHOR("Advanced Micro Devices, Inc");
1795MODULE_DESCRIPTION("adt7475 driver");
1796MODULE_LICENSE("GPL");