Merge branch 'akpm'
[linux-2.6/next.git] / drivers / hwmon / lm93.c
blob3b43df418613faf329abe451022126109aae15ae
1 /*
2 lm93.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
4 Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com>
5 Copyright (c) 2004 Utilitek Systems, Inc.
7 derived in part from lm78.c:
8 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
10 derived in part from lm85.c:
11 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
12 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
14 derived in part from w83l785ts.c:
15 Copyright (c) 2003-2004 Jean Delvare <khali@linux-fr.org>
17 Ported to Linux 2.6 by Eric J. Bowersox <ericb@aspsys.com>
18 Copyright (c) 2005 Aspen Systems, Inc.
20 Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org>
21 Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab
23 Modified for mainline integration by Hans J. Koch <hjk@hansjkoch.de>
24 Copyright (c) 2007 Hans J. Koch, Linutronix GmbH
26 This program is free software; you can redistribute it and/or modify
27 it under the terms of the GNU General Public License as published by
28 the Free Software Foundation; either version 2 of the License, or
29 (at your option) any later version.
31 This program is distributed in the hope that it will be useful,
32 but WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 GNU General Public License for more details.
36 You should have received a copy of the GNU General Public License
37 along with this program; if not, write to the Free Software
38 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41 #include <linux/module.h>
42 #include <linux/init.h>
43 #include <linux/slab.h>
44 #include <linux/i2c.h>
45 #include <linux/hwmon.h>
46 #include <linux/hwmon-sysfs.h>
47 #include <linux/hwmon-vid.h>
48 #include <linux/err.h>
49 #include <linux/delay.h>
51 /* LM93 REGISTER ADDRESSES */
53 /* miscellaneous */
54 #define LM93_REG_MFR_ID 0x3e
55 #define LM93_REG_VER 0x3f
56 #define LM93_REG_STATUS_CONTROL 0xe2
57 #define LM93_REG_CONFIG 0xe3
58 #define LM93_REG_SLEEP_CONTROL 0xe4
60 /* alarm values start here */
61 #define LM93_REG_HOST_ERROR_1 0x48
63 /* voltage inputs: in1-in16 (nr => 0-15) */
64 #define LM93_REG_IN(nr) (0x56 + (nr))
65 #define LM93_REG_IN_MIN(nr) (0x90 + (nr) * 2)
66 #define LM93_REG_IN_MAX(nr) (0x91 + (nr) * 2)
68 /* temperature inputs: temp1-temp4 (nr => 0-3) */
69 #define LM93_REG_TEMP(nr) (0x50 + (nr))
70 #define LM93_REG_TEMP_MIN(nr) (0x78 + (nr) * 2)
71 #define LM93_REG_TEMP_MAX(nr) (0x79 + (nr) * 2)
73 /* temp[1-4]_auto_boost (nr => 0-3) */
74 #define LM93_REG_BOOST(nr) (0x80 + (nr))
76 /* #PROCHOT inputs: prochot1-prochot2 (nr => 0-1) */
77 #define LM93_REG_PROCHOT_CUR(nr) (0x67 + (nr) * 2)
78 #define LM93_REG_PROCHOT_AVG(nr) (0x68 + (nr) * 2)
79 #define LM93_REG_PROCHOT_MAX(nr) (0xb0 + (nr))
81 /* fan tach inputs: fan1-fan4 (nr => 0-3) */
82 #define LM93_REG_FAN(nr) (0x6e + (nr) * 2)
83 #define LM93_REG_FAN_MIN(nr) (0xb4 + (nr) * 2)
85 /* pwm outputs: pwm1-pwm2 (nr => 0-1, reg => 0-3) */
86 #define LM93_REG_PWM_CTL(nr,reg) (0xc8 + (reg) + (nr) * 4)
87 #define LM93_PWM_CTL1 0x0
88 #define LM93_PWM_CTL2 0x1
89 #define LM93_PWM_CTL3 0x2
90 #define LM93_PWM_CTL4 0x3
92 /* GPIO input state */
93 #define LM93_REG_GPI 0x6b
95 /* vid inputs: vid1-vid2 (nr => 0-1) */
96 #define LM93_REG_VID(nr) (0x6c + (nr))
98 /* vccp1 & vccp2: VID relative inputs (nr => 0-1) */
99 #define LM93_REG_VCCP_LIMIT_OFF(nr) (0xb2 + (nr))
101 /* temp[1-4]_auto_boost_hyst */
102 #define LM93_REG_BOOST_HYST_12 0xc0
103 #define LM93_REG_BOOST_HYST_34 0xc1
104 #define LM93_REG_BOOST_HYST(nr) (0xc0 + (nr)/2)
106 /* temp[1-4]_auto_pwm_[min|hyst] */
107 #define LM93_REG_PWM_MIN_HYST_12 0xc3
108 #define LM93_REG_PWM_MIN_HYST_34 0xc4
109 #define LM93_REG_PWM_MIN_HYST(nr) (0xc3 + (nr)/2)
111 /* prochot_override & prochot_interval */
112 #define LM93_REG_PROCHOT_OVERRIDE 0xc6
113 #define LM93_REG_PROCHOT_INTERVAL 0xc7
115 /* temp[1-4]_auto_base (nr => 0-3) */
116 #define LM93_REG_TEMP_BASE(nr) (0xd0 + (nr))
118 /* temp[1-4]_auto_offsets (step => 0-11) */
119 #define LM93_REG_TEMP_OFFSET(step) (0xd4 + (step))
121 /* #PROCHOT & #VRDHOT PWM ramp control */
122 #define LM93_REG_PWM_RAMP_CTL 0xbf
124 /* miscellaneous */
125 #define LM93_REG_SFC1 0xbc
126 #define LM93_REG_SFC2 0xbd
127 #define LM93_REG_GPI_VID_CTL 0xbe
128 #define LM93_REG_SF_TACH_TO_PWM 0xe0
130 /* error masks */
131 #define LM93_REG_GPI_ERR_MASK 0xec
132 #define LM93_REG_MISC_ERR_MASK 0xed
134 /* LM93 REGISTER VALUES */
135 #define LM93_MFR_ID 0x73
136 #define LM93_MFR_ID_PROTOTYPE 0x72
138 /* LM94 REGISTER VALUES */
139 #define LM94_MFR_ID_2 0x7a
140 #define LM94_MFR_ID 0x79
141 #define LM94_MFR_ID_PROTOTYPE 0x78
143 /* SMBus capabilities */
144 #define LM93_SMBUS_FUNC_FULL (I2C_FUNC_SMBUS_BYTE_DATA | \
145 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA)
146 #define LM93_SMBUS_FUNC_MIN (I2C_FUNC_SMBUS_BYTE_DATA | \
147 I2C_FUNC_SMBUS_WORD_DATA)
149 /* Addresses to scan */
150 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
152 /* Insmod parameters */
154 static int disable_block;
155 module_param(disable_block, bool, 0);
156 MODULE_PARM_DESC(disable_block,
157 "Set to non-zero to disable SMBus block data transactions.");
159 static int init;
160 module_param(init, bool, 0);
161 MODULE_PARM_DESC(init, "Set to non-zero to force chip initialization.");
163 static int vccp_limit_type[2] = {0,0};
164 module_param_array(vccp_limit_type, int, NULL, 0);
165 MODULE_PARM_DESC(vccp_limit_type, "Configures in7 and in8 limit modes.");
167 static int vid_agtl;
168 module_param(vid_agtl, int, 0);
169 MODULE_PARM_DESC(vid_agtl, "Configures VID pin input thresholds.");
171 /* Driver data */
172 static struct i2c_driver lm93_driver;
174 /* LM93 BLOCK READ COMMANDS */
175 static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = {
176 { 0xf2, 8 },
177 { 0xf3, 8 },
178 { 0xf4, 6 },
179 { 0xf5, 16 },
180 { 0xf6, 4 },
181 { 0xf7, 8 },
182 { 0xf8, 12 },
183 { 0xf9, 32 },
184 { 0xfa, 8 },
185 { 0xfb, 8 },
186 { 0xfc, 16 },
187 { 0xfd, 9 },
190 /* ALARMS: SYSCTL format described further below
191 REG: 64 bits in 8 registers, as immediately below */
192 struct block1_t {
193 u8 host_status_1;
194 u8 host_status_2;
195 u8 host_status_3;
196 u8 host_status_4;
197 u8 p1_prochot_status;
198 u8 p2_prochot_status;
199 u8 gpi_status;
200 u8 fan_status;
204 * Client-specific data
206 struct lm93_data {
207 struct device *hwmon_dev;
209 struct mutex update_lock;
210 unsigned long last_updated; /* In jiffies */
212 /* client update function */
213 void (*update)(struct lm93_data *, struct i2c_client *);
215 char valid; /* !=0 if following fields are valid */
217 /* register values, arranged by block read groups */
218 struct block1_t block1;
220 /* temp1 - temp4: unfiltered readings
221 temp1 - temp2: filtered readings */
222 u8 block2[6];
224 /* vin1 - vin16: readings */
225 u8 block3[16];
227 /* prochot1 - prochot2: readings */
228 struct {
229 u8 cur;
230 u8 avg;
231 } block4[2];
233 /* fan counts 1-4 => 14-bits, LE, *left* justified */
234 u16 block5[4];
236 /* block6 has a lot of data we don't need */
237 struct {
238 u8 min;
239 u8 max;
240 } temp_lim[4];
242 /* vin1 - vin16: low and high limits */
243 struct {
244 u8 min;
245 u8 max;
246 } block7[16];
248 /* fan count limits 1-4 => same format as block5 */
249 u16 block8[4];
251 /* pwm control registers (2 pwms, 4 regs) */
252 u8 block9[2][4];
254 /* auto/pwm base temp and offset temp registers */
255 struct {
256 u8 base[4];
257 u8 offset[12];
258 } block10;
260 /* master config register */
261 u8 config;
263 /* VID1 & VID2 => register format, 6-bits, right justified */
264 u8 vid[2];
266 /* prochot1 - prochot2: limits */
267 u8 prochot_max[2];
269 /* vccp1 & vccp2 (in7 & in8): VID relative limits (register format) */
270 u8 vccp_limits[2];
272 /* GPIO input state (register format, i.e. inverted) */
273 u8 gpi;
275 /* #PROCHOT override (register format) */
276 u8 prochot_override;
278 /* #PROCHOT intervals (register format) */
279 u8 prochot_interval;
281 /* Fan Boost Temperatures (register format) */
282 u8 boost[4];
284 /* Fan Boost Hysteresis (register format) */
285 u8 boost_hyst[2];
287 /* Temperature Zone Min. PWM & Hysteresis (register format) */
288 u8 auto_pwm_min_hyst[2];
290 /* #PROCHOT & #VRDHOT PWM Ramp Control */
291 u8 pwm_ramp_ctl;
293 /* miscellaneous setup regs */
294 u8 sfc1;
295 u8 sfc2;
296 u8 sf_tach_to_pwm;
298 /* The two PWM CTL2 registers can read something other than what was
299 last written for the OVR_DC field (duty cycle override). So, we
300 save the user-commanded value here. */
301 u8 pwm_override[2];
304 /* VID: mV
305 REG: 6-bits, right justified, *always* using Intel VRM/VRD 10 */
306 static int LM93_VID_FROM_REG(u8 reg)
308 return vid_from_reg((reg & 0x3f), 100);
311 /* min, max, and nominal register values, per channel (u8) */
312 static const u8 lm93_vin_reg_min[16] = {
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae,
316 static const u8 lm93_vin_reg_max[16] = {
317 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
318 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1,
320 /* Values from the datasheet. They're here for documentation only.
321 static const u8 lm93_vin_reg_nom[16] = {
322 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
323 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0,
327 /* min, max, and nominal voltage readings, per channel (mV)*/
328 static const unsigned long lm93_vin_val_min[16] = {
329 0, 0, 0, 0, 0, 0, 0, 0,
330 0, 0, 0, 0, 0, 0, 0, 3000,
333 static const unsigned long lm93_vin_val_max[16] = {
334 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600,
335 4400, 6500, 3333, 2625, 1312, 1312, 1236, 3600,
337 /* Values from the datasheet. They're here for documentation only.
338 static const unsigned long lm93_vin_val_nom[16] = {
339 927, 927, 927, 1200, 1500, 1500, 1200, 1200,
340 3300, 5000, 2500, 1969, 984, 984, 309, 3300,
344 static unsigned LM93_IN_FROM_REG(int nr, u8 reg)
346 const long uV_max = lm93_vin_val_max[nr] * 1000;
347 const long uV_min = lm93_vin_val_min[nr] * 1000;
349 const long slope = (uV_max - uV_min) /
350 (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]);
351 const long intercept = uV_min - slope * lm93_vin_reg_min[nr];
353 return (slope * reg + intercept + 500) / 1000;
356 /* IN: mV, limits determined by channel nr
357 REG: scaling determined by channel nr */
358 static u8 LM93_IN_TO_REG(int nr, unsigned val)
360 /* range limit */
361 const long mV = SENSORS_LIMIT(val,
362 lm93_vin_val_min[nr], lm93_vin_val_max[nr]);
364 /* try not to lose too much precision here */
365 const long uV = mV * 1000;
366 const long uV_max = lm93_vin_val_max[nr] * 1000;
367 const long uV_min = lm93_vin_val_min[nr] * 1000;
369 /* convert */
370 const long slope = (uV_max - uV_min) /
371 (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]);
372 const long intercept = uV_min - slope * lm93_vin_reg_min[nr];
374 u8 result = ((uV - intercept + (slope/2)) / slope);
375 result = SENSORS_LIMIT(result,
376 lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]);
377 return result;
380 /* vid in mV, upper == 0 indicates low limit, otherwise upper limit */
381 static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid)
383 const long uV_offset = upper ? (((reg >> 4 & 0x0f) + 1) * 12500) :
384 (((reg >> 0 & 0x0f) + 1) * -25000);
385 const long uV_vid = vid * 1000;
386 return (uV_vid + uV_offset + 5000) / 10000;
389 #define LM93_IN_MIN_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,0,vid)
390 #define LM93_IN_MAX_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,1,vid)
392 /* vid in mV , upper == 0 indicates low limit, otherwise upper limit
393 upper also determines which nibble of the register is returned
394 (the other nibble will be 0x0) */
395 static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid)
397 long uV_offset = vid * 1000 - val * 10000;
398 if (upper) {
399 uV_offset = SENSORS_LIMIT(uV_offset, 12500, 200000);
400 return (u8)((uV_offset / 12500 - 1) << 4);
401 } else {
402 uV_offset = SENSORS_LIMIT(uV_offset, -400000, -25000);
403 return (u8)((uV_offset / -25000 - 1) << 0);
407 /* TEMP: 1/1000 degrees C (-128C to +127C)
408 REG: 1C/bit, two's complement */
409 static int LM93_TEMP_FROM_REG(u8 reg)
411 return (s8)reg * 1000;
414 #define LM93_TEMP_MIN (-128000)
415 #define LM93_TEMP_MAX ( 127000)
417 /* TEMP: 1/1000 degrees C (-128C to +127C)
418 REG: 1C/bit, two's complement */
419 static u8 LM93_TEMP_TO_REG(long temp)
421 int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX);
422 ntemp += (ntemp<0 ? -500 : 500);
423 return (u8)(ntemp / 1000);
426 /* Determine 4-bit temperature offset resolution */
427 static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr)
429 /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */
430 return sfc2 & (nr < 2 ? 0x10 : 0x20);
433 /* This function is common to all 4-bit temperature offsets
434 reg is 4 bits right justified
435 mode 0 => 1C/bit, mode !0 => 0.5C/bit */
436 static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode)
438 return (reg & 0x0f) * (mode ? 5 : 10);
441 #define LM93_TEMP_OFFSET_MIN ( 0)
442 #define LM93_TEMP_OFFSET_MAX0 (150)
443 #define LM93_TEMP_OFFSET_MAX1 ( 75)
445 /* This function is common to all 4-bit temperature offsets
446 returns 4 bits right justified
447 mode 0 => 1C/bit, mode !0 => 0.5C/bit */
448 static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode)
450 int factor = mode ? 5 : 10;
452 off = SENSORS_LIMIT(off, LM93_TEMP_OFFSET_MIN,
453 mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0);
454 return (u8)((off + factor/2) / factor);
457 /* 0 <= nr <= 3 */
458 static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode)
460 /* temp1-temp2 (nr=0,1) use lower nibble */
461 if (nr < 2)
462 return LM93_TEMP_OFFSET_FROM_REG(reg & 0x0f, mode);
464 /* temp3-temp4 (nr=2,3) use upper nibble */
465 else
466 return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode);
469 /* TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero))
470 REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero)
471 0 <= nr <= 3 */
472 static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode)
474 u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode);
476 /* temp1-temp2 (nr=0,1) use lower nibble */
477 if (nr < 2)
478 return (old & 0xf0) | (new & 0x0f);
480 /* temp3-temp4 (nr=2,3) use upper nibble */
481 else
482 return (new << 4 & 0xf0) | (old & 0x0f);
485 static int LM93_AUTO_BOOST_HYST_FROM_REGS(struct lm93_data *data, int nr,
486 int mode)
488 u8 reg;
490 switch (nr) {
491 case 0:
492 reg = data->boost_hyst[0] & 0x0f;
493 break;
494 case 1:
495 reg = data->boost_hyst[0] >> 4 & 0x0f;
496 break;
497 case 2:
498 reg = data->boost_hyst[1] & 0x0f;
499 break;
500 case 3:
501 default:
502 reg = data->boost_hyst[1] >> 4 & 0x0f;
503 break;
506 return LM93_TEMP_FROM_REG(data->boost[nr]) -
507 LM93_TEMP_OFFSET_FROM_REG(reg, mode);
510 static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst,
511 int nr, int mode)
513 u8 reg = LM93_TEMP_OFFSET_TO_REG(
514 (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode);
516 switch (nr) {
517 case 0:
518 reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f);
519 break;
520 case 1:
521 reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f);
522 break;
523 case 2:
524 reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f);
525 break;
526 case 3:
527 default:
528 reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f);
529 break;
532 return reg;
535 /* PWM: 0-255 per sensors documentation
536 REG: 0-13 as mapped below... right justified */
537 typedef enum { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ } pwm_freq_t;
538 static int lm93_pwm_map[2][16] = {
540 0x00, /* 0.00% */ 0x40, /* 25.00% */
541 0x50, /* 31.25% */ 0x60, /* 37.50% */
542 0x70, /* 43.75% */ 0x80, /* 50.00% */
543 0x90, /* 56.25% */ 0xa0, /* 62.50% */
544 0xb0, /* 68.75% */ 0xc0, /* 75.00% */
545 0xd0, /* 81.25% */ 0xe0, /* 87.50% */
546 0xf0, /* 93.75% */ 0xff, /* 100.00% */
547 0xff, 0xff, /* 14, 15 are reserved and should never occur */
550 0x00, /* 0.00% */ 0x40, /* 25.00% */
551 0x49, /* 28.57% */ 0x52, /* 32.14% */
552 0x5b, /* 35.71% */ 0x64, /* 39.29% */
553 0x6d, /* 42.86% */ 0x76, /* 46.43% */
554 0x80, /* 50.00% */ 0x89, /* 53.57% */
555 0x92, /* 57.14% */ 0xb6, /* 71.43% */
556 0xdb, /* 85.71% */ 0xff, /* 100.00% */
557 0xff, 0xff, /* 14, 15 are reserved and should never occur */
561 static int LM93_PWM_FROM_REG(u8 reg, pwm_freq_t freq)
563 return lm93_pwm_map[freq][reg & 0x0f];
566 /* round up to nearest match */
567 static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq)
569 int i;
570 for (i = 0; i < 13; i++)
571 if (pwm <= lm93_pwm_map[freq][i])
572 break;
574 /* can fall through with i==13 */
575 return (u8)i;
578 static int LM93_FAN_FROM_REG(u16 regs)
580 const u16 count = le16_to_cpu(regs) >> 2;
581 return count==0 ? -1 : count==0x3fff ? 0: 1350000 / count;
585 * RPM: (82.5 to 1350000)
586 * REG: 14-bits, LE, *left* justified
588 static u16 LM93_FAN_TO_REG(long rpm)
590 u16 count, regs;
592 if (rpm == 0) {
593 count = 0x3fff;
594 } else {
595 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
596 count = SENSORS_LIMIT((1350000 + rpm) / rpm, 1, 0x3ffe);
599 regs = count << 2;
600 return cpu_to_le16(regs);
603 /* PWM FREQ: HZ
604 REG: 0-7 as mapped below */
605 static int lm93_pwm_freq_map[8] = {
606 22500, 96, 84, 72, 60, 48, 36, 12
609 static int LM93_PWM_FREQ_FROM_REG(u8 reg)
611 return lm93_pwm_freq_map[reg & 0x07];
614 /* round up to nearest match */
615 static u8 LM93_PWM_FREQ_TO_REG(int freq)
617 int i;
618 for (i = 7; i > 0; i--)
619 if (freq <= lm93_pwm_freq_map[i])
620 break;
622 /* can fall through with i==0 */
623 return (u8)i;
626 /* TIME: 1/100 seconds
627 * REG: 0-7 as mapped below */
628 static int lm93_spinup_time_map[8] = {
629 0, 10, 25, 40, 70, 100, 200, 400,
632 static int LM93_SPINUP_TIME_FROM_REG(u8 reg)
634 return lm93_spinup_time_map[reg >> 5 & 0x07];
637 /* round up to nearest match */
638 static u8 LM93_SPINUP_TIME_TO_REG(int time)
640 int i;
641 for (i = 0; i < 7; i++)
642 if (time <= lm93_spinup_time_map[i])
643 break;
645 /* can fall through with i==8 */
646 return (u8)i;
649 #define LM93_RAMP_MIN 0
650 #define LM93_RAMP_MAX 75
652 static int LM93_RAMP_FROM_REG(u8 reg)
654 return (reg & 0x0f) * 5;
657 /* RAMP: 1/100 seconds
658 REG: 50mS/bit 4-bits right justified */
659 static u8 LM93_RAMP_TO_REG(int ramp)
661 ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX);
662 return (u8)((ramp + 2) / 5);
665 /* PROCHOT: 0-255, 0 => 0%, 255 => > 96.6%
666 * REG: (same) */
667 static u8 LM93_PROCHOT_TO_REG(long prochot)
669 prochot = SENSORS_LIMIT(prochot, 0, 255);
670 return (u8)prochot;
673 /* PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds)
674 * REG: 0-9 as mapped below */
675 static int lm93_interval_map[10] = {
676 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200,
679 static int LM93_INTERVAL_FROM_REG(u8 reg)
681 return lm93_interval_map[reg & 0x0f];
684 /* round up to nearest match */
685 static u8 LM93_INTERVAL_TO_REG(long interval)
687 int i;
688 for (i = 0; i < 9; i++)
689 if (interval <= lm93_interval_map[i])
690 break;
692 /* can fall through with i==9 */
693 return (u8)i;
696 /* GPIO: 0-255, GPIO0 is LSB
697 * REG: inverted */
698 static unsigned LM93_GPI_FROM_REG(u8 reg)
700 return ~reg & 0xff;
703 /* alarm bitmask definitions
704 The LM93 has nearly 64 bits of error status... I've pared that down to
705 what I think is a useful subset in order to fit it into 32 bits.
707 Especially note that the #VRD_HOT alarms are missing because we provide
708 that information as values in another sysfs file.
710 If libsensors is extended to support 64 bit values, this could be revisited.
712 #define LM93_ALARM_IN1 0x00000001
713 #define LM93_ALARM_IN2 0x00000002
714 #define LM93_ALARM_IN3 0x00000004
715 #define LM93_ALARM_IN4 0x00000008
716 #define LM93_ALARM_IN5 0x00000010
717 #define LM93_ALARM_IN6 0x00000020
718 #define LM93_ALARM_IN7 0x00000040
719 #define LM93_ALARM_IN8 0x00000080
720 #define LM93_ALARM_IN9 0x00000100
721 #define LM93_ALARM_IN10 0x00000200
722 #define LM93_ALARM_IN11 0x00000400
723 #define LM93_ALARM_IN12 0x00000800
724 #define LM93_ALARM_IN13 0x00001000
725 #define LM93_ALARM_IN14 0x00002000
726 #define LM93_ALARM_IN15 0x00004000
727 #define LM93_ALARM_IN16 0x00008000
728 #define LM93_ALARM_FAN1 0x00010000
729 #define LM93_ALARM_FAN2 0x00020000
730 #define LM93_ALARM_FAN3 0x00040000
731 #define LM93_ALARM_FAN4 0x00080000
732 #define LM93_ALARM_PH1_ERR 0x00100000
733 #define LM93_ALARM_PH2_ERR 0x00200000
734 #define LM93_ALARM_SCSI1_ERR 0x00400000
735 #define LM93_ALARM_SCSI2_ERR 0x00800000
736 #define LM93_ALARM_DVDDP1_ERR 0x01000000
737 #define LM93_ALARM_DVDDP2_ERR 0x02000000
738 #define LM93_ALARM_D1_ERR 0x04000000
739 #define LM93_ALARM_D2_ERR 0x08000000
740 #define LM93_ALARM_TEMP1 0x10000000
741 #define LM93_ALARM_TEMP2 0x20000000
742 #define LM93_ALARM_TEMP3 0x40000000
744 static unsigned LM93_ALARMS_FROM_REG(struct block1_t b1)
746 unsigned result;
747 result = b1.host_status_2 & 0x3f;
749 if (vccp_limit_type[0])
750 result |= (b1.host_status_4 & 0x10) << 2;
751 else
752 result |= b1.host_status_2 & 0x40;
754 if (vccp_limit_type[1])
755 result |= (b1.host_status_4 & 0x20) << 2;
756 else
757 result |= b1.host_status_2 & 0x80;
759 result |= b1.host_status_3 << 8;
760 result |= (b1.fan_status & 0x0f) << 16;
761 result |= (b1.p1_prochot_status & 0x80) << 13;
762 result |= (b1.p2_prochot_status & 0x80) << 14;
763 result |= (b1.host_status_4 & 0xfc) << 20;
764 result |= (b1.host_status_1 & 0x07) << 28;
765 return result;
768 #define MAX_RETRIES 5
770 static u8 lm93_read_byte(struct i2c_client *client, u8 reg)
772 int value, i;
774 /* retry in case of read errors */
775 for (i=1; i<=MAX_RETRIES; i++) {
776 if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) {
777 return value;
778 } else {
779 dev_warn(&client->dev,"lm93: read byte data failed, "
780 "address 0x%02x.\n", reg);
781 mdelay(i + 3);
786 /* <TODO> what to return in case of error? */
787 dev_err(&client->dev,"lm93: All read byte retries failed!!\n");
788 return 0;
791 static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value)
793 int result;
795 /* <TODO> how to handle write errors? */
796 result = i2c_smbus_write_byte_data(client, reg, value);
798 if (result < 0)
799 dev_warn(&client->dev,"lm93: write byte data failed, "
800 "0x%02x at address 0x%02x.\n", value, reg);
802 return result;
805 static u16 lm93_read_word(struct i2c_client *client, u8 reg)
807 int value, i;
809 /* retry in case of read errors */
810 for (i=1; i<=MAX_RETRIES; i++) {
811 if ((value = i2c_smbus_read_word_data(client, reg)) >= 0) {
812 return value;
813 } else {
814 dev_warn(&client->dev,"lm93: read word data failed, "
815 "address 0x%02x.\n", reg);
816 mdelay(i + 3);
821 /* <TODO> what to return in case of error? */
822 dev_err(&client->dev,"lm93: All read word retries failed!!\n");
823 return 0;
826 static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value)
828 int result;
830 /* <TODO> how to handle write errors? */
831 result = i2c_smbus_write_word_data(client, reg, value);
833 if (result < 0)
834 dev_warn(&client->dev,"lm93: write word data failed, "
835 "0x%04x at address 0x%02x.\n", value, reg);
837 return result;
840 static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX];
843 read block data into values, retry if not expected length
844 fbn => index to lm93_block_read_cmds table
845 (Fixed Block Number - section 14.5.2 of LM93 datasheet)
847 static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values)
849 int i, result=0;
851 for (i = 1; i <= MAX_RETRIES; i++) {
852 result = i2c_smbus_read_block_data(client,
853 lm93_block_read_cmds[fbn].cmd, lm93_block_buffer);
855 if (result == lm93_block_read_cmds[fbn].len) {
856 break;
857 } else {
858 dev_warn(&client->dev,"lm93: block read data failed, "
859 "command 0x%02x.\n",
860 lm93_block_read_cmds[fbn].cmd);
861 mdelay(i + 3);
865 if (result == lm93_block_read_cmds[fbn].len) {
866 memcpy(values,lm93_block_buffer,lm93_block_read_cmds[fbn].len);
867 } else {
868 /* <TODO> what to do in case of error? */
872 static struct lm93_data *lm93_update_device(struct device *dev)
874 struct i2c_client *client = to_i2c_client(dev);
875 struct lm93_data *data = i2c_get_clientdata(client);
876 const unsigned long interval = HZ + (HZ / 2);
878 mutex_lock(&data->update_lock);
880 if (time_after(jiffies, data->last_updated + interval) ||
881 !data->valid) {
883 data->update(data, client);
884 data->last_updated = jiffies;
885 data->valid = 1;
888 mutex_unlock(&data->update_lock);
889 return data;
892 /* update routine for data that has no corresponding SMBus block command */
893 static void lm93_update_client_common(struct lm93_data *data,
894 struct i2c_client *client)
896 int i;
897 u8 *ptr;
899 /* temp1 - temp4: limits */
900 for (i = 0; i < 4; i++) {
901 data->temp_lim[i].min =
902 lm93_read_byte(client, LM93_REG_TEMP_MIN(i));
903 data->temp_lim[i].max =
904 lm93_read_byte(client, LM93_REG_TEMP_MAX(i));
907 /* config register */
908 data->config = lm93_read_byte(client, LM93_REG_CONFIG);
910 /* vid1 - vid2: values */
911 for (i = 0; i < 2; i++)
912 data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i));
914 /* prochot1 - prochot2: limits */
915 for (i = 0; i < 2; i++)
916 data->prochot_max[i] = lm93_read_byte(client,
917 LM93_REG_PROCHOT_MAX(i));
919 /* vccp1 - vccp2: VID relative limits */
920 for (i = 0; i < 2; i++)
921 data->vccp_limits[i] = lm93_read_byte(client,
922 LM93_REG_VCCP_LIMIT_OFF(i));
924 /* GPIO input state */
925 data->gpi = lm93_read_byte(client, LM93_REG_GPI);
927 /* #PROCHOT override state */
928 data->prochot_override = lm93_read_byte(client,
929 LM93_REG_PROCHOT_OVERRIDE);
931 /* #PROCHOT intervals */
932 data->prochot_interval = lm93_read_byte(client,
933 LM93_REG_PROCHOT_INTERVAL);
935 /* Fan Boost Temperature registers */
936 for (i = 0; i < 4; i++)
937 data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i));
939 /* Fan Boost Temperature Hyst. registers */
940 data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12);
941 data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34);
943 /* Temperature Zone Min. PWM & Hysteresis registers */
944 data->auto_pwm_min_hyst[0] =
945 lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_12);
946 data->auto_pwm_min_hyst[1] =
947 lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_34);
949 /* #PROCHOT & #VRDHOT PWM Ramp Control register */
950 data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
952 /* misc setup registers */
953 data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1);
954 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
955 data->sf_tach_to_pwm = lm93_read_byte(client,
956 LM93_REG_SF_TACH_TO_PWM);
958 /* write back alarm values to clear */
959 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++)
960 lm93_write_byte(client, LM93_REG_HOST_ERROR_1 + i, *(ptr + i));
963 /* update routine which uses SMBus block data commands */
964 static void lm93_update_client_full(struct lm93_data *data,
965 struct i2c_client *client)
967 dev_dbg(&client->dev,"starting device update (block data enabled)\n");
969 /* in1 - in16: values & limits */
970 lm93_read_block(client, 3, (u8 *)(data->block3));
971 lm93_read_block(client, 7, (u8 *)(data->block7));
973 /* temp1 - temp4: values */
974 lm93_read_block(client, 2, (u8 *)(data->block2));
976 /* prochot1 - prochot2: values */
977 lm93_read_block(client, 4, (u8 *)(data->block4));
979 /* fan1 - fan4: values & limits */
980 lm93_read_block(client, 5, (u8 *)(data->block5));
981 lm93_read_block(client, 8, (u8 *)(data->block8));
983 /* pmw control registers */
984 lm93_read_block(client, 9, (u8 *)(data->block9));
986 /* alarm values */
987 lm93_read_block(client, 1, (u8 *)(&data->block1));
989 /* auto/pwm registers */
990 lm93_read_block(client, 10, (u8 *)(&data->block10));
992 lm93_update_client_common(data, client);
995 /* update routine which uses SMBus byte/word data commands only */
996 static void lm93_update_client_min(struct lm93_data *data,
997 struct i2c_client *client)
999 int i,j;
1000 u8 *ptr;
1002 dev_dbg(&client->dev,"starting device update (block data disabled)\n");
1004 /* in1 - in16: values & limits */
1005 for (i = 0; i < 16; i++) {
1006 data->block3[i] =
1007 lm93_read_byte(client, LM93_REG_IN(i));
1008 data->block7[i].min =
1009 lm93_read_byte(client, LM93_REG_IN_MIN(i));
1010 data->block7[i].max =
1011 lm93_read_byte(client, LM93_REG_IN_MAX(i));
1014 /* temp1 - temp4: values */
1015 for (i = 0; i < 4; i++) {
1016 data->block2[i] =
1017 lm93_read_byte(client, LM93_REG_TEMP(i));
1020 /* prochot1 - prochot2: values */
1021 for (i = 0; i < 2; i++) {
1022 data->block4[i].cur =
1023 lm93_read_byte(client, LM93_REG_PROCHOT_CUR(i));
1024 data->block4[i].avg =
1025 lm93_read_byte(client, LM93_REG_PROCHOT_AVG(i));
1028 /* fan1 - fan4: values & limits */
1029 for (i = 0; i < 4; i++) {
1030 data->block5[i] =
1031 lm93_read_word(client, LM93_REG_FAN(i));
1032 data->block8[i] =
1033 lm93_read_word(client, LM93_REG_FAN_MIN(i));
1036 /* pwm control registers */
1037 for (i = 0; i < 2; i++) {
1038 for (j = 0; j < 4; j++) {
1039 data->block9[i][j] =
1040 lm93_read_byte(client, LM93_REG_PWM_CTL(i,j));
1044 /* alarm values */
1045 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) {
1046 *(ptr + i) =
1047 lm93_read_byte(client, LM93_REG_HOST_ERROR_1 + i);
1050 /* auto/pwm (base temp) registers */
1051 for (i = 0; i < 4; i++) {
1052 data->block10.base[i] =
1053 lm93_read_byte(client, LM93_REG_TEMP_BASE(i));
1056 /* auto/pwm (offset temp) registers */
1057 for (i = 0; i < 12; i++) {
1058 data->block10.offset[i] =
1059 lm93_read_byte(client, LM93_REG_TEMP_OFFSET(i));
1062 lm93_update_client_common(data, client);
1065 /* following are the sysfs callback functions */
1066 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
1067 char *buf)
1069 int nr = (to_sensor_dev_attr(attr))->index;
1071 struct lm93_data *data = lm93_update_device(dev);
1072 return sprintf(buf, "%d\n", LM93_IN_FROM_REG(nr, data->block3[nr]));
1075 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 0);
1076 static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 1);
1077 static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 2);
1078 static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 3);
1079 static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 4);
1080 static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 5);
1081 static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 6);
1082 static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 7);
1083 static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_in, NULL, 8);
1084 static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_in, NULL, 9);
1085 static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_in, NULL, 10);
1086 static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_in, NULL, 11);
1087 static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_in, NULL, 12);
1088 static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, show_in, NULL, 13);
1089 static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, show_in, NULL, 14);
1090 static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in, NULL, 15);
1092 static ssize_t show_in_min(struct device *dev,
1093 struct device_attribute *attr, char *buf)
1095 int nr = (to_sensor_dev_attr(attr))->index;
1096 struct lm93_data *data = lm93_update_device(dev);
1097 int vccp = nr - 6;
1098 long rc, vid;
1100 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1101 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1102 rc = LM93_IN_MIN_FROM_REG(data->vccp_limits[vccp], vid);
1104 else {
1105 rc = LM93_IN_FROM_REG(nr, data->block7[nr].min); \
1107 return sprintf(buf, "%ld\n", rc); \
1110 static ssize_t store_in_min(struct device *dev, struct device_attribute *attr,
1111 const char *buf, size_t count)
1113 int nr = (to_sensor_dev_attr(attr))->index;
1114 struct i2c_client *client = to_i2c_client(dev);
1115 struct lm93_data *data = i2c_get_clientdata(client);
1116 u32 val = simple_strtoul(buf, NULL, 10);
1117 int vccp = nr - 6;
1118 long vid;
1120 mutex_lock(&data->update_lock);
1121 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1122 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1123 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0xf0) |
1124 LM93_IN_REL_TO_REG(val, 0, vid);
1125 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1126 data->vccp_limits[vccp]);
1128 else {
1129 data->block7[nr].min = LM93_IN_TO_REG(nr,val);
1130 lm93_write_byte(client, LM93_REG_IN_MIN(nr),
1131 data->block7[nr].min);
1133 mutex_unlock(&data->update_lock);
1134 return count;
1137 static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
1138 show_in_min, store_in_min, 0);
1139 static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
1140 show_in_min, store_in_min, 1);
1141 static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
1142 show_in_min, store_in_min, 2);
1143 static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
1144 show_in_min, store_in_min, 3);
1145 static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
1146 show_in_min, store_in_min, 4);
1147 static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
1148 show_in_min, store_in_min, 5);
1149 static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO,
1150 show_in_min, store_in_min, 6);
1151 static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO,
1152 show_in_min, store_in_min, 7);
1153 static SENSOR_DEVICE_ATTR(in9_min, S_IWUSR | S_IRUGO,
1154 show_in_min, store_in_min, 8);
1155 static SENSOR_DEVICE_ATTR(in10_min, S_IWUSR | S_IRUGO,
1156 show_in_min, store_in_min, 9);
1157 static SENSOR_DEVICE_ATTR(in11_min, S_IWUSR | S_IRUGO,
1158 show_in_min, store_in_min, 10);
1159 static SENSOR_DEVICE_ATTR(in12_min, S_IWUSR | S_IRUGO,
1160 show_in_min, store_in_min, 11);
1161 static SENSOR_DEVICE_ATTR(in13_min, S_IWUSR | S_IRUGO,
1162 show_in_min, store_in_min, 12);
1163 static SENSOR_DEVICE_ATTR(in14_min, S_IWUSR | S_IRUGO,
1164 show_in_min, store_in_min, 13);
1165 static SENSOR_DEVICE_ATTR(in15_min, S_IWUSR | S_IRUGO,
1166 show_in_min, store_in_min, 14);
1167 static SENSOR_DEVICE_ATTR(in16_min, S_IWUSR | S_IRUGO,
1168 show_in_min, store_in_min, 15);
1170 static ssize_t show_in_max(struct device *dev,
1171 struct device_attribute *attr, char *buf)
1173 int nr = (to_sensor_dev_attr(attr))->index;
1174 struct lm93_data *data = lm93_update_device(dev);
1175 int vccp = nr - 6;
1176 long rc, vid;
1178 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1179 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1180 rc = LM93_IN_MAX_FROM_REG(data->vccp_limits[vccp],vid);
1182 else {
1183 rc = LM93_IN_FROM_REG(nr,data->block7[nr].max); \
1185 return sprintf(buf,"%ld\n",rc); \
1188 static ssize_t store_in_max(struct device *dev, struct device_attribute *attr,
1189 const char *buf, size_t count)
1191 int nr = (to_sensor_dev_attr(attr))->index;
1192 struct i2c_client *client = to_i2c_client(dev);
1193 struct lm93_data *data = i2c_get_clientdata(client);
1194 u32 val = simple_strtoul(buf, NULL, 10);
1195 int vccp = nr - 6;
1196 long vid;
1198 mutex_lock(&data->update_lock);
1199 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1200 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1201 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0x0f) |
1202 LM93_IN_REL_TO_REG(val, 1, vid);
1203 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1204 data->vccp_limits[vccp]);
1206 else {
1207 data->block7[nr].max = LM93_IN_TO_REG(nr,val);
1208 lm93_write_byte(client, LM93_REG_IN_MAX(nr),
1209 data->block7[nr].max);
1211 mutex_unlock(&data->update_lock);
1212 return count;
1215 static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
1216 show_in_max, store_in_max, 0);
1217 static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
1218 show_in_max, store_in_max, 1);
1219 static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
1220 show_in_max, store_in_max, 2);
1221 static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
1222 show_in_max, store_in_max, 3);
1223 static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
1224 show_in_max, store_in_max, 4);
1225 static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
1226 show_in_max, store_in_max, 5);
1227 static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO,
1228 show_in_max, store_in_max, 6);
1229 static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO,
1230 show_in_max, store_in_max, 7);
1231 static SENSOR_DEVICE_ATTR(in9_max, S_IWUSR | S_IRUGO,
1232 show_in_max, store_in_max, 8);
1233 static SENSOR_DEVICE_ATTR(in10_max, S_IWUSR | S_IRUGO,
1234 show_in_max, store_in_max, 9);
1235 static SENSOR_DEVICE_ATTR(in11_max, S_IWUSR | S_IRUGO,
1236 show_in_max, store_in_max, 10);
1237 static SENSOR_DEVICE_ATTR(in12_max, S_IWUSR | S_IRUGO,
1238 show_in_max, store_in_max, 11);
1239 static SENSOR_DEVICE_ATTR(in13_max, S_IWUSR | S_IRUGO,
1240 show_in_max, store_in_max, 12);
1241 static SENSOR_DEVICE_ATTR(in14_max, S_IWUSR | S_IRUGO,
1242 show_in_max, store_in_max, 13);
1243 static SENSOR_DEVICE_ATTR(in15_max, S_IWUSR | S_IRUGO,
1244 show_in_max, store_in_max, 14);
1245 static SENSOR_DEVICE_ATTR(in16_max, S_IWUSR | S_IRUGO,
1246 show_in_max, store_in_max, 15);
1248 static ssize_t show_temp(struct device *dev,
1249 struct device_attribute *attr, char *buf)
1251 int nr = (to_sensor_dev_attr(attr))->index;
1252 struct lm93_data *data = lm93_update_device(dev);
1253 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block2[nr]));
1256 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
1257 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
1258 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
1260 static ssize_t show_temp_min(struct device *dev,
1261 struct device_attribute *attr, char *buf)
1263 int nr = (to_sensor_dev_attr(attr))->index;
1264 struct lm93_data *data = lm93_update_device(dev);
1265 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].min));
1268 static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr,
1269 const char *buf, size_t count)
1271 int nr = (to_sensor_dev_attr(attr))->index;
1272 struct i2c_client *client = to_i2c_client(dev);
1273 struct lm93_data *data = i2c_get_clientdata(client);
1274 long val = simple_strtol(buf, NULL, 10);
1276 mutex_lock(&data->update_lock);
1277 data->temp_lim[nr].min = LM93_TEMP_TO_REG(val);
1278 lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), data->temp_lim[nr].min);
1279 mutex_unlock(&data->update_lock);
1280 return count;
1283 static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO,
1284 show_temp_min, store_temp_min, 0);
1285 static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO,
1286 show_temp_min, store_temp_min, 1);
1287 static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO,
1288 show_temp_min, store_temp_min, 2);
1290 static ssize_t show_temp_max(struct device *dev,
1291 struct device_attribute *attr, char *buf)
1293 int nr = (to_sensor_dev_attr(attr))->index;
1294 struct lm93_data *data = lm93_update_device(dev);
1295 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].max));
1298 static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr,
1299 const char *buf, size_t count)
1301 int nr = (to_sensor_dev_attr(attr))->index;
1302 struct i2c_client *client = to_i2c_client(dev);
1303 struct lm93_data *data = i2c_get_clientdata(client);
1304 long val = simple_strtol(buf, NULL, 10);
1306 mutex_lock(&data->update_lock);
1307 data->temp_lim[nr].max = LM93_TEMP_TO_REG(val);
1308 lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), data->temp_lim[nr].max);
1309 mutex_unlock(&data->update_lock);
1310 return count;
1313 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
1314 show_temp_max, store_temp_max, 0);
1315 static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO,
1316 show_temp_max, store_temp_max, 1);
1317 static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO,
1318 show_temp_max, store_temp_max, 2);
1320 static ssize_t show_temp_auto_base(struct device *dev,
1321 struct device_attribute *attr, char *buf)
1323 int nr = (to_sensor_dev_attr(attr))->index;
1324 struct lm93_data *data = lm93_update_device(dev);
1325 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block10.base[nr]));
1328 static ssize_t store_temp_auto_base(struct device *dev,
1329 struct device_attribute *attr,
1330 const char *buf, size_t count)
1332 int nr = (to_sensor_dev_attr(attr))->index;
1333 struct i2c_client *client = to_i2c_client(dev);
1334 struct lm93_data *data = i2c_get_clientdata(client);
1335 long val = simple_strtol(buf, NULL, 10);
1337 mutex_lock(&data->update_lock);
1338 data->block10.base[nr] = LM93_TEMP_TO_REG(val);
1339 lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), data->block10.base[nr]);
1340 mutex_unlock(&data->update_lock);
1341 return count;
1344 static SENSOR_DEVICE_ATTR(temp1_auto_base, S_IWUSR | S_IRUGO,
1345 show_temp_auto_base, store_temp_auto_base, 0);
1346 static SENSOR_DEVICE_ATTR(temp2_auto_base, S_IWUSR | S_IRUGO,
1347 show_temp_auto_base, store_temp_auto_base, 1);
1348 static SENSOR_DEVICE_ATTR(temp3_auto_base, S_IWUSR | S_IRUGO,
1349 show_temp_auto_base, store_temp_auto_base, 2);
1351 static ssize_t show_temp_auto_boost(struct device *dev,
1352 struct device_attribute *attr,char *buf)
1354 int nr = (to_sensor_dev_attr(attr))->index;
1355 struct lm93_data *data = lm93_update_device(dev);
1356 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->boost[nr]));
1359 static ssize_t store_temp_auto_boost(struct device *dev,
1360 struct device_attribute *attr,
1361 const char *buf, size_t count)
1363 int nr = (to_sensor_dev_attr(attr))->index;
1364 struct i2c_client *client = to_i2c_client(dev);
1365 struct lm93_data *data = i2c_get_clientdata(client);
1366 long val = simple_strtol(buf, NULL, 10);
1368 mutex_lock(&data->update_lock);
1369 data->boost[nr] = LM93_TEMP_TO_REG(val);
1370 lm93_write_byte(client, LM93_REG_BOOST(nr), data->boost[nr]);
1371 mutex_unlock(&data->update_lock);
1372 return count;
1375 static SENSOR_DEVICE_ATTR(temp1_auto_boost, S_IWUSR | S_IRUGO,
1376 show_temp_auto_boost, store_temp_auto_boost, 0);
1377 static SENSOR_DEVICE_ATTR(temp2_auto_boost, S_IWUSR | S_IRUGO,
1378 show_temp_auto_boost, store_temp_auto_boost, 1);
1379 static SENSOR_DEVICE_ATTR(temp3_auto_boost, S_IWUSR | S_IRUGO,
1380 show_temp_auto_boost, store_temp_auto_boost, 2);
1382 static ssize_t show_temp_auto_boost_hyst(struct device *dev,
1383 struct device_attribute *attr,
1384 char *buf)
1386 int nr = (to_sensor_dev_attr(attr))->index;
1387 struct lm93_data *data = lm93_update_device(dev);
1388 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1389 return sprintf(buf,"%d\n",
1390 LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode));
1393 static ssize_t store_temp_auto_boost_hyst(struct device *dev,
1394 struct device_attribute *attr,
1395 const char *buf, size_t count)
1397 int nr = (to_sensor_dev_attr(attr))->index;
1398 struct i2c_client *client = to_i2c_client(dev);
1399 struct lm93_data *data = i2c_get_clientdata(client);
1400 u32 val = simple_strtoul(buf, NULL, 10);
1402 mutex_lock(&data->update_lock);
1403 /* force 0.5C/bit mode */
1404 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1405 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1406 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1407 data->boost_hyst[nr/2] = LM93_AUTO_BOOST_HYST_TO_REG(data, val, nr, 1);
1408 lm93_write_byte(client, LM93_REG_BOOST_HYST(nr),
1409 data->boost_hyst[nr/2]);
1410 mutex_unlock(&data->update_lock);
1411 return count;
1414 static SENSOR_DEVICE_ATTR(temp1_auto_boost_hyst, S_IWUSR | S_IRUGO,
1415 show_temp_auto_boost_hyst,
1416 store_temp_auto_boost_hyst, 0);
1417 static SENSOR_DEVICE_ATTR(temp2_auto_boost_hyst, S_IWUSR | S_IRUGO,
1418 show_temp_auto_boost_hyst,
1419 store_temp_auto_boost_hyst, 1);
1420 static SENSOR_DEVICE_ATTR(temp3_auto_boost_hyst, S_IWUSR | S_IRUGO,
1421 show_temp_auto_boost_hyst,
1422 store_temp_auto_boost_hyst, 2);
1424 static ssize_t show_temp_auto_offset(struct device *dev,
1425 struct device_attribute *attr, char *buf)
1427 struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr);
1428 int nr = s_attr->index;
1429 int ofs = s_attr->nr;
1430 struct lm93_data *data = lm93_update_device(dev);
1431 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1432 return sprintf(buf,"%d\n",
1433 LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs],
1434 nr,mode));
1437 static ssize_t store_temp_auto_offset(struct device *dev,
1438 struct device_attribute *attr,
1439 const char *buf, size_t count)
1441 struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr);
1442 int nr = s_attr->index;
1443 int ofs = s_attr->nr;
1444 struct i2c_client *client = to_i2c_client(dev);
1445 struct lm93_data *data = i2c_get_clientdata(client);
1446 u32 val = simple_strtoul(buf, NULL, 10);
1448 mutex_lock(&data->update_lock);
1449 /* force 0.5C/bit mode */
1450 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1451 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1452 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1453 data->block10.offset[ofs] = LM93_TEMP_AUTO_OFFSET_TO_REG(
1454 data->block10.offset[ofs], val, nr, 1);
1455 lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ofs),
1456 data->block10.offset[ofs]);
1457 mutex_unlock(&data->update_lock);
1458 return count;
1461 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset1, S_IWUSR | S_IRUGO,
1462 show_temp_auto_offset, store_temp_auto_offset, 0, 0);
1463 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset2, S_IWUSR | S_IRUGO,
1464 show_temp_auto_offset, store_temp_auto_offset, 1, 0);
1465 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset3, S_IWUSR | S_IRUGO,
1466 show_temp_auto_offset, store_temp_auto_offset, 2, 0);
1467 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset4, S_IWUSR | S_IRUGO,
1468 show_temp_auto_offset, store_temp_auto_offset, 3, 0);
1469 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset5, S_IWUSR | S_IRUGO,
1470 show_temp_auto_offset, store_temp_auto_offset, 4, 0);
1471 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset6, S_IWUSR | S_IRUGO,
1472 show_temp_auto_offset, store_temp_auto_offset, 5, 0);
1473 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset7, S_IWUSR | S_IRUGO,
1474 show_temp_auto_offset, store_temp_auto_offset, 6, 0);
1475 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset8, S_IWUSR | S_IRUGO,
1476 show_temp_auto_offset, store_temp_auto_offset, 7, 0);
1477 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset9, S_IWUSR | S_IRUGO,
1478 show_temp_auto_offset, store_temp_auto_offset, 8, 0);
1479 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset10, S_IWUSR | S_IRUGO,
1480 show_temp_auto_offset, store_temp_auto_offset, 9, 0);
1481 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset11, S_IWUSR | S_IRUGO,
1482 show_temp_auto_offset, store_temp_auto_offset, 10, 0);
1483 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset12, S_IWUSR | S_IRUGO,
1484 show_temp_auto_offset, store_temp_auto_offset, 11, 0);
1485 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset1, S_IWUSR | S_IRUGO,
1486 show_temp_auto_offset, store_temp_auto_offset, 0, 1);
1487 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset2, S_IWUSR | S_IRUGO,
1488 show_temp_auto_offset, store_temp_auto_offset, 1, 1);
1489 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset3, S_IWUSR | S_IRUGO,
1490 show_temp_auto_offset, store_temp_auto_offset, 2, 1);
1491 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset4, S_IWUSR | S_IRUGO,
1492 show_temp_auto_offset, store_temp_auto_offset, 3, 1);
1493 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset5, S_IWUSR | S_IRUGO,
1494 show_temp_auto_offset, store_temp_auto_offset, 4, 1);
1495 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset6, S_IWUSR | S_IRUGO,
1496 show_temp_auto_offset, store_temp_auto_offset, 5, 1);
1497 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset7, S_IWUSR | S_IRUGO,
1498 show_temp_auto_offset, store_temp_auto_offset, 6, 1);
1499 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset8, S_IWUSR | S_IRUGO,
1500 show_temp_auto_offset, store_temp_auto_offset, 7, 1);
1501 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset9, S_IWUSR | S_IRUGO,
1502 show_temp_auto_offset, store_temp_auto_offset, 8, 1);
1503 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset10, S_IWUSR | S_IRUGO,
1504 show_temp_auto_offset, store_temp_auto_offset, 9, 1);
1505 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset11, S_IWUSR | S_IRUGO,
1506 show_temp_auto_offset, store_temp_auto_offset, 10, 1);
1507 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset12, S_IWUSR | S_IRUGO,
1508 show_temp_auto_offset, store_temp_auto_offset, 11, 1);
1509 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset1, S_IWUSR | S_IRUGO,
1510 show_temp_auto_offset, store_temp_auto_offset, 0, 2);
1511 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset2, S_IWUSR | S_IRUGO,
1512 show_temp_auto_offset, store_temp_auto_offset, 1, 2);
1513 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset3, S_IWUSR | S_IRUGO,
1514 show_temp_auto_offset, store_temp_auto_offset, 2, 2);
1515 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset4, S_IWUSR | S_IRUGO,
1516 show_temp_auto_offset, store_temp_auto_offset, 3, 2);
1517 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset5, S_IWUSR | S_IRUGO,
1518 show_temp_auto_offset, store_temp_auto_offset, 4, 2);
1519 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset6, S_IWUSR | S_IRUGO,
1520 show_temp_auto_offset, store_temp_auto_offset, 5, 2);
1521 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset7, S_IWUSR | S_IRUGO,
1522 show_temp_auto_offset, store_temp_auto_offset, 6, 2);
1523 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset8, S_IWUSR | S_IRUGO,
1524 show_temp_auto_offset, store_temp_auto_offset, 7, 2);
1525 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset9, S_IWUSR | S_IRUGO,
1526 show_temp_auto_offset, store_temp_auto_offset, 8, 2);
1527 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset10, S_IWUSR | S_IRUGO,
1528 show_temp_auto_offset, store_temp_auto_offset, 9, 2);
1529 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset11, S_IWUSR | S_IRUGO,
1530 show_temp_auto_offset, store_temp_auto_offset, 10, 2);
1531 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset12, S_IWUSR | S_IRUGO,
1532 show_temp_auto_offset, store_temp_auto_offset, 11, 2);
1534 static ssize_t show_temp_auto_pwm_min(struct device *dev,
1535 struct device_attribute *attr, char *buf)
1537 int nr = (to_sensor_dev_attr(attr))->index;
1538 u8 reg, ctl4;
1539 struct lm93_data *data = lm93_update_device(dev);
1540 reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f;
1541 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1542 return sprintf(buf,"%d\n",LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ?
1543 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));
1546 static ssize_t store_temp_auto_pwm_min(struct device *dev,
1547 struct device_attribute *attr,
1548 const char *buf, size_t count)
1550 int nr = (to_sensor_dev_attr(attr))->index;
1551 struct i2c_client *client = to_i2c_client(dev);
1552 struct lm93_data *data = i2c_get_clientdata(client);
1553 u32 val = simple_strtoul(buf, NULL, 10);
1554 u8 reg, ctl4;
1556 mutex_lock(&data->update_lock);
1557 reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr));
1558 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4));
1559 reg = (reg & 0x0f) |
1560 LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1561 LM93_PWM_MAP_LO_FREQ :
1562 LM93_PWM_MAP_HI_FREQ) << 4;
1563 data->auto_pwm_min_hyst[nr/2] = reg;
1564 lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg);
1565 mutex_unlock(&data->update_lock);
1566 return count;
1569 static SENSOR_DEVICE_ATTR(temp1_auto_pwm_min, S_IWUSR | S_IRUGO,
1570 show_temp_auto_pwm_min,
1571 store_temp_auto_pwm_min, 0);
1572 static SENSOR_DEVICE_ATTR(temp2_auto_pwm_min, S_IWUSR | S_IRUGO,
1573 show_temp_auto_pwm_min,
1574 store_temp_auto_pwm_min, 1);
1575 static SENSOR_DEVICE_ATTR(temp3_auto_pwm_min, S_IWUSR | S_IRUGO,
1576 show_temp_auto_pwm_min,
1577 store_temp_auto_pwm_min, 2);
1579 static ssize_t show_temp_auto_offset_hyst(struct device *dev,
1580 struct device_attribute *attr, char *buf)
1582 int nr = (to_sensor_dev_attr(attr))->index;
1583 struct lm93_data *data = lm93_update_device(dev);
1584 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1585 return sprintf(buf,"%d\n",LM93_TEMP_OFFSET_FROM_REG(
1586 data->auto_pwm_min_hyst[nr/2], mode));
1589 static ssize_t store_temp_auto_offset_hyst(struct device *dev,
1590 struct device_attribute *attr,
1591 const char *buf, size_t count)
1593 int nr = (to_sensor_dev_attr(attr))->index;
1594 struct i2c_client *client = to_i2c_client(dev);
1595 struct lm93_data *data = i2c_get_clientdata(client);
1596 u32 val = simple_strtoul(buf, NULL, 10);
1597 u8 reg;
1599 mutex_lock(&data->update_lock);
1600 /* force 0.5C/bit mode */
1601 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1602 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1603 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1604 reg = data->auto_pwm_min_hyst[nr/2];
1605 reg = (reg & 0xf0) | (LM93_TEMP_OFFSET_TO_REG(val, 1) & 0x0f);
1606 data->auto_pwm_min_hyst[nr/2] = reg;
1607 lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg);
1608 mutex_unlock(&data->update_lock);
1609 return count;
1612 static SENSOR_DEVICE_ATTR(temp1_auto_offset_hyst, S_IWUSR | S_IRUGO,
1613 show_temp_auto_offset_hyst,
1614 store_temp_auto_offset_hyst, 0);
1615 static SENSOR_DEVICE_ATTR(temp2_auto_offset_hyst, S_IWUSR | S_IRUGO,
1616 show_temp_auto_offset_hyst,
1617 store_temp_auto_offset_hyst, 1);
1618 static SENSOR_DEVICE_ATTR(temp3_auto_offset_hyst, S_IWUSR | S_IRUGO,
1619 show_temp_auto_offset_hyst,
1620 store_temp_auto_offset_hyst, 2);
1622 static ssize_t show_fan_input(struct device *dev,
1623 struct device_attribute *attr, char *buf)
1625 struct sensor_device_attribute *s_attr = to_sensor_dev_attr(attr);
1626 int nr = s_attr->index;
1627 struct lm93_data *data = lm93_update_device(dev);
1629 return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block5[nr]));
1632 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0);
1633 static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1);
1634 static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2);
1635 static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan_input, NULL, 3);
1637 static ssize_t show_fan_min(struct device *dev,
1638 struct device_attribute *attr, char *buf)
1640 int nr = (to_sensor_dev_attr(attr))->index;
1641 struct lm93_data *data = lm93_update_device(dev);
1643 return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block8[nr]));
1646 static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr,
1647 const char *buf, size_t count)
1649 int nr = (to_sensor_dev_attr(attr))->index;
1650 struct i2c_client *client = to_i2c_client(dev);
1651 struct lm93_data *data = i2c_get_clientdata(client);
1652 u32 val = simple_strtoul(buf, NULL, 10);
1654 mutex_lock(&data->update_lock);
1655 data->block8[nr] = LM93_FAN_TO_REG(val);
1656 lm93_write_word(client,LM93_REG_FAN_MIN(nr),data->block8[nr]);
1657 mutex_unlock(&data->update_lock);
1658 return count;
1661 static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
1662 show_fan_min, store_fan_min, 0);
1663 static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
1664 show_fan_min, store_fan_min, 1);
1665 static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO,
1666 show_fan_min, store_fan_min, 2);
1667 static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO,
1668 show_fan_min, store_fan_min, 3);
1670 /* some tedious bit-twiddling here to deal with the register format:
1672 data->sf_tach_to_pwm: (tach to pwm mapping bits)
1674 bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
1675 T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1
1677 data->sfc2: (enable bits)
1679 bit | 3 | 2 | 1 | 0
1680 T4 T3 T2 T1
1683 static ssize_t show_fan_smart_tach(struct device *dev,
1684 struct device_attribute *attr, char *buf)
1686 int nr = (to_sensor_dev_attr(attr))->index;
1687 struct lm93_data *data = lm93_update_device(dev);
1688 long rc = 0;
1689 int mapping;
1691 /* extract the relevant mapping */
1692 mapping = (data->sf_tach_to_pwm >> (nr * 2)) & 0x03;
1694 /* if there's a mapping and it's enabled */
1695 if (mapping && ((data->sfc2 >> nr) & 0x01))
1696 rc = mapping;
1697 return sprintf(buf,"%ld\n",rc);
1700 /* helper function - must grab data->update_lock before calling
1701 fan is 0-3, indicating fan1-fan4 */
1702 static void lm93_write_fan_smart_tach(struct i2c_client *client,
1703 struct lm93_data *data, int fan, long value)
1705 /* insert the new mapping and write it out */
1706 data->sf_tach_to_pwm = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM);
1707 data->sf_tach_to_pwm &= ~(0x3 << fan * 2);
1708 data->sf_tach_to_pwm |= value << fan * 2;
1709 lm93_write_byte(client, LM93_REG_SF_TACH_TO_PWM, data->sf_tach_to_pwm);
1711 /* insert the enable bit and write it out */
1712 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1713 if (value)
1714 data->sfc2 |= 1 << fan;
1715 else
1716 data->sfc2 &= ~(1 << fan);
1717 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1720 static ssize_t store_fan_smart_tach(struct device *dev,
1721 struct device_attribute *attr,
1722 const char *buf, size_t count)
1724 int nr = (to_sensor_dev_attr(attr))->index;
1725 struct i2c_client *client = to_i2c_client(dev);
1726 struct lm93_data *data = i2c_get_clientdata(client);
1727 u32 val = simple_strtoul(buf, NULL, 10);
1729 mutex_lock(&data->update_lock);
1730 /* sanity test, ignore the write otherwise */
1731 if (0 <= val && val <= 2) {
1732 /* can't enable if pwm freq is 22.5KHz */
1733 if (val) {
1734 u8 ctl4 = lm93_read_byte(client,
1735 LM93_REG_PWM_CTL(val-1,LM93_PWM_CTL4));
1736 if ((ctl4 & 0x07) == 0)
1737 val = 0;
1739 lm93_write_fan_smart_tach(client, data, nr, val);
1741 mutex_unlock(&data->update_lock);
1742 return count;
1745 static SENSOR_DEVICE_ATTR(fan1_smart_tach, S_IWUSR | S_IRUGO,
1746 show_fan_smart_tach, store_fan_smart_tach, 0);
1747 static SENSOR_DEVICE_ATTR(fan2_smart_tach, S_IWUSR | S_IRUGO,
1748 show_fan_smart_tach, store_fan_smart_tach, 1);
1749 static SENSOR_DEVICE_ATTR(fan3_smart_tach, S_IWUSR | S_IRUGO,
1750 show_fan_smart_tach, store_fan_smart_tach, 2);
1751 static SENSOR_DEVICE_ATTR(fan4_smart_tach, S_IWUSR | S_IRUGO,
1752 show_fan_smart_tach, store_fan_smart_tach, 3);
1754 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1755 char *buf)
1757 int nr = (to_sensor_dev_attr(attr))->index;
1758 struct lm93_data *data = lm93_update_device(dev);
1759 u8 ctl2, ctl4;
1760 long rc;
1762 ctl2 = data->block9[nr][LM93_PWM_CTL2];
1763 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1764 if (ctl2 & 0x01) /* show user commanded value if enabled */
1765 rc = data->pwm_override[nr];
1766 else /* show present h/w value if manual pwm disabled */
1767 rc = LM93_PWM_FROM_REG(ctl2 >> 4, (ctl4 & 0x07) ?
1768 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ);
1769 return sprintf(buf,"%ld\n",rc);
1772 static ssize_t store_pwm(struct device *dev, struct device_attribute *attr,
1773 const char *buf, size_t count)
1775 int nr = (to_sensor_dev_attr(attr))->index;
1776 struct i2c_client *client = to_i2c_client(dev);
1777 struct lm93_data *data = i2c_get_clientdata(client);
1778 u32 val = simple_strtoul(buf, NULL, 10);
1779 u8 ctl2, ctl4;
1781 mutex_lock(&data->update_lock);
1782 ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2));
1783 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4));
1784 ctl2 = (ctl2 & 0x0f) | LM93_PWM_TO_REG(val,(ctl4 & 0x07) ?
1785 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ) << 4;
1786 /* save user commanded value */
1787 data->pwm_override[nr] = LM93_PWM_FROM_REG(ctl2 >> 4,
1788 (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ :
1789 LM93_PWM_MAP_HI_FREQ);
1790 lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2);
1791 mutex_unlock(&data->update_lock);
1792 return count;
1795 static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
1796 static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
1798 static ssize_t show_pwm_enable(struct device *dev,
1799 struct device_attribute *attr, char *buf)
1801 int nr = (to_sensor_dev_attr(attr))->index;
1802 struct lm93_data *data = lm93_update_device(dev);
1803 u8 ctl2;
1804 long rc;
1806 ctl2 = data->block9[nr][LM93_PWM_CTL2];
1807 if (ctl2 & 0x01) /* manual override enabled ? */
1808 rc = ((ctl2 & 0xF0) == 0xF0) ? 0 : 1;
1809 else
1810 rc = 2;
1811 return sprintf(buf,"%ld\n",rc);
1814 static ssize_t store_pwm_enable(struct device *dev,
1815 struct device_attribute *attr,
1816 const char *buf, size_t count)
1818 int nr = (to_sensor_dev_attr(attr))->index;
1819 struct i2c_client *client = to_i2c_client(dev);
1820 struct lm93_data *data = i2c_get_clientdata(client);
1821 u32 val = simple_strtoul(buf, NULL, 10);
1822 u8 ctl2;
1824 mutex_lock(&data->update_lock);
1825 ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2));
1827 switch (val) {
1828 case 0:
1829 ctl2 |= 0xF1; /* enable manual override, set PWM to max */
1830 break;
1831 case 1: ctl2 |= 0x01; /* enable manual override */
1832 break;
1833 case 2: ctl2 &= ~0x01; /* disable manual override */
1834 break;
1835 default:
1836 mutex_unlock(&data->update_lock);
1837 return -EINVAL;
1840 lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2);
1841 mutex_unlock(&data->update_lock);
1842 return count;
1845 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
1846 show_pwm_enable, store_pwm_enable, 0);
1847 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
1848 show_pwm_enable, store_pwm_enable, 1);
1850 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
1851 char *buf)
1853 int nr = (to_sensor_dev_attr(attr))->index;
1854 struct lm93_data *data = lm93_update_device(dev);
1855 u8 ctl4;
1857 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1858 return sprintf(buf,"%d\n",LM93_PWM_FREQ_FROM_REG(ctl4));
1861 /* helper function - must grab data->update_lock before calling
1862 pwm is 0-1, indicating pwm1-pwm2
1863 this disables smart tach for all tach channels bound to the given pwm */
1864 static void lm93_disable_fan_smart_tach(struct i2c_client *client,
1865 struct lm93_data *data, int pwm)
1867 int mapping = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM);
1868 int mask;
1870 /* collapse the mapping into a mask of enable bits */
1871 mapping = (mapping >> pwm) & 0x55;
1872 mask = mapping & 0x01;
1873 mask |= (mapping & 0x04) >> 1;
1874 mask |= (mapping & 0x10) >> 2;
1875 mask |= (mapping & 0x40) >> 3;
1877 /* disable smart tach according to the mask */
1878 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1879 data->sfc2 &= ~mask;
1880 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1883 static ssize_t store_pwm_freq(struct device *dev,
1884 struct device_attribute *attr,
1885 const char *buf, size_t count)
1887 int nr = (to_sensor_dev_attr(attr))->index;
1888 struct i2c_client *client = to_i2c_client(dev);
1889 struct lm93_data *data = i2c_get_clientdata(client);
1890 u32 val = simple_strtoul(buf, NULL, 10);
1891 u8 ctl4;
1893 mutex_lock(&data->update_lock);
1894 ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4));
1895 ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(val);
1896 data->block9[nr][LM93_PWM_CTL4] = ctl4;
1897 /* ctl4 == 0 -> 22.5KHz -> disable smart tach */
1898 if (!ctl4)
1899 lm93_disable_fan_smart_tach(client, data, nr);
1900 lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4), ctl4);
1901 mutex_unlock(&data->update_lock);
1902 return count;
1905 static SENSOR_DEVICE_ATTR(pwm1_freq, S_IWUSR | S_IRUGO,
1906 show_pwm_freq, store_pwm_freq, 0);
1907 static SENSOR_DEVICE_ATTR(pwm2_freq, S_IWUSR | S_IRUGO,
1908 show_pwm_freq, store_pwm_freq, 1);
1910 static ssize_t show_pwm_auto_channels(struct device *dev,
1911 struct device_attribute *attr, char *buf)
1913 int nr = (to_sensor_dev_attr(attr))->index;
1914 struct lm93_data *data = lm93_update_device(dev);
1915 return sprintf(buf,"%d\n",data->block9[nr][LM93_PWM_CTL1]);
1918 static ssize_t store_pwm_auto_channels(struct device *dev,
1919 struct device_attribute *attr,
1920 const char *buf, size_t count)
1922 int nr = (to_sensor_dev_attr(attr))->index;
1923 struct i2c_client *client = to_i2c_client(dev);
1924 struct lm93_data *data = i2c_get_clientdata(client);
1925 u32 val = simple_strtoul(buf, NULL, 10);
1927 mutex_lock(&data->update_lock);
1928 data->block9[nr][LM93_PWM_CTL1] = SENSORS_LIMIT(val, 0, 255);
1929 lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL1),
1930 data->block9[nr][LM93_PWM_CTL1]);
1931 mutex_unlock(&data->update_lock);
1932 return count;
1935 static SENSOR_DEVICE_ATTR(pwm1_auto_channels, S_IWUSR | S_IRUGO,
1936 show_pwm_auto_channels, store_pwm_auto_channels, 0);
1937 static SENSOR_DEVICE_ATTR(pwm2_auto_channels, S_IWUSR | S_IRUGO,
1938 show_pwm_auto_channels, store_pwm_auto_channels, 1);
1940 static ssize_t show_pwm_auto_spinup_min(struct device *dev,
1941 struct device_attribute *attr,char *buf)
1943 int nr = (to_sensor_dev_attr(attr))->index;
1944 struct lm93_data *data = lm93_update_device(dev);
1945 u8 ctl3, ctl4;
1947 ctl3 = data->block9[nr][LM93_PWM_CTL3];
1948 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1949 return sprintf(buf,"%d\n",
1950 LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ?
1951 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));
1954 static ssize_t store_pwm_auto_spinup_min(struct device *dev,
1955 struct device_attribute *attr,
1956 const char *buf, size_t count)
1958 int nr = (to_sensor_dev_attr(attr))->index;
1959 struct i2c_client *client = to_i2c_client(dev);
1960 struct lm93_data *data = i2c_get_clientdata(client);
1961 u32 val = simple_strtoul(buf, NULL, 10);
1962 u8 ctl3, ctl4;
1964 mutex_lock(&data->update_lock);
1965 ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3));
1966 ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1967 ctl3 = (ctl3 & 0xf0) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1968 LM93_PWM_MAP_LO_FREQ :
1969 LM93_PWM_MAP_HI_FREQ);
1970 data->block9[nr][LM93_PWM_CTL3] = ctl3;
1971 lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3);
1972 mutex_unlock(&data->update_lock);
1973 return count;
1976 static SENSOR_DEVICE_ATTR(pwm1_auto_spinup_min, S_IWUSR | S_IRUGO,
1977 show_pwm_auto_spinup_min,
1978 store_pwm_auto_spinup_min, 0);
1979 static SENSOR_DEVICE_ATTR(pwm2_auto_spinup_min, S_IWUSR | S_IRUGO,
1980 show_pwm_auto_spinup_min,
1981 store_pwm_auto_spinup_min, 1);
1983 static ssize_t show_pwm_auto_spinup_time(struct device *dev,
1984 struct device_attribute *attr, char *buf)
1986 int nr = (to_sensor_dev_attr(attr))->index;
1987 struct lm93_data *data = lm93_update_device(dev);
1988 return sprintf(buf,"%d\n",LM93_SPINUP_TIME_FROM_REG(
1989 data->block9[nr][LM93_PWM_CTL3]));
1992 static ssize_t store_pwm_auto_spinup_time(struct device *dev,
1993 struct device_attribute *attr,
1994 const char *buf, size_t count)
1996 int nr = (to_sensor_dev_attr(attr))->index;
1997 struct i2c_client *client = to_i2c_client(dev);
1998 struct lm93_data *data = i2c_get_clientdata(client);
1999 u32 val = simple_strtoul(buf, NULL, 10);
2000 u8 ctl3;
2002 mutex_lock(&data->update_lock);
2003 ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3));
2004 ctl3 = (ctl3 & 0x1f) | (LM93_SPINUP_TIME_TO_REG(val) << 5 & 0xe0);
2005 data->block9[nr][LM93_PWM_CTL3] = ctl3;
2006 lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3);
2007 mutex_unlock(&data->update_lock);
2008 return count;
2011 static SENSOR_DEVICE_ATTR(pwm1_auto_spinup_time, S_IWUSR | S_IRUGO,
2012 show_pwm_auto_spinup_time,
2013 store_pwm_auto_spinup_time, 0);
2014 static SENSOR_DEVICE_ATTR(pwm2_auto_spinup_time, S_IWUSR | S_IRUGO,
2015 show_pwm_auto_spinup_time,
2016 store_pwm_auto_spinup_time, 1);
2018 static ssize_t show_pwm_auto_prochot_ramp(struct device *dev,
2019 struct device_attribute *attr, char *buf)
2021 struct lm93_data *data = lm93_update_device(dev);
2022 return sprintf(buf,"%d\n",
2023 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl >> 4 & 0x0f));
2026 static ssize_t store_pwm_auto_prochot_ramp(struct device *dev,
2027 struct device_attribute *attr,
2028 const char *buf, size_t count)
2030 struct i2c_client *client = to_i2c_client(dev);
2031 struct lm93_data *data = i2c_get_clientdata(client);
2032 u32 val = simple_strtoul(buf, NULL, 10);
2033 u8 ramp;
2035 mutex_lock(&data->update_lock);
2036 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
2037 ramp = (ramp & 0x0f) | (LM93_RAMP_TO_REG(val) << 4 & 0xf0);
2038 lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp);
2039 mutex_unlock(&data->update_lock);
2040 return count;
2043 static DEVICE_ATTR(pwm_auto_prochot_ramp, S_IRUGO | S_IWUSR,
2044 show_pwm_auto_prochot_ramp,
2045 store_pwm_auto_prochot_ramp);
2047 static ssize_t show_pwm_auto_vrdhot_ramp(struct device *dev,
2048 struct device_attribute *attr, char *buf)
2050 struct lm93_data *data = lm93_update_device(dev);
2051 return sprintf(buf,"%d\n",
2052 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl & 0x0f));
2055 static ssize_t store_pwm_auto_vrdhot_ramp(struct device *dev,
2056 struct device_attribute *attr,
2057 const char *buf, size_t count)
2059 struct i2c_client *client = to_i2c_client(dev);
2060 struct lm93_data *data = i2c_get_clientdata(client);
2061 u32 val = simple_strtoul(buf, NULL, 10);
2062 u8 ramp;
2064 mutex_lock(&data->update_lock);
2065 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
2066 ramp = (ramp & 0xf0) | (LM93_RAMP_TO_REG(val) & 0x0f);
2067 lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp);
2068 mutex_unlock(&data->update_lock);
2069 return 0;
2072 static DEVICE_ATTR(pwm_auto_vrdhot_ramp, S_IRUGO | S_IWUSR,
2073 show_pwm_auto_vrdhot_ramp,
2074 store_pwm_auto_vrdhot_ramp);
2076 static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
2077 char *buf)
2079 int nr = (to_sensor_dev_attr(attr))->index;
2080 struct lm93_data *data = lm93_update_device(dev);
2081 return sprintf(buf,"%d\n",LM93_VID_FROM_REG(data->vid[nr]));
2084 static SENSOR_DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL, 0);
2085 static SENSOR_DEVICE_ATTR(cpu1_vid, S_IRUGO, show_vid, NULL, 1);
2087 static ssize_t show_prochot(struct device *dev, struct device_attribute *attr,
2088 char *buf)
2090 int nr = (to_sensor_dev_attr(attr))->index;
2091 struct lm93_data *data = lm93_update_device(dev);
2092 return sprintf(buf,"%d\n",data->block4[nr].cur);
2095 static SENSOR_DEVICE_ATTR(prochot1, S_IRUGO, show_prochot, NULL, 0);
2096 static SENSOR_DEVICE_ATTR(prochot2, S_IRUGO, show_prochot, NULL, 1);
2098 static ssize_t show_prochot_avg(struct device *dev,
2099 struct device_attribute *attr, char *buf)
2101 int nr = (to_sensor_dev_attr(attr))->index;
2102 struct lm93_data *data = lm93_update_device(dev);
2103 return sprintf(buf,"%d\n",data->block4[nr].avg);
2106 static SENSOR_DEVICE_ATTR(prochot1_avg, S_IRUGO, show_prochot_avg, NULL, 0);
2107 static SENSOR_DEVICE_ATTR(prochot2_avg, S_IRUGO, show_prochot_avg, NULL, 1);
2109 static ssize_t show_prochot_max(struct device *dev,
2110 struct device_attribute *attr, char *buf)
2112 int nr = (to_sensor_dev_attr(attr))->index;
2113 struct lm93_data *data = lm93_update_device(dev);
2114 return sprintf(buf,"%d\n",data->prochot_max[nr]);
2117 static ssize_t store_prochot_max(struct device *dev,
2118 struct device_attribute *attr,
2119 const char *buf, size_t count)
2121 int nr = (to_sensor_dev_attr(attr))->index;
2122 struct i2c_client *client = to_i2c_client(dev);
2123 struct lm93_data *data = i2c_get_clientdata(client);
2124 u32 val = simple_strtoul(buf, NULL, 10);
2126 mutex_lock(&data->update_lock);
2127 data->prochot_max[nr] = LM93_PROCHOT_TO_REG(val);
2128 lm93_write_byte(client, LM93_REG_PROCHOT_MAX(nr),
2129 data->prochot_max[nr]);
2130 mutex_unlock(&data->update_lock);
2131 return count;
2134 static SENSOR_DEVICE_ATTR(prochot1_max, S_IWUSR | S_IRUGO,
2135 show_prochot_max, store_prochot_max, 0);
2136 static SENSOR_DEVICE_ATTR(prochot2_max, S_IWUSR | S_IRUGO,
2137 show_prochot_max, store_prochot_max, 1);
2139 static const u8 prochot_override_mask[] = { 0x80, 0x40 };
2141 static ssize_t show_prochot_override(struct device *dev,
2142 struct device_attribute *attr, char *buf)
2144 int nr = (to_sensor_dev_attr(attr))->index;
2145 struct lm93_data *data = lm93_update_device(dev);
2146 return sprintf(buf,"%d\n",
2147 (data->prochot_override & prochot_override_mask[nr]) ? 1 : 0);
2150 static ssize_t store_prochot_override(struct device *dev,
2151 struct device_attribute *attr,
2152 const char *buf, size_t count)
2154 int nr = (to_sensor_dev_attr(attr))->index;
2155 struct i2c_client *client = to_i2c_client(dev);
2156 struct lm93_data *data = i2c_get_clientdata(client);
2157 u32 val = simple_strtoul(buf, NULL, 10);
2159 mutex_lock(&data->update_lock);
2160 if (val)
2161 data->prochot_override |= prochot_override_mask[nr];
2162 else
2163 data->prochot_override &= (~prochot_override_mask[nr]);
2164 lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE,
2165 data->prochot_override);
2166 mutex_unlock(&data->update_lock);
2167 return count;
2170 static SENSOR_DEVICE_ATTR(prochot1_override, S_IWUSR | S_IRUGO,
2171 show_prochot_override, store_prochot_override, 0);
2172 static SENSOR_DEVICE_ATTR(prochot2_override, S_IWUSR | S_IRUGO,
2173 show_prochot_override, store_prochot_override, 1);
2175 static ssize_t show_prochot_interval(struct device *dev,
2176 struct device_attribute *attr, char *buf)
2178 int nr = (to_sensor_dev_attr(attr))->index;
2179 struct lm93_data *data = lm93_update_device(dev);
2180 u8 tmp;
2181 if (nr==1)
2182 tmp = (data->prochot_interval & 0xf0) >> 4;
2183 else
2184 tmp = data->prochot_interval & 0x0f;
2185 return sprintf(buf,"%d\n",LM93_INTERVAL_FROM_REG(tmp));
2188 static ssize_t store_prochot_interval(struct device *dev,
2189 struct device_attribute *attr,
2190 const char *buf, size_t count)
2192 int nr = (to_sensor_dev_attr(attr))->index;
2193 struct i2c_client *client = to_i2c_client(dev);
2194 struct lm93_data *data = i2c_get_clientdata(client);
2195 u32 val = simple_strtoul(buf, NULL, 10);
2196 u8 tmp;
2198 mutex_lock(&data->update_lock);
2199 tmp = lm93_read_byte(client, LM93_REG_PROCHOT_INTERVAL);
2200 if (nr==1)
2201 tmp = (tmp & 0x0f) | (LM93_INTERVAL_TO_REG(val) << 4);
2202 else
2203 tmp = (tmp & 0xf0) | LM93_INTERVAL_TO_REG(val);
2204 data->prochot_interval = tmp;
2205 lm93_write_byte(client, LM93_REG_PROCHOT_INTERVAL, tmp);
2206 mutex_unlock(&data->update_lock);
2207 return count;
2210 static SENSOR_DEVICE_ATTR(prochot1_interval, S_IWUSR | S_IRUGO,
2211 show_prochot_interval, store_prochot_interval, 0);
2212 static SENSOR_DEVICE_ATTR(prochot2_interval, S_IWUSR | S_IRUGO,
2213 show_prochot_interval, store_prochot_interval, 1);
2215 static ssize_t show_prochot_override_duty_cycle(struct device *dev,
2216 struct device_attribute *attr,
2217 char *buf)
2219 struct lm93_data *data = lm93_update_device(dev);
2220 return sprintf(buf,"%d\n",data->prochot_override & 0x0f);
2223 static ssize_t store_prochot_override_duty_cycle(struct device *dev,
2224 struct device_attribute *attr,
2225 const char *buf, size_t count)
2227 struct i2c_client *client = to_i2c_client(dev);
2228 struct lm93_data *data = i2c_get_clientdata(client);
2229 u32 val = simple_strtoul(buf, NULL, 10);
2231 mutex_lock(&data->update_lock);
2232 data->prochot_override = (data->prochot_override & 0xf0) |
2233 SENSORS_LIMIT(val, 0, 15);
2234 lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE,
2235 data->prochot_override);
2236 mutex_unlock(&data->update_lock);
2237 return count;
2240 static DEVICE_ATTR(prochot_override_duty_cycle, S_IRUGO | S_IWUSR,
2241 show_prochot_override_duty_cycle,
2242 store_prochot_override_duty_cycle);
2244 static ssize_t show_prochot_short(struct device *dev,
2245 struct device_attribute *attr, char *buf)
2247 struct lm93_data *data = lm93_update_device(dev);
2248 return sprintf(buf,"%d\n",(data->config & 0x10) ? 1 : 0);
2251 static ssize_t store_prochot_short(struct device *dev,
2252 struct device_attribute *attr,
2253 const char *buf, size_t count)
2255 struct i2c_client *client = to_i2c_client(dev);
2256 struct lm93_data *data = i2c_get_clientdata(client);
2257 u32 val = simple_strtoul(buf, NULL, 10);
2259 mutex_lock(&data->update_lock);
2260 if (val)
2261 data->config |= 0x10;
2262 else
2263 data->config &= ~0x10;
2264 lm93_write_byte(client, LM93_REG_CONFIG, data->config);
2265 mutex_unlock(&data->update_lock);
2266 return count;
2269 static DEVICE_ATTR(prochot_short, S_IRUGO | S_IWUSR,
2270 show_prochot_short, store_prochot_short);
2272 static ssize_t show_vrdhot(struct device *dev, struct device_attribute *attr,
2273 char *buf)
2275 int nr = (to_sensor_dev_attr(attr))->index;
2276 struct lm93_data *data = lm93_update_device(dev);
2277 return sprintf(buf,"%d\n",
2278 data->block1.host_status_1 & (1 << (nr+4)) ? 1 : 0);
2281 static SENSOR_DEVICE_ATTR(vrdhot1, S_IRUGO, show_vrdhot, NULL, 0);
2282 static SENSOR_DEVICE_ATTR(vrdhot2, S_IRUGO, show_vrdhot, NULL, 1);
2284 static ssize_t show_gpio(struct device *dev, struct device_attribute *attr,
2285 char *buf)
2287 struct lm93_data *data = lm93_update_device(dev);
2288 return sprintf(buf,"%d\n",LM93_GPI_FROM_REG(data->gpi));
2291 static DEVICE_ATTR(gpio, S_IRUGO, show_gpio, NULL);
2293 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
2294 char *buf)
2296 struct lm93_data *data = lm93_update_device(dev);
2297 return sprintf(buf,"%d\n",LM93_ALARMS_FROM_REG(data->block1));
2300 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
2302 static struct attribute *lm93_attrs[] = {
2303 &sensor_dev_attr_in1_input.dev_attr.attr,
2304 &sensor_dev_attr_in2_input.dev_attr.attr,
2305 &sensor_dev_attr_in3_input.dev_attr.attr,
2306 &sensor_dev_attr_in4_input.dev_attr.attr,
2307 &sensor_dev_attr_in5_input.dev_attr.attr,
2308 &sensor_dev_attr_in6_input.dev_attr.attr,
2309 &sensor_dev_attr_in7_input.dev_attr.attr,
2310 &sensor_dev_attr_in8_input.dev_attr.attr,
2311 &sensor_dev_attr_in9_input.dev_attr.attr,
2312 &sensor_dev_attr_in10_input.dev_attr.attr,
2313 &sensor_dev_attr_in11_input.dev_attr.attr,
2314 &sensor_dev_attr_in12_input.dev_attr.attr,
2315 &sensor_dev_attr_in13_input.dev_attr.attr,
2316 &sensor_dev_attr_in14_input.dev_attr.attr,
2317 &sensor_dev_attr_in15_input.dev_attr.attr,
2318 &sensor_dev_attr_in16_input.dev_attr.attr,
2319 &sensor_dev_attr_in1_min.dev_attr.attr,
2320 &sensor_dev_attr_in2_min.dev_attr.attr,
2321 &sensor_dev_attr_in3_min.dev_attr.attr,
2322 &sensor_dev_attr_in4_min.dev_attr.attr,
2323 &sensor_dev_attr_in5_min.dev_attr.attr,
2324 &sensor_dev_attr_in6_min.dev_attr.attr,
2325 &sensor_dev_attr_in7_min.dev_attr.attr,
2326 &sensor_dev_attr_in8_min.dev_attr.attr,
2327 &sensor_dev_attr_in9_min.dev_attr.attr,
2328 &sensor_dev_attr_in10_min.dev_attr.attr,
2329 &sensor_dev_attr_in11_min.dev_attr.attr,
2330 &sensor_dev_attr_in12_min.dev_attr.attr,
2331 &sensor_dev_attr_in13_min.dev_attr.attr,
2332 &sensor_dev_attr_in14_min.dev_attr.attr,
2333 &sensor_dev_attr_in15_min.dev_attr.attr,
2334 &sensor_dev_attr_in16_min.dev_attr.attr,
2335 &sensor_dev_attr_in1_max.dev_attr.attr,
2336 &sensor_dev_attr_in2_max.dev_attr.attr,
2337 &sensor_dev_attr_in3_max.dev_attr.attr,
2338 &sensor_dev_attr_in4_max.dev_attr.attr,
2339 &sensor_dev_attr_in5_max.dev_attr.attr,
2340 &sensor_dev_attr_in6_max.dev_attr.attr,
2341 &sensor_dev_attr_in7_max.dev_attr.attr,
2342 &sensor_dev_attr_in8_max.dev_attr.attr,
2343 &sensor_dev_attr_in9_max.dev_attr.attr,
2344 &sensor_dev_attr_in10_max.dev_attr.attr,
2345 &sensor_dev_attr_in11_max.dev_attr.attr,
2346 &sensor_dev_attr_in12_max.dev_attr.attr,
2347 &sensor_dev_attr_in13_max.dev_attr.attr,
2348 &sensor_dev_attr_in14_max.dev_attr.attr,
2349 &sensor_dev_attr_in15_max.dev_attr.attr,
2350 &sensor_dev_attr_in16_max.dev_attr.attr,
2351 &sensor_dev_attr_temp1_input.dev_attr.attr,
2352 &sensor_dev_attr_temp2_input.dev_attr.attr,
2353 &sensor_dev_attr_temp3_input.dev_attr.attr,
2354 &sensor_dev_attr_temp1_min.dev_attr.attr,
2355 &sensor_dev_attr_temp2_min.dev_attr.attr,
2356 &sensor_dev_attr_temp3_min.dev_attr.attr,
2357 &sensor_dev_attr_temp1_max.dev_attr.attr,
2358 &sensor_dev_attr_temp2_max.dev_attr.attr,
2359 &sensor_dev_attr_temp3_max.dev_attr.attr,
2360 &sensor_dev_attr_temp1_auto_base.dev_attr.attr,
2361 &sensor_dev_attr_temp2_auto_base.dev_attr.attr,
2362 &sensor_dev_attr_temp3_auto_base.dev_attr.attr,
2363 &sensor_dev_attr_temp1_auto_boost.dev_attr.attr,
2364 &sensor_dev_attr_temp2_auto_boost.dev_attr.attr,
2365 &sensor_dev_attr_temp3_auto_boost.dev_attr.attr,
2366 &sensor_dev_attr_temp1_auto_boost_hyst.dev_attr.attr,
2367 &sensor_dev_attr_temp2_auto_boost_hyst.dev_attr.attr,
2368 &sensor_dev_attr_temp3_auto_boost_hyst.dev_attr.attr,
2369 &sensor_dev_attr_temp1_auto_offset1.dev_attr.attr,
2370 &sensor_dev_attr_temp1_auto_offset2.dev_attr.attr,
2371 &sensor_dev_attr_temp1_auto_offset3.dev_attr.attr,
2372 &sensor_dev_attr_temp1_auto_offset4.dev_attr.attr,
2373 &sensor_dev_attr_temp1_auto_offset5.dev_attr.attr,
2374 &sensor_dev_attr_temp1_auto_offset6.dev_attr.attr,
2375 &sensor_dev_attr_temp1_auto_offset7.dev_attr.attr,
2376 &sensor_dev_attr_temp1_auto_offset8.dev_attr.attr,
2377 &sensor_dev_attr_temp1_auto_offset9.dev_attr.attr,
2378 &sensor_dev_attr_temp1_auto_offset10.dev_attr.attr,
2379 &sensor_dev_attr_temp1_auto_offset11.dev_attr.attr,
2380 &sensor_dev_attr_temp1_auto_offset12.dev_attr.attr,
2381 &sensor_dev_attr_temp2_auto_offset1.dev_attr.attr,
2382 &sensor_dev_attr_temp2_auto_offset2.dev_attr.attr,
2383 &sensor_dev_attr_temp2_auto_offset3.dev_attr.attr,
2384 &sensor_dev_attr_temp2_auto_offset4.dev_attr.attr,
2385 &sensor_dev_attr_temp2_auto_offset5.dev_attr.attr,
2386 &sensor_dev_attr_temp2_auto_offset6.dev_attr.attr,
2387 &sensor_dev_attr_temp2_auto_offset7.dev_attr.attr,
2388 &sensor_dev_attr_temp2_auto_offset8.dev_attr.attr,
2389 &sensor_dev_attr_temp2_auto_offset9.dev_attr.attr,
2390 &sensor_dev_attr_temp2_auto_offset10.dev_attr.attr,
2391 &sensor_dev_attr_temp2_auto_offset11.dev_attr.attr,
2392 &sensor_dev_attr_temp2_auto_offset12.dev_attr.attr,
2393 &sensor_dev_attr_temp3_auto_offset1.dev_attr.attr,
2394 &sensor_dev_attr_temp3_auto_offset2.dev_attr.attr,
2395 &sensor_dev_attr_temp3_auto_offset3.dev_attr.attr,
2396 &sensor_dev_attr_temp3_auto_offset4.dev_attr.attr,
2397 &sensor_dev_attr_temp3_auto_offset5.dev_attr.attr,
2398 &sensor_dev_attr_temp3_auto_offset6.dev_attr.attr,
2399 &sensor_dev_attr_temp3_auto_offset7.dev_attr.attr,
2400 &sensor_dev_attr_temp3_auto_offset8.dev_attr.attr,
2401 &sensor_dev_attr_temp3_auto_offset9.dev_attr.attr,
2402 &sensor_dev_attr_temp3_auto_offset10.dev_attr.attr,
2403 &sensor_dev_attr_temp3_auto_offset11.dev_attr.attr,
2404 &sensor_dev_attr_temp3_auto_offset12.dev_attr.attr,
2405 &sensor_dev_attr_temp1_auto_pwm_min.dev_attr.attr,
2406 &sensor_dev_attr_temp2_auto_pwm_min.dev_attr.attr,
2407 &sensor_dev_attr_temp3_auto_pwm_min.dev_attr.attr,
2408 &sensor_dev_attr_temp1_auto_offset_hyst.dev_attr.attr,
2409 &sensor_dev_attr_temp2_auto_offset_hyst.dev_attr.attr,
2410 &sensor_dev_attr_temp3_auto_offset_hyst.dev_attr.attr,
2411 &sensor_dev_attr_fan1_input.dev_attr.attr,
2412 &sensor_dev_attr_fan2_input.dev_attr.attr,
2413 &sensor_dev_attr_fan3_input.dev_attr.attr,
2414 &sensor_dev_attr_fan4_input.dev_attr.attr,
2415 &sensor_dev_attr_fan1_min.dev_attr.attr,
2416 &sensor_dev_attr_fan2_min.dev_attr.attr,
2417 &sensor_dev_attr_fan3_min.dev_attr.attr,
2418 &sensor_dev_attr_fan4_min.dev_attr.attr,
2419 &sensor_dev_attr_fan1_smart_tach.dev_attr.attr,
2420 &sensor_dev_attr_fan2_smart_tach.dev_attr.attr,
2421 &sensor_dev_attr_fan3_smart_tach.dev_attr.attr,
2422 &sensor_dev_attr_fan4_smart_tach.dev_attr.attr,
2423 &sensor_dev_attr_pwm1.dev_attr.attr,
2424 &sensor_dev_attr_pwm2.dev_attr.attr,
2425 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2426 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
2427 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
2428 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
2429 &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
2430 &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
2431 &sensor_dev_attr_pwm1_auto_spinup_min.dev_attr.attr,
2432 &sensor_dev_attr_pwm2_auto_spinup_min.dev_attr.attr,
2433 &sensor_dev_attr_pwm1_auto_spinup_time.dev_attr.attr,
2434 &sensor_dev_attr_pwm2_auto_spinup_time.dev_attr.attr,
2435 &dev_attr_pwm_auto_prochot_ramp.attr,
2436 &dev_attr_pwm_auto_vrdhot_ramp.attr,
2437 &sensor_dev_attr_cpu0_vid.dev_attr.attr,
2438 &sensor_dev_attr_cpu1_vid.dev_attr.attr,
2439 &sensor_dev_attr_prochot1.dev_attr.attr,
2440 &sensor_dev_attr_prochot2.dev_attr.attr,
2441 &sensor_dev_attr_prochot1_avg.dev_attr.attr,
2442 &sensor_dev_attr_prochot2_avg.dev_attr.attr,
2443 &sensor_dev_attr_prochot1_max.dev_attr.attr,
2444 &sensor_dev_attr_prochot2_max.dev_attr.attr,
2445 &sensor_dev_attr_prochot1_override.dev_attr.attr,
2446 &sensor_dev_attr_prochot2_override.dev_attr.attr,
2447 &sensor_dev_attr_prochot1_interval.dev_attr.attr,
2448 &sensor_dev_attr_prochot2_interval.dev_attr.attr,
2449 &dev_attr_prochot_override_duty_cycle.attr,
2450 &dev_attr_prochot_short.attr,
2451 &sensor_dev_attr_vrdhot1.dev_attr.attr,
2452 &sensor_dev_attr_vrdhot2.dev_attr.attr,
2453 &dev_attr_gpio.attr,
2454 &dev_attr_alarms.attr,
2455 NULL
2458 static struct attribute_group lm93_attr_grp = {
2459 .attrs = lm93_attrs,
2462 static void lm93_init_client(struct i2c_client *client)
2464 int i;
2465 u8 reg;
2467 /* configure VID pin input thresholds */
2468 reg = lm93_read_byte(client, LM93_REG_GPI_VID_CTL);
2469 lm93_write_byte(client, LM93_REG_GPI_VID_CTL,
2470 reg | (vid_agtl ? 0x03 : 0x00));
2472 if (init) {
2473 /* enable #ALERT pin */
2474 reg = lm93_read_byte(client, LM93_REG_CONFIG);
2475 lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x08);
2477 /* enable ASF mode for BMC status registers */
2478 reg = lm93_read_byte(client, LM93_REG_STATUS_CONTROL);
2479 lm93_write_byte(client, LM93_REG_STATUS_CONTROL, reg | 0x02);
2481 /* set sleep state to S0 */
2482 lm93_write_byte(client, LM93_REG_SLEEP_CONTROL, 0);
2484 /* unmask #VRDHOT and dynamic VCCP (if nec) error events */
2485 reg = lm93_read_byte(client, LM93_REG_MISC_ERR_MASK);
2486 reg &= ~0x03;
2487 reg &= ~(vccp_limit_type[0] ? 0x10 : 0);
2488 reg &= ~(vccp_limit_type[1] ? 0x20 : 0);
2489 lm93_write_byte(client, LM93_REG_MISC_ERR_MASK, reg);
2492 /* start monitoring */
2493 reg = lm93_read_byte(client, LM93_REG_CONFIG);
2494 lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x01);
2496 /* spin until ready */
2497 for (i=0; i<20; i++) {
2498 msleep(10);
2499 if ((lm93_read_byte(client, LM93_REG_CONFIG) & 0x80) == 0x80)
2500 return;
2503 dev_warn(&client->dev,"timed out waiting for sensor "
2504 "chip to signal ready!\n");
2507 /* Return 0 if detection is successful, -ENODEV otherwise */
2508 static int lm93_detect(struct i2c_client *client, struct i2c_board_info *info)
2510 struct i2c_adapter *adapter = client->adapter;
2511 int mfr, ver;
2512 const char *name;
2514 if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN))
2515 return -ENODEV;
2517 /* detection */
2518 mfr = lm93_read_byte(client, LM93_REG_MFR_ID);
2519 if (mfr != 0x01) {
2520 dev_dbg(&adapter->dev,
2521 "detect failed, bad manufacturer id 0x%02x!\n", mfr);
2522 return -ENODEV;
2525 ver = lm93_read_byte(client, LM93_REG_VER);
2526 switch (ver) {
2527 case LM93_MFR_ID:
2528 case LM93_MFR_ID_PROTOTYPE:
2529 name = "lm93";
2530 break;
2531 case LM94_MFR_ID_2:
2532 case LM94_MFR_ID:
2533 case LM94_MFR_ID_PROTOTYPE:
2534 name = "lm94";
2535 break;
2536 default:
2537 dev_dbg(&adapter->dev,
2538 "detect failed, bad version id 0x%02x!\n", ver);
2539 return -ENODEV;
2542 strlcpy(info->type, name, I2C_NAME_SIZE);
2543 dev_dbg(&adapter->dev,"loading %s at %d,0x%02x\n",
2544 client->name, i2c_adapter_id(client->adapter),
2545 client->addr);
2547 return 0;
2550 static int lm93_probe(struct i2c_client *client,
2551 const struct i2c_device_id *id)
2553 struct lm93_data *data;
2554 int err, func;
2555 void (*update)(struct lm93_data *, struct i2c_client *);
2557 /* choose update routine based on bus capabilities */
2558 func = i2c_get_functionality(client->adapter);
2559 if (((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) &&
2560 (!disable_block)) {
2561 dev_dbg(&client->dev, "using SMBus block data transactions\n");
2562 update = lm93_update_client_full;
2563 } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) {
2564 dev_dbg(&client->dev, "disabled SMBus block data "
2565 "transactions\n");
2566 update = lm93_update_client_min;
2567 } else {
2568 dev_dbg(&client->dev, "detect failed, "
2569 "smbus byte and/or word data not supported!\n");
2570 err = -ENODEV;
2571 goto err_out;
2574 data = kzalloc(sizeof(struct lm93_data), GFP_KERNEL);
2575 if (!data) {
2576 dev_dbg(&client->dev, "out of memory!\n");
2577 err = -ENOMEM;
2578 goto err_out;
2580 i2c_set_clientdata(client, data);
2582 /* housekeeping */
2583 data->valid = 0;
2584 data->update = update;
2585 mutex_init(&data->update_lock);
2587 /* initialize the chip */
2588 lm93_init_client(client);
2590 err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp);
2591 if (err)
2592 goto err_free;
2594 /* Register hwmon driver class */
2595 data->hwmon_dev = hwmon_device_register(&client->dev);
2596 if ( !IS_ERR(data->hwmon_dev))
2597 return 0;
2599 err = PTR_ERR(data->hwmon_dev);
2600 dev_err(&client->dev, "error registering hwmon device.\n");
2601 sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp);
2602 err_free:
2603 kfree(data);
2604 err_out:
2605 return err;
2608 static int lm93_remove(struct i2c_client *client)
2610 struct lm93_data *data = i2c_get_clientdata(client);
2612 hwmon_device_unregister(data->hwmon_dev);
2613 sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp);
2615 kfree(data);
2616 return 0;
2619 static const struct i2c_device_id lm93_id[] = {
2620 { "lm93", 0 },
2621 { "lm94", 0 },
2624 MODULE_DEVICE_TABLE(i2c, lm93_id);
2626 static struct i2c_driver lm93_driver = {
2627 .class = I2C_CLASS_HWMON,
2628 .driver = {
2629 .name = "lm93",
2631 .probe = lm93_probe,
2632 .remove = lm93_remove,
2633 .id_table = lm93_id,
2634 .detect = lm93_detect,
2635 .address_list = normal_i2c,
2638 static int __init lm93_init(void)
2640 return i2c_add_driver(&lm93_driver);
2643 static void __exit lm93_exit(void)
2645 i2c_del_driver(&lm93_driver);
2648 MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, "
2649 "Hans J. Koch <hjk@hansjkoch.de>");
2650 MODULE_DESCRIPTION("LM93 driver");
2651 MODULE_LICENSE("GPL");
2653 module_init(lm93_init);
2654 module_exit(lm93_exit);