Skip to content

Commit adb4e3f

Browse files
chanwoochoijic23
authored andcommitted
iio: adc: exynos_adc: Control special clock of ADC to support Exynos3250 ADC
This patch control special clock for ADC in Exynos series's FSYS block. If special clock of ADC is registerd on clock list of common clk framework, Exynos ADC drvier have to control this clock. Exynos3250/Exynos4/Exynos5 has 'adc' clock as following: - 'adc' clock: bus clock for ADC Exynos3250 has additional 'sclk_adc' clock as following: - 'sclk_adc' clock: special clock for ADC which provide clock to internal ADC Exynos 4210/4212/4412 and Exynos5250/5420 has not included 'sclk_adc' clock in FSYS_BLK. But, Exynos3250 based on Cortex-A7 has only included 'sclk_adc' clock in FSYS_BLK. Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> Acked-by: Kyungmin Park <kyungmin.park@samsung.com> Reviewed-by: Tomasz Figa <t.figa@samsung.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent e49d99e commit adb4e3f

1 file changed

Lines changed: 103 additions & 8 deletions

File tree

‎drivers/iio/adc/exynos_adc.c‎

Lines changed: 103 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/platform_device.h>
2525
#include <linux/interrupt.h>
2626
#include <linux/delay.h>
27+
#include <linux/errno.h>
2728
#include <linux/kernel.h>
2829
#include <linux/slab.h>
2930
#include <linux/io.h>
@@ -70,8 +71,9 @@
7071
#define ADC_V2_CON2_ACH_SEL(x) (((x) & 0xF) << 0)
7172
#define ADC_V2_CON2_ACH_MASK 0xF
7273

73-
#define MAX_ADC_V2_CHANNELS 10
74-
#define MAX_ADC_V1_CHANNELS 8
74+
#define MAX_ADC_V2_CHANNELS 10
75+
#define MAX_ADC_V1_CHANNELS 8
76+
#define MAX_EXYNOS3250_ADC_CHANNELS 2
7577

7678
/* Bit definitions common for ADC_V1 and ADC_V2 */
7779
#define ADC_CON_EN_START (1u << 0)
@@ -81,9 +83,11 @@
8183

