2 * dme1737.c - Driver for the SMSC DME1737, Asus A8000, SMSC SCH311x, SCH5027,
3 * and SCH5127 Super-I/O chips integrated hardware monitoring
5 * Copyright (c) 2007, 2008, 2009, 2010 Juerg Haefliger <juergh@gmail.com>
7 * This driver is an I2C/ISA hybrid, meaning that it uses the I2C bus to access
8 * the chip registers if a DME1737, A8000, or SCH5027 is found and the ISA bus
9 * if a SCH311x or SCH5127 chip is found. Both types of chips have very
10 * similar hardware monitoring capabilities but differ in the way they can be
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/jiffies.h>
34 #include <linux/i2c.h>
35 #include <linux/platform_device.h>
36 #include <linux/hwmon.h>
37 #include <linux/hwmon-sysfs.h>
38 #include <linux/hwmon-vid.h>
39 #include <linux/err.h>
40 #include <linux/mutex.h>
41 #include <linux/acpi.h>
44 /* ISA device, if found */
45 static struct platform_device
*pdev
;
47 /* Module load parameters */
48 static bool force_start
;
49 module_param(force_start
, bool, 0);
50 MODULE_PARM_DESC(force_start
, "Force the chip to start monitoring inputs");
52 static unsigned short force_id
;
53 module_param(force_id
, ushort
, 0);
54 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
56 static bool probe_all_addr
;
57 module_param(probe_all_addr
, bool, 0);
58 MODULE_PARM_DESC(probe_all_addr
,
59 "Include probing of non-standard LPC addresses");
61 /* Addresses to scan */
62 static const unsigned short normal_i2c
[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END
};
64 enum chips
{ dme1737
, sch5027
, sch311x
, sch5127
};
66 #define DO_REPORT "Please report to the driver maintainer."
68 /* ---------------------------------------------------------------------
71 * The sensors are defined as follows:
73 * Voltages Temperatures
74 * -------- ------------
75 * in0 +5VTR (+5V stdby) temp1 Remote diode 1
76 * in1 Vccp (proc core) temp2 Internal temp
77 * in2 VCC (internal +3.3V) temp3 Remote diode 2
80 * in5 VTR (+3.3V stby)
82 * in7 Vtrip (sch5127 only)
84 * --------------------------------------------------------------------- */
86 /* Voltages (in) numbered 0-7 (ix) */
87 #define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) : \
88 (ix) < 7 ? 0x94 + (ix) : \
90 #define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \
92 #define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \
95 /* Temperatures (temp) numbered 0-2 (ix) */
96 #define DME1737_REG_TEMP(ix) (0x25 + (ix))
97 #define DME1737_REG_TEMP_MIN(ix) (0x4e + (ix) * 2)
98 #define DME1737_REG_TEMP_MAX(ix) (0x4f + (ix) * 2)
99 #define DME1737_REG_TEMP_OFFSET(ix) ((ix) == 0 ? 0x1f \
103 * Voltage and temperature LSBs
104 * The LSBs (4 bits each) are stored in 5 registers with the following layouts:
105 * IN_TEMP_LSB(0) = [in5, in6]
106 * IN_TEMP_LSB(1) = [temp3, temp1]
107 * IN_TEMP_LSB(2) = [in4, temp2]
108 * IN_TEMP_LSB(3) = [in3, in0]
109 * IN_TEMP_LSB(4) = [in2, in1]
110 * IN_TEMP_LSB(5) = [res, in7]
112 #define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix))
113 static const u8 DME1737_REG_IN_LSB
[] = {3, 4, 4, 3, 2, 0, 0, 5};
114 static const u8 DME1737_REG_IN_LSB_SHL
[] = {4, 4, 0, 0, 0, 0, 4, 4};
115 static const u8 DME1737_REG_TEMP_LSB
[] = {1, 2, 1};
116 static const u8 DME1737_REG_TEMP_LSB_SHL
[] = {4, 4, 0};
118 /* Fans numbered 0-5 (ix) */
119 #define DME1737_REG_FAN(ix) ((ix) < 4 ? 0x28 + (ix) * 2 \
121 #define DME1737_REG_FAN_MIN(ix) ((ix) < 4 ? 0x54 + (ix) * 2 \
123 #define DME1737_REG_FAN_OPT(ix) ((ix) < 4 ? 0x90 + (ix) \
125 #define DME1737_REG_FAN_MAX(ix) (0xb4 + (ix)) /* only for fan[4-5] */
127 /* PWMs numbered 0-2, 4-5 (ix) */
128 #define DME1737_REG_PWM(ix) ((ix) < 3 ? 0x30 + (ix) \
130 #define DME1737_REG_PWM_CONFIG(ix) (0x5c + (ix)) /* only for pwm[0-2] */
131 #define DME1737_REG_PWM_MIN(ix) (0x64 + (ix)) /* only for pwm[0-2] */
132 #define DME1737_REG_PWM_FREQ(ix) ((ix) < 3 ? 0x5f + (ix) \
135 * The layout of the ramp rate registers is different from the other pwm
136 * registers. The bits for the 3 PWMs are stored in 2 registers:
137 * PWM_RR(0) = [OFF3, OFF2, OFF1, RES, RR1E, RR1-2, RR1-1, RR1-0]
138 * PWM_RR(1) = [RR2E, RR2-2, RR2-1, RR2-0, RR3E, RR3-2, RR3-1, RR3-0]
140 #define DME1737_REG_PWM_RR(ix) (0x62 + (ix)) /* only for pwm[0-2] */
142 /* Thermal zones 0-2 */
143 #define DME1737_REG_ZONE_LOW(ix) (0x67 + (ix))
144 #define DME1737_REG_ZONE_ABS(ix) (0x6a + (ix))
146 * The layout of the hysteresis registers is different from the other zone
147 * registers. The bits for the 3 zones are stored in 2 registers:
148 * ZONE_HYST(0) = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0]
149 * ZONE_HYST(1) = [H3-3, H3-2, H3-1, H3-0, RES, RES, RES, RES]
151 #define DME1737_REG_ZONE_HYST(ix) (0x6d + (ix))
154 * Alarm registers and bit mapping
155 * The 3 8-bit alarm registers will be concatenated to a single 32-bit
156 * alarm value [0, ALARM3, ALARM2, ALARM1].
158 #define DME1737_REG_ALARM1 0x41
159 #define DME1737_REG_ALARM2 0x42
160 #define DME1737_REG_ALARM3 0x83
161 static const u8 DME1737_BIT_ALARM_IN
[] = {0, 1, 2, 3, 8, 16, 17, 18};
162 static const u8 DME1737_BIT_ALARM_TEMP
[] = {4, 5, 6};
163 static const u8 DME1737_BIT_ALARM_FAN
[] = {10, 11, 12, 13, 22, 23};
165 /* Miscellaneous registers */
166 #define DME1737_REG_DEVICE 0x3d
167 #define DME1737_REG_COMPANY 0x3e
168 #define DME1737_REG_VERSTEP 0x3f
169 #define DME1737_REG_CONFIG 0x40
170 #define DME1737_REG_CONFIG2 0x7f
171 #define DME1737_REG_VID 0x43
172 #define DME1737_REG_TACH_PWM 0x81
174 /* ---------------------------------------------------------------------
176 * --------------------------------------------------------------------- */
178 /* Chip identification */
179 #define DME1737_COMPANY_SMSC 0x5c
180 #define DME1737_VERSTEP 0x88
181 #define DME1737_VERSTEP_MASK 0xf8
182 #define SCH311X_DEVICE 0x8c
183 #define SCH5027_VERSTEP 0x69
184 #define SCH5127_DEVICE 0x8e
186 /* Device ID values (global configuration register index 0x20) */
187 #define DME1737_ID_1 0x77
188 #define DME1737_ID_2 0x78
189 #define SCH3112_ID 0x7c
190 #define SCH3114_ID 0x7d
191 #define SCH3116_ID 0x7f
192 #define SCH5027_ID 0x89
193 #define SCH5127_ID 0x86
195 /* Length of ISA address segment */
196 #define DME1737_EXTENT 2
198 /* chip-dependent features */
199 #define HAS_TEMP_OFFSET (1 << 0) /* bit 0 */
200 #define HAS_VID (1 << 1) /* bit 1 */
201 #define HAS_ZONE3 (1 << 2) /* bit 2 */
202 #define HAS_ZONE_HYST (1 << 3) /* bit 3 */
203 #define HAS_PWM_MIN (1 << 4) /* bit 4 */
204 #define HAS_FAN(ix) (1 << ((ix) + 5)) /* bits 5-10 */
205 #define HAS_PWM(ix) (1 << ((ix) + 11)) /* bits 11-16 */
206 #define HAS_IN7 (1 << 17) /* bit 17 */
208 /* ---------------------------------------------------------------------
209 * Data structures and manipulation thereof
210 * --------------------------------------------------------------------- */
212 struct dme1737_data
{
213 struct i2c_client
*client
; /* for I2C devices only */
214 struct device
*hwmon_dev
;
216 unsigned int addr
; /* for ISA devices only */
218 struct mutex update_lock
;
219 int valid
; /* !=0 if following fields are valid */
220 unsigned long last_update
; /* in jiffies */
221 unsigned long last_vbat
; /* in jiffies */
223 const int *in_nominal
; /* pointer to IN_NOMINAL array */
229 /* Register values */
256 /* Nominal voltage values */
257 static const int IN_NOMINAL_DME1737
[] = {5000, 2250, 3300, 5000, 12000, 3300,
259 static const int IN_NOMINAL_SCH311x
[] = {2500, 1500, 3300, 5000, 12000, 3300,
261 static const int IN_NOMINAL_SCH5027
[] = {5000, 2250, 3300, 1125, 1125, 3300,
263 static const int IN_NOMINAL_SCH5127
[] = {2500, 2250, 3300, 1125, 1125, 3300,
265 #define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \
266 (type) == sch5027 ? IN_NOMINAL_SCH5027 : \
267 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \
272 * Voltage inputs have 16 bits resolution, limit values have 8 bits
275 static inline int IN_FROM_REG(int reg
, int nominal
, int res
)
277 return (reg
* nominal
+ (3 << (res
- 3))) / (3 << (res
- 2));
280 static inline int IN_TO_REG(long val
, int nominal
)
282 val
= clamp_val(val
, 0, 255 * nominal
/ 192);
283 return DIV_ROUND_CLOSEST(val
* 192, nominal
);
288 * The register values represent temperatures in 2's complement notation from
289 * -127 degrees C to +127 degrees C. Temp inputs have 16 bits resolution, limit
290 * values have 8 bits resolution.
292 static inline int TEMP_FROM_REG(int reg
, int res
)
294 return (reg
* 1000) >> (res
- 8);
297 static inline int TEMP_TO_REG(long val
)
299 val
= clamp_val(val
, -128000, 127000);
300 return DIV_ROUND_CLOSEST(val
, 1000);
303 /* Temperature range */
304 static const int TEMP_RANGE
[] = {2000, 2500, 3333, 4000, 5000, 6666, 8000,
305 10000, 13333, 16000, 20000, 26666, 32000,
306 40000, 53333, 80000};
308 static inline int TEMP_RANGE_FROM_REG(int reg
)
310 return TEMP_RANGE
[(reg
>> 4) & 0x0f];
313 static int TEMP_RANGE_TO_REG(long val
, int reg
)
317 for (i
= 15; i
> 0; i
--) {
318 if (val
> (TEMP_RANGE
[i
] + TEMP_RANGE
[i
- 1] + 1) / 2)
322 return (reg
& 0x0f) | (i
<< 4);
326 * Temperature hysteresis
328 * reg[0] = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0]
329 * reg[1] = [H3-3, H3-2, H3-1, H3-0, xxxx, xxxx, xxxx, xxxx]
331 static inline int TEMP_HYST_FROM_REG(int reg
, int ix
)
333 return (((ix
== 1) ? reg
: reg
>> 4) & 0x0f) * 1000;
336 static inline int TEMP_HYST_TO_REG(int temp
, long hyst
, int ix
, int reg
)
338 hyst
= clamp_val(hyst
, temp
- 15000, temp
);
339 hyst
= DIV_ROUND_CLOSEST(temp
- hyst
, 1000);
341 return (ix
== 1) ? (reg
& 0xf0) | hyst
: (reg
& 0x0f) | (hyst
<< 4);
345 static inline int FAN_FROM_REG(int reg
, int tpc
)
350 return (reg
== 0 || reg
== 0xffff) ? 0 : 90000 * 60 / reg
;
353 static inline int FAN_TO_REG(long val
, int tpc
)
356 return clamp_val(val
/ tpc
, 0, 0xffff);
358 return (val
<= 0) ? 0xffff :
359 clamp_val(90000 * 60 / val
, 0, 0xfffe);
364 * Fan TPC (tach pulse count)
365 * Converts a register value to a TPC multiplier or returns 0 if the tachometer
366 * is configured in legacy (non-tpc) mode
368 static inline int FAN_TPC_FROM_REG(int reg
)
370 return (reg
& 0x20) ? 0 : 60 >> (reg
& 0x03);
375 * The type of a fan is expressed in number of pulses-per-revolution that it
378 static inline int FAN_TYPE_FROM_REG(int reg
)
380 int edge
= (reg
>> 1) & 0x03;
382 return (edge
> 0) ? 1 << (edge
- 1) : 0;
385 static inline int FAN_TYPE_TO_REG(long val
, int reg
)
387 int edge
= (val
== 4) ? 3 : val
;
389 return (reg
& 0xf9) | (edge
<< 1);
393 static const int FAN_MAX
[] = {0x54, 0x38, 0x2a, 0x21, 0x1c, 0x18, 0x15, 0x12,
396 static int FAN_MAX_FROM_REG(int reg
)
400 for (i
= 10; i
> 0; i
--) {
401 if (reg
== FAN_MAX
[i
])
405 return 1000 + i
* 500;
408 static int FAN_MAX_TO_REG(long val
)
412 for (i
= 10; i
> 0; i
--) {
413 if (val
> (1000 + (i
- 1) * 500))
422 * Register to enable mapping:
423 * 000: 2 fan on zone 1 auto
424 * 001: 2 fan on zone 2 auto
425 * 010: 2 fan on zone 3 auto
427 * 100: -1 fan disabled
428 * 101: 2 fan on hottest of zones 2,3 auto
429 * 110: 2 fan on hottest of zones 1,2,3 auto
430 * 111: 1 fan in manual mode
432 static inline int PWM_EN_FROM_REG(int reg
)
434 static const int en
[] = {2, 2, 2, 0, -1, 2, 2, 1};
436 return en
[(reg
>> 5) & 0x07];
439 static inline int PWM_EN_TO_REG(int val
, int reg
)
441 int en
= (val
== 1) ? 7 : 3;
443 return (reg
& 0x1f) | ((en
& 0x07) << 5);
447 * PWM auto channels zone
448 * Register to auto channels zone mapping (ACZ is a bitfield with bit x
449 * corresponding to zone x+1):
450 * 000: 001 fan on zone 1 auto
451 * 001: 010 fan on zone 2 auto
452 * 010: 100 fan on zone 3 auto
453 * 011: 000 fan full on
454 * 100: 000 fan disabled
455 * 101: 110 fan on hottest of zones 2,3 auto
456 * 110: 111 fan on hottest of zones 1,2,3 auto
457 * 111: 000 fan in manual mode
459 static inline int PWM_ACZ_FROM_REG(int reg
)
461 static const int acz
[] = {1, 2, 4, 0, 0, 6, 7, 0};
463 return acz
[(reg
>> 5) & 0x07];
466 static inline int PWM_ACZ_TO_REG(long val
, int reg
)
468 int acz
= (val
== 4) ? 2 : val
- 1;
470 return (reg
& 0x1f) | ((acz
& 0x07) << 5);
474 static const int PWM_FREQ
[] = {11, 15, 22, 29, 35, 44, 59, 88,
475 15000, 20000, 30000, 25000, 0, 0, 0, 0};
477 static inline int PWM_FREQ_FROM_REG(int reg
)
479 return PWM_FREQ
[reg
& 0x0f];
482 static int PWM_FREQ_TO_REG(long val
, int reg
)
486 /* the first two cases are special - stupid chip design! */
489 } else if (val
> 22500) {
492 for (i
= 9; i
> 0; i
--) {
493 if (val
> (PWM_FREQ
[i
] + PWM_FREQ
[i
- 1] + 1) / 2)
498 return (reg
& 0xf0) | i
;
504 * reg[0] = [OFF3, OFF2, OFF1, RES, RR1-E, RR1-2, RR1-1, RR1-0]
505 * reg[1] = [RR2-E, RR2-2, RR2-1, RR2-0, RR3-E, RR3-2, RR3-1, RR3-0]
507 static const u8 PWM_RR
[] = {206, 104, 69, 41, 26, 18, 10, 5};
509 static inline int PWM_RR_FROM_REG(int reg
, int ix
)
511 int rr
= (ix
== 1) ? reg
>> 4 : reg
;
513 return (rr
& 0x08) ? PWM_RR
[rr
& 0x07] : 0;
516 static int PWM_RR_TO_REG(long val
, int ix
, int reg
)
520 for (i
= 0; i
< 7; i
++) {
521 if (val
> (PWM_RR
[i
] + PWM_RR
[i
+ 1] + 1) / 2)
525 return (ix
== 1) ? (reg
& 0x8f) | (i
<< 4) : (reg
& 0xf8) | i
;
528 /* PWM ramp rate enable */
529 static inline int PWM_RR_EN_FROM_REG(int reg
, int ix
)
531 return PWM_RR_FROM_REG(reg
, ix
) ? 1 : 0;
534 static inline int PWM_RR_EN_TO_REG(long val
, int ix
, int reg
)
536 int en
= (ix
== 1) ? 0x80 : 0x08;
538 return val
? reg
| en
: reg
& ~en
;
543 * The PWM min/off bits are part of the PMW ramp rate register 0 (see above for
544 * the register layout).
546 static inline int PWM_OFF_FROM_REG(int reg
, int ix
)
548 return (reg
>> (ix
+ 5)) & 0x01;
551 static inline int PWM_OFF_TO_REG(int val
, int ix
, int reg
)
553 return (reg
& ~(1 << (ix
+ 5))) | ((val
& 0x01) << (ix
+ 5));
556 /* ---------------------------------------------------------------------
559 * ISA access is performed through an index/data register pair and needs to
560 * be protected by a mutex during runtime (not required for initialization).
561 * We use data->update_lock for this and need to ensure that we acquire it
562 * before calling dme1737_read or dme1737_write.
563 * --------------------------------------------------------------------- */
565 static u8
dme1737_read(const struct dme1737_data
*data
, u8 reg
)
567 struct i2c_client
*client
= data
->client
;
570 if (client
) { /* I2C device */
571 val
= i2c_smbus_read_byte_data(client
, reg
);
574 dev_warn(&client
->dev
,
575 "Read from register 0x%02x failed! %s\n",
578 } else { /* ISA device */
579 outb(reg
, data
->addr
);
580 val
= inb(data
->addr
+ 1);
586 static s32
dme1737_write(const struct dme1737_data
*data
, u8 reg
, u8 val
)
588 struct i2c_client
*client
= data
->client
;
591 if (client
) { /* I2C device */
592 res
= i2c_smbus_write_byte_data(client
, reg
, val
);
595 dev_warn(&client
->dev
,
596 "Write to register 0x%02x failed! %s\n",
599 } else { /* ISA device */
600 outb(reg
, data
->addr
);
601 outb(val
, data
->addr
+ 1);
607 static struct dme1737_data
*dme1737_update_device(struct device
*dev
)
609 struct dme1737_data
*data
= dev_get_drvdata(dev
);
613 mutex_lock(&data
->update_lock
);
615 /* Enable a Vbat monitoring cycle every 10 mins */
616 if (time_after(jiffies
, data
->last_vbat
+ 600 * HZ
) || !data
->valid
) {
617 dme1737_write(data
, DME1737_REG_CONFIG
, dme1737_read(data
,
618 DME1737_REG_CONFIG
) | 0x10);
619 data
->last_vbat
= jiffies
;
622 /* Sample register contents every 1 sec */
623 if (time_after(jiffies
, data
->last_update
+ HZ
) || !data
->valid
) {
624 if (data
->has_features
& HAS_VID
) {
625 data
->vid
= dme1737_read(data
, DME1737_REG_VID
) &
629 /* In (voltage) registers */
630 for (ix
= 0; ix
< ARRAY_SIZE(data
->in
); ix
++) {
632 * Voltage inputs are stored as 16 bit values even
633 * though they have only 12 bits resolution. This is
634 * to make it consistent with the temp inputs.
636 if (ix
== 7 && !(data
->has_features
& HAS_IN7
))
638 data
->in
[ix
] = dme1737_read(data
,
639 DME1737_REG_IN(ix
)) << 8;
640 data
->in_min
[ix
] = dme1737_read(data
,
641 DME1737_REG_IN_MIN(ix
));
642 data
->in_max
[ix
] = dme1737_read(data
,
643 DME1737_REG_IN_MAX(ix
));
647 for (ix
= 0; ix
< ARRAY_SIZE(data
->temp
); ix
++) {
649 * Temp inputs are stored as 16 bit values even
650 * though they have only 12 bits resolution. This is
651 * to take advantage of implicit conversions between
652 * register values (2's complement) and temp values
655 data
->temp
[ix
] = dme1737_read(data
,
656 DME1737_REG_TEMP(ix
)) << 8;
657 data
->temp_min
[ix
] = dme1737_read(data
,
658 DME1737_REG_TEMP_MIN(ix
));
659 data
->temp_max
[ix
] = dme1737_read(data
,
660 DME1737_REG_TEMP_MAX(ix
));
661 if (data
->has_features
& HAS_TEMP_OFFSET
) {
662 data
->temp_offset
[ix
] = dme1737_read(data
,
663 DME1737_REG_TEMP_OFFSET(ix
));
668 * In and temp LSB registers
669 * The LSBs are latched when the MSBs are read, so the order in
670 * which the registers are read (MSB first, then LSB) is
673 for (ix
= 0; ix
< ARRAY_SIZE(lsb
); ix
++) {
674 if (ix
== 5 && !(data
->has_features
& HAS_IN7
))
676 lsb
[ix
] = dme1737_read(data
,
677 DME1737_REG_IN_TEMP_LSB(ix
));
679 for (ix
= 0; ix
< ARRAY_SIZE(data
->in
); ix
++) {
680 if (ix
== 7 && !(data
->has_features
& HAS_IN7
))
682 data
->in
[ix
] |= (lsb
[DME1737_REG_IN_LSB
[ix
]] <<
683 DME1737_REG_IN_LSB_SHL
[ix
]) & 0xf0;
685 for (ix
= 0; ix
< ARRAY_SIZE(data
->temp
); ix
++) {
686 data
->temp
[ix
] |= (lsb
[DME1737_REG_TEMP_LSB
[ix
]] <<
687 DME1737_REG_TEMP_LSB_SHL
[ix
]) & 0xf0;
691 for (ix
= 0; ix
< ARRAY_SIZE(data
->fan
); ix
++) {
693 * Skip reading registers if optional fans are not
696 if (!(data
->has_features
& HAS_FAN(ix
)))
698 data
->fan
[ix
] = dme1737_read(data
,
699 DME1737_REG_FAN(ix
));
700 data
->fan
[ix
] |= dme1737_read(data
,
701 DME1737_REG_FAN(ix
) + 1) << 8;
702 data
->fan_min
[ix
] = dme1737_read(data
,
703 DME1737_REG_FAN_MIN(ix
));
704 data
->fan_min
[ix
] |= dme1737_read(data
,
705 DME1737_REG_FAN_MIN(ix
) + 1) << 8;
706 data
->fan_opt
[ix
] = dme1737_read(data
,
707 DME1737_REG_FAN_OPT(ix
));
708 /* fan_max exists only for fan[5-6] */
710 data
->fan_max
[ix
- 4] = dme1737_read(data
,
711 DME1737_REG_FAN_MAX(ix
));
716 for (ix
= 0; ix
< ARRAY_SIZE(data
->pwm
); ix
++) {
718 * Skip reading registers if optional PWMs are not
721 if (!(data
->has_features
& HAS_PWM(ix
)))
723 data
->pwm
[ix
] = dme1737_read(data
,
724 DME1737_REG_PWM(ix
));
725 data
->pwm_freq
[ix
] = dme1737_read(data
,
726 DME1737_REG_PWM_FREQ(ix
));
727 /* pwm_config and pwm_min exist only for pwm[1-3] */
729 data
->pwm_config
[ix
] = dme1737_read(data
,
730 DME1737_REG_PWM_CONFIG(ix
));
731 data
->pwm_min
[ix
] = dme1737_read(data
,
732 DME1737_REG_PWM_MIN(ix
));
735 for (ix
= 0; ix
< ARRAY_SIZE(data
->pwm_rr
); ix
++) {
736 data
->pwm_rr
[ix
] = dme1737_read(data
,
737 DME1737_REG_PWM_RR(ix
));
740 /* Thermal zone registers */
741 for (ix
= 0; ix
< ARRAY_SIZE(data
->zone_low
); ix
++) {
742 /* Skip reading registers if zone3 is not present */
743 if ((ix
== 2) && !(data
->has_features
& HAS_ZONE3
))
745 /* sch5127 zone2 registers are special */
746 if ((ix
== 1) && (data
->type
== sch5127
)) {
747 data
->zone_low
[1] = dme1737_read(data
,
748 DME1737_REG_ZONE_LOW(2));
749 data
->zone_abs
[1] = dme1737_read(data
,
750 DME1737_REG_ZONE_ABS(2));
752 data
->zone_low
[ix
] = dme1737_read(data
,
753 DME1737_REG_ZONE_LOW(ix
));
754 data
->zone_abs
[ix
] = dme1737_read(data
,
755 DME1737_REG_ZONE_ABS(ix
));
758 if (data
->has_features
& HAS_ZONE_HYST
) {
759 for (ix
= 0; ix
< ARRAY_SIZE(data
->zone_hyst
); ix
++) {
760 data
->zone_hyst
[ix
] = dme1737_read(data
,
761 DME1737_REG_ZONE_HYST(ix
));
765 /* Alarm registers */
766 data
->alarms
= dme1737_read(data
,
769 * Bit 7 tells us if the other alarm registers are non-zero and
770 * therefore also need to be read
772 if (data
->alarms
& 0x80) {
773 data
->alarms
|= dme1737_read(data
,
774 DME1737_REG_ALARM2
) << 8;
775 data
->alarms
|= dme1737_read(data
,
776 DME1737_REG_ALARM3
) << 16;
780 * The ISA chips require explicit clearing of alarm bits.
781 * Don't worry, an alarm will come back if the condition
782 * that causes it still exists
785 if (data
->alarms
& 0xff0000)
786 dme1737_write(data
, DME1737_REG_ALARM3
, 0xff);
787 if (data
->alarms
& 0xff00)
788 dme1737_write(data
, DME1737_REG_ALARM2
, 0xff);
789 if (data
->alarms
& 0xff)
790 dme1737_write(data
, DME1737_REG_ALARM1
, 0xff);
793 data
->last_update
= jiffies
;
797 mutex_unlock(&data
->update_lock
);
802 /* ---------------------------------------------------------------------
803 * Voltage sysfs attributes
805 * --------------------------------------------------------------------- */
807 #define SYS_IN_INPUT 0
810 #define SYS_IN_ALARM 3
812 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
815 struct dme1737_data
*data
= dme1737_update_device(dev
);
816 struct sensor_device_attribute_2
817 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
818 int ix
= sensor_attr_2
->index
;
819 int fn
= sensor_attr_2
->nr
;
824 res
= IN_FROM_REG(data
->in
[ix
], data
->in_nominal
[ix
], 16);
827 res
= IN_FROM_REG(data
->in_min
[ix
], data
->in_nominal
[ix
], 8);
830 res
= IN_FROM_REG(data
->in_max
[ix
], data
->in_nominal
[ix
], 8);
833 res
= (data
->alarms
>> DME1737_BIT_ALARM_IN
[ix
]) & 0x01;
837 dev_dbg(dev
, "Unknown function %d.\n", fn
);
840 return sprintf(buf
, "%d\n", res
);
843 static ssize_t
set_in(struct device
*dev
, struct device_attribute
*attr
,
844 const char *buf
, size_t count
)
846 struct dme1737_data
*data
= dev_get_drvdata(dev
);
847 struct sensor_device_attribute_2
848 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
849 int ix
= sensor_attr_2
->index
;
850 int fn
= sensor_attr_2
->nr
;
854 err
= kstrtol(buf
, 10, &val
);
858 mutex_lock(&data
->update_lock
);
861 data
->in_min
[ix
] = IN_TO_REG(val
, data
->in_nominal
[ix
]);
862 dme1737_write(data
, DME1737_REG_IN_MIN(ix
),
866 data
->in_max
[ix
] = IN_TO_REG(val
, data
->in_nominal
[ix
]);
867 dme1737_write(data
, DME1737_REG_IN_MAX(ix
),
871 dev_dbg(dev
, "Unknown function %d.\n", fn
);
873 mutex_unlock(&data
->update_lock
);
878 /* ---------------------------------------------------------------------
879 * Temperature sysfs attributes
881 * --------------------------------------------------------------------- */
883 #define SYS_TEMP_INPUT 0
884 #define SYS_TEMP_MIN 1
885 #define SYS_TEMP_MAX 2
886 #define SYS_TEMP_OFFSET 3
887 #define SYS_TEMP_ALARM 4
888 #define SYS_TEMP_FAULT 5
890 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
893 struct dme1737_data
*data
= dme1737_update_device(dev
);
894 struct sensor_device_attribute_2
895 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
896 int ix
= sensor_attr_2
->index
;
897 int fn
= sensor_attr_2
->nr
;
902 res
= TEMP_FROM_REG(data
->temp
[ix
], 16);
905 res
= TEMP_FROM_REG(data
->temp_min
[ix
], 8);
908 res
= TEMP_FROM_REG(data
->temp_max
[ix
], 8);
910 case SYS_TEMP_OFFSET
:
911 res
= TEMP_FROM_REG(data
->temp_offset
[ix
], 8);
914 res
= (data
->alarms
>> DME1737_BIT_ALARM_TEMP
[ix
]) & 0x01;
917 res
= (((u16
)data
->temp
[ix
] & 0xff00) == 0x8000);
921 dev_dbg(dev
, "Unknown function %d.\n", fn
);
924 return sprintf(buf
, "%d\n", res
);
927 static ssize_t
set_temp(struct device
*dev
, struct device_attribute
*attr
,
928 const char *buf
, size_t count
)
930 struct dme1737_data
*data
= dev_get_drvdata(dev
);
931 struct sensor_device_attribute_2
932 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
933 int ix
= sensor_attr_2
->index
;
934 int fn
= sensor_attr_2
->nr
;
938 err
= kstrtol(buf
, 10, &val
);
942 mutex_lock(&data
->update_lock
);
945 data
->temp_min
[ix
] = TEMP_TO_REG(val
);
946 dme1737_write(data
, DME1737_REG_TEMP_MIN(ix
),
950 data
->temp_max
[ix
] = TEMP_TO_REG(val
);
951 dme1737_write(data
, DME1737_REG_TEMP_MAX(ix
),
954 case SYS_TEMP_OFFSET
:
955 data
->temp_offset
[ix
] = TEMP_TO_REG(val
);
956 dme1737_write(data
, DME1737_REG_TEMP_OFFSET(ix
),
957 data
->temp_offset
[ix
]);
960 dev_dbg(dev
, "Unknown function %d.\n", fn
);
962 mutex_unlock(&data
->update_lock
);
967 /* ---------------------------------------------------------------------
968 * Zone sysfs attributes
970 * --------------------------------------------------------------------- */
972 #define SYS_ZONE_AUTO_CHANNELS_TEMP 0
973 #define SYS_ZONE_AUTO_POINT1_TEMP_HYST 1
974 #define SYS_ZONE_AUTO_POINT1_TEMP 2
975 #define SYS_ZONE_AUTO_POINT2_TEMP 3
976 #define SYS_ZONE_AUTO_POINT3_TEMP 4
978 static ssize_t
show_zone(struct device
*dev
, struct device_attribute
*attr
,
981 struct dme1737_data
*data
= dme1737_update_device(dev
);
982 struct sensor_device_attribute_2
983 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
984 int ix
= sensor_attr_2
->index
;
985 int fn
= sensor_attr_2
->nr
;
989 case SYS_ZONE_AUTO_CHANNELS_TEMP
:
990 /* check config2 for non-standard temp-to-zone mapping */
991 if ((ix
== 1) && (data
->config2
& 0x02))
996 case SYS_ZONE_AUTO_POINT1_TEMP_HYST
:
997 res
= TEMP_FROM_REG(data
->zone_low
[ix
], 8) -
998 TEMP_HYST_FROM_REG(data
->zone_hyst
[ix
== 2], ix
);
1000 case SYS_ZONE_AUTO_POINT1_TEMP
:
1001 res
= TEMP_FROM_REG(data
->zone_low
[ix
], 8);
1003 case SYS_ZONE_AUTO_POINT2_TEMP
:
1004 /* pwm_freq holds the temp range bits in the upper nibble */
1005 res
= TEMP_FROM_REG(data
->zone_low
[ix
], 8) +
1006 TEMP_RANGE_FROM_REG(data
->pwm_freq
[ix
]);
1008 case SYS_ZONE_AUTO_POINT3_TEMP
:
1009 res
= TEMP_FROM_REG(data
->zone_abs
[ix
], 8);
1013 dev_dbg(dev
, "Unknown function %d.\n", fn
);
1016 return sprintf(buf
, "%d\n", res
);
1019 static ssize_t
set_zone(struct device
*dev
, struct device_attribute
*attr
,
1020 const char *buf
, size_t count
)
1022 struct dme1737_data
*data
= dev_get_drvdata(dev
);
1023 struct sensor_device_attribute_2
1024 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
1025 int ix
= sensor_attr_2
->index
;
1026 int fn
= sensor_attr_2
->nr
;
1032 err
= kstrtol(buf
, 10, &val
);
1036 mutex_lock(&data
->update_lock
);
1038 case SYS_ZONE_AUTO_POINT1_TEMP_HYST
:
1039 /* Refresh the cache */
1040 data
->zone_low
[ix
] = dme1737_read(data
,
1041 DME1737_REG_ZONE_LOW(ix
));
1042 /* Modify the temp hyst value */
1043 temp
= TEMP_FROM_REG(data
->zone_low
[ix
], 8);
1044 reg
= dme1737_read(data
, DME1737_REG_ZONE_HYST(ix
== 2));
1045 data
->zone_hyst
[ix
== 2] = TEMP_HYST_TO_REG(temp
, val
, ix
, reg
);
1046 dme1737_write(data
, DME1737_REG_ZONE_HYST(ix
== 2),
1047 data
->zone_hyst
[ix
== 2]);
1049 case SYS_ZONE_AUTO_POINT1_TEMP
:
1050 data
->zone_low
[ix
] = TEMP_TO_REG(val
);
1051 dme1737_write(data
, DME1737_REG_ZONE_LOW(ix
),
1052 data
->zone_low
[ix
]);
1054 case SYS_ZONE_AUTO_POINT2_TEMP
:
1055 /* Refresh the cache */
1056 data
->zone_low
[ix
] = dme1737_read(data
,
1057 DME1737_REG_ZONE_LOW(ix
));
1059 * Modify the temp range value (which is stored in the upper
1060 * nibble of the pwm_freq register)
1062 temp
= TEMP_FROM_REG(data
->zone_low
[ix
], 8);
1063 val
= clamp_val(val
, temp
, temp
+ 80000);
1064 reg
= dme1737_read(data
, DME1737_REG_PWM_FREQ(ix
));
1065 data
->pwm_freq
[ix
] = TEMP_RANGE_TO_REG(val
- temp
, reg
);
1066 dme1737_write(data
, DME1737_REG_PWM_FREQ(ix
),
1067 data
->pwm_freq
[ix
]);
1069 case SYS_ZONE_AUTO_POINT3_TEMP
:
1070 data
->zone_abs
[ix
] = TEMP_TO_REG(val
);
1071 dme1737_write(data
, DME1737_REG_ZONE_ABS(ix
),
1072 data
->zone_abs
[ix
]);
1075 dev_dbg(dev
, "Unknown function %d.\n", fn
);
1077 mutex_unlock(&data
->update_lock
);
1082 /* ---------------------------------------------------------------------
1083 * Fan sysfs attributes
1085 * --------------------------------------------------------------------- */
1087 #define SYS_FAN_INPUT 0
1088 #define SYS_FAN_MIN 1
1089 #define SYS_FAN_MAX 2
1090 #define SYS_FAN_ALARM 3
1091 #define SYS_FAN_TYPE 4
1093 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*attr
,
1096 struct dme1737_data
*data
= dme1737_update_device(dev
);
1097 struct sensor_device_attribute_2
1098 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
1099 int ix
= sensor_attr_2
->index
;
1100 int fn
= sensor_attr_2
->nr
;
1105 res
= FAN_FROM_REG(data
->fan
[ix
],
1107 FAN_TPC_FROM_REG(data
->fan_opt
[ix
]));
1110 res
= FAN_FROM_REG(data
->fan_min
[ix
],
1112 FAN_TPC_FROM_REG(data
->fan_opt
[ix
]));
1115 /* only valid for fan[5-6] */
1116 res
= FAN_MAX_FROM_REG(data
->fan_max
[ix
- 4]);
1119 res
= (data
->alarms
>> DME1737_BIT_ALARM_FAN
[ix
]) & 0x01;
1122 /* only valid for fan[1-4] */
1123 res
= FAN_TYPE_FROM_REG(data
->fan_opt
[ix
]);
1127 dev_dbg(dev
, "Unknown function %d.\n", fn
);
1130 return sprintf(buf
, "%d\n", res
);
1133 static ssize_t
set_fan(struct device
*dev
, struct device_attribute
*attr
,
1134 const char *buf
, size_t count
)
1136 struct dme1737_data
*data
= dev_get_drvdata(dev
);
1137 struct sensor_device_attribute_2
1138 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
1139 int ix
= sensor_attr_2
->index
;
1140 int fn
= sensor_attr_2
->nr
;
1144 err
= kstrtol(buf
, 10, &val
);
1148 mutex_lock(&data
->update_lock
);
1152 data
->fan_min
[ix
] = FAN_TO_REG(val
, 0);
1154 /* Refresh the cache */
1155 data
->fan_opt
[ix
] = dme1737_read(data
,
1156 DME1737_REG_FAN_OPT(ix
));
1157 /* Modify the fan min value */
1158 data
->fan_min
[ix
] = FAN_TO_REG(val
,
1159 FAN_TPC_FROM_REG(data
->fan_opt
[ix
]));
1161 dme1737_write(data
, DME1737_REG_FAN_MIN(ix
),
1162 data
->fan_min
[ix
] & 0xff);
1163 dme1737_write(data
, DME1737_REG_FAN_MIN(ix
) + 1,
1164 data
->fan_min
[ix
] >> 8);
1167 /* Only valid for fan[5-6] */
1168 data
->fan_max
[ix
- 4] = FAN_MAX_TO_REG(val
);
1169 dme1737_write(data
, DME1737_REG_FAN_MAX(ix
),
1170 data
->fan_max
[ix
- 4]);
1173 /* Only valid for fan[1-4] */
1174 if (!(val
== 1 || val
== 2 || val
== 4)) {
1177 "Fan type value %ld not supported. Choose one of 1, 2, or 4.\n",
1181 data
->fan_opt
[ix
] = FAN_TYPE_TO_REG(val
, dme1737_read(data
,
1182 DME1737_REG_FAN_OPT(ix
)));
1183 dme1737_write(data
, DME1737_REG_FAN_OPT(ix
),
1187 dev_dbg(dev
, "Unknown function %d.\n", fn
);
1190 mutex_unlock(&data
->update_lock
);
1195 /* ---------------------------------------------------------------------
1196 * PWM sysfs attributes
1198 * --------------------------------------------------------------------- */
1201 #define SYS_PWM_FREQ 1
1202 #define SYS_PWM_ENABLE 2
1203 #define SYS_PWM_RAMP_RATE 3
1204 #define SYS_PWM_AUTO_CHANNELS_ZONE 4
1205 #define SYS_PWM_AUTO_PWM_MIN 5
1206 #define SYS_PWM_AUTO_POINT1_PWM 6
1207 #define SYS_PWM_AUTO_POINT2_PWM 7
1209 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*attr
,
1212 struct dme1737_data
*data
= dme1737_update_device(dev
);
1213 struct sensor_device_attribute_2
1214 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
1215 int ix
= sensor_attr_2
->index
;
1216 int fn
= sensor_attr_2
->nr
;
1221 if (PWM_EN_FROM_REG(data
->pwm_config
[ix
]) == 0)
1224 res
= data
->pwm
[ix
];
1227 res
= PWM_FREQ_FROM_REG(data
->pwm_freq
[ix
]);
1229 case SYS_PWM_ENABLE
:
1231 res
= 1; /* pwm[5-6] hard-wired to manual mode */
1233 res
= PWM_EN_FROM_REG(data
->pwm_config
[ix
]);
1235 case SYS_PWM_RAMP_RATE
:
1236 /* Only valid for pwm[1-3] */
1237 res
= PWM_RR_FROM_REG(data
->pwm_rr
[ix
> 0], ix
);
1239 case SYS_PWM_AUTO_CHANNELS_ZONE
:
1240 /* Only valid for pwm[1-3] */
1241 if (PWM_EN_FROM_REG(data
->pwm_config
[ix
]) == 2)
1242 res
= PWM_ACZ_FROM_REG(data
->pwm_config
[ix
]);
1244 res
= data
->pwm_acz
[ix
];
1246 case SYS_PWM_AUTO_PWM_MIN
:
1247 /* Only valid for pwm[1-3] */
1248 if (PWM_OFF_FROM_REG(data
->pwm_rr
[0], ix
))
1249 res
= data
->pwm_min
[ix
];
1253 case SYS_PWM_AUTO_POINT1_PWM
:
1254 /* Only valid for pwm[1-3] */
1255 res
= data
->pwm_min
[ix
];
1257 case SYS_PWM_AUTO_POINT2_PWM
:
1258 /* Only valid for pwm[1-3] */
1259 res
= 255; /* hard-wired */
1263 dev_dbg(dev
, "Unknown function %d.\n", fn
);
1266 return sprintf(buf
, "%d\n", res
);
1269 static struct attribute
*dme1737_pwm_chmod_attr
[];
1270 static void dme1737_chmod_file(struct device
*, struct attribute
*, umode_t
);
1272 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
1273 const char *buf
, size_t count
)
1275 struct dme1737_data
*data
= dev_get_drvdata(dev
);
1276 struct sensor_device_attribute_2
1277 *sensor_attr_2
= to_sensor_dev_attr_2(attr
);
1278 int ix
= sensor_attr_2
->index
;
1279 int fn
= sensor_attr_2
->nr
;
1283 err
= kstrtol(buf
, 10, &val
);
1287 mutex_lock(&data
->update_lock
);
1290 data
->pwm
[ix
] = clamp_val(val
, 0, 255);
1291 dme1737_write(data
, DME1737_REG_PWM(ix
), data
->pwm
[ix
]);
1294 data
->pwm_freq
[ix
] = PWM_FREQ_TO_REG(val
, dme1737_read(data
,
1295 DME1737_REG_PWM_FREQ(ix
)));
1296 dme1737_write(data
, DME1737_REG_PWM_FREQ(ix
),
1297 data
->pwm_freq
[ix
]);
1299 case SYS_PWM_ENABLE
:
1300 /* Only valid for pwm[1-3] */
1301 if (val
< 0 || val
> 2) {
1304 "PWM enable %ld not supported. Choose one of 0, 1, or 2.\n",
1308 /* Refresh the cache */
1309 data
->pwm_config
[ix
] = dme1737_read(data
,
1310 DME1737_REG_PWM_CONFIG(ix
));
1311 if (val
== PWM_EN_FROM_REG(data
->pwm_config
[ix
])) {
1312 /* Bail out if no change */
1315 /* Do some housekeeping if we are currently in auto mode */
1316 if (PWM_EN_FROM_REG(data
->pwm_config
[ix
]) == 2) {
1317 /* Save the current zone channel assignment */
1318 data
->pwm_acz
[ix
] = PWM_ACZ_FROM_REG(
1319 data
->pwm_config
[ix
]);
1320 /* Save the current ramp rate state and disable it */
1321 data
->pwm_rr
[ix
> 0] = dme1737_read(data
,
1322 DME1737_REG_PWM_RR(ix
> 0));
1323 data
->pwm_rr_en
&= ~(1 << ix
);
1324 if (PWM_RR_EN_FROM_REG(data
->pwm_rr
[ix
> 0], ix
)) {
1325 data
->pwm_rr_en
|= (1 << ix
);
1326 data
->pwm_rr
[ix
> 0] = PWM_RR_EN_TO_REG(0, ix
,
1327 data
->pwm_rr
[ix
> 0]);
1329 DME1737_REG_PWM_RR(ix
> 0),
1330 data
->pwm_rr
[ix
> 0]);
1333 /* Set the new PWM mode */
1336 /* Change permissions of pwm[ix] to read-only */
1337 dme1737_chmod_file(dev
, dme1737_pwm_chmod_attr
[ix
],
1339 /* Turn fan fully on */
1340 data
->pwm_config
[ix
] = PWM_EN_TO_REG(0,
1341 data
->pwm_config
[ix
]);
1342 dme1737_write(data
, DME1737_REG_PWM_CONFIG(ix
),
1343 data
->pwm_config
[ix
]);
1346 /* Turn on manual mode */
1347 data
->pwm_config
[ix
] = PWM_EN_TO_REG(1,
1348 data
->pwm_config
[ix
]);
1349 dme1737_write(data
, DME1737_REG_PWM_CONFIG(ix
),
1350 data
->pwm_config
[ix
]);
1351 /* Change permissions of pwm[ix] to read-writeable */
1352 dme1737_chmod_file(dev
, dme1737_pwm_chmod_attr
[ix
],
1356 /* Change permissions of pwm[ix] to read-only */
1357 dme1737_chmod_file(dev
, dme1737_pwm_chmod_attr
[ix
],
1360 * Turn on auto mode using the saved zone channel
1363 data
->pwm_config
[ix
] = PWM_ACZ_TO_REG(
1365 data
->pwm_config
[ix
]);
1366 dme1737_write(data
, DME1737_REG_PWM_CONFIG(ix
),
1367 data
->pwm_config
[ix
]);
1368 /* Enable PWM ramp rate if previously enabled */
1369 if (data
->pwm_rr_en
& (1 << ix
)) {
1370 data
->pwm_rr
[ix
> 0] = PWM_RR_EN_TO_REG(1, ix
,
1372 DME1737_REG_PWM_RR(ix
> 0)));
1374 DME1737_REG_PWM_RR(ix
> 0),
1375 data
->pwm_rr
[ix
> 0]);
1380 case SYS_PWM_RAMP_RATE
:
1381 /* Only valid for pwm[1-3] */
1382 /* Refresh the cache */
1383 data
->pwm_config
[ix
] = dme1737_read(data
,
1384 DME1737_REG_PWM_CONFIG(ix
));
1385 data
->pwm_rr
[ix
> 0] = dme1737_read(data
,
1386 DME1737_REG_PWM_RR(ix
> 0));
1387 /* Set the ramp rate value */
1389 data
->pwm_rr
[ix
> 0] = PWM_RR_TO_REG(val
, ix
,
1390 data
->pwm_rr
[ix
> 0]);
1393 * Enable/disable the feature only if the associated PWM
1394 * output is in automatic mode.
1396 if (PWM_EN_FROM_REG(data
->pwm_config
[ix
]) == 2) {
1397 data
->pwm_rr
[ix
> 0] = PWM_RR_EN_TO_REG(val
> 0, ix
,
1398 data
->pwm_rr
[ix
> 0]);
1400 dme1737_write(data
, DME1737_REG_PWM_RR(ix
> 0),
1401 data
->pwm_rr
[ix
> 0]);
1403 case SYS_PWM_AUTO_CHANNELS_ZONE
:
1404 /* Only valid for pwm[1-3] */
1405 if (!(val
== 1 || val
== 2 || val
== 4 ||
1406 val
== 6 || val
== 7)) {
1409 "PWM auto channels zone %ld not supported. Choose one of 1, 2, 4, 6, "
1413 /* Refresh the cache */
1414 data
->pwm_config
[ix
] = dme1737_read(data
,
1415 DME1737_REG_PWM_CONFIG(ix
));
1416 if (PWM_EN_FROM_REG(data
->pwm_config
[ix
]) == 2) {
1418 * PWM is already in auto mode so update the temp
1419 * channel assignment
1421 data
->pwm_config
[ix
] = PWM_ACZ_TO_REG(val
,
1422 data
->pwm_config
[ix
]);
1423 dme1737_write(data
, DME1737_REG_PWM_CONFIG(ix
),
1424 data
->pwm_config
[ix
]);
1427 * PWM is not in auto mode so we save the temp
1428 * channel assignment for later use
1430 data
->pwm_acz
[ix
] = val
;
1433 case SYS_PWM_AUTO_PWM_MIN
:
1434 /* Only valid for pwm[1-3] */
1435 /* Refresh the cache */
1436 data
->pwm_min
[ix
] = dme1737_read(data
,
1437 DME1737_REG_PWM_MIN(ix
));
1439 * There are only 2 values supported for the auto_pwm_min
1440 * value: 0 or auto_point1_pwm. So if the temperature drops
1441 * below the auto_point1_temp_hyst value, the fan either turns
1442 * off or runs at auto_point1_pwm duty-cycle.
1444 if (val
> ((data
->pwm_min
[ix
] + 1) / 2)) {
1445 data
->pwm_rr
[0] = PWM_OFF_TO_REG(1, ix
,
1447 DME1737_REG_PWM_RR(0)));
1449 data
->pwm_rr
[0] = PWM_OFF_TO_REG(0, ix
,
1451 DME1737_REG_PWM_RR(0)));
1453 dme1737_write(data
, DME1737_REG_PWM_RR(0),
1456 case SYS_PWM_AUTO_POINT1_PWM
:
1457 /* Only valid for pwm[1-3] */
1458 data
->pwm_min
[ix
] = clamp_val(val
, 0, 255);
1459 dme1737_write(data
, DME1737_REG_PWM_MIN(ix
),
1463 dev_dbg(dev
, "Unknown function %d.\n", fn
);
1466 mutex_unlock(&data
->update_lock
);
1471 /* ---------------------------------------------------------------------
1472 * Miscellaneous sysfs attributes
1473 * --------------------------------------------------------------------- */
1475 static ssize_t
vrm_show(struct device
*dev
, struct device_attribute
*attr
,
1478 struct i2c_client
*client
= to_i2c_client(dev
);
1479 struct dme1737_data
*data
= i2c_get_clientdata(client
);
1481 return sprintf(buf
, "%d\n", data
->vrm
);
1484 static ssize_t
vrm_store(struct device
*dev
, struct device_attribute
*attr
,
1485 const char *buf
, size_t count
)
1487 struct dme1737_data
*data
= dev_get_drvdata(dev
);
1491 err
= kstrtoul(buf
, 10, &val
);
1502 static ssize_t
cpu0_vid_show(struct device
*dev
,
1503 struct device_attribute
*attr
, char *buf
)
1505 struct dme1737_data
*data
= dme1737_update_device(dev
);
1507 return sprintf(buf
, "%d\n", vid_from_reg(data
->vid
, data
->vrm
));
1510 static ssize_t
name_show(struct device
*dev
, struct device_attribute
*attr
,
1513 struct dme1737_data
*data
= dev_get_drvdata(dev
);
1515 return sprintf(buf
, "%s\n", data
->name
);
1518 /* ---------------------------------------------------------------------
1519 * Sysfs device attribute defines and structs
1520 * --------------------------------------------------------------------- */
1524 #define SENSOR_DEVICE_ATTR_IN(ix) \
1525 static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \
1526 show_in, NULL, SYS_IN_INPUT, ix); \
1527 static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
1528 show_in, set_in, SYS_IN_MIN, ix); \
1529 static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
1530 show_in, set_in, SYS_IN_MAX, ix); \
1531 static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \
1532 show_in, NULL, SYS_IN_ALARM, ix)
1534 SENSOR_DEVICE_ATTR_IN(0);
1535 SENSOR_DEVICE_ATTR_IN(1);
1536 SENSOR_DEVICE_ATTR_IN(2);
1537 SENSOR_DEVICE_ATTR_IN(3);
1538 SENSOR_DEVICE_ATTR_IN(4);
1539 SENSOR_DEVICE_ATTR_IN(5);
1540 SENSOR_DEVICE_ATTR_IN(6);
1541 SENSOR_DEVICE_ATTR_IN(7);
1543 /* Temperatures 1-3 */
1545 #define SENSOR_DEVICE_ATTR_TEMP(ix) \
1546 static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \
1547 show_temp, NULL, SYS_TEMP_INPUT, ix-1); \
1548 static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \
1549 show_temp, set_temp, SYS_TEMP_MIN, ix-1); \
1550 static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
1551 show_temp, set_temp, SYS_TEMP_MAX, ix-1); \
1552 static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \
1553 show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \
1554 static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \
1555 show_temp, NULL, SYS_TEMP_ALARM, ix-1); \
1556 static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \
1557 show_temp, NULL, SYS_TEMP_FAULT, ix-1)
1559 SENSOR_DEVICE_ATTR_TEMP(1);
1560 SENSOR_DEVICE_ATTR_TEMP(2);
1561 SENSOR_DEVICE_ATTR_TEMP(3);
1565 #define SENSOR_DEVICE_ATTR_ZONE(ix) \
1566 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \
1567 show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \
1568 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \
1569 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \
1570 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \
1571 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \
1572 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \
1573 show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \
1574 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \
1575 show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1)
1577 SENSOR_DEVICE_ATTR_ZONE(1);
1578 SENSOR_DEVICE_ATTR_ZONE(2);
1579 SENSOR_DEVICE_ATTR_ZONE(3);
1583 #define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \
1584 static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
1585 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1586 static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
1587 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1588 static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
1589 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1590 static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \
1591 show_fan, set_fan, SYS_FAN_TYPE, ix-1)
1593 SENSOR_DEVICE_ATTR_FAN_1TO4(1);
1594 SENSOR_DEVICE_ATTR_FAN_1TO4(2);
1595 SENSOR_DEVICE_ATTR_FAN_1TO4(3);
1596 SENSOR_DEVICE_ATTR_FAN_1TO4(4);
1600 #define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \
1601 static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
1602 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1603 static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
1604 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1605 static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
1606 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1607 static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \
1608 show_fan, set_fan, SYS_FAN_MAX, ix-1)
1610 SENSOR_DEVICE_ATTR_FAN_5TO6(5);
1611 SENSOR_DEVICE_ATTR_FAN_5TO6(6);
1615 #define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \
1616 static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \
1617 show_pwm, set_pwm, SYS_PWM, ix-1); \
1618 static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \
1619 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1620 static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
1621 show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \
1622 static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \
1623 show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \
1624 static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \
1625 show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \
1626 static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \
1627 show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \
1628 static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \
1629 show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \
1630 static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \
1631 show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1)
1633 SENSOR_DEVICE_ATTR_PWM_1TO3(1);
1634 SENSOR_DEVICE_ATTR_PWM_1TO3(2);
1635 SENSOR_DEVICE_ATTR_PWM_1TO3(3);
1639 #define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \
1640 static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \
1641 show_pwm, set_pwm, SYS_PWM, ix-1); \
1642 static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \
1643 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1644 static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
1645 show_pwm, NULL, SYS_PWM_ENABLE, ix-1)
1647 SENSOR_DEVICE_ATTR_PWM_5TO6(5);
1648 SENSOR_DEVICE_ATTR_PWM_5TO6(6);
1652 static DEVICE_ATTR_RW(vrm
);
1653 static DEVICE_ATTR_RO(cpu0_vid
);
1654 static DEVICE_ATTR_RO(name
); /* for ISA devices */
1657 * This struct holds all the attributes that are always present and need to be
1658 * created unconditionally. The attributes that need modification of their
1659 * permissions are created read-only and write permissions are added or removed
1660 * on the fly when required
1662 static struct attribute
*dme1737_attr
[] = {
1664 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
1665 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
1666 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
1667 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
1668 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
1669 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
1670 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
1671 &sensor_dev_attr_in1_alarm
.dev_attr
.attr
,
1672 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
1673 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
1674 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
1675 &sensor_dev_attr_in2_alarm
.dev_attr
.attr
,
1676 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
1677 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
1678 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
1679 &sensor_dev_attr_in3_alarm
.dev_attr
.attr
,
1680 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
1681 &sensor_dev_attr_in4_min
.dev_attr
.attr
,
1682 &sensor_dev_attr_in4_max
.dev_attr
.attr
,
1683 &sensor_dev_attr_in4_alarm
.dev_attr
.attr
,
1684 &sensor_dev_attr_in5_input
.dev_attr
.attr
,
1685 &sensor_dev_attr_in5_min
.dev_attr
.attr
,
1686 &sensor_dev_attr_in5_max
.dev_attr
.attr
,
1687 &sensor_dev_attr_in5_alarm
.dev_attr
.attr
,
1688 &sensor_dev_attr_in6_input
.dev_attr
.attr
,
1689 &sensor_dev_attr_in6_min
.dev_attr
.attr
,
1690 &sensor_dev_attr_in6_max
.dev_attr
.attr
,
1691 &sensor_dev_attr_in6_alarm
.dev_attr
.attr
,
1693 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
1694 &sensor_dev_attr_temp1_min
.dev_attr
.attr
,
1695 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
1696 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
1697 &sensor_dev_attr_temp1_fault
.dev_attr
.attr
,
1698 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
1699 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
1700 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
1701 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
1702 &sensor_dev_attr_temp2_fault
.dev_attr
.attr
,
1703 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
1704 &sensor_dev_attr_temp3_min
.dev_attr
.attr
,
1705 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
1706 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
1707 &sensor_dev_attr_temp3_fault
.dev_attr
.attr
,
1709 &sensor_dev_attr_zone1_auto_point1_temp
.dev_attr
.attr
,
1710 &sensor_dev_attr_zone1_auto_point2_temp
.dev_attr
.attr
,
1711 &sensor_dev_attr_zone1_auto_point3_temp
.dev_attr
.attr
,
1712 &sensor_dev_attr_zone1_auto_channels_temp
.dev_attr
.attr
,
1713 &sensor_dev_attr_zone2_auto_point1_temp
.dev_attr
.attr
,
1714 &sensor_dev_attr_zone2_auto_point2_temp
.dev_attr
.attr
,
1715 &sensor_dev_attr_zone2_auto_point3_temp
.dev_attr
.attr
,
1716 &sensor_dev_attr_zone2_auto_channels_temp
.dev_attr
.attr
,
1720 static const struct attribute_group dme1737_group
= {
1721 .attrs
= dme1737_attr
,
1725 * The following struct holds temp offset attributes, which are not available
1726 * in all chips. The following chips support them:
1729 static struct attribute
*dme1737_temp_offset_attr
[] = {
1730 &sensor_dev_attr_temp1_offset
.dev_attr
.attr
,
1731 &sensor_dev_attr_temp2_offset
.dev_attr
.attr
,
1732 &sensor_dev_attr_temp3_offset
.dev_attr
.attr
,
1736 static const struct attribute_group dme1737_temp_offset_group
= {
1737 .attrs
= dme1737_temp_offset_attr
,
1741 * The following struct holds VID related attributes, which are not available
1742 * in all chips. The following chips support them:
1745 static struct attribute
*dme1737_vid_attr
[] = {
1747 &dev_attr_cpu0_vid
.attr
,
1751 static const struct attribute_group dme1737_vid_group
= {
1752 .attrs
= dme1737_vid_attr
,
1756 * The following struct holds temp zone 3 related attributes, which are not
1757 * available in all chips. The following chips support them:
1758 * DME1737, SCH311x, SCH5027
1760 static struct attribute
*dme1737_zone3_attr
[] = {
1761 &sensor_dev_attr_zone3_auto_point1_temp
.dev_attr
.attr
,
1762 &sensor_dev_attr_zone3_auto_point2_temp
.dev_attr
.attr
,
1763 &sensor_dev_attr_zone3_auto_point3_temp
.dev_attr
.attr
,
1764 &sensor_dev_attr_zone3_auto_channels_temp
.dev_attr
.attr
,
1768 static const struct attribute_group dme1737_zone3_group
= {
1769 .attrs
= dme1737_zone3_attr
,
1774 * The following struct holds temp zone hysteresis related attributes, which
1775 * are not available in all chips. The following chips support them:
1778 static struct attribute
*dme1737_zone_hyst_attr
[] = {
1779 &sensor_dev_attr_zone1_auto_point1_temp_hyst
.dev_attr
.attr
,
1780 &sensor_dev_attr_zone2_auto_point1_temp_hyst
.dev_attr
.attr
,
1781 &sensor_dev_attr_zone3_auto_point1_temp_hyst
.dev_attr
.attr
,
1785 static const struct attribute_group dme1737_zone_hyst_group
= {
1786 .attrs
= dme1737_zone_hyst_attr
,
1790 * The following struct holds voltage in7 related attributes, which
1791 * are not available in all chips. The following chips support them:
1794 static struct attribute
*dme1737_in7_attr
[] = {
1795 &sensor_dev_attr_in7_input
.dev_attr
.attr
,
1796 &sensor_dev_attr_in7_min
.dev_attr
.attr
,
1797 &sensor_dev_attr_in7_max
.dev_attr
.attr
,
1798 &sensor_dev_attr_in7_alarm
.dev_attr
.attr
,
1802 static const struct attribute_group dme1737_in7_group
= {
1803 .attrs
= dme1737_in7_attr
,
1807 * The following structs hold the PWM attributes, some of which are optional.
1808 * Their creation depends on the chip configuration which is determined during
1811 static struct attribute
*dme1737_pwm1_attr
[] = {
1812 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
1813 &sensor_dev_attr_pwm1_freq
.dev_attr
.attr
,
1814 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
1815 &sensor_dev_attr_pwm1_ramp_rate
.dev_attr
.attr
,
1816 &sensor_dev_attr_pwm1_auto_channels_zone
.dev_attr
.attr
,
1817 &sensor_dev_attr_pwm1_auto_point1_pwm
.dev_attr
.attr
,
1818 &sensor_dev_attr_pwm1_auto_point2_pwm
.dev_attr
.attr
,
1821 static struct attribute
*dme1737_pwm2_attr
[] = {
1822 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
1823 &sensor_dev_attr_pwm2_freq
.dev_attr
.attr
,
1824 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
1825 &sensor_dev_attr_pwm2_ramp_rate
.dev_attr
.attr
,
1826 &sensor_dev_attr_pwm2_auto_channels_zone
.dev_attr
.attr
,
1827 &sensor_dev_attr_pwm2_auto_point1_pwm
.dev_attr
.attr
,
1828 &sensor_dev_attr_pwm2_auto_point2_pwm
.dev_attr
.attr
,
1831 static struct attribute
*dme1737_pwm3_attr
[] = {
1832 &sensor_dev_attr_pwm3
.dev_attr
.attr
,
1833 &sensor_dev_attr_pwm3_freq
.dev_attr
.attr
,
1834 &sensor_dev_attr_pwm3_enable
.dev_attr
.attr
,
1835 &sensor_dev_attr_pwm3_ramp_rate
.dev_attr
.attr
,
1836 &sensor_dev_attr_pwm3_auto_channels_zone
.dev_attr
.attr
,
1837 &sensor_dev_attr_pwm3_auto_point1_pwm
.dev_attr
.attr
,
1838 &sensor_dev_attr_pwm3_auto_point2_pwm
.dev_attr
.attr
,
1841 static struct attribute
*dme1737_pwm5_attr
[] = {
1842 &sensor_dev_attr_pwm5
.dev_attr
.attr
,
1843 &sensor_dev_attr_pwm5_freq
.dev_attr
.attr
,
1844 &sensor_dev_attr_pwm5_enable
.dev_attr
.attr
,
1847 static struct attribute
*dme1737_pwm6_attr
[] = {
1848 &sensor_dev_attr_pwm6
.dev_attr
.attr
,
1849 &sensor_dev_attr_pwm6_freq
.dev_attr
.attr
,
1850 &sensor_dev_attr_pwm6_enable
.dev_attr
.attr
,
1854 static const struct attribute_group dme1737_pwm_group
[] = {
1855 { .attrs
= dme1737_pwm1_attr
},
1856 { .attrs
= dme1737_pwm2_attr
},
1857 { .attrs
= dme1737_pwm3_attr
},
1859 { .attrs
= dme1737_pwm5_attr
},
1860 { .attrs
= dme1737_pwm6_attr
},
1864 * The following struct holds auto PWM min attributes, which are not available
1865 * in all chips. Their creation depends on the chip type which is determined
1866 * during module load.
1868 static struct attribute
*dme1737_auto_pwm_min_attr
[] = {
1869 &sensor_dev_attr_pwm1_auto_pwm_min
.dev_attr
.attr
,
1870 &sensor_dev_attr_pwm2_auto_pwm_min
.dev_attr
.attr
,
1871 &sensor_dev_attr_pwm3_auto_pwm_min
.dev_attr
.attr
,
1875 * The following structs hold the fan attributes, some of which are optional.
1876 * Their creation depends on the chip configuration which is determined during
1879 static struct attribute
*dme1737_fan1_attr
[] = {
1880 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
1881 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
1882 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
1883 &sensor_dev_attr_fan1_type
.dev_attr
.attr
,
1886 static struct attribute
*dme1737_fan2_attr
[] = {
1887 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
1888 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
1889 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
1890 &sensor_dev_attr_fan2_type
.dev_attr
.attr
,
1893 static struct attribute
*dme1737_fan3_attr
[] = {
1894 &sensor_dev_attr_fan3_input
.dev_attr
.attr
,
1895 &sensor_dev_attr_fan3_min
.dev_attr
.attr
,
1896 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
1897 &sensor_dev_attr_fan3_type
.dev_attr
.attr
,
1900 static struct attribute
*dme1737_fan4_attr
[] = {
1901 &sensor_dev_attr_fan4_input
.dev_attr
.attr
,
1902 &sensor_dev_attr_fan4_min
.dev_attr
.attr
,
1903 &sensor_dev_attr_fan4_alarm
.dev_attr
.attr
,
1904 &sensor_dev_attr_fan4_type
.dev_attr
.attr
,
1907 static struct attribute
*dme1737_fan5_attr
[] = {
1908 &sensor_dev_attr_fan5_input
.dev_attr
.attr
,
1909 &sensor_dev_attr_fan5_min
.dev_attr
.attr
,
1910 &sensor_dev_attr_fan5_alarm
.dev_attr
.attr
,
1911 &sensor_dev_attr_fan5_max
.dev_attr
.attr
,
1914 static struct attribute
*dme1737_fan6_attr
[] = {
1915 &sensor_dev_attr_fan6_input
.dev_attr
.attr
,
1916 &sensor_dev_attr_fan6_min
.dev_attr
.attr
,
1917 &sensor_dev_attr_fan6_alarm
.dev_attr
.attr
,
1918 &sensor_dev_attr_fan6_max
.dev_attr
.attr
,
1922 static const struct attribute_group dme1737_fan_group
[] = {
1923 { .attrs
= dme1737_fan1_attr
},
1924 { .attrs
= dme1737_fan2_attr
},
1925 { .attrs
= dme1737_fan3_attr
},
1926 { .attrs
= dme1737_fan4_attr
},
1927 { .attrs
= dme1737_fan5_attr
},
1928 { .attrs
= dme1737_fan6_attr
},
1932 * The permissions of the following zone attributes are changed to read-
1933 * writeable if the chip is *not* locked. Otherwise they stay read-only.
1935 static struct attribute
*dme1737_zone_chmod_attr
[] = {
1936 &sensor_dev_attr_zone1_auto_point1_temp
.dev_attr
.attr
,
1937 &sensor_dev_attr_zone1_auto_point2_temp
.dev_attr
.attr
,
1938 &sensor_dev_attr_zone1_auto_point3_temp
.dev_attr
.attr
,
1939 &sensor_dev_attr_zone2_auto_point1_temp
.dev_attr
.attr
,
1940 &sensor_dev_attr_zone2_auto_point2_temp
.dev_attr
.attr
,
1941 &sensor_dev_attr_zone2_auto_point3_temp
.dev_attr
.attr
,
1945 static const struct attribute_group dme1737_zone_chmod_group
= {
1946 .attrs
= dme1737_zone_chmod_attr
,
1951 * The permissions of the following zone 3 attributes are changed to read-
1952 * writeable if the chip is *not* locked. Otherwise they stay read-only.
1954 static struct attribute
*dme1737_zone3_chmod_attr
[] = {
1955 &sensor_dev_attr_zone3_auto_point1_temp
.dev_attr
.attr
,
1956 &sensor_dev_attr_zone3_auto_point2_temp
.dev_attr
.attr
,
1957 &sensor_dev_attr_zone3_auto_point3_temp
.dev_attr
.attr
,
1961 static const struct attribute_group dme1737_zone3_chmod_group
= {
1962 .attrs
= dme1737_zone3_chmod_attr
,
1966 * The permissions of the following PWM attributes are changed to read-
1967 * writeable if the chip is *not* locked and the respective PWM is available.
1968 * Otherwise they stay read-only.
1970 static struct attribute
*dme1737_pwm1_chmod_attr
[] = {
1971 &sensor_dev_attr_pwm1_freq
.dev_attr
.attr
,
1972 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
1973 &sensor_dev_attr_pwm1_ramp_rate
.dev_attr
.attr
,
1974 &sensor_dev_attr_pwm1_auto_channels_zone
.dev_attr
.attr
,
1975 &sensor_dev_attr_pwm1_auto_point1_pwm
.dev_attr
.attr
,
1978 static struct attribute
*dme1737_pwm2_chmod_attr
[] = {
1979 &sensor_dev_attr_pwm2_freq
.dev_attr
.attr
,
1980 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
1981 &sensor_dev_attr_pwm2_ramp_rate
.dev_attr
.attr
,
1982 &sensor_dev_attr_pwm2_auto_channels_zone
.dev_attr
.attr
,
1983 &sensor_dev_attr_pwm2_auto_point1_pwm
.dev_attr
.attr
,
1986 static struct attribute
*dme1737_pwm3_chmod_attr
[] = {
1987 &sensor_dev_attr_pwm3_freq
.dev_attr
.attr
,
1988 &sensor_dev_attr_pwm3_enable
.dev_attr
.attr
,
1989 &sensor_dev_attr_pwm3_ramp_rate
.dev_attr
.attr
,
1990 &sensor_dev_attr_pwm3_auto_channels_zone
.dev_attr
.attr
,
1991 &sensor_dev_attr_pwm3_auto_point1_pwm
.dev_attr
.attr
,
1994 static struct attribute
*dme1737_pwm5_chmod_attr
[] = {
1995 &sensor_dev_attr_pwm5
.dev_attr
.attr
,
1996 &sensor_dev_attr_pwm5_freq
.dev_attr
.attr
,
1999 static struct attribute
*dme1737_pwm6_chmod_attr
[] = {
2000 &sensor_dev_attr_pwm6
.dev_attr
.attr
,
2001 &sensor_dev_attr_pwm6_freq
.dev_attr
.attr
,
2005 static const struct attribute_group dme1737_pwm_chmod_group
[] = {
2006 { .attrs
= dme1737_pwm1_chmod_attr
},
2007 { .attrs
= dme1737_pwm2_chmod_attr
},
2008 { .attrs
= dme1737_pwm3_chmod_attr
},
2010 { .attrs
= dme1737_pwm5_chmod_attr
},
2011 { .attrs
= dme1737_pwm6_chmod_attr
},
2015 * Pwm[1-3] are read-writeable if the associated pwm is in manual mode and the
2016 * chip is not locked. Otherwise they are read-only.
2018 static struct attribute
*dme1737_pwm_chmod_attr
[] = {
2019 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
2020 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
2021 &sensor_dev_attr_pwm3
.dev_attr
.attr
,
2024 /* ---------------------------------------------------------------------
2025 * Super-IO functions
2026 * --------------------------------------------------------------------- */
2028 static inline void dme1737_sio_enter(int sio_cip
)
2030 outb(0x55, sio_cip
);
2033 static inline void dme1737_sio_exit(int sio_cip
)
2035 outb(0xaa, sio_cip
);
2038 static inline int dme1737_sio_inb(int sio_cip
, int reg
)
2041 return inb(sio_cip
+ 1);
2044 static inline void dme1737_sio_outb(int sio_cip
, int reg
, int val
)
2047 outb(val
, sio_cip
+ 1);
2050 /* ---------------------------------------------------------------------
2051 * Device initialization
2052 * --------------------------------------------------------------------- */
2054 static int dme1737_i2c_get_features(int, struct dme1737_data
*);
2056 static void dme1737_chmod_file(struct device
*dev
,
2057 struct attribute
*attr
, umode_t mode
)
2059 if (sysfs_chmod_file(&dev
->kobj
, attr
, mode
)) {
2060 dev_warn(dev
, "Failed to change permissions of %s.\n",
2065 static void dme1737_chmod_group(struct device
*dev
,
2066 const struct attribute_group
*group
,
2069 struct attribute
**attr
;
2071 for (attr
= group
->attrs
; *attr
; attr
++)
2072 dme1737_chmod_file(dev
, *attr
, mode
);
2075 static void dme1737_remove_files(struct device
*dev
)
2077 struct dme1737_data
*data
= dev_get_drvdata(dev
);
2080 for (ix
= 0; ix
< ARRAY_SIZE(dme1737_fan_group
); ix
++) {
2081 if (data
->has_features
& HAS_FAN(ix
)) {
2082 sysfs_remove_group(&dev
->kobj
,
2083 &dme1737_fan_group
[ix
]);
2087 for (ix
= 0; ix
< ARRAY_SIZE(dme1737_pwm_group
); ix
++) {
2088 if (data
->has_features
& HAS_PWM(ix
)) {
2089 sysfs_remove_group(&dev
->kobj
,
2090 &dme1737_pwm_group
[ix
]);
2091 if ((data
->has_features
& HAS_PWM_MIN
) && ix
< 3) {
2092 sysfs_remove_file(&dev
->kobj
,
2093 dme1737_auto_pwm_min_attr
[ix
]);
2098 if (data
->has_features
& HAS_TEMP_OFFSET
)
2099 sysfs_remove_group(&dev
->kobj
, &dme1737_temp_offset_group
);
2100 if (data
->has_features
& HAS_VID
)
2101 sysfs_remove_group(&dev
->kobj
, &dme1737_vid_group
);
2102 if (data
->has_features
& HAS_ZONE3
)
2103 sysfs_remove_group(&dev
->kobj
, &dme1737_zone3_group
);
2104 if (data
->has_features
& HAS_ZONE_HYST
)
2105 sysfs_remove_group(&dev
->kobj
, &dme1737_zone_hyst_group
);
2106 if (data
->has_features
& HAS_IN7
)
2107 sysfs_remove_group(&dev
->kobj
, &dme1737_in7_group
);
2108 sysfs_remove_group(&dev
->kobj
, &dme1737_group
);
2111 sysfs_remove_file(&dev
->kobj
, &dev_attr_name
.attr
);
2114 static int dme1737_create_files(struct device
*dev
)
2116 struct dme1737_data
*data
= dev_get_drvdata(dev
);
2119 /* Create a name attribute for ISA devices */
2120 if (!data
->client
) {
2121 err
= sysfs_create_file(&dev
->kobj
, &dev_attr_name
.attr
);
2126 /* Create standard sysfs attributes */
2127 err
= sysfs_create_group(&dev
->kobj
, &dme1737_group
);
2131 /* Create chip-dependent sysfs attributes */
2132 if (data
->has_features
& HAS_TEMP_OFFSET
) {
2133 err
= sysfs_create_group(&dev
->kobj
,
2134 &dme1737_temp_offset_group
);
2138 if (data
->has_features
& HAS_VID
) {
2139 err
= sysfs_create_group(&dev
->kobj
, &dme1737_vid_group
);
2143 if (data
->has_features
& HAS_ZONE3
) {
2144 err
= sysfs_create_group(&dev
->kobj
, &dme1737_zone3_group
);
2148 if (data
->has_features
& HAS_ZONE_HYST
) {
2149 err
= sysfs_create_group(&dev
->kobj
, &dme1737_zone_hyst_group
);
2153 if (data
->has_features
& HAS_IN7
) {
2154 err
= sysfs_create_group(&dev
->kobj
, &dme1737_in7_group
);
2159 /* Create fan sysfs attributes */
2160 for (ix
= 0; ix
< ARRAY_SIZE(dme1737_fan_group
); ix
++) {
2161 if (data
->has_features
& HAS_FAN(ix
)) {
2162 err
= sysfs_create_group(&dev
->kobj
,
2163 &dme1737_fan_group
[ix
]);
2169 /* Create PWM sysfs attributes */
2170 for (ix
= 0; ix
< ARRAY_SIZE(dme1737_pwm_group
); ix
++) {
2171 if (data
->has_features
& HAS_PWM(ix
)) {
2172 err
= sysfs_create_group(&dev
->kobj
,
2173 &dme1737_pwm_group
[ix
]);
2176 if ((data
->has_features
& HAS_PWM_MIN
) && (ix
< 3)) {
2177 err
= sysfs_create_file(&dev
->kobj
,
2178 dme1737_auto_pwm_min_attr
[ix
]);
2186 * Inform if the device is locked. Otherwise change the permissions of
2187 * selected attributes from read-only to read-writeable.
2189 if (data
->config
& 0x02) {
2191 "Device is locked. Some attributes will be read-only.\n");
2193 /* Change permissions of zone sysfs attributes */
2194 dme1737_chmod_group(dev
, &dme1737_zone_chmod_group
,
2197 /* Change permissions of chip-dependent sysfs attributes */
2198 if (data
->has_features
& HAS_TEMP_OFFSET
) {
2199 dme1737_chmod_group(dev
, &dme1737_temp_offset_group
,
2202 if (data
->has_features
& HAS_ZONE3
) {
2203 dme1737_chmod_group(dev
, &dme1737_zone3_chmod_group
,
2206 if (data
->has_features
& HAS_ZONE_HYST
) {
2207 dme1737_chmod_group(dev
, &dme1737_zone_hyst_group
,
2211 /* Change permissions of PWM sysfs attributes */
2212 for (ix
= 0; ix
< ARRAY_SIZE(dme1737_pwm_chmod_group
); ix
++) {
2213 if (data
->has_features
& HAS_PWM(ix
)) {
2214 dme1737_chmod_group(dev
,
2215 &dme1737_pwm_chmod_group
[ix
],
2217 if ((data
->has_features
& HAS_PWM_MIN
) &&
2219 dme1737_chmod_file(dev
,
2220 dme1737_auto_pwm_min_attr
[ix
],
2226 /* Change permissions of pwm[1-3] if in manual mode */
2227 for (ix
= 0; ix
< 3; ix
++) {
2228 if ((data
->has_features
& HAS_PWM(ix
)) &&
2229 (PWM_EN_FROM_REG(data
->pwm_config
[ix
]) == 1)) {
2230 dme1737_chmod_file(dev
,
2231 dme1737_pwm_chmod_attr
[ix
],
2240 dme1737_remove_files(dev
);
2245 static int dme1737_init_device(struct device
*dev
)
2247 struct dme1737_data
*data
= dev_get_drvdata(dev
);
2248 struct i2c_client
*client
= data
->client
;
2252 /* Point to the right nominal voltages array */
2253 data
->in_nominal
= IN_NOMINAL(data
->type
);
2255 data
->config
= dme1737_read(data
, DME1737_REG_CONFIG
);
2256 /* Inform if part is not monitoring/started */
2257 if (!(data
->config
& 0x01)) {
2260 "Device is not monitoring. Use the force_start load parameter to override.\n");
2264 /* Force monitoring */
2265 data
->config
|= 0x01;
2266 dme1737_write(data
, DME1737_REG_CONFIG
, data
->config
);
2268 /* Inform if part is not ready */
2269 if (!(data
->config
& 0x04)) {
2270 dev_err(dev
, "Device is not ready.\n");
2275 * Determine which optional fan and pwm features are enabled (only
2276 * valid for I2C devices)
2278 if (client
) { /* I2C chip */
2279 data
->config2
= dme1737_read(data
, DME1737_REG_CONFIG2
);
2280 /* Check if optional fan3 input is enabled */
2281 if (data
->config2
& 0x04)
2282 data
->has_features
|= HAS_FAN(2);
2285 * Fan4 and pwm3 are only available if the client's I2C address
2286 * is the default 0x2e. Otherwise the I/Os associated with
2287 * these functions are used for addr enable/select.
2289 if (client
->addr
== 0x2e)
2290 data
->has_features
|= HAS_FAN(3) | HAS_PWM(2);
2293 * Determine which of the optional fan[5-6] and pwm[5-6]
2294 * features are enabled. For this, we need to query the runtime
2295 * registers through the Super-IO LPC interface. Try both
2296 * config ports 0x2e and 0x4e.
2298 if (dme1737_i2c_get_features(0x2e, data
) &&
2299 dme1737_i2c_get_features(0x4e, data
)) {
2301 "Failed to query Super-IO for optional features.\n");
2305 /* Fan[1-2] and pwm[1-2] are present in all chips */
2306 data
->has_features
|= HAS_FAN(0) | HAS_FAN(1) | HAS_PWM(0) | HAS_PWM(1);
2308 /* Chip-dependent features */
2309 switch (data
->type
) {
2311 data
->has_features
|= HAS_TEMP_OFFSET
| HAS_VID
| HAS_ZONE3
|
2312 HAS_ZONE_HYST
| HAS_PWM_MIN
;
2315 data
->has_features
|= HAS_TEMP_OFFSET
| HAS_ZONE3
|
2316 HAS_ZONE_HYST
| HAS_PWM_MIN
| HAS_FAN(2) | HAS_PWM(2);
2319 data
->has_features
|= HAS_ZONE3
;
2322 data
->has_features
|= HAS_FAN(2) | HAS_PWM(2) | HAS_IN7
;
2329 "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n",
2330 (data
->has_features
& HAS_PWM(2)) ? "yes" : "no",
2331 (data
->has_features
& HAS_PWM(4)) ? "yes" : "no",
2332 (data
->has_features
& HAS_PWM(5)) ? "yes" : "no",
2333 (data
->has_features
& HAS_FAN(2)) ? "yes" : "no",
2334 (data
->has_features
& HAS_FAN(3)) ? "yes" : "no",
2335 (data
->has_features
& HAS_FAN(4)) ? "yes" : "no",
2336 (data
->has_features
& HAS_FAN(5)) ? "yes" : "no");
2338 reg
= dme1737_read(data
, DME1737_REG_TACH_PWM
);
2339 /* Inform if fan-to-pwm mapping differs from the default */
2340 if (client
&& reg
!= 0xa4) { /* I2C chip */
2342 "Non-standard fan to pwm mapping: fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, fan4->pwm%d. %s\n",
2343 (reg
& 0x03) + 1, ((reg
>> 2) & 0x03) + 1,
2344 ((reg
>> 4) & 0x03) + 1, ((reg
>> 6) & 0x03) + 1,
2346 } else if (!client
&& reg
!= 0x24) { /* ISA chip */
2348 "Non-standard fan to pwm mapping: fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. %s\n",
2349 (reg
& 0x03) + 1, ((reg
>> 2) & 0x03) + 1,
2350 ((reg
>> 4) & 0x03) + 1, DO_REPORT
);
2354 * Switch pwm[1-3] to manual mode if they are currently disabled and
2355 * set the duty-cycles to 0% (which is identical to the PWMs being
2358 if (!(data
->config
& 0x02)) {
2359 for (ix
= 0; ix
< 3; ix
++) {
2360 data
->pwm_config
[ix
] = dme1737_read(data
,
2361 DME1737_REG_PWM_CONFIG(ix
));
2362 if ((data
->has_features
& HAS_PWM(ix
)) &&
2363 (PWM_EN_FROM_REG(data
->pwm_config
[ix
]) == -1)) {
2365 "Switching pwm%d to manual mode.\n",
2367 data
->pwm_config
[ix
] = PWM_EN_TO_REG(1,
2368 data
->pwm_config
[ix
]);
2369 dme1737_write(data
, DME1737_REG_PWM(ix
), 0);
2371 DME1737_REG_PWM_CONFIG(ix
),
2372 data
->pwm_config
[ix
]);
2377 /* Initialize the default PWM auto channels zone (acz) assignments */
2378 data
->pwm_acz
[0] = 1; /* pwm1 -> zone1 */
2379 data
->pwm_acz
[1] = 2; /* pwm2 -> zone2 */
2380 data
->pwm_acz
[2] = 4; /* pwm3 -> zone3 */
2383 if (data
->has_features
& HAS_VID
)
2384 data
->vrm
= vid_which_vrm();
2389 /* ---------------------------------------------------------------------
2390 * I2C device detection and registration
2391 * --------------------------------------------------------------------- */
2393 static struct i2c_driver dme1737_i2c_driver
;
2395 static int dme1737_i2c_get_features(int sio_cip
, struct dme1737_data
*data
)
2400 dme1737_sio_enter(sio_cip
);
2404 * We currently know about two kinds of DME1737 and SCH5027.
2406 reg
= force_id
? force_id
: dme1737_sio_inb(sio_cip
, 0x20);
2407 if (!(reg
== DME1737_ID_1
|| reg
== DME1737_ID_2
||
2408 reg
== SCH5027_ID
)) {
2413 /* Select logical device A (runtime registers) */
2414 dme1737_sio_outb(sio_cip
, 0x07, 0x0a);
2416 /* Get the base address of the runtime registers */
2417 addr
= (dme1737_sio_inb(sio_cip
, 0x60) << 8) |
2418 dme1737_sio_inb(sio_cip
, 0x61);
2425 * Read the runtime registers to determine which optional features
2426 * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set
2427 * to '10' if the respective feature is enabled.
2429 if ((inb(addr
+ 0x43) & 0x0c) == 0x08) /* fan6 */
2430 data
->has_features
|= HAS_FAN(5);
2431 if ((inb(addr
+ 0x44) & 0x0c) == 0x08) /* pwm6 */
2432 data
->has_features
|= HAS_PWM(5);
2433 if ((inb(addr
+ 0x45) & 0x0c) == 0x08) /* fan5 */
2434 data
->has_features
|= HAS_FAN(4);
2435 if ((inb(addr
+ 0x46) & 0x0c) == 0x08) /* pwm5 */
2436 data
->has_features
|= HAS_PWM(4);
2439 dme1737_sio_exit(sio_cip
);
2444 /* Return 0 if detection is successful, -ENODEV otherwise */
2445 static int dme1737_i2c_detect(struct i2c_client
*client
,
2446 struct i2c_board_info
*info
)
2448 struct i2c_adapter
*adapter
= client
->adapter
;
2449 struct device
*dev
= &adapter
->dev
;
2450 u8 company
, verstep
= 0;
2453 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
2456 company
= i2c_smbus_read_byte_data(client
, DME1737_REG_COMPANY
);
2457 verstep
= i2c_smbus_read_byte_data(client
, DME1737_REG_VERSTEP
);
2459 if (company
== DME1737_COMPANY_SMSC
&&
2460 verstep
== SCH5027_VERSTEP
) {
2462 } else if (company
== DME1737_COMPANY_SMSC
&&
2463 (verstep
& DME1737_VERSTEP_MASK
) == DME1737_VERSTEP
) {
2469 dev_info(dev
, "Found a %s chip at 0x%02x (rev 0x%02x).\n",
2470 verstep
== SCH5027_VERSTEP
? "SCH5027" : "DME1737",
2471 client
->addr
, verstep
);
2472 strlcpy(info
->type
, name
, I2C_NAME_SIZE
);
2477 static int dme1737_i2c_probe(struct i2c_client
*client
,
2478 const struct i2c_device_id
*id
)
2480 struct dme1737_data
*data
;
2481 struct device
*dev
= &client
->dev
;
2484 data
= devm_kzalloc(dev
, sizeof(struct dme1737_data
), GFP_KERNEL
);
2488 i2c_set_clientdata(client
, data
);
2489 data
->type
= id
->driver_data
;
2490 data
->client
= client
;
2491 data
->name
= client
->name
;
2492 mutex_init(&data
->update_lock
);
2494 /* Initialize the DME1737 chip */
2495 err
= dme1737_init_device(dev
);
2497 dev_err(dev
, "Failed to initialize device.\n");
2501 /* Create sysfs files */
2502 err
= dme1737_create_files(dev
);
2504 dev_err(dev
, "Failed to create sysfs files.\n");
2508 /* Register device */
2509 data
->hwmon_dev
= hwmon_device_register(dev
);
2510 if (IS_ERR(data
->hwmon_dev
)) {
2511 dev_err(dev
, "Failed to register device.\n");
2512 err
= PTR_ERR(data
->hwmon_dev
);
2519 dme1737_remove_files(dev
);
2523 static int dme1737_i2c_remove(struct i2c_client
*client
)
2525 struct dme1737_data
*data
= i2c_get_clientdata(client
);
2527 hwmon_device_unregister(data
->hwmon_dev
);
2528 dme1737_remove_files(&client
->dev
);
2533 static const struct i2c_device_id dme1737_id
[] = {
2534 { "dme1737", dme1737
},
2535 { "sch5027", sch5027
},
2538 MODULE_DEVICE_TABLE(i2c
, dme1737_id
);
2540 static struct i2c_driver dme1737_i2c_driver
= {
2541 .class = I2C_CLASS_HWMON
,
2545 .probe
= dme1737_i2c_probe
,
2546 .remove
= dme1737_i2c_remove
,
2547 .id_table
= dme1737_id
,
2548 .detect
= dme1737_i2c_detect
,
2549 .address_list
= normal_i2c
,
2552 /* ---------------------------------------------------------------------
2553 * ISA device detection and registration
2554 * --------------------------------------------------------------------- */
2556 static int __init
dme1737_isa_detect(int sio_cip
, unsigned short *addr
)
2559 unsigned short base_addr
;
2561 dme1737_sio_enter(sio_cip
);
2565 * We currently know about SCH3112, SCH3114, SCH3116, and SCH5127
2567 reg
= force_id
? force_id
: dme1737_sio_inb(sio_cip
, 0x20);
2568 if (!(reg
== SCH3112_ID
|| reg
== SCH3114_ID
|| reg
== SCH3116_ID
||
2569 reg
== SCH5127_ID
)) {
2574 /* Select logical device A (runtime registers) */
2575 dme1737_sio_outb(sio_cip
, 0x07, 0x0a);
2577 /* Get the base address of the runtime registers */
2578 base_addr
= (dme1737_sio_inb(sio_cip
, 0x60) << 8) |
2579 dme1737_sio_inb(sio_cip
, 0x61);
2581 pr_err("Base address not set\n");
2587 * Access to the hwmon registers is through an index/data register
2588 * pair located at offset 0x70/0x71.
2590 *addr
= base_addr
+ 0x70;
2593 dme1737_sio_exit(sio_cip
);
2597 static int __init
dme1737_isa_device_add(unsigned short addr
)
2599 struct resource res
= {
2601 .end
= addr
+ DME1737_EXTENT
- 1,
2603 .flags
= IORESOURCE_IO
,
2607 err
= acpi_check_resource_conflict(&res
);
2611 pdev
= platform_device_alloc("dme1737", addr
);
2613 pr_err("Failed to allocate device\n");
2618 err
= platform_device_add_resources(pdev
, &res
, 1);
2620 pr_err("Failed to add device resource (err = %d)\n", err
);
2621 goto exit_device_put
;
2624 err
= platform_device_add(pdev
);
2626 pr_err("Failed to add device (err = %d)\n", err
);
2627 goto exit_device_put
;
2633 platform_device_put(pdev
);
2639 static int dme1737_isa_probe(struct platform_device
*pdev
)
2642 struct resource
*res
;
2643 struct dme1737_data
*data
;
2644 struct device
*dev
= &pdev
->dev
;
2647 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
2648 if (!devm_request_region(dev
, res
->start
, DME1737_EXTENT
, "dme1737")) {
2649 dev_err(dev
, "Failed to request region 0x%04x-0x%04x.\n",
2650 (unsigned short)res
->start
,
2651 (unsigned short)res
->start
+ DME1737_EXTENT
- 1);
2655 data
= devm_kzalloc(dev
, sizeof(struct dme1737_data
), GFP_KERNEL
);
2659 data
->addr
= res
->start
;
2660 platform_set_drvdata(pdev
, data
);
2662 /* Skip chip detection if module is loaded with force_id parameter */
2667 data
->type
= sch311x
;
2670 data
->type
= sch5127
;
2673 company
= dme1737_read(data
, DME1737_REG_COMPANY
);
2674 device
= dme1737_read(data
, DME1737_REG_DEVICE
);
2676 if ((company
== DME1737_COMPANY_SMSC
) &&
2677 (device
== SCH311X_DEVICE
)) {
2678 data
->type
= sch311x
;
2679 } else if ((company
== DME1737_COMPANY_SMSC
) &&
2680 (device
== SCH5127_DEVICE
)) {
2681 data
->type
= sch5127
;
2687 if (data
->type
== sch5127
)
2688 data
->name
= "sch5127";
2690 data
->name
= "sch311x";
2692 /* Initialize the mutex */
2693 mutex_init(&data
->update_lock
);
2695 dev_info(dev
, "Found a %s chip at 0x%04x\n",
2696 data
->type
== sch5127
? "SCH5127" : "SCH311x", data
->addr
);
2698 /* Initialize the chip */
2699 err
= dme1737_init_device(dev
);
2701 dev_err(dev
, "Failed to initialize device.\n");
2705 /* Create sysfs files */
2706 err
= dme1737_create_files(dev
);
2708 dev_err(dev
, "Failed to create sysfs files.\n");
2712 /* Register device */
2713 data
->hwmon_dev
= hwmon_device_register(dev
);
2714 if (IS_ERR(data
->hwmon_dev
)) {
2715 dev_err(dev
, "Failed to register device.\n");
2716 err
= PTR_ERR(data
->hwmon_dev
);
2717 goto exit_remove_files
;
2723 dme1737_remove_files(dev
);
2727 static int dme1737_isa_remove(struct platform_device
*pdev
)
2729 struct dme1737_data
*data
= platform_get_drvdata(pdev
);
2731 hwmon_device_unregister(data
->hwmon_dev
);
2732 dme1737_remove_files(&pdev
->dev
);
2737 static struct platform_driver dme1737_isa_driver
= {
2741 .probe
= dme1737_isa_probe
,
2742 .remove
= dme1737_isa_remove
,
2745 /* ---------------------------------------------------------------------
2746 * Module initialization and cleanup
2747 * --------------------------------------------------------------------- */
2749 static int __init
dme1737_init(void)
2752 unsigned short addr
;
2754 err
= i2c_add_driver(&dme1737_i2c_driver
);
2758 if (dme1737_isa_detect(0x2e, &addr
) &&
2759 dme1737_isa_detect(0x4e, &addr
) &&
2761 (dme1737_isa_detect(0x162e, &addr
) &&
2762 dme1737_isa_detect(0x164e, &addr
)))) {
2763 /* Return 0 if we didn't find an ISA device */
2767 err
= platform_driver_register(&dme1737_isa_driver
);
2769 goto exit_del_i2c_driver
;
2771 /* Sets global pdev as a side effect */
2772 err
= dme1737_isa_device_add(addr
);
2774 goto exit_del_isa_driver
;
2778 exit_del_isa_driver
:
2779 platform_driver_unregister(&dme1737_isa_driver
);
2780 exit_del_i2c_driver
:
2781 i2c_del_driver(&dme1737_i2c_driver
);
2786 static void __exit
dme1737_exit(void)
2789 platform_device_unregister(pdev
);
2790 platform_driver_unregister(&dme1737_isa_driver
);
2793 i2c_del_driver(&dme1737_i2c_driver
);
2796 MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");
2797 MODULE_DESCRIPTION("DME1737 sensors");
2798 MODULE_LICENSE("GPL");
2800 module_init(dme1737_init
);
2801 module_exit(dme1737_exit
);