Commit 3c2e3512 authored by Guenter Roeck's avatar Guenter Roeck

hwmon: (it87) Pass SIO base address as parameter to superio functions

This will let us support more than one chip on different SIO addresses
with the same driver.
Tested-by: default avatarMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 8e50e3c3
...@@ -80,9 +80,9 @@ MODULE_PARM_DESC(force_id, "Override the detected device ID"); ...@@ -80,9 +80,9 @@ MODULE_PARM_DESC(force_id, "Override the detected device ID");
static struct platform_device *it87_pdev; static struct platform_device *it87_pdev;
#define REG 0x2e /* The register to read/write */ #define REG_2E 0x2e /* The register to read/write */
#define DEV 0x07 /* Register: Logical device select */ #define DEV 0x07 /* Register: Logical device select */
#define VAL 0x2f /* The value to read/write */
#define PME 0x04 /* The device with the fan registers in it */ #define PME 0x04 /* The device with the fan registers in it */
/* The device with the IT8718F/IT8720F VID value in it */ /* The device with the IT8718F/IT8720F VID value in it */
...@@ -91,54 +91,54 @@ static struct platform_device *it87_pdev; ...@@ -91,54 +91,54 @@ static struct platform_device *it87_pdev;
#define DEVID 0x20 /* Register: Device ID */ #define DEVID 0x20 /* Register: Device ID */
#define DEVREV 0x22 /* Register: Device Revision */ #define DEVREV 0x22 /* Register: Device Revision */
static inline int superio_inb(int reg) static inline int superio_inb(int ioreg, int reg)
{ {
outb(reg, REG); outb(reg, ioreg);
return inb(VAL); return inb(ioreg + 1);
} }
static inline void superio_outb(int reg, int val) static inline void superio_outb(int ioreg, int reg, int val)
{ {
outb(reg, REG); outb(reg, ioreg);
outb(val, VAL); outb(val, ioreg + 1);
} }
static int superio_inw(int reg) static int superio_inw(int ioreg, int reg)
{ {
int val; int val;
outb(reg++, REG); outb(reg++, ioreg);
val = inb(VAL) << 8; val = inb(ioreg + 1) << 8;
outb(reg, REG); outb(reg, ioreg);
val |= inb(VAL); val |= inb(ioreg + 1);
return val; return val;
} }
static inline void superio_select(int ldn) static inline void superio_select(int ioreg, int ldn)
{ {
outb(DEV, REG); outb(DEV, ioreg);
outb(ldn, VAL); outb(ldn, ioreg + 1);
} }
static inline int superio_enter(void) static inline int superio_enter(int ioreg)
{ {
/* /*
* Try to reserve REG and REG + 1 for exclusive access. * Try to reserve ioreg and ioreg + 1 for exclusive access.
*/ */
if (!request_muxed_region(REG, 2, DRVNAME)) if (!request_muxed_region(ioreg, 2, DRVNAME))
return -EBUSY; return -EBUSY;
outb(0x87, REG); outb(0x87, ioreg);
outb(0x01, REG); outb(0x01, ioreg);
outb(0x55, REG); outb(0x55, ioreg);
outb(0x55, REG); outb(0x55, ioreg);
return 0; return 0;
} }
static inline void superio_exit(void) static inline void superio_exit(int ioreg)
{ {
outb(0x02, REG); outb(0x02, ioreg);
outb(0x02, VAL); outb(0x02, ioreg + 1);
release_region(REG, 2); release_region(ioreg, 2);
} }
/* Logical device 4 registers */ /* Logical device 4 registers */
...@@ -1929,20 +1929,20 @@ static const struct attribute_group it87_group_label = { ...@@ -1929,20 +1929,20 @@ static const struct attribute_group it87_group_label = {
}; };
/* SuperIO detection - will change isa_address if a chip is found */ /* SuperIO detection - will change isa_address if a chip is found */
static int __init it87_find(unsigned short *address, static int __init it87_find(int sioaddr, unsigned short *address,
struct it87_sio_data *sio_data) struct it87_sio_data *sio_data)
{ {
int err; int err;
u16 chip_type; u16 chip_type;
const char *board_vendor, *board_name; const char *board_vendor, *board_name;
const struct it87_devices *config; const struct it87_devices *config;
err = superio_enter(); err = superio_enter(sioaddr);
if (err) if (err)
return err; return err;
err = -ENODEV; err = -ENODEV;
chip_type = force_id ? force_id : superio_inw(DEVID); chip_type = force_id ? force_id : superio_inw(sioaddr, DEVID);
switch (chip_type) { switch (chip_type) {
case IT8705F_DEVID: case IT8705F_DEVID:
...@@ -2005,20 +2005,20 @@ static int __init it87_find(unsigned short *address, ...@@ -2005,20 +2005,20 @@ static int __init it87_find(unsigned short *address,
goto exit; goto exit;
} }
superio_select(PME); superio_select(sioaddr, PME);
if (!(superio_inb(IT87_ACT_REG) & 0x01)) { if (!(superio_inb(sioaddr, IT87_ACT_REG) & 0x01)) {
pr_info("Device not activated, skipping\n"); pr_info("Device not activated, skipping\n");
goto exit; goto exit;
} }
*address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1);
if (*address == 0) { if (*address == 0) {
pr_info("Base address not set, skipping\n"); pr_info("Base address not set, skipping\n");
goto exit; goto exit;
} }
err = 0; err = 0;
sio_data->revision = superio_inb(DEVREV) & 0x0f; sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f;
pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type, pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type,
it87_devices[sio_data->type].suffix, it87_devices[sio_data->type].suffix,
*address, sio_data->revision); *address, sio_data->revision);
...@@ -2047,18 +2047,19 @@ static int __init it87_find(unsigned short *address, ...@@ -2047,18 +2047,19 @@ static int __init it87_find(unsigned short *address,
/* Read GPIO config and VID value from LDN 7 (GPIO) */ /* Read GPIO config and VID value from LDN 7 (GPIO) */
if (sio_data->type == it87) { if (sio_data->type == it87) {
/* The IT8705F has a different LD number for GPIO */ /* The IT8705F has a different LD number for GPIO */
superio_select(5); superio_select(sioaddr, 5);
sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; sio_data->beep_pin = superio_inb(sioaddr,
IT87_SIO_BEEP_PIN_REG) & 0x3f;
} else if (sio_data->type == it8783) { } else if (sio_data->type == it8783) {
int reg25, reg27, reg2a, reg2c, regef; int reg25, reg27, reg2a, reg2c, regef;
superio_select(GPIO); superio_select(sioaddr, GPIO);
reg25 = superio_inb(IT87_SIO_GPIO1_REG); reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
reg27 = superio_inb(IT87_SIO_GPIO3_REG); reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
reg2a = superio_inb(IT87_SIO_PINX1_REG); reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
reg2c = superio_inb(IT87_SIO_PINX2_REG); reg2c = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
regef = superio_inb(IT87_SIO_SPI_REG); regef = superio_inb(sioaddr, IT87_SIO_SPI_REG);
/* Check if fan3 is there or not */ /* Check if fan3 is there or not */
if ((reg27 & (1 << 0)) || !(reg2c & (1 << 2))) if ((reg27 & (1 << 0)) || !(reg2c & (1 << 2)))
...@@ -2101,7 +2102,8 @@ static int __init it87_find(unsigned short *address, ...@@ -2101,7 +2102,8 @@ static int __init it87_find(unsigned short *address,
*/ */
if (!(reg2c & (1 << 1))) { if (!(reg2c & (1 << 1))) {
reg2c |= (1 << 1); reg2c |= (1 << 1);
superio_outb(IT87_SIO_PINX2_REG, reg2c); superio_outb(sioaddr, IT87_SIO_PINX2_REG,
reg2c);
pr_notice("Routing internal VCCH5V to in7.\n"); pr_notice("Routing internal VCCH5V to in7.\n");
} }
pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n"); pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
...@@ -2113,13 +2115,14 @@ static int __init it87_find(unsigned short *address, ...@@ -2113,13 +2115,14 @@ static int __init it87_find(unsigned short *address,
if (reg2c & (1 << 1)) if (reg2c & (1 << 1))
sio_data->internal |= (1 << 1); sio_data->internal |= (1 << 1);
sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; sio_data->beep_pin = superio_inb(sioaddr,
IT87_SIO_BEEP_PIN_REG) & 0x3f;
} else if (sio_data->type == it8603) { } else if (sio_data->type == it8603) {
int reg27, reg29; int reg27, reg29;
superio_select(GPIO); superio_select(sioaddr, GPIO);
reg27 = superio_inb(IT87_SIO_GPIO3_REG); reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
/* Check if fan3 is there or not */ /* Check if fan3 is there or not */
if (reg27 & (1 << 6)) if (reg27 & (1 << 6))
...@@ -2128,7 +2131,7 @@ static int __init it87_find(unsigned short *address, ...@@ -2128,7 +2131,7 @@ static int __init it87_find(unsigned short *address,
sio_data->skip_fan |= (1 << 2); sio_data->skip_fan |= (1 << 2);
/* Check if fan2 is there or not */ /* Check if fan2 is there or not */
reg29 = superio_inb(IT87_SIO_GPIO5_REG); reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
if (reg29 & (1 << 1)) if (reg29 & (1 << 1))
sio_data->skip_pwm |= (1 << 1); sio_data->skip_pwm |= (1 << 1);
if (reg29 & (1 << 2)) if (reg29 & (1 << 2))
...@@ -2137,38 +2140,39 @@ static int __init it87_find(unsigned short *address, ...@@ -2137,38 +2140,39 @@ static int __init it87_find(unsigned short *address,
sio_data->skip_in |= (1 << 5); /* No VIN5 */ sio_data->skip_in |= (1 << 5); /* No VIN5 */
sio_data->skip_in |= (1 << 6); /* No VIN6 */ sio_data->skip_in |= (1 << 6); /* No VIN6 */
sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; sio_data->beep_pin = superio_inb(sioaddr,
IT87_SIO_BEEP_PIN_REG) & 0x3f;
} else if (sio_data->type == it8620) { } else if (sio_data->type == it8620) {
int reg; int reg;
superio_select(GPIO); superio_select(sioaddr, GPIO);
/* Check for pwm5 */ /* Check for pwm5 */
reg = superio_inb(IT87_SIO_GPIO1_REG); reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
if (reg & (1 << 6)) if (reg & (1 << 6))
sio_data->skip_pwm |= (1 << 4); sio_data->skip_pwm |= (1 << 4);
/* Check for fan4, fan5 */ /* Check for fan4, fan5 */
reg = superio_inb(IT87_SIO_GPIO2_REG); reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
if (!(reg & (1 << 5))) if (!(reg & (1 << 5)))
sio_data->skip_fan |= (1 << 3); sio_data->skip_fan |= (1 << 3);
if (!(reg & (1 << 4))) if (!(reg & (1 << 4)))
sio_data->skip_fan |= (1 << 4); sio_data->skip_fan |= (1 << 4);
/* Check for pwm3, fan3 */ /* Check for pwm3, fan3 */
reg = superio_inb(IT87_SIO_GPIO3_REG); reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
if (reg & (1 << 6)) if (reg & (1 << 6))
sio_data->skip_pwm |= (1 << 2); sio_data->skip_pwm |= (1 << 2);
if (reg & (1 << 7)) if (reg & (1 << 7))
sio_data->skip_fan |= (1 << 2); sio_data->skip_fan |= (1 << 2);
/* Check for pwm4 */ /* Check for pwm4 */
reg = superio_inb(IT87_SIO_GPIO4_REG); reg = superio_inb(sioaddr, IT87_SIO_GPIO4_REG);
if (!(reg & (1 << 2))) if (!(reg & (1 << 2)))
sio_data->skip_pwm |= (1 << 3); sio_data->skip_pwm |= (1 << 3);
/* Check for pwm2, fan2 */ /* Check for pwm2, fan2 */
reg = superio_inb(IT87_SIO_GPIO5_REG); reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
if (reg & (1 << 1)) if (reg & (1 << 1))
sio_data->skip_pwm |= (1 << 1); sio_data->skip_pwm |= (1 << 1);
if (reg & (1 << 2)) if (reg & (1 << 2))
...@@ -2179,14 +2183,15 @@ static int __init it87_find(unsigned short *address, ...@@ -2179,14 +2183,15 @@ static int __init it87_find(unsigned short *address,
sio_data->skip_fan |= (1 << 5); sio_data->skip_fan |= (1 << 5);
} }
sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; sio_data->beep_pin = superio_inb(sioaddr,
IT87_SIO_BEEP_PIN_REG) & 0x3f;
} else { } else {
int reg; int reg;
bool uart6; bool uart6;
superio_select(GPIO); superio_select(sioaddr, GPIO);
reg = superio_inb(IT87_SIO_GPIO3_REG); reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
if (!sio_data->skip_vid) { if (!sio_data->skip_vid) {
/* We need at least 4 VID pins */ /* We need at least 4 VID pins */
if (reg & 0x0f) { if (reg & 0x0f) {
...@@ -2202,7 +2207,7 @@ static int __init it87_find(unsigned short *address, ...@@ -2202,7 +2207,7 @@ static int __init it87_find(unsigned short *address,
sio_data->skip_fan |= (1 << 2); sio_data->skip_fan |= (1 << 2);
/* Check if fan2 is there or not */ /* Check if fan2 is there or not */
reg = superio_inb(IT87_SIO_GPIO5_REG); reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
if (reg & (1 << 1)) if (reg & (1 << 1))
sio_data->skip_pwm |= (1 << 1); sio_data->skip_pwm |= (1 << 1);
if (reg & (1 << 2)) if (reg & (1 << 2))
...@@ -2210,9 +2215,10 @@ static int __init it87_find(unsigned short *address, ...@@ -2210,9 +2215,10 @@ static int __init it87_find(unsigned short *address,
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(sioaddr,
IT87_SIO_VID_REG);
reg = superio_inb(IT87_SIO_PINX2_REG); reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
uart6 = sio_data->type == it8782 && (reg & (1 << 2)); uart6 = sio_data->type == it8782 && (reg & (1 << 2));
...@@ -2232,7 +2238,7 @@ static int __init it87_find(unsigned short *address, ...@@ -2232,7 +2238,7 @@ static int __init it87_find(unsigned short *address,
*/ */
if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) { if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) {
reg |= (1 << 1); reg |= (1 << 1);
superio_outb(IT87_SIO_PINX2_REG, reg); superio_outb(sioaddr, IT87_SIO_PINX2_REG, reg);
pr_notice("Routing internal VCCH to in7\n"); pr_notice("Routing internal VCCH to in7\n");
} }
if (reg & (1 << 0)) if (reg & (1 << 0))
...@@ -2254,7 +2260,8 @@ static int __init it87_find(unsigned short *address, ...@@ -2254,7 +2260,8 @@ static int __init it87_find(unsigned short *address,
sio_data->skip_temp |= (1 << 2); sio_data->skip_temp |= (1 << 2);
} }
sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; sio_data->beep_pin = superio_inb(sioaddr,
IT87_SIO_BEEP_PIN_REG) & 0x3f;
} }
if (sio_data->beep_pin) if (sio_data->beep_pin)
pr_info("Beeping is supported\n"); pr_info("Beeping is supported\n");
...@@ -2279,7 +2286,7 @@ static int __init it87_find(unsigned short *address, ...@@ -2279,7 +2286,7 @@ static int __init it87_find(unsigned short *address,
} }
exit: exit:
superio_exit(); superio_exit(sioaddr);
return err; return err;
} }
...@@ -2939,7 +2946,7 @@ static int __init sm_it87_init(void) ...@@ -2939,7 +2946,7 @@ static int __init sm_it87_init(void)
struct it87_sio_data sio_data; struct it87_sio_data sio_data;
memset(&sio_data, 0, sizeof(struct it87_sio_data)); memset(&sio_data, 0, sizeof(struct it87_sio_data));
err = it87_find(&isa_address, &sio_data); err = it87_find(REG_2E, &isa_address, &sio_data);
if (err) if (err)
return err; return err;
err = platform_driver_register(&it87_driver); err = platform_driver_register(&it87_driver);
......
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