struct ad7150_chip_info {
struct i2c_client *client;
- struct iio_dev *indio_dev;
bool inter;
u16 ch1_threshold; /* Ch1 Threshold (in fixed threshold mode) */
u8 ch1_sensitivity; /* Ch1 Sensitivity (in adaptive threshold mode) */
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "%s\n", chip->conversion_mode);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
u8 cfg;
int i;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
u8 data[2];
ad7150_i2c_read(chip, AD7150_CH1_DATA_HIGH, data, 2);
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
u8 data[2];
ad7150_i2c_read(chip, AD7150_CH2_DATA_HIGH, data, 2);
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "%s\n", chip->threshold_mode);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
u8 cfg;
ad7150_i2c_read(chip, AD7150_CFG, &cfg, 1);
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "%d\n", chip->ch1_threshold);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "%d\n", chip->ch2_threshold);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "%d\n", chip->ch1_sensitivity);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "%d\n", chip->ch2_sensitivity);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "%d\n", chip->ch1_timeout);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "%d\n", chip->ch2_timeout);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "0x%02x\n", chip->ch1_setup);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "0x%02x\n", chip->ch2_setup);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
return sprintf(buf, "0x%02x\n", chip->powerdown_timer);
}
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7150_chip_info *chip = dev_info->dev_data;
+ struct ad7150_chip_info *chip = iio_priv(dev_info);
unsigned long data;
int ret;
static irqreturn_t ad7150_event_handler(int irq, void *private)
{
struct iio_dev *indio_dev = private;
- struct ad7150_chip_info *chip = iio_dev_get_devdata(indio_dev);
+ struct ad7150_chip_info *chip = iio_priv(indio_dev);
u8 int_status;
s64 timestamp = iio_get_time_ns();
const struct i2c_device_id *id)
{
int ret = 0, regdone = 0;
- struct ad7150_chip_info *chip = kzalloc(sizeof(*chip), GFP_KERNEL);
- if (chip == NULL) {
+ struct ad7150_chip_info *chip;
+ struct iio_dev *indio_dev;
+
+ indio_dev = iio_allocate_device(sizeof(*chip));
+ if (indio_dev == NULL) {
ret = -ENOMEM;
goto error_ret;
}
-
+ chip = iio_priv(indio_dev);
/* this is only used for device removal purposes */
- i2c_set_clientdata(client, chip);
+ i2c_set_clientdata(client, indio_dev);
chip->client = client;
- chip->indio_dev = iio_allocate_device(0);
- if (chip->indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_free_chip;
- }
-
/* Establish that the iio_dev is a child of the i2c device */
- chip->indio_dev->name = id->name;
- chip->indio_dev->dev.parent = &client->dev;
+ indio_dev->name = id->name;
+ indio_dev->dev.parent = &client->dev;
- chip->indio_dev->info = &ad7150_info;
- chip->indio_dev->dev_data = (void *)(chip);
+ indio_dev->info = &ad7150_info;
- chip->indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(chip->indio_dev);
+ ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
regdone = 1;
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING,
"ad7150",
- chip->indio_dev);
+ indio_dev);
if (ret)
goto error_free_dev;
}
error_free_dev:
if (regdone)
- iio_device_unregister(chip->indio_dev);
+ iio_device_unregister(indio_dev);
else
- iio_free_device(chip->indio_dev);
-error_free_chip:
- kfree(chip);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
static int __devexit ad7150_remove(struct i2c_client *client)
{
- struct ad7150_chip_info *chip = i2c_get_clientdata(client);
- struct iio_dev *indio_dev = chip->indio_dev;
+ struct iio_dev *indio_dev = i2c_get_clientdata(client);
if (client->irq)
free_irq(client->irq, indio_dev);
iio_device_unregister(indio_dev);
- kfree(chip);
return 0;
}