/* Each client has this additional data */
struct ds620_data {
- struct device *hwmon_dev;
+ struct i2c_client *client;
struct mutex update_lock;
char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */
static struct ds620_data *ds620_update_client(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct ds620_data *data = i2c_get_clientdata(client);
+ struct ds620_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
struct ds620_data *ret = data;
mutex_lock(&data->update_lock);
long val;
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
- struct i2c_client *client = to_i2c_client(dev);
- struct ds620_data *data = i2c_get_clientdata(client);
+ struct ds620_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
res = kstrtol(buf, 10, &val);
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct ds620_data *data = ds620_update_client(dev);
- struct i2c_client *client = to_i2c_client(dev);
+ struct i2c_client *client;
u16 conf, new_conf;
int res;
if (IS_ERR(data))
return PTR_ERR(data);
+ client = data->client;
+
/* reset alarms if necessary */
res = i2c_smbus_read_word_swapped(client, DS620_REG_CONF);
if (res < 0)
static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
DS620_REG_CONFIG_THF);
-static struct attribute *ds620_attributes[] = {
+static struct attribute *ds620_attrs[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr,
&sensor_dev_attr_temp1_min.dev_attr.attr,
&sensor_dev_attr_temp1_max.dev_attr.attr,
NULL
};
-static const struct attribute_group ds620_group = {
- .attrs = ds620_attributes,
-};
+ATTRIBUTE_GROUPS(ds620);
static int ds620_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct device *dev = &client->dev;
+ struct device *hwmon_dev;
struct ds620_data *data;
- int err;
- data = devm_kzalloc(&client->dev, sizeof(struct ds620_data),
- GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(struct ds620_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
- i2c_set_clientdata(client, data);
+ data->client = client;
mutex_init(&data->update_lock);
/* Initialize the DS620 chip */
ds620_init_client(client);
- /* Register sysfs hooks */
- err = sysfs_create_group(&client->dev.kobj, &ds620_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 exit_remove_files;
- }
-
- dev_info(&client->dev, "temperature sensor found\n");
-
- return 0;
-
-exit_remove_files:
- sysfs_remove_group(&client->dev.kobj, &ds620_group);
- return err;
-}
-
-static int ds620_remove(struct i2c_client *client)
-{
- struct ds620_data *data = i2c_get_clientdata(client);
-
- hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &ds620_group);
-
- return 0;
+ hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
+ data, ds620_groups);
+ return PTR_ERR_OR_ZERO(hwmon_dev);
}
static const struct i2c_device_id ds620_id[] = {
.name = "ds620",
},
.probe = ds620_probe,
- .remove = ds620_remove,
.id_table = ds620_id,
};