struct smm665_data {
enum chips type;
int conversion_time; /* ADC conversion time */
- struct device *hwmon_dev;
+ struct i2c_client *client;
struct mutex update_lock;
bool valid;
unsigned long last_updated; /* in jiffies */
static struct smm665_data *smm665_update_device(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct smm665_data *data = i2c_get_clientdata(client);
+ struct smm665_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
struct smm665_data *ret = data;
mutex_lock(&data->update_lock);
static int smm665_get_min(struct device *dev, int index)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct smm665_data *data = i2c_get_clientdata(client);
+ struct smm665_data *data = dev_get_drvdata(dev);
return data->alarm_min_limit[index];
}
static int smm665_get_max(struct device *dev, int index)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct smm665_data *data = i2c_get_clientdata(client);
+ struct smm665_data *data = dev_get_drvdata(dev);
return data->alarm_max_limit[index];
}
static int smm665_get_lcrit(struct device *dev, int index)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct smm665_data *data = i2c_get_clientdata(client);
+ struct smm665_data *data = dev_get_drvdata(dev);
return data->critical_min_limit[index];
}
static int smm665_get_crit(struct device *dev, int index)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct smm665_data *data = i2c_get_clientdata(client);
+ struct smm665_data *data = dev_get_drvdata(dev);
return data->critical_max_limit[index];
}
* Finally, construct an array of pointers to members of the above objects,
* as required for sysfs_create_group()
*/
-static struct attribute *smm665_attributes[] = {
+static struct attribute *smm665_attrs[] = {
&sensor_dev_attr_in1_input.dev_attr.attr,
&sensor_dev_attr_in1_min.dev_attr.attr,
&sensor_dev_attr_in1_max.dev_attr.attr,
NULL,
};
-static const struct attribute_group smm665_group = {
- .attrs = smm665_attributes,
-};
+ATTRIBUTE_GROUPS(smm665);
static int smm665_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct i2c_adapter *adapter = client->adapter;
struct smm665_data *data;
+ struct device *hwmon_dev;
int i, ret;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);
+ data->client = client;
data->type = id->driver_data;
data->cmdreg = i2c_new_dummy(adapter, (client->addr & ~SMM665_REGMASK)
| SMM665_CMDREG_BASE);
data->alarm_max_limit[i] = smm665_convert(val, i);
}
- /* Register sysfs hooks */
- ret = sysfs_create_group(&client->dev.kobj, &smm665_group);
- if (ret)
+ hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
+ client->name, data,
+ smm665_groups);
+ if (IS_ERR(hwmon_dev)) {
+ ret = PTR_ERR(hwmon_dev);
goto out_unregister;
-
- data->hwmon_dev = hwmon_device_register(&client->dev);
- if (IS_ERR(data->hwmon_dev)) {
- ret = PTR_ERR(data->hwmon_dev);
- goto out_remove_group;
}
return 0;
-out_remove_group:
- sysfs_remove_group(&client->dev.kobj, &smm665_group);
out_unregister:
i2c_unregister_device(data->cmdreg);
return ret;
struct smm665_data *data = i2c_get_clientdata(client);
i2c_unregister_device(data->cmdreg);
- hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &smm665_group);
-
return 0;
}