Skip to content

Commit

Permalink
staging: iio: adc: ad7476 new SPI ADC driver
Browse files Browse the repository at this point in the history
New driver handling:
	AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, AD7495
SPI micropower and high speed 12-/10-/8-Bit ADCs

staging: iio: adc: ad7476 apply list review feedback by Jonathan Cameron

Changes since last RFC post V1:
	Mainly list review feedback by Jonathan Cameron

-Remove scan_attrs from chip info structure.
-Remove name from chip info structure, use new spi_device_id instead.
-Allow transfer buffers to live in their own cache lines, to avoid DMA/cache coherency issues.
-Move scan el code into the ring buffer file.
-Use helper function to alloc the pollfunc.
-Use regulator framework and get vref_mv from the regulator in case not specified by pdata.
-Devices with buit-in reference use vref from the chip info structure
-Don't error on missing platform_data

-Make vref_mv type unsigned short
-Print in_scale "Vref / 2^(bits)" if fractional.

Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Michael Hennerich authored and Greg Kroah-Hartman committed Oct 12, 2010
1 parent 1dd8b73 commit 349282d
Show file tree
Hide file tree
Showing 5 changed files with 599 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/staging/iio/adc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ config AD799X_RING_BUFFER
help
Say yes here to include ring buffer support in the AD799X
ADC driver.

config AD7476
tristate "Analog Devices AD7475/6/7/8 AD7466/7/8 and AD7495 ADC driver"
depends on SPI
help
Say yes here to build support for Analog Devices AD7475/6/7/8,
AD7466/7/8 and AD7495 ADC driver.
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 ad7476.
4 changes: 4 additions & 0 deletions drivers/staging/iio/adc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ obj-$(CONFIG_MAX1363) += max1363.o
ad799x-y := ad799x_core.o
ad799x-$(CONFIG_AD799X_RING_BUFFER) += ad799x_ring.o
obj-$(CONFIG_AD799X) += ad799x.o

ad7476-y := ad7476_core.o
ad7476-$(CONFIG_IIO_RING_BUFFER) += ad7476_ring.o
obj-$(CONFIG_AD7476) += ad7476.o
79 changes: 79 additions & 0 deletions drivers/staging/iio/adc/ad7476.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* AD7476/5/7/8 (A) SPI ADC driver
*
* Copyright 2010 Analog Devices Inc.
*
* Licensed under the GPL-2 or later.
*/
#ifndef IIO_ADC_AD7476_H_
#define IIO_ADC_AD7476_H_

#define RES_MASK(bits) ((1 << (bits)) - 1)

/*
* TODO: struct ad7476_platform_data needs to go into include/linux/iio
*/

struct ad7476_platform_data {
u16 vref_mv;
};

struct ad7476_chip_info {
u8 bits;
u8 storagebits;
u8 res_shift;
char sign;
u16 int_vref_mv;
};

struct ad7476_state {
struct iio_dev *indio_dev;
struct spi_device *spi;
const struct ad7476_chip_info *chip_info;
struct regulator *reg;
struct work_struct poll_work;
atomic_t protect_ring;
u16 int_vref_mv;
struct spi_transfer xfer;
struct spi_message msg;
/*
* DMA (thus cache coherency maintenance) requires the
* transfer buffers to live in their own cache lines.
*/
unsigned char data[2] ____cacheline_aligned;
};

enum ad7476_supported_device_ids {
ID_AD7466,
ID_AD7467,
ID_AD7468,
ID_AD7475,
ID_AD7476,
ID_AD7477,
ID_AD7478,
ID_AD7495
};

#ifdef CONFIG_IIO_RING_BUFFER
int ad7476_scan_from_ring(struct ad7476_state *st);
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 ssize_t ad7476_scan_from_ring(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return 0;
}

static inline int
ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev)
{
return 0;
}

static inline void ad7476_ring_cleanup(struct iio_dev *indio_dev)
{
}
#endif /* CONFIG_IIO_RING_BUFFER */
#endif /* IIO_ADC_AD7476_H_ */
Loading

0 comments on commit 349282d

Please sign in to comment.