diff options
Diffstat (limited to 'drivers/staging/iio/adc')
-rw-r--r-- | drivers/staging/iio/adc/Kconfig | 14 | ||||
-rw-r--r-- | drivers/staging/iio/adc/Makefile | 1 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7150.c | 91 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7152.c | 73 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7291.c | 86 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7314.c | 48 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7476.h | 5 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7476_core.c | 84 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7476_ring.c | 10 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7745.c | 79 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7793.c | 987 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7793.h | 107 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7816.c | 74 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7887_core.c | 3 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7887_ring.c | 6 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad799x_core.c | 13 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad799x_ring.c | 4 | ||||
-rw-r--r-- | drivers/staging/iio/adc/adt7310.c | 94 | ||||
-rw-r--r-- | drivers/staging/iio/adc/adt7410.c | 86 | ||||
-rw-r--r-- | drivers/staging/iio/adc/adt75.c | 123 | ||||
-rw-r--r-- | drivers/staging/iio/adc/max1363_core.c | 20 |
21 files changed, 1514 insertions, 494 deletions
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig index 8c751c46ddd7..b39f2e1c1fe6 100644 --- a/drivers/staging/iio/adc/Kconfig +++ b/drivers/staging/iio/adc/Kconfig @@ -130,6 +130,20 @@ config AD7780 To compile this driver as a module, choose M here: the module will be called ad7780. +config AD7793 + tristate "Analog Devices AD7792 AD7793 ADC driver" + depends on SPI + select IIO_RING_BUFFER + select IIO_SW_RING + select IIO_TRIGGER + help + Say yes here to build support for Analog Devices + AD7792 and AD7793 SPI analog to digital convertors (ADC). + If unsure, say N (but it's safe to say "Y"). + + To compile this driver as a module, choose M here: the + module will be called AD7793. + config AD7745 tristate "Analog Devices AD7745, AD7746 AD7747 capacitive sensor driver" depends on I2C diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile index 1d9b3f582eab..f02035139979 100644 --- a/drivers/staging/iio/adc/Makefile +++ b/drivers/staging/iio/adc/Makefile @@ -35,6 +35,7 @@ obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7745) += ad7745.o obj-$(CONFIG_AD7780) += ad7780.o +obj-$(CONFIG_AD7793) += ad7793.o obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_ADT75) += adt75.o obj-$(CONFIG_ADT7310) += adt7310.o diff --git a/drivers/staging/iio/adc/ad7150.c b/drivers/staging/iio/adc/ad7150.c index ca32b6778a9e..04017ef6688a 100644 --- a/drivers/staging/iio/adc/ad7150.c +++ b/drivers/staging/iio/adc/ad7150.c @@ -59,7 +59,6 @@ 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) */ @@ -184,7 +183,7 @@ static ssize_t ad7150_show_conversion_mode(struct device *dev, 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); } @@ -195,7 +194,7 @@ static ssize_t ad7150_store_conversion_mode(struct device *dev, 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; @@ -234,7 +233,7 @@ static ssize_t ad7150_show_ch1_value(struct device *dev, 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); @@ -248,7 +247,7 @@ static ssize_t ad7150_show_ch2_value(struct device *dev, 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); @@ -262,7 +261,7 @@ static ssize_t ad7150_show_threshold_mode(struct device *dev, 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); } @@ -273,7 +272,7 @@ static ssize_t ad7150_store_threshold_mode(struct device *dev, 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); @@ -305,7 +304,7 @@ static ssize_t ad7150_show_ch1_threshold(struct device *dev, 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); } @@ -316,7 +315,7 @@ static ssize_t ad7150_store_ch1_threshold(struct device *dev, 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; @@ -341,7 +340,7 @@ static ssize_t ad7150_show_ch2_threshold(struct device *dev, 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); } @@ -352,7 +351,7 @@ static ssize_t ad7150_store_ch2_threshold(struct device *dev, 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; @@ -377,7 +376,7 @@ static ssize_t ad7150_show_ch1_sensitivity(struct device *dev, 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); } @@ -388,7 +387,7 @@ static ssize_t ad7150_store_ch1_sensitivity(struct device *dev, 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; @@ -412,7 +411,7 @@ static ssize_t ad7150_show_ch2_sensitivity(struct device *dev, 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); } @@ -423,7 +422,7 @@ static ssize_t ad7150_store_ch2_sensitivity(struct device *dev, 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; @@ -447,7 +446,7 @@ static ssize_t ad7150_show_ch1_timeout(struct device *dev, 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); } @@ -458,7 +457,7 @@ static ssize_t ad7150_store_ch1_timeout(struct device *dev, 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; @@ -482,7 +481,7 @@ static ssize_t ad7150_show_ch2_timeout(struct device *dev, 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); } @@ -493,7 +492,7 @@ static ssize_t ad7150_store_ch2_timeout(struct device *dev, 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; @@ -517,7 +516,7 @@ static ssize_t ad7150_show_ch1_setup(struct device *dev, 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); } @@ -528,7 +527,7 @@ static ssize_t ad7150_store_ch1_setup(struct device *dev, 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; @@ -553,7 +552,7 @@ static ssize_t ad7150_show_ch2_setup(struct device *dev, 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); } @@ -564,7 +563,7 @@ static ssize_t ad7150_store_ch2_setup(struct device *dev, 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; @@ -588,7 +587,7 @@ static ssize_t ad7150_show_powerdown_timer(struct device *dev, 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); } @@ -599,7 +598,7 @@ static ssize_t ad7150_store_powerdown_timer(struct device *dev, 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; @@ -645,7 +644,7 @@ static const struct attribute_group ad7150_attribute_group = { 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(); @@ -714,33 +713,29 @@ static int __devinit ad7150_probe(struct i2c_client *client, 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; @@ -752,7 +747,7 @@ static int __devinit ad7150_probe(struct i2c_client *client, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "ad7150", - chip->indio_dev); + indio_dev); if (ret) goto error_free_dev; } @@ -763,24 +758,20 @@ static int __devinit ad7150_probe(struct i2c_client *client, 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; } diff --git a/drivers/staging/iio/adc/ad7152.c b/drivers/staging/iio/adc/ad7152.c index 7a38bcbbe1af..21f5f380fb5e 100644 --- a/drivers/staging/iio/adc/ad7152.c +++ b/drivers/staging/iio/adc/ad7152.c @@ -51,7 +51,6 @@ struct ad7152_chip_info { struct i2c_client *client; - struct iio_dev *indio_dev; u16 ch1_offset; /* Channel 1 offset calibration coefficient */ u16 ch1_gain; /* Channel 1 gain coefficient */ u8 ch1_setup; @@ -166,7 +165,7 @@ static ssize_t ad7152_show_ch1_value(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); u8 data[2]; ad7152_i2c_read(chip, AD7152_CH1_DATA_HIGH, data, 2); @@ -180,7 +179,7 @@ static ssize_t ad7152_show_ch2_value(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); u8 data[2]; ad7152_i2c_read(chip, AD7152_CH2_DATA_HIGH, data, 2); @@ -194,7 +193,7 @@ static ssize_t ad7152_show_conversion_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%s\n", chip->conversion_mode); } @@ -205,7 +204,7 @@ static ssize_t ad7152_store_conversion_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); u8 cfg; int i; @@ -234,7 +233,7 @@ static ssize_t ad7152_show_ch1_offset(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", chip->ch1_offset); } @@ -245,7 +244,7 @@ static ssize_t ad7152_store_ch1_offset(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -270,7 +269,7 @@ static ssize_t ad7152_show_ch2_offset(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", chip->ch2_offset); } @@ -281,7 +280,7 @@ static ssize_t ad7152_store_ch2_offset(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -306,7 +305,7 @@ static ssize_t ad7152_show_ch1_gain(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", chip->ch1_gain); } @@ -317,7 +316,7 @@ static ssize_t ad7152_store_ch1_gain(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -342,7 +341,7 @@ static ssize_t ad7152_show_ch2_gain(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", chip->ch2_gain); } @@ -353,7 +352,7 @@ static ssize_t ad7152_store_ch2_gain(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -378,7 +377,7 @@ static ssize_t ad7152_show_ch1_setup(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "0x%02x\n", chip->ch1_setup); } @@ -389,7 +388,7 @@ static ssize_t ad7152_store_ch1_setup(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -413,7 +412,7 @@ static ssize_t ad7152_show_ch2_setup(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "0x%02x\n", chip->ch2_setup); } @@ -424,7 +423,7 @@ static ssize_t ad7152_store_ch2_setup(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -448,7 +447,7 @@ static ssize_t ad7152_show_filter_rate_setup(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "0x%02x\n", chip->filter_rate_setup); } @@ -459,7 +458,7 @@ static ssize_t ad7152_store_filter_rate_setup(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7152_chip_info *chip = dev_info->dev_data; + struct ad7152_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -509,31 +508,27 @@ static int __devinit ad7152_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = 0; - struct ad7152_chip_info *chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { + struct ad7152_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; - } - /* Echipabilish that the iio_dev is a child of the i2c device */ - chip->indio_dev->name = id->name; - chip->indio_dev->dev.parent = &client->dev; - chip->indio_dev->info = &ad7152_info; - chip->indio_dev->dev_data = (void *)(chip); - chip->indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->name = id->name; + indio_dev->dev.parent = &client->dev; + indio_dev->info = &ad7152_info; + 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; @@ -542,20 +537,16 @@ static int __devinit ad7152_probe(struct i2c_client *client, return 0; error_free_dev: - iio_free_device(chip->indio_dev); -error_free_chip: - kfree(chip); + iio_free_device(indio_dev); error_ret: return ret; } static int __devexit ad7152_remove(struct i2c_client *client) { - struct ad7152_chip_info *chip = i2c_get_clientdata(client); - struct iio_dev *indio_dev = chip->indio_dev; + struct iio_dev *indio_dev = i2c_get_clientdata(client); iio_device_unregister(indio_dev); - kfree(chip); return 0; } diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c index 1be3453479b7..96cbb17bc2cd 100644 --- a/drivers/staging/iio/adc/ad7291.c +++ b/drivers/staging/iio/adc/ad7291.c @@ -61,7 +61,6 @@ struct ad7291_chip_info { struct i2c_client *client; - struct iio_dev *indio_dev; u16 command; u8 channels; /* Active voltage channels */ }; @@ -157,7 +156,7 @@ static ssize_t ad7291_show_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); if (chip->command & AD7291_AUTOCYCLE) return sprintf(buf, "autocycle\n"); @@ -171,7 +170,7 @@ static ssize_t ad7291_store_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); u16 command; int ret; @@ -208,7 +207,7 @@ static ssize_t ad7291_store_reset(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); u16 command; int ret; @@ -231,7 +230,7 @@ static ssize_t ad7291_show_ext_ref(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", !!(chip->command & AD7291_EXT_REF)); } @@ -242,7 +241,7 @@ static ssize_t ad7291_store_ext_ref(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); u16 command; int ret; @@ -269,7 +268,7 @@ static ssize_t ad7291_show_noise_delay(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", !!(chip->command & AD7291_NOISE_DELAY)); } @@ -280,7 +279,7 @@ static ssize_t ad7291_store_noise_delay(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); u16 command; int ret; @@ -307,7 +306,7 @@ static ssize_t ad7291_show_t_sense(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); u16 data; char sign = ' '; int ret; @@ -334,7 +333,7 @@ static ssize_t ad7291_show_t_average(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); u16 data; char sign = ' '; int ret; @@ -361,7 +360,7 @@ static ssize_t ad7291_show_voltage(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); u16 data[AD7291_VOLTAGE_LIMIT_COUNT]; int i, size, ret; @@ -390,7 +389,7 @@ static ssize_t ad7291_show_channel_mask(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "0x%x\n", (chip->command & AD7291_VOLTAGE_MASK) >> AD7291_VOLTAGE_OFFSET); @@ -402,7 +401,7 @@ static ssize_t ad7291_store_channel_mask(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); u16 command; unsigned long data; int i, ret; @@ -457,7 +456,7 @@ static const struct attribute_group ad7291_attribute_group = { static irqreturn_t ad7291_event_handler(int irq, void *private) { struct iio_dev *indio_dev = private; - struct ad7291_chip_info *chip = iio_dev_get_devdata(private); + struct ad7291_chip_info *chip = iio_priv(private); u16 t_status, v_status; u16 command; int i; @@ -532,7 +531,7 @@ static inline ssize_t ad7291_show_t_bound(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); u16 data; char sign = ' '; @@ -560,7 +559,7 @@ static inline ssize_t ad7291_set_t_bound(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); long tmp1, tmp2; u16 data; @@ -608,7 +607,7 @@ static inline ssize_t ad7291_show_v_bound(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); u16 data; int ret; @@ -633,7 +632,7 @@ static inline ssize_t ad7291_set_v_bound(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7291_chip_info *chip = dev_info->dev_data; + struct ad7291_chip_info *chip = iio_priv(dev_info); unsigned long value; u16 data; int ret; @@ -792,32 +791,27 @@ static int __devinit ad7291_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ad7291_chip_info *chip; + struct iio_dev *indio_dev; int ret = 0; - chip = kzalloc(sizeof(struct ad7291_chip_info), GFP_KERNEL); - - if (chip == NULL) - return -ENOMEM; - + 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->command = AD7291_NOISE_DELAY | AD7291_T_SENSE_MASK; - chip->indio_dev = iio_allocate_device(0); - if (chip->indio_dev == NULL) { - ret = -ENOMEM; - goto error_free_chip; - } - - chip->indio_dev->name = id->name; - chip->indio_dev->dev.parent = &client->dev; - chip->indio_dev->info = &ad7291_info; - chip->indio_dev->dev_data = (void *)chip; - chip->indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->name = id->name; + indio_dev->dev.parent = &client->dev; + indio_dev->info = &ad7291_info; + 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; @@ -827,7 +821,7 @@ static int __devinit ad7291_probe(struct i2c_client *client, &ad7291_event_handler, IRQF_TRIGGER_LOW | IRQF_ONESHOT, id->name, - chip->indio_dev); + indio_dev); if (ret) goto error_unreg_dev; @@ -847,27 +841,23 @@ static int __devinit ad7291_probe(struct i2c_client *client, return 0; error_unreg_irq: - free_irq(client->irq, chip->indio_dev); + free_irq(client->irq, indio_dev); error_unreg_dev: - iio_device_unregister(chip->indio_dev); + iio_device_unregister(indio_dev); error_free_dev: - iio_free_device(chip->indio_dev); -error_free_chip: - kfree(chip); - + iio_free_device(indio_dev); +error_ret: return ret; } static int __devexit ad7291_remove(struct i2c_client *client) { - struct ad7291_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, chip->indio_dev); + free_irq(client->irq, indio_dev); iio_device_unregister(indio_dev); - iio_free_device(chip->indio_dev); - kfree(chip); + iio_free_device(indio_dev); return 0; } diff --git a/drivers/staging/iio/adc/ad7314.c b/drivers/staging/iio/adc/ad7314.c index 98bb16fcff26..9070d9cac725 100644 --- a/drivers/staging/iio/adc/ad7314.c +++ b/drivers/staging/iio/adc/ad7314.c @@ -43,7 +43,6 @@ struct ad7314_chip_info { struct spi_device *spi_dev; - struct iio_dev *indio_dev; s64 last_timestamp; u8 mode; }; @@ -87,7 +86,7 @@ static ssize_t ad7314_show_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7314_chip_info *chip = dev_info->dev_data; + struct ad7314_chip_info *chip = iio_priv(dev_info); if (chip->mode) return sprintf(buf, "power-save\n"); @@ -101,7 +100,7 @@ static ssize_t ad7314_store_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7314_chip_info *chip = dev_info->dev_data; + struct ad7314_chip_info *chip = iio_priv(dev_info); u16 mode = 0; int ret; @@ -136,7 +135,7 @@ static ssize_t ad7314_show_temperature(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7314_chip_info *chip = dev_info->dev_data; + struct ad7314_chip_info *chip = iio_priv(dev_info); u16 data; char sign = ' '; int ret; @@ -202,54 +201,45 @@ static const struct iio_info ad7314_info = { static int __devinit ad7314_probe(struct spi_device *spi_dev) { struct ad7314_chip_info *chip; + struct iio_dev *indio_dev; int ret = 0; - chip = kzalloc(sizeof(struct ad7314_chip_info), GFP_KERNEL); - - if (chip == NULL) - return -ENOMEM; - + 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 */ dev_set_drvdata(&spi_dev->dev, chip); chip->spi_dev = spi_dev; - chip->indio_dev = iio_allocate_device(0); - if (chip->indio_dev == NULL) { - ret = -ENOMEM; - goto error_free_chip; - } + indio_dev->name = spi_get_device_id(spi_dev)->name; + indio_dev->dev.parent = &spi_dev->dev; + indio_dev->info = &ad7314_info; - chip->indio_dev->name = spi_get_device_id(spi_dev)->name; - chip->indio_dev->dev.parent = &spi_dev->dev; - chip->indio_dev->info = &ad7314_info; - chip->indio_dev->dev_data = (void *)chip; - - ret = iio_device_register(chip->indio_dev); + ret = iio_device_register(indio_dev); if (ret) goto error_free_dev; dev_info(&spi_dev->dev, "%s temperature sensor registered.\n", - chip->indio_dev->name); + indio_dev->name); return 0; error_free_dev: - iio_free_device(chip->indio_dev); -error_free_chip: - kfree(chip); - + iio_free_device(indio_dev); +error_ret: return ret; } static int __devexit ad7314_remove(struct spi_device *spi_dev) { - struct ad7314_chip_info *chip = dev_get_drvdata(&spi_dev->dev); - struct iio_dev *indio_dev = chip->indio_dev; + struct iio_dev *indio_dev = dev_get_drvdata(&spi_dev->dev); dev_set_drvdata(&spi_dev->dev, NULL); iio_device_unregister(indio_dev); - iio_free_device(chip->indio_dev); - kfree(chip); + iio_free_device(indio_dev); return 0; } diff --git a/drivers/staging/iio/adc/ad7476.h b/drivers/staging/iio/adc/ad7476.h index 01a70211f4ff..0d44976e846f 100644 --- a/drivers/staging/iio/adc/ad7476.h +++ b/drivers/staging/iio/adc/ad7476.h @@ -24,7 +24,6 @@ struct ad7476_chip_info { }; struct ad7476_state { - struct iio_dev *indio_dev; struct spi_device *spi; const struct ad7476_chip_info *chip_info; struct regulator *reg; @@ -51,11 +50,11 @@ enum ad7476_supported_device_ids { }; #ifdef CONFIG_IIO_RING_BUFFER -int ad7476_scan_from_ring(struct ad7476_state *st); +int ad7476_scan_from_ring(struct iio_dev *indio_dev); int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev); void ad7476_ring_cleanup(struct iio_dev *indio_dev); #else /* CONFIG_IIO_RING_BUFFER */ -static inline int ad7476_scan_from_ring(struct ad7476_state *st) +static inline int ad7476_scan_from_ring(struct iio_dev *indio_dev) { return 0; } diff --git a/drivers/staging/iio/adc/ad7476_core.c b/drivers/staging/iio/adc/ad7476_core.c index 50cedb422839..c21089894d28 100644 --- a/drivers/staging/iio/adc/ad7476_core.c +++ b/drivers/staging/iio/adc/ad7476_core.c @@ -39,14 +39,14 @@ static int ad7476_read_raw(struct iio_dev *dev_info, long m) { int ret; - struct ad7476_state *st = dev_info->dev_data; + struct ad7476_state *st = iio_priv(dev_info); unsigned int scale_uv; switch (m) { case 0: mutex_lock(&dev_info->mlock); if (iio_ring_enabled(dev_info)) - ret = ad7476_scan_from_ring(st); + ret = ad7476_scan_from_ring(dev_info); else ret = ad7476_scan_direct(st); mutex_unlock(&dev_info->mlock); @@ -127,23 +127,26 @@ static int __devinit ad7476_probe(struct spi_device *spi) { struct ad7476_platform_data *pdata = spi->dev.platform_data; struct ad7476_state *st; + struct iio_dev *indio_dev; int ret, voltage_uv = 0; + bool reg_done = false; + struct regulator *reg; - st = kzalloc(sizeof(*st), GFP_KERNEL); - if (st == NULL) { + indio_dev = iio_allocate_device(sizeof(*st)); + if (indio_dev == NULL) { ret = -ENOMEM; goto error_ret; } - - st->reg = regulator_get(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); + st = iio_priv(indio_dev); + reg = regulator_get(&spi->dev, "vcc"); + if (!IS_ERR(reg)) { + ret = regulator_enable(reg); if (ret) goto error_put_reg; - voltage_uv = regulator_get_voltage(st->reg); + voltage_uv = regulator_get_voltage(reg); } - + st->reg = reg; st->chip_info = &ad7476_chip_info_tbl[spi_get_device_id(spi)->driver_data]; @@ -156,24 +159,17 @@ static int __devinit ad7476_probe(struct spi_device *spi) else dev_warn(&spi->dev, "reference voltage unspecified\n"); - spi_set_drvdata(spi, st); + spi_set_drvdata(spi, indio_dev); st->spi = spi; - st->indio_dev = iio_allocate_device(0); - if (st->indio_dev == NULL) { - ret = -ENOMEM; - goto error_disable_reg; - } - /* Establish that the iio_dev is a child of the spi device */ - st->indio_dev->dev.parent = &spi->dev; - st->indio_dev->name = spi_get_device_id(spi)->name; - st->indio_dev->dev_data = (void *)(st); - st->indio_dev->modes = INDIO_DIRECT_MODE; - st->indio_dev->channels = st->chip_info->channel; - st->indio_dev->num_channels = 2; - st->indio_dev->info = &ad7476_info; + indio_dev->dev.parent = &spi->dev; + indio_dev->name = spi_get_device_id(spi)->name; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = st->chip_info->channel; + indio_dev->num_channels = 2; + indio_dev->info = &ad7476_info; /* Setup default message */ st->xfer.rx_buf = &st->data; @@ -182,15 +178,15 @@ static int __devinit ad7476_probe(struct spi_device *spi) spi_message_init(&st->msg); spi_message_add_tail(&st->xfer, &st->msg); - ret = ad7476_register_ring_funcs_and_init(st->indio_dev); + ret = ad7476_register_ring_funcs_and_init(indio_dev); if (ret) - goto error_free_device; + goto error_disable_reg; - ret = iio_device_register(st->indio_dev); + ret = iio_device_register(indio_dev); if (ret) - goto error_free_device; + goto error_disable_reg; - ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0, + ret = iio_ring_buffer_register_ex(indio_dev->ring, 0, st->chip_info->channel, ARRAY_SIZE(st->chip_info->channel)); if (ret) @@ -198,33 +194,35 @@ static int __devinit ad7476_probe(struct spi_device *spi) return 0; error_cleanup_ring: - ad7476_ring_cleanup(st->indio_dev); - iio_device_unregister(st->indio_dev); -error_free_device: - iio_free_device(st->indio_dev); + ad7476_ring_cleanup(indio_dev); + iio_device_unregister(indio_dev); error_disable_reg: - if (!IS_ERR(st->reg)) + if (!IS_ERR(reg)) regulator_disable(st->reg); error_put_reg: - if (!IS_ERR(st->reg)) - regulator_put(st->reg); - kfree(st); + if (!IS_ERR(reg)) + regulator_put(reg); + if (!reg_done) + iio_free_device(indio_dev); error_ret: return ret; } static int ad7476_remove(struct spi_device *spi) { - struct ad7476_state *st = spi_get_drvdata(spi); - struct iio_dev *indio_dev = st->indio_dev; + struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct ad7476_state *st = iio_priv(indio_dev); + /* copy needed as st will have been freed */ + struct regulator *reg = st->reg; + iio_ring_buffer_unregister(indio_dev->ring); ad7476_ring_cleanup(indio_dev); iio_device_unregister(indio_dev); - if (!IS_ERR(st->reg)) { - regulator_disable(st->reg); - regulator_put(st->reg); + if (!IS_ERR(reg)) { + regulator_disable(reg); + regulator_put(reg); } - kfree(st); + return 0; } diff --git a/drivers/staging/iio/adc/ad7476_ring.c b/drivers/staging/iio/adc/ad7476_ring.c index b1b2ee2c56b0..a92fc5a1a604 100644 --- a/drivers/staging/iio/adc/ad7476_ring.c +++ b/drivers/staging/iio/adc/ad7476_ring.c @@ -22,9 +22,9 @@ #include "ad7476.h" -int ad7476_scan_from_ring(struct ad7476_state *st) +int ad7476_scan_from_ring(struct iio_dev *indio_dev) { - struct iio_ring_buffer *ring = st->indio_dev->ring; + struct iio_ring_buffer *ring = indio_dev->ring; int ret; u8 *ring_data; @@ -55,7 +55,7 @@ error_ret: **/ static int ad7476_ring_preenable(struct iio_dev *indio_dev) { - struct ad7476_state *st = indio_dev->dev_data; + struct ad7476_state *st = iio_priv(indio_dev); struct iio_ring_buffer *ring = indio_dev->ring; st->d_size = ring->scan_count * @@ -79,7 +79,7 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->private_data; - struct ad7476_state *st = iio_dev_get_devdata(indio_dev); + struct ad7476_state *st = iio_priv(indio_dev); s64 time_ns; __u8 *rxbuf; int b_sent; @@ -115,7 +115,7 @@ static const struct iio_ring_setup_ops ad7476_ring_setup_ops = { int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev) { - struct ad7476_state *st = indio_dev->dev_data; + struct ad7476_state *st = iio_priv(indio_dev); int ret = 0; indio_dev->ring = iio_sw_rb_allocate(indio_dev); diff --git a/drivers/staging/iio/adc/ad7745.c b/drivers/staging/iio/adc/ad7745.c index 1944223ef163..4c13f26aa9ae 100644 --- a/drivers/staging/iio/adc/ad7745.c +++ b/drivers/staging/iio/adc/ad7745.c @@ -54,7 +54,6 @@ struct ad774x_chip_info { struct i2c_client *client; - struct iio_dev *indio_dev; bool inter; u16 cap_offs; /* Capacitive offset */ u16 cap_gain; /* Capacitive gain calibration */ @@ -169,7 +168,7 @@ static ssize_t ad774x_show_conversion_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%s\n", chip->conversion_mode); } @@ -180,7 +179,7 @@ static ssize_t ad774x_store_conversion_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); u8 cfg; int i; @@ -210,7 +209,7 @@ static ssize_t ad774x_show_dac_value(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); u8 data; @@ -225,7 +224,7 @@ static ssize_t ad774x_store_dac_value(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); unsigned long data; int ret; @@ -256,7 +255,7 @@ static ssize_t ad774x_show_cap_setup(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "0x%02x\n", chip->cap_setup); } @@ -267,7 +266,7 @@ static ssize_t ad774x_store_cap_setup(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -291,7 +290,7 @@ static ssize_t ad774x_show_vt_setup(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "0x%02x\n", chip->vt_setup); } @@ -302,7 +301,7 @@ static ssize_t ad774x_store_vt_setup(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -326,7 +325,7 @@ static ssize_t ad774x_show_exec_setup(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "0x%02x\n", chip->exec_setup); } @@ -337,7 +336,7 @@ static ssize_t ad774x_store_exec_setup(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -361,7 +360,7 @@ static ssize_t ad774x_show_volt_gain(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", chip->volt_gain); } @@ -372,7 +371,7 @@ static ssize_t ad774x_store_volt_gain(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -397,7 +396,7 @@ static ssize_t ad774x_show_cap_data(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); unsigned long data; char tmp[3]; @@ -414,7 +413,7 @@ static ssize_t ad774x_show_vt_data(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); unsigned long data; char tmp[3]; @@ -431,7 +430,7 @@ static ssize_t ad774x_show_cap_offs(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", chip->cap_offs); } @@ -442,7 +441,7 @@ static ssize_t ad774x_store_cap_offs(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -467,7 +466,7 @@ static ssize_t ad774x_show_cap_gain(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", chip->cap_gain); } @@ -478,7 +477,7 @@ static ssize_t ad774x_store_cap_gain(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad774x_chip_info *chip = dev_info->dev_data; + struct ad774x_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -534,7 +533,7 @@ static const struct attribute_group ad774x_attribute_group = { static irqreturn_t ad774x_event_handler(int irq, void *private) { struct iio_dev *indio_dev = private; - struct ad774x_chip_info *chip = iio_dev_get_devdata(indio_dev); + struct ad774x_chip_info *chip = iio_priv(indio_dev); u8 int_status; ad774x_i2c_read(chip, AD774X_STATUS, &int_status, 1); @@ -579,31 +578,27 @@ static int __devinit ad774x_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = 0, regdone = 0; - struct ad774x_chip_info *chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { + struct ad774x_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; - chip->indio_dev->info = &ad774x_info; - chip->indio_dev->dev_data = (void *)(chip); - chip->indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->name = id->name; + indio_dev->dev.parent = &client->dev; + indio_dev->info = &ad774x_info; + 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; @@ -614,7 +609,7 @@ static int __devinit ad774x_probe(struct i2c_client *client, &ad774x_event_handler, IRQF_TRIGGER_FALLING, "ad774x", - chip->indio_dev); + indio_dev); if (ret) goto error_free_dev; } @@ -625,24 +620,20 @@ static int __devinit ad774x_probe(struct i2c_client *client, error_free_dev: if (regdone) - free_irq(client->irq, chip->indio_dev); + free_irq(client->irq, 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 ad774x_remove(struct i2c_client *client) { - struct ad774x_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; } diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c new file mode 100644 index 000000000000..90f6c039d6c6 --- /dev/null +++ b/drivers/staging/iio/adc/ad7793.c @@ -0,0 +1,987 @@ +/* + * AD7792/AD7793 SPI ADC driver + * + * Copyright 2011 Analog Devices Inc. + * + * Licensed under the GPL-2. + */ + +#include <linux/interrupt.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/spi/spi.h> +#include <linux/regulator/consumer.h> +#include <linux/err.h> +#include <linux/sched.h> +#include <linux/delay.h> + +#include "../iio.h" +#include "../sysfs.h" +#include "../ring_generic.h" +#include "../ring_sw.h" +#include "../trigger.h" +#include "adc.h" + +#include "ad7793.h" + +/* NOTE: + * The AD7792/AD7793 features a dual use data out ready DOUT/RDY output. + * In order to avoid contentions on the SPI bus, it's therefore necessary + * to use spi bus locking. + * + * The DOUT/RDY output must also be wired to an interrupt capable GPIO. + */ + +struct ad7793_chip_info { + struct iio_chan_spec channel[7]; +}; + +struct ad7793_state { + struct spi_device *spi; + struct iio_trigger *trig; + const struct ad7793_chip_info *chip_info; + struct regulator *reg; + struct ad7793_platform_data *pdata; + wait_queue_head_t wq_data_avail; + bool done; + bool irq_dis; + u16 int_vref_mv; + u16 mode; + u16 conf; + u32 scale_avail[8][2]; + u32 available_scan_masks[7]; + /* + * DMA (thus cache coherency maintenance) requires the + * transfer buffers to live in their own cache lines. + */ + u8 data[4] ____cacheline_aligned; +}; + +enum ad7793_supported_device_ids { + ID_AD7792, + ID_AD7793, +}; + +static int __ad7793_write_reg(struct ad7793_state *st, bool locked, + bool cs_change, unsigned char reg, + unsigned size, unsigned val) +{ + u8 *data = st->data; + struct spi_transfer t = { + .tx_buf = data, + .len = size + 1, + .cs_change = cs_change, + }; + struct spi_message m; + + data[0] = AD7793_COMM_WRITE | AD7793_COMM_ADDR(reg); + + switch (size) { + case 3: + data[1] = val >> 16; + data[2] = val >> 8; + data[3] = val; + break; + case 2: + data[1] = val >> 8; + data[2] = val; + break; + case 1: + data[1] = val; + break; + default: + return -EINVAL; + } + + spi_message_init(&m); + spi_message_add_tail(&t, &m); + + if (locked) + return spi_sync_locked(st->spi, &m); + else + return spi_sync(st->spi, &m); +} + +static int ad7793_write_reg(struct ad7793_state *st, + unsigned reg, unsigned size, unsigned val) +{ + return __ad7793_write_reg(st, false, false, reg, size, val); +} + +static int __ad7793_read_reg(struct ad7793_state *st, bool locked, + bool cs_change, unsigned char reg, + int *val, unsigned size) +{ + u8 *data = st->data; + int ret; + struct spi_transfer t[] = { + { + .tx_buf = data, + .len = 1, + }, { + .rx_buf = data, + .len = size, + .cs_change = cs_change, + }, + }; + struct spi_message m; + + data[0] = AD7793_COMM_READ | AD7793_COMM_ADDR(reg); + + spi_message_init(&m); + spi_message_add_tail(&t[0], &m); + spi_message_add_tail(&t[1], &m); + + if (locked) + ret = spi_sync_locked(st->spi, &m); + else + ret = spi_sync(st->spi, &m); + + if (ret < 0) + return ret; + + switch (size) { + case 3: + *val = data[0] << 16 | data[1] << 8 | data[2]; + break; + case 2: + *val = data[0] << 8 | data[1]; + break; + case 1: + *val = data[0]; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int ad7793_read_reg(struct ad7793_state *st, + unsigned reg, int *val, unsigned size) +{ + return __ad7793_read_reg(st, 0, 0, reg, val, size); +} + +static int ad7793_read(struct ad7793_state *st, unsigned ch, + unsigned len, int *val) +{ + int ret; + st->conf = (st->conf & ~AD7793_CONF_CHAN(-1)) | AD7793_CONF_CHAN(ch); + st->mode = (st->mode & ~AD7793_MODE_SEL(-1)) | + AD7793_MODE_SEL(AD7793_MODE_SINGLE); + + ad7793_write_reg(st, AD7793_REG_CONF, sizeof(st->conf), st->conf); + + spi_bus_lock(st->spi->master); + st->done = false; + + ret = __ad7793_write_reg(st, 1, 1, AD7793_REG_MODE, + sizeof(st->mode), st->mode); + if (ret < 0) + goto out; + + st->irq_dis = false; + enable_irq(st->spi->irq); + wait_event_interruptible(st->wq_data_avail, st->done); + + ret = __ad7793_read_reg(st, 1, 0, AD7793_REG_DATA, val, len); +out: + spi_bus_unlock(st->spi->master); + + return ret; +} + +static int ad7793_calibrate(struct ad7793_state *st, unsigned mode, unsigned ch) +{ + int ret; + + st->conf = (st->conf & ~AD7793_CONF_CHAN(-1)) | AD7793_CONF_CHAN(ch); + st->mode = (st->mode & ~AD7793_MODE_SEL(-1)) | AD7793_MODE_SEL(mode); + + ad7793_write_reg(st, AD7793_REG_CONF, sizeof(st->conf), st->conf); + + spi_bus_lock(st->spi->master); + st->done = false; + + ret = __ad7793_write_reg(st, 1, 1, AD7793_REG_MODE, + sizeof(st->mode), st->mode); + if (ret < 0) + goto out; + + st->irq_dis = false; + enable_irq(st->spi->irq); + wait_event_interruptible(st->wq_data_avail, st->done); + + st->mode = (st->mode & ~AD7793_MODE_SEL(-1)) | + AD7793_MODE_SEL(AD7793_MODE_IDLE); + + ret = __ad7793_write_reg(st, 1, 0, AD7793_REG_MODE, + sizeof(st->mode), st->mode); +out: + spi_bus_unlock(st->spi->master); + + return ret; +} + +static const u8 ad7793_calib_arr[6][2] = { + {AD7793_MODE_CAL_INT_ZERO, AD7793_CH_AIN1P_AIN1M}, + {AD7793_MODE_CAL_INT_FULL, AD7793_CH_AIN1P_AIN1M}, + {AD7793_MODE_CAL_INT_ZERO, AD7793_CH_AIN2P_AIN2M}, + {AD7793_MODE_CAL_INT_FULL, AD7793_CH_AIN2P_AIN2M}, + {AD7793_MODE_CAL_INT_ZERO, AD7793_CH_AIN3P_AIN3M}, + {AD7793_MODE_CAL_INT_FULL, AD7793_CH_AIN3P_AIN3M} +}; + +static int ad7793_calibrate_all(struct ad7793_state *st) +{ + int i, ret; + + for (i = 0; i < ARRAY_SIZE(ad7793_calib_arr); i++) { + ret = ad7793_calibrate(st, ad7793_calib_arr[i][0], + ad7793_calib_arr[i][1]); + if (ret) + goto out; + } + + return 0; +out: + dev_err(&st->spi->dev, "Calibration failed\n"); + return ret; +} + +static int ad7793_setup(struct ad7793_state *st) +{ + int i, ret = -1; + unsigned long long scale_uv; + u32 id; + + /* reset the serial interface */ + ret = spi_write(st->spi, (u8 *)&ret, sizeof(ret)); + if (ret < 0) + goto out; + msleep(1); /* Wait for at least 500us */ + + /* write/read test for device presence */ + ret = ad7793_read_reg(st, AD7793_REG_ID, &id, 1); + if (ret) + goto out; + + id &= AD7793_ID_MASK; + + if (!((id == AD7792_ID) || (id == AD7793_ID))) { + dev_err(&st->spi->dev, "device ID query failed\n"); + goto out; + } + + st->mode = (st->pdata->mode & ~AD7793_MODE_SEL(-1)) | + AD7793_MODE_SEL(AD7793_MODE_IDLE); + st->conf = st->pdata->conf & ~AD7793_CONF_CHAN(-1); + + ret = ad7793_write_reg(st, AD7793_REG_MODE, sizeof(st->mode), st->mode); + if (ret) + goto out; + + ret = ad7793_write_reg(st, AD7793_REG_CONF, sizeof(st->conf), st->conf); + if (ret) + goto out; + + ret = ad7793_write_reg(st, AD7793_REG_IO, + sizeof(st->pdata->io), st->pdata->io); + if (ret) + goto out; + + ret = ad7793_calibrate_all(st); + if (ret) + goto out; + + /* Populate available ADC input ranges */ + for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) { + scale_uv = ((u64)st->int_vref_mv * 100000000) + >> (st->chip_info->channel[0].scan_type.realbits - + (!!(st->conf & AD7793_CONF_UNIPOLAR) ? 0 : 1)); + scale_uv >>= i; + + st->scale_avail[i][1] = do_div(scale_uv, 100000000) * 10; + st->scale_avail[i][0] = scale_uv; + } + + return 0; +out: + dev_err(&st->spi->dev, "setup failed\n"); + return ret; +} + +static int ad7793_scan_from_ring(struct ad7793_state *st, unsigned ch, int *val) +{ + struct iio_ring_buffer *ring = iio_priv_to_dev(st)->ring; + int ret; + s64 dat64[2]; + u32 *dat32 = (u32 *)dat64; + + if (!(ring->scan_mask & (1 << ch))) + return -EBUSY; + + ret = ring->access->read_last(ring, (u8 *) &dat64); + if (ret) + return ret; + + *val = *dat32; + + return 0; +} + +static int ad7793_ring_preenable(struct iio_dev *indio_dev) +{ + struct ad7793_state *st = iio_priv(indio_dev); + struct iio_ring_buffer *ring = indio_dev->ring; + size_t d_size; + unsigned channel; + + if (!ring->scan_count) + return -EINVAL; + + channel = __ffs(ring->scan_mask); + + d_size = ring->scan_count * + indio_dev->channels[0].scan_type.storagebits / 8; + + if (ring->scan_timestamp) { + d_size += sizeof(s64); + + if (d_size % sizeof(s64)) + d_size += sizeof(s64) - (d_size % sizeof(s64)); + } + + if (indio_dev->ring->access->set_bytes_per_datum) + indio_dev->ring->access->set_bytes_per_datum(indio_dev->ring, + d_size); + + st->mode = (st->mode & ~AD7793_MODE_SEL(-1)) | + AD7793_MODE_SEL(AD7793_MODE_CONT); + st->conf = (st->conf & ~AD7793_CONF_CHAN(-1)) | + AD7793_CONF_CHAN(indio_dev->channels[channel].address); + + ad7793_write_reg(st, AD7793_REG_CONF, sizeof(st->conf), st->conf); + + spi_bus_lock(st->spi->master); + __ad7793_write_reg(st, 1, 1, AD7793_REG_MODE, + sizeof(st->mode), st->mode); + + st->irq_dis = false; + enable_irq(st->spi->irq); + + return 0; +} + +static int ad7793_ring_postdisable(struct iio_dev *indio_dev) +{ + struct ad7793_state *st = iio_priv(indio_dev); + + st->mode = (st->mode & ~AD7793_MODE_SEL(-1)) | + AD7793_MODE_SEL(AD7793_MODE_IDLE); + + st->done = false; + wait_event_interruptible(st->wq_data_avail, st->done); + + if (!st->irq_dis) + disable_irq_nosync(st->spi->irq); + + __ad7793_write_reg(st, 1, 0, AD7793_REG_MODE, + sizeof(st->mode), st->mode); + + return spi_bus_unlock(st->spi->master); +} + +/** + * ad7793_trigger_handler() bh of trigger launched polling to ring buffer + **/ + +static irqreturn_t ad7793_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->private_data; + struct iio_ring_buffer *ring = indio_dev->ring; + struct ad7793_state *st = iio_priv(indio_dev); + s64 dat64[2]; + s32 *dat32 = (s32 *)dat64; + + if (ring->scan_count) + __ad7793_read_reg(st, 1, 1, AD7793_REG_DATA, + dat32, + indio_dev->channels[0].scan_type.realbits/8); + + /* Guaranteed to be aligned with 8 byte boundary */ + if (ring->scan_timestamp) + dat64[1] = pf->timestamp; + + ring->access->store_to(ring, (u8 *)dat64, pf->timestamp); + + iio_trigger_notify_done(indio_dev->trig); + st->irq_dis = false; + enable_irq(st->spi->irq); + + return IRQ_HANDLED; +} + +static const struct iio_ring_setup_ops ad7793_ring_setup_ops = { + .preenable = &ad7793_ring_preenable, + .postenable = &iio_triggered_ring_postenable, + .predisable = &iio_triggered_ring_predisable, + .postdisable = &ad7793_ring_postdisable, +}; + +static int ad7793_register_ring_funcs_and_init(struct iio_dev *indio_dev) +{ + int ret; + + indio_dev->ring = iio_sw_rb_allocate(indio_dev); + if (!indio_dev->ring) { + ret = -ENOMEM; + goto error_ret; + } + /* Effectively select the ring buffer implementation */ + indio_dev->ring->access = &ring_sw_access_funcs; + indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time, + &ad7793_trigger_handler, + IRQF_ONESHOT, + indio_dev, + "ad7793_consumer%d", + indio_dev->id); + if (indio_dev->pollfunc == NULL) { + ret = -ENOMEM; + goto error_deallocate_sw_rb; + } + + /* Ring buffer functions - here trigger setup related */ + indio_dev->ring->setup_ops = &ad7793_ring_setup_ops; + + /* Flag that polled ring buffering is possible */ + indio_dev->modes |= INDIO_RING_TRIGGERED; + return 0; + +error_deallocate_sw_rb: + iio_sw_rb_free(indio_dev->ring); +error_ret: + return ret; +} + +static void ad7793_ring_cleanup(struct iio_dev *indio_dev) +{ + /* ensure that the trigger has been detached */ + if (indio_dev->trig) { + iio_put_trigger(indio_dev->trig); + iio_trigger_dettach_poll_func(indio_dev->trig, + indio_dev->pollfunc); + } + iio_dealloc_pollfunc(indio_dev->pollfunc); + iio_sw_rb_free(indio_dev->ring); +} + +/** + * ad7793_data_rdy_trig_poll() the event handler for the data rdy trig + **/ +static irqreturn_t ad7793_data_rdy_trig_poll(int irq, void *private) +{ + struct ad7793_state *st = iio_priv(private); + + st->done = true; + wake_up_interruptible(&st->wq_data_avail); + disable_irq_nosync(irq); + st->irq_dis = true; + iio_trigger_poll(st->trig, iio_get_time_ns()); + + return IRQ_HANDLED; +} + +static int ad7793_probe_trigger(struct iio_dev *indio_dev) +{ + struct ad7793_state *st = iio_priv(indio_dev); + int ret; + + st->trig = iio_allocate_trigger("%s-dev%d", + spi_get_device_id(st->spi)->name, + indio_dev->id); + if (st->trig == NULL) { + ret = -ENOMEM; + goto error_ret; + } + + ret = request_irq(st->spi->irq, + ad7793_data_rdy_trig_poll, + IRQF_TRIGGER_LOW, + spi_get_device_id(st->spi)->name, + indio_dev); + if (ret) + goto error_free_trig; + + disable_irq_nosync(st->spi->irq); + st->irq_dis = true; + st->trig->dev.parent = &st->spi->dev; + st->trig->owner = THIS_MODULE; + st->trig->private_data = indio_dev; + + ret = iio_trigger_register(st->trig); + + /* select default trigger */ + indio_dev->trig = st->trig; + if (ret) + goto error_free_irq; + + return 0; + +error_free_irq: + free_irq(st->spi->irq, indio_dev); +error_free_trig: + iio_free_trigger(st->trig); +error_ret: + return ret; +} + +static void ad7793_remove_trigger(struct iio_dev *indio_dev) +{ + struct ad7793_state *st = iio_priv(indio_dev); + + iio_trigger_unregister(st->trig); + free_irq(st->spi->irq, indio_dev); + iio_free_trigger(st->trig); +} + +static const u16 sample_freq_avail[16] = {0, 470, 242, 123, 62, 50, 39, 33, 19, + 17, 16, 12, 10, 8, 6, 4}; + +static ssize_t ad7793_read_frequency(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct ad7793_state *st = iio_priv(indio_dev); + + return sprintf(buf, "%d\n", + sample_freq_avail[AD7793_MODE_RATE(st->mode)]); +} + +static ssize_t ad7793_write_frequency(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct ad7793_state *st = iio_priv(indio_dev); + long lval; + int i, ret; + + mutex_lock(&indio_dev->mlock); + if (iio_ring_enabled(indio_dev)) { + mutex_unlock(&indio_dev->mlock); + return -EBUSY; + } + mutex_unlock(&indio_dev->mlock); + + ret = strict_strtol(buf, 10, &lval); + if (ret) + return ret; + + ret = -EINVAL; + + for (i = 0; i < ARRAY_SIZE(sample_freq_avail); i++) + if (lval == sample_freq_avail[i]) { + mutex_lock(&indio_dev->mlock); + st->mode &= ~AD7793_MODE_RATE(-1); + st->mode |= AD7793_MODE_RATE(i); + ad7793_write_reg(st, AD7793_REG_MODE, + sizeof(st->mode), st->mode); + mutex_unlock(&indio_dev->mlock); + ret = 0; + } + + return ret ? ret : len; +} + +static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, + ad7793_read_frequency, + ad7793_write_frequency); + +static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( + "470 242 123 62 50 39 33 19 17 16 12 10 8 6 4"); + +static ssize_t ad7793_show_scale_available(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct ad7793_state *st = iio_priv(indio_dev); + int i, len = 0; + + for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) + len += sprintf(buf + len, "%d.%09u ", st->scale_avail[i][0], + st->scale_avail[i][1]); + + len += sprintf(buf + len, "\n"); + + return len; +} + +static IIO_DEVICE_ATTR_NAMED(in_m_in_scale_available, in-in_scale_available, + S_IRUGO, ad7793_show_scale_available, NULL, 0); + +static struct attribute *ad7793_attributes[] = { + &iio_dev_attr_sampling_frequency.dev_attr.attr, + &iio_const_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_in_m_in_scale_available.dev_attr.attr, + NULL +}; + +static const struct attribute_group ad7793_attribute_group = { + .attrs = ad7793_attributes, +}; + +static int ad7793_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long m) +{ + struct ad7793_state *st = iio_priv(indio_dev); + int ret, smpl = 0; + unsigned long long scale_uv; + bool unipolar = !!(st->conf & AD7793_CONF_UNIPOLAR); + + switch (m) { + case 0: + mutex_lock(&indio_dev->mlock); + if (iio_ring_enabled(indio_dev)) + ret = ad7793_scan_from_ring(st, + chan->scan_index, &smpl); + else + ret = ad7793_read(st, chan->address, + chan->scan_type.realbits / 8, &smpl); + mutex_unlock(&indio_dev->mlock); + + if (ret < 0) + return ret; + + *val = (smpl >> chan->scan_type.shift) & + ((1 << (chan->scan_type.realbits)) - 1); + + if (!unipolar) + *val -= (1 << (chan->scan_type.realbits - 1)); + + return IIO_VAL_INT; + + case (1 << IIO_CHAN_INFO_SCALE_SHARED): + *val = st->scale_avail[(st->conf >> 8) & 0x7][0]; + *val2 = st->scale_avail[(st->conf >> 8) & 0x7][1]; + + return IIO_VAL_INT_PLUS_NANO; + + case (1 << IIO_CHAN_INFO_SCALE_SEPARATE): + switch (chan->type) { + case IIO_IN: + /* 1170mV / 2^23 * 6 */ + scale_uv = (1170ULL * 100000000ULL * 6ULL) + >> (chan->scan_type.realbits - + (unipolar ? 0 : 1)); + break; + case IIO_TEMP: + /* Always uses unity gain and internal ref */ + scale_uv = (2500ULL * 100000000ULL) + >> (chan->scan_type.realbits - + (unipolar ? 0 : 1)); + break; + default: + return -EINVAL; + } + + *val2 = do_div(scale_uv, 100000000) * 10; + *val = scale_uv; + + return IIO_VAL_INT_PLUS_NANO; + } + return -EINVAL; +} + +static int ad7793_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, + int val2, + long mask) +{ + struct ad7793_state *st = iio_priv(indio_dev); + int ret, i; + unsigned int tmp; + + mutex_lock(&indio_dev->mlock); + if (iio_ring_enabled(indio_dev)) { + mutex_unlock(&indio_dev->mlock); + return -EBUSY; + } + + switch (mask) { + case (1 << IIO_CHAN_INFO_SCALE_SHARED): + ret = -EINVAL; + for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) + if (val2 == st->scale_avail[i][1]) { + tmp = st->conf; + st->conf &= ~AD7793_CONF_GAIN(-1); + st->conf |= AD7793_CONF_GAIN(i); + + if (tmp != st->conf) { + ad7793_write_reg(st, AD7793_REG_CONF, + sizeof(st->conf), + st->conf); + ad7793_calibrate_all(st); + } + ret = 0; + } + + default: + ret = -EINVAL; + } + + mutex_unlock(&indio_dev->mlock); + return ret; +} + +static int ad7793_validate_trigger(struct iio_dev *indio_dev, + struct iio_trigger *trig) +{ + if (indio_dev->trig != trig) + return -EINVAL; + + return 0; +} + +static int ad7793_write_raw_get_fmt(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + long mask) +{ + return IIO_VAL_INT_PLUS_NANO; +} + +static const struct iio_info ad7793_info = { + .read_raw = &ad7793_read_raw, + .write_raw = &ad7793_write_raw, + .write_raw_get_fmt = &ad7793_write_raw_get_fmt, + .attrs = &ad7793_attribute_group, + .validate_trigger = ad7793_validate_trigger, + .driver_module = THIS_MODULE, +}; + +static const struct ad7793_chip_info ad7793_chip_info_tbl[] = { + [ID_AD7793] = { + .channel[0] = IIO_CHAN(IIO_IN_DIFF, 0, 1, 0, NULL, 0, 0, + (1 << IIO_CHAN_INFO_SCALE_SHARED), + AD7793_CH_AIN1P_AIN1M, + 0, IIO_ST('s', 24, 32, 0), 0), + .channel[1] = IIO_CHAN(IIO_IN_DIFF, 0, 1, 0, NULL, 1, 1, + (1 << IIO_CHAN_INFO_SCALE_SHARED), + AD7793_CH_AIN2P_AIN2M, + 1, IIO_ST('s', 24, 32, 0), 0), + .channel[2] = IIO_CHAN(IIO_IN_DIFF, 0, 1, 0, NULL, 2, 2, + (1 << IIO_CHAN_INFO_SCALE_SHARED), + AD7793_CH_AIN3P_AIN3M, + 2, IIO_ST('s', 24, 32, 0), 0), + .channel[3] = IIO_CHAN(IIO_IN_DIFF, 0, 1, 0, "shorted", 0, 0, + (1 << IIO_CHAN_INFO_SCALE_SHARED), + AD7793_CH_AIN1M_AIN1M, + 3, IIO_ST('s', 24, 32, 0), 0), + .channel[4] = IIO_CHAN(IIO_TEMP, 0, 1, 0, NULL, 0, 0, + (1 << IIO_CHAN_INFO_SCALE_SEPARATE), + AD7793_CH_TEMP, + 4, IIO_ST('s', 24, 32, 0), 0), + .channel[5] = IIO_CHAN(IIO_IN, 0, 1, 0, "supply", 4, 0, + (1 << IIO_CHAN_INFO_SCALE_SEPARATE), + AD7793_CH_AVDD_MONITOR, + 5, IIO_ST('s', 24, 32, 0), 0), + .channel[6] = IIO_CHAN_SOFT_TIMESTAMP(6), + }, + [ID_AD7792] = { + .channel[0] = IIO_CHAN(IIO_IN_DIFF, 0, 1, 0, NULL, 0, 0, + (1 << IIO_CHAN_INFO_SCALE_SHARED), + AD7793_CH_AIN1P_AIN1M, + 0, IIO_ST('s', 16, 32, 0), 0), + .channel[1] = IIO_CHAN(IIO_IN_DIFF, 0, 1, 0, NULL, 1, 1, + (1 << IIO_CHAN_INFO_SCALE_SHARED), + AD7793_CH_AIN2P_AIN2M, + 1, IIO_ST('s', 16, 32, 0), 0), + .channel[2] = IIO_CHAN(IIO_IN_DIFF, 0, 1, 0, NULL, 2, 2, + (1 << IIO_CHAN_INFO_SCALE_SHARED), + AD7793_CH_AIN3P_AIN3M, + 2, IIO_ST('s', 16, 32, 0), 0), + .channel[3] = IIO_CHAN(IIO_IN_DIFF, 0, 1, 0, "shorted", 0, 0, + (1 << IIO_CHAN_INFO_SCALE_SHARED), + AD7793_CH_AIN1M_AIN1M, + 3, IIO_ST('s', 16, 32, 0), 0), + .channel[4] = IIO_CHAN(IIO_TEMP, 0, 1, 0, NULL, 0, 0, + (1 << IIO_CHAN_INFO_SCALE_SEPARATE), + AD7793_CH_TEMP, + 4, IIO_ST('s', 16, 32, 0), 0), + .channel[5] = IIO_CHAN(IIO_IN, 0, 1, 0, "supply", 4, 0, + (1 << IIO_CHAN_INFO_SCALE_SEPARATE), + AD7793_CH_AVDD_MONITOR, + 5, IIO_ST('s', 16, 32, 0), 0), + .channel[6] = IIO_CHAN_SOFT_TIMESTAMP(6), + }, +}; + +static int __devinit ad7793_probe(struct spi_device *spi) +{ + struct ad7793_platform_data *pdata = spi->dev.platform_data; + struct ad7793_state *st; + struct iio_dev *indio_dev; + int ret, i, voltage_uv = 0, regdone = 0; + + if (!pdata) { + dev_err(&spi->dev, "no platform data?\n"); + return -ENODEV; + } + + if (!spi->irq) { + dev_err(&spi->dev, "no IRQ?\n"); + return -ENODEV; + } + + indio_dev = iio_allocate_device(sizeof(*st)); + if (indio_dev == NULL) + return -ENOMEM; + + st = iio_priv(indio_dev); + + st->reg = regulator_get(&spi->dev, "vcc"); + if (!IS_ERR(st->reg)) { + ret = regulator_enable(st->reg); + if (ret) + goto error_put_reg; + + voltage_uv = regulator_get_voltage(st->reg); + } + + st->chip_info = + &ad7793_chip_info_tbl[spi_get_device_id(spi)->driver_data]; + + st->pdata = pdata; + + if (pdata && pdata->vref_mv) + st->int_vref_mv = pdata->vref_mv; + else if (voltage_uv) + st->int_vref_mv = voltage_uv / 1000; + else + st->int_vref_mv = 2500; /* Build-in ref */ + + spi_set_drvdata(spi, indio_dev); + st->spi = spi; + + indio_dev->dev.parent = &spi->dev; + indio_dev->name = spi_get_device_id(spi)->name; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = st->chip_info->channel; + indio_dev->available_scan_masks = st->available_scan_masks; + indio_dev->num_channels = 7; + indio_dev->info = &ad7793_info; + + for (i = 0; i < indio_dev->num_channels; i++) + st->available_scan_masks[i] = (1 << i) | (1 << + indio_dev->channels[indio_dev->num_channels - 1]. + scan_index); + + init_waitqueue_head(&st->wq_data_avail); + + ret = ad7793_register_ring_funcs_and_init(indio_dev); + if (ret) + goto error_disable_reg; + + ret = iio_device_register(indio_dev); + if (ret) + goto error_unreg_ring; + regdone = 1; + + ret = ad7793_probe_trigger(indio_dev); + if (ret) + goto error_unreg_ring; + + ret = iio_ring_buffer_register_ex(indio_dev->ring, 0, + indio_dev->channels, + indio_dev->num_channels); + if (ret) + goto error_remove_trigger; + + ret = ad7793_setup(st); + if (ret) + goto error_uninitialize_ring; + + return 0; + +error_uninitialize_ring: + iio_ring_buffer_unregister(indio_dev->ring); +error_remove_trigger: + ad7793_remove_trigger(indio_dev); +error_unreg_ring: + ad7793_ring_cleanup(indio_dev); +error_disable_reg: + if (!IS_ERR(st->reg)) + regulator_disable(st->reg); +error_put_reg: + if (!IS_ERR(st->reg)) + regulator_put(st->reg); + + if (regdone) + iio_device_unregister(indio_dev); + else + iio_free_device(indio_dev); + + return ret; +} + +static int ad7793_remove(struct spi_device *spi) +{ + struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct ad7793_state *st = iio_priv(indio_dev); + + iio_ring_buffer_unregister(indio_dev->ring); + ad7793_remove_trigger(indio_dev); + ad7793_ring_cleanup(indio_dev); + + if (!IS_ERR(st->reg)) { + regulator_disable(st->reg); + regulator_put(st->reg); + } + + iio_device_unregister(indio_dev); + + return 0; +} + +static const struct spi_device_id ad7793_id[] = { + {"ad7792", ID_AD7792}, + {"ad7793", ID_AD7793}, + {} +}; + +static struct spi_driver ad7793_driver = { + .driver = { + .name = "ad7793", + .bus = &spi_bus_type, + .owner = THIS_MODULE, + }, + .probe = ad7793_probe, + .remove = __devexit_p(ad7793_remove), + .id_table = ad7793_id, +}; + +static int __init ad7793_init(void) +{ + return spi_register_driver(&ad7793_driver); +} +module_init(ad7793_init); + +static void __exit ad7793_exit(void) +{ + spi_unregister_driver(&ad7793_driver); +} +module_exit(ad7793_exit); + +MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); +MODULE_DESCRIPTION("Analog Devices AD7792/3 ADC"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/ad7793.h b/drivers/staging/iio/adc/ad7793.h new file mode 100644 index 000000000000..64f7d41dc453 --- /dev/null +++ b/drivers/staging/iio/adc/ad7793.h @@ -0,0 +1,107 @@ +/* + * AD7792/AD7793 SPI ADC driver + * + * Copyright 2011 Analog Devices Inc. + * + * Licensed under the GPL-2. + */ +#ifndef IIO_ADC_AD7793_H_ +#define IIO_ADC_AD7793_H_ + +/* + * TODO: struct ad7793_platform_data needs to go into include/linux/iio + */ + +/* Registers */ +#define AD7793_REG_COMM 0 /* Communications Register (WO, 8-bit) */ +#define AD7793_REG_STAT 0 /* Status Register (RO, 8-bit) */ +#define AD7793_REG_MODE 1 /* Mode Register (RW, 16-bit */ +#define AD7793_REG_CONF 2 /* Configuration Register (RW, 16-bit) */ +#define AD7793_REG_DATA 3 /* Data Register (RO, 16-/24-bit) */ +#define AD7793_REG_ID 4 /* ID Register (RO, 8-bit) */ +#define AD7793_REG_IO 5 /* IO Register (RO, 8-bit) */ +#define AD7793_REG_OFFSET 6 /* Offset Register (RW, 16-bit + * (AD7792)/24-bit (AD7793)) */ +#define AD7793_REG_FULLSALE 7 /* Full-Scale Register + * (RW, 16-bit (AD7792)/24-bit (AD7793)) */ + +/* Communications Register Bit Designations (AD7793_REG_COMM) */ +#define AD7793_COMM_WEN (1 << 7) /* Write Enable */ +#define AD7793_COMM_WRITE (0 << 6) /* Write Operation */ +#define AD7793_COMM_READ (1 << 6) /* Read Operation */ +#define AD7793_COMM_ADDR(x) (((x) & 0x7) << 3) /* Register Address */ +#define AD7793_COMM_CREAD (1 << 2) /* Continuous Read of Data Register */ + +/* Status Register Bit Designations (AD7793_REG_STAT) */ +#define AD7793_STAT_RDY (1 << 7) /* Ready */ +#define AD7793_STAT_ERR (1 << 6) /* Error (Overrange, Underrange) */ +#define AD7793_STAT_CH3 (1 << 2) /* Channel 3 */ +#define AD7793_STAT_CH2 (1 << 1) /* Channel 2 */ +#define AD7793_STAT_CH1 (1 << 0) /* Channel 1 */ + +/* Mode Register Bit Designations (AD7793_REG_MODE) */ +#define AD7793_MODE_SEL(x) (((x) & 0x7) << 13) /* Operation Mode Select */ +#define AD7793_MODE_CLKSRC(x) (((x) & 0x3) << 6) /* ADC Clock Source Select */ +#define AD7793_MODE_RATE(x) ((x) & 0xF) /* Filter Update Rate Select */ + +#define AD7793_MODE_CONT 0 /* Continuous Conversion Mode */ +#define AD7793_MODE_SINGLE 1 /* Single Conversion Mode */ +#define AD7793_MODE_IDLE 2 /* Idle Mode */ +#define AD7793_MODE_PWRDN 3 /* Power-Down Mode */ +#define AD7793_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */ +#define AD7793_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */ +#define AD7793_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */ +#define AD7793_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */ + +#define AD7793_CLK_INT 0 /* Internal 64 kHz Clock not + * available at the CLK pin */ +#define AD7793_CLK_INT_CO 1 /* Internal 64 kHz Clock available + * at the CLK pin */ +#define AD7793_CLK_EXT 2 /* External 64 kHz Clock */ +#define AD7793_CLK_EXT_DIV2 3 /* External Clock divided by 2 */ + +/* Configuration Register Bit Designations (AD7793_REG_CONF) */ +#define AD7793_CONF_VBIAS(x) (((x) & 0x3) << 14) /* Bias Voltage + * Generator Enable */ +#define AD7793_CONF_BO_EN (1 << 13) /* Burnout Current Enable */ +#define AD7793_CONF_UNIPOLAR (1 << 12) /* Unipolar/Bipolar Enable */ +#define AD7793_CONF_BOOST (1 << 11) /* Boost Enable */ +#define AD7793_CONF_GAIN(x) (((x) & 0x7) << 8) /* Gain Select */ +#define AD7793_CONF_REFSEL (1 << 7) /* INT/EXT Reference Select */ +#define AD7793_CONF_BUF (1 << 4) /* Buffered Mode Enable */ +#define AD7793_CONF_CHAN(x) ((x) & 0x7) /* Channel select */ + +#define AD7793_CH_AIN1P_AIN1M 0 /* AIN1(+) - AIN1(-) */ +#define AD7793_CH_AIN2P_AIN2M 1 /* AIN2(+) - AIN2(-) */ +#define AD7793_CH_AIN3P_AIN3M 2 /* AIN3(+) - AIN3(-) */ +#define AD7793_CH_AIN1M_AIN1M 3 /* AIN1(-) - AIN1(-) */ +#define AD7793_CH_TEMP 6 /* Temp Sensor */ +#define AD7793_CH_AVDD_MONITOR 7 /* AVDD Monitor */ + +/* ID Register Bit Designations (AD7793_REG_ID) */ +#define AD7792_ID 0xA +#define AD7793_ID 0xB +#define AD7793_ID_MASK 0xF + +/* IO (Excitation Current Sources) Register Bit Designations (AD7793_REG_IO) */ +#define AD7793_IO_IEXC1_IOUT1_IEXC2_IOUT2 0 /* IEXC1 connect to IOUT1, + * IEXC2 connect to IOUT2 */ +#define AD7793_IO_IEXC1_IOUT2_IEXC2_IOUT1 1 /* IEXC1 connect to IOUT2, + * IEXC2 connect to IOUT1 */ +#define AD7793_IO_IEXC1_IEXC2_IOUT1 2 /* Both current sources + * IEXC1,2 connect to IOUT1 */ +#define AD7793_IO_IEXC1_IEXC2_IOUT2 3 /* Both current sources + * IEXC1,2 connect to IOUT2 */ + +#define AD7793_IO_IXCEN_10uA (1 << 0) /* Excitation Current 10uA */ +#define AD7793_IO_IXCEN_210uA (2 << 0) /* Excitation Current 210uA */ +#define AD7793_IO_IXCEN_1mA (3 << 0) /* Excitation Current 1mA */ + +struct ad7793_platform_data { + u16 vref_mv; + u16 mode; + u16 conf; + u8 io; +}; + +#endif /* IIO_ADC_AD7793_H_ */ diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index 11379e469b07..0c84217bde3d 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -43,7 +43,6 @@ struct ad7816_chip_info { struct spi_device *spi_dev; - struct iio_dev *indio_dev; u16 rdwr_pin; u16 convert_pin; u16 busy_pin; @@ -113,7 +112,7 @@ static ssize_t ad7816_show_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7816_chip_info *chip = dev_info->dev_data; + struct ad7816_chip_info *chip = iio_priv(dev_info); if (chip->mode) return sprintf(buf, "power-save\n"); @@ -127,7 +126,7 @@ static ssize_t ad7816_store_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7816_chip_info *chip = dev_info->dev_data; + struct ad7816_chip_info *chip = iio_priv(dev_info); if (strcmp(buf, "full")) { gpio_set_value(chip->rdwr_pin, 1); @@ -159,7 +158,7 @@ static ssize_t ad7816_show_channel(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7816_chip_info *chip = dev_info->dev_data; + struct ad7816_chip_info *chip = iio_priv(dev_info); return sprintf(buf, "%d\n", chip->channel_id); } @@ -170,7 +169,7 @@ static ssize_t ad7816_store_channel(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7816_chip_info *chip = dev_info->dev_data; + struct ad7816_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; @@ -208,7 +207,7 @@ static ssize_t ad7816_show_value(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7816_chip_info *chip = dev_info->dev_data; + struct ad7816_chip_info *chip = iio_priv(dev_info); u16 data; s8 value; int ret; @@ -265,7 +264,7 @@ static ssize_t ad7816_show_oti(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7816_chip_info *chip = dev_info->dev_data; + struct ad7816_chip_info *chip = iio_priv(dev_info); int value; if (chip->channel_id > AD7816_CS_MAX) { @@ -286,7 +285,7 @@ static inline ssize_t ad7816_set_oti(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7816_chip_info *chip = dev_info->dev_data; + struct ad7816_chip_info *chip = iio_priv(dev_info); long value; u8 data; int ret; @@ -345,6 +344,7 @@ static const struct iio_info ad7816_info = { static int __devinit ad7816_probe(struct spi_device *spi_dev) { struct ad7816_chip_info *chip; + struct iio_dev *indio_dev; unsigned short *pins = spi_dev->dev.platform_data; int ret = 0; int i; @@ -354,13 +354,14 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev) return -EINVAL; } - chip = kzalloc(sizeof(struct ad7816_chip_info), GFP_KERNEL); - - if (chip == NULL) - return -ENOMEM; - + 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 */ - dev_set_drvdata(&spi_dev->dev, chip); + dev_set_drvdata(&spi_dev->dev, indio_dev); chip->spi_dev = spi_dev; for (i = 0; i <= AD7816_CS_MAX; i++) @@ -373,7 +374,7 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev) if (ret) { dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n", chip->rdwr_pin); - goto error_free_chip; + goto error_free_device; } gpio_direction_input(chip->rdwr_pin); ret = gpio_request(chip->convert_pin, spi_get_device_id(spi_dev)->name); @@ -391,20 +392,14 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev) } gpio_direction_input(chip->busy_pin); - chip->indio_dev = iio_allocate_device(0); - if (chip->indio_dev == NULL) { - ret = -ENOMEM; - goto error_free_gpio; - } - chip->indio_dev->name = spi_get_device_id(spi_dev)->name; - chip->indio_dev->dev.parent = &spi_dev->dev; - chip->indio_dev->info = &ad7816_info; - chip->indio_dev->dev_data = (void *)chip; - chip->indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->name = spi_get_device_id(spi_dev)->name; + indio_dev->dev.parent = &spi_dev->dev; + indio_dev->info = &ad7816_info; + 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; + goto error_free_gpio; if (spi_dev->irq) { /* Only low trigger is supported in ad7816/7/8 */ @@ -412,47 +407,44 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev) NULL, &ad7816_event_handler, IRQF_TRIGGER_LOW, - chip->indio_dev->name, - chip->indio_dev); + indio_dev->name, + indio_dev); if (ret) goto error_unreg_dev; } dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n", - chip->indio_dev->name); + indio_dev->name); return 0; error_unreg_dev: - iio_device_unregister(chip->indio_dev); -error_free_dev: - iio_free_device(chip->indio_dev); + iio_device_unregister(indio_dev); error_free_gpio: gpio_free(chip->busy_pin); error_free_gpio_convert: gpio_free(chip->convert_pin); error_free_gpio_rdwr: gpio_free(chip->rdwr_pin); -error_free_chip: - kfree(chip); - +error_free_device: + iio_free_device(indio_dev); +error_ret: return ret; } static int __devexit ad7816_remove(struct spi_device *spi_dev) { - struct ad7816_chip_info *chip = dev_get_drvdata(&spi_dev->dev); - struct iio_dev *indio_dev = chip->indio_dev; + struct iio_dev *indio_dev = dev_get_drvdata(&spi_dev->dev); + struct ad7816_chip_info *chip = iio_priv(indio_dev); dev_set_drvdata(&spi_dev->dev, NULL); if (spi_dev->irq) free_irq(spi_dev->irq, indio_dev); - iio_device_unregister(indio_dev); - iio_free_device(chip->indio_dev); gpio_free(chip->busy_pin); gpio_free(chip->convert_pin); gpio_free(chip->rdwr_pin); - kfree(chip); + iio_device_unregister(indio_dev); + iio_free_device(indio_dev); return 0; } diff --git a/drivers/staging/iio/adc/ad7887_core.c b/drivers/staging/iio/adc/ad7887_core.c index de14b174cef7..3d9121e5c37d 100644 --- a/drivers/staging/iio/adc/ad7887_core.c +++ b/drivers/staging/iio/adc/ad7887_core.c @@ -37,7 +37,7 @@ static int ad7887_read_raw(struct iio_dev *dev_info, long m) { int ret; - struct ad7887_state *st = dev_info->dev_data; + struct ad7887_state *st = iio_priv(dev_info); unsigned int scale_uv; switch (m) { @@ -118,7 +118,6 @@ static int __devinit ad7887_probe(struct spi_device *spi) /* Estabilish that the iio_dev is a child of the spi device */ indio_dev->dev.parent = &spi->dev; indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->dev_data = (void *)(st); indio_dev->info = &ad7887_info; indio_dev->modes = INDIO_DIRECT_MODE; diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c index 0e4a5f4fd892..0ac7c0b9d71d 100644 --- a/drivers/staging/iio/adc/ad7887_ring.c +++ b/drivers/staging/iio/adc/ad7887_ring.c @@ -64,7 +64,7 @@ error_ret: **/ static int ad7887_ring_preenable(struct iio_dev *indio_dev) { - struct ad7887_state *st = indio_dev->dev_data; + struct ad7887_state *st = iio_priv(indio_dev); struct iio_ring_buffer *ring = indio_dev->ring; st->d_size = ring->scan_count * @@ -100,7 +100,7 @@ static int ad7887_ring_preenable(struct iio_dev *indio_dev) static int ad7887_ring_postdisable(struct iio_dev *indio_dev) { - struct ad7887_state *st = indio_dev->dev_data; + struct ad7887_state *st = iio_priv(indio_dev); /* dummy read: restore default CH0 settin */ return spi_sync(st->spi, &st->msg[AD7887_CH0]); @@ -116,7 +116,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->private_data; - struct ad7887_state *st = iio_dev_get_devdata(indio_dev); + struct ad7887_state *st = iio_priv(indio_dev); struct iio_ring_buffer *ring = indio_dev->ring; s64 time_ns; __u8 *buf; diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index 29bfbcf82064..92cfe2e3ea4a 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -143,7 +143,7 @@ static int ad799x_read_raw(struct iio_dev *dev_info, long m) { int ret; - struct ad799x_state *st = dev_info->dev_data; + struct ad799x_state *st = iio_priv(dev_info); unsigned int scale_uv; switch (m) { @@ -176,7 +176,7 @@ static ssize_t ad799x_read_frequency(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad799x_state *st = iio_dev_get_devdata(dev_info); + struct ad799x_state *st = iio_priv(dev_info); int ret, len = 0; u8 val; @@ -221,7 +221,7 @@ static ssize_t ad799x_write_frequency(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad799x_state *st = iio_dev_get_devdata(dev_info); + struct ad799x_state *st = iio_priv(dev_info); long val; int ret; @@ -281,7 +281,7 @@ static ssize_t ad799x_read_channel_config(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad799x_state *st = iio_dev_get_devdata(dev_info); + struct ad799x_state *st = iio_priv(dev_info); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int ret; @@ -299,7 +299,7 @@ static ssize_t ad799x_write_channel_config(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad799x_state *st = iio_dev_get_devdata(dev_info); + struct ad799x_state *st = iio_priv(dev_info); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); long val; @@ -319,7 +319,7 @@ static ssize_t ad799x_write_channel_config(struct device *dev, static irqreturn_t ad799x_event_handler(int irq, void *private) { struct iio_dev *indio_dev = private; - struct ad799x_state *st = iio_dev_get_devdata(private); + struct ad799x_state *st = iio_priv(private); u8 status; int i, ret; @@ -686,7 +686,6 @@ static int __devinit ad799x_probe(struct i2c_client *client, indio_dev->name = id->name; indio_dev->info = st->chip_info->info; indio_dev->name = id->name; - indio_dev->dev_data = (void *)(st); indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = st->chip_info->channel; diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c index 1ae8857b3d25..0376a826c26c 100644 --- a/drivers/staging/iio/adc/ad799x_ring.c +++ b/drivers/staging/iio/adc/ad799x_ring.c @@ -72,7 +72,7 @@ error_ret: static int ad799x_ring_preenable(struct iio_dev *indio_dev) { struct iio_ring_buffer *ring = indio_dev->ring; - struct ad799x_state *st = iio_dev_get_devdata(indio_dev); + struct ad799x_state *st = iio_priv(indio_dev); /* * Need to figure out the current mode based upon the requested @@ -109,7 +109,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->private_data; - struct ad799x_state *st = iio_dev_get_devdata(indio_dev); + struct ad799x_state *st = iio_priv(indio_dev); struct iio_ring_buffer *ring = indio_dev->ring; s64 time_ns; __u8 *rxbuf; diff --git a/drivers/staging/iio/adc/adt7310.c b/drivers/staging/iio/adc/adt7310.c index 68eca0b99ac0..1a41b8034405 100644 --- a/drivers/staging/iio/adc/adt7310.c +++ b/drivers/staging/iio/adc/adt7310.c @@ -80,7 +80,6 @@ struct adt7310_chip_info { struct spi_device *spi_dev; - struct iio_dev *indio_dev; u8 config; }; @@ -176,7 +175,7 @@ static ssize_t adt7310_show_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); u8 config; config = chip->config & ADT7310_MODE_MASK; @@ -199,7 +198,7 @@ static ssize_t adt7310_store_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); u16 config; int ret; @@ -243,7 +242,7 @@ static ssize_t adt7310_show_resolution(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); int ret; int bits; @@ -265,7 +264,7 @@ static ssize_t adt7310_store_resolution(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); unsigned long data; u16 config; int ret; @@ -301,7 +300,7 @@ static ssize_t adt7310_show_id(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); u8 id; int ret; @@ -351,7 +350,7 @@ static ssize_t adt7310_show_value(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); u8 status; u16 data; int ret, i = 0; @@ -390,7 +389,7 @@ static const struct attribute_group adt7310_attribute_group = { static irqreturn_t adt7310_event_handler(int irq, void *private) { struct iio_dev *indio_dev = private; - struct adt7310_chip_info *chip = iio_dev_get_devdata(indio_dev); + struct adt7310_chip_info *chip = iio_priv(indio_dev); s64 timestamp = iio_get_time_ns(); u8 status; int ret; @@ -425,7 +424,7 @@ static ssize_t adt7310_show_event_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); int ret; ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); @@ -444,7 +443,7 @@ static ssize_t adt7310_set_event_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); u16 config; int ret; @@ -477,7 +476,7 @@ static ssize_t adt7310_show_fault_queue(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); int ret; ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); @@ -493,7 +492,7 @@ static ssize_t adt7310_set_fault_queue(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; u8 config; @@ -523,7 +522,7 @@ static inline ssize_t adt7310_show_t_bound(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); u16 data; int ret; @@ -541,7 +540,7 @@ static inline ssize_t adt7310_set_t_bound(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); long tmp1, tmp2; u16 data; char *pos; @@ -661,7 +660,7 @@ static ssize_t adt7310_show_t_hyst(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); int ret; u8 t_hyst; @@ -678,7 +677,7 @@ static inline ssize_t adt7310_set_t_hyst(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7310_chip_info *chip = dev_info->dev_data; + struct adt7310_chip_info *chip = iio_priv(dev_info); int ret; unsigned long data; u8 t_hyst; @@ -760,33 +759,28 @@ static const struct iio_info adt7310_info = { static int __devinit adt7310_probe(struct spi_device *spi_dev) { struct adt7310_chip_info *chip; + struct iio_dev *indio_dev; int ret = 0; unsigned long *adt7310_platform_data = spi_dev->dev.platform_data; unsigned long irq_flags; - chip = kzalloc(sizeof(struct adt7310_chip_info), GFP_KERNEL); - - if (chip == NULL) - return -ENOMEM; - + 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 */ - dev_set_drvdata(&spi_dev->dev, chip); + dev_set_drvdata(&spi_dev->dev, indio_dev); chip->spi_dev = spi_dev; - chip->indio_dev = iio_allocate_device(0); - if (chip->indio_dev == NULL) { - ret = -ENOMEM; - goto error_free_chip; - } - - chip->indio_dev->dev.parent = &spi_dev->dev; - chip->indio_dev->name = spi_get_device_id(spi_dev)->name; - chip->indio_dev->info = &adt7310_info; - chip->indio_dev->dev_data = (void *)chip; - chip->indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->dev.parent = &spi_dev->dev; + indio_dev->name = spi_get_device_id(spi_dev)->name; + indio_dev->info = &adt7310_info; + 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; @@ -800,8 +794,8 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev) NULL, &adt7310_event_handler, irq_flags, - chip->indio_dev->name, - chip->indio_dev); + indio_dev->name, + indio_dev); if (ret) goto error_unreg_dev; } @@ -812,8 +806,8 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev) NULL, &adt7310_event_handler, adt7310_platform_data[1], - chip->indio_dev->name, - chip->indio_dev); + indio_dev->name, + indio_dev); if (ret) goto error_unreg_ct_irq; } @@ -841,38 +835,34 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev) } dev_info(&spi_dev->dev, "%s temperature sensor registered.\n", - chip->indio_dev->name); + indio_dev->name); return 0; error_unreg_int_irq: - free_irq(adt7310_platform_data[0], chip->indio_dev); + free_irq(adt7310_platform_data[0], indio_dev); error_unreg_ct_irq: - free_irq(spi_dev->irq, chip->indio_dev); + free_irq(spi_dev->irq, indio_dev); error_unreg_dev: - iio_device_unregister(chip->indio_dev); + iio_device_unregister(indio_dev); error_free_dev: - iio_free_device(chip->indio_dev); -error_free_chip: - kfree(chip); - + iio_free_device(indio_dev); +error_ret: return ret; } static int __devexit adt7310_remove(struct spi_device *spi_dev) { - struct adt7310_chip_info *chip = dev_get_drvdata(&spi_dev->dev); - struct iio_dev *indio_dev = chip->indio_dev; + struct iio_dev *indio_dev = dev_get_drvdata(&spi_dev->dev); unsigned long *adt7310_platform_data = spi_dev->dev.platform_data; dev_set_drvdata(&spi_dev->dev, NULL); if (adt7310_platform_data[0]) - free_irq(adt7310_platform_data[0], chip->indio_dev); + free_irq(adt7310_platform_data[0], indio_dev); if (spi_dev->irq) - free_irq(spi_dev->irq, chip->indio_dev); + free_irq(spi_dev->irq, indio_dev); iio_device_unregister(indio_dev); - iio_free_device(chip->indio_dev); - kfree(chip); + iio_free_device(indio_dev); return 0; } diff --git a/drivers/staging/iio/adc/adt7410.c b/drivers/staging/iio/adc/adt7410.c index c40a84f9c2ff..76aa0639a55a 100644 --- a/drivers/staging/iio/adc/adt7410.c +++ b/drivers/staging/iio/adc/adt7410.c @@ -75,7 +75,6 @@ struct adt7410_chip_info { struct i2c_client *client; - struct iio_dev *indio_dev; u8 config; }; @@ -144,7 +143,7 @@ static ssize_t adt7410_show_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); u8 config; config = chip->config & ADT7410_MODE_MASK; @@ -167,7 +166,7 @@ static ssize_t adt7410_store_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); u16 config; int ret; @@ -211,7 +210,7 @@ static ssize_t adt7410_show_resolution(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); int ret; int bits; @@ -233,7 +232,7 @@ static ssize_t adt7410_store_resolution(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); unsigned long data; u16 config; int ret; @@ -269,7 +268,7 @@ static ssize_t adt7410_show_id(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); u8 id; int ret; @@ -319,7 +318,7 @@ static ssize_t adt7410_show_value(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); u8 status; u16 data; int ret, i = 0; @@ -358,7 +357,7 @@ static const struct attribute_group adt7410_attribute_group = { static irqreturn_t adt7410_event_handler(int irq, void *private) { struct iio_dev *indio_dev = private; - struct adt7410_chip_info *chip = iio_dev_get_devdata(indio_dev); + struct adt7410_chip_info *chip = iio_priv(indio_dev); s64 timestamp = iio_get_time_ns(); u8 status; @@ -392,7 +391,7 @@ static ssize_t adt7410_show_event_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); int ret; ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); @@ -411,7 +410,7 @@ static ssize_t adt7410_set_event_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); u16 config; int ret; @@ -444,7 +443,7 @@ static ssize_t adt7410_show_fault_queue(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); int ret; ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config); @@ -460,7 +459,7 @@ static ssize_t adt7410_set_fault_queue(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; u8 config; @@ -490,7 +489,7 @@ static inline ssize_t adt7410_show_t_bound(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); u16 data; int ret; @@ -508,7 +507,7 @@ static inline ssize_t adt7410_set_t_bound(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); long tmp1, tmp2; u16 data; char *pos; @@ -628,7 +627,7 @@ static ssize_t adt7410_show_t_hyst(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); int ret; u8 t_hyst; @@ -645,7 +644,7 @@ static inline ssize_t adt7410_set_t_hyst(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt7410_chip_info *chip = dev_info->dev_data; + struct adt7410_chip_info *chip = iio_priv(dev_info); int ret; unsigned long data; u8 t_hyst; @@ -728,31 +727,27 @@ static int __devinit adt7410_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adt7410_chip_info *chip; + struct iio_dev *indio_dev; int ret = 0; unsigned long *adt7410_platform_data = client->dev.platform_data; - chip = kzalloc(sizeof(struct adt7410_chip_info), GFP_KERNEL); - - if (chip == NULL) - return -ENOMEM; - + 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; - } - chip->indio_dev->name = id->name; - chip->indio_dev->dev.parent = &client->dev; - chip->indio_dev->info = &adt7410_info; - chip->indio_dev->dev_data = (void *)chip; - chip->indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->name = id->name; + indio_dev->dev.parent = &client->dev; + indio_dev->info = &adt7410_info; + 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; @@ -763,7 +758,7 @@ static int __devinit adt7410_probe(struct i2c_client *client, &adt7410_event_handler, IRQF_TRIGGER_LOW, id->name, - chip->indio_dev); + indio_dev); if (ret) goto error_unreg_dev; } @@ -775,7 +770,7 @@ static int __devinit adt7410_probe(struct i2c_client *client, &adt7410_event_handler, adt7410_platform_data[1], id->name, - chip->indio_dev); + indio_dev); if (ret) goto error_unreg_ct_irq; } @@ -809,32 +804,27 @@ static int __devinit adt7410_probe(struct i2c_client *client, return 0; error_unreg_int_irq: - free_irq(adt7410_platform_data[0], chip->indio_dev); + free_irq(adt7410_platform_data[0], indio_dev); error_unreg_ct_irq: - free_irq(client->irq, chip->indio_dev); + free_irq(client->irq, indio_dev); error_unreg_dev: - iio_device_unregister(chip->indio_dev); + iio_device_unregister(indio_dev); error_free_dev: - iio_free_device(chip->indio_dev); -error_free_chip: - kfree(chip); - + iio_free_device(indio_dev); +error_ret: return ret; } static int __devexit adt7410_remove(struct i2c_client *client) { - struct adt7410_chip_info *chip = i2c_get_clientdata(client); - struct iio_dev *indio_dev = chip->indio_dev; + struct iio_dev *indio_dev = i2c_get_clientdata(client); unsigned long *adt7410_platform_data = client->dev.platform_data; if (adt7410_platform_data[0]) - free_irq(adt7410_platform_data[0], chip->indio_dev); + free_irq(adt7410_platform_data[0], indio_dev); if (client->irq) - free_irq(client->irq, chip->indio_dev); + free_irq(client->irq, indio_dev); iio_device_unregister(indio_dev); - iio_free_device(chip->indio_dev); - kfree(chip); return 0; } diff --git a/drivers/staging/iio/adc/adt75.c b/drivers/staging/iio/adc/adt75.c index 1171fb9c178f..38f141de6a4b 100644 --- a/drivers/staging/iio/adc/adt75.c +++ b/drivers/staging/iio/adc/adt75.c @@ -51,7 +51,6 @@ struct adt75_chip_info { struct i2c_client *client; - struct iio_dev *indio_dev; u8 config; }; @@ -59,8 +58,9 @@ struct adt75_chip_info { * adt75 register access by I2C */ -static int adt75_i2c_read(struct adt75_chip_info *chip, u8 reg, u8 *data) +static int adt75_i2c_read(struct iio_dev *dev_info, u8 reg, u8 *data) { + struct adt75_chip_info *chip = iio_priv(dev_info); struct i2c_client *client = chip->client; int ret = 0, len; @@ -84,8 +84,9 @@ static int adt75_i2c_read(struct adt75_chip_info *chip, u8 reg, u8 *data) return ret; } -static int adt75_i2c_write(struct adt75_chip_info *chip, u8 reg, u8 data) +static int adt75_i2c_write(struct iio_dev *dev_info, u8 reg, u8 data) { + struct adt75_chip_info *chip = iio_priv(dev_info); struct i2c_client *client = chip->client; int ret = 0; @@ -104,8 +105,7 @@ static ssize_t adt75_show_mode(struct device *dev, struct device_attribute *attr, char *buf) { - struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_get_drvdata(dev)); if (chip->config & ADT75_PD) return sprintf(buf, "power-save\n"); @@ -119,11 +119,11 @@ static ssize_t adt75_store_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_info); int ret; u8 config; - ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config); + ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config); if (ret) return -EIO; @@ -131,7 +131,7 @@ static ssize_t adt75_store_mode(struct device *dev, if (!strcmp(buf, "full")) config |= ADT75_PD; - ret = adt75_i2c_write(chip, ADT75_CONFIG, config); + ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config); if (ret) return -EIO; @@ -158,8 +158,7 @@ static ssize_t adt75_show_oneshot(struct device *dev, struct device_attribute *attr, char *buf) { - struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_get_drvdata(dev)); return sprintf(buf, "%d\n", !!(chip->config & ADT75_ONESHOT)); } @@ -170,7 +169,7 @@ static ssize_t adt75_store_oneshot(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_info); unsigned long data = 0; int ret; u8 config; @@ -180,7 +179,7 @@ static ssize_t adt75_store_oneshot(struct device *dev, return -EINVAL; - ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config); + ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config); if (ret) return -EIO; @@ -188,7 +187,7 @@ static ssize_t adt75_store_oneshot(struct device *dev, if (data) config |= ADT75_ONESHOT; - ret = adt75_i2c_write(chip, ADT75_CONFIG, config); + ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config); if (ret) return -EIO; @@ -207,7 +206,7 @@ static ssize_t adt75_show_value(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_info); u16 data; char sign = ' '; int ret; @@ -224,7 +223,7 @@ static ssize_t adt75_show_value(struct device *dev, return -EIO; } - ret = adt75_i2c_read(chip, ADT75_TEMPERATURE, (u8 *)&data); + ret = adt75_i2c_read(dev_info, ADT75_TEMPERATURE, (u8 *)&data); if (ret) return -EIO; @@ -277,11 +276,11 @@ static ssize_t adt75_show_oti_mode(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_info); int ret; /* retrive ALART status */ - ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config); + ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config); if (ret) return -EIO; @@ -297,12 +296,12 @@ static ssize_t adt75_set_oti_mode(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_info); int ret; u8 config; /* retrive ALART status */ - ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config); + ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config); if (ret) return -EIO; @@ -310,7 +309,7 @@ static ssize_t adt75_set_oti_mode(struct device *dev, if (strcmp(buf, "comparator") != 0) config |= ADT75_OS_INT; - ret = adt75_i2c_write(chip, ADT75_CONFIG, config); + ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config); if (ret) return -EIO; @@ -331,11 +330,11 @@ static ssize_t adt75_show_smbus_alart(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_info); int ret; /* retrive ALART status */ - ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config); + ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config); if (ret) return -EIO; @@ -348,7 +347,7 @@ static ssize_t adt75_set_smbus_alart(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_info); unsigned long data = 0; int ret; u8 config; @@ -358,7 +357,7 @@ static ssize_t adt75_set_smbus_alart(struct device *dev, return -EINVAL; /* retrive ALART status */ - ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config); + ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config); if (ret) return -EIO; @@ -366,7 +365,7 @@ static ssize_t adt75_set_smbus_alart(struct device *dev, if (data) config |= ADT75_SMBUS_ALART; - ret = adt75_i2c_write(chip, ADT75_CONFIG, config); + ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config); if (ret) return -EIO; @@ -380,11 +379,11 @@ static ssize_t adt75_show_fault_queue(struct device *dev, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_info); int ret; /* retrive ALART status */ - ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config); + ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config); if (ret) return -EIO; @@ -398,7 +397,7 @@ static ssize_t adt75_set_fault_queue(struct device *dev, size_t len) { struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; + struct adt75_chip_info *chip = iio_priv(dev_info); unsigned long data; int ret; u8 config; @@ -408,13 +407,13 @@ static ssize_t adt75_set_fault_queue(struct device *dev, return -EINVAL; /* retrive ALART status */ - ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config); + ret = adt75_i2c_read(dev_info, ADT75_CONFIG, &chip->config); if (ret) return -EIO; config = chip->config & ~ADT75_FAULT_QUEUE_MASK; config |= (data << ADT75_FAULT_QUEUE_OFFSET); - ret = adt75_i2c_write(chip, ADT75_CONFIG, config); + ret = adt75_i2c_write(dev_info, ADT75_CONFIG, config); if (ret) return -EIO; @@ -428,12 +427,11 @@ static inline ssize_t adt75_show_t_bound(struct device *dev, { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; u16 data; char sign = ' '; int ret; - ret = adt75_i2c_read(chip, this_attr->address, (u8 *)&data); + ret = adt75_i2c_read(dev_info, this_attr->address, (u8 *)&data); if (ret) return -EIO; @@ -456,7 +454,6 @@ static inline ssize_t adt75_set_t_bound(struct device *dev, { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev *dev_info = dev_get_drvdata(dev); - struct adt75_chip_info *chip = dev_info->dev_data; long tmp1, tmp2; u16 data; char *pos; @@ -491,7 +488,7 @@ static inline ssize_t adt75_set_t_bound(struct device *dev, data <<= ADT75_VALUE_OFFSET; data = swab16(data); - ret = adt75_i2c_write(chip, this_attr->address, (u8)data); + ret = adt75_i2c_write(dev_info, this_attr->address, (u8)data); if (ret) return -EIO; @@ -549,31 +546,27 @@ static int __devinit adt75_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adt75_chip_info *chip; + struct iio_dev *indio_dev; int ret = 0; - chip = kzalloc(sizeof(struct adt75_chip_info), GFP_KERNEL); - - if (chip == NULL) - return -ENOMEM; + 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; - } - - chip->indio_dev->name = id->name; - chip->indio_dev->dev.parent = &client->dev; - chip->indio_dev->info = &adt75_info; - chip->indio_dev->dev_data = (void *)chip; - chip->indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->name = id->name; + indio_dev->dev.parent = &client->dev; + indio_dev->info = &adt75_info; + 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; @@ -582,12 +575,12 @@ static int __devinit adt75_probe(struct i2c_client *client, NULL, &adt75_event_handler, IRQF_TRIGGER_LOW, - chip->indio_dev->name, - chip->indio_dev); + indio_dev->name, + indio_dev); if (ret) goto error_unreg_dev; - ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config); + ret = adt75_i2c_read(indio_dev, ADT75_CONFIG, &chip->config); if (ret) { ret = -EIO; goto error_unreg_irq; @@ -596,7 +589,7 @@ static int __devinit adt75_probe(struct i2c_client *client, /* set irq polarity low level */ chip->config &= ~ADT75_OS_POLARITY; - ret = adt75_i2c_write(chip, ADT75_CONFIG, chip->config); + ret = adt75_i2c_write(indio_dev, ADT75_CONFIG, chip->config); if (ret) { ret = -EIO; goto error_unreg_irq; @@ -604,31 +597,27 @@ static int __devinit adt75_probe(struct i2c_client *client, } dev_info(&client->dev, "%s temperature sensor registered.\n", - chip->indio_dev->name); + indio_dev->name); return 0; error_unreg_irq: - free_irq(client->irq, chip->indio_dev); + free_irq(client->irq, indio_dev); error_unreg_dev: - iio_device_unregister(chip->indio_dev); + iio_device_unregister(indio_dev); error_free_dev: - iio_free_device(chip->indio_dev); -error_free_chip: - kfree(chip); - + iio_free_device(indio_dev); +error_ret: return ret; } static int __devexit adt75_remove(struct i2c_client *client) { - struct adt75_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, chip->indio_dev); + free_irq(client->irq, indio_dev); iio_device_unregister(indio_dev); - iio_free_device(chip->indio_dev); - kfree(chip); + iio_free_device(indio_dev); return 0; } diff --git a/drivers/staging/iio/adc/max1363_core.c b/drivers/staging/iio/adc/max1363_core.c index 98cebd26310f..72b0917412ee 100644 --- a/drivers/staging/iio/adc/max1363_core.c +++ b/drivers/staging/iio/adc/max1363_core.c @@ -1255,12 +1255,15 @@ static int __devinit max1363_probe(struct i2c_client *client, struct regulator *reg; reg = regulator_get(&client->dev, "vcc"); - if (!IS_ERR(reg)) { - ret = regulator_enable(reg); - if (ret) - goto error_put_reg; + if (IS_ERR(reg)) { + ret = PTR_ERR(reg); + goto error_out; } + ret = regulator_enable(reg); + if (ret) + goto error_put_reg; + indio_dev = iio_allocate_device(sizeof(struct max1363_state)); if (indio_dev == NULL) { ret = -ENOMEM; @@ -1323,6 +1326,7 @@ static int __devinit max1363_probe(struct i2c_client *client, } return 0; + error_uninit_ring: iio_ring_buffer_unregister(indio_dev->ring); error_cleanup_ring: @@ -1335,12 +1339,10 @@ error_free_device: else iio_device_unregister(indio_dev); error_disable_reg: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); + regulator_disable(reg); error_put_reg: - if (!IS_ERR(st->reg)) - regulator_put(st->reg); - + regulator_put(reg); +error_out: return ret; } |