blob: 5dd61f6a57b93f8d7cc73a47dff549d9a25f3901 [file] [log] [blame]
Stefan Roeseb3201b52012-04-12 11:05:35 +02001/*
2 * ST SPEAr ADC driver
3 *
4 * Copyright 2012 Stefan Roese <sr@denx.de>
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/platform_device.h>
11#include <linux/interrupt.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/io.h>
16#include <linux/clk.h>
17#include <linux/err.h>
18#include <linux/completion.h>
19#include <linux/of.h>
20#include <linux/of_address.h>
21
Jonathan Cameron06458e22012-04-25 15:54:58 +010022#include <linux/iio/iio.h>
23#include <linux/iio/sysfs.h>
Stefan Roeseb3201b52012-04-12 11:05:35 +020024
Jonathan Cameronb64aef72014-05-04 17:45:00 +010025/* SPEAR registers definitions */
26#define SPEAR600_ADC_SCAN_RATE_LO(x) ((x) & 0xFFFF)
27#define SPEAR600_ADC_SCAN_RATE_HI(x) (((x) >> 0x10) & 0xFFFF)
28#define SPEAR_ADC_CLK_LOW(x) (((x) & 0xf) << 0)
29#define SPEAR_ADC_CLK_HIGH(x) (((x) & 0xf) << 4)
Stefan Roeseb3201b52012-04-12 11:05:35 +020030
31/* Bit definitions for SPEAR_ADC_STATUS */
Haneen Mohammed418880f2015-03-26 02:23:29 +030032#define SPEAR_ADC_STATUS_START_CONVERSION BIT(0)
Jonathan Cameronb64aef72014-05-04 17:45:00 +010033#define SPEAR_ADC_STATUS_CHANNEL_NUM(x) ((x) << 1)
Haneen Mohammed418880f2015-03-26 02:23:29 +030034#define SPEAR_ADC_STATUS_ADC_ENABLE BIT(4)
Jonathan Cameronb64aef72014-05-04 17:45:00 +010035#define SPEAR_ADC_STATUS_AVG_SAMPLE(x) ((x) << 5)
Haneen Mohammed418880f2015-03-26 02:23:29 +030036#define SPEAR_ADC_STATUS_VREF_INTERNAL BIT(9)
Stefan Roeseb3201b52012-04-12 11:05:35 +020037
Jonathan Cameronb64aef72014-05-04 17:45:00 +010038#define SPEAR_ADC_DATA_MASK 0x03ff
39#define SPEAR_ADC_DATA_BITS 10
Stefan Roeseb3201b52012-04-12 11:05:35 +020040
Jonathan Cameronb64aef72014-05-04 17:45:00 +010041#define SPEAR_ADC_MOD_NAME "spear-adc"
Stefan Roeseb3201b52012-04-12 11:05:35 +020042
Jonathan Cameronb64aef72014-05-04 17:45:00 +010043#define SPEAR_ADC_CHANNEL_NUM 8
Stefan Roeseb3201b52012-04-12 11:05:35 +020044
Jonathan Cameronb64aef72014-05-04 17:45:00 +010045#define SPEAR_ADC_CLK_MIN 2500000
46#define SPEAR_ADC_CLK_MAX 20000000
Stefan Roeseb3201b52012-04-12 11:05:35 +020047
48struct adc_regs_spear3xx {
49 u32 status;
50 u32 average;
51 u32 scan_rate;
52 u32 clk; /* Not avail for 1340 & 1310 */
Jonathan Cameronb64aef72014-05-04 17:45:00 +010053 u32 ch_ctrl[SPEAR_ADC_CHANNEL_NUM];
54 u32 ch_data[SPEAR_ADC_CHANNEL_NUM];
Stefan Roeseb3201b52012-04-12 11:05:35 +020055};
56
57struct chan_data {
58 u32 lsb;
59 u32 msb;
60};
61
62struct adc_regs_spear6xx {
63 u32 status;
64 u32 pad[2];
65 u32 clk;
Jonathan Cameronb64aef72014-05-04 17:45:00 +010066 u32 ch_ctrl[SPEAR_ADC_CHANNEL_NUM];
67 struct chan_data ch_data[SPEAR_ADC_CHANNEL_NUM];
Stefan Roeseb3201b52012-04-12 11:05:35 +020068 u32 scan_rate_lo;
69 u32 scan_rate_hi;
70 struct chan_data average;
71};
72
Jonathan Cameronb586e5d2014-05-04 17:45:00 +010073struct spear_adc_state {
Stefan Roeseb3201b52012-04-12 11:05:35 +020074 struct device_node *np;
75 struct adc_regs_spear3xx __iomem *adc_base_spear3xx;
76 struct adc_regs_spear6xx __iomem *adc_base_spear6xx;
77 struct clk *clk;
78 struct completion completion;
79 u32 current_clk;
80 u32 sampling_freq;
81 u32 avg_samples;
82 u32 vref_external;
83 u32 value;
84};
85
86/*
87 * Functions to access some SPEAr ADC register. Abstracted into
88 * static inline functions, because of different register offsets
89 * on different SoC variants (SPEAr300 vs SPEAr600 etc).
90 */
Jonathan Cameronb586e5d2014-05-04 17:45:00 +010091static void spear_adc_set_status(struct spear_adc_state *st, u32 val)
Stefan Roeseb3201b52012-04-12 11:05:35 +020092{
Jonathan Cameronb586e5d2014-05-04 17:45:00 +010093 __raw_writel(val, &st->adc_base_spear6xx->status);
Stefan Roeseb3201b52012-04-12 11:05:35 +020094}
95
Jonathan Cameronb586e5d2014-05-04 17:45:00 +010096static void spear_adc_set_clk(struct spear_adc_state *st, u32 val)
Stefan Roeseb3201b52012-04-12 11:05:35 +020097{
98 u32 clk_high, clk_low, count;
Jonathan Cameronb586e5d2014-05-04 17:45:00 +010099 u32 apb_clk = clk_get_rate(st->clk);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200100
Tapasweni Pathakffceca82014-10-08 22:56:15 +0530101 count = DIV_ROUND_UP(apb_clk, val);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200102 clk_low = count / 2;
103 clk_high = count - clk_low;
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100104 st->current_clk = apb_clk / count;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200105
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100106 __raw_writel(SPEAR_ADC_CLK_LOW(clk_low) | SPEAR_ADC_CLK_HIGH(clk_high),
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100107 &st->adc_base_spear6xx->clk);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200108}
109
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100110static void spear_adc_set_ctrl(struct spear_adc_state *st, int n,
Stefan Roeseb3201b52012-04-12 11:05:35 +0200111 u32 val)
112{
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100113 __raw_writel(val, &st->adc_base_spear6xx->ch_ctrl[n]);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200114}
115
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100116static u32 spear_adc_get_average(struct spear_adc_state *st)
Stefan Roeseb3201b52012-04-12 11:05:35 +0200117{
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100118 if (of_device_is_compatible(st->np, "st,spear600-adc")) {
119 return __raw_readl(&st->adc_base_spear6xx->average.msb) &
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100120 SPEAR_ADC_DATA_MASK;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200121 } else {
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100122 return __raw_readl(&st->adc_base_spear3xx->average) &
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100123 SPEAR_ADC_DATA_MASK;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200124 }
125}
126
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100127static void spear_adc_set_scanrate(struct spear_adc_state *st, u32 rate)
Stefan Roeseb3201b52012-04-12 11:05:35 +0200128{
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100129 if (of_device_is_compatible(st->np, "st,spear600-adc")) {
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100130 __raw_writel(SPEAR600_ADC_SCAN_RATE_LO(rate),
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100131 &st->adc_base_spear6xx->scan_rate_lo);
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100132 __raw_writel(SPEAR600_ADC_SCAN_RATE_HI(rate),
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100133 &st->adc_base_spear6xx->scan_rate_hi);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200134 } else {
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100135 __raw_writel(rate, &st->adc_base_spear3xx->scan_rate);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200136 }
137}
138
Jonathan Camerone20d6092014-05-04 17:45:00 +0100139static int spear_adc_read_raw(struct iio_dev *indio_dev,
140 struct iio_chan_spec const *chan,
141 int *val,
142 int *val2,
143 long mask)
Stefan Roeseb3201b52012-04-12 11:05:35 +0200144{
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100145 struct spear_adc_state *st = iio_priv(indio_dev);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200146 u32 status;
147
148 switch (mask) {
Jonathan Cameronb11f98f2012-04-15 17:41:18 +0100149 case IIO_CHAN_INFO_RAW:
Stefan Roeseb3201b52012-04-12 11:05:35 +0200150 mutex_lock(&indio_dev->mlock);
151
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100152 status = SPEAR_ADC_STATUS_CHANNEL_NUM(chan->channel) |
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100153 SPEAR_ADC_STATUS_AVG_SAMPLE(st->avg_samples) |
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100154 SPEAR_ADC_STATUS_START_CONVERSION |
155 SPEAR_ADC_STATUS_ADC_ENABLE;
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100156 if (st->vref_external == 0)
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100157 status |= SPEAR_ADC_STATUS_VREF_INTERNAL;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200158
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100159 spear_adc_set_status(st, status);
160 wait_for_completion(&st->completion); /* set by ISR */
161 *val = st->value;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200162
163 mutex_unlock(&indio_dev->mlock);
164
165 return IIO_VAL_INT;
166
167 case IIO_CHAN_INFO_SCALE:
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100168 *val = st->vref_external;
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100169 *val2 = SPEAR_ADC_DATA_BITS;
Lars-Peter Clausenbfbab2b2013-09-28 10:31:00 +0100170 return IIO_VAL_FRACTIONAL_LOG2;
Jonathan Cameron932de742014-05-04 17:45:00 +0100171 case IIO_CHAN_INFO_SAMP_FREQ:
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100172 *val = st->current_clk;
Jonathan Cameron932de742014-05-04 17:45:00 +0100173 return IIO_VAL_INT;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200174 }
175
176 return -EINVAL;
177}
178
Jonathan Cameron932de742014-05-04 17:45:00 +0100179static int spear_adc_write_raw(struct iio_dev *indio_dev,
180 struct iio_chan_spec const *chan,
181 int val,
182 int val2,
183 long mask)
184{
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100185 struct spear_adc_state *st = iio_priv(indio_dev);
Jonathan Cameron932de742014-05-04 17:45:00 +0100186 int ret = 0;
187
188 if (mask != IIO_CHAN_INFO_SAMP_FREQ)
189 return -EINVAL;
190
191 mutex_lock(&indio_dev->mlock);
192
193 if ((val < SPEAR_ADC_CLK_MIN) ||
Ioana Ciorneie8ef49f2015-10-14 21:14:13 +0300194 (val > SPEAR_ADC_CLK_MAX) ||
195 (val2 != 0)) {
Jonathan Cameron932de742014-05-04 17:45:00 +0100196 ret = -EINVAL;
197 goto out;
198 }
199
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100200 spear_adc_set_clk(st, val);
Jonathan Cameron932de742014-05-04 17:45:00 +0100201
202out:
203 mutex_unlock(&indio_dev->mlock);
204 return ret;
205}
206
Stefan Roeseb3201b52012-04-12 11:05:35 +0200207#define SPEAR_ADC_CHAN(idx) { \
208 .type = IIO_VOLTAGE, \
209 .indexed = 1, \
Jonathan Cameronf1e067b2013-03-04 21:06:04 +0000210 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
211 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
Jonathan Cameron932de742014-05-04 17:45:00 +0100212 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
Stefan Roeseb3201b52012-04-12 11:05:35 +0200213 .channel = idx, \
Stefan Roeseb3201b52012-04-12 11:05:35 +0200214}
215
Lars-Peter Clausenf4e4b952012-08-09 08:51:00 +0100216static const struct iio_chan_spec spear_adc_iio_channels[] = {
Stefan Roeseb3201b52012-04-12 11:05:35 +0200217 SPEAR_ADC_CHAN(0),
218 SPEAR_ADC_CHAN(1),
219 SPEAR_ADC_CHAN(2),
220 SPEAR_ADC_CHAN(3),
221 SPEAR_ADC_CHAN(4),
222 SPEAR_ADC_CHAN(5),
223 SPEAR_ADC_CHAN(6),
224 SPEAR_ADC_CHAN(7),
225};
226
227static irqreturn_t spear_adc_isr(int irq, void *dev_id)
228{
Tapasweni Pathak31f8f062014-10-30 17:02:25 +0530229 struct spear_adc_state *st = dev_id;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200230
231 /* Read value to clear IRQ */
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100232 st->value = spear_adc_get_average(st);
233 complete(&st->completion);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200234
235 return IRQ_HANDLED;
236}
237
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100238static int spear_adc_configure(struct spear_adc_state *st)
Stefan Roeseb3201b52012-04-12 11:05:35 +0200239{
240 int i;
241
242 /* Reset ADC core */
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100243 spear_adc_set_status(st, 0);
244 __raw_writel(0, &st->adc_base_spear6xx->clk);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200245 for (i = 0; i < 8; i++)
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100246 spear_adc_set_ctrl(st, i, 0);
247 spear_adc_set_scanrate(st, 0);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200248
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100249 spear_adc_set_clk(st, st->sampling_freq);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200250
251 return 0;
252}
253
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100254static const struct iio_info spear_adc_info = {
Jonathan Camerone20d6092014-05-04 17:45:00 +0100255 .read_raw = &spear_adc_read_raw,
Jonathan Cameron932de742014-05-04 17:45:00 +0100256 .write_raw = &spear_adc_write_raw,
Stefan Roeseb3201b52012-04-12 11:05:35 +0200257 .driver_module = THIS_MODULE,
258};
259
Bill Pemberton4ae1c612012-11-19 13:21:57 -0500260static int spear_adc_probe(struct platform_device *pdev)
Stefan Roeseb3201b52012-04-12 11:05:35 +0200261{
262 struct device_node *np = pdev->dev.of_node;
263 struct device *dev = &pdev->dev;
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100264 struct spear_adc_state *st;
Amitoj Kaur Chawla09b9da32016-02-29 13:03:46 +0530265 struct resource *res;
Jonathan Camerone90ba522014-05-04 17:45:00 +0100266 struct iio_dev *indio_dev = NULL;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200267 int ret = -ENODEV;
268 int irq;
269
Jonathan Camerone90ba522014-05-04 17:45:00 +0100270 indio_dev = devm_iio_device_alloc(dev, sizeof(struct spear_adc_state));
271 if (!indio_dev) {
Stefan Roeseb3201b52012-04-12 11:05:35 +0200272 dev_err(dev, "failed allocating iio device\n");
Sachin Kamat8c7f6d52013-07-22 12:02:00 +0100273 return -ENOMEM;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200274 }
275
Jonathan Camerone90ba522014-05-04 17:45:00 +0100276 st = iio_priv(indio_dev);
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100277 st->np = np;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200278
279 /*
280 * SPEAr600 has a different register layout than other SPEAr SoC's
281 * (e.g. SPEAr3xx). Let's provide two register base addresses
282 * to support multi-arch kernels.
283 */
Amitoj Kaur Chawla09b9da32016-02-29 13:03:46 +0530284 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
285 st->adc_base_spear6xx = devm_ioremap_resource(&pdev->dev, res);
286 if (IS_ERR(st->adc_base_spear6xx))
287 return PTR_ERR(st->adc_base_spear6xx);
288
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100289 st->adc_base_spear3xx =
290 (struct adc_regs_spear3xx __iomem *)st->adc_base_spear6xx;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200291
Gujulan Elango, Hari Prasath (H.)b8cc27c2016-02-02 12:56:32 +0000292 st->clk = devm_clk_get(dev, NULL);
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100293 if (IS_ERR(st->clk)) {
Stefan Roeseb3201b52012-04-12 11:05:35 +0200294 dev_err(dev, "failed getting clock\n");
Amitoj Kaur Chawla09b9da32016-02-29 13:03:46 +0530295 return PTR_ERR(st->clk);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200296 }
297
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100298 ret = clk_prepare_enable(st->clk);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200299 if (ret) {
300 dev_err(dev, "failed enabling clock\n");
Amitoj Kaur Chawla09b9da32016-02-29 13:03:46 +0530301 return ret;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200302 }
303
304 irq = platform_get_irq(pdev, 0);
Lars-Peter Clausena47f6e02013-10-16 21:45:00 +0100305 if (irq <= 0) {
Stefan Roeseb3201b52012-04-12 11:05:35 +0200306 dev_err(dev, "failed getting interrupt resource\n");
307 ret = -EINVAL;
Gujulan Elango, Hari Prasath (H.)b8cc27c2016-02-02 12:56:32 +0000308 goto errout2;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200309 }
310
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100311 ret = devm_request_irq(dev, irq, spear_adc_isr, 0, SPEAR_ADC_MOD_NAME,
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100312 st);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200313 if (ret < 0) {
314 dev_err(dev, "failed requesting interrupt\n");
Gujulan Elango, Hari Prasath (H.)b8cc27c2016-02-02 12:56:32 +0000315 goto errout2;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200316 }
317
318 if (of_property_read_u32(np, "sampling-frequency",
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100319 &st->sampling_freq)) {
Stefan Roeseb3201b52012-04-12 11:05:35 +0200320 dev_err(dev, "sampling-frequency missing in DT\n");
321 ret = -EINVAL;
Gujulan Elango, Hari Prasath (H.)b8cc27c2016-02-02 12:56:32 +0000322 goto errout2;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200323 }
324
325 /*
326 * Optional avg_samples defaults to 0, resulting in single data
327 * conversion
328 */
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100329 of_property_read_u32(np, "average-samples", &st->avg_samples);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200330
331 /*
332 * Optional vref_external defaults to 0, resulting in internal vref
333 * selection
334 */
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100335 of_property_read_u32(np, "vref-external", &st->vref_external);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200336
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100337 spear_adc_configure(st);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200338
Jonathan Camerone90ba522014-05-04 17:45:00 +0100339 platform_set_drvdata(pdev, indio_dev);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200340
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100341 init_completion(&st->completion);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200342
Jonathan Camerone90ba522014-05-04 17:45:00 +0100343 indio_dev->name = SPEAR_ADC_MOD_NAME;
344 indio_dev->dev.parent = dev;
345 indio_dev->info = &spear_adc_info;
346 indio_dev->modes = INDIO_DIRECT_MODE;
347 indio_dev->channels = spear_adc_iio_channels;
348 indio_dev->num_channels = ARRAY_SIZE(spear_adc_iio_channels);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200349
Jonathan Camerone90ba522014-05-04 17:45:00 +0100350 ret = iio_device_register(indio_dev);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200351 if (ret)
Gujulan Elango, Hari Prasath (H.)b8cc27c2016-02-02 12:56:32 +0000352 goto errout2;
Stefan Roeseb3201b52012-04-12 11:05:35 +0200353
354 dev_info(dev, "SPEAR ADC driver loaded, IRQ %d\n", irq);
355
356 return 0;
357
Stefan Roeseb3201b52012-04-12 11:05:35 +0200358errout2:
Gujulan Elango, Hari Prasath (H.)b8cc27c2016-02-02 12:56:32 +0000359 clk_disable_unprepare(st->clk);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200360 return ret;
361}
362
Bill Pemberton447d4f22012-11-19 13:26:37 -0500363static int spear_adc_remove(struct platform_device *pdev)
Stefan Roeseb3201b52012-04-12 11:05:35 +0200364{
Jonathan Camerone90ba522014-05-04 17:45:00 +0100365 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
366 struct spear_adc_state *st = iio_priv(indio_dev);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200367
Jonathan Camerone90ba522014-05-04 17:45:00 +0100368 iio_device_unregister(indio_dev);
Jonathan Cameronb586e5d2014-05-04 17:45:00 +0100369 clk_disable_unprepare(st->clk);
Stefan Roeseb3201b52012-04-12 11:05:35 +0200370
371 return 0;
372}
373
Sachin Kamate89b6742013-06-07 12:06:00 +0100374#ifdef CONFIG_OF
Stefan Roeseb3201b52012-04-12 11:05:35 +0200375static const struct of_device_id spear_adc_dt_ids[] = {
376 { .compatible = "st,spear600-adc", },
377 { /* sentinel */ }
378};
379MODULE_DEVICE_TABLE(of, spear_adc_dt_ids);
Sachin Kamate89b6742013-06-07 12:06:00 +0100380#endif
Stefan Roeseb3201b52012-04-12 11:05:35 +0200381
382static struct platform_driver spear_adc_driver = {
383 .probe = spear_adc_probe,
Bill Pembertone543acf2012-11-19 13:21:38 -0500384 .remove = spear_adc_remove,
Stefan Roeseb3201b52012-04-12 11:05:35 +0200385 .driver = {
Jonathan Cameronb64aef72014-05-04 17:45:00 +0100386 .name = SPEAR_ADC_MOD_NAME,
Stefan Roeseb3201b52012-04-12 11:05:35 +0200387 .of_match_table = of_match_ptr(spear_adc_dt_ids),
388 },
389};
390
391module_platform_driver(spear_adc_driver);
392
393MODULE_AUTHOR("Stefan Roese <sr@denx.de>");
394MODULE_DESCRIPTION("SPEAr ADC driver");
395MODULE_LICENSE("GPL");