Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1 | /* |
| 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 Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 6 | * Copyright (C) 2009 Jean Delvare <khali@linux-fr.org> |
| 7 | * |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 8 | * 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> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/i2c.h> |
| 19 | #include <linux/hwmon.h> |
| 20 | #include <linux/hwmon-sysfs.h> |
| 21 | #include <linux/err.h> |
| 22 | |
| 23 | /* Indexes for the sysfs hooks */ |
| 24 | |
| 25 | #define INPUT 0 |
| 26 | #define MIN 1 |
| 27 | #define MAX 2 |
| 28 | #define CONTROL 3 |
| 29 | #define OFFSET 3 |
| 30 | #define AUTOMIN 4 |
| 31 | #define THERM 5 |
| 32 | #define HYSTERSIS 6 |
| 33 | |
| 34 | /* These are unique identifiers for the sysfs functions - unlike the |
| 35 | numbers above, these are not also indexes into an array |
| 36 | */ |
| 37 | |
| 38 | #define ALARM 9 |
| 39 | #define FAULT 10 |
| 40 | |
| 41 | /* 7475 Common Registers */ |
| 42 | |
Jean Delvare | d07ca4a | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 43 | #define REG_DEVREV2 0x12 /* ADT7490 only */ |
| 44 | |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 45 | #define REG_VTT 0x1E /* ADT7490 only */ |
| 46 | #define REG_EXTEND3 0x1F /* ADT7490 only */ |
| 47 | |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 48 | #define REG_VOLTAGE_BASE 0x20 |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 49 | #define REG_TEMP_BASE 0x25 |
| 50 | #define REG_TACH_BASE 0x28 |
| 51 | #define REG_PWM_BASE 0x30 |
| 52 | #define REG_PWM_MAX_BASE 0x38 |
| 53 | |
| 54 | #define REG_DEVID 0x3D |
| 55 | #define REG_VENDID 0x3E |
Jean Delvare | d656b6f | 2009-12-09 20:36:04 +0100 | [diff] [blame] | 56 | #define REG_DEVID2 0x3F |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 57 | |
| 58 | #define REG_STATUS1 0x41 |
| 59 | #define REG_STATUS2 0x42 |
| 60 | |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 61 | #define REG_VID 0x43 /* ADT7476 only */ |
| 62 | |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 63 | #define REG_VOLTAGE_MIN_BASE 0x44 |
| 64 | #define REG_VOLTAGE_MAX_BASE 0x45 |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 65 | |
| 66 | #define REG_TEMP_MIN_BASE 0x4E |
| 67 | #define REG_TEMP_MAX_BASE 0x4F |
| 68 | |
| 69 | #define REG_TACH_MIN_BASE 0x54 |
| 70 | |
| 71 | #define REG_PWM_CONFIG_BASE 0x5C |
| 72 | |
| 73 | #define REG_TEMP_TRANGE_BASE 0x5F |
| 74 | |
| 75 | #define REG_PWM_MIN_BASE 0x64 |
| 76 | |
| 77 | #define REG_TEMP_TMIN_BASE 0x67 |
| 78 | #define REG_TEMP_THERM_BASE 0x6A |
| 79 | |
| 80 | #define REG_REMOTE1_HYSTERSIS 0x6D |
| 81 | #define REG_REMOTE2_HYSTERSIS 0x6E |
| 82 | |
| 83 | #define REG_TEMP_OFFSET_BASE 0x70 |
| 84 | |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 85 | #define REG_CONFIG2 0x73 |
| 86 | |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 87 | #define REG_EXTEND1 0x76 |
| 88 | #define REG_EXTEND2 0x77 |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 89 | |
| 90 | #define REG_CONFIG3 0x78 |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 91 | #define REG_CONFIG5 0x7C |
Jean Delvare | f99318b | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 92 | #define REG_CONFIG4 0x7D |
| 93 | |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 94 | #define REG_STATUS4 0x81 /* ADT7490 only */ |
| 95 | |
| 96 | #define REG_VTT_MIN 0x84 /* ADT7490 only */ |
| 97 | #define REG_VTT_MAX 0x86 /* ADT7490 only */ |
| 98 | |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 99 | #define VID_VIDSEL 0x80 /* ADT7476 only */ |
| 100 | |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 101 | #define CONFIG2_ATTN 0x20 |
| 102 | |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 103 | #define CONFIG3_SMBALERT 0x01 |
| 104 | #define CONFIG3_THERM 0x02 |
| 105 | |
| 106 | #define CONFIG4_PINFUNC 0x03 |
Jean Delvare | f99318b | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 107 | #define CONFIG4_MAXDUTY 0x08 |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 108 | #define CONFIG4_ATTN_IN10 0x30 |
| 109 | #define CONFIG4_ATTN_IN43 0xC0 |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 110 | |
| 111 | #define CONFIG5_TWOSCOMP 0x01 |
| 112 | #define CONFIG5_TEMPOFFSET 0x02 |
| 113 | |
| 114 | /* ADT7475 Settings */ |
| 115 | |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 116 | #define ADT7475_VOLTAGE_COUNT 5 /* Not counting Vtt */ |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 117 | #define ADT7475_TEMP_COUNT 3 |
| 118 | #define ADT7475_TACH_COUNT 4 |
| 119 | #define ADT7475_PWM_COUNT 3 |
| 120 | |
| 121 | /* Macro to read the registers */ |
| 122 | |
| 123 | #define adt7475_read(reg) i2c_smbus_read_byte_data(client, (reg)) |
| 124 | |
| 125 | /* Macros to easily index the registers */ |
| 126 | |
| 127 | #define TACH_REG(idx) (REG_TACH_BASE + ((idx) * 2)) |
| 128 | #define TACH_MIN_REG(idx) (REG_TACH_MIN_BASE + ((idx) * 2)) |
| 129 | |
| 130 | #define PWM_REG(idx) (REG_PWM_BASE + (idx)) |
| 131 | #define PWM_MAX_REG(idx) (REG_PWM_MAX_BASE + (idx)) |
| 132 | #define PWM_MIN_REG(idx) (REG_PWM_MIN_BASE + (idx)) |
| 133 | #define PWM_CONFIG_REG(idx) (REG_PWM_CONFIG_BASE + (idx)) |
| 134 | |
| 135 | #define VOLTAGE_REG(idx) (REG_VOLTAGE_BASE + (idx)) |
| 136 | #define VOLTAGE_MIN_REG(idx) (REG_VOLTAGE_MIN_BASE + ((idx) * 2)) |
| 137 | #define VOLTAGE_MAX_REG(idx) (REG_VOLTAGE_MAX_BASE + ((idx) * 2)) |
| 138 | |
| 139 | #define TEMP_REG(idx) (REG_TEMP_BASE + (idx)) |
| 140 | #define TEMP_MIN_REG(idx) (REG_TEMP_MIN_BASE + ((idx) * 2)) |
| 141 | #define TEMP_MAX_REG(idx) (REG_TEMP_MAX_BASE + ((idx) * 2)) |
| 142 | #define TEMP_TMIN_REG(idx) (REG_TEMP_TMIN_BASE + (idx)) |
| 143 | #define TEMP_THERM_REG(idx) (REG_TEMP_THERM_BASE + (idx)) |
| 144 | #define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx)) |
| 145 | #define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx)) |
| 146 | |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 147 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 148 | |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 149 | I2C_CLIENT_INSMOD_4(adt7473, adt7475, adt7476, adt7490); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 150 | |
| 151 | static const struct i2c_device_id adt7475_id[] = { |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 152 | { "adt7473", adt7473 }, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 153 | { "adt7475", adt7475 }, |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 154 | { "adt7476", adt7476 }, |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 155 | { "adt7490", adt7490 }, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 156 | { } |
| 157 | }; |
| 158 | MODULE_DEVICE_TABLE(i2c, adt7475_id); |
| 159 | |
| 160 | struct adt7475_data { |
| 161 | struct device *hwmon_dev; |
| 162 | struct mutex lock; |
| 163 | |
| 164 | unsigned long measure_updated; |
| 165 | unsigned long limits_updated; |
| 166 | char valid; |
| 167 | |
Jean Delvare | f99318b | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 168 | u8 config4; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 169 | u8 config5; |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 170 | u8 has_voltage; |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 171 | u8 bypass_attn; /* Bypass voltage attenuator */ |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 172 | u8 has_pwm2:1; |
| 173 | u8 has_fan4:1; |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 174 | u32 alarms; |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 175 | u16 voltage[3][6]; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 176 | u16 temp[7][3]; |
| 177 | u16 tach[2][4]; |
| 178 | u8 pwm[4][3]; |
| 179 | u8 range[3]; |
| 180 | u8 pwmctl[3]; |
| 181 | u8 pwmchan[3]; |
| 182 | }; |
| 183 | |
| 184 | static struct i2c_driver adt7475_driver; |
| 185 | static struct adt7475_data *adt7475_update_device(struct device *dev); |
| 186 | static void adt7475_read_hystersis(struct i2c_client *client); |
| 187 | static void adt7475_read_pwm(struct i2c_client *client, int index); |
| 188 | |
| 189 | /* Given a temp value, convert it to register value */ |
| 190 | |
| 191 | static inline u16 temp2reg(struct adt7475_data *data, long val) |
| 192 | { |
| 193 | u16 ret; |
| 194 | |
| 195 | if (!(data->config5 & CONFIG5_TWOSCOMP)) { |
| 196 | val = SENSORS_LIMIT(val, -64000, 191000); |
| 197 | ret = (val + 64500) / 1000; |
| 198 | } else { |
| 199 | val = SENSORS_LIMIT(val, -128000, 127000); |
| 200 | if (val < -500) |
| 201 | ret = (256500 + val) / 1000; |
| 202 | else |
| 203 | ret = (val + 500) / 1000; |
| 204 | } |
| 205 | |
| 206 | return ret << 2; |
| 207 | } |
| 208 | |
| 209 | /* Given a register value, convert it to a real temp value */ |
| 210 | |
| 211 | static inline int reg2temp(struct adt7475_data *data, u16 reg) |
| 212 | { |
| 213 | if (data->config5 & CONFIG5_TWOSCOMP) { |
| 214 | if (reg >= 512) |
| 215 | return (reg - 1024) * 250; |
| 216 | else |
| 217 | return reg * 250; |
| 218 | } else |
| 219 | return (reg - 256) * 250; |
| 220 | } |
| 221 | |
| 222 | static inline int tach2rpm(u16 tach) |
| 223 | { |
| 224 | if (tach == 0 || tach == 0xFFFF) |
| 225 | return 0; |
| 226 | |
| 227 | return (90000 * 60) / tach; |
| 228 | } |
| 229 | |
| 230 | static inline u16 rpm2tach(unsigned long rpm) |
| 231 | { |
| 232 | if (rpm == 0) |
| 233 | return 0; |
| 234 | |
| 235 | return SENSORS_LIMIT((90000 * 60) / rpm, 1, 0xFFFF); |
| 236 | } |
| 237 | |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 238 | /* Scaling factors for voltage inputs, taken from the ADT7490 datasheet */ |
| 239 | static const int adt7473_in_scaling[ADT7475_VOLTAGE_COUNT + 1][2] = { |
| 240 | { 45, 94 }, /* +2.5V */ |
| 241 | { 175, 525 }, /* Vccp */ |
| 242 | { 68, 71 }, /* Vcc */ |
| 243 | { 93, 47 }, /* +5V */ |
| 244 | { 120, 20 }, /* +12V */ |
| 245 | { 45, 45 }, /* Vtt */ |
| 246 | }; |
| 247 | |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 248 | static inline int reg2volt(int channel, u16 reg, u8 bypass_attn) |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 249 | { |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 250 | const int *r = adt7473_in_scaling[channel]; |
| 251 | |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 252 | if (bypass_attn & (1 << channel)) |
| 253 | return DIV_ROUND_CLOSEST(reg * 2250, 1024); |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 254 | return DIV_ROUND_CLOSEST(reg * (r[0] + r[1]) * 2250, r[1] * 1024); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 255 | } |
| 256 | |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 257 | static inline u16 volt2reg(int channel, long volt, u8 bypass_attn) |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 258 | { |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 259 | const int *r = adt7473_in_scaling[channel]; |
| 260 | long reg; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 261 | |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 262 | if (bypass_attn & (1 << channel)) |
| 263 | reg = (volt * 1024) / 2250; |
| 264 | else |
| 265 | reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250); |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 266 | return SENSORS_LIMIT(reg, 0, 1023) & (0xff << 2); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static u16 adt7475_read_word(struct i2c_client *client, int reg) |
| 270 | { |
| 271 | u16 val; |
| 272 | |
| 273 | val = i2c_smbus_read_byte_data(client, reg); |
| 274 | val |= (i2c_smbus_read_byte_data(client, reg + 1) << 8); |
| 275 | |
| 276 | return val; |
| 277 | } |
| 278 | |
| 279 | static void adt7475_write_word(struct i2c_client *client, int reg, u16 val) |
| 280 | { |
| 281 | i2c_smbus_write_byte_data(client, reg + 1, val >> 8); |
| 282 | i2c_smbus_write_byte_data(client, reg, val & 0xFF); |
| 283 | } |
| 284 | |
| 285 | /* Find the nearest value in a table - used for pwm frequency and |
| 286 | auto temp range */ |
| 287 | static int find_nearest(long val, const int *array, int size) |
| 288 | { |
| 289 | int i; |
| 290 | |
| 291 | if (val < array[0]) |
| 292 | return 0; |
| 293 | |
| 294 | if (val > array[size - 1]) |
| 295 | return size - 1; |
| 296 | |
| 297 | for (i = 0; i < size - 1; i++) { |
| 298 | int a, b; |
| 299 | |
| 300 | if (val > array[i + 1]) |
| 301 | continue; |
| 302 | |
| 303 | a = val - array[i]; |
| 304 | b = array[i + 1] - val; |
| 305 | |
| 306 | return (a <= b) ? i : i + 1; |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static ssize_t show_voltage(struct device *dev, struct device_attribute *attr, |
| 313 | char *buf) |
| 314 | { |
| 315 | struct adt7475_data *data = adt7475_update_device(dev); |
| 316 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 317 | unsigned short val; |
| 318 | |
| 319 | switch (sattr->nr) { |
| 320 | case ALARM: |
| 321 | return sprintf(buf, "%d\n", |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 322 | (data->alarms >> sattr->index) & 1); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 323 | default: |
| 324 | val = data->voltage[sattr->nr][sattr->index]; |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 325 | return sprintf(buf, "%d\n", |
| 326 | reg2volt(sattr->index, val, data->bypass_attn)); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
| 330 | static ssize_t set_voltage(struct device *dev, struct device_attribute *attr, |
| 331 | const char *buf, size_t count) |
| 332 | { |
| 333 | |
| 334 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 335 | struct i2c_client *client = to_i2c_client(dev); |
| 336 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 337 | unsigned char reg; |
| 338 | long val; |
| 339 | |
| 340 | if (strict_strtol(buf, 10, &val)) |
| 341 | return -EINVAL; |
| 342 | |
| 343 | mutex_lock(&data->lock); |
| 344 | |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 345 | data->voltage[sattr->nr][sattr->index] = |
| 346 | volt2reg(sattr->index, val, data->bypass_attn); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 347 | |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 348 | if (sattr->index < ADT7475_VOLTAGE_COUNT) { |
| 349 | if (sattr->nr == MIN) |
| 350 | reg = VOLTAGE_MIN_REG(sattr->index); |
| 351 | else |
| 352 | reg = VOLTAGE_MAX_REG(sattr->index); |
| 353 | } else { |
| 354 | if (sattr->nr == MIN) |
| 355 | reg = REG_VTT_MIN; |
| 356 | else |
| 357 | reg = REG_VTT_MAX; |
| 358 | } |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 359 | |
| 360 | i2c_smbus_write_byte_data(client, reg, |
| 361 | data->voltage[sattr->nr][sattr->index] >> 2); |
| 362 | mutex_unlock(&data->lock); |
| 363 | |
| 364 | return count; |
| 365 | } |
| 366 | |
| 367 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
| 368 | char *buf) |
| 369 | { |
| 370 | struct adt7475_data *data = adt7475_update_device(dev); |
| 371 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 372 | int out; |
| 373 | |
| 374 | switch (sattr->nr) { |
| 375 | case HYSTERSIS: |
| 376 | mutex_lock(&data->lock); |
| 377 | out = data->temp[sattr->nr][sattr->index]; |
| 378 | if (sattr->index != 1) |
| 379 | out = (out >> 4) & 0xF; |
| 380 | else |
| 381 | out = (out & 0xF); |
| 382 | /* Show the value as an absolute number tied to |
| 383 | * THERM */ |
| 384 | out = reg2temp(data, data->temp[THERM][sattr->index]) - |
| 385 | out * 1000; |
| 386 | mutex_unlock(&data->lock); |
| 387 | break; |
| 388 | |
| 389 | case OFFSET: |
| 390 | /* Offset is always 2's complement, regardless of the |
| 391 | * setting in CONFIG5 */ |
| 392 | mutex_lock(&data->lock); |
| 393 | out = (s8)data->temp[sattr->nr][sattr->index]; |
| 394 | if (data->config5 & CONFIG5_TEMPOFFSET) |
| 395 | out *= 1000; |
| 396 | else |
| 397 | out *= 500; |
| 398 | mutex_unlock(&data->lock); |
| 399 | break; |
| 400 | |
| 401 | case ALARM: |
| 402 | out = (data->alarms >> (sattr->index + 4)) & 1; |
| 403 | break; |
| 404 | |
| 405 | case FAULT: |
| 406 | /* Note - only for remote1 and remote2 */ |
Jean Delvare | cf312e0 | 2009-11-16 12:45:39 +0100 | [diff] [blame] | 407 | out = !!(data->alarms & (sattr->index ? 0x8000 : 0x4000)); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 408 | break; |
| 409 | |
| 410 | default: |
| 411 | /* All other temp values are in the configured format */ |
| 412 | out = reg2temp(data, data->temp[sattr->nr][sattr->index]); |
| 413 | } |
| 414 | |
| 415 | return sprintf(buf, "%d\n", out); |
| 416 | } |
| 417 | |
| 418 | static ssize_t set_temp(struct device *dev, struct device_attribute *attr, |
| 419 | const char *buf, size_t count) |
| 420 | { |
| 421 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 422 | struct i2c_client *client = to_i2c_client(dev); |
| 423 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 424 | unsigned char reg = 0; |
| 425 | u8 out; |
| 426 | int temp; |
| 427 | long val; |
| 428 | |
| 429 | if (strict_strtol(buf, 10, &val)) |
| 430 | return -EINVAL; |
| 431 | |
| 432 | mutex_lock(&data->lock); |
| 433 | |
| 434 | /* We need the config register in all cases for temp <-> reg conv. */ |
| 435 | data->config5 = adt7475_read(REG_CONFIG5); |
| 436 | |
| 437 | switch (sattr->nr) { |
| 438 | case OFFSET: |
| 439 | if (data->config5 & CONFIG5_TEMPOFFSET) { |
| 440 | val = SENSORS_LIMIT(val, -63000, 127000); |
| 441 | out = data->temp[OFFSET][sattr->index] = val / 1000; |
| 442 | } else { |
| 443 | val = SENSORS_LIMIT(val, -63000, 64000); |
| 444 | out = data->temp[OFFSET][sattr->index] = val / 500; |
| 445 | } |
| 446 | break; |
| 447 | |
| 448 | case HYSTERSIS: |
| 449 | /* The value will be given as an absolute value, turn it |
| 450 | into an offset based on THERM */ |
| 451 | |
| 452 | /* Read fresh THERM and HYSTERSIS values from the chip */ |
| 453 | data->temp[THERM][sattr->index] = |
| 454 | adt7475_read(TEMP_THERM_REG(sattr->index)) << 2; |
| 455 | adt7475_read_hystersis(client); |
| 456 | |
| 457 | temp = reg2temp(data, data->temp[THERM][sattr->index]); |
| 458 | val = SENSORS_LIMIT(val, temp - 15000, temp); |
| 459 | val = (temp - val) / 1000; |
| 460 | |
| 461 | if (sattr->index != 1) { |
| 462 | data->temp[HYSTERSIS][sattr->index] &= 0xF0; |
| 463 | data->temp[HYSTERSIS][sattr->index] |= (val & 0xF) << 4; |
| 464 | } else { |
| 465 | data->temp[HYSTERSIS][sattr->index] &= 0x0F; |
| 466 | data->temp[HYSTERSIS][sattr->index] |= (val & 0xF); |
| 467 | } |
| 468 | |
| 469 | out = data->temp[HYSTERSIS][sattr->index]; |
| 470 | break; |
| 471 | |
| 472 | default: |
| 473 | data->temp[sattr->nr][sattr->index] = temp2reg(data, val); |
| 474 | |
| 475 | /* We maintain an extra 2 digits of precision for simplicity |
| 476 | * - shift those back off before writing the value */ |
| 477 | out = (u8) (data->temp[sattr->nr][sattr->index] >> 2); |
| 478 | } |
| 479 | |
| 480 | switch (sattr->nr) { |
| 481 | case MIN: |
| 482 | reg = TEMP_MIN_REG(sattr->index); |
| 483 | break; |
| 484 | case MAX: |
| 485 | reg = TEMP_MAX_REG(sattr->index); |
| 486 | break; |
| 487 | case OFFSET: |
| 488 | reg = TEMP_OFFSET_REG(sattr->index); |
| 489 | break; |
| 490 | case AUTOMIN: |
| 491 | reg = TEMP_TMIN_REG(sattr->index); |
| 492 | break; |
| 493 | case THERM: |
| 494 | reg = TEMP_THERM_REG(sattr->index); |
| 495 | break; |
| 496 | case HYSTERSIS: |
| 497 | if (sattr->index != 2) |
| 498 | reg = REG_REMOTE1_HYSTERSIS; |
| 499 | else |
| 500 | reg = REG_REMOTE2_HYSTERSIS; |
| 501 | |
| 502 | break; |
| 503 | } |
| 504 | |
| 505 | i2c_smbus_write_byte_data(client, reg, out); |
| 506 | |
| 507 | mutex_unlock(&data->lock); |
| 508 | return count; |
| 509 | } |
| 510 | |
| 511 | /* Table of autorange values - the user will write the value in millidegrees, |
| 512 | and we'll convert it */ |
| 513 | static const int autorange_table[] = { |
| 514 | 2000, 2500, 3330, 4000, 5000, 6670, 8000, |
| 515 | 10000, 13330, 16000, 20000, 26670, 32000, 40000, |
| 516 | 53330, 80000 |
| 517 | }; |
| 518 | |
| 519 | static ssize_t show_point2(struct device *dev, struct device_attribute *attr, |
| 520 | char *buf) |
| 521 | { |
| 522 | struct adt7475_data *data = adt7475_update_device(dev); |
| 523 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 524 | int out, val; |
| 525 | |
| 526 | mutex_lock(&data->lock); |
| 527 | out = (data->range[sattr->index] >> 4) & 0x0F; |
| 528 | val = reg2temp(data, data->temp[AUTOMIN][sattr->index]); |
| 529 | mutex_unlock(&data->lock); |
| 530 | |
| 531 | return sprintf(buf, "%d\n", val + autorange_table[out]); |
| 532 | } |
| 533 | |
| 534 | static ssize_t set_point2(struct device *dev, struct device_attribute *attr, |
| 535 | const char *buf, size_t count) |
| 536 | { |
| 537 | struct i2c_client *client = to_i2c_client(dev); |
| 538 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 539 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 540 | int temp; |
| 541 | long val; |
| 542 | |
| 543 | if (strict_strtol(buf, 10, &val)) |
| 544 | return -EINVAL; |
| 545 | |
| 546 | mutex_lock(&data->lock); |
| 547 | |
| 548 | /* Get a fresh copy of the needed registers */ |
| 549 | data->config5 = adt7475_read(REG_CONFIG5); |
| 550 | data->temp[AUTOMIN][sattr->index] = |
| 551 | adt7475_read(TEMP_TMIN_REG(sattr->index)) << 2; |
| 552 | data->range[sattr->index] = |
| 553 | adt7475_read(TEMP_TRANGE_REG(sattr->index)); |
| 554 | |
| 555 | /* The user will write an absolute value, so subtract the start point |
| 556 | to figure the range */ |
| 557 | temp = reg2temp(data, data->temp[AUTOMIN][sattr->index]); |
| 558 | val = SENSORS_LIMIT(val, temp + autorange_table[0], |
| 559 | temp + autorange_table[ARRAY_SIZE(autorange_table) - 1]); |
| 560 | val -= temp; |
| 561 | |
| 562 | /* Find the nearest table entry to what the user wrote */ |
| 563 | val = find_nearest(val, autorange_table, ARRAY_SIZE(autorange_table)); |
| 564 | |
| 565 | data->range[sattr->index] &= ~0xF0; |
| 566 | data->range[sattr->index] |= val << 4; |
| 567 | |
| 568 | i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index), |
| 569 | data->range[sattr->index]); |
| 570 | |
| 571 | mutex_unlock(&data->lock); |
| 572 | return count; |
| 573 | } |
| 574 | |
| 575 | static ssize_t show_tach(struct device *dev, struct device_attribute *attr, |
| 576 | char *buf) |
| 577 | { |
| 578 | struct adt7475_data *data = adt7475_update_device(dev); |
| 579 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 580 | int out; |
| 581 | |
| 582 | if (sattr->nr == ALARM) |
| 583 | out = (data->alarms >> (sattr->index + 10)) & 1; |
| 584 | else |
| 585 | out = tach2rpm(data->tach[sattr->nr][sattr->index]); |
| 586 | |
| 587 | return sprintf(buf, "%d\n", out); |
| 588 | } |
| 589 | |
| 590 | static ssize_t set_tach(struct device *dev, struct device_attribute *attr, |
| 591 | const char *buf, size_t count) |
| 592 | { |
| 593 | |
| 594 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 595 | struct i2c_client *client = to_i2c_client(dev); |
| 596 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 597 | unsigned long val; |
| 598 | |
| 599 | if (strict_strtoul(buf, 10, &val)) |
| 600 | return -EINVAL; |
| 601 | |
| 602 | mutex_lock(&data->lock); |
| 603 | |
| 604 | data->tach[MIN][sattr->index] = rpm2tach(val); |
| 605 | |
| 606 | adt7475_write_word(client, TACH_MIN_REG(sattr->index), |
| 607 | data->tach[MIN][sattr->index]); |
| 608 | |
| 609 | mutex_unlock(&data->lock); |
| 610 | return count; |
| 611 | } |
| 612 | |
| 613 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
| 614 | char *buf) |
| 615 | { |
| 616 | struct adt7475_data *data = adt7475_update_device(dev); |
| 617 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 618 | |
| 619 | return sprintf(buf, "%d\n", data->pwm[sattr->nr][sattr->index]); |
| 620 | } |
| 621 | |
| 622 | static ssize_t show_pwmchan(struct device *dev, struct device_attribute *attr, |
| 623 | char *buf) |
| 624 | { |
| 625 | struct adt7475_data *data = adt7475_update_device(dev); |
| 626 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 627 | |
| 628 | return sprintf(buf, "%d\n", data->pwmchan[sattr->index]); |
| 629 | } |
| 630 | |
| 631 | static ssize_t show_pwmctrl(struct device *dev, struct device_attribute *attr, |
| 632 | char *buf) |
| 633 | { |
| 634 | struct adt7475_data *data = adt7475_update_device(dev); |
| 635 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 636 | |
| 637 | return sprintf(buf, "%d\n", data->pwmctl[sattr->index]); |
| 638 | } |
| 639 | |
| 640 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 641 | const char *buf, size_t count) |
| 642 | { |
| 643 | |
| 644 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 645 | struct i2c_client *client = to_i2c_client(dev); |
| 646 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 647 | unsigned char reg = 0; |
| 648 | long val; |
| 649 | |
| 650 | if (strict_strtol(buf, 10, &val)) |
| 651 | return -EINVAL; |
| 652 | |
| 653 | mutex_lock(&data->lock); |
| 654 | |
| 655 | switch (sattr->nr) { |
| 656 | case INPUT: |
| 657 | /* Get a fresh value for CONTROL */ |
| 658 | data->pwm[CONTROL][sattr->index] = |
| 659 | adt7475_read(PWM_CONFIG_REG(sattr->index)); |
| 660 | |
| 661 | /* If we are not in manual mode, then we shouldn't allow |
| 662 | * the user to set the pwm speed */ |
| 663 | if (((data->pwm[CONTROL][sattr->index] >> 5) & 7) != 7) { |
| 664 | mutex_unlock(&data->lock); |
| 665 | return count; |
| 666 | } |
| 667 | |
| 668 | reg = PWM_REG(sattr->index); |
| 669 | break; |
| 670 | |
| 671 | case MIN: |
| 672 | reg = PWM_MIN_REG(sattr->index); |
| 673 | break; |
| 674 | |
| 675 | case MAX: |
| 676 | reg = PWM_MAX_REG(sattr->index); |
| 677 | break; |
| 678 | } |
| 679 | |
| 680 | data->pwm[sattr->nr][sattr->index] = SENSORS_LIMIT(val, 0, 0xFF); |
| 681 | i2c_smbus_write_byte_data(client, reg, |
| 682 | data->pwm[sattr->nr][sattr->index]); |
| 683 | |
| 684 | mutex_unlock(&data->lock); |
| 685 | |
| 686 | return count; |
| 687 | } |
| 688 | |
| 689 | /* Called by set_pwmctrl and set_pwmchan */ |
| 690 | |
| 691 | static int hw_set_pwm(struct i2c_client *client, int index, |
| 692 | unsigned int pwmctl, unsigned int pwmchan) |
| 693 | { |
| 694 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 695 | long val = 0; |
| 696 | |
| 697 | switch (pwmctl) { |
| 698 | case 0: |
| 699 | val = 0x03; /* Run at full speed */ |
| 700 | break; |
| 701 | case 1: |
| 702 | val = 0x07; /* Manual mode */ |
| 703 | break; |
| 704 | case 2: |
| 705 | switch (pwmchan) { |
| 706 | case 1: |
| 707 | /* Remote1 controls PWM */ |
| 708 | val = 0x00; |
| 709 | break; |
| 710 | case 2: |
| 711 | /* local controls PWM */ |
| 712 | val = 0x01; |
| 713 | break; |
| 714 | case 4: |
| 715 | /* remote2 controls PWM */ |
| 716 | val = 0x02; |
| 717 | break; |
| 718 | case 6: |
| 719 | /* local/remote2 control PWM */ |
| 720 | val = 0x05; |
| 721 | break; |
| 722 | case 7: |
| 723 | /* All three control PWM */ |
| 724 | val = 0x06; |
| 725 | break; |
| 726 | default: |
| 727 | return -EINVAL; |
| 728 | } |
| 729 | break; |
| 730 | default: |
| 731 | return -EINVAL; |
| 732 | } |
| 733 | |
| 734 | data->pwmctl[index] = pwmctl; |
| 735 | data->pwmchan[index] = pwmchan; |
| 736 | |
| 737 | data->pwm[CONTROL][index] &= ~0xE0; |
| 738 | data->pwm[CONTROL][index] |= (val & 7) << 5; |
| 739 | |
| 740 | i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index), |
| 741 | data->pwm[CONTROL][index]); |
| 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | static ssize_t set_pwmchan(struct device *dev, struct device_attribute *attr, |
| 747 | const char *buf, size_t count) |
| 748 | { |
| 749 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 750 | struct i2c_client *client = to_i2c_client(dev); |
| 751 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 752 | int r; |
| 753 | long val; |
| 754 | |
| 755 | if (strict_strtol(buf, 10, &val)) |
| 756 | return -EINVAL; |
| 757 | |
| 758 | mutex_lock(&data->lock); |
| 759 | /* Read Modify Write PWM values */ |
| 760 | adt7475_read_pwm(client, sattr->index); |
| 761 | r = hw_set_pwm(client, sattr->index, data->pwmctl[sattr->index], val); |
| 762 | if (r) |
| 763 | count = r; |
| 764 | mutex_unlock(&data->lock); |
| 765 | |
| 766 | return count; |
| 767 | } |
| 768 | |
| 769 | static ssize_t set_pwmctrl(struct device *dev, struct device_attribute *attr, |
| 770 | const char *buf, size_t count) |
| 771 | { |
| 772 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 773 | struct i2c_client *client = to_i2c_client(dev); |
| 774 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 775 | int r; |
| 776 | long val; |
| 777 | |
| 778 | if (strict_strtol(buf, 10, &val)) |
| 779 | return -EINVAL; |
| 780 | |
| 781 | mutex_lock(&data->lock); |
| 782 | /* Read Modify Write PWM values */ |
| 783 | adt7475_read_pwm(client, sattr->index); |
| 784 | r = hw_set_pwm(client, sattr->index, val, data->pwmchan[sattr->index]); |
| 785 | if (r) |
| 786 | count = r; |
| 787 | mutex_unlock(&data->lock); |
| 788 | |
| 789 | return count; |
| 790 | } |
| 791 | |
| 792 | /* List of frequencies for the PWM */ |
| 793 | static const int pwmfreq_table[] = { |
| 794 | 11, 14, 22, 29, 35, 44, 58, 88 |
| 795 | }; |
| 796 | |
| 797 | static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr, |
| 798 | char *buf) |
| 799 | { |
| 800 | struct adt7475_data *data = adt7475_update_device(dev); |
| 801 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 802 | |
| 803 | return sprintf(buf, "%d\n", |
| 804 | pwmfreq_table[data->range[sattr->index] & 7]); |
| 805 | } |
| 806 | |
| 807 | static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr, |
| 808 | const char *buf, size_t count) |
| 809 | { |
| 810 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 811 | struct i2c_client *client = to_i2c_client(dev); |
| 812 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 813 | int out; |
| 814 | long val; |
| 815 | |
| 816 | if (strict_strtol(buf, 10, &val)) |
| 817 | return -EINVAL; |
| 818 | |
| 819 | out = find_nearest(val, pwmfreq_table, ARRAY_SIZE(pwmfreq_table)); |
| 820 | |
| 821 | mutex_lock(&data->lock); |
| 822 | |
| 823 | data->range[sattr->index] = |
| 824 | adt7475_read(TEMP_TRANGE_REG(sattr->index)); |
| 825 | data->range[sattr->index] &= ~7; |
| 826 | data->range[sattr->index] |= out; |
| 827 | |
| 828 | i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index), |
| 829 | data->range[sattr->index]); |
| 830 | |
| 831 | mutex_unlock(&data->lock); |
| 832 | return count; |
| 833 | } |
| 834 | |
Jean Delvare | f99318b | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 835 | static ssize_t show_pwm_at_crit(struct device *dev, |
| 836 | struct device_attribute *devattr, char *buf) |
| 837 | { |
| 838 | struct adt7475_data *data = adt7475_update_device(dev); |
| 839 | return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY)); |
| 840 | } |
| 841 | |
| 842 | static ssize_t set_pwm_at_crit(struct device *dev, |
| 843 | struct device_attribute *devattr, |
| 844 | const char *buf, size_t count) |
| 845 | { |
| 846 | struct i2c_client *client = to_i2c_client(dev); |
| 847 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 848 | long val; |
| 849 | |
| 850 | if (strict_strtol(buf, 10, &val)) |
| 851 | return -EINVAL; |
| 852 | if (val != 0 && val != 1) |
| 853 | return -EINVAL; |
| 854 | |
| 855 | mutex_lock(&data->lock); |
| 856 | data->config4 = i2c_smbus_read_byte_data(client, REG_CONFIG4); |
| 857 | if (val) |
| 858 | data->config4 |= CONFIG4_MAXDUTY; |
| 859 | else |
| 860 | data->config4 &= ~CONFIG4_MAXDUTY; |
| 861 | i2c_smbus_write_byte_data(client, REG_CONFIG4, data->config4); |
| 862 | mutex_unlock(&data->lock); |
| 863 | |
| 864 | return count; |
| 865 | } |
| 866 | |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 867 | static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_voltage, NULL, INPUT, 0); |
| 868 | static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_voltage, |
| 869 | set_voltage, MAX, 0); |
| 870 | static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_voltage, |
| 871 | set_voltage, MIN, 0); |
| 872 | static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, show_voltage, NULL, ALARM, 0); |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 873 | static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_voltage, NULL, INPUT, 1); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 874 | static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_voltage, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 875 | set_voltage, MAX, 1); |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 876 | static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_voltage, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 877 | set_voltage, MIN, 1); |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 878 | static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, show_voltage, NULL, ALARM, 1); |
| 879 | static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_voltage, NULL, INPUT, 2); |
| 880 | static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_voltage, |
| 881 | set_voltage, MAX, 2); |
| 882 | static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_voltage, |
| 883 | set_voltage, MIN, 2); |
| 884 | static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_voltage, NULL, ALARM, 2); |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 885 | static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_voltage, NULL, INPUT, 3); |
| 886 | static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_voltage, |
| 887 | set_voltage, MAX, 3); |
| 888 | static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_voltage, |
| 889 | set_voltage, MIN, 3); |
| 890 | static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, show_voltage, NULL, ALARM, 3); |
| 891 | static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_voltage, NULL, INPUT, 4); |
| 892 | static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_voltage, |
| 893 | set_voltage, MAX, 4); |
| 894 | static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_voltage, |
| 895 | set_voltage, MIN, 4); |
| 896 | static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, show_voltage, NULL, ALARM, 8); |
| 897 | static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_voltage, NULL, INPUT, 5); |
| 898 | static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_voltage, |
| 899 | set_voltage, MAX, 5); |
| 900 | static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_voltage, |
| 901 | set_voltage, MIN, 5); |
| 902 | static SENSOR_DEVICE_ATTR_2(in5_alarm, S_IRUGO, show_voltage, NULL, ALARM, 31); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 903 | static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, INPUT, 0); |
| 904 | static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, show_temp, NULL, ALARM, 0); |
| 905 | static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_temp, NULL, FAULT, 0); |
| 906 | static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 907 | MAX, 0); |
| 908 | static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 909 | MIN, 0); |
| 910 | static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp, |
| 911 | set_temp, OFFSET, 0); |
| 912 | static SENSOR_DEVICE_ATTR_2(temp1_auto_point1_temp, S_IRUGO | S_IWUSR, |
| 913 | show_temp, set_temp, AUTOMIN, 0); |
| 914 | static SENSOR_DEVICE_ATTR_2(temp1_auto_point2_temp, S_IRUGO | S_IWUSR, |
| 915 | show_point2, set_point2, 0, 0); |
| 916 | static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 917 | THERM, 0); |
| 918 | static SENSOR_DEVICE_ATTR_2(temp1_crit_hyst, S_IRUGO | S_IWUSR, show_temp, |
| 919 | set_temp, HYSTERSIS, 0); |
| 920 | static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, INPUT, 1); |
| 921 | static SENSOR_DEVICE_ATTR_2(temp2_alarm, S_IRUGO, show_temp, NULL, ALARM, 1); |
| 922 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 923 | MAX, 1); |
| 924 | static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 925 | MIN, 1); |
| 926 | static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp, |
| 927 | set_temp, OFFSET, 1); |
| 928 | static SENSOR_DEVICE_ATTR_2(temp2_auto_point1_temp, S_IRUGO | S_IWUSR, |
| 929 | show_temp, set_temp, AUTOMIN, 1); |
| 930 | static SENSOR_DEVICE_ATTR_2(temp2_auto_point2_temp, S_IRUGO | S_IWUSR, |
| 931 | show_point2, set_point2, 0, 1); |
| 932 | static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 933 | THERM, 1); |
| 934 | static SENSOR_DEVICE_ATTR_2(temp2_crit_hyst, S_IRUGO | S_IWUSR, show_temp, |
| 935 | set_temp, HYSTERSIS, 1); |
| 936 | static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, INPUT, 2); |
| 937 | static SENSOR_DEVICE_ATTR_2(temp3_alarm, S_IRUGO, show_temp, NULL, ALARM, 2); |
| 938 | static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_temp, NULL, FAULT, 2); |
| 939 | static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 940 | MAX, 2); |
| 941 | static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 942 | MIN, 2); |
| 943 | static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp, |
| 944 | set_temp, OFFSET, 2); |
| 945 | static SENSOR_DEVICE_ATTR_2(temp3_auto_point1_temp, S_IRUGO | S_IWUSR, |
| 946 | show_temp, set_temp, AUTOMIN, 2); |
| 947 | static SENSOR_DEVICE_ATTR_2(temp3_auto_point2_temp, S_IRUGO | S_IWUSR, |
| 948 | show_point2, set_point2, 0, 2); |
| 949 | static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 950 | THERM, 2); |
| 951 | static SENSOR_DEVICE_ATTR_2(temp3_crit_hyst, S_IRUGO | S_IWUSR, show_temp, |
| 952 | set_temp, HYSTERSIS, 2); |
| 953 | static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_tach, NULL, INPUT, 0); |
| 954 | static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_tach, set_tach, |
| 955 | MIN, 0); |
| 956 | static SENSOR_DEVICE_ATTR_2(fan1_alarm, S_IRUGO, show_tach, NULL, ALARM, 0); |
| 957 | static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_tach, NULL, INPUT, 1); |
| 958 | static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_tach, set_tach, |
| 959 | MIN, 1); |
| 960 | static SENSOR_DEVICE_ATTR_2(fan2_alarm, S_IRUGO, show_tach, NULL, ALARM, 1); |
| 961 | static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_tach, NULL, INPUT, 2); |
| 962 | static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_tach, set_tach, |
| 963 | MIN, 2); |
| 964 | static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_tach, NULL, ALARM, 2); |
| 965 | static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_tach, NULL, INPUT, 3); |
| 966 | static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_tach, set_tach, |
| 967 | MIN, 3); |
| 968 | static SENSOR_DEVICE_ATTR_2(fan4_alarm, S_IRUGO, show_tach, NULL, ALARM, 3); |
| 969 | static SENSOR_DEVICE_ATTR_2(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT, |
| 970 | 0); |
| 971 | static SENSOR_DEVICE_ATTR_2(pwm1_freq, S_IRUGO | S_IWUSR, show_pwmfreq, |
| 972 | set_pwmfreq, INPUT, 0); |
| 973 | static SENSOR_DEVICE_ATTR_2(pwm1_enable, S_IRUGO | S_IWUSR, show_pwmctrl, |
| 974 | set_pwmctrl, INPUT, 0); |
Jean Delvare | 84d2a31 | 2009-11-16 12:45:40 +0100 | [diff] [blame] | 975 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 976 | show_pwmchan, set_pwmchan, INPUT, 0); |
| 977 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm, |
| 978 | set_pwm, MIN, 0); |
| 979 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm, |
| 980 | set_pwm, MAX, 0); |
| 981 | static SENSOR_DEVICE_ATTR_2(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT, |
| 982 | 1); |
| 983 | static SENSOR_DEVICE_ATTR_2(pwm2_freq, S_IRUGO | S_IWUSR, show_pwmfreq, |
| 984 | set_pwmfreq, INPUT, 1); |
| 985 | static SENSOR_DEVICE_ATTR_2(pwm2_enable, S_IRUGO | S_IWUSR, show_pwmctrl, |
| 986 | set_pwmctrl, INPUT, 1); |
Jean Delvare | 84d2a31 | 2009-11-16 12:45:40 +0100 | [diff] [blame] | 987 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 988 | show_pwmchan, set_pwmchan, INPUT, 1); |
| 989 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm, |
| 990 | set_pwm, MIN, 1); |
| 991 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm, |
| 992 | set_pwm, MAX, 1); |
| 993 | static SENSOR_DEVICE_ATTR_2(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT, |
| 994 | 2); |
| 995 | static SENSOR_DEVICE_ATTR_2(pwm3_freq, S_IRUGO | S_IWUSR, show_pwmfreq, |
| 996 | set_pwmfreq, INPUT, 2); |
| 997 | static SENSOR_DEVICE_ATTR_2(pwm3_enable, S_IRUGO | S_IWUSR, show_pwmctrl, |
| 998 | set_pwmctrl, INPUT, 2); |
Jean Delvare | 84d2a31 | 2009-11-16 12:45:40 +0100 | [diff] [blame] | 999 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1000 | show_pwmchan, set_pwmchan, INPUT, 2); |
| 1001 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm, |
| 1002 | set_pwm, MIN, 2); |
| 1003 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm, |
| 1004 | set_pwm, MAX, 2); |
| 1005 | |
Jean Delvare | f99318b | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1006 | /* Non-standard name, might need revisiting */ |
| 1007 | static DEVICE_ATTR(pwm_use_point2_pwm_at_crit, S_IWUSR | S_IRUGO, |
| 1008 | show_pwm_at_crit, set_pwm_at_crit); |
| 1009 | |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1010 | static struct attribute *adt7475_attrs[] = { |
| 1011 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1012 | &sensor_dev_attr_in1_max.dev_attr.attr, |
| 1013 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 1014 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
| 1015 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 1016 | &sensor_dev_attr_in2_max.dev_attr.attr, |
| 1017 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 1018 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
| 1019 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1020 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
| 1021 | &sensor_dev_attr_temp1_fault.dev_attr.attr, |
| 1022 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 1023 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 1024 | &sensor_dev_attr_temp1_offset.dev_attr.attr, |
| 1025 | &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr, |
| 1026 | &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr, |
| 1027 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 1028 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
| 1029 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 1030 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
| 1031 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1032 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1033 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
| 1034 | &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr, |
| 1035 | &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr, |
| 1036 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
| 1037 | &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, |
| 1038 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 1039 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
| 1040 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
| 1041 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
| 1042 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1043 | &sensor_dev_attr_temp3_offset.dev_attr.attr, |
| 1044 | &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr, |
| 1045 | &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr, |
| 1046 | &sensor_dev_attr_temp3_crit.dev_attr.attr, |
| 1047 | &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr, |
| 1048 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 1049 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 1050 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1051 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 1052 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
| 1053 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1054 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 1055 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
| 1056 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1057 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 1058 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, |
| 1059 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
Jean Delvare | 84d2a31 | 2009-11-16 12:45:40 +0100 | [diff] [blame] | 1060 | &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1061 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
| 1062 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1063 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 1064 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, |
| 1065 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
Jean Delvare | 84d2a31 | 2009-11-16 12:45:40 +0100 | [diff] [blame] | 1066 | &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1067 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, |
| 1068 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, |
Jean Delvare | f99318b | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1069 | &dev_attr_pwm_use_point2_pwm_at_crit.attr, |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1070 | NULL, |
| 1071 | }; |
| 1072 | |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1073 | static struct attribute *fan4_attrs[] = { |
| 1074 | &sensor_dev_attr_fan4_input.dev_attr.attr, |
| 1075 | &sensor_dev_attr_fan4_min.dev_attr.attr, |
| 1076 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
| 1077 | NULL |
| 1078 | }; |
| 1079 | |
| 1080 | static struct attribute *pwm2_attrs[] = { |
| 1081 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 1082 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, |
| 1083 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1084 | &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, |
| 1085 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, |
| 1086 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, |
| 1087 | NULL |
| 1088 | }; |
| 1089 | |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1090 | static struct attribute *in0_attrs[] = { |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1091 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 1092 | &sensor_dev_attr_in0_max.dev_attr.attr, |
| 1093 | &sensor_dev_attr_in0_min.dev_attr.attr, |
| 1094 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1095 | NULL |
| 1096 | }; |
| 1097 | |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1098 | static struct attribute *in3_attrs[] = { |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1099 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 1100 | &sensor_dev_attr_in3_max.dev_attr.attr, |
| 1101 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 1102 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1103 | NULL |
| 1104 | }; |
| 1105 | |
| 1106 | static struct attribute *in4_attrs[] = { |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1107 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 1108 | &sensor_dev_attr_in4_max.dev_attr.attr, |
| 1109 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 1110 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1111 | NULL |
| 1112 | }; |
| 1113 | |
| 1114 | static struct attribute *in5_attrs[] = { |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1115 | &sensor_dev_attr_in5_input.dev_attr.attr, |
| 1116 | &sensor_dev_attr_in5_max.dev_attr.attr, |
| 1117 | &sensor_dev_attr_in5_min.dev_attr.attr, |
| 1118 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
| 1119 | NULL |
| 1120 | }; |
| 1121 | |
Jean Delvare | 54ecb9e | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1122 | static struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs }; |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1123 | static struct attribute_group fan4_attr_group = { .attrs = fan4_attrs }; |
| 1124 | static struct attribute_group pwm2_attr_group = { .attrs = pwm2_attrs }; |
| 1125 | static struct attribute_group in0_attr_group = { .attrs = in0_attrs }; |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1126 | static struct attribute_group in3_attr_group = { .attrs = in3_attrs }; |
| 1127 | static struct attribute_group in4_attr_group = { .attrs = in4_attrs }; |
| 1128 | static struct attribute_group in5_attr_group = { .attrs = in5_attrs }; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1129 | |
| 1130 | static int adt7475_detect(struct i2c_client *client, int kind, |
| 1131 | struct i2c_board_info *info) |
| 1132 | { |
| 1133 | struct i2c_adapter *adapter = client->adapter; |
Jean Delvare | d656b6f | 2009-12-09 20:36:04 +0100 | [diff] [blame] | 1134 | int vendid, devid, devid2; |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 1135 | const char *name; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1136 | |
| 1137 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 1138 | return -ENODEV; |
| 1139 | |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 1140 | vendid = adt7475_read(REG_VENDID); |
Jean Delvare | d656b6f | 2009-12-09 20:36:04 +0100 | [diff] [blame] | 1141 | devid2 = adt7475_read(REG_DEVID2); |
| 1142 | if (vendid != 0x41 || /* Analog Devices */ |
| 1143 | (devid2 & 0xf8) != 0x68) |
| 1144 | return -ENODEV; |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 1145 | |
Jean Delvare | d656b6f | 2009-12-09 20:36:04 +0100 | [diff] [blame] | 1146 | devid = adt7475_read(REG_DEVID); |
| 1147 | if (devid == 0x73) |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 1148 | name = "adt7473"; |
Jean Delvare | d656b6f | 2009-12-09 20:36:04 +0100 | [diff] [blame] | 1149 | else if (devid == 0x75 && client->addr == 0x2e) |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 1150 | name = "adt7475"; |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1151 | else if (devid == 0x76) |
| 1152 | name = "adt7476"; |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1153 | else if ((devid2 & 0xfc) == 0x6c) |
| 1154 | name = "adt7490"; |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 1155 | else { |
| 1156 | dev_dbg(&adapter->dev, |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1157 | "Couldn't detect an ADT7473/75/76/90 part at " |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 1158 | "0x%02x\n", (unsigned int)client->addr); |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 1159 | return -ENODEV; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1160 | } |
| 1161 | |
Jean Delvare | b180d05 | 2009-12-09 20:36:02 +0100 | [diff] [blame] | 1162 | strlcpy(info->type, name, I2C_NAME_SIZE); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1163 | |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
Jean Delvare | 0f14480 | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1167 | static void adt7475_remove_files(struct i2c_client *client, |
| 1168 | struct adt7475_data *data) |
| 1169 | { |
| 1170 | sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group); |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1171 | if (data->has_fan4) |
| 1172 | sysfs_remove_group(&client->dev.kobj, &fan4_attr_group); |
| 1173 | if (data->has_pwm2) |
| 1174 | sysfs_remove_group(&client->dev.kobj, &pwm2_attr_group); |
| 1175 | if (data->has_voltage & (1 << 0)) |
| 1176 | sysfs_remove_group(&client->dev.kobj, &in0_attr_group); |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1177 | if (data->has_voltage & (1 << 3)) |
| 1178 | sysfs_remove_group(&client->dev.kobj, &in3_attr_group); |
| 1179 | if (data->has_voltage & (1 << 4)) |
| 1180 | sysfs_remove_group(&client->dev.kobj, &in4_attr_group); |
| 1181 | if (data->has_voltage & (1 << 5)) |
| 1182 | sysfs_remove_group(&client->dev.kobj, &in5_attr_group); |
Jean Delvare | 0f14480 | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1183 | } |
| 1184 | |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1185 | static int adt7475_probe(struct i2c_client *client, |
| 1186 | const struct i2c_device_id *id) |
| 1187 | { |
Jean Delvare | d07ca4a | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1188 | static const char *names[] = { |
| 1189 | [adt7473] = "ADT7473", |
| 1190 | [adt7475] = "ADT7475", |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1191 | [adt7476] = "ADT7476", |
Jean Delvare | d07ca4a | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1192 | [adt7490] = "ADT7490", |
| 1193 | }; |
| 1194 | |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1195 | struct adt7475_data *data; |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1196 | int i, ret = 0, revision; |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1197 | u8 config2, config3; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1198 | |
| 1199 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 1200 | if (data == NULL) |
| 1201 | return -ENOMEM; |
| 1202 | |
| 1203 | mutex_init(&data->lock); |
| 1204 | i2c_set_clientdata(client, data); |
| 1205 | |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1206 | /* Initialize device-specific values */ |
| 1207 | switch (id->driver_data) { |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1208 | case adt7476: |
| 1209 | data->has_voltage = 0x0e; /* in1 to in3 */ |
| 1210 | revision = adt7475_read(REG_DEVID2) & 0x07; |
| 1211 | break; |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1212 | case adt7490: |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1213 | data->has_voltage = 0x3e; /* in1 to in5 */ |
| 1214 | revision = adt7475_read(REG_DEVID2) & 0x03; |
Jean Delvare | d07ca4a | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1215 | if (revision == 0x03) |
| 1216 | revision += adt7475_read(REG_DEVREV2); |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1217 | break; |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1218 | default: |
| 1219 | data->has_voltage = 0x06; /* in1, in2 */ |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1220 | revision = adt7475_read(REG_DEVID2) & 0x07; |
| 1221 | } |
| 1222 | |
| 1223 | config3 = adt7475_read(REG_CONFIG3); |
| 1224 | /* Pin PWM2 may alternatively be used for ALERT output */ |
| 1225 | if (!(config3 & CONFIG3_SMBALERT)) |
| 1226 | data->has_pwm2 = 1; |
| 1227 | /* Meaning of this bit is inverted for the ADT7473-1 */ |
| 1228 | if (id->driver_data == adt7473 && revision >= 1) |
| 1229 | data->has_pwm2 = !data->has_pwm2; |
| 1230 | |
| 1231 | data->config4 = adt7475_read(REG_CONFIG4); |
| 1232 | /* Pin TACH4 may alternatively be used for THERM */ |
| 1233 | if ((data->config4 & CONFIG4_PINFUNC) == 0x0) |
| 1234 | data->has_fan4 = 1; |
| 1235 | |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1236 | /* THERM configuration is more complex on the ADT7476 and ADT7490, |
| 1237 | because 2 different pins (TACH4 and +2.5 Vin) can be used for |
| 1238 | this function */ |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1239 | if (id->driver_data == adt7490) { |
| 1240 | if ((data->config4 & CONFIG4_PINFUNC) == 0x1 && |
| 1241 | !(config3 & CONFIG3_THERM)) |
| 1242 | data->has_fan4 = 1; |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1243 | } |
| 1244 | if (id->driver_data == adt7476 || id->driver_data == adt7490) { |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1245 | if (!(config3 & CONFIG3_THERM) || |
| 1246 | (data->config4 & CONFIG4_PINFUNC) == 0x1) |
| 1247 | data->has_voltage |= (1 << 0); /* in0 */ |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1248 | } |
| 1249 | |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1250 | /* On the ADT7476, the +12V input pin may instead be used as VID5 */ |
| 1251 | if (id->driver_data == adt7476) { |
| 1252 | u8 vid = adt7475_read(REG_VID); |
| 1253 | if (!(vid & VID_VIDSEL)) |
| 1254 | data->has_voltage |= (1 << 4); /* in4 */ |
| 1255 | } |
| 1256 | |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1257 | /* Voltage attenuators can be bypassed, globally or individually */ |
| 1258 | config2 = adt7475_read(REG_CONFIG2); |
| 1259 | if (config2 & CONFIG2_ATTN) { |
| 1260 | data->bypass_attn = (0x3 << 3) | 0x3; |
| 1261 | } else { |
| 1262 | data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) | |
| 1263 | ((data->config4 & CONFIG4_ATTN_IN43) >> 3); |
| 1264 | } |
| 1265 | data->bypass_attn &= data->has_voltage; |
| 1266 | |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1267 | /* Call adt7475_read_pwm for all pwm's as this will reprogram any |
| 1268 | pwm's which are disabled to manual mode with 0% duty cycle */ |
| 1269 | for (i = 0; i < ADT7475_PWM_COUNT; i++) |
| 1270 | adt7475_read_pwm(client, i); |
| 1271 | |
| 1272 | ret = sysfs_create_group(&client->dev.kobj, &adt7475_attr_group); |
| 1273 | if (ret) |
| 1274 | goto efree; |
| 1275 | |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1276 | /* Features that can be disabled individually */ |
| 1277 | if (data->has_fan4) { |
| 1278 | ret = sysfs_create_group(&client->dev.kobj, &fan4_attr_group); |
| 1279 | if (ret) |
| 1280 | goto eremove; |
| 1281 | } |
| 1282 | if (data->has_pwm2) { |
| 1283 | ret = sysfs_create_group(&client->dev.kobj, &pwm2_attr_group); |
| 1284 | if (ret) |
| 1285 | goto eremove; |
| 1286 | } |
| 1287 | if (data->has_voltage & (1 << 0)) { |
| 1288 | ret = sysfs_create_group(&client->dev.kobj, &in0_attr_group); |
| 1289 | if (ret) |
| 1290 | goto eremove; |
| 1291 | } |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1292 | if (data->has_voltage & (1 << 3)) { |
| 1293 | ret = sysfs_create_group(&client->dev.kobj, &in3_attr_group); |
| 1294 | if (ret) |
| 1295 | goto eremove; |
| 1296 | } |
| 1297 | if (data->has_voltage & (1 << 4)) { |
| 1298 | ret = sysfs_create_group(&client->dev.kobj, &in4_attr_group); |
| 1299 | if (ret) |
| 1300 | goto eremove; |
| 1301 | } |
| 1302 | if (data->has_voltage & (1 << 5)) { |
| 1303 | ret = sysfs_create_group(&client->dev.kobj, &in5_attr_group); |
| 1304 | if (ret) |
| 1305 | goto eremove; |
| 1306 | } |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1307 | |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1308 | data->hwmon_dev = hwmon_device_register(&client->dev); |
| 1309 | if (IS_ERR(data->hwmon_dev)) { |
| 1310 | ret = PTR_ERR(data->hwmon_dev); |
| 1311 | goto eremove; |
| 1312 | } |
| 1313 | |
Jean Delvare | d07ca4a | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1314 | dev_info(&client->dev, "%s device, revision %d\n", |
| 1315 | names[id->driver_data], revision); |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1316 | if ((data->has_voltage & 0x11) || data->has_fan4 || data->has_pwm2) |
| 1317 | dev_info(&client->dev, "Optional features:%s%s%s%s\n", |
Jean Delvare | d07ca4a | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1318 | (data->has_voltage & (1 << 0)) ? " in0" : "", |
Jean Delvare | d8d2ee0 | 2009-12-09 20:36:08 +0100 | [diff] [blame^] | 1319 | (data->has_voltage & (1 << 4)) ? " in4" : "", |
Jean Delvare | d07ca4a | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1320 | data->has_fan4 ? " fan4" : "", |
| 1321 | data->has_pwm2 ? " pwm2" : ""); |
Jean Delvare | ebfaf1f | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1322 | if (data->bypass_attn) |
| 1323 | dev_info(&client->dev, "Bypassing attenuators on:%s%s%s%s\n", |
| 1324 | (data->bypass_attn & (1 << 0)) ? " in0" : "", |
| 1325 | (data->bypass_attn & (1 << 1)) ? " in1" : "", |
| 1326 | (data->bypass_attn & (1 << 3)) ? " in3" : "", |
| 1327 | (data->bypass_attn & (1 << 4)) ? " in4" : ""); |
Jean Delvare | d07ca4a | 2009-12-09 20:36:07 +0100 | [diff] [blame] | 1328 | |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1329 | return 0; |
| 1330 | |
| 1331 | eremove: |
Jean Delvare | 0f14480 | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1332 | adt7475_remove_files(client, data); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1333 | efree: |
| 1334 | kfree(data); |
| 1335 | return ret; |
| 1336 | } |
| 1337 | |
| 1338 | static int adt7475_remove(struct i2c_client *client) |
| 1339 | { |
| 1340 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 1341 | |
| 1342 | hwmon_device_unregister(data->hwmon_dev); |
Jean Delvare | 0f14480 | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1343 | adt7475_remove_files(client, data); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1344 | kfree(data); |
| 1345 | |
| 1346 | return 0; |
| 1347 | } |
| 1348 | |
| 1349 | static struct i2c_driver adt7475_driver = { |
| 1350 | .class = I2C_CLASS_HWMON, |
| 1351 | .driver = { |
| 1352 | .name = "adt7475", |
| 1353 | }, |
| 1354 | .probe = adt7475_probe, |
| 1355 | .remove = adt7475_remove, |
| 1356 | .id_table = adt7475_id, |
| 1357 | .detect = adt7475_detect, |
| 1358 | .address_data = &addr_data, |
| 1359 | }; |
| 1360 | |
| 1361 | static void adt7475_read_hystersis(struct i2c_client *client) |
| 1362 | { |
| 1363 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 1364 | |
| 1365 | data->temp[HYSTERSIS][0] = (u16) adt7475_read(REG_REMOTE1_HYSTERSIS); |
| 1366 | data->temp[HYSTERSIS][1] = data->temp[HYSTERSIS][0]; |
| 1367 | data->temp[HYSTERSIS][2] = (u16) adt7475_read(REG_REMOTE2_HYSTERSIS); |
| 1368 | } |
| 1369 | |
| 1370 | static void adt7475_read_pwm(struct i2c_client *client, int index) |
| 1371 | { |
| 1372 | struct adt7475_data *data = i2c_get_clientdata(client); |
| 1373 | unsigned int v; |
| 1374 | |
| 1375 | data->pwm[CONTROL][index] = adt7475_read(PWM_CONFIG_REG(index)); |
| 1376 | |
| 1377 | /* Figure out the internal value for pwmctrl and pwmchan |
| 1378 | based on the current settings */ |
| 1379 | v = (data->pwm[CONTROL][index] >> 5) & 7; |
| 1380 | |
| 1381 | if (v == 3) |
| 1382 | data->pwmctl[index] = 0; |
| 1383 | else if (v == 7) |
| 1384 | data->pwmctl[index] = 1; |
| 1385 | else if (v == 4) { |
| 1386 | /* The fan is disabled - we don't want to |
| 1387 | support that, so change to manual mode and |
| 1388 | set the duty cycle to 0 instead |
| 1389 | */ |
| 1390 | data->pwm[INPUT][index] = 0; |
| 1391 | data->pwm[CONTROL][index] &= ~0xE0; |
| 1392 | data->pwm[CONTROL][index] |= (7 << 5); |
| 1393 | |
| 1394 | i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index), |
| 1395 | data->pwm[INPUT][index]); |
| 1396 | |
| 1397 | i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index), |
| 1398 | data->pwm[CONTROL][index]); |
| 1399 | |
| 1400 | data->pwmctl[index] = 1; |
| 1401 | } else { |
| 1402 | data->pwmctl[index] = 2; |
| 1403 | |
| 1404 | switch (v) { |
| 1405 | case 0: |
| 1406 | data->pwmchan[index] = 1; |
| 1407 | break; |
| 1408 | case 1: |
| 1409 | data->pwmchan[index] = 2; |
| 1410 | break; |
| 1411 | case 2: |
| 1412 | data->pwmchan[index] = 4; |
| 1413 | break; |
| 1414 | case 5: |
| 1415 | data->pwmchan[index] = 6; |
| 1416 | break; |
| 1417 | case 6: |
| 1418 | data->pwmchan[index] = 7; |
| 1419 | break; |
| 1420 | } |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | static struct adt7475_data *adt7475_update_device(struct device *dev) |
| 1425 | { |
| 1426 | struct i2c_client *client = to_i2c_client(dev); |
| 1427 | struct adt7475_data *data = i2c_get_clientdata(client); |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1428 | u16 ext; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1429 | int i; |
| 1430 | |
| 1431 | mutex_lock(&data->lock); |
| 1432 | |
| 1433 | /* Measurement values update every 2 seconds */ |
| 1434 | if (time_after(jiffies, data->measure_updated + HZ * 2) || |
| 1435 | !data->valid) { |
| 1436 | data->alarms = adt7475_read(REG_STATUS2) << 8; |
| 1437 | data->alarms |= adt7475_read(REG_STATUS1); |
| 1438 | |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1439 | ext = (adt7475_read(REG_EXTEND2) << 8) | |
| 1440 | adt7475_read(REG_EXTEND1); |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1441 | for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { |
| 1442 | if (!(data->has_voltage & (1 << i))) |
| 1443 | continue; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1444 | data->voltage[INPUT][i] = |
| 1445 | (adt7475_read(VOLTAGE_REG(i)) << 2) | |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1446 | ((ext >> (i * 2)) & 3); |
| 1447 | } |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1448 | |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1449 | for (i = 0; i < ADT7475_TEMP_COUNT; i++) |
| 1450 | data->temp[INPUT][i] = |
| 1451 | (adt7475_read(TEMP_REG(i)) << 2) | |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1452 | ((ext >> ((i + 5) * 2)) & 3); |
| 1453 | |
| 1454 | if (data->has_voltage & (1 << 5)) { |
| 1455 | data->alarms |= adt7475_read(REG_STATUS4) << 24; |
| 1456 | ext = adt7475_read(REG_EXTEND3); |
| 1457 | data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 | |
| 1458 | ((ext >> 4) & 3); |
| 1459 | } |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1460 | |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1461 | for (i = 0; i < ADT7475_TACH_COUNT; i++) { |
| 1462 | if (i == 3 && !data->has_fan4) |
| 1463 | continue; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1464 | data->tach[INPUT][i] = |
| 1465 | adt7475_read_word(client, TACH_REG(i)); |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1466 | } |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1467 | |
| 1468 | /* Updated by hw when in auto mode */ |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1469 | for (i = 0; i < ADT7475_PWM_COUNT; i++) { |
| 1470 | if (i == 1 && !data->has_pwm2) |
| 1471 | continue; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1472 | data->pwm[INPUT][i] = adt7475_read(PWM_REG(i)); |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1473 | } |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1474 | |
| 1475 | data->measure_updated = jiffies; |
| 1476 | } |
| 1477 | |
| 1478 | /* Limits and settings, should never change update every 60 seconds */ |
Jean Delvare | 56e35ee | 2009-11-16 12:45:40 +0100 | [diff] [blame] | 1479 | if (time_after(jiffies, data->limits_updated + HZ * 60) || |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1480 | !data->valid) { |
Jean Delvare | f99318b | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1481 | data->config4 = adt7475_read(REG_CONFIG4); |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1482 | data->config5 = adt7475_read(REG_CONFIG5); |
| 1483 | |
| 1484 | for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { |
Jean Delvare | cffb9dd | 2009-12-09 20:36:03 +0100 | [diff] [blame] | 1485 | if (!(data->has_voltage & (1 << i))) |
| 1486 | continue; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1487 | /* Adjust values so they match the input precision */ |
| 1488 | data->voltage[MIN][i] = |
| 1489 | adt7475_read(VOLTAGE_MIN_REG(i)) << 2; |
| 1490 | data->voltage[MAX][i] = |
| 1491 | adt7475_read(VOLTAGE_MAX_REG(i)) << 2; |
| 1492 | } |
| 1493 | |
Jean Delvare | 3d84998 | 2009-12-09 20:36:05 +0100 | [diff] [blame] | 1494 | if (data->has_voltage & (1 << 5)) { |
| 1495 | data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2; |
| 1496 | data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2; |
| 1497 | } |
| 1498 | |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1499 | for (i = 0; i < ADT7475_TEMP_COUNT; i++) { |
| 1500 | /* Adjust values so they match the input precision */ |
| 1501 | data->temp[MIN][i] = |
| 1502 | adt7475_read(TEMP_MIN_REG(i)) << 2; |
| 1503 | data->temp[MAX][i] = |
| 1504 | adt7475_read(TEMP_MAX_REG(i)) << 2; |
| 1505 | data->temp[AUTOMIN][i] = |
| 1506 | adt7475_read(TEMP_TMIN_REG(i)) << 2; |
| 1507 | data->temp[THERM][i] = |
| 1508 | adt7475_read(TEMP_THERM_REG(i)) << 2; |
| 1509 | data->temp[OFFSET][i] = |
| 1510 | adt7475_read(TEMP_OFFSET_REG(i)); |
| 1511 | } |
| 1512 | adt7475_read_hystersis(client); |
| 1513 | |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1514 | for (i = 0; i < ADT7475_TACH_COUNT; i++) { |
| 1515 | if (i == 3 && !data->has_fan4) |
| 1516 | continue; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1517 | data->tach[MIN][i] = |
| 1518 | adt7475_read_word(client, TACH_MIN_REG(i)); |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1519 | } |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1520 | |
| 1521 | for (i = 0; i < ADT7475_PWM_COUNT; i++) { |
Jean Delvare | 378933c | 2009-12-09 20:36:06 +0100 | [diff] [blame] | 1522 | if (i == 1 && !data->has_pwm2) |
| 1523 | continue; |
Jordan Crouse | 1c301fc | 2009-01-15 22:27:47 +0100 | [diff] [blame] | 1524 | data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i)); |
| 1525 | data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i)); |
| 1526 | /* Set the channel and control information */ |
| 1527 | adt7475_read_pwm(client, i); |
| 1528 | } |
| 1529 | |
| 1530 | data->range[0] = adt7475_read(TEMP_TRANGE_REG(0)); |
| 1531 | data->range[1] = adt7475_read(TEMP_TRANGE_REG(1)); |
| 1532 | data->range[2] = adt7475_read(TEMP_TRANGE_REG(2)); |
| 1533 | |
| 1534 | data->limits_updated = jiffies; |
| 1535 | data->valid = 1; |
| 1536 | } |
| 1537 | |
| 1538 | mutex_unlock(&data->lock); |
| 1539 | |
| 1540 | return data; |
| 1541 | } |
| 1542 | |
| 1543 | static int __init sensors_adt7475_init(void) |
| 1544 | { |
| 1545 | return i2c_add_driver(&adt7475_driver); |
| 1546 | } |
| 1547 | |
| 1548 | static void __exit sensors_adt7475_exit(void) |
| 1549 | { |
| 1550 | i2c_del_driver(&adt7475_driver); |
| 1551 | } |
| 1552 | |
| 1553 | MODULE_AUTHOR("Advanced Micro Devices, Inc"); |
| 1554 | MODULE_DESCRIPTION("adt7475 driver"); |
| 1555 | MODULE_LICENSE("GPL"); |
| 1556 | |
| 1557 | module_init(sensors_adt7475_init); |
| 1558 | module_exit(sensors_adt7475_exit); |