blob: a6aac33aa33c78cc2d7c662416a4801339939bfd [file] [log] [blame]
Stefan Popaca5b4632018-12-17 14:23:36 +02001/* SPDX-License-Identifier: GPL-2.0 */
Michael Hennerichb9618c02011-02-22 21:46:18 +01002/*
3 * AD7606 ADC driver
4 *
5 * Copyright 2011 Analog Devices Inc.
Michael Hennerichb9618c02011-02-22 21:46:18 +01006 */
7
8#ifndef IIO_ADC_AD7606_H_
9#define IIO_ADC_AD7606_H_
10
Beniamin Bia7677f732019-07-18 09:27:30 +030011#define AD760X_CHANNEL(num, mask) { \
12 .type = IIO_VOLTAGE, \
13 .indexed = 1, \
14 .channel = num, \
15 .address = num, \
16 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
17 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
18 .info_mask_shared_by_all = mask, \
19 .scan_index = num, \
20 .scan_type = { \
21 .sign = 's', \
22 .realbits = 16, \
23 .storagebits = 16, \
24 .endianness = IIO_CPU, \
25 }, \
26}
27
28#define AD7605_CHANNEL(num) \
29 AD760X_CHANNEL(num, 0)
30
31#define AD7606_CHANNEL(num) \
32 AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
33
Michael Hennerichb9618c02011-02-22 21:46:18 +010034/**
Masanari Iidae3c5be22014-04-22 12:23:00 +010035 * struct ad7606_chip_info - chip specific information
Michael Hennerich1caf7cb2011-05-18 14:42:00 +010036 * @channels: channel specification
37 * @num_channels: number of channels
Stefan Popa6bf229a2019-04-02 16:18:39 +030038 * @oversampling_avail pointer to the array which stores the available
39 * oversampling ratios.
40 * @oversampling_num number of elements stored in oversampling_avail array
Beniamin Bia7989b4b2019-04-02 16:18:40 +030041 * @os_req_reset some devices require a reset to update oversampling
Michael Hennerichb9618c02011-02-22 21:46:18 +010042 */
Michael Hennerichb9618c02011-02-22 21:46:18 +010043struct ad7606_chip_info {
Lars-Peter Clausenf4e4b952012-08-09 08:51:00 +010044 const struct iio_chan_spec *channels;
Alison Schofield51fadb92016-03-26 12:50:24 -070045 unsigned int num_channels;
Stefan Popa6bf229a2019-04-02 16:18:39 +030046 const unsigned int *oversampling_avail;
47 unsigned int oversampling_num;
Beniamin Bia7989b4b2019-04-02 16:18:40 +030048 bool os_req_reset;
Michael Hennerichb9618c02011-02-22 21:46:18 +010049};
50
51/**
52 * struct ad7606_state - driver instance specific data
Alexandru Ardelean7c2d5372018-09-18 15:15:03 +030053 * @dev pointer to kernel device
54 * @chip_info entry in the table of chips that describes this device
55 * @reg regulator info for the the power supply of the device
Alexandru Ardelean7c2d5372018-09-18 15:15:03 +030056 * @bops bus operations (SPI or parallel)
57 * @range voltage range selection, selects which scale to apply
58 * @oversampling oversampling selection
Alexandru Ardelean7c2d5372018-09-18 15:15:03 +030059 * @base_address address from where to read data in parallel operation
Beniamin Bia3c23e9e2019-05-27 15:56:48 +030060 * @sw_mode_en software mode enabled
Stefan Popa6bf229a2019-04-02 16:18:39 +030061 * @scale_avail pointer to the array which stores the available scales
62 * @num_scales number of elements stored in the scale_avail array
63 * @oversampling_avail pointer to the array which stores the available
64 * oversampling ratios.
65 * @num_os_ratios number of elements stored in oversampling_avail array
Beniamin Bia88dd0312019-05-27 15:56:47 +030066 * @write_scale pointer to the function which writes the scale
67 * @write_os pointer to the function which writes the os
Alexandru Ardelean7c2d5372018-09-18 15:15:03 +030068 * @lock protect sensor state from concurrent accesses to GPIOs
69 * @gpio_convst GPIO descriptor for conversion start signal (CONVST)
70 * @gpio_reset GPIO descriptor for device hard-reset
71 * @gpio_range GPIO descriptor for range selection
72 * @gpio_standby GPIO descriptor for stand-by signal (STBY),
73 * controls power-down mode of device
74 * @gpio_frstdata GPIO descriptor for reading from device when data
75 * is being read on the first channel
76 * @gpio_os GPIO descriptors to control oversampling on the device
Stefan Popa557e5852018-12-13 14:46:15 +020077 * @complete completion to indicate end of conversion
Stefan Popacc49bd12018-12-17 14:23:37 +020078 * @trig The IIO trigger associated with the device.
Alexandru Ardelean7c2d5372018-09-18 15:15:03 +030079 * @data buffer for reading data from the device
Michael Hennerichb9618c02011-02-22 21:46:18 +010080 */
Michael Hennerichb9618c02011-02-22 21:46:18 +010081struct ad7606_state {
Michael Hennerichb9618c02011-02-22 21:46:18 +010082 struct device *dev;
83 const struct ad7606_chip_info *chip_info;
Michael Hennerichb9618c02011-02-22 21:46:18 +010084 struct regulator *reg;
Michael Hennerichb9618c02011-02-22 21:46:18 +010085 const struct ad7606_bus_ops *bops;
Beniamin Bia88dd0312019-05-27 15:56:47 +030086 unsigned int range[16];
Alison Schofield51fadb92016-03-26 12:50:24 -070087 unsigned int oversampling;
Michael Hennerichb9618c02011-02-22 21:46:18 +010088 void __iomem *base_address;
Beniamin Bia3c23e9e2019-05-27 15:56:48 +030089 bool sw_mode_en;
Stefan Popa6bf229a2019-04-02 16:18:39 +030090 const unsigned int *scale_avail;
91 unsigned int num_scales;
92 const unsigned int *oversampling_avail;
93 unsigned int num_os_ratios;
Beniamin Bia88dd0312019-05-27 15:56:47 +030094 int (*write_scale)(struct iio_dev *indio_dev, int ch, int val);
95 int (*write_os)(struct iio_dev *indio_dev, int val);
Michael Hennerichb9618c02011-02-22 21:46:18 +010096
Arushi Singhal755d0da2017-03-21 01:21:34 +053097 struct mutex lock; /* protect sensor state */
Lars-Peter Clausen722407a2016-10-19 19:07:07 +020098 struct gpio_desc *gpio_convst;
99 struct gpio_desc *gpio_reset;
100 struct gpio_desc *gpio_range;
101 struct gpio_desc *gpio_standby;
102 struct gpio_desc *gpio_frstdata;
103 struct gpio_descs *gpio_os;
Stefan Popacc49bd12018-12-17 14:23:37 +0200104 struct iio_trigger *trig;
Stefan Popa557e5852018-12-13 14:46:15 +0200105 struct completion completion;
Lars-Peter Clausen722407a2016-10-19 19:07:07 +0200106
Michael Hennerichb9618c02011-02-22 21:46:18 +0100107 /*
108 * DMA (thus cache coherency maintenance) requires the
109 * transfer buffers to live in their own cache lines.
Beniamin Bia7989b4b2019-04-02 16:18:40 +0300110 * 16 * 16-bit samples + 64-bit timestamp
Michael Hennerichb9618c02011-02-22 21:46:18 +0100111 */
Beniamin Bia7989b4b2019-04-02 16:18:40 +0300112 unsigned short data[20] ____cacheline_aligned;
Michael Hennerichb9618c02011-02-22 21:46:18 +0100113};
114
Alexandru Ardelean7c2d5372018-09-18 15:15:03 +0300115/**
116 * struct ad7606_bus_ops - driver bus operations
117 * @read_block function pointer for reading blocks of data
Beniamin Biaa0c648c2019-07-18 09:27:31 +0300118 * @sw_mode_config: pointer to a function which configured the device
119 * for software mode
Alexandru Ardelean7c2d5372018-09-18 15:15:03 +0300120 */
Michael Hennerichb9618c02011-02-22 21:46:18 +0100121struct ad7606_bus_ops {
122 /* more methods added in future? */
Giulio Benetti727198f2018-06-09 00:13:31 +0200123 int (*read_block)(struct device *dev, int num, void *data);
Beniamin Biaa0c648c2019-07-18 09:27:31 +0300124 int (*sw_mode_config)(struct iio_dev *indio_dev);
Michael Hennerichb9618c02011-02-22 21:46:18 +0100125};
126
Lars-Peter Clausen71faca72016-10-19 19:07:04 +0200127int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
128 const char *name, unsigned int id,
129 const struct ad7606_bus_ops *bops);
Michael Hennerichb9618c02011-02-22 21:46:18 +0100130
131enum ad7606_supported_device_ids {
Alexandru Ardeleanbb9fc6a2018-09-13 14:02:12 +0300132 ID_AD7605_4,
Michael Hennerichb9618c02011-02-22 21:46:18 +0100133 ID_AD7606_8,
134 ID_AD7606_6,
Beniamin Bia7989b4b2019-04-02 16:18:40 +0300135 ID_AD7606_4,
136 ID_AD7616,
Michael Hennerichb9618c02011-02-22 21:46:18 +0100137};
138
Lars-Peter Clausen2c3a5232016-02-08 11:13:29 +0100139#ifdef CONFIG_PM_SLEEP
140extern const struct dev_pm_ops ad7606_pm_ops;
141#define AD7606_PM_OPS (&ad7606_pm_ops)
142#else
143#define AD7606_PM_OPS NULL
144#endif
145
Michael Hennerichb9618c02011-02-22 21:46:18 +0100146#endif /* IIO_ADC_AD7606_H_ */