2018-12-17 20:23:36 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2011-02-23 04:46:18 +08:00
|
|
|
/*
|
|
|
|
* AD7606 ADC driver
|
|
|
|
*
|
|
|
|
* Copyright 2011 Analog Devices Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef IIO_ADC_AD7606_H_
|
|
|
|
#define IIO_ADC_AD7606_H_
|
|
|
|
|
2019-07-18 14:27:33 +08:00
|
|
|
#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all) { \
|
2019-07-18 14:27:30 +08:00
|
|
|
.type = IIO_VOLTAGE, \
|
|
|
|
.indexed = 1, \
|
|
|
|
.channel = num, \
|
|
|
|
.address = num, \
|
2019-07-18 14:27:33 +08:00
|
|
|
.info_mask_separate = mask_sep, \
|
|
|
|
.info_mask_shared_by_type = mask_type, \
|
|
|
|
.info_mask_shared_by_all = mask_all, \
|
2019-07-18 14:27:30 +08:00
|
|
|
.scan_index = num, \
|
|
|
|
.scan_type = { \
|
|
|
|
.sign = 's', \
|
|
|
|
.realbits = 16, \
|
|
|
|
.storagebits = 16, \
|
|
|
|
.endianness = IIO_CPU, \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
2019-07-18 14:27:33 +08:00
|
|
|
#define AD7605_CHANNEL(num) \
|
|
|
|
AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \
|
|
|
|
BIT(IIO_CHAN_INFO_SCALE), 0)
|
2019-07-18 14:27:30 +08:00
|
|
|
|
2019-07-18 14:27:33 +08:00
|
|
|
#define AD7606_CHANNEL(num) \
|
|
|
|
AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \
|
|
|
|
BIT(IIO_CHAN_INFO_SCALE), \
|
|
|
|
BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
|
|
|
|
|
|
|
|
#define AD7616_CHANNEL(num) \
|
|
|
|
AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),\
|
|
|
|
0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
|
2019-07-18 14:27:30 +08:00
|
|
|
|
2011-02-23 04:46:18 +08:00
|
|
|
/**
|
2014-04-22 19:23:00 +08:00
|
|
|
* struct ad7606_chip_info - chip specific information
|
2011-05-18 21:42:00 +08:00
|
|
|
* @channels: channel specification
|
|
|
|
* @num_channels: number of channels
|
2019-04-02 21:18:39 +08:00
|
|
|
* @oversampling_avail pointer to the array which stores the available
|
|
|
|
* oversampling ratios.
|
|
|
|
* @oversampling_num number of elements stored in oversampling_avail array
|
2019-04-02 21:18:40 +08:00
|
|
|
* @os_req_reset some devices require a reset to update oversampling
|
2019-08-21 22:16:53 +08:00
|
|
|
* @init_delay_ms required delay in miliseconds for initialization
|
|
|
|
* after a restart
|
2011-02-23 04:46:18 +08:00
|
|
|
*/
|
|
|
|
struct ad7606_chip_info {
|
2012-08-09 15:51:00 +08:00
|
|
|
const struct iio_chan_spec *channels;
|
2016-03-27 03:50:24 +08:00
|
|
|
unsigned int num_channels;
|
2019-04-02 21:18:39 +08:00
|
|
|
const unsigned int *oversampling_avail;
|
|
|
|
unsigned int oversampling_num;
|
2019-04-02 21:18:40 +08:00
|
|
|
bool os_req_reset;
|
2019-08-21 22:16:53 +08:00
|
|
|
unsigned long init_delay_ms;
|
2011-02-23 04:46:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct ad7606_state - driver instance specific data
|
2018-09-18 20:15:03 +08:00
|
|
|
* @dev pointer to kernel device
|
|
|
|
* @chip_info entry in the table of chips that describes this device
|
|
|
|
* @reg regulator info for the the power supply of the device
|
|
|
|
* @bops bus operations (SPI or parallel)
|
|
|
|
* @range voltage range selection, selects which scale to apply
|
|
|
|
* @oversampling oversampling selection
|
|
|
|
* @base_address address from where to read data in parallel operation
|
2019-05-27 20:56:48 +08:00
|
|
|
* @sw_mode_en software mode enabled
|
2019-04-02 21:18:39 +08:00
|
|
|
* @scale_avail pointer to the array which stores the available scales
|
|
|
|
* @num_scales number of elements stored in the scale_avail array
|
|
|
|
* @oversampling_avail pointer to the array which stores the available
|
|
|
|
* oversampling ratios.
|
|
|
|
* @num_os_ratios number of elements stored in oversampling_avail array
|
2019-05-27 20:56:47 +08:00
|
|
|
* @write_scale pointer to the function which writes the scale
|
|
|
|
* @write_os pointer to the function which writes the os
|
2018-09-18 20:15:03 +08:00
|
|
|
* @lock protect sensor state from concurrent accesses to GPIOs
|
|
|
|
* @gpio_convst GPIO descriptor for conversion start signal (CONVST)
|
|
|
|
* @gpio_reset GPIO descriptor for device hard-reset
|
|
|
|
* @gpio_range GPIO descriptor for range selection
|
|
|
|
* @gpio_standby GPIO descriptor for stand-by signal (STBY),
|
|
|
|
* controls power-down mode of device
|
|
|
|
* @gpio_frstdata GPIO descriptor for reading from device when data
|
|
|
|
* is being read on the first channel
|
|
|
|
* @gpio_os GPIO descriptors to control oversampling on the device
|
2018-12-13 20:46:15 +08:00
|
|
|
* @complete completion to indicate end of conversion
|
2018-12-17 20:23:37 +08:00
|
|
|
* @trig The IIO trigger associated with the device.
|
2018-09-18 20:15:03 +08:00
|
|
|
* @data buffer for reading data from the device
|
2019-07-18 14:27:33 +08:00
|
|
|
* @d16 be16 buffer for reading data from the device
|
2011-02-23 04:46:18 +08:00
|
|
|
*/
|
|
|
|
struct ad7606_state {
|
|
|
|
struct device *dev;
|
|
|
|
const struct ad7606_chip_info *chip_info;
|
|
|
|
struct regulator *reg;
|
|
|
|
const struct ad7606_bus_ops *bops;
|
2019-05-27 20:56:47 +08:00
|
|
|
unsigned int range[16];
|
2016-03-27 03:50:24 +08:00
|
|
|
unsigned int oversampling;
|
2011-02-23 04:46:18 +08:00
|
|
|
void __iomem *base_address;
|
2019-05-27 20:56:48 +08:00
|
|
|
bool sw_mode_en;
|
2019-04-02 21:18:39 +08:00
|
|
|
const unsigned int *scale_avail;
|
|
|
|
unsigned int num_scales;
|
|
|
|
const unsigned int *oversampling_avail;
|
|
|
|
unsigned int num_os_ratios;
|
2019-05-27 20:56:47 +08:00
|
|
|
int (*write_scale)(struct iio_dev *indio_dev, int ch, int val);
|
|
|
|
int (*write_os)(struct iio_dev *indio_dev, int val);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
2017-03-21 03:51:34 +08:00
|
|
|
struct mutex lock; /* protect sensor state */
|
2016-10-20 01:07:07 +08:00
|
|
|
struct gpio_desc *gpio_convst;
|
|
|
|
struct gpio_desc *gpio_reset;
|
|
|
|
struct gpio_desc *gpio_range;
|
|
|
|
struct gpio_desc *gpio_standby;
|
|
|
|
struct gpio_desc *gpio_frstdata;
|
|
|
|
struct gpio_descs *gpio_os;
|
2018-12-17 20:23:37 +08:00
|
|
|
struct iio_trigger *trig;
|
2018-12-13 20:46:15 +08:00
|
|
|
struct completion completion;
|
2016-10-20 01:07:07 +08:00
|
|
|
|
2011-02-23 04:46:18 +08:00
|
|
|
/*
|
|
|
|
* DMA (thus cache coherency maintenance) requires the
|
|
|
|
* transfer buffers to live in their own cache lines.
|
2019-04-02 21:18:40 +08:00
|
|
|
* 16 * 16-bit samples + 64-bit timestamp
|
2011-02-23 04:46:18 +08:00
|
|
|
*/
|
2019-04-02 21:18:40 +08:00
|
|
|
unsigned short data[20] ____cacheline_aligned;
|
2019-07-18 14:27:33 +08:00
|
|
|
__be16 d16[2];
|
2011-02-23 04:46:18 +08:00
|
|
|
};
|
|
|
|
|
2018-09-18 20:15:03 +08:00
|
|
|
/**
|
|
|
|
* struct ad7606_bus_ops - driver bus operations
|
|
|
|
* @read_block function pointer for reading blocks of data
|
2019-07-18 14:27:31 +08:00
|
|
|
* @sw_mode_config: pointer to a function which configured the device
|
|
|
|
* for software mode
|
2019-07-18 14:27:33 +08:00
|
|
|
* @reg_read function pointer for reading spi register
|
|
|
|
* @reg_write function pointer for writing spi register
|
|
|
|
* @write_mask function pointer for write spi register with mask
|
|
|
|
* @rd_wr_cmd pointer to the function which calculates the spi address
|
2018-09-18 20:15:03 +08:00
|
|
|
*/
|
2011-02-23 04:46:18 +08:00
|
|
|
struct ad7606_bus_ops {
|
|
|
|
/* more methods added in future? */
|
2018-06-09 06:13:31 +08:00
|
|
|
int (*read_block)(struct device *dev, int num, void *data);
|
2019-07-18 14:27:31 +08:00
|
|
|
int (*sw_mode_config)(struct iio_dev *indio_dev);
|
2019-07-18 14:27:33 +08:00
|
|
|
int (*reg_read)(struct ad7606_state *st, unsigned int addr);
|
|
|
|
int (*reg_write)(struct ad7606_state *st,
|
|
|
|
unsigned int addr,
|
|
|
|
unsigned int val);
|
|
|
|
int (*write_mask)(struct ad7606_state *st,
|
|
|
|
unsigned int addr,
|
|
|
|
unsigned long mask,
|
|
|
|
unsigned int val);
|
|
|
|
u16 (*rd_wr_cmd)(int addr, char isWriteOp);
|
2011-02-23 04:46:18 +08:00
|
|
|
};
|
|
|
|
|
2016-10-20 01:07:04 +08:00
|
|
|
int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
|
|
|
|
const char *name, unsigned int id,
|
|
|
|
const struct ad7606_bus_ops *bops);
|
2011-02-23 04:46:18 +08:00
|
|
|
|
|
|
|
enum ad7606_supported_device_ids {
|
2018-09-13 19:02:12 +08:00
|
|
|
ID_AD7605_4,
|
2011-02-23 04:46:18 +08:00
|
|
|
ID_AD7606_8,
|
|
|
|
ID_AD7606_6,
|
2019-04-02 21:18:40 +08:00
|
|
|
ID_AD7606_4,
|
2019-08-21 22:16:53 +08:00
|
|
|
ID_AD7606B,
|
2019-04-02 21:18:40 +08:00
|
|
|
ID_AD7616,
|
2011-02-23 04:46:18 +08:00
|
|
|
};
|
|
|
|
|
2016-02-08 18:13:29 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
extern const struct dev_pm_ops ad7606_pm_ops;
|
|
|
|
#define AD7606_PM_OPS (&ad7606_pm_ops)
|
|
|
|
#else
|
|
|
|
#define AD7606_PM_OPS NULL
|
|
|
|
#endif
|
|
|
|
|
2011-02-23 04:46:18 +08:00
|
|
|
#endif /* IIO_ADC_AD7606_H_ */
|