struct tsl2563_chip {
struct mutex lock;
struct i2c_client *client;
- struct iio_dev *indio_dev;
struct delayed_work poweroff_work;
struct work_struct work_thresh;
static ssize_t tsl2563_adc_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tsl2563_chip *chip = indio_dev->dev_data;
+ struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int ret;
static ssize_t tsl2563_lux_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tsl2563_chip *chip = indio_dev->dev_data;
+ struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
u32 calib0, calib1;
int ret;
static ssize_t tsl2563_calib_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tsl2563_chip *chip = indio_dev->dev_data;
+ struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int ret;
struct device_attribute *attr,
const char *buf, size_t len)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tsl2563_chip *chip = indio_dev->dev_data;
+ struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int value;
u32 calib;
struct device_attribute *attr,
char *buf)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tsl2563_chip *chip = indio_dev->dev_data;
+ struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
return sprintf(buf, "%s\n", chip->client->name);
}
struct device_attribute *attr,
char *buf)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tsl2563_chip *chip = indio_dev->dev_data;
+ struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
u16 val = 0;
switch (this_attr->address) {
const char *buf,
size_t len)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tsl2563_chip *chip = indio_dev->dev_data;
+ struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
unsigned long val;
int ret;
s64 timestamp,
int not_test)
{
- struct tsl2563_chip *chip = dev_info->dev_data;
+ struct tsl2563_chip *chip = iio_priv(dev_info);
chip->event_timestamp = timestamp;
schedule_work(&chip->work_thresh);
struct tsl2563_chip, work_thresh);
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,
0,
IIO_EV_TYPE_THRESH,
size_t len)
{
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);
int input, ret = 0;
struct device_attribute *attr,
char *buf)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tsl2563_chip *chip = indio_dev->dev_data;
+ struct tsl2563_chip *chip = iio_priv(dev_get_drvdata(dev));
int ret;
u8 rxbuf;
ssize_t len;
static int __devinit tsl2563_probe(struct i2c_client *client,
const struct i2c_device_id *device_id)
{
+ struct iio_dev *indio_dev;
struct tsl2563_chip *chip;
struct tsl2563_platform_data *pdata = client->dev.platform_data;
int err = 0;
int ret;
u8 id;
- chip = kzalloc(sizeof(*chip), GFP_KERNEL);
- if (!chip)
+ indio_dev = iio_allocate_device(sizeof(*chip));
+ if (!indio_dev)
return -ENOMEM;
+ chip = iio_priv(indio_dev);
+
INIT_WORK(&chip->work_thresh, tsl2563_int_bh);
i2c_set_clientdata(client, chip);
chip->client = client;
dev_info(&client->dev, "model %d, rev. %d\n", id >> 4, id & 0x0f);
- chip->indio_dev = iio_allocate_device(0);
- if (!chip->indio_dev)
- goto fail1;
- chip->indio_dev->attrs = &tsl2563_group;
- 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;
+ indio_dev->attrs = &tsl2563_group;
+ indio_dev->dev.parent = &client->dev;
+ indio_dev->driver_module = THIS_MODULE;
+ indio_dev->modes = INDIO_DIRECT_MODE;
if (client->irq) {
- chip->indio_dev->num_interrupt_lines = 1;
- chip->indio_dev->event_attrs
+ indio_dev->num_interrupt_lines = 1;
+ indio_dev->event_attrs
= &tsl2563_event_attribute_group;
}
- ret = iio_device_register(chip->indio_dev);
+ ret = iio_device_register(indio_dev);
if (ret)
goto fail1;
if (client->irq) {
ret = iio_register_interrupt_line(client->irq,
- chip->indio_dev,
+ indio_dev,
0,
IRQF_TRIGGER_RISING,
client->name);
return 0;
fail3:
if (client->irq)
- iio_unregister_interrupt_line(chip->indio_dev, 0);
+ iio_unregister_interrupt_line(indio_dev, 0);
fail2:
- iio_device_unregister(chip->indio_dev);
+ iio_device_unregister(indio_dev);
fail1:
kfree(chip);
return err;
static int tsl2563_remove(struct i2c_client *client)
{
struct tsl2563_chip *chip = i2c_get_clientdata(client);
+ struct iio_dev *indio_dev = iio_priv_to_dev(chip);
if (!chip->int_enabled)
cancel_delayed_work(&chip->poweroff_work);
/* Ensure that interrupts are disabled - then flush any bottom halves */
flush_scheduled_work();
tsl2563_set_power(chip, 0);
if (client->irq)
- iio_unregister_interrupt_line(chip->indio_dev, 0);
- iio_device_unregister(chip->indio_dev);
+ iio_unregister_interrupt_line(indio_dev, 0);
+ iio_device_unregister(indio_dev);
- kfree(chip);
return 0;
}