blob: b4618b2705f76ae1805ab5dd5f24c2c76833d241 [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_read_value(struct i2c_client *client, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
328 int res;
329
330 if (reg < 0x80) {
331 /* "RAM" locations */
332 res = i2c_smbus_read_byte_data(client, reg) & 0xff;
333 } else {
334 /* EEPROM, do nothing */
335 res = 0;
336 }
337 return res;
338}
339
Ben Dooksc49efce2005-10-26 21:07:25 +0200340static int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
342 int res;
343
344 if (reg < 0x80) {
345 /* "RAM" locations */
346 res = i2c_smbus_write_byte_data(client, reg, value);
347 } else {
348 /* EEPROM, do nothing */
349 res = 0;
350 }
351 return res;
352}
353
Ben Dooksc49efce2005-10-26 21:07:25 +0200354static void adm1026_init_client(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
356 int value, i;
357 struct adm1026_data *data = i2c_get_clientdata(client);
358
359 dev_dbg(&client->dev, "Initializing device\n");
360 /* Read chip config */
361 data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
362 data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
363 data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
364
365 /* Inform user of chip config */
366 dev_dbg(&client->dev, "ADM1026_REG_CONFIG1 is: 0x%02x\n",
367 data->config1);
368 if ((data->config1 & CFG1_MONITOR) == 0) {
369 dev_dbg(&client->dev, "Monitoring not currently "
370 "enabled.\n");
371 }
372 if (data->config1 & CFG1_INT_ENABLE) {
373 dev_dbg(&client->dev, "SMBALERT interrupts are "
374 "enabled.\n");
375 }
376 if (data->config1 & CFG1_AIN8_9) {
377 dev_dbg(&client->dev, "in8 and in9 enabled. "
378 "temp3 disabled.\n");
379 } else {
380 dev_dbg(&client->dev, "temp3 enabled. in8 and "
381 "in9 disabled.\n");
382 }
383 if (data->config1 & CFG1_THERM_HOT) {
384 dev_dbg(&client->dev, "Automatic THERM, PWM, "
385 "and temp limits enabled.\n");
386 }
387
388 value = data->config3;
389 if (data->config3 & CFG3_GPIO16_ENABLE) {
Jean Delvare368609c2005-07-29 12:15:07 -0700390 dev_dbg(&client->dev, "GPIO16 enabled. THERM "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 "pin disabled.\n");
392 } else {
393 dev_dbg(&client->dev, "THERM pin enabled. "
394 "GPIO16 disabled.\n");
395 }
396 if (data->config3 & CFG3_VREF_250) {
397 dev_dbg(&client->dev, "Vref is 2.50 Volts.\n");
398 } else {
399 dev_dbg(&client->dev, "Vref is 1.82 Volts.\n");
400 }
401 /* Read and pick apart the existing GPIO configuration */
402 value = 0;
403 for (i = 0;i <= 15;++i) {
404 if ((i & 0x03) == 0) {
405 value = adm1026_read_value(client,
406 ADM1026_REG_GPIO_CFG_0_3 + i/4);
407 }
408 data->gpio_config[i] = value & 0x03;
409 value >>= 2;
410 }
411 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
412
413 /* ... and then print it */
414 adm1026_print_gpio(client);
415
416 /* If the user asks us to reprogram the GPIO config, then
417 * do it now.
418 */
419 if (gpio_input[0] != -1 || gpio_output[0] != -1
420 || gpio_inverted[0] != -1 || gpio_normal[0] != -1
421 || gpio_fan[0] != -1) {
422 adm1026_fixup_gpio(client);
423 }
424
425 /* WE INTENTIONALLY make no changes to the limits,
426 * offsets, pwms, fans and zones. If they were
427 * configured, we don't want to mess with them.
428 * If they weren't, the default is 100% PWM, no
429 * control and will suffice until 'sensors -s'
430 * can be run by the user. We DO set the default
431 * value for pwm1.auto_pwm_min to its maximum
432 * so that enabling automatic pwm fan control
433 * without first setting a value for pwm1.auto_pwm_min
434 * will not result in potentially dangerous fan speed decrease.
435 */
436 data->pwm1.auto_pwm_min=255;
437 /* Start monitoring */
438 value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
439 /* Set MONITOR, clear interrupt acknowledge and s/w reset */
440 value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
441 dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
442 data->config1 = value;
443 adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
444
445 /* initialize fan_div[] to hardware defaults */
446 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) |
447 (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8);
448 for (i = 0;i <= 7;++i) {
449 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
450 value >>= 2;
451 }
452}
453
Ben Dooksc49efce2005-10-26 21:07:25 +0200454static void adm1026_print_gpio(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 struct adm1026_data *data = i2c_get_clientdata(client);
457 int i;
458
459 dev_dbg(&client->dev, "GPIO config is:");
460 for (i = 0;i <= 7;++i) {
461 if (data->config2 & (1 << i)) {
462 dev_dbg(&client->dev, "\t%sGP%s%d\n",
463 data->gpio_config[i] & 0x02 ? "" : "!",
464 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
465 i);
466 } else {
467 dev_dbg(&client->dev, "\tFAN%d\n", i);
468 }
469 }
470 for (i = 8;i <= 15;++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 }
476 if (data->config3 & CFG3_GPIO16_ENABLE) {
477 dev_dbg(&client->dev, "\t%sGP%s16\n",
478 data->gpio_config[16] & 0x02 ? "" : "!",
479 data->gpio_config[16] & 0x01 ? "OUT" : "IN");
480 } else {
481 /* GPIO16 is THERM */
482 dev_dbg(&client->dev, "\tTHERM\n");
483 }
484}
485
Ben Dooksc49efce2005-10-26 21:07:25 +0200486static void adm1026_fixup_gpio(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
488 struct adm1026_data *data = i2c_get_clientdata(client);
489 int i;
490 int value;
491
492 /* Make the changes requested. */
493 /* We may need to unlock/stop monitoring or soft-reset the
494 * chip before we can make changes. This hasn't been
495 * tested much. FIXME
496 */
497
498 /* Make outputs */
499 for (i = 0;i <= 16;++i) {
500 if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
501 data->gpio_config[gpio_output[i]] |= 0x01;
502 }
503 /* if GPIO0-7 is output, it isn't a FAN tach */
504 if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
505 data->config2 |= 1 << gpio_output[i];
506 }
507 }
508
509 /* Input overrides output */
510 for (i = 0;i <= 16;++i) {
511 if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
512 data->gpio_config[gpio_input[i]] &= ~ 0x01;
513 }
514 /* if GPIO0-7 is input, it isn't a FAN tach */
515 if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
516 data->config2 |= 1 << gpio_input[i];
517 }
518 }
519
520 /* Inverted */
521 for (i = 0;i <= 16;++i) {
522 if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
523 data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
524 }
525 }
526
527 /* Normal overrides inverted */
528 for (i = 0;i <= 16;++i) {
529 if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
530 data->gpio_config[gpio_normal[i]] |= 0x02;
531 }
532 }
533
534 /* Fan overrides input and output */
535 for (i = 0;i <= 7;++i) {
536 if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
537 data->config2 &= ~(1 << gpio_fan[i]);
538 }
539 }
540
541 /* Write new configs to registers */
542 adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
543 data->config3 = (data->config3 & 0x3f)
544 | ((data->gpio_config[16] & 0x03) << 6);
545 adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
546 for (i = 15, value = 0;i >= 0;--i) {
547 value <<= 2;
548 value |= data->gpio_config[i] & 0x03;
549 if ((i & 0x03) == 0) {
550 adm1026_write_value(client,
551 ADM1026_REG_GPIO_CFG_0_3 + i/4,
552 value);
553 value = 0;
554 }
555 }
556
557 /* Print the new config */
558 adm1026_print_gpio(client);
559}
560
561
562static struct adm1026_data *adm1026_update_device(struct device *dev)
563{
564 struct i2c_client *client = to_i2c_client(dev);
565 struct adm1026_data *data = i2c_get_clientdata(client);
566 int i;
567 long value, alarms, gpio;
568
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100569 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 if (!data->valid
571 || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) {
572 /* Things that change quickly */
573 dev_dbg(&client->dev,"Reading sensor values\n");
574 for (i = 0;i <= 16;++i) {
575 data->in[i] =
576 adm1026_read_value(client, ADM1026_REG_IN[i]);
577 }
578
579 for (i = 0;i <= 7;++i) {
580 data->fan[i] =
581 adm1026_read_value(client, ADM1026_REG_FAN(i));
582 }
583
584 for (i = 0;i <= 2;++i) {
585 /* NOTE: temp[] is s8 and we assume 2's complement
586 * "conversion" in the assignment */
587 data->temp[i] =
588 adm1026_read_value(client, ADM1026_REG_TEMP[i]);
589 }
590
591 data->pwm1.pwm = adm1026_read_value(client,
592 ADM1026_REG_PWM);
593 data->analog_out = adm1026_read_value(client,
594 ADM1026_REG_DAC);
595 /* GPIO16 is MSbit of alarms, move it to gpio */
596 alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
597 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
598 alarms &= 0x7f;
599 alarms <<= 8;
600 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
601 alarms <<= 8;
602 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
603 alarms <<= 8;
604 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
605 data->alarms = alarms;
606
607 /* Read the GPIO values */
608 gpio |= adm1026_read_value(client,
609 ADM1026_REG_GPIO_STATUS_8_15);
610 gpio <<= 8;
611 gpio |= adm1026_read_value(client,
612 ADM1026_REG_GPIO_STATUS_0_7);
613 data->gpio = gpio;
614
615 data->last_reading = jiffies;
616 }; /* last_reading */
617
618 if (!data->valid ||
619 time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) {
620 /* Things that don't change often */
621 dev_dbg(&client->dev, "Reading config values\n");
622 for (i = 0;i <= 16;++i) {
623 data->in_min[i] = adm1026_read_value(client,
624 ADM1026_REG_IN_MIN[i]);
625 data->in_max[i] = adm1026_read_value(client,
626 ADM1026_REG_IN_MAX[i]);
627 }
628
629 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
630 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
631 << 8);
632 for (i = 0;i <= 7;++i) {
633 data->fan_min[i] = adm1026_read_value(client,
634 ADM1026_REG_FAN_MIN(i));
635 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
636 value >>= 2;
637 }
638
639 for (i = 0; i <= 2; ++i) {
640 /* NOTE: temp_xxx[] are s8 and we assume 2's
641 * complement "conversion" in the assignment
642 */
643 data->temp_min[i] = adm1026_read_value(client,
644 ADM1026_REG_TEMP_MIN[i]);
645 data->temp_max[i] = adm1026_read_value(client,
646 ADM1026_REG_TEMP_MAX[i]);
647 data->temp_tmin[i] = adm1026_read_value(client,
648 ADM1026_REG_TEMP_TMIN[i]);
649 data->temp_crit[i] = adm1026_read_value(client,
650 ADM1026_REG_TEMP_THERM[i]);
651 data->temp_offset[i] = adm1026_read_value(client,
652 ADM1026_REG_TEMP_OFFSET[i]);
653 }
654
655 /* Read the STATUS/alarm masks */
656 alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
657 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
658 alarms = (alarms & 0x7f) << 8;
659 alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
660 alarms <<= 8;
661 alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
662 alarms <<= 8;
663 alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
664 data->alarm_mask = alarms;
665
666 /* Read the GPIO values */
667 gpio |= adm1026_read_value(client,
668 ADM1026_REG_GPIO_MASK_8_15);
669 gpio <<= 8;
670 gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
671 data->gpio_mask = gpio;
672
673 /* Read various values from CONFIG1 */
674 data->config1 = adm1026_read_value(client,
675 ADM1026_REG_CONFIG1);
676 if (data->config1 & CFG1_PWM_AFC) {
677 data->pwm1.enable = 2;
678 data->pwm1.auto_pwm_min =
679 PWM_MIN_FROM_REG(data->pwm1.pwm);
680 }
681 /* Read the GPIO config */
682 data->config2 = adm1026_read_value(client,
683 ADM1026_REG_CONFIG2);
684 data->config3 = adm1026_read_value(client,
685 ADM1026_REG_CONFIG3);
686 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
687
688 value = 0;
689 for (i = 0;i <= 15;++i) {
690 if ((i & 0x03) == 0) {
691 value = adm1026_read_value(client,
692 ADM1026_REG_GPIO_CFG_0_3 + i/4);
693 }
694 data->gpio_config[i] = value & 0x03;
695 value >>= 2;
696 }
697
698 data->last_config = jiffies;
699 }; /* last_config */
700
701 dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n");
702 data->vid = (data->gpio >> 11) & 0x1f;
703 data->valid = 1;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100704 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 return data;
706}
707
Yani Ioannou050480f2005-06-05 10:51:46 +0200708static ssize_t show_in(struct device *dev, struct device_attribute *attr,
709 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Yani Ioannou050480f2005-06-05 10:51:46 +0200711 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
712 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 struct adm1026_data *data = adm1026_update_device(dev);
714 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
715}
Yani Ioannou050480f2005-06-05 10:51:46 +0200716static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
717 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718{
Yani Ioannou050480f2005-06-05 10:51:46 +0200719 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
720 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 struct adm1026_data *data = adm1026_update_device(dev);
722 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
723}
Yani Ioannou050480f2005-06-05 10:51:46 +0200724static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
725 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
Yani Ioannou050480f2005-06-05 10:51:46 +0200727 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
728 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 struct i2c_client *client = to_i2c_client(dev);
730 struct adm1026_data *data = i2c_get_clientdata(client);
731 int val = simple_strtol(buf, NULL, 10);
732
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100733 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 data->in_min[nr] = INS_TO_REG(nr, val);
735 adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100736 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 return count;
738}
Yani Ioannou050480f2005-06-05 10:51:46 +0200739static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
740 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741{
Yani Ioannou050480f2005-06-05 10:51:46 +0200742 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
743 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 struct adm1026_data *data = adm1026_update_device(dev);
745 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
746}
Yani Ioannou050480f2005-06-05 10:51:46 +0200747static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
748 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
Yani Ioannou050480f2005-06-05 10:51:46 +0200750 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
751 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 struct i2c_client *client = to_i2c_client(dev);
753 struct adm1026_data *data = i2c_get_clientdata(client);
754 int val = simple_strtol(buf, NULL, 10);
755
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100756 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 data->in_max[nr] = INS_TO_REG(nr, val);
758 adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100759 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 return count;
761}
762
Yani Ioannou050480f2005-06-05 10:51:46 +0200763#define in_reg(offset) \
764static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in, \
765 NULL, offset); \
766static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
767 show_in_min, set_in_min, offset); \
768static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
769 show_in_max, set_in_max, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771
772in_reg(0);
773in_reg(1);
774in_reg(2);
775in_reg(3);
776in_reg(4);
777in_reg(5);
778in_reg(6);
779in_reg(7);
780in_reg(8);
781in_reg(9);
782in_reg(10);
783in_reg(11);
784in_reg(12);
785in_reg(13);
786in_reg(14);
787in_reg(15);
788
Yani Ioannou74880c02005-05-17 06:41:12 -0400789static ssize_t show_in16(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
791 struct adm1026_data *data = adm1026_update_device(dev);
792 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
793 NEG12_OFFSET);
794}
Yani Ioannou74880c02005-05-17 06:41:12 -0400795static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796{
797 struct adm1026_data *data = adm1026_update_device(dev);
798 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
799 - NEG12_OFFSET);
800}
Yani Ioannou74880c02005-05-17 06:41:12 -0400801static 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 -0700802{
803 struct i2c_client *client = to_i2c_client(dev);
804 struct adm1026_data *data = i2c_get_clientdata(client);
805 int val = simple_strtol(buf, NULL, 10);
806
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100807 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
809 adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100810 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 return count;
812}
Yani Ioannou74880c02005-05-17 06:41:12 -0400813static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
815 struct adm1026_data *data = adm1026_update_device(dev);
816 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
817 - NEG12_OFFSET);
818}
Yani Ioannou74880c02005-05-17 06:41:12 -0400819static 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 -0700820{
821 struct i2c_client *client = to_i2c_client(dev);
822 struct adm1026_data *data = i2c_get_clientdata(client);
823 int val = simple_strtol(buf, NULL, 10);
824
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100825 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
827 adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100828 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 return count;
830}
831
Yani Ioannou050480f2005-06-05 10:51:46 +0200832static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL, 16);
833static SENSOR_DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min, 16);
834static SENSOR_DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836
837
838
839/* Now add fan read/write functions */
840
Yani Ioannou050480f2005-06-05 10:51:46 +0200841static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
842 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Yani Ioannou050480f2005-06-05 10:51:46 +0200844 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
845 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 struct adm1026_data *data = adm1026_update_device(dev);
847 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
848 data->fan_div[nr]));
849}
Yani Ioannou050480f2005-06-05 10:51:46 +0200850static ssize_t show_fan_min(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_min[nr],
857 data->fan_div[nr]));
858}
Yani Ioannou050480f2005-06-05 10:51:46 +0200859static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
860 const char *buf, size_t count)
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 i2c_client *client = to_i2c_client(dev);
865 struct adm1026_data *data = i2c_get_clientdata(client);
866 int val = simple_strtol(buf, NULL, 10);
867
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100868 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
870 adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
871 data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100872 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 return count;
874}
875
Yani Ioannou050480f2005-06-05 10:51:46 +0200876#define fan_offset(offset) \
877static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL, \
878 offset - 1); \
879static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
880 show_fan_min, set_fan_min, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882fan_offset(1);
883fan_offset(2);
884fan_offset(3);
885fan_offset(4);
886fan_offset(5);
887fan_offset(6);
888fan_offset(7);
889fan_offset(8);
890
891/* Adjust fan_min to account for new fan divisor */
892static void fixup_fan_min(struct device *dev, int fan, int old_div)
893{
894 struct i2c_client *client = to_i2c_client(dev);
895 struct adm1026_data *data = i2c_get_clientdata(client);
896 int new_min;
897 int new_div = data->fan_div[fan];
898
899 /* 0 and 0xff are special. Don't adjust them */
900 if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
901 return;
902 }
903
904 new_min = data->fan_min[fan] * old_div / new_div;
905 new_min = SENSORS_LIMIT(new_min, 1, 254);
906 data->fan_min[fan] = new_min;
907 adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
908}
909
910/* Now add fan_div read/write functions */
Yani Ioannou050480f2005-06-05 10:51:46 +0200911static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
912 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913{
Yani Ioannou050480f2005-06-05 10:51:46 +0200914 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
915 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 struct adm1026_data *data = adm1026_update_device(dev);
917 return sprintf(buf,"%d\n", data->fan_div[nr]);
918}
Yani Ioannou050480f2005-06-05 10:51:46 +0200919static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
920 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
Yani Ioannou050480f2005-06-05 10:51:46 +0200922 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
923 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 struct i2c_client *client = to_i2c_client(dev);
925 struct adm1026_data *data = i2c_get_clientdata(client);
926 int val,orig_div,new_div,shift;
927
928 val = simple_strtol(buf, NULL, 10);
929 new_div = DIV_TO_REG(val);
930 if (new_div == 0) {
931 return -EINVAL;
932 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100933 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 orig_div = data->fan_div[nr];
935 data->fan_div[nr] = DIV_FROM_REG(new_div);
936
937 if (nr < 4) { /* 0 <= nr < 4 */
938 shift = 2 * nr;
939 adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
940 ((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
941 (new_div << shift)));
942 } else { /* 3 < nr < 8 */
943 shift = 2 * (nr - 4);
944 adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
945 ((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
946 (new_div << shift)));
947 }
948
949 if (data->fan_div[nr] != orig_div) {
950 fixup_fan_min(dev,nr,orig_div);
951 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100952 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 return count;
954}
955
956#define fan_offset_div(offset) \
Yani Ioannou050480f2005-06-05 10:51:46 +0200957static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
958 show_fan_div, set_fan_div, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960fan_offset_div(1);
961fan_offset_div(2);
962fan_offset_div(3);
963fan_offset_div(4);
964fan_offset_div(5);
965fan_offset_div(6);
966fan_offset_div(7);
967fan_offset_div(8);
968
969/* Temps */
Yani Ioannou050480f2005-06-05 10:51:46 +0200970static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
971 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Yani Ioannou050480f2005-06-05 10:51:46 +0200973 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
974 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 struct adm1026_data *data = adm1026_update_device(dev);
976 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
977}
Yani Ioannou050480f2005-06-05 10:51:46 +0200978static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
979 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980{
Yani Ioannou050480f2005-06-05 10:51:46 +0200981 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
982 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 struct adm1026_data *data = adm1026_update_device(dev);
984 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
985}
Yani Ioannou050480f2005-06-05 10:51:46 +0200986static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
987 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
Yani Ioannou050480f2005-06-05 10:51:46 +0200989 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
990 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 struct i2c_client *client = to_i2c_client(dev);
992 struct adm1026_data *data = i2c_get_clientdata(client);
993 int val = simple_strtol(buf, NULL, 10);
994
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100995 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 data->temp_min[nr] = TEMP_TO_REG(val);
997 adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
998 data->temp_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100999 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 return count;
1001}
Yani Ioannou050480f2005-06-05 10:51:46 +02001002static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
1003 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Yani Ioannou050480f2005-06-05 10:51:46 +02001005 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1006 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 struct adm1026_data *data = adm1026_update_device(dev);
1008 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
1009}
Yani Ioannou050480f2005-06-05 10:51:46 +02001010static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
1011 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
Yani Ioannou050480f2005-06-05 10:51:46 +02001013 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1014 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 struct i2c_client *client = to_i2c_client(dev);
1016 struct adm1026_data *data = i2c_get_clientdata(client);
1017 int val = simple_strtol(buf, NULL, 10);
1018
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001019 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 data->temp_max[nr] = TEMP_TO_REG(val);
1021 adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
1022 data->temp_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001023 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 return count;
1025}
Yani Ioannou050480f2005-06-05 10:51:46 +02001026
1027#define temp_reg(offset) \
1028static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \
1029 NULL, offset - 1); \
1030static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
1031 show_temp_min, set_temp_min, offset - 1); \
1032static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
1033 show_temp_max, set_temp_max, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
1035
1036temp_reg(1);
1037temp_reg(2);
1038temp_reg(3);
1039
Yani Ioannou050480f2005-06-05 10:51:46 +02001040static ssize_t show_temp_offset(struct device *dev,
1041 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042{
Yani Ioannou050480f2005-06-05 10:51:46 +02001043 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1044 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 struct adm1026_data *data = adm1026_update_device(dev);
1046 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
1047}
Yani Ioannou050480f2005-06-05 10:51:46 +02001048static ssize_t set_temp_offset(struct device *dev,
1049 struct device_attribute *attr, const char *buf,
1050 size_t count)
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 i2c_client *client = to_i2c_client(dev);
1055 struct adm1026_data *data = i2c_get_clientdata(client);
1056 int val = simple_strtol(buf, NULL, 10);
1057
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001058 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 data->temp_offset[nr] = TEMP_TO_REG(val);
1060 adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
1061 data->temp_offset[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001062 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 return count;
1064}
1065
Yani Ioannou050480f2005-06-05 10:51:46 +02001066#define temp_offset_reg(offset) \
1067static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
1068 show_temp_offset, set_temp_offset, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070temp_offset_reg(1);
1071temp_offset_reg(2);
1072temp_offset_reg(3);
1073
Yani Ioannou050480f2005-06-05 10:51:46 +02001074static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev,
1075 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
Yani Ioannou050480f2005-06-05 10:51:46 +02001077 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1078 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 struct adm1026_data *data = adm1026_update_device(dev);
1080 return sprintf(buf,"%d\n", TEMP_FROM_REG(
1081 ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
1082}
Yani Ioannou050480f2005-06-05 10:51:46 +02001083static ssize_t show_temp_auto_point2_temp(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(data->temp_tmin[nr] +
1090 ADM1026_FAN_CONTROL_TEMP_RANGE));
1091}
Yani Ioannou050480f2005-06-05 10:51:46 +02001092static ssize_t show_temp_auto_point1_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}
Yani Ioannou050480f2005-06-05 10:51:46 +02001100static ssize_t set_temp_auto_point1_temp(struct device *dev,
1101 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
Yani Ioannou050480f2005-06-05 10:51:46 +02001103 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1104 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 struct i2c_client *client = to_i2c_client(dev);
1106 struct adm1026_data *data = i2c_get_clientdata(client);
1107 int val = simple_strtol(buf, NULL, 10);
1108
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001109 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 data->temp_tmin[nr] = TEMP_TO_REG(val);
1111 adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
1112 data->temp_tmin[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001113 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 return count;
1115}
1116
Yani Ioannou050480f2005-06-05 10:51:46 +02001117#define temp_auto_point(offset) \
1118static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
1119 show_temp_auto_point1_temp, set_temp_auto_point1_temp, \
1120 offset - 1); \
1121static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
1122 show_temp_auto_point1_temp_hyst, NULL, offset - 1); \
1123static SENSOR_DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
1124 show_temp_auto_point2_temp, NULL, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
1126temp_auto_point(1);
1127temp_auto_point(2);
1128temp_auto_point(3);
1129
Yani Ioannou050480f2005-06-05 10:51:46 +02001130static ssize_t show_temp_crit_enable(struct device *dev,
1131 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
1133 struct adm1026_data *data = adm1026_update_device(dev);
1134 return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
1135}
Yani Ioannou050480f2005-06-05 10:51:46 +02001136static ssize_t set_temp_crit_enable(struct device *dev,
1137 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138{
1139 struct i2c_client *client = to_i2c_client(dev);
1140 struct adm1026_data *data = i2c_get_clientdata(client);
1141 int val = simple_strtol(buf, NULL, 10);
1142
1143 if ((val == 1) || (val==0)) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001144 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
1146 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1147 data->config1);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001148 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 }
1150 return count;
1151}
1152
Yani Ioannou050480f2005-06-05 10:51:46 +02001153#define temp_crit_enable(offset) \
1154static DEVICE_ATTR(temp##offset##_crit_enable, S_IRUGO | S_IWUSR, \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 show_temp_crit_enable, set_temp_crit_enable);
1156
Yani Ioannou050480f2005-06-05 10:51:46 +02001157temp_crit_enable(1);
1158temp_crit_enable(2);
1159temp_crit_enable(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Yani Ioannou050480f2005-06-05 10:51:46 +02001161static ssize_t show_temp_crit(struct device *dev,
1162 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Yani Ioannou050480f2005-06-05 10:51:46 +02001164 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1165 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 struct adm1026_data *data = adm1026_update_device(dev);
1167 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
1168}
Yani Ioannou050480f2005-06-05 10:51:46 +02001169static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
1170 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
Yani Ioannou050480f2005-06-05 10:51:46 +02001172 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1173 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 struct i2c_client *client = to_i2c_client(dev);
1175 struct adm1026_data *data = i2c_get_clientdata(client);
1176 int val = simple_strtol(buf, NULL, 10);
1177
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001178 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 data->temp_crit[nr] = TEMP_TO_REG(val);
1180 adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
1181 data->temp_crit[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001182 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 return count;
1184}
1185
Yani Ioannou050480f2005-06-05 10:51:46 +02001186#define temp_crit_reg(offset) \
1187static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
1188 show_temp_crit, set_temp_crit, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190temp_crit_reg(1);
1191temp_crit_reg(2);
1192temp_crit_reg(3);
1193
Yani Ioannou74880c02005-05-17 06:41:12 -04001194static ssize_t show_analog_out_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195{
1196 struct adm1026_data *data = adm1026_update_device(dev);
1197 return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
1198}
Yani Ioannou74880c02005-05-17 06:41:12 -04001199static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 size_t count)
1201{
1202 struct i2c_client *client = to_i2c_client(dev);
1203 struct adm1026_data *data = i2c_get_clientdata(client);
1204 int val = simple_strtol(buf, NULL, 10);
1205
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001206 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 data->analog_out = DAC_TO_REG(val);
1208 adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001209 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 return count;
1211}
1212
1213static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
1214 set_analog_out_reg);
1215
Yani Ioannou74880c02005-05-17 06:41:12 -04001216static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217{
1218 struct adm1026_data *data = adm1026_update_device(dev);
1219 return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
1220}
Grant Coady937df8d2005-05-12 11:59:29 +10001221static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
Yani Ioannou74880c02005-05-17 06:41:12 -04001223static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
1225 struct adm1026_data *data = adm1026_update_device(dev);
1226 return sprintf(buf,"%d\n", data->vrm);
1227}
Yani Ioannou74880c02005-05-17 06:41:12 -04001228static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 size_t count)
1230{
1231 struct i2c_client *client = to_i2c_client(dev);
1232 struct adm1026_data *data = i2c_get_clientdata(client);
1233
1234 data->vrm = simple_strtol(buf, NULL, 10);
1235 return count;
1236}
1237
1238static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1239
Yani Ioannou74880c02005-05-17 06:41:12 -04001240static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
1242 struct adm1026_data *data = adm1026_update_device(dev);
1243 return sprintf(buf, "%ld\n", (long) (data->alarms));
1244}
1245
1246static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
1247
Yani Ioannou74880c02005-05-17 06:41:12 -04001248static ssize_t show_alarm_mask(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
1250 struct adm1026_data *data = adm1026_update_device(dev);
1251 return sprintf(buf,"%ld\n", data->alarm_mask);
1252}
Yani Ioannou74880c02005-05-17 06:41:12 -04001253static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 size_t count)
1255{
1256 struct i2c_client *client = to_i2c_client(dev);
1257 struct adm1026_data *data = i2c_get_clientdata(client);
1258 int val = simple_strtol(buf, NULL, 10);
1259 unsigned long mask;
1260
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001261 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 data->alarm_mask = val & 0x7fffffff;
1263 mask = data->alarm_mask
1264 | (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
1265 adm1026_write_value(client, ADM1026_REG_MASK1,
1266 mask & 0xff);
1267 mask >>= 8;
1268 adm1026_write_value(client, ADM1026_REG_MASK2,
1269 mask & 0xff);
1270 mask >>= 8;
1271 adm1026_write_value(client, ADM1026_REG_MASK3,
1272 mask & 0xff);
1273 mask >>= 8;
1274 adm1026_write_value(client, ADM1026_REG_MASK4,
1275 mask & 0xff);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001276 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 return count;
1278}
1279
1280static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
1281 set_alarm_mask);
1282
1283
Yani Ioannou74880c02005-05-17 06:41:12 -04001284static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285{
1286 struct adm1026_data *data = adm1026_update_device(dev);
1287 return sprintf(buf,"%ld\n", data->gpio);
1288}
Yani Ioannou74880c02005-05-17 06:41:12 -04001289static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 size_t count)
1291{
1292 struct i2c_client *client = to_i2c_client(dev);
1293 struct adm1026_data *data = i2c_get_clientdata(client);
1294 int val = simple_strtol(buf, NULL, 10);
1295 long gpio;
1296
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001297 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 data->gpio = val & 0x1ffff;
1299 gpio = data->gpio;
1300 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
1301 gpio >>= 8;
1302 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
1303 gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
1304 adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001305 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 return count;
1307}
1308
1309static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
1310
1311
Yani Ioannou74880c02005-05-17 06:41:12 -04001312static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
1314 struct adm1026_data *data = adm1026_update_device(dev);
1315 return sprintf(buf,"%ld\n", data->gpio_mask);
1316}
Yani Ioannou74880c02005-05-17 06:41:12 -04001317static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 size_t count)
1319{
1320 struct i2c_client *client = to_i2c_client(dev);
1321 struct adm1026_data *data = i2c_get_clientdata(client);
1322 int val = simple_strtol(buf, NULL, 10);
1323 long mask;
1324
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001325 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 data->gpio_mask = val & 0x1ffff;
1327 mask = data->gpio_mask;
1328 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
1329 mask >>= 8;
1330 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
1331 mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
1332 adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001333 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 return count;
1335}
1336
1337static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
1338
Yani Ioannou74880c02005-05-17 06:41:12 -04001339static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
1341 struct adm1026_data *data = adm1026_update_device(dev);
1342 return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
1343}
Yani Ioannou74880c02005-05-17 06:41:12 -04001344static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 size_t count)
1346{
1347 struct i2c_client *client = to_i2c_client(dev);
1348 struct adm1026_data *data = i2c_get_clientdata(client);
1349
1350 if (data->pwm1.enable == 1) {
1351 int val = simple_strtol(buf, NULL, 10);
1352
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001353 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 data->pwm1.pwm = PWM_TO_REG(val);
1355 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001356 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 }
1358 return count;
1359}
Yani Ioannou74880c02005-05-17 06:41:12 -04001360static ssize_t show_auto_pwm_min(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
1362 struct adm1026_data *data = adm1026_update_device(dev);
1363 return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
1364}
Yani Ioannou74880c02005-05-17 06:41:12 -04001365static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 size_t count)
1367{
1368 struct i2c_client *client = to_i2c_client(dev);
1369 struct adm1026_data *data = i2c_get_clientdata(client);
1370 int val = simple_strtol(buf, NULL, 10);
1371
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001372 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
1374 if (data->pwm1.enable == 2) { /* apply immediately */
1375 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1376 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1377 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1378 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001379 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 return count;
1381}
Yani Ioannou74880c02005-05-17 06:41:12 -04001382static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
1384 return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
1385}
Yani Ioannou74880c02005-05-17 06:41:12 -04001386static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
1388 struct adm1026_data *data = adm1026_update_device(dev);
1389 return sprintf(buf,"%d\n", data->pwm1.enable);
1390}
Yani Ioannou74880c02005-05-17 06:41:12 -04001391static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 size_t count)
1393{
1394 struct i2c_client *client = to_i2c_client(dev);
1395 struct adm1026_data *data = i2c_get_clientdata(client);
1396 int val = simple_strtol(buf, NULL, 10);
1397 int old_enable;
1398
1399 if ((val >= 0) && (val < 3)) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001400 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 old_enable = data->pwm1.enable;
1402 data->pwm1.enable = val;
1403 data->config1 = (data->config1 & ~CFG1_PWM_AFC)
1404 | ((val == 2) ? CFG1_PWM_AFC : 0);
1405 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1406 data->config1);
1407 if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
1408 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1409 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1410 adm1026_write_value(client, ADM1026_REG_PWM,
1411 data->pwm1.pwm);
1412 } else if (!((old_enable == 1) && (val == 1))) {
1413 /* set pwm to safe value */
1414 data->pwm1.pwm = 255;
1415 adm1026_write_value(client, ADM1026_REG_PWM,
1416 data->pwm1.pwm);
1417 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001418 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 }
1420 return count;
1421}
1422
1423/* enable PWM fan control */
1424static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1425static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1426static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1427static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1428 set_pwm_enable);
1429static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1430 set_pwm_enable);
1431static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1432 set_pwm_enable);
1433static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1434 show_auto_pwm_min, set_auto_pwm_min);
1435static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1436 show_auto_pwm_min, set_auto_pwm_min);
1437static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1438 show_auto_pwm_min, set_auto_pwm_min);
1439
1440static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1441static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1442static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1443
Mark M. Hoffman681c6f72006-09-24 21:15:35 +02001444static struct attribute *adm1026_attributes[] = {
1445 &sensor_dev_attr_in0_input.dev_attr.attr,
1446 &sensor_dev_attr_in0_max.dev_attr.attr,
1447 &sensor_dev_attr_in0_min.dev_attr.attr,
1448 &sensor_dev_attr_in1_input.dev_attr.attr,
1449 &sensor_dev_attr_in1_max.dev_attr.attr,
1450 &sensor_dev_attr_in1_min.dev_attr.attr,
1451 &sensor_dev_attr_in2_input.dev_attr.attr,
1452 &sensor_dev_attr_in2_max.dev_attr.attr,
1453 &sensor_dev_attr_in2_min.dev_attr.attr,
1454 &sensor_dev_attr_in3_input.dev_attr.attr,
1455 &sensor_dev_attr_in3_max.dev_attr.attr,
1456 &sensor_dev_attr_in3_min.dev_attr.attr,
1457 &sensor_dev_attr_in4_input.dev_attr.attr,
1458 &sensor_dev_attr_in4_max.dev_attr.attr,
1459 &sensor_dev_attr_in4_min.dev_attr.attr,
1460 &sensor_dev_attr_in5_input.dev_attr.attr,
1461 &sensor_dev_attr_in5_max.dev_attr.attr,
1462 &sensor_dev_attr_in5_min.dev_attr.attr,
1463 &sensor_dev_attr_in6_input.dev_attr.attr,
1464 &sensor_dev_attr_in6_max.dev_attr.attr,
1465 &sensor_dev_attr_in6_min.dev_attr.attr,
1466 &sensor_dev_attr_in7_input.dev_attr.attr,
1467 &sensor_dev_attr_in7_max.dev_attr.attr,
1468 &sensor_dev_attr_in7_min.dev_attr.attr,
1469 &sensor_dev_attr_in8_input.dev_attr.attr,
1470 &sensor_dev_attr_in8_max.dev_attr.attr,
1471 &sensor_dev_attr_in8_min.dev_attr.attr,
1472 &sensor_dev_attr_in9_input.dev_attr.attr,
1473 &sensor_dev_attr_in9_max.dev_attr.attr,
1474 &sensor_dev_attr_in9_min.dev_attr.attr,
1475 &sensor_dev_attr_in10_input.dev_attr.attr,
1476 &sensor_dev_attr_in10_max.dev_attr.attr,
1477 &sensor_dev_attr_in10_min.dev_attr.attr,
1478 &sensor_dev_attr_in11_input.dev_attr.attr,
1479 &sensor_dev_attr_in11_max.dev_attr.attr,
1480 &sensor_dev_attr_in11_min.dev_attr.attr,
1481 &sensor_dev_attr_in12_input.dev_attr.attr,
1482 &sensor_dev_attr_in12_max.dev_attr.attr,
1483 &sensor_dev_attr_in12_min.dev_attr.attr,
1484 &sensor_dev_attr_in13_input.dev_attr.attr,
1485 &sensor_dev_attr_in13_max.dev_attr.attr,
1486 &sensor_dev_attr_in13_min.dev_attr.attr,
1487 &sensor_dev_attr_in14_input.dev_attr.attr,
1488 &sensor_dev_attr_in14_max.dev_attr.attr,
1489 &sensor_dev_attr_in14_min.dev_attr.attr,
1490 &sensor_dev_attr_in15_input.dev_attr.attr,
1491 &sensor_dev_attr_in15_max.dev_attr.attr,
1492 &sensor_dev_attr_in15_min.dev_attr.attr,
1493 &sensor_dev_attr_in16_input.dev_attr.attr,
1494 &sensor_dev_attr_in16_max.dev_attr.attr,
1495 &sensor_dev_attr_in16_min.dev_attr.attr,
1496 &sensor_dev_attr_fan1_input.dev_attr.attr,
1497 &sensor_dev_attr_fan1_div.dev_attr.attr,
1498 &sensor_dev_attr_fan1_min.dev_attr.attr,
1499 &sensor_dev_attr_fan2_input.dev_attr.attr,
1500 &sensor_dev_attr_fan2_div.dev_attr.attr,
1501 &sensor_dev_attr_fan2_min.dev_attr.attr,
1502 &sensor_dev_attr_fan3_input.dev_attr.attr,
1503 &sensor_dev_attr_fan3_div.dev_attr.attr,
1504 &sensor_dev_attr_fan3_min.dev_attr.attr,
1505 &sensor_dev_attr_fan4_input.dev_attr.attr,
1506 &sensor_dev_attr_fan4_div.dev_attr.attr,
1507 &sensor_dev_attr_fan4_min.dev_attr.attr,
1508 &sensor_dev_attr_fan5_input.dev_attr.attr,
1509 &sensor_dev_attr_fan5_div.dev_attr.attr,
1510 &sensor_dev_attr_fan5_min.dev_attr.attr,
1511 &sensor_dev_attr_fan6_input.dev_attr.attr,
1512 &sensor_dev_attr_fan6_div.dev_attr.attr,
1513 &sensor_dev_attr_fan6_min.dev_attr.attr,
1514 &sensor_dev_attr_fan7_input.dev_attr.attr,
1515 &sensor_dev_attr_fan7_div.dev_attr.attr,
1516 &sensor_dev_attr_fan7_min.dev_attr.attr,
1517 &sensor_dev_attr_fan8_input.dev_attr.attr,
1518 &sensor_dev_attr_fan8_div.dev_attr.attr,
1519 &sensor_dev_attr_fan8_min.dev_attr.attr,
1520 &sensor_dev_attr_temp1_input.dev_attr.attr,
1521 &sensor_dev_attr_temp1_max.dev_attr.attr,
1522 &sensor_dev_attr_temp1_min.dev_attr.attr,
1523 &sensor_dev_attr_temp2_input.dev_attr.attr,
1524 &sensor_dev_attr_temp2_max.dev_attr.attr,
1525 &sensor_dev_attr_temp2_min.dev_attr.attr,
1526 &sensor_dev_attr_temp3_input.dev_attr.attr,
1527 &sensor_dev_attr_temp3_max.dev_attr.attr,
1528 &sensor_dev_attr_temp3_min.dev_attr.attr,
1529 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1530 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1531 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1532 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
1533 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
1534 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
1535 &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr,
1536 &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr.attr,
1537 &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
1538 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
1539 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
1540 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
1541 &sensor_dev_attr_temp1_crit.dev_attr.attr,
1542 &sensor_dev_attr_temp2_crit.dev_attr.attr,
1543 &sensor_dev_attr_temp3_crit.dev_attr.attr,
1544 &dev_attr_temp1_crit_enable.attr,
1545 &dev_attr_temp2_crit_enable.attr,
1546 &dev_attr_temp3_crit_enable.attr,
1547 &dev_attr_cpu0_vid.attr,
1548 &dev_attr_vrm.attr,
1549 &dev_attr_alarms.attr,
1550 &dev_attr_alarm_mask.attr,
1551 &dev_attr_gpio.attr,
1552 &dev_attr_gpio_mask.attr,
1553 &dev_attr_pwm1.attr,
1554 &dev_attr_pwm2.attr,
1555 &dev_attr_pwm3.attr,
1556 &dev_attr_pwm1_enable.attr,
1557 &dev_attr_pwm2_enable.attr,
1558 &dev_attr_pwm3_enable.attr,
1559 &dev_attr_temp1_auto_point1_pwm.attr,
1560 &dev_attr_temp2_auto_point1_pwm.attr,
1561 &dev_attr_temp3_auto_point1_pwm.attr,
1562 &dev_attr_temp1_auto_point2_pwm.attr,
1563 &dev_attr_temp2_auto_point2_pwm.attr,
1564 &dev_attr_temp3_auto_point2_pwm.attr,
1565 &dev_attr_analog_out.attr,
1566 NULL
1567};
1568
1569static const struct attribute_group adm1026_group = {
1570 .attrs = adm1026_attributes,
1571};
1572
Ben Dooksc49efce2005-10-26 21:07:25 +02001573static int adm1026_detect(struct i2c_adapter *adapter, int address,
1574 int kind)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
1576 int company, verstep;
1577 struct i2c_client *new_client;
1578 struct adm1026_data *data;
1579 int err = 0;
1580 const char *type_name = "";
1581
1582 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1583 /* We need to be able to do byte I/O */
1584 goto exit;
1585 };
1586
1587 /* OK. For now, we presume we have a valid client. We now create the
1588 client structure, even though we cannot fill it completely yet.
1589 But it allows us to access adm1026_{read,write}_value. */
1590
Deepak Saxenaba9c2e82005-10-17 23:08:32 +02001591 if (!(data = kzalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 err = -ENOMEM;
1593 goto exit;
1594 }
1595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 new_client = &data->client;
1597 i2c_set_clientdata(new_client, data);
1598 new_client->addr = address;
1599 new_client->adapter = adapter;
1600 new_client->driver = &adm1026_driver;
1601 new_client->flags = 0;
1602
1603 /* Now, we do the remaining detection. */
1604
1605 company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
1606 verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
1607
1608 dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
1609 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1610 i2c_adapter_id(new_client->adapter), new_client->addr,
1611 company, verstep);
1612
1613 /* If auto-detecting, Determine the chip type. */
1614 if (kind <= 0) {
1615 dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
1616 "...\n", i2c_adapter_id(adapter), address);
1617 if (company == ADM1026_COMPANY_ANALOG_DEV
1618 && verstep == ADM1026_VERSTEP_ADM1026) {
1619 kind = adm1026;
1620 } else if (company == ADM1026_COMPANY_ANALOG_DEV
1621 && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1622 dev_err(&adapter->dev, ": Unrecognized stepping "
1623 "0x%02x. Defaulting to ADM1026.\n", verstep);
1624 kind = adm1026;
1625 } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1626 dev_err(&adapter->dev, ": Found version/stepping "
1627 "0x%02x. Assuming generic ADM1026.\n",
1628 verstep);
1629 kind = any_chip;
1630 } else {
1631 dev_dbg(&new_client->dev, ": Autodetection "
1632 "failed\n");
1633 /* Not an ADM1026 ... */
1634 if (kind == 0) { /* User used force=x,y */
1635 dev_err(&adapter->dev, "Generic ADM1026 not "
1636 "found at %d,0x%02x. Try "
1637 "force_adm1026.\n",
1638 i2c_adapter_id(adapter), address);
1639 }
1640 err = 0;
1641 goto exitfree;
1642 }
1643 }
1644
1645 /* Fill in the chip specific driver values */
1646 switch (kind) {
1647 case any_chip :
1648 type_name = "adm1026";
1649 break;
1650 case adm1026 :
1651 type_name = "adm1026";
1652 break;
1653 default :
1654 dev_err(&adapter->dev, ": Internal error, invalid "
1655 "kind (%d)!", kind);
1656 err = -EFAULT;
1657 goto exitfree;
1658 }
1659 strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
1660
1661 /* Fill in the remaining client fields */
1662 data->type = kind;
1663 data->valid = 0;
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001664 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
1666 /* Tell the I2C layer a new client has arrived */
1667 if ((err = i2c_attach_client(new_client)))
1668 goto exitfree;
1669
1670 /* Set the VRM version */
Jean Delvare303760b2005-07-31 21:52:01 +02001671 data->vrm = vid_which_vrm();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 /* Initialize the ADM1026 chip */
1674 adm1026_init_client(new_client);
1675
1676 /* Register sysfs hooks */
Mark M. Hoffman681c6f72006-09-24 21:15:35 +02001677 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1026_group)))
1678 goto exitdetach;
1679
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001680 data->class_dev = hwmon_device_register(&new_client->dev);
1681 if (IS_ERR(data->class_dev)) {
1682 err = PTR_ERR(data->class_dev);
Mark M. Hoffman681c6f72006-09-24 21:15:35 +02001683 goto exitremove;
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001684 }
1685
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 return 0;
1687
1688 /* Error out and cleanup code */
Mark M. Hoffman681c6f72006-09-24 21:15:35 +02001689exitremove:
1690 sysfs_remove_group(&new_client->dev.kobj, &adm1026_group);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001691exitdetach:
1692 i2c_detach_client(new_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693exitfree:
Alexey Dobriyan1f57ff82005-08-26 01:49:14 +04001694 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695exit:
1696 return err;
1697}
Mark M. Hoffman681c6f72006-09-24 21:15:35 +02001698
1699static int adm1026_detach_client(struct i2c_client *client)
1700{
1701 struct adm1026_data *data = i2c_get_clientdata(client);
1702 hwmon_device_unregister(data->class_dev);
1703 sysfs_remove_group(&client->dev.kobj, &adm1026_group);
1704 i2c_detach_client(client);
1705 kfree(data);
1706 return 0;
1707}
1708
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709static int __init sm_adm1026_init(void)
1710{
1711 return i2c_add_driver(&adm1026_driver);
1712}
1713
1714static void __exit sm_adm1026_exit(void)
1715{
1716 i2c_del_driver(&adm1026_driver);
1717}
1718
1719MODULE_LICENSE("GPL");
1720MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1721 "Justin Thiessen <jthiessen@penguincomputing.com>");
1722MODULE_DESCRIPTION("ADM1026 driver");
1723
1724module_init(sm_adm1026_init);
1725module_exit(sm_adm1026_exit);