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 * @write_scale_sw pointer to the function which writes the scale via spi 20 in software mode 21 * @write_os_sw pointer to the function which writes the os via spi 22 in software mode 23 * @sw_mode_config: pointer to a function which configured the device 24 * for software mode 25 */ 26 struct ad7606_chip_info { 27 const struct iio_chan_spec *channels; 28 unsigned int num_channels; 29 const unsigned int *oversampling_avail; 30 unsigned int oversampling_num; 31 bool os_req_reset; 32 int (*write_scale_sw)(struct iio_dev *indio_dev, int ch, int val); 33 int (*write_os_sw)(struct iio_dev *indio_dev, int val); 34 int (*sw_mode_config)(struct iio_dev *indio_dev); 35 }; 36 37 /** 38 * struct ad7606_state - driver instance specific data 39 * @dev pointer to kernel device 40 * @chip_info entry in the table of chips that describes this device 41 * @reg regulator info for the the power supply of the device 42 * @bops bus operations (SPI or parallel) 43 * @range voltage range selection, selects which scale to apply 44 * @oversampling oversampling selection 45 * @base_address address from where to read data in parallel operation 46 * @sw_mode_en software mode enabled 47 * @scale_avail pointer to the array which stores the available scales 48 * @num_scales number of elements stored in the scale_avail array 49 * @oversampling_avail pointer to the array which stores the available 50 * oversampling ratios. 51 * @num_os_ratios number of elements stored in oversampling_avail array 52 * @write_scale pointer to the function which writes the scale 53 * @write_os pointer to the function which writes the os 54 * @lock protect sensor state from concurrent accesses to GPIOs 55 * @gpio_convst GPIO descriptor for conversion start signal (CONVST) 56 * @gpio_reset GPIO descriptor for device hard-reset 57 * @gpio_range GPIO descriptor for range selection 58 * @gpio_standby GPIO descriptor for stand-by signal (STBY), 59 * controls power-down mode of device 60 * @gpio_frstdata GPIO descriptor for reading from device when data 61 * is being read on the first channel 62 * @gpio_os GPIO descriptors to control oversampling on the device 63 * @complete completion to indicate end of conversion 64 * @trig The IIO trigger associated with the device. 65 * @data buffer for reading data from the device 66 */ 67 struct ad7606_state { 68 struct device *dev; 69 const struct ad7606_chip_info *chip_info; 70 struct regulator *reg; 71 const struct ad7606_bus_ops *bops; 72 unsigned int range[16]; 73 unsigned int oversampling; 74 void __iomem *base_address; 75 bool sw_mode_en; 76 const unsigned int *scale_avail; 77 unsigned int num_scales; 78 const unsigned int *oversampling_avail; 79 unsigned int num_os_ratios; 80 int (*write_scale)(struct iio_dev *indio_dev, int ch, int val); 81 int (*write_os)(struct iio_dev *indio_dev, int val); 82 83 struct mutex lock; /* protect sensor state */ 84 struct gpio_desc *gpio_convst; 85 struct gpio_desc *gpio_reset; 86 struct gpio_desc *gpio_range; 87 struct gpio_desc *gpio_standby; 88 struct gpio_desc *gpio_frstdata; 89 struct gpio_descs *gpio_os; 90 struct iio_trigger *trig; 91 struct completion completion; 92 93 /* 94 * DMA (thus cache coherency maintenance) requires the 95 * transfer buffers to live in their own cache lines. 96 * 16 * 16-bit samples + 64-bit timestamp 97 */ 98 unsigned short data[20] ____cacheline_aligned; 99 }; 100 101 /** 102 * struct ad7606_bus_ops - driver bus operations 103 * @read_block function pointer for reading blocks of data 104 */ 105 struct ad7606_bus_ops { 106 /* more methods added in future? */ 107 int (*read_block)(struct device *dev, int num, void *data); 108 }; 109 110 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, 111 const char *name, unsigned int id, 112 const struct ad7606_bus_ops *bops); 113 114 enum ad7606_supported_device_ids { 115 ID_AD7605_4, 116 ID_AD7606_8, 117 ID_AD7606_6, 118 ID_AD7606_4, 119 ID_AD7616, 120 }; 121 122 #ifdef CONFIG_PM_SLEEP 123 extern const struct dev_pm_ops ad7606_pm_ops; 124 #define AD7606_PM_OPS (&ad7606_pm_ops) 125 #else 126 #define AD7606_PM_OPS NULL 127 #endif 128 129 #endif /* IIO_ADC_AD7606_H_ */ 130