summaryrefslogtreecommitdiff
path: root/drivers/hwmon/jc42.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/jc42.c')
-rw-r--r--drivers/hwmon/jc42.c97
1 files changed, 30 insertions, 67 deletions
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
index b927ee5ccdd7..a9bfd6736d9a 100644
--- a/drivers/hwmon/jc42.c
+++ b/drivers/hwmon/jc42.c
@@ -180,25 +180,7 @@ static int jc42_remove(struct i2c_client *client);
static struct jc42_data *jc42_update_device(struct device *dev);
static const struct i2c_device_id jc42_id[] = {
- { "adt7408", 0 },
- { "at30ts00", 0 },
- { "cat94ts02", 0 },
- { "cat6095", 0 },
{ "jc42", 0 },
- { "max6604", 0 },
- { "mcp9804", 0 },
- { "mcp9805", 0 },
- { "mcp98242", 0 },
- { "mcp98243", 0 },
- { "mcp9843", 0 },
- { "se97", 0 },
- { "se97b", 0 },
- { "se98", 0 },
- { "stts424", 0 },
- { "stts2002", 0 },
- { "stts3000", 0 },
- { "tse2002", 0 },
- { "ts3000", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, jc42_id);
@@ -350,8 +332,10 @@ set(temp_min, JC42_REG_TEMP_LOWER);
set(temp_max, JC42_REG_TEMP_UPPER);
set(temp_crit, JC42_REG_TEMP_CRITICAL);
-/* JC42.4 compliant chips only support four hysteresis values.
- * Pick best choice and go from there. */
+/*
+ * JC42.4 compliant chips only support four hysteresis values.
+ * Pick best choice and go from there.
+ */
static ssize_t set_temp_crit_hyst(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
@@ -467,20 +451,19 @@ static const struct attribute_group jc42_group = {
};
/* Return 0 if detection is successful, -ENODEV otherwise */
-static int jc42_detect(struct i2c_client *new_client,
- struct i2c_board_info *info)
+static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info)
{
- struct i2c_adapter *adapter = new_client->adapter;
+ struct i2c_adapter *adapter = client->adapter;
int i, config, cap, manid, devid;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_WORD_DATA))
return -ENODEV;
- cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP);
- config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG);
- manid = i2c_smbus_read_word_swapped(new_client, JC42_REG_MANID);
- devid = i2c_smbus_read_word_swapped(new_client, JC42_REG_DEVICEID);
+ cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP);
+ config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG);
+ manid = i2c_smbus_read_word_swapped(client, JC42_REG_MANID);
+ devid = i2c_smbus_read_word_swapped(client, JC42_REG_DEVICEID);
if (cap < 0 || config < 0 || manid < 0 || devid < 0)
return -ENODEV;
@@ -499,47 +482,42 @@ static int jc42_detect(struct i2c_client *new_client,
return -ENODEV;
}
-static int jc42_probe(struct i2c_client *new_client,
- const struct i2c_device_id *id)
+static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
struct jc42_data *data;
int config, cap, err;
+ struct device *dev = &client->dev;
- data = kzalloc(sizeof(struct jc42_data), GFP_KERNEL);
- if (!data) {
- err = -ENOMEM;
- goto exit;
- }
+ data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
- i2c_set_clientdata(new_client, data);
+ i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);
- cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP);
- if (cap < 0) {
- err = -EINVAL;
- goto exit_free;
- }
+ cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP);
+ if (cap < 0)
+ return cap;
+
data->extended = !!(cap & JC42_CAP_RANGE);
- config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG);
- if (config < 0) {
- err = -EINVAL;
- goto exit_free;
- }
+ config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG);
+ if (config < 0)
+ return config;
+
data->orig_config = config;
if (config & JC42_CFG_SHUTDOWN) {
config &= ~JC42_CFG_SHUTDOWN;
- i2c_smbus_write_word_swapped(new_client, JC42_REG_CONFIG,
- config);
+ i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config);
}
data->config = config;
/* Register sysfs hooks */
- err = sysfs_create_group(&new_client->dev.kobj, &jc42_group);
+ err = sysfs_create_group(&dev->kobj, &jc42_group);
if (err)
- goto exit_free;
+ return err;
- data->hwmon_dev = hwmon_device_register(&new_client->dev);
+ data->hwmon_dev = hwmon_device_register(dev);
if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev);
goto exit_remove;
@@ -548,10 +526,7 @@ static int jc42_probe(struct i2c_client *new_client,
return 0;
exit_remove:
- sysfs_remove_group(&new_client->dev.kobj, &jc42_group);
-exit_free:
- kfree(data);
-exit:
+ sysfs_remove_group(&dev->kobj, &jc42_group);
return err;
}
@@ -563,7 +538,6 @@ static int jc42_remove(struct i2c_client *client)
if (data->config != data->orig_config)
i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG,
data->orig_config);
- kfree(data);
return 0;
}
@@ -614,19 +588,8 @@ abort:
return ret;
}
-static int __init sensors_jc42_init(void)
-{
- return i2c_add_driver(&jc42_driver);
-}
-
-static void __exit sensors_jc42_exit(void)
-{
- i2c_del_driver(&jc42_driver);
-}
+module_i2c_driver(jc42_driver);
MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>");
MODULE_DESCRIPTION("JC42 driver");
MODULE_LICENSE("GPL");
-
-module_init(sensors_jc42_init);
-module_exit(sensors_jc42_exit);