// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2013 Oskar Andero <[email protected]> * Copyright (C) 2014 Rose Technology * Allan Bendorff Jensen <[email protected]> * Soren Andersen <[email protected]> * * Driver for following ADC chips from Microchip Technology's: * 10 Bit converter * MCP3001 * MCP3002 * MCP3004 * MCP3008 * ------------ * 12 bit converter * MCP3201 * MCP3202 * MCP3204 * MCP3208 * ------------ * 13 bit converter * MCP3301 * ------------ * 22 bit converter * MCP3550 * MCP3551 * MCP3553 * * Datasheet can be found here: * https://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp3001 * https://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf mcp3002 * https://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf mcp3004/08 * http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp3201 * http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202 * http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08 * https://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf mcp3301 * http://ww1.microchip.com/downloads/en/DeviceDoc/21950D.pdf mcp3550/1/3 */ #include <linux/err.h> #include <linux/delay.h> #include <linux/spi/spi.h> #include <linux/module.h> #include <linux/mod_devicetable.h> #include <linux/iio/iio.h> #include <linux/regulator/consumer.h> enum { … }; struct mcp320x_chip_info { … }; /** * struct mcp320x - Microchip SPI ADC instance * @spi: SPI slave (parent of the IIO device) * @msg: SPI message to select a channel and receive a value from the ADC * @transfer: SPI transfers used by @msg * @start_conv_msg: SPI message to start a conversion by briefly asserting CS * @start_conv_transfer: SPI transfer used by @start_conv_msg * @reg: regulator generating Vref * @lock: protects read sequences * @chip_info: ADC properties * @tx_buf: buffer for @transfer[0] (not used on single-channel converters) * @rx_buf: buffer for @transfer[1] */ struct mcp320x { … }; static int mcp320x_channel_to_tx_data(int device_index, const unsigned int channel, bool differential) { … } static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel, bool differential, int device_index, int *val) { … } static int mcp320x_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *channel, int *val, int *val2, long mask) { … } #define MCP320X_VOLTAGE_CHANNEL(num) … #define MCP320X_VOLTAGE_CHANNEL_DIFF(chan1, chan2) … static const struct iio_chan_spec mcp3201_channels[] = …; static const struct iio_chan_spec mcp3202_channels[] = …; static const struct iio_chan_spec mcp3204_channels[] = …; static const struct iio_chan_spec mcp3208_channels[] = …; static const struct iio_info mcp320x_info = …; static const struct mcp320x_chip_info mcp320x_chip_infos[] = …; static void mcp320x_regulator_disable(void *reg) { … } static int mcp320x_probe(struct spi_device *spi) { … } static const struct of_device_id mcp320x_dt_ids[] = …; MODULE_DEVICE_TABLE(of, mcp320x_dt_ids); static const struct spi_device_id mcp320x_id[] = …; MODULE_DEVICE_TABLE(spi, mcp320x_id); static struct spi_driver mcp320x_driver = …; module_spi_driver(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;