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