From patchwork Fri Jan 26 15:19:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Rossak X-Patchwork-Id: 10186345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 57C7460383 for ; Fri, 26 Jan 2018 15:23:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4968429C2A for ; Fri, 26 Jan 2018 15:23:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BFFE29C19; Fri, 26 Jan 2018 15:23:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8563529C19 for ; Fri, 26 Jan 2018 15:23:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751509AbeAZPT7 (ORCPT ); Fri, 26 Jan 2018 10:19:59 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46221 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751973AbeAZPTz (ORCPT ); Fri, 26 Jan 2018 10:19:55 -0500 Received: by mail-wr0-f193.google.com with SMTP id g21so814698wrb.13; Fri, 26 Jan 2018 07:19:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6QlsTwEH9WAkK/tAe8j6pX7DZbuz5Yw81JMY2IxJKe8=; b=cLc1mBVw/zv9m2JM7lvH9SyH1NJTFCqrJfMnTwtV/A0ct7Pr+HoubdnOJTPx2p9U2D Fh2Ty0nG7dP57qieFY9LwMUvKm7WCcrpOvVn8TpOSsg3x4UMEfq6xrXBXKy5EUy7szAL VC+9GTs96kI0/13tetPs/tDPqfHvHEVsjnFR4twAnq9ZaafZzvT22Id9QJ5TQkNC9iKf 5aaKe9vs9CPaYPpp8oJWvkOZdDag1QIpwd7isfx4C7zfkowdswWj0P+yxIPbDhfDl2zp E24r+7L5zLCZx1jNkB+e+Kysam25t6aFRZ6e4cGKXnM+ux4syuRmaMdJ1dO510NtITbp NBXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6QlsTwEH9WAkK/tAe8j6pX7DZbuz5Yw81JMY2IxJKe8=; b=nGlyGKJ22XA2tJv7cRPt1JbhfuccxYOa2qpTp0HA/2uQ8NLt2QjuD77hFYHZ5ErA8z 8kCHKvqfOi4Dk+JQPAPQ6Wl4wzIXfviboiJFdUbkeFAlAo4SM6/TA2o5H7OztVQojZy4 WlZzX7+eal+Nna8gzW21Iy/eOMSjemRqiPWLgyYh7jpoHtiBMQW/wap2/s0zLdQWzi9H LkFIsduqGexTnZFD/IW7wpQbRjT05C1hWhw+olu9ikZR2M6zndlhfzSrD6ZQXmFHatbL 2NRG2PHYZZgvBbzR8xOYDwdcUP+7pV1mPbt4oqrn6XU6SOX8zDwPctJ3ZBfNEqZS+qG3 JCaw== X-Gm-Message-State: AKwxytfuFxe3/5Fr31trS/JFdzgVo80dfbKflC54xxrTweVgk3RUPOMb HO9fr9a0vH7WWw6MVoZ1POQ= X-Google-Smtp-Source: AH8x225kufPhQ2HTJD3OyLlbrM7CQxU3pS0yM4hOg6K12zTjMIrrnzo4p4mx82kTMHrMa4paH/qL+Q== X-Received: by 10.223.156.197 with SMTP id h5mr11629579wre.17.1516979994315; Fri, 26 Jan 2018 07:19:54 -0800 (PST) Received: from debian-laptop.fritz.box (p578F04D2.dip0.t-ipconnect.de. [87.143.4.210]) by smtp.gmail.com with ESMTPSA id e15sm4586130wmd.26.2018.01.26.07.19.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 07:19:53 -0800 (PST) From: Philipp Rossak To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@free-electrons.com, wens@csie.org, linux@armlinux.org.uk, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, davem@davemloft.net, hans.verkuil@cisco.com, mchehab@kernel.org, rask@formelder.dk, clabbe.montjoie@gmail.com, sean@mess.org, krzk@kernel.org, quentin.schulz@free-electrons.com, icenowy@aosc.io, edu.molinas@gmail.com, singhalsimran0@gmail.com Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com Subject: [PATCH 05/16] iio: adc: sun4i-gpadc-iio: rework: support clocks and reset Date: Fri, 26 Jan 2018 16:19:30 +0100 Message-Id: <20180126151941.12183-6-embed3d@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180126151941.12183-1-embed3d@gmail.com> References: <20180126151941.12183-1-embed3d@gmail.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For adding newer sensor some basic rework of the code is necessary. The SoCs after H3 has newer thermal sensor ADCs, which have two clock inputs (bus clock and sampling clock) and a reset. The registers are also re-arranged. This commit reworks the code, adds the process of the clocks and resets. Signed-off-by: Philipp Rossak Signed-off-by: Icenowy Zheng --- drivers/iio/adc/sun4i-gpadc-iio.c | 80 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 363936b37c5a..1a80744bd472 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -22,6 +22,7 @@ * shutdown for not being used. */ +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include @@ -75,6 +77,9 @@ struct gpadc_data { u32 ctrl2_map; u32 sensor_en_map; u32 filter_map; + bool has_bus_clk; + bool has_bus_rst; + bool has_mod_clk; }; static const struct gpadc_data sun4i_gpadc_data = { @@ -134,6 +139,9 @@ struct sun4i_gpadc_iio { atomic_t ignore_temp_data_irq; const struct gpadc_data *data; bool no_irq; + struct clk *bus_clk; + struct clk *mod_clk; + struct reset_control *reset; /* prevents concurrent reads of temperature and ADC */ struct mutex mutex; struct thermal_zone_device *tzd; @@ -435,6 +443,12 @@ static int sun4i_gpadc_runtime_suspend(struct device *dev) { struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); + if (info->data->has_mod_clk) + clk_disable(info->mod_clk); + + if (info->data->has_bus_clk) + clk_disable(info->bus_clk); + return info->data->sample_end(info); } @@ -483,6 +497,12 @@ static int sun4i_gpadc_runtime_resume(struct device *dev) { struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); + if (info->data->has_mod_clk) + clk_enable(info->mod_clk); + + if (info->data->has_bus_clk) + clk_enable(info->bus_clk); + return info->data->sample_start(info); } @@ -597,10 +617,61 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, return ret; } + if (info->data->has_bus_rst) { + info->reset = devm_reset_control_get(&pdev->dev, NULL); + if (IS_ERR(info->reset)) { + ret = PTR_ERR(info->reset); + return ret; + } + + ret = reset_control_deassert(info->reset); + if (ret) + return ret; + } + + if (info->data->has_bus_clk) { + info->bus_clk = devm_clk_get(&pdev->dev, "bus"); + if (IS_ERR(info->bus_clk)) { + ret = PTR_ERR(info->bus_clk); + goto assert_reset; + } + + ret = clk_prepare_enable(info->bus_clk); + if (ret) + goto assert_reset; + } + + if (info->data->has_mod_clk) { + info->mod_clk = devm_clk_get(&pdev->dev, "mod"); + if (IS_ERR(info->mod_clk)) { + ret = PTR_ERR(info->mod_clk); + goto disable_bus_clk; + } + + /* Running at 6MHz */ + ret = clk_set_rate(info->mod_clk, 4000000); + if (ret) + goto disable_bus_clk; + + ret = clk_prepare_enable(info->mod_clk); + if (ret) + goto disable_bus_clk; + } + if (IS_ENABLED(CONFIG_THERMAL_OF)) info->sensor_device = &pdev->dev; return 0; + +disable_bus_clk: + if (info->data->has_bus_clk) + clk_disable_unprepare(info->bus_clk); + +assert_reset: + if (info->data->has_bus_rst) + reset_control_assert(info->reset); + + return ret; } static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, @@ -766,6 +837,15 @@ static int sun4i_gpadc_remove(struct platform_device *pdev) if (!info->no_irq) iio_map_array_unregister(indio_dev); + if (info->data->has_mod_clk) + clk_disable_unprepare(info->mod_clk); + + if (info->data->has_bus_clk) + clk_disable_unprepare(info->bus_clk); + + if (info->data->has_bus_rst) + reset_control_assert(info->reset); + return 0; }