Commit 591ec650 authored by Jean Delvare's avatar Jean Delvare

hwmon: (it87) Check for fan2 and fan3 availability

The fan2 and fan3 input and output pins can be used as GPIOs. Check
their function before exposing their sysfs attributes and accessing
their registers.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 895ff267
...@@ -125,6 +125,7 @@ superio_exit(void) ...@@ -125,6 +125,7 @@ superio_exit(void)
/* Logical device 7 registers (IT8712F and later) */ /* Logical device 7 registers (IT8712F and later) */
#define IT87_SIO_GPIO3_REG 0x27 #define IT87_SIO_GPIO3_REG 0x27
#define IT87_SIO_GPIO5_REG 0x29
#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */ #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
#define IT87_SIO_VID_REG 0xfc /* VID value */ #define IT87_SIO_VID_REG 0xfc /* VID value */
...@@ -245,8 +246,9 @@ struct it87_sio_data { ...@@ -245,8 +246,9 @@ struct it87_sio_data {
/* Values read from Super-I/O config space */ /* Values read from Super-I/O config space */
u8 revision; u8 revision;
u8 vid_value; u8 vid_value;
/* Features skipped based on config or DMI */
u8 skip_vid; u8 skip_vid;
/* Values set based on DMI strings */ u8 skip_fan;
u8 skip_pwm; u8 skip_pwm;
}; };
...@@ -1044,6 +1046,19 @@ static int __init it87_find(unsigned short *address, ...@@ -1044,6 +1046,19 @@ static int __init it87_find(unsigned short *address,
sio_data->skip_vid = 1; sio_data->skip_vid = 1;
} }
/* Check if fan3 is there or not */
if (reg & (1 << 6))
sio_data->skip_pwm |= (1 << 2);
if (reg & (1 << 7))
sio_data->skip_fan |= (1 << 2);
/* Check if fan2 is there or not */
reg = superio_inb(IT87_SIO_GPIO5_REG);
if (reg & (1 << 1))
sio_data->skip_pwm |= (1 << 1);
if (reg & (1 << 2))
sio_data->skip_fan |= (1 << 1);
if ((sio_data->type == it8718 || sio_data->type == it8720) if ((sio_data->type == it8718 || sio_data->type == it8720)
&& !(sio_data->skip_vid)) && !(sio_data->skip_vid))
sio_data->vid_value = superio_inb(IT87_SIO_VID_REG); sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
...@@ -1367,8 +1382,10 @@ static int __devinit it87_check_pwm(struct device *dev) ...@@ -1367,8 +1382,10 @@ static int __devinit it87_check_pwm(struct device *dev)
/* Called when we have found a new IT87. */ /* Called when we have found a new IT87. */
static void __devinit it87_init_device(struct platform_device *pdev) static void __devinit it87_init_device(struct platform_device *pdev)
{ {
struct it87_sio_data *sio_data = pdev->dev.platform_data;
struct it87_data *data = platform_get_drvdata(pdev); struct it87_data *data = platform_get_drvdata(pdev);
int tmp, i; int tmp, i;
u8 mask;
/* initialize to sane defaults: /* initialize to sane defaults:
* - if the chip is in manual pwm mode, this will be overwritten with * - if the chip is in manual pwm mode, this will be overwritten with
...@@ -1414,10 +1431,11 @@ static void __devinit it87_init_device(struct platform_device *pdev) ...@@ -1414,10 +1431,11 @@ static void __devinit it87_init_device(struct platform_device *pdev)
} }
/* Check if tachometers are reset manually or by some reason */ /* Check if tachometers are reset manually or by some reason */
mask = 0x70 & ~(sio_data->skip_fan << 4);
data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
if ((data->fan_main_ctrl & 0x70) == 0) { if ((data->fan_main_ctrl & mask) == 0) {
/* Enable all fan tachometers */ /* Enable all fan tachometers */
data->fan_main_ctrl |= 0x70; data->fan_main_ctrl |= mask;
it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
} }
data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
...@@ -1440,6 +1458,9 @@ static void __devinit it87_init_device(struct platform_device *pdev) ...@@ -1440,6 +1458,9 @@ static void __devinit it87_init_device(struct platform_device *pdev)
} }
} }
/* Fan input pins may be used for alternative functions */
data->has_fan &= ~sio_data->skip_fan;
/* Set current fan mode registers and the default settings for the /* Set current fan mode registers and the default settings for the
* other mode registers */ * other mode registers */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment