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@linutronix.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 */
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
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
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 /* SMBus capabilities */
139 #define LM93_SMBUS_FUNC_FULL (I2C_FUNC_SMBUS_BYTE_DATA | \
140 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA)
141 #define LM93_SMBUS_FUNC_MIN (I2C_FUNC_SMBUS_BYTE_DATA | \
142 I2C_FUNC_SMBUS_WORD_DATA)
144 /* Addresses to scan */
145 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
147 /* Insmod parameters */
148 I2C_CLIENT_INSMOD_1(lm93);
150 static int disable_block;
151 module_param(disable_block, bool, 0);
152 MODULE_PARM_DESC(disable_block,
153 "Set to non-zero to disable SMBus block data transactions.");
156 module_param(init, bool, 0);
157 MODULE_PARM_DESC(init, "Set to non-zero to force chip initialization.");
159 static int vccp_limit_type[2] = {0,0};
160 module_param_array(vccp_limit_type, int, NULL, 0);
161 MODULE_PARM_DESC(vccp_limit_type, "Configures in7 and in8 limit modes.");
164 module_param(vid_agtl, int, 0);
165 MODULE_PARM_DESC(vid_agtl, "Configures VID pin input thresholds.");
168 static struct i2c_driver lm93_driver;
170 /* LM93 BLOCK READ COMMANDS */
171 static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = {
186 /* ALARMS: SYSCTL format described further below
187 REG: 64 bits in 8 registers, as immediately below */
193 u8 p1_prochot_status;
194 u8 p2_prochot_status;
200 * Client-specific data
203 struct i2c_client client;
204 struct device *hwmon_dev;
206 struct mutex update_lock;
207 unsigned long last_updated; /* In jiffies */
209 /* client update function */
210 void (*update)(struct lm93_data *, struct i2c_client *);
212 char valid; /* !=0 if following fields are valid */
214 /* register values, arranged by block read groups */
215 struct block1_t block1;
217 /* temp1 - temp4: unfiltered readings
218 temp1 - temp2: filtered readings */
221 /* vin1 - vin16: readings */
224 /* prochot1 - prochot2: readings */
230 /* fan counts 1-4 => 14-bits, LE, *left* justified */
233 /* block6 has a lot of data we don't need */
239 /* vin1 - vin16: low and high limits */
245 /* fan count limits 1-4 => same format as block5 */
248 /* pwm control registers (2 pwms, 4 regs) */
251 /* auto/pwm base temp and offset temp registers */
257 /* master config register */
260 /* VID1 & VID2 => register format, 6-bits, right justified */
263 /* prochot1 - prochot2: limits */
266 /* vccp1 & vccp2 (in7 & in8): VID relative limits (register format) */
269 /* GPIO input state (register format, i.e. inverted) */
272 /* #PROCHOT override (register format) */
275 /* #PROCHOT intervals (register format) */
278 /* Fan Boost Temperatures (register format) */
281 /* Fan Boost Hysteresis (register format) */
284 /* Temperature Zone Min. PWM & Hysteresis (register format) */
285 u8 auto_pwm_min_hyst[2];
287 /* #PROCHOT & #VRDHOT PWM Ramp Control */
290 /* miscellaneous setup regs */
295 /* The two PWM CTL2 registers can read something other than what was
296 last written for the OVR_DC field (duty cycle override). So, we
297 save the user-commanded value here. */
302 REG: 6-bits, right justified, *always* using Intel VRM/VRD 10 */
303 static int LM93_VID_FROM_REG(u8 reg)
305 return vid_from_reg((reg & 0x3f), 100);
308 /* min, max, and nominal register values, per channel (u8) */
309 static const u8 lm93_vin_reg_min[16] = {
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae,
313 static const u8 lm93_vin_reg_max[16] = {
314 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
315 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1,
317 /* Values from the datasheet. They're here for documentation only.
318 static const u8 lm93_vin_reg_nom[16] = {
319 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
320 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0,
324 /* min, max, and nominal voltage readings, per channel (mV)*/
325 static const unsigned long lm93_vin_val_min[16] = {
326 0, 0, 0, 0, 0, 0, 0, 0,
327 0, 0, 0, 0, 0, 0, 0, 3000,
330 static const unsigned long lm93_vin_val_max[16] = {
331 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600,
332 4400, 6500, 3333, 2625, 1312, 1312, 1236, 3600,
334 /* Values from the datasheet. They're here for documentation only.
335 static const unsigned long lm93_vin_val_nom[16] = {
336 927, 927, 927, 1200, 1500, 1500, 1200, 1200,
337 3300, 5000, 2500, 1969, 984, 984, 309, 3300,
341 static unsigned LM93_IN_FROM_REG(int nr, u8 reg)
343 const long uV_max = lm93_vin_val_max[nr] * 1000;
344 const long uV_min = lm93_vin_val_min[nr] * 1000;
346 const long slope = (uV_max - uV_min) /
347 (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]);
348 const long intercept = uV_min - slope * lm93_vin_reg_min[nr];
350 return (slope * reg + intercept + 500) / 1000;
353 /* IN: mV, limits determined by channel nr
354 REG: scaling determined by channel nr */
355 static u8 LM93_IN_TO_REG(int nr, unsigned val)
358 const long mV = SENSORS_LIMIT(val,
359 lm93_vin_val_min[nr], lm93_vin_val_max[nr]);
361 /* try not to lose too much precision here */
362 const long uV = mV * 1000;
363 const long uV_max = lm93_vin_val_max[nr] * 1000;
364 const long uV_min = lm93_vin_val_min[nr] * 1000;
367 const long slope = (uV_max - uV_min) /
368 (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]);
369 const long intercept = uV_min - slope * lm93_vin_reg_min[nr];
371 u8 result = ((uV - intercept + (slope/2)) / slope);
372 result = SENSORS_LIMIT(result,
373 lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]);
377 /* vid in mV, upper == 0 indicates low limit, otherwise upper limit */
378 static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid)
380 const long uV_offset = upper ? (((reg >> 4 & 0x0f) + 1) * 12500) :
381 (((reg >> 0 & 0x0f) + 1) * -25000);
382 const long uV_vid = vid * 1000;
383 return (uV_vid + uV_offset + 5000) / 10000;
386 #define LM93_IN_MIN_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,0,vid)
387 #define LM93_IN_MAX_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,1,vid)
389 /* vid in mV , upper == 0 indicates low limit, otherwise upper limit
390 upper also determines which nibble of the register is returned
391 (the other nibble will be 0x0) */
392 static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid)
394 long uV_offset = vid * 1000 - val * 10000;
396 uV_offset = SENSORS_LIMIT(uV_offset, 12500, 200000);
397 return (u8)((uV_offset / 12500 - 1) << 4);
399 uV_offset = SENSORS_LIMIT(uV_offset, -400000, -25000);
400 return (u8)((uV_offset / -25000 - 1) << 0);
404 /* TEMP: 1/1000 degrees C (-128C to +127C)
405 REG: 1C/bit, two's complement */
406 static int LM93_TEMP_FROM_REG(u8 reg)
408 return (s8)reg * 1000;
411 #define LM93_TEMP_MIN (-128000)
412 #define LM93_TEMP_MAX ( 127000)
414 /* TEMP: 1/1000 degrees C (-128C to +127C)
415 REG: 1C/bit, two's complement */
416 static u8 LM93_TEMP_TO_REG(long temp)
418 int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX);
419 ntemp += (ntemp<0 ? -500 : 500);
420 return (u8)(ntemp / 1000);
423 /* Determine 4-bit temperature offset resolution */
424 static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr)
426 /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */
427 return sfc2 & (nr < 2 ? 0x10 : 0x20);
430 /* This function is common to all 4-bit temperature offsets
431 reg is 4 bits right justified
432 mode 0 => 1C/bit, mode !0 => 0.5C/bit */
433 static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode)
435 return (reg & 0x0f) * (mode ? 5 : 10);
438 #define LM93_TEMP_OFFSET_MIN ( 0)
439 #define LM93_TEMP_OFFSET_MAX0 (150)
440 #define LM93_TEMP_OFFSET_MAX1 ( 75)
442 /* This function is common to all 4-bit temperature offsets
443 returns 4 bits right justified
444 mode 0 => 1C/bit, mode !0 => 0.5C/bit */
445 static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode)
447 int factor = mode ? 5 : 10;
449 off = SENSORS_LIMIT(off, LM93_TEMP_OFFSET_MIN,
450 mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0);
451 return (u8)((off + factor/2) / factor);
455 static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode)
457 /* temp1-temp2 (nr=0,1) use lower nibble */
459 return LM93_TEMP_OFFSET_FROM_REG(reg & 0x0f, mode);
461 /* temp3-temp4 (nr=2,3) use upper nibble */
463 return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode);
466 /* TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero))
467 REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero)
469 static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode)
471 u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode);
473 /* temp1-temp2 (nr=0,1) use lower nibble */
475 return (old & 0xf0) | (new & 0x0f);
477 /* temp3-temp4 (nr=2,3) use upper nibble */
479 return (new << 4 & 0xf0) | (old & 0x0f);
482 static int LM93_AUTO_BOOST_HYST_FROM_REGS(struct lm93_data *data, int nr,
489 reg = data->boost_hyst[0] & 0x0f;
492 reg = data->boost_hyst[0] >> 4 & 0x0f;
495 reg = data->boost_hyst[1] & 0x0f;
499 reg = data->boost_hyst[1] >> 4 & 0x0f;
503 return LM93_TEMP_FROM_REG(data->boost[nr]) -
504 LM93_TEMP_OFFSET_FROM_REG(reg, mode);
507 static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst,
510 u8 reg = LM93_TEMP_OFFSET_TO_REG(
511 (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode);
515 reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f);
518 reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f);
521 reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f);
525 reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f);
532 /* PWM: 0-255 per sensors documentation
533 REG: 0-13 as mapped below... right justified */
534 typedef enum { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ } pwm_freq_t;
535 static int lm93_pwm_map[2][16] = {
537 0x00, /* 0.00% */ 0x40, /* 25.00% */
538 0x50, /* 31.25% */ 0x60, /* 37.50% */
539 0x70, /* 43.75% */ 0x80, /* 50.00% */
540 0x90, /* 56.25% */ 0xa0, /* 62.50% */
541 0xb0, /* 68.75% */ 0xc0, /* 75.00% */
542 0xd0, /* 81.25% */ 0xe0, /* 87.50% */
543 0xf0, /* 93.75% */ 0xff, /* 100.00% */
544 0xff, 0xff, /* 14, 15 are reserved and should never occur */
547 0x00, /* 0.00% */ 0x40, /* 25.00% */
548 0x49, /* 28.57% */ 0x52, /* 32.14% */
549 0x5b, /* 35.71% */ 0x64, /* 39.29% */
550 0x6d, /* 42.86% */ 0x76, /* 46.43% */
551 0x80, /* 50.00% */ 0x89, /* 53.57% */
552 0x92, /* 57.14% */ 0xb6, /* 71.43% */
553 0xdb, /* 85.71% */ 0xff, /* 100.00% */
554 0xff, 0xff, /* 14, 15 are reserved and should never occur */
558 static int LM93_PWM_FROM_REG(u8 reg, pwm_freq_t freq)
560 return lm93_pwm_map[freq][reg & 0x0f];
563 /* round up to nearest match */
564 static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq)
567 for (i = 0; i < 13; i++)
568 if (pwm <= lm93_pwm_map[freq][i])
571 /* can fall through with i==13 */
575 static int LM93_FAN_FROM_REG(u16 regs)
577 const u16 count = le16_to_cpu(regs) >> 2;
578 return count==0 ? -1 : count==0x3fff ? 0: 1350000 / count;
582 * RPM: (82.5 to 1350000)
583 * REG: 14-bits, LE, *left* justified
585 static u16 LM93_FAN_TO_REG(long rpm)
592 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
593 count = SENSORS_LIMIT((1350000 + rpm) / rpm, 1, 0x3ffe);
597 return cpu_to_le16(regs);
601 REG: 0-7 as mapped below */
602 static int lm93_pwm_freq_map[8] = {
603 22500, 96, 84, 72, 60, 48, 36, 12
606 static int LM93_PWM_FREQ_FROM_REG(u8 reg)
608 return lm93_pwm_freq_map[reg & 0x07];
611 /* round up to nearest match */
612 static u8 LM93_PWM_FREQ_TO_REG(int freq)
615 for (i = 7; i > 0; i--)
616 if (freq <= lm93_pwm_freq_map[i])
619 /* can fall through with i==0 */
623 /* TIME: 1/100 seconds
624 * REG: 0-7 as mapped below */
625 static int lm93_spinup_time_map[8] = {
626 0, 10, 25, 40, 70, 100, 200, 400,
629 static int LM93_SPINUP_TIME_FROM_REG(u8 reg)
631 return lm93_spinup_time_map[reg >> 5 & 0x07];
634 /* round up to nearest match */
635 static u8 LM93_SPINUP_TIME_TO_REG(int time)
638 for (i = 0; i < 7; i++)
639 if (time <= lm93_spinup_time_map[i])
642 /* can fall through with i==8 */
646 #define LM93_RAMP_MIN 0
647 #define LM93_RAMP_MAX 75
649 static int LM93_RAMP_FROM_REG(u8 reg)
651 return (reg & 0x0f) * 5;
654 /* RAMP: 1/100 seconds
655 REG: 50mS/bit 4-bits right justified */
656 static u8 LM93_RAMP_TO_REG(int ramp)
658 ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX);
659 return (u8)((ramp + 2) / 5);
662 /* PROCHOT: 0-255, 0 => 0%, 255 => > 96.6%
664 static u8 LM93_PROCHOT_TO_REG(long prochot)
666 prochot = SENSORS_LIMIT(prochot, 0, 255);
670 /* PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds)
671 * REG: 0-9 as mapped below */
672 static int lm93_interval_map[10] = {
673 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200,
676 static int LM93_INTERVAL_FROM_REG(u8 reg)
678 return lm93_interval_map[reg & 0x0f];
681 /* round up to nearest match */
682 static u8 LM93_INTERVAL_TO_REG(long interval)
685 for (i = 0; i < 9; i++)
686 if (interval <= lm93_interval_map[i])
689 /* can fall through with i==9 */
693 /* GPIO: 0-255, GPIO0 is LSB
695 static unsigned LM93_GPI_FROM_REG(u8 reg)
700 /* alarm bitmask definitions
701 The LM93 has nearly 64 bits of error status... I've pared that down to
702 what I think is a useful subset in order to fit it into 32 bits.
704 Especially note that the #VRD_HOT alarms are missing because we provide
705 that information as values in another sysfs file.
707 If libsensors is extended to support 64 bit values, this could be revisited.
709 #define LM93_ALARM_IN1 0x00000001
710 #define LM93_ALARM_IN2 0x00000002
711 #define LM93_ALARM_IN3 0x00000004
712 #define LM93_ALARM_IN4 0x00000008
713 #define LM93_ALARM_IN5 0x00000010
714 #define LM93_ALARM_IN6 0x00000020
715 #define LM93_ALARM_IN7 0x00000040
716 #define LM93_ALARM_IN8 0x00000080
717 #define LM93_ALARM_IN9 0x00000100
718 #define LM93_ALARM_IN10 0x00000200
719 #define LM93_ALARM_IN11 0x00000400
720 #define LM93_ALARM_IN12 0x00000800
721 #define LM93_ALARM_IN13 0x00001000
722 #define LM93_ALARM_IN14 0x00002000
723 #define LM93_ALARM_IN15 0x00004000
724 #define LM93_ALARM_IN16 0x00008000
725 #define LM93_ALARM_FAN1 0x00010000
726 #define LM93_ALARM_FAN2 0x00020000
727 #define LM93_ALARM_FAN3 0x00040000
728 #define LM93_ALARM_FAN4 0x00080000
729 #define LM93_ALARM_PH1_ERR 0x00100000
730 #define LM93_ALARM_PH2_ERR 0x00200000
731 #define LM93_ALARM_SCSI1_ERR 0x00400000
732 #define LM93_ALARM_SCSI2_ERR 0x00800000
733 #define LM93_ALARM_DVDDP1_ERR 0x01000000
734 #define LM93_ALARM_DVDDP2_ERR 0x02000000
735 #define LM93_ALARM_D1_ERR 0x04000000
736 #define LM93_ALARM_D2_ERR 0x08000000
737 #define LM93_ALARM_TEMP1 0x10000000
738 #define LM93_ALARM_TEMP2 0x20000000
739 #define LM93_ALARM_TEMP3 0x40000000
741 static unsigned LM93_ALARMS_FROM_REG(struct block1_t b1)
744 result = b1.host_status_2 & 0x3f;
746 if (vccp_limit_type[0])
747 result |= (b1.host_status_4 & 0x10) << 2;
749 result |= b1.host_status_2 & 0x40;
751 if (vccp_limit_type[1])
752 result |= (b1.host_status_4 & 0x20) << 2;
754 result |= b1.host_status_2 & 0x80;
756 result |= b1.host_status_3 << 8;
757 result |= (b1.fan_status & 0x0f) << 16;
758 result |= (b1.p1_prochot_status & 0x80) << 13;
759 result |= (b1.p2_prochot_status & 0x80) << 14;
760 result |= (b1.host_status_4 & 0xfc) << 20;
761 result |= (b1.host_status_1 & 0x07) << 28;
765 #define MAX_RETRIES 5
767 static u8 lm93_read_byte(struct i2c_client *client, u8 reg)
771 /* retry in case of read errors */
772 for (i=1; i<=MAX_RETRIES; i++) {
773 if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) {
776 dev_warn(&client->dev,"lm93: read byte data failed, "
777 "address 0x%02x.\n", reg);
783 /* <TODO> what to return in case of error? */
784 dev_err(&client->dev,"lm93: All read byte retries failed!!\n");
788 static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value)
792 /* <TODO> how to handle write errors? */
793 result = i2c_smbus_write_byte_data(client, reg, value);
796 dev_warn(&client->dev,"lm93: write byte data failed, "
797 "0x%02x at address 0x%02x.\n", value, reg);
802 static u16 lm93_read_word(struct i2c_client *client, u8 reg)
806 /* retry in case of read errors */
807 for (i=1; i<=MAX_RETRIES; i++) {
808 if ((value = i2c_smbus_read_word_data(client, reg)) >= 0) {
811 dev_warn(&client->dev,"lm93: read word data failed, "
812 "address 0x%02x.\n", reg);
818 /* <TODO> what to return in case of error? */
819 dev_err(&client->dev,"lm93: All read word retries failed!!\n");
823 static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value)
827 /* <TODO> how to handle write errors? */
828 result = i2c_smbus_write_word_data(client, reg, value);
831 dev_warn(&client->dev,"lm93: write word data failed, "
832 "0x%04x at address 0x%02x.\n", value, reg);
837 static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX];
840 read block data into values, retry if not expected length
841 fbn => index to lm93_block_read_cmds table
842 (Fixed Block Number - section 14.5.2 of LM93 datasheet)
844 static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values)
848 for (i = 1; i <= MAX_RETRIES; i++) {
849 result = i2c_smbus_read_block_data(client,
850 lm93_block_read_cmds[fbn].cmd, lm93_block_buffer);
852 if (result == lm93_block_read_cmds[fbn].len) {
855 dev_warn(&client->dev,"lm93: block read data failed, "
857 lm93_block_read_cmds[fbn].cmd);
862 if (result == lm93_block_read_cmds[fbn].len) {
863 memcpy(values,lm93_block_buffer,lm93_block_read_cmds[fbn].len);
865 /* <TODO> what to do in case of error? */
869 static struct lm93_data *lm93_update_device(struct device *dev)
871 struct i2c_client *client = to_i2c_client(dev);
872 struct lm93_data *data = i2c_get_clientdata(client);
873 const unsigned long interval = HZ + (HZ / 2);
875 mutex_lock(&data->update_lock);
877 if (time_after(jiffies, data->last_updated + interval) ||
880 data->update(data, client);
881 data->last_updated = jiffies;
885 mutex_unlock(&data->update_lock);
889 /* update routine for data that has no corresponding SMBus block command */
890 static void lm93_update_client_common(struct lm93_data *data,
891 struct i2c_client *client)
896 /* temp1 - temp4: limits */
897 for (i = 0; i < 4; i++) {
898 data->temp_lim[i].min =
899 lm93_read_byte(client, LM93_REG_TEMP_MIN(i));
900 data->temp_lim[i].max =
901 lm93_read_byte(client, LM93_REG_TEMP_MAX(i));
904 /* config register */
905 data->config = lm93_read_byte(client, LM93_REG_CONFIG);
907 /* vid1 - vid2: values */
908 for (i = 0; i < 2; i++)
909 data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i));
911 /* prochot1 - prochot2: limits */
912 for (i = 0; i < 2; i++)
913 data->prochot_max[i] = lm93_read_byte(client,
914 LM93_REG_PROCHOT_MAX(i));
916 /* vccp1 - vccp2: VID relative limits */
917 for (i = 0; i < 2; i++)
918 data->vccp_limits[i] = lm93_read_byte(client,
919 LM93_REG_VCCP_LIMIT_OFF(i));
921 /* GPIO input state */
922 data->gpi = lm93_read_byte(client, LM93_REG_GPI);
924 /* #PROCHOT override state */
925 data->prochot_override = lm93_read_byte(client,
926 LM93_REG_PROCHOT_OVERRIDE);
928 /* #PROCHOT intervals */
929 data->prochot_interval = lm93_read_byte(client,
930 LM93_REG_PROCHOT_INTERVAL);
932 /* Fan Boost Termperature registers */
933 for (i = 0; i < 4; i++)
934 data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i));
936 /* Fan Boost Temperature Hyst. registers */
937 data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12);
938 data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34);
940 /* Temperature Zone Min. PWM & Hysteresis registers */
941 data->auto_pwm_min_hyst[0] =
942 lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_12);
943 data->auto_pwm_min_hyst[1] =
944 lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_34);
946 /* #PROCHOT & #VRDHOT PWM Ramp Control register */
947 data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
949 /* misc setup registers */
950 data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1);
951 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
952 data->sf_tach_to_pwm = lm93_read_byte(client,
953 LM93_REG_SF_TACH_TO_PWM);
955 /* write back alarm values to clear */
956 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++)
957 lm93_write_byte(client, LM93_REG_HOST_ERROR_1 + i, *(ptr + i));
960 /* update routine which uses SMBus block data commands */
961 static void lm93_update_client_full(struct lm93_data *data,
962 struct i2c_client *client)
964 dev_dbg(&client->dev,"starting device update (block data enabled)\n");
966 /* in1 - in16: values & limits */
967 lm93_read_block(client, 3, (u8 *)(data->block3));
968 lm93_read_block(client, 7, (u8 *)(data->block7));
970 /* temp1 - temp4: values */
971 lm93_read_block(client, 2, (u8 *)(data->block2));
973 /* prochot1 - prochot2: values */
974 lm93_read_block(client, 4, (u8 *)(data->block4));
976 /* fan1 - fan4: values & limits */
977 lm93_read_block(client, 5, (u8 *)(data->block5));
978 lm93_read_block(client, 8, (u8 *)(data->block8));
980 /* pmw control registers */
981 lm93_read_block(client, 9, (u8 *)(data->block9));
984 lm93_read_block(client, 1, (u8 *)(&data->block1));
986 /* auto/pwm registers */
987 lm93_read_block(client, 10, (u8 *)(&data->block10));
989 lm93_update_client_common(data, client);
992 /* update routine which uses SMBus byte/word data commands only */
993 static void lm93_update_client_min(struct lm93_data *data,
994 struct i2c_client *client)
999 dev_dbg(&client->dev,"starting device update (block data disabled)\n");
1001 /* in1 - in16: values & limits */
1002 for (i = 0; i < 16; i++) {
1004 lm93_read_byte(client, LM93_REG_IN(i));
1005 data->block7[i].min =
1006 lm93_read_byte(client, LM93_REG_IN_MIN(i));
1007 data->block7[i].max =
1008 lm93_read_byte(client, LM93_REG_IN_MAX(i));
1011 /* temp1 - temp4: values */
1012 for (i = 0; i < 4; i++) {
1014 lm93_read_byte(client, LM93_REG_TEMP(i));
1017 /* prochot1 - prochot2: values */
1018 for (i = 0; i < 2; i++) {
1019 data->block4[i].cur =
1020 lm93_read_byte(client, LM93_REG_PROCHOT_CUR(i));
1021 data->block4[i].avg =
1022 lm93_read_byte(client, LM93_REG_PROCHOT_AVG(i));
1025 /* fan1 - fan4: values & limits */
1026 for (i = 0; i < 4; i++) {
1028 lm93_read_word(client, LM93_REG_FAN(i));
1030 lm93_read_word(client, LM93_REG_FAN_MIN(i));
1033 /* pwm control registers */
1034 for (i = 0; i < 2; i++) {
1035 for (j = 0; j < 4; j++) {
1036 data->block9[i][j] =
1037 lm93_read_byte(client, LM93_REG_PWM_CTL(i,j));
1042 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) {
1044 lm93_read_byte(client, LM93_REG_HOST_ERROR_1 + i);
1047 /* auto/pwm (base temp) registers */
1048 for (i = 0; i < 4; i++) {
1049 data->block10.base[i] =
1050 lm93_read_byte(client, LM93_REG_TEMP_BASE(i));
1053 /* auto/pwm (offset temp) registers */
1054 for (i = 0; i < 12; i++) {
1055 data->block10.offset[i] =
1056 lm93_read_byte(client, LM93_REG_TEMP_OFFSET(i));
1059 lm93_update_client_common(data, client);
1062 /* following are the sysfs callback functions */
1063 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
1066 int nr = (to_sensor_dev_attr(attr))->index;
1068 struct lm93_data *data = lm93_update_device(dev);
1069 return sprintf(buf, "%d\n", LM93_IN_FROM_REG(nr, data->block3[nr]));
1072 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 0);
1073 static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 1);
1074 static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 2);
1075 static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 3);
1076 static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 4);
1077 static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 5);
1078 static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 6);
1079 static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 7);
1080 static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_in, NULL, 8);
1081 static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_in, NULL, 9);
1082 static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_in, NULL, 10);
1083 static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_in, NULL, 11);
1084 static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_in, NULL, 12);
1085 static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, show_in, NULL, 13);
1086 static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, show_in, NULL, 14);
1087 static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in, NULL, 15);
1089 static ssize_t show_in_min(struct device *dev,
1090 struct device_attribute *attr, char *buf)
1092 int nr = (to_sensor_dev_attr(attr))->index;
1093 struct lm93_data *data = lm93_update_device(dev);
1097 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1098 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1099 rc = LM93_IN_MIN_FROM_REG(data->vccp_limits[vccp], vid);
1102 rc = LM93_IN_FROM_REG(nr, data->block7[nr].min); \
1104 return sprintf(buf, "%ld\n", rc); \
1107 static ssize_t store_in_min(struct device *dev, struct device_attribute *attr,
1108 const char *buf, size_t count)
1110 int nr = (to_sensor_dev_attr(attr))->index;
1111 struct i2c_client *client = to_i2c_client(dev);
1112 struct lm93_data *data = i2c_get_clientdata(client);
1113 u32 val = simple_strtoul(buf, NULL, 10);
1117 mutex_lock(&data->update_lock);
1118 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1119 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1120 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0xf0) |
1121 LM93_IN_REL_TO_REG(val, 0, vid);
1122 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1123 data->vccp_limits[vccp]);
1126 data->block7[nr].min = LM93_IN_TO_REG(nr,val);
1127 lm93_write_byte(client, LM93_REG_IN_MIN(nr),
1128 data->block7[nr].min);
1130 mutex_unlock(&data->update_lock);
1134 static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
1135 show_in_min, store_in_min, 0);
1136 static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
1137 show_in_min, store_in_min, 1);
1138 static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
1139 show_in_min, store_in_min, 2);
1140 static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
1141 show_in_min, store_in_min, 3);
1142 static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
1143 show_in_min, store_in_min, 4);
1144 static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
1145 show_in_min, store_in_min, 5);
1146 static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO,
1147 show_in_min, store_in_min, 6);
1148 static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO,
1149 show_in_min, store_in_min, 7);
1150 static SENSOR_DEVICE_ATTR(in9_min, S_IWUSR | S_IRUGO,
1151 show_in_min, store_in_min, 8);
1152 static SENSOR_DEVICE_ATTR(in10_min, S_IWUSR | S_IRUGO,
1153 show_in_min, store_in_min, 9);
1154 static SENSOR_DEVICE_ATTR(in11_min, S_IWUSR | S_IRUGO,
1155 show_in_min, store_in_min, 10);
1156 static SENSOR_DEVICE_ATTR(in12_min, S_IWUSR | S_IRUGO,
1157 show_in_min, store_in_min, 11);
1158 static SENSOR_DEVICE_ATTR(in13_min, S_IWUSR | S_IRUGO,
1159 show_in_min, store_in_min, 12);
1160 static SENSOR_DEVICE_ATTR(in14_min, S_IWUSR | S_IRUGO,
1161 show_in_min, store_in_min, 13);
1162 static SENSOR_DEVICE_ATTR(in15_min, S_IWUSR | S_IRUGO,
1163 show_in_min, store_in_min, 14);
1164 static SENSOR_DEVICE_ATTR(in16_min, S_IWUSR | S_IRUGO,
1165 show_in_min, store_in_min, 15);
1167 static ssize_t show_in_max(struct device *dev,
1168 struct device_attribute *attr, char *buf)
1170 int nr = (to_sensor_dev_attr(attr))->index;
1171 struct lm93_data *data = lm93_update_device(dev);
1175 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1176 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1177 rc = LM93_IN_MAX_FROM_REG(data->vccp_limits[vccp],vid);
1180 rc = LM93_IN_FROM_REG(nr,data->block7[nr].max); \
1182 return sprintf(buf,"%ld\n",rc); \
1185 static ssize_t store_in_max(struct device *dev, struct device_attribute *attr,
1186 const char *buf, size_t count)
1188 int nr = (to_sensor_dev_attr(attr))->index;
1189 struct i2c_client *client = to_i2c_client(dev);
1190 struct lm93_data *data = i2c_get_clientdata(client);
1191 u32 val = simple_strtoul(buf, NULL, 10);
1195 mutex_lock(&data->update_lock);
1196 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) {
1197 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1198 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0x0f) |
1199 LM93_IN_REL_TO_REG(val, 1, vid);
1200 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1201 data->vccp_limits[vccp]);
1204 data->block7[nr].max = LM93_IN_TO_REG(nr,val);
1205 lm93_write_byte(client, LM93_REG_IN_MAX(nr),
1206 data->block7[nr].max);
1208 mutex_unlock(&data->update_lock);
1212 static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
1213 show_in_max, store_in_max, 0);
1214 static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
1215 show_in_max, store_in_max, 1);
1216 static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
1217 show_in_max, store_in_max, 2);
1218 static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
1219 show_in_max, store_in_max, 3);
1220 static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
1221 show_in_max, store_in_max, 4);
1222 static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
1223 show_in_max, store_in_max, 5);
1224 static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO,
1225 show_in_max, store_in_max, 6);
1226 static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO,
1227 show_in_max, store_in_max, 7);
1228 static SENSOR_DEVICE_ATTR(in9_max, S_IWUSR | S_IRUGO,
1229 show_in_max, store_in_max, 8);
1230 static SENSOR_DEVICE_ATTR(in10_max, S_IWUSR | S_IRUGO,
1231 show_in_max, store_in_max, 9);
1232 static SENSOR_DEVICE_ATTR(in11_max, S_IWUSR | S_IRUGO,
1233 show_in_max, store_in_max, 10);
1234 static SENSOR_DEVICE_ATTR(in12_max, S_IWUSR | S_IRUGO,
1235 show_in_max, store_in_max, 11);
1236 static SENSOR_DEVICE_ATTR(in13_max, S_IWUSR | S_IRUGO,
1237 show_in_max, store_in_max, 12);
1238 static SENSOR_DEVICE_ATTR(in14_max, S_IWUSR | S_IRUGO,
1239 show_in_max, store_in_max, 13);
1240 static SENSOR_DEVICE_ATTR(in15_max, S_IWUSR | S_IRUGO,
1241 show_in_max, store_in_max, 14);
1242 static SENSOR_DEVICE_ATTR(in16_max, S_IWUSR | S_IRUGO,
1243 show_in_max, store_in_max, 15);
1245 static ssize_t show_temp(struct device *dev,
1246 struct device_attribute *attr, char *buf)
1248 int nr = (to_sensor_dev_attr(attr))->index;
1249 struct lm93_data *data = lm93_update_device(dev);
1250 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block2[nr]));
1253 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
1254 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
1255 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
1257 static ssize_t show_temp_min(struct device *dev,
1258 struct device_attribute *attr, char *buf)
1260 int nr = (to_sensor_dev_attr(attr))->index;
1261 struct lm93_data *data = lm93_update_device(dev);
1262 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].min));
1265 static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr,
1266 const char *buf, size_t count)
1268 int nr = (to_sensor_dev_attr(attr))->index;
1269 struct i2c_client *client = to_i2c_client(dev);
1270 struct lm93_data *data = i2c_get_clientdata(client);
1271 long val = simple_strtol(buf, NULL, 10);
1273 mutex_lock(&data->update_lock);
1274 data->temp_lim[nr].min = LM93_TEMP_TO_REG(val);
1275 lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), data->temp_lim[nr].min);
1276 mutex_unlock(&data->update_lock);
1280 static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO,
1281 show_temp_min, store_temp_min, 0);
1282 static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO,
1283 show_temp_min, store_temp_min, 1);
1284 static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO,
1285 show_temp_min, store_temp_min, 2);
1287 static ssize_t show_temp_max(struct device *dev,
1288 struct device_attribute *attr, char *buf)
1290 int nr = (to_sensor_dev_attr(attr))->index;
1291 struct lm93_data *data = lm93_update_device(dev);
1292 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].max));
1295 static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr,
1296 const char *buf, size_t count)
1298 int nr = (to_sensor_dev_attr(attr))->index;
1299 struct i2c_client *client = to_i2c_client(dev);
1300 struct lm93_data *data = i2c_get_clientdata(client);
1301 long val = simple_strtol(buf, NULL, 10);
1303 mutex_lock(&data->update_lock);
1304 data->temp_lim[nr].max = LM93_TEMP_TO_REG(val);
1305 lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), data->temp_lim[nr].max);
1306 mutex_unlock(&data->update_lock);
1310 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
1311 show_temp_max, store_temp_max, 0);
1312 static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO,
1313 show_temp_max, store_temp_max, 1);
1314 static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO,
1315 show_temp_max, store_temp_max, 2);
1317 static ssize_t show_temp_auto_base(struct device *dev,
1318 struct device_attribute *attr, char *buf)
1320 int nr = (to_sensor_dev_attr(attr))->index;
1321 struct lm93_data *data = lm93_update_device(dev);
1322 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block10.base[nr]));
1325 static ssize_t store_temp_auto_base(struct device *dev,
1326 struct device_attribute *attr,
1327 const char *buf, size_t count)
1329 int nr = (to_sensor_dev_attr(attr))->index;
1330 struct i2c_client *client = to_i2c_client(dev);
1331 struct lm93_data *data = i2c_get_clientdata(client);
1332 long val = simple_strtol(buf, NULL, 10);
1334 mutex_lock(&data->update_lock);
1335 data->block10.base[nr] = LM93_TEMP_TO_REG(val);
1336 lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), data->block10.base[nr]);
1337 mutex_unlock(&data->update_lock);
1341 static SENSOR_DEVICE_ATTR(temp1_auto_base, S_IWUSR | S_IRUGO,
1342 show_temp_auto_base, store_temp_auto_base, 0);
1343 static SENSOR_DEVICE_ATTR(temp2_auto_base, S_IWUSR | S_IRUGO,
1344 show_temp_auto_base, store_temp_auto_base, 1);
1345 static SENSOR_DEVICE_ATTR(temp3_auto_base, S_IWUSR | S_IRUGO,
1346 show_temp_auto_base, store_temp_auto_base, 2);
1348 static ssize_t show_temp_auto_boost(struct device *dev,
1349 struct device_attribute *attr,char *buf)
1351 int nr = (to_sensor_dev_attr(attr))->index;
1352 struct lm93_data *data = lm93_update_device(dev);
1353 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->boost[nr]));
1356 static ssize_t store_temp_auto_boost(struct device *dev,
1357 struct device_attribute *attr,
1358 const char *buf, size_t count)
1360 int nr = (to_sensor_dev_attr(attr))->index;
1361 struct i2c_client *client = to_i2c_client(dev);
1362 struct lm93_data *data = i2c_get_clientdata(client);
1363 long val = simple_strtol(buf, NULL, 10);
1365 mutex_lock(&data->update_lock);
1366 data->boost[nr] = LM93_TEMP_TO_REG(val);
1367 lm93_write_byte(client, LM93_REG_BOOST(nr), data->boost[nr]);
1368 mutex_unlock(&data->update_lock);
1372 static SENSOR_DEVICE_ATTR(temp1_auto_boost, S_IWUSR | S_IRUGO,
1373 show_temp_auto_boost, store_temp_auto_boost, 0);
1374 static SENSOR_DEVICE_ATTR(temp2_auto_boost, S_IWUSR | S_IRUGO,
1375 show_temp_auto_boost, store_temp_auto_boost, 1);
1376 static SENSOR_DEVICE_ATTR(temp3_auto_boost, S_IWUSR | S_IRUGO,
1377 show_temp_auto_boost, store_temp_auto_boost, 2);
1379 static ssize_t show_temp_auto_boost_hyst(struct device *dev,
1380 struct device_attribute *attr,
1383 int nr = (to_sensor_dev_attr(attr))->index;
1384 struct lm93_data *data = lm93_update_device(dev);
1385 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1386 return sprintf(buf,"%d\n",
1387 LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode));
1390 static ssize_t store_temp_auto_boost_hyst(struct device *dev,
1391 struct device_attribute *attr,
1392 const char *buf, size_t count)
1394 int nr = (to_sensor_dev_attr(attr))->index;
1395 struct i2c_client *client = to_i2c_client(dev);
1396 struct lm93_data *data = i2c_get_clientdata(client);
1397 u32 val = simple_strtoul(buf, NULL, 10);
1399 mutex_lock(&data->update_lock);
1400 /* force 0.5C/bit mode */
1401 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1402 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1403 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1404 data->boost_hyst[nr/2] = LM93_AUTO_BOOST_HYST_TO_REG(data, val, nr, 1);
1405 lm93_write_byte(client, LM93_REG_BOOST_HYST(nr),
1406 data->boost_hyst[nr/2]);
1407 mutex_unlock(&data->update_lock);
1411 static SENSOR_DEVICE_ATTR(temp1_auto_boost_hyst, S_IWUSR | S_IRUGO,
1412 show_temp_auto_boost_hyst,
1413 store_temp_auto_boost_hyst, 0);
1414 static SENSOR_DEVICE_ATTR(temp2_auto_boost_hyst, S_IWUSR | S_IRUGO,
1415 show_temp_auto_boost_hyst,
1416 store_temp_auto_boost_hyst, 1);
1417 static SENSOR_DEVICE_ATTR(temp3_auto_boost_hyst, S_IWUSR | S_IRUGO,
1418 show_temp_auto_boost_hyst,
1419 store_temp_auto_boost_hyst, 2);
1421 static ssize_t show_temp_auto_offset(struct device *dev,
1422 struct device_attribute *attr, char *buf)
1424 struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr);
1425 int nr = s_attr->index;
1426 int ofs = s_attr->nr;
1427 struct lm93_data *data = lm93_update_device(dev);
1428 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1429 return sprintf(buf,"%d\n",
1430 LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs],
1434 static ssize_t store_temp_auto_offset(struct device *dev,
1435 struct device_attribute *attr,
1436 const char *buf, size_t count)
1438 struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr);
1439 int nr = s_attr->index;
1440 int ofs = s_attr->nr;
1441 struct i2c_client *client = to_i2c_client(dev);
1442 struct lm93_data *data = i2c_get_clientdata(client);
1443 u32 val = simple_strtoul(buf, NULL, 10);
1445 mutex_lock(&data->update_lock);
1446 /* force 0.5C/bit mode */
1447 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1448 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1449 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1450 data->block10.offset[ofs] = LM93_TEMP_AUTO_OFFSET_TO_REG(
1451 data->block10.offset[ofs], val, nr, 1);
1452 lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ofs),
1453 data->block10.offset[ofs]);
1454 mutex_unlock(&data->update_lock);
1458 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset1, S_IWUSR | S_IRUGO,
1459 show_temp_auto_offset, store_temp_auto_offset, 0, 0);
1460 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset2, S_IWUSR | S_IRUGO,
1461 show_temp_auto_offset, store_temp_auto_offset, 1, 0);
1462 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset3, S_IWUSR | S_IRUGO,
1463 show_temp_auto_offset, store_temp_auto_offset, 2, 0);
1464 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset4, S_IWUSR | S_IRUGO,
1465 show_temp_auto_offset, store_temp_auto_offset, 3, 0);
1466 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset5, S_IWUSR | S_IRUGO,
1467 show_temp_auto_offset, store_temp_auto_offset, 4, 0);
1468 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset6, S_IWUSR | S_IRUGO,
1469 show_temp_auto_offset, store_temp_auto_offset, 5, 0);
1470 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset7, S_IWUSR | S_IRUGO,
1471 show_temp_auto_offset, store_temp_auto_offset, 6, 0);
1472 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset8, S_IWUSR | S_IRUGO,
1473 show_temp_auto_offset, store_temp_auto_offset, 7, 0);
1474 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset9, S_IWUSR | S_IRUGO,
1475 show_temp_auto_offset, store_temp_auto_offset, 8, 0);
1476 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset10, S_IWUSR | S_IRUGO,
1477 show_temp_auto_offset, store_temp_auto_offset, 9, 0);
1478 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset11, S_IWUSR | S_IRUGO,
1479 show_temp_auto_offset, store_temp_auto_offset, 10, 0);
1480 static SENSOR_DEVICE_ATTR_2(temp1_auto_offset12, S_IWUSR | S_IRUGO,
1481 show_temp_auto_offset, store_temp_auto_offset, 11, 0);
1482 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset1, S_IWUSR | S_IRUGO,
1483 show_temp_auto_offset, store_temp_auto_offset, 0, 1);
1484 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset2, S_IWUSR | S_IRUGO,
1485 show_temp_auto_offset, store_temp_auto_offset, 1, 1);
1486 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset3, S_IWUSR | S_IRUGO,
1487 show_temp_auto_offset, store_temp_auto_offset, 2, 1);
1488 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset4, S_IWUSR | S_IRUGO,
1489 show_temp_auto_offset, store_temp_auto_offset, 3, 1);
1490 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset5, S_IWUSR | S_IRUGO,
1491 show_temp_auto_offset, store_temp_auto_offset, 4, 1);
1492 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset6, S_IWUSR | S_IRUGO,
1493 show_temp_auto_offset, store_temp_auto_offset, 5, 1);
1494 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset7, S_IWUSR | S_IRUGO,
1495 show_temp_auto_offset, store_temp_auto_offset, 6, 1);
1496 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset8, S_IWUSR | S_IRUGO,
1497 show_temp_auto_offset, store_temp_auto_offset, 7, 1);
1498 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset9, S_IWUSR | S_IRUGO,
1499 show_temp_auto_offset, store_temp_auto_offset, 8, 1);
1500 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset10, S_IWUSR | S_IRUGO,
1501 show_temp_auto_offset, store_temp_auto_offset, 9, 1);
1502 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset11, S_IWUSR | S_IRUGO,
1503 show_temp_auto_offset, store_temp_auto_offset, 10, 1);
1504 static SENSOR_DEVICE_ATTR_2(temp2_auto_offset12, S_IWUSR | S_IRUGO,
1505 show_temp_auto_offset, store_temp_auto_offset, 11, 1);
1506 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset1, S_IWUSR | S_IRUGO,
1507 show_temp_auto_offset, store_temp_auto_offset, 0, 2);
1508 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset2, S_IWUSR | S_IRUGO,
1509 show_temp_auto_offset, store_temp_auto_offset, 1, 2);
1510 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset3, S_IWUSR | S_IRUGO,
1511 show_temp_auto_offset, store_temp_auto_offset, 2, 2);
1512 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset4, S_IWUSR | S_IRUGO,
1513 show_temp_auto_offset, store_temp_auto_offset, 3, 2);
1514 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset5, S_IWUSR | S_IRUGO,
1515 show_temp_auto_offset, store_temp_auto_offset, 4, 2);
1516 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset6, S_IWUSR | S_IRUGO,
1517 show_temp_auto_offset, store_temp_auto_offset, 5, 2);
1518 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset7, S_IWUSR | S_IRUGO,
1519 show_temp_auto_offset, store_temp_auto_offset, 6, 2);
1520 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset8, S_IWUSR | S_IRUGO,
1521 show_temp_auto_offset, store_temp_auto_offset, 7, 2);
1522 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset9, S_IWUSR | S_IRUGO,
1523 show_temp_auto_offset, store_temp_auto_offset, 8, 2);
1524 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset10, S_IWUSR | S_IRUGO,
1525 show_temp_auto_offset, store_temp_auto_offset, 9, 2);
1526 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset11, S_IWUSR | S_IRUGO,
1527 show_temp_auto_offset, store_temp_auto_offset, 10, 2);
1528 static SENSOR_DEVICE_ATTR_2(temp3_auto_offset12, S_IWUSR | S_IRUGO,
1529 show_temp_auto_offset, store_temp_auto_offset, 11, 2);
1531 static ssize_t show_temp_auto_pwm_min(struct device *dev,
1532 struct device_attribute *attr, char *buf)
1534 int nr = (to_sensor_dev_attr(attr))->index;
1536 struct lm93_data *data = lm93_update_device(dev);
1537 reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f;
1538 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1539 return sprintf(buf,"%d\n",LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ?
1540 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));
1543 static ssize_t store_temp_auto_pwm_min(struct device *dev,
1544 struct device_attribute *attr,
1545 const char *buf, size_t count)
1547 int nr = (to_sensor_dev_attr(attr))->index;
1548 struct i2c_client *client = to_i2c_client(dev);
1549 struct lm93_data *data = i2c_get_clientdata(client);
1550 u32 val = simple_strtoul(buf, NULL, 10);
1553 mutex_lock(&data->update_lock);
1554 reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr));
1555 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4));
1556 reg = (reg & 0x0f) |
1557 LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1558 LM93_PWM_MAP_LO_FREQ :
1559 LM93_PWM_MAP_HI_FREQ) << 4;
1560 data->auto_pwm_min_hyst[nr/2] = reg;
1561 lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg);
1562 mutex_unlock(&data->update_lock);
1566 static SENSOR_DEVICE_ATTR(temp1_auto_pwm_min, S_IWUSR | S_IRUGO,
1567 show_temp_auto_pwm_min,
1568 store_temp_auto_pwm_min, 0);
1569 static SENSOR_DEVICE_ATTR(temp2_auto_pwm_min, S_IWUSR | S_IRUGO,
1570 show_temp_auto_pwm_min,
1571 store_temp_auto_pwm_min, 1);
1572 static SENSOR_DEVICE_ATTR(temp3_auto_pwm_min, S_IWUSR | S_IRUGO,
1573 show_temp_auto_pwm_min,
1574 store_temp_auto_pwm_min, 2);
1576 static ssize_t show_temp_auto_offset_hyst(struct device *dev,
1577 struct device_attribute *attr, char *buf)
1579 int nr = (to_sensor_dev_attr(attr))->index;
1580 struct lm93_data *data = lm93_update_device(dev);
1581 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1582 return sprintf(buf,"%d\n",LM93_TEMP_OFFSET_FROM_REG(
1583 data->auto_pwm_min_hyst[nr/2], mode));
1586 static ssize_t store_temp_auto_offset_hyst(struct device *dev,
1587 struct device_attribute *attr,
1588 const char *buf, size_t count)
1590 int nr = (to_sensor_dev_attr(attr))->index;
1591 struct i2c_client *client = to_i2c_client(dev);
1592 struct lm93_data *data = i2c_get_clientdata(client);
1593 u32 val = simple_strtoul(buf, NULL, 10);
1596 mutex_lock(&data->update_lock);
1597 /* force 0.5C/bit mode */
1598 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1599 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1600 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1601 reg = data->auto_pwm_min_hyst[nr/2];
1602 reg = (reg & 0xf0) | (LM93_TEMP_OFFSET_TO_REG(val, 1) & 0x0f);
1603 data->auto_pwm_min_hyst[nr/2] = reg;
1604 lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg);
1605 mutex_unlock(&data->update_lock);
1609 static SENSOR_DEVICE_ATTR(temp1_auto_offset_hyst, S_IWUSR | S_IRUGO,
1610 show_temp_auto_offset_hyst,
1611 store_temp_auto_offset_hyst, 0);
1612 static SENSOR_DEVICE_ATTR(temp2_auto_offset_hyst, S_IWUSR | S_IRUGO,
1613 show_temp_auto_offset_hyst,
1614 store_temp_auto_offset_hyst, 1);
1615 static SENSOR_DEVICE_ATTR(temp3_auto_offset_hyst, S_IWUSR | S_IRUGO,
1616 show_temp_auto_offset_hyst,
1617 store_temp_auto_offset_hyst, 2);
1619 static ssize_t show_fan_input(struct device *dev,
1620 struct device_attribute *attr, char *buf)
1622 struct sensor_device_attribute *s_attr = to_sensor_dev_attr(attr);
1623 int nr = s_attr->index;
1624 struct lm93_data *data = lm93_update_device(dev);
1626 return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block5[nr]));
1629 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0);
1630 static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1);
1631 static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2);
1632 static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan_input, NULL, 3);
1634 static ssize_t show_fan_min(struct device *dev,
1635 struct device_attribute *attr, char *buf)
1637 int nr = (to_sensor_dev_attr(attr))->index;
1638 struct lm93_data *data = lm93_update_device(dev);
1640 return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block8[nr]));
1643 static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr,
1644 const char *buf, size_t count)
1646 int nr = (to_sensor_dev_attr(attr))->index;
1647 struct i2c_client *client = to_i2c_client(dev);
1648 struct lm93_data *data = i2c_get_clientdata(client);
1649 u32 val = simple_strtoul(buf, NULL, 10);
1651 mutex_lock(&data->update_lock);
1652 data->block8[nr] = LM93_FAN_TO_REG(val);
1653 lm93_write_word(client,LM93_REG_FAN_MIN(nr),data->block8[nr]);
1654 mutex_unlock(&data->update_lock);
1658 static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
1659 show_fan_min, store_fan_min, 0);
1660 static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
1661 show_fan_min, store_fan_min, 1);
1662 static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO,
1663 show_fan_min, store_fan_min, 2);
1664 static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO,
1665 show_fan_min, store_fan_min, 3);
1667 /* some tedious bit-twiddling here to deal with the register format:
1669 data->sf_tach_to_pwm: (tach to pwm mapping bits)
1671 bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
1672 T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1
1674 data->sfc2: (enable bits)
1680 static ssize_t show_fan_smart_tach(struct device *dev,
1681 struct device_attribute *attr, char *buf)
1683 int nr = (to_sensor_dev_attr(attr))->index;
1684 struct lm93_data *data = lm93_update_device(dev);
1688 /* extract the relevant mapping */
1689 mapping = (data->sf_tach_to_pwm >> (nr * 2)) & 0x03;
1691 /* if there's a mapping and it's enabled */
1692 if (mapping && ((data->sfc2 >> nr) & 0x01))
1694 return sprintf(buf,"%ld\n",rc);
1697 /* helper function - must grab data->update_lock before calling
1698 fan is 0-3, indicating fan1-fan4 */
1699 static void lm93_write_fan_smart_tach(struct i2c_client *client,
1700 struct lm93_data *data, int fan, long value)
1702 /* insert the new mapping and write it out */
1703 data->sf_tach_to_pwm = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM);
1704 data->sf_tach_to_pwm &= ~(0x3 << fan * 2);
1705 data->sf_tach_to_pwm |= value << fan * 2;
1706 lm93_write_byte(client, LM93_REG_SF_TACH_TO_PWM, data->sf_tach_to_pwm);
1708 /* insert the enable bit and write it out */
1709 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1711 data->sfc2 |= 1 << fan;
1713 data->sfc2 &= ~(1 << fan);
1714 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1717 static ssize_t store_fan_smart_tach(struct device *dev,
1718 struct device_attribute *attr,
1719 const char *buf, size_t count)
1721 int nr = (to_sensor_dev_attr(attr))->index;
1722 struct i2c_client *client = to_i2c_client(dev);
1723 struct lm93_data *data = i2c_get_clientdata(client);
1724 u32 val = simple_strtoul(buf, NULL, 10);
1726 mutex_lock(&data->update_lock);
1727 /* sanity test, ignore the write otherwise */
1728 if (0 <= val && val <= 2) {
1729 /* can't enable if pwm freq is 22.5KHz */
1731 u8 ctl4 = lm93_read_byte(client,
1732 LM93_REG_PWM_CTL(val-1,LM93_PWM_CTL4));
1733 if ((ctl4 & 0x07) == 0)
1736 lm93_write_fan_smart_tach(client, data, nr, val);
1738 mutex_unlock(&data->update_lock);
1742 static SENSOR_DEVICE_ATTR(fan1_smart_tach, S_IWUSR | S_IRUGO,
1743 show_fan_smart_tach, store_fan_smart_tach, 0);
1744 static SENSOR_DEVICE_ATTR(fan2_smart_tach, S_IWUSR | S_IRUGO,
1745 show_fan_smart_tach, store_fan_smart_tach, 1);
1746 static SENSOR_DEVICE_ATTR(fan3_smart_tach, S_IWUSR | S_IRUGO,
1747 show_fan_smart_tach, store_fan_smart_tach, 2);
1748 static SENSOR_DEVICE_ATTR(fan4_smart_tach, S_IWUSR | S_IRUGO,
1749 show_fan_smart_tach, store_fan_smart_tach, 3);
1751 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1754 int nr = (to_sensor_dev_attr(attr))->index;
1755 struct lm93_data *data = lm93_update_device(dev);
1759 ctl2 = data->block9[nr][LM93_PWM_CTL2];
1760 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1761 if (ctl2 & 0x01) /* show user commanded value if enabled */
1762 rc = data->pwm_override[nr];
1763 else /* show present h/w value if manual pwm disabled */
1764 rc = LM93_PWM_FROM_REG(ctl2 >> 4, (ctl4 & 0x07) ?
1765 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ);
1766 return sprintf(buf,"%ld\n",rc);
1769 static ssize_t store_pwm(struct device *dev, struct device_attribute *attr,
1770 const char *buf, size_t count)
1772 int nr = (to_sensor_dev_attr(attr))->index;
1773 struct i2c_client *client = to_i2c_client(dev);
1774 struct lm93_data *data = i2c_get_clientdata(client);
1775 u32 val = simple_strtoul(buf, NULL, 10);
1778 mutex_lock(&data->update_lock);
1779 ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2));
1780 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4));
1781 ctl2 = (ctl2 & 0x0f) | LM93_PWM_TO_REG(val,(ctl4 & 0x07) ?
1782 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ) << 4;
1783 /* save user commanded value */
1784 data->pwm_override[nr] = LM93_PWM_FROM_REG(ctl2 >> 4,
1785 (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ :
1786 LM93_PWM_MAP_HI_FREQ);
1787 lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2);
1788 mutex_unlock(&data->update_lock);
1792 static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
1793 static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
1795 static ssize_t show_pwm_enable(struct device *dev,
1796 struct device_attribute *attr, char *buf)
1798 int nr = (to_sensor_dev_attr(attr))->index;
1799 struct lm93_data *data = lm93_update_device(dev);
1803 ctl2 = data->block9[nr][LM93_PWM_CTL2];
1804 if (ctl2 & 0x01) /* manual override enabled ? */
1805 rc = ((ctl2 & 0xF0) == 0xF0) ? 0 : 1;
1808 return sprintf(buf,"%ld\n",rc);
1811 static ssize_t store_pwm_enable(struct device *dev,
1812 struct device_attribute *attr,
1813 const char *buf, size_t count)
1815 int nr = (to_sensor_dev_attr(attr))->index;
1816 struct i2c_client *client = to_i2c_client(dev);
1817 struct lm93_data *data = i2c_get_clientdata(client);
1818 u32 val = simple_strtoul(buf, NULL, 10);
1821 mutex_lock(&data->update_lock);
1822 ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2));
1826 ctl2 |= 0xF1; /* enable manual override, set PWM to max */
1828 case 1: ctl2 |= 0x01; /* enable manual override */
1830 case 2: ctl2 &= ~0x01; /* disable manual override */
1833 mutex_unlock(&data->update_lock);
1837 lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2);
1838 mutex_unlock(&data->update_lock);
1842 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
1843 show_pwm_enable, store_pwm_enable, 0);
1844 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
1845 show_pwm_enable, store_pwm_enable, 1);
1847 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
1850 int nr = (to_sensor_dev_attr(attr))->index;
1851 struct lm93_data *data = lm93_update_device(dev);
1854 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1855 return sprintf(buf,"%d\n",LM93_PWM_FREQ_FROM_REG(ctl4));
1858 /* helper function - must grab data->update_lock before calling
1859 pwm is 0-1, indicating pwm1-pwm2
1860 this disables smart tach for all tach channels bound to the given pwm */
1861 static void lm93_disable_fan_smart_tach(struct i2c_client *client,
1862 struct lm93_data *data, int pwm)
1864 int mapping = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM);
1867 /* collapse the mapping into a mask of enable bits */
1868 mapping = (mapping >> pwm) & 0x55;
1869 mask = mapping & 0x01;
1870 mask |= (mapping & 0x04) >> 1;
1871 mask |= (mapping & 0x10) >> 2;
1872 mask |= (mapping & 0x40) >> 3;
1874 /* disable smart tach according to the mask */
1875 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1876 data->sfc2 &= ~mask;
1877 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1880 static ssize_t store_pwm_freq(struct device *dev,
1881 struct device_attribute *attr,
1882 const char *buf, size_t count)
1884 int nr = (to_sensor_dev_attr(attr))->index;
1885 struct i2c_client *client = to_i2c_client(dev);
1886 struct lm93_data *data = i2c_get_clientdata(client);
1887 u32 val = simple_strtoul(buf, NULL, 10);
1890 mutex_lock(&data->update_lock);
1891 ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4));
1892 ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(val);
1893 data->block9[nr][LM93_PWM_CTL4] = ctl4;
1894 /* ctl4 == 0 -> 22.5KHz -> disable smart tach */
1896 lm93_disable_fan_smart_tach(client, data, nr);
1897 lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4), ctl4);
1898 mutex_unlock(&data->update_lock);
1902 static SENSOR_DEVICE_ATTR(pwm1_freq, S_IWUSR | S_IRUGO,
1903 show_pwm_freq, store_pwm_freq, 0);
1904 static SENSOR_DEVICE_ATTR(pwm2_freq, S_IWUSR | S_IRUGO,
1905 show_pwm_freq, store_pwm_freq, 1);
1907 static ssize_t show_pwm_auto_channels(struct device *dev,
1908 struct device_attribute *attr, char *buf)
1910 int nr = (to_sensor_dev_attr(attr))->index;
1911 struct lm93_data *data = lm93_update_device(dev);
1912 return sprintf(buf,"%d\n",data->block9[nr][LM93_PWM_CTL1]);
1915 static ssize_t store_pwm_auto_channels(struct device *dev,
1916 struct device_attribute *attr,
1917 const char *buf, size_t count)
1919 int nr = (to_sensor_dev_attr(attr))->index;
1920 struct i2c_client *client = to_i2c_client(dev);
1921 struct lm93_data *data = i2c_get_clientdata(client);
1922 u32 val = simple_strtoul(buf, NULL, 10);
1924 mutex_lock(&data->update_lock);
1925 data->block9[nr][LM93_PWM_CTL1] = SENSORS_LIMIT(val, 0, 255);
1926 lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL1),
1927 data->block9[nr][LM93_PWM_CTL1]);
1928 mutex_unlock(&data->update_lock);
1932 static SENSOR_DEVICE_ATTR(pwm1_auto_channels, S_IWUSR | S_IRUGO,
1933 show_pwm_auto_channels, store_pwm_auto_channels, 0);
1934 static SENSOR_DEVICE_ATTR(pwm2_auto_channels, S_IWUSR | S_IRUGO,
1935 show_pwm_auto_channels, store_pwm_auto_channels, 1);
1937 static ssize_t show_pwm_auto_spinup_min(struct device *dev,
1938 struct device_attribute *attr,char *buf)
1940 int nr = (to_sensor_dev_attr(attr))->index;
1941 struct lm93_data *data = lm93_update_device(dev);
1944 ctl3 = data->block9[nr][LM93_PWM_CTL3];
1945 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1946 return sprintf(buf,"%d\n",
1947 LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ?
1948 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));
1951 static ssize_t store_pwm_auto_spinup_min(struct device *dev,
1952 struct device_attribute *attr,
1953 const char *buf, size_t count)
1955 int nr = (to_sensor_dev_attr(attr))->index;
1956 struct i2c_client *client = to_i2c_client(dev);
1957 struct lm93_data *data = i2c_get_clientdata(client);
1958 u32 val = simple_strtoul(buf, NULL, 10);
1961 mutex_lock(&data->update_lock);
1962 ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3));
1963 ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1964 ctl3 = (ctl3 & 0xf0) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1965 LM93_PWM_MAP_LO_FREQ :
1966 LM93_PWM_MAP_HI_FREQ);
1967 data->block9[nr][LM93_PWM_CTL3] = ctl3;
1968 lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3);
1969 mutex_unlock(&data->update_lock);
1973 static SENSOR_DEVICE_ATTR(pwm1_auto_spinup_min, S_IWUSR | S_IRUGO,
1974 show_pwm_auto_spinup_min,
1975 store_pwm_auto_spinup_min, 0);
1976 static SENSOR_DEVICE_ATTR(pwm2_auto_spinup_min, S_IWUSR | S_IRUGO,
1977 show_pwm_auto_spinup_min,
1978 store_pwm_auto_spinup_min, 1);
1980 static ssize_t show_pwm_auto_spinup_time(struct device *dev,
1981 struct device_attribute *attr, char *buf)
1983 int nr = (to_sensor_dev_attr(attr))->index;
1984 struct lm93_data *data = lm93_update_device(dev);
1985 return sprintf(buf,"%d\n",LM93_SPINUP_TIME_FROM_REG(
1986 data->block9[nr][LM93_PWM_CTL3]));
1989 static ssize_t store_pwm_auto_spinup_time(struct device *dev,
1990 struct device_attribute *attr,
1991 const char *buf, size_t count)
1993 int nr = (to_sensor_dev_attr(attr))->index;
1994 struct i2c_client *client = to_i2c_client(dev);
1995 struct lm93_data *data = i2c_get_clientdata(client);
1996 u32 val = simple_strtoul(buf, NULL, 10);
1999 mutex_lock(&data->update_lock);
2000 ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3));
2001 ctl3 = (ctl3 & 0x1f) | (LM93_SPINUP_TIME_TO_REG(val) << 5 & 0xe0);
2002 data->block9[nr][LM93_PWM_CTL3] = ctl3;
2003 lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3);
2004 mutex_unlock(&data->update_lock);
2008 static SENSOR_DEVICE_ATTR(pwm1_auto_spinup_time, S_IWUSR | S_IRUGO,
2009 show_pwm_auto_spinup_time,
2010 store_pwm_auto_spinup_time, 0);
2011 static SENSOR_DEVICE_ATTR(pwm2_auto_spinup_time, S_IWUSR | S_IRUGO,
2012 show_pwm_auto_spinup_time,
2013 store_pwm_auto_spinup_time, 1);
2015 static ssize_t show_pwm_auto_prochot_ramp(struct device *dev,
2016 struct device_attribute *attr, char *buf)
2018 struct lm93_data *data = lm93_update_device(dev);
2019 return sprintf(buf,"%d\n",
2020 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl >> 4 & 0x0f));
2023 static ssize_t store_pwm_auto_prochot_ramp(struct device *dev,
2024 struct device_attribute *attr,
2025 const char *buf, size_t count)
2027 struct i2c_client *client = to_i2c_client(dev);
2028 struct lm93_data *data = i2c_get_clientdata(client);
2029 u32 val = simple_strtoul(buf, NULL, 10);
2032 mutex_lock(&data->update_lock);
2033 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
2034 ramp = (ramp & 0x0f) | (LM93_RAMP_TO_REG(val) << 4 & 0xf0);
2035 lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp);
2036 mutex_unlock(&data->update_lock);
2040 static DEVICE_ATTR(pwm_auto_prochot_ramp, S_IRUGO | S_IWUSR,
2041 show_pwm_auto_prochot_ramp,
2042 store_pwm_auto_prochot_ramp);
2044 static ssize_t show_pwm_auto_vrdhot_ramp(struct device *dev,
2045 struct device_attribute *attr, char *buf)
2047 struct lm93_data *data = lm93_update_device(dev);
2048 return sprintf(buf,"%d\n",
2049 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl & 0x0f));
2052 static ssize_t store_pwm_auto_vrdhot_ramp(struct device *dev,
2053 struct device_attribute *attr,
2054 const char *buf, size_t count)
2056 struct i2c_client *client = to_i2c_client(dev);
2057 struct lm93_data *data = i2c_get_clientdata(client);
2058 u32 val = simple_strtoul(buf, NULL, 10);
2061 mutex_lock(&data->update_lock);
2062 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
2063 ramp = (ramp & 0xf0) | (LM93_RAMP_TO_REG(val) & 0x0f);
2064 lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp);
2065 mutex_unlock(&data->update_lock);
2069 static DEVICE_ATTR(pwm_auto_vrdhot_ramp, S_IRUGO | S_IWUSR,
2070 show_pwm_auto_vrdhot_ramp,
2071 store_pwm_auto_vrdhot_ramp);
2073 static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
2076 int nr = (to_sensor_dev_attr(attr))->index;
2077 struct lm93_data *data = lm93_update_device(dev);
2078 return sprintf(buf,"%d\n",LM93_VID_FROM_REG(data->vid[nr]));
2081 static SENSOR_DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL, 0);
2082 static SENSOR_DEVICE_ATTR(cpu1_vid, S_IRUGO, show_vid, NULL, 1);
2084 static ssize_t show_prochot(struct device *dev, struct device_attribute *attr,
2087 int nr = (to_sensor_dev_attr(attr))->index;
2088 struct lm93_data *data = lm93_update_device(dev);
2089 return sprintf(buf,"%d\n",data->block4[nr].cur);
2092 static SENSOR_DEVICE_ATTR(prochot1, S_IRUGO, show_prochot, NULL, 0);
2093 static SENSOR_DEVICE_ATTR(prochot2, S_IRUGO, show_prochot, NULL, 1);
2095 static ssize_t show_prochot_avg(struct device *dev,
2096 struct device_attribute *attr, char *buf)
2098 int nr = (to_sensor_dev_attr(attr))->index;
2099 struct lm93_data *data = lm93_update_device(dev);
2100 return sprintf(buf,"%d\n",data->block4[nr].avg);
2103 static SENSOR_DEVICE_ATTR(prochot1_avg, S_IRUGO, show_prochot_avg, NULL, 0);
2104 static SENSOR_DEVICE_ATTR(prochot2_avg, S_IRUGO, show_prochot_avg, NULL, 1);
2106 static ssize_t show_prochot_max(struct device *dev,
2107 struct device_attribute *attr, char *buf)
2109 int nr = (to_sensor_dev_attr(attr))->index;
2110 struct lm93_data *data = lm93_update_device(dev);
2111 return sprintf(buf,"%d\n",data->prochot_max[nr]);
2114 static ssize_t store_prochot_max(struct device *dev,
2115 struct device_attribute *attr,
2116 const char *buf, size_t count)
2118 int nr = (to_sensor_dev_attr(attr))->index;
2119 struct i2c_client *client = to_i2c_client(dev);
2120 struct lm93_data *data = i2c_get_clientdata(client);
2121 u32 val = simple_strtoul(buf, NULL, 10);
2123 mutex_lock(&data->update_lock);
2124 data->prochot_max[nr] = LM93_PROCHOT_TO_REG(val);
2125 lm93_write_byte(client, LM93_REG_PROCHOT_MAX(nr),
2126 data->prochot_max[nr]);
2127 mutex_unlock(&data->update_lock);
2131 static SENSOR_DEVICE_ATTR(prochot1_max, S_IWUSR | S_IRUGO,
2132 show_prochot_max, store_prochot_max, 0);
2133 static SENSOR_DEVICE_ATTR(prochot2_max, S_IWUSR | S_IRUGO,
2134 show_prochot_max, store_prochot_max, 1);
2136 static const u8 prochot_override_mask[] = { 0x80, 0x40 };
2138 static ssize_t show_prochot_override(struct device *dev,
2139 struct device_attribute *attr, char *buf)
2141 int nr = (to_sensor_dev_attr(attr))->index;
2142 struct lm93_data *data = lm93_update_device(dev);
2143 return sprintf(buf,"%d\n",
2144 (data->prochot_override & prochot_override_mask[nr]) ? 1 : 0);
2147 static ssize_t store_prochot_override(struct device *dev,
2148 struct device_attribute *attr,
2149 const char *buf, size_t count)
2151 int nr = (to_sensor_dev_attr(attr))->index;
2152 struct i2c_client *client = to_i2c_client(dev);
2153 struct lm93_data *data = i2c_get_clientdata(client);
2154 u32 val = simple_strtoul(buf, NULL, 10);
2156 mutex_lock(&data->update_lock);
2158 data->prochot_override |= prochot_override_mask[nr];
2160 data->prochot_override &= (~prochot_override_mask[nr]);
2161 lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE,
2162 data->prochot_override);
2163 mutex_unlock(&data->update_lock);
2167 static SENSOR_DEVICE_ATTR(prochot1_override, S_IWUSR | S_IRUGO,
2168 show_prochot_override, store_prochot_override, 0);
2169 static SENSOR_DEVICE_ATTR(prochot2_override, S_IWUSR | S_IRUGO,
2170 show_prochot_override, store_prochot_override, 1);
2172 static ssize_t show_prochot_interval(struct device *dev,
2173 struct device_attribute *attr, char *buf)
2175 int nr = (to_sensor_dev_attr(attr))->index;
2176 struct lm93_data *data = lm93_update_device(dev);
2179 tmp = (data->prochot_interval & 0xf0) >> 4;
2181 tmp = data->prochot_interval & 0x0f;
2182 return sprintf(buf,"%d\n",LM93_INTERVAL_FROM_REG(tmp));
2185 static ssize_t store_prochot_interval(struct device *dev,
2186 struct device_attribute *attr,
2187 const char *buf, size_t count)
2189 int nr = (to_sensor_dev_attr(attr))->index;
2190 struct i2c_client *client = to_i2c_client(dev);
2191 struct lm93_data *data = i2c_get_clientdata(client);
2192 u32 val = simple_strtoul(buf, NULL, 10);
2195 mutex_lock(&data->update_lock);
2196 tmp = lm93_read_byte(client, LM93_REG_PROCHOT_INTERVAL);
2198 tmp = (tmp & 0x0f) | (LM93_INTERVAL_TO_REG(val) << 4);
2200 tmp = (tmp & 0xf0) | LM93_INTERVAL_TO_REG(val);
2201 data->prochot_interval = tmp;
2202 lm93_write_byte(client, LM93_REG_PROCHOT_INTERVAL, tmp);
2203 mutex_unlock(&data->update_lock);
2207 static SENSOR_DEVICE_ATTR(prochot1_interval, S_IWUSR | S_IRUGO,
2208 show_prochot_interval, store_prochot_interval, 0);
2209 static SENSOR_DEVICE_ATTR(prochot2_interval, S_IWUSR | S_IRUGO,
2210 show_prochot_interval, store_prochot_interval, 1);
2212 static ssize_t show_prochot_override_duty_cycle(struct device *dev,
2213 struct device_attribute *attr,
2216 struct lm93_data *data = lm93_update_device(dev);
2217 return sprintf(buf,"%d\n",data->prochot_override & 0x0f);
2220 static ssize_t store_prochot_override_duty_cycle(struct device *dev,
2221 struct device_attribute *attr,
2222 const char *buf, size_t count)
2224 struct i2c_client *client = to_i2c_client(dev);
2225 struct lm93_data *data = i2c_get_clientdata(client);
2226 u32 val = simple_strtoul(buf, NULL, 10);
2228 mutex_lock(&data->update_lock);
2229 data->prochot_override = (data->prochot_override & 0xf0) |
2230 SENSORS_LIMIT(val, 0, 15);
2231 lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE,
2232 data->prochot_override);
2233 mutex_unlock(&data->update_lock);
2237 static DEVICE_ATTR(prochot_override_duty_cycle, S_IRUGO | S_IWUSR,
2238 show_prochot_override_duty_cycle,
2239 store_prochot_override_duty_cycle);
2241 static ssize_t show_prochot_short(struct device *dev,
2242 struct device_attribute *attr, char *buf)
2244 struct lm93_data *data = lm93_update_device(dev);
2245 return sprintf(buf,"%d\n",(data->config & 0x10) ? 1 : 0);
2248 static ssize_t store_prochot_short(struct device *dev,
2249 struct device_attribute *attr,
2250 const char *buf, size_t count)
2252 struct i2c_client *client = to_i2c_client(dev);
2253 struct lm93_data *data = i2c_get_clientdata(client);
2254 u32 val = simple_strtoul(buf, NULL, 10);
2256 mutex_lock(&data->update_lock);
2258 data->config |= 0x10;
2260 data->config &= ~0x10;
2261 lm93_write_byte(client, LM93_REG_CONFIG, data->config);
2262 mutex_unlock(&data->update_lock);
2266 static DEVICE_ATTR(prochot_short, S_IRUGO | S_IWUSR,
2267 show_prochot_short, store_prochot_short);
2269 static ssize_t show_vrdhot(struct device *dev, struct device_attribute *attr,
2272 int nr = (to_sensor_dev_attr(attr))->index;
2273 struct lm93_data *data = lm93_update_device(dev);
2274 return sprintf(buf,"%d\n",
2275 data->block1.host_status_1 & (1 << (nr+4)) ? 1 : 0);
2278 static SENSOR_DEVICE_ATTR(vrdhot1, S_IRUGO, show_vrdhot, NULL, 0);
2279 static SENSOR_DEVICE_ATTR(vrdhot2, S_IRUGO, show_vrdhot, NULL, 1);
2281 static ssize_t show_gpio(struct device *dev, struct device_attribute *attr,
2284 struct lm93_data *data = lm93_update_device(dev);
2285 return sprintf(buf,"%d\n",LM93_GPI_FROM_REG(data->gpi));
2288 static DEVICE_ATTR(gpio, S_IRUGO, show_gpio, NULL);
2290 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
2293 struct lm93_data *data = lm93_update_device(dev);
2294 return sprintf(buf,"%d\n",LM93_ALARMS_FROM_REG(data->block1));
2297 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
2299 static struct attribute *lm93_attrs[] = {
2300 &sensor_dev_attr_in1_input.dev_attr.attr,
2301 &sensor_dev_attr_in2_input.dev_attr.attr,
2302 &sensor_dev_attr_in3_input.dev_attr.attr,
2303 &sensor_dev_attr_in4_input.dev_attr.attr,
2304 &sensor_dev_attr_in5_input.dev_attr.attr,
2305 &sensor_dev_attr_in6_input.dev_attr.attr,
2306 &sensor_dev_attr_in7_input.dev_attr.attr,
2307 &sensor_dev_attr_in8_input.dev_attr.attr,
2308 &sensor_dev_attr_in9_input.dev_attr.attr,
2309 &sensor_dev_attr_in10_input.dev_attr.attr,
2310 &sensor_dev_attr_in11_input.dev_attr.attr,
2311 &sensor_dev_attr_in12_input.dev_attr.attr,
2312 &sensor_dev_attr_in13_input.dev_attr.attr,
2313 &sensor_dev_attr_in14_input.dev_attr.attr,
2314 &sensor_dev_attr_in15_input.dev_attr.attr,
2315 &sensor_dev_attr_in16_input.dev_attr.attr,
2316 &sensor_dev_attr_in1_min.dev_attr.attr,
2317 &sensor_dev_attr_in2_min.dev_attr.attr,
2318 &sensor_dev_attr_in3_min.dev_attr.attr,
2319 &sensor_dev_attr_in4_min.dev_attr.attr,
2320 &sensor_dev_attr_in5_min.dev_attr.attr,
2321 &sensor_dev_attr_in6_min.dev_attr.attr,
2322 &sensor_dev_attr_in7_min.dev_attr.attr,
2323 &sensor_dev_attr_in8_min.dev_attr.attr,
2324 &sensor_dev_attr_in9_min.dev_attr.attr,
2325 &sensor_dev_attr_in10_min.dev_attr.attr,
2326 &sensor_dev_attr_in11_min.dev_attr.attr,
2327 &sensor_dev_attr_in12_min.dev_attr.attr,
2328 &sensor_dev_attr_in13_min.dev_attr.attr,
2329 &sensor_dev_attr_in14_min.dev_attr.attr,
2330 &sensor_dev_attr_in15_min.dev_attr.attr,
2331 &sensor_dev_attr_in16_min.dev_attr.attr,
2332 &sensor_dev_attr_in1_max.dev_attr.attr,
2333 &sensor_dev_attr_in2_max.dev_attr.attr,
2334 &sensor_dev_attr_in3_max.dev_attr.attr,
2335 &sensor_dev_attr_in4_max.dev_attr.attr,
2336 &sensor_dev_attr_in5_max.dev_attr.attr,
2337 &sensor_dev_attr_in6_max.dev_attr.attr,
2338 &sensor_dev_attr_in7_max.dev_attr.attr,
2339 &sensor_dev_attr_in8_max.dev_attr.attr,
2340 &sensor_dev_attr_in9_max.dev_attr.attr,
2341 &sensor_dev_attr_in10_max.dev_attr.attr,
2342 &sensor_dev_attr_in11_max.dev_attr.attr,
2343 &sensor_dev_attr_in12_max.dev_attr.attr,
2344 &sensor_dev_attr_in13_max.dev_attr.attr,
2345 &sensor_dev_attr_in14_max.dev_attr.attr,
2346 &sensor_dev_attr_in15_max.dev_attr.attr,
2347 &sensor_dev_attr_in16_max.dev_attr.attr,
2348 &sensor_dev_attr_temp1_input.dev_attr.attr,
2349 &sensor_dev_attr_temp2_input.dev_attr.attr,
2350 &sensor_dev_attr_temp3_input.dev_attr.attr,
2351 &sensor_dev_attr_temp1_min.dev_attr.attr,
2352 &sensor_dev_attr_temp2_min.dev_attr.attr,
2353 &sensor_dev_attr_temp3_min.dev_attr.attr,
2354 &sensor_dev_attr_temp1_max.dev_attr.attr,
2355 &sensor_dev_attr_temp2_max.dev_attr.attr,
2356 &sensor_dev_attr_temp3_max.dev_attr.attr,
2357 &sensor_dev_attr_temp1_auto_base.dev_attr.attr,
2358 &sensor_dev_attr_temp2_auto_base.dev_attr.attr,
2359 &sensor_dev_attr_temp3_auto_base.dev_attr.attr,
2360 &sensor_dev_attr_temp1_auto_boost.dev_attr.attr,
2361 &sensor_dev_attr_temp2_auto_boost.dev_attr.attr,
2362 &sensor_dev_attr_temp3_auto_boost.dev_attr.attr,
2363 &sensor_dev_attr_temp1_auto_boost_hyst.dev_attr.attr,
2364 &sensor_dev_attr_temp2_auto_boost_hyst.dev_attr.attr,
2365 &sensor_dev_attr_temp3_auto_boost_hyst.dev_attr.attr,
2366 &sensor_dev_attr_temp1_auto_offset1.dev_attr.attr,
2367 &sensor_dev_attr_temp1_auto_offset2.dev_attr.attr,
2368 &sensor_dev_attr_temp1_auto_offset3.dev_attr.attr,
2369 &sensor_dev_attr_temp1_auto_offset4.dev_attr.attr,
2370 &sensor_dev_attr_temp1_auto_offset5.dev_attr.attr,
2371 &sensor_dev_attr_temp1_auto_offset6.dev_attr.attr,
2372 &sensor_dev_attr_temp1_auto_offset7.dev_attr.attr,
2373 &sensor_dev_attr_temp1_auto_offset8.dev_attr.attr,
2374 &sensor_dev_attr_temp1_auto_offset9.dev_attr.attr,
2375 &sensor_dev_attr_temp1_auto_offset10.dev_attr.attr,
2376 &sensor_dev_attr_temp1_auto_offset11.dev_attr.attr,
2377 &sensor_dev_attr_temp1_auto_offset12.dev_attr.attr,
2378 &sensor_dev_attr_temp2_auto_offset1.dev_attr.attr,
2379 &sensor_dev_attr_temp2_auto_offset2.dev_attr.attr,
2380 &sensor_dev_attr_temp2_auto_offset3.dev_attr.attr,
2381 &sensor_dev_attr_temp2_auto_offset4.dev_attr.attr,
2382 &sensor_dev_attr_temp2_auto_offset5.dev_attr.attr,
2383 &sensor_dev_attr_temp2_auto_offset6.dev_attr.attr,
2384 &sensor_dev_attr_temp2_auto_offset7.dev_attr.attr,
2385 &sensor_dev_attr_temp2_auto_offset8.dev_attr.attr,
2386 &sensor_dev_attr_temp2_auto_offset9.dev_attr.attr,
2387 &sensor_dev_attr_temp2_auto_offset10.dev_attr.attr,
2388 &sensor_dev_attr_temp2_auto_offset11.dev_attr.attr,
2389 &sensor_dev_attr_temp2_auto_offset12.dev_attr.attr,
2390 &sensor_dev_attr_temp3_auto_offset1.dev_attr.attr,
2391 &sensor_dev_attr_temp3_auto_offset2.dev_attr.attr,
2392 &sensor_dev_attr_temp3_auto_offset3.dev_attr.attr,
2393 &sensor_dev_attr_temp3_auto_offset4.dev_attr.attr,
2394 &sensor_dev_attr_temp3_auto_offset5.dev_attr.attr,
2395 &sensor_dev_attr_temp3_auto_offset6.dev_attr.attr,
2396 &sensor_dev_attr_temp3_auto_offset7.dev_attr.attr,
2397 &sensor_dev_attr_temp3_auto_offset8.dev_attr.attr,
2398 &sensor_dev_attr_temp3_auto_offset9.dev_attr.attr,
2399 &sensor_dev_attr_temp3_auto_offset10.dev_attr.attr,
2400 &sensor_dev_attr_temp3_auto_offset11.dev_attr.attr,
2401 &sensor_dev_attr_temp3_auto_offset12.dev_attr.attr,
2402 &sensor_dev_attr_temp1_auto_pwm_min.dev_attr.attr,
2403 &sensor_dev_attr_temp2_auto_pwm_min.dev_attr.attr,
2404 &sensor_dev_attr_temp3_auto_pwm_min.dev_attr.attr,
2405 &sensor_dev_attr_temp1_auto_offset_hyst.dev_attr.attr,
2406 &sensor_dev_attr_temp2_auto_offset_hyst.dev_attr.attr,
2407 &sensor_dev_attr_temp3_auto_offset_hyst.dev_attr.attr,
2408 &sensor_dev_attr_fan1_input.dev_attr.attr,
2409 &sensor_dev_attr_fan2_input.dev_attr.attr,
2410 &sensor_dev_attr_fan3_input.dev_attr.attr,
2411 &sensor_dev_attr_fan4_input.dev_attr.attr,
2412 &sensor_dev_attr_fan1_min.dev_attr.attr,
2413 &sensor_dev_attr_fan2_min.dev_attr.attr,
2414 &sensor_dev_attr_fan3_min.dev_attr.attr,
2415 &sensor_dev_attr_fan4_min.dev_attr.attr,
2416 &sensor_dev_attr_fan1_smart_tach.dev_attr.attr,
2417 &sensor_dev_attr_fan2_smart_tach.dev_attr.attr,
2418 &sensor_dev_attr_fan3_smart_tach.dev_attr.attr,
2419 &sensor_dev_attr_fan4_smart_tach.dev_attr.attr,
2420 &sensor_dev_attr_pwm1.dev_attr.attr,
2421 &sensor_dev_attr_pwm2.dev_attr.attr,
2422 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2423 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
2424 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
2425 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
2426 &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
2427 &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
2428 &sensor_dev_attr_pwm1_auto_spinup_min.dev_attr.attr,
2429 &sensor_dev_attr_pwm2_auto_spinup_min.dev_attr.attr,
2430 &sensor_dev_attr_pwm1_auto_spinup_time.dev_attr.attr,
2431 &sensor_dev_attr_pwm2_auto_spinup_time.dev_attr.attr,
2432 &dev_attr_pwm_auto_prochot_ramp.attr,
2433 &dev_attr_pwm_auto_vrdhot_ramp.attr,
2434 &sensor_dev_attr_cpu0_vid.dev_attr.attr,
2435 &sensor_dev_attr_cpu1_vid.dev_attr.attr,
2436 &sensor_dev_attr_prochot1.dev_attr.attr,
2437 &sensor_dev_attr_prochot2.dev_attr.attr,
2438 &sensor_dev_attr_prochot1_avg.dev_attr.attr,
2439 &sensor_dev_attr_prochot2_avg.dev_attr.attr,
2440 &sensor_dev_attr_prochot1_max.dev_attr.attr,
2441 &sensor_dev_attr_prochot2_max.dev_attr.attr,
2442 &sensor_dev_attr_prochot1_override.dev_attr.attr,
2443 &sensor_dev_attr_prochot2_override.dev_attr.attr,
2444 &sensor_dev_attr_prochot1_interval.dev_attr.attr,
2445 &sensor_dev_attr_prochot2_interval.dev_attr.attr,
2446 &dev_attr_prochot_override_duty_cycle.attr,
2447 &dev_attr_prochot_short.attr,
2448 &sensor_dev_attr_vrdhot1.dev_attr.attr,
2449 &sensor_dev_attr_vrdhot2.dev_attr.attr,
2450 &dev_attr_gpio.attr,
2451 &dev_attr_alarms.attr,
2455 static struct attribute_group lm93_attr_grp = {
2456 .attrs = lm93_attrs,
2459 static void lm93_init_client(struct i2c_client *client)
2464 /* configure VID pin input thresholds */
2465 reg = lm93_read_byte(client, LM93_REG_GPI_VID_CTL);
2466 lm93_write_byte(client, LM93_REG_GPI_VID_CTL,
2467 reg | (vid_agtl ? 0x03 : 0x00));
2470 /* enable #ALERT pin */
2471 reg = lm93_read_byte(client, LM93_REG_CONFIG);
2472 lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x08);
2474 /* enable ASF mode for BMC status registers */
2475 reg = lm93_read_byte(client, LM93_REG_STATUS_CONTROL);
2476 lm93_write_byte(client, LM93_REG_STATUS_CONTROL, reg | 0x02);
2478 /* set sleep state to S0 */
2479 lm93_write_byte(client, LM93_REG_SLEEP_CONTROL, 0);
2481 /* unmask #VRDHOT and dynamic VCCP (if nec) error events */
2482 reg = lm93_read_byte(client, LM93_REG_MISC_ERR_MASK);
2484 reg &= ~(vccp_limit_type[0] ? 0x10 : 0);
2485 reg &= ~(vccp_limit_type[1] ? 0x20 : 0);
2486 lm93_write_byte(client, LM93_REG_MISC_ERR_MASK, reg);
2489 /* start monitoring */
2490 reg = lm93_read_byte(client, LM93_REG_CONFIG);
2491 lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x01);
2493 /* spin until ready */
2494 for (i=0; i<20; i++) {
2496 if ((lm93_read_byte(client, LM93_REG_CONFIG) & 0x80) == 0x80)
2500 dev_warn(&client->dev,"timed out waiting for sensor "
2501 "chip to signal ready!\n");
2504 static int lm93_detect(struct i2c_adapter *adapter, int address, int kind)
2506 struct lm93_data *data;
2507 struct i2c_client *client;
2509 int err = -ENODEV, func;
2510 void (*update)(struct lm93_data *, struct i2c_client *);
2512 /* choose update routine based on bus capabilities */
2513 func = i2c_get_functionality(adapter);
2514 if ( ((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) &&
2515 (!disable_block) ) {
2516 dev_dbg(&adapter->dev,"using SMBus block data transactions\n");
2517 update = lm93_update_client_full;
2518 } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) {
2519 dev_dbg(&adapter->dev,"disabled SMBus block data "
2521 update = lm93_update_client_min;
2523 dev_dbg(&adapter->dev,"detect failed, "
2524 "smbus byte and/or word data not supported!\n");
2528 /* OK. For now, we presume we have a valid client. We now create the
2529 client structure, even though we cannot fill it completely yet.
2530 But it allows us to access lm78_{read,write}_value. */
2532 if ( !(data = kzalloc(sizeof(struct lm93_data), GFP_KERNEL))) {
2533 dev_dbg(&adapter->dev,"out of memory!\n");
2538 client = &data->client;
2539 i2c_set_clientdata(client, data);
2540 client->addr = address;
2541 client->adapter = adapter;
2542 client->driver = &lm93_driver;
2546 int mfr = lm93_read_byte(client, LM93_REG_MFR_ID);
2549 dev_dbg(&adapter->dev,"detect failed, "
2550 "bad manufacturer id 0x%02x!\n", mfr);
2556 int ver = lm93_read_byte(client, LM93_REG_VER);
2558 if ((ver == LM93_MFR_ID) || (ver == LM93_MFR_ID_PROTOTYPE)) {
2561 dev_dbg(&adapter->dev,"detect failed, "
2562 "bad version id 0x%02x!\n", ver);
2564 dev_dbg(&adapter->dev,
2565 "(ignored 'force' parameter)\n");
2570 /* fill in remaining client fields */
2571 strlcpy(client->name, "lm93", I2C_NAME_SIZE);
2572 dev_dbg(&adapter->dev,"loading %s at %d,0x%02x\n",
2573 client->name, i2c_adapter_id(client->adapter),
2578 data->update = update;
2579 mutex_init(&data->update_lock);
2581 /* tell the I2C layer a new client has arrived */
2582 if ((err = i2c_attach_client(client)))
2585 /* initialize the chip */
2586 lm93_init_client(client);
2588 err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp);
2592 /* Register hwmon driver class */
2593 data->hwmon_dev = hwmon_device_register(&client->dev);
2594 if ( !IS_ERR(data->hwmon_dev))
2597 err = PTR_ERR(data->hwmon_dev);
2598 dev_err(&client->dev, "error registering hwmon device.\n");
2599 sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp);
2601 i2c_detach_client(client);
2608 /* This function is called when:
2609 * lm93_driver is inserted (when this module is loaded), for each
2611 * when a new adapter is inserted (and lm93_driver is still present) */
2612 static int lm93_attach_adapter(struct i2c_adapter *adapter)
2614 return i2c_probe(adapter, &addr_data, lm93_detect);
2617 static int lm93_detach_client(struct i2c_client *client)
2619 struct lm93_data *data = i2c_get_clientdata(client);
2622 hwmon_device_unregister(data->hwmon_dev);
2623 sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp);
2625 err = i2c_detach_client(client);
2631 static struct i2c_driver lm93_driver = {
2635 .attach_adapter = lm93_attach_adapter,
2636 .detach_client = lm93_detach_client,
2639 static int __init lm93_init(void)
2641 return i2c_add_driver(&lm93_driver);
2644 static void __exit lm93_exit(void)
2646 i2c_del_driver(&lm93_driver);
2649 MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, "
2650 "Hans J. Koch <hjk@linutronix.de");
2651 MODULE_DESCRIPTION("LM93 driver");
2652 MODULE_LICENSE("GPL");
2654 module_init(lm93_init);
2655 module_exit(lm93_exit);