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>, 65563e27dSR.Marek@sh.cvut.cz Rudolf Marek <r.marek@sh.cvut.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/config.h> 395563e27dSR.Marek@sh.cvut.cz #include <linux/module.h> 405563e27dSR.Marek@sh.cvut.cz #include <linux/init.h> 415563e27dSR.Marek@sh.cvut.cz #include <linux/slab.h> 425563e27dSR.Marek@sh.cvut.cz #include <linux/i2c.h> 435563e27dSR.Marek@sh.cvut.cz #include <linux/i2c-sensor.h> 445563e27dSR.Marek@sh.cvut.cz #include <linux/i2c-vid.h> 45ce785ab4SR.Marek@sh.cvut.cz #include <linux/hwmon.h> 465563e27dSR.Marek@sh.cvut.cz #include <linux/hwmon-sysfs.h> 47ce785ab4SR.Marek@sh.cvut.cz #include <linux/err.h> 485563e27dSR.Marek@sh.cvut.cz 495563e27dSR.Marek@sh.cvut.cz /* Addresses to scan */ 505563e27dSR.Marek@sh.cvut.cz static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; 515563e27dSR.Marek@sh.cvut.cz 525563e27dSR.Marek@sh.cvut.cz /* Insmod parameters */ 535563e27dSR.Marek@sh.cvut.cz SENSORS_INSMOD_1(w83792d); 545563e27dSR.Marek@sh.cvut.cz I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " 555563e27dSR.Marek@sh.cvut.cz "{bus, clientaddr, subclientaddr1, subclientaddr2}"); 565563e27dSR.Marek@sh.cvut.cz 575563e27dSR.Marek@sh.cvut.cz static int init; 585563e27dSR.Marek@sh.cvut.cz module_param(init, bool, 0); 595563e27dSR.Marek@sh.cvut.cz MODULE_PARM_DESC(init, "Set to one to force chip initialization"); 605563e27dSR.Marek@sh.cvut.cz 615563e27dSR.Marek@sh.cvut.cz /* The W83792D registers */ 625563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_IN[9] = { 635563e27dSR.Marek@sh.cvut.cz 0x20, /* Vcore A in DataSheet */ 645563e27dSR.Marek@sh.cvut.cz 0x21, /* Vcore B in DataSheet */ 655563e27dSR.Marek@sh.cvut.cz 0x22, /* VIN0 in DataSheet */ 665563e27dSR.Marek@sh.cvut.cz 0x23, /* VIN1 in DataSheet */ 675563e27dSR.Marek@sh.cvut.cz 0x24, /* VIN2 in DataSheet */ 685563e27dSR.Marek@sh.cvut.cz 0x25, /* VIN3 in DataSheet */ 695563e27dSR.Marek@sh.cvut.cz 0x26, /* 5VCC in DataSheet */ 705563e27dSR.Marek@sh.cvut.cz 0xB0, /* 5VSB in DataSheet */ 715563e27dSR.Marek@sh.cvut.cz 0xB1 /* VBAT in DataSheet */ 725563e27dSR.Marek@sh.cvut.cz }; 735563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_LOW_BITS1 0x3E /* Low Bits I in DataSheet */ 745563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_LOW_BITS2 0x3F /* Low Bits II in DataSheet */ 755563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_IN_MAX[9] = { 765563e27dSR.Marek@sh.cvut.cz 0x2B, /* Vcore A High Limit in DataSheet */ 775563e27dSR.Marek@sh.cvut.cz 0x2D, /* Vcore B High Limit in DataSheet */ 785563e27dSR.Marek@sh.cvut.cz 0x2F, /* VIN0 High Limit in DataSheet */ 795563e27dSR.Marek@sh.cvut.cz 0x31, /* VIN1 High Limit in DataSheet */ 805563e27dSR.Marek@sh.cvut.cz 0x33, /* VIN2 High Limit in DataSheet */ 815563e27dSR.Marek@sh.cvut.cz 0x35, /* VIN3 High Limit in DataSheet */ 825563e27dSR.Marek@sh.cvut.cz 0x37, /* 5VCC High Limit in DataSheet */ 835563e27dSR.Marek@sh.cvut.cz 0xB4, /* 5VSB High Limit in DataSheet */ 845563e27dSR.Marek@sh.cvut.cz 0xB6 /* VBAT High Limit in DataSheet */ 855563e27dSR.Marek@sh.cvut.cz }; 865563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_IN_MIN[9] = { 875563e27dSR.Marek@sh.cvut.cz 0x2C, /* Vcore A Low Limit in DataSheet */ 885563e27dSR.Marek@sh.cvut.cz 0x2E, /* Vcore B Low Limit in DataSheet */ 895563e27dSR.Marek@sh.cvut.cz 0x30, /* VIN0 Low Limit in DataSheet */ 905563e27dSR.Marek@sh.cvut.cz 0x32, /* VIN1 Low Limit in DataSheet */ 915563e27dSR.Marek@sh.cvut.cz 0x34, /* VIN2 Low Limit in DataSheet */ 925563e27dSR.Marek@sh.cvut.cz 0x36, /* VIN3 Low Limit in DataSheet */ 935563e27dSR.Marek@sh.cvut.cz 0x38, /* 5VCC Low Limit in DataSheet */ 945563e27dSR.Marek@sh.cvut.cz 0xB5, /* 5VSB Low Limit in DataSheet */ 955563e27dSR.Marek@sh.cvut.cz 0xB7 /* VBAT Low Limit in DataSheet */ 965563e27dSR.Marek@sh.cvut.cz }; 975563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_FAN[7] = { 985563e27dSR.Marek@sh.cvut.cz 0x28, /* FAN 1 Count in DataSheet */ 995563e27dSR.Marek@sh.cvut.cz 0x29, /* FAN 2 Count in DataSheet */ 1005563e27dSR.Marek@sh.cvut.cz 0x2A, /* FAN 3 Count in DataSheet */ 1015563e27dSR.Marek@sh.cvut.cz 0xB8, /* FAN 4 Count in DataSheet */ 1025563e27dSR.Marek@sh.cvut.cz 0xB9, /* FAN 5 Count in DataSheet */ 1035563e27dSR.Marek@sh.cvut.cz 0xBA, /* FAN 6 Count in DataSheet */ 1045563e27dSR.Marek@sh.cvut.cz 0xBE /* FAN 7 Count in DataSheet */ 1055563e27dSR.Marek@sh.cvut.cz }; 1065563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_FAN_MIN[7] = { 1075563e27dSR.Marek@sh.cvut.cz 0x3B, /* FAN 1 Count Low Limit in DataSheet */ 1085563e27dSR.Marek@sh.cvut.cz 0x3C, /* FAN 2 Count Low Limit in DataSheet */ 1095563e27dSR.Marek@sh.cvut.cz 0x3D, /* FAN 3 Count Low Limit in DataSheet */ 1105563e27dSR.Marek@sh.cvut.cz 0xBB, /* FAN 4 Count Low Limit in DataSheet */ 1115563e27dSR.Marek@sh.cvut.cz 0xBC, /* FAN 5 Count Low Limit in DataSheet */ 1125563e27dSR.Marek@sh.cvut.cz 0xBD, /* FAN 6 Count Low Limit in DataSheet */ 1135563e27dSR.Marek@sh.cvut.cz 0xBF /* FAN 7 Count Low Limit in DataSheet */ 1145563e27dSR.Marek@sh.cvut.cz }; 1155563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_FAN_CFG 0x84 /* FAN Configuration in DataSheet */ 1165563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_FAN_DIV[4] = { 1175563e27dSR.Marek@sh.cvut.cz 0x47, /* contains FAN2 and FAN1 Divisor */ 1185563e27dSR.Marek@sh.cvut.cz 0x5B, /* contains FAN4 and FAN3 Divisor */ 1195563e27dSR.Marek@sh.cvut.cz 0x5C, /* contains FAN6 and FAN5 Divisor */ 1205563e27dSR.Marek@sh.cvut.cz 0x9E /* contains FAN7 Divisor. */ 1215563e27dSR.Marek@sh.cvut.cz }; 1225563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_PWM[7] = { 1235563e27dSR.Marek@sh.cvut.cz 0x81, /* FAN 1 Duty Cycle, be used to control */ 1245563e27dSR.Marek@sh.cvut.cz 0x83, /* FAN 2 Duty Cycle, be used to control */ 1255563e27dSR.Marek@sh.cvut.cz 0x94, /* FAN 3 Duty Cycle, be used to control */ 1265563e27dSR.Marek@sh.cvut.cz 0xA3, /* FAN 4 Duty Cycle, be used to control */ 1275563e27dSR.Marek@sh.cvut.cz 0xA4, /* FAN 5 Duty Cycle, be used to control */ 1285563e27dSR.Marek@sh.cvut.cz 0xA5, /* FAN 6 Duty Cycle, be used to control */ 1295563e27dSR.Marek@sh.cvut.cz 0xA6 /* FAN 7 Duty Cycle, be used to control */ 1305563e27dSR.Marek@sh.cvut.cz }; 1315563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_BANK 0x4E 1325563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_TEMP2_CONFIG 0xC2 1335563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_TEMP3_CONFIG 0xCA 1345563e27dSR.Marek@sh.cvut.cz 1355563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_TEMP1[3] = { 1365563e27dSR.Marek@sh.cvut.cz 0x27, /* TEMP 1 in DataSheet */ 1375563e27dSR.Marek@sh.cvut.cz 0x39, /* TEMP 1 Over in DataSheet */ 1385563e27dSR.Marek@sh.cvut.cz 0x3A, /* TEMP 1 Hyst in DataSheet */ 1395563e27dSR.Marek@sh.cvut.cz }; 1405563e27dSR.Marek@sh.cvut.cz 1415563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_TEMP_ADD[2][6] = { 1425563e27dSR.Marek@sh.cvut.cz { 0xC0, /* TEMP 2 in DataSheet */ 1435563e27dSR.Marek@sh.cvut.cz 0xC1, /* TEMP 2(0.5 deg) in DataSheet */ 1445563e27dSR.Marek@sh.cvut.cz 0xC5, /* TEMP 2 Over High part in DataSheet */ 1455563e27dSR.Marek@sh.cvut.cz 0xC6, /* TEMP 2 Over Low part in DataSheet */ 1465563e27dSR.Marek@sh.cvut.cz 0xC3, /* TEMP 2 Thyst High part in DataSheet */ 1475563e27dSR.Marek@sh.cvut.cz 0xC4 }, /* TEMP 2 Thyst Low part in DataSheet */ 1485563e27dSR.Marek@sh.cvut.cz { 0xC8, /* TEMP 3 in DataSheet */ 1495563e27dSR.Marek@sh.cvut.cz 0xC9, /* TEMP 3(0.5 deg) in DataSheet */ 1505563e27dSR.Marek@sh.cvut.cz 0xCD, /* TEMP 3 Over High part in DataSheet */ 1515563e27dSR.Marek@sh.cvut.cz 0xCE, /* TEMP 3 Over Low part in DataSheet */ 1525563e27dSR.Marek@sh.cvut.cz 0xCB, /* TEMP 3 Thyst High part in DataSheet */ 1535563e27dSR.Marek@sh.cvut.cz 0xCC } /* TEMP 3 Thyst Low part in DataSheet */ 1545563e27dSR.Marek@sh.cvut.cz }; 1555563e27dSR.Marek@sh.cvut.cz 1565563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_THERMAL[3] = { 1575563e27dSR.Marek@sh.cvut.cz 0x85, /* SmartFanI: Fan1 target value */ 1585563e27dSR.Marek@sh.cvut.cz 0x86, /* SmartFanI: Fan2 target value */ 1595563e27dSR.Marek@sh.cvut.cz 0x96 /* SmartFanI: Fan3 target value */ 1605563e27dSR.Marek@sh.cvut.cz }; 1615563e27dSR.Marek@sh.cvut.cz 1625563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_TOLERANCE[3] = { 1635563e27dSR.Marek@sh.cvut.cz 0x87, /* (bit3-0)SmartFan Fan1 tolerance */ 1645563e27dSR.Marek@sh.cvut.cz 0x87, /* (bit7-4)SmartFan Fan2 tolerance */ 1655563e27dSR.Marek@sh.cvut.cz 0x97 /* (bit3-0)SmartFan Fan3 tolerance */ 1665563e27dSR.Marek@sh.cvut.cz }; 1675563e27dSR.Marek@sh.cvut.cz 1685563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_POINTS[3][4] = { 1695563e27dSR.Marek@sh.cvut.cz { 0x85, /* SmartFanII: Fan1 temp point 1 */ 1705563e27dSR.Marek@sh.cvut.cz 0xE3, /* SmartFanII: Fan1 temp point 2 */ 1715563e27dSR.Marek@sh.cvut.cz 0xE4, /* SmartFanII: Fan1 temp point 3 */ 1725563e27dSR.Marek@sh.cvut.cz 0xE5 }, /* SmartFanII: Fan1 temp point 4 */ 1735563e27dSR.Marek@sh.cvut.cz { 0x86, /* SmartFanII: Fan2 temp point 1 */ 1745563e27dSR.Marek@sh.cvut.cz 0xE6, /* SmartFanII: Fan2 temp point 2 */ 1755563e27dSR.Marek@sh.cvut.cz 0xE7, /* SmartFanII: Fan2 temp point 3 */ 1765563e27dSR.Marek@sh.cvut.cz 0xE8 }, /* SmartFanII: Fan2 temp point 4 */ 1775563e27dSR.Marek@sh.cvut.cz { 0x96, /* SmartFanII: Fan3 temp point 1 */ 1785563e27dSR.Marek@sh.cvut.cz 0xE9, /* SmartFanII: Fan3 temp point 2 */ 1795563e27dSR.Marek@sh.cvut.cz 0xEA, /* SmartFanII: Fan3 temp point 3 */ 1805563e27dSR.Marek@sh.cvut.cz 0xEB } /* SmartFanII: Fan3 temp point 4 */ 1815563e27dSR.Marek@sh.cvut.cz }; 1825563e27dSR.Marek@sh.cvut.cz 1835563e27dSR.Marek@sh.cvut.cz static const u8 W83792D_REG_LEVELS[3][4] = { 1845563e27dSR.Marek@sh.cvut.cz { 0x88, /* (bit3-0) SmartFanII: Fan1 Non-Stop */ 1855563e27dSR.Marek@sh.cvut.cz 0x88, /* (bit7-4) SmartFanII: Fan1 Level 1 */ 1865563e27dSR.Marek@sh.cvut.cz 0xE0, /* (bit7-4) SmartFanII: Fan1 Level 2 */ 1875563e27dSR.Marek@sh.cvut.cz 0xE0 }, /* (bit3-0) SmartFanII: Fan1 Level 3 */ 1885563e27dSR.Marek@sh.cvut.cz { 0x89, /* (bit3-0) SmartFanII: Fan2 Non-Stop */ 1895563e27dSR.Marek@sh.cvut.cz 0x89, /* (bit7-4) SmartFanII: Fan2 Level 1 */ 1905563e27dSR.Marek@sh.cvut.cz 0xE1, /* (bit7-4) SmartFanII: Fan2 Level 2 */ 1915563e27dSR.Marek@sh.cvut.cz 0xE1 }, /* (bit3-0) SmartFanII: Fan2 Level 3 */ 1925563e27dSR.Marek@sh.cvut.cz { 0x98, /* (bit3-0) SmartFanII: Fan3 Non-Stop */ 1935563e27dSR.Marek@sh.cvut.cz 0x98, /* (bit7-4) SmartFanII: Fan3 Level 1 */ 1945563e27dSR.Marek@sh.cvut.cz 0xE2, /* (bit7-4) SmartFanII: Fan3 Level 2 */ 1955563e27dSR.Marek@sh.cvut.cz 0xE2 } /* (bit3-0) SmartFanII: Fan3 Level 3 */ 1965563e27dSR.Marek@sh.cvut.cz }; 1975563e27dSR.Marek@sh.cvut.cz 1985563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CONFIG 0x40 1995563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_VID_FANDIV 0x47 2005563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CHIPID 0x49 2015563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_WCHIPID 0x58 2025563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CHIPMAN 0x4F 2035563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_PIN 0x4B 2045563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_I2C_SUBADDR 0x4A 2055563e27dSR.Marek@sh.cvut.cz 2065563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_ALARM1 0xA9 /* realtime status register1 */ 2075563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_ALARM2 0xAA /* realtime status register2 */ 2085563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_ALARM3 0xAB /* realtime status register3 */ 2095563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CHASSIS 0x42 /* Bit 5: Case Open status bit */ 2105563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_CHASSIS_CLR 0x44 /* Bit 7: Case Open CLR_CHS/Reset bit */ 2115563e27dSR.Marek@sh.cvut.cz 2125563e27dSR.Marek@sh.cvut.cz /* control in0/in1 's limit modifiability */ 2135563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_VID_IN_B 0x17 2145563e27dSR.Marek@sh.cvut.cz 2155563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_VBAT 0x5D 2165563e27dSR.Marek@sh.cvut.cz #define W83792D_REG_I2C_ADDR 0x48 2175563e27dSR.Marek@sh.cvut.cz 2185563e27dSR.Marek@sh.cvut.cz /* Conversions. Rounding and limit checking is only done on the TO_REG 2195563e27dSR.Marek@sh.cvut.cz variants. Note that you should be a bit careful with which arguments 2205563e27dSR.Marek@sh.cvut.cz these macros are called: arguments may be evaluated more than once. 2215563e27dSR.Marek@sh.cvut.cz Fixing this is just not worth it. */ 2225563e27dSR.Marek@sh.cvut.cz #define IN_FROM_REG(nr,val) (((nr)<=1)?(val*2): \ 2235563e27dSR.Marek@sh.cvut.cz ((((nr)==6)||((nr)==7))?(val*6):(val*4))) 2245563e27dSR.Marek@sh.cvut.cz #define IN_TO_REG(nr,val) (((nr)<=1)?(val/2): \ 2255563e27dSR.Marek@sh.cvut.cz ((((nr)==6)||((nr)==7))?(val/6):(val/4))) 2265563e27dSR.Marek@sh.cvut.cz 2275563e27dSR.Marek@sh.cvut.cz static inline u8 2285563e27dSR.Marek@sh.cvut.cz FAN_TO_REG(long rpm, int div) 2295563e27dSR.Marek@sh.cvut.cz { 2305563e27dSR.Marek@sh.cvut.cz if (rpm == 0) 2315563e27dSR.Marek@sh.cvut.cz return 255; 2325563e27dSR.Marek@sh.cvut.cz rpm = SENSORS_LIMIT(rpm, 1, 1000000); 2335563e27dSR.Marek@sh.cvut.cz return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 2345563e27dSR.Marek@sh.cvut.cz } 2355563e27dSR.Marek@sh.cvut.cz 2365563e27dSR.Marek@sh.cvut.cz #define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \ 2375563e27dSR.Marek@sh.cvut.cz ((val) == 255 ? 0 : \ 2385563e27dSR.Marek@sh.cvut.cz 1350000 / ((val) * (div)))) 2395563e27dSR.Marek@sh.cvut.cz 2405563e27dSR.Marek@sh.cvut.cz /* for temp1 */ 2415563e27dSR.Marek@sh.cvut.cz #define TEMP1_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ 2425563e27dSR.Marek@sh.cvut.cz : (val)) / 1000, 0, 0xff)) 2435563e27dSR.Marek@sh.cvut.cz #define TEMP1_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000) 2445563e27dSR.Marek@sh.cvut.cz /* for temp2 and temp3, because they need addtional resolution */ 2455563e27dSR.Marek@sh.cvut.cz #define TEMP_ADD_FROM_REG(val1, val2) \ 2465563e27dSR.Marek@sh.cvut.cz ((((val1) & 0x80 ? (val1)-0x100 \ 2475563e27dSR.Marek@sh.cvut.cz : (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0)) 2485563e27dSR.Marek@sh.cvut.cz #define TEMP_ADD_TO_REG_HIGH(val) \ 2495563e27dSR.Marek@sh.cvut.cz (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ 2505563e27dSR.Marek@sh.cvut.cz : (val)) / 1000, 0, 0xff)) 2515563e27dSR.Marek@sh.cvut.cz #define TEMP_ADD_TO_REG_LOW(val) ((val%1000) ? 0x80 : 0x00) 2525563e27dSR.Marek@sh.cvut.cz 2535563e27dSR.Marek@sh.cvut.cz #define PWM_FROM_REG(val) (val) 2545563e27dSR.Marek@sh.cvut.cz #define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) 2555563e27dSR.Marek@sh.cvut.cz #define DIV_FROM_REG(val) (1 << (val)) 2565563e27dSR.Marek@sh.cvut.cz 2575563e27dSR.Marek@sh.cvut.cz static inline u8 2585563e27dSR.Marek@sh.cvut.cz DIV_TO_REG(long val) 2595563e27dSR.Marek@sh.cvut.cz { 2605563e27dSR.Marek@sh.cvut.cz int i; 2615563e27dSR.Marek@sh.cvut.cz val = SENSORS_LIMIT(val, 1, 128) >> 1; 2625563e27dSR.Marek@sh.cvut.cz for (i = 0; i < 6; i++) { 2635563e27dSR.Marek@sh.cvut.cz if (val == 0) 2645563e27dSR.Marek@sh.cvut.cz break; 2655563e27dSR.Marek@sh.cvut.cz val >>= 1; 2665563e27dSR.Marek@sh.cvut.cz } 2675563e27dSR.Marek@sh.cvut.cz return ((u8) i); 2685563e27dSR.Marek@sh.cvut.cz } 2695563e27dSR.Marek@sh.cvut.cz 2705563e27dSR.Marek@sh.cvut.cz struct w83792d_data { 2715563e27dSR.Marek@sh.cvut.cz struct i2c_client client; 272ce785ab4SR.Marek@sh.cvut.cz struct class_device *class_dev; 2735563e27dSR.Marek@sh.cvut.cz struct semaphore lock; 2745563e27dSR.Marek@sh.cvut.cz enum chips type; 2755563e27dSR.Marek@sh.cvut.cz 2765563e27dSR.Marek@sh.cvut.cz struct semaphore update_lock; 2775563e27dSR.Marek@sh.cvut.cz char valid; /* !=0 if following fields are valid */ 2785563e27dSR.Marek@sh.cvut.cz unsigned long last_updated; /* In jiffies */ 2795563e27dSR.Marek@sh.cvut.cz 2805563e27dSR.Marek@sh.cvut.cz /* array of 2 pointers to subclients */ 2815563e27dSR.Marek@sh.cvut.cz struct i2c_client *lm75[2]; 2825563e27dSR.Marek@sh.cvut.cz 2835563e27dSR.Marek@sh.cvut.cz u8 in[9]; /* Register value */ 2845563e27dSR.Marek@sh.cvut.cz u8 in_max[9]; /* Register value */ 2855563e27dSR.Marek@sh.cvut.cz u8 in_min[9]; /* Register value */ 2865563e27dSR.Marek@sh.cvut.cz u8 low_bits[2]; /* Additional resolution to voltage in0-6 */ 2875563e27dSR.Marek@sh.cvut.cz u8 fan[7]; /* Register value */ 2885563e27dSR.Marek@sh.cvut.cz u8 fan_min[7]; /* Register value */ 2895563e27dSR.Marek@sh.cvut.cz u8 temp1[3]; /* current, over, thyst */ 2905563e27dSR.Marek@sh.cvut.cz u8 temp_add[2][6]; /* Register value */ 2915563e27dSR.Marek@sh.cvut.cz u8 fan_div[7]; /* Register encoding, shifted right */ 2925563e27dSR.Marek@sh.cvut.cz u8 pwm[7]; /* We only consider the first 3 set of pwm, 2935563e27dSR.Marek@sh.cvut.cz although 792 chip has 7 set of pwm. */ 2945563e27dSR.Marek@sh.cvut.cz u8 pwmenable[3]; 2955563e27dSR.Marek@sh.cvut.cz u8 pwm_mode[7]; /* indicates PWM or DC mode: 1->PWM; 0->DC */ 2965563e27dSR.Marek@sh.cvut.cz u32 alarms; /* realtime status register encoding,combined */ 2975563e27dSR.Marek@sh.cvut.cz u8 chassis; /* Chassis status */ 2985563e27dSR.Marek@sh.cvut.cz u8 chassis_clear; /* CLR_CHS, clear chassis intrusion detection */ 2995563e27dSR.Marek@sh.cvut.cz u8 thermal_cruise[3]; /* Smart FanI: Fan1,2,3 target value */ 3005563e27dSR.Marek@sh.cvut.cz u8 tolerance[3]; /* Fan1,2,3 tolerance(Smart Fan I/II) */ 3015563e27dSR.Marek@sh.cvut.cz u8 sf2_points[3][4]; /* Smart FanII: Fan1,2,3 temperature points */ 3025563e27dSR.Marek@sh.cvut.cz u8 sf2_levels[3][4]; /* Smart FanII: Fan1,2,3 duty cycle levels */ 3035563e27dSR.Marek@sh.cvut.cz }; 3045563e27dSR.Marek@sh.cvut.cz 3055563e27dSR.Marek@sh.cvut.cz static int w83792d_attach_adapter(struct i2c_adapter *adapter); 3065563e27dSR.Marek@sh.cvut.cz static int w83792d_detect(struct i2c_adapter *adapter, int address, int kind); 3075563e27dSR.Marek@sh.cvut.cz static int w83792d_detach_client(struct i2c_client *client); 3085563e27dSR.Marek@sh.cvut.cz 3095563e27dSR.Marek@sh.cvut.cz static int w83792d_read_value(struct i2c_client *client, u8 register); 3105563e27dSR.Marek@sh.cvut.cz static int w83792d_write_value(struct i2c_client *client, u8 register, 3115563e27dSR.Marek@sh.cvut.cz u8 value); 3125563e27dSR.Marek@sh.cvut.cz static struct w83792d_data *w83792d_update_device(struct device *dev); 3135563e27dSR.Marek@sh.cvut.cz 3145563e27dSR.Marek@sh.cvut.cz #ifdef DEBUG 3155563e27dSR.Marek@sh.cvut.cz static void w83792d_print_debug(struct w83792d_data *data, struct device *dev); 3165563e27dSR.Marek@sh.cvut.cz #endif 3175563e27dSR.Marek@sh.cvut.cz 3185563e27dSR.Marek@sh.cvut.cz static void w83792d_init_client(struct i2c_client *client); 3195563e27dSR.Marek@sh.cvut.cz 3205563e27dSR.Marek@sh.cvut.cz static struct i2c_driver w83792d_driver = { 3215563e27dSR.Marek@sh.cvut.cz .owner = THIS_MODULE, 3225563e27dSR.Marek@sh.cvut.cz .name = "w83792d", 3235563e27dSR.Marek@sh.cvut.cz .flags = I2C_DF_NOTIFY, 3245563e27dSR.Marek@sh.cvut.cz .attach_adapter = w83792d_attach_adapter, 3255563e27dSR.Marek@sh.cvut.cz .detach_client = w83792d_detach_client, 3265563e27dSR.Marek@sh.cvut.cz }; 3275563e27dSR.Marek@sh.cvut.cz 3285563e27dSR.Marek@sh.cvut.cz static long in_count_from_reg(int nr, struct w83792d_data *data) 3295563e27dSR.Marek@sh.cvut.cz { 3305563e27dSR.Marek@sh.cvut.cz u16 vol_count = data->in[nr]; 3315563e27dSR.Marek@sh.cvut.cz u16 low_bits = 0; 3325563e27dSR.Marek@sh.cvut.cz vol_count = (vol_count << 2); 3335563e27dSR.Marek@sh.cvut.cz switch (nr) 3345563e27dSR.Marek@sh.cvut.cz { 3355563e27dSR.Marek@sh.cvut.cz case 0: /* vin0 */ 3365563e27dSR.Marek@sh.cvut.cz low_bits = (data->low_bits[0]) & 0x03; 3375563e27dSR.Marek@sh.cvut.cz break; 3385563e27dSR.Marek@sh.cvut.cz case 1: /* vin1 */ 3395563e27dSR.Marek@sh.cvut.cz low_bits = ((data->low_bits[0]) & 0x0c) >> 2; 3405563e27dSR.Marek@sh.cvut.cz break; 3415563e27dSR.Marek@sh.cvut.cz case 2: /* vin2 */ 3425563e27dSR.Marek@sh.cvut.cz low_bits = ((data->low_bits[0]) & 0x30) >> 4; 3435563e27dSR.Marek@sh.cvut.cz break; 3445563e27dSR.Marek@sh.cvut.cz case 3: /* vin3 */ 3455563e27dSR.Marek@sh.cvut.cz low_bits = ((data->low_bits[0]) & 0xc0) >> 6; 3465563e27dSR.Marek@sh.cvut.cz break; 3475563e27dSR.Marek@sh.cvut.cz case 4: /* vin4 */ 3485563e27dSR.Marek@sh.cvut.cz low_bits = (data->low_bits[1]) & 0x03; 3495563e27dSR.Marek@sh.cvut.cz break; 3505563e27dSR.Marek@sh.cvut.cz case 5: /* vin5 */ 3515563e27dSR.Marek@sh.cvut.cz low_bits = ((data->low_bits[1]) & 0x0c) >> 2; 3525563e27dSR.Marek@sh.cvut.cz break; 3535563e27dSR.Marek@sh.cvut.cz case 6: /* vin6 */ 3545563e27dSR.Marek@sh.cvut.cz low_bits = ((data->low_bits[1]) & 0x30) >> 4; 3555563e27dSR.Marek@sh.cvut.cz default: 3565563e27dSR.Marek@sh.cvut.cz break; 3575563e27dSR.Marek@sh.cvut.cz } 3585563e27dSR.Marek@sh.cvut.cz vol_count = vol_count | low_bits; 3595563e27dSR.Marek@sh.cvut.cz return vol_count; 3605563e27dSR.Marek@sh.cvut.cz } 3615563e27dSR.Marek@sh.cvut.cz 3625563e27dSR.Marek@sh.cvut.cz /* following are the sysfs callback functions */ 3635563e27dSR.Marek@sh.cvut.cz static ssize_t show_in(struct device *dev, struct device_attribute *attr, 3645563e27dSR.Marek@sh.cvut.cz char *buf) 3655563e27dSR.Marek@sh.cvut.cz { 3665563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 3675563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; 3685563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 3695563e27dSR.Marek@sh.cvut.cz return sprintf(buf,"%ld\n", IN_FROM_REG(nr,(in_count_from_reg(nr, data)))); 3705563e27dSR.Marek@sh.cvut.cz } 3715563e27dSR.Marek@sh.cvut.cz 3725563e27dSR.Marek@sh.cvut.cz #define show_in_reg(reg) \ 3735563e27dSR.Marek@sh.cvut.cz static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ 3745563e27dSR.Marek@sh.cvut.cz char *buf) \ 3755563e27dSR.Marek@sh.cvut.cz { \ 3765563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 3775563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; \ 3785563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); \ 3795563e27dSR.Marek@sh.cvut.cz return sprintf(buf,"%ld\n", (long)(IN_FROM_REG(nr, (data->reg[nr])*4))); \ 3805563e27dSR.Marek@sh.cvut.cz } 3815563e27dSR.Marek@sh.cvut.cz 3825563e27dSR.Marek@sh.cvut.cz show_in_reg(in_min); 3835563e27dSR.Marek@sh.cvut.cz show_in_reg(in_max); 3845563e27dSR.Marek@sh.cvut.cz 3855563e27dSR.Marek@sh.cvut.cz #define store_in_reg(REG, reg) \ 3865563e27dSR.Marek@sh.cvut.cz static ssize_t store_in_##reg (struct device *dev, \ 3875563e27dSR.Marek@sh.cvut.cz struct device_attribute *attr, \ 3885563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) \ 3895563e27dSR.Marek@sh.cvut.cz { \ 3905563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 3915563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; \ 3925563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); \ 3935563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); \ 3945563e27dSR.Marek@sh.cvut.cz u32 val; \ 3955563e27dSR.Marek@sh.cvut.cz \ 3965563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); \ 3975563e27dSR.Marek@sh.cvut.cz data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val)/4, 0, 255); \ 3985563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_IN_##REG[nr], data->in_##reg[nr]); \ 3995563e27dSR.Marek@sh.cvut.cz \ 4005563e27dSR.Marek@sh.cvut.cz return count; \ 4015563e27dSR.Marek@sh.cvut.cz } 4025563e27dSR.Marek@sh.cvut.cz store_in_reg(MIN, min); 4035563e27dSR.Marek@sh.cvut.cz store_in_reg(MAX, max); 4045563e27dSR.Marek@sh.cvut.cz 4055563e27dSR.Marek@sh.cvut.cz #define sysfs_in_reg(offset) \ 4065563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in, \ 4075563e27dSR.Marek@sh.cvut.cz NULL, offset); \ 4085563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 4095563e27dSR.Marek@sh.cvut.cz show_in_min, store_in_min, offset); \ 4105563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 4115563e27dSR.Marek@sh.cvut.cz show_in_max, store_in_max, offset); 4125563e27dSR.Marek@sh.cvut.cz 4135563e27dSR.Marek@sh.cvut.cz sysfs_in_reg(0); 4145563e27dSR.Marek@sh.cvut.cz sysfs_in_reg(1); 4155563e27dSR.Marek@sh.cvut.cz sysfs_in_reg(2); 4165563e27dSR.Marek@sh.cvut.cz sysfs_in_reg(3); 4175563e27dSR.Marek@sh.cvut.cz sysfs_in_reg(4); 4185563e27dSR.Marek@sh.cvut.cz sysfs_in_reg(5); 4195563e27dSR.Marek@sh.cvut.cz sysfs_in_reg(6); 4205563e27dSR.Marek@sh.cvut.cz sysfs_in_reg(7); 4215563e27dSR.Marek@sh.cvut.cz sysfs_in_reg(8); 4225563e27dSR.Marek@sh.cvut.cz 4235563e27dSR.Marek@sh.cvut.cz #define device_create_file_in(client, offset) \ 4245563e27dSR.Marek@sh.cvut.cz do { \ 4255563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_in##offset##_input.dev_attr); \ 4265563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_in##offset##_max.dev_attr); \ 4275563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_in##offset##_min.dev_attr); \ 4285563e27dSR.Marek@sh.cvut.cz } while (0) 4295563e27dSR.Marek@sh.cvut.cz 4305563e27dSR.Marek@sh.cvut.cz #define show_fan_reg(reg) \ 4315563e27dSR.Marek@sh.cvut.cz static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \ 4325563e27dSR.Marek@sh.cvut.cz char *buf) \ 4335563e27dSR.Marek@sh.cvut.cz { \ 4345563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 4355563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index - 1; \ 4365563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); \ 4375563e27dSR.Marek@sh.cvut.cz return sprintf(buf,"%d\n", \ 4385563e27dSR.Marek@sh.cvut.cz FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \ 4395563e27dSR.Marek@sh.cvut.cz } 4405563e27dSR.Marek@sh.cvut.cz 4415563e27dSR.Marek@sh.cvut.cz show_fan_reg(fan); 4425563e27dSR.Marek@sh.cvut.cz show_fan_reg(fan_min); 4435563e27dSR.Marek@sh.cvut.cz 4445563e27dSR.Marek@sh.cvut.cz static ssize_t 4455563e27dSR.Marek@sh.cvut.cz store_fan_min(struct device *dev, struct device_attribute *attr, 4465563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 4475563e27dSR.Marek@sh.cvut.cz { 4485563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 4495563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index - 1; 4505563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 4515563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 4525563e27dSR.Marek@sh.cvut.cz u32 val; 4535563e27dSR.Marek@sh.cvut.cz 4545563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); 4555563e27dSR.Marek@sh.cvut.cz data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 4565563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], 4575563e27dSR.Marek@sh.cvut.cz data->fan_min[nr]); 4585563e27dSR.Marek@sh.cvut.cz 4595563e27dSR.Marek@sh.cvut.cz return count; 4605563e27dSR.Marek@sh.cvut.cz } 4615563e27dSR.Marek@sh.cvut.cz 4625563e27dSR.Marek@sh.cvut.cz static ssize_t 4635563e27dSR.Marek@sh.cvut.cz show_fan_div(struct device *dev, struct device_attribute *attr, 4645563e27dSR.Marek@sh.cvut.cz char *buf) 4655563e27dSR.Marek@sh.cvut.cz { 4665563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 4675563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; 4685563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 4695563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1])); 4705563e27dSR.Marek@sh.cvut.cz } 4715563e27dSR.Marek@sh.cvut.cz 4725563e27dSR.Marek@sh.cvut.cz /* Note: we save and restore the fan minimum here, because its value is 4735563e27dSR.Marek@sh.cvut.cz determined in part by the fan divisor. This follows the principle of 4745563e27dSR.Marek@sh.cvut.cz least suprise; the user doesn't expect the fan minimum to change just 4755563e27dSR.Marek@sh.cvut.cz because the divisor changed. */ 4765563e27dSR.Marek@sh.cvut.cz static ssize_t 4775563e27dSR.Marek@sh.cvut.cz store_fan_div(struct device *dev, struct device_attribute *attr, 4785563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 4795563e27dSR.Marek@sh.cvut.cz { 4805563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 4815563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index - 1; 4825563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 4835563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 4845563e27dSR.Marek@sh.cvut.cz unsigned long min; 4855563e27dSR.Marek@sh.cvut.cz /*u8 reg;*/ 4865563e27dSR.Marek@sh.cvut.cz u8 fan_div_reg = 0; 4875563e27dSR.Marek@sh.cvut.cz u8 tmp_fan_div; 4885563e27dSR.Marek@sh.cvut.cz 4895563e27dSR.Marek@sh.cvut.cz /* Save fan_min */ 4905563e27dSR.Marek@sh.cvut.cz min = FAN_FROM_REG(data->fan_min[nr], 4915563e27dSR.Marek@sh.cvut.cz DIV_FROM_REG(data->fan_div[nr])); 4925563e27dSR.Marek@sh.cvut.cz 4935563e27dSR.Marek@sh.cvut.cz data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10)); 4945563e27dSR.Marek@sh.cvut.cz 4955563e27dSR.Marek@sh.cvut.cz fan_div_reg = w83792d_read_value(client, W83792D_REG_FAN_DIV[nr >> 1]); 4965563e27dSR.Marek@sh.cvut.cz fan_div_reg &= (nr & 0x01) ? 0x8f : 0xf8; 4975563e27dSR.Marek@sh.cvut.cz tmp_fan_div = (nr & 0x01) ? (((data->fan_div[nr]) << 4) & 0x70) 4985563e27dSR.Marek@sh.cvut.cz : ((data->fan_div[nr]) & 0x07); 4995563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_FAN_DIV[nr >> 1], 5005563e27dSR.Marek@sh.cvut.cz fan_div_reg | tmp_fan_div); 5015563e27dSR.Marek@sh.cvut.cz 5025563e27dSR.Marek@sh.cvut.cz /* Restore fan_min */ 5035563e27dSR.Marek@sh.cvut.cz data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 5045563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], data->fan_min[nr]); 5055563e27dSR.Marek@sh.cvut.cz 5065563e27dSR.Marek@sh.cvut.cz return count; 5075563e27dSR.Marek@sh.cvut.cz } 5085563e27dSR.Marek@sh.cvut.cz 5095563e27dSR.Marek@sh.cvut.cz #define sysfs_fan(offset) \ 5105563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL, \ 5115563e27dSR.Marek@sh.cvut.cz offset); \ 5125563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ 5135563e27dSR.Marek@sh.cvut.cz show_fan_div, store_fan_div, offset); \ 5145563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 5155563e27dSR.Marek@sh.cvut.cz show_fan_min, store_fan_min, offset); 5165563e27dSR.Marek@sh.cvut.cz 5175563e27dSR.Marek@sh.cvut.cz sysfs_fan(1); 5185563e27dSR.Marek@sh.cvut.cz sysfs_fan(2); 5195563e27dSR.Marek@sh.cvut.cz sysfs_fan(3); 5205563e27dSR.Marek@sh.cvut.cz sysfs_fan(4); 5215563e27dSR.Marek@sh.cvut.cz sysfs_fan(5); 5225563e27dSR.Marek@sh.cvut.cz sysfs_fan(6); 5235563e27dSR.Marek@sh.cvut.cz sysfs_fan(7); 5245563e27dSR.Marek@sh.cvut.cz 5255563e27dSR.Marek@sh.cvut.cz #define device_create_file_fan(client, offset) \ 5265563e27dSR.Marek@sh.cvut.cz do { \ 5275563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_input.dev_attr); \ 5285563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_div.dev_attr); \ 5295563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_min.dev_attr); \ 5305563e27dSR.Marek@sh.cvut.cz } while (0) 5315563e27dSR.Marek@sh.cvut.cz 5325563e27dSR.Marek@sh.cvut.cz 5335563e27dSR.Marek@sh.cvut.cz /* read/write the temperature1, includes measured value and limits */ 5345563e27dSR.Marek@sh.cvut.cz 5355563e27dSR.Marek@sh.cvut.cz static ssize_t show_temp1(struct device *dev, struct device_attribute *attr, 5365563e27dSR.Marek@sh.cvut.cz char *buf) 5375563e27dSR.Marek@sh.cvut.cz { 5385563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 5395563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; 5405563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 5415563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[nr])); 5425563e27dSR.Marek@sh.cvut.cz } 5435563e27dSR.Marek@sh.cvut.cz 5445563e27dSR.Marek@sh.cvut.cz static ssize_t store_temp1(struct device *dev, struct device_attribute *attr, 5455563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 5465563e27dSR.Marek@sh.cvut.cz { 5475563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 5485563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; 5495563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 5505563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 5515563e27dSR.Marek@sh.cvut.cz s32 val; 5525563e27dSR.Marek@sh.cvut.cz 5535563e27dSR.Marek@sh.cvut.cz val = simple_strtol(buf, NULL, 10); 5545563e27dSR.Marek@sh.cvut.cz 5555563e27dSR.Marek@sh.cvut.cz data->temp1[nr] = TEMP1_TO_REG(val); 5565563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_TEMP1[nr], 5575563e27dSR.Marek@sh.cvut.cz data->temp1[nr]); 5585563e27dSR.Marek@sh.cvut.cz 5595563e27dSR.Marek@sh.cvut.cz return count; 5605563e27dSR.Marek@sh.cvut.cz } 5615563e27dSR.Marek@sh.cvut.cz 5625563e27dSR.Marek@sh.cvut.cz 5635563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0); 5645563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp1, 5655563e27dSR.Marek@sh.cvut.cz store_temp1, 1); 5665563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1, 5675563e27dSR.Marek@sh.cvut.cz store_temp1, 2); 5685563e27dSR.Marek@sh.cvut.cz 5695563e27dSR.Marek@sh.cvut.cz #define device_create_file_temp1(client) \ 5705563e27dSR.Marek@sh.cvut.cz do { \ 5715563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_temp1_input.dev_attr); \ 5725563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_temp1_max.dev_attr); \ 5735563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_temp1_max_hyst.dev_attr); \ 5745563e27dSR.Marek@sh.cvut.cz } while (0) 5755563e27dSR.Marek@sh.cvut.cz 5765563e27dSR.Marek@sh.cvut.cz 5775563e27dSR.Marek@sh.cvut.cz /* read/write the temperature2-3, includes measured value and limits */ 5785563e27dSR.Marek@sh.cvut.cz 5795563e27dSR.Marek@sh.cvut.cz static ssize_t show_temp23(struct device *dev, struct device_attribute *attr, 5805563e27dSR.Marek@sh.cvut.cz char *buf) 5815563e27dSR.Marek@sh.cvut.cz { 5825563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 5835563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->nr; 5845563e27dSR.Marek@sh.cvut.cz int index = sensor_attr->index; 5855563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 5865563e27dSR.Marek@sh.cvut.cz return sprintf(buf,"%ld\n", 5875563e27dSR.Marek@sh.cvut.cz (long)TEMP_ADD_FROM_REG(data->temp_add[nr][index], 5885563e27dSR.Marek@sh.cvut.cz data->temp_add[nr][index+1])); 5895563e27dSR.Marek@sh.cvut.cz } 5905563e27dSR.Marek@sh.cvut.cz 5915563e27dSR.Marek@sh.cvut.cz static ssize_t store_temp23(struct device *dev, struct device_attribute *attr, 5925563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 5935563e27dSR.Marek@sh.cvut.cz { 5945563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 5955563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->nr; 5965563e27dSR.Marek@sh.cvut.cz int index = sensor_attr->index; 5975563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 5985563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 5995563e27dSR.Marek@sh.cvut.cz s32 val; 6005563e27dSR.Marek@sh.cvut.cz 6015563e27dSR.Marek@sh.cvut.cz val = simple_strtol(buf, NULL, 10); 6025563e27dSR.Marek@sh.cvut.cz 6035563e27dSR.Marek@sh.cvut.cz data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val); 6045563e27dSR.Marek@sh.cvut.cz data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val); 6055563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index], 6065563e27dSR.Marek@sh.cvut.cz data->temp_add[nr][index]); 6075563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index+1], 6085563e27dSR.Marek@sh.cvut.cz data->temp_add[nr][index+1]); 6095563e27dSR.Marek@sh.cvut.cz 6105563e27dSR.Marek@sh.cvut.cz return count; 6115563e27dSR.Marek@sh.cvut.cz } 6125563e27dSR.Marek@sh.cvut.cz 6135563e27dSR.Marek@sh.cvut.cz #define sysfs_temp23(name,idx) \ 6145563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR_2(name##_input, S_IRUGO, show_temp23, NULL, \ 6155563e27dSR.Marek@sh.cvut.cz idx, 0); \ 6165563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR_2(name##_max, S_IRUGO | S_IWUSR, \ 6175563e27dSR.Marek@sh.cvut.cz show_temp23, store_temp23, idx, 2); \ 6185563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR_2(name##_max_hyst, S_IRUGO | S_IWUSR, \ 6195563e27dSR.Marek@sh.cvut.cz show_temp23, store_temp23, idx, 4); 6205563e27dSR.Marek@sh.cvut.cz 6215563e27dSR.Marek@sh.cvut.cz sysfs_temp23(temp2,0) 6225563e27dSR.Marek@sh.cvut.cz sysfs_temp23(temp3,1) 6235563e27dSR.Marek@sh.cvut.cz 6245563e27dSR.Marek@sh.cvut.cz #define device_create_file_temp_add(client, offset) \ 6255563e27dSR.Marek@sh.cvut.cz do { \ 6265563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_temp##offset##_input.dev_attr); \ 6275563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_temp##offset##_max.dev_attr); \ 6285563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, \ 6295563e27dSR.Marek@sh.cvut.cz &sensor_dev_attr_temp##offset##_max_hyst.dev_attr); \ 6305563e27dSR.Marek@sh.cvut.cz } while (0) 6315563e27dSR.Marek@sh.cvut.cz 6325563e27dSR.Marek@sh.cvut.cz 6335563e27dSR.Marek@sh.cvut.cz /* get reatime status of all sensors items: voltage, temp, fan */ 6345563e27dSR.Marek@sh.cvut.cz static ssize_t 6355563e27dSR.Marek@sh.cvut.cz show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 6365563e27dSR.Marek@sh.cvut.cz { 6375563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 6385563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%d\n", data->alarms); 6395563e27dSR.Marek@sh.cvut.cz } 6405563e27dSR.Marek@sh.cvut.cz 6415563e27dSR.Marek@sh.cvut.cz static 6425563e27dSR.Marek@sh.cvut.cz DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 6435563e27dSR.Marek@sh.cvut.cz #define device_create_file_alarms(client) \ 6445563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &dev_attr_alarms); 6455563e27dSR.Marek@sh.cvut.cz 6465563e27dSR.Marek@sh.cvut.cz 6475563e27dSR.Marek@sh.cvut.cz 6485563e27dSR.Marek@sh.cvut.cz static ssize_t 6495563e27dSR.Marek@sh.cvut.cz show_pwm(struct device *dev, struct device_attribute *attr, 6505563e27dSR.Marek@sh.cvut.cz char *buf) 6515563e27dSR.Marek@sh.cvut.cz { 6525563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 6535563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; 6545563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 6555563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%ld\n", (long) PWM_FROM_REG(data->pwm[nr-1])); 6565563e27dSR.Marek@sh.cvut.cz } 6575563e27dSR.Marek@sh.cvut.cz 6585563e27dSR.Marek@sh.cvut.cz static ssize_t 6595563e27dSR.Marek@sh.cvut.cz show_pwmenable(struct device *dev, struct device_attribute *attr, 6605563e27dSR.Marek@sh.cvut.cz char *buf) 6615563e27dSR.Marek@sh.cvut.cz { 6625563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 6635563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index - 1; 6645563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 6655563e27dSR.Marek@sh.cvut.cz long pwm_enable_tmp = 1; 6665563e27dSR.Marek@sh.cvut.cz 6675563e27dSR.Marek@sh.cvut.cz switch (data->pwmenable[nr]) { 6685563e27dSR.Marek@sh.cvut.cz case 0: 6695563e27dSR.Marek@sh.cvut.cz pwm_enable_tmp = 1; /* manual mode */ 6705563e27dSR.Marek@sh.cvut.cz break; 6715563e27dSR.Marek@sh.cvut.cz case 1: 6725563e27dSR.Marek@sh.cvut.cz pwm_enable_tmp = 3; /*thermal cruise/Smart Fan I */ 6735563e27dSR.Marek@sh.cvut.cz break; 6745563e27dSR.Marek@sh.cvut.cz case 2: 6755563e27dSR.Marek@sh.cvut.cz pwm_enable_tmp = 2; /* Smart Fan II */ 6765563e27dSR.Marek@sh.cvut.cz break; 6775563e27dSR.Marek@sh.cvut.cz } 6785563e27dSR.Marek@sh.cvut.cz 6795563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%ld\n", pwm_enable_tmp); 6805563e27dSR.Marek@sh.cvut.cz } 6815563e27dSR.Marek@sh.cvut.cz 6825563e27dSR.Marek@sh.cvut.cz static ssize_t 6835563e27dSR.Marek@sh.cvut.cz store_pwm(struct device *dev, struct device_attribute *attr, 6845563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 6855563e27dSR.Marek@sh.cvut.cz { 6865563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 6875563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index - 1; 6885563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 6895563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 6905563e27dSR.Marek@sh.cvut.cz u32 val; 6915563e27dSR.Marek@sh.cvut.cz 6925563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); 6935563e27dSR.Marek@sh.cvut.cz data->pwm[nr] = PWM_TO_REG(val); 6945563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]); 6955563e27dSR.Marek@sh.cvut.cz 6965563e27dSR.Marek@sh.cvut.cz return count; 6975563e27dSR.Marek@sh.cvut.cz } 6985563e27dSR.Marek@sh.cvut.cz 6995563e27dSR.Marek@sh.cvut.cz static ssize_t 7005563e27dSR.Marek@sh.cvut.cz store_pwmenable(struct device *dev, struct device_attribute *attr, 7015563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 7025563e27dSR.Marek@sh.cvut.cz { 7035563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 7045563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index - 1; 7055563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 7065563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 7075563e27dSR.Marek@sh.cvut.cz u32 val; 7085563e27dSR.Marek@sh.cvut.cz u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp; 7095563e27dSR.Marek@sh.cvut.cz 7105563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); 7115563e27dSR.Marek@sh.cvut.cz switch (val) { 7125563e27dSR.Marek@sh.cvut.cz case 1: 7135563e27dSR.Marek@sh.cvut.cz data->pwmenable[nr] = 0; /* manual mode */ 7145563e27dSR.Marek@sh.cvut.cz break; 7155563e27dSR.Marek@sh.cvut.cz case 2: 7165563e27dSR.Marek@sh.cvut.cz data->pwmenable[nr] = 2; /* Smart Fan II */ 7175563e27dSR.Marek@sh.cvut.cz break; 7185563e27dSR.Marek@sh.cvut.cz case 3: 7195563e27dSR.Marek@sh.cvut.cz data->pwmenable[nr] = 1; /* thermal cruise/Smart Fan I */ 7205563e27dSR.Marek@sh.cvut.cz break; 7215563e27dSR.Marek@sh.cvut.cz default: 7225563e27dSR.Marek@sh.cvut.cz return -EINVAL; 7235563e27dSR.Marek@sh.cvut.cz } 7245563e27dSR.Marek@sh.cvut.cz cfg1_tmp = data->pwmenable[0]; 7255563e27dSR.Marek@sh.cvut.cz cfg2_tmp = (data->pwmenable[1]) << 2; 7265563e27dSR.Marek@sh.cvut.cz cfg3_tmp = (data->pwmenable[2]) << 4; 7275563e27dSR.Marek@sh.cvut.cz cfg4_tmp = w83792d_read_value(client,W83792D_REG_FAN_CFG) & 0xc0; 7285563e27dSR.Marek@sh.cvut.cz fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp; 7295563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp); 7305563e27dSR.Marek@sh.cvut.cz 7315563e27dSR.Marek@sh.cvut.cz return count; 7325563e27dSR.Marek@sh.cvut.cz } 7335563e27dSR.Marek@sh.cvut.cz 7345563e27dSR.Marek@sh.cvut.cz #define sysfs_pwm(offset) \ 7355563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ 7365563e27dSR.Marek@sh.cvut.cz show_pwm, store_pwm, offset); \ 7375563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ 7385563e27dSR.Marek@sh.cvut.cz show_pwmenable, store_pwmenable, offset); \ 7395563e27dSR.Marek@sh.cvut.cz 7405563e27dSR.Marek@sh.cvut.cz sysfs_pwm(1); 7415563e27dSR.Marek@sh.cvut.cz sysfs_pwm(2); 7425563e27dSR.Marek@sh.cvut.cz sysfs_pwm(3); 7435563e27dSR.Marek@sh.cvut.cz 7445563e27dSR.Marek@sh.cvut.cz 7455563e27dSR.Marek@sh.cvut.cz #define device_create_file_pwm(client, offset) \ 7465563e27dSR.Marek@sh.cvut.cz do { \ 7475563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_pwm##offset.dev_attr); \ 7485563e27dSR.Marek@sh.cvut.cz } while (0) 7495563e27dSR.Marek@sh.cvut.cz 7505563e27dSR.Marek@sh.cvut.cz #define device_create_file_pwmenable(client, offset) \ 7515563e27dSR.Marek@sh.cvut.cz do { \ 7525563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_pwm##offset##_enable.dev_attr); \ 7535563e27dSR.Marek@sh.cvut.cz } while (0) 7545563e27dSR.Marek@sh.cvut.cz 7555563e27dSR.Marek@sh.cvut.cz 7565563e27dSR.Marek@sh.cvut.cz static ssize_t 7575563e27dSR.Marek@sh.cvut.cz show_pwm_mode(struct device *dev, struct device_attribute *attr, 7585563e27dSR.Marek@sh.cvut.cz char *buf) 7595563e27dSR.Marek@sh.cvut.cz { 7605563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 7615563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; 7625563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 7635563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%d\n", data->pwm_mode[nr-1]); 7645563e27dSR.Marek@sh.cvut.cz } 7655563e27dSR.Marek@sh.cvut.cz 7665563e27dSR.Marek@sh.cvut.cz static ssize_t 7675563e27dSR.Marek@sh.cvut.cz store_pwm_mode(struct device *dev, struct device_attribute *attr, 7685563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 7695563e27dSR.Marek@sh.cvut.cz { 7705563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 7715563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index - 1; 7725563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 7735563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 7745563e27dSR.Marek@sh.cvut.cz u32 val; 7755563e27dSR.Marek@sh.cvut.cz u8 pwm_mode_mask = 0; 7765563e27dSR.Marek@sh.cvut.cz 7775563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); 7785563e27dSR.Marek@sh.cvut.cz data->pwm_mode[nr] = SENSORS_LIMIT(val, 0, 1); 7795563e27dSR.Marek@sh.cvut.cz pwm_mode_mask = w83792d_read_value(client, 7805563e27dSR.Marek@sh.cvut.cz W83792D_REG_PWM[nr]) & 0x7f; 7815563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_PWM[nr], 7825563e27dSR.Marek@sh.cvut.cz ((data->pwm_mode[nr]) << 7) | pwm_mode_mask); 7835563e27dSR.Marek@sh.cvut.cz 7845563e27dSR.Marek@sh.cvut.cz return count; 7855563e27dSR.Marek@sh.cvut.cz } 7865563e27dSR.Marek@sh.cvut.cz 7875563e27dSR.Marek@sh.cvut.cz #define sysfs_pwm_mode(offset) \ 7885563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(pwm##offset##_mode, S_IRUGO | S_IWUSR, \ 7895563e27dSR.Marek@sh.cvut.cz show_pwm_mode, store_pwm_mode, offset); 7905563e27dSR.Marek@sh.cvut.cz 7915563e27dSR.Marek@sh.cvut.cz sysfs_pwm_mode(1); 7925563e27dSR.Marek@sh.cvut.cz sysfs_pwm_mode(2); 7935563e27dSR.Marek@sh.cvut.cz sysfs_pwm_mode(3); 7945563e27dSR.Marek@sh.cvut.cz 7955563e27dSR.Marek@sh.cvut.cz #define device_create_file_pwm_mode(client, offset) \ 7965563e27dSR.Marek@sh.cvut.cz do { \ 7975563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_pwm##offset##_mode.dev_attr); \ 7985563e27dSR.Marek@sh.cvut.cz } while (0) 7995563e27dSR.Marek@sh.cvut.cz 8005563e27dSR.Marek@sh.cvut.cz 8015563e27dSR.Marek@sh.cvut.cz static ssize_t 8025563e27dSR.Marek@sh.cvut.cz show_regs_chassis(struct device *dev, struct device_attribute *attr, 8035563e27dSR.Marek@sh.cvut.cz char *buf) 8045563e27dSR.Marek@sh.cvut.cz { 8055563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 8065563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%d\n", data->chassis); 8075563e27dSR.Marek@sh.cvut.cz } 8085563e27dSR.Marek@sh.cvut.cz 8095563e27dSR.Marek@sh.cvut.cz static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL); 8105563e27dSR.Marek@sh.cvut.cz 8115563e27dSR.Marek@sh.cvut.cz #define device_create_file_chassis(client) \ 8125563e27dSR.Marek@sh.cvut.cz do { \ 8135563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &dev_attr_chassis); \ 8145563e27dSR.Marek@sh.cvut.cz } while (0) 8155563e27dSR.Marek@sh.cvut.cz 8165563e27dSR.Marek@sh.cvut.cz 8175563e27dSR.Marek@sh.cvut.cz static ssize_t 8185563e27dSR.Marek@sh.cvut.cz show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf) 8195563e27dSR.Marek@sh.cvut.cz { 8205563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 8215563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%d\n", data->chassis_clear); 8225563e27dSR.Marek@sh.cvut.cz } 8235563e27dSR.Marek@sh.cvut.cz 8245563e27dSR.Marek@sh.cvut.cz static ssize_t 8255563e27dSR.Marek@sh.cvut.cz store_chassis_clear(struct device *dev, struct device_attribute *attr, 8265563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 8275563e27dSR.Marek@sh.cvut.cz { 8285563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 8295563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 8305563e27dSR.Marek@sh.cvut.cz u32 val; 8315563e27dSR.Marek@sh.cvut.cz u8 temp1 = 0, temp2 = 0; 8325563e27dSR.Marek@sh.cvut.cz 8335563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); 8345563e27dSR.Marek@sh.cvut.cz 8355563e27dSR.Marek@sh.cvut.cz data->chassis_clear = SENSORS_LIMIT(val, 0 ,1); 8365563e27dSR.Marek@sh.cvut.cz temp1 = ((data->chassis_clear) << 7) & 0x80; 8375563e27dSR.Marek@sh.cvut.cz temp2 = w83792d_read_value(client, 8385563e27dSR.Marek@sh.cvut.cz W83792D_REG_CHASSIS_CLR) & 0x7f; 8395563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, temp1 | temp2); 8405563e27dSR.Marek@sh.cvut.cz 8415563e27dSR.Marek@sh.cvut.cz return count; 8425563e27dSR.Marek@sh.cvut.cz } 8435563e27dSR.Marek@sh.cvut.cz 8445563e27dSR.Marek@sh.cvut.cz static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR, 8455563e27dSR.Marek@sh.cvut.cz show_chassis_clear, store_chassis_clear); 8465563e27dSR.Marek@sh.cvut.cz 8475563e27dSR.Marek@sh.cvut.cz #define device_create_file_chassis_clear(client) \ 8485563e27dSR.Marek@sh.cvut.cz do { \ 8495563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &dev_attr_chassis_clear); \ 8505563e27dSR.Marek@sh.cvut.cz } while (0) 8515563e27dSR.Marek@sh.cvut.cz 8525563e27dSR.Marek@sh.cvut.cz 8535563e27dSR.Marek@sh.cvut.cz 8545563e27dSR.Marek@sh.cvut.cz /* For Smart Fan I / Thermal Cruise */ 8555563e27dSR.Marek@sh.cvut.cz static ssize_t 8565563e27dSR.Marek@sh.cvut.cz show_thermal_cruise(struct device *dev, struct device_attribute *attr, 8575563e27dSR.Marek@sh.cvut.cz char *buf) 8585563e27dSR.Marek@sh.cvut.cz { 8595563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 8605563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; 8615563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 8625563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%ld\n", (long)data->thermal_cruise[nr-1]); 8635563e27dSR.Marek@sh.cvut.cz } 8645563e27dSR.Marek@sh.cvut.cz 8655563e27dSR.Marek@sh.cvut.cz static ssize_t 8665563e27dSR.Marek@sh.cvut.cz store_thermal_cruise(struct device *dev, struct device_attribute *attr, 8675563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 8685563e27dSR.Marek@sh.cvut.cz { 8695563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 8705563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index - 1; 8715563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 8725563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 8735563e27dSR.Marek@sh.cvut.cz u32 val; 8745563e27dSR.Marek@sh.cvut.cz u8 target_tmp=0, target_mask=0; 8755563e27dSR.Marek@sh.cvut.cz 8765563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); 8775563e27dSR.Marek@sh.cvut.cz target_tmp = val; 8785563e27dSR.Marek@sh.cvut.cz target_tmp = target_tmp & 0x7f; 8795563e27dSR.Marek@sh.cvut.cz target_mask = w83792d_read_value(client, W83792D_REG_THERMAL[nr]) & 0x80; 8805563e27dSR.Marek@sh.cvut.cz data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255); 8815563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_THERMAL[nr], 8825563e27dSR.Marek@sh.cvut.cz (data->thermal_cruise[nr]) | target_mask); 8835563e27dSR.Marek@sh.cvut.cz 8845563e27dSR.Marek@sh.cvut.cz return count; 8855563e27dSR.Marek@sh.cvut.cz } 8865563e27dSR.Marek@sh.cvut.cz 8875563e27dSR.Marek@sh.cvut.cz #define sysfs_thermal_cruise(offset) \ 8885563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(thermal_cruise##offset, S_IRUGO | S_IWUSR, \ 8895563e27dSR.Marek@sh.cvut.cz show_thermal_cruise, store_thermal_cruise, offset); 8905563e27dSR.Marek@sh.cvut.cz 8915563e27dSR.Marek@sh.cvut.cz sysfs_thermal_cruise(1); 8925563e27dSR.Marek@sh.cvut.cz sysfs_thermal_cruise(2); 8935563e27dSR.Marek@sh.cvut.cz sysfs_thermal_cruise(3); 8945563e27dSR.Marek@sh.cvut.cz 8955563e27dSR.Marek@sh.cvut.cz #define device_create_file_thermal_cruise(client, offset) \ 8965563e27dSR.Marek@sh.cvut.cz do { \ 8975563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, \ 8985563e27dSR.Marek@sh.cvut.cz &sensor_dev_attr_thermal_cruise##offset.dev_attr); \ 8995563e27dSR.Marek@sh.cvut.cz } while (0) 9005563e27dSR.Marek@sh.cvut.cz 9015563e27dSR.Marek@sh.cvut.cz 9025563e27dSR.Marek@sh.cvut.cz /* For Smart Fan I/Thermal Cruise and Smart Fan II */ 9035563e27dSR.Marek@sh.cvut.cz static ssize_t 9045563e27dSR.Marek@sh.cvut.cz show_tolerance(struct device *dev, struct device_attribute *attr, 9055563e27dSR.Marek@sh.cvut.cz char *buf) 9065563e27dSR.Marek@sh.cvut.cz { 9075563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 9085563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index; 9095563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 9105563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%ld\n", (long)data->tolerance[nr-1]); 9115563e27dSR.Marek@sh.cvut.cz } 9125563e27dSR.Marek@sh.cvut.cz 9135563e27dSR.Marek@sh.cvut.cz static ssize_t 9145563e27dSR.Marek@sh.cvut.cz store_tolerance(struct device *dev, struct device_attribute *attr, 9155563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 9165563e27dSR.Marek@sh.cvut.cz { 9175563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 9185563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->index - 1; 9195563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 9205563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 9215563e27dSR.Marek@sh.cvut.cz u32 val; 9225563e27dSR.Marek@sh.cvut.cz u8 tol_tmp, tol_mask; 9235563e27dSR.Marek@sh.cvut.cz 9245563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); 9255563e27dSR.Marek@sh.cvut.cz tol_mask = w83792d_read_value(client, 9265563e27dSR.Marek@sh.cvut.cz W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0); 9275563e27dSR.Marek@sh.cvut.cz tol_tmp = SENSORS_LIMIT(val, 0, 15); 9285563e27dSR.Marek@sh.cvut.cz tol_tmp &= 0x0f; 9295563e27dSR.Marek@sh.cvut.cz data->tolerance[nr] = tol_tmp; 9305563e27dSR.Marek@sh.cvut.cz if (nr == 1) { 9315563e27dSR.Marek@sh.cvut.cz tol_tmp <<= 4; 9325563e27dSR.Marek@sh.cvut.cz } 9335563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_TOLERANCE[nr], 9345563e27dSR.Marek@sh.cvut.cz tol_mask | tol_tmp); 9355563e27dSR.Marek@sh.cvut.cz 9365563e27dSR.Marek@sh.cvut.cz return count; 9375563e27dSR.Marek@sh.cvut.cz } 9385563e27dSR.Marek@sh.cvut.cz 9395563e27dSR.Marek@sh.cvut.cz #define sysfs_tolerance(offset) \ 9405563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR(tolerance##offset, S_IRUGO | S_IWUSR, \ 9415563e27dSR.Marek@sh.cvut.cz show_tolerance, store_tolerance, offset); 9425563e27dSR.Marek@sh.cvut.cz 9435563e27dSR.Marek@sh.cvut.cz sysfs_tolerance(1); 9445563e27dSR.Marek@sh.cvut.cz sysfs_tolerance(2); 9455563e27dSR.Marek@sh.cvut.cz sysfs_tolerance(3); 9465563e27dSR.Marek@sh.cvut.cz 9475563e27dSR.Marek@sh.cvut.cz #define device_create_file_tolerance(client, offset) \ 9485563e27dSR.Marek@sh.cvut.cz do { \ 9495563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, &sensor_dev_attr_tolerance##offset.dev_attr); \ 9505563e27dSR.Marek@sh.cvut.cz } while (0) 9515563e27dSR.Marek@sh.cvut.cz 9525563e27dSR.Marek@sh.cvut.cz 9535563e27dSR.Marek@sh.cvut.cz /* For Smart Fan II */ 9545563e27dSR.Marek@sh.cvut.cz static ssize_t 9555563e27dSR.Marek@sh.cvut.cz show_sf2_point(struct device *dev, struct device_attribute *attr, 9565563e27dSR.Marek@sh.cvut.cz char *buf) 9575563e27dSR.Marek@sh.cvut.cz { 9585563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 9595563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->nr; 9605563e27dSR.Marek@sh.cvut.cz int index = sensor_attr->index; 9615563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 9625563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%ld\n", (long)data->sf2_points[index-1][nr-1]); 9635563e27dSR.Marek@sh.cvut.cz } 9645563e27dSR.Marek@sh.cvut.cz 9655563e27dSR.Marek@sh.cvut.cz static ssize_t 9665563e27dSR.Marek@sh.cvut.cz store_sf2_point(struct device *dev, struct device_attribute *attr, 9675563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 9685563e27dSR.Marek@sh.cvut.cz { 9695563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 9705563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->nr - 1; 9715563e27dSR.Marek@sh.cvut.cz int index = sensor_attr->index - 1; 9725563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 9735563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 9745563e27dSR.Marek@sh.cvut.cz u32 val; 9755563e27dSR.Marek@sh.cvut.cz u8 mask_tmp = 0; 9765563e27dSR.Marek@sh.cvut.cz 9775563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); 9785563e27dSR.Marek@sh.cvut.cz data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127); 9795563e27dSR.Marek@sh.cvut.cz mask_tmp = w83792d_read_value(client, 9805563e27dSR.Marek@sh.cvut.cz W83792D_REG_POINTS[index][nr]) & 0x80; 9815563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_POINTS[index][nr], 9825563e27dSR.Marek@sh.cvut.cz mask_tmp|data->sf2_points[index][nr]); 9835563e27dSR.Marek@sh.cvut.cz 9845563e27dSR.Marek@sh.cvut.cz return count; 9855563e27dSR.Marek@sh.cvut.cz } 9865563e27dSR.Marek@sh.cvut.cz 9875563e27dSR.Marek@sh.cvut.cz #define sysfs_sf2_point(offset, index) \ 9885563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR_2(sf2_point##offset##_fan##index, S_IRUGO | S_IWUSR, \ 9895563e27dSR.Marek@sh.cvut.cz show_sf2_point, store_sf2_point, offset, index); 9905563e27dSR.Marek@sh.cvut.cz 9915563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(1, 1); /* Fan1 */ 9925563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(2, 1); /* Fan1 */ 9935563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(3, 1); /* Fan1 */ 9945563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(4, 1); /* Fan1 */ 9955563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(1, 2); /* Fan2 */ 9965563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(2, 2); /* Fan2 */ 9975563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(3, 2); /* Fan2 */ 9985563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(4, 2); /* Fan2 */ 9995563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(1, 3); /* Fan3 */ 10005563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(2, 3); /* Fan3 */ 10015563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(3, 3); /* Fan3 */ 10025563e27dSR.Marek@sh.cvut.cz sysfs_sf2_point(4, 3); /* Fan3 */ 10035563e27dSR.Marek@sh.cvut.cz 10045563e27dSR.Marek@sh.cvut.cz #define device_create_file_sf2_point(client, offset, index) \ 10055563e27dSR.Marek@sh.cvut.cz do { \ 10065563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, \ 10075563e27dSR.Marek@sh.cvut.cz &sensor_dev_attr_sf2_point##offset##_fan##index.dev_attr); \ 10085563e27dSR.Marek@sh.cvut.cz } while (0) 10095563e27dSR.Marek@sh.cvut.cz 10105563e27dSR.Marek@sh.cvut.cz 10115563e27dSR.Marek@sh.cvut.cz static ssize_t 10125563e27dSR.Marek@sh.cvut.cz show_sf2_level(struct device *dev, struct device_attribute *attr, 10135563e27dSR.Marek@sh.cvut.cz char *buf) 10145563e27dSR.Marek@sh.cvut.cz { 10155563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 10165563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->nr; 10175563e27dSR.Marek@sh.cvut.cz int index = sensor_attr->index; 10185563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = w83792d_update_device(dev); 10195563e27dSR.Marek@sh.cvut.cz return sprintf(buf, "%d\n", 10205563e27dSR.Marek@sh.cvut.cz (((data->sf2_levels[index-1][nr]) * 100) / 15)); 10215563e27dSR.Marek@sh.cvut.cz } 10225563e27dSR.Marek@sh.cvut.cz 10235563e27dSR.Marek@sh.cvut.cz static ssize_t 10245563e27dSR.Marek@sh.cvut.cz store_sf2_level(struct device *dev, struct device_attribute *attr, 10255563e27dSR.Marek@sh.cvut.cz const char *buf, size_t count) 10265563e27dSR.Marek@sh.cvut.cz { 10275563e27dSR.Marek@sh.cvut.cz struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 10285563e27dSR.Marek@sh.cvut.cz int nr = sensor_attr->nr; 10295563e27dSR.Marek@sh.cvut.cz int index = sensor_attr->index - 1; 10305563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 10315563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 10325563e27dSR.Marek@sh.cvut.cz u32 val; 10335563e27dSR.Marek@sh.cvut.cz u8 mask_tmp=0, level_tmp=0; 10345563e27dSR.Marek@sh.cvut.cz 10355563e27dSR.Marek@sh.cvut.cz val = simple_strtoul(buf, NULL, 10); 10365563e27dSR.Marek@sh.cvut.cz data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15); 10375563e27dSR.Marek@sh.cvut.cz mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr]) 10385563e27dSR.Marek@sh.cvut.cz & ((nr==3) ? 0xf0 : 0x0f); 10395563e27dSR.Marek@sh.cvut.cz if (nr==3) { 10405563e27dSR.Marek@sh.cvut.cz level_tmp = data->sf2_levels[index][nr]; 10415563e27dSR.Marek@sh.cvut.cz } else { 10425563e27dSR.Marek@sh.cvut.cz level_tmp = data->sf2_levels[index][nr] << 4; 10435563e27dSR.Marek@sh.cvut.cz } 10445563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_LEVELS[index][nr], level_tmp | mask_tmp); 10455563e27dSR.Marek@sh.cvut.cz 10465563e27dSR.Marek@sh.cvut.cz return count; 10475563e27dSR.Marek@sh.cvut.cz } 10485563e27dSR.Marek@sh.cvut.cz 10495563e27dSR.Marek@sh.cvut.cz #define sysfs_sf2_level(offset, index) \ 10505563e27dSR.Marek@sh.cvut.cz static SENSOR_DEVICE_ATTR_2(sf2_level##offset##_fan##index, S_IRUGO | S_IWUSR, \ 10515563e27dSR.Marek@sh.cvut.cz show_sf2_level, store_sf2_level, offset, index); 10525563e27dSR.Marek@sh.cvut.cz 10535563e27dSR.Marek@sh.cvut.cz sysfs_sf2_level(1, 1); /* Fan1 */ 10545563e27dSR.Marek@sh.cvut.cz sysfs_sf2_level(2, 1); /* Fan1 */ 10555563e27dSR.Marek@sh.cvut.cz sysfs_sf2_level(3, 1); /* Fan1 */ 10565563e27dSR.Marek@sh.cvut.cz sysfs_sf2_level(1, 2); /* Fan2 */ 10575563e27dSR.Marek@sh.cvut.cz sysfs_sf2_level(2, 2); /* Fan2 */ 10585563e27dSR.Marek@sh.cvut.cz sysfs_sf2_level(3, 2); /* Fan2 */ 10595563e27dSR.Marek@sh.cvut.cz sysfs_sf2_level(1, 3); /* Fan3 */ 10605563e27dSR.Marek@sh.cvut.cz sysfs_sf2_level(2, 3); /* Fan3 */ 10615563e27dSR.Marek@sh.cvut.cz sysfs_sf2_level(3, 3); /* Fan3 */ 10625563e27dSR.Marek@sh.cvut.cz 10635563e27dSR.Marek@sh.cvut.cz #define device_create_file_sf2_level(client, offset, index) \ 10645563e27dSR.Marek@sh.cvut.cz do { \ 10655563e27dSR.Marek@sh.cvut.cz device_create_file(&client->dev, \ 10665563e27dSR.Marek@sh.cvut.cz &sensor_dev_attr_sf2_level##offset##_fan##index.dev_attr); \ 10675563e27dSR.Marek@sh.cvut.cz } while (0) 10685563e27dSR.Marek@sh.cvut.cz 10695563e27dSR.Marek@sh.cvut.cz 10705563e27dSR.Marek@sh.cvut.cz /* This function is called when: 10715563e27dSR.Marek@sh.cvut.cz * w83792d_driver is inserted (when this module is loaded), for each 10725563e27dSR.Marek@sh.cvut.cz available adapter 10735563e27dSR.Marek@sh.cvut.cz * when a new adapter is inserted (and w83792d_driver is still present) */ 10745563e27dSR.Marek@sh.cvut.cz static int 10755563e27dSR.Marek@sh.cvut.cz w83792d_attach_adapter(struct i2c_adapter *adapter) 10765563e27dSR.Marek@sh.cvut.cz { 10775563e27dSR.Marek@sh.cvut.cz if (!(adapter->class & I2C_CLASS_HWMON)) 10785563e27dSR.Marek@sh.cvut.cz return 0; 1079*2ed2dc3cSJean Delvare return i2c_probe(adapter, &addr_data, w83792d_detect); 10805563e27dSR.Marek@sh.cvut.cz } 10815563e27dSR.Marek@sh.cvut.cz 10825563e27dSR.Marek@sh.cvut.cz 10835563e27dSR.Marek@sh.cvut.cz static int 10845563e27dSR.Marek@sh.cvut.cz w83792d_create_subclient(struct i2c_adapter *adapter, 10855563e27dSR.Marek@sh.cvut.cz struct i2c_client *new_client, int addr, 10865563e27dSR.Marek@sh.cvut.cz struct i2c_client **sub_cli) 10875563e27dSR.Marek@sh.cvut.cz { 10885563e27dSR.Marek@sh.cvut.cz int err; 10895563e27dSR.Marek@sh.cvut.cz struct i2c_client *sub_client; 10905563e27dSR.Marek@sh.cvut.cz 10915563e27dSR.Marek@sh.cvut.cz (*sub_cli) = sub_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 10925563e27dSR.Marek@sh.cvut.cz if (!(sub_client)) { 10935563e27dSR.Marek@sh.cvut.cz return -ENOMEM; 10945563e27dSR.Marek@sh.cvut.cz } 10955563e27dSR.Marek@sh.cvut.cz memset(sub_client, 0x00, sizeof(struct i2c_client)); 10965563e27dSR.Marek@sh.cvut.cz sub_client->addr = 0x48 + addr; 10975563e27dSR.Marek@sh.cvut.cz i2c_set_clientdata(sub_client, NULL); 10985563e27dSR.Marek@sh.cvut.cz sub_client->adapter = adapter; 10995563e27dSR.Marek@sh.cvut.cz sub_client->driver = &w83792d_driver; 11005563e27dSR.Marek@sh.cvut.cz sub_client->flags = 0; 11015563e27dSR.Marek@sh.cvut.cz strlcpy(sub_client->name, "w83792d subclient", I2C_NAME_SIZE); 11025563e27dSR.Marek@sh.cvut.cz if ((err = i2c_attach_client(sub_client))) { 11035563e27dSR.Marek@sh.cvut.cz dev_err(&new_client->dev, "subclient registration " 11045563e27dSR.Marek@sh.cvut.cz "at address 0x%x failed\n", sub_client->addr); 11055563e27dSR.Marek@sh.cvut.cz kfree(sub_client); 11065563e27dSR.Marek@sh.cvut.cz return err; 11075563e27dSR.Marek@sh.cvut.cz } 11085563e27dSR.Marek@sh.cvut.cz return 0; 11095563e27dSR.Marek@sh.cvut.cz } 11105563e27dSR.Marek@sh.cvut.cz 11115563e27dSR.Marek@sh.cvut.cz 11125563e27dSR.Marek@sh.cvut.cz static int 11135563e27dSR.Marek@sh.cvut.cz w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, 11145563e27dSR.Marek@sh.cvut.cz struct i2c_client *new_client) 11155563e27dSR.Marek@sh.cvut.cz { 11165563e27dSR.Marek@sh.cvut.cz int i, id, err; 11175563e27dSR.Marek@sh.cvut.cz u8 val; 11185563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(new_client); 11195563e27dSR.Marek@sh.cvut.cz 11205563e27dSR.Marek@sh.cvut.cz id = i2c_adapter_id(adapter); 11215563e27dSR.Marek@sh.cvut.cz if (force_subclients[0] == id && force_subclients[1] == address) { 11225563e27dSR.Marek@sh.cvut.cz for (i = 2; i <= 3; i++) { 11235563e27dSR.Marek@sh.cvut.cz if (force_subclients[i] < 0x48 || 11245563e27dSR.Marek@sh.cvut.cz force_subclients[i] > 0x4f) { 11255563e27dSR.Marek@sh.cvut.cz dev_err(&new_client->dev, "invalid subclient " 11265563e27dSR.Marek@sh.cvut.cz "address %d; must be 0x48-0x4f\n", 11275563e27dSR.Marek@sh.cvut.cz force_subclients[i]); 11285563e27dSR.Marek@sh.cvut.cz err = -ENODEV; 11295563e27dSR.Marek@sh.cvut.cz goto ERROR_SC_0; 11305563e27dSR.Marek@sh.cvut.cz } 11315563e27dSR.Marek@sh.cvut.cz } 11325563e27dSR.Marek@sh.cvut.cz w83792d_write_value(new_client, W83792D_REG_I2C_SUBADDR, 11335563e27dSR.Marek@sh.cvut.cz (force_subclients[2] & 0x07) | 11345563e27dSR.Marek@sh.cvut.cz ((force_subclients[3] & 0x07) << 4)); 11355563e27dSR.Marek@sh.cvut.cz } 11365563e27dSR.Marek@sh.cvut.cz 11375563e27dSR.Marek@sh.cvut.cz val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); 11385563e27dSR.Marek@sh.cvut.cz if (!(val & 0x08)) { 11395563e27dSR.Marek@sh.cvut.cz err = w83792d_create_subclient(adapter, new_client, val & 0x7, 11405563e27dSR.Marek@sh.cvut.cz &data->lm75[0]); 11415563e27dSR.Marek@sh.cvut.cz if (err < 0) 11425563e27dSR.Marek@sh.cvut.cz goto ERROR_SC_0; 11435563e27dSR.Marek@sh.cvut.cz } 11445563e27dSR.Marek@sh.cvut.cz if (!(val & 0x80)) { 11455563e27dSR.Marek@sh.cvut.cz if ((data->lm75[0] != NULL) && 11465563e27dSR.Marek@sh.cvut.cz ((val & 0x7) == ((val >> 4) & 0x7))) { 11475563e27dSR.Marek@sh.cvut.cz dev_err(&new_client->dev, "duplicate addresses 0x%x, " 11485563e27dSR.Marek@sh.cvut.cz "use force_subclient\n", data->lm75[0]->addr); 11495563e27dSR.Marek@sh.cvut.cz err = -ENODEV; 11505563e27dSR.Marek@sh.cvut.cz goto ERROR_SC_1; 11515563e27dSR.Marek@sh.cvut.cz } 11525563e27dSR.Marek@sh.cvut.cz err = w83792d_create_subclient(adapter, new_client, 11535563e27dSR.Marek@sh.cvut.cz (val >> 4) & 0x7, &data->lm75[1]); 11545563e27dSR.Marek@sh.cvut.cz if (err < 0) 11555563e27dSR.Marek@sh.cvut.cz goto ERROR_SC_1; 11565563e27dSR.Marek@sh.cvut.cz } 11575563e27dSR.Marek@sh.cvut.cz 11585563e27dSR.Marek@sh.cvut.cz return 0; 11595563e27dSR.Marek@sh.cvut.cz 11605563e27dSR.Marek@sh.cvut.cz /* Undo inits in case of errors */ 11615563e27dSR.Marek@sh.cvut.cz 11625563e27dSR.Marek@sh.cvut.cz ERROR_SC_1: 11635563e27dSR.Marek@sh.cvut.cz if (data->lm75[0] != NULL) { 11645563e27dSR.Marek@sh.cvut.cz i2c_detach_client(data->lm75[0]); 11655563e27dSR.Marek@sh.cvut.cz kfree(data->lm75[0]); 11665563e27dSR.Marek@sh.cvut.cz } 11675563e27dSR.Marek@sh.cvut.cz ERROR_SC_0: 11685563e27dSR.Marek@sh.cvut.cz return err; 11695563e27dSR.Marek@sh.cvut.cz } 11705563e27dSR.Marek@sh.cvut.cz 11715563e27dSR.Marek@sh.cvut.cz 11725563e27dSR.Marek@sh.cvut.cz static int 11735563e27dSR.Marek@sh.cvut.cz w83792d_detect(struct i2c_adapter *adapter, int address, int kind) 11745563e27dSR.Marek@sh.cvut.cz { 11755563e27dSR.Marek@sh.cvut.cz int i = 0, val1 = 0, val2; 11765563e27dSR.Marek@sh.cvut.cz struct i2c_client *new_client; 11775563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data; 11785563e27dSR.Marek@sh.cvut.cz int err = 0; 11795563e27dSR.Marek@sh.cvut.cz const char *client_name = ""; 11805563e27dSR.Marek@sh.cvut.cz 11815563e27dSR.Marek@sh.cvut.cz if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 11825563e27dSR.Marek@sh.cvut.cz goto ERROR0; 11835563e27dSR.Marek@sh.cvut.cz } 11845563e27dSR.Marek@sh.cvut.cz 11855563e27dSR.Marek@sh.cvut.cz /* OK. For now, we presume we have a valid client. We now create the 11865563e27dSR.Marek@sh.cvut.cz client structure, even though we cannot fill it completely yet. 11875563e27dSR.Marek@sh.cvut.cz But it allows us to access w83792d_{read,write}_value. */ 11885563e27dSR.Marek@sh.cvut.cz 11895563e27dSR.Marek@sh.cvut.cz if (!(data = kmalloc(sizeof(struct w83792d_data), GFP_KERNEL))) { 11905563e27dSR.Marek@sh.cvut.cz err = -ENOMEM; 11915563e27dSR.Marek@sh.cvut.cz goto ERROR0; 11925563e27dSR.Marek@sh.cvut.cz } 11935563e27dSR.Marek@sh.cvut.cz memset(data, 0, sizeof(struct w83792d_data)); 11945563e27dSR.Marek@sh.cvut.cz 11955563e27dSR.Marek@sh.cvut.cz new_client = &data->client; 11965563e27dSR.Marek@sh.cvut.cz i2c_set_clientdata(new_client, data); 11975563e27dSR.Marek@sh.cvut.cz new_client->addr = address; 11985563e27dSR.Marek@sh.cvut.cz init_MUTEX(&data->lock); 11995563e27dSR.Marek@sh.cvut.cz new_client->adapter = adapter; 12005563e27dSR.Marek@sh.cvut.cz new_client->driver = &w83792d_driver; 12015563e27dSR.Marek@sh.cvut.cz new_client->flags = 0; 12025563e27dSR.Marek@sh.cvut.cz 12035563e27dSR.Marek@sh.cvut.cz /* Now, we do the remaining detection. */ 12045563e27dSR.Marek@sh.cvut.cz 12055563e27dSR.Marek@sh.cvut.cz /* The w83792d may be stuck in some other bank than bank 0. This may 12065563e27dSR.Marek@sh.cvut.cz make reading other information impossible. Specify a force=... or 12075563e27dSR.Marek@sh.cvut.cz force_*=... parameter, and the Winbond will be reset to the right 12085563e27dSR.Marek@sh.cvut.cz bank. */ 12095563e27dSR.Marek@sh.cvut.cz if (kind < 0) { 12105563e27dSR.Marek@sh.cvut.cz if (w83792d_read_value(new_client, W83792D_REG_CONFIG) & 0x80) { 12115563e27dSR.Marek@sh.cvut.cz dev_warn(&new_client->dev, "Detection failed at step " 12125563e27dSR.Marek@sh.cvut.cz "3\n"); 12135563e27dSR.Marek@sh.cvut.cz goto ERROR1; 12145563e27dSR.Marek@sh.cvut.cz } 12155563e27dSR.Marek@sh.cvut.cz val1 = w83792d_read_value(new_client, W83792D_REG_BANK); 12165563e27dSR.Marek@sh.cvut.cz val2 = w83792d_read_value(new_client, W83792D_REG_CHIPMAN); 12175563e27dSR.Marek@sh.cvut.cz /* Check for Winbond ID if in bank 0 */ 12185563e27dSR.Marek@sh.cvut.cz if (!(val1 & 0x07)) { /* is Bank0 */ 12195563e27dSR.Marek@sh.cvut.cz if (((!(val1 & 0x80)) && (val2 != 0xa3)) || 12205563e27dSR.Marek@sh.cvut.cz ((val1 & 0x80) && (val2 != 0x5c))) { 12215563e27dSR.Marek@sh.cvut.cz goto ERROR1; 12225563e27dSR.Marek@sh.cvut.cz } 12235563e27dSR.Marek@sh.cvut.cz } 12245563e27dSR.Marek@sh.cvut.cz /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR 12255563e27dSR.Marek@sh.cvut.cz should match */ 12265563e27dSR.Marek@sh.cvut.cz if (w83792d_read_value(new_client, 12275563e27dSR.Marek@sh.cvut.cz W83792D_REG_I2C_ADDR) != address) { 12285563e27dSR.Marek@sh.cvut.cz dev_warn(&new_client->dev, "Detection failed " 12295563e27dSR.Marek@sh.cvut.cz "at step 5\n"); 12305563e27dSR.Marek@sh.cvut.cz goto ERROR1; 12315563e27dSR.Marek@sh.cvut.cz } 12325563e27dSR.Marek@sh.cvut.cz } 12335563e27dSR.Marek@sh.cvut.cz 12345563e27dSR.Marek@sh.cvut.cz /* We have either had a force parameter, or we have already detected the 12355563e27dSR.Marek@sh.cvut.cz Winbond. Put it now into bank 0 and Vendor ID High Byte */ 12365563e27dSR.Marek@sh.cvut.cz w83792d_write_value(new_client, 12375563e27dSR.Marek@sh.cvut.cz W83792D_REG_BANK, 12385563e27dSR.Marek@sh.cvut.cz (w83792d_read_value(new_client, 12395563e27dSR.Marek@sh.cvut.cz W83792D_REG_BANK) & 0x78) | 0x80); 12405563e27dSR.Marek@sh.cvut.cz 12415563e27dSR.Marek@sh.cvut.cz /* Determine the chip type. */ 12425563e27dSR.Marek@sh.cvut.cz if (kind <= 0) { 12435563e27dSR.Marek@sh.cvut.cz /* get vendor ID */ 12445563e27dSR.Marek@sh.cvut.cz val2 = w83792d_read_value(new_client, W83792D_REG_CHIPMAN); 12455563e27dSR.Marek@sh.cvut.cz if (val2 != 0x5c) { /* the vendor is NOT Winbond */ 12465563e27dSR.Marek@sh.cvut.cz goto ERROR1; 12475563e27dSR.Marek@sh.cvut.cz } 12485563e27dSR.Marek@sh.cvut.cz val1 = w83792d_read_value(new_client, W83792D_REG_WCHIPID); 12495563e27dSR.Marek@sh.cvut.cz if (val1 == 0x7a && address >= 0x2c) { 12505563e27dSR.Marek@sh.cvut.cz kind = w83792d; 12515563e27dSR.Marek@sh.cvut.cz } else { 12525563e27dSR.Marek@sh.cvut.cz if (kind == 0) 12535563e27dSR.Marek@sh.cvut.cz dev_warn(&new_client->dev, 12545563e27dSR.Marek@sh.cvut.cz "w83792d: Ignoring 'force' parameter for" 12555563e27dSR.Marek@sh.cvut.cz " unknown chip at adapter %d, address" 12565563e27dSR.Marek@sh.cvut.cz " 0x%02x\n", i2c_adapter_id(adapter), 12575563e27dSR.Marek@sh.cvut.cz address); 12585563e27dSR.Marek@sh.cvut.cz goto ERROR1; 12595563e27dSR.Marek@sh.cvut.cz } 12605563e27dSR.Marek@sh.cvut.cz } 12615563e27dSR.Marek@sh.cvut.cz 12625563e27dSR.Marek@sh.cvut.cz if (kind == w83792d) { 12635563e27dSR.Marek@sh.cvut.cz client_name = "w83792d"; 12645563e27dSR.Marek@sh.cvut.cz } else { 12655563e27dSR.Marek@sh.cvut.cz dev_err(&new_client->dev, "w83792d: Internal error: unknown" 12665563e27dSR.Marek@sh.cvut.cz " kind (%d)?!?", kind); 12675563e27dSR.Marek@sh.cvut.cz goto ERROR1; 12685563e27dSR.Marek@sh.cvut.cz } 12695563e27dSR.Marek@sh.cvut.cz 12705563e27dSR.Marek@sh.cvut.cz /* Fill in the remaining client fields and put into the global list */ 12715563e27dSR.Marek@sh.cvut.cz strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 12725563e27dSR.Marek@sh.cvut.cz data->type = kind; 12735563e27dSR.Marek@sh.cvut.cz 12745563e27dSR.Marek@sh.cvut.cz data->valid = 0; 12755563e27dSR.Marek@sh.cvut.cz init_MUTEX(&data->update_lock); 12765563e27dSR.Marek@sh.cvut.cz 12775563e27dSR.Marek@sh.cvut.cz /* Tell the I2C layer a new client has arrived */ 12785563e27dSR.Marek@sh.cvut.cz if ((err = i2c_attach_client(new_client))) 12795563e27dSR.Marek@sh.cvut.cz goto ERROR1; 12805563e27dSR.Marek@sh.cvut.cz 12815563e27dSR.Marek@sh.cvut.cz if ((err = w83792d_detect_subclients(adapter, address, 12825563e27dSR.Marek@sh.cvut.cz kind, new_client))) 12835563e27dSR.Marek@sh.cvut.cz goto ERROR2; 12845563e27dSR.Marek@sh.cvut.cz 12855563e27dSR.Marek@sh.cvut.cz /* Initialize the chip */ 12865563e27dSR.Marek@sh.cvut.cz w83792d_init_client(new_client); 12875563e27dSR.Marek@sh.cvut.cz 12885563e27dSR.Marek@sh.cvut.cz /* A few vars need to be filled upon startup */ 12895563e27dSR.Marek@sh.cvut.cz for (i = 1; i <= 7; i++) { 12905563e27dSR.Marek@sh.cvut.cz data->fan_min[i - 1] = w83792d_read_value(new_client, 12915563e27dSR.Marek@sh.cvut.cz W83792D_REG_FAN_MIN[i]); 12925563e27dSR.Marek@sh.cvut.cz } 12935563e27dSR.Marek@sh.cvut.cz 12945563e27dSR.Marek@sh.cvut.cz /* Register sysfs hooks */ 1295ce785ab4SR.Marek@sh.cvut.cz data->class_dev = hwmon_device_register(&new_client->dev); 1296ce785ab4SR.Marek@sh.cvut.cz if (IS_ERR(data->class_dev)) { 1297ce785ab4SR.Marek@sh.cvut.cz err = PTR_ERR(data->class_dev); 1298ce785ab4SR.Marek@sh.cvut.cz goto ERROR3; 1299ce785ab4SR.Marek@sh.cvut.cz } 13005563e27dSR.Marek@sh.cvut.cz device_create_file_in(new_client, 0); 13015563e27dSR.Marek@sh.cvut.cz device_create_file_in(new_client, 1); 13025563e27dSR.Marek@sh.cvut.cz device_create_file_in(new_client, 2); 13035563e27dSR.Marek@sh.cvut.cz device_create_file_in(new_client, 3); 13045563e27dSR.Marek@sh.cvut.cz device_create_file_in(new_client, 4); 13055563e27dSR.Marek@sh.cvut.cz device_create_file_in(new_client, 5); 13065563e27dSR.Marek@sh.cvut.cz device_create_file_in(new_client, 6); 13075563e27dSR.Marek@sh.cvut.cz device_create_file_in(new_client, 7); 13085563e27dSR.Marek@sh.cvut.cz device_create_file_in(new_client, 8); 13095563e27dSR.Marek@sh.cvut.cz 13105563e27dSR.Marek@sh.cvut.cz device_create_file_fan(new_client, 1); 13115563e27dSR.Marek@sh.cvut.cz device_create_file_fan(new_client, 2); 13125563e27dSR.Marek@sh.cvut.cz device_create_file_fan(new_client, 3); 13135563e27dSR.Marek@sh.cvut.cz device_create_file_fan(new_client, 4); 13145563e27dSR.Marek@sh.cvut.cz device_create_file_fan(new_client, 5); 13155563e27dSR.Marek@sh.cvut.cz device_create_file_fan(new_client, 6); 13165563e27dSR.Marek@sh.cvut.cz device_create_file_fan(new_client, 7); 13175563e27dSR.Marek@sh.cvut.cz 13185563e27dSR.Marek@sh.cvut.cz device_create_file_temp1(new_client); /* Temp1 */ 13195563e27dSR.Marek@sh.cvut.cz device_create_file_temp_add(new_client, 2); /* Temp2 */ 13205563e27dSR.Marek@sh.cvut.cz device_create_file_temp_add(new_client, 3); /* Temp3 */ 13215563e27dSR.Marek@sh.cvut.cz 13225563e27dSR.Marek@sh.cvut.cz device_create_file_alarms(new_client); 13235563e27dSR.Marek@sh.cvut.cz 13245563e27dSR.Marek@sh.cvut.cz device_create_file_pwm(new_client, 1); 13255563e27dSR.Marek@sh.cvut.cz device_create_file_pwm(new_client, 2); 13265563e27dSR.Marek@sh.cvut.cz device_create_file_pwm(new_client, 3); 13275563e27dSR.Marek@sh.cvut.cz 13285563e27dSR.Marek@sh.cvut.cz device_create_file_pwmenable(new_client, 1); 13295563e27dSR.Marek@sh.cvut.cz device_create_file_pwmenable(new_client, 2); 13305563e27dSR.Marek@sh.cvut.cz device_create_file_pwmenable(new_client, 3); 13315563e27dSR.Marek@sh.cvut.cz 13325563e27dSR.Marek@sh.cvut.cz device_create_file_pwm_mode(new_client, 1); 13335563e27dSR.Marek@sh.cvut.cz device_create_file_pwm_mode(new_client, 2); 13345563e27dSR.Marek@sh.cvut.cz device_create_file_pwm_mode(new_client, 3); 13355563e27dSR.Marek@sh.cvut.cz 13365563e27dSR.Marek@sh.cvut.cz device_create_file_chassis(new_client); 13375563e27dSR.Marek@sh.cvut.cz device_create_file_chassis_clear(new_client); 13385563e27dSR.Marek@sh.cvut.cz 13395563e27dSR.Marek@sh.cvut.cz device_create_file_thermal_cruise(new_client, 1); 13405563e27dSR.Marek@sh.cvut.cz device_create_file_thermal_cruise(new_client, 2); 13415563e27dSR.Marek@sh.cvut.cz device_create_file_thermal_cruise(new_client, 3); 13425563e27dSR.Marek@sh.cvut.cz 13435563e27dSR.Marek@sh.cvut.cz device_create_file_tolerance(new_client, 1); 13445563e27dSR.Marek@sh.cvut.cz device_create_file_tolerance(new_client, 2); 13455563e27dSR.Marek@sh.cvut.cz device_create_file_tolerance(new_client, 3); 13465563e27dSR.Marek@sh.cvut.cz 13475563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 1, 1); /* Fan1 */ 13485563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 2, 1); /* Fan1 */ 13495563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 3, 1); /* Fan1 */ 13505563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 4, 1); /* Fan1 */ 13515563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 1, 2); /* Fan2 */ 13525563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 2, 2); /* Fan2 */ 13535563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 3, 2); /* Fan2 */ 13545563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 4, 2); /* Fan2 */ 13555563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 1, 3); /* Fan3 */ 13565563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 2, 3); /* Fan3 */ 13575563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 3, 3); /* Fan3 */ 13585563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_point(new_client, 4, 3); /* Fan3 */ 13595563e27dSR.Marek@sh.cvut.cz 13605563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_level(new_client, 1, 1); /* Fan1 */ 13615563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_level(new_client, 2, 1); /* Fan1 */ 13625563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_level(new_client, 3, 1); /* Fan1 */ 13635563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_level(new_client, 1, 2); /* Fan2 */ 13645563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_level(new_client, 2, 2); /* Fan2 */ 13655563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_level(new_client, 3, 2); /* Fan2 */ 13665563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_level(new_client, 1, 3); /* Fan3 */ 13675563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_level(new_client, 2, 3); /* Fan3 */ 13685563e27dSR.Marek@sh.cvut.cz device_create_file_sf2_level(new_client, 3, 3); /* Fan3 */ 13695563e27dSR.Marek@sh.cvut.cz 13705563e27dSR.Marek@sh.cvut.cz return 0; 13715563e27dSR.Marek@sh.cvut.cz 1372ce785ab4SR.Marek@sh.cvut.cz ERROR3: 1373ce785ab4SR.Marek@sh.cvut.cz if (data->lm75[0] != NULL) { 1374ce785ab4SR.Marek@sh.cvut.cz i2c_detach_client(data->lm75[0]); 1375ce785ab4SR.Marek@sh.cvut.cz kfree(data->lm75[0]); 1376ce785ab4SR.Marek@sh.cvut.cz } 1377ce785ab4SR.Marek@sh.cvut.cz if (data->lm75[1] != NULL) { 1378ce785ab4SR.Marek@sh.cvut.cz i2c_detach_client(data->lm75[1]); 1379ce785ab4SR.Marek@sh.cvut.cz kfree(data->lm75[1]); 1380ce785ab4SR.Marek@sh.cvut.cz } 13815563e27dSR.Marek@sh.cvut.cz ERROR2: 13825563e27dSR.Marek@sh.cvut.cz i2c_detach_client(new_client); 13835563e27dSR.Marek@sh.cvut.cz ERROR1: 13845563e27dSR.Marek@sh.cvut.cz kfree(data); 13855563e27dSR.Marek@sh.cvut.cz ERROR0: 13865563e27dSR.Marek@sh.cvut.cz return err; 13875563e27dSR.Marek@sh.cvut.cz } 13885563e27dSR.Marek@sh.cvut.cz 13895563e27dSR.Marek@sh.cvut.cz static int 13905563e27dSR.Marek@sh.cvut.cz w83792d_detach_client(struct i2c_client *client) 13915563e27dSR.Marek@sh.cvut.cz { 1392ce785ab4SR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 13935563e27dSR.Marek@sh.cvut.cz int err; 13945563e27dSR.Marek@sh.cvut.cz 1395ce785ab4SR.Marek@sh.cvut.cz /* main client */ 1396ce785ab4SR.Marek@sh.cvut.cz if (data) 1397ce785ab4SR.Marek@sh.cvut.cz hwmon_device_unregister(data->class_dev); 1398ce785ab4SR.Marek@sh.cvut.cz 13997bef5594SJean Delvare if ((err = i2c_detach_client(client))) 14005563e27dSR.Marek@sh.cvut.cz return err; 14015563e27dSR.Marek@sh.cvut.cz 14025563e27dSR.Marek@sh.cvut.cz /* main client */ 1403ce785ab4SR.Marek@sh.cvut.cz if (data) 1404ce785ab4SR.Marek@sh.cvut.cz kfree(data); 1405ce785ab4SR.Marek@sh.cvut.cz /* subclient */ 1406ce785ab4SR.Marek@sh.cvut.cz else 1407ce785ab4SR.Marek@sh.cvut.cz kfree(client); 14085563e27dSR.Marek@sh.cvut.cz 14095563e27dSR.Marek@sh.cvut.cz return 0; 14105563e27dSR.Marek@sh.cvut.cz } 14115563e27dSR.Marek@sh.cvut.cz 14125563e27dSR.Marek@sh.cvut.cz /* The SMBus locks itself, usually, but nothing may access the Winbond between 14135563e27dSR.Marek@sh.cvut.cz bank switches. ISA access must always be locked explicitly! 14145563e27dSR.Marek@sh.cvut.cz We ignore the W83792D BUSY flag at this moment - it could lead to deadlocks, 14155563e27dSR.Marek@sh.cvut.cz would slow down the W83792D access and should not be necessary. 14165563e27dSR.Marek@sh.cvut.cz There are some ugly typecasts here, but the good news is - they should 14175563e27dSR.Marek@sh.cvut.cz nowhere else be necessary! */ 14185563e27dSR.Marek@sh.cvut.cz static int 14195563e27dSR.Marek@sh.cvut.cz w83792d_read_value(struct i2c_client *client, u8 reg) 14205563e27dSR.Marek@sh.cvut.cz { 14215563e27dSR.Marek@sh.cvut.cz int res=0; 14225563e27dSR.Marek@sh.cvut.cz res = i2c_smbus_read_byte_data(client, reg); 14235563e27dSR.Marek@sh.cvut.cz 14245563e27dSR.Marek@sh.cvut.cz return res; 14255563e27dSR.Marek@sh.cvut.cz } 14265563e27dSR.Marek@sh.cvut.cz 14275563e27dSR.Marek@sh.cvut.cz static int 14285563e27dSR.Marek@sh.cvut.cz w83792d_write_value(struct i2c_client *client, u8 reg, u8 value) 14295563e27dSR.Marek@sh.cvut.cz { 14305563e27dSR.Marek@sh.cvut.cz i2c_smbus_write_byte_data(client, reg, value); 14315563e27dSR.Marek@sh.cvut.cz return 0; 14325563e27dSR.Marek@sh.cvut.cz } 14335563e27dSR.Marek@sh.cvut.cz 14345563e27dSR.Marek@sh.cvut.cz /* Called when we have found a new W83792D. It should set limits, etc. */ 14355563e27dSR.Marek@sh.cvut.cz static void 14365563e27dSR.Marek@sh.cvut.cz w83792d_init_client(struct i2c_client *client) 14375563e27dSR.Marek@sh.cvut.cz { 14385563e27dSR.Marek@sh.cvut.cz u8 temp2_cfg, temp3_cfg, vid_in_b; 14395563e27dSR.Marek@sh.cvut.cz 14405563e27dSR.Marek@sh.cvut.cz if (init) { 14415563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_CONFIG, 0x80); 14425563e27dSR.Marek@sh.cvut.cz } 14435563e27dSR.Marek@sh.cvut.cz /* Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0): 14445563e27dSR.Marek@sh.cvut.cz W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of 14455563e27dSR.Marek@sh.cvut.cz vin0/vin1 can be modified by user; 14465563e27dSR.Marek@sh.cvut.cz W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of 14475563e27dSR.Marek@sh.cvut.cz vin0/vin1 auto-updated, can NOT be modified by user. */ 14485563e27dSR.Marek@sh.cvut.cz vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B); 14495563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_VID_IN_B, 14505563e27dSR.Marek@sh.cvut.cz vid_in_b & 0xbf); 14515563e27dSR.Marek@sh.cvut.cz 14525563e27dSR.Marek@sh.cvut.cz temp2_cfg = w83792d_read_value(client, W83792D_REG_TEMP2_CONFIG); 14535563e27dSR.Marek@sh.cvut.cz temp3_cfg = w83792d_read_value(client, W83792D_REG_TEMP3_CONFIG); 14545563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_TEMP2_CONFIG, 14555563e27dSR.Marek@sh.cvut.cz temp2_cfg & 0xe6); 14565563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_TEMP3_CONFIG, 14575563e27dSR.Marek@sh.cvut.cz temp3_cfg & 0xe6); 14585563e27dSR.Marek@sh.cvut.cz 14595563e27dSR.Marek@sh.cvut.cz /* Start monitoring */ 14605563e27dSR.Marek@sh.cvut.cz w83792d_write_value(client, W83792D_REG_CONFIG, 14615563e27dSR.Marek@sh.cvut.cz (w83792d_read_value(client, 14625563e27dSR.Marek@sh.cvut.cz W83792D_REG_CONFIG) & 0xf7) 14635563e27dSR.Marek@sh.cvut.cz | 0x01); 14645563e27dSR.Marek@sh.cvut.cz } 14655563e27dSR.Marek@sh.cvut.cz 14665563e27dSR.Marek@sh.cvut.cz static struct w83792d_data *w83792d_update_device(struct device *dev) 14675563e27dSR.Marek@sh.cvut.cz { 14685563e27dSR.Marek@sh.cvut.cz struct i2c_client *client = to_i2c_client(dev); 14695563e27dSR.Marek@sh.cvut.cz struct w83792d_data *data = i2c_get_clientdata(client); 14705563e27dSR.Marek@sh.cvut.cz int i, j; 14715563e27dSR.Marek@sh.cvut.cz u8 reg_array_tmp[4], pwm_array_tmp[7], reg_tmp; 14725563e27dSR.Marek@sh.cvut.cz 14735563e27dSR.Marek@sh.cvut.cz down(&data->update_lock); 14745563e27dSR.Marek@sh.cvut.cz 14755563e27dSR.Marek@sh.cvut.cz if (time_after 14765563e27dSR.Marek@sh.cvut.cz (jiffies - data->last_updated, (unsigned long) (HZ * 3)) 14775563e27dSR.Marek@sh.cvut.cz || time_before(jiffies, data->last_updated) || !data->valid) { 14785563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "Starting device update\n"); 14795563e27dSR.Marek@sh.cvut.cz 14805563e27dSR.Marek@sh.cvut.cz /* Update the voltages measured value and limits */ 14815563e27dSR.Marek@sh.cvut.cz for (i = 0; i < 9; i++) { 14825563e27dSR.Marek@sh.cvut.cz data->in[i] = w83792d_read_value(client, 14835563e27dSR.Marek@sh.cvut.cz W83792D_REG_IN[i]); 14845563e27dSR.Marek@sh.cvut.cz data->in_max[i] = w83792d_read_value(client, 14855563e27dSR.Marek@sh.cvut.cz W83792D_REG_IN_MAX[i]); 14865563e27dSR.Marek@sh.cvut.cz data->in_min[i] = w83792d_read_value(client, 14875563e27dSR.Marek@sh.cvut.cz W83792D_REG_IN_MIN[i]); 14885563e27dSR.Marek@sh.cvut.cz } 14895563e27dSR.Marek@sh.cvut.cz data->low_bits[0] = w83792d_read_value(client, 14905563e27dSR.Marek@sh.cvut.cz W83792D_REG_LOW_BITS1); 14915563e27dSR.Marek@sh.cvut.cz data->low_bits[1] = w83792d_read_value(client, 14925563e27dSR.Marek@sh.cvut.cz W83792D_REG_LOW_BITS2); 14935563e27dSR.Marek@sh.cvut.cz for (i = 0; i < 7; i++) { 14945563e27dSR.Marek@sh.cvut.cz /* Update the Fan measured value and limits */ 14955563e27dSR.Marek@sh.cvut.cz data->fan[i] = w83792d_read_value(client, 14965563e27dSR.Marek@sh.cvut.cz W83792D_REG_FAN[i]); 14975563e27dSR.Marek@sh.cvut.cz data->fan_min[i] = w83792d_read_value(client, 14985563e27dSR.Marek@sh.cvut.cz W83792D_REG_FAN_MIN[i]); 14995563e27dSR.Marek@sh.cvut.cz /* Update the PWM/DC Value and PWM/DC flag */ 15005563e27dSR.Marek@sh.cvut.cz pwm_array_tmp[i] = w83792d_read_value(client, 15015563e27dSR.Marek@sh.cvut.cz W83792D_REG_PWM[i]); 15025563e27dSR.Marek@sh.cvut.cz data->pwm[i] = pwm_array_tmp[i] & 0x0f; 15035563e27dSR.Marek@sh.cvut.cz data->pwm_mode[i] = (pwm_array_tmp[i] >> 7) & 0x01; 15045563e27dSR.Marek@sh.cvut.cz } 15055563e27dSR.Marek@sh.cvut.cz 15065563e27dSR.Marek@sh.cvut.cz reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG); 15075563e27dSR.Marek@sh.cvut.cz data->pwmenable[0] = reg_tmp & 0x03; 15085563e27dSR.Marek@sh.cvut.cz data->pwmenable[1] = (reg_tmp>>2) & 0x03; 15095563e27dSR.Marek@sh.cvut.cz data->pwmenable[2] = (reg_tmp>>4) & 0x03; 15105563e27dSR.Marek@sh.cvut.cz 15115563e27dSR.Marek@sh.cvut.cz for (i = 0; i < 3; i++) { 15125563e27dSR.Marek@sh.cvut.cz data->temp1[i] = w83792d_read_value(client, 15135563e27dSR.Marek@sh.cvut.cz W83792D_REG_TEMP1[i]); 15145563e27dSR.Marek@sh.cvut.cz } 15155563e27dSR.Marek@sh.cvut.cz for (i = 0; i < 2; i++) { 15165563e27dSR.Marek@sh.cvut.cz for (j = 0; j < 6; j++) { 15175563e27dSR.Marek@sh.cvut.cz data->temp_add[i][j] = w83792d_read_value( 15185563e27dSR.Marek@sh.cvut.cz client,W83792D_REG_TEMP_ADD[i][j]); 15195563e27dSR.Marek@sh.cvut.cz } 15205563e27dSR.Marek@sh.cvut.cz } 15215563e27dSR.Marek@sh.cvut.cz 15225563e27dSR.Marek@sh.cvut.cz /* Update the Fan Divisor */ 15235563e27dSR.Marek@sh.cvut.cz for (i = 0; i < 4; i++) { 15245563e27dSR.Marek@sh.cvut.cz reg_array_tmp[i] = w83792d_read_value(client, 15255563e27dSR.Marek@sh.cvut.cz W83792D_REG_FAN_DIV[i]); 15265563e27dSR.Marek@sh.cvut.cz } 15275563e27dSR.Marek@sh.cvut.cz data->fan_div[0] = reg_array_tmp[0] & 0x07; 15285563e27dSR.Marek@sh.cvut.cz data->fan_div[1] = (reg_array_tmp[0] >> 4) & 0x07; 15295563e27dSR.Marek@sh.cvut.cz data->fan_div[2] = reg_array_tmp[1] & 0x07; 15305563e27dSR.Marek@sh.cvut.cz data->fan_div[3] = (reg_array_tmp[1] >> 4) & 0x07; 15315563e27dSR.Marek@sh.cvut.cz data->fan_div[4] = reg_array_tmp[2] & 0x07; 15325563e27dSR.Marek@sh.cvut.cz data->fan_div[5] = (reg_array_tmp[2] >> 4) & 0x07; 15335563e27dSR.Marek@sh.cvut.cz data->fan_div[6] = reg_array_tmp[3] & 0x07; 15345563e27dSR.Marek@sh.cvut.cz 15355563e27dSR.Marek@sh.cvut.cz /* Update the realtime status */ 15365563e27dSR.Marek@sh.cvut.cz data->alarms = w83792d_read_value(client, W83792D_REG_ALARM1) + 15375563e27dSR.Marek@sh.cvut.cz (w83792d_read_value(client, W83792D_REG_ALARM2) << 8) + 15385563e27dSR.Marek@sh.cvut.cz (w83792d_read_value(client, W83792D_REG_ALARM3) << 16); 15395563e27dSR.Marek@sh.cvut.cz 15405563e27dSR.Marek@sh.cvut.cz /* Update CaseOpen status and it's CLR_CHS. */ 15415563e27dSR.Marek@sh.cvut.cz data->chassis = (w83792d_read_value(client, 15425563e27dSR.Marek@sh.cvut.cz W83792D_REG_CHASSIS) >> 5) & 0x01; 15435563e27dSR.Marek@sh.cvut.cz data->chassis_clear = (w83792d_read_value(client, 15445563e27dSR.Marek@sh.cvut.cz W83792D_REG_CHASSIS_CLR) >> 7) & 0x01; 15455563e27dSR.Marek@sh.cvut.cz 15465563e27dSR.Marek@sh.cvut.cz /* Update Thermal Cruise/Smart Fan I target value */ 15475563e27dSR.Marek@sh.cvut.cz for (i = 0; i < 3; i++) { 15485563e27dSR.Marek@sh.cvut.cz data->thermal_cruise[i] = 15495563e27dSR.Marek@sh.cvut.cz w83792d_read_value(client, 15505563e27dSR.Marek@sh.cvut.cz W83792D_REG_THERMAL[i]) & 0x7f; 15515563e27dSR.Marek@sh.cvut.cz } 15525563e27dSR.Marek@sh.cvut.cz 15535563e27dSR.Marek@sh.cvut.cz /* Update Smart Fan I/II tolerance */ 15545563e27dSR.Marek@sh.cvut.cz reg_tmp = w83792d_read_value(client, W83792D_REG_TOLERANCE[0]); 15555563e27dSR.Marek@sh.cvut.cz data->tolerance[0] = reg_tmp & 0x0f; 15565563e27dSR.Marek@sh.cvut.cz data->tolerance[1] = (reg_tmp >> 4) & 0x0f; 15575563e27dSR.Marek@sh.cvut.cz data->tolerance[2] = w83792d_read_value(client, 15585563e27dSR.Marek@sh.cvut.cz W83792D_REG_TOLERANCE[2]) & 0x0f; 15595563e27dSR.Marek@sh.cvut.cz 15605563e27dSR.Marek@sh.cvut.cz /* Update Smart Fan II temperature points */ 15615563e27dSR.Marek@sh.cvut.cz for (i = 0; i < 3; i++) { 15625563e27dSR.Marek@sh.cvut.cz for (j = 0; j < 4; j++) { 15635563e27dSR.Marek@sh.cvut.cz data->sf2_points[i][j] = w83792d_read_value( 15645563e27dSR.Marek@sh.cvut.cz client,W83792D_REG_POINTS[i][j]) & 0x7f; 15655563e27dSR.Marek@sh.cvut.cz } 15665563e27dSR.Marek@sh.cvut.cz } 15675563e27dSR.Marek@sh.cvut.cz 15685563e27dSR.Marek@sh.cvut.cz /* Update Smart Fan II duty cycle levels */ 15695563e27dSR.Marek@sh.cvut.cz for (i = 0; i < 3; i++) { 15705563e27dSR.Marek@sh.cvut.cz reg_tmp = w83792d_read_value(client, 15715563e27dSR.Marek@sh.cvut.cz W83792D_REG_LEVELS[i][0]); 15725563e27dSR.Marek@sh.cvut.cz data->sf2_levels[i][0] = reg_tmp & 0x0f; 15735563e27dSR.Marek@sh.cvut.cz data->sf2_levels[i][1] = (reg_tmp >> 4) & 0x0f; 15745563e27dSR.Marek@sh.cvut.cz reg_tmp = w83792d_read_value(client, 15755563e27dSR.Marek@sh.cvut.cz W83792D_REG_LEVELS[i][2]); 15765563e27dSR.Marek@sh.cvut.cz data->sf2_levels[i][2] = (reg_tmp >> 4) & 0x0f; 15775563e27dSR.Marek@sh.cvut.cz data->sf2_levels[i][3] = reg_tmp & 0x0f; 15785563e27dSR.Marek@sh.cvut.cz } 15795563e27dSR.Marek@sh.cvut.cz 15805563e27dSR.Marek@sh.cvut.cz data->last_updated = jiffies; 15815563e27dSR.Marek@sh.cvut.cz data->valid = 1; 15825563e27dSR.Marek@sh.cvut.cz } 15835563e27dSR.Marek@sh.cvut.cz 15845563e27dSR.Marek@sh.cvut.cz up(&data->update_lock); 15855563e27dSR.Marek@sh.cvut.cz 15865563e27dSR.Marek@sh.cvut.cz #ifdef DEBUG 15875563e27dSR.Marek@sh.cvut.cz w83792d_print_debug(data, dev); 15885563e27dSR.Marek@sh.cvut.cz #endif 15895563e27dSR.Marek@sh.cvut.cz 15905563e27dSR.Marek@sh.cvut.cz return data; 15915563e27dSR.Marek@sh.cvut.cz } 15925563e27dSR.Marek@sh.cvut.cz 15935563e27dSR.Marek@sh.cvut.cz #ifdef DEBUG 15945563e27dSR.Marek@sh.cvut.cz static void w83792d_print_debug(struct w83792d_data *data, struct device *dev) 15955563e27dSR.Marek@sh.cvut.cz { 15965563e27dSR.Marek@sh.cvut.cz int i=0, j=0; 15975563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "==========The following is the debug message...========\n"); 15985563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "9 set of Voltages: =====>\n"); 15995563e27dSR.Marek@sh.cvut.cz for (i=0; i<9; i++) { 16005563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]); 16015563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]); 16025563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]); 16035563e27dSR.Marek@sh.cvut.cz } 16045563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits[0]); 16055563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits[1]); 16065563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n"); 16075563e27dSR.Marek@sh.cvut.cz for (i=0; i<7; i++) { 16085563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]); 16095563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]); 16105563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]); 16115563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "pwm_mode[%d] is: 0x%x\n", i, data->pwm_mode[i]); 16125563e27dSR.Marek@sh.cvut.cz } 16135563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "3 set of Temperatures: =====>\n"); 16145563e27dSR.Marek@sh.cvut.cz for (i=0; i<3; i++) { 16155563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]); 16165563e27dSR.Marek@sh.cvut.cz } 16175563e27dSR.Marek@sh.cvut.cz 16185563e27dSR.Marek@sh.cvut.cz for (i=0; i<2; i++) { 16195563e27dSR.Marek@sh.cvut.cz for (j=0; j<6; j++) { 16205563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j, 16215563e27dSR.Marek@sh.cvut.cz data->temp_add[i][j]); 16225563e27dSR.Marek@sh.cvut.cz } 16235563e27dSR.Marek@sh.cvut.cz } 16245563e27dSR.Marek@sh.cvut.cz 16255563e27dSR.Marek@sh.cvut.cz for (i=0; i<7; i++) { 16265563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]); 16275563e27dSR.Marek@sh.cvut.cz } 16285563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "==========End of the debug message...==================\n"); 16295563e27dSR.Marek@sh.cvut.cz dev_dbg(dev, "\n"); 16305563e27dSR.Marek@sh.cvut.cz } 16315563e27dSR.Marek@sh.cvut.cz #endif 16325563e27dSR.Marek@sh.cvut.cz 16335563e27dSR.Marek@sh.cvut.cz static int __init 16345563e27dSR.Marek@sh.cvut.cz sensors_w83792d_init(void) 16355563e27dSR.Marek@sh.cvut.cz { 16365563e27dSR.Marek@sh.cvut.cz return i2c_add_driver(&w83792d_driver); 16375563e27dSR.Marek@sh.cvut.cz } 16385563e27dSR.Marek@sh.cvut.cz 16395563e27dSR.Marek@sh.cvut.cz static void __exit 16405563e27dSR.Marek@sh.cvut.cz sensors_w83792d_exit(void) 16415563e27dSR.Marek@sh.cvut.cz { 16425563e27dSR.Marek@sh.cvut.cz i2c_del_driver(&w83792d_driver); 16435563e27dSR.Marek@sh.cvut.cz } 16445563e27dSR.Marek@sh.cvut.cz 16455563e27dSR.Marek@sh.cvut.cz MODULE_AUTHOR("Chunhao Huang @ Winbond <DZShen@Winbond.com.tw>"); 16465563e27dSR.Marek@sh.cvut.cz MODULE_DESCRIPTION("W83792AD/D driver for linux-2.6"); 16475563e27dSR.Marek@sh.cvut.cz MODULE_LICENSE("GPL"); 16485563e27dSR.Marek@sh.cvut.cz 16495563e27dSR.Marek@sh.cvut.cz module_init(sensors_w83792d_init); 16505563e27dSR.Marek@sh.cvut.cz module_exit(sensors_w83792d_exit); 16515563e27dSR.Marek@sh.cvut.cz 1652