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: 10186431 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 6AFE8601D5 for ; Fri, 26 Jan 2018 15:35:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A36728448 for ; Fri, 26 Jan 2018 15:35:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E52F2986F; Fri, 26 Jan 2018 15:35:44 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D9DA829CDE for ; Fri, 26 Jan 2018 15:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=wfx4Lf1aF52dXmxQSFPW9OOggADuSyGN0tzXgfqHccY=; b=VRGXlTr20XyaeX763kvJww+zrG fE/YwNrJahzueWgDDaSmZ4QRaJWZpMNf4ZEFzQ9UDr1/GuiHG4VbIYqUgvwoQWMroseg2N89kbv7C 6Mvky+qmOBxyPls+kfnDLgoZMZQXa/N5UHW1XcUFz7qM6VQVRhNKTff96dW2TeuHtYySrgRIdk5ly 6TpsfgIqVnfW5SWleF+jAwo0u21bbr54G0oHPvfKP6ttDeMLzaSir1/YDwDq6Xq44IVE4xhLzPajK upyEYA4dhQIkUmbXC+yr9DxYq0jvRhRG9UTHxxvUzZtXNyKNqYq1FlKZq1+bsnnunDTcItaunaB84 rfEdtdvg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ef62V-00044s-7n; Fri, 26 Jan 2018 15:35:39 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ef5nR-0000Xt-32 for linux-arm-kernel@lists.infradead.org; Fri, 26 Jan 2018 15:20:11 +0000 Received: by mail-wr0-x244.google.com with SMTP id g21so814697wrb.13 for ; Fri, 26 Jan 2018 07:19:55 -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=fdnVOuV3cgebKoH1IsoQ92+33AaLXgE1yJRRpaH/YPzFHDztKBr13zKLlSHZwkwXS5 FOaOkldCmxL9sCBbircKtsNm4a2f3oCg/rfrELX99K0OjWiB4aYL1Mgmorb/ECKMqcFK YrSiLyQPKU7XkUhXP6o/pImW3u6CZV7MGJDjj4Ezvwssvjy/f4yVz3IbZEMF7jceVcqL TM6G1ir+PK4S0Da2rC7diLvOcNLMU4Bn/WflDRggKl8T9HtUKo19MQU38RdYfAXJ00Sd NPjj+FJsnJPwyL+HS6MYfgGTMqeHtNBsbk5nfQrEV3Idk871+QMf19MXV3DfskQjoRPG 8xSg== X-Gm-Message-State: AKwxytc1r/q+jg7lrrlAOBhYFlvJGh9STW63oBn77M4URf8d6LQH6oLj Rg5HFx0sfs7/vZYNFdUzD7U= 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 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> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-sunxi@googlegroups.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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; }