2 * exynos_adc.c - Support for ADC in EXYNOS SoCs
4 * 8 ~ 10 channel, 10/12-bit ADC
6 * Copyright (C) 2013 Naveen Krishna Chatradhi <ch.naveen@samsung.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <linux/interrupt.h>
26 #include <linux/delay.h>
27 #include <linux/errno.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
31 #include <linux/clk.h>
32 #include <linux/completion.h>
34 #include <linux/of_irq.h>
35 #include <linux/regulator/consumer.h>
36 #include <linux/of_platform.h>
37 #include <linux/err.h>
38 #include <linux/input.h>
40 #include <linux/iio/iio.h>
41 #include <linux/iio/machine.h>
42 #include <linux/iio/driver.h>
43 #include <linux/mfd/syscon.h>
44 #include <linux/regmap.h>
46 #include <linux/platform_data/touchscreen-s3c2410.h>
48 /* S3C/EXYNOS4412/5250 ADC_V1 registers definitions */
49 #define ADC_V1_CON(x) ((x) + 0x00)
50 #define ADC_V1_TSC(x) ((x) + 0x04)
51 #define ADC_V1_DLY(x) ((x) + 0x08)
52 #define ADC_V1_DATX(x) ((x) + 0x0C)
53 #define ADC_V1_DATY(x) ((x) + 0x10)
54 #define ADC_V1_UPDN(x) ((x) + 0x14)
55 #define ADC_V1_INTCLR(x) ((x) + 0x18)
56 #define ADC_V1_MUX(x) ((x) + 0x1c)
57 #define ADC_V1_CLRINTPNDNUP(x) ((x) + 0x20)
59 /* S3C2410 ADC registers definitions */
60 #define ADC_S3C2410_MUX(x) ((x) + 0x18)
62 /* Future ADC_V2 registers definitions */
63 #define ADC_V2_CON1(x) ((x) + 0x00)
64 #define ADC_V2_CON2(x) ((x) + 0x04)
65 #define ADC_V2_STAT(x) ((x) + 0x08)
66 #define ADC_V2_INT_EN(x) ((x) + 0x10)
67 #define ADC_V2_INT_ST(x) ((x) + 0x14)
68 #define ADC_V2_VER(x) ((x) + 0x20)
70 /* Bit definitions for ADC_V1 */
71 #define ADC_V1_CON_RES (1u << 16)
72 #define ADC_V1_CON_PRSCEN (1u << 14)
73 #define ADC_V1_CON_PRSCLV(x) (((x) & 0xFF) << 6)
74 #define ADC_V1_CON_STANDBY (1u << 2)
76 /* Bit definitions for S3C2410 ADC */
77 #define ADC_S3C2410_CON_SELMUX(x) (((x) & 7) << 3)
78 #define ADC_S3C2410_DATX_MASK 0x3FF
79 #define ADC_S3C2416_CON_RES_SEL (1u << 3)
81 /* touch screen always uses channel 0 */
82 #define ADC_S3C2410_MUX_TS 0
84 /* ADCTSC Register Bits */
85 #define ADC_S3C2443_TSC_UD_SEN (1u << 8)
86 #define ADC_S3C2410_TSC_YM_SEN (1u << 7)
87 #define ADC_S3C2410_TSC_YP_SEN (1u << 6)
88 #define ADC_S3C2410_TSC_XM_SEN (1u << 5)
89 #define ADC_S3C2410_TSC_XP_SEN (1u << 4)
90 #define ADC_S3C2410_TSC_PULL_UP_DISABLE (1u << 3)
91 #define ADC_S3C2410_TSC_AUTO_PST (1u << 2)
92 #define ADC_S3C2410_TSC_XY_PST(x) (((x) & 0x3) << 0)
94 #define ADC_TSC_WAIT4INT (ADC_S3C2410_TSC_YM_SEN | \
95 ADC_S3C2410_TSC_YP_SEN | \
96 ADC_S3C2410_TSC_XP_SEN | \
97 ADC_S3C2410_TSC_XY_PST(3))
99 #define ADC_TSC_AUTOPST (ADC_S3C2410_TSC_YM_SEN | \
100 ADC_S3C2410_TSC_YP_SEN | \
101 ADC_S3C2410_TSC_XP_SEN | \
102 ADC_S3C2410_TSC_AUTO_PST | \
103 ADC_S3C2410_TSC_XY_PST(0))
105 /* Bit definitions for ADC_V2 */
106 #define ADC_V2_CON1_SOFT_RESET (1u << 2)
108 #define ADC_V2_CON2_OSEL (1u << 10)
109 #define ADC_V2_CON2_ESEL (1u << 9)
110 #define ADC_V2_CON2_HIGHF (1u << 8)
111 #define ADC_V2_CON2_C_TIME(x) (((x) & 7) << 4)
112 #define ADC_V2_CON2_ACH_SEL(x) (((x) & 0xF) << 0)
113 #define ADC_V2_CON2_ACH_MASK 0xF
115 #define MAX_ADC_V2_CHANNELS 10
116 #define MAX_ADC_V1_CHANNELS 8
117 #define MAX_EXYNOS3250_ADC_CHANNELS 2
119 /* Bit definitions common for ADC_V1 and ADC_V2 */
120 #define ADC_CON_EN_START (1u << 0)
121 #define ADC_CON_EN_START_MASK (0x3 << 0)
122 #define ADC_DATX_PRESSED (1u << 15)
123 #define ADC_DATX_MASK 0xFFF
124 #define ADC_DATY_MASK 0xFFF
126 #define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100))
128 #define EXYNOS_ADCV1_PHY_OFFSET 0x0718
129 #define EXYNOS_ADCV2_PHY_OFFSET 0x0720
132 struct exynos_adc_data
*data
;
134 struct input_dev
*input
;
136 struct regmap
*pmu_map
;
142 struct regulator
*vdd
;
144 struct completion completion
;
147 unsigned int version
;
154 struct exynos_adc_data
{
161 void (*init_hw
)(struct exynos_adc
*info
);
162 void (*exit_hw
)(struct exynos_adc
*info
);
163 void (*clear_irq
)(struct exynos_adc
*info
);
164 void (*start_conv
)(struct exynos_adc
*info
, unsigned long addr
);
167 static void exynos_adc_unprepare_clk(struct exynos_adc
*info
)
169 if (info
->data
->needs_sclk
)
170 clk_unprepare(info
->sclk
);
171 clk_unprepare(info
->clk
);
174 static int exynos_adc_prepare_clk(struct exynos_adc
*info
)
178 ret
= clk_prepare(info
->clk
);
180 dev_err(info
->dev
, "failed preparing adc clock: %d\n", ret
);
184 if (info
->data
->needs_sclk
) {
185 ret
= clk_prepare(info
->sclk
);
187 clk_unprepare(info
->clk
);
189 "failed preparing sclk_adc clock: %d\n", ret
);
197 static void exynos_adc_disable_clk(struct exynos_adc
*info
)
199 if (info
->data
->needs_sclk
)
200 clk_disable(info
->sclk
);
201 clk_disable(info
->clk
);
204 static int exynos_adc_enable_clk(struct exynos_adc
*info
)
208 ret
= clk_enable(info
->clk
);
210 dev_err(info
->dev
, "failed enabling adc clock: %d\n", ret
);
214 if (info
->data
->needs_sclk
) {
215 ret
= clk_enable(info
->sclk
);
217 clk_disable(info
->clk
);
219 "failed enabling sclk_adc clock: %d\n", ret
);
227 static void exynos_adc_v1_init_hw(struct exynos_adc
*info
)
231 if (info
->data
->needs_adc_phy
)
232 regmap_write(info
->pmu_map
, info
->data
->phy_offset
, 1);
234 /* set default prescaler values and Enable prescaler */
235 con1
= ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN
;
237 /* Enable 12-bit ADC resolution */
238 con1
|= ADC_V1_CON_RES
;
239 writel(con1
, ADC_V1_CON(info
->regs
));
241 /* set touchscreen delay */
242 writel(info
->delay
, ADC_V1_DLY(info
->regs
));
245 static void exynos_adc_v1_exit_hw(struct exynos_adc
*info
)
249 if (info
->data
->needs_adc_phy
)
250 regmap_write(info
->pmu_map
, info
->data
->phy_offset
, 0);
252 con
= readl(ADC_V1_CON(info
->regs
));
253 con
|= ADC_V1_CON_STANDBY
;
254 writel(con
, ADC_V1_CON(info
->regs
));
257 static void exynos_adc_v1_clear_irq(struct exynos_adc
*info
)
259 writel(1, ADC_V1_INTCLR(info
->regs
));
262 static void exynos_adc_v1_start_conv(struct exynos_adc
*info
,
267 writel(addr
, ADC_V1_MUX(info
->regs
));
269 con1
= readl(ADC_V1_CON(info
->regs
));
270 writel(con1
| ADC_CON_EN_START
, ADC_V1_CON(info
->regs
));
273 static const struct exynos_adc_data exynos_adc_v1_data
= {
274 .num_channels
= MAX_ADC_V1_CHANNELS
,
275 .mask
= ADC_DATX_MASK
, /* 12 bit ADC resolution */
276 .needs_adc_phy
= true,
277 .phy_offset
= EXYNOS_ADCV1_PHY_OFFSET
,
279 .init_hw
= exynos_adc_v1_init_hw
,
280 .exit_hw
= exynos_adc_v1_exit_hw
,
281 .clear_irq
= exynos_adc_v1_clear_irq
,
282 .start_conv
= exynos_adc_v1_start_conv
,
285 static void exynos_adc_s3c2416_start_conv(struct exynos_adc
*info
,
290 /* Enable 12 bit ADC resolution */
291 con1
= readl(ADC_V1_CON(info
->regs
));
292 con1
|= ADC_S3C2416_CON_RES_SEL
;
293 writel(con1
, ADC_V1_CON(info
->regs
));
295 /* Select channel for S3C2416 */
296 writel(addr
, ADC_S3C2410_MUX(info
->regs
));
298 con1
= readl(ADC_V1_CON(info
->regs
));
299 writel(con1
| ADC_CON_EN_START
, ADC_V1_CON(info
->regs
));
302 static struct exynos_adc_data
const exynos_adc_s3c2416_data
= {
303 .num_channels
= MAX_ADC_V1_CHANNELS
,
304 .mask
= ADC_DATX_MASK
, /* 12 bit ADC resolution */
306 .init_hw
= exynos_adc_v1_init_hw
,
307 .exit_hw
= exynos_adc_v1_exit_hw
,
308 .start_conv
= exynos_adc_s3c2416_start_conv
,
311 static void exynos_adc_s3c2443_start_conv(struct exynos_adc
*info
,
316 /* Select channel for S3C2433 */
317 writel(addr
, ADC_S3C2410_MUX(info
->regs
));
319 con1
= readl(ADC_V1_CON(info
->regs
));
320 writel(con1
| ADC_CON_EN_START
, ADC_V1_CON(info
->regs
));
323 static struct exynos_adc_data
const exynos_adc_s3c2443_data
= {
324 .num_channels
= MAX_ADC_V1_CHANNELS
,
325 .mask
= ADC_S3C2410_DATX_MASK
, /* 10 bit ADC resolution */
327 .init_hw
= exynos_adc_v1_init_hw
,
328 .exit_hw
= exynos_adc_v1_exit_hw
,
329 .start_conv
= exynos_adc_s3c2443_start_conv
,
332 static void exynos_adc_s3c64xx_start_conv(struct exynos_adc
*info
,
337 con1
= readl(ADC_V1_CON(info
->regs
));
338 con1
&= ~ADC_S3C2410_CON_SELMUX(0x7);
339 con1
|= ADC_S3C2410_CON_SELMUX(addr
);
340 writel(con1
| ADC_CON_EN_START
, ADC_V1_CON(info
->regs
));
343 static struct exynos_adc_data
const exynos_adc_s3c24xx_data
= {
344 .num_channels
= MAX_ADC_V1_CHANNELS
,
345 .mask
= ADC_S3C2410_DATX_MASK
, /* 10 bit ADC resolution */
347 .init_hw
= exynos_adc_v1_init_hw
,
348 .exit_hw
= exynos_adc_v1_exit_hw
,
349 .start_conv
= exynos_adc_s3c64xx_start_conv
,
352 static struct exynos_adc_data
const exynos_adc_s3c64xx_data
= {
353 .num_channels
= MAX_ADC_V1_CHANNELS
,
354 .mask
= ADC_DATX_MASK
, /* 12 bit ADC resolution */
356 .init_hw
= exynos_adc_v1_init_hw
,
357 .exit_hw
= exynos_adc_v1_exit_hw
,
358 .clear_irq
= exynos_adc_v1_clear_irq
,
359 .start_conv
= exynos_adc_s3c64xx_start_conv
,
362 static void exynos_adc_v2_init_hw(struct exynos_adc
*info
)
366 if (info
->data
->needs_adc_phy
)
367 regmap_write(info
->pmu_map
, info
->data
->phy_offset
, 1);
369 con1
= ADC_V2_CON1_SOFT_RESET
;
370 writel(con1
, ADC_V2_CON1(info
->regs
));
372 con2
= ADC_V2_CON2_OSEL
| ADC_V2_CON2_ESEL
|
373 ADC_V2_CON2_HIGHF
| ADC_V2_CON2_C_TIME(0);
374 writel(con2
, ADC_V2_CON2(info
->regs
));
376 /* Enable interrupts */
377 writel(1, ADC_V2_INT_EN(info
->regs
));
380 static void exynos_adc_v2_exit_hw(struct exynos_adc
*info
)
384 if (info
->data
->needs_adc_phy
)
385 regmap_write(info
->pmu_map
, info
->data
->phy_offset
, 0);
387 con
= readl(ADC_V2_CON1(info
->regs
));
388 con
&= ~ADC_CON_EN_START
;
389 writel(con
, ADC_V2_CON1(info
->regs
));
392 static void exynos_adc_v2_clear_irq(struct exynos_adc
*info
)
394 writel(1, ADC_V2_INT_ST(info
->regs
));
397 static void exynos_adc_v2_start_conv(struct exynos_adc
*info
,
402 con2
= readl(ADC_V2_CON2(info
->regs
));
403 con2
&= ~ADC_V2_CON2_ACH_MASK
;
404 con2
|= ADC_V2_CON2_ACH_SEL(addr
);
405 writel(con2
, ADC_V2_CON2(info
->regs
));
407 con1
= readl(ADC_V2_CON1(info
->regs
));
408 writel(con1
| ADC_CON_EN_START
, ADC_V2_CON1(info
->regs
));
411 static const struct exynos_adc_data exynos_adc_v2_data
= {
412 .num_channels
= MAX_ADC_V2_CHANNELS
,
413 .mask
= ADC_DATX_MASK
, /* 12 bit ADC resolution */
414 .needs_adc_phy
= true,
415 .phy_offset
= EXYNOS_ADCV2_PHY_OFFSET
,
417 .init_hw
= exynos_adc_v2_init_hw
,
418 .exit_hw
= exynos_adc_v2_exit_hw
,
419 .clear_irq
= exynos_adc_v2_clear_irq
,
420 .start_conv
= exynos_adc_v2_start_conv
,
423 static const struct exynos_adc_data exynos3250_adc_data
= {
424 .num_channels
= MAX_EXYNOS3250_ADC_CHANNELS
,
425 .mask
= ADC_DATX_MASK
, /* 12 bit ADC resolution */
427 .needs_adc_phy
= true,
428 .phy_offset
= EXYNOS_ADCV1_PHY_OFFSET
,
430 .init_hw
= exynos_adc_v2_init_hw
,
431 .exit_hw
= exynos_adc_v2_exit_hw
,
432 .clear_irq
= exynos_adc_v2_clear_irq
,
433 .start_conv
= exynos_adc_v2_start_conv
,
436 static void exynos_adc_exynos7_init_hw(struct exynos_adc
*info
)
440 if (info
->data
->needs_adc_phy
)
441 regmap_write(info
->pmu_map
, info
->data
->phy_offset
, 1);
443 con1
= ADC_V2_CON1_SOFT_RESET
;
444 writel(con1
, ADC_V2_CON1(info
->regs
));
446 con2
= readl(ADC_V2_CON2(info
->regs
));
447 con2
&= ~ADC_V2_CON2_C_TIME(7);
448 con2
|= ADC_V2_CON2_C_TIME(0);
449 writel(con2
, ADC_V2_CON2(info
->regs
));
451 /* Enable interrupts */
452 writel(1, ADC_V2_INT_EN(info
->regs
));
455 static const struct exynos_adc_data exynos7_adc_data
= {
456 .num_channels
= MAX_ADC_V1_CHANNELS
,
457 .mask
= ADC_DATX_MASK
, /* 12 bit ADC resolution */
459 .init_hw
= exynos_adc_exynos7_init_hw
,
460 .exit_hw
= exynos_adc_v2_exit_hw
,
461 .clear_irq
= exynos_adc_v2_clear_irq
,
462 .start_conv
= exynos_adc_v2_start_conv
,
465 static const struct of_device_id exynos_adc_match
[] = {
467 .compatible
= "samsung,s3c2410-adc",
468 .data
= &exynos_adc_s3c24xx_data
,
470 .compatible
= "samsung,s3c2416-adc",
471 .data
= &exynos_adc_s3c2416_data
,
473 .compatible
= "samsung,s3c2440-adc",
474 .data
= &exynos_adc_s3c24xx_data
,
476 .compatible
= "samsung,s3c2443-adc",
477 .data
= &exynos_adc_s3c2443_data
,
479 .compatible
= "samsung,s3c6410-adc",
480 .data
= &exynos_adc_s3c64xx_data
,
482 .compatible
= "samsung,exynos-adc-v1",
483 .data
= &exynos_adc_v1_data
,
485 .compatible
= "samsung,exynos-adc-v2",
486 .data
= &exynos_adc_v2_data
,
488 .compatible
= "samsung,exynos3250-adc",
489 .data
= &exynos3250_adc_data
,
491 .compatible
= "samsung,exynos7-adc",
492 .data
= &exynos7_adc_data
,
496 MODULE_DEVICE_TABLE(of
, exynos_adc_match
);
498 static struct exynos_adc_data
*exynos_adc_get_data(struct platform_device
*pdev
)
500 const struct of_device_id
*match
;
502 match
= of_match_node(exynos_adc_match
, pdev
->dev
.of_node
);
503 return (struct exynos_adc_data
*)match
->data
;
506 static int exynos_read_raw(struct iio_dev
*indio_dev
,
507 struct iio_chan_spec
const *chan
,
512 struct exynos_adc
*info
= iio_priv(indio_dev
);
513 unsigned long timeout
;
516 if (mask
!= IIO_CHAN_INFO_RAW
)
519 mutex_lock(&indio_dev
->mlock
);
520 reinit_completion(&info
->completion
);
522 /* Select the channel to be used and Trigger conversion */
523 if (info
->data
->start_conv
)
524 info
->data
->start_conv(info
, chan
->address
);
526 timeout
= wait_for_completion_timeout(&info
->completion
,
529 dev_warn(&indio_dev
->dev
, "Conversion timed out! Resetting\n");
530 if (info
->data
->init_hw
)
531 info
->data
->init_hw(info
);
539 mutex_unlock(&indio_dev
->mlock
);
544 static int exynos_read_s3c64xx_ts(struct iio_dev
*indio_dev
, int *x
, int *y
)
546 struct exynos_adc
*info
= iio_priv(indio_dev
);
547 unsigned long timeout
;
550 mutex_lock(&indio_dev
->mlock
);
551 info
->read_ts
= true;
553 reinit_completion(&info
->completion
);
555 writel(ADC_S3C2410_TSC_PULL_UP_DISABLE
| ADC_TSC_AUTOPST
,
556 ADC_V1_TSC(info
->regs
));
558 /* Select the ts channel to be used and Trigger conversion */
559 info
->data
->start_conv(info
, ADC_S3C2410_MUX_TS
);
561 timeout
= wait_for_completion_timeout(&info
->completion
,
564 dev_warn(&indio_dev
->dev
, "Conversion timed out! Resetting\n");
565 if (info
->data
->init_hw
)
566 info
->data
->init_hw(info
);
574 info
->read_ts
= false;
575 mutex_unlock(&indio_dev
->mlock
);
580 static irqreturn_t
exynos_adc_isr(int irq
, void *dev_id
)
582 struct exynos_adc
*info
= dev_id
;
583 u32 mask
= info
->data
->mask
;
587 info
->ts_x
= readl(ADC_V1_DATX(info
->regs
));
588 info
->ts_y
= readl(ADC_V1_DATY(info
->regs
));
589 writel(ADC_TSC_WAIT4INT
| ADC_S3C2443_TSC_UD_SEN
, ADC_V1_TSC(info
->regs
));
591 info
->value
= readl(ADC_V1_DATX(info
->regs
)) & mask
;
595 if (info
->data
->clear_irq
)
596 info
->data
->clear_irq(info
);
598 complete(&info
->completion
);
604 * Here we (ab)use a threaded interrupt handler to stay running
605 * for as long as the touchscreen remains pressed, we report
606 * a new event with the latest data and then sleep until the
607 * next timer tick. This mirrors the behavior of the old
608 * driver, with much less code.
610 static irqreturn_t
exynos_ts_isr(int irq
, void *dev_id
)
612 struct exynos_adc
*info
= dev_id
;
613 struct iio_dev
*dev
= dev_get_drvdata(info
->dev
);
618 while (info
->input
->users
) {
619 ret
= exynos_read_s3c64xx_ts(dev
, &x
, &y
);
620 if (ret
== -ETIMEDOUT
)
623 pressed
= x
& y
& ADC_DATX_PRESSED
;
625 input_report_key(info
->input
, BTN_TOUCH
, 0);
626 input_sync(info
->input
);
630 input_report_abs(info
->input
, ABS_X
, x
& ADC_DATX_MASK
);
631 input_report_abs(info
->input
, ABS_Y
, y
& ADC_DATY_MASK
);
632 input_report_key(info
->input
, BTN_TOUCH
, 1);
633 input_sync(info
->input
);
635 usleep_range(1000, 1100);
638 writel(0, ADC_V1_CLRINTPNDNUP(info
->regs
));
643 static int exynos_adc_reg_access(struct iio_dev
*indio_dev
,
644 unsigned reg
, unsigned writeval
,
647 struct exynos_adc
*info
= iio_priv(indio_dev
);
652 *readval
= readl(info
->regs
+ reg
);
657 static const struct iio_info exynos_adc_iio_info
= {
658 .read_raw
= &exynos_read_raw
,
659 .debugfs_reg_access
= &exynos_adc_reg_access
,
662 #define ADC_CHANNEL(_index, _id) { \
663 .type = IIO_VOLTAGE, \
667 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
668 .datasheet_name = _id, \
671 static const struct iio_chan_spec exynos_adc_iio_channels
[] = {
672 ADC_CHANNEL(0, "adc0"),
673 ADC_CHANNEL(1, "adc1"),
674 ADC_CHANNEL(2, "adc2"),
675 ADC_CHANNEL(3, "adc3"),
676 ADC_CHANNEL(4, "adc4"),
677 ADC_CHANNEL(5, "adc5"),
678 ADC_CHANNEL(6, "adc6"),
679 ADC_CHANNEL(7, "adc7"),
680 ADC_CHANNEL(8, "adc8"),
681 ADC_CHANNEL(9, "adc9"),
684 static int exynos_adc_remove_devices(struct device
*dev
, void *c
)
686 struct platform_device
*pdev
= to_platform_device(dev
);
688 platform_device_unregister(pdev
);
693 static int exynos_adc_ts_open(struct input_dev
*dev
)
695 struct exynos_adc
*info
= input_get_drvdata(dev
);
697 enable_irq(info
->tsirq
);
702 static void exynos_adc_ts_close(struct input_dev
*dev
)
704 struct exynos_adc
*info
= input_get_drvdata(dev
);
706 disable_irq(info
->tsirq
);
709 static int exynos_adc_ts_init(struct exynos_adc
*info
)
713 if (info
->tsirq
<= 0)
716 info
->input
= input_allocate_device();
720 info
->input
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
721 info
->input
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
723 input_set_abs_params(info
->input
, ABS_X
, 0, 0x3FF, 0, 0);
724 input_set_abs_params(info
->input
, ABS_Y
, 0, 0x3FF, 0, 0);
726 info
->input
->name
= "S3C24xx TouchScreen";
727 info
->input
->id
.bustype
= BUS_HOST
;
728 info
->input
->open
= exynos_adc_ts_open
;
729 info
->input
->close
= exynos_adc_ts_close
;
731 input_set_drvdata(info
->input
, info
);
733 ret
= input_register_device(info
->input
);
735 input_free_device(info
->input
);
739 disable_irq(info
->tsirq
);
740 ret
= request_threaded_irq(info
->tsirq
, NULL
, exynos_ts_isr
,
741 IRQF_ONESHOT
, "touchscreen", info
);
743 input_unregister_device(info
->input
);
748 static int exynos_adc_probe(struct platform_device
*pdev
)
750 struct exynos_adc
*info
= NULL
;
751 struct device_node
*np
= pdev
->dev
.of_node
;
752 struct s3c2410_ts_mach_info
*pdata
= dev_get_platdata(&pdev
->dev
);
753 struct iio_dev
*indio_dev
= NULL
;
754 struct resource
*mem
;
759 indio_dev
= devm_iio_device_alloc(&pdev
->dev
, sizeof(struct exynos_adc
));
761 dev_err(&pdev
->dev
, "failed allocating iio device\n");
765 info
= iio_priv(indio_dev
);
767 info
->data
= exynos_adc_get_data(pdev
);
769 dev_err(&pdev
->dev
, "failed getting exynos_adc_data\n");
773 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
774 info
->regs
= devm_ioremap_resource(&pdev
->dev
, mem
);
775 if (IS_ERR(info
->regs
))
776 return PTR_ERR(info
->regs
);
779 if (info
->data
->needs_adc_phy
) {
780 info
->pmu_map
= syscon_regmap_lookup_by_phandle(
782 "samsung,syscon-phandle");
783 if (IS_ERR(info
->pmu_map
)) {
784 dev_err(&pdev
->dev
, "syscon regmap lookup failed.\n");
785 return PTR_ERR(info
->pmu_map
);
789 irq
= platform_get_irq(pdev
, 0);
791 dev_err(&pdev
->dev
, "no irq resource?\n");
796 irq
= platform_get_irq(pdev
, 1);
797 if (irq
== -EPROBE_DEFER
)
802 info
->dev
= &pdev
->dev
;
804 init_completion(&info
->completion
);
806 info
->clk
= devm_clk_get(&pdev
->dev
, "adc");
807 if (IS_ERR(info
->clk
)) {
808 dev_err(&pdev
->dev
, "failed getting clock, err = %ld\n",
810 return PTR_ERR(info
->clk
);
813 if (info
->data
->needs_sclk
) {
814 info
->sclk
= devm_clk_get(&pdev
->dev
, "sclk");
815 if (IS_ERR(info
->sclk
)) {
817 "failed getting sclk clock, err = %ld\n",
818 PTR_ERR(info
->sclk
));
819 return PTR_ERR(info
->sclk
);
823 info
->vdd
= devm_regulator_get(&pdev
->dev
, "vdd");
824 if (IS_ERR(info
->vdd
)) {
825 dev_err(&pdev
->dev
, "failed getting regulator, err = %ld\n",
827 return PTR_ERR(info
->vdd
);
830 ret
= regulator_enable(info
->vdd
);
834 ret
= exynos_adc_prepare_clk(info
);
836 goto err_disable_reg
;
838 ret
= exynos_adc_enable_clk(info
);
840 goto err_unprepare_clk
;
842 platform_set_drvdata(pdev
, indio_dev
);
844 indio_dev
->name
= dev_name(&pdev
->dev
);
845 indio_dev
->dev
.parent
= &pdev
->dev
;
846 indio_dev
->dev
.of_node
= pdev
->dev
.of_node
;
847 indio_dev
->info
= &exynos_adc_iio_info
;
848 indio_dev
->modes
= INDIO_DIRECT_MODE
;
849 indio_dev
->channels
= exynos_adc_iio_channels
;
850 indio_dev
->num_channels
= info
->data
->num_channels
;
852 ret
= request_irq(info
->irq
, exynos_adc_isr
,
853 0, dev_name(&pdev
->dev
), info
);
855 dev_err(&pdev
->dev
, "failed requesting irq, irq = %d\n",
857 goto err_disable_clk
;
860 ret
= iio_device_register(indio_dev
);
864 if (info
->data
->init_hw
)
865 info
->data
->init_hw(info
);
867 /* leave out any TS related code if unreachable */
868 if (IS_REACHABLE(CONFIG_INPUT
)) {
869 has_ts
= of_property_read_bool(pdev
->dev
.of_node
,
870 "has-touchscreen") || pdata
;
874 info
->delay
= pdata
->delay
;
879 ret
= exynos_adc_ts_init(info
);
883 ret
= of_platform_populate(np
, exynos_adc_match
, NULL
, &indio_dev
->dev
);
885 dev_err(&pdev
->dev
, "failed adding child nodes\n");
886 goto err_of_populate
;
892 device_for_each_child(&indio_dev
->dev
, NULL
,
893 exynos_adc_remove_devices
);
895 input_unregister_device(info
->input
);
896 free_irq(info
->tsirq
, info
);
899 iio_device_unregister(indio_dev
);
901 free_irq(info
->irq
, info
);
903 if (info
->data
->exit_hw
)
904 info
->data
->exit_hw(info
);
905 exynos_adc_disable_clk(info
);
907 exynos_adc_unprepare_clk(info
);
909 regulator_disable(info
->vdd
);
913 static int exynos_adc_remove(struct platform_device
*pdev
)
915 struct iio_dev
*indio_dev
= platform_get_drvdata(pdev
);
916 struct exynos_adc
*info
= iio_priv(indio_dev
);
918 if (IS_REACHABLE(CONFIG_INPUT
)) {
919 free_irq(info
->tsirq
, info
);
920 input_unregister_device(info
->input
);
922 device_for_each_child(&indio_dev
->dev
, NULL
,
923 exynos_adc_remove_devices
);
924 iio_device_unregister(indio_dev
);
925 free_irq(info
->irq
, info
);
926 if (info
->data
->exit_hw
)
927 info
->data
->exit_hw(info
);
928 exynos_adc_disable_clk(info
);
929 exynos_adc_unprepare_clk(info
);
930 regulator_disable(info
->vdd
);
935 #ifdef CONFIG_PM_SLEEP
936 static int exynos_adc_suspend(struct device
*dev
)
938 struct iio_dev
*indio_dev
= dev_get_drvdata(dev
);
939 struct exynos_adc
*info
= iio_priv(indio_dev
);
941 if (info
->data
->exit_hw
)
942 info
->data
->exit_hw(info
);
943 exynos_adc_disable_clk(info
);
944 regulator_disable(info
->vdd
);
949 static int exynos_adc_resume(struct device
*dev
)
951 struct iio_dev
*indio_dev
= dev_get_drvdata(dev
);
952 struct exynos_adc
*info
= iio_priv(indio_dev
);
955 ret
= regulator_enable(info
->vdd
);
959 ret
= exynos_adc_enable_clk(info
);
963 if (info
->data
->init_hw
)
964 info
->data
->init_hw(info
);
970 static SIMPLE_DEV_PM_OPS(exynos_adc_pm_ops
,
974 static struct platform_driver exynos_adc_driver
= {
975 .probe
= exynos_adc_probe
,
976 .remove
= exynos_adc_remove
,
978 .name
= "exynos-adc",
979 .of_match_table
= exynos_adc_match
,
980 .pm
= &exynos_adc_pm_ops
,
984 module_platform_driver(exynos_adc_driver
);
986 MODULE_AUTHOR("Naveen Krishna Chatradhi <ch.naveen@samsung.com>");
987 MODULE_DESCRIPTION("Samsung EXYNOS5 ADC driver");
988 MODULE_LICENSE("GPL v2");