* Client-specific data
*/
struct lm93_data {
- struct device *hwmon_dev;
+ struct i2c_client *client;
struct mutex update_lock;
unsigned long last_updated; /* In jiffies */
static struct lm93_data *lm93_update_device(struct device *dev)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
const unsigned long interval = HZ + (HZ / 2);
mutex_lock(&data->update_lock);
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int vccp = nr - 6;
long vid;
unsigned long val;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
int vccp = nr - 6;
long vid;
unsigned long val;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr);
int nr = s_attr->index;
int ofs = s_attr->nr;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 reg, ctl4;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 reg;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 ctl2, ctl4;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 ctl2;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 ctl4;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 ctl3, ctl4;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 ctl3;
unsigned long val;
int err;
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 ramp;
unsigned long val;
int err;
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 ramp;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
const char *buf, size_t count)
{
int nr = (to_sensor_dev_attr(attr))->index;
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
u8 tmp;
unsigned long val;
int err;
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct lm93_data *data = i2c_get_clientdata(client);
+ struct lm93_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
unsigned long val;
int err;
NULL
};
-static struct attribute_group lm93_attr_grp = {
- .attrs = lm93_attrs,
-};
+ATTRIBUTE_GROUPS(lm93);
static void lm93_init_client(struct i2c_client *client)
{
static int lm93_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct device *dev = &client->dev;
struct lm93_data *data;
- int err, func;
+ struct device *hwmon_dev;
+ int func;
void (*update)(struct lm93_data *, struct i2c_client *);
/* choose update routine based on bus capabilities */
func = i2c_get_functionality(client->adapter);
if (((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) &&
(!disable_block)) {
- dev_dbg(&client->dev, "using SMBus block data transactions\n");
+ dev_dbg(dev, "using SMBus block data transactions\n");
update = lm93_update_client_full;
} else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) {
- dev_dbg(&client->dev,
- "disabled SMBus block data transactions\n");
+ dev_dbg(dev, "disabled SMBus block data transactions\n");
update = lm93_update_client_min;
} else {
- dev_dbg(&client->dev,
- "detect failed, smbus byte and/or word data not supported!\n");
+ dev_dbg(dev, "detect failed, smbus byte and/or word data not supported!\n");
return -ENODEV;
}
- data = devm_kzalloc(&client->dev, sizeof(struct lm93_data), GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(struct lm93_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
- i2c_set_clientdata(client, data);
/* housekeeping */
+ data->client = client;
data->update = update;
mutex_init(&data->update_lock);
/* initialize the chip */
lm93_init_client(client);
- err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp);
- if (err)
- return err;
-
- /* Register hwmon driver class */
- data->hwmon_dev = hwmon_device_register(&client->dev);
- if (!IS_ERR(data->hwmon_dev))
- return 0;
-
- err = PTR_ERR(data->hwmon_dev);
- dev_err(&client->dev, "error registering hwmon device.\n");
- sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp);
- return err;
-}
-
-static int lm93_remove(struct i2c_client *client)
-{
- struct lm93_data *data = i2c_get_clientdata(client);
-
- hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp);
-
- return 0;
+ hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
+ data,
+ lm93_groups);
+ return PTR_ERR_OR_ZERO(hwmon_dev);
}
static const struct i2c_device_id lm93_id[] = {
.name = "lm93",
},
.probe = lm93_probe,
- .remove = lm93_remove,
.id_table = lm93_id,
.detect = lm93_detect,
.address_list = normal_i2c,