blob: 8d8c4cc023dbb990989ee298b3e4e8434503ff9d [file] [log] [blame]
Maurus Cuelenaere3929e1e2010-01-14 00:30:31 +01001/* arch/arm/plat-samsung/adc.c
Ben Dooks28ab44c5b2008-12-18 14:20:04 +00002 *
3 * Copyright (c) 2008 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>, <ben-linux@fluff.org>
6 *
Maurus Cuelenaere3929e1e2010-01-14 00:30:31 +01007 * Samsung ADC device core
Ben Dooks28ab44c5b2008-12-18 14:20:04 +00008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License.
12*/
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/platform_device.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040017#include <linux/sched.h>
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000018#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000020#include <linux/err.h>
21#include <linux/clk.h>
22#include <linux/interrupt.h>
23#include <linux/io.h>
MyungJoo Hamf4629042011-07-20 21:08:17 +090024#include <linux/regulator/consumer.h>
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000025
26#include <plat/regs-adc.h>
27#include <plat/adc.h>
28
29/* This driver is designed to control the usage of the ADC block between
30 * the touchscreen and any other drivers that may need to use it, such as
31 * the hwmon driver.
32 *
33 * Priority will be given to the touchscreen driver, but as this itself is
34 * rate limited it should not starve other requests which are processed in
35 * order that they are received.
36 *
37 * Each user registers to get a client block which uniquely identifies it
38 * and stores information such as the necessary functions to callback when
39 * action is required.
40 */
41
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +010042enum s3c_cpu_type {
MyungJoo Ham64df92e2011-07-20 21:08:18 +090043 TYPE_ADCV1, /* S3C24XX */
Heiko Stuebner6247cea2011-10-12 21:34:12 +090044 TYPE_ADCV11, /* S3C2443 */
MyungJoo Ham64df92e2011-07-20 21:08:18 +090045 TYPE_ADCV2, /* S3C64XX, S5P64X0, S5PC100 */
46 TYPE_ADCV3, /* S5PV210, S5PC110, EXYNOS4210 */
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +010047};
48
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000049struct s3c_adc_client {
50 struct platform_device *pdev;
51 struct list_head pend;
Ben Dookse170adc2009-07-18 10:12:27 +010052 wait_queue_head_t *wait;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000053
54 unsigned int nr_samples;
Ben Dookse170adc2009-07-18 10:12:27 +010055 int result;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000056 unsigned char is_ts;
57 unsigned char channel;
58
Ben Dookse170adc2009-07-18 10:12:27 +010059 void (*select_cb)(struct s3c_adc_client *c, unsigned selected);
60 void (*convert_cb)(struct s3c_adc_client *c,
61 unsigned val1, unsigned val2,
Nelson Castillo3f7ea462009-05-08 08:10:12 -050062 unsigned *samples_left);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000063};
64
65struct adc_device {
66 struct platform_device *pdev;
67 struct platform_device *owner;
68 struct clk *clk;
69 struct s3c_adc_client *cur;
70 struct s3c_adc_client *ts_pend;
71 void __iomem *regs;
Ben Dooks1f1f5842010-05-10 13:31:36 +090072 spinlock_t lock;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000073
74 unsigned int prescale;
75
76 int irq;
MyungJoo Hamf4629042011-07-20 21:08:17 +090077 struct regulator *vdd;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000078};
79
80static struct adc_device *adc_dev;
81
Ben Dooks1f1f5842010-05-10 13:31:36 +090082static LIST_HEAD(adc_pending); /* protected by adc_device.lock */
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000083
84#define adc_dbg(_adc, msg...) dev_dbg(&(_adc)->pdev->dev, msg)
85
86static inline void s3c_adc_convert(struct adc_device *adc)
87{
88 unsigned con = readl(adc->regs + S3C2410_ADCCON);
89
90 con |= S3C2410_ADCCON_ENABLE_START;
91 writel(con, adc->regs + S3C2410_ADCCON);
92}
93
94static inline void s3c_adc_select(struct adc_device *adc,
95 struct s3c_adc_client *client)
96{
97 unsigned con = readl(adc->regs + S3C2410_ADCCON);
MyungJoo Ham64df92e2011-07-20 21:08:18 +090098 enum s3c_cpu_type cpu = platform_get_device_id(adc->pdev)->driver_data;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +000099
Ben Dookse170adc2009-07-18 10:12:27 +0100100 client->select_cb(client, 1);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000101
Heiko Stuebnerdf303e02011-10-12 21:34:11 +0900102 if (cpu == TYPE_ADCV1 || cpu == TYPE_ADCV2)
103 con &= ~S3C2410_ADCCON_MUXMASK;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000104 con &= ~S3C2410_ADCCON_STDBM;
105 con &= ~S3C2410_ADCCON_STARTMASK;
106
MyungJoo Ham64df92e2011-07-20 21:08:18 +0900107 if (!client->is_ts) {
108 if (cpu == TYPE_ADCV3)
109 writel(client->channel & 0xf, adc->regs + S5P_ADCMUX);
Heiko Stuebner6247cea2011-10-12 21:34:12 +0900110 else if (cpu == TYPE_ADCV11)
111 writel(client->channel & 0xf,
112 adc->regs + S3C2443_ADCMUX);
MyungJoo Ham64df92e2011-07-20 21:08:18 +0900113 else
114 con |= S3C2410_ADCCON_SELMUX(client->channel);
115 }
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000116
117 writel(con, adc->regs + S3C2410_ADCCON);
118}
119
120static void s3c_adc_dbgshow(struct adc_device *adc)
121{
122 adc_dbg(adc, "CON=%08x, TSC=%08x, DLY=%08x\n",
123 readl(adc->regs + S3C2410_ADCCON),
124 readl(adc->regs + S3C2410_ADCTSC),
125 readl(adc->regs + S3C2410_ADCDLY));
126}
127
Ben Dooksf8c8ac82009-04-17 12:36:49 +0100128static void s3c_adc_try(struct adc_device *adc)
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000129{
130 struct s3c_adc_client *next = adc->ts_pend;
131
132 if (!next && !list_empty(&adc_pending)) {
133 next = list_first_entry(&adc_pending,
134 struct s3c_adc_client, pend);
135 list_del(&next->pend);
136 } else
137 adc->ts_pend = NULL;
138
139 if (next) {
140 adc_dbg(adc, "new client is %p\n", next);
141 adc->cur = next;
142 s3c_adc_select(adc, next);
143 s3c_adc_convert(adc);
144 s3c_adc_dbgshow(adc);
145 }
146}
147
148int s3c_adc_start(struct s3c_adc_client *client,
149 unsigned int channel, unsigned int nr_samples)
150{
151 struct adc_device *adc = adc_dev;
152 unsigned long flags;
153
154 if (!adc) {
155 printk(KERN_ERR "%s: failed to find adc\n", __func__);
156 return -EINVAL;
157 }
158
159 if (client->is_ts && adc->ts_pend)
160 return -EAGAIN;
161
Ben Dooks1f1f5842010-05-10 13:31:36 +0900162 spin_lock_irqsave(&adc->lock, flags);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000163
164 client->channel = channel;
165 client->nr_samples = nr_samples;
166
167 if (client->is_ts)
168 adc->ts_pend = client;
169 else
170 list_add_tail(&client->pend, &adc_pending);
171
172 if (!adc->cur)
173 s3c_adc_try(adc);
Ben Dooks1f1f5842010-05-10 13:31:36 +0900174
175 spin_unlock_irqrestore(&adc->lock, flags);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000176
177 return 0;
178}
179EXPORT_SYMBOL_GPL(s3c_adc_start);
180
Ben Dookse170adc2009-07-18 10:12:27 +0100181static void s3c_convert_done(struct s3c_adc_client *client,
182 unsigned v, unsigned u, unsigned *left)
183{
184 client->result = v;
185 wake_up(client->wait);
186}
187
188int s3c_adc_read(struct s3c_adc_client *client, unsigned int ch)
189{
190 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wake);
191 int ret;
192
193 client->convert_cb = s3c_convert_done;
194 client->wait = &wake;
195 client->result = -1;
196
197 ret = s3c_adc_start(client, ch, 1);
198 if (ret < 0)
199 goto err;
200
201 ret = wait_event_timeout(wake, client->result >= 0, HZ / 2);
202 if (client->result < 0) {
203 ret = -ETIMEDOUT;
204 goto err;
205 }
206
207 client->convert_cb = NULL;
208 return client->result;
209
210err:
211 return ret;
212}
Ryan Mallond3bf3952009-10-14 09:18:30 +1300213EXPORT_SYMBOL_GPL(s3c_adc_read);
Ben Dookse170adc2009-07-18 10:12:27 +0100214
215static void s3c_adc_default_select(struct s3c_adc_client *client,
216 unsigned select)
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000217{
218}
219
220struct s3c_adc_client *s3c_adc_register(struct platform_device *pdev,
Ben Dookse170adc2009-07-18 10:12:27 +0100221 void (*select)(struct s3c_adc_client *client,
222 unsigned int selected),
223 void (*conv)(struct s3c_adc_client *client,
224 unsigned d0, unsigned d1,
Nelson Castillo3f7ea462009-05-08 08:10:12 -0500225 unsigned *samples_left),
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000226 unsigned int is_ts)
227{
228 struct s3c_adc_client *client;
229
230 WARN_ON(!pdev);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000231
232 if (!select)
233 select = s3c_adc_default_select;
234
Ben Dookse170adc2009-07-18 10:12:27 +0100235 if (!pdev)
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000236 return ERR_PTR(-EINVAL);
237
238 client = kzalloc(sizeof(struct s3c_adc_client), GFP_KERNEL);
239 if (!client) {
240 dev_err(&pdev->dev, "no memory for adc client\n");
241 return ERR_PTR(-ENOMEM);
242 }
243
244 client->pdev = pdev;
245 client->is_ts = is_ts;
246 client->select_cb = select;
247 client->convert_cb = conv;
248
249 return client;
250}
251EXPORT_SYMBOL_GPL(s3c_adc_register);
252
253void s3c_adc_release(struct s3c_adc_client *client)
254{
Ben Dooks1f1f5842010-05-10 13:31:36 +0900255 unsigned long flags;
256
257 spin_lock_irqsave(&adc_dev->lock, flags);
258
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000259 /* We should really check that nothing is in progress. */
Ramax Lo0c3ee072009-04-14 23:56:18 +0800260 if (adc_dev->cur == client)
261 adc_dev->cur = NULL;
262 if (adc_dev->ts_pend == client)
263 adc_dev->ts_pend = NULL;
264 else {
265 struct list_head *p, *n;
266 struct s3c_adc_client *tmp;
267
268 list_for_each_safe(p, n, &adc_pending) {
269 tmp = list_entry(p, struct s3c_adc_client, pend);
270 if (tmp == client)
271 list_del(&tmp->pend);
272 }
273 }
274
275 if (adc_dev->cur == NULL)
276 s3c_adc_try(adc_dev);
Ben Dooks1f1f5842010-05-10 13:31:36 +0900277
278 spin_unlock_irqrestore(&adc_dev->lock, flags);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000279 kfree(client);
280}
281EXPORT_SYMBOL_GPL(s3c_adc_release);
282
283static irqreturn_t s3c_adc_irq(int irq, void *pw)
284{
285 struct adc_device *adc = pw;
286 struct s3c_adc_client *client = adc->cur;
Maurus Cuelenaere91492b42010-01-30 18:01:48 +0100287 enum s3c_cpu_type cpu = platform_get_device_id(adc->pdev)->driver_data;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000288 unsigned data0, data1;
289
290 if (!client) {
291 dev_warn(&adc->pdev->dev, "%s: no adc pending\n", __func__);
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +0100292 goto exit;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000293 }
294
295 data0 = readl(adc->regs + S3C2410_ADCDAT0);
296 data1 = readl(adc->regs + S3C2410_ADCDAT1);
297 adc_dbg(adc, "read %d: 0x%04x, 0x%04x\n", client->nr_samples, data0, data1);
298
Nelson Castillo3f7ea462009-05-08 08:10:12 -0500299 client->nr_samples--;
Ben Dookse170adc2009-07-18 10:12:27 +0100300
Heiko Stuebner6247cea2011-10-12 21:34:12 +0900301 if (cpu == TYPE_ADCV1 || cpu == TYPE_ADCV11) {
302 data0 &= 0x3ff;
303 data1 &= 0x3ff;
304 } else {
MyungJoo Ham64df92e2011-07-20 21:08:18 +0900305 /* S3C64XX/S5P ADC resolution is 12-bit */
Maurus Cuelenaere91492b42010-01-30 18:01:48 +0100306 data0 &= 0xfff;
307 data1 &= 0xfff;
Maurus Cuelenaere91492b42010-01-30 18:01:48 +0100308 }
309
Ben Dookse170adc2009-07-18 10:12:27 +0100310 if (client->convert_cb)
Maurus Cuelenaere91492b42010-01-30 18:01:48 +0100311 (client->convert_cb)(client, data0, data1, &client->nr_samples);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000312
Nelson Castillo3f7ea462009-05-08 08:10:12 -0500313 if (client->nr_samples > 0) {
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000314 /* fire another conversion for this */
315
Ben Dookse170adc2009-07-18 10:12:27 +0100316 client->select_cb(client, 1);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000317 s3c_adc_convert(adc);
318 } else {
Ben Dooks1f1f5842010-05-10 13:31:36 +0900319 spin_lock(&adc->lock);
Ben Dookse170adc2009-07-18 10:12:27 +0100320 (client->select_cb)(client, 0);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000321 adc->cur = NULL;
322
323 s3c_adc_try(adc);
Ben Dooks1f1f5842010-05-10 13:31:36 +0900324 spin_unlock(&adc->lock);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000325 }
326
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +0100327exit:
Heiko Stuebner6247cea2011-10-12 21:34:12 +0900328 if (cpu == TYPE_ADCV2 || cpu == TYPE_ADCV3) {
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +0100329 /* Clear ADC interrupt */
330 writel(0, adc->regs + S3C64XX_ADCCLRINT);
331 }
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000332 return IRQ_HANDLED;
333}
334
335static int s3c_adc_probe(struct platform_device *pdev)
336{
337 struct device *dev = &pdev->dev;
338 struct adc_device *adc;
339 struct resource *regs;
340 int ret;
Maurus Cuelenaere91492b42010-01-30 18:01:48 +0100341 unsigned tmp;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000342
343 adc = kzalloc(sizeof(struct adc_device), GFP_KERNEL);
344 if (adc == NULL) {
345 dev_err(dev, "failed to allocate adc_device\n");
346 return -ENOMEM;
347 }
348
Ben Dooks1f1f5842010-05-10 13:31:36 +0900349 spin_lock_init(&adc->lock);
350
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000351 adc->pdev = pdev;
352 adc->prescale = S3C2410_ADCCON_PRSCVL(49);
353
MyungJoo Hamf4629042011-07-20 21:08:17 +0900354 adc->vdd = regulator_get(dev, "vdd");
355 if (IS_ERR(adc->vdd)) {
356 dev_err(dev, "operating without regulator \"vdd\" .\n");
357 ret = PTR_ERR(adc->vdd);
358 goto err_alloc;
359 }
360
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000361 adc->irq = platform_get_irq(pdev, 1);
362 if (adc->irq <= 0) {
363 dev_err(dev, "failed to get adc irq\n");
364 ret = -ENOENT;
MyungJoo Hamf4629042011-07-20 21:08:17 +0900365 goto err_reg;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000366 }
367
368 ret = request_irq(adc->irq, s3c_adc_irq, 0, dev_name(dev), adc);
369 if (ret < 0) {
370 dev_err(dev, "failed to attach adc irq\n");
MyungJoo Hamf4629042011-07-20 21:08:17 +0900371 goto err_reg;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000372 }
373
374 adc->clk = clk_get(dev, "adc");
375 if (IS_ERR(adc->clk)) {
376 dev_err(dev, "failed to get adc clock\n");
377 ret = PTR_ERR(adc->clk);
378 goto err_irq;
379 }
380
381 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
382 if (!regs) {
383 dev_err(dev, "failed to find registers\n");
384 ret = -ENXIO;
385 goto err_clk;
386 }
387
388 adc->regs = ioremap(regs->start, resource_size(regs));
389 if (!adc->regs) {
390 dev_err(dev, "failed to map registers\n");
391 ret = -ENXIO;
392 goto err_clk;
393 }
394
MyungJoo Hamf4629042011-07-20 21:08:17 +0900395 ret = regulator_enable(adc->vdd);
396 if (ret)
397 goto err_ioremap;
398
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000399 clk_enable(adc->clk);
400
Maurus Cuelenaere91492b42010-01-30 18:01:48 +0100401 tmp = adc->prescale | S3C2410_ADCCON_PRSCEN;
MyungJoo Ham64df92e2011-07-20 21:08:18 +0900402 if (platform_get_device_id(pdev)->driver_data != TYPE_ADCV1) {
Maurus Cuelenaere91492b42010-01-30 18:01:48 +0100403 /* Enable 12-bit ADC resolution */
404 tmp |= S3C64XX_ADCCON_RESSEL;
405 }
406 writel(tmp, adc->regs + S3C2410_ADCCON);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000407
408 dev_info(dev, "attached adc driver\n");
409
410 platform_set_drvdata(pdev, adc);
411 adc_dev = adc;
412
413 return 0;
414
MyungJoo Hamf4629042011-07-20 21:08:17 +0900415 err_ioremap:
416 iounmap(adc->regs);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000417 err_clk:
418 clk_put(adc->clk);
419
420 err_irq:
421 free_irq(adc->irq, adc);
MyungJoo Hamf4629042011-07-20 21:08:17 +0900422 err_reg:
423 regulator_put(adc->vdd);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000424 err_alloc:
425 kfree(adc);
426 return ret;
427}
428
Uwe Kleine-Königad4e22f2009-11-24 22:07:10 +0100429static int __devexit s3c_adc_remove(struct platform_device *pdev)
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000430{
431 struct adc_device *adc = platform_get_drvdata(pdev);
432
433 iounmap(adc->regs);
434 free_irq(adc->irq, adc);
435 clk_disable(adc->clk);
MyungJoo Hamf4629042011-07-20 21:08:17 +0900436 regulator_disable(adc->vdd);
437 regulator_put(adc->vdd);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000438 clk_put(adc->clk);
439 kfree(adc);
440
441 return 0;
442}
443
444#ifdef CONFIG_PM
MyungJoo Ham67dcaec2011-07-20 21:08:18 +0900445static int s3c_adc_suspend(struct device *dev)
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000446{
MyungJoo Ham67dcaec2011-07-20 21:08:18 +0900447 struct platform_device *pdev = container_of(dev,
448 struct platform_device, dev);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000449 struct adc_device *adc = platform_get_drvdata(pdev);
Ben Dooks1f1f5842010-05-10 13:31:36 +0900450 unsigned long flags;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000451 u32 con;
452
Ben Dooks1f1f5842010-05-10 13:31:36 +0900453 spin_lock_irqsave(&adc->lock, flags);
454
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000455 con = readl(adc->regs + S3C2410_ADCCON);
456 con |= S3C2410_ADCCON_STDBM;
457 writel(con, adc->regs + S3C2410_ADCCON);
458
Vasily Khoruzhicka0af8b32010-02-18 18:32:29 +0200459 disable_irq(adc->irq);
Ben Dooks1f1f5842010-05-10 13:31:36 +0900460 spin_unlock_irqrestore(&adc->lock, flags);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000461 clk_disable(adc->clk);
MyungJoo Hamf4629042011-07-20 21:08:17 +0900462 regulator_disable(adc->vdd);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000463
464 return 0;
465}
466
MyungJoo Ham67dcaec2011-07-20 21:08:18 +0900467static int s3c_adc_resume(struct device *dev)
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000468{
MyungJoo Ham67dcaec2011-07-20 21:08:18 +0900469 struct platform_device *pdev = container_of(dev,
470 struct platform_device, dev);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000471 struct adc_device *adc = platform_get_drvdata(pdev);
MyungJoo Hamf4629042011-07-20 21:08:17 +0900472 int ret;
MyungJoo Ham67dcaec2011-07-20 21:08:18 +0900473 unsigned long tmp;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000474
MyungJoo Hamf4629042011-07-20 21:08:17 +0900475 ret = regulator_enable(adc->vdd);
476 if (ret)
477 return ret;
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000478 clk_enable(adc->clk);
Vasily Khoruzhicka0af8b32010-02-18 18:32:29 +0200479 enable_irq(adc->irq);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000480
MyungJoo Ham67dcaec2011-07-20 21:08:18 +0900481 tmp = adc->prescale | S3C2410_ADCCON_PRSCEN;
482 /* Enable 12-bit ADC resolution */
483 if (platform_get_device_id(pdev)->driver_data != TYPE_ADCV1)
484 tmp |= S3C64XX_ADCCON_RESSEL;
485 writel(tmp, adc->regs + S3C2410_ADCCON);
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000486
487 return 0;
488}
489
490#else
491#define s3c_adc_suspend NULL
492#define s3c_adc_resume NULL
493#endif
494
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +0100495static struct platform_device_id s3c_adc_driver_ids[] = {
496 {
497 .name = "s3c24xx-adc",
MyungJoo Ham64df92e2011-07-20 21:08:18 +0900498 .driver_data = TYPE_ADCV1,
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +0100499 }, {
Heiko Stuebner6247cea2011-10-12 21:34:12 +0900500 .name = "s3c2443-adc",
501 .driver_data = TYPE_ADCV11,
502 }, {
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +0100503 .name = "s3c64xx-adc",
MyungJoo Ham64df92e2011-07-20 21:08:18 +0900504 .driver_data = TYPE_ADCV2,
505 }, {
506 .name = "samsung-adc-v3",
507 .driver_data = TYPE_ADCV3,
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +0100508 },
509 { }
510};
511MODULE_DEVICE_TABLE(platform, s3c_adc_driver_ids);
512
MyungJoo Ham67dcaec2011-07-20 21:08:18 +0900513static const struct dev_pm_ops adc_pm_ops = {
514 .suspend = s3c_adc_suspend,
515 .resume = s3c_adc_resume,
516};
517
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000518static struct platform_driver s3c_adc_driver = {
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +0100519 .id_table = s3c_adc_driver_ids,
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000520 .driver = {
Maurus Cuelenaerebcedfa92010-01-14 00:30:34 +0100521 .name = "s3c-adc",
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000522 .owner = THIS_MODULE,
MyungJoo Ham67dcaec2011-07-20 21:08:18 +0900523 .pm = &adc_pm_ops,
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000524 },
525 .probe = s3c_adc_probe,
526 .remove = __devexit_p(s3c_adc_remove),
Ben Dooks28ab44c5b2008-12-18 14:20:04 +0000527};
528
529static int __init adc_init(void)
530{
531 int ret;
532
533 ret = platform_driver_register(&s3c_adc_driver);
534 if (ret)
535 printk(KERN_ERR "%s: failed to add adc driver\n", __func__);
536
537 return ret;
538}
539
MyungJoo Hamf4629042011-07-20 21:08:17 +0900540module_init(adc_init);