1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * lm93.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
5 * Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com>
6 * Copyright (c) 2004 Utilitek Systems, Inc.
8 * derived in part from lm78.c:
9 * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
11 * derived in part from lm85.c:
12 * Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
13 * Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
15 * derived in part from w83l785ts.c:
16 * Copyright (c) 2003-2004 Jean Delvare <jdelvare@suse.de>
18 * Ported to Linux 2.6 by Eric J. Bowersox <ericb@aspsys.com>
19 * Copyright (c) 2005 Aspen Systems, Inc.
21 * Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org>
22 * Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab
24 * Modified for mainline integration by Hans J. Koch <hjk@hansjkoch.de>
25 * Copyright (c) 2007 Hans J. Koch, Linutronix GmbH
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <linux/i2c.h>
32 #include <linux/hwmon.h>
33 #include <linux/hwmon-sysfs.h>
34 #include <linux/hwmon-vid.h>
35 #include <linux/err.h>
36 #include <linux/delay.h>
37 #include <linux/jiffies.h>
39 /* LM93 REGISTER ADDRESSES */
42 #define LM93_REG_MFR_ID 0x3e
43 #define LM93_REG_VER 0x3f
44 #define LM93_REG_STATUS_CONTROL 0xe2
45 #define LM93_REG_CONFIG 0xe3
46 #define LM93_REG_SLEEP_CONTROL 0xe4
48 /* alarm values start here */
49 #define LM93_REG_HOST_ERROR_1 0x48
51 /* voltage inputs: in1-in16 (nr => 0-15) */
52 #define LM93_REG_IN(nr) (0x56 + (nr))
53 #define LM93_REG_IN_MIN(nr) (0x90 + (nr) * 2)
54 #define LM93_REG_IN_MAX(nr) (0x91 + (nr) * 2)
56 /* temperature inputs: temp1-temp4 (nr => 0-3) */
57 #define LM93_REG_TEMP(nr) (0x50 + (nr))
58 #define LM93_REG_TEMP_MIN(nr) (0x78 + (nr) * 2)
59 #define LM93_REG_TEMP_MAX(nr) (0x79 + (nr) * 2)
61 /* temp[1-4]_auto_boost (nr => 0-3) */
62 #define LM93_REG_BOOST(nr) (0x80 + (nr))
64 /* #PROCHOT inputs: prochot1-prochot2 (nr => 0-1) */
65 #define LM93_REG_PROCHOT_CUR(nr) (0x67 + (nr) * 2)
66 #define LM93_REG_PROCHOT_AVG(nr) (0x68 + (nr) * 2)
67 #define LM93_REG_PROCHOT_MAX(nr) (0xb0 + (nr))
69 /* fan tach inputs: fan1-fan4 (nr => 0-3) */
70 #define LM93_REG_FAN(nr) (0x6e + (nr) * 2)
71 #define LM93_REG_FAN_MIN(nr) (0xb4 + (nr) * 2)
73 /* pwm outputs: pwm1-pwm2 (nr => 0-1, reg => 0-3) */
74 #define LM93_REG_PWM_CTL(nr, reg) (0xc8 + (reg) + (nr) * 4)
75 #define LM93_PWM_CTL1 0x0
76 #define LM93_PWM_CTL2 0x1
77 #define LM93_PWM_CTL3 0x2
78 #define LM93_PWM_CTL4 0x3
80 /* GPIO input state */
81 #define LM93_REG_GPI 0x6b
83 /* vid inputs: vid1-vid2 (nr => 0-1) */
84 #define LM93_REG_VID(nr) (0x6c + (nr))
86 /* vccp1 & vccp2: VID relative inputs (nr => 0-1) */
87 #define LM93_REG_VCCP_LIMIT_OFF(nr) (0xb2 + (nr))
89 /* temp[1-4]_auto_boost_hyst */
90 #define LM93_REG_BOOST_HYST_12 0xc0
91 #define LM93_REG_BOOST_HYST_34 0xc1
92 #define LM93_REG_BOOST_HYST(nr) (0xc0 + (nr)/2)
94 /* temp[1-4]_auto_pwm_[min|hyst] */
95 #define LM93_REG_PWM_MIN_HYST_12 0xc3
96 #define LM93_REG_PWM_MIN_HYST_34 0xc4
97 #define LM93_REG_PWM_MIN_HYST(nr) (0xc3 + (nr)/2)
99 /* prochot_override & prochot_interval */
100 #define LM93_REG_PROCHOT_OVERRIDE 0xc6
101 #define LM93_REG_PROCHOT_INTERVAL 0xc7
103 /* temp[1-4]_auto_base (nr => 0-3) */
104 #define LM93_REG_TEMP_BASE(nr) (0xd0 + (nr))
106 /* temp[1-4]_auto_offsets (step => 0-11) */
107 #define LM93_REG_TEMP_OFFSET(step) (0xd4 + (step))
109 /* #PROCHOT & #VRDHOT PWM ramp control */
110 #define LM93_REG_PWM_RAMP_CTL 0xbf
113 #define LM93_REG_SFC1 0xbc
114 #define LM93_REG_SFC2 0xbd
115 #define LM93_REG_GPI_VID_CTL 0xbe
116 #define LM93_REG_SF_TACH_TO_PWM 0xe0
119 #define LM93_REG_GPI_ERR_MASK 0xec
120 #define LM93_REG_MISC_ERR_MASK 0xed
122 /* LM93 REGISTER VALUES */
123 #define LM93_MFR_ID 0x73
124 #define LM93_MFR_ID_PROTOTYPE 0x72
126 /* LM94 REGISTER VALUES */
127 #define LM94_MFR_ID_2 0x7a
128 #define LM94_MFR_ID 0x79
129 #define LM94_MFR_ID_PROTOTYPE 0x78
131 /* SMBus capabilities */
132 #define LM93_SMBUS_FUNC_FULL (I2C_FUNC_SMBUS_BYTE_DATA | \
133 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA)
134 #define LM93_SMBUS_FUNC_MIN (I2C_FUNC_SMBUS_BYTE_DATA | \
135 I2C_FUNC_SMBUS_WORD_DATA)
137 /* Addresses to scan */
138 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
140 /* Insmod parameters */
142 static bool disable_block;
143 module_param(disable_block, bool, 0);
144 MODULE_PARM_DESC(disable_block,
145 "Set to non-zero to disable SMBus block data transactions.");
148 module_param(init, bool, 0);
149 MODULE_PARM_DESC(init, "Set to non-zero to force chip initialization.");
151 static int vccp_limit_type[2] = {0, 0};
152 module_param_array(vccp_limit_type, int, NULL, 0);
153 MODULE_PARM_DESC(vccp_limit_type, "Configures in7 and in8 limit modes.");
156 module_param(vid_agtl, int, 0);
157 MODULE_PARM_DESC(vid_agtl, "Configures VID pin input thresholds.");
160 static struct i2c_driver lm93_driver;
162 /* LM93 BLOCK READ COMMANDS */
163 static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = {
179 * ALARMS: SYSCTL format described further below
180 * REG: 64 bits in 8 registers, as immediately below
187 u8 p1_prochot_status;
188 u8 p2_prochot_status;
194 * Client-specific data
197 struct i2c_client *client;
199 struct mutex update_lock;
200 unsigned long last_updated; /* In jiffies */
202 /* client update function */
203 void (*update)(struct lm93_data *, struct i2c_client *);
205 bool valid; /* true if following fields are valid */
207 /* register values, arranged by block read groups */
208 struct block1_t block1;
211 * temp1 - temp4: unfiltered readings
212 * temp1 - temp2: filtered readings
216 /* vin1 - vin16: readings */
219 /* prochot1 - prochot2: readings */
225 /* fan counts 1-4 => 14-bits, LE, *left* justified */
228 /* block6 has a lot of data we don't need */
234 /* vin1 - vin16: low and high limits */
240 /* fan count limits 1-4 => same format as block5 */
243 /* pwm control registers (2 pwms, 4 regs) */
246 /* auto/pwm base temp and offset temp registers */
252 /* master config register */
255 /* VID1 & VID2 => register format, 6-bits, right justified */
258 /* prochot1 - prochot2: limits */
261 /* vccp1 & vccp2 (in7 & in8): VID relative limits (register format) */
264 /* GPIO input state (register format, i.e. inverted) */
267 /* #PROCHOT override (register format) */
270 /* #PROCHOT intervals (register format) */
273 /* Fan Boost Temperatures (register format) */
276 /* Fan Boost Hysteresis (register format) */
279 /* Temperature Zone Min. PWM & Hysteresis (register format) */
280 u8 auto_pwm_min_hyst[2];
282 /* #PROCHOT & #VRDHOT PWM Ramp Control */
285 /* miscellaneous setup regs */
291 * The two PWM CTL2 registers can read something other than what was
292 * last written for the OVR_DC field (duty cycle override). So, we
293 * save the user-commanded value here.
300 * REG: 6-bits, right justified, *always* using Intel VRM/VRD 10
302 static int LM93_VID_FROM_REG(u8 reg)
304 return vid_from_reg((reg & 0x3f), 100);
307 /* min, max, and nominal register values, per channel (u8) */
308 static const u8 lm93_vin_reg_min[16] = {
309 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae,
312 static const u8 lm93_vin_reg_max[16] = {
313 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
314 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,
335 * Values from the datasheet. They're here for documentation only.
336 * static const unsigned long lm93_vin_val_nom[16] = {
337 * 927, 927, 927, 1200, 1500, 1500, 1200, 1200,
338 * 3300, 5000, 2500, 1969, 984, 984, 309, 3300,
342 static unsigned LM93_IN_FROM_REG(int nr, u8 reg)
344 const long uv_max = lm93_vin_val_max[nr] * 1000;
345 const long uv_min = lm93_vin_val_min[nr] * 1000;
347 const long slope = (uv_max - uv_min) /
348 (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]);
349 const long intercept = uv_min - slope * lm93_vin_reg_min[nr];
351 return (slope * reg + intercept + 500) / 1000;
355 * IN: mV, limits determined by channel nr
356 * REG: scaling determined by channel nr
358 static u8 LM93_IN_TO_REG(int nr, unsigned val)
361 const long mv = clamp_val(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;
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 = clamp_val(result,
376 lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]);
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))
393 * vid in mV , upper == 0 indicates low limit, otherwise upper limit
394 * upper also determines which nibble of the register is returned
395 * (the other nibble will be 0x0)
397 static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid)
399 long uv_offset = vid * 1000 - val * 10000;
401 uv_offset = clamp_val(uv_offset, 12500, 200000);
402 return (u8)((uv_offset / 12500 - 1) << 4);
404 uv_offset = clamp_val(uv_offset, -400000, -25000);
405 return (u8)((uv_offset / -25000 - 1) << 0);
410 * TEMP: 1/1000 degrees C (-128C to +127C)
411 * REG: 1C/bit, two's complement
413 static int LM93_TEMP_FROM_REG(u8 reg)
415 return (s8)reg * 1000;
418 #define LM93_TEMP_MIN (-128000)
419 #define LM93_TEMP_MAX (127000)
422 * TEMP: 1/1000 degrees C (-128C to +127C)
423 * REG: 1C/bit, two's complement
425 static u8 LM93_TEMP_TO_REG(long temp)
427 int ntemp = clamp_val(temp, LM93_TEMP_MIN, LM93_TEMP_MAX);
428 ntemp += (ntemp < 0 ? -500 : 500);
429 return (u8)(ntemp / 1000);
432 /* Determine 4-bit temperature offset resolution */
433 static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr)
435 /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */
436 return sfc2 & (nr < 2 ? 0x10 : 0x20);
440 * This function is common to all 4-bit temperature offsets
441 * reg is 4 bits right justified
442 * mode 0 => 1C/bit, mode !0 => 0.5C/bit
444 static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode)
446 return (reg & 0x0f) * (mode ? 5 : 10);
449 #define LM93_TEMP_OFFSET_MIN (0)
450 #define LM93_TEMP_OFFSET_MAX0 (150)
451 #define LM93_TEMP_OFFSET_MAX1 (75)
454 * This function is common to all 4-bit temperature offsets
455 * returns 4 bits right justified
456 * mode 0 => 1C/bit, mode !0 => 0.5C/bit
458 static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode)
460 int factor = mode ? 5 : 10;
462 off = clamp_val(off, LM93_TEMP_OFFSET_MIN,
463 mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0);
464 return (u8)((off + factor/2) / factor);
468 static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode)
470 /* temp1-temp2 (nr=0,1) use lower nibble */
472 return LM93_TEMP_OFFSET_FROM_REG(reg & 0x0f, mode);
474 /* temp3-temp4 (nr=2,3) use upper nibble */
476 return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode);
480 * TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero))
481 * REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero)
484 static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode)
486 u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode);
488 /* temp1-temp2 (nr=0,1) use lower nibble */
490 return (old & 0xf0) | (new & 0x0f);
492 /* temp3-temp4 (nr=2,3) use upper nibble */
494 return (new << 4 & 0xf0) | (old & 0x0f);
497 static int LM93_AUTO_BOOST_HYST_FROM_REGS(struct lm93_data *data, int nr,
504 reg = data->boost_hyst[0] & 0x0f;
507 reg = data->boost_hyst[0] >> 4 & 0x0f;
510 reg = data->boost_hyst[1] & 0x0f;
514 reg = data->boost_hyst[1] >> 4 & 0x0f;
518 return LM93_TEMP_FROM_REG(data->boost[nr]) -
519 LM93_TEMP_OFFSET_FROM_REG(reg, mode);
522 static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst,
525 u8 reg = LM93_TEMP_OFFSET_TO_REG(
526 (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode);
530 reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f);
533 reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f);
536 reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f);
540 reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f);
548 * PWM: 0-255 per sensors documentation
549 * REG: 0-13 as mapped below... right justified
551 enum pwm_freq { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ };
553 static int lm93_pwm_map[2][16] = {
555 0x00, /* 0.00% */ 0x40, /* 25.00% */
556 0x50, /* 31.25% */ 0x60, /* 37.50% */
557 0x70, /* 43.75% */ 0x80, /* 50.00% */
558 0x90, /* 56.25% */ 0xa0, /* 62.50% */
559 0xb0, /* 68.75% */ 0xc0, /* 75.00% */
560 0xd0, /* 81.25% */ 0xe0, /* 87.50% */
561 0xf0, /* 93.75% */ 0xff, /* 100.00% */
562 0xff, 0xff, /* 14, 15 are reserved and should never occur */
565 0x00, /* 0.00% */ 0x40, /* 25.00% */
566 0x49, /* 28.57% */ 0x52, /* 32.14% */
567 0x5b, /* 35.71% */ 0x64, /* 39.29% */
568 0x6d, /* 42.86% */ 0x76, /* 46.43% */
569 0x80, /* 50.00% */ 0x89, /* 53.57% */
570 0x92, /* 57.14% */ 0xb6, /* 71.43% */
571 0xdb, /* 85.71% */ 0xff, /* 100.00% */
572 0xff, 0xff, /* 14, 15 are reserved and should never occur */
576 static int LM93_PWM_FROM_REG(u8 reg, enum pwm_freq freq)
578 return lm93_pwm_map[freq][reg & 0x0f];
581 /* round up to nearest match */
582 static u8 LM93_PWM_TO_REG(int pwm, enum pwm_freq freq)
585 for (i = 0; i < 13; i++)
586 if (pwm <= lm93_pwm_map[freq][i])
589 /* can fall through with i==13 */
593 static int LM93_FAN_FROM_REG(u16 regs)
595 const u16 count = le16_to_cpu(regs) >> 2;
596 return count == 0 ? -1 : count == 0x3fff ? 0 : 1350000 / count;
600 * RPM: (82.5 to 1350000)
601 * REG: 14-bits, LE, *left* justified
603 static u16 LM93_FAN_TO_REG(long rpm)
610 rpm = clamp_val(rpm, 1, 1000000);
611 count = clamp_val((1350000 + rpm) / rpm, 1, 0x3ffe);
615 return cpu_to_le16(regs);
620 * REG: 0-7 as mapped below
622 static int lm93_pwm_freq_map[8] = {
623 22500, 96, 84, 72, 60, 48, 36, 12
626 static int LM93_PWM_FREQ_FROM_REG(u8 reg)
628 return lm93_pwm_freq_map[reg & 0x07];
631 /* round up to nearest match */
632 static u8 LM93_PWM_FREQ_TO_REG(int freq)
635 for (i = 7; i > 0; i--)
636 if (freq <= lm93_pwm_freq_map[i])
639 /* can fall through with i==0 */
644 * TIME: 1/100 seconds
645 * REG: 0-7 as mapped below
647 static int lm93_spinup_time_map[8] = {
648 0, 10, 25, 40, 70, 100, 200, 400,
651 static int LM93_SPINUP_TIME_FROM_REG(u8 reg)
653 return lm93_spinup_time_map[reg >> 5 & 0x07];
656 /* round up to nearest match */
657 static u8 LM93_SPINUP_TIME_TO_REG(int time)
660 for (i = 0; i < 7; i++)
661 if (time <= lm93_spinup_time_map[i])
664 /* can fall through with i==8 */
668 #define LM93_RAMP_MIN 0
669 #define LM93_RAMP_MAX 75
671 static int LM93_RAMP_FROM_REG(u8 reg)
673 return (reg & 0x0f) * 5;
677 * RAMP: 1/100 seconds
678 * REG: 50mS/bit 4-bits right justified
680 static u8 LM93_RAMP_TO_REG(int ramp)
682 ramp = clamp_val(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX);
683 return (u8)((ramp + 2) / 5);
687 * PROCHOT: 0-255, 0 => 0%, 255 => > 96.6%
690 static u8 LM93_PROCHOT_TO_REG(long prochot)
692 prochot = clamp_val(prochot, 0, 255);
697 * PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds)
698 * REG: 0-9 as mapped below
700 static int lm93_interval_map[10] = {
701 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200,
704 static int LM93_INTERVAL_FROM_REG(u8 reg)
706 return lm93_interval_map[reg & 0x0f];
709 /* round up to nearest match */
710 static u8 LM93_INTERVAL_TO_REG(long interval)
713 for (i = 0; i < 9; i++)
714 if (interval <= lm93_interval_map[i])
717 /* can fall through with i==9 */
722 * GPIO: 0-255, GPIO0 is LSB
725 static unsigned LM93_GPI_FROM_REG(u8 reg)
731 * alarm bitmask definitions
732 * The LM93 has nearly 64 bits of error status... I've pared that down to
733 * what I think is a useful subset in order to fit it into 32 bits.
735 * Especially note that the #VRD_HOT alarms are missing because we provide
736 * that information as values in another sysfs file.
738 * If libsensors is extended to support 64 bit values, this could be revisited.
740 #define LM93_ALARM_IN1 0x00000001
741 #define LM93_ALARM_IN2 0x00000002
742 #define LM93_ALARM_IN3 0x00000004
743 #define LM93_ALARM_IN4 0x00000008
744 #define LM93_ALARM_IN5 0x00000010
745 #define LM93_ALARM_IN6 0x00000020
746 #define LM93_ALARM_IN7 0x00000040
747 #define LM93_ALARM_IN8 0x00000080
748 #define LM93_ALARM_IN9 0x00000100
749 #define LM93_ALARM_IN10 0x00000200
750 #define LM93_ALARM_IN11 0x00000400
751 #define LM93_ALARM_IN12 0x00000800
752 #define LM93_ALARM_IN13 0x00001000
753 #define LM93_ALARM_IN14 0x00002000
754 #define LM93_ALARM_IN15 0x00004000
755 #define LM93_ALARM_IN16 0x00008000
756 #define LM93_ALARM_FAN1 0x00010000
757 #define LM93_ALARM_FAN2 0x00020000
758 #define LM93_ALARM_FAN3 0x00040000
759 #define LM93_ALARM_FAN4 0x00080000
760 #define LM93_ALARM_PH1_ERR 0x00100000
761 #define LM93_ALARM_PH2_ERR 0x00200000
762 #define LM93_ALARM_SCSI1_ERR 0x00400000
763 #define LM93_ALARM_SCSI2_ERR 0x00800000
764 #define LM93_ALARM_DVDDP1_ERR 0x01000000
765 #define LM93_ALARM_DVDDP2_ERR 0x02000000
766 #define LM93_ALARM_D1_ERR 0x04000000
767 #define LM93_ALARM_D2_ERR 0x08000000
768 #define LM93_ALARM_TEMP1 0x10000000
769 #define LM93_ALARM_TEMP2 0x20000000
770 #define LM93_ALARM_TEMP3 0x40000000
772 static unsigned LM93_ALARMS_FROM_REG(struct block1_t b1)
775 result = b1.host_status_2 & 0x3f;
777 if (vccp_limit_type[0])
778 result |= (b1.host_status_4 & 0x10) << 2;
780 result |= b1.host_status_2 & 0x40;
782 if (vccp_limit_type[1])
783 result |= (b1.host_status_4 & 0x20) << 2;
785 result |= b1.host_status_2 & 0x80;
787 result |= b1.host_status_3 << 8;
788 result |= (b1.fan_status & 0x0f) << 16;
789 result |= (b1.p1_prochot_status & 0x80) << 13;
790 result |= (b1.p2_prochot_status & 0x80) << 14;
791 result |= (b1.host_status_4 & 0xfc) << 20;
792 result |= (b1.host_status_1 & 0x07) << 28;
796 #define MAX_RETRIES 5
798 static u8 lm93_read_byte(struct i2c_client *client, u8 reg)
802 /* retry in case of read errors */
803 for (i = 1; i <= MAX_RETRIES; i++) {
804 value = i2c_smbus_read_byte_data(client, reg);
808 dev_warn(&client->dev,
809 "lm93: read byte data failed, address 0x%02x.\n",
816 /* <TODO> what to return in case of error? */
817 dev_err(&client->dev, "lm93: All read byte retries failed!!\n");
821 static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value)
825 /* <TODO> how to handle write errors? */
826 result = i2c_smbus_write_byte_data(client, reg, value);
829 dev_warn(&client->dev,
830 "lm93: write byte data failed, 0x%02x at address 0x%02x.\n",
836 static u16 lm93_read_word(struct i2c_client *client, u8 reg)
840 /* retry in case of read errors */
841 for (i = 1; i <= MAX_RETRIES; i++) {
842 value = i2c_smbus_read_word_data(client, reg);
846 dev_warn(&client->dev,
847 "lm93: read word data failed, address 0x%02x.\n",
854 /* <TODO> what to return in case of error? */
855 dev_err(&client->dev, "lm93: All read word retries failed!!\n");
859 static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value)
863 /* <TODO> how to handle write errors? */
864 result = i2c_smbus_write_word_data(client, reg, value);
867 dev_warn(&client->dev,
868 "lm93: write word data failed, 0x%04x at address 0x%02x.\n",
874 static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX];
877 * read block data into values, retry if not expected length
878 * fbn => index to lm93_block_read_cmds table
879 * (Fixed Block Number - section 14.5.2 of LM93 datasheet)
881 static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values)
885 for (i = 1; i <= MAX_RETRIES; i++) {
886 result = i2c_smbus_read_block_data(client,
887 lm93_block_read_cmds[fbn].cmd, lm93_block_buffer);
889 if (result == lm93_block_read_cmds[fbn].len) {
892 dev_warn(&client->dev,
893 "lm93: block read data failed, command 0x%02x.\n",
894 lm93_block_read_cmds[fbn].cmd);
899 if (result == lm93_block_read_cmds[fbn].len) {
900 memcpy(values, lm93_block_buffer,
901 lm93_block_read_cmds[fbn].len);
903 /* <TODO> what to do in case of error? */
907 static struct lm93_data *lm93_update_device(struct device *dev)
909 struct lm93_data *data = dev_get_drvdata(dev);
910 struct i2c_client *client = data->client;
911 const unsigned long interval = HZ + (HZ / 2);
913 mutex_lock(&data->update_lock);
915 if (time_after(jiffies, data->last_updated + interval) ||
918 data->update(data, client);
919 data->last_updated = jiffies;
923 mutex_unlock(&data->update_lock);
927 /* update routine for data that has no corresponding SMBus block command */
928 static void lm93_update_client_common(struct lm93_data *data,
929 struct i2c_client *client)
934 /* temp1 - temp4: limits */
935 for (i = 0; i < 4; i++) {
936 data->temp_lim[i].min =
937 lm93_read_byte(client, LM93_REG_TEMP_MIN(i));
938 data->temp_lim[i].max =
939 lm93_read_byte(client, LM93_REG_TEMP_MAX(i));
942 /* config register */
943 data->config = lm93_read_byte(client, LM93_REG_CONFIG);
945 /* vid1 - vid2: values */
946 for (i = 0; i < 2; i++)
947 data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i));
949 /* prochot1 - prochot2: limits */
950 for (i = 0; i < 2; i++)
951 data->prochot_max[i] = lm93_read_byte(client,
952 LM93_REG_PROCHOT_MAX(i));
954 /* vccp1 - vccp2: VID relative limits */
955 for (i = 0; i < 2; i++)
956 data->vccp_limits[i] = lm93_read_byte(client,
957 LM93_REG_VCCP_LIMIT_OFF(i));
959 /* GPIO input state */
960 data->gpi = lm93_read_byte(client, LM93_REG_GPI);
962 /* #PROCHOT override state */
963 data->prochot_override = lm93_read_byte(client,
964 LM93_REG_PROCHOT_OVERRIDE);
966 /* #PROCHOT intervals */
967 data->prochot_interval = lm93_read_byte(client,
968 LM93_REG_PROCHOT_INTERVAL);
970 /* Fan Boost Temperature registers */
971 for (i = 0; i < 4; i++)
972 data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i));
974 /* Fan Boost Temperature Hyst. registers */
975 data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12);
976 data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34);
978 /* Temperature Zone Min. PWM & Hysteresis registers */
979 data->auto_pwm_min_hyst[0] =
980 lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_12);
981 data->auto_pwm_min_hyst[1] =
982 lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_34);
984 /* #PROCHOT & #VRDHOT PWM Ramp Control register */
985 data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
987 /* misc setup registers */
988 data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1);
989 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
990 data->sf_tach_to_pwm = lm93_read_byte(client,
991 LM93_REG_SF_TACH_TO_PWM);
993 /* write back alarm values to clear */
994 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++)
995 lm93_write_byte(client, LM93_REG_HOST_ERROR_1 + i, *(ptr + i));
998 /* update routine which uses SMBus block data commands */
999 static void lm93_update_client_full(struct lm93_data *data,
1000 struct i2c_client *client)
1002 dev_dbg(&client->dev, "starting device update (block data enabled)\n");
1004 /* in1 - in16: values & limits */
1005 lm93_read_block(client, 3, (u8 *)(data->block3));
1006 lm93_read_block(client, 7, (u8 *)(data->block7));
1008 /* temp1 - temp4: values */
1009 lm93_read_block(client, 2, (u8 *)(data->block2));
1011 /* prochot1 - prochot2: values */
1012 lm93_read_block(client, 4, (u8 *)(data->block4));
1014 /* fan1 - fan4: values & limits */
1015 lm93_read_block(client, 5, (u8 *)(data->block5));
1016 lm93_read_block(client, 8, (u8 *)(data->block8));
1018 /* pmw control registers */
1019 lm93_read_block(client, 9, (u8 *)(data->block9));
1022 lm93_read_block(client, 1, (u8 *)(&data->block1));
1024 /* auto/pwm registers */
1025 lm93_read_block(client, 10, (u8 *)(&data->block10));
1027 lm93_update_client_common(data, client);
1030 /* update routine which uses SMBus byte/word data commands only */
1031 static void lm93_update_client_min(struct lm93_data *data,
1032 struct i2c_client *client)
1037 dev_dbg(&client->dev, "starting device update (block data disabled)\n");
1039 /* in1 - in16: values & limits */
1040 for (i = 0; i < 16; i++) {
1042 lm93_read_byte(client, LM93_REG_IN(i));
1043 data->block7[i].min =
1044 lm93_read_byte(client, LM93_REG_IN_MIN(i));
1045 data->block7[i].max =
1046 lm93_read_byte(client, LM93_REG_IN_MAX(i));
1049 /* temp1 - temp4: values */
1050 for (i = 0; i < 4; i++) {
1052 lm93_read_byte(client, LM93_REG_TEMP(i));
1055 /* prochot1 - prochot2: values */
1056 for (i = 0; i < 2; i++) {
1057 data->block4[i].cur =
1058 lm93_read_byte(client, LM93_REG_PROCHOT_CUR(i));
1059 data->block4[i].avg =
1060 lm93_read_byte(client, LM93_REG_PROCHOT_AVG(i));
1063 /* fan1 - fan4: values & limits */
1064 for (i = 0; i < 4; i++) {
1066 lm93_read_word(client, LM93_REG_FAN(i));
1068 lm93_read_word(client, LM93_REG_FAN_MIN(i));
1071 /* pwm control registers */
1072 for (i = 0; i < 2; i++) {
1073 for (j = 0; j < 4; j++) {
1074 data->block9[i][j] =
1075 lm93_read_byte(client, LM93_REG_PWM_CTL(i, j));
1080 for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) {
1082 lm93_read_byte(client, LM93_REG_HOST_ERROR_1 + i);
1085 /* auto/pwm (base temp) registers */
1086 for (i = 0; i < 4; i++) {
1087 data->block10.base[i] =
1088 lm93_read_byte(client, LM93_REG_TEMP_BASE(i));
1091 /* auto/pwm (offset temp) registers */
1092 for (i = 0; i < 12; i++) {
1093 data->block10.offset[i] =
1094 lm93_read_byte(client, LM93_REG_TEMP_OFFSET(i));
1097 lm93_update_client_common(data, client);
1100 /* following are the sysfs callback functions */
1101 static ssize_t in_show(struct device *dev, struct device_attribute *attr,
1104 int nr = (to_sensor_dev_attr(attr))->index;
1106 struct lm93_data *data = lm93_update_device(dev);
1107 return sprintf(buf, "%d\n", LM93_IN_FROM_REG(nr, data->block3[nr]));
1110 static SENSOR_DEVICE_ATTR_RO(in1_input, in, 0);
1111 static SENSOR_DEVICE_ATTR_RO(in2_input, in, 1);
1112 static SENSOR_DEVICE_ATTR_RO(in3_input, in, 2);
1113 static SENSOR_DEVICE_ATTR_RO(in4_input, in, 3);
1114 static SENSOR_DEVICE_ATTR_RO(in5_input, in, 4);
1115 static SENSOR_DEVICE_ATTR_RO(in6_input, in, 5);
1116 static SENSOR_DEVICE_ATTR_RO(in7_input, in, 6);
1117 static SENSOR_DEVICE_ATTR_RO(in8_input, in, 7);
1118 static SENSOR_DEVICE_ATTR_RO(in9_input, in, 8);
1119 static SENSOR_DEVICE_ATTR_RO(in10_input, in, 9);
1120 static SENSOR_DEVICE_ATTR_RO(in11_input, in, 10);
1121 static SENSOR_DEVICE_ATTR_RO(in12_input, in, 11);
1122 static SENSOR_DEVICE_ATTR_RO(in13_input, in, 12);
1123 static SENSOR_DEVICE_ATTR_RO(in14_input, in, 13);
1124 static SENSOR_DEVICE_ATTR_RO(in15_input, in, 14);
1125 static SENSOR_DEVICE_ATTR_RO(in16_input, in, 15);
1127 static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
1130 int nr = (to_sensor_dev_attr(attr))->index;
1131 struct lm93_data *data = lm93_update_device(dev);
1135 if ((nr == 6 || nr == 7) && vccp_limit_type[vccp]) {
1136 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1137 rc = LM93_IN_MIN_FROM_REG(data->vccp_limits[vccp], vid);
1139 rc = LM93_IN_FROM_REG(nr, data->block7[nr].min);
1141 return sprintf(buf, "%ld\n", rc);
1144 static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
1145 const char *buf, size_t count)
1147 int nr = (to_sensor_dev_attr(attr))->index;
1148 struct lm93_data *data = dev_get_drvdata(dev);
1149 struct i2c_client *client = data->client;
1155 err = kstrtoul(buf, 10, &val);
1159 mutex_lock(&data->update_lock);
1160 if ((nr == 6 || nr == 7) && vccp_limit_type[vccp]) {
1161 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1162 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0xf0) |
1163 LM93_IN_REL_TO_REG(val, 0, vid);
1164 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1165 data->vccp_limits[vccp]);
1167 data->block7[nr].min = LM93_IN_TO_REG(nr, val);
1168 lm93_write_byte(client, LM93_REG_IN_MIN(nr),
1169 data->block7[nr].min);
1171 mutex_unlock(&data->update_lock);
1175 static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 0);
1176 static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 1);
1177 static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 2);
1178 static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 3);
1179 static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 4);
1180 static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 5);
1181 static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 6);
1182 static SENSOR_DEVICE_ATTR_RW(in8_min, in_min, 7);
1183 static SENSOR_DEVICE_ATTR_RW(in9_min, in_min, 8);
1184 static SENSOR_DEVICE_ATTR_RW(in10_min, in_min, 9);
1185 static SENSOR_DEVICE_ATTR_RW(in11_min, in_min, 10);
1186 static SENSOR_DEVICE_ATTR_RW(in12_min, in_min, 11);
1187 static SENSOR_DEVICE_ATTR_RW(in13_min, in_min, 12);
1188 static SENSOR_DEVICE_ATTR_RW(in14_min, in_min, 13);
1189 static SENSOR_DEVICE_ATTR_RW(in15_min, in_min, 14);
1190 static SENSOR_DEVICE_ATTR_RW(in16_min, in_min, 15);
1192 static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
1195 int nr = (to_sensor_dev_attr(attr))->index;
1196 struct lm93_data *data = lm93_update_device(dev);
1200 if ((nr == 6 || nr == 7) && vccp_limit_type[vccp]) {
1201 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1202 rc = LM93_IN_MAX_FROM_REG(data->vccp_limits[vccp], vid);
1204 rc = LM93_IN_FROM_REG(nr, data->block7[nr].max);
1206 return sprintf(buf, "%ld\n", rc);
1209 static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
1210 const char *buf, size_t count)
1212 int nr = (to_sensor_dev_attr(attr))->index;
1213 struct lm93_data *data = dev_get_drvdata(dev);
1214 struct i2c_client *client = data->client;
1220 err = kstrtoul(buf, 10, &val);
1224 mutex_lock(&data->update_lock);
1225 if ((nr == 6 || nr == 7) && vccp_limit_type[vccp]) {
1226 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1227 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0x0f) |
1228 LM93_IN_REL_TO_REG(val, 1, vid);
1229 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1230 data->vccp_limits[vccp]);
1232 data->block7[nr].max = LM93_IN_TO_REG(nr, val);
1233 lm93_write_byte(client, LM93_REG_IN_MAX(nr),
1234 data->block7[nr].max);
1236 mutex_unlock(&data->update_lock);
1240 static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 0);
1241 static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 1);
1242 static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 2);
1243 static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 3);
1244 static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 4);
1245 static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 5);
1246 static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 6);
1247 static SENSOR_DEVICE_ATTR_RW(in8_max, in_max, 7);
1248 static SENSOR_DEVICE_ATTR_RW(in9_max, in_max, 8);
1249 static SENSOR_DEVICE_ATTR_RW(in10_max, in_max, 9);
1250 static SENSOR_DEVICE_ATTR_RW(in11_max, in_max, 10);
1251 static SENSOR_DEVICE_ATTR_RW(in12_max, in_max, 11);
1252 static SENSOR_DEVICE_ATTR_RW(in13_max, in_max, 12);
1253 static SENSOR_DEVICE_ATTR_RW(in14_max, in_max, 13);
1254 static SENSOR_DEVICE_ATTR_RW(in15_max, in_max, 14);
1255 static SENSOR_DEVICE_ATTR_RW(in16_max, in_max, 15);
1257 static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
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->block2[nr]));
1265 static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
1266 static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
1267 static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
1269 static ssize_t temp_min_show(struct device *dev,
1270 struct device_attribute *attr, char *buf)
1272 int nr = (to_sensor_dev_attr(attr))->index;
1273 struct lm93_data *data = lm93_update_device(dev);
1274 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->temp_lim[nr].min));
1277 static ssize_t temp_min_store(struct device *dev,
1278 struct device_attribute *attr, const char *buf,
1281 int nr = (to_sensor_dev_attr(attr))->index;
1282 struct lm93_data *data = dev_get_drvdata(dev);
1283 struct i2c_client *client = data->client;
1287 err = kstrtol(buf, 10, &val);
1291 mutex_lock(&data->update_lock);
1292 data->temp_lim[nr].min = LM93_TEMP_TO_REG(val);
1293 lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), data->temp_lim[nr].min);
1294 mutex_unlock(&data->update_lock);
1298 static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
1299 static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
1300 static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
1302 static ssize_t temp_max_show(struct device *dev,
1303 struct device_attribute *attr, char *buf)
1305 int nr = (to_sensor_dev_attr(attr))->index;
1306 struct lm93_data *data = lm93_update_device(dev);
1307 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->temp_lim[nr].max));
1310 static ssize_t temp_max_store(struct device *dev,
1311 struct device_attribute *attr, const char *buf,
1314 int nr = (to_sensor_dev_attr(attr))->index;
1315 struct lm93_data *data = dev_get_drvdata(dev);
1316 struct i2c_client *client = data->client;
1320 err = kstrtol(buf, 10, &val);
1324 mutex_lock(&data->update_lock);
1325 data->temp_lim[nr].max = LM93_TEMP_TO_REG(val);
1326 lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), data->temp_lim[nr].max);
1327 mutex_unlock(&data->update_lock);
1331 static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
1332 static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
1333 static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
1335 static ssize_t temp_auto_base_show(struct device *dev,
1336 struct device_attribute *attr, char *buf)
1338 int nr = (to_sensor_dev_attr(attr))->index;
1339 struct lm93_data *data = lm93_update_device(dev);
1340 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->block10.base[nr]));
1343 static ssize_t temp_auto_base_store(struct device *dev,
1344 struct device_attribute *attr,
1345 const char *buf, size_t count)
1347 int nr = (to_sensor_dev_attr(attr))->index;
1348 struct lm93_data *data = dev_get_drvdata(dev);
1349 struct i2c_client *client = data->client;
1353 err = kstrtol(buf, 10, &val);
1357 mutex_lock(&data->update_lock);
1358 data->block10.base[nr] = LM93_TEMP_TO_REG(val);
1359 lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), data->block10.base[nr]);
1360 mutex_unlock(&data->update_lock);
1364 static SENSOR_DEVICE_ATTR_RW(temp1_auto_base, temp_auto_base, 0);
1365 static SENSOR_DEVICE_ATTR_RW(temp2_auto_base, temp_auto_base, 1);
1366 static SENSOR_DEVICE_ATTR_RW(temp3_auto_base, temp_auto_base, 2);
1368 static ssize_t temp_auto_boost_show(struct device *dev,
1369 struct device_attribute *attr, char *buf)
1371 int nr = (to_sensor_dev_attr(attr))->index;
1372 struct lm93_data *data = lm93_update_device(dev);
1373 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->boost[nr]));
1376 static ssize_t temp_auto_boost_store(struct device *dev,
1377 struct device_attribute *attr,
1378 const char *buf, size_t count)
1380 int nr = (to_sensor_dev_attr(attr))->index;
1381 struct lm93_data *data = dev_get_drvdata(dev);
1382 struct i2c_client *client = data->client;
1386 err = kstrtol(buf, 10, &val);
1390 mutex_lock(&data->update_lock);
1391 data->boost[nr] = LM93_TEMP_TO_REG(val);
1392 lm93_write_byte(client, LM93_REG_BOOST(nr), data->boost[nr]);
1393 mutex_unlock(&data->update_lock);
1397 static SENSOR_DEVICE_ATTR_RW(temp1_auto_boost, temp_auto_boost, 0);
1398 static SENSOR_DEVICE_ATTR_RW(temp2_auto_boost, temp_auto_boost, 1);
1399 static SENSOR_DEVICE_ATTR_RW(temp3_auto_boost, temp_auto_boost, 2);
1401 static ssize_t temp_auto_boost_hyst_show(struct device *dev,
1402 struct device_attribute *attr,
1405 int nr = (to_sensor_dev_attr(attr))->index;
1406 struct lm93_data *data = lm93_update_device(dev);
1407 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1408 return sprintf(buf, "%d\n",
1409 LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode));
1412 static ssize_t temp_auto_boost_hyst_store(struct device *dev,
1413 struct device_attribute *attr,
1414 const char *buf, size_t count)
1416 int nr = (to_sensor_dev_attr(attr))->index;
1417 struct lm93_data *data = dev_get_drvdata(dev);
1418 struct i2c_client *client = data->client;
1422 err = kstrtoul(buf, 10, &val);
1426 mutex_lock(&data->update_lock);
1427 /* force 0.5C/bit mode */
1428 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1429 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1430 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1431 data->boost_hyst[nr/2] = LM93_AUTO_BOOST_HYST_TO_REG(data, val, nr, 1);
1432 lm93_write_byte(client, LM93_REG_BOOST_HYST(nr),
1433 data->boost_hyst[nr/2]);
1434 mutex_unlock(&data->update_lock);
1438 static SENSOR_DEVICE_ATTR_RW(temp1_auto_boost_hyst, temp_auto_boost_hyst, 0);
1439 static SENSOR_DEVICE_ATTR_RW(temp2_auto_boost_hyst, temp_auto_boost_hyst, 1);
1440 static SENSOR_DEVICE_ATTR_RW(temp3_auto_boost_hyst, temp_auto_boost_hyst, 2);
1442 static ssize_t temp_auto_offset_show(struct device *dev,
1443 struct device_attribute *attr, char *buf)
1445 struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr);
1446 int nr = s_attr->index;
1447 int ofs = s_attr->nr;
1448 struct lm93_data *data = lm93_update_device(dev);
1449 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1450 return sprintf(buf, "%d\n",
1451 LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs],
1455 static ssize_t temp_auto_offset_store(struct device *dev,
1456 struct device_attribute *attr,
1457 const char *buf, size_t count)
1459 struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr);
1460 int nr = s_attr->index;
1461 int ofs = s_attr->nr;
1462 struct lm93_data *data = dev_get_drvdata(dev);
1463 struct i2c_client *client = data->client;
1467 err = kstrtoul(buf, 10, &val);
1471 mutex_lock(&data->update_lock);
1472 /* force 0.5C/bit mode */
1473 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1474 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1475 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1476 data->block10.offset[ofs] = LM93_TEMP_AUTO_OFFSET_TO_REG(
1477 data->block10.offset[ofs], val, nr, 1);
1478 lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ofs),
1479 data->block10.offset[ofs]);
1480 mutex_unlock(&data->update_lock);
1484 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset1, temp_auto_offset, 0, 0);
1485 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset2, temp_auto_offset, 1, 0);
1486 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset3, temp_auto_offset, 2, 0);
1487 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset4, temp_auto_offset, 3, 0);
1488 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset5, temp_auto_offset, 4, 0);
1489 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset6, temp_auto_offset, 5, 0);
1490 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset7, temp_auto_offset, 6, 0);
1491 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset8, temp_auto_offset, 7, 0);
1492 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset9, temp_auto_offset, 8, 0);
1493 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset10, temp_auto_offset, 9, 0);
1494 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset11, temp_auto_offset, 10, 0);
1495 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_offset12, temp_auto_offset, 11, 0);
1496 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset1, temp_auto_offset, 0, 1);
1497 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset2, temp_auto_offset, 1, 1);
1498 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset3, temp_auto_offset, 2, 1);
1499 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset4, temp_auto_offset, 3, 1);
1500 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset5, temp_auto_offset, 4, 1);
1501 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset6, temp_auto_offset, 5, 1);
1502 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset7, temp_auto_offset, 6, 1);
1503 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset8, temp_auto_offset, 7, 1);
1504 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset9, temp_auto_offset, 8, 1);
1505 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset10, temp_auto_offset, 9, 1);
1506 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset11, temp_auto_offset, 10, 1);
1507 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_offset12, temp_auto_offset, 11, 1);
1508 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset1, temp_auto_offset, 0, 2);
1509 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset2, temp_auto_offset, 1, 2);
1510 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset3, temp_auto_offset, 2, 2);
1511 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset4, temp_auto_offset, 3, 2);
1512 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset5, temp_auto_offset, 4, 2);
1513 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset6, temp_auto_offset, 5, 2);
1514 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset7, temp_auto_offset, 6, 2);
1515 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset8, temp_auto_offset, 7, 2);
1516 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset9, temp_auto_offset, 8, 2);
1517 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset10, temp_auto_offset, 9, 2);
1518 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset11, temp_auto_offset, 10, 2);
1519 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_offset12, temp_auto_offset, 11, 2);
1521 static ssize_t temp_auto_pwm_min_show(struct device *dev,
1522 struct device_attribute *attr,
1525 int nr = (to_sensor_dev_attr(attr))->index;
1527 struct lm93_data *data = lm93_update_device(dev);
1528 reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f;
1529 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1530 return sprintf(buf, "%d\n", LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ?
1531 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));
1534 static ssize_t temp_auto_pwm_min_store(struct device *dev,
1535 struct device_attribute *attr,
1536 const char *buf, size_t count)
1538 int nr = (to_sensor_dev_attr(attr))->index;
1539 struct lm93_data *data = dev_get_drvdata(dev);
1540 struct i2c_client *client = data->client;
1545 err = kstrtoul(buf, 10, &val);
1549 mutex_lock(&data->update_lock);
1550 reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr));
1551 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1552 reg = (reg & 0x0f) |
1553 LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1554 LM93_PWM_MAP_LO_FREQ :
1555 LM93_PWM_MAP_HI_FREQ) << 4;
1556 data->auto_pwm_min_hyst[nr/2] = reg;
1557 lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg);
1558 mutex_unlock(&data->update_lock);
1562 static SENSOR_DEVICE_ATTR_RW(temp1_auto_pwm_min, temp_auto_pwm_min, 0);
1563 static SENSOR_DEVICE_ATTR_RW(temp2_auto_pwm_min, temp_auto_pwm_min, 1);
1564 static SENSOR_DEVICE_ATTR_RW(temp3_auto_pwm_min, temp_auto_pwm_min, 2);
1566 static ssize_t temp_auto_offset_hyst_show(struct device *dev,
1567 struct device_attribute *attr,
1570 int nr = (to_sensor_dev_attr(attr))->index;
1571 struct lm93_data *data = lm93_update_device(dev);
1572 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1573 return sprintf(buf, "%d\n", LM93_TEMP_OFFSET_FROM_REG(
1574 data->auto_pwm_min_hyst[nr / 2], mode));
1577 static ssize_t temp_auto_offset_hyst_store(struct device *dev,
1578 struct device_attribute *attr,
1579 const char *buf, size_t count)
1581 int nr = (to_sensor_dev_attr(attr))->index;
1582 struct lm93_data *data = dev_get_drvdata(dev);
1583 struct i2c_client *client = data->client;
1588 err = kstrtoul(buf, 10, &val);
1592 mutex_lock(&data->update_lock);
1593 /* force 0.5C/bit mode */
1594 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1595 data->sfc2 |= ((nr < 2) ? 0x10 : 0x20);
1596 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1597 reg = data->auto_pwm_min_hyst[nr/2];
1598 reg = (reg & 0xf0) | (LM93_TEMP_OFFSET_TO_REG(val, 1) & 0x0f);
1599 data->auto_pwm_min_hyst[nr/2] = reg;
1600 lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg);
1601 mutex_unlock(&data->update_lock);
1605 static SENSOR_DEVICE_ATTR_RW(temp1_auto_offset_hyst, temp_auto_offset_hyst, 0);
1606 static SENSOR_DEVICE_ATTR_RW(temp2_auto_offset_hyst, temp_auto_offset_hyst, 1);
1607 static SENSOR_DEVICE_ATTR_RW(temp3_auto_offset_hyst, temp_auto_offset_hyst, 2);
1609 static ssize_t fan_input_show(struct device *dev,
1610 struct device_attribute *attr, char *buf)
1612 struct sensor_device_attribute *s_attr = to_sensor_dev_attr(attr);
1613 int nr = s_attr->index;
1614 struct lm93_data *data = lm93_update_device(dev);
1616 return sprintf(buf, "%d\n", LM93_FAN_FROM_REG(data->block5[nr]));
1619 static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0);
1620 static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1);
1621 static SENSOR_DEVICE_ATTR_RO(fan3_input, fan_input, 2);
1622 static SENSOR_DEVICE_ATTR_RO(fan4_input, fan_input, 3);
1624 static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
1627 int nr = (to_sensor_dev_attr(attr))->index;
1628 struct lm93_data *data = lm93_update_device(dev);
1630 return sprintf(buf, "%d\n", LM93_FAN_FROM_REG(data->block8[nr]));
1633 static ssize_t fan_min_store(struct device *dev,
1634 struct device_attribute *attr, const char *buf,
1637 int nr = (to_sensor_dev_attr(attr))->index;
1638 struct lm93_data *data = dev_get_drvdata(dev);
1639 struct i2c_client *client = data->client;
1643 err = kstrtoul(buf, 10, &val);
1647 mutex_lock(&data->update_lock);
1648 data->block8[nr] = LM93_FAN_TO_REG(val);
1649 lm93_write_word(client, LM93_REG_FAN_MIN(nr), data->block8[nr]);
1650 mutex_unlock(&data->update_lock);
1654 static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
1655 static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
1656 static SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2);
1657 static SENSOR_DEVICE_ATTR_RW(fan4_min, fan_min, 3);
1660 * some tedious bit-twiddling here to deal with the register format:
1662 * data->sf_tach_to_pwm: (tach to pwm mapping bits)
1664 * bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
1665 * T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1
1667 * data->sfc2: (enable bits)
1669 * bit | 3 | 2 | 1 | 0
1673 static ssize_t fan_smart_tach_show(struct device *dev,
1674 struct device_attribute *attr, char *buf)
1676 int nr = (to_sensor_dev_attr(attr))->index;
1677 struct lm93_data *data = lm93_update_device(dev);
1681 /* extract the relevant mapping */
1682 mapping = (data->sf_tach_to_pwm >> (nr * 2)) & 0x03;
1684 /* if there's a mapping and it's enabled */
1685 if (mapping && ((data->sfc2 >> nr) & 0x01))
1687 return sprintf(buf, "%ld\n", rc);
1691 * helper function - must grab data->update_lock before calling
1692 * fan is 0-3, indicating fan1-fan4
1694 static void lm93_write_fan_smart_tach(struct i2c_client *client,
1695 struct lm93_data *data, int fan, long value)
1697 /* insert the new mapping and write it out */
1698 data->sf_tach_to_pwm = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM);
1699 data->sf_tach_to_pwm &= ~(0x3 << fan * 2);
1700 data->sf_tach_to_pwm |= value << fan * 2;
1701 lm93_write_byte(client, LM93_REG_SF_TACH_TO_PWM, data->sf_tach_to_pwm);
1703 /* insert the enable bit and write it out */
1704 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1706 data->sfc2 |= 1 << fan;
1708 data->sfc2 &= ~(1 << fan);
1709 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1712 static ssize_t fan_smart_tach_store(struct device *dev,
1713 struct device_attribute *attr,
1714 const char *buf, size_t count)
1716 int nr = (to_sensor_dev_attr(attr))->index;
1717 struct lm93_data *data = dev_get_drvdata(dev);
1718 struct i2c_client *client = data->client;
1722 err = kstrtoul(buf, 10, &val);
1726 mutex_lock(&data->update_lock);
1727 /* sanity test, ignore the write otherwise */
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_RW(fan1_smart_tach, fan_smart_tach, 0);
1743 static SENSOR_DEVICE_ATTR_RW(fan2_smart_tach, fan_smart_tach, 1);
1744 static SENSOR_DEVICE_ATTR_RW(fan3_smart_tach, fan_smart_tach, 2);
1745 static SENSOR_DEVICE_ATTR_RW(fan4_smart_tach, fan_smart_tach, 3);
1747 static ssize_t pwm_show(struct device *dev, struct device_attribute *attr,
1750 int nr = (to_sensor_dev_attr(attr))->index;
1751 struct lm93_data *data = lm93_update_device(dev);
1755 ctl2 = data->block9[nr][LM93_PWM_CTL2];
1756 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1757 if (ctl2 & 0x01) /* show user commanded value if enabled */
1758 rc = data->pwm_override[nr];
1759 else /* show present h/w value if manual pwm disabled */
1760 rc = LM93_PWM_FROM_REG(ctl2 >> 4, (ctl4 & 0x07) ?
1761 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ);
1762 return sprintf(buf, "%ld\n", rc);
1765 static ssize_t pwm_store(struct device *dev, struct device_attribute *attr,
1766 const char *buf, size_t count)
1768 int nr = (to_sensor_dev_attr(attr))->index;
1769 struct lm93_data *data = dev_get_drvdata(dev);
1770 struct i2c_client *client = data->client;
1775 err = kstrtoul(buf, 10, &val);
1779 mutex_lock(&data->update_lock);
1780 ctl2 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL2));
1781 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1782 ctl2 = (ctl2 & 0x0f) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1783 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ) << 4;
1784 /* save user commanded value */
1785 data->pwm_override[nr] = LM93_PWM_FROM_REG(ctl2 >> 4,
1786 (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ :
1787 LM93_PWM_MAP_HI_FREQ);
1788 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL2), ctl2);
1789 mutex_unlock(&data->update_lock);
1793 static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0);
1794 static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1);
1796 static ssize_t pwm_enable_show(struct device *dev,
1797 struct device_attribute *attr, char *buf)
1799 int nr = (to_sensor_dev_attr(attr))->index;
1800 struct lm93_data *data = lm93_update_device(dev);
1804 ctl2 = data->block9[nr][LM93_PWM_CTL2];
1805 if (ctl2 & 0x01) /* manual override enabled ? */
1806 rc = ((ctl2 & 0xF0) == 0xF0) ? 0 : 1;
1809 return sprintf(buf, "%ld\n", rc);
1812 static ssize_t pwm_enable_store(struct device *dev,
1813 struct device_attribute *attr,
1814 const char *buf, size_t count)
1816 int nr = (to_sensor_dev_attr(attr))->index;
1817 struct lm93_data *data = dev_get_drvdata(dev);
1818 struct i2c_client *client = data->client;
1823 err = kstrtoul(buf, 10, &val);
1827 mutex_lock(&data->update_lock);
1828 ctl2 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL2));
1832 ctl2 |= 0xF1; /* enable manual override, set PWM to max */
1835 ctl2 |= 0x01; /* enable manual override */
1838 ctl2 &= ~0x01; /* disable manual override */
1841 mutex_unlock(&data->update_lock);
1845 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL2), ctl2);
1846 mutex_unlock(&data->update_lock);
1850 static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_enable, 0);
1851 static SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_enable, 1);
1853 static ssize_t pwm_freq_show(struct device *dev,
1854 struct device_attribute *attr, char *buf)
1856 int nr = (to_sensor_dev_attr(attr))->index;
1857 struct lm93_data *data = lm93_update_device(dev);
1860 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1861 return sprintf(buf, "%d\n", LM93_PWM_FREQ_FROM_REG(ctl4));
1865 * helper function - must grab data->update_lock before calling
1866 * pwm is 0-1, indicating pwm1-pwm2
1867 * this disables smart tach for all tach channels bound to the given pwm
1869 static void lm93_disable_fan_smart_tach(struct i2c_client *client,
1870 struct lm93_data *data, int pwm)
1872 int mapping = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM);
1875 /* collapse the mapping into a mask of enable bits */
1876 mapping = (mapping >> pwm) & 0x55;
1877 mask = mapping & 0x01;
1878 mask |= (mapping & 0x04) >> 1;
1879 mask |= (mapping & 0x10) >> 2;
1880 mask |= (mapping & 0x40) >> 3;
1882 /* disable smart tach according to the mask */
1883 data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2);
1884 data->sfc2 &= ~mask;
1885 lm93_write_byte(client, LM93_REG_SFC2, data->sfc2);
1888 static ssize_t pwm_freq_store(struct device *dev,
1889 struct device_attribute *attr, const char *buf,
1892 int nr = (to_sensor_dev_attr(attr))->index;
1893 struct lm93_data *data = dev_get_drvdata(dev);
1894 struct i2c_client *client = data->client;
1899 err = kstrtoul(buf, 10, &val);
1903 mutex_lock(&data->update_lock);
1904 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1905 ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(val);
1906 data->block9[nr][LM93_PWM_CTL4] = ctl4;
1907 /* ctl4 == 0 -> 22.5KHz -> disable smart tach */
1909 lm93_disable_fan_smart_tach(client, data, nr);
1910 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4), ctl4);
1911 mutex_unlock(&data->update_lock);
1915 static SENSOR_DEVICE_ATTR_RW(pwm1_freq, pwm_freq, 0);
1916 static SENSOR_DEVICE_ATTR_RW(pwm2_freq, pwm_freq, 1);
1918 static ssize_t pwm_auto_channels_show(struct device *dev,
1919 struct device_attribute *attr,
1922 int nr = (to_sensor_dev_attr(attr))->index;
1923 struct lm93_data *data = lm93_update_device(dev);
1924 return sprintf(buf, "%d\n", data->block9[nr][LM93_PWM_CTL1]);
1927 static ssize_t pwm_auto_channels_store(struct device *dev,
1928 struct device_attribute *attr,
1929 const char *buf, size_t count)
1931 int nr = (to_sensor_dev_attr(attr))->index;
1932 struct lm93_data *data = dev_get_drvdata(dev);
1933 struct i2c_client *client = data->client;
1937 err = kstrtoul(buf, 10, &val);
1941 mutex_lock(&data->update_lock);
1942 data->block9[nr][LM93_PWM_CTL1] = clamp_val(val, 0, 255);
1943 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL1),
1944 data->block9[nr][LM93_PWM_CTL1]);
1945 mutex_unlock(&data->update_lock);
1949 static SENSOR_DEVICE_ATTR_RW(pwm1_auto_channels, pwm_auto_channels, 0);
1950 static SENSOR_DEVICE_ATTR_RW(pwm2_auto_channels, pwm_auto_channels, 1);
1952 static ssize_t pwm_auto_spinup_min_show(struct device *dev,
1953 struct device_attribute *attr,
1956 int nr = (to_sensor_dev_attr(attr))->index;
1957 struct lm93_data *data = lm93_update_device(dev);
1960 ctl3 = data->block9[nr][LM93_PWM_CTL3];
1961 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1962 return sprintf(buf, "%d\n",
1963 LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ?
1964 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));
1967 static ssize_t pwm_auto_spinup_min_store(struct device *dev,
1968 struct device_attribute *attr,
1969 const char *buf, size_t count)
1971 int nr = (to_sensor_dev_attr(attr))->index;
1972 struct lm93_data *data = dev_get_drvdata(dev);
1973 struct i2c_client *client = data->client;
1978 err = kstrtoul(buf, 10, &val);
1982 mutex_lock(&data->update_lock);
1983 ctl3 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3));
1984 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1985 ctl3 = (ctl3 & 0xf0) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1986 LM93_PWM_MAP_LO_FREQ :
1987 LM93_PWM_MAP_HI_FREQ);
1988 data->block9[nr][LM93_PWM_CTL3] = ctl3;
1989 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3);
1990 mutex_unlock(&data->update_lock);
1994 static SENSOR_DEVICE_ATTR_RW(pwm1_auto_spinup_min, pwm_auto_spinup_min, 0);
1995 static SENSOR_DEVICE_ATTR_RW(pwm2_auto_spinup_min, pwm_auto_spinup_min, 1);
1997 static ssize_t pwm_auto_spinup_time_show(struct device *dev,
1998 struct device_attribute *attr,
2001 int nr = (to_sensor_dev_attr(attr))->index;
2002 struct lm93_data *data = lm93_update_device(dev);
2003 return sprintf(buf, "%d\n", LM93_SPINUP_TIME_FROM_REG(
2004 data->block9[nr][LM93_PWM_CTL3]));
2007 static ssize_t pwm_auto_spinup_time_store(struct device *dev,
2008 struct device_attribute *attr,
2009 const char *buf, size_t count)
2011 int nr = (to_sensor_dev_attr(attr))->index;
2012 struct lm93_data *data = dev_get_drvdata(dev);
2013 struct i2c_client *client = data->client;
2018 err = kstrtoul(buf, 10, &val);
2022 mutex_lock(&data->update_lock);
2023 ctl3 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3));
2024 ctl3 = (ctl3 & 0x1f) | (LM93_SPINUP_TIME_TO_REG(val) << 5 & 0xe0);
2025 data->block9[nr][LM93_PWM_CTL3] = ctl3;
2026 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3);
2027 mutex_unlock(&data->update_lock);
2031 static SENSOR_DEVICE_ATTR_RW(pwm1_auto_spinup_time, pwm_auto_spinup_time, 0);
2032 static SENSOR_DEVICE_ATTR_RW(pwm2_auto_spinup_time, pwm_auto_spinup_time, 1);
2034 static ssize_t pwm_auto_prochot_ramp_show(struct device *dev,
2035 struct device_attribute *attr, char *buf)
2037 struct lm93_data *data = lm93_update_device(dev);
2038 return sprintf(buf, "%d\n",
2039 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl >> 4 & 0x0f));
2042 static ssize_t pwm_auto_prochot_ramp_store(struct device *dev,
2043 struct device_attribute *attr,
2044 const char *buf, size_t count)
2046 struct lm93_data *data = dev_get_drvdata(dev);
2047 struct i2c_client *client = data->client;
2052 err = kstrtoul(buf, 10, &val);
2056 mutex_lock(&data->update_lock);
2057 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
2058 ramp = (ramp & 0x0f) | (LM93_RAMP_TO_REG(val) << 4 & 0xf0);
2059 lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp);
2060 mutex_unlock(&data->update_lock);
2064 static DEVICE_ATTR_RW(pwm_auto_prochot_ramp);
2066 static ssize_t pwm_auto_vrdhot_ramp_show(struct device *dev,
2067 struct device_attribute *attr, char *buf)
2069 struct lm93_data *data = lm93_update_device(dev);
2070 return sprintf(buf, "%d\n",
2071 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl & 0x0f));
2074 static ssize_t pwm_auto_vrdhot_ramp_store(struct device *dev,
2075 struct device_attribute *attr,
2076 const char *buf, size_t count)
2078 struct lm93_data *data = dev_get_drvdata(dev);
2079 struct i2c_client *client = data->client;
2084 err = kstrtoul(buf, 10, &val);
2088 mutex_lock(&data->update_lock);
2089 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
2090 ramp = (ramp & 0xf0) | (LM93_RAMP_TO_REG(val) & 0x0f);
2091 lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp);
2092 mutex_unlock(&data->update_lock);
2096 static DEVICE_ATTR_RW(pwm_auto_vrdhot_ramp);
2098 static ssize_t vid_show(struct device *dev, struct device_attribute *attr,
2101 int nr = (to_sensor_dev_attr(attr))->index;
2102 struct lm93_data *data = lm93_update_device(dev);
2103 return sprintf(buf, "%d\n", LM93_VID_FROM_REG(data->vid[nr]));
2106 static SENSOR_DEVICE_ATTR_RO(cpu0_vid, vid, 0);
2107 static SENSOR_DEVICE_ATTR_RO(cpu1_vid, vid, 1);
2109 static ssize_t prochot_show(struct device *dev, struct device_attribute *attr,
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->block4[nr].cur);
2117 static SENSOR_DEVICE_ATTR_RO(prochot1, prochot, 0);
2118 static SENSOR_DEVICE_ATTR_RO(prochot2, prochot, 1);
2120 static ssize_t prochot_avg_show(struct device *dev,
2121 struct device_attribute *attr, char *buf)
2123 int nr = (to_sensor_dev_attr(attr))->index;
2124 struct lm93_data *data = lm93_update_device(dev);
2125 return sprintf(buf, "%d\n", data->block4[nr].avg);
2128 static SENSOR_DEVICE_ATTR_RO(prochot1_avg, prochot_avg, 0);
2129 static SENSOR_DEVICE_ATTR_RO(prochot2_avg, prochot_avg, 1);
2131 static ssize_t prochot_max_show(struct device *dev,
2132 struct device_attribute *attr, char *buf)
2134 int nr = (to_sensor_dev_attr(attr))->index;
2135 struct lm93_data *data = lm93_update_device(dev);
2136 return sprintf(buf, "%d\n", data->prochot_max[nr]);
2139 static ssize_t prochot_max_store(struct device *dev,
2140 struct device_attribute *attr,
2141 const char *buf, size_t count)
2143 int nr = (to_sensor_dev_attr(attr))->index;
2144 struct lm93_data *data = dev_get_drvdata(dev);
2145 struct i2c_client *client = data->client;
2149 err = kstrtoul(buf, 10, &val);
2153 mutex_lock(&data->update_lock);
2154 data->prochot_max[nr] = LM93_PROCHOT_TO_REG(val);
2155 lm93_write_byte(client, LM93_REG_PROCHOT_MAX(nr),
2156 data->prochot_max[nr]);
2157 mutex_unlock(&data->update_lock);
2161 static SENSOR_DEVICE_ATTR_RW(prochot1_max, prochot_max, 0);
2162 static SENSOR_DEVICE_ATTR_RW(prochot2_max, prochot_max, 1);
2164 static const u8 prochot_override_mask[] = { 0x80, 0x40 };
2166 static ssize_t prochot_override_show(struct device *dev,
2167 struct device_attribute *attr, char *buf)
2169 int nr = (to_sensor_dev_attr(attr))->index;
2170 struct lm93_data *data = lm93_update_device(dev);
2171 return sprintf(buf, "%d\n",
2172 (data->prochot_override & prochot_override_mask[nr]) ? 1 : 0);
2175 static ssize_t prochot_override_store(struct device *dev,
2176 struct device_attribute *attr,
2177 const char *buf, size_t count)
2179 int nr = (to_sensor_dev_attr(attr))->index;
2180 struct lm93_data *data = dev_get_drvdata(dev);
2181 struct i2c_client *client = data->client;
2185 err = kstrtoul(buf, 10, &val);
2189 mutex_lock(&data->update_lock);
2191 data->prochot_override |= prochot_override_mask[nr];
2193 data->prochot_override &= (~prochot_override_mask[nr]);
2194 lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE,
2195 data->prochot_override);
2196 mutex_unlock(&data->update_lock);
2200 static SENSOR_DEVICE_ATTR_RW(prochot1_override, prochot_override, 0);
2201 static SENSOR_DEVICE_ATTR_RW(prochot2_override, prochot_override, 1);
2203 static ssize_t prochot_interval_show(struct device *dev,
2204 struct device_attribute *attr, char *buf)
2206 int nr = (to_sensor_dev_attr(attr))->index;
2207 struct lm93_data *data = lm93_update_device(dev);
2210 tmp = (data->prochot_interval & 0xf0) >> 4;
2212 tmp = data->prochot_interval & 0x0f;
2213 return sprintf(buf, "%d\n", LM93_INTERVAL_FROM_REG(tmp));
2216 static ssize_t prochot_interval_store(struct device *dev,
2217 struct device_attribute *attr,
2218 const char *buf, size_t count)
2220 int nr = (to_sensor_dev_attr(attr))->index;
2221 struct lm93_data *data = dev_get_drvdata(dev);
2222 struct i2c_client *client = data->client;
2227 err = kstrtoul(buf, 10, &val);
2231 mutex_lock(&data->update_lock);
2232 tmp = lm93_read_byte(client, LM93_REG_PROCHOT_INTERVAL);
2234 tmp = (tmp & 0x0f) | (LM93_INTERVAL_TO_REG(val) << 4);
2236 tmp = (tmp & 0xf0) | LM93_INTERVAL_TO_REG(val);
2237 data->prochot_interval = tmp;
2238 lm93_write_byte(client, LM93_REG_PROCHOT_INTERVAL, tmp);
2239 mutex_unlock(&data->update_lock);
2243 static SENSOR_DEVICE_ATTR_RW(prochot1_interval, prochot_interval, 0);
2244 static SENSOR_DEVICE_ATTR_RW(prochot2_interval, prochot_interval, 1);
2246 static ssize_t prochot_override_duty_cycle_show(struct device *dev,
2247 struct device_attribute *attr,
2250 struct lm93_data *data = lm93_update_device(dev);
2251 return sprintf(buf, "%d\n", data->prochot_override & 0x0f);
2254 static ssize_t prochot_override_duty_cycle_store(struct device *dev,
2255 struct device_attribute *attr,
2256 const char *buf, size_t count)
2258 struct lm93_data *data = dev_get_drvdata(dev);
2259 struct i2c_client *client = data->client;
2263 err = kstrtoul(buf, 10, &val);
2267 mutex_lock(&data->update_lock);
2268 data->prochot_override = (data->prochot_override & 0xf0) |
2269 clamp_val(val, 0, 15);
2270 lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE,
2271 data->prochot_override);
2272 mutex_unlock(&data->update_lock);
2276 static DEVICE_ATTR_RW(prochot_override_duty_cycle);
2278 static ssize_t prochot_short_show(struct device *dev,
2279 struct device_attribute *attr, char *buf)
2281 struct lm93_data *data = lm93_update_device(dev);
2282 return sprintf(buf, "%d\n", (data->config & 0x10) ? 1 : 0);
2285 static ssize_t prochot_short_store(struct device *dev,
2286 struct device_attribute *attr,
2287 const char *buf, size_t count)
2289 struct lm93_data *data = dev_get_drvdata(dev);
2290 struct i2c_client *client = data->client;
2294 err = kstrtoul(buf, 10, &val);
2298 mutex_lock(&data->update_lock);
2300 data->config |= 0x10;
2302 data->config &= ~0x10;
2303 lm93_write_byte(client, LM93_REG_CONFIG, data->config);
2304 mutex_unlock(&data->update_lock);
2308 static DEVICE_ATTR_RW(prochot_short);
2310 static ssize_t vrdhot_show(struct device *dev, struct device_attribute *attr,
2313 int nr = (to_sensor_dev_attr(attr))->index;
2314 struct lm93_data *data = lm93_update_device(dev);
2315 return sprintf(buf, "%d\n",
2316 data->block1.host_status_1 & (1 << (nr + 4)) ? 1 : 0);
2319 static SENSOR_DEVICE_ATTR_RO(vrdhot1, vrdhot, 0);
2320 static SENSOR_DEVICE_ATTR_RO(vrdhot2, vrdhot, 1);
2322 static ssize_t gpio_show(struct device *dev, struct device_attribute *attr,
2325 struct lm93_data *data = lm93_update_device(dev);
2326 return sprintf(buf, "%d\n", LM93_GPI_FROM_REG(data->gpi));
2329 static DEVICE_ATTR_RO(gpio);
2331 static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
2334 struct lm93_data *data = lm93_update_device(dev);
2335 return sprintf(buf, "%d\n", LM93_ALARMS_FROM_REG(data->block1));
2338 static DEVICE_ATTR_RO(alarms);
2340 static struct attribute *lm93_attrs[] = {
2341 &sensor_dev_attr_in1_input.dev_attr.attr,
2342 &sensor_dev_attr_in2_input.dev_attr.attr,
2343 &sensor_dev_attr_in3_input.dev_attr.attr,
2344 &sensor_dev_attr_in4_input.dev_attr.attr,
2345 &sensor_dev_attr_in5_input.dev_attr.attr,
2346 &sensor_dev_attr_in6_input.dev_attr.attr,
2347 &sensor_dev_attr_in7_input.dev_attr.attr,
2348 &sensor_dev_attr_in8_input.dev_attr.attr,
2349 &sensor_dev_attr_in9_input.dev_attr.attr,
2350 &sensor_dev_attr_in10_input.dev_attr.attr,
2351 &sensor_dev_attr_in11_input.dev_attr.attr,
2352 &sensor_dev_attr_in12_input.dev_attr.attr,
2353 &sensor_dev_attr_in13_input.dev_attr.attr,
2354 &sensor_dev_attr_in14_input.dev_attr.attr,
2355 &sensor_dev_attr_in15_input.dev_attr.attr,
2356 &sensor_dev_attr_in16_input.dev_attr.attr,
2357 &sensor_dev_attr_in1_min.dev_attr.attr,
2358 &sensor_dev_attr_in2_min.dev_attr.attr,
2359 &sensor_dev_attr_in3_min.dev_attr.attr,
2360 &sensor_dev_attr_in4_min.dev_attr.attr,
2361 &sensor_dev_attr_in5_min.dev_attr.attr,
2362 &sensor_dev_attr_in6_min.dev_attr.attr,
2363 &sensor_dev_attr_in7_min.dev_attr.attr,
2364 &sensor_dev_attr_in8_min.dev_attr.attr,
2365 &sensor_dev_attr_in9_min.dev_attr.attr,
2366 &sensor_dev_attr_in10_min.dev_attr.attr,
2367 &sensor_dev_attr_in11_min.dev_attr.attr,
2368 &sensor_dev_attr_in12_min.dev_attr.attr,
2369 &sensor_dev_attr_in13_min.dev_attr.attr,
2370 &sensor_dev_attr_in14_min.dev_attr.attr,
2371 &sensor_dev_attr_in15_min.dev_attr.attr,
2372 &sensor_dev_attr_in16_min.dev_attr.attr,
2373 &sensor_dev_attr_in1_max.dev_attr.attr,
2374 &sensor_dev_attr_in2_max.dev_attr.attr,
2375 &sensor_dev_attr_in3_max.dev_attr.attr,
2376 &sensor_dev_attr_in4_max.dev_attr.attr,
2377 &sensor_dev_attr_in5_max.dev_attr.attr,
2378 &sensor_dev_attr_in6_max.dev_attr.attr,
2379 &sensor_dev_attr_in7_max.dev_attr.attr,
2380 &sensor_dev_attr_in8_max.dev_attr.attr,
2381 &sensor_dev_attr_in9_max.dev_attr.attr,
2382 &sensor_dev_attr_in10_max.dev_attr.attr,
2383 &sensor_dev_attr_in11_max.dev_attr.attr,
2384 &sensor_dev_attr_in12_max.dev_attr.attr,
2385 &sensor_dev_attr_in13_max.dev_attr.attr,
2386 &sensor_dev_attr_in14_max.dev_attr.attr,
2387 &sensor_dev_attr_in15_max.dev_attr.attr,
2388 &sensor_dev_attr_in16_max.dev_attr.attr,
2389 &sensor_dev_attr_temp1_input.dev_attr.attr,
2390 &sensor_dev_attr_temp2_input.dev_attr.attr,
2391 &sensor_dev_attr_temp3_input.dev_attr.attr,
2392 &sensor_dev_attr_temp1_min.dev_attr.attr,
2393 &sensor_dev_attr_temp2_min.dev_attr.attr,
2394 &sensor_dev_attr_temp3_min.dev_attr.attr,
2395 &sensor_dev_attr_temp1_max.dev_attr.attr,
2396 &sensor_dev_attr_temp2_max.dev_attr.attr,
2397 &sensor_dev_attr_temp3_max.dev_attr.attr,
2398 &sensor_dev_attr_temp1_auto_base.dev_attr.attr,
2399 &sensor_dev_attr_temp2_auto_base.dev_attr.attr,
2400 &sensor_dev_attr_temp3_auto_base.dev_attr.attr,
2401 &sensor_dev_attr_temp1_auto_boost.dev_attr.attr,
2402 &sensor_dev_attr_temp2_auto_boost.dev_attr.attr,
2403 &sensor_dev_attr_temp3_auto_boost.dev_attr.attr,
2404 &sensor_dev_attr_temp1_auto_boost_hyst.dev_attr.attr,
2405 &sensor_dev_attr_temp2_auto_boost_hyst.dev_attr.attr,
2406 &sensor_dev_attr_temp3_auto_boost_hyst.dev_attr.attr,
2407 &sensor_dev_attr_temp1_auto_offset1.dev_attr.attr,
2408 &sensor_dev_attr_temp1_auto_offset2.dev_attr.attr,
2409 &sensor_dev_attr_temp1_auto_offset3.dev_attr.attr,
2410 &sensor_dev_attr_temp1_auto_offset4.dev_attr.attr,
2411 &sensor_dev_attr_temp1_auto_offset5.dev_attr.attr,
2412 &sensor_dev_attr_temp1_auto_offset6.dev_attr.attr,
2413 &sensor_dev_attr_temp1_auto_offset7.dev_attr.attr,
2414 &sensor_dev_attr_temp1_auto_offset8.dev_attr.attr,
2415 &sensor_dev_attr_temp1_auto_offset9.dev_attr.attr,
2416 &sensor_dev_attr_temp1_auto_offset10.dev_attr.attr,
2417 &sensor_dev_attr_temp1_auto_offset11.dev_attr.attr,
2418 &sensor_dev_attr_temp1_auto_offset12.dev_attr.attr,
2419 &sensor_dev_attr_temp2_auto_offset1.dev_attr.attr,
2420 &sensor_dev_attr_temp2_auto_offset2.dev_attr.attr,
2421 &sensor_dev_attr_temp2_auto_offset3.dev_attr.attr,
2422 &sensor_dev_attr_temp2_auto_offset4.dev_attr.attr,
2423 &sensor_dev_attr_temp2_auto_offset5.dev_attr.attr,
2424 &sensor_dev_attr_temp2_auto_offset6.dev_attr.attr,
2425 &sensor_dev_attr_temp2_auto_offset7.dev_attr.attr,
2426 &sensor_dev_attr_temp2_auto_offset8.dev_attr.attr,
2427 &sensor_dev_attr_temp2_auto_offset9.dev_attr.attr,
2428 &sensor_dev_attr_temp2_auto_offset10.dev_attr.attr,
2429 &sensor_dev_attr_temp2_auto_offset11.dev_attr.attr,
2430 &sensor_dev_attr_temp2_auto_offset12.dev_attr.attr,
2431 &sensor_dev_attr_temp3_auto_offset1.dev_attr.attr,
2432 &sensor_dev_attr_temp3_auto_offset2.dev_attr.attr,
2433 &sensor_dev_attr_temp3_auto_offset3.dev_attr.attr,
2434 &sensor_dev_attr_temp3_auto_offset4.dev_attr.attr,
2435 &sensor_dev_attr_temp3_auto_offset5.dev_attr.attr,
2436 &sensor_dev_attr_temp3_auto_offset6.dev_attr.attr,
2437 &sensor_dev_attr_temp3_auto_offset7.dev_attr.attr,
2438 &sensor_dev_attr_temp3_auto_offset8.dev_attr.attr,
2439 &sensor_dev_attr_temp3_auto_offset9.dev_attr.attr,
2440 &sensor_dev_attr_temp3_auto_offset10.dev_attr.attr,
2441 &sensor_dev_attr_temp3_auto_offset11.dev_attr.attr,
2442 &sensor_dev_attr_temp3_auto_offset12.dev_attr.attr,
2443 &sensor_dev_attr_temp1_auto_pwm_min.dev_attr.attr,
2444 &sensor_dev_attr_temp2_auto_pwm_min.dev_attr.attr,
2445 &sensor_dev_attr_temp3_auto_pwm_min.dev_attr.attr,
2446 &sensor_dev_attr_temp1_auto_offset_hyst.dev_attr.attr,
2447 &sensor_dev_attr_temp2_auto_offset_hyst.dev_attr.attr,
2448 &sensor_dev_attr_temp3_auto_offset_hyst.dev_attr.attr,
2449 &sensor_dev_attr_fan1_input.dev_attr.attr,
2450 &sensor_dev_attr_fan2_input.dev_attr.attr,
2451 &sensor_dev_attr_fan3_input.dev_attr.attr,
2452 &sensor_dev_attr_fan4_input.dev_attr.attr,
2453 &sensor_dev_attr_fan1_min.dev_attr.attr,
2454 &sensor_dev_attr_fan2_min.dev_attr.attr,
2455 &sensor_dev_attr_fan3_min.dev_attr.attr,
2456 &sensor_dev_attr_fan4_min.dev_attr.attr,
2457 &sensor_dev_attr_fan1_smart_tach.dev_attr.attr,
2458 &sensor_dev_attr_fan2_smart_tach.dev_attr.attr,
2459 &sensor_dev_attr_fan3_smart_tach.dev_attr.attr,
2460 &sensor_dev_attr_fan4_smart_tach.dev_attr.attr,
2461 &sensor_dev_attr_pwm1.dev_attr.attr,
2462 &sensor_dev_attr_pwm2.dev_attr.attr,
2463 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2464 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
2465 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
2466 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
2467 &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
2468 &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
2469 &sensor_dev_attr_pwm1_auto_spinup_min.dev_attr.attr,
2470 &sensor_dev_attr_pwm2_auto_spinup_min.dev_attr.attr,
2471 &sensor_dev_attr_pwm1_auto_spinup_time.dev_attr.attr,
2472 &sensor_dev_attr_pwm2_auto_spinup_time.dev_attr.attr,
2473 &dev_attr_pwm_auto_prochot_ramp.attr,
2474 &dev_attr_pwm_auto_vrdhot_ramp.attr,
2475 &sensor_dev_attr_cpu0_vid.dev_attr.attr,
2476 &sensor_dev_attr_cpu1_vid.dev_attr.attr,
2477 &sensor_dev_attr_prochot1.dev_attr.attr,
2478 &sensor_dev_attr_prochot2.dev_attr.attr,
2479 &sensor_dev_attr_prochot1_avg.dev_attr.attr,
2480 &sensor_dev_attr_prochot2_avg.dev_attr.attr,
2481 &sensor_dev_attr_prochot1_max.dev_attr.attr,
2482 &sensor_dev_attr_prochot2_max.dev_attr.attr,
2483 &sensor_dev_attr_prochot1_override.dev_attr.attr,
2484 &sensor_dev_attr_prochot2_override.dev_attr.attr,
2485 &sensor_dev_attr_prochot1_interval.dev_attr.attr,
2486 &sensor_dev_attr_prochot2_interval.dev_attr.attr,
2487 &dev_attr_prochot_override_duty_cycle.attr,
2488 &dev_attr_prochot_short.attr,
2489 &sensor_dev_attr_vrdhot1.dev_attr.attr,
2490 &sensor_dev_attr_vrdhot2.dev_attr.attr,
2491 &dev_attr_gpio.attr,
2492 &dev_attr_alarms.attr,
2496 ATTRIBUTE_GROUPS(lm93);
2498 static void lm93_init_client(struct i2c_client *client)
2503 /* configure VID pin input thresholds */
2504 reg = lm93_read_byte(client, LM93_REG_GPI_VID_CTL);
2505 lm93_write_byte(client, LM93_REG_GPI_VID_CTL,
2506 reg | (vid_agtl ? 0x03 : 0x00));
2509 /* enable #ALERT pin */
2510 reg = lm93_read_byte(client, LM93_REG_CONFIG);
2511 lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x08);
2513 /* enable ASF mode for BMC status registers */
2514 reg = lm93_read_byte(client, LM93_REG_STATUS_CONTROL);
2515 lm93_write_byte(client, LM93_REG_STATUS_CONTROL, reg | 0x02);
2517 /* set sleep state to S0 */
2518 lm93_write_byte(client, LM93_REG_SLEEP_CONTROL, 0);
2520 /* unmask #VRDHOT and dynamic VCCP (if nec) error events */
2521 reg = lm93_read_byte(client, LM93_REG_MISC_ERR_MASK);
2523 reg &= ~(vccp_limit_type[0] ? 0x10 : 0);
2524 reg &= ~(vccp_limit_type[1] ? 0x20 : 0);
2525 lm93_write_byte(client, LM93_REG_MISC_ERR_MASK, reg);
2528 /* start monitoring */
2529 reg = lm93_read_byte(client, LM93_REG_CONFIG);
2530 lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x01);
2532 /* spin until ready */
2533 for (i = 0; i < 20; i++) {
2535 if ((lm93_read_byte(client, LM93_REG_CONFIG) & 0x80) == 0x80)
2539 dev_warn(&client->dev,
2540 "timed out waiting for sensor chip to signal ready!\n");
2543 /* Return 0 if detection is successful, -ENODEV otherwise */
2544 static int lm93_detect(struct i2c_client *client, struct i2c_board_info *info)
2546 struct i2c_adapter *adapter = client->adapter;
2550 if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN))
2554 mfr = lm93_read_byte(client, LM93_REG_MFR_ID);
2556 dev_dbg(&adapter->dev,
2557 "detect failed, bad manufacturer id 0x%02x!\n", mfr);
2561 ver = lm93_read_byte(client, LM93_REG_VER);
2564 case LM93_MFR_ID_PROTOTYPE:
2569 case LM94_MFR_ID_PROTOTYPE:
2573 dev_dbg(&adapter->dev,
2574 "detect failed, bad version id 0x%02x!\n", ver);
2578 strscpy(info->type, name, I2C_NAME_SIZE);
2579 dev_dbg(&adapter->dev, "loading %s at %d, 0x%02x\n",
2580 client->name, i2c_adapter_id(client->adapter),
2586 static int lm93_probe(struct i2c_client *client)
2588 struct device *dev = &client->dev;
2589 struct lm93_data *data;
2590 struct device *hwmon_dev;
2592 void (*update)(struct lm93_data *, struct i2c_client *);
2594 /* choose update routine based on bus capabilities */
2595 func = i2c_get_functionality(client->adapter);
2596 if (((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) &&
2598 dev_dbg(dev, "using SMBus block data transactions\n");
2599 update = lm93_update_client_full;
2600 } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) {
2601 dev_dbg(dev, "disabled SMBus block data transactions\n");
2602 update = lm93_update_client_min;
2604 dev_dbg(dev, "detect failed, smbus byte and/or word data not supported!\n");
2608 data = devm_kzalloc(dev, sizeof(struct lm93_data), GFP_KERNEL);
2613 data->client = client;
2614 data->update = update;
2615 mutex_init(&data->update_lock);
2617 /* initialize the chip */
2618 lm93_init_client(client);
2620 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
2623 return PTR_ERR_OR_ZERO(hwmon_dev);
2626 static const struct i2c_device_id lm93_id[] = {
2631 MODULE_DEVICE_TABLE(i2c, lm93_id);
2633 static struct i2c_driver lm93_driver = {
2634 .class = I2C_CLASS_HWMON,
2638 .probe = lm93_probe,
2639 .id_table = lm93_id,
2640 .detect = lm93_detect,
2641 .address_list = normal_i2c,
2644 module_i2c_driver(lm93_driver);
2646 MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, "
2647 "Hans J. Koch <hjk@hansjkoch.de>");
2648 MODULE_DESCRIPTION("LM93 driver");
2649 MODULE_LICENSE("GPL");