8284
struct exynos_adc {
8385
struct exynos_adc_data *data;
86+
struct device *dev;
8487
void __iomem *regs;
8588
void __iomem *enable_reg;
8689
struct clk *clk;
90+
struct clk *sclk;
8791
unsigned int irq;
8892
struct regulator *vdd;
8993

@@ -95,13 +99,74 @@ struct exynos_adc {
9599

96100
struct exynos_adc_data {
97101
int num_channels;
102+
bool needs_sclk;
98103

99104
void (*init_hw)(struct exynos_adc *info);
100105
void (*exit_hw)(struct exynos_adc *info);
101106
void (*clear_irq)(struct exynos_adc *info);
102107
void (*start_conv)(struct exynos_adc *info, unsigned long addr);
103108
};
104109

110+
static void exynos_adc_unprepare_clk(struct exynos_adc *info)
111+
{
112+
if (info->data->needs_sclk)
113+
clk_unprepare(info->sclk);
114+
clk_unprepare(info->clk);
115+
}
116+
117+
static int exynos_adc_prepare_clk(struct exynos_adc *info)
118+
{
119+
int ret;
120+
121+
ret = clk_prepare(info->clk);
122+
if (ret) {
123+
dev_err(info->dev, "failed preparing adc clock: %d\n", ret);
124+
return ret;
125+
}
126+
127+
if (info->data->needs_sclk) {
128+
ret = clk_prepare(info->sclk);
129+
if (ret) {
130+
clk_unprepare(info->clk);
131+
dev_err(info->dev,
132+
"failed preparing sclk_adc clock: %d\n", ret);
133+
return ret;
134+
}
135+
}
136+
137+
return 0;
138+
}
139+
140+
static void exynos_adc_disable_clk(struct exynos_adc *info)
141+
{
142+
if (info->data->needs_sclk)
143+
clk_disable(info->sclk);
144+
clk_disable(info->clk);
145+
}
146+
147+
static int exynos_adc_enable_clk(struct exynos_adc *info)
148+
{
149+
int ret;
150+
151+
ret = clk_enable(info->clk);
152+
if (ret) {
153+
dev_err(info->dev, "failed enabling adc clock: %d\n", ret);
154+
return ret;
155+
}
156+
157+
if (info->data->needs_sclk) {
158+
ret = clk_enable(info->sclk);
159+
if (ret) {
160+
clk_disable(info->clk);
161+
dev_err(info->dev,
162+
"failed enabling sclk_adc clock: %d\n", ret);
163+
return ret;
164+
}
165+
}
166+
167+
return 0;
168+
}
169+
105170
static void exynos_adc_v1_init_hw(struct exynos_adc *info)
106171
{
107172
u32 con1;
@@ -208,13 +273,26 @@ static const struct exynos_adc_data exynos_adc_v2_data = {
208273
.start_conv = exynos_adc_v2_start_conv,
209274
};
210275

276+
static const struct exynos_adc_data exynos3250_adc_data = {
277+
.num_channels = MAX_EXYNOS3250_ADC_CHANNELS,
278+
.needs_sclk = true,
279+
280+
.init_hw = exynos_adc_v2_init_hw,
281+
.exit_hw = exynos_adc_v2_exit_hw,
282+
.clear_irq = exynos_adc_v2_clear_irq,
283+
.start_conv = exynos_adc_v2_start_conv,
284+
};
285+
211286
static const struct of_device_id exynos_adc_match[] = {
212287
{
213288
.compatible = "samsung,exynos-adc-v1",
214289
.data = &exynos_adc_v1_data,
215290
}, {
216291
.compatible = "samsung,exynos-adc-v2",
217292
.data = &exynos_adc_v2_data,
293+
}, {
294+
.compatible = "samsung,exynos3250-adc",
295+
.data = &exynos3250_adc_data,
218296
},
219297
{},
220298
};
@@ -376,6 +454,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
376454
}
377455

378456
info->irq = irq;
457+
info->dev = &pdev->dev;
379458

380459
init_completion(&info->completion);
381460

@@ -386,6 +465,16 @@ static int exynos_adc_probe(struct platform_device *pdev)
386465
return PTR_ERR(info->clk);
387466
}
388467

468+
if (info->data->needs_sclk) {
469+
info->sclk = devm_clk_get(&pdev->dev, "sclk");
470+
if (IS_ERR(info->sclk)) {
471+
dev_err(&pdev->dev,
472+
"failed getting sclk clock, err = %ld\n",
473+
PTR_ERR(info->sclk));
474+
return PTR_ERR(info->sclk);
475+
}
476+
}
477+
389478
info->vdd = devm_regulator_get(&pdev->dev, "vdd");
390479
if (IS_ERR(info->vdd)) {
391480
dev_err(&pdev->dev, "failed getting regulator, err = %ld\n",
@@ -397,10 +486,14 @@ static int exynos_adc_probe(struct platform_device *pdev)
397486
if (ret)
398487
return ret;
399488

400-
ret = clk_prepare_enable(info->clk);
489+
ret = exynos_adc_prepare_clk(info);
401490
if (ret)
402491
goto err_disable_reg;
403492

493+
ret = exynos_adc_enable_clk(info);
494+
if (ret)
495+
goto err_unprepare_clk;
496+
404497
platform_set_drvdata(pdev, indio_dev);
405498

406499
indio_dev->name = dev_name(&pdev->dev);
@@ -443,7 +536,9 @@ static int exynos_adc_probe(struct platform_device *pdev)
443536
err_disable_clk:
444537
if (info->data->exit_hw)
445538
info->data->exit_hw(info);
446-
clk_disable_unprepare(info->clk);
539+
exynos_adc_disable_clk(info);
540+
err_unprepare_clk:
541+
exynos_adc_unprepare_clk(info);
447542
err_disable_reg:
448543
regulator_disable(info->vdd);
449544
return ret;
@@ -460,7 +555,8 @@ static int exynos_adc_remove(struct platform_device *pdev)
460555
free_irq(info->irq, info);
461556
if (info->data->exit_hw)
462557
info->data->exit_hw(info);
463-
clk_disable_unprepare(info->clk);
558+
exynos_adc_disable_clk(info);
559+
exynos_adc_unprepare_clk(info);
464560
regulator_disable(info->vdd);
465561

466562
return 0;
@@ -474,8 +570,7 @@ static int exynos_adc_suspend(struct device *dev)
474570

475571
if (info->data->exit_hw)
476572
info->data->exit_hw(info);
477-
478-
clk_disable_unprepare(info->clk);
573+
exynos_adc_disable_clk(info);
479574
regulator_disable(info->vdd);
480575

481576
return 0;
@@ -491,7 +586,7 @@ static int exynos_adc_resume(struct device *dev)
491586
if (ret)
492587
return ret;
493588

494-
ret = clk_prepare_enable(info->clk);
589+
ret = exynos_adc_enable_clk(info);
495590
if (ret)
496591
return ret;
497592

0 commit comments

Comments
 (0)