From patchwork Wed Apr 16 10:11:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 3999541 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EB762BFF02 for ; Wed, 16 Apr 2014 10:15:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EAC3520259 for ; Wed, 16 Apr 2014 10:15:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F31F3201DE for ; Wed, 16 Apr 2014 10:15:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WaMpV-0001eW-99; Wed, 16 Apr 2014 10:12:33 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WaMpI-0001Tb-7n for linux-arm-kernel@lists.infradead.org; Wed, 16 Apr 2014 10:12:20 +0000 Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N4400321CBWNUB0@mailout2.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 16 Apr 2014 19:11:56 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.116]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 82.95.14803.C675E435; Wed, 16 Apr 2014 19:11:56 +0900 (KST) X-AuditID: cbfee691-b7efc6d0000039d3-8a-534e576c4839 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 7C.C1.28157.B675E435; Wed, 16 Apr 2014 19:11:56 +0900 (KST) Received: from chan.10.32.193.11 ([10.252.81.195]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N44007IGCBU7Q30@mmp2.samsung.com>; Wed, 16 Apr 2014 19:11:55 +0900 (KST) From: Chanwoo Choi To: jic23@kernel.org, ch.naveen@samsung.com, kgene.kim@samsung.com Subject: [PATCHv3 1/2] iio: adc: exynos_adc: Control special clock of ADC to support Exynos3250 ADC Date: Wed, 16 Apr 2014 19:11:57 +0900 Message-id: <1397643118-6934-2-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1397643118-6934-1-git-send-email-cw00.choi@samsung.com> References: <1397643118-6934-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAIsWRmVeSWpSXmKPExsWyRsSkRDcn3C/Y4N80YYu7zw8zWlz/8pzV Yv6Rc6wW/W8Wslqce7WS0eJB0yomi94FV9ksNj2+xmqxsG0Ji8W8I+9YLC7vmsNmMeP8PiaL pdcvMllMmL6WxeLtneksFq17j7BbnPzTy2ixfsZrFgchjzXz1jB6XO7rZfJYufwLm8fmFVoe m1Z1snncubYHyFtS79G3ZRWjx+dNcgGcUVw2Kak5mWWpRfp2CVwZDYtPshbMNK+Y2PeftYHx t04XIyeHhICJxI1l21kgbDGJC/fWs3UxcnEICSxllPgx+TwrTNG1LU2MEInpjBKPpz6BcpqY JC7v2sQIUsUmoCWx/8UNNhBbRMBJ4ue3e2CjmAUWMUvMXn0OLCEskCrx6+NVZhCbRUBVom3e ZKA4BwevgIvEze3lENvkJD7secQOYnMKuEo0nDoJdoUQUMn5h//AFksIdHJIPGmf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+fUL9gId6UxMqq1KL8+KLSnNTiQ4zJQEdNZJYSTc4HJp28knhDYxMzI0sjc0ML I2Nz0oSVxHkPtloHCgmkJ5akZqemFqQWwWxh4uCUamDMkGEL2iRUyTYxT9rUN9Nh24lFbTPf zmw3Of53wcsv6jvtJlyLqrr3PeHbGtv3Cev95DRaBa0Y50lOSFX+sG/XP+durYmXvJfcrjur sp+tz31q3k9Nx7xvp1hYk2K6vbbtu3HmJfcLDXXVv00/9+1SmiH73Ttky8t47kVrNM53FHp9 ZLT2bPJQYinOSDTUYi4qTgQAtdSF7jADAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140416_031220_418720_2F2E183D X-CRM114-Status: GOOD ( 15.69 ) X-Spam-Score: -5.7 (-----) Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Chanwoo Choi , pawel.moll@arm.com, ijc+devicetree@hellion.org.uk, sachin.kamat@linaro.org, t.figa@samsung.com, rdunlap@infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, robh+dt@kernel.org, galak@codeaurora.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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_tsadc' clock as following: - 'sclk_tsadc' clock: special clock for ADC which provide clock to internal ADC Exynos 4210/4212/4412 and Exynos5250/5420 has not included 'sclk_tsadc' clock in FSYS_BLK. But, Exynos3250 based on Cortex-A7 has only included 'sclk_tsadc' clock in FSYS_BLK. Cc: Jonathan Cameron Cc: Kukjin Kim Cc: Naveen Krishna Chatradhi Cc: linux-iio@vger.kernel.org Signed-off-by: Chanwoo Choi Acked-by: Kyungmin Park --- drivers/iio/adc/exynos_adc.c | 86 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 13 deletions(-) diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c index d25b262..486771e 100644 --- a/drivers/iio/adc/exynos_adc.c +++ b/drivers/iio/adc/exynos_adc.c @@ -40,8 +40,9 @@ #include enum adc_version { - ADC_V1, - ADC_V2 + ADC_V1 = 0x1, + ADC_V2 = 0x2, + ADC_V3 = (ADC_V1 | ADC_V2), }; /* EXYNOS4412/5250 ADC_V1 registers definitions */ @@ -85,9 +86,11 @@ enum adc_version { #define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(1000)) struct exynos_adc { + struct device *dev; void __iomem *regs; void __iomem *enable_reg; struct clk *clk; + struct clk *sclk; unsigned int irq; struct regulator *vdd; @@ -100,6 +103,7 @@ struct exynos_adc { static const struct of_device_id exynos_adc_match[] = { { .compatible = "samsung,exynos-adc-v1", .data = (void *)ADC_V1 }, { .compatible = "samsung,exynos-adc-v2", .data = (void *)ADC_V2 }, + { .compatible = "samsung,exynos-adc-v3", .data = (void *)ADC_V3 }, {}, }; MODULE_DEVICE_TABLE(of, exynos_adc_match); @@ -128,7 +132,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev, mutex_lock(&indio_dev->mlock); /* Select the channel to be used and Trigger conversion */ - if (info->version == ADC_V2) { + if (info->version >= ADC_V2) { con2 = readl(ADC_V2_CON2(info->regs)); con2 &= ~ADC_V2_CON2_ACH_MASK; con2 |= ADC_V2_CON2_ACH_SEL(chan->address); @@ -165,7 +169,7 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id) info->value = readl(ADC_V1_DATX(info->regs)) & ADC_DATX_MASK; /* clear irq */ - if (info->version == ADC_V2) + if (info->version >= ADC_V2) writel(1, ADC_V2_INT_ST(info->regs)); else writel(1, ADC_V1_INTCLR(info->regs)); @@ -226,11 +230,43 @@ static int exynos_adc_remove_devices(struct device *dev, void *c) return 0; } +static int exynos_adc_enable_clock(struct exynos_adc *info, bool enable) +{ + int ret; + + if (enable) { + ret = clk_prepare_enable(info->clk); + if (ret) { + dev_err(info->dev, "failed to enable adc clock\n"); + return ret; + } + if (info->version == ADC_V3) { + ret = clk_prepare_enable(info->sclk); + if (ret) { + dev_err(info->dev, + "failed to enable sclk_tsadc clock\n"); + goto err; + } + } + + } else { + if (info->version == ADC_V3) + clk_disable_unprepare(info->sclk); + clk_disable_unprepare(info->clk); + } + + return 0; +err: + clk_disable_unprepare(info->clk); + + return ret; +} + static void exynos_adc_hw_init(struct exynos_adc *info) { u32 con1, con2; - if (info->version == ADC_V2) { + if (info->version >= ADC_V2) { con1 = ADC_V2_CON1_SOFT_RESET; writel(con1, ADC_V2_CON1(info->regs)); @@ -287,6 +323,7 @@ static int exynos_adc_probe(struct platform_device *pdev) } info->irq = irq; + info->dev = &pdev->dev; init_completion(&info->completion); @@ -300,6 +337,8 @@ static int exynos_adc_probe(struct platform_device *pdev) writel(1, info->enable_reg); + info->version = exynos_adc_get_version(pdev); + info->clk = devm_clk_get(&pdev->dev, "adc"); if (IS_ERR(info->clk)) { dev_err(&pdev->dev, "failed getting clock, err = %ld\n", @@ -308,6 +347,16 @@ static int exynos_adc_probe(struct platform_device *pdev) goto err_irq; } + if (info->version == ADC_V3) { + info->sclk = devm_clk_get(&pdev->dev, "sclk_tsadc"); + if (IS_ERR(info->sclk)) { + ret = PTR_ERR(info->sclk); + dev_warn(&pdev->dev, + "failed getting sclk clock, err = %d\n", ret); + goto err_irq; + } + } + info->vdd = devm_regulator_get(&pdev->dev, "vdd"); if (IS_ERR(info->vdd)) { dev_err(&pdev->dev, "failed getting regulator, err = %ld\n", @@ -316,8 +365,6 @@ static int exynos_adc_probe(struct platform_device *pdev) goto err_irq; } - info->version = exynos_adc_get_version(pdev); - platform_set_drvdata(pdev, indio_dev); indio_dev->name = dev_name(&pdev->dev); @@ -340,7 +387,11 @@ static int exynos_adc_probe(struct platform_device *pdev) if (ret) goto err_iio_dev; - clk_prepare_enable(info->clk); + ret = exynos_adc_enable_clock(info, true); + if (ret) { + dev_err(&pdev->dev, "failed to enable clock\n"); + goto err_regulator; + } exynos_adc_hw_init(info); @@ -355,8 +406,9 @@ static int exynos_adc_probe(struct platform_device *pdev) err_of_populate: device_for_each_child(&pdev->dev, NULL, exynos_adc_remove_devices); + exynos_adc_enable_clock(info, false); +err_regulator: regulator_disable(info->vdd); - clk_disable_unprepare(info->clk); err_iio_dev: iio_device_unregister(indio_dev); err_irq: @@ -372,7 +424,7 @@ static int exynos_adc_remove(struct platform_device *pdev) device_for_each_child(&pdev->dev, NULL, exynos_adc_remove_devices); regulator_disable(info->vdd); - clk_disable_unprepare(info->clk); + exynos_adc_enable_clock(info, false); writel(0, info->enable_reg); iio_device_unregister(indio_dev); free_irq(info->irq, info); @@ -387,7 +439,7 @@ static int exynos_adc_suspend(struct device *dev) struct exynos_adc *info = iio_priv(indio_dev); u32 con; - if (info->version == ADC_V2) { + if (info->version >= ADC_V2) { con = readl(ADC_V2_CON1(info->regs)); con &= ~ADC_CON_EN_START; writel(con, ADC_V2_CON1(info->regs)); @@ -397,7 +449,7 @@ static int exynos_adc_suspend(struct device *dev) writel(con, ADC_V1_CON(info->regs)); } - clk_disable_unprepare(info->clk); + exynos_adc_enable_clock(info, false); writel(0, info->enable_reg); regulator_disable(info->vdd); @@ -415,11 +467,19 @@ static int exynos_adc_resume(struct device *dev) return ret; writel(1, info->enable_reg); - clk_prepare_enable(info->clk); + ret = exynos_adc_enable_clock(info, true); + if (ret) { + dev_err(dev, "failed to enable clock\n"); + goto err; + } exynos_adc_hw_init(info); return 0; +err: + regulator_disable(info->vdd); + + return ret; } #endif