aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83795.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/w83795.c')
-rw-r--r--drivers/hwmon/w83795.c218
1 files changed, 119 insertions, 99 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index e25a2e31df3f..511bced1ee97 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -438,6 +438,123 @@ static int w83795_write(struct i2c_client *client, u16 reg, u8 value)
438 return err; 438 return err;
439} 439}
440 440
441static void w83795_update_limits(struct i2c_client *client)
442{
443 struct w83795_data *data = i2c_get_clientdata(client);
444 int i, limit;
445
446 /* Read the voltage limits */
447 for (i = 0; i < ARRAY_SIZE(data->in); i++) {
448 if (!(data->has_in & (1 << i)))
449 continue;
450 data->in[i][IN_MAX] =
451 w83795_read(client, W83795_REG_IN[i][IN_MAX]);
452 data->in[i][IN_LOW] =
453 w83795_read(client, W83795_REG_IN[i][IN_LOW]);
454 }
455 for (i = 0; i < ARRAY_SIZE(data->in_lsb); i++) {
456 if ((i == 2 && data->chip_type == w83795adg) ||
457 (i >= 4 && !(data->has_in & (1 << (i + 11)))))
458 continue;
459 data->in_lsb[i][IN_MAX] =
460 w83795_read(client, IN_LSB_REG(i, IN_MAX));
461 data->in_lsb[i][IN_LOW] =
462 w83795_read(client, IN_LSB_REG(i, IN_LOW));
463 }
464
465 /* Read the fan limits */
466 for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
467 u8 lsb;
468
469 /* Each register contains LSB for 2 fans, but we want to
470 * read it only once to save time */
471 if ((i & 1) == 0 && (data->has_fan & (3 << i)))
472 lsb = w83795_read(client, W83795_REG_FAN_MIN_LSB(i));
473
474 if (!(data->has_fan & (1 << i)))
475 continue;
476 data->fan_min[i] =
477 w83795_read(client, W83795_REG_FAN_MIN_HL(i)) << 4;
478 data->fan_min[i] |=
479 (lsb >> W83795_REG_FAN_MIN_LSB_SHIFT(i)) & 0x0F;
480 }
481
482 /* Read the temperature limits */
483 for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
484 if (!(data->has_temp & (1 << i)))
485 continue;
486 for (limit = TEMP_CRIT; limit <= TEMP_WARN_HYST; limit++)
487 data->temp[i][limit] =
488 w83795_read(client, W83795_REG_TEMP[i][limit]);
489 }
490
491 /* Read the DTS limits */
492 if (data->enable_dts != 0) {
493 for (limit = DTS_CRIT; limit <= DTS_WARN_HYST; limit++)
494 data->dts_ext[limit] =
495 w83795_read(client, W83795_REG_DTS_EXT(limit));
496 }
497
498 /* Read beep settings */
499 for (i = 0; i < ARRAY_SIZE(data->beeps); i++)
500 data->beeps[i] = w83795_read(client, W83795_REG_BEEP(i));
501}
502
503static void w83795_update_pwm_config(struct i2c_client *client)
504{
505 struct w83795_data *data = i2c_get_clientdata(client);
506 int i, tmp;
507
508 /* Read temperature source selection */
509 for (i = 0; i < ARRAY_SIZE(data->temp_src); i++)
510 data->temp_src[i] = w83795_read(client, W83795_REG_TSS(i));
511
512 /* Read automatic fan speed control settings */
513 data->pwm_fcms[0] = w83795_read(client, W83795_REG_FCMS1);
514 data->pwm_fcms[1] = w83795_read(client, W83795_REG_FCMS2);
515 for (i = 0; i < ARRAY_SIZE(data->pwm_tfmr); i++)
516 data->pwm_tfmr[i] = w83795_read(client, W83795_REG_TFMR(i));
517 data->pwm_fomc = w83795_read(client, W83795_REG_FOMC);
518 for (i = 0; i < data->has_pwm; i++) {
519 for (tmp = PWM_FREQ; tmp <= PWM_STOP_TIME; tmp++)
520 data->pwm[i][tmp] =
521 w83795_read(client, W83795_REG_PWM(i, tmp));
522 }
523 for (i = 0; i < ARRAY_SIZE(data->target_speed); i++) {
524 data->target_speed[i] =
525 w83795_read(client, W83795_REG_FTSH(i)) << 4;
526 data->target_speed[i] |=
527 w83795_read(client, W83795_REG_FTSL(i)) >> 4;
528 }
529 data->tol_speed = w83795_read(client, W83795_REG_TFTS) & 0x3f;
530
531 for (i = 0; i < ARRAY_SIZE(data->pwm_temp); i++) {
532 data->pwm_temp[i][TEMP_PWM_TTTI] =
533 w83795_read(client, W83795_REG_TTTI(i)) & 0x7f;
534 data->pwm_temp[i][TEMP_PWM_CTFS] =
535 w83795_read(client, W83795_REG_CTFS(i));
536 tmp = w83795_read(client, W83795_REG_HT(i));
537 data->pwm_temp[i][TEMP_PWM_HCT] = (tmp >> 4) & 0x0f;
538 data->pwm_temp[i][TEMP_PWM_HOT] = tmp & 0x0f;
539 }
540
541 /* Read SmartFanIV trip points */
542 for (i = 0; i < ARRAY_SIZE(data->sf4_reg); i++) {
543 for (tmp = 0; tmp < 7; tmp++) {
544 data->sf4_reg[i][SF4_TEMP][tmp] =
545 w83795_read(client,
546 W83795_REG_SF4_TEMP(i, tmp));
547 data->sf4_reg[i][SF4_PWM][tmp] =
548 w83795_read(client, W83795_REG_SF4_PWM(i, tmp));
549 }
550 }
551
552 /* Read setup PWM */
553 for (i = 0; i < ARRAY_SIZE(data->setup_pwm); i++)
554 data->setup_pwm[i] =
555 w83795_read(client, W83795_REG_SETUP_PWM(i));
556}
557
441static struct w83795_data *w83795_update_device(struct device *dev) 558static struct w83795_data *w83795_update_device(struct device *dev)
442{ 559{
443 struct i2c_client *client = to_i2c_client(dev); 560 struct i2c_client *client = to_i2c_client(dev);
@@ -1899,112 +2016,15 @@ static int w83795_probe(struct i2c_client *client,
1899 } 2016 }
1900 } 2017 }
1901 2018
1902 /* Read the voltage limits */
1903 for (i = 0; i < ARRAY_SIZE(data->in); i++) {
1904 if (!(data->has_in & (1 << i)))
1905 continue;
1906 data->in[i][IN_MAX] =
1907 w83795_read(client, W83795_REG_IN[i][IN_MAX]);
1908 data->in[i][IN_LOW] =
1909 w83795_read(client, W83795_REG_IN[i][IN_LOW]);
1910 }
1911 for (i = 0; i < ARRAY_SIZE(data->in_lsb); i++) {
1912 if ((i == 2 && data->chip_type == w83795adg) ||
1913 (i >= 4 && !(data->has_in & (1 << (i + 11)))))
1914 continue;
1915 data->in_lsb[i][IN_MAX] =
1916 w83795_read(client, IN_LSB_REG(i, IN_MAX));
1917 data->in_lsb[i][IN_LOW] =
1918 w83795_read(client, IN_LSB_REG(i, IN_LOW));
1919 }
1920 data->has_gain = w83795_read(client, W83795_REG_VMIGB_CTRL) & 0x0f; 2019 data->has_gain = w83795_read(client, W83795_REG_VMIGB_CTRL) & 0x0f;
1921 2020 w83795_update_limits(client);
1922 /* Read the fan limits */
1923 for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
1924 /* Each register contains LSB for 2 fans, but we want to
1925 * read it only once to save time */
1926 if ((i & 1) == 0 && (data->has_fan & (3 << i)))
1927 tmp = w83795_read(client, W83795_REG_FAN_MIN_LSB(i));
1928
1929 if (!(data->has_fan & (1 << i)))
1930 continue;
1931 data->fan_min[i] =
1932 w83795_read(client, W83795_REG_FAN_MIN_HL(i)) << 4;
1933 data->fan_min[i] |=
1934 (tmp >> W83795_REG_FAN_MIN_LSB_SHIFT(i)) & 0x0F;
1935 }
1936
1937 /* Read the temperature limits */
1938 for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
1939 if (!(data->has_temp & (1 << i)))
1940 continue;
1941 for (tmp = TEMP_CRIT; tmp <= TEMP_WARN_HYST; tmp++)
1942 data->temp[i][tmp] =
1943 w83795_read(client, W83795_REG_TEMP[i][tmp]);
1944 }
1945
1946 /* Read the DTS limits */
1947 if (data->enable_dts != 0) {
1948 for (i = DTS_CRIT; i <= DTS_WARN_HYST; i++)
1949 data->dts_ext[i] =
1950 w83795_read(client, W83795_REG_DTS_EXT(i));
1951 }
1952
1953 /* First update temp source selction */
1954 for (i = 0; i < 3; i++)
1955 data->temp_src[i] = w83795_read(client, W83795_REG_TSS(i));
1956 2021
1957 /* pwm and smart fan */ 2022 /* pwm and smart fan */
1958 if (data->chip_type == w83795g) 2023 if (data->chip_type == w83795g)
1959 data->has_pwm = 8; 2024 data->has_pwm = 8;
1960 else 2025 else
1961 data->has_pwm = 2; 2026 data->has_pwm = 2;
1962 data->pwm_fcms[0] = w83795_read(client, W83795_REG_FCMS1); 2027 w83795_update_pwm_config(client);
1963 data->pwm_fcms[1] = w83795_read(client, W83795_REG_FCMS2);
1964 for (i = 0; i < ARRAY_SIZE(data->pwm_tfmr); i++)
1965 data->pwm_tfmr[i] = w83795_read(client, W83795_REG_TFMR(i));
1966 data->pwm_fomc = w83795_read(client, W83795_REG_FOMC);
1967 for (i = 0; i < data->has_pwm; i++) {
1968 for (tmp = PWM_FREQ; tmp <= PWM_STOP_TIME; tmp++)
1969 data->pwm[i][tmp] =
1970 w83795_read(client, W83795_REG_PWM(i, tmp));
1971 }
1972 for (i = 0; i < 8; i++) {
1973 data->target_speed[i] =
1974 w83795_read(client, W83795_REG_FTSH(i)) << 4;
1975 data->target_speed[i] |=
1976 w83795_read(client, W83795_REG_FTSL(i)) >> 4;
1977 }
1978 data->tol_speed = w83795_read(client, W83795_REG_TFTS) & 0x3f;
1979
1980 for (i = 0; i < ARRAY_SIZE(data->pwm_temp); i++) {
1981 data->pwm_temp[i][TEMP_PWM_TTTI] =
1982 w83795_read(client, W83795_REG_TTTI(i)) & 0x7f;
1983 data->pwm_temp[i][TEMP_PWM_CTFS] =
1984 w83795_read(client, W83795_REG_CTFS(i));
1985 tmp = w83795_read(client, W83795_REG_HT(i));
1986 data->pwm_temp[i][TEMP_PWM_HCT] = (tmp >> 4) & 0x0f;
1987 data->pwm_temp[i][TEMP_PWM_HOT] = tmp & 0x0f;
1988 }
1989 for (i = 0; i < ARRAY_SIZE(data->sf4_reg); i++) {
1990 for (tmp = 0; tmp < 7; tmp++) {
1991 data->sf4_reg[i][SF4_TEMP][tmp] =
1992 w83795_read(client,
1993 W83795_REG_SF4_TEMP(i, tmp));
1994 data->sf4_reg[i][SF4_PWM][tmp] =
1995 w83795_read(client, W83795_REG_SF4_PWM(i, tmp));
1996 }
1997 }
1998
1999 /* Setup PWM Register */
2000 for (i = 0; i < 3; i++) {
2001 data->setup_pwm[i] =
2002 w83795_read(client, W83795_REG_SETUP_PWM(i));
2003 }
2004
2005 /* Read beep settings */
2006 for (i = 0; i < ARRAY_SIZE(data->beeps); i++)
2007 data->beeps[i] = w83795_read(client, W83795_REG_BEEP(i));
2008 2028
2009 err = w83795_handle_files(dev, device_create_file); 2029 err = w83795_handle_files(dev, device_create_file);
2010 if (err) 2030 if (err)