/* Client data */
struct gl520_data {
- struct device *hwmon_dev;
+ struct i2c_client *client;
+ const struct attribute_group *groups[3];
struct mutex update_lock;
char valid; /* zero until the following fields are valid */
unsigned long last_updated; /* in jiffies */
static struct gl520_data *gl520_update_device(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int val, i;
mutex_lock(&data->update_lock);
static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int n = to_sensor_dev_attr(attr)->index;
u8 r;
long v;
static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int n = to_sensor_dev_attr(attr)->index;
u8 r;
long v;
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 gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int n = to_sensor_dev_attr(attr)->index;
u8 r;
unsigned long v;
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 gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int n = to_sensor_dev_attr(attr)->index;
u8 r;
unsigned long v;
static ssize_t set_fan_off(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 r;
unsigned long v;
int err;
static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int n = to_sensor_dev_attr(attr)->index;
long v;
int err;
static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute
*attr, const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int n = to_sensor_dev_attr(attr)->index;
long v;
int err;
static ssize_t set_beep_enable(struct device *dev, struct device_attribute
*attr, const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 r;
unsigned long v;
int err;
static ssize_t set_beep_mask(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long r;
int err;
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 gl520_data *data = i2c_get_clientdata(client);
+ struct gl520_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int bitnr = to_sensor_dev_attr(attr)->index;
unsigned long bit;
static int gl520_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct device *dev = &client->dev;
+ struct device *hwmon_dev;
struct gl520_data *data;
- int err;
- data = devm_kzalloc(&client->dev, sizeof(struct gl520_data),
- GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(struct gl520_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);
+ data->client = client;
/* Initialize the GL520SM chip */
gl520_init_client(client);
- /* Register sysfs hooks */
- err = sysfs_create_group(&client->dev.kobj, &gl520_group);
- if (err)
- return err;
+ /* sysfs hooks */
+ data->groups[0] = &gl520_group;
if (data->two_temps)
- err = sysfs_create_group(&client->dev.kobj, &gl520_group_temp2);
+ data->groups[1] = &gl520_group_temp2;
else
- err = sysfs_create_group(&client->dev.kobj, &gl520_group_in4);
-
- 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;
+ data->groups[1] = &gl520_group_in4;
-exit_remove_files:
- sysfs_remove_group(&client->dev.kobj, &gl520_group);
- sysfs_remove_group(&client->dev.kobj, &gl520_group_in4);
- sysfs_remove_group(&client->dev.kobj, &gl520_group_temp2);
- return err;
-}
-
-static int gl520_remove(struct i2c_client *client)
-{
- struct gl520_data *data = i2c_get_clientdata(client);
-
- hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &gl520_group);
- sysfs_remove_group(&client->dev.kobj, &gl520_group_in4);
- sysfs_remove_group(&client->dev.kobj, &gl520_group_temp2);
-
- 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 gl520_id[] = {
.name = "gl520sm",
},
.probe = gl520_probe,
- .remove = gl520_remove,
.id_table = gl520_id,
.detect = gl520_detect,
.address_list = normal_i2c,