summaryrefslogtreecommitdiff
path: root/drivers/hwmon/lineage-pem.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-08-05 15:55:36 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-05 15:55:36 -0700
commit161d2e0a195292a8a67b0f5c48e12a9984f75dac (patch)
tree4f3c516ab41737b1e51a58ca3d5f8cca421ae949 /drivers/hwmon/lineage-pem.c
parentc489d98c8c81a898cfed6bec193cca2006f956aa (diff)
parentfce9626cd93abaf1ef21b361f8a0fa493cc855b2 (diff)
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon updates from Guenter Roeck: "Notable changes: - Heiko Schocher provided a driver for TI TMP103. - Kamil Debski provided a driver for pwm-controlled fans. - Neelesh Gupta provided a driver for power, fan rpm, voltage and temperature reporting on powerpc/powernv systems. - Scott Kanowitz provided a driver supporting Lattice's POWR1220 power manager IC. - Richard Zhu provided a pmbus front-end driver for TPS40422. - Frans Klaver added support for TMP112 to the lm75 driver. - Johannes Pointner added support for EPCOS B57330V2103 to the ntc_thermistor driver. - Guenter Roeck added support for TMP441 and TMP442 to the tmp421 driver. - Axel Lin converted several drivers to the new hwmon API (36 of them, if I counted correctly), and cleaned up many of the drivers along the way. There are also a number of patches fixing bugs discovered while testing Axel's changes" * tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (88 commits) hwmon: (g762) Use of_property_read_u32 at appropriate place hwmon: (sis5595) Prevent overflow problem when writing large limits hwmon: (gpio-fan) Prevent overflow problem when writing large limits hwmon: (ibmpowernv) Use of_property_read_u32 at appropriate place hwmon: (lm85) Convert to devm_hwmon_device_register_with_groups hwmon: (lm85) Avoid forward declaration hwmon: (lm78) Convert to devm_hwmon_device_register_with_groups hwmon: (max6697) Use of_property_read_bool at appropriate places hwmon: (pwm-fan) Make SENSORS_PWM_FAN depend on OF hwmon: (pwm-fan) Remove duplicate dev_set_drvdata call hwmon: (nct6775) Remove num_attr_groups from struct nct6775_data hwmon: (nct6775) Update module description and Kconfig for NCT6106D and NCT6791D hwmon: (adt7411) Convert to devm_hwmon_device_register_with_groups hwmon: (g762) Convert to hwmon_device_register_with_groups hwmon: (emc2103) Convert to devm_hwmon_device_register_with_groups hwmon: (smsc47m1) Avoid forward declaration hwmon: (smsc47m192) Convert to devm_hwmon_device_register_with_groups hwmon: (smsc47m192) Avoid forward declaration hwmon: (max1668) Make max1668_addr_list array const hwmon: (max6639) Make normal_i2c array const ...
Diffstat (limited to 'drivers/hwmon/lineage-pem.c')
-rw-r--r--drivers/hwmon/lineage-pem.c66
1 files changed, 19 insertions, 47 deletions
diff --git a/drivers/hwmon/lineage-pem.c b/drivers/hwmon/lineage-pem.c
index ebbb9f4f27a3..84d791bdb62d 100644
--- a/drivers/hwmon/lineage-pem.c
+++ b/drivers/hwmon/lineage-pem.c
@@ -125,7 +125,8 @@
#define FAN_SPEED_LEN 5
struct pem_data {
- struct device *hwmon_dev;
+ struct i2c_client *client;
+ const struct attribute_group *groups[4];
struct mutex update_lock;
bool valid;
@@ -160,8 +161,8 @@ abort:
static struct pem_data *pem_update_device(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct pem_data *data = i2c_get_clientdata(client);
+ struct pem_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
struct pem_data *ret = data;
mutex_lock(&data->update_lock);
@@ -444,18 +445,20 @@ static int pem_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct i2c_adapter *adapter = client->adapter;
+ struct device *dev = &client->dev;
+ struct device *hwmon_dev;
struct pem_data *data;
- int ret;
+ int ret, idx = 0;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BLOCK_DATA
| I2C_FUNC_SMBUS_WRITE_BYTE))
return -ENODEV;
- data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
- i2c_set_clientdata(client, data);
+ data->client = client;
mutex_init(&data->update_lock);
/*
@@ -471,14 +474,12 @@ static int pem_probe(struct i2c_client *client,
if (ret < 0)
return ret;
- dev_info(&client->dev, "Firmware revision %d.%d.%d\n",
+ dev_info(dev, "Firmware revision %d.%d.%d\n",
data->firmware_rev[0], data->firmware_rev[1],
data->firmware_rev[2]);
- /* Register sysfs hooks */
- ret = sysfs_create_group(&client->dev.kobj, &pem_group);
- if (ret)
- return ret;
+ /* sysfs hooks */
+ data->groups[idx++] = &pem_group;
/*
* Check if input readings are supported.
@@ -501,12 +502,9 @@ static int pem_probe(struct i2c_client *client,
data->input_string[2] || data->input_string[3]))
data->input_length = sizeof(data->input_string);
}
- ret = 0;
- if (data->input_length) {
- ret = sysfs_create_group(&client->dev.kobj, &pem_input_group);
- if (ret)
- goto out_remove_groups;
- }
+
+ if (data->input_length)
+ data->groups[idx++] = &pem_input_group;
/*
* Check if fan speed readings are supported.
@@ -520,37 +518,12 @@ static int pem_probe(struct i2c_client *client,
if (!ret && (data->fan_speed[0] || data->fan_speed[1] ||
data->fan_speed[2] || data->fan_speed[3])) {
data->fans_supported = true;
- ret = sysfs_create_group(&client->dev.kobj, &pem_fan_group);
- if (ret)
- goto out_remove_groups;
- }
-
- data->hwmon_dev = hwmon_device_register(&client->dev);
- if (IS_ERR(data->hwmon_dev)) {
- ret = PTR_ERR(data->hwmon_dev);
- goto out_remove_groups;
+ data->groups[idx++] = &pem_fan_group;
}
- return 0;
-
-out_remove_groups:
- sysfs_remove_group(&client->dev.kobj, &pem_input_group);
- sysfs_remove_group(&client->dev.kobj, &pem_fan_group);
- sysfs_remove_group(&client->dev.kobj, &pem_group);
- return ret;
-}
-
-static int pem_remove(struct i2c_client *client)
-{
- struct pem_data *data = i2c_get_clientdata(client);
-
- hwmon_device_unregister(data->hwmon_dev);
-
- sysfs_remove_group(&client->dev.kobj, &pem_input_group);
- sysfs_remove_group(&client->dev.kobj, &pem_fan_group);
- sysfs_remove_group(&client->dev.kobj, &pem_group);
-
- return 0;
+ hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
+ data, data->groups);
+ return PTR_ERR_OR_ZERO(hwmon_dev);
}
static const struct i2c_device_id pem_id[] = {
@@ -564,7 +537,6 @@ static struct i2c_driver pem_driver = {
.name = "lineage_pem",
},
.probe = pem_probe,
- .remove = pem_remove,
.id_table = pem_id,
};