aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adt7475.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/adt7475.c')
-rw-r--r--drivers/hwmon/adt7475.c538
1 files changed, 468 insertions, 70 deletions
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index b5a95193c694..99abfddedbc3 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -3,7 +3,8 @@
3 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc. 3 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net> 4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
5 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com> 5 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
6 6 * Copyright (C) 2009 Jean Delvare <khali@linux-fr.org>
7 *
7 * Derived from the lm83 driver by Jean Delvare 8 * Derived from the lm83 driver by Jean Delvare
8 * 9 *
9 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
@@ -17,6 +18,7 @@
17#include <linux/i2c.h> 18#include <linux/i2c.h>
18#include <linux/hwmon.h> 19#include <linux/hwmon.h>
19#include <linux/hwmon-sysfs.h> 20#include <linux/hwmon-sysfs.h>
21#include <linux/hwmon-vid.h>
20#include <linux/err.h> 22#include <linux/err.h>
21 23
22/* Indexes for the sysfs hooks */ 24/* Indexes for the sysfs hooks */
@@ -39,7 +41,12 @@
39 41
40/* 7475 Common Registers */ 42/* 7475 Common Registers */
41 43
42#define REG_VOLTAGE_BASE 0x21 44#define REG_DEVREV2 0x12 /* ADT7490 only */
45
46#define REG_VTT 0x1E /* ADT7490 only */
47#define REG_EXTEND3 0x1F /* ADT7490 only */
48
49#define REG_VOLTAGE_BASE 0x20
43#define REG_TEMP_BASE 0x25 50#define REG_TEMP_BASE 0x25
44#define REG_TACH_BASE 0x28 51#define REG_TACH_BASE 0x28
45#define REG_PWM_BASE 0x30 52#define REG_PWM_BASE 0x30
@@ -47,12 +54,15 @@
47 54
48#define REG_DEVID 0x3D 55#define REG_DEVID 0x3D
49#define REG_VENDID 0x3E 56#define REG_VENDID 0x3E
57#define REG_DEVID2 0x3F
50 58
51#define REG_STATUS1 0x41 59#define REG_STATUS1 0x41
52#define REG_STATUS2 0x42 60#define REG_STATUS2 0x42
53 61
54#define REG_VOLTAGE_MIN_BASE 0x46 62#define REG_VID 0x43 /* ADT7476 only */
55#define REG_VOLTAGE_MAX_BASE 0x47 63
64#define REG_VOLTAGE_MIN_BASE 0x44
65#define REG_VOLTAGE_MAX_BASE 0x45
56 66
57#define REG_TEMP_MIN_BASE 0x4E 67#define REG_TEMP_MIN_BASE 0x4E
58#define REG_TEMP_MAX_BASE 0x4F 68#define REG_TEMP_MAX_BASE 0x4F
@@ -73,16 +83,39 @@
73 83
74#define REG_TEMP_OFFSET_BASE 0x70 84#define REG_TEMP_OFFSET_BASE 0x70
75 85
86#define REG_CONFIG2 0x73
87
76#define REG_EXTEND1 0x76 88#define REG_EXTEND1 0x76
77#define REG_EXTEND2 0x77 89#define REG_EXTEND2 0x77
90
91#define REG_CONFIG3 0x78
78#define REG_CONFIG5 0x7C 92#define REG_CONFIG5 0x7C
93#define REG_CONFIG4 0x7D
94
95#define REG_STATUS4 0x81 /* ADT7490 only */
96
97#define REG_VTT_MIN 0x84 /* ADT7490 only */
98#define REG_VTT_MAX 0x86 /* ADT7490 only */
99
100#define VID_VIDSEL 0x80 /* ADT7476 only */
101
102#define CONFIG2_ATTN 0x20
103
104#define CONFIG3_SMBALERT 0x01
105#define CONFIG3_THERM 0x02
106
107#define CONFIG4_PINFUNC 0x03
108#define CONFIG4_MAXDUTY 0x08
109#define CONFIG4_ATTN_IN10 0x30
110#define CONFIG4_ATTN_IN43 0xC0
79 111
80#define CONFIG5_TWOSCOMP 0x01 112#define CONFIG5_TWOSCOMP 0x01
81#define CONFIG5_TEMPOFFSET 0x02 113#define CONFIG5_TEMPOFFSET 0x02
114#define CONFIG5_VIDGPIO 0x10 /* ADT7476 only */
82 115
83/* ADT7475 Settings */ 116/* ADT7475 Settings */
84 117
85#define ADT7475_VOLTAGE_COUNT 2 118#define ADT7475_VOLTAGE_COUNT 5 /* Not counting Vtt */
86#define ADT7475_TEMP_COUNT 3 119#define ADT7475_TEMP_COUNT 3
87#define ADT7475_TACH_COUNT 4 120#define ADT7475_TACH_COUNT 4
88#define ADT7475_PWM_COUNT 3 121#define ADT7475_PWM_COUNT 3
@@ -113,12 +146,15 @@
113#define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx)) 146#define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx))
114#define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx)) 147#define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx))
115 148
116static unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END }; 149static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
117 150
118I2C_CLIENT_INSMOD_1(adt7475); 151I2C_CLIENT_INSMOD_4(adt7473, adt7475, adt7476, adt7490);
119 152
120static const struct i2c_device_id adt7475_id[] = { 153static const struct i2c_device_id adt7475_id[] = {
154 { "adt7473", adt7473 },
121 { "adt7475", adt7475 }, 155 { "adt7475", adt7475 },
156 { "adt7476", adt7476 },
157 { "adt7490", adt7490 },
122 { } 158 { }
123}; 159};
124MODULE_DEVICE_TABLE(i2c, adt7475_id); 160MODULE_DEVICE_TABLE(i2c, adt7475_id);
@@ -131,15 +167,24 @@ struct adt7475_data {
131 unsigned long limits_updated; 167 unsigned long limits_updated;
132 char valid; 168 char valid;
133 169
170 u8 config4;
134 u8 config5; 171 u8 config5;
135 u16 alarms; 172 u8 has_voltage;
136 u16 voltage[3][3]; 173 u8 bypass_attn; /* Bypass voltage attenuator */
174 u8 has_pwm2:1;
175 u8 has_fan4:1;
176 u8 has_vid:1;
177 u32 alarms;
178 u16 voltage[3][6];
137 u16 temp[7][3]; 179 u16 temp[7][3];
138 u16 tach[2][4]; 180 u16 tach[2][4];
139 u8 pwm[4][3]; 181 u8 pwm[4][3];
140 u8 range[3]; 182 u8 range[3];
141 u8 pwmctl[3]; 183 u8 pwmctl[3];
142 u8 pwmchan[3]; 184 u8 pwmchan[3];
185
186 u8 vid;
187 u8 vrm;
143}; 188};
144 189
145static struct i2c_driver adt7475_driver; 190static struct i2c_driver adt7475_driver;
@@ -196,26 +241,35 @@ static inline u16 rpm2tach(unsigned long rpm)
196 return SENSORS_LIMIT((90000 * 60) / rpm, 1, 0xFFFF); 241 return SENSORS_LIMIT((90000 * 60) / rpm, 1, 0xFFFF);
197} 242}
198 243
199static inline int reg2vcc(u16 reg) 244/* Scaling factors for voltage inputs, taken from the ADT7490 datasheet */
200{ 245static const int adt7473_in_scaling[ADT7475_VOLTAGE_COUNT + 1][2] = {
201 return (4296 * reg) / 1000; 246 { 45, 94 }, /* +2.5V */
202} 247 { 175, 525 }, /* Vccp */
248 { 68, 71 }, /* Vcc */
249 { 93, 47 }, /* +5V */
250 { 120, 20 }, /* +12V */
251 { 45, 45 }, /* Vtt */
252};
203 253
204static inline int reg2vccp(u16 reg) 254static inline int reg2volt(int channel, u16 reg, u8 bypass_attn)
205{ 255{
206 return (2929 * reg) / 1000; 256 const int *r = adt7473_in_scaling[channel];
207}
208 257
209static inline u16 vcc2reg(long vcc) 258 if (bypass_attn & (1 << channel))
210{ 259 return DIV_ROUND_CLOSEST(reg * 2250, 1024);
211 vcc = SENSORS_LIMIT(vcc, 0, 4396); 260 return DIV_ROUND_CLOSEST(reg * (r[0] + r[1]) * 2250, r[1] * 1024);
212 return (vcc * 1000) / 4296;
213} 261}
214 262
215static inline u16 vccp2reg(long vcc) 263static inline u16 volt2reg(int channel, long volt, u8 bypass_attn)
216{ 264{
217 vcc = SENSORS_LIMIT(vcc, 0, 2998); 265 const int *r = adt7473_in_scaling[channel];
218 return (vcc * 1000) / 2929; 266 long reg;
267
268 if (bypass_attn & (1 << channel))
269 reg = (volt * 1024) / 2250;
270 else
271 reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250);
272 return SENSORS_LIMIT(reg, 0, 1023) & (0xff << 2);
219} 273}
220 274
221static u16 adt7475_read_word(struct i2c_client *client, int reg) 275static u16 adt7475_read_word(struct i2c_client *client, int reg)
@@ -271,12 +325,11 @@ static ssize_t show_voltage(struct device *dev, struct device_attribute *attr,
271 switch (sattr->nr) { 325 switch (sattr->nr) {
272 case ALARM: 326 case ALARM:
273 return sprintf(buf, "%d\n", 327 return sprintf(buf, "%d\n",
274 (data->alarms >> (sattr->index + 1)) & 1); 328 (data->alarms >> sattr->index) & 1);
275 default: 329 default:
276 val = data->voltage[sattr->nr][sattr->index]; 330 val = data->voltage[sattr->nr][sattr->index];
277 return sprintf(buf, "%d\n", 331 return sprintf(buf, "%d\n",
278 sattr->index == 332 reg2volt(sattr->index, val, data->bypass_attn));
279 0 ? reg2vccp(val) : reg2vcc(val));
280 } 333 }
281} 334}
282 335
@@ -296,12 +349,19 @@ static ssize_t set_voltage(struct device *dev, struct device_attribute *attr,
296 mutex_lock(&data->lock); 349 mutex_lock(&data->lock);
297 350
298 data->voltage[sattr->nr][sattr->index] = 351 data->voltage[sattr->nr][sattr->index] =
299 sattr->index ? vcc2reg(val) : vccp2reg(val); 352 volt2reg(sattr->index, val, data->bypass_attn);
300 353
301 if (sattr->nr == MIN) 354 if (sattr->index < ADT7475_VOLTAGE_COUNT) {
302 reg = VOLTAGE_MIN_REG(sattr->index); 355 if (sattr->nr == MIN)
303 else 356 reg = VOLTAGE_MIN_REG(sattr->index);
304 reg = VOLTAGE_MAX_REG(sattr->index); 357 else
358 reg = VOLTAGE_MAX_REG(sattr->index);
359 } else {
360 if (sattr->nr == MIN)
361 reg = REG_VTT_MIN;
362 else
363 reg = REG_VTT_MAX;
364 }
305 365
306 i2c_smbus_write_byte_data(client, reg, 366 i2c_smbus_write_byte_data(client, reg,
307 data->voltage[sattr->nr][sattr->index] >> 2); 367 data->voltage[sattr->nr][sattr->index] >> 2);
@@ -778,18 +838,103 @@ static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
778 return count; 838 return count;
779} 839}
780 840
781static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_voltage, NULL, INPUT, 0); 841static ssize_t show_pwm_at_crit(struct device *dev,
782static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_voltage, 842 struct device_attribute *devattr, char *buf)
843{
844 struct adt7475_data *data = adt7475_update_device(dev);
845 return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY));
846}
847
848static ssize_t set_pwm_at_crit(struct device *dev,
849 struct device_attribute *devattr,
850 const char *buf, size_t count)
851{
852 struct i2c_client *client = to_i2c_client(dev);
853 struct adt7475_data *data = i2c_get_clientdata(client);
854 long val;
855
856 if (strict_strtol(buf, 10, &val))
857 return -EINVAL;
858 if (val != 0 && val != 1)
859 return -EINVAL;
860
861 mutex_lock(&data->lock);
862 data->config4 = i2c_smbus_read_byte_data(client, REG_CONFIG4);
863 if (val)
864 data->config4 |= CONFIG4_MAXDUTY;
865 else
866 data->config4 &= ~CONFIG4_MAXDUTY;
867 i2c_smbus_write_byte_data(client, REG_CONFIG4, data->config4);
868 mutex_unlock(&data->lock);
869
870 return count;
871}
872
873static ssize_t show_vrm(struct device *dev, struct device_attribute *devattr,
874 char *buf)
875{
876 struct adt7475_data *data = dev_get_drvdata(dev);
877 return sprintf(buf, "%d\n", (int)data->vrm);
878}
879
880static ssize_t set_vrm(struct device *dev, struct device_attribute *devattr,
881 const char *buf, size_t count)
882{
883 struct adt7475_data *data = dev_get_drvdata(dev);
884 long val;
885
886 if (strict_strtol(buf, 10, &val))
887 return -EINVAL;
888 if (val < 0 || val > 255)
889 return -EINVAL;
890 data->vrm = val;
891
892 return count;
893}
894
895static ssize_t show_vid(struct device *dev, struct device_attribute *devattr,
896 char *buf)
897{
898 struct adt7475_data *data = adt7475_update_device(dev);
899 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
900}
901
902static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_voltage, NULL, INPUT, 0);
903static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_voltage,
783 set_voltage, MAX, 0); 904 set_voltage, MAX, 0);
784static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_voltage, 905static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_voltage,
785 set_voltage, MIN, 0); 906 set_voltage, MIN, 0);
786static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, show_voltage, NULL, ALARM, 0); 907static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, show_voltage, NULL, ALARM, 0);
787static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_voltage, NULL, INPUT, 1); 908static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_voltage, NULL, INPUT, 1);
788static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_voltage, 909static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_voltage,
789 set_voltage, MAX, 1); 910 set_voltage, MAX, 1);
790static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_voltage, 911static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_voltage,
791 set_voltage, MIN, 1); 912 set_voltage, MIN, 1);
792static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_voltage, NULL, ALARM, 1); 913static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, show_voltage, NULL, ALARM, 1);
914static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_voltage, NULL, INPUT, 2);
915static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_voltage,
916 set_voltage, MAX, 2);
917static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_voltage,
918 set_voltage, MIN, 2);
919static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_voltage, NULL, ALARM, 2);
920static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_voltage, NULL, INPUT, 3);
921static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_voltage,
922 set_voltage, MAX, 3);
923static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_voltage,
924 set_voltage, MIN, 3);
925static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, show_voltage, NULL, ALARM, 3);
926static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_voltage, NULL, INPUT, 4);
927static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_voltage,
928 set_voltage, MAX, 4);
929static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_voltage,
930 set_voltage, MIN, 4);
931static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, show_voltage, NULL, ALARM, 8);
932static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_voltage, NULL, INPUT, 5);
933static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_voltage,
934 set_voltage, MAX, 5);
935static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_voltage,
936 set_voltage, MIN, 5);
937static SENSOR_DEVICE_ATTR_2(in5_alarm, S_IRUGO, show_voltage, NULL, ALARM, 31);
793static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, INPUT, 0); 938static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, INPUT, 0);
794static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, show_temp, NULL, ALARM, 0); 939static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, show_temp, NULL, ALARM, 0);
795static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_temp, NULL, FAULT, 0); 940static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_temp, NULL, FAULT, 0);
@@ -893,6 +1038,13 @@ static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
893static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm, 1038static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
894 set_pwm, MAX, 2); 1039 set_pwm, MAX, 2);
895 1040
1041/* Non-standard name, might need revisiting */
1042static DEVICE_ATTR(pwm_use_point2_pwm_at_crit, S_IWUSR | S_IRUGO,
1043 show_pwm_at_crit, set_pwm_at_crit);
1044
1045static DEVICE_ATTR(vrm, S_IWUSR | S_IRUGO, show_vrm, set_vrm);
1046static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
1047
896static struct attribute *adt7475_attrs[] = { 1048static struct attribute *adt7475_attrs[] = {
897 &sensor_dev_attr_in1_input.dev_attr.attr, 1049 &sensor_dev_attr_in1_input.dev_attr.attr,
898 &sensor_dev_attr_in1_max.dev_attr.attr, 1050 &sensor_dev_attr_in1_max.dev_attr.attr,
@@ -940,60 +1092,156 @@ static struct attribute *adt7475_attrs[] = {
940 &sensor_dev_attr_fan3_input.dev_attr.attr, 1092 &sensor_dev_attr_fan3_input.dev_attr.attr,
941 &sensor_dev_attr_fan3_min.dev_attr.attr, 1093 &sensor_dev_attr_fan3_min.dev_attr.attr,
942 &sensor_dev_attr_fan3_alarm.dev_attr.attr, 1094 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
943 &sensor_dev_attr_fan4_input.dev_attr.attr,
944 &sensor_dev_attr_fan4_min.dev_attr.attr,
945 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
946 &sensor_dev_attr_pwm1.dev_attr.attr, 1095 &sensor_dev_attr_pwm1.dev_attr.attr,
947 &sensor_dev_attr_pwm1_freq.dev_attr.attr, 1096 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
948 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 1097 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
949 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, 1098 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
950 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, 1099 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
951 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, 1100 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
952 &sensor_dev_attr_pwm2.dev_attr.attr,
953 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
954 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
955 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
956 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
957 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
958 &sensor_dev_attr_pwm3.dev_attr.attr, 1101 &sensor_dev_attr_pwm3.dev_attr.attr,
959 &sensor_dev_attr_pwm3_freq.dev_attr.attr, 1102 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
960 &sensor_dev_attr_pwm3_enable.dev_attr.attr, 1103 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
961 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, 1104 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
962 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, 1105 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
963 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, 1106 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1107 &dev_attr_pwm_use_point2_pwm_at_crit.attr,
964 NULL, 1108 NULL,
965}; 1109};
966 1110
967struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs }; 1111static struct attribute *fan4_attrs[] = {
1112 &sensor_dev_attr_fan4_input.dev_attr.attr,
1113 &sensor_dev_attr_fan4_min.dev_attr.attr,
1114 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1115 NULL
1116};
1117
1118static struct attribute *pwm2_attrs[] = {
1119 &sensor_dev_attr_pwm2.dev_attr.attr,
1120 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1121 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1122 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1123 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1124 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1125 NULL
1126};
1127
1128static struct attribute *in0_attrs[] = {
1129 &sensor_dev_attr_in0_input.dev_attr.attr,
1130 &sensor_dev_attr_in0_max.dev_attr.attr,
1131 &sensor_dev_attr_in0_min.dev_attr.attr,
1132 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1133 NULL
1134};
1135
1136static struct attribute *in3_attrs[] = {
1137 &sensor_dev_attr_in3_input.dev_attr.attr,
1138 &sensor_dev_attr_in3_max.dev_attr.attr,
1139 &sensor_dev_attr_in3_min.dev_attr.attr,
1140 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1141 NULL
1142};
1143
1144static struct attribute *in4_attrs[] = {
1145 &sensor_dev_attr_in4_input.dev_attr.attr,
1146 &sensor_dev_attr_in4_max.dev_attr.attr,
1147 &sensor_dev_attr_in4_min.dev_attr.attr,
1148 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1149 NULL
1150};
1151
1152static struct attribute *in5_attrs[] = {
1153 &sensor_dev_attr_in5_input.dev_attr.attr,
1154 &sensor_dev_attr_in5_max.dev_attr.attr,
1155 &sensor_dev_attr_in5_min.dev_attr.attr,
1156 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1157 NULL
1158};
1159
1160static struct attribute *vid_attrs[] = {
1161 &dev_attr_cpu0_vid.attr,
1162 &dev_attr_vrm.attr,
1163 NULL
1164};
1165
1166static struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs };
1167static struct attribute_group fan4_attr_group = { .attrs = fan4_attrs };
1168static struct attribute_group pwm2_attr_group = { .attrs = pwm2_attrs };
1169static struct attribute_group in0_attr_group = { .attrs = in0_attrs };
1170static struct attribute_group in3_attr_group = { .attrs = in3_attrs };
1171static struct attribute_group in4_attr_group = { .attrs = in4_attrs };
1172static struct attribute_group in5_attr_group = { .attrs = in5_attrs };
1173static struct attribute_group vid_attr_group = { .attrs = vid_attrs };
968 1174
969static int adt7475_detect(struct i2c_client *client, int kind, 1175static int adt7475_detect(struct i2c_client *client, int kind,
970 struct i2c_board_info *info) 1176 struct i2c_board_info *info)
971{ 1177{
972 struct i2c_adapter *adapter = client->adapter; 1178 struct i2c_adapter *adapter = client->adapter;
1179 int vendid, devid, devid2;
1180 const char *name;
973 1181
974 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1182 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
975 return -ENODEV; 1183 return -ENODEV;
976 1184
977 if (kind <= 0) { 1185 vendid = adt7475_read(REG_VENDID);
978 if (adt7475_read(REG_VENDID) != 0x41 || 1186 devid2 = adt7475_read(REG_DEVID2);
979 adt7475_read(REG_DEVID) != 0x75) { 1187 if (vendid != 0x41 || /* Analog Devices */
980 dev_err(&adapter->dev, 1188 (devid2 & 0xf8) != 0x68)
981 "Couldn't detect a adt7475 part at 0x%02x\n", 1189 return -ENODEV;
982 (unsigned int)client->addr); 1190
983 return -ENODEV; 1191 devid = adt7475_read(REG_DEVID);
984 } 1192 if (devid == 0x73)
1193 name = "adt7473";
1194 else if (devid == 0x75 && client->addr == 0x2e)
1195 name = "adt7475";
1196 else if (devid == 0x76)
1197 name = "adt7476";
1198 else if ((devid2 & 0xfc) == 0x6c)
1199 name = "adt7490";
1200 else {
1201 dev_dbg(&adapter->dev,
1202 "Couldn't detect an ADT7473/75/76/90 part at "
1203 "0x%02x\n", (unsigned int)client->addr);
1204 return -ENODEV;
985 } 1205 }
986 1206
987 strlcpy(info->type, adt7475_id[0].name, I2C_NAME_SIZE); 1207 strlcpy(info->type, name, I2C_NAME_SIZE);
988 1208
989 return 0; 1209 return 0;
990} 1210}
991 1211
1212static void adt7475_remove_files(struct i2c_client *client,
1213 struct adt7475_data *data)
1214{
1215 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group);
1216 if (data->has_fan4)
1217 sysfs_remove_group(&client->dev.kobj, &fan4_attr_group);
1218 if (data->has_pwm2)
1219 sysfs_remove_group(&client->dev.kobj, &pwm2_attr_group);
1220 if (data->has_voltage & (1 << 0))
1221 sysfs_remove_group(&client->dev.kobj, &in0_attr_group);
1222 if (data->has_voltage & (1 << 3))
1223 sysfs_remove_group(&client->dev.kobj, &in3_attr_group);
1224 if (data->has_voltage & (1 << 4))
1225 sysfs_remove_group(&client->dev.kobj, &in4_attr_group);
1226 if (data->has_voltage & (1 << 5))
1227 sysfs_remove_group(&client->dev.kobj, &in5_attr_group);
1228 if (data->has_vid)
1229 sysfs_remove_group(&client->dev.kobj, &vid_attr_group);
1230}
1231
992static int adt7475_probe(struct i2c_client *client, 1232static int adt7475_probe(struct i2c_client *client,
993 const struct i2c_device_id *id) 1233 const struct i2c_device_id *id)
994{ 1234{
1235 static const char *names[] = {
1236 [adt7473] = "ADT7473",
1237 [adt7475] = "ADT7475",
1238 [adt7476] = "ADT7476",
1239 [adt7490] = "ADT7490",
1240 };
1241
995 struct adt7475_data *data; 1242 struct adt7475_data *data;
996 int i, ret = 0; 1243 int i, ret = 0, revision;
1244 u8 config2, config3;
997 1245
998 data = kzalloc(sizeof(*data), GFP_KERNEL); 1246 data = kzalloc(sizeof(*data), GFP_KERNEL);
999 if (data == NULL) 1247 if (data == NULL)
@@ -1002,6 +1250,70 @@ static int adt7475_probe(struct i2c_client *client,
1002 mutex_init(&data->lock); 1250 mutex_init(&data->lock);
1003 i2c_set_clientdata(client, data); 1251 i2c_set_clientdata(client, data);
1004 1252
1253 /* Initialize device-specific values */
1254 switch (id->driver_data) {
1255 case adt7476:
1256 data->has_voltage = 0x0e; /* in1 to in3 */
1257 revision = adt7475_read(REG_DEVID2) & 0x07;
1258 break;
1259 case adt7490:
1260 data->has_voltage = 0x3e; /* in1 to in5 */
1261 revision = adt7475_read(REG_DEVID2) & 0x03;
1262 if (revision == 0x03)
1263 revision += adt7475_read(REG_DEVREV2);
1264 break;
1265 default:
1266 data->has_voltage = 0x06; /* in1, in2 */
1267 revision = adt7475_read(REG_DEVID2) & 0x07;
1268 }
1269
1270 config3 = adt7475_read(REG_CONFIG3);
1271 /* Pin PWM2 may alternatively be used for ALERT output */
1272 if (!(config3 & CONFIG3_SMBALERT))
1273 data->has_pwm2 = 1;
1274 /* Meaning of this bit is inverted for the ADT7473-1 */
1275 if (id->driver_data == adt7473 && revision >= 1)
1276 data->has_pwm2 = !data->has_pwm2;
1277
1278 data->config4 = adt7475_read(REG_CONFIG4);
1279 /* Pin TACH4 may alternatively be used for THERM */
1280 if ((data->config4 & CONFIG4_PINFUNC) == 0x0)
1281 data->has_fan4 = 1;
1282
1283 /* THERM configuration is more complex on the ADT7476 and ADT7490,
1284 because 2 different pins (TACH4 and +2.5 Vin) can be used for
1285 this function */
1286 if (id->driver_data == adt7490) {
1287 if ((data->config4 & CONFIG4_PINFUNC) == 0x1 &&
1288 !(config3 & CONFIG3_THERM))
1289 data->has_fan4 = 1;
1290 }
1291 if (id->driver_data == adt7476 || id->driver_data == adt7490) {
1292 if (!(config3 & CONFIG3_THERM) ||
1293 (data->config4 & CONFIG4_PINFUNC) == 0x1)
1294 data->has_voltage |= (1 << 0); /* in0 */
1295 }
1296
1297 /* On the ADT7476, the +12V input pin may instead be used as VID5,
1298 and VID pins may alternatively be used as GPIO */
1299 if (id->driver_data == adt7476) {
1300 u8 vid = adt7475_read(REG_VID);
1301 if (!(vid & VID_VIDSEL))
1302 data->has_voltage |= (1 << 4); /* in4 */
1303
1304 data->has_vid = !(adt7475_read(REG_CONFIG5) & CONFIG5_VIDGPIO);
1305 }
1306
1307 /* Voltage attenuators can be bypassed, globally or individually */
1308 config2 = adt7475_read(REG_CONFIG2);
1309 if (config2 & CONFIG2_ATTN) {
1310 data->bypass_attn = (0x3 << 3) | 0x3;
1311 } else {
1312 data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) |
1313 ((data->config4 & CONFIG4_ATTN_IN43) >> 3);
1314 }
1315 data->bypass_attn &= data->has_voltage;
1316
1005 /* Call adt7475_read_pwm for all pwm's as this will reprogram any 1317 /* Call adt7475_read_pwm for all pwm's as this will reprogram any
1006 pwm's which are disabled to manual mode with 0% duty cycle */ 1318 pwm's which are disabled to manual mode with 0% duty cycle */
1007 for (i = 0; i < ADT7475_PWM_COUNT; i++) 1319 for (i = 0; i < ADT7475_PWM_COUNT; i++)
@@ -1011,16 +1323,70 @@ static int adt7475_probe(struct i2c_client *client,
1011 if (ret) 1323 if (ret)
1012 goto efree; 1324 goto efree;
1013 1325
1326 /* Features that can be disabled individually */
1327 if (data->has_fan4) {
1328 ret = sysfs_create_group(&client->dev.kobj, &fan4_attr_group);
1329 if (ret)
1330 goto eremove;
1331 }
1332 if (data->has_pwm2) {
1333 ret = sysfs_create_group(&client->dev.kobj, &pwm2_attr_group);
1334 if (ret)
1335 goto eremove;
1336 }
1337 if (data->has_voltage & (1 << 0)) {
1338 ret = sysfs_create_group(&client->dev.kobj, &in0_attr_group);
1339 if (ret)
1340 goto eremove;
1341 }
1342 if (data->has_voltage & (1 << 3)) {
1343 ret = sysfs_create_group(&client->dev.kobj, &in3_attr_group);
1344 if (ret)
1345 goto eremove;
1346 }
1347 if (data->has_voltage & (1 << 4)) {
1348 ret = sysfs_create_group(&client->dev.kobj, &in4_attr_group);
1349 if (ret)
1350 goto eremove;
1351 }
1352 if (data->has_voltage & (1 << 5)) {
1353 ret = sysfs_create_group(&client->dev.kobj, &in5_attr_group);
1354 if (ret)
1355 goto eremove;
1356 }
1357 if (data->has_vid) {
1358 data->vrm = vid_which_vrm();
1359 ret = sysfs_create_group(&client->dev.kobj, &vid_attr_group);
1360 if (ret)
1361 goto eremove;
1362 }
1363
1014 data->hwmon_dev = hwmon_device_register(&client->dev); 1364 data->hwmon_dev = hwmon_device_register(&client->dev);
1015 if (IS_ERR(data->hwmon_dev)) { 1365 if (IS_ERR(data->hwmon_dev)) {
1016 ret = PTR_ERR(data->hwmon_dev); 1366 ret = PTR_ERR(data->hwmon_dev);
1017 goto eremove; 1367 goto eremove;
1018 } 1368 }
1019 1369
1370 dev_info(&client->dev, "%s device, revision %d\n",
1371 names[id->driver_data], revision);
1372 if ((data->has_voltage & 0x11) || data->has_fan4 || data->has_pwm2)
1373 dev_info(&client->dev, "Optional features:%s%s%s%s%s\n",
1374 (data->has_voltage & (1 << 0)) ? " in0" : "",
1375 (data->has_voltage & (1 << 4)) ? " in4" : "",
1376 data->has_fan4 ? " fan4" : "",
1377 data->has_pwm2 ? " pwm2" : "",
1378 data->has_vid ? " vid" : "");
1379 if (data->bypass_attn)
1380 dev_info(&client->dev, "Bypassing attenuators on:%s%s%s%s\n",
1381 (data->bypass_attn & (1 << 0)) ? " in0" : "",
1382 (data->bypass_attn & (1 << 1)) ? " in1" : "",
1383 (data->bypass_attn & (1 << 3)) ? " in3" : "",
1384 (data->bypass_attn & (1 << 4)) ? " in4" : "");
1385
1020 return 0; 1386 return 0;
1021 1387
1022eremove: 1388eremove:
1023 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group); 1389 adt7475_remove_files(client, data);
1024efree: 1390efree:
1025 kfree(data); 1391 kfree(data);
1026 return ret; 1392 return ret;
@@ -1031,7 +1397,7 @@ static int adt7475_remove(struct i2c_client *client)
1031 struct adt7475_data *data = i2c_get_clientdata(client); 1397 struct adt7475_data *data = i2c_get_clientdata(client);
1032 1398
1033 hwmon_device_unregister(data->hwmon_dev); 1399 hwmon_device_unregister(data->hwmon_dev);
1034 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group); 1400 adt7475_remove_files(client, data);
1035 kfree(data); 1401 kfree(data);
1036 1402
1037 return 0; 1403 return 0;
@@ -1116,7 +1482,7 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1116{ 1482{
1117 struct i2c_client *client = to_i2c_client(dev); 1483 struct i2c_client *client = to_i2c_client(dev);
1118 struct adt7475_data *data = i2c_get_clientdata(client); 1484 struct adt7475_data *data = i2c_get_clientdata(client);
1119 u8 ext; 1485 u16 ext;
1120 int i; 1486 int i;
1121 1487
1122 mutex_lock(&data->lock); 1488 mutex_lock(&data->lock);
@@ -1127,25 +1493,44 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1127 data->alarms = adt7475_read(REG_STATUS2) << 8; 1493 data->alarms = adt7475_read(REG_STATUS2) << 8;
1128 data->alarms |= adt7475_read(REG_STATUS1); 1494 data->alarms |= adt7475_read(REG_STATUS1);
1129 1495
1130 ext = adt7475_read(REG_EXTEND1); 1496 ext = (adt7475_read(REG_EXTEND2) << 8) |
1131 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) 1497 adt7475_read(REG_EXTEND1);
1498 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
1499 if (!(data->has_voltage & (1 << i)))
1500 continue;
1132 data->voltage[INPUT][i] = 1501 data->voltage[INPUT][i] =
1133 (adt7475_read(VOLTAGE_REG(i)) << 2) | 1502 (adt7475_read(VOLTAGE_REG(i)) << 2) |
1134 ((ext >> ((i + 1) * 2)) & 3); 1503 ((ext >> (i * 2)) & 3);
1504 }
1135 1505
1136 ext = adt7475_read(REG_EXTEND2);
1137 for (i = 0; i < ADT7475_TEMP_COUNT; i++) 1506 for (i = 0; i < ADT7475_TEMP_COUNT; i++)
1138 data->temp[INPUT][i] = 1507 data->temp[INPUT][i] =
1139 (adt7475_read(TEMP_REG(i)) << 2) | 1508 (adt7475_read(TEMP_REG(i)) << 2) |
1140 ((ext >> ((i + 1) * 2)) & 3); 1509 ((ext >> ((i + 5) * 2)) & 3);
1141 1510
1142 for (i = 0; i < ADT7475_TACH_COUNT; i++) 1511 if (data->has_voltage & (1 << 5)) {
1512 data->alarms |= adt7475_read(REG_STATUS4) << 24;
1513 ext = adt7475_read(REG_EXTEND3);
1514 data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 |
1515 ((ext >> 4) & 3);
1516 }
1517
1518 for (i = 0; i < ADT7475_TACH_COUNT; i++) {
1519 if (i == 3 && !data->has_fan4)
1520 continue;
1143 data->tach[INPUT][i] = 1521 data->tach[INPUT][i] =
1144 adt7475_read_word(client, TACH_REG(i)); 1522 adt7475_read_word(client, TACH_REG(i));
1523 }
1145 1524
1146 /* Updated by hw when in auto mode */ 1525 /* Updated by hw when in auto mode */
1147 for (i = 0; i < ADT7475_PWM_COUNT; i++) 1526 for (i = 0; i < ADT7475_PWM_COUNT; i++) {
1527 if (i == 1 && !data->has_pwm2)
1528 continue;
1148 data->pwm[INPUT][i] = adt7475_read(PWM_REG(i)); 1529 data->pwm[INPUT][i] = adt7475_read(PWM_REG(i));
1530 }
1531
1532 if (data->has_vid)
1533 data->vid = adt7475_read(REG_VID) & 0x3f;
1149 1534
1150 data->measure_updated = jiffies; 1535 data->measure_updated = jiffies;
1151 } 1536 }
@@ -1153,9 +1538,12 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1153 /* Limits and settings, should never change update every 60 seconds */ 1538 /* Limits and settings, should never change update every 60 seconds */
1154 if (time_after(jiffies, data->limits_updated + HZ * 60) || 1539 if (time_after(jiffies, data->limits_updated + HZ * 60) ||
1155 !data->valid) { 1540 !data->valid) {
1541 data->config4 = adt7475_read(REG_CONFIG4);
1156 data->config5 = adt7475_read(REG_CONFIG5); 1542 data->config5 = adt7475_read(REG_CONFIG5);
1157 1543
1158 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { 1544 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
1545 if (!(data->has_voltage & (1 << i)))
1546 continue;
1159 /* Adjust values so they match the input precision */ 1547 /* Adjust values so they match the input precision */
1160 data->voltage[MIN][i] = 1548 data->voltage[MIN][i] =
1161 adt7475_read(VOLTAGE_MIN_REG(i)) << 2; 1549 adt7475_read(VOLTAGE_MIN_REG(i)) << 2;
@@ -1163,6 +1551,11 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1163 adt7475_read(VOLTAGE_MAX_REG(i)) << 2; 1551 adt7475_read(VOLTAGE_MAX_REG(i)) << 2;
1164 } 1552 }
1165 1553
1554 if (data->has_voltage & (1 << 5)) {
1555 data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2;
1556 data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2;
1557 }
1558
1166 for (i = 0; i < ADT7475_TEMP_COUNT; i++) { 1559 for (i = 0; i < ADT7475_TEMP_COUNT; i++) {
1167 /* Adjust values so they match the input precision */ 1560 /* Adjust values so they match the input precision */
1168 data->temp[MIN][i] = 1561 data->temp[MIN][i] =
@@ -1178,11 +1571,16 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1178 } 1571 }
1179 adt7475_read_hystersis(client); 1572 adt7475_read_hystersis(client);
1180 1573
1181 for (i = 0; i < ADT7475_TACH_COUNT; i++) 1574 for (i = 0; i < ADT7475_TACH_COUNT; i++) {
1575 if (i == 3 && !data->has_fan4)
1576 continue;
1182 data->tach[MIN][i] = 1577 data->tach[MIN][i] =
1183 adt7475_read_word(client, TACH_MIN_REG(i)); 1578 adt7475_read_word(client, TACH_MIN_REG(i));
1579 }
1184 1580
1185 for (i = 0; i < ADT7475_PWM_COUNT; i++) { 1581 for (i = 0; i < ADT7475_PWM_COUNT; i++) {
1582 if (i == 1 && !data->has_pwm2)
1583 continue;
1186 data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i)); 1584 data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i));
1187 data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i)); 1585 data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i));
1188 /* Set the channel and control information */ 1586 /* Set the channel and control information */