Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | * AD7606 ADC driver |
| 3 | * |
| 4 | * Copyright 2011 Analog Devices Inc. |
| 5 | * |
| 6 | * Licensed under the GPL-2. |
| 7 | */ |
| 8 | |
| 9 | #ifndef IIO_ADC_AD7606_H_ |
| 10 | #define IIO_ADC_AD7606_H_ |
| 11 | |
| 12 | /* |
| 13 | * TODO: struct ad7606_platform_data needs to go into include/linux/iio |
| 14 | */ |
| 15 | |
| 16 | /** |
Masanari Iida | e3c5be2 | 2014-04-22 12:23:00 +0100 | [diff] [blame] | 17 | * struct ad7606_platform_data - platform/board specific information |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 18 | * @default_os: default oversampling value {0, 2, 4, 8, 16, 32, 64} |
| 19 | * @default_range: default range +/-{5000, 10000} mVolt |
| 20 | * @gpio_convst: number of gpio connected to the CONVST pin |
| 21 | * @gpio_reset: gpio connected to the RESET pin, if not used set to -1 |
| 22 | * @gpio_range: gpio connected to the RANGE pin, if not used set to -1 |
| 23 | * @gpio_os0: gpio connected to the OS0 pin, if not used set to -1 |
| 24 | * @gpio_os1: gpio connected to the OS1 pin, if not used set to -1 |
| 25 | * @gpio_os2: gpio connected to the OS2 pin, if not used set to -1 |
| 26 | * @gpio_frstdata: gpio connected to the FRSTDAT pin, if not used set to -1 |
| 27 | * @gpio_stby: gpio connected to the STBY pin, if not used set to -1 |
| 28 | */ |
| 29 | |
| 30 | struct ad7606_platform_data { |
| 31 | unsigned default_os; |
| 32 | unsigned default_range; |
| 33 | unsigned gpio_convst; |
| 34 | unsigned gpio_reset; |
| 35 | unsigned gpio_range; |
| 36 | unsigned gpio_os0; |
| 37 | unsigned gpio_os1; |
| 38 | unsigned gpio_os2; |
| 39 | unsigned gpio_frstdata; |
| 40 | unsigned gpio_stby; |
| 41 | }; |
| 42 | |
| 43 | /** |
Masanari Iida | e3c5be2 | 2014-04-22 12:23:00 +0100 | [diff] [blame] | 44 | * struct ad7606_chip_info - chip specific information |
Maxime Jayat | 3f79410 | 2013-10-12 01:29:46 +0200 | [diff] [blame] | 45 | * @name: identification string for chip |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 46 | * @int_vref_mv: the internal reference voltage |
Michael Hennerich | 1caf7cb | 2011-05-18 14:42:00 +0100 | [diff] [blame] | 47 | * @channels: channel specification |
| 48 | * @num_channels: number of channels |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 49 | */ |
| 50 | |
| 51 | struct ad7606_chip_info { |
Jonathan Cameron | 13cfac2 | 2011-05-18 14:41:38 +0100 | [diff] [blame] | 52 | const char *name; |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 53 | u16 int_vref_mv; |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 54 | const struct iio_chan_spec *channels; |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 55 | unsigned num_channels; |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * struct ad7606_state - driver instance specific data |
| 60 | */ |
| 61 | |
| 62 | struct ad7606_state { |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 63 | struct device *dev; |
| 64 | const struct ad7606_chip_info *chip_info; |
| 65 | struct ad7606_platform_data *pdata; |
| 66 | struct regulator *reg; |
| 67 | struct work_struct poll_work; |
| 68 | wait_queue_head_t wq_data_avail; |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 69 | const struct ad7606_bus_ops *bops; |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 70 | unsigned range; |
| 71 | unsigned oversampling; |
| 72 | bool done; |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 73 | void __iomem *base_address; |
| 74 | |
| 75 | /* |
| 76 | * DMA (thus cache coherency maintenance) requires the |
| 77 | * transfer buffers to live in their own cache lines. |
| 78 | */ |
| 79 | |
| 80 | unsigned short data[8] ____cacheline_aligned; |
| 81 | }; |
| 82 | |
| 83 | struct ad7606_bus_ops { |
| 84 | /* more methods added in future? */ |
| 85 | int (*read_block)(struct device *, int, void *); |
| 86 | }; |
| 87 | |
Michael Hennerich | e61181d | 2011-05-18 14:42:01 +0100 | [diff] [blame] | 88 | void ad7606_suspend(struct iio_dev *indio_dev); |
| 89 | void ad7606_resume(struct iio_dev *indio_dev); |
| 90 | struct iio_dev *ad7606_probe(struct device *dev, int irq, |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 91 | void __iomem *base_address, unsigned id, |
| 92 | const struct ad7606_bus_ops *bops); |
Jonathan Cameron | 8cbb36a | 2011-09-30 10:05:42 +0100 | [diff] [blame] | 93 | int ad7606_remove(struct iio_dev *indio_dev, int irq); |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 94 | int ad7606_reset(struct ad7606_state *st); |
| 95 | |
| 96 | enum ad7606_supported_device_ids { |
| 97 | ID_AD7606_8, |
| 98 | ID_AD7606_6, |
| 99 | ID_AD7606_4 |
| 100 | }; |
| 101 | |
Michael Hennerich | b9618c0 | 2011-02-22 21:46:18 +0100 | [diff] [blame] | 102 | int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev); |
| 103 | void ad7606_ring_cleanup(struct iio_dev *indio_dev); |
| 104 | #endif /* IIO_ADC_AD7606_H_ */ |