From 5b5112711f86b7c24a8397e2787f22c532fa4509 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Mon, 8 Jul 2013 13:50:04 -0700 Subject: [PATCH] hwmon: (nct6775) Avoid using device platform data outside probe function Plan going forward is to attach all device attributes to the hwmon device and no longer to the platform device. With that change, accessing platform data outside the probe function will be more difficult. To avoid the problem, change code to no longer rely on it. Signed-off-by: Guenter Roeck --- nct6775.c | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/nct6775.c b/nct6775.c index b1f0b8d..075bb36 100644 --- a/nct6775.c +++ b/nct6775.c @@ -721,6 +721,7 @@ static inline u8 in_to_reg(u32 val, u8 nr) struct nct6775_data { int addr; /* IO base of hw monitor block */ + int sioreg; /* SIO register address */ enum kinds kind; const char *name; @@ -3009,7 +3010,6 @@ clear_caseopen(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct nct6775_data *data = dev_get_drvdata(dev); - struct nct6775_sio_data *sio_data = dev->platform_data; int nr = to_sensor_dev_attr(attr)->index - INTRUSION_ALARM_BASE; unsigned long val; u8 reg; @@ -3025,19 +3025,19 @@ clear_caseopen(struct device *dev, struct device_attribute *attr, * The CR registers are the same for all chips, and not all chips * support clearing the caseopen status through "regular" registers. */ - ret = superio_enter(sio_data->sioreg); + ret = superio_enter(data->sioreg); if (ret) { count = ret; goto error; } - superio_select(sio_data->sioreg, NCT6775_LD_ACPI); - reg = superio_inb(sio_data->sioreg, NCT6775_REG_CR_CASEOPEN_CLR[nr]); + superio_select(data->sioreg, NCT6775_LD_ACPI); + reg = superio_inb(data->sioreg, NCT6775_REG_CR_CASEOPEN_CLR[nr]); reg |= NCT6775_CR_CASEOPEN_CLR_MASK[nr]; - superio_outb(sio_data->sioreg, NCT6775_REG_CR_CASEOPEN_CLR[nr], reg); + superio_outb(data->sioreg, NCT6775_REG_CR_CASEOPEN_CLR[nr], reg); reg &= ~NCT6775_CR_CASEOPEN_CLR_MASK[nr]; - superio_outb(sio_data->sioreg, NCT6775_REG_CR_CASEOPEN_CLR[nr], reg); - superio_exit(sio_data->sioreg); + superio_outb(data->sioreg, NCT6775_REG_CR_CASEOPEN_CLR[nr], reg); + superio_exit(data->sioreg); data->valid = false; /* Force cache refresh */ error: @@ -3164,22 +3164,22 @@ static inline void nct6775_init_device(struct nct6775_data *data) } static void -nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data, - struct nct6775_data *data) +nct6775_check_fan_inputs(struct nct6775_data *data) { - int regval; bool fan3pin, fan4pin, fan4min, fan5pin, fan6pin; bool pwm3pin, pwm4pin, pwm5pin, pwm6pin; + int sioreg = data->sioreg; + int regval; /* fan4 and fan5 share some pins with the GPIO and serial flash */ if (data->kind == nct6775) { - regval = superio_inb(sio_data->sioreg, 0x2c); + regval = superio_inb(sioreg, 0x2c); fan3pin = regval & (1 << 6); pwm3pin = regval & (1 << 7); /* On NCT6775, fan4 shares pins with the fdc interface */ - fan4pin = !(superio_inb(sio_data->sioreg, 0x2A) & 0x80); + fan4pin = !(superio_inb(sioreg, 0x2A) & 0x80); fan4min = false; fan5pin = false; fan6pin = false; @@ -3187,25 +3187,25 @@ nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data, pwm5pin = false; pwm6pin = false; } else if (data->kind == nct6776) { - bool gpok = superio_inb(sio_data->sioreg, 0x27) & 0x80; + bool gpok = superio_inb(sioreg, 0x27) & 0x80; - superio_select(sio_data->sioreg, NCT6775_LD_HWM); - regval = superio_inb(sio_data->sioreg, SIO_REG_ENABLE); + superio_select(sioreg, NCT6775_LD_HWM); + regval = superio_inb(sioreg, SIO_REG_ENABLE); if (regval & 0x80) fan3pin = gpok; else - fan3pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x40); + fan3pin = !(superio_inb(sioreg, 0x24) & 0x40); if (regval & 0x40) fan4pin = gpok; else - fan4pin = superio_inb(sio_data->sioreg, 0x1C) & 0x01; + fan4pin = superio_inb(sioreg, 0x1C) & 0x01; if (regval & 0x20) fan5pin = gpok; else - fan5pin = superio_inb(sio_data->sioreg, 0x1C) & 0x02; + fan5pin = superio_inb(sioreg, 0x1C) & 0x02; fan4min = fan4pin; fan6pin = false; @@ -3214,7 +3214,7 @@ nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data, pwm5pin = false; pwm6pin = false; } else if (data->kind == nct6106) { - regval = superio_inb(sio_data->sioreg, 0x24); + regval = superio_inb(sioreg, 0x24); fan3pin = !(regval & 0x80); pwm3pin = regval & 0x08; @@ -3226,7 +3226,7 @@ nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data, pwm5pin = false; pwm6pin = false; } else { /* NCT6779D or NCT6791D */ - regval = superio_inb(sio_data->sioreg, 0x1c); + regval = superio_inb(sioreg, 0x1c); fan3pin = !(regval & (1 << 5)); fan4pin = !(regval & (1 << 6)); @@ -3239,7 +3239,7 @@ nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data, fan4min = fan4pin; if (data->kind == nct6791) { - regval = superio_inb(sio_data->sioreg, 0x2d); + regval = superio_inb(sioreg, 0x2d); fan6pin = (regval & (1 << 1)); pwm6pin = (regval & (1 << 0)); } else { /* NCT6779D */ @@ -3309,6 +3309,7 @@ static int nct6775_probe(struct platform_device *pdev) return -ENOMEM; data->kind = sio_data->kind; + data->sioreg = sio_data->sioreg; data->addr = res->start; mutex_init(&data->update_lock); data->name = nct6775_device_names[data->kind]; @@ -3860,7 +3861,7 @@ static int nct6775_probe(struct platform_device *pdev) data->name); } - nct6775_check_fan_inputs(sio_data, data); + nct6775_check_fan_inputs(data); superio_exit(sio_data->sioreg); @@ -3931,11 +3932,10 @@ static int nct6775_remove(struct platform_device *pdev) static int nct6775_suspend(struct device *dev) { struct nct6775_data *data = nct6775_update_device(dev); - struct nct6775_sio_data *sio_data = dev->platform_data; mutex_lock(&data->update_lock); data->vbat = nct6775_read_value(data, data->REG_VBAT); - if (sio_data->kind == nct6775) { + if (data->kind == nct6775) { data->fandiv1 = nct6775_read_value(data, NCT6775_REG_FANDIV1); data->fandiv2 = nct6775_read_value(data, NCT6775_REG_FANDIV2); } @@ -3947,7 +3947,6 @@ static int nct6775_suspend(struct device *dev) static int nct6775_resume(struct device *dev) { struct nct6775_data *data = dev_get_drvdata(dev); - struct nct6775_sio_data *sio_data = dev->platform_data; int i, j; mutex_lock(&data->update_lock); @@ -3984,7 +3983,7 @@ static int nct6775_resume(struct device *dev) /* Restore other settings */ nct6775_write_value(data, data->REG_VBAT, data->vbat); - if (sio_data->kind == nct6775) { + if (data->kind == nct6775) { nct6775_write_value(data, NCT6775_REG_FANDIV1, data->fandiv1); nct6775_write_value(data, NCT6775_REG_FANDIV2, data->fandiv2); } -- 2.39.5