Skip to content

Commit 145b0a5

Browse files
chanwoochoijic23
authored andcommitted
iio: adc: exynos_adc: Add support for s3c24xx ADC
This patch add support for s3c2410/s3c2416/s3c2440/s3c2443 ADC. The s3c24xx is alomost same as ADCv1. But, There are a little difference as following: - ADCMUX register address - ADCDAT mask (10 bit or 12 bit ADC resolution according to SoC version) - s3c24xx/s3c64xx has not included ADC_PHY enable register Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 249535d commit 145b0a5

3 files changed

Lines changed: 114 additions & 13 deletions

File tree

‎Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ New driver handles the following
1111

1212
Required properties:
1313
- compatible: Must be "samsung,exynos-adc-v1"
14-
for exynos4412/5250 controllers.
14+
for exynos4412/5250 and s5pv210 controllers.
1515
Must be "samsung,exynos-adc-v2" for
1616
future controllers.
1717
Must be "samsung,exynos3250-adc" for
1818
controllers compatible with ADC of Exynos3250.
19+
Must be "samsung,s3c2410-adc" for
20+
the ADC in s3c2410 and compatibles
21+
Must be "samsung,s3c2416-adc" for
22+
the ADC in s3c2416 and compatibles
23+
Must be "samsung,s3c2440-adc" for
24+
the ADC in s3c2440 and compatibles
25+
Must be "samsung,s3c2443-adc" for
26+
the ADC in s3c2443 and compatibles
1927
Must be "samsung,s3c6410-adc" for
2028
the ADC in s3c6410 and compatibles
21-
- reg: Contains ADC register address range (base address and
22-
length) and the address of the phy enable register.
29+
- reg: List of ADC register address range
30+
- The base address and range of ADC register
31+
- The base address and range of ADC_PHY register (every
32+
SoC except for s3c24xx/s3c64xx ADC)
2333
- interrupts: Contains the interrupt information for the timer. The
2434
format is being dependent on which interrupt controller
2535
the Samsung device uses.

‎drivers/iio/adc/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ config AT91_ADC
129129

130130
config EXYNOS_ADC
131131
tristate "Exynos ADC driver support"
132-
depends on ARCH_EXYNOS || (OF && COMPILE_TEST)
132+
depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST)
133133
help
134134
Core support for the ADC block found in the Samsung EXYNOS series
135135
of SoCs for drivers such as the touchscreen and hwmon to use to share

‎drivers/iio/adc/exynos_adc.c‎

Lines changed: 100 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#define ADC_V1_INTCLR(x) ((x) + 0x18)
4848
#define ADC_V1_MUX(x) ((x) + 0x1c)
4949

50+
/* S3C2410 ADC registers definitions */
51+
#define ADC_S3C2410_MUX(x) ((x) + 0x18)
52+
5053
/* Future ADC_V2 registers definitions */
5154
#define ADC_V2_CON1(x) ((x) + 0x00)
5255
#define ADC_V2_CON2(x) ((x) + 0x04)
@@ -63,6 +66,8 @@
6366

6467
/* Bit definitions for S3C2410 ADC */
6568
#define ADC_S3C2410_CON_SELMUX(x) (((x) & 7) << 3)
69+
#define ADC_S3C2410_DATX_MASK 0x3FF
70+
#define ADC_S3C2416_CON_RES_SEL (1u << 3)
6671

6772
/* Bit definitions for ADC_V2 */
6873
#define ADC_V2_CON1_SOFT_RESET (1u << 2)
@@ -80,6 +85,7 @@
8085

8186
/* Bit definitions common for ADC_V1 and ADC_V2 */
8287
#define ADC_CON_EN_START (1u << 0)
88+
#define ADC_CON_EN_START_MASK (0x3 << 0)
8389
#define ADC_DATX_MASK 0xFFF
8490

