提交 927afbec 编写于 作者: J Jonathan Cameron 提交者: Greg Kroah-Hartman

staging:iio:light:isl29018: allocate device state with iio_dev

V2: Actually allocate the space for iio_priv
Signed-off-by: NJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 88fa4de4
...@@ -54,7 +54,6 @@ ...@@ -54,7 +54,6 @@
#define ISL29018_MAX_REGS ISL29018_REG_ADD_DATA_MSB #define ISL29018_MAX_REGS ISL29018_REG_ADD_DATA_MSB
struct isl29018_chip { struct isl29018_chip {
struct iio_dev *indio_dev;
struct i2c_client *client; struct i2c_client *client;
struct mutex lock; struct mutex lock;
unsigned int range; unsigned int range;
...@@ -227,7 +226,7 @@ static int isl29018_read_proximity_ir(struct i2c_client *client, int scheme, ...@@ -227,7 +226,7 @@ static int isl29018_read_proximity_ir(struct i2c_client *client, int scheme,
static ssize_t get_sensor_data(struct device *dev, char *buf, int mode) static ssize_t get_sensor_data(struct device *dev, char *buf, int mode)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct isl29018_chip *chip = indio_dev->dev_data; struct isl29018_chip *chip = iio_priv(indio_dev);
struct i2c_client *client = chip->client; struct i2c_client *client = chip->client;
int value = 0; int value = 0;
int status; int status;
...@@ -269,7 +268,7 @@ static ssize_t show_range(struct device *dev, ...@@ -269,7 +268,7 @@ static ssize_t show_range(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct isl29018_chip *chip = indio_dev->dev_data; struct isl29018_chip *chip = iio_priv(indio_dev);
return sprintf(buf, "%u\n", chip->range); return sprintf(buf, "%u\n", chip->range);
} }
...@@ -278,7 +277,7 @@ static ssize_t store_range(struct device *dev, ...@@ -278,7 +277,7 @@ static ssize_t store_range(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct isl29018_chip *chip = indio_dev->dev_data; struct isl29018_chip *chip = iio_priv(indio_dev);
struct i2c_client *client = chip->client; struct i2c_client *client = chip->client;
int status; int status;
unsigned long lval; unsigned long lval;
...@@ -311,7 +310,7 @@ static ssize_t show_resolution(struct device *dev, ...@@ -311,7 +310,7 @@ static ssize_t show_resolution(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct isl29018_chip *chip = indio_dev->dev_data; struct isl29018_chip *chip = iio_priv(indio_dev);
return sprintf(buf, "%u\n", chip->adc_bit); return sprintf(buf, "%u\n", chip->adc_bit);
} }
...@@ -320,7 +319,7 @@ static ssize_t store_resolution(struct device *dev, ...@@ -320,7 +319,7 @@ static ssize_t store_resolution(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct isl29018_chip *chip = indio_dev->dev_data; struct isl29018_chip *chip = iio_priv(indio_dev);
struct i2c_client *client = chip->client; struct i2c_client *client = chip->client;
int status; int status;
unsigned long lval; unsigned long lval;
...@@ -351,7 +350,7 @@ static ssize_t show_prox_infrared_supression(struct device *dev, ...@@ -351,7 +350,7 @@ static ssize_t show_prox_infrared_supression(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct isl29018_chip *chip = indio_dev->dev_data; struct isl29018_chip *chip = iio_priv(indio_dev);
/* return the "proximity scheme" i.e. if the chip does on chip /* return the "proximity scheme" i.e. if the chip does on chip
infrared supression (1 means perform on chip supression) */ infrared supression (1 means perform on chip supression) */
...@@ -362,7 +361,7 @@ static ssize_t store_prox_infrared_supression(struct device *dev, ...@@ -362,7 +361,7 @@ static ssize_t store_prox_infrared_supression(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct isl29018_chip *chip = indio_dev->dev_data; struct isl29018_chip *chip = iio_priv(indio_dev);
unsigned long lval; unsigned long lval;
if (strict_strtoul(buf, 10, &lval)) if (strict_strtoul(buf, 10, &lval))
...@@ -464,16 +463,18 @@ static int __devinit isl29018_probe(struct i2c_client *client, ...@@ -464,16 +463,18 @@ static int __devinit isl29018_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct isl29018_chip *chip; struct isl29018_chip *chip;
struct iio_dev *indio_dev;
int err; int err;
chip = kzalloc(sizeof(struct isl29018_chip), GFP_KERNEL); indio_dev = iio_allocate_device(sizeof(*chip));
if (!chip) { if (indio_dev == NULL) {
dev_err(&client->dev, "Memory allocation fails\n"); dev_err(&client->dev, "iio allocation fails\n");
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
chip = iio_priv(indio_dev);
i2c_set_clientdata(client, chip); i2c_set_clientdata(client, indio_dev);
chip->client = client; chip->client = client;
mutex_init(&chip->lock); mutex_init(&chip->lock);
...@@ -483,19 +484,13 @@ static int __devinit isl29018_probe(struct i2c_client *client, ...@@ -483,19 +484,13 @@ static int __devinit isl29018_probe(struct i2c_client *client,
err = isl29018_chip_init(client); err = isl29018_chip_init(client);
if (err) if (err)
goto exit_free; goto exit_iio_free;
chip->indio_dev = iio_allocate_device(0); indio_dev->info = &isl29108_info;
if (!chip->indio_dev) { indio_dev->name = id->name;
dev_err(&client->dev, "iio allocation fails\n"); indio_dev->dev.parent = &client->dev;
goto exit_free; indio_dev->modes = INDIO_DIRECT_MODE;
} err = iio_device_register(indio_dev);
chip->indio_dev->info = &isl29108_info;
chip->indio_dev->name = id->name;
chip->indio_dev->dev.parent = &client->dev;
chip->indio_dev->dev_data = (void *)(chip);
chip->indio_dev->modes = INDIO_DIRECT_MODE;
err = iio_device_register(chip->indio_dev);
if (err) { if (err) {
dev_err(&client->dev, "iio registration fails\n"); dev_err(&client->dev, "iio registration fails\n");
goto exit_iio_free; goto exit_iio_free;
...@@ -503,20 +498,17 @@ static int __devinit isl29018_probe(struct i2c_client *client, ...@@ -503,20 +498,17 @@ static int __devinit isl29018_probe(struct i2c_client *client,
return 0; return 0;
exit_iio_free: exit_iio_free:
iio_free_device(chip->indio_dev); iio_free_device(indio_dev);
exit_free:
kfree(chip);
exit: exit:
return err; return err;
} }
static int __devexit isl29018_remove(struct i2c_client *client) static int __devexit isl29018_remove(struct i2c_client *client)
{ {
struct isl29018_chip *chip = i2c_get_clientdata(client); struct iio_dev *indio_dev = i2c_get_clientdata(client);
dev_dbg(&client->dev, "%s()\n", __func__); dev_dbg(&client->dev, "%s()\n", __func__);
iio_device_unregister(chip->indio_dev); iio_device_unregister(indio_dev);
kfree(chip);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册