* The structure is dynamically allocated.
*/
struct lm85_data {
- struct device *hwmon_dev;
+ struct i2c_client *client;
+ const struct attribute_group *groups[6];
const int *freq_map;
enum chips type;
static struct lm85_data *lm85_update_device(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int i;
mutex_lock(&data->update_lock);
const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
*attr, const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 config;
unsigned long val;
int err;
struct device_attribute *attr, const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
struct device_attribute *attr, const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
struct device_attribute *attr, const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
struct device_attribute *attr, const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 tmp;
long val;
int err;
struct device_attribute *attr, const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int min;
long val;
int err;
struct device_attribute *attr, const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
struct device_attribute *attr, const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int min;
long val;
int err;
struct device_attribute *attr, const char *buf, size_t count)
{
int nr = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm85_data *data = i2c_get_clientdata(client);
+ struct lm85_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
return 0;
}
-static void lm85_remove_files(struct i2c_client *client, struct lm85_data *data)
-{
- sysfs_remove_group(&client->dev.kobj, &lm85_group);
- if (data->type != emc6d103s) {
- sysfs_remove_group(&client->dev.kobj, &lm85_group_minctl);
- sysfs_remove_group(&client->dev.kobj, &lm85_group_temp_off);
- }
- if (!data->has_vid5)
- sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
- if (data->type == emc6d100)
- sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
-}
-
-static int lm85_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
+static int lm85_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
+ struct device *dev = &client->dev;
+ struct device *hwmon_dev;
struct lm85_data *data;
- int err;
+ int idx = 0;
- data = devm_kzalloc(&client->dev, sizeof(struct lm85_data), GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(struct lm85_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
- i2c_set_clientdata(client, data);
+ data->client = client;
data->type = id->driver_data;
mutex_init(&data->update_lock);
/* Initialize the LM85 chip */
lm85_init_client(client);
- /* Register sysfs hooks */
- err = sysfs_create_group(&client->dev.kobj, &lm85_group);
- if (err)
- return err;
+ /* sysfs hooks */
+ data->groups[idx++] = &lm85_group;
/* minctl and temp_off exist on all chips except emc6d103s */
if (data->type != emc6d103s) {
- err = sysfs_create_group(&client->dev.kobj, &lm85_group_minctl);
- if (err)
- goto err_remove_files;
- err = sysfs_create_group(&client->dev.kobj,
- &lm85_group_temp_off);
- if (err)
- goto err_remove_files;
+ data->groups[idx++] = &lm85_group_minctl;
+ data->groups[idx++] = &lm85_group_temp_off;
}
/*
data->has_vid5 = true;
}
- if (!data->has_vid5) {
- err = sysfs_create_group(&client->dev.kobj, &lm85_group_in4);
- if (err)
- goto err_remove_files;
- }
+ if (!data->has_vid5)
+ data->groups[idx++] = &lm85_group_in4;
/* The EMC6D100 has 3 additional voltage inputs */
- if (data->type == emc6d100) {
- err = sysfs_create_group(&client->dev.kobj, &lm85_group_in567);
- if (err)
- goto err_remove_files;
- }
-
- data->hwmon_dev = hwmon_device_register(&client->dev);
- if (IS_ERR(data->hwmon_dev)) {
- err = PTR_ERR(data->hwmon_dev);
- goto err_remove_files;
- }
-
- return 0;
-
- /* Error out and cleanup code */
- err_remove_files:
- lm85_remove_files(client, data);
- return err;
-}
+ if (data->type == emc6d100)
+ data->groups[idx++] = &lm85_group_in567;
-static int lm85_remove(struct i2c_client *client)
-{
- struct lm85_data *data = i2c_get_clientdata(client);
- hwmon_device_unregister(data->hwmon_dev);
- lm85_remove_files(client, data);
- 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 lm85_id[] = {
.name = "lm85",
},
.probe = lm85_probe,
- .remove = lm85_remove,
.id_table = lm85_id,
.detect = lm85_detect,
.address_list = normal_i2c,