Skip to content

Commit

Permalink
hwmon: (ds1621) Convert to use hwmon_device_register_with_groups
Browse files Browse the repository at this point in the history
Signed-off-by: Guenter Roeck <[email protected]>
  • Loading branch information
groeck committed Oct 13, 2013
1 parent bab2243 commit 8269b75
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions drivers/hwmon/ds1621.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static const u8 DS1621_REG_TEMP[3] = {

/* Each client has this additional data */
struct ds1621_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 */
Expand Down Expand Up @@ -151,10 +151,10 @@ static inline u16 DS1621_TEMP_TO_REG(long temp, u8 zbits)
return temp;
}

static void ds1621_init_client(struct i2c_client *client)
static void ds1621_init_client(struct ds1621_data *data,
struct i2c_client *client)
{
u8 conf, new_conf, sreg, resol;
struct ds1621_data *data = i2c_get_clientdata(client);

new_conf = conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
/* switch to continuous conversion mode */
Expand Down Expand Up @@ -197,8 +197,8 @@ static void ds1621_init_client(struct i2c_client *client)

static struct ds1621_data *ds1621_update_client(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct ds1621_data *data = i2c_get_clientdata(client);
struct ds1621_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
u8 new_conf;

mutex_lock(&data->update_lock);
Expand Down Expand Up @@ -247,8 +247,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct i2c_client *client = to_i2c_client(dev);
struct ds1621_data *data = i2c_get_clientdata(client);
struct ds1621_data *data = dev_get_drvdata(dev);
long val;
int err;

Expand All @@ -258,7 +257,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,

mutex_lock(&data->update_lock);
data->temp[attr->index] = DS1621_TEMP_TO_REG(val, data->zbits);
i2c_smbus_write_word_swapped(client, DS1621_REG_TEMP[attr->index],
i2c_smbus_write_word_swapped(data->client, DS1621_REG_TEMP[attr->index],
data->temp[attr->index]);
mutex_unlock(&data->update_lock);
return count;
Expand All @@ -282,16 +281,15 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
static ssize_t show_convrate(struct device *dev, struct device_attribute *da,
char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct ds1621_data *data = i2c_get_clientdata(client);
struct ds1621_data *data = dev_get_drvdata(dev);
return scnprintf(buf, PAGE_SIZE, "%hu\n", data->update_interval);
}

static ssize_t set_convrate(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct ds1621_data *data = i2c_get_clientdata(client);
struct ds1621_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
unsigned long convrate;
s32 err;
int resol = 0;
Expand Down Expand Up @@ -343,8 +341,7 @@ static umode_t ds1621_attribute_visible(struct kobject *kobj,
struct attribute *attr, int index)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct i2c_client *client = to_i2c_client(dev);
struct ds1621_data *data = i2c_get_clientdata(client);
struct ds1621_data *data = dev_get_drvdata(dev);

if (attr == &dev_attr_update_interval.attr)
if (data->kind == ds1621 || data->kind == ds1625)
Expand All @@ -358,49 +355,46 @@ static const struct attribute_group ds1621_group = {
.is_visible = ds1621_attribute_visible
};

static const struct attribute_group *ds1621_groups[] = {
&ds1621_group,
NULL
};

static int ds1621_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct ds1621_data *data;
int err;
struct device *hwmon_dev;

data = devm_kzalloc(&client->dev, sizeof(struct ds1621_data),
GFP_KERNEL);
if (!data)
return -ENOMEM;

i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);

data->kind = id->driver_data;
data->client = client;

/* Initialize the DS1621 chip */
ds1621_init_client(client);
ds1621_init_client(data, client);

/* Register sysfs hooks */
err = sysfs_create_group(&client->dev.kobj, &ds1621_group);
if (err)
return err;
hwmon_dev = hwmon_device_register_with_groups(&client->dev,
client->name, data,
ds1621_groups);
if (IS_ERR(hwmon_dev))
return PTR_ERR(hwmon_dev);

data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev);
goto exit_remove_files;
}
i2c_set_clientdata(client, hwmon_dev);

return 0;

exit_remove_files:
sysfs_remove_group(&client->dev.kobj, &ds1621_group);
return err;
}

static int ds1621_remove(struct i2c_client *client)
{
struct ds1621_data *data = i2c_get_clientdata(client);
struct device *hwmon_dev = i2c_get_clientdata(client);

hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &ds1621_group);
hwmon_device_unregister(hwmon_dev);

return 0;
}
Expand Down

0 comments on commit 8269b75

Please sign in to comment.