1 /*
2  * AD7298 SPI ADC driver
3  *
4  * Copyright 2011 Analog Devices Inc.
5  *
6  * Licensed under the GPL-2.
7  */
8 
9 #ifndef IIO_ADC_AD7298_H_
10 #define IIO_ADC_AD7298_H_
11 
12 #define AD7298_WRITE	(1 << 15) /* write to the control register */
13 #define AD7298_REPEAT	(1 << 14) /* repeated conversion enable */
14 #define AD7298_CH(x)	(1 << (13 - (x))) /* channel select */
15 #define AD7298_TSENSE	(1 << 5) /* temperature conversion enable */
16 #define AD7298_EXTREF	(1 << 2) /* external reference enable */
17 #define AD7298_TAVG	(1 << 1) /* temperature sensor averaging enable */
18 #define AD7298_PDD	(1 << 0) /* partial power down enable */
19 
20 #define AD7298_CH_MASK	(AD7298_CH0 | AD7298_CH1 | AD7298_CH2 | AD7298_CH3 | \
21 			AD7298_CH4 | AD7298_CH5 | AD7298_CH6 | AD7298_CH7)
22 
23 #define AD7298_MAX_CHAN		8
24 #define AD7298_BITS		12
25 #define AD7298_STORAGE_BITS	16
26 #define AD7298_INTREF_mV	2500
27 
28 #define RES_MASK(bits)	((1 << (bits)) - 1)
29 
30 /*
31  * TODO: struct ad7298_platform_data needs to go into include/linux/iio
32  */
33 
34 struct ad7298_platform_data {
35 	/* External Vref voltage applied */
36 	u16				vref_mv;
37 };
38 
39 struct ad7298_state {
40 	struct iio_dev			*indio_dev;
41 	struct spi_device		*spi;
42 	struct regulator		*reg;
43 	struct work_struct		poll_work;
44 	atomic_t			protect_ring;
45 	size_t				d_size;
46 	u16				int_vref_mv;
47 	unsigned			ext_ref;
48 	struct spi_transfer		ring_xfer[10];
49 	struct spi_transfer		scan_single_xfer[3];
50 	struct spi_message		ring_msg;
51 	struct spi_message		scan_single_msg;
52 	/*
53 	 * DMA (thus cache coherency maintenance) requires the
54 	 * transfer buffers to live in their own cache lines.
55 	 */
56 	unsigned short			rx_buf[8] ____cacheline_aligned;
57 	unsigned short			tx_buf[2];
58 };
59 
60 #ifdef CONFIG_IIO_RING_BUFFER
61 int ad7298_scan_from_ring(struct ad7298_state *st, long ch);
62 int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev);
63 void ad7298_ring_cleanup(struct iio_dev *indio_dev);
64 #else /* CONFIG_IIO_RING_BUFFER */
ad7298_scan_from_ring(struct ad7298_state * st,long ch)65 static inline int ad7298_scan_from_ring(struct ad7298_state *st, long ch)
66 {
67 	return 0;
68 }
69 
70 static inline int
ad7298_register_ring_funcs_and_init(struct iio_dev * indio_dev)71 ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
72 {
73 	return 0;
74 }
75 
ad7298_ring_cleanup(struct iio_dev * indio_dev)76 static inline void ad7298_ring_cleanup(struct iio_dev *indio_dev)
77 {
78 }
79 #endif /* CONFIG_IIO_RING_BUFFER */
80 #endif /* IIO_ADC_AD7298_H_ */
81