diff options
Diffstat (limited to 'drivers/hwmon/g760a.c')
| -rw-r--r-- | drivers/hwmon/g760a.c | 117 |
1 files changed, 40 insertions, 77 deletions
diff --git a/drivers/hwmon/g760a.c b/drivers/hwmon/g760a.c index ea6480b80e7f..39ae8f826417 100644 --- a/drivers/hwmon/g760a.c +++ b/drivers/hwmon/g760a.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * g760a - Driver for the Global Mixed-mode Technology Inc. G760A * fan speed PWM controller chip @@ -6,11 +7,6 @@ * * Complete datasheet is available at GMT's website: * http://www.gmt.com.tw/product/datasheet/EDS-760A.pdf - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. */ #include <linux/module.h> @@ -24,12 +20,6 @@ #include <linux/mutex.h> #include <linux/sysfs.h> -static const struct i2c_device_id g760a_id[] = { - { "g760a", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, g760a_id); - enum g760a_regs { G760A_REG_SET_CNT = 0x00, G760A_REG_ACT_CNT = 0x01, @@ -44,7 +34,6 @@ enum g760a_regs { struct g760a_data { struct i2c_client *client; - struct device *hwmon_dev; struct mutex update_lock; /* board specific parameters */ @@ -74,20 +63,6 @@ static inline unsigned int rpm_from_cnt(u8 val, u32 clk, u16 div) return ((val == 0x00) ? 0 : ((clk*30)/(val*div))); } -/* new-style driver model */ -static int g760a_probe(struct i2c_client *client, - const struct i2c_device_id *id); -static int g760a_remove(struct i2c_client *client); - -static struct i2c_driver g760a_driver = { - .driver = { - .name = "g760a", - }, - .probe = g760a_probe, - .remove = g760a_remove, - .id_table = g760a_id, -}; - /* read/write wrappers */ static int g760a_read_value(struct i2c_client *client, enum g760a_regs reg) { @@ -106,8 +81,8 @@ static int g760a_write_value(struct i2c_client *client, enum g760a_regs reg, static struct g760a_data *g760a_update_client(struct device *dev) { - struct i2c_client *client = to_i2c_client(dev); - struct g760a_data *data = i2c_get_clientdata(client); + struct g760a_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; mutex_lock(&data->update_lock); @@ -120,7 +95,7 @@ static struct g760a_data *g760a_update_client(struct device *dev) data->fan_sta = g760a_read_value(client, G760A_REG_FAN_STA); data->last_updated = jiffies; - data->valid = 1; + data->valid = true; } mutex_unlock(&data->update_lock); @@ -128,8 +103,8 @@ static struct g760a_data *g760a_update_client(struct device *dev) return data; } -static ssize_t show_fan(struct device *dev, struct device_attribute *da, - char *buf) +static ssize_t fan1_input_show(struct device *dev, + struct device_attribute *da, char *buf) { struct g760a_data *data = g760a_update_client(dev); unsigned int rpm = 0; @@ -142,8 +117,8 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *da, return sprintf(buf, "%d\n", rpm); } -static ssize_t show_fan_alarm(struct device *dev, struct device_attribute *da, - char *buf) +static ssize_t fan1_alarm_show(struct device *dev, + struct device_attribute *da, char *buf) { struct g760a_data *data = g760a_update_client(dev); @@ -152,19 +127,19 @@ static ssize_t show_fan_alarm(struct device *dev, struct device_attribute *da, return sprintf(buf, "%d\n", fan_alarm); } -static ssize_t get_pwm(struct device *dev, struct device_attribute *da, - char *buf) +static ssize_t pwm1_show(struct device *dev, struct device_attribute *da, + char *buf) { struct g760a_data *data = g760a_update_client(dev); return sprintf(buf, "%d\n", PWM_FROM_CNT(data->set_cnt)); } -static ssize_t set_pwm(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) +static ssize_t pwm1_store(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); struct g760a_data *data = g760a_update_client(dev); + struct i2c_client *client = data->client; unsigned long val; if (kstrtoul(buf, 10, &val)) @@ -178,42 +153,36 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *da, return count; } -static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, get_pwm, set_pwm); -static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL); -static DEVICE_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL); +static DEVICE_ATTR_RW(pwm1); +static DEVICE_ATTR_RO(fan1_input); +static DEVICE_ATTR_RO(fan1_alarm); -static struct attribute *g760a_attributes[] = { +static struct attribute *g760a_attrs[] = { &dev_attr_pwm1.attr, &dev_attr_fan1_input.attr, &dev_attr_fan1_alarm.attr, NULL }; -static const struct attribute_group g760a_group = { - .attrs = g760a_attributes, -}; +ATTRIBUTE_GROUPS(g760a); /* * new-style driver model code */ -static int g760a_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int g760a_probe(struct i2c_client *client) { + struct device *dev = &client->dev; struct g760a_data *data; - int err; + struct device *hwmon_dev; - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA)) + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - data = devm_kzalloc(&client->dev, sizeof(struct g760a_data), - GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(struct g760a_data), GFP_KERNEL); if (!data) return -ENOMEM; - i2c_set_clientdata(client, data); - data->client = client; mutex_init(&data->update_lock); @@ -221,31 +190,25 @@ static int g760a_probe(struct i2c_client *client, data->fan_div = G760A_DEFAULT_FAN_DIV; data->clk = G760A_DEFAULT_CLK; - /* Register sysfs hooks */ - err = sysfs_create_group(&client->dev.kobj, &g760a_group); - if (err) - return err; - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - err = PTR_ERR(data->hwmon_dev); - goto error_hwmon_device_register; - } - - return 0; - -error_hwmon_device_register: - sysfs_remove_group(&client->dev.kobj, &g760a_group); - return err; + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, + g760a_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); } -static int g760a_remove(struct i2c_client *client) -{ - struct g760a_data *data = i2c_get_clientdata(client); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &g760a_group); - return 0; -} +static const struct i2c_device_id g760a_id[] = { + { "g760a" }, + { } +}; +MODULE_DEVICE_TABLE(i2c, g760a_id); + +static struct i2c_driver g760a_driver = { + .driver = { + .name = "g760a", + }, + .probe = g760a_probe, + .id_table = g760a_id, +}; module_i2c_driver(g760a_driver); |
