/* per client data */
struct adm9240_data {
- struct device *hwmon_dev;
+ struct i2c_client *client;
struct mutex update_lock;
char valid;
unsigned long last_updated_measure;
static struct adm9240_data *adm9240_update_device(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct adm9240_data *data = i2c_get_clientdata(client);
+ struct adm9240_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)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
- struct i2c_client *client = to_i2c_client(dev);
- struct adm9240_data *data = i2c_get_clientdata(client);
+ struct adm9240_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
- struct i2c_client *client = to_i2c_client(dev);
- struct adm9240_data *data = i2c_get_clientdata(client);
+ struct adm9240_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
- struct i2c_client *client = to_i2c_client(dev);
- struct adm9240_data *data = i2c_get_clientdata(client);
+ struct adm9240_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
- struct i2c_client *client = to_i2c_client(dev);
- struct adm9240_data *data = i2c_get_clientdata(client);
+ struct adm9240_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int nr = attr->index;
u8 new_div;
unsigned long val;
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct adm9240_data *data = i2c_get_clientdata(client);
+ struct adm9240_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)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct adm9240_data *data = i2c_get_clientdata(client);
+ struct adm9240_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
if (kstrtoul(buf, 10, &val) || val != 0)
static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm,
chassis_clear, 12);
-static struct attribute *adm9240_attributes[] = {
+static struct attribute *adm9240_attrs[] = {
&sensor_dev_attr_in0_input.dev_attr.attr,
&sensor_dev_attr_in0_min.dev_attr.attr,
&sensor_dev_attr_in0_max.dev_attr.attr,
NULL
};
-static const struct attribute_group adm9240_group = {
- .attrs = adm9240_attributes,
-};
+ATTRIBUTE_GROUPS(adm9240);
/*** sensor chip detect and driver install ***/
static int adm9240_probe(struct i2c_client *new_client,
const struct i2c_device_id *id)
{
+ struct device *dev = &new_client->dev;
+ struct device *hwmon_dev;
struct adm9240_data *data;
- int err;
- data = devm_kzalloc(&new_client->dev, sizeof(*data), GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
i2c_set_clientdata(new_client, data);
+ data->client = new_client;
mutex_init(&data->update_lock);
adm9240_init_client(new_client);
- /* populate sysfs filesystem */
- err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group);
- if (err)
- return err;
-
- data->hwmon_dev = hwmon_device_register(&new_client->dev);
- if (IS_ERR(data->hwmon_dev)) {
- err = PTR_ERR(data->hwmon_dev);
- goto exit_remove;
- }
-
- return 0;
-
-exit_remove:
- sysfs_remove_group(&new_client->dev.kobj, &adm9240_group);
- return err;
-}
-
-static int adm9240_remove(struct i2c_client *client)
-{
- struct adm9240_data *data = i2c_get_clientdata(client);
-
- hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &adm9240_group);
-
- return 0;
+ hwmon_dev = devm_hwmon_device_register_with_groups(dev,
+ new_client->name,
+ data,
+ adm9240_groups);
+ return PTR_ERR_OR_ZERO(hwmon_dev);
}
static const struct i2c_device_id adm9240_id[] = {
.name = "adm9240",
},
.probe = adm9240_probe,
- .remove = adm9240_remove,
.id_table = adm9240_id,
.detect = adm9240_detect,
.address_list = normal_i2c,