blob: 6d4f8b8d358edde71408f52554555aafcd21e594 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
5 Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
6
7 Chip details at:
8
9 <http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/jiffies.h>
30#include <linux/i2c.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040031#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020032#include <linux/hwmon-sysfs.h>
33#include <linux/hwmon-vid.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040034#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010035#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/* Addresses to scan */
38static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/* Insmod parameters */
Jean Delvaref4b50262005-07-31 21:49:03 +020041I2C_CLIENT_INSMOD_1(adm1026);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
44 -1, -1, -1, -1, -1, -1, -1, -1 };
45static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
46 -1, -1, -1, -1, -1, -1, -1, -1 };
47static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
48 -1, -1, -1, -1, -1, -1, -1, -1 };
49static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
50 -1, -1, -1, -1, -1, -1, -1, -1 };
51static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
52module_param_array(gpio_input,int,NULL,0);
53MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
54module_param_array(gpio_output,int,NULL,0);
55MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
56 "outputs");
57module_param_array(gpio_inverted,int,NULL,0);
58MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
59 "inverted");
60module_param_array(gpio_normal,int,NULL,0);
61MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
62 "normal/non-inverted");
63module_param_array(gpio_fan,int,NULL,0);
64MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
65
66/* Many ADM1026 constants specified below */
67
68/* The ADM1026 registers */
69#define ADM1026_REG_CONFIG1 0x00
70#define CFG1_MONITOR 0x01
71#define CFG1_INT_ENABLE 0x02
72#define CFG1_INT_CLEAR 0x04
73#define CFG1_AIN8_9 0x08
74#define CFG1_THERM_HOT 0x10
75#define CFG1_DAC_AFC 0x20
76#define CFG1_PWM_AFC 0x40
77#define CFG1_RESET 0x80
78#define ADM1026_REG_CONFIG2 0x01
79/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
80#define ADM1026_REG_CONFIG3 0x07
81#define CFG3_GPIO16_ENABLE 0x01
82#define CFG3_CI_CLEAR 0x02
83#define CFG3_VREF_250 0x04
84#define CFG3_GPIO16_DIR 0x40
85#define CFG3_GPIO16_POL 0x80
86#define ADM1026_REG_E2CONFIG 0x13
87#define E2CFG_READ 0x01
88#define E2CFG_WRITE 0x02
89#define E2CFG_ERASE 0x04
90#define E2CFG_ROM 0x08
91#define E2CFG_CLK_EXT 0x80
92
93/* There are 10 general analog inputs and 7 dedicated inputs
94 * They are:
95 * 0 - 9 = AIN0 - AIN9
96 * 10 = Vbat
97 * 11 = 3.3V Standby
98 * 12 = 3.3V Main
99 * 13 = +5V
100 * 14 = Vccp (CPU core voltage)
101 * 15 = +12V
102 * 16 = -12V
103 */
104static u16 ADM1026_REG_IN[] = {
105 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
106 0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
107 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
108 };
109static u16 ADM1026_REG_IN_MIN[] = {
110 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
111 0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
112 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
113 };
114static u16 ADM1026_REG_IN_MAX[] = {
115 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
116 0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
117 0x43, 0x44, 0x45, 0x46, 0x47
118 };
119
120/* Temperatures are:
121 * 0 - Internal
122 * 1 - External 1
123 * 2 - External 2
124 */
125static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
126static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
127static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
128static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
129static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
130static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
131
132#define ADM1026_REG_FAN(nr) (0x38 + (nr))
133#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
134#define ADM1026_REG_FAN_DIV_0_3 0x02
135#define ADM1026_REG_FAN_DIV_4_7 0x03
136
137#define ADM1026_REG_DAC 0x04
138#define ADM1026_REG_PWM 0x05
139
140#define ADM1026_REG_GPIO_CFG_0_3 0x08
141#define ADM1026_REG_GPIO_CFG_4_7 0x09
142#define ADM1026_REG_GPIO_CFG_8_11 0x0a
143#define ADM1026_REG_GPIO_CFG_12_15 0x0b
144/* CFG_16 in REG_CFG3 */
145#define ADM1026_REG_GPIO_STATUS_0_7 0x24
146#define ADM1026_REG_GPIO_STATUS_8_15 0x25
147/* STATUS_16 in REG_STATUS4 */
148#define ADM1026_REG_GPIO_MASK_0_7 0x1c
149#define ADM1026_REG_GPIO_MASK_8_15 0x1d
150/* MASK_16 in REG_MASK4 */
151
152#define ADM1026_REG_COMPANY 0x16
153#define ADM1026_REG_VERSTEP 0x17
154/* These are the recognized values for the above regs */
155#define ADM1026_COMPANY_ANALOG_DEV 0x41
156#define ADM1026_VERSTEP_GENERIC 0x40
157#define ADM1026_VERSTEP_ADM1026 0x44
158
159#define ADM1026_REG_MASK1 0x18
160#define ADM1026_REG_MASK2 0x19
161#define ADM1026_REG_MASK3 0x1a
162#define ADM1026_REG_MASK4 0x1b
163
164#define ADM1026_REG_STATUS1 0x20
165#define ADM1026_REG_STATUS2 0x21
166#define ADM1026_REG_STATUS3 0x22
167#define ADM1026_REG_STATUS4 0x23
168
169#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
170#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
171#define ADM1026_PWM_MAX 255
172
173/* Conversions. Rounding and limit checking is only done on the TO_REG
174 * variants. Note that you should be a bit careful with which arguments
175 * these macros are called: arguments may be evaluated more than once.
176 */
177
178/* IN are scaled acording to built-in resistors. These are the
179 * voltages corresponding to 3/4 of full scale (192 or 0xc0)
180 * NOTE: The -12V input needs an additional factor to account
181 * for the Vref pullup resistor.
182 * NEG12_OFFSET = SCALE * Vref / V-192 - Vref
183 * = 13875 * 2.50 / 1.875 - 2500
184 * = 16000
185 *
186 * The values in this table are based on Table II, page 15 of the
187 * datasheet.
188 */
189static int adm1026_scaling[] = { /* .001 Volts */
190 2250, 2250, 2250, 2250, 2250, 2250,
191 1875, 1875, 1875, 1875, 3000, 3330,
192 3330, 4995, 2250, 12000, 13875
193 };
194#define NEG12_OFFSET 16000
195#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
196#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
197 0,255))
198#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
199
200/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
201 * and we assume a 2 pulse-per-rev fan tach signal
202 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
203 */
204#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
205 (div)),1,254))
206#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\
207 (div)))
208#define DIV_FROM_REG(val) (1<<(val))
209#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
210
211/* Temperature is reported in 1 degC increments */
212#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
213 -127,127))
214#define TEMP_FROM_REG(val) ((val) * 1000)
215#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
216 -127,127))
217#define OFFSET_FROM_REG(val) ((val) * 1000)
218
219#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
220#define PWM_FROM_REG(val) (val)
221
222#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
223#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
224
225/* Analog output is a voltage, and scaled to millivolts. The datasheet
226 * indicates that the DAC could be used to drive the fans, but in our
227 * example board (Arima HDAMA) it isn't connected to the fans at all.
228 */
229#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
230#define DAC_FROM_REG(val) (((val)*2500)/255)
231
232/* Typically used with systems using a v9.1 VRM spec ? */
233#define ADM1026_INIT_VRM 91
234
235/* Chip sampling rates
236 *
237 * Some sensors are not updated more frequently than once per second
238 * so it doesn't make sense to read them more often than that.
239 * We cache the results and return the saved data if the driver
240 * is called again before a second has elapsed.
241 *
242 * Also, there is significant configuration data for this chip
243 * So, we keep the config data up to date in the cache
244 * when it is written and only sample it once every 5 *minutes*
245 */
246#define ADM1026_DATA_INTERVAL (1 * HZ)
247#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
248
249/* We allow for multiple chips in a single system.
250 *
251 * For each registered ADM1026, we need to keep state information
252 * at client->data. The adm1026_data structure is dynamically
253 * allocated, when a new client structure is allocated. */
254
255struct pwm_data {
256 u8 pwm;
257 u8 enable;
258 u8 auto_pwm_min;
259};
260
261struct adm1026_data {
262 struct i2c_client client;
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400263 struct class_device *class_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100264 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 enum chips type;
266
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100267 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 int valid; /* !=0 if following fields are valid */
269 unsigned long last_reading; /* In jiffies */
270 unsigned long last_config; /* In jiffies */
271
272 u8 in[17]; /* Register value */
273 u8 in_max[17]; /* Register value */
274 u8 in_min[17]; /* Register value */
275 s8 temp[3]; /* Register value */
276 s8 temp_min[3]; /* Register value */
277 s8 temp_max[3]; /* Register value */
278 s8 temp_tmin[3]; /* Register value */
279 s8 temp_crit[3]; /* Register value */
280 s8 temp_offset[3]; /* Register value */
281 u8 fan[8]; /* Register value */
282 u8 fan_min[8]; /* Register value */
283 u8 fan_div[8]; /* Decoded value */
284 struct pwm_data pwm1; /* Pwm control values */
285 int vid; /* Decoded value */
286 u8 vrm; /* VRM version */
287 u8 analog_out; /* Register value (DAC) */
288 long alarms; /* Register encoding, combined */
289 long alarm_mask; /* Register encoding, combined */
290 long gpio; /* Register encoding, combined */
291 long gpio_mask; /* Register encoding, combined */
292 u8 gpio_config[17]; /* Decoded value */
293 u8 config1; /* Register value */
294 u8 config2; /* Register value */
295 u8 config3; /* Register value */
296};
297
298static int adm1026_attach_adapter(struct i2c_adapter *adapter);
299static int adm1026_detect(struct i2c_adapter *adapter, int address,
300 int kind);
301static int adm1026_detach_client(struct i2c_client *client);
Darren Jenkinsf6c27fc2006-02-27 23:14:58 +0100302static int adm1026_read_value(struct i2c_client *client, u8 reg);
303static int adm1026_write_value(struct i2c_client *client, u8 reg, int value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304static void adm1026_print_gpio(struct i2c_client *client);
305static void adm1026_fixup_gpio(struct i2c_client *client);
306static struct adm1026_data *adm1026_update_device(struct device *dev);
307static void adm1026_init_client(struct i2c_client *client);
308
309
310static struct i2c_driver adm1026_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100311 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100312 .name = "adm1026",
313 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 .attach_adapter = adm1026_attach_adapter,
315 .detach_client = adm1026_detach_client,
316};
317
Ben Dooksc49efce2005-10-26 21:07:25 +0200318static int adm1026_attach_adapter(struct i2c_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
320 if (!(adapter->class & I2C_CLASS_HWMON)) {
321 return 0;
322 }
Jean Delvare2ed2dc32005-07-31 21:42:02 +0200323 return i2c_probe(adapter, &addr_data, adm1026_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
Ben Dooksc49efce2005-10-26 21:07:25 +0200326static int adm1026_detach_client(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400328 struct adm1026_data *data = i2c_get_clientdata(client);
329 hwmon_device_unregister(data->class_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 i2c_detach_client(client);
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400331 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 return 0;
333}
334
Ben Dooksc49efce2005-10-26 21:07:25 +0200335static int adm1026_read_value(struct i2c_client *client, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
337 int res;
338
339 if (reg < 0x80) {
340 /* "RAM" locations */
341 res = i2c_smbus_read_byte_data(client, reg) & 0xff;
342 } else {
343 /* EEPROM, do nothing */
344 res = 0;
345 }
346 return res;
347}
348
Ben Dooksc49efce2005-10-26 21:07:25 +0200349static int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
351 int res;
352
353 if (reg < 0x80) {
354 /* "RAM" locations */
355 res = i2c_smbus_write_byte_data(client, reg, value);
356 } else {
357 /* EEPROM, do nothing */
358 res = 0;
359 }
360 return res;
361}
362
Ben Dooksc49efce2005-10-26 21:07:25 +0200363static void adm1026_init_client(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 int value, i;
366 struct adm1026_data *data = i2c_get_clientdata(client);
367
368 dev_dbg(&client->dev, "Initializing device\n");
369 /* Read chip config */
370 data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
371 data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
372 data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
373
374 /* Inform user of chip config */
375 dev_dbg(&client->dev, "ADM1026_REG_CONFIG1 is: 0x%02x\n",
376 data->config1);
377 if ((data->config1 & CFG1_MONITOR) == 0) {
378 dev_dbg(&client->dev, "Monitoring not currently "
379 "enabled.\n");
380 }
381 if (data->config1 & CFG1_INT_ENABLE) {
382 dev_dbg(&client->dev, "SMBALERT interrupts are "
383 "enabled.\n");
384 }
385 if (data->config1 & CFG1_AIN8_9) {
386 dev_dbg(&client->dev, "in8 and in9 enabled. "
387 "temp3 disabled.\n");
388 } else {
389 dev_dbg(&client->dev, "temp3 enabled. in8 and "
390 "in9 disabled.\n");
391 }
392 if (data->config1 & CFG1_THERM_HOT) {
393 dev_dbg(&client->dev, "Automatic THERM, PWM, "
394 "and temp limits enabled.\n");
395 }
396
397 value = data->config3;
398 if (data->config3 & CFG3_GPIO16_ENABLE) {
Jean Delvare368609c2005-07-29 12:15:07 -0700399 dev_dbg(&client->dev, "GPIO16 enabled. THERM "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 "pin disabled.\n");
401 } else {
402 dev_dbg(&client->dev, "THERM pin enabled. "
403 "GPIO16 disabled.\n");
404 }
405 if (data->config3 & CFG3_VREF_250) {
406 dev_dbg(&client->dev, "Vref is 2.50 Volts.\n");
407 } else {
408 dev_dbg(&client->dev, "Vref is 1.82 Volts.\n");
409 }
410 /* Read and pick apart the existing GPIO configuration */
411 value = 0;
412 for (i = 0;i <= 15;++i) {
413 if ((i & 0x03) == 0) {
414 value = adm1026_read_value(client,
415 ADM1026_REG_GPIO_CFG_0_3 + i/4);
416 }
417 data->gpio_config[i] = value & 0x03;
418 value >>= 2;
419 }
420 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
421
422 /* ... and then print it */
423 adm1026_print_gpio(client);
424
425 /* If the user asks us to reprogram the GPIO config, then
426 * do it now.
427 */
428 if (gpio_input[0] != -1 || gpio_output[0] != -1
429 || gpio_inverted[0] != -1 || gpio_normal[0] != -1
430 || gpio_fan[0] != -1) {
431 adm1026_fixup_gpio(client);
432 }
433
434 /* WE INTENTIONALLY make no changes to the limits,
435 * offsets, pwms, fans and zones. If they were
436 * configured, we don't want to mess with them.
437 * If they weren't, the default is 100% PWM, no
438 * control and will suffice until 'sensors -s'
439 * can be run by the user. We DO set the default
440 * value for pwm1.auto_pwm_min to its maximum
441 * so that enabling automatic pwm fan control
442 * without first setting a value for pwm1.auto_pwm_min
443 * will not result in potentially dangerous fan speed decrease.
444 */
445 data->pwm1.auto_pwm_min=255;
446 /* Start monitoring */
447 value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
448 /* Set MONITOR, clear interrupt acknowledge and s/w reset */
449 value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
450 dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
451 data->config1 = value;
452 adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
453
454 /* initialize fan_div[] to hardware defaults */
455 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) |
456 (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8);
457 for (i = 0;i <= 7;++i) {
458 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
459 value >>= 2;
460 }
461}
462
Ben Dooksc49efce2005-10-26 21:07:25 +0200463static void adm1026_print_gpio(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 struct adm1026_data *data = i2c_get_clientdata(client);
466 int i;
467
468 dev_dbg(&client->dev, "GPIO config is:");
469 for (i = 0;i <= 7;++i) {
470 if (data->config2 & (1 << i)) {
471 dev_dbg(&client->dev, "\t%sGP%s%d\n",
472 data->gpio_config[i] & 0x02 ? "" : "!",
473 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
474 i);
475 } else {
476 dev_dbg(&client->dev, "\tFAN%d\n", i);
477 }
478 }
479 for (i = 8;i <= 15;++i) {
480 dev_dbg(&client->dev, "\t%sGP%s%d\n",
481 data->gpio_config[i] & 0x02 ? "" : "!",
482 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
483 i);
484 }
485 if (data->config3 & CFG3_GPIO16_ENABLE) {
486 dev_dbg(&client->dev, "\t%sGP%s16\n",
487 data->gpio_config[16] & 0x02 ? "" : "!",
488 data->gpio_config[16] & 0x01 ? "OUT" : "IN");
489 } else {
490 /* GPIO16 is THERM */
491 dev_dbg(&client->dev, "\tTHERM\n");
492 }
493}
494
Ben Dooksc49efce2005-10-26 21:07:25 +0200495static void adm1026_fixup_gpio(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
497 struct adm1026_data *data = i2c_get_clientdata(client);
498 int i;
499 int value;
500
501 /* Make the changes requested. */
502 /* We may need to unlock/stop monitoring or soft-reset the
503 * chip before we can make changes. This hasn't been
504 * tested much. FIXME
505 */
506
507 /* Make outputs */
508 for (i = 0;i <= 16;++i) {
509 if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
510 data->gpio_config[gpio_output[i]] |= 0x01;
511 }
512 /* if GPIO0-7 is output, it isn't a FAN tach */
513 if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
514 data->config2 |= 1 << gpio_output[i];
515 }
516 }
517
518 /* Input overrides output */
519 for (i = 0;i <= 16;++i) {
520 if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
521 data->gpio_config[gpio_input[i]] &= ~ 0x01;
522 }
523 /* if GPIO0-7 is input, it isn't a FAN tach */
524 if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
525 data->config2 |= 1 << gpio_input[i];
526 }
527 }
528
529 /* Inverted */
530 for (i = 0;i <= 16;++i) {
531 if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
532 data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
533 }
534 }
535
536 /* Normal overrides inverted */
537 for (i = 0;i <= 16;++i) {
538 if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
539 data->gpio_config[gpio_normal[i]] |= 0x02;
540 }
541 }
542
543 /* Fan overrides input and output */
544 for (i = 0;i <= 7;++i) {
545 if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
546 data->config2 &= ~(1 << gpio_fan[i]);
547 }
548 }
549
550 /* Write new configs to registers */
551 adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
552 data->config3 = (data->config3 & 0x3f)
553 | ((data->gpio_config[16] & 0x03) << 6);
554 adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
555 for (i = 15, value = 0;i >= 0;--i) {
556 value <<= 2;
557 value |= data->gpio_config[i] & 0x03;
558 if ((i & 0x03) == 0) {
559 adm1026_write_value(client,
560 ADM1026_REG_GPIO_CFG_0_3 + i/4,
561 value);
562 value = 0;
563 }
564 }
565
566 /* Print the new config */
567 adm1026_print_gpio(client);
568}
569
570
571static struct adm1026_data *adm1026_update_device(struct device *dev)
572{
573 struct i2c_client *client = to_i2c_client(dev);
574 struct adm1026_data *data = i2c_get_clientdata(client);
575 int i;
576 long value, alarms, gpio;
577
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100578 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 if (!data->valid
580 || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) {
581 /* Things that change quickly */
582 dev_dbg(&client->dev,"Reading sensor values\n");
583 for (i = 0;i <= 16;++i) {
584 data->in[i] =
585 adm1026_read_value(client, ADM1026_REG_IN[i]);
586 }
587
588 for (i = 0;i <= 7;++i) {
589 data->fan[i] =
590 adm1026_read_value(client, ADM1026_REG_FAN(i));
591 }
592
593 for (i = 0;i <= 2;++i) {
594 /* NOTE: temp[] is s8 and we assume 2's complement
595 * "conversion" in the assignment */
596 data->temp[i] =
597 adm1026_read_value(client, ADM1026_REG_TEMP[i]);
598 }
599
600 data->pwm1.pwm = adm1026_read_value(client,
601 ADM1026_REG_PWM);
602 data->analog_out = adm1026_read_value(client,
603 ADM1026_REG_DAC);
604 /* GPIO16 is MSbit of alarms, move it to gpio */
605 alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
606 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
607 alarms &= 0x7f;
608 alarms <<= 8;
609 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
610 alarms <<= 8;
611 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
612 alarms <<= 8;
613 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
614 data->alarms = alarms;
615
616 /* Read the GPIO values */
617 gpio |= adm1026_read_value(client,
618 ADM1026_REG_GPIO_STATUS_8_15);
619 gpio <<= 8;
620 gpio |= adm1026_read_value(client,
621 ADM1026_REG_GPIO_STATUS_0_7);
622 data->gpio = gpio;
623
624 data->last_reading = jiffies;
625 }; /* last_reading */
626
627 if (!data->valid ||
628 time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) {
629 /* Things that don't change often */
630 dev_dbg(&client->dev, "Reading config values\n");
631 for (i = 0;i <= 16;++i) {
632 data->in_min[i] = adm1026_read_value(client,
633 ADM1026_REG_IN_MIN[i]);
634 data->in_max[i] = adm1026_read_value(client,
635 ADM1026_REG_IN_MAX[i]);
636 }
637
638 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
639 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
640 << 8);
641 for (i = 0;i <= 7;++i) {
642 data->fan_min[i] = adm1026_read_value(client,
643 ADM1026_REG_FAN_MIN(i));
644 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
645 value >>= 2;
646 }
647
648 for (i = 0; i <= 2; ++i) {
649 /* NOTE: temp_xxx[] are s8 and we assume 2's
650 * complement "conversion" in the assignment
651 */
652 data->temp_min[i] = adm1026_read_value(client,
653 ADM1026_REG_TEMP_MIN[i]);
654 data->temp_max[i] = adm1026_read_value(client,
655 ADM1026_REG_TEMP_MAX[i]);
656 data->temp_tmin[i] = adm1026_read_value(client,
657 ADM1026_REG_TEMP_TMIN[i]);
658 data->temp_crit[i] = adm1026_read_value(client,
659 ADM1026_REG_TEMP_THERM[i]);
660 data->temp_offset[i] = adm1026_read_value(client,
661 ADM1026_REG_TEMP_OFFSET[i]);
662 }
663
664 /* Read the STATUS/alarm masks */
665 alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
666 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
667 alarms = (alarms & 0x7f) << 8;
668 alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
669 alarms <<= 8;
670 alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
671 alarms <<= 8;
672 alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
673 data->alarm_mask = alarms;
674
675 /* Read the GPIO values */
676 gpio |= adm1026_read_value(client,
677 ADM1026_REG_GPIO_MASK_8_15);
678 gpio <<= 8;
679 gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
680 data->gpio_mask = gpio;
681
682 /* Read various values from CONFIG1 */
683 data->config1 = adm1026_read_value(client,
684 ADM1026_REG_CONFIG1);
685 if (data->config1 & CFG1_PWM_AFC) {
686 data->pwm1.enable = 2;
687 data->pwm1.auto_pwm_min =
688 PWM_MIN_FROM_REG(data->pwm1.pwm);
689 }
690 /* Read the GPIO config */
691 data->config2 = adm1026_read_value(client,
692 ADM1026_REG_CONFIG2);
693 data->config3 = adm1026_read_value(client,
694 ADM1026_REG_CONFIG3);
695 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
696
697 value = 0;
698 for (i = 0;i <= 15;++i) {
699 if ((i & 0x03) == 0) {
700 value = adm1026_read_value(client,
701 ADM1026_REG_GPIO_CFG_0_3 + i/4);
702 }
703 data->gpio_config[i] = value & 0x03;
704 value >>= 2;
705 }
706
707 data->last_config = jiffies;
708 }; /* last_config */
709
710 dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n");
711 data->vid = (data->gpio >> 11) & 0x1f;
712 data->valid = 1;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100713 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 return data;
715}
716
Yani Ioannou050480f2005-06-05 10:51:46 +0200717static ssize_t show_in(struct device *dev, struct device_attribute *attr,
718 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
Yani Ioannou050480f2005-06-05 10:51:46 +0200720 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
721 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 struct adm1026_data *data = adm1026_update_device(dev);
723 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
724}
Yani Ioannou050480f2005-06-05 10:51:46 +0200725static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
726 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
Yani Ioannou050480f2005-06-05 10:51:46 +0200728 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
729 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 struct adm1026_data *data = adm1026_update_device(dev);
731 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
732}
Yani Ioannou050480f2005-06-05 10:51:46 +0200733static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
734 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Yani Ioannou050480f2005-06-05 10:51:46 +0200736 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
737 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 struct i2c_client *client = to_i2c_client(dev);
739 struct adm1026_data *data = i2c_get_clientdata(client);
740 int val = simple_strtol(buf, NULL, 10);
741
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100742 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 data->in_min[nr] = INS_TO_REG(nr, val);
744 adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100745 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 return count;
747}
Yani Ioannou050480f2005-06-05 10:51:46 +0200748static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
749 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750{
Yani Ioannou050480f2005-06-05 10:51:46 +0200751 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
752 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 struct adm1026_data *data = adm1026_update_device(dev);
754 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
755}
Yani Ioannou050480f2005-06-05 10:51:46 +0200756static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
757 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
Yani Ioannou050480f2005-06-05 10:51:46 +0200759 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
760 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 struct i2c_client *client = to_i2c_client(dev);
762 struct adm1026_data *data = i2c_get_clientdata(client);
763 int val = simple_strtol(buf, NULL, 10);
764
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100765 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 data->in_max[nr] = INS_TO_REG(nr, val);
767 adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100768 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 return count;
770}
771
Yani Ioannou050480f2005-06-05 10:51:46 +0200772#define in_reg(offset) \
773static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in, \
774 NULL, offset); \
775static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
776 show_in_min, set_in_min, offset); \
777static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
778 show_in_max, set_in_max, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780
781in_reg(0);
782in_reg(1);
783in_reg(2);
784in_reg(3);
785in_reg(4);
786in_reg(5);
787in_reg(6);
788in_reg(7);
789in_reg(8);
790in_reg(9);
791in_reg(10);
792in_reg(11);
793in_reg(12);
794in_reg(13);
795in_reg(14);
796in_reg(15);
797
Yani Ioannou74880c02005-05-17 06:41:12 -0400798static ssize_t show_in16(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
800 struct adm1026_data *data = adm1026_update_device(dev);
801 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
802 NEG12_OFFSET);
803}
Yani Ioannou74880c02005-05-17 06:41:12 -0400804static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805{
806 struct adm1026_data *data = adm1026_update_device(dev);
807 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
808 - NEG12_OFFSET);
809}
Yani Ioannou74880c02005-05-17 06:41:12 -0400810static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
812 struct i2c_client *client = to_i2c_client(dev);
813 struct adm1026_data *data = i2c_get_clientdata(client);
814 int val = simple_strtol(buf, NULL, 10);
815
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100816 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
818 adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100819 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 return count;
821}
Yani Ioannou74880c02005-05-17 06:41:12 -0400822static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
824 struct adm1026_data *data = adm1026_update_device(dev);
825 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
826 - NEG12_OFFSET);
827}
Yani Ioannou74880c02005-05-17 06:41:12 -0400828static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
830 struct i2c_client *client = to_i2c_client(dev);
831 struct adm1026_data *data = i2c_get_clientdata(client);
832 int val = simple_strtol(buf, NULL, 10);
833
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100834 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
836 adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100837 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 return count;
839}
840
Yani Ioannou050480f2005-06-05 10:51:46 +0200841static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL, 16);
842static SENSOR_DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min, 16);
843static SENSOR_DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845
846
847
848/* Now add fan read/write functions */
849
Yani Ioannou050480f2005-06-05 10:51:46 +0200850static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
851 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Yani Ioannou050480f2005-06-05 10:51:46 +0200853 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
854 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 struct adm1026_data *data = adm1026_update_device(dev);
856 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
857 data->fan_div[nr]));
858}
Yani Ioannou050480f2005-06-05 10:51:46 +0200859static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
860 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Yani Ioannou050480f2005-06-05 10:51:46 +0200862 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
863 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 struct adm1026_data *data = adm1026_update_device(dev);
865 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
866 data->fan_div[nr]));
867}
Yani Ioannou050480f2005-06-05 10:51:46 +0200868static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
869 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
Yani Ioannou050480f2005-06-05 10:51:46 +0200871 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
872 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 struct i2c_client *client = to_i2c_client(dev);
874 struct adm1026_data *data = i2c_get_clientdata(client);
875 int val = simple_strtol(buf, NULL, 10);
876
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100877 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
879 adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
880 data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100881 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 return count;
883}
884
Yani Ioannou050480f2005-06-05 10:51:46 +0200885#define fan_offset(offset) \
886static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL, \
887 offset - 1); \
888static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
889 show_fan_min, set_fan_min, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891fan_offset(1);
892fan_offset(2);
893fan_offset(3);
894fan_offset(4);
895fan_offset(5);
896fan_offset(6);
897fan_offset(7);
898fan_offset(8);
899
900/* Adjust fan_min to account for new fan divisor */
901static void fixup_fan_min(struct device *dev, int fan, int old_div)
902{
903 struct i2c_client *client = to_i2c_client(dev);
904 struct adm1026_data *data = i2c_get_clientdata(client);
905 int new_min;
906 int new_div = data->fan_div[fan];
907
908 /* 0 and 0xff are special. Don't adjust them */
909 if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
910 return;
911 }
912
913 new_min = data->fan_min[fan] * old_div / new_div;
914 new_min = SENSORS_LIMIT(new_min, 1, 254);
915 data->fan_min[fan] = new_min;
916 adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
917}
918
919/* Now add fan_div read/write functions */
Yani Ioannou050480f2005-06-05 10:51:46 +0200920static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
921 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
Yani Ioannou050480f2005-06-05 10:51:46 +0200923 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
924 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 struct adm1026_data *data = adm1026_update_device(dev);
926 return sprintf(buf,"%d\n", data->fan_div[nr]);
927}
Yani Ioannou050480f2005-06-05 10:51:46 +0200928static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
929 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
Yani Ioannou050480f2005-06-05 10:51:46 +0200931 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
932 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 struct i2c_client *client = to_i2c_client(dev);
934 struct adm1026_data *data = i2c_get_clientdata(client);
935 int val,orig_div,new_div,shift;
936
937 val = simple_strtol(buf, NULL, 10);
938 new_div = DIV_TO_REG(val);
939 if (new_div == 0) {
940 return -EINVAL;
941 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100942 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 orig_div = data->fan_div[nr];
944 data->fan_div[nr] = DIV_FROM_REG(new_div);
945
946 if (nr < 4) { /* 0 <= nr < 4 */
947 shift = 2 * nr;
948 adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
949 ((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
950 (new_div << shift)));
951 } else { /* 3 < nr < 8 */
952 shift = 2 * (nr - 4);
953 adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
954 ((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
955 (new_div << shift)));
956 }
957
958 if (data->fan_div[nr] != orig_div) {
959 fixup_fan_min(dev,nr,orig_div);
960 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100961 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 return count;
963}
964
965#define fan_offset_div(offset) \
Yani Ioannou050480f2005-06-05 10:51:46 +0200966static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
967 show_fan_div, set_fan_div, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
969fan_offset_div(1);
970fan_offset_div(2);
971fan_offset_div(3);
972fan_offset_div(4);
973fan_offset_div(5);
974fan_offset_div(6);
975fan_offset_div(7);
976fan_offset_div(8);
977
978/* Temps */
Yani Ioannou050480f2005-06-05 10:51:46 +0200979static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
980 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981{
Yani Ioannou050480f2005-06-05 10:51:46 +0200982 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
983 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 struct adm1026_data *data = adm1026_update_device(dev);
985 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
986}
Yani Ioannou050480f2005-06-05 10:51:46 +0200987static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
988 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989{
Yani Ioannou050480f2005-06-05 10:51:46 +0200990 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
991 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 struct adm1026_data *data = adm1026_update_device(dev);
993 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
994}
Yani Ioannou050480f2005-06-05 10:51:46 +0200995static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
996 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997{
Yani Ioannou050480f2005-06-05 10:51:46 +0200998 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
999 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 struct i2c_client *client = to_i2c_client(dev);
1001 struct adm1026_data *data = i2c_get_clientdata(client);
1002 int val = simple_strtol(buf, NULL, 10);
1003
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001004 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 data->temp_min[nr] = TEMP_TO_REG(val);
1006 adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
1007 data->temp_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001008 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 return count;
1010}
Yani Ioannou050480f2005-06-05 10:51:46 +02001011static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
1012 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
Yani Ioannou050480f2005-06-05 10:51:46 +02001014 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1015 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 struct adm1026_data *data = adm1026_update_device(dev);
1017 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
1018}
Yani Ioannou050480f2005-06-05 10:51:46 +02001019static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
1020 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
Yani Ioannou050480f2005-06-05 10:51:46 +02001022 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1023 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 struct i2c_client *client = to_i2c_client(dev);
1025 struct adm1026_data *data = i2c_get_clientdata(client);
1026 int val = simple_strtol(buf, NULL, 10);
1027
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001028 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 data->temp_max[nr] = TEMP_TO_REG(val);
1030 adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
1031 data->temp_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001032 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 return count;
1034}
Yani Ioannou050480f2005-06-05 10:51:46 +02001035
1036#define temp_reg(offset) \
1037static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \
1038 NULL, offset - 1); \
1039static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
1040 show_temp_min, set_temp_min, offset - 1); \
1041static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
1042 show_temp_max, set_temp_max, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044
1045temp_reg(1);
1046temp_reg(2);
1047temp_reg(3);
1048
Yani Ioannou050480f2005-06-05 10:51:46 +02001049static ssize_t show_temp_offset(struct device *dev,
1050 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
Yani Ioannou050480f2005-06-05 10:51:46 +02001052 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1053 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 struct adm1026_data *data = adm1026_update_device(dev);
1055 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
1056}
Yani Ioannou050480f2005-06-05 10:51:46 +02001057static ssize_t set_temp_offset(struct device *dev,
1058 struct device_attribute *attr, const char *buf,
1059 size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060{
Yani Ioannou050480f2005-06-05 10:51:46 +02001061 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1062 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 struct i2c_client *client = to_i2c_client(dev);
1064 struct adm1026_data *data = i2c_get_clientdata(client);
1065 int val = simple_strtol(buf, NULL, 10);
1066
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001067 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 data->temp_offset[nr] = TEMP_TO_REG(val);
1069 adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
1070 data->temp_offset[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001071 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 return count;
1073}
1074
Yani Ioannou050480f2005-06-05 10:51:46 +02001075#define temp_offset_reg(offset) \
1076static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
1077 show_temp_offset, set_temp_offset, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
1079temp_offset_reg(1);
1080temp_offset_reg(2);
1081temp_offset_reg(3);
1082
Yani Ioannou050480f2005-06-05 10:51:46 +02001083static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev,
1084 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
Yani Ioannou050480f2005-06-05 10:51:46 +02001086 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1087 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 struct adm1026_data *data = adm1026_update_device(dev);
1089 return sprintf(buf,"%d\n", TEMP_FROM_REG(
1090 ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
1091}
Yani Ioannou050480f2005-06-05 10:51:46 +02001092static ssize_t show_temp_auto_point2_temp(struct device *dev,
1093 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Yani Ioannou050480f2005-06-05 10:51:46 +02001095 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1096 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 struct adm1026_data *data = adm1026_update_device(dev);
1098 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
1099 ADM1026_FAN_CONTROL_TEMP_RANGE));
1100}
Yani Ioannou050480f2005-06-05 10:51:46 +02001101static ssize_t show_temp_auto_point1_temp(struct device *dev,
1102 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103{
Yani Ioannou050480f2005-06-05 10:51:46 +02001104 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1105 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 struct adm1026_data *data = adm1026_update_device(dev);
1107 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
1108}
Yani Ioannou050480f2005-06-05 10:51:46 +02001109static ssize_t set_temp_auto_point1_temp(struct device *dev,
1110 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Yani Ioannou050480f2005-06-05 10:51:46 +02001112 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1113 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 struct i2c_client *client = to_i2c_client(dev);
1115 struct adm1026_data *data = i2c_get_clientdata(client);
1116 int val = simple_strtol(buf, NULL, 10);
1117
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001118 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 data->temp_tmin[nr] = TEMP_TO_REG(val);
1120 adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
1121 data->temp_tmin[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001122 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 return count;
1124}
1125
Yani Ioannou050480f2005-06-05 10:51:46 +02001126#define temp_auto_point(offset) \
1127static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
1128 show_temp_auto_point1_temp, set_temp_auto_point1_temp, \
1129 offset - 1); \
1130static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
1131 show_temp_auto_point1_temp_hyst, NULL, offset - 1); \
1132static SENSOR_DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
1133 show_temp_auto_point2_temp, NULL, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
1135temp_auto_point(1);
1136temp_auto_point(2);
1137temp_auto_point(3);
1138
Yani Ioannou050480f2005-06-05 10:51:46 +02001139static ssize_t show_temp_crit_enable(struct device *dev,
1140 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141{
1142 struct adm1026_data *data = adm1026_update_device(dev);
1143 return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
1144}
Yani Ioannou050480f2005-06-05 10:51:46 +02001145static ssize_t set_temp_crit_enable(struct device *dev,
1146 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147{
1148 struct i2c_client *client = to_i2c_client(dev);
1149 struct adm1026_data *data = i2c_get_clientdata(client);
1150 int val = simple_strtol(buf, NULL, 10);
1151
1152 if ((val == 1) || (val==0)) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001153 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
1155 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1156 data->config1);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001157 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 }
1159 return count;
1160}
1161
Yani Ioannou050480f2005-06-05 10:51:46 +02001162#define temp_crit_enable(offset) \
1163static DEVICE_ATTR(temp##offset##_crit_enable, S_IRUGO | S_IWUSR, \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 show_temp_crit_enable, set_temp_crit_enable);
1165
Yani Ioannou050480f2005-06-05 10:51:46 +02001166temp_crit_enable(1);
1167temp_crit_enable(2);
1168temp_crit_enable(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Yani Ioannou050480f2005-06-05 10:51:46 +02001170static ssize_t show_temp_crit(struct device *dev,
1171 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Yani Ioannou050480f2005-06-05 10:51:46 +02001173 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1174 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 struct adm1026_data *data = adm1026_update_device(dev);
1176 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
1177}
Yani Ioannou050480f2005-06-05 10:51:46 +02001178static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
1179 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
Yani Ioannou050480f2005-06-05 10:51:46 +02001181 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1182 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 struct i2c_client *client = to_i2c_client(dev);
1184 struct adm1026_data *data = i2c_get_clientdata(client);
1185 int val = simple_strtol(buf, NULL, 10);
1186
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001187 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 data->temp_crit[nr] = TEMP_TO_REG(val);
1189 adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
1190 data->temp_crit[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001191 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 return count;
1193}
1194
Yani Ioannou050480f2005-06-05 10:51:46 +02001195#define temp_crit_reg(offset) \
1196static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
1197 show_temp_crit, set_temp_crit, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
1199temp_crit_reg(1);
1200temp_crit_reg(2);
1201temp_crit_reg(3);
1202
Yani Ioannou74880c02005-05-17 06:41:12 -04001203static ssize_t show_analog_out_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
1205 struct adm1026_data *data = adm1026_update_device(dev);
1206 return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
1207}
Yani Ioannou74880c02005-05-17 06:41:12 -04001208static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 size_t count)
1210{
1211 struct i2c_client *client = to_i2c_client(dev);
1212 struct adm1026_data *data = i2c_get_clientdata(client);
1213 int val = simple_strtol(buf, NULL, 10);
1214
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001215 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 data->analog_out = DAC_TO_REG(val);
1217 adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001218 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 return count;
1220}
1221
1222static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
1223 set_analog_out_reg);
1224
Yani Ioannou74880c02005-05-17 06:41:12 -04001225static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
1227 struct adm1026_data *data = adm1026_update_device(dev);
1228 return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
1229}
Grant Coady937df8d2005-05-12 11:59:29 +10001230static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Yani Ioannou74880c02005-05-17 06:41:12 -04001232static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
1234 struct adm1026_data *data = adm1026_update_device(dev);
1235 return sprintf(buf,"%d\n", data->vrm);
1236}
Yani Ioannou74880c02005-05-17 06:41:12 -04001237static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 size_t count)
1239{
1240 struct i2c_client *client = to_i2c_client(dev);
1241 struct adm1026_data *data = i2c_get_clientdata(client);
1242
1243 data->vrm = simple_strtol(buf, NULL, 10);
1244 return count;
1245}
1246
1247static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1248
Yani Ioannou74880c02005-05-17 06:41:12 -04001249static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
1251 struct adm1026_data *data = adm1026_update_device(dev);
1252 return sprintf(buf, "%ld\n", (long) (data->alarms));
1253}
1254
1255static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
1256
Yani Ioannou74880c02005-05-17 06:41:12 -04001257static ssize_t show_alarm_mask(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
1259 struct adm1026_data *data = adm1026_update_device(dev);
1260 return sprintf(buf,"%ld\n", data->alarm_mask);
1261}
Yani Ioannou74880c02005-05-17 06:41:12 -04001262static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 size_t count)
1264{
1265 struct i2c_client *client = to_i2c_client(dev);
1266 struct adm1026_data *data = i2c_get_clientdata(client);
1267 int val = simple_strtol(buf, NULL, 10);
1268 unsigned long mask;
1269
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001270 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 data->alarm_mask = val & 0x7fffffff;
1272 mask = data->alarm_mask
1273 | (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
1274 adm1026_write_value(client, ADM1026_REG_MASK1,
1275 mask & 0xff);
1276 mask >>= 8;
1277 adm1026_write_value(client, ADM1026_REG_MASK2,
1278 mask & 0xff);
1279 mask >>= 8;
1280 adm1026_write_value(client, ADM1026_REG_MASK3,
1281 mask & 0xff);
1282 mask >>= 8;
1283 adm1026_write_value(client, ADM1026_REG_MASK4,
1284 mask & 0xff);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001285 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 return count;
1287}
1288
1289static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
1290 set_alarm_mask);
1291
1292
Yani Ioannou74880c02005-05-17 06:41:12 -04001293static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294{
1295 struct adm1026_data *data = adm1026_update_device(dev);
1296 return sprintf(buf,"%ld\n", data->gpio);
1297}
Yani Ioannou74880c02005-05-17 06:41:12 -04001298static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 size_t count)
1300{
1301 struct i2c_client *client = to_i2c_client(dev);
1302 struct adm1026_data *data = i2c_get_clientdata(client);
1303 int val = simple_strtol(buf, NULL, 10);
1304 long gpio;
1305
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001306 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 data->gpio = val & 0x1ffff;
1308 gpio = data->gpio;
1309 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
1310 gpio >>= 8;
1311 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
1312 gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
1313 adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001314 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 return count;
1316}
1317
1318static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
1319
1320
Yani Ioannou74880c02005-05-17 06:41:12 -04001321static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
1323 struct adm1026_data *data = adm1026_update_device(dev);
1324 return sprintf(buf,"%ld\n", data->gpio_mask);
1325}
Yani Ioannou74880c02005-05-17 06:41:12 -04001326static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 size_t count)
1328{
1329 struct i2c_client *client = to_i2c_client(dev);
1330 struct adm1026_data *data = i2c_get_clientdata(client);
1331 int val = simple_strtol(buf, NULL, 10);
1332 long mask;
1333
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001334 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 data->gpio_mask = val & 0x1ffff;
1336 mask = data->gpio_mask;
1337 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
1338 mask >>= 8;
1339 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
1340 mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
1341 adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001342 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 return count;
1344}
1345
1346static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
1347
Yani Ioannou74880c02005-05-17 06:41:12 -04001348static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
1350 struct adm1026_data *data = adm1026_update_device(dev);
1351 return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
1352}
Yani Ioannou74880c02005-05-17 06:41:12 -04001353static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 size_t count)
1355{
1356 struct i2c_client *client = to_i2c_client(dev);
1357 struct adm1026_data *data = i2c_get_clientdata(client);
1358
1359 if (data->pwm1.enable == 1) {
1360 int val = simple_strtol(buf, NULL, 10);
1361
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001362 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 data->pwm1.pwm = PWM_TO_REG(val);
1364 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001365 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 }
1367 return count;
1368}
Yani Ioannou74880c02005-05-17 06:41:12 -04001369static ssize_t show_auto_pwm_min(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370{
1371 struct adm1026_data *data = adm1026_update_device(dev);
1372 return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
1373}
Yani Ioannou74880c02005-05-17 06:41:12 -04001374static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 size_t count)
1376{
1377 struct i2c_client *client = to_i2c_client(dev);
1378 struct adm1026_data *data = i2c_get_clientdata(client);
1379 int val = simple_strtol(buf, NULL, 10);
1380
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001381 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
1383 if (data->pwm1.enable == 2) { /* apply immediately */
1384 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1385 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1386 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1387 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001388 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 return count;
1390}
Yani Ioannou74880c02005-05-17 06:41:12 -04001391static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
1393 return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
1394}
Yani Ioannou74880c02005-05-17 06:41:12 -04001395static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396{
1397 struct adm1026_data *data = adm1026_update_device(dev);
1398 return sprintf(buf,"%d\n", data->pwm1.enable);
1399}
Yani Ioannou74880c02005-05-17 06:41:12 -04001400static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 size_t count)
1402{
1403 struct i2c_client *client = to_i2c_client(dev);
1404 struct adm1026_data *data = i2c_get_clientdata(client);
1405 int val = simple_strtol(buf, NULL, 10);
1406 int old_enable;
1407
1408 if ((val >= 0) && (val < 3)) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001409 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 old_enable = data->pwm1.enable;
1411 data->pwm1.enable = val;
1412 data->config1 = (data->config1 & ~CFG1_PWM_AFC)
1413 | ((val == 2) ? CFG1_PWM_AFC : 0);
1414 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1415 data->config1);
1416 if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
1417 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1418 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1419 adm1026_write_value(client, ADM1026_REG_PWM,
1420 data->pwm1.pwm);
1421 } else if (!((old_enable == 1) && (val == 1))) {
1422 /* set pwm to safe value */
1423 data->pwm1.pwm = 255;
1424 adm1026_write_value(client, ADM1026_REG_PWM,
1425 data->pwm1.pwm);
1426 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001427 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 }
1429 return count;
1430}
1431
1432/* enable PWM fan control */
1433static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1434static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1435static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1436static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1437 set_pwm_enable);
1438static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1439 set_pwm_enable);
1440static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1441 set_pwm_enable);
1442static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1443 show_auto_pwm_min, set_auto_pwm_min);
1444static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1445 show_auto_pwm_min, set_auto_pwm_min);
1446static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1447 show_auto_pwm_min, set_auto_pwm_min);
1448
1449static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1450static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1451static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1452
Ben Dooksc49efce2005-10-26 21:07:25 +02001453static int adm1026_detect(struct i2c_adapter *adapter, int address,
1454 int kind)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
1456 int company, verstep;
1457 struct i2c_client *new_client;
1458 struct adm1026_data *data;
1459 int err = 0;
1460 const char *type_name = "";
1461
1462 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1463 /* We need to be able to do byte I/O */
1464 goto exit;
1465 };
1466
1467 /* OK. For now, we presume we have a valid client. We now create the
1468 client structure, even though we cannot fill it completely yet.
1469 But it allows us to access adm1026_{read,write}_value. */
1470
Deepak Saxenaba9c2e82005-10-17 23:08:32 +02001471 if (!(data = kzalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 err = -ENOMEM;
1473 goto exit;
1474 }
1475
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 new_client = &data->client;
1477 i2c_set_clientdata(new_client, data);
1478 new_client->addr = address;
1479 new_client->adapter = adapter;
1480 new_client->driver = &adm1026_driver;
1481 new_client->flags = 0;
1482
1483 /* Now, we do the remaining detection. */
1484
1485 company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
1486 verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
1487
1488 dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
1489 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1490 i2c_adapter_id(new_client->adapter), new_client->addr,
1491 company, verstep);
1492
1493 /* If auto-detecting, Determine the chip type. */
1494 if (kind <= 0) {
1495 dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
1496 "...\n", i2c_adapter_id(adapter), address);
1497 if (company == ADM1026_COMPANY_ANALOG_DEV
1498 && verstep == ADM1026_VERSTEP_ADM1026) {
1499 kind = adm1026;
1500 } else if (company == ADM1026_COMPANY_ANALOG_DEV
1501 && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1502 dev_err(&adapter->dev, ": Unrecognized stepping "
1503 "0x%02x. Defaulting to ADM1026.\n", verstep);
1504 kind = adm1026;
1505 } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1506 dev_err(&adapter->dev, ": Found version/stepping "
1507 "0x%02x. Assuming generic ADM1026.\n",
1508 verstep);
1509 kind = any_chip;
1510 } else {
1511 dev_dbg(&new_client->dev, ": Autodetection "
1512 "failed\n");
1513 /* Not an ADM1026 ... */
1514 if (kind == 0) { /* User used force=x,y */
1515 dev_err(&adapter->dev, "Generic ADM1026 not "
1516 "found at %d,0x%02x. Try "
1517 "force_adm1026.\n",
1518 i2c_adapter_id(adapter), address);
1519 }
1520 err = 0;
1521 goto exitfree;
1522 }
1523 }
1524
1525 /* Fill in the chip specific driver values */
1526 switch (kind) {
1527 case any_chip :
1528 type_name = "adm1026";
1529 break;
1530 case adm1026 :
1531 type_name = "adm1026";
1532 break;
1533 default :
1534 dev_err(&adapter->dev, ": Internal error, invalid "
1535 "kind (%d)!", kind);
1536 err = -EFAULT;
1537 goto exitfree;
1538 }
1539 strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
1540
1541 /* Fill in the remaining client fields */
1542 data->type = kind;
1543 data->valid = 0;
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001544 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
1546 /* Tell the I2C layer a new client has arrived */
1547 if ((err = i2c_attach_client(new_client)))
1548 goto exitfree;
1549
1550 /* Set the VRM version */
Jean Delvare303760b2005-07-31 21:52:01 +02001551 data->vrm = vid_which_vrm();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
1553 /* Initialize the ADM1026 chip */
1554 adm1026_init_client(new_client);
1555
1556 /* Register sysfs hooks */
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001557 data->class_dev = hwmon_device_register(&new_client->dev);
1558 if (IS_ERR(data->class_dev)) {
1559 err = PTR_ERR(data->class_dev);
1560 goto exitdetach;
1561 }
1562
Yani Ioannou050480f2005-06-05 10:51:46 +02001563 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
1564 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
1565 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
1566 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
1567 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
1568 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
1569 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
1570 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
1571 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
1572 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
1573 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
1574 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
1575 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
1576 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
1577 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
1578 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
1579 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
1580 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
1581 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
1582 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
1583 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
1584 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
1585 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
1586 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
1587 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
1588 device_create_file(&new_client->dev, &sensor_dev_attr_in8_max.dev_attr);
1589 device_create_file(&new_client->dev, &sensor_dev_attr_in8_min.dev_attr);
1590 device_create_file(&new_client->dev, &sensor_dev_attr_in9_input.dev_attr);
1591 device_create_file(&new_client->dev, &sensor_dev_attr_in9_max.dev_attr);
1592 device_create_file(&new_client->dev, &sensor_dev_attr_in9_min.dev_attr);
1593 device_create_file(&new_client->dev, &sensor_dev_attr_in10_input.dev_attr);
1594 device_create_file(&new_client->dev, &sensor_dev_attr_in10_max.dev_attr);
1595 device_create_file(&new_client->dev, &sensor_dev_attr_in10_min.dev_attr);
1596 device_create_file(&new_client->dev, &sensor_dev_attr_in11_input.dev_attr);
1597 device_create_file(&new_client->dev, &sensor_dev_attr_in11_max.dev_attr);
1598 device_create_file(&new_client->dev, &sensor_dev_attr_in11_min.dev_attr);
1599 device_create_file(&new_client->dev, &sensor_dev_attr_in12_input.dev_attr);
1600 device_create_file(&new_client->dev, &sensor_dev_attr_in12_max.dev_attr);
1601 device_create_file(&new_client->dev, &sensor_dev_attr_in12_min.dev_attr);
1602 device_create_file(&new_client->dev, &sensor_dev_attr_in13_input.dev_attr);
1603 device_create_file(&new_client->dev, &sensor_dev_attr_in13_max.dev_attr);
1604 device_create_file(&new_client->dev, &sensor_dev_attr_in13_min.dev_attr);
1605 device_create_file(&new_client->dev, &sensor_dev_attr_in14_input.dev_attr);
1606 device_create_file(&new_client->dev, &sensor_dev_attr_in14_max.dev_attr);
1607 device_create_file(&new_client->dev, &sensor_dev_attr_in14_min.dev_attr);
1608 device_create_file(&new_client->dev, &sensor_dev_attr_in15_input.dev_attr);
1609 device_create_file(&new_client->dev, &sensor_dev_attr_in15_max.dev_attr);
1610 device_create_file(&new_client->dev, &sensor_dev_attr_in15_min.dev_attr);
1611 device_create_file(&new_client->dev, &sensor_dev_attr_in16_input.dev_attr);
1612 device_create_file(&new_client->dev, &sensor_dev_attr_in16_max.dev_attr);
1613 device_create_file(&new_client->dev, &sensor_dev_attr_in16_min.dev_attr);
1614 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr);
1615 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr);
1616 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr);
1617 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr);
1618 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr);
1619 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr);
1620 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr);
1621 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr);
1622 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr);
1623 device_create_file(&new_client->dev, &sensor_dev_attr_fan4_input.dev_attr);
1624 device_create_file(&new_client->dev, &sensor_dev_attr_fan4_div.dev_attr);
1625 device_create_file(&new_client->dev, &sensor_dev_attr_fan4_min.dev_attr);
1626 device_create_file(&new_client->dev, &sensor_dev_attr_fan5_input.dev_attr);
1627 device_create_file(&new_client->dev, &sensor_dev_attr_fan5_div.dev_attr);
1628 device_create_file(&new_client->dev, &sensor_dev_attr_fan5_min.dev_attr);
1629 device_create_file(&new_client->dev, &sensor_dev_attr_fan6_input.dev_attr);
1630 device_create_file(&new_client->dev, &sensor_dev_attr_fan6_div.dev_attr);
1631 device_create_file(&new_client->dev, &sensor_dev_attr_fan6_min.dev_attr);
1632 device_create_file(&new_client->dev, &sensor_dev_attr_fan7_input.dev_attr);
1633 device_create_file(&new_client->dev, &sensor_dev_attr_fan7_div.dev_attr);
1634 device_create_file(&new_client->dev, &sensor_dev_attr_fan7_min.dev_attr);
1635 device_create_file(&new_client->dev, &sensor_dev_attr_fan8_input.dev_attr);
1636 device_create_file(&new_client->dev, &sensor_dev_attr_fan8_div.dev_attr);
1637 device_create_file(&new_client->dev, &sensor_dev_attr_fan8_min.dev_attr);
1638 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
1639 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
1640 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
1641 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
1642 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
1643 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
1644 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
1645 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
1646 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
1647 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_offset.dev_attr);
1648 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_offset.dev_attr);
1649 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_offset.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 device_create_file(&new_client->dev,
Yani Ioannou050480f2005-06-05 10:51:46 +02001651 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 device_create_file(&new_client->dev,
Yani Ioannou050480f2005-06-05 10:51:46 +02001653 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 device_create_file(&new_client->dev,
Yani Ioannou050480f2005-06-05 10:51:46 +02001655 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 device_create_file(&new_client->dev,
Yani Ioannou050480f2005-06-05 10:51:46 +02001657 &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 device_create_file(&new_client->dev,
Yani Ioannou050480f2005-06-05 10:51:46 +02001659 &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 device_create_file(&new_client->dev,
Yani Ioannou050480f2005-06-05 10:51:46 +02001661 &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 device_create_file(&new_client->dev,
Yani Ioannou050480f2005-06-05 10:51:46 +02001663 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 device_create_file(&new_client->dev,
Yani Ioannou050480f2005-06-05 10:51:46 +02001665 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 device_create_file(&new_client->dev,
Yani Ioannou050480f2005-06-05 10:51:46 +02001667 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr);
1668 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_crit.dev_attr);
1669 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_crit.dev_attr);
1670 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_crit.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
1672 device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
1673 device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
Grant Coady937df8d2005-05-12 11:59:29 +10001674 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 device_create_file(&new_client->dev, &dev_attr_vrm);
1676 device_create_file(&new_client->dev, &dev_attr_alarms);
1677 device_create_file(&new_client->dev, &dev_attr_alarm_mask);
1678 device_create_file(&new_client->dev, &dev_attr_gpio);
1679 device_create_file(&new_client->dev, &dev_attr_gpio_mask);
1680 device_create_file(&new_client->dev, &dev_attr_pwm1);
1681 device_create_file(&new_client->dev, &dev_attr_pwm2);
1682 device_create_file(&new_client->dev, &dev_attr_pwm3);
1683 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
1684 device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
1685 device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
1686 device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
1687 device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
1688 device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
1689 device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
1690 device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
1691 device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
1692 device_create_file(&new_client->dev, &dev_attr_analog_out);
1693 return 0;
1694
1695 /* Error out and cleanup code */
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001696exitdetach:
1697 i2c_detach_client(new_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698exitfree:
Alexey Dobriyan1f57ff82005-08-26 01:49:14 +04001699 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700exit:
1701 return err;
1702}
1703static int __init sm_adm1026_init(void)
1704{
1705 return i2c_add_driver(&adm1026_driver);
1706}
1707
1708static void __exit sm_adm1026_exit(void)
1709{
1710 i2c_del_driver(&adm1026_driver);
1711}
1712
1713MODULE_LICENSE("GPL");
1714MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1715 "Justin Thiessen <jthiessen@penguincomputing.com>");
1716MODULE_DESCRIPTION("ADM1026 driver");
1717
1718module_init(sm_adm1026_init);
1719module_exit(sm_adm1026_exit);