/* Each client has this additional data */
struct gl518_data {
- struct device *hwmon_dev;
+ struct i2c_client *client;
+ const struct attribute_group *groups[3];
enum chips type;
struct mutex update_lock;
static struct gl518_data *gl518_update_device(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl518_data *data = i2c_get_clientdata(client);
+ struct gl518_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int val;
mutex_lock(&data->update_lock);
struct device_attribute *attr, \
const char *buf, size_t count) \
{ \
- struct i2c_client *client = to_i2c_client(dev); \
- struct gl518_data *data = i2c_get_clientdata(client); \
+ struct gl518_data *data = dev_get_drvdata(dev); \
+ struct i2c_client *client = data->client; \
long val; \
int err = kstrtol(buf, 10, &val); \
if (err) \
struct device_attribute *attr, \
const char *buf, size_t count) \
{ \
- struct i2c_client *client = to_i2c_client(dev); \
- struct gl518_data *data = i2c_get_clientdata(client); \
+ struct gl518_data *data = dev_get_drvdata(dev); \
+ struct i2c_client *client = data->client; \
int regvalue; \
unsigned long val; \
int err = kstrtoul(buf, 10, &val); \
static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl518_data *data = i2c_get_clientdata(client);
+ struct gl518_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int nr = to_sensor_dev_attr(attr)->index;
int regvalue;
unsigned long val;
static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl518_data *data = i2c_get_clientdata(client);
+ struct gl518_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int nr = to_sensor_dev_attr(attr)->index;
int regvalue;
unsigned long val;
static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl518_data *data = i2c_get_clientdata(client);
+ struct gl518_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int bitnr = to_sensor_dev_attr(attr)->index;
unsigned long bit;
int err;
static int gl518_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct device *dev = &client->dev;
+ struct device *hwmon_dev;
struct gl518_data *data;
- int err, revision;
+ int revision;
- data = devm_kzalloc(&client->dev, sizeof(struct gl518_data),
- GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(struct gl518_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
- i2c_set_clientdata(client, data);
+ data->client = client;
revision = gl518_read_value(client, GL518_REG_REVISION);
data->type = revision == 0x80 ? gl518sm_r80 : gl518sm_r00;
mutex_init(&data->update_lock);
data->alarm_mask = 0xff;
gl518_init_client(client);
- /* Register sysfs hooks */
- err = sysfs_create_group(&client->dev.kobj, &gl518_group);
- if (err)
- return err;
- if (data->type == gl518sm_r80) {
- err = sysfs_create_group(&client->dev.kobj, &gl518_group_r80);
- if (err)
- goto exit_remove_files;
- }
-
- data->hwmon_dev = hwmon_device_register(&client->dev);
- if (IS_ERR(data->hwmon_dev)) {
- err = PTR_ERR(data->hwmon_dev);
- goto exit_remove_files;
- }
-
- return 0;
-
-exit_remove_files:
- sysfs_remove_group(&client->dev.kobj, &gl518_group);
- if (data->type == gl518sm_r80)
- sysfs_remove_group(&client->dev.kobj, &gl518_group_r80);
- return err;
-}
-
-static int gl518_remove(struct i2c_client *client)
-{
- struct gl518_data *data = i2c_get_clientdata(client);
-
- hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &gl518_group);
+ /* sysfs hooks */
+ data->groups[0] = &gl518_group;
if (data->type == gl518sm_r80)
- sysfs_remove_group(&client->dev.kobj, &gl518_group_r80);
+ data->groups[1] = &gl518_group_r80;
- 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 gl518_id[] = {
.name = "gl518sm",
},
.probe = gl518_probe,
- .remove = gl518_remove,
.id_table = gl518_id,
.detect = gl518_detect,
.address_list = normal_i2c,