23 #include <linux/module.h>
26 #include <linux/device.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
41 #define LPC32XX_ADC_SELECT(x) ((x) + 0x04)
42 #define LPC32XX_ADC_CTRL(x) ((x) + 0x08)
43 #define LPC32XX_ADC_VALUE(x) ((x) + 0x48)
46 #define AD_REFm 0x00000200
47 #define AD_REFp 0x00000080
48 #define AD_IN 0x00000010
50 #define AD_INTERNAL 0x00000004
53 #define AD_STROBE 0x00000002
54 #define AD_PDN_CTRL 0x00000004
57 #define ADC_VALUE_MASK 0x000003FF
59 #define MOD_NAME "lpc32xx-adc"
69 static int lpc32xx_read_raw(
struct iio_dev *indio_dev,
97 static const struct iio_info lpc32xx_adc_iio_info = {
98 .read_raw = &lpc32xx_read_raw,
102 #define LPC32XX_ADC_CHANNEL(_index) { \
103 .type = IIO_VOLTAGE, \
106 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, \
107 .address = AD_IN * _index, \
108 .scan_index = _index, \
111 static const struct iio_chan_spec lpc32xx_adc_iio_channels[] = {
139 dev_err(&pdev->
dev,
"failed to get platform I/O memory\n");
146 dev_err(&pdev->
dev,
"failed allocating iio device\n");
151 info = iio_priv(iodev);
155 dev_err(&pdev->
dev,
"failed mapping memory\n");
161 if (IS_ERR(info->
clk)) {
162 dev_err(&pdev->
dev,
"failed getting clock\n");
167 if ((irq < 0) || (irq >=
NR_IRQS)) {
168 dev_err(&pdev->
dev,
"failed getting interrupt resource\n");
175 dev_err(&pdev->
dev,
"failed requesting interrupt\n");
179 platform_set_drvdata(pdev, iodev);
184 iodev->
dev.parent = &pdev->
dev;
185 iodev->
info = &lpc32xx_adc_iio_info;
187 iodev->
channels = lpc32xx_adc_iio_channels;
194 dev_info(&pdev->
dev,
"LPC32XX ADC driver loaded, IRQ %d\n", irq);
212 struct iio_dev *iodev = platform_get_drvdata(pdev);
218 platform_set_drvdata(pdev,
NULL);
227 static const struct of_device_id lpc32xx_adc_match[] = {
235 .probe = lpc32xx_adc_probe,