aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio/adc/ad7887.h
diff options
context:
space:
mode:
authorMichael Hennerich <michael.hennerich@analog.com>2010-11-22 08:35:32 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-11-29 14:02:56 -0500
commit2b4756aa36909a94596752db341a0a2c8bb8c6ea (patch)
tree98a3a89cadfde697b78cf5e9566d62832869b0d6 /drivers/staging/iio/adc/ad7887.h
parentb5a49481754a5cbfdc47bd701208f77c5c9010c6 (diff)
staging: iio: adc: Enable driver support for ad7887 AD converter
Enable support for AD7887: SPI Micropower, 2-Channel, 125 kSPS, 12-Bit ADC staging: iio: adc: Fix according to review feedback Review feedback by Jonathan Cameron: Combine statements. Document struct members. Remove redundant variable initialization. Simplify multichannel scan from ring logic. Fix coding style. [v2] staging: iio: adc: ad7887: Fix typos 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>
Diffstat (limited to 'drivers/staging/iio/adc/ad7887.h')
-rw-r--r--drivers/staging/iio/adc/ad7887.h105
1 files changed, 105 insertions, 0 deletions
diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h
new file mode 100644
index 00000000000..8c2a218c949
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7887.h
@@ -0,0 +1,105 @@
1/*
2 * AD7887 SPI ADC driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8#ifndef IIO_ADC_AD7887_H_
9#define IIO_ADC_AD7887_H_
10
11#define AD7887_REF_DIS (1 << 5) /* on-chip reference disable */
12#define AD7887_DUAL (1 << 4) /* dual-channel mode */
13#define AD7887_CH_AIN1 (1 << 3) /* convert on channel 1, DUAL=1 */
14#define AD7887_CH_AIN0 (0 << 3) /* convert on channel 0, DUAL=0,1 */
15#define AD7887_PM_MODE1 (0) /* CS based shutdown */
16#define AD7887_PM_MODE2 (1) /* full on */
17#define AD7887_PM_MODE3 (2) /* auto shutdown after conversion */
18#define AD7887_PM_MODE4 (3) /* standby mode */
19
20enum ad7887_channels {
21 AD7887_CH0,
22 AD7887_CH0_CH1,
23 AD7887_CH1,
24};
25
26#define RES_MASK(bits) ((1 << (bits)) - 1) /* TODO: move this into a common header */
27
28/*
29 * TODO: struct ad7887_platform_data needs to go into include/linux/iio
30 */
31
32struct ad7887_platform_data {
33 /* External Vref voltage applied */
34 u16 vref_mv;
35 /*
36 * AD7887:
37 * In single channel mode en_dual = flase, AIN1/Vref pins assumes its
38 * Vref function. In dual channel mode en_dual = true, AIN1 becomes the
39 * second input channel, and Vref is internally connected to Vdd.
40 */
41 bool en_dual;
42 /*
43 * AD7887:
44 * use_onchip_ref = true, the Vref is internally connected to the 2.500V
45 * Voltage reference. If use_onchip_ref = false, the reference voltage
46 * is supplied by AIN1/Vref
47 */
48 bool use_onchip_ref;
49};
50
51struct ad7887_chip_info {
52 u8 bits; /* number of ADC bits */
53 u8 storagebits; /* number of bits read from the ADC */
54 u8 left_shift; /* number of bits the sample must be shifted */
55 char sign; /* [s]igned or [u]nsigned */
56 u16 int_vref_mv; /* internal reference voltage */
57};
58
59struct ad7887_state {
60 struct iio_dev *indio_dev;
61 struct spi_device *spi;
62 const struct ad7887_chip_info *chip_info;
63 struct regulator *reg;
64 struct work_struct poll_work;
65 atomic_t protect_ring;
66 u16 int_vref_mv;
67 bool en_dual;
68 struct spi_transfer xfer[4];
69 struct spi_message msg[3];
70 struct spi_message *ring_msg;
71 unsigned char tx_cmd_buf[8];
72
73 /*
74 * DMA (thus cache coherency maintenance) requires the
75 * transfer buffers to live in their own cache lines.
76 */
77
78 unsigned char data[4] ____cacheline_aligned;
79};
80
81enum ad7887_supported_device_ids {
82 ID_AD7887
83};
84
85#ifdef CONFIG_IIO_RING_BUFFER
86int ad7887_scan_from_ring(struct ad7887_state *st, long mask);
87int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev);
88void ad7887_ring_cleanup(struct iio_dev *indio_dev);
89#else /* CONFIG_IIO_RING_BUFFER */
90static inline int ad7887_scan_from_ring(struct ad7887_state *st, long mask)
91{
92 return 0;
93}
94
95static inline int
96ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
97{
98 return 0;
99}
100
101static inline void ad7887_ring_cleanup(struct iio_dev *indio_dev)
102{
103}
104#endif /* CONFIG_IIO_RING_BUFFER */
105#endif /* IIO_ADC_AD7887_H_ */