xref: /openbmc/linux/drivers/iio/adc/ad7606.h (revision 1fa0a7dc)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * AD7606 ADC driver
4  *
5  * Copyright 2011 Analog Devices Inc.
6  */
7 
8 #ifndef IIO_ADC_AD7606_H_
9 #define IIO_ADC_AD7606_H_
10 
11 /**
12  * struct ad7606_chip_info - chip specific information
13  * @channels:		channel specification
14  * @num_channels:	number of channels
15  * @oversampling_avail	pointer to the array which stores the available
16  *			oversampling ratios.
17  * @oversampling_num	number of elements stored in oversampling_avail array
18  * @os_req_reset	some devices require a reset to update oversampling
19  */
20 struct ad7606_chip_info {
21 	const struct iio_chan_spec	*channels;
22 	unsigned int			num_channels;
23 	const unsigned int		*oversampling_avail;
24 	unsigned int			oversampling_num;
25 	bool				os_req_reset;
26 };
27 
28 /**
29  * struct ad7606_state - driver instance specific data
30  * @dev		pointer to kernel device
31  * @chip_info		entry in the table of chips that describes this device
32  * @reg		regulator info for the the power supply of the device
33  * @bops		bus operations (SPI or parallel)
34  * @range		voltage range selection, selects which scale to apply
35  * @oversampling	oversampling selection
36  * @base_address	address from where to read data in parallel operation
37  * @scale_avail		pointer to the array which stores the available scales
38  * @num_scales		number of elements stored in the scale_avail array
39  * @oversampling_avail	pointer to the array which stores the available
40  *			oversampling ratios.
41  * @num_os_ratios	number of elements stored in oversampling_avail array
42  * @lock		protect sensor state from concurrent accesses to GPIOs
43  * @gpio_convst	GPIO descriptor for conversion start signal (CONVST)
44  * @gpio_reset		GPIO descriptor for device hard-reset
45  * @gpio_range		GPIO descriptor for range selection
46  * @gpio_standby	GPIO descriptor for stand-by signal (STBY),
47  *			controls power-down mode of device
48  * @gpio_frstdata	GPIO descriptor for reading from device when data
49  *			is being read on the first channel
50  * @gpio_os		GPIO descriptors to control oversampling on the device
51  * @complete		completion to indicate end of conversion
52  * @trig		The IIO trigger associated with the device.
53  * @data		buffer for reading data from the device
54  */
55 struct ad7606_state {
56 	struct device			*dev;
57 	const struct ad7606_chip_info	*chip_info;
58 	struct regulator		*reg;
59 	const struct ad7606_bus_ops	*bops;
60 	unsigned int			range;
61 	unsigned int			oversampling;
62 	void __iomem			*base_address;
63 	const unsigned int		*scale_avail;
64 	unsigned int			num_scales;
65 	const unsigned int		*oversampling_avail;
66 	unsigned int			num_os_ratios;
67 
68 	struct mutex			lock; /* protect sensor state */
69 	struct gpio_desc		*gpio_convst;
70 	struct gpio_desc		*gpio_reset;
71 	struct gpio_desc		*gpio_range;
72 	struct gpio_desc		*gpio_standby;
73 	struct gpio_desc		*gpio_frstdata;
74 	struct gpio_descs		*gpio_os;
75 	struct iio_trigger		*trig;
76 	struct completion		completion;
77 
78 	/*
79 	 * DMA (thus cache coherency maintenance) requires the
80 	 * transfer buffers to live in their own cache lines.
81 	 * 16 * 16-bit samples + 64-bit timestamp
82 	 */
83 	unsigned short			data[20] ____cacheline_aligned;
84 };
85 
86 /**
87  * struct ad7606_bus_ops - driver bus operations
88  * @read_block		function pointer for reading blocks of data
89  */
90 struct ad7606_bus_ops {
91 	/* more methods added in future? */
92 	int (*read_block)(struct device *dev, int num, void *data);
93 };
94 
95 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
96 		 const char *name, unsigned int id,
97 		 const struct ad7606_bus_ops *bops);
98 
99 enum ad7606_supported_device_ids {
100 	ID_AD7605_4,
101 	ID_AD7606_8,
102 	ID_AD7606_6,
103 	ID_AD7606_4,
104 	ID_AD7616,
105 };
106 
107 #ifdef CONFIG_PM_SLEEP
108 extern const struct dev_pm_ops ad7606_pm_ops;
109 #define AD7606_PM_OPS (&ad7606_pm_ops)
110 #else
111 #define AD7606_PM_OPS NULL
112 #endif
113 
114 #endif /* IIO_ADC_AD7606_H_ */
115