*/
struct adm1025_data {
- struct device *hwmon_dev;
+ struct i2c_client *client;
+ const struct attribute_group *groups[3];
struct mutex update_lock;
char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */
static struct adm1025_data *adm1025_update_device(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct adm1025_data *data = i2c_get_clientdata(client);
+ struct adm1025_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
mutex_lock(&data->update_lock);
const char *buf, size_t count)
{
int index = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct adm1025_data *data = i2c_get_clientdata(client);
+ struct adm1025_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int index = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct adm1025_data *data = i2c_get_clientdata(client);
+ struct adm1025_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int index = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct adm1025_data *data = i2c_get_clientdata(client);
+ struct adm1025_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int index = to_sensor_dev_attr(attr)->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct adm1025_data *data = i2c_get_clientdata(client);
+ struct adm1025_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
static int adm1025_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct device *dev = &client->dev;
+ struct device *hwmon_dev;
struct adm1025_data *data;
- int err;
u8 config;
- data = devm_kzalloc(&client->dev, sizeof(struct adm1025_data),
- GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(struct adm1025_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
i2c_set_clientdata(client, data);
+ data->client = client;
mutex_init(&data->update_lock);
/* Initialize the ADM1025 chip */
adm1025_init_client(client);
- /* Register sysfs hooks */
- err = sysfs_create_group(&client->dev.kobj, &adm1025_group);
- if (err)
- return err;
-
+ /* sysfs hooks */
+ data->groups[0] = &adm1025_group;
/* Pin 11 is either in4 (+12V) or VID4 */
config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
- if (!(config & 0x20)) {
- err = sysfs_create_group(&client->dev.kobj, &adm1025_group_in4);
- if (err)
- goto exit_remove;
- }
-
- data->hwmon_dev = hwmon_device_register(&client->dev);
- if (IS_ERR(data->hwmon_dev)) {
- err = PTR_ERR(data->hwmon_dev);
- goto exit_remove;
- }
-
- return 0;
+ if (!(config & 0x20))
+ data->groups[1] = &adm1025_group_in4;
-exit_remove:
- sysfs_remove_group(&client->dev.kobj, &adm1025_group);
- sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
- return err;
-}
-
-static int adm1025_remove(struct i2c_client *client)
-{
- struct adm1025_data *data = i2c_get_clientdata(client);
-
- hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &adm1025_group);
- sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
-
- 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 adm1025_id[] = {
.name = "adm1025",
},
.probe = adm1025_probe,
- .remove = adm1025_remove,
.id_table = adm1025_id,
.detect = adm1025_detect,
.address_list = normal_i2c,