xref: /linux/drivers/hwmon/w83792d.c (revision 179c4fdb565dd2157e5dfe89318b74868e3b523d)
15563e27dSR.Marek@sh.cvut.cz /*
25563e27dSR.Marek@sh.cvut.cz     w83792d.c - Part of lm_sensors, Linux kernel modules for hardware
35563e27dSR.Marek@sh.cvut.cz                 monitoring
45563e27dSR.Marek@sh.cvut.cz     Copyright (C) 2004, 2005 Winbond Electronics Corp.
55563e27dSR.Marek@sh.cvut.cz                         Chunhao Huang <DZShen@Winbond.com.tw>,
67188cc66SJean Delvare                         Rudolf Marek <r.marek@assembler.cz>
75563e27dSR.Marek@sh.cvut.cz 
85563e27dSR.Marek@sh.cvut.cz     This program is free software; you can redistribute it and/or modify
95563e27dSR.Marek@sh.cvut.cz     it under the terms of the GNU General Public License as published by
105563e27dSR.Marek@sh.cvut.cz     the Free Software Foundation; either version 2 of the License, or
115563e27dSR.Marek@sh.cvut.cz     (at your option) any later version.
125563e27dSR.Marek@sh.cvut.cz 
135563e27dSR.Marek@sh.cvut.cz     This program is distributed in the hope that it will be useful,
145563e27dSR.Marek@sh.cvut.cz     but WITHOUT ANY WARRANTY; without even the implied warranty of
155563e27dSR.Marek@sh.cvut.cz     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165563e27dSR.Marek@sh.cvut.cz     GNU General Public License for more details.
175563e27dSR.Marek@sh.cvut.cz 
185563e27dSR.Marek@sh.cvut.cz     You should have received a copy of the GNU General Public License
195563e27dSR.Marek@sh.cvut.cz     along with this program; if not, write to the Free Software
205563e27dSR.Marek@sh.cvut.cz     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
215563e27dSR.Marek@sh.cvut.cz 
225563e27dSR.Marek@sh.cvut.cz     Note:
235563e27dSR.Marek@sh.cvut.cz     1. This driver is only for 2.6 kernel, 2.4 kernel need a different driver.
245563e27dSR.Marek@sh.cvut.cz     2. This driver is only for Winbond W83792D C version device, there
255563e27dSR.Marek@sh.cvut.cz        are also some motherboards with B version W83792D device. The
265563e27dSR.Marek@sh.cvut.cz        calculation method to in6-in7(measured value, limits) is a little
275563e27dSR.Marek@sh.cvut.cz        different between C and B version. C or B version can be identified
285563e27dSR.Marek@sh.cvut.cz        by CR[0x49h].
295563e27dSR.Marek@sh.cvut.cz */
305563e27dSR.Marek@sh.cvut.cz 
315563e27dSR.Marek@sh.cvut.cz /*
325563e27dSR.Marek@sh.cvut.cz     Supports following chips:
335563e27dSR.Marek@sh.cvut.cz 
345563e27dSR.Marek@sh.cvut.cz     Chip	#vin	#fanin	#pwm	#temp	wchipid	vendid	i2c	ISA
355563e27dSR.Marek@sh.cvut.cz     w83792d	9	7	7	3	0x7a	0x5ca3	yes	no
365563e27dSR.Marek@sh.cvut.cz */
375563e27dSR.Marek@sh.cvut.cz 
385563e27dSR.Marek@sh.cvut.cz #include <linux/module.h>
395563e27dSR.Marek@sh.cvut.cz #include <linux/init.h>
405563e27dSR.Marek@sh.cvut.cz #include <linux/slab.h>
415563e27dSR.Marek@sh.cvut.cz #include <linux/i2c.h>
42ce785ab4SR.Marek@sh.cvut.cz #include <linux/hwmon.h>
435563e27dSR.Marek@sh.cvut.cz #include <linux/hwmon-sysfs.h>
44ce785ab4SR.Marek@sh.cvut.cz #include <linux/err.h>
459a61bf63SIngo Molnar #include <linux/mutex.h>
46f52f79daSRudolf Marek #include <linux/sysfs.h>
475563e27dSR.Marek@sh.cvut.cz 
485563e27dSR.Marek@sh.cvut.cz /* Addresses to scan */
4925e9c86dSMark M. Hoffman static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
5025e9c86dSMark M. Hoffman 						I2C_CLIENT_END };
515563e27dSR.Marek@sh.cvut.cz 
525563e27dSR.Marek@sh.cvut.cz /* Insmod parameters */
533aed198cSJean Delvare 
543aed198cSJean Delvare static unsigned short force_subclients[4];
553aed198cSJean Delvare module_param_array(force_subclients, short, NULL, 0);
563aed198cSJean Delvare MODULE_PARM_DESC(force_subclients, "List of subclient addresses: "
575563e27dSR.Marek@sh.cvut.cz 			"{bus, clientaddr, subclientaddr1, subclientaddr2}");
585563e27dSR.Marek@sh.cvut.cz 
595563e27dSR.Marek@sh.cvut.cz static int init;
605563e27dSR.Marek@sh.cvut.cz module_param(init, bool, 0);
615563e27dSR.Marek@sh.cvut.cz MODULE_PARM_DESC(init, "Set to one to force chip initialization");
625563e27dSR.Marek@sh.cvut.cz 
635563e27dSR.Marek@sh.cvut.cz /* The W83792D registers */
645563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_IN[9] = {
655563e27dSR.Marek@sh.cvut.cz 	0x20,	/* Vcore A in DataSheet */
665563e27dSR.Marek@sh.cvut.cz 	0x21,	/* Vcore B in DataSheet */
675563e27dSR.Marek@sh.cvut.cz 	0x22,	/* VIN0 in DataSheet */
685563e27dSR.Marek@sh.cvut.cz 	0x23,	/* VIN1 in DataSheet */
695563e27dSR.Marek@sh.cvut.cz 	0x24,	/* VIN2 in DataSheet */
705563e27dSR.Marek@sh.cvut.cz 	0x25,	/* VIN3 in DataSheet */
715563e27dSR.Marek@sh.cvut.cz 	0x26,	/* 5VCC in DataSheet */
725563e27dSR.Marek@sh.cvut.cz 	0xB0,	/* 5VSB in DataSheet */
735563e27dSR.Marek@sh.cvut.cz 	0xB1	/* VBAT in DataSheet */
745563e27dSR.Marek@sh.cvut.cz };
755563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_LOW_BITS1 0x3E  /* Low Bits I in DataSheet */
765563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_LOW_BITS2 0x3F  /* Low Bits II in DataSheet */
775563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_IN_MAX[9] = {
785563e27dSR.Marek@sh.cvut.cz 	0x2B,	/* Vcore A High Limit in DataSheet */
795563e27dSR.Marek@sh.cvut.cz 	0x2D,	/* Vcore B High Limit in DataSheet */
805563e27dSR.Marek@sh.cvut.cz 	0x2F,	/* VIN0 High Limit in DataSheet */
815563e27dSR.Marek@sh.cvut.cz 	0x31,	/* VIN1 High Limit in DataSheet */
825563e27dSR.Marek@sh.cvut.cz 	0x33,	/* VIN2 High Limit in DataSheet */
835563e27dSR.Marek@sh.cvut.cz 	0x35,	/* VIN3 High Limit in DataSheet */
845563e27dSR.Marek@sh.cvut.cz 	0x37,	/* 5VCC High Limit in DataSheet */
855563e27dSR.Marek@sh.cvut.cz 	0xB4,	/* 5VSB High Limit in DataSheet */
865563e27dSR.Marek@sh.cvut.cz 	0xB6	/* VBAT High Limit in DataSheet */
875563e27dSR.Marek@sh.cvut.cz };
885563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_IN_MIN[9] = {
895563e27dSR.Marek@sh.cvut.cz 	0x2C,	/* Vcore A Low Limit in DataSheet */
905563e27dSR.Marek@sh.cvut.cz 	0x2E,	/* Vcore B Low Limit in DataSheet */
915563e27dSR.Marek@sh.cvut.cz 	0x30,	/* VIN0 Low Limit in DataSheet */
925563e27dSR.Marek@sh.cvut.cz 	0x32,	/* VIN1 Low Limit in DataSheet */
935563e27dSR.Marek@sh.cvut.cz 	0x34,	/* VIN2 Low Limit in DataSheet */
945563e27dSR.Marek@sh.cvut.cz 	0x36,	/* VIN3 Low Limit in DataSheet */
955563e27dSR.Marek@sh.cvut.cz 	0x38,	/* 5VCC Low Limit in DataSheet */
965563e27dSR.Marek@sh.cvut.cz 	0xB5,	/* 5VSB Low Limit in DataSheet */
975563e27dSR.Marek@sh.cvut.cz 	0xB7	/* VBAT Low Limit in DataSheet */
985563e27dSR.Marek@sh.cvut.cz };
995563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_FAN[7] = {
1005563e27dSR.Marek@sh.cvut.cz 	0x28,	/* FAN 1 Count in DataSheet */
1015563e27dSR.Marek@sh.cvut.cz 	0x29,	/* FAN 2 Count in DataSheet */
1025563e27dSR.Marek@sh.cvut.cz 	0x2A,	/* FAN 3 Count in DataSheet */
1035563e27dSR.Marek@sh.cvut.cz 	0xB8,	/* FAN 4 Count in DataSheet */
1045563e27dSR.Marek@sh.cvut.cz 	0xB9,	/* FAN 5 Count in DataSheet */
1055563e27dSR.Marek@sh.cvut.cz 	0xBA,	/* FAN 6 Count in DataSheet */
1065563e27dSR.Marek@sh.cvut.cz 	0xBE	/* FAN 7 Count in DataSheet */
1075563e27dSR.Marek@sh.cvut.cz };
1085563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_FAN_MIN[7] = {
1095563e27dSR.Marek@sh.cvut.cz 	0x3B,	/* FAN 1 Count Low Limit in DataSheet */
1105563e27dSR.Marek@sh.cvut.cz 	0x3C,	/* FAN 2 Count Low Limit in DataSheet */
1115563e27dSR.Marek@sh.cvut.cz 	0x3D,	/* FAN 3 Count Low Limit in DataSheet */
1125563e27dSR.Marek@sh.cvut.cz 	0xBB,	/* FAN 4 Count Low Limit in DataSheet */
1135563e27dSR.Marek@sh.cvut.cz 	0xBC,	/* FAN 5 Count Low Limit in DataSheet */
1145563e27dSR.Marek@sh.cvut.cz 	0xBD,	/* FAN 6 Count Low Limit in DataSheet */
1155563e27dSR.Marek@sh.cvut.cz 	0xBF	/* FAN 7 Count Low Limit in DataSheet */
1165563e27dSR.Marek@sh.cvut.cz };
1175563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_FAN_CFG 0x84	/* FAN Configuration in DataSheet */
1185563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_FAN_DIV[4] = {
1195563e27dSR.Marek@sh.cvut.cz 	0x47,	/* contains FAN2 and FAN1 Divisor */
1205563e27dSR.Marek@sh.cvut.cz 	0x5B,	/* contains FAN4 and FAN3 Divisor */
1215563e27dSR.Marek@sh.cvut.cz 	0x5C,	/* contains FAN6 and FAN5 Divisor */
1225563e27dSR.Marek@sh.cvut.cz 	0x9E	/* contains FAN7 Divisor. */
1235563e27dSR.Marek@sh.cvut.cz };
1245563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_PWM[7] = {
1255563e27dSR.Marek@sh.cvut.cz 	0x81,	/* FAN 1 Duty Cycle, be used to control */
1265563e27dSR.Marek@sh.cvut.cz 	0x83,	/* FAN 2 Duty Cycle, be used to control */
1275563e27dSR.Marek@sh.cvut.cz 	0x94,	/* FAN 3 Duty Cycle, be used to control */
1285563e27dSR.Marek@sh.cvut.cz 	0xA3,	/* FAN 4 Duty Cycle, be used to control */
1295563e27dSR.Marek@sh.cvut.cz 	0xA4,	/* FAN 5 Duty Cycle, be used to control */
1305563e27dSR.Marek@sh.cvut.cz 	0xA5,	/* FAN 6 Duty Cycle, be used to control */
1315563e27dSR.Marek@sh.cvut.cz 	0xA6	/* FAN 7 Duty Cycle, be used to control */
1325563e27dSR.Marek@sh.cvut.cz };
1335563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_BANK		0x4E
1345563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_TEMP2_CONFIG	0xC2
1355563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_TEMP3_CONFIG	0xCA
1365563e27dSR.Marek@sh.cvut.cz 
1375563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_TEMP1[3] = {
1385563e27dSR.Marek@sh.cvut.cz 	0x27,	/* TEMP 1 in DataSheet */
1395563e27dSR.Marek@sh.cvut.cz 	0x39,	/* TEMP 1 Over in DataSheet */
1405563e27dSR.Marek@sh.cvut.cz 	0x3A,	/* TEMP 1 Hyst in DataSheet */
1415563e27dSR.Marek@sh.cvut.cz };
1425563e27dSR.Marek@sh.cvut.cz 
1435563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_TEMP_ADD[2][6] = {
1445563e27dSR.Marek@sh.cvut.cz 	{ 0xC0,		/* TEMP 2 in DataSheet */
1455563e27dSR.Marek@sh.cvut.cz 	  0xC1,		/* TEMP 2(0.5 deg) in DataSheet */
1465563e27dSR.Marek@sh.cvut.cz 	  0xC5,		/* TEMP 2 Over High part in DataSheet */
1475563e27dSR.Marek@sh.cvut.cz 	  0xC6,		/* TEMP 2 Over Low part in DataSheet */
1485563e27dSR.Marek@sh.cvut.cz 	  0xC3,		/* TEMP 2 Thyst High part in DataSheet */
1495563e27dSR.Marek@sh.cvut.cz 	  0xC4 },	/* TEMP 2 Thyst Low part in DataSheet */
1505563e27dSR.Marek@sh.cvut.cz 	{ 0xC8,		/* TEMP 3 in DataSheet */
1515563e27dSR.Marek@sh.cvut.cz 	  0xC9,		/* TEMP 3(0.5 deg) in DataSheet */
1525563e27dSR.Marek@sh.cvut.cz 	  0xCD,		/* TEMP 3 Over High part in DataSheet */
1535563e27dSR.Marek@sh.cvut.cz 	  0xCE,		/* TEMP 3 Over Low part in DataSheet */
1545563e27dSR.Marek@sh.cvut.cz 	  0xCB,		/* TEMP 3 Thyst High part in DataSheet */
1555563e27dSR.Marek@sh.cvut.cz 	  0xCC }	/* TEMP 3 Thyst Low part in DataSheet */
1565563e27dSR.Marek@sh.cvut.cz };
1575563e27dSR.Marek@sh.cvut.cz 
1585563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_THERMAL[3] = {
1595563e27dSR.Marek@sh.cvut.cz 	0x85,	/* SmartFanI: Fan1 target value */
1605563e27dSR.Marek@sh.cvut.cz 	0x86,	/* SmartFanI: Fan2 target value */
1615563e27dSR.Marek@sh.cvut.cz 	0x96	/* SmartFanI: Fan3 target value */
1625563e27dSR.Marek@sh.cvut.cz };
1635563e27dSR.Marek@sh.cvut.cz 
1645563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_TOLERANCE[3] = {
1655563e27dSR.Marek@sh.cvut.cz 	0x87,	/* (bit3-0)SmartFan Fan1 tolerance */
1665563e27dSR.Marek@sh.cvut.cz 	0x87,	/* (bit7-4)SmartFan Fan2 tolerance */
1675563e27dSR.Marek@sh.cvut.cz 	0x97	/* (bit3-0)SmartFan Fan3 tolerance */
1685563e27dSR.Marek@sh.cvut.cz };
1695563e27dSR.Marek@sh.cvut.cz 
1705563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_POINTS[3][4] = {
1715563e27dSR.Marek@sh.cvut.cz 	{ 0x85,		/* SmartFanII: Fan1 temp point 1 */
1725563e27dSR.Marek@sh.cvut.cz 	  0xE3,		/* SmartFanII: Fan1 temp point 2 */
1735563e27dSR.Marek@sh.cvut.cz 	  0xE4,		/* SmartFanII: Fan1 temp point 3 */
1745563e27dSR.Marek@sh.cvut.cz 	  0xE5 },	/* SmartFanII: Fan1 temp point 4 */
1755563e27dSR.Marek@sh.cvut.cz 	{ 0x86,		/* SmartFanII: Fan2 temp point 1 */
1765563e27dSR.Marek@sh.cvut.cz 	  0xE6,		/* SmartFanII: Fan2 temp point 2 */
1775563e27dSR.Marek@sh.cvut.cz 	  0xE7,		/* SmartFanII: Fan2 temp point 3 */
1785563e27dSR.Marek@sh.cvut.cz 	  0xE8 },	/* SmartFanII: Fan2 temp point 4 */
1795563e27dSR.Marek@sh.cvut.cz 	{ 0x96,		/* SmartFanII: Fan3 temp point 1 */
1805563e27dSR.Marek@sh.cvut.cz 	  0xE9,		/* SmartFanII: Fan3 temp point 2 */
1815563e27dSR.Marek@sh.cvut.cz 	  0xEA,		/* SmartFanII: Fan3 temp point 3 */
1825563e27dSR.Marek@sh.cvut.cz 	  0xEB }	/* SmartFanII: Fan3 temp point 4 */
1835563e27dSR.Marek@sh.cvut.cz };
1845563e27dSR.Marek@sh.cvut.cz 
1855563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_LEVELS[3][4] = {
1865563e27dSR.Marek@sh.cvut.cz 	{ 0x88,		/* (bit3-0) SmartFanII: Fan1 Non-Stop */
1875563e27dSR.Marek@sh.cvut.cz 	  0x88,		/* (bit7-4) SmartFanII: Fan1 Level 1 */
1885563e27dSR.Marek@sh.cvut.cz 	  0xE0,		/* (bit7-4) SmartFanII: Fan1 Level 2 */
1895563e27dSR.Marek@sh.cvut.cz 	  0xE0 },	/* (bit3-0) SmartFanII: Fan1 Level 3 */
1905563e27dSR.Marek@sh.cvut.cz 	{ 0x89,		/* (bit3-0) SmartFanII: Fan2 Non-Stop */
1915563e27dSR.Marek@sh.cvut.cz 	  0x89,		/* (bit7-4) SmartFanII: Fan2 Level 1 */
1925563e27dSR.Marek@sh.cvut.cz 	  0xE1,		/* (bit7-4) SmartFanII: Fan2 Level 2 */
1935563e27dSR.Marek@sh.cvut.cz 	  0xE1 },	/* (bit3-0) SmartFanII: Fan2 Level 3 */
1945563e27dSR.Marek@sh.cvut.cz 	{ 0x98,		/* (bit3-0) SmartFanII: Fan3 Non-Stop */
1955563e27dSR.Marek@sh.cvut.cz 	  0x98,		/* (bit7-4) SmartFanII: Fan3 Level 1 */
1965563e27dSR.Marek@sh.cvut.cz 	  0xE2,		/* (bit7-4) SmartFanII: Fan3 Level 2 */
1975563e27dSR.Marek@sh.cvut.cz 	  0xE2 }	/* (bit3-0) SmartFanII: Fan3 Level 3 */
1985563e27dSR.Marek@sh.cvut.cz };
1995563e27dSR.Marek@sh.cvut.cz 
20096320519SJean Delvare #define W83792D_REG_GPIO_EN		0x1A
2015563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CONFIG		0x40
2025563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_VID_FANDIV		0x47
2035563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CHIPID		0x49
2045563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_WCHIPID		0x58
2055563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CHIPMAN		0x4F
2065563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_PIN			0x4B
2075563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_I2C_SUBADDR		0x4A
2085563e27dSR.Marek@sh.cvut.cz 
2095563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_ALARM1 0xA9		/* realtime status register1 */
2105563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_ALARM2 0xAA		/* realtime status register2 */
2115563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_ALARM3 0xAB		/* realtime status register3 */
2125563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CHASSIS 0x42	/* Bit 5: Case Open status bit */
2135563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CHASSIS_CLR 0x44	/* Bit 7: Case Open CLR_CHS/Reset bit */
2145563e27dSR.Marek@sh.cvut.cz 
2155563e27dSR.Marek@sh.cvut.cz /* control in0/in1 's limit modifiability */
2165563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_VID_IN_B		0x17
2175563e27dSR.Marek@sh.cvut.cz 
2185563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_VBAT		0x5D
2195563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_I2C_ADDR		0x48
2205563e27dSR.Marek@sh.cvut.cz 
2215563e27dSR.Marek@sh.cvut.cz /* Conversions. Rounding and limit checking is only done on the TO_REG
2225563e27dSR.Marek@sh.cvut.cz    variants. Note that you should be a bit careful with which arguments
2235563e27dSR.Marek@sh.cvut.cz    these macros are called: arguments may be evaluated more than once.
2245563e27dSR.Marek@sh.cvut.cz    Fixing this is just not worth it. */
2255563e27dSR.Marek@sh.cvut.cz #define IN_FROM_REG(nr,val) (((nr)<=1)?(val*2): \
2265563e27dSR.Marek@sh.cvut.cz 				((((nr)==6)||((nr)==7))?(val*6):(val*4)))
2275563e27dSR.Marek@sh.cvut.cz #define IN_TO_REG(nr,val) (((nr)<=1)?(val/2): \
2285563e27dSR.Marek@sh.cvut.cz 				((((nr)==6)||((nr)==7))?(val/6):(val/4)))
2295563e27dSR.Marek@sh.cvut.cz 
2305563e27dSR.Marek@sh.cvut.cz static inline u8
2315563e27dSR.Marek@sh.cvut.cz FAN_TO_REG(long rpm, int div)
2325563e27dSR.Marek@sh.cvut.cz {
2335563e27dSR.Marek@sh.cvut.cz 	if (rpm == 0)
2345563e27dSR.Marek@sh.cvut.cz 		return 255;
2355563e27dSR.Marek@sh.cvut.cz 	rpm = SENSORS_LIMIT(rpm, 1, 1000000);
2365563e27dSR.Marek@sh.cvut.cz 	return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
2375563e27dSR.Marek@sh.cvut.cz }
2385563e27dSR.Marek@sh.cvut.cz 
2395563e27dSR.Marek@sh.cvut.cz #define FAN_FROM_REG(val,div)	((val) == 0   ? -1 : \
2405563e27dSR.Marek@sh.cvut.cz 				((val) == 255 ? 0 : \
2415563e27dSR.Marek@sh.cvut.cz 						1350000 / ((val) * (div))))
2425563e27dSR.Marek@sh.cvut.cz 
2435563e27dSR.Marek@sh.cvut.cz /* for temp1 */
2445563e27dSR.Marek@sh.cvut.cz #define TEMP1_TO_REG(val)	(SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \
2455563e27dSR.Marek@sh.cvut.cz 					: (val)) / 1000, 0, 0xff))
2465563e27dSR.Marek@sh.cvut.cz #define TEMP1_FROM_REG(val)	(((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
24725985edcSLucas De Marchi /* for temp2 and temp3, because they need additional resolution */
2485563e27dSR.Marek@sh.cvut.cz #define TEMP_ADD_FROM_REG(val1, val2) \
2495563e27dSR.Marek@sh.cvut.cz 	((((val1) & 0x80 ? (val1)-0x100 \
2505563e27dSR.Marek@sh.cvut.cz 		: (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0))
2515563e27dSR.Marek@sh.cvut.cz #define TEMP_ADD_TO_REG_HIGH(val) \
2525563e27dSR.Marek@sh.cvut.cz 	(SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \
2535563e27dSR.Marek@sh.cvut.cz 			: (val)) / 1000, 0, 0xff))
2545563e27dSR.Marek@sh.cvut.cz #define TEMP_ADD_TO_REG_LOW(val)	((val%1000) ? 0x80 : 0x00)
2555563e27dSR.Marek@sh.cvut.cz 
2565563e27dSR.Marek@sh.cvut.cz #define DIV_FROM_REG(val)		(1 << (val))
2575563e27dSR.Marek@sh.cvut.cz 
2585563e27dSR.Marek@sh.cvut.cz static inline u8
2595563e27dSR.Marek@sh.cvut.cz DIV_TO_REG(long val)
2605563e27dSR.Marek@sh.cvut.cz {
2615563e27dSR.Marek@sh.cvut.cz 	int i;
2625563e27dSR.Marek@sh.cvut.cz 	val = SENSORS_LIMIT(val, 1, 128) >> 1;
26396320519SJean Delvare 	for (i = 0; i < 7; i++) {
2645563e27dSR.Marek@sh.cvut.cz 		if (val == 0)
2655563e27dSR.Marek@sh.cvut.cz 			break;
2665563e27dSR.Marek@sh.cvut.cz 		val >>= 1;
2675563e27dSR.Marek@sh.cvut.cz 	}
2685563e27dSR.Marek@sh.cvut.cz 	return ((u8) i);
2695563e27dSR.Marek@sh.cvut.cz }
2705563e27dSR.Marek@sh.cvut.cz 
2715563e27dSR.Marek@sh.cvut.cz struct w83792d_data {
2721beeffe4STony Jones 	struct device *hwmon_dev;
2735563e27dSR.Marek@sh.cvut.cz 
2749a61bf63SIngo Molnar 	struct mutex update_lock;
2755563e27dSR.Marek@sh.cvut.cz 	char valid;		/* !=0 if following fields are valid */
2765563e27dSR.Marek@sh.cvut.cz 	unsigned long last_updated;	/* In jiffies */
2775563e27dSR.Marek@sh.cvut.cz 
2785563e27dSR.Marek@sh.cvut.cz 	/* array of 2 pointers to subclients */
2795563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *lm75[2];
2805563e27dSR.Marek@sh.cvut.cz 
2815563e27dSR.Marek@sh.cvut.cz 	u8 in[9];		/* Register value */
2825563e27dSR.Marek@sh.cvut.cz 	u8 in_max[9];		/* Register value */
2835563e27dSR.Marek@sh.cvut.cz 	u8 in_min[9];		/* Register value */
28499d85560SJean Delvare 	u16 low_bits;		/* Additional resolution to voltage in6-0 */
2855563e27dSR.Marek@sh.cvut.cz 	u8 fan[7];		/* Register value */
2865563e27dSR.Marek@sh.cvut.cz 	u8 fan_min[7];		/* Register value */
2875563e27dSR.Marek@sh.cvut.cz 	u8 temp1[3];		/* current, over, thyst */
2885563e27dSR.Marek@sh.cvut.cz 	u8 temp_add[2][6];	/* Register value */
2895563e27dSR.Marek@sh.cvut.cz 	u8 fan_div[7];		/* Register encoding, shifted right */
2905563e27dSR.Marek@sh.cvut.cz 	u8 pwm[7];		/* We only consider the first 3 set of pwm,
2915563e27dSR.Marek@sh.cvut.cz 				   although 792 chip has 7 set of pwm. */
2925563e27dSR.Marek@sh.cvut.cz 	u8 pwmenable[3];
2935563e27dSR.Marek@sh.cvut.cz 	u32 alarms;		/* realtime status register encoding,combined */
2945563e27dSR.Marek@sh.cvut.cz 	u8 chassis;		/* Chassis status */
2955563e27dSR.Marek@sh.cvut.cz 	u8 chassis_clear;	/* CLR_CHS, clear chassis intrusion detection */
2965563e27dSR.Marek@sh.cvut.cz 	u8 thermal_cruise[3];	/* Smart FanI: Fan1,2,3 target value */
2975563e27dSR.Marek@sh.cvut.cz 	u8 tolerance[3];	/* Fan1,2,3 tolerance(Smart Fan I/II) */
2985563e27dSR.Marek@sh.cvut.cz 	u8 sf2_points[3][4];	/* Smart FanII: Fan1,2,3 temperature points */
2995563e27dSR.Marek@sh.cvut.cz 	u8 sf2_levels[3][4];	/* Smart FanII: Fan1,2,3 duty cycle levels */
3005563e27dSR.Marek@sh.cvut.cz };
3015563e27dSR.Marek@sh.cvut.cz 
30231d5d275SJean Delvare static int w83792d_probe(struct i2c_client *client,
30331d5d275SJean Delvare 			 const struct i2c_device_id *id);
304310ec792SJean Delvare static int w83792d_detect(struct i2c_client *client,
30531d5d275SJean Delvare 			  struct i2c_board_info *info);
30631d5d275SJean Delvare static int w83792d_remove(struct i2c_client *client);
3075563e27dSR.Marek@sh.cvut.cz static struct w83792d_data *w83792d_update_device(struct device *dev);
3085563e27dSR.Marek@sh.cvut.cz 
3095563e27dSR.Marek@sh.cvut.cz #ifdef DEBUG
3105563e27dSR.Marek@sh.cvut.cz static void w83792d_print_debug(struct w83792d_data *data, struct device *dev);
3115563e27dSR.Marek@sh.cvut.cz #endif
3125563e27dSR.Marek@sh.cvut.cz 
3135563e27dSR.Marek@sh.cvut.cz static void w83792d_init_client(struct i2c_client *client);
3145563e27dSR.Marek@sh.cvut.cz 
31531d5d275SJean Delvare static const struct i2c_device_id w83792d_id[] = {
3161f86df49SJean Delvare 	{ "w83792d", 0 },
31731d5d275SJean Delvare 	{ }
31831d5d275SJean Delvare };
31931d5d275SJean Delvare MODULE_DEVICE_TABLE(i2c, w83792d_id);
32031d5d275SJean Delvare 
3215563e27dSR.Marek@sh.cvut.cz static struct i2c_driver w83792d_driver = {
32231d5d275SJean Delvare 	.class		= I2C_CLASS_HWMON,
323cdaf7934SLaurent Riffard 	.driver = {
3245563e27dSR.Marek@sh.cvut.cz 		.name = "w83792d",
325cdaf7934SLaurent Riffard 	},
32631d5d275SJean Delvare 	.probe		= w83792d_probe,
32731d5d275SJean Delvare 	.remove		= w83792d_remove,
32831d5d275SJean Delvare 	.id_table	= w83792d_id,
32931d5d275SJean Delvare 	.detect		= w83792d_detect,
330c3813d6aSJean Delvare 	.address_list	= normal_i2c,
3315563e27dSR.Marek@sh.cvut.cz };
3325563e27dSR.Marek@sh.cvut.cz 
33399d85560SJean Delvare static inline long in_count_from_reg(int nr, struct w83792d_data *data)
3345563e27dSR.Marek@sh.cvut.cz {
33599d85560SJean Delvare 	/* in7 and in8 do not have low bits, but the formula still works */
33699d85560SJean Delvare 	return ((data->in[nr] << 2) | ((data->low_bits >> (2 * nr)) & 0x03));
3375563e27dSR.Marek@sh.cvut.cz }
3385563e27dSR.Marek@sh.cvut.cz 
3390d0ab7feSJean Delvare /* The SMBus locks itself. The Winbond W83792D chip has a bank register,
3400d0ab7feSJean Delvare    but the driver only accesses registers in bank 0, so we don't have
3410d0ab7feSJean Delvare    to switch banks and lock access between switches. */
3420d0ab7feSJean Delvare static inline int w83792d_read_value(struct i2c_client *client, u8 reg)
3430d0ab7feSJean Delvare {
3440d0ab7feSJean Delvare 	return i2c_smbus_read_byte_data(client, reg);
3450d0ab7feSJean Delvare }
3460d0ab7feSJean Delvare 
3470d0ab7feSJean Delvare static inline int
3480d0ab7feSJean Delvare w83792d_write_value(struct i2c_client *client, u8 reg, u8 value)
3490d0ab7feSJean Delvare {
3500d0ab7feSJean Delvare 	return i2c_smbus_write_byte_data(client, reg, value);
3510d0ab7feSJean Delvare }
3520d0ab7feSJean Delvare 
3535563e27dSR.Marek@sh.cvut.cz /* following are the sysfs callback functions */
3545563e27dSR.Marek@sh.cvut.cz static ssize_t show_in(struct device *dev, struct device_attribute *attr,
3555563e27dSR.Marek@sh.cvut.cz 			char *buf)
3565563e27dSR.Marek@sh.cvut.cz {
3575563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
3585563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index;
3595563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
3605563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf,"%ld\n", IN_FROM_REG(nr,(in_count_from_reg(nr, data))));
3615563e27dSR.Marek@sh.cvut.cz }
3625563e27dSR.Marek@sh.cvut.cz 
3635563e27dSR.Marek@sh.cvut.cz #define show_in_reg(reg) \
3645563e27dSR.Marek@sh.cvut.cz static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
3655563e27dSR.Marek@sh.cvut.cz 			char *buf) \
3665563e27dSR.Marek@sh.cvut.cz { \
3675563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
3685563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index; \
3695563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev); \
3705563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf,"%ld\n", (long)(IN_FROM_REG(nr, (data->reg[nr])*4))); \
3715563e27dSR.Marek@sh.cvut.cz }
3725563e27dSR.Marek@sh.cvut.cz 
3735563e27dSR.Marek@sh.cvut.cz show_in_reg(in_min);
3745563e27dSR.Marek@sh.cvut.cz show_in_reg(in_max);
3755563e27dSR.Marek@sh.cvut.cz 
3765563e27dSR.Marek@sh.cvut.cz #define store_in_reg(REG, reg) \
3775563e27dSR.Marek@sh.cvut.cz static ssize_t store_in_##reg (struct device *dev, \
3785563e27dSR.Marek@sh.cvut.cz 				struct device_attribute *attr, \
3795563e27dSR.Marek@sh.cvut.cz 				const char *buf, size_t count) \
3805563e27dSR.Marek@sh.cvut.cz { \
3815563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
3825563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index; \
3835563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev); \
3845563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client); \
3855563e27dSR.Marek@sh.cvut.cz 	u32 val; \
3865563e27dSR.Marek@sh.cvut.cz 	 \
3875563e27dSR.Marek@sh.cvut.cz 	val = simple_strtoul(buf, NULL, 10); \
388bed73082SYuan Mu 	mutex_lock(&data->update_lock); \
3895563e27dSR.Marek@sh.cvut.cz 	data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val)/4, 0, 255); \
3905563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_IN_##REG[nr], data->in_##reg[nr]); \
391bed73082SYuan Mu 	mutex_unlock(&data->update_lock); \
3925563e27dSR.Marek@sh.cvut.cz 	 \
3935563e27dSR.Marek@sh.cvut.cz 	return count; \
3945563e27dSR.Marek@sh.cvut.cz }
3955563e27dSR.Marek@sh.cvut.cz store_in_reg(MIN, min);
3965563e27dSR.Marek@sh.cvut.cz store_in_reg(MAX, max);
3975563e27dSR.Marek@sh.cvut.cz 
3985563e27dSR.Marek@sh.cvut.cz #define show_fan_reg(reg) \
3995563e27dSR.Marek@sh.cvut.cz static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
4005563e27dSR.Marek@sh.cvut.cz 			char *buf) \
4015563e27dSR.Marek@sh.cvut.cz { \
4025563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
4035563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index - 1; \
4045563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev); \
4055563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf,"%d\n", \
4065563e27dSR.Marek@sh.cvut.cz 		FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
4075563e27dSR.Marek@sh.cvut.cz }
4085563e27dSR.Marek@sh.cvut.cz 
4095563e27dSR.Marek@sh.cvut.cz show_fan_reg(fan);
4105563e27dSR.Marek@sh.cvut.cz show_fan_reg(fan_min);
4115563e27dSR.Marek@sh.cvut.cz 
4125563e27dSR.Marek@sh.cvut.cz static ssize_t
4135563e27dSR.Marek@sh.cvut.cz store_fan_min(struct device *dev, struct device_attribute *attr,
4145563e27dSR.Marek@sh.cvut.cz 		const char *buf, size_t count)
4155563e27dSR.Marek@sh.cvut.cz {
4165563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
4175563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index - 1;
4185563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
4195563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
4205563e27dSR.Marek@sh.cvut.cz 	u32 val;
4215563e27dSR.Marek@sh.cvut.cz 
4225563e27dSR.Marek@sh.cvut.cz 	val = simple_strtoul(buf, NULL, 10);
423bed73082SYuan Mu 	mutex_lock(&data->update_lock);
4245563e27dSR.Marek@sh.cvut.cz 	data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
4255563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_FAN_MIN[nr],
4265563e27dSR.Marek@sh.cvut.cz 				data->fan_min[nr]);
427bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
4285563e27dSR.Marek@sh.cvut.cz 
4295563e27dSR.Marek@sh.cvut.cz 	return count;
4305563e27dSR.Marek@sh.cvut.cz }
4315563e27dSR.Marek@sh.cvut.cz 
4325563e27dSR.Marek@sh.cvut.cz static ssize_t
4335563e27dSR.Marek@sh.cvut.cz show_fan_div(struct device *dev, struct device_attribute *attr,
4345563e27dSR.Marek@sh.cvut.cz 		char *buf)
4355563e27dSR.Marek@sh.cvut.cz {
4365563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
4375563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index;
4385563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
4395563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1]));
4405563e27dSR.Marek@sh.cvut.cz }
4415563e27dSR.Marek@sh.cvut.cz 
4425563e27dSR.Marek@sh.cvut.cz /* Note: we save and restore the fan minimum here, because its value is
4435563e27dSR.Marek@sh.cvut.cz    determined in part by the fan divisor.  This follows the principle of
444d6e05edcSAndreas Mohr    least surprise; the user doesn't expect the fan minimum to change just
4455563e27dSR.Marek@sh.cvut.cz    because the divisor changed. */
4465563e27dSR.Marek@sh.cvut.cz static ssize_t
4475563e27dSR.Marek@sh.cvut.cz store_fan_div(struct device *dev, struct device_attribute *attr,
4485563e27dSR.Marek@sh.cvut.cz 		const char *buf, size_t count)
4495563e27dSR.Marek@sh.cvut.cz {
4505563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
4515563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index - 1;
4525563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
4535563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
4545563e27dSR.Marek@sh.cvut.cz 	unsigned long min;
4555563e27dSR.Marek@sh.cvut.cz 	/*u8 reg;*/
4565563e27dSR.Marek@sh.cvut.cz 	u8 fan_div_reg = 0;
4575563e27dSR.Marek@sh.cvut.cz 	u8 tmp_fan_div;
4585563e27dSR.Marek@sh.cvut.cz 
4595563e27dSR.Marek@sh.cvut.cz 	/* Save fan_min */
460bed73082SYuan Mu 	mutex_lock(&data->update_lock);
4615563e27dSR.Marek@sh.cvut.cz 	min = FAN_FROM_REG(data->fan_min[nr],
4625563e27dSR.Marek@sh.cvut.cz 			   DIV_FROM_REG(data->fan_div[nr]));
4635563e27dSR.Marek@sh.cvut.cz 
4645563e27dSR.Marek@sh.cvut.cz 	data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10));
4655563e27dSR.Marek@sh.cvut.cz 
4665563e27dSR.Marek@sh.cvut.cz 	fan_div_reg = w83792d_read_value(client, W83792D_REG_FAN_DIV[nr >> 1]);
4675563e27dSR.Marek@sh.cvut.cz 	fan_div_reg &= (nr & 0x01) ? 0x8f : 0xf8;
4685563e27dSR.Marek@sh.cvut.cz 	tmp_fan_div = (nr & 0x01) ? (((data->fan_div[nr]) << 4) & 0x70)
4695563e27dSR.Marek@sh.cvut.cz 					: ((data->fan_div[nr]) & 0x07);
4705563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_FAN_DIV[nr >> 1],
4715563e27dSR.Marek@sh.cvut.cz 					fan_div_reg | tmp_fan_div);
4725563e27dSR.Marek@sh.cvut.cz 
4735563e27dSR.Marek@sh.cvut.cz 	/* Restore fan_min */
4745563e27dSR.Marek@sh.cvut.cz 	data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
4755563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], data->fan_min[nr]);
476bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
4775563e27dSR.Marek@sh.cvut.cz 
4785563e27dSR.Marek@sh.cvut.cz 	return count;
4795563e27dSR.Marek@sh.cvut.cz }
4805563e27dSR.Marek@sh.cvut.cz 
4815563e27dSR.Marek@sh.cvut.cz /* read/write the temperature1, includes measured value and limits */
4825563e27dSR.Marek@sh.cvut.cz 
4835563e27dSR.Marek@sh.cvut.cz static ssize_t show_temp1(struct device *dev, struct device_attribute *attr,
4845563e27dSR.Marek@sh.cvut.cz 				char *buf)
4855563e27dSR.Marek@sh.cvut.cz {
4865563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
4875563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index;
4885563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
4895563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[nr]));
4905563e27dSR.Marek@sh.cvut.cz }
4915563e27dSR.Marek@sh.cvut.cz 
4925563e27dSR.Marek@sh.cvut.cz static ssize_t store_temp1(struct device *dev, struct device_attribute *attr,
4935563e27dSR.Marek@sh.cvut.cz 				const char *buf, size_t count)
4945563e27dSR.Marek@sh.cvut.cz {
4955563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
4965563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index;
4975563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
4985563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
4995563e27dSR.Marek@sh.cvut.cz 	s32 val;
5005563e27dSR.Marek@sh.cvut.cz 
5015563e27dSR.Marek@sh.cvut.cz 	val = simple_strtol(buf, NULL, 10);
502bed73082SYuan Mu 	mutex_lock(&data->update_lock);
5035563e27dSR.Marek@sh.cvut.cz 	data->temp1[nr] = TEMP1_TO_REG(val);
5045563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_TEMP1[nr],
5055563e27dSR.Marek@sh.cvut.cz 		data->temp1[nr]);
506bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
5075563e27dSR.Marek@sh.cvut.cz 
5085563e27dSR.Marek@sh.cvut.cz 	return count;
5095563e27dSR.Marek@sh.cvut.cz }
5105563e27dSR.Marek@sh.cvut.cz 
5115563e27dSR.Marek@sh.cvut.cz /* read/write the temperature2-3, includes measured value and limits */
5125563e27dSR.Marek@sh.cvut.cz 
5135563e27dSR.Marek@sh.cvut.cz static ssize_t show_temp23(struct device *dev, struct device_attribute *attr,
5145563e27dSR.Marek@sh.cvut.cz 				char *buf)
5155563e27dSR.Marek@sh.cvut.cz {
5165563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
5175563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->nr;
5185563e27dSR.Marek@sh.cvut.cz 	int index = sensor_attr->index;
5195563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
5205563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf,"%ld\n",
5215563e27dSR.Marek@sh.cvut.cz 		(long)TEMP_ADD_FROM_REG(data->temp_add[nr][index],
5225563e27dSR.Marek@sh.cvut.cz 			data->temp_add[nr][index+1]));
5235563e27dSR.Marek@sh.cvut.cz }
5245563e27dSR.Marek@sh.cvut.cz 
5255563e27dSR.Marek@sh.cvut.cz static ssize_t store_temp23(struct device *dev, struct device_attribute *attr,
5265563e27dSR.Marek@sh.cvut.cz 				const char *buf, size_t count)
5275563e27dSR.Marek@sh.cvut.cz {
5285563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
5295563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->nr;
5305563e27dSR.Marek@sh.cvut.cz 	int index = sensor_attr->index;
5315563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
5325563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
5335563e27dSR.Marek@sh.cvut.cz 	s32 val;
5345563e27dSR.Marek@sh.cvut.cz 
5355563e27dSR.Marek@sh.cvut.cz 	val = simple_strtol(buf, NULL, 10);
536bed73082SYuan Mu 	mutex_lock(&data->update_lock);
5375563e27dSR.Marek@sh.cvut.cz 	data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val);
5385563e27dSR.Marek@sh.cvut.cz 	data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val);
5395563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index],
5405563e27dSR.Marek@sh.cvut.cz 		data->temp_add[nr][index]);
5415563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index+1],
5425563e27dSR.Marek@sh.cvut.cz 		data->temp_add[nr][index+1]);
543bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
5445563e27dSR.Marek@sh.cvut.cz 
5455563e27dSR.Marek@sh.cvut.cz 	return count;
5465563e27dSR.Marek@sh.cvut.cz }
5475563e27dSR.Marek@sh.cvut.cz 
5485563e27dSR.Marek@sh.cvut.cz /* get reatime status of all sensors items: voltage, temp, fan */
5495563e27dSR.Marek@sh.cvut.cz static ssize_t
5505563e27dSR.Marek@sh.cvut.cz show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
5515563e27dSR.Marek@sh.cvut.cz {
5525563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
5535563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%d\n", data->alarms);
5545563e27dSR.Marek@sh.cvut.cz }
5555563e27dSR.Marek@sh.cvut.cz 
55643e61a2dSGong Jun static ssize_t show_alarm(struct device *dev,
55743e61a2dSGong Jun 			  struct device_attribute *attr, char *buf)
55843e61a2dSGong Jun {
55943e61a2dSGong Jun 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
56043e61a2dSGong Jun 	int nr = sensor_attr->index;
56143e61a2dSGong Jun 	struct w83792d_data *data = w83792d_update_device(dev);
56243e61a2dSGong Jun 	return sprintf(buf, "%d\n", (data->alarms >> nr) & 1);
56343e61a2dSGong Jun }
56443e61a2dSGong Jun 
5655563e27dSR.Marek@sh.cvut.cz static ssize_t
5665563e27dSR.Marek@sh.cvut.cz show_pwm(struct device *dev, struct device_attribute *attr,
5675563e27dSR.Marek@sh.cvut.cz 		char *buf)
5685563e27dSR.Marek@sh.cvut.cz {
5695563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
5705563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index;
5715563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
57253e2761bSYuan Mu 	return sprintf(buf, "%d\n", (data->pwm[nr] & 0x0f) << 4);
5735563e27dSR.Marek@sh.cvut.cz }
5745563e27dSR.Marek@sh.cvut.cz 
5755563e27dSR.Marek@sh.cvut.cz static ssize_t
5765563e27dSR.Marek@sh.cvut.cz show_pwmenable(struct device *dev, struct device_attribute *attr,
5775563e27dSR.Marek@sh.cvut.cz 			char *buf)
5785563e27dSR.Marek@sh.cvut.cz {
5795563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
5805563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index - 1;
5815563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
5825563e27dSR.Marek@sh.cvut.cz 	long pwm_enable_tmp = 1;
5835563e27dSR.Marek@sh.cvut.cz 
5845563e27dSR.Marek@sh.cvut.cz 	switch (data->pwmenable[nr]) {
5855563e27dSR.Marek@sh.cvut.cz 	case 0:
5865563e27dSR.Marek@sh.cvut.cz 		pwm_enable_tmp = 1; /* manual mode */
5875563e27dSR.Marek@sh.cvut.cz 		break;
5885563e27dSR.Marek@sh.cvut.cz 	case 1:
5895563e27dSR.Marek@sh.cvut.cz 		pwm_enable_tmp = 3; /*thermal cruise/Smart Fan I */
5905563e27dSR.Marek@sh.cvut.cz 		break;
5915563e27dSR.Marek@sh.cvut.cz 	case 2:
5925563e27dSR.Marek@sh.cvut.cz 		pwm_enable_tmp = 2; /* Smart Fan II */
5935563e27dSR.Marek@sh.cvut.cz 		break;
5945563e27dSR.Marek@sh.cvut.cz 	}
5955563e27dSR.Marek@sh.cvut.cz 
5965563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%ld\n", pwm_enable_tmp);
5975563e27dSR.Marek@sh.cvut.cz }
5985563e27dSR.Marek@sh.cvut.cz 
5995563e27dSR.Marek@sh.cvut.cz static ssize_t
6005563e27dSR.Marek@sh.cvut.cz store_pwm(struct device *dev, struct device_attribute *attr,
6015563e27dSR.Marek@sh.cvut.cz 		const char *buf, size_t count)
6025563e27dSR.Marek@sh.cvut.cz {
6035563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
60453e2761bSYuan Mu 	int nr = sensor_attr->index;
6055563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
6065563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
60753e2761bSYuan Mu 	u8 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255) >> 4;
6085563e27dSR.Marek@sh.cvut.cz 
60953e2761bSYuan Mu 	mutex_lock(&data->update_lock);
61053e2761bSYuan Mu 	val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0;
61153e2761bSYuan Mu 	data->pwm[nr] = val;
6125563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]);
61353e2761bSYuan Mu 	mutex_unlock(&data->update_lock);
6145563e27dSR.Marek@sh.cvut.cz 
6155563e27dSR.Marek@sh.cvut.cz 	return count;
6165563e27dSR.Marek@sh.cvut.cz }
6175563e27dSR.Marek@sh.cvut.cz 
6185563e27dSR.Marek@sh.cvut.cz static ssize_t
6195563e27dSR.Marek@sh.cvut.cz store_pwmenable(struct device *dev, struct device_attribute *attr,
6205563e27dSR.Marek@sh.cvut.cz 			const char *buf, size_t count)
6215563e27dSR.Marek@sh.cvut.cz {
6225563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
6235563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index - 1;
6245563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
6255563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
6265563e27dSR.Marek@sh.cvut.cz 	u32 val;
6275563e27dSR.Marek@sh.cvut.cz 	u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp;
6285563e27dSR.Marek@sh.cvut.cz 
6295563e27dSR.Marek@sh.cvut.cz 	val = simple_strtoul(buf, NULL, 10);
630bed73082SYuan Mu 	if (val < 1 || val > 3)
631bed73082SYuan Mu 		return -EINVAL;
632bed73082SYuan Mu 
633bed73082SYuan Mu 	mutex_lock(&data->update_lock);
6345563e27dSR.Marek@sh.cvut.cz 	switch (val) {
6355563e27dSR.Marek@sh.cvut.cz 	case 1:
6365563e27dSR.Marek@sh.cvut.cz 		data->pwmenable[nr] = 0; /* manual mode */
6375563e27dSR.Marek@sh.cvut.cz 		break;
6385563e27dSR.Marek@sh.cvut.cz 	case 2:
6395563e27dSR.Marek@sh.cvut.cz 		data->pwmenable[nr] = 2; /* Smart Fan II */
6405563e27dSR.Marek@sh.cvut.cz 		break;
6415563e27dSR.Marek@sh.cvut.cz 	case 3:
6425563e27dSR.Marek@sh.cvut.cz 		data->pwmenable[nr] = 1; /* thermal cruise/Smart Fan I */
6435563e27dSR.Marek@sh.cvut.cz 		break;
6445563e27dSR.Marek@sh.cvut.cz 	}
6455563e27dSR.Marek@sh.cvut.cz 	cfg1_tmp = data->pwmenable[0];
6465563e27dSR.Marek@sh.cvut.cz 	cfg2_tmp = (data->pwmenable[1]) << 2;
6475563e27dSR.Marek@sh.cvut.cz 	cfg3_tmp = (data->pwmenable[2]) << 4;
6485563e27dSR.Marek@sh.cvut.cz 	cfg4_tmp = w83792d_read_value(client,W83792D_REG_FAN_CFG) & 0xc0;
6495563e27dSR.Marek@sh.cvut.cz 	fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp;
6505563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp);
651bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
6525563e27dSR.Marek@sh.cvut.cz 
6535563e27dSR.Marek@sh.cvut.cz 	return count;
6545563e27dSR.Marek@sh.cvut.cz }
6555563e27dSR.Marek@sh.cvut.cz 
6565563e27dSR.Marek@sh.cvut.cz static ssize_t
6575563e27dSR.Marek@sh.cvut.cz show_pwm_mode(struct device *dev, struct device_attribute *attr,
6585563e27dSR.Marek@sh.cvut.cz 			char *buf)
6595563e27dSR.Marek@sh.cvut.cz {
6605563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
6615563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index;
6625563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
66353e2761bSYuan Mu 	return sprintf(buf, "%d\n", data->pwm[nr] >> 7);
6645563e27dSR.Marek@sh.cvut.cz }
6655563e27dSR.Marek@sh.cvut.cz 
6665563e27dSR.Marek@sh.cvut.cz static ssize_t
6675563e27dSR.Marek@sh.cvut.cz store_pwm_mode(struct device *dev, struct device_attribute *attr,
6685563e27dSR.Marek@sh.cvut.cz 			const char *buf, size_t count)
6695563e27dSR.Marek@sh.cvut.cz {
6705563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
67153e2761bSYuan Mu 	int nr = sensor_attr->index;
6725563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
6735563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
6745563e27dSR.Marek@sh.cvut.cz 	u32 val;
6755563e27dSR.Marek@sh.cvut.cz 
6765563e27dSR.Marek@sh.cvut.cz 	val = simple_strtoul(buf, NULL, 10);
67753e2761bSYuan Mu 	if (val != 0 && val != 1)
67853e2761bSYuan Mu 		return -EINVAL;
67953e2761bSYuan Mu 
68053e2761bSYuan Mu 	mutex_lock(&data->update_lock);
68153e2761bSYuan Mu 	data->pwm[nr] = w83792d_read_value(client, W83792D_REG_PWM[nr]);
68253e2761bSYuan Mu 	if (val) {			/* PWM mode */
68353e2761bSYuan Mu 		data->pwm[nr] |= 0x80;
68453e2761bSYuan Mu 	} else {			/* DC mode */
68553e2761bSYuan Mu 		data->pwm[nr] &= 0x7f;
68653e2761bSYuan Mu 	}
68753e2761bSYuan Mu 	w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]);
68853e2761bSYuan Mu 	mutex_unlock(&data->update_lock);
6895563e27dSR.Marek@sh.cvut.cz 
6905563e27dSR.Marek@sh.cvut.cz 	return count;
6915563e27dSR.Marek@sh.cvut.cz }
6925563e27dSR.Marek@sh.cvut.cz 
6935563e27dSR.Marek@sh.cvut.cz static ssize_t
694c32301b5SJean Delvare show_chassis(struct device *dev, struct device_attribute *attr,
6955563e27dSR.Marek@sh.cvut.cz 			char *buf)
6965563e27dSR.Marek@sh.cvut.cz {
6975563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
6985563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%d\n", data->chassis);
6995563e27dSR.Marek@sh.cvut.cz }
7005563e27dSR.Marek@sh.cvut.cz 
7015563e27dSR.Marek@sh.cvut.cz static ssize_t
702c32301b5SJean Delvare show_regs_chassis(struct device *dev, struct device_attribute *attr,
703c32301b5SJean Delvare 			char *buf)
704c32301b5SJean Delvare {
705c32301b5SJean Delvare 	dev_warn(dev,
706c32301b5SJean Delvare 		 "Attribute %s is deprecated, use intrusion0_alarm instead\n",
707c32301b5SJean Delvare 		 "chassis");
708c32301b5SJean Delvare 	return show_chassis(dev, attr, buf);
709c32301b5SJean Delvare }
710c32301b5SJean Delvare 
711c32301b5SJean Delvare static ssize_t
7125563e27dSR.Marek@sh.cvut.cz show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf)
7135563e27dSR.Marek@sh.cvut.cz {
7145563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
7155563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%d\n", data->chassis_clear);
7165563e27dSR.Marek@sh.cvut.cz }
7175563e27dSR.Marek@sh.cvut.cz 
7185563e27dSR.Marek@sh.cvut.cz static ssize_t
719c32301b5SJean Delvare store_chassis_clear_legacy(struct device *dev, struct device_attribute *attr,
7205563e27dSR.Marek@sh.cvut.cz 			const char *buf, size_t count)
7215563e27dSR.Marek@sh.cvut.cz {
7225563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
7235563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
7245563e27dSR.Marek@sh.cvut.cz 	u32 val;
7255563e27dSR.Marek@sh.cvut.cz 	u8 temp1 = 0, temp2 = 0;
7265563e27dSR.Marek@sh.cvut.cz 
727c32301b5SJean Delvare 	dev_warn(dev,
728c32301b5SJean Delvare 		 "Attribute %s is deprecated, use intrusion0_alarm instead\n",
729c32301b5SJean Delvare 		 "chassis_clear");
730c32301b5SJean Delvare 
7315563e27dSR.Marek@sh.cvut.cz 	val = simple_strtoul(buf, NULL, 10);
732bed73082SYuan Mu 	mutex_lock(&data->update_lock);
7335563e27dSR.Marek@sh.cvut.cz 	data->chassis_clear = SENSORS_LIMIT(val, 0 ,1);
7345563e27dSR.Marek@sh.cvut.cz 	temp1 = ((data->chassis_clear) << 7) & 0x80;
7355563e27dSR.Marek@sh.cvut.cz 	temp2 = w83792d_read_value(client,
7365563e27dSR.Marek@sh.cvut.cz 		W83792D_REG_CHASSIS_CLR) & 0x7f;
7375563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, temp1 | temp2);
738bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
7395563e27dSR.Marek@sh.cvut.cz 
7405563e27dSR.Marek@sh.cvut.cz 	return count;
7415563e27dSR.Marek@sh.cvut.cz }
7425563e27dSR.Marek@sh.cvut.cz 
743c32301b5SJean Delvare static ssize_t
744c32301b5SJean Delvare store_chassis_clear(struct device *dev, struct device_attribute *attr,
745c32301b5SJean Delvare 			const char *buf, size_t count)
746c32301b5SJean Delvare {
747c32301b5SJean Delvare 	struct i2c_client *client = to_i2c_client(dev);
748c32301b5SJean Delvare 	struct w83792d_data *data = i2c_get_clientdata(client);
749c32301b5SJean Delvare 	unsigned long val;
750c32301b5SJean Delvare 	u8 reg;
751c32301b5SJean Delvare 
752*179c4fdbSFrans Meulenbroeks 	if (kstrtoul(buf, 10, &val) || val != 0)
753c32301b5SJean Delvare 		return -EINVAL;
754c32301b5SJean Delvare 
755c32301b5SJean Delvare 	mutex_lock(&data->update_lock);
756c32301b5SJean Delvare 	reg = w83792d_read_value(client, W83792D_REG_CHASSIS_CLR);
757c32301b5SJean Delvare 	w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, reg | 0x80);
758c32301b5SJean Delvare 	data->valid = 0;		/* Force cache refresh */
759c32301b5SJean Delvare 	mutex_unlock(&data->update_lock);
760c32301b5SJean Delvare 
761c32301b5SJean Delvare 	return count;
762c32301b5SJean Delvare }
763c32301b5SJean Delvare 
7645563e27dSR.Marek@sh.cvut.cz /* For Smart Fan I / Thermal Cruise */
7655563e27dSR.Marek@sh.cvut.cz static ssize_t
7665563e27dSR.Marek@sh.cvut.cz show_thermal_cruise(struct device *dev, struct device_attribute *attr,
7675563e27dSR.Marek@sh.cvut.cz 			char *buf)
7685563e27dSR.Marek@sh.cvut.cz {
7695563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
7705563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index;
7715563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
7725563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%ld\n", (long)data->thermal_cruise[nr-1]);
7735563e27dSR.Marek@sh.cvut.cz }
7745563e27dSR.Marek@sh.cvut.cz 
7755563e27dSR.Marek@sh.cvut.cz static ssize_t
7765563e27dSR.Marek@sh.cvut.cz store_thermal_cruise(struct device *dev, struct device_attribute *attr,
7775563e27dSR.Marek@sh.cvut.cz 			const char *buf, size_t count)
7785563e27dSR.Marek@sh.cvut.cz {
7795563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
7805563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index - 1;
7815563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
7825563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
7835563e27dSR.Marek@sh.cvut.cz 	u32 val;
7845563e27dSR.Marek@sh.cvut.cz 	u8 target_tmp=0, target_mask=0;
7855563e27dSR.Marek@sh.cvut.cz 
7865563e27dSR.Marek@sh.cvut.cz 	val = simple_strtoul(buf, NULL, 10);
7875563e27dSR.Marek@sh.cvut.cz 	target_tmp = val;
7885563e27dSR.Marek@sh.cvut.cz 	target_tmp = target_tmp & 0x7f;
789bed73082SYuan Mu 	mutex_lock(&data->update_lock);
7905563e27dSR.Marek@sh.cvut.cz 	target_mask = w83792d_read_value(client, W83792D_REG_THERMAL[nr]) & 0x80;
7915563e27dSR.Marek@sh.cvut.cz 	data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255);
7925563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_THERMAL[nr],
7935563e27dSR.Marek@sh.cvut.cz 		(data->thermal_cruise[nr]) | target_mask);
794bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
7955563e27dSR.Marek@sh.cvut.cz 
7965563e27dSR.Marek@sh.cvut.cz 	return count;
7975563e27dSR.Marek@sh.cvut.cz }
7985563e27dSR.Marek@sh.cvut.cz 
7995563e27dSR.Marek@sh.cvut.cz /* For Smart Fan I/Thermal Cruise and Smart Fan II */
8005563e27dSR.Marek@sh.cvut.cz static ssize_t
8015563e27dSR.Marek@sh.cvut.cz show_tolerance(struct device *dev, struct device_attribute *attr,
8025563e27dSR.Marek@sh.cvut.cz 		char *buf)
8035563e27dSR.Marek@sh.cvut.cz {
8045563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
8055563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index;
8065563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
8075563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%ld\n", (long)data->tolerance[nr-1]);
8085563e27dSR.Marek@sh.cvut.cz }
8095563e27dSR.Marek@sh.cvut.cz 
8105563e27dSR.Marek@sh.cvut.cz static ssize_t
8115563e27dSR.Marek@sh.cvut.cz store_tolerance(struct device *dev, struct device_attribute *attr,
8125563e27dSR.Marek@sh.cvut.cz 		const char *buf, size_t count)
8135563e27dSR.Marek@sh.cvut.cz {
8145563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
8155563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->index - 1;
8165563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
8175563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
8185563e27dSR.Marek@sh.cvut.cz 	u32 val;
8195563e27dSR.Marek@sh.cvut.cz 	u8 tol_tmp, tol_mask;
8205563e27dSR.Marek@sh.cvut.cz 
8215563e27dSR.Marek@sh.cvut.cz 	val = simple_strtoul(buf, NULL, 10);
822bed73082SYuan Mu 	mutex_lock(&data->update_lock);
8235563e27dSR.Marek@sh.cvut.cz 	tol_mask = w83792d_read_value(client,
8245563e27dSR.Marek@sh.cvut.cz 		W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0);
8255563e27dSR.Marek@sh.cvut.cz 	tol_tmp = SENSORS_LIMIT(val, 0, 15);
8265563e27dSR.Marek@sh.cvut.cz 	tol_tmp &= 0x0f;
8275563e27dSR.Marek@sh.cvut.cz 	data->tolerance[nr] = tol_tmp;
8285563e27dSR.Marek@sh.cvut.cz 	if (nr == 1) {
8295563e27dSR.Marek@sh.cvut.cz 		tol_tmp <<= 4;
8305563e27dSR.Marek@sh.cvut.cz 	}
8315563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_TOLERANCE[nr],
8325563e27dSR.Marek@sh.cvut.cz 		tol_mask | tol_tmp);
833bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
8345563e27dSR.Marek@sh.cvut.cz 
8355563e27dSR.Marek@sh.cvut.cz 	return count;
8365563e27dSR.Marek@sh.cvut.cz }
8375563e27dSR.Marek@sh.cvut.cz 
8385563e27dSR.Marek@sh.cvut.cz /* For Smart Fan II */
8395563e27dSR.Marek@sh.cvut.cz static ssize_t
8405563e27dSR.Marek@sh.cvut.cz show_sf2_point(struct device *dev, struct device_attribute *attr,
8415563e27dSR.Marek@sh.cvut.cz 		char *buf)
8425563e27dSR.Marek@sh.cvut.cz {
8435563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
8445563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->nr;
8455563e27dSR.Marek@sh.cvut.cz 	int index = sensor_attr->index;
8465563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
8475563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%ld\n", (long)data->sf2_points[index-1][nr-1]);
8485563e27dSR.Marek@sh.cvut.cz }
8495563e27dSR.Marek@sh.cvut.cz 
8505563e27dSR.Marek@sh.cvut.cz static ssize_t
8515563e27dSR.Marek@sh.cvut.cz store_sf2_point(struct device *dev, struct device_attribute *attr,
8525563e27dSR.Marek@sh.cvut.cz 		const char *buf, size_t count)
8535563e27dSR.Marek@sh.cvut.cz {
8545563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
8555563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->nr - 1;
8565563e27dSR.Marek@sh.cvut.cz 	int index = sensor_attr->index - 1;
8575563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
8585563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
8595563e27dSR.Marek@sh.cvut.cz 	u32 val;
8605563e27dSR.Marek@sh.cvut.cz 	u8 mask_tmp = 0;
8615563e27dSR.Marek@sh.cvut.cz 
8625563e27dSR.Marek@sh.cvut.cz 	val = simple_strtoul(buf, NULL, 10);
863bed73082SYuan Mu 	mutex_lock(&data->update_lock);
8645563e27dSR.Marek@sh.cvut.cz 	data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127);
8655563e27dSR.Marek@sh.cvut.cz 	mask_tmp = w83792d_read_value(client,
8665563e27dSR.Marek@sh.cvut.cz 					W83792D_REG_POINTS[index][nr]) & 0x80;
8675563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_POINTS[index][nr],
8685563e27dSR.Marek@sh.cvut.cz 		mask_tmp|data->sf2_points[index][nr]);
869bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
8705563e27dSR.Marek@sh.cvut.cz 
8715563e27dSR.Marek@sh.cvut.cz 	return count;
8725563e27dSR.Marek@sh.cvut.cz }
8735563e27dSR.Marek@sh.cvut.cz 
8745563e27dSR.Marek@sh.cvut.cz static ssize_t
8755563e27dSR.Marek@sh.cvut.cz show_sf2_level(struct device *dev, struct device_attribute *attr,
8765563e27dSR.Marek@sh.cvut.cz 		char *buf)
8775563e27dSR.Marek@sh.cvut.cz {
8785563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
8795563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->nr;
8805563e27dSR.Marek@sh.cvut.cz 	int index = sensor_attr->index;
8815563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = w83792d_update_device(dev);
8825563e27dSR.Marek@sh.cvut.cz 	return sprintf(buf, "%d\n",
8835563e27dSR.Marek@sh.cvut.cz 			(((data->sf2_levels[index-1][nr]) * 100) / 15));
8845563e27dSR.Marek@sh.cvut.cz }
8855563e27dSR.Marek@sh.cvut.cz 
8865563e27dSR.Marek@sh.cvut.cz static ssize_t
8875563e27dSR.Marek@sh.cvut.cz store_sf2_level(struct device *dev, struct device_attribute *attr,
8885563e27dSR.Marek@sh.cvut.cz 		const char *buf, size_t count)
8895563e27dSR.Marek@sh.cvut.cz {
8905563e27dSR.Marek@sh.cvut.cz 	struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
8915563e27dSR.Marek@sh.cvut.cz 	int nr = sensor_attr->nr;
8925563e27dSR.Marek@sh.cvut.cz 	int index = sensor_attr->index - 1;
8935563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
8945563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
8955563e27dSR.Marek@sh.cvut.cz 	u32 val;
8965563e27dSR.Marek@sh.cvut.cz 	u8 mask_tmp=0, level_tmp=0;
8975563e27dSR.Marek@sh.cvut.cz 
8985563e27dSR.Marek@sh.cvut.cz 	val = simple_strtoul(buf, NULL, 10);
899bed73082SYuan Mu 	mutex_lock(&data->update_lock);
9005563e27dSR.Marek@sh.cvut.cz 	data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15);
9015563e27dSR.Marek@sh.cvut.cz 	mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr])
9025563e27dSR.Marek@sh.cvut.cz 		& ((nr==3) ? 0xf0 : 0x0f);
9035563e27dSR.Marek@sh.cvut.cz 	if (nr==3) {
9045563e27dSR.Marek@sh.cvut.cz 		level_tmp = data->sf2_levels[index][nr];
9055563e27dSR.Marek@sh.cvut.cz 	} else {
9065563e27dSR.Marek@sh.cvut.cz 		level_tmp = data->sf2_levels[index][nr] << 4;
9075563e27dSR.Marek@sh.cvut.cz 	}
9085563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_LEVELS[index][nr], level_tmp | mask_tmp);
909bed73082SYuan Mu 	mutex_unlock(&data->update_lock);
9105563e27dSR.Marek@sh.cvut.cz 
9115563e27dSR.Marek@sh.cvut.cz 	return count;
9125563e27dSR.Marek@sh.cvut.cz }
9135563e27dSR.Marek@sh.cvut.cz 
9145563e27dSR.Marek@sh.cvut.cz 
9155563e27dSR.Marek@sh.cvut.cz static int
91631d5d275SJean Delvare w83792d_detect_subclients(struct i2c_client *new_client)
9175563e27dSR.Marek@sh.cvut.cz {
9185563e27dSR.Marek@sh.cvut.cz 	int i, id, err;
91931d5d275SJean Delvare 	int address = new_client->addr;
9205563e27dSR.Marek@sh.cvut.cz 	u8 val;
92131d5d275SJean Delvare 	struct i2c_adapter *adapter = new_client->adapter;
9225563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(new_client);
9235563e27dSR.Marek@sh.cvut.cz 
9245563e27dSR.Marek@sh.cvut.cz 	id = i2c_adapter_id(adapter);
9255563e27dSR.Marek@sh.cvut.cz 	if (force_subclients[0] == id && force_subclients[1] == address) {
9265563e27dSR.Marek@sh.cvut.cz 		for (i = 2; i <= 3; i++) {
9275563e27dSR.Marek@sh.cvut.cz 			if (force_subclients[i] < 0x48 ||
9285563e27dSR.Marek@sh.cvut.cz 			    force_subclients[i] > 0x4f) {
9295563e27dSR.Marek@sh.cvut.cz 				dev_err(&new_client->dev, "invalid subclient "
9305563e27dSR.Marek@sh.cvut.cz 					"address %d; must be 0x48-0x4f\n",
9315563e27dSR.Marek@sh.cvut.cz 					force_subclients[i]);
9325563e27dSR.Marek@sh.cvut.cz 				err = -ENODEV;
9335563e27dSR.Marek@sh.cvut.cz 				goto ERROR_SC_0;
9345563e27dSR.Marek@sh.cvut.cz 			}
9355563e27dSR.Marek@sh.cvut.cz 		}
9365563e27dSR.Marek@sh.cvut.cz 		w83792d_write_value(new_client, W83792D_REG_I2C_SUBADDR,
9375563e27dSR.Marek@sh.cvut.cz 					(force_subclients[2] & 0x07) |
9385563e27dSR.Marek@sh.cvut.cz 					((force_subclients[3] & 0x07) << 4));
9395563e27dSR.Marek@sh.cvut.cz 	}
9405563e27dSR.Marek@sh.cvut.cz 
9415563e27dSR.Marek@sh.cvut.cz 	val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR);
9425563e27dSR.Marek@sh.cvut.cz 	if (!(val & 0x08)) {
94331d5d275SJean Delvare 		data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7));
9445563e27dSR.Marek@sh.cvut.cz 	}
9455563e27dSR.Marek@sh.cvut.cz 	if (!(val & 0x80)) {
9465563e27dSR.Marek@sh.cvut.cz 		if ((data->lm75[0] != NULL) &&
9475563e27dSR.Marek@sh.cvut.cz 			((val & 0x7) == ((val >> 4) & 0x7))) {
9485563e27dSR.Marek@sh.cvut.cz 			dev_err(&new_client->dev, "duplicate addresses 0x%x, "
9495563e27dSR.Marek@sh.cvut.cz 				"use force_subclient\n", data->lm75[0]->addr);
9505563e27dSR.Marek@sh.cvut.cz 			err = -ENODEV;
9515563e27dSR.Marek@sh.cvut.cz 			goto ERROR_SC_1;
9525563e27dSR.Marek@sh.cvut.cz 		}
95331d5d275SJean Delvare 		data->lm75[1] = i2c_new_dummy(adapter,
95431d5d275SJean Delvare 					      0x48 + ((val >> 4) & 0x7));
9555563e27dSR.Marek@sh.cvut.cz 	}
9565563e27dSR.Marek@sh.cvut.cz 
9575563e27dSR.Marek@sh.cvut.cz 	return 0;
9585563e27dSR.Marek@sh.cvut.cz 
9595563e27dSR.Marek@sh.cvut.cz /* Undo inits in case of errors */
9605563e27dSR.Marek@sh.cvut.cz 
9615563e27dSR.Marek@sh.cvut.cz ERROR_SC_1:
96231d5d275SJean Delvare 	if (data->lm75[0] != NULL)
96331d5d275SJean Delvare 		i2c_unregister_device(data->lm75[0]);
9645563e27dSR.Marek@sh.cvut.cz ERROR_SC_0:
9655563e27dSR.Marek@sh.cvut.cz 	return err;
9665563e27dSR.Marek@sh.cvut.cz }
9675563e27dSR.Marek@sh.cvut.cz 
968f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in, NULL, 0);
969f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
970f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
971f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
972f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4);
973f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5);
974f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6);
975f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7);
976f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8);
977f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO,
978f52f79daSRudolf Marek 			show_in_min, store_in_min, 0);
979f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
980f52f79daSRudolf Marek 			show_in_min, store_in_min, 1);
981f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
982f52f79daSRudolf Marek 			show_in_min, store_in_min, 2);
983f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
984f52f79daSRudolf Marek 			show_in_min, store_in_min, 3);
985f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
986f52f79daSRudolf Marek 			show_in_min, store_in_min, 4);
987f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
988f52f79daSRudolf Marek 			show_in_min, store_in_min, 5);
989f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
990f52f79daSRudolf Marek 			show_in_min, store_in_min, 6);
991f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO,
992f52f79daSRudolf Marek 			show_in_min, store_in_min, 7);
993f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO,
994f52f79daSRudolf Marek 			show_in_min, store_in_min, 8);
995f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO,
996f52f79daSRudolf Marek 			show_in_max, store_in_max, 0);
997f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
998f52f79daSRudolf Marek 			show_in_max, store_in_max, 1);
999f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
1000f52f79daSRudolf Marek 			show_in_max, store_in_max, 2);
1001f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
1002f52f79daSRudolf Marek 			show_in_max, store_in_max, 3);
1003f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
1004f52f79daSRudolf Marek 			show_in_max, store_in_max, 4);
1005f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
1006f52f79daSRudolf Marek 			show_in_max, store_in_max, 5);
1007f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
1008f52f79daSRudolf Marek 			show_in_max, store_in_max, 6);
1009f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO,
1010f52f79daSRudolf Marek 			show_in_max, store_in_max, 7);
1011f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO,
1012f52f79daSRudolf Marek 			show_in_max, store_in_max, 8);
1013f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp1, NULL, 0, 0);
1014f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp23, NULL, 0, 0);
1015f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp23, NULL, 1, 0);
1016f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR,
1017f52f79daSRudolf Marek 			show_temp1, store_temp1, 0, 1);
1018f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp23,
1019f52f79daSRudolf Marek 			store_temp23, 0, 2);
1020f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp23,
1021f52f79daSRudolf Marek 			store_temp23, 1, 2);
1022f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR,
1023f52f79daSRudolf Marek 			show_temp1, store_temp1, 0, 2);
1024f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR,
1025f52f79daSRudolf Marek 			show_temp23, store_temp23, 0, 4);
1026f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR,
1027f52f79daSRudolf Marek 			show_temp23, store_temp23, 1, 4);
1028f52f79daSRudolf Marek static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
102943e61a2dSGong Jun static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
103043e61a2dSGong Jun static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
103143e61a2dSGong Jun static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 2);
103243e61a2dSGong Jun static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 3);
103343e61a2dSGong Jun static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 4);
103443e61a2dSGong Jun static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 5);
103543e61a2dSGong Jun static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 6);
103643e61a2dSGong Jun static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 7);
103743e61a2dSGong Jun static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 8);
103843e61a2dSGong Jun static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 9);
103943e61a2dSGong Jun static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 10);
104043e61a2dSGong Jun static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 11);
104143e61a2dSGong Jun static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 12);
104243e61a2dSGong Jun static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL, 15);
104343e61a2dSGong Jun static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 19);
104443e61a2dSGong Jun static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 20);
104543e61a2dSGong Jun static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 21);
104643e61a2dSGong Jun static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 22);
104743e61a2dSGong Jun static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 23);
1048f52f79daSRudolf Marek static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL);
1049f52f79daSRudolf Marek static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR,
1050c32301b5SJean Delvare 			show_chassis_clear, store_chassis_clear_legacy);
1051c32301b5SJean Delvare static DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1052c32301b5SJean Delvare 			show_chassis, store_chassis_clear);
1053f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
1054f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
1055f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2);
1056f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
1057f52f79daSRudolf Marek 			show_pwmenable, store_pwmenable, 1);
1058f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
1059f52f79daSRudolf Marek 			show_pwmenable, store_pwmenable, 2);
1060f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
1061f52f79daSRudolf Marek 			show_pwmenable, store_pwmenable, 3);
1062f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(pwm1_mode, S_IWUSR | S_IRUGO,
1063f52f79daSRudolf Marek 			show_pwm_mode, store_pwm_mode, 0);
1064f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(pwm2_mode, S_IWUSR | S_IRUGO,
1065f52f79daSRudolf Marek 			show_pwm_mode, store_pwm_mode, 1);
1066f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(pwm3_mode, S_IWUSR | S_IRUGO,
1067f52f79daSRudolf Marek 			show_pwm_mode, store_pwm_mode, 2);
1068f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(tolerance1, S_IWUSR | S_IRUGO,
1069f52f79daSRudolf Marek 			show_tolerance, store_tolerance, 1);
1070f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(tolerance2, S_IWUSR | S_IRUGO,
1071f52f79daSRudolf Marek 			show_tolerance, store_tolerance, 2);
1072f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(tolerance3, S_IWUSR | S_IRUGO,
1073f52f79daSRudolf Marek 			show_tolerance, store_tolerance, 3);
1074f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(thermal_cruise1, S_IWUSR | S_IRUGO,
1075f52f79daSRudolf Marek 			show_thermal_cruise, store_thermal_cruise, 1);
1076f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(thermal_cruise2, S_IWUSR | S_IRUGO,
1077f52f79daSRudolf Marek 			show_thermal_cruise, store_thermal_cruise, 2);
1078f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(thermal_cruise3, S_IWUSR | S_IRUGO,
1079f52f79daSRudolf Marek 			show_thermal_cruise, store_thermal_cruise, 3);
1080f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point1_fan1, S_IRUGO | S_IWUSR,
1081f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 1, 1);
1082f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point2_fan1, S_IRUGO | S_IWUSR,
1083f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 2, 1);
1084f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point3_fan1, S_IRUGO | S_IWUSR,
1085f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 3, 1);
1086f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point4_fan1, S_IRUGO | S_IWUSR,
1087f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 4, 1);
1088f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point1_fan2, S_IRUGO | S_IWUSR,
1089f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 1, 2);
1090f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point2_fan2, S_IRUGO | S_IWUSR,
1091f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 2, 2);
1092f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point3_fan2, S_IRUGO | S_IWUSR,
1093f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 3, 2);
1094f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point4_fan2, S_IRUGO | S_IWUSR,
1095f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 4, 2);
1096f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point1_fan3, S_IRUGO | S_IWUSR,
1097f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 1, 3);
1098f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point2_fan3, S_IRUGO | S_IWUSR,
1099f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 2, 3);
1100f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point3_fan3, S_IRUGO | S_IWUSR,
1101f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 3, 3);
1102f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_point4_fan3, S_IRUGO | S_IWUSR,
1103f52f79daSRudolf Marek 			show_sf2_point, store_sf2_point, 4, 3);
1104f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_level1_fan1, S_IRUGO | S_IWUSR,
1105f52f79daSRudolf Marek 			show_sf2_level, store_sf2_level, 1, 1);
1106f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_level2_fan1, S_IRUGO | S_IWUSR,
1107f52f79daSRudolf Marek 			show_sf2_level, store_sf2_level, 2, 1);
1108f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_level3_fan1, S_IRUGO | S_IWUSR,
1109f52f79daSRudolf Marek 			show_sf2_level, store_sf2_level, 3, 1);
1110f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_level1_fan2, S_IRUGO | S_IWUSR,
1111f52f79daSRudolf Marek 			show_sf2_level, store_sf2_level, 1, 2);
1112f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_level2_fan2, S_IRUGO | S_IWUSR,
1113f52f79daSRudolf Marek 			show_sf2_level, store_sf2_level, 2, 2);
1114f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_level3_fan2, S_IRUGO | S_IWUSR,
1115f52f79daSRudolf Marek 			show_sf2_level, store_sf2_level, 3, 2);
1116f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_level1_fan3, S_IRUGO | S_IWUSR,
1117f52f79daSRudolf Marek 			show_sf2_level, store_sf2_level, 1, 3);
1118f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_level2_fan3, S_IRUGO | S_IWUSR,
1119f52f79daSRudolf Marek 			show_sf2_level, store_sf2_level, 2, 3);
1120f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR_2(sf2_level3_fan3, S_IRUGO | S_IWUSR,
1121f52f79daSRudolf Marek 			show_sf2_level, store_sf2_level, 3, 3);
1122f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 1);
1123f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 2);
1124f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 3);
1125f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 4);
1126f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 5);
1127f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 6);
1128f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 7);
1129f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
1130f52f79daSRudolf Marek 			show_fan_min, store_fan_min, 1);
1131f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
1132f52f79daSRudolf Marek 			show_fan_min, store_fan_min, 2);
1133f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO,
1134f52f79daSRudolf Marek 			show_fan_min, store_fan_min, 3);
1135f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO,
1136f52f79daSRudolf Marek 			show_fan_min, store_fan_min, 4);
1137f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO,
1138f52f79daSRudolf Marek 			show_fan_min, store_fan_min, 5);
1139f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO,
1140f52f79daSRudolf Marek 			show_fan_min, store_fan_min, 6);
1141f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO,
1142f52f79daSRudolf Marek 			show_fan_min, store_fan_min, 7);
1143f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
1144f52f79daSRudolf Marek 			show_fan_div, store_fan_div, 1);
1145f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
1146f52f79daSRudolf Marek 			show_fan_div, store_fan_div, 2);
1147f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan3_div, S_IWUSR | S_IRUGO,
1148f52f79daSRudolf Marek 			show_fan_div, store_fan_div, 3);
1149f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan4_div, S_IWUSR | S_IRUGO,
1150f52f79daSRudolf Marek 			show_fan_div, store_fan_div, 4);
1151f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan5_div, S_IWUSR | S_IRUGO,
1152f52f79daSRudolf Marek 			show_fan_div, store_fan_div, 5);
1153f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan6_div, S_IWUSR | S_IRUGO,
1154f52f79daSRudolf Marek 			show_fan_div, store_fan_div, 6);
1155f52f79daSRudolf Marek static SENSOR_DEVICE_ATTR(fan7_div, S_IWUSR | S_IRUGO,
1156f52f79daSRudolf Marek 			show_fan_div, store_fan_div, 7);
1157f52f79daSRudolf Marek 
115843e61a2dSGong Jun static struct attribute *w83792d_attributes_fan[4][5] = {
11591f8dae31SYuan Mu 	{
1160f52f79daSRudolf Marek 		&sensor_dev_attr_fan4_input.dev_attr.attr,
1161f52f79daSRudolf Marek 		&sensor_dev_attr_fan4_min.dev_attr.attr,
1162f52f79daSRudolf Marek 		&sensor_dev_attr_fan4_div.dev_attr.attr,
116343e61a2dSGong Jun 		&sensor_dev_attr_fan4_alarm.dev_attr.attr,
1164f52f79daSRudolf Marek 		NULL
1165f52f79daSRudolf Marek 	}, {
1166f52f79daSRudolf Marek 		&sensor_dev_attr_fan5_input.dev_attr.attr,
1167f52f79daSRudolf Marek 		&sensor_dev_attr_fan5_min.dev_attr.attr,
1168f52f79daSRudolf Marek 		&sensor_dev_attr_fan5_div.dev_attr.attr,
116943e61a2dSGong Jun 		&sensor_dev_attr_fan5_alarm.dev_attr.attr,
1170f52f79daSRudolf Marek 		NULL
1171f52f79daSRudolf Marek 	}, {
1172f52f79daSRudolf Marek 		&sensor_dev_attr_fan6_input.dev_attr.attr,
1173f52f79daSRudolf Marek 		&sensor_dev_attr_fan6_min.dev_attr.attr,
1174f52f79daSRudolf Marek 		&sensor_dev_attr_fan6_div.dev_attr.attr,
117543e61a2dSGong Jun 		&sensor_dev_attr_fan6_alarm.dev_attr.attr,
1176f52f79daSRudolf Marek 		NULL
1177f52f79daSRudolf Marek 	}, {
1178f52f79daSRudolf Marek 		&sensor_dev_attr_fan7_input.dev_attr.attr,
1179f52f79daSRudolf Marek 		&sensor_dev_attr_fan7_min.dev_attr.attr,
1180f52f79daSRudolf Marek 		&sensor_dev_attr_fan7_div.dev_attr.attr,
118143e61a2dSGong Jun 		&sensor_dev_attr_fan7_alarm.dev_attr.attr,
1182f52f79daSRudolf Marek 		NULL
11831f8dae31SYuan Mu 	}
1184f52f79daSRudolf Marek };
1185f52f79daSRudolf Marek 
1186f52f79daSRudolf Marek static const struct attribute_group w83792d_group_fan[4] = {
1187f52f79daSRudolf Marek 	{ .attrs = w83792d_attributes_fan[0] },
1188f52f79daSRudolf Marek 	{ .attrs = w83792d_attributes_fan[1] },
1189f52f79daSRudolf Marek 	{ .attrs = w83792d_attributes_fan[2] },
1190f52f79daSRudolf Marek 	{ .attrs = w83792d_attributes_fan[3] },
1191f52f79daSRudolf Marek };
1192f52f79daSRudolf Marek 
1193f52f79daSRudolf Marek static struct attribute *w83792d_attributes[] = {
1194f52f79daSRudolf Marek 	&sensor_dev_attr_in0_input.dev_attr.attr,
1195f52f79daSRudolf Marek 	&sensor_dev_attr_in0_max.dev_attr.attr,
1196f52f79daSRudolf Marek 	&sensor_dev_attr_in0_min.dev_attr.attr,
1197f52f79daSRudolf Marek 	&sensor_dev_attr_in1_input.dev_attr.attr,
1198f52f79daSRudolf Marek 	&sensor_dev_attr_in1_max.dev_attr.attr,
1199f52f79daSRudolf Marek 	&sensor_dev_attr_in1_min.dev_attr.attr,
1200f52f79daSRudolf Marek 	&sensor_dev_attr_in2_input.dev_attr.attr,
1201f52f79daSRudolf Marek 	&sensor_dev_attr_in2_max.dev_attr.attr,
1202f52f79daSRudolf Marek 	&sensor_dev_attr_in2_min.dev_attr.attr,
1203f52f79daSRudolf Marek 	&sensor_dev_attr_in3_input.dev_attr.attr,
1204f52f79daSRudolf Marek 	&sensor_dev_attr_in3_max.dev_attr.attr,
1205f52f79daSRudolf Marek 	&sensor_dev_attr_in3_min.dev_attr.attr,
1206f52f79daSRudolf Marek 	&sensor_dev_attr_in4_input.dev_attr.attr,
1207f52f79daSRudolf Marek 	&sensor_dev_attr_in4_max.dev_attr.attr,
1208f52f79daSRudolf Marek 	&sensor_dev_attr_in4_min.dev_attr.attr,
1209f52f79daSRudolf Marek 	&sensor_dev_attr_in5_input.dev_attr.attr,
1210f52f79daSRudolf Marek 	&sensor_dev_attr_in5_max.dev_attr.attr,
1211f52f79daSRudolf Marek 	&sensor_dev_attr_in5_min.dev_attr.attr,
1212f52f79daSRudolf Marek 	&sensor_dev_attr_in6_input.dev_attr.attr,
1213f52f79daSRudolf Marek 	&sensor_dev_attr_in6_max.dev_attr.attr,
1214f52f79daSRudolf Marek 	&sensor_dev_attr_in6_min.dev_attr.attr,
1215f52f79daSRudolf Marek 	&sensor_dev_attr_in7_input.dev_attr.attr,
1216f52f79daSRudolf Marek 	&sensor_dev_attr_in7_max.dev_attr.attr,
1217f52f79daSRudolf Marek 	&sensor_dev_attr_in7_min.dev_attr.attr,
1218f52f79daSRudolf Marek 	&sensor_dev_attr_in8_input.dev_attr.attr,
1219f52f79daSRudolf Marek 	&sensor_dev_attr_in8_max.dev_attr.attr,
1220f52f79daSRudolf Marek 	&sensor_dev_attr_in8_min.dev_attr.attr,
122143e61a2dSGong Jun 	&sensor_dev_attr_in0_alarm.dev_attr.attr,
122243e61a2dSGong Jun 	&sensor_dev_attr_in1_alarm.dev_attr.attr,
122343e61a2dSGong Jun 	&sensor_dev_attr_in2_alarm.dev_attr.attr,
122443e61a2dSGong Jun 	&sensor_dev_attr_in3_alarm.dev_attr.attr,
122543e61a2dSGong Jun 	&sensor_dev_attr_in4_alarm.dev_attr.attr,
122643e61a2dSGong Jun 	&sensor_dev_attr_in5_alarm.dev_attr.attr,
122743e61a2dSGong Jun 	&sensor_dev_attr_in6_alarm.dev_attr.attr,
122843e61a2dSGong Jun 	&sensor_dev_attr_in7_alarm.dev_attr.attr,
122943e61a2dSGong Jun 	&sensor_dev_attr_in8_alarm.dev_attr.attr,
1230f52f79daSRudolf Marek 	&sensor_dev_attr_temp1_input.dev_attr.attr,
1231f52f79daSRudolf Marek 	&sensor_dev_attr_temp1_max.dev_attr.attr,
1232f52f79daSRudolf Marek 	&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
1233f52f79daSRudolf Marek 	&sensor_dev_attr_temp2_input.dev_attr.attr,
1234f52f79daSRudolf Marek 	&sensor_dev_attr_temp2_max.dev_attr.attr,
1235f52f79daSRudolf Marek 	&sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
1236f52f79daSRudolf Marek 	&sensor_dev_attr_temp3_input.dev_attr.attr,
1237f52f79daSRudolf Marek 	&sensor_dev_attr_temp3_max.dev_attr.attr,
1238f52f79daSRudolf Marek 	&sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
123943e61a2dSGong Jun 	&sensor_dev_attr_temp1_alarm.dev_attr.attr,
124043e61a2dSGong Jun 	&sensor_dev_attr_temp2_alarm.dev_attr.attr,
124143e61a2dSGong Jun 	&sensor_dev_attr_temp3_alarm.dev_attr.attr,
1242f52f79daSRudolf Marek 	&sensor_dev_attr_pwm1.dev_attr.attr,
1243f52f79daSRudolf Marek 	&sensor_dev_attr_pwm1_mode.dev_attr.attr,
1244f52f79daSRudolf Marek 	&sensor_dev_attr_pwm1_enable.dev_attr.attr,
1245f52f79daSRudolf Marek 	&sensor_dev_attr_pwm2.dev_attr.attr,
1246f52f79daSRudolf Marek 	&sensor_dev_attr_pwm2_mode.dev_attr.attr,
1247f52f79daSRudolf Marek 	&sensor_dev_attr_pwm2_enable.dev_attr.attr,
1248f52f79daSRudolf Marek 	&sensor_dev_attr_pwm3.dev_attr.attr,
1249f52f79daSRudolf Marek 	&sensor_dev_attr_pwm3_mode.dev_attr.attr,
1250f52f79daSRudolf Marek 	&sensor_dev_attr_pwm3_enable.dev_attr.attr,
1251f52f79daSRudolf Marek 	&dev_attr_alarms.attr,
1252f52f79daSRudolf Marek 	&dev_attr_chassis.attr,
1253f52f79daSRudolf Marek 	&dev_attr_chassis_clear.attr,
1254c32301b5SJean Delvare 	&dev_attr_intrusion0_alarm.attr,
1255f52f79daSRudolf Marek 	&sensor_dev_attr_tolerance1.dev_attr.attr,
1256f52f79daSRudolf Marek 	&sensor_dev_attr_thermal_cruise1.dev_attr.attr,
1257f52f79daSRudolf Marek 	&sensor_dev_attr_tolerance2.dev_attr.attr,
1258f52f79daSRudolf Marek 	&sensor_dev_attr_thermal_cruise2.dev_attr.attr,
1259f52f79daSRudolf Marek 	&sensor_dev_attr_tolerance3.dev_attr.attr,
1260f52f79daSRudolf Marek 	&sensor_dev_attr_thermal_cruise3.dev_attr.attr,
1261f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point1_fan1.dev_attr.attr,
1262f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point2_fan1.dev_attr.attr,
1263f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point3_fan1.dev_attr.attr,
1264f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point4_fan1.dev_attr.attr,
1265f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point1_fan2.dev_attr.attr,
1266f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point2_fan2.dev_attr.attr,
1267f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point3_fan2.dev_attr.attr,
1268f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point4_fan2.dev_attr.attr,
1269f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point1_fan3.dev_attr.attr,
1270f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point2_fan3.dev_attr.attr,
1271f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point3_fan3.dev_attr.attr,
1272f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_point4_fan3.dev_attr.attr,
1273f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_level1_fan1.dev_attr.attr,
1274f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_level2_fan1.dev_attr.attr,
1275f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_level3_fan1.dev_attr.attr,
1276f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_level1_fan2.dev_attr.attr,
1277f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_level2_fan2.dev_attr.attr,
1278f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_level3_fan2.dev_attr.attr,
1279f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_level1_fan3.dev_attr.attr,
1280f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_level2_fan3.dev_attr.attr,
1281f52f79daSRudolf Marek 	&sensor_dev_attr_sf2_level3_fan3.dev_attr.attr,
1282f52f79daSRudolf Marek 	&sensor_dev_attr_fan1_input.dev_attr.attr,
1283f52f79daSRudolf Marek 	&sensor_dev_attr_fan1_min.dev_attr.attr,
1284f52f79daSRudolf Marek 	&sensor_dev_attr_fan1_div.dev_attr.attr,
128543e61a2dSGong Jun 	&sensor_dev_attr_fan1_alarm.dev_attr.attr,
1286f52f79daSRudolf Marek 	&sensor_dev_attr_fan2_input.dev_attr.attr,
1287f52f79daSRudolf Marek 	&sensor_dev_attr_fan2_min.dev_attr.attr,
1288f52f79daSRudolf Marek 	&sensor_dev_attr_fan2_div.dev_attr.attr,
128943e61a2dSGong Jun 	&sensor_dev_attr_fan2_alarm.dev_attr.attr,
1290f52f79daSRudolf Marek 	&sensor_dev_attr_fan3_input.dev_attr.attr,
1291f52f79daSRudolf Marek 	&sensor_dev_attr_fan3_min.dev_attr.attr,
1292f52f79daSRudolf Marek 	&sensor_dev_attr_fan3_div.dev_attr.attr,
129343e61a2dSGong Jun 	&sensor_dev_attr_fan3_alarm.dev_attr.attr,
1294f52f79daSRudolf Marek 	NULL
1295f52f79daSRudolf Marek };
1296f52f79daSRudolf Marek 
1297f52f79daSRudolf Marek static const struct attribute_group w83792d_group = {
1298f52f79daSRudolf Marek 	.attrs = w83792d_attributes,
1299f52f79daSRudolf Marek };
13005563e27dSR.Marek@sh.cvut.cz 
130131d5d275SJean Delvare /* Return 0 if detection is successful, -ENODEV otherwise */
13025563e27dSR.Marek@sh.cvut.cz static int
1303310ec792SJean Delvare w83792d_detect(struct i2c_client *client, struct i2c_board_info *info)
13045563e27dSR.Marek@sh.cvut.cz {
130531d5d275SJean Delvare 	struct i2c_adapter *adapter = client->adapter;
130631d5d275SJean Delvare 	int val1, val2;
130731d5d275SJean Delvare 	unsigned short address = client->addr;
13085563e27dSR.Marek@sh.cvut.cz 
13095563e27dSR.Marek@sh.cvut.cz 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
131031d5d275SJean Delvare 		return -ENODEV;
13115563e27dSR.Marek@sh.cvut.cz 	}
13125563e27dSR.Marek@sh.cvut.cz 
13132de1875aSJean Delvare 	if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80)
131431d5d275SJean Delvare 		return -ENODEV;
13152de1875aSJean Delvare 
13161f8dae31SYuan Mu 	val1 = w83792d_read_value(client, W83792D_REG_BANK);
13171f8dae31SYuan Mu 	val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
13185563e27dSR.Marek@sh.cvut.cz 	/* Check for Winbond ID if in bank 0 */
13195563e27dSR.Marek@sh.cvut.cz 	if (!(val1 & 0x07)) {  /* is Bank0 */
13202de1875aSJean Delvare 		if ((!(val1 & 0x80) && val2 != 0xa3) ||
13212de1875aSJean Delvare 		    ( (val1 & 0x80) && val2 != 0x5c))
132231d5d275SJean Delvare 			return -ENODEV;
13235563e27dSR.Marek@sh.cvut.cz 	}
13245563e27dSR.Marek@sh.cvut.cz 	/* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
13255563e27dSR.Marek@sh.cvut.cz 	   should match */
13262de1875aSJean Delvare 	if (w83792d_read_value(client, W83792D_REG_I2C_ADDR) != address)
132731d5d275SJean Delvare 		return -ENODEV;
13285563e27dSR.Marek@sh.cvut.cz 
13292de1875aSJean Delvare 	/*  Put it now into bank 0 and Vendor ID High Byte */
13301f8dae31SYuan Mu 	w83792d_write_value(client,
13315563e27dSR.Marek@sh.cvut.cz 			    W83792D_REG_BANK,
13321f8dae31SYuan Mu 			    (w83792d_read_value(client,
13335563e27dSR.Marek@sh.cvut.cz 				W83792D_REG_BANK) & 0x78) | 0x80);
13345563e27dSR.Marek@sh.cvut.cz 
13355563e27dSR.Marek@sh.cvut.cz 	/* Determine the chip type. */
13361f8dae31SYuan Mu 	val1 = w83792d_read_value(client, W83792D_REG_WCHIPID);
13372de1875aSJean Delvare 	val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
13382de1875aSJean Delvare 	if (val1 != 0x7a || val2 != 0x5c)
133931d5d275SJean Delvare 		return -ENODEV;
13405563e27dSR.Marek@sh.cvut.cz 
134131d5d275SJean Delvare 	strlcpy(info->type, "w83792d", I2C_NAME_SIZE);
134231d5d275SJean Delvare 
134331d5d275SJean Delvare 	return 0;
13445563e27dSR.Marek@sh.cvut.cz }
13455563e27dSR.Marek@sh.cvut.cz 
134631d5d275SJean Delvare static int
134731d5d275SJean Delvare w83792d_probe(struct i2c_client *client, const struct i2c_device_id *id)
134831d5d275SJean Delvare {
134931d5d275SJean Delvare 	struct w83792d_data *data;
135031d5d275SJean Delvare 	struct device *dev = &client->dev;
135131d5d275SJean Delvare 	int i, val1, err;
13525563e27dSR.Marek@sh.cvut.cz 
135331d5d275SJean Delvare 	data = kzalloc(sizeof(struct w83792d_data), GFP_KERNEL);
135431d5d275SJean Delvare 	if (!data) {
135531d5d275SJean Delvare 		err = -ENOMEM;
135631d5d275SJean Delvare 		goto ERROR0;
135731d5d275SJean Delvare 	}
135831d5d275SJean Delvare 
135931d5d275SJean Delvare 	i2c_set_clientdata(client, data);
13605563e27dSR.Marek@sh.cvut.cz 	data->valid = 0;
13619a61bf63SIngo Molnar 	mutex_init(&data->update_lock);
13625563e27dSR.Marek@sh.cvut.cz 
136331d5d275SJean Delvare 	err = w83792d_detect_subclients(client);
136431d5d275SJean Delvare 	if (err)
13655563e27dSR.Marek@sh.cvut.cz 		goto ERROR1;
13665563e27dSR.Marek@sh.cvut.cz 
13675563e27dSR.Marek@sh.cvut.cz 	/* Initialize the chip */
13681f8dae31SYuan Mu 	w83792d_init_client(client);
13695563e27dSR.Marek@sh.cvut.cz 
13705563e27dSR.Marek@sh.cvut.cz 	/* A few vars need to be filled upon startup */
137196320519SJean Delvare 	for (i = 0; i < 7; i++) {
13721f8dae31SYuan Mu 		data->fan_min[i] = w83792d_read_value(client,
13735563e27dSR.Marek@sh.cvut.cz 					W83792D_REG_FAN_MIN[i]);
13745563e27dSR.Marek@sh.cvut.cz 	}
13755563e27dSR.Marek@sh.cvut.cz 
13765563e27dSR.Marek@sh.cvut.cz 	/* Register sysfs hooks */
1377f52f79daSRudolf Marek 	if ((err = sysfs_create_group(&dev->kobj, &w83792d_group)))
1378ce785ab4SR.Marek@sh.cvut.cz 		goto ERROR3;
137996320519SJean Delvare 
138096320519SJean Delvare 	/* Read GPIO enable register to check if pins for fan 4,5 are used as
138196320519SJean Delvare 	   GPIO */
13821f8dae31SYuan Mu 	val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN);
1383f52f79daSRudolf Marek 
138496320519SJean Delvare 	if (!(val1 & 0x40))
1385f52f79daSRudolf Marek 		if ((err = sysfs_create_group(&dev->kobj,
1386f52f79daSRudolf Marek 					      &w83792d_group_fan[0])))
1387f52f79daSRudolf Marek 			goto exit_remove_files;
1388f52f79daSRudolf Marek 
138996320519SJean Delvare 	if (!(val1 & 0x20))
1390f52f79daSRudolf Marek 		if ((err = sysfs_create_group(&dev->kobj,
1391f52f79daSRudolf Marek 					      &w83792d_group_fan[1])))
1392f52f79daSRudolf Marek 			goto exit_remove_files;
139396320519SJean Delvare 
13941f8dae31SYuan Mu 	val1 = w83792d_read_value(client, W83792D_REG_PIN);
139596320519SJean Delvare 	if (val1 & 0x40)
1396f52f79daSRudolf Marek 		if ((err = sysfs_create_group(&dev->kobj,
1397f52f79daSRudolf Marek 					      &w83792d_group_fan[2])))
1398f52f79daSRudolf Marek 			goto exit_remove_files;
1399f52f79daSRudolf Marek 
140096320519SJean Delvare 	if (val1 & 0x04)
1401f52f79daSRudolf Marek 		if ((err = sysfs_create_group(&dev->kobj,
1402f52f79daSRudolf Marek 					      &w83792d_group_fan[3])))
1403f52f79daSRudolf Marek 			goto exit_remove_files;
14045563e27dSR.Marek@sh.cvut.cz 
14051beeffe4STony Jones 	data->hwmon_dev = hwmon_device_register(dev);
14061beeffe4STony Jones 	if (IS_ERR(data->hwmon_dev)) {
14071beeffe4STony Jones 		err = PTR_ERR(data->hwmon_dev);
1408f52f79daSRudolf Marek 		goto exit_remove_files;
14091f8dae31SYuan Mu 	}
14105563e27dSR.Marek@sh.cvut.cz 
14115563e27dSR.Marek@sh.cvut.cz 	return 0;
14125563e27dSR.Marek@sh.cvut.cz 
1413f52f79daSRudolf Marek exit_remove_files:
1414f52f79daSRudolf Marek 	sysfs_remove_group(&dev->kobj, &w83792d_group);
1415f52f79daSRudolf Marek 	for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
1416f52f79daSRudolf Marek 		sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]);
1417ce785ab4SR.Marek@sh.cvut.cz ERROR3:
141831d5d275SJean Delvare 	if (data->lm75[0] != NULL)
141931d5d275SJean Delvare 		i2c_unregister_device(data->lm75[0]);
142031d5d275SJean Delvare 	if (data->lm75[1] != NULL)
142131d5d275SJean Delvare 		i2c_unregister_device(data->lm75[1]);
14225563e27dSR.Marek@sh.cvut.cz ERROR1:
14235563e27dSR.Marek@sh.cvut.cz 	kfree(data);
14245563e27dSR.Marek@sh.cvut.cz ERROR0:
14255563e27dSR.Marek@sh.cvut.cz 	return err;
14265563e27dSR.Marek@sh.cvut.cz }
14275563e27dSR.Marek@sh.cvut.cz 
14285563e27dSR.Marek@sh.cvut.cz static int
142931d5d275SJean Delvare w83792d_remove(struct i2c_client *client)
14305563e27dSR.Marek@sh.cvut.cz {
1431ce785ab4SR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
143231d5d275SJean Delvare 	int i;
14335563e27dSR.Marek@sh.cvut.cz 
14341beeffe4STony Jones 	hwmon_device_unregister(data->hwmon_dev);
1435f52f79daSRudolf Marek 	sysfs_remove_group(&client->dev.kobj, &w83792d_group);
1436f52f79daSRudolf Marek 	for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
1437f52f79daSRudolf Marek 		sysfs_remove_group(&client->dev.kobj,
1438f52f79daSRudolf Marek 				   &w83792d_group_fan[i]);
1439ce785ab4SR.Marek@sh.cvut.cz 
144031d5d275SJean Delvare 	if (data->lm75[0] != NULL)
144131d5d275SJean Delvare 		i2c_unregister_device(data->lm75[0]);
144231d5d275SJean Delvare 	if (data->lm75[1] != NULL)
144331d5d275SJean Delvare 		i2c_unregister_device(data->lm75[1]);
14445563e27dSR.Marek@sh.cvut.cz 
1445ce785ab4SR.Marek@sh.cvut.cz 	kfree(data);
14465563e27dSR.Marek@sh.cvut.cz 	return 0;
14475563e27dSR.Marek@sh.cvut.cz }
14485563e27dSR.Marek@sh.cvut.cz 
14495563e27dSR.Marek@sh.cvut.cz static void
14505563e27dSR.Marek@sh.cvut.cz w83792d_init_client(struct i2c_client *client)
14515563e27dSR.Marek@sh.cvut.cz {
14525563e27dSR.Marek@sh.cvut.cz 	u8 temp2_cfg, temp3_cfg, vid_in_b;
14535563e27dSR.Marek@sh.cvut.cz 
14545563e27dSR.Marek@sh.cvut.cz 	if (init) {
14555563e27dSR.Marek@sh.cvut.cz 		w83792d_write_value(client, W83792D_REG_CONFIG, 0x80);
14565563e27dSR.Marek@sh.cvut.cz 	}
14575563e27dSR.Marek@sh.cvut.cz 	/* Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0):
14585563e27dSR.Marek@sh.cvut.cz 	   W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of
14595563e27dSR.Marek@sh.cvut.cz 	     vin0/vin1 can be modified by user;
14605563e27dSR.Marek@sh.cvut.cz 	   W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of
14615563e27dSR.Marek@sh.cvut.cz 	     vin0/vin1 auto-updated, can NOT be modified by user. */
14625563e27dSR.Marek@sh.cvut.cz 	vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B);
14635563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_VID_IN_B,
14645563e27dSR.Marek@sh.cvut.cz 			    vid_in_b & 0xbf);
14655563e27dSR.Marek@sh.cvut.cz 
14665563e27dSR.Marek@sh.cvut.cz 	temp2_cfg = w83792d_read_value(client, W83792D_REG_TEMP2_CONFIG);
14675563e27dSR.Marek@sh.cvut.cz 	temp3_cfg = w83792d_read_value(client, W83792D_REG_TEMP3_CONFIG);
14685563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_TEMP2_CONFIG,
14695563e27dSR.Marek@sh.cvut.cz 				temp2_cfg & 0xe6);
14705563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_TEMP3_CONFIG,
14715563e27dSR.Marek@sh.cvut.cz 				temp3_cfg & 0xe6);
14725563e27dSR.Marek@sh.cvut.cz 
14735563e27dSR.Marek@sh.cvut.cz 	/* Start monitoring */
14745563e27dSR.Marek@sh.cvut.cz 	w83792d_write_value(client, W83792D_REG_CONFIG,
14755563e27dSR.Marek@sh.cvut.cz 			    (w83792d_read_value(client,
14765563e27dSR.Marek@sh.cvut.cz 						W83792D_REG_CONFIG) & 0xf7)
14775563e27dSR.Marek@sh.cvut.cz 			    | 0x01);
14785563e27dSR.Marek@sh.cvut.cz }
14795563e27dSR.Marek@sh.cvut.cz 
14805563e27dSR.Marek@sh.cvut.cz static struct w83792d_data *w83792d_update_device(struct device *dev)
14815563e27dSR.Marek@sh.cvut.cz {
14825563e27dSR.Marek@sh.cvut.cz 	struct i2c_client *client = to_i2c_client(dev);
14835563e27dSR.Marek@sh.cvut.cz 	struct w83792d_data *data = i2c_get_clientdata(client);
14845563e27dSR.Marek@sh.cvut.cz 	int i, j;
148553e2761bSYuan Mu 	u8 reg_array_tmp[4], reg_tmp;
14865563e27dSR.Marek@sh.cvut.cz 
14879a61bf63SIngo Molnar 	mutex_lock(&data->update_lock);
14885563e27dSR.Marek@sh.cvut.cz 
14895563e27dSR.Marek@sh.cvut.cz 	if (time_after
14905563e27dSR.Marek@sh.cvut.cz 	    (jiffies - data->last_updated, (unsigned long) (HZ * 3))
14915563e27dSR.Marek@sh.cvut.cz 	    || time_before(jiffies, data->last_updated) || !data->valid) {
14925563e27dSR.Marek@sh.cvut.cz 		dev_dbg(dev, "Starting device update\n");
14935563e27dSR.Marek@sh.cvut.cz 
14945563e27dSR.Marek@sh.cvut.cz 		/* Update the voltages measured value and limits */
14955563e27dSR.Marek@sh.cvut.cz 		for (i = 0; i < 9; i++) {
14965563e27dSR.Marek@sh.cvut.cz 			data->in[i] = w83792d_read_value(client,
14975563e27dSR.Marek@sh.cvut.cz 						W83792D_REG_IN[i]);
14985563e27dSR.Marek@sh.cvut.cz 			data->in_max[i] = w83792d_read_value(client,
14995563e27dSR.Marek@sh.cvut.cz 						W83792D_REG_IN_MAX[i]);
15005563e27dSR.Marek@sh.cvut.cz 			data->in_min[i] = w83792d_read_value(client,
15015563e27dSR.Marek@sh.cvut.cz 						W83792D_REG_IN_MIN[i]);
15025563e27dSR.Marek@sh.cvut.cz 		}
150399d85560SJean Delvare 		data->low_bits = w83792d_read_value(client,
150499d85560SJean Delvare 						W83792D_REG_LOW_BITS1) +
150599d85560SJean Delvare 				 (w83792d_read_value(client,
150699d85560SJean Delvare 						W83792D_REG_LOW_BITS2) << 8);
15075563e27dSR.Marek@sh.cvut.cz 		for (i = 0; i < 7; i++) {
15085563e27dSR.Marek@sh.cvut.cz 			/* Update the Fan measured value and limits */
15095563e27dSR.Marek@sh.cvut.cz 			data->fan[i] = w83792d_read_value(client,
15105563e27dSR.Marek@sh.cvut.cz 						W83792D_REG_FAN[i]);
15115563e27dSR.Marek@sh.cvut.cz 			data->fan_min[i] = w83792d_read_value(client,
15125563e27dSR.Marek@sh.cvut.cz 						W83792D_REG_FAN_MIN[i]);
15135563e27dSR.Marek@sh.cvut.cz 			/* Update the PWM/DC Value and PWM/DC flag */
151453e2761bSYuan Mu 			data->pwm[i] = w83792d_read_value(client,
15155563e27dSR.Marek@sh.cvut.cz 						W83792D_REG_PWM[i]);
15165563e27dSR.Marek@sh.cvut.cz 		}
15175563e27dSR.Marek@sh.cvut.cz 
15185563e27dSR.Marek@sh.cvut.cz 		reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG);
15195563e27dSR.Marek@sh.cvut.cz 		data->pwmenable[0] = reg_tmp & 0x03;
15205563e27dSR.Marek@sh.cvut.cz 		data->pwmenable[1] = (reg_tmp>>2) & 0x03;
15215563e27dSR.Marek@sh.cvut.cz 		data->pwmenable[2] = (reg_tmp>>4) & 0x03;
15225563e27dSR.Marek@sh.cvut.cz 
15235563e27dSR.Marek@sh.cvut.cz 		for (i = 0; i < 3; i++) {
15245563e27dSR.Marek@sh.cvut.cz 			data->temp1[i] = w83792d_read_value(client,
15255563e27dSR.Marek@sh.cvut.cz 							W83792D_REG_TEMP1[i]);
15265563e27dSR.Marek@sh.cvut.cz 		}
15275563e27dSR.Marek@sh.cvut.cz 		for (i = 0; i < 2; i++) {
15285563e27dSR.Marek@sh.cvut.cz 			for (j = 0; j < 6; j++) {
15295563e27dSR.Marek@sh.cvut.cz 				data->temp_add[i][j] = w83792d_read_value(
15305563e27dSR.Marek@sh.cvut.cz 					client,W83792D_REG_TEMP_ADD[i][j]);
15315563e27dSR.Marek@sh.cvut.cz 			}
15325563e27dSR.Marek@sh.cvut.cz 		}
15335563e27dSR.Marek@sh.cvut.cz 
15345563e27dSR.Marek@sh.cvut.cz 		/* Update the Fan Divisor */
15355563e27dSR.Marek@sh.cvut.cz 		for (i = 0; i < 4; i++) {
15365563e27dSR.Marek@sh.cvut.cz 			reg_array_tmp[i] = w83792d_read_value(client,
15375563e27dSR.Marek@sh.cvut.cz 							W83792D_REG_FAN_DIV[i]);
15385563e27dSR.Marek@sh.cvut.cz 		}
15395563e27dSR.Marek@sh.cvut.cz 		data->fan_div[0] = reg_array_tmp[0] & 0x07;
15405563e27dSR.Marek@sh.cvut.cz 		data->fan_div[1] = (reg_array_tmp[0] >> 4) & 0x07;
15415563e27dSR.Marek@sh.cvut.cz 		data->fan_div[2] = reg_array_tmp[1] & 0x07;
15425563e27dSR.Marek@sh.cvut.cz 		data->fan_div[3] = (reg_array_tmp[1] >> 4) & 0x07;
15435563e27dSR.Marek@sh.cvut.cz 		data->fan_div[4] = reg_array_tmp[2] & 0x07;
15445563e27dSR.Marek@sh.cvut.cz 		data->fan_div[5] = (reg_array_tmp[2] >> 4) & 0x07;
15455563e27dSR.Marek@sh.cvut.cz 		data->fan_div[6] = reg_array_tmp[3] & 0x07;
15465563e27dSR.Marek@sh.cvut.cz 
15475563e27dSR.Marek@sh.cvut.cz 		/* Update the realtime status */
15485563e27dSR.Marek@sh.cvut.cz 		data->alarms = w83792d_read_value(client, W83792D_REG_ALARM1) +
15495563e27dSR.Marek@sh.cvut.cz 			(w83792d_read_value(client, W83792D_REG_ALARM2) << 8) +
15505563e27dSR.Marek@sh.cvut.cz 			(w83792d_read_value(client, W83792D_REG_ALARM3) << 16);
15515563e27dSR.Marek@sh.cvut.cz 
15525563e27dSR.Marek@sh.cvut.cz 		/* Update CaseOpen status and it's CLR_CHS. */
15535563e27dSR.Marek@sh.cvut.cz 		data->chassis = (w83792d_read_value(client,
15545563e27dSR.Marek@sh.cvut.cz 			W83792D_REG_CHASSIS) >> 5) & 0x01;
15555563e27dSR.Marek@sh.cvut.cz 		data->chassis_clear = (w83792d_read_value(client,
15565563e27dSR.Marek@sh.cvut.cz 			W83792D_REG_CHASSIS_CLR) >> 7) & 0x01;
15575563e27dSR.Marek@sh.cvut.cz 
15585563e27dSR.Marek@sh.cvut.cz 		/* Update Thermal Cruise/Smart Fan I target value */
15595563e27dSR.Marek@sh.cvut.cz 		for (i = 0; i < 3; i++) {
15605563e27dSR.Marek@sh.cvut.cz 			data->thermal_cruise[i] =
15615563e27dSR.Marek@sh.cvut.cz 				w83792d_read_value(client,
15625563e27dSR.Marek@sh.cvut.cz 				W83792D_REG_THERMAL[i]) & 0x7f;
15635563e27dSR.Marek@sh.cvut.cz 		}
15645563e27dSR.Marek@sh.cvut.cz 
15655563e27dSR.Marek@sh.cvut.cz 		/* Update Smart Fan I/II tolerance */
15665563e27dSR.Marek@sh.cvut.cz 		reg_tmp = w83792d_read_value(client, W83792D_REG_TOLERANCE[0]);
15675563e27dSR.Marek@sh.cvut.cz 		data->tolerance[0] = reg_tmp & 0x0f;
15685563e27dSR.Marek@sh.cvut.cz 		data->tolerance[1] = (reg_tmp >> 4) & 0x0f;
15695563e27dSR.Marek@sh.cvut.cz 		data->tolerance[2] = w83792d_read_value(client,
15705563e27dSR.Marek@sh.cvut.cz 					W83792D_REG_TOLERANCE[2]) & 0x0f;
15715563e27dSR.Marek@sh.cvut.cz 
15725563e27dSR.Marek@sh.cvut.cz 		/* Update Smart Fan II temperature points */
15735563e27dSR.Marek@sh.cvut.cz 		for (i = 0; i < 3; i++) {
15745563e27dSR.Marek@sh.cvut.cz 			for (j = 0; j < 4; j++) {
15755563e27dSR.Marek@sh.cvut.cz 				data->sf2_points[i][j] = w83792d_read_value(
15765563e27dSR.Marek@sh.cvut.cz 					client,W83792D_REG_POINTS[i][j]) & 0x7f;
15775563e27dSR.Marek@sh.cvut.cz 			}
15785563e27dSR.Marek@sh.cvut.cz 		}
15795563e27dSR.Marek@sh.cvut.cz 
15805563e27dSR.Marek@sh.cvut.cz 		/* Update Smart Fan II duty cycle levels */
15815563e27dSR.Marek@sh.cvut.cz 		for (i = 0; i < 3; i++) {
15825563e27dSR.Marek@sh.cvut.cz 			reg_tmp = w83792d_read_value(client,
15835563e27dSR.Marek@sh.cvut.cz 						W83792D_REG_LEVELS[i][0]);
15845563e27dSR.Marek@sh.cvut.cz 			data->sf2_levels[i][0] = reg_tmp & 0x0f;
15855563e27dSR.Marek@sh.cvut.cz 			data->sf2_levels[i][1] = (reg_tmp >> 4) & 0x0f;
15865563e27dSR.Marek@sh.cvut.cz 			reg_tmp = w83792d_read_value(client,
15875563e27dSR.Marek@sh.cvut.cz 						W83792D_REG_LEVELS[i][2]);
15885563e27dSR.Marek@sh.cvut.cz 			data->sf2_levels[i][2] = (reg_tmp >> 4) & 0x0f;
15895563e27dSR.Marek@sh.cvut.cz 			data->sf2_levels[i][3] = reg_tmp & 0x0f;
15905563e27dSR.Marek@sh.cvut.cz 		}
15915563e27dSR.Marek@sh.cvut.cz 
15925563e27dSR.Marek@sh.cvut.cz 		data->last_updated = jiffies;
15935563e27dSR.Marek@sh.cvut.cz 		data->valid = 1;
15945563e27dSR.Marek@sh.cvut.cz 	}
15955563e27dSR.Marek@sh.cvut.cz 
15969a61bf63SIngo Molnar 	mutex_unlock(&data->update_lock);
15975563e27dSR.Marek@sh.cvut.cz 
15985563e27dSR.Marek@sh.cvut.cz #ifdef DEBUG
15995563e27dSR.Marek@sh.cvut.cz 	w83792d_print_debug(data, dev);
16005563e27dSR.Marek@sh.cvut.cz #endif
16015563e27dSR.Marek@sh.cvut.cz 
16025563e27dSR.Marek@sh.cvut.cz 	return data;
16035563e27dSR.Marek@sh.cvut.cz }
16045563e27dSR.Marek@sh.cvut.cz 
16055563e27dSR.Marek@sh.cvut.cz #ifdef DEBUG
16065563e27dSR.Marek@sh.cvut.cz static void w83792d_print_debug(struct w83792d_data *data, struct device *dev)
16075563e27dSR.Marek@sh.cvut.cz {
16085563e27dSR.Marek@sh.cvut.cz 	int i=0, j=0;
16095563e27dSR.Marek@sh.cvut.cz 	dev_dbg(dev, "==========The following is the debug message...========\n");
16105563e27dSR.Marek@sh.cvut.cz 	dev_dbg(dev, "9 set of Voltages: =====>\n");
16115563e27dSR.Marek@sh.cvut.cz 	for (i=0; i<9; i++) {
16125563e27dSR.Marek@sh.cvut.cz 		dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]);
16135563e27dSR.Marek@sh.cvut.cz 		dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]);
16145563e27dSR.Marek@sh.cvut.cz 		dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]);
16155563e27dSR.Marek@sh.cvut.cz 	}
161699d85560SJean Delvare 	dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff);
161799d85560SJean Delvare 	dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8);
16185563e27dSR.Marek@sh.cvut.cz 	dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n");
16195563e27dSR.Marek@sh.cvut.cz 	for (i=0; i<7; i++) {
16205563e27dSR.Marek@sh.cvut.cz 		dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]);
16215563e27dSR.Marek@sh.cvut.cz 		dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]);
16225563e27dSR.Marek@sh.cvut.cz 		dev_dbg(dev, "pwm[%d]     is: 0x%x\n", i, data->pwm[i]);
16235563e27dSR.Marek@sh.cvut.cz 	}
16245563e27dSR.Marek@sh.cvut.cz 	dev_dbg(dev, "3 set of Temperatures: =====>\n");
16255563e27dSR.Marek@sh.cvut.cz 	for (i=0; i<3; i++) {
16265563e27dSR.Marek@sh.cvut.cz 		dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]);
16275563e27dSR.Marek@sh.cvut.cz 	}
16285563e27dSR.Marek@sh.cvut.cz 
16295563e27dSR.Marek@sh.cvut.cz 	for (i=0; i<2; i++) {
16305563e27dSR.Marek@sh.cvut.cz 		for (j=0; j<6; j++) {
16315563e27dSR.Marek@sh.cvut.cz 			dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j,
16325563e27dSR.Marek@sh.cvut.cz 							data->temp_add[i][j]);
16335563e27dSR.Marek@sh.cvut.cz 		}
16345563e27dSR.Marek@sh.cvut.cz 	}
16355563e27dSR.Marek@sh.cvut.cz 
16365563e27dSR.Marek@sh.cvut.cz 	for (i=0; i<7; i++) {
16375563e27dSR.Marek@sh.cvut.cz 		dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]);
16385563e27dSR.Marek@sh.cvut.cz 	}
16395563e27dSR.Marek@sh.cvut.cz 	dev_dbg(dev, "==========End of the debug message...==================\n");
16405563e27dSR.Marek@sh.cvut.cz 	dev_dbg(dev, "\n");
16415563e27dSR.Marek@sh.cvut.cz }
16425563e27dSR.Marek@sh.cvut.cz #endif
16435563e27dSR.Marek@sh.cvut.cz 
16445563e27dSR.Marek@sh.cvut.cz static int __init
16455563e27dSR.Marek@sh.cvut.cz sensors_w83792d_init(void)
16465563e27dSR.Marek@sh.cvut.cz {
16475563e27dSR.Marek@sh.cvut.cz 	return i2c_add_driver(&w83792d_driver);
16485563e27dSR.Marek@sh.cvut.cz }
16495563e27dSR.Marek@sh.cvut.cz 
16505563e27dSR.Marek@sh.cvut.cz static void __exit
16515563e27dSR.Marek@sh.cvut.cz sensors_w83792d_exit(void)
16525563e27dSR.Marek@sh.cvut.cz {
16535563e27dSR.Marek@sh.cvut.cz 	i2c_del_driver(&w83792d_driver);
16545563e27dSR.Marek@sh.cvut.cz }
16555563e27dSR.Marek@sh.cvut.cz 
16565563e27dSR.Marek@sh.cvut.cz MODULE_AUTHOR("Chunhao Huang @ Winbond <DZShen@Winbond.com.tw>");
16575563e27dSR.Marek@sh.cvut.cz MODULE_DESCRIPTION("W83792AD/D driver for linux-2.6");
16585563e27dSR.Marek@sh.cvut.cz MODULE_LICENSE("GPL");
16595563e27dSR.Marek@sh.cvut.cz 
16605563e27dSR.Marek@sh.cvut.cz module_init(sensors_w83792d_init);
16615563e27dSR.Marek@sh.cvut.cz module_exit(sensors_w83792d_exit);
16625563e27dSR.Marek@sh.cvut.cz 
1663