8591
#define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100))
@@ -103,6 +109,8 @@ struct exynos_adc {
103109
struct exynos_adc_data {
104110
int num_channels;
105111
bool needs_sclk;
112+
bool needs_adc_phy;
113+
u32 mask;
106114

107115
void (*init_hw)(struct exynos_adc *info);
108116
void (*exit_hw)(struct exynos_adc *info);
@@ -174,7 +182,8 @@ static void exynos_adc_v1_init_hw(struct exynos_adc *info)
174182
{
175183
u32 con1;
176184

177-
writel(1, info->enable_reg);
185+
if (info->data->needs_adc_phy)
186+
writel(1, info->enable_reg);
178187

179188
/* set default prescaler values and Enable prescaler */
180189
con1 = ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
@@ -188,7 +197,8 @@ static void exynos_adc_v1_exit_hw(struct exynos_adc *info)
188197
{
189198
u32 con;
190199

191-
writel(0, info->enable_reg);
200+
if (info->data->needs_adc_phy)
201+
writel(0, info->enable_reg);
192202

193203
con = readl(ADC_V1_CON(info->regs));
194204
con |= ADC_V1_CON_STANDBY;
@@ -213,13 +223,62 @@ static void exynos_adc_v1_start_conv(struct exynos_adc *info,
213223

214224
static const struct exynos_adc_data exynos_adc_v1_data = {
215225
.num_channels = MAX_ADC_V1_CHANNELS,
226+
.mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
227+
.needs_adc_phy = true,
216228

217229
.init_hw = exynos_adc_v1_init_hw,
218230
.exit_hw = exynos_adc_v1_exit_hw,
219231
.clear_irq = exynos_adc_v1_clear_irq,
220232
.start_conv = exynos_adc_v1_start_conv,
221233
};
222234

235+
static void exynos_adc_s3c2416_start_conv(struct exynos_adc *info,
236+
unsigned long addr)
237+
{
238+
u32 con1;
239+
240+
/* Enable 12 bit ADC resolution */
241+
con1 = readl(ADC_V1_CON(info->regs));
242+
con1 |= ADC_S3C2416_CON_RES_SEL;
243+
writel(con1, ADC_V1_CON(info->regs));
244+
245+
/* Select channel for S3C2416 */
246+
writel(addr, ADC_S3C2410_MUX(info->regs));
247+
248+
con1 = readl(ADC_V1_CON(info->regs));
249+
writel(con1 | ADC_CON_EN_START, ADC_V1_CON(info->regs));
250+
}
251+
252+
static struct exynos_adc_data const exynos_adc_s3c2416_data = {
253+
.num_channels = MAX_ADC_V1_CHANNELS,
254+
.mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
255+
256+
.init_hw = exynos_adc_v1_init_hw,
257+
.exit_hw = exynos_adc_v1_exit_hw,
258+
.start_conv = exynos_adc_s3c2416_start_conv,
259+
};
260+
261+
static void exynos_adc_s3c2443_start_conv(struct exynos_adc *info,
262+
unsigned long addr)
263+
{
264+
u32 con1;
265+
266+
/* Select channel for S3C2433 */
267+
writel(addr, ADC_S3C2410_MUX(info->regs));
268+
269+
con1 = readl(ADC_V1_CON(info->regs));
270+
writel(con1 | ADC_CON_EN_START, ADC_V1_CON(info->regs));
271+
}
272+
273+
static struct exynos_adc_data const exynos_adc_s3c2443_data = {
274+
.num_channels = MAX_ADC_V1_CHANNELS,
275+
.mask = ADC_S3C2410_DATX_MASK, /* 10 bit ADC resolution */
276+
277+
.init_hw = exynos_adc_v1_init_hw,
278+
.exit_hw = exynos_adc_v1_exit_hw,
279+
.start_conv = exynos_adc_s3c2443_start_conv,
280+
};
281+
223282
static void exynos_adc_s3c64xx_start_conv(struct exynos_adc *info,
224283
unsigned long addr)
225284
{
@@ -231,8 +290,18 @@ static void exynos_adc_s3c64xx_start_conv(struct exynos_adc *info,
231290
writel(con1 | ADC_CON_EN_START, ADC_V1_CON(info->regs));
232291
}
233292

293+
static struct exynos_adc_data const exynos_adc_s3c24xx_data = {
294+
.num_channels = MAX_ADC_V1_CHANNELS,
295+
.mask = ADC_S3C2410_DATX_MASK, /* 10 bit ADC resolution */
296+
297+
.init_hw = exynos_adc_v1_init_hw,
298+
.exit_hw = exynos_adc_v1_exit_hw,
299+
.start_conv = exynos_adc_s3c64xx_start_conv,
300+
};
301+
234302
static struct exynos_adc_data const exynos_adc_s3c64xx_data = {
235303
.num_channels = MAX_ADC_V1_CHANNELS,
304+
.mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
236305

237306
.init_hw = exynos_adc_v1_init_hw,
238307
.exit_hw = exynos_adc_v1_exit_hw,
@@ -244,7 +313,8 @@ static void exynos_adc_v2_init_hw(struct exynos_adc *info)
244313
{
245314
u32 con1, con2;
246315

247-
writel(1, info->enable_reg);
316+
if (info->data->needs_adc_phy)
317+
writel(1, info->enable_reg);
248318

249319
con1 = ADC_V2_CON1_SOFT_RESET;
250320
writel(con1, ADC_V2_CON1(info->regs));
@@ -261,7 +331,8 @@ static void exynos_adc_v2_exit_hw(struct exynos_adc *info)
261331
{
262332
u32 con;
263333

264-
writel(0, info->enable_reg);
334+
if (info->data->needs_adc_phy)
335+
writel(0, info->enable_reg);
265336

266337
con = readl(ADC_V2_CON1(info->regs));
267338
con &= ~ADC_CON_EN_START;
@@ -289,6 +360,8 @@ static void exynos_adc_v2_start_conv(struct exynos_adc *info,
289360

290361
static const struct exynos_adc_data exynos_adc_v2_data = {
291362
.num_channels = MAX_ADC_V2_CHANNELS,
363+
.mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
364+
.needs_adc_phy = true,
292365

293366
.init_hw = exynos_adc_v2_init_hw,
294367
.exit_hw = exynos_adc_v2_exit_hw,
@@ -298,7 +371,9 @@ static const struct exynos_adc_data exynos_adc_v2_data = {
298371

299372
static const struct exynos_adc_data exynos3250_adc_data = {
300373
.num_channels = MAX_EXYNOS3250_ADC_CHANNELS,
374+
.mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
301375
.needs_sclk = true,
376+
.needs_adc_phy = true,
302377

303378
.init_hw = exynos_adc_v2_init_hw,
304379
.exit_hw = exynos_adc_v2_exit_hw,
@@ -308,6 +383,18 @@ static const struct exynos_adc_data exynos3250_adc_data = {
308383

309384
static const struct of_device_id exynos_adc_match[] = {
310385
{
386+
.compatible = "samsung,s3c2410-adc",
387+
.data = &exynos_adc_s3c24xx_data,
388+
}, {
389+
.compatible = "samsung,s3c2416-adc",
390+
.data = &exynos_adc_s3c2416_data,
391+
}, {
392+
.compatible = "samsung,s3c2440-adc",
393+
.data = &exynos_adc_s3c24xx_data,
394+
}, {
395+
.compatible = "samsung,s3c2443-adc",
396+
.data = &exynos_adc_s3c2443_data,
397+
}, {
311398
.compatible = "samsung,s3c6410-adc",
312399
.data = &exynos_adc_s3c64xx_data,
313400
}, {
@@ -373,9 +460,10 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
373460
static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
374461
{
375462
struct exynos_adc *info = (struct exynos_adc *)dev_id;
463+
u32 mask = info->data->mask;
376464

377465
/* Read value */
378-
info->value = readl(ADC_V1_DATX(info->regs)) & ADC_DATX_MASK;
466+
info->value = readl(ADC_V1_DATX(info->regs)) & mask;
379467

380468
/* clear irq */
381469
if (info->data->clear_irq)
@@ -468,10 +556,13 @@ static int exynos_adc_probe(struct platform_device *pdev)
468556
if (IS_ERR(info->regs))
469557
return PTR_ERR(info->regs);
470558

471-
mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
472-
info->enable_reg = devm_ioremap_resource(&pdev->dev, mem);
473-
if (IS_ERR(info->enable_reg))
474-
return PTR_ERR(info->enable_reg);
559+
560+
if (info->data->needs_adc_phy) {
561+
mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
562+
info->enable_reg = devm_ioremap_resource(&pdev->dev, mem);
563+
if (IS_ERR(info->enable_reg))
564+
return PTR_ERR(info->enable_reg);
565+
}
475566

476567
irq = platform_get_irq(pdev, 0);
477568
if (irq < 0) {

0 commit comments

Comments
 (0)