Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chanwoo Choi and committed by
Jonathan Cameron
adb4e3f4 e49d99e0

+103 -8
+103 -8
drivers/iio/adc/exynos_adc.c
··· 24 24 #include <linux/platform_device.h> 25 25 #include <linux/interrupt.h> 26 26 #include <linux/delay.h> 27 + #include <linux/errno.h> 27 28 #include <linux/kernel.h> 28 29 #include <linux/slab.h> 29 30 #include <linux/io.h> ··· 71 70 #define ADC_V2_CON2_ACH_SEL(x) (((x) & 0xF) << 0) 72 71 #define ADC_V2_CON2_ACH_MASK 0xF 73 72 74 - #define MAX_ADC_V2_CHANNELS 10 75 - #define MAX_ADC_V1_CHANNELS 8 73 + #define MAX_ADC_V2_CHANNELS 10 74 + #define MAX_ADC_V1_CHANNELS 8 75 + #define MAX_EXYNOS3250_ADC_CHANNELS 2 76 76 77 77 /* Bit definitions common for ADC_V1 and ADC_V2 */ 78 78 #define ADC_CON_EN_START (1u << 0) ··· 83 81 84 82 struct exynos_adc { 85 83 struct exynos_adc_data *data; 84 + struct device *dev; 86 85 void __iomem *regs; 87 86 void __iomem *enable_reg; 88 87 struct clk *clk; 88 + struct clk *sclk; 89 89 unsigned int irq; 90 90 struct regulator *vdd; 91 91 ··· 99 95 100 96 struct exynos_adc_data { 101 97 int num_channels; 98 + bool needs_sclk; 102 99 103 100 void (*init_hw)(struct exynos_adc *info); 104 101 void (*exit_hw)(struct exynos_adc *info); 105 102 void (*clear_irq)(struct exynos_adc *info); 106 103 void (*start_conv)(struct exynos_adc *info, unsigned long addr); 107 104 }; 105 + 106 + static void exynos_adc_unprepare_clk(struct exynos_adc *info) 107 + { 108 + if (info->data->needs_sclk) 109 + clk_unprepare(info->sclk); 110 + clk_unprepare(info->clk); 111 + } 112 + 113 + static int exynos_adc_prepare_clk(struct exynos_adc *info) 114 + { 115 + int ret; 116 + 117 + ret = clk_prepare(info->clk); 118 + if (ret) { 119 + dev_err(info->dev, "failed preparing adc clock: %d\n", ret); 120 + return ret; 121 + } 122 + 123 + if (info->data->needs_sclk) { 124 + ret = clk_prepare(info->sclk); 125 + if (ret) { 126 + clk_unprepare(info->clk); 127 + dev_err(info->dev, 128 + "failed preparing sclk_adc clock: %d\n", ret); 129 + return ret; 130 + } 131 + } 132 + 133 + return 0; 134 + } 135 + 136 + static void exynos_adc_disable_clk(struct exynos_adc *info) 137 + { 138 + if (info->data->needs_sclk) 139 + clk_disable(info->sclk); 140 + clk_disable(info->clk); 141 + } 142 + 143 + static int exynos_adc_enable_clk(struct exynos_adc *info) 144 + { 145 + int ret; 146 + 147 + ret = clk_enable(info->clk); 148 + if (ret) { 149 + dev_err(info->dev, "failed enabling adc clock: %d\n", ret); 150 + return ret; 151 + } 152 + 153 + if (info->data->needs_sclk) { 154 + ret = clk_enable(info->sclk); 155 + if (ret) { 156 + clk_disable(info->clk); 157 + dev_err(info->dev, 158 + "failed enabling sclk_adc clock: %d\n", ret); 159 + return ret; 160 + } 161 + } 162 + 163 + return 0; 164 + } 108 165 109 166 static void exynos_adc_v1_init_hw(struct exynos_adc *info) 110 167 { ··· 273 208 .start_conv = exynos_adc_v2_start_conv, 274 209 }; 275 210 211 + static const struct exynos_adc_data exynos3250_adc_data = { 212 + .num_channels = MAX_EXYNOS3250_ADC_CHANNELS, 213 + .needs_sclk = true, 214 + 215 + .init_hw = exynos_adc_v2_init_hw, 216 + .exit_hw = exynos_adc_v2_exit_hw, 217 + .clear_irq = exynos_adc_v2_clear_irq, 218 + .start_conv = exynos_adc_v2_start_conv, 219 + }; 220 + 276 221 static const struct of_device_id exynos_adc_match[] = { 277 222 { 278 223 .compatible = "samsung,exynos-adc-v1", ··· 290 215 }, { 291 216 .compatible = "samsung,exynos-adc-v2", 292 217 .data = &exynos_adc_v2_data, 218 + }, { 219 + .compatible = "samsung,exynos3250-adc", 220 + .data = &exynos3250_adc_data, 293 221 }, 294 222 {}, 295 223 }; ··· 454 376 } 455 377 456 378 info->irq = irq; 379 + info->dev = &pdev->dev; 457 380 458 381 init_completion(&info->completion); 459 382 ··· 463 384 dev_err(&pdev->dev, "failed getting clock, err = %ld\n", 464 385 PTR_ERR(info->clk)); 465 386 return PTR_ERR(info->clk); 387 + } 388 + 389 + if (info->data->needs_sclk) { 390 + info->sclk = devm_clk_get(&pdev->dev, "sclk"); 391 + if (IS_ERR(info->sclk)) { 392 + dev_err(&pdev->dev, 393 + "failed getting sclk clock, err = %ld\n", 394 + PTR_ERR(info->sclk)); 395 + return PTR_ERR(info->sclk); 396 + } 466 397 } 467 398 468 399 info->vdd = devm_regulator_get(&pdev->dev, "vdd"); ··· 486 397 if (ret) 487 398 return ret; 488 399 489 - ret = clk_prepare_enable(info->clk); 400 + ret = exynos_adc_prepare_clk(info); 490 401 if (ret) 491 402 goto err_disable_reg; 403 + 404 + ret = exynos_adc_enable_clk(info); 405 + if (ret) 406 + goto err_unprepare_clk; 492 407 493 408 platform_set_drvdata(pdev, indio_dev); 494 409 ··· 536 443 err_disable_clk: 537 444 if (info->data->exit_hw) 538 445 info->data->exit_hw(info); 539 - clk_disable_unprepare(info->clk); 446 + exynos_adc_disable_clk(info); 447 + err_unprepare_clk: 448 + exynos_adc_unprepare_clk(info); 540 449 err_disable_reg: 541 450 regulator_disable(info->vdd); 542 451 return ret; ··· 555 460 free_irq(info->irq, info); 556 461 if (info->data->exit_hw) 557 462 info->data->exit_hw(info); 558 - clk_disable_unprepare(info->clk); 463 + exynos_adc_disable_clk(info); 464 + exynos_adc_unprepare_clk(info); 559 465 regulator_disable(info->vdd); 560 466 561 467 return 0; ··· 570 474 571 475 if (info->data->exit_hw) 572 476 info->data->exit_hw(info); 573 - 574 - clk_disable_unprepare(info->clk); 477 + exynos_adc_disable_clk(info); 575 478 regulator_disable(info->vdd); 576 479 577 480 return 0; ··· 586 491 if (ret) 587 492 return ret; 588 493 589 - ret = clk_prepare_enable(info->clk); 494 + ret = exynos_adc_enable_clk(info); 590 495 if (ret) 591 496 return ret; 592 497