diff options
Diffstat (limited to 'drivers/hwmon/f71805f.c')
| -rw-r--r-- | drivers/hwmon/f71805f.c | 281 |
1 files changed, 174 insertions, 107 deletions
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c index 525a00bd70b..9e57b77ecd3 100644 --- a/drivers/hwmon/f71805f.c +++ b/drivers/hwmon/f71805f.c @@ -1,7 +1,7 @@ /* * f71805f.c - driver for the Fintek F71805F/FG and F71872F/FG Super-I/O * chips integrated hardware monitoring features - * Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org> + * Copyright (C) 2005-2006 Jean Delvare <jdelvare@suse.de> * * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates * complete hardware monitoring features: voltage, fan and temperature @@ -28,6 +28,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> @@ -200,7 +202,7 @@ struct f71805f_sio_data { static inline long in_from_reg(u8 reg) { - return (reg * 8); + return reg * 8; } /* The 2 least significant bits are not used */ @@ -210,13 +212,13 @@ static inline u8 in_to_reg(long val) return 0; if (val >= 2016) return 0xfc; - return (((val + 16) / 32) << 2); + return ((val + 16) / 32) << 2; } /* in0 is downscaled by a factor 2 internally */ static inline long in0_from_reg(u8 reg) { - return (reg * 16); + return reg * 16; } static inline u8 in0_to_reg(long val) @@ -225,7 +227,7 @@ static inline u8 in0_to_reg(long val) return 0; if (val >= 4032) return 0xfc; - return (((val + 32) / 64) << 2); + return ((val + 32) / 64) << 2; } /* The 4 most significant bits are not used */ @@ -234,17 +236,19 @@ static inline long fan_from_reg(u16 reg) reg &= 0xfff; if (!reg || reg == 0xfff) return 0; - return (1500000 / reg); + return 1500000 / reg; } static inline u16 fan_to_reg(long rpm) { - /* If the low limit is set below what the chip can measure, - store the largest possible 12-bit value in the registers, - so that no alarm will ever trigger. */ + /* + * If the low limit is set below what the chip can measure, + * store the largest possible 12-bit value in the registers, + * so that no alarm will ever trigger. + */ if (rpm < 367) return 0xfff; - return (1500000 / rpm); + return 1500000 / rpm; } static inline unsigned long pwm_freq_from_reg(u8 reg) @@ -276,16 +280,16 @@ static inline int pwm_mode_from_reg(u8 reg) static inline long temp_from_reg(u8 reg) { - return (reg * 1000); + return reg * 1000; } static inline u8 temp_to_reg(long val) { - if (val < 0) - val = 0; - else if (val > 1000 * 0xff) - val = 0xff; - return ((val + 500) / 1000); + if (val <= 0) + return 0; + if (val >= 1000 * 0xff) + return 0xff; + return (val + 500) / 1000; } /* @@ -306,9 +310,11 @@ static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val) outb(val, data->addr + DATA_REG_OFFSET); } -/* It is important to read the MSB first, because doing so latches the - value of the LSB, so we are sure both bytes belong to the same value. - Must be called with data->update_lock held, except during initialization */ +/* + * It is important to read the MSB first, because doing so latches the + * value of the LSB, so we are sure both bytes belong to the same value. + * Must be called with data->update_lock held, except during initialization + */ static u16 f71805f_read16(struct f71805f_data *data, u8 reg) { u16 val; @@ -453,7 +459,12 @@ static ssize_t set_in0_max(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - long val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->in_high[nr] = in0_to_reg(val); @@ -469,7 +480,12 @@ static ssize_t set_in0_min(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - long val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->in_low[nr] = in0_to_reg(val); @@ -515,7 +531,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - long val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->in_high[nr] = in_to_reg(val); @@ -531,7 +552,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - long val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->in_low[nr] = in_to_reg(val); @@ -577,7 +603,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - long val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->fan_low[nr] = fan_to_reg(val); @@ -593,7 +624,12 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - long val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->fan_target[nr] = fan_to_reg(val); @@ -662,7 +698,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - unsigned long val = simple_strtoul(buf, NULL, 10); + unsigned long val; + int err; + + err = kstrtoul(buf, 10, &val); + if (err) + return err; if (val > 255) return -EINVAL; @@ -683,8 +724,13 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - unsigned long val = simple_strtoul(buf, NULL, 10); u8 reg; + unsigned long val; + int err; + + err = kstrtoul(buf, 10, &val); + if (err) + return err; if (val < 1 || val > 3) return -EINVAL; @@ -728,7 +774,12 @@ static ssize_t set_pwm_freq(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - unsigned long val = simple_strtoul(buf, NULL, 10); + unsigned long val; + int err; + + err = kstrtoul(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->pwm_freq[nr] = pwm_freq_to_reg(val); @@ -740,7 +791,7 @@ static ssize_t set_pwm_freq(struct device *dev, struct device_attribute static ssize_t show_pwm_auto_point_temp(struct device *dev, struct device_attribute *devattr, - char* buf) + char *buf) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); @@ -753,13 +804,18 @@ static ssize_t show_pwm_auto_point_temp(struct device *dev, static ssize_t set_pwm_auto_point_temp(struct device *dev, struct device_attribute *devattr, - const char* buf, size_t count) + const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); int pwmnr = attr->nr; int apnr = attr->index; - unsigned long val = simple_strtol(buf, NULL, 10); + unsigned long val; + int err; + + err = kstrtoul(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->auto_points[pwmnr].temp[apnr] = temp_to_reg(val); @@ -772,7 +828,7 @@ static ssize_t set_pwm_auto_point_temp(struct device *dev, static ssize_t show_pwm_auto_point_fan(struct device *dev, struct device_attribute *devattr, - char* buf) + char *buf) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); @@ -785,18 +841,23 @@ static ssize_t show_pwm_auto_point_fan(struct device *dev, static ssize_t set_pwm_auto_point_fan(struct device *dev, struct device_attribute *devattr, - const char* buf, size_t count) + const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); int pwmnr = attr->nr; int apnr = attr->index; - unsigned long val = simple_strtoul(buf, NULL, 10); + unsigned long val; + int err; + + err = kstrtoul(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->auto_points[pwmnr].fan[apnr] = fan_to_reg(val); f71805f_write16(data, F71805F_REG_PWM_AUTO_POINT_FAN(pwmnr, apnr), - data->auto_points[pwmnr].fan[apnr]); + data->auto_points[pwmnr].fan[apnr]); mutex_unlock(&data->update_lock); return count; @@ -849,7 +910,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - long val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->temp_high[nr] = temp_to_reg(val); @@ -865,7 +931,12 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; - long val = simple_strtol(buf, NULL, 10); + long val; + int err; + + err = kstrtol(buf, 10, &val); + if (err) + return err; mutex_lock(&data->update_lock); data->temp_hyst[nr] = temp_to_reg(val); @@ -918,9 +989,9 @@ static ssize_t show_name(struct device *dev, struct device_attribute } static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL, 0); -static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, +static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, show_in0_max, set_in0_max, 0); -static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, +static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR, show_in0_min, set_in0_min, 0); static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1); static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR, @@ -1008,8 +1079,10 @@ static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_hyst, set_temp_hyst, 2); static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2); -/* pwm (value) files are created read-only, write permission is - then added or removed dynamically as needed */ +/* + * pwm (value) files are created read-only, write permission is + * then added or removed dynamically as needed + */ static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO, show_pwm, set_pwm, 0); static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable, set_pwm_enable, 0); @@ -1244,8 +1317,10 @@ static const struct attribute_group f71805f_group_optin[4] = { { .attrs = f71805f_attributes_optin[3] }, }; -/* We don't include pwm_freq files in the arrays above, because they must be - created conditionally (only if pwm_mode is 1 == PWM) */ +/* + * We don't include pwm_freq files in the arrays above, because they must be + * created conditionally (only if pwm_mode is 1 == PWM) + */ static struct attribute *f71805f_attributes_pwm_freq[] = { &sensor_dev_attr_pwm1_freq.dev_attr.attr, &sensor_dev_attr_pwm2_freq.dev_attr.attr, @@ -1268,25 +1343,28 @@ static struct attribute *f71805f_attr_pwm[] = { * Device registration and initialization */ -static void __devinit f71805f_init_device(struct f71805f_data *data) +static void f71805f_init_device(struct f71805f_data *data) { u8 reg; int i; reg = f71805f_read8(data, F71805F_REG_START); if ((reg & 0x41) != 0x01) { - printk(KERN_DEBUG DRVNAME ": Starting monitoring " - "operations\n"); + pr_debug("Starting monitoring operations\n"); f71805f_write8(data, F71805F_REG_START, (reg | 0x01) & ~0x40); } - /* Fan monitoring can be disabled. If it is, we won't be polling - the register values, and won't create the related sysfs files. */ + /* + * Fan monitoring can be disabled. If it is, we won't be polling + * the register values, and won't create the related sysfs files. + */ for (i = 0; i < 3; i++) { data->fan_ctrl[i] = f71805f_read8(data, F71805F_REG_FAN_CTRL(i)); - /* Clear latch full bit, else "speed mode" fan speed control - doesn't work */ + /* + * Clear latch full bit, else "speed mode" fan speed control + * doesn't work + */ if (data->fan_ctrl[i] & FAN_CTRL_LATCH_FULL) { data->fan_ctrl[i] &= ~FAN_CTRL_LATCH_FULL; f71805f_write8(data, F71805F_REG_FAN_CTRL(i), @@ -1295,31 +1373,30 @@ static void __devinit f71805f_init_device(struct f71805f_data *data) } } -static int __devinit f71805f_probe(struct platform_device *pdev) +static int f71805f_probe(struct platform_device *pdev) { - struct f71805f_sio_data *sio_data = pdev->dev.platform_data; + struct f71805f_sio_data *sio_data = dev_get_platdata(&pdev->dev); struct f71805f_data *data; struct resource *res; int i, err; - static const char *names[] = { + static const char * const names[] = { "f71805f", "f71872f", }; - if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) { - err = -ENOMEM; - printk(KERN_ERR DRVNAME ": Out of memory\n"); - goto exit; - } + data = devm_kzalloc(&pdev->dev, sizeof(struct f71805f_data), + GFP_KERNEL); + if (!data) + return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_IO, 0); - if (!request_region(res->start + ADDR_REG_OFFSET, 2, DRVNAME)) { - err = -EBUSY; + if (!devm_request_region(&pdev->dev, res->start + ADDR_REG_OFFSET, 2, + DRVNAME)) { dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n", (unsigned long)(res->start + ADDR_REG_OFFSET), (unsigned long)(res->start + ADDR_REG_OFFSET + 1)); - goto exit_free; + return -EBUSY; } data->addr = res->start; data->name = names[sio_data->kind]; @@ -1345,40 +1422,47 @@ static int __devinit f71805f_probe(struct platform_device *pdev) f71805f_init_device(data); /* Register sysfs interface files */ - if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group))) - goto exit_release_region; + err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group); + if (err) + return err; if (data->has_in & (1 << 4)) { /* in4 */ - if ((err = sysfs_create_group(&pdev->dev.kobj, - &f71805f_group_optin[0]))) + err = sysfs_create_group(&pdev->dev.kobj, + &f71805f_group_optin[0]); + if (err) goto exit_remove_files; } if (data->has_in & (1 << 8)) { /* in8 */ - if ((err = sysfs_create_group(&pdev->dev.kobj, - &f71805f_group_optin[1]))) + err = sysfs_create_group(&pdev->dev.kobj, + &f71805f_group_optin[1]); + if (err) goto exit_remove_files; } if (data->has_in & (1 << 9)) { /* in9 (F71872F/FG only) */ - if ((err = sysfs_create_group(&pdev->dev.kobj, - &f71805f_group_optin[2]))) + err = sysfs_create_group(&pdev->dev.kobj, + &f71805f_group_optin[2]); + if (err) goto exit_remove_files; } if (data->has_in & (1 << 10)) { /* in9 (F71872F/FG only) */ - if ((err = sysfs_create_group(&pdev->dev.kobj, - &f71805f_group_optin[3]))) + err = sysfs_create_group(&pdev->dev.kobj, + &f71805f_group_optin[3]); + if (err) goto exit_remove_files; } for (i = 0; i < 3; i++) { /* If control mode is PWM, create pwm_freq file */ if (!(data->fan_ctrl[i] & FAN_CTRL_DC_MODE)) { - if ((err = sysfs_create_file(&pdev->dev.kobj, - f71805f_attributes_pwm_freq[i]))) + err = sysfs_create_file(&pdev->dev.kobj, + f71805f_attributes_pwm_freq[i]); + if (err) goto exit_remove_files; } /* If PWM is in manual mode, add write permission */ if (data->fan_ctrl[i] & FAN_CTRL_MODE_MANUAL) { - if ((err = sysfs_chmod_file(&pdev->dev.kobj, - f71805f_attr_pwm[i], - S_IRUGO | S_IWUSR))) { + err = sysfs_chmod_file(&pdev->dev.kobj, + f71805f_attr_pwm[i], + S_IRUGO | S_IWUSR); + if (err) { dev_err(&pdev->dev, "chmod +w pwm%d failed\n", i + 1); goto exit_remove_files; @@ -1400,19 +1484,12 @@ exit_remove_files: for (i = 0; i < 4; i++) sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); -exit_release_region: - release_region(res->start + ADDR_REG_OFFSET, 2); -exit_free: - platform_set_drvdata(pdev, NULL); - kfree(data); -exit: return err; } -static int __devexit f71805f_remove(struct platform_device *pdev) +static int f71805f_remove(struct platform_device *pdev) { struct f71805f_data *data = platform_get_drvdata(pdev); - struct resource *res; int i; hwmon_device_unregister(data->hwmon_dev); @@ -1420,11 +1497,6 @@ static int __devexit f71805f_remove(struct platform_device *pdev) for (i = 0; i < 4; i++) sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); - platform_set_drvdata(pdev, NULL); - kfree(data); - - res = platform_get_resource(pdev, IORESOURCE_IO, 0); - release_region(res->start + ADDR_REG_OFFSET, 2); return 0; } @@ -1435,7 +1507,7 @@ static struct platform_driver f71805f_driver = { .name = DRVNAME, }, .probe = f71805f_probe, - .remove = __devexit_p(f71805f_remove), + .remove = f71805f_remove, }; static int __init f71805f_device_add(unsigned short address, @@ -1451,7 +1523,7 @@ static int __init f71805f_device_add(unsigned short address, pdev = platform_device_alloc(DRVNAME, address); if (!pdev) { err = -ENOMEM; - printk(KERN_ERR DRVNAME ": Device allocation failed\n"); + pr_err("Device allocation failed\n"); goto exit; } @@ -1462,22 +1534,20 @@ static int __init f71805f_device_add(unsigned short address, err = platform_device_add_resources(pdev, &res, 1); if (err) { - printk(KERN_ERR DRVNAME ": Device resource addition failed " - "(%d)\n", err); + pr_err("Device resource addition failed (%d)\n", err); goto exit_device_put; } err = platform_device_add_data(pdev, sio_data, sizeof(struct f71805f_sio_data)); if (err) { - printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); + pr_err("Platform data allocation failed\n"); goto exit_device_put; } err = platform_device_add(pdev); if (err) { - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", - err); + pr_err("Device addition failed (%d)\n", err); goto exit_device_put; } @@ -1495,7 +1565,7 @@ static int __init f71805f_find(int sioaddr, unsigned short *address, int err = -ENODEV; u16 devid; - static const char *names[] = { + static const char * const names[] = { "F71805F/FG", "F71872F/FG or F71806F/FG", }; @@ -1516,30 +1586,27 @@ static int __init f71805f_find(int sioaddr, unsigned short *address, sio_data->fnsel1 = superio_inb(sioaddr, SIO_REG_FNSEL1); break; default: - printk(KERN_INFO DRVNAME ": Unsupported Fintek device, " - "skipping\n"); + pr_info("Unsupported Fintek device, skipping\n"); goto exit; } superio_select(sioaddr, F71805F_LD_HWM); if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { - printk(KERN_WARNING DRVNAME ": Device not activated, " - "skipping\n"); + pr_warn("Device not activated, skipping\n"); goto exit; } *address = superio_inw(sioaddr, SIO_REG_ADDR); if (*address == 0) { - printk(KERN_WARNING DRVNAME ": Base address not set, " - "skipping\n"); + pr_warn("Base address not set, skipping\n"); goto exit; } *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */ err = 0; - printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %u\n", - names[sio_data->kind], *address, - superio_inb(sioaddr, SIO_REG_DEVREV)); + pr_info("Found %s chip at %#x, revision %u\n", + names[sio_data->kind], *address, + superio_inb(sioaddr, SIO_REG_DEVREV)); exit: superio_exit(sioaddr); @@ -1579,7 +1646,7 @@ static void __exit f71805f_exit(void) platform_driver_unregister(&f71805f_driver); } -MODULE_AUTHOR("Jean Delvare <khali@linux-fr>"); +MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("F71805F/F71872F hardware monitoring driver"); |
