11/*
22 w83627ehf - Driver for the hardware monitoring functionality of
33 the Winbond W83627EHF Super-I/O chip
4- Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
4+ Copyright (C) 2005-2011 Jean Delvare <khali@linux-fr.org>
55 Copyright (C) 2006 Yuan Mu (Winbond),
66 Rudolf Marek <r.marek@assembler.cz>
77 David Hubbard <david.c.hubbard@gmail.com>
3939 0x8860 0xa1
4040 w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3
4141 w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3
42+ w83627uhg 8 2 2 2 0xa230 0xc1 0x5ca3
4243 w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3
4344 w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3
4445 nct6775f 9 4 3 9 0xb470 0xc1 0x5ca3
6162#include <linux/io.h>
6263#include "lm75.h"
6364
64- enum kinds { w83627ehf , w83627dhg , w83627dhg_p , w83667hg , w83667hg_b , nct6775 ,
65- nct6776 };
65+ enum kinds {
66+ w83627ehf , w83627dhg , w83627dhg_p , w83627uhg ,
67+ w83667hg , w83667hg_b , nct6775 , nct6776 ,
68+ };
6669
6770/* used to set data->name = w83627ehf_device_names[data->sio_kind] */
6871static const char * const w83627ehf_device_names [] = {
6972 "w83627ehf" ,
7073 "w83627dhg" ,
7174 "w83627dhg" ,
75+ "w83627uhg" ,
7276 "w83667hg" ,
7377 "w83667hg" ,
7478 "nct6775" ,
@@ -104,6 +108,7 @@ MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal");
104108#define SIO_W83627EHG_ID 0x8860
105109#define SIO_W83627DHG_ID 0xa020
106110#define SIO_W83627DHG_P_ID 0xb070
111+ #define SIO_W83627UHG_ID 0xa230
107112#define SIO_W83667HG_ID 0xa510
108113#define SIO_W83667HG_B_ID 0xb350
109114#define SIO_NCT6775_ID 0xb470
@@ -388,18 +393,23 @@ div_from_reg(u8 reg)
388393 return 1 << reg ;
389394}
390395
391- /* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */
392-
393- static u8 scale_in [10 ] = { 8 , 8 , 16 , 16 , 8 , 8 , 8 , 16 , 16 , 8 };
396+ /* Some of the voltage inputs have internal scaling, the tables below
397+ * contain 8 (the ADC LSB in mV) * scaling factor * 100 */
398+ static const u16 scale_in_common [10 ] = {
399+ 800 , 800 , 1600 , 1600 , 800 , 800 , 800 , 1600 , 1600 , 800
400+ };
401+ static const u16 scale_in_w83627uhg [9 ] = {
402+ 800 , 800 , 3328 , 3424 , 800 , 800 , 0 , 3328 , 3400
403+ };
394404
395- static inline long in_from_reg (u8 reg , u8 nr )
405+ static inline long in_from_reg (u8 reg , u8 nr , const u16 * scale_in )
396406{
397- return reg * scale_in [nr ];
407+ return DIV_ROUND_CLOSEST ( reg * scale_in [nr ], 100 ) ;
398408}
399409
400- static inline u8 in_to_reg (u32 val , u8 nr )
410+ static inline u8 in_to_reg (u32 val , u8 nr , const u16 * scale_in )
401411{
402- return SENSORS_LIMIT ((( val + ( scale_in [ nr ] / 2 )) / scale_in [nr ]), 0 ,
412+ return SENSORS_LIMIT (DIV_ROUND_CLOSEST ( val * 100 , scale_in [nr ]), 0 ,
403413 255 );
404414}
405415
@@ -430,6 +440,7 @@ struct w83627ehf_data {
430440 const u16 * REG_FAN_STOP_TIME ;
431441 const u16 * REG_FAN_MAX_OUTPUT ;
432442 const u16 * REG_FAN_STEP_OUTPUT ;
443+ const u16 * scale_in ;
433444
434445 unsigned int (* fan_from_reg )(u16 reg , unsigned int divreg );
435446 unsigned int (* fan_from_reg_min )(u16 reg , unsigned int divreg );
@@ -481,7 +492,8 @@ struct w83627ehf_data {
481492 u8 vrm ;
482493
483494 u16 have_temp ;
484- u8 in6_skip ;
495+ u8 in6_skip :1 ;
496+ u8 temp3_val_only :1 ;
485497};
486498
487499struct w83627ehf_sio_data {
@@ -907,7 +919,8 @@ show_##reg(struct device *dev, struct device_attribute *attr, \
907919 struct sensor_device_attribute *sensor_attr = \
908920 to_sensor_dev_attr(attr); \
909921 int nr = sensor_attr->index; \
910- return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr)); \
922+ return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr, \
923+ data->scale_in)); \
911924}
912925show_in_reg (in )
913926show_in_reg (in_min )
@@ -928,7 +941,7 @@ store_in_##reg(struct device *dev, struct device_attribute *attr, \
928941 if (err < 0) \
929942 return err; \
930943 mutex_lock(&data->update_lock); \
931- data->in_##reg[nr] = in_to_reg(val, nr); \
944+ data->in_##reg[nr] = in_to_reg(val, nr, data->scale_in ); \
932945 w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \
933946 data->in_##reg[nr]); \
934947 mutex_unlock(&data->update_lock); \
@@ -1617,25 +1630,28 @@ static struct sensor_device_attribute sda_sf3_arrays_fan4[] = {
16171630 store_fan_step_output , 3 ),
16181631};
16191632
1633+ static struct sensor_device_attribute sda_sf3_arrays_fan3 [] = {
1634+ SENSOR_ATTR (pwm3_stop_time , S_IWUSR | S_IRUGO , show_fan_stop_time ,
1635+ store_fan_stop_time , 2 ),
1636+ SENSOR_ATTR (pwm3_start_output , S_IWUSR | S_IRUGO , show_fan_start_output ,
1637+ store_fan_start_output , 2 ),
1638+ SENSOR_ATTR (pwm3_stop_output , S_IWUSR | S_IRUGO , show_fan_stop_output ,
1639+ store_fan_stop_output , 2 ),
1640+ };
1641+
16201642static struct sensor_device_attribute sda_sf3_arrays [] = {
16211643 SENSOR_ATTR (pwm1_stop_time , S_IWUSR | S_IRUGO , show_fan_stop_time ,
16221644 store_fan_stop_time , 0 ),
16231645 SENSOR_ATTR (pwm2_stop_time , S_IWUSR | S_IRUGO , show_fan_stop_time ,
16241646 store_fan_stop_time , 1 ),
1625- SENSOR_ATTR (pwm3_stop_time , S_IWUSR | S_IRUGO , show_fan_stop_time ,
1626- store_fan_stop_time , 2 ),
16271647 SENSOR_ATTR (pwm1_start_output , S_IWUSR | S_IRUGO , show_fan_start_output ,
16281648 store_fan_start_output , 0 ),
16291649 SENSOR_ATTR (pwm2_start_output , S_IWUSR | S_IRUGO , show_fan_start_output ,
16301650 store_fan_start_output , 1 ),
1631- SENSOR_ATTR (pwm3_start_output , S_IWUSR | S_IRUGO , show_fan_start_output ,
1632- store_fan_start_output , 2 ),
16331651 SENSOR_ATTR (pwm1_stop_output , S_IWUSR | S_IRUGO , show_fan_stop_output ,
16341652 store_fan_stop_output , 0 ),
16351653 SENSOR_ATTR (pwm2_stop_output , S_IWUSR | S_IRUGO , show_fan_stop_output ,
16361654 store_fan_stop_output , 1 ),
1637- SENSOR_ATTR (pwm3_stop_output , S_IWUSR | S_IRUGO , show_fan_stop_output ,
1638- store_fan_stop_output , 2 ),
16391655};
16401656
16411657
@@ -1728,6 +1744,8 @@ static void w83627ehf_device_remove_files(struct device *dev)
17281744 data -> REG_FAN_STEP_OUTPUT [attr -> index ] != 0xff )
17291745 device_remove_file (dev , & attr -> dev_attr );
17301746 }
1747+ for (i = 0 ; i < ARRAY_SIZE (sda_sf3_arrays_fan3 ); i ++ )
1748+ device_remove_file (dev , & sda_sf3_arrays_fan3 [i ].dev_attr );
17311749 for (i = 0 ; i < ARRAY_SIZE (sda_sf3_arrays_fan4 ); i ++ )
17321750 device_remove_file (dev , & sda_sf3_arrays_fan4 [i ].dev_attr );
17331751 for (i = 0 ; i < data -> in_num ; i ++ ) {
@@ -1756,6 +1774,8 @@ static void w83627ehf_device_remove_files(struct device *dev)
17561774 continue ;
17571775 device_remove_file (dev , & sda_temp_input [i ].dev_attr );
17581776 device_remove_file (dev , & sda_temp_label [i ].dev_attr );
1777+ if (i == 2 && data -> temp3_val_only )
1778+ continue ;
17591779 device_remove_file (dev , & sda_temp_max [i ].dev_attr );
17601780 device_remove_file (dev , & sda_temp_max_hyst [i ].dev_attr );
17611781 if (i > 2 )
@@ -1808,6 +1828,9 @@ static inline void __devinit w83627ehf_init_device(struct w83627ehf_data *data,
18081828 case w83627ehf :
18091829 diode = w83627ehf_read_value (data , W83627EHF_REG_DIODE );
18101830 break ;
1831+ case w83627uhg :
1832+ diode = 0x00 ;
1833+ break ;
18111834 default :
18121835 diode = 0x70 ;
18131836 }
@@ -1871,6 +1894,13 @@ w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data,
18711894{
18721895 int fan3pin , fan4pin , fan4min , fan5pin , regval ;
18731896
1897+ /* The W83627UHG is simple, only two fan inputs, no config */
1898+ if (sio_data -> kind == w83627uhg ) {
1899+ data -> has_fan = 0x03 ; /* fan1 and fan2 */
1900+ data -> has_fan_min = 0x03 ;
1901+ return ;
1902+ }
1903+
18741904 superio_enter (sio_data -> sioreg );
18751905
18761906 /* fan4 and fan5 share some pins with the GPIO and serial flash */
@@ -1962,11 +1992,21 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
19621992
19631993 /* 627EHG and 627EHF have 10 voltage inputs; 627DHG and 667HG have 9 */
19641994 data -> in_num = (sio_data -> kind == w83627ehf ) ? 10 : 9 ;
1965- /* 667HG, NCT6775F, and NCT6776F have 3 pwms */
1966- data -> pwm_num = (sio_data -> kind == w83667hg
1967- || sio_data -> kind == w83667hg_b
1968- || sio_data -> kind == nct6775
1969- || sio_data -> kind == nct6776 ) ? 3 : 4 ;
1995+ /* 667HG, NCT6775F, and NCT6776F have 3 pwms, and 627UHG has only 2 */
1996+ switch (sio_data -> kind ) {
1997+ default :
1998+ data -> pwm_num = 4 ;
1999+ break ;
2000+ case w83667hg :
2001+ case w83667hg_b :
2002+ case nct6775 :
2003+ case nct6776 :
2004+ data -> pwm_num = 3 ;
2005+ break ;
2006+ case w83627uhg :
2007+ data -> pwm_num = 2 ;
2008+ break ;
2009+ }
19702010
19712011 /* Default to 3 temperature inputs, code below will adjust as needed */
19722012 data -> have_temp = 0x07 ;
@@ -2084,6 +2124,42 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
20842124 || (data -> temp_src [3 ] == 2 && (data -> have_temp & (1 << 3 ))))
20852125 data -> in6_skip = 1 ;
20862126
2127+ data -> temp_label = w83667hg_b_temp_label ;
2128+ } else if (sio_data -> kind == w83627uhg ) {
2129+ u8 reg ;
2130+
2131+ w83627ehf_set_temp_reg_ehf (data , 3 );
2132+
2133+ /*
2134+ * Temperature sources for temp1 and temp2 are selected with
2135+ * bank 0, registers 0x49 and 0x4a.
2136+ */
2137+ data -> temp_src [0 ] = 0 ; /* SYSTIN */
2138+ reg = w83627ehf_read_value (data , 0x49 ) & 0x07 ;
2139+ /* Adjust to have the same mapping as other source registers */
2140+ if (reg == 0 )
2141+ data -> temp_src [1 ]++ ;
2142+ else if (reg >= 2 && reg <= 5 )
2143+ data -> temp_src [1 ] += 2 ;
2144+ else /* should never happen */
2145+ data -> have_temp &= ~(1 << 1 );
2146+ reg = w83627ehf_read_value (data , 0x4a );
2147+ data -> temp_src [2 ] = reg >> 5 ;
2148+
2149+ /*
2150+ * Skip temp3 if source is invalid or the same as temp1
2151+ * or temp2.
2152+ */
2153+ if (data -> temp_src [2 ] == 2 || data -> temp_src [2 ] == 3 ||
2154+ data -> temp_src [2 ] == data -> temp_src [0 ] ||
2155+ ((data -> have_temp & (1 << 1 )) &&
2156+ data -> temp_src [2 ] == data -> temp_src [1 ]))
2157+ data -> have_temp &= ~(1 << 2 );
2158+ else
2159+ data -> temp3_val_only = 1 ; /* No limit regs */
2160+
2161+ data -> in6_skip = 1 ; /* No VIN3 */
2162+
20872163 data -> temp_label = w83667hg_b_temp_label ;
20882164 } else {
20892165 w83627ehf_set_temp_reg_ehf (data , 3 );
@@ -2162,6 +2238,12 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
21622238 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON ;
21632239 }
21642240
2241+ /* Setup input voltage scaling factors */
2242+ if (sio_data -> kind == w83627uhg )
2243+ data -> scale_in = scale_in_w83627uhg ;
2244+ else
2245+ data -> scale_in = scale_in_common ;
2246+
21652247 /* Initialize the chip */
21662248 w83627ehf_init_device (data , sio_data -> kind );
21672249
@@ -2178,7 +2260,7 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
21782260 err = device_create_file (dev , & dev_attr_cpu0_vid );
21792261 if (err )
21802262 goto exit_release ;
2181- } else {
2263+ } else if ( sio_data -> kind != w83627uhg ) {
21822264 superio_select (sio_data -> sioreg , W83627EHF_LD_HWM );
21832265 if (superio_inb (sio_data -> sioreg , SIO_REG_VID_CTRL ) & 0x80 ) {
21842266 /* Set VID input sensibility if needed. In theory the
@@ -2268,7 +2350,14 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
22682350 goto exit_remove ;
22692351 }
22702352 }
2271- /* if fan4 is enabled create the sf3 files for it */
2353+ /* if fan3 and fan4 are enabled create the sf3 files for them */
2354+ if ((data -> has_fan & (1 << 2 )) && data -> pwm_num >= 3 )
2355+ for (i = 0 ; i < ARRAY_SIZE (sda_sf3_arrays_fan3 ); i ++ ) {
2356+ err = device_create_file (dev ,
2357+ & sda_sf3_arrays_fan3 [i ].dev_attr );
2358+ if (err )
2359+ goto exit_remove ;
2360+ }
22722361 if ((data -> has_fan & (1 << 3 )) && data -> pwm_num >= 4 )
22732362 for (i = 0 ; i < ARRAY_SIZE (sda_sf3_arrays_fan4 ); i ++ ) {
22742363 err = device_create_file (dev ,
@@ -2336,6 +2425,8 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
23362425 if (err )
23372426 goto exit_remove ;
23382427 }
2428+ if (i == 2 && data -> temp3_val_only )
2429+ continue ;
23392430 if (data -> reg_temp_over [i ]) {
23402431 err = device_create_file (dev ,
23412432 & sda_temp_max [i ].dev_attr );
@@ -2419,6 +2510,7 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
24192510 static const char __initdata sio_name_W83627EHG [] = "W83627EHG" ;
24202511 static const char __initdata sio_name_W83627DHG [] = "W83627DHG" ;
24212512 static const char __initdata sio_name_W83627DHG_P [] = "W83627DHG-P" ;
2513+ static const char __initdata sio_name_W83627UHG [] = "W83627UHG" ;
24222514 static const char __initdata sio_name_W83667HG [] = "W83667HG" ;
24232515 static const char __initdata sio_name_W83667HG_B [] = "W83667HG-B" ;
24242516 static const char __initdata sio_name_NCT6775 [] = "NCT6775F" ;
@@ -2451,6 +2543,10 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
24512543 sio_data -> kind = w83627dhg_p ;
24522544 sio_name = sio_name_W83627DHG_P ;
24532545 break ;
2546+ case SIO_W83627UHG_ID :
2547+ sio_data -> kind = w83627uhg ;
2548+ sio_name = sio_name_W83627UHG ;
2549+ break ;
24542550 case SIO_W83667HG_ID :
24552551 sio_data -> kind = w83667hg ;
24562552 sio_name = sio_name_W83667HG ;
0 commit comments