Commit 33789dce authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:tsl2563 take advantage of new iio_device_allocate private data.

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent c77b3810
...@@ -115,7 +115,6 @@ static struct tsl2563_gainlevel_coeff tsl2563_gainlevel_table[] = { ...@@ -115,7 +115,6 @@ static struct tsl2563_gainlevel_coeff tsl2563_gainlevel_table[] = {
struct tsl2563_chip { struct tsl2563_chip {
struct mutex lock; struct mutex lock;
struct i2c_client *client; struct i2c_client *client;
struct iio_dev *indio_dev;
struct delayed_work poweroff_work; struct delayed_work poweroff_work;
struct work_struct work_thresh; struct work_struct work_thresh;
...@@ -470,8 +469,7 @@ static unsigned int adc_to_lux(u32 adc0, u32 adc1) ...@@ -470,8 +469,7 @@ static unsigned int adc_to_lux(u32 adc0, u32 adc1)
static ssize_t tsl2563_adc_show(struct device *dev, static ssize_t tsl2563_adc_show(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 tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct tsl2563_chip *chip = indio_dev->dev_data;
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int ret; int ret;
...@@ -508,8 +506,7 @@ static u32 calib_adc(u32 adc, u32 calib) ...@@ -508,8 +506,7 @@ static u32 calib_adc(u32 adc, u32 calib)
static ssize_t tsl2563_lux_show(struct device *dev, static ssize_t tsl2563_lux_show(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 tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct tsl2563_chip *chip = indio_dev->dev_data;
u32 calib0, calib1; u32 calib0, calib1;
int ret; int ret;
...@@ -537,8 +534,7 @@ static ssize_t format_calib(char *buf, int len, u32 calib) ...@@ -537,8 +534,7 @@ static ssize_t format_calib(char *buf, int len, u32 calib)
static ssize_t tsl2563_calib_show(struct device *dev, static ssize_t tsl2563_calib_show(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 tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct tsl2563_chip *chip = indio_dev->dev_data;
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int ret; int ret;
...@@ -561,8 +557,7 @@ static ssize_t tsl2563_calib_store(struct device *dev, ...@@ -561,8 +557,7 @@ static ssize_t tsl2563_calib_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t len) const char *buf, size_t len)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct tsl2563_chip *chip = indio_dev->dev_data;
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int value; int value;
u32 calib; u32 calib;
...@@ -598,8 +593,7 @@ static ssize_t tsl2563_show_name(struct device *dev, ...@@ -598,8 +593,7 @@ static ssize_t tsl2563_show_name(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct tsl2563_chip *chip = indio_dev->dev_data;
return sprintf(buf, "%s\n", chip->client->name); return sprintf(buf, "%s\n", chip->client->name);
} }
...@@ -623,8 +617,7 @@ static ssize_t tsl2563_read_thresh(struct device *dev, ...@@ -623,8 +617,7 @@ static ssize_t tsl2563_read_thresh(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct tsl2563_chip *chip = indio_dev->dev_data;
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
u16 val = 0; u16 val = 0;
switch (this_attr->address) { switch (this_attr->address) {
...@@ -643,8 +636,7 @@ static ssize_t tsl2563_write_thresh(struct device *dev, ...@@ -643,8 +636,7 @@ static ssize_t tsl2563_write_thresh(struct device *dev,
const char *buf, const char *buf,
size_t len) size_t len)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct tsl2563_chip *chip = indio_dev->dev_data;
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
unsigned long val; unsigned long val;
int ret; int ret;
...@@ -690,7 +682,7 @@ static int tsl2563_int_th(struct iio_dev *dev_info, ...@@ -690,7 +682,7 @@ static int tsl2563_int_th(struct iio_dev *dev_info,
s64 timestamp, s64 timestamp,
int not_test) int not_test)
{ {
struct tsl2563_chip *chip = dev_info->dev_data; struct tsl2563_chip *chip = iio_priv(dev_info);
chip->event_timestamp = timestamp; chip->event_timestamp = timestamp;
schedule_work(&chip->work_thresh); schedule_work(&chip->work_thresh);
...@@ -705,7 +697,7 @@ static void tsl2563_int_bh(struct work_struct *work_s) ...@@ -705,7 +697,7 @@ static void tsl2563_int_bh(struct work_struct *work_s)
struct tsl2563_chip, work_thresh); struct tsl2563_chip, work_thresh);
u8 cmd = TSL2563_CMD | TSL2563_CLEARINT; u8 cmd = TSL2563_CMD | TSL2563_CLEARINT;
iio_push_event(chip->indio_dev, 0, iio_push_event(iio_priv_to_dev(chip), 0,
IIO_UNMOD_EVENT_CODE(IIO_EV_CLASS_LIGHT, IIO_UNMOD_EVENT_CODE(IIO_EV_CLASS_LIGHT,
0, 0,
IIO_EV_TYPE_THRESH, IIO_EV_TYPE_THRESH,
...@@ -725,7 +717,7 @@ static ssize_t tsl2563_write_interrupt_config(struct device *dev, ...@@ -725,7 +717,7 @@ static ssize_t tsl2563_write_interrupt_config(struct device *dev,
size_t len) size_t len)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct tsl2563_chip *chip = indio_dev->dev_data; struct tsl2563_chip *chip = iio_priv(indio_dev);
struct iio_event_attr *this_attr = to_iio_event_attr(attr); struct iio_event_attr *this_attr = to_iio_event_attr(attr);
int input, ret = 0; int input, ret = 0;
...@@ -771,8 +763,7 @@ static ssize_t tsl2563_read_interrupt_config(struct device *dev, ...@@ -771,8 +763,7 @@ static ssize_t tsl2563_read_interrupt_config(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct tsl2563_chip *chip = indio_dev->dev_data;
int ret; int ret;
u8 rxbuf; u8 rxbuf;
ssize_t len; ssize_t len;
...@@ -816,16 +807,19 @@ static struct i2c_driver tsl2563_i2c_driver; ...@@ -816,16 +807,19 @@ static struct i2c_driver tsl2563_i2c_driver;
static int __devinit tsl2563_probe(struct i2c_client *client, static int __devinit tsl2563_probe(struct i2c_client *client,
const struct i2c_device_id *device_id) const struct i2c_device_id *device_id)
{ {
struct iio_dev *indio_dev;
struct tsl2563_chip *chip; struct tsl2563_chip *chip;
struct tsl2563_platform_data *pdata = client->dev.platform_data; struct tsl2563_platform_data *pdata = client->dev.platform_data;
int err = 0; int err = 0;
int ret; int ret;
u8 id; u8 id;
chip = kzalloc(sizeof(*chip), GFP_KERNEL); indio_dev = iio_allocate_device(sizeof(*chip));
if (!chip) if (!indio_dev)
return -ENOMEM; return -ENOMEM;
chip = iio_priv(indio_dev);
INIT_WORK(&chip->work_thresh, tsl2563_int_bh); INIT_WORK(&chip->work_thresh, tsl2563_int_bh);
i2c_set_clientdata(client, chip); i2c_set_clientdata(client, chip);
chip->client = client; chip->client = client;
...@@ -857,26 +851,22 @@ static int __devinit tsl2563_probe(struct i2c_client *client, ...@@ -857,26 +851,22 @@ static int __devinit tsl2563_probe(struct i2c_client *client,
dev_info(&client->dev, "model %d, rev. %d\n", id >> 4, id & 0x0f); dev_info(&client->dev, "model %d, rev. %d\n", id >> 4, id & 0x0f);
chip->indio_dev = iio_allocate_device(0); indio_dev->attrs = &tsl2563_group;
if (!chip->indio_dev) indio_dev->dev.parent = &client->dev;
goto fail1; indio_dev->driver_module = THIS_MODULE;
chip->indio_dev->attrs = &tsl2563_group; indio_dev->modes = INDIO_DIRECT_MODE;
chip->indio_dev->dev.parent = &client->dev;
chip->indio_dev->dev_data = (void *)(chip);
chip->indio_dev->driver_module = THIS_MODULE;
chip->indio_dev->modes = INDIO_DIRECT_MODE;
if (client->irq) { if (client->irq) {
chip->indio_dev->num_interrupt_lines = 1; indio_dev->num_interrupt_lines = 1;
chip->indio_dev->event_attrs indio_dev->event_attrs
= &tsl2563_event_attribute_group; = &tsl2563_event_attribute_group;
} }
ret = iio_device_register(chip->indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto fail1; goto fail1;
if (client->irq) { if (client->irq) {
ret = iio_register_interrupt_line(client->irq, ret = iio_register_interrupt_line(client->irq,
chip->indio_dev, indio_dev,
0, 0,
IRQF_TRIGGER_RISING, IRQF_TRIGGER_RISING,
client->name); client->name);
...@@ -894,9 +884,9 @@ static int __devinit tsl2563_probe(struct i2c_client *client, ...@@ -894,9 +884,9 @@ static int __devinit tsl2563_probe(struct i2c_client *client,
return 0; return 0;
fail3: fail3:
if (client->irq) if (client->irq)
iio_unregister_interrupt_line(chip->indio_dev, 0); iio_unregister_interrupt_line(indio_dev, 0);
fail2: fail2:
iio_device_unregister(chip->indio_dev); iio_device_unregister(indio_dev);
fail1: fail1:
kfree(chip); kfree(chip);
return err; return err;
...@@ -905,6 +895,7 @@ static int __devinit tsl2563_probe(struct i2c_client *client, ...@@ -905,6 +895,7 @@ static int __devinit tsl2563_probe(struct i2c_client *client,
static int tsl2563_remove(struct i2c_client *client) static int tsl2563_remove(struct i2c_client *client)
{ {
struct tsl2563_chip *chip = i2c_get_clientdata(client); struct tsl2563_chip *chip = i2c_get_clientdata(client);
struct iio_dev *indio_dev = iio_priv_to_dev(chip);
if (!chip->int_enabled) if (!chip->int_enabled)
cancel_delayed_work(&chip->poweroff_work); cancel_delayed_work(&chip->poweroff_work);
/* Ensure that interrupts are disabled - then flush any bottom halves */ /* Ensure that interrupts are disabled - then flush any bottom halves */
...@@ -913,10 +904,9 @@ static int tsl2563_remove(struct i2c_client *client) ...@@ -913,10 +904,9 @@ static int tsl2563_remove(struct i2c_client *client)
flush_scheduled_work(); flush_scheduled_work();
tsl2563_set_power(chip, 0); tsl2563_set_power(chip, 0);
if (client->irq) if (client->irq)
iio_unregister_interrupt_line(chip->indio_dev, 0); iio_unregister_interrupt_line(indio_dev, 0);
iio_device_unregister(chip->indio_dev); iio_device_unregister(indio_dev);
kfree(chip);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment