From patchwork Sun Jan 28 23:29:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Rossak X-Patchwork-Id: 10188595 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 A3D476056F for ; Sun, 28 Jan 2018 23:32:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DD31286D1 for ; Sun, 28 Jan 2018 23:32:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9251C286D7; Sun, 28 Jan 2018 23:32:47 +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 047A9286D2 for ; Sun, 28 Jan 2018 23:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752749AbeA1X3h (ORCPT ); Sun, 28 Jan 2018 18:29:37 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:40246 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752661AbeA1X3d (ORCPT ); Sun, 28 Jan 2018 18:29:33 -0500 Received: by mail-wr0-f193.google.com with SMTP id i56so5272956wra.7; Sun, 28 Jan 2018 15:29:32 -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=ZFKdW+6uq9GD3by7X0blyEx7auA7daBvwuw9wBZxcV8=; b=D5mOPstRojD91sfB6QkkhuRzaJ4SggUp6SXbiMeaOeECJeFgfZcvMXJ0CKaJN+tmTG 8OdPcNhamC71m8TCf/kVasPNAyxUu9YRXgPPhbbBmG73nW9QKLA/nHt+fdSGkGU0+Nt+ DR6UL7xrYBGFIg7HlFJqU0EKl5VV1uvTAZEaJ/d3r7InNne20Xd4urRVhwhfahALtZbl YLckZiMTXfPiTCOnWpsDWUjP63bXVnNd7e+7ibzsGK2A+CGxTDR/4lQxXoItb06yteBw 7XaCRr9iK4fTFAzEta4i1rn9C4T8Qwam4tPSPhJifp7kAjQTHdZKwe/xheki5NZlvp4A D6EQ== 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=ZFKdW+6uq9GD3by7X0blyEx7auA7daBvwuw9wBZxcV8=; b=oFS5e4UI/FR3QAp5QthdV7uczQdZ0H++L0aMXfJy7RUCqy5LN2E8Tdg4kQhdkOCM7a vLJ06U6gLnykT5rDrBi2nB5VpHRCQ5U/eAgIqVfWzWfNLHwWM4evUei2C/pbgYqfOZPr iM2j3J7nk6DyWQX0/To/09cMdbSqBzXevytqpklMQzs6Kg2XRoZ2Wc/xBlJ6BIYf+NND ecKEhvzGn7B7y/UrNllS2vYHC0Gc8sVUFba8SZsPm71FT/FPQ/kFpqTYEYNdkDSHd1Ht MbgnPJgrgvhXIKR0xC3FNCIOuWzozYcL73Xw43OKsdvM4lEZlkLWmxenbKgN5I0Wy3Q6 LHug== X-Gm-Message-State: AKwxytfT5ECPDuLYGOEJHI0h4JxfIo1H2bnemMW45oICe2qZl8Aj8k38 /sV6itTNl1PMXynJjXuQY98= X-Google-Smtp-Source: AH8x224i5hKXKZkqzKNg3JwwCEQPKDzn4+3cO4y/0WwkfGARpDpfSMEGV9PnqC8wa5fPgkmoAHwrjA== X-Received: by 10.223.146.135 with SMTP id 7mr16206804wrn.123.1517182171673; Sun, 28 Jan 2018 15:29:31 -0800 (PST) Received: from debian-laptop.fritz.box (p578F04D2.dip0.t-ipconnect.de. [87.143.4.210]) by smtp.gmail.com with ESMTPSA id m86sm11839223wmi.40.2018.01.28.15.29.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jan 2018 15:29:31 -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 v2 05/16] iio: adc: sun4i-gpadc-iio: rework: support clocks and reset Date: Mon, 29 Jan 2018 00:29:08 +0100 Message-Id: <20180128232919.12639-6-embed3d@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180128232919.12639-1-embed3d@gmail.com> References: <20180128232919.12639-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 | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index db57d9fffe48..51ec0104d678 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 @@ -68,6 +70,9 @@ struct gpadc_data { unsigned int temp_data; int (*sample_start)(struct sun4i_gpadc_iio *info); int (*sample_end)(struct sun4i_gpadc_iio *info); + bool has_bus_clk; + bool has_bus_rst; + bool has_mod_clk; }; static const struct gpadc_data sun4i_gpadc_data = { @@ -127,6 +132,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; @@ -420,6 +428,10 @@ static int sun4i_gpadc_runtime_suspend(struct device *dev) { struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); + clk_disable(info->mod_clk); + + clk_disable(info->bus_clk); + return info->data->sample_end(info); } @@ -446,6 +458,10 @@ static int sun4i_gpadc_runtime_resume(struct device *dev) { struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); + clk_enable(info->mod_clk); + + clk_enable(info->bus_clk); + return info->data->sample_start(info); } @@ -560,10 +576,59 @@ 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: + clk_disable_unprepare(info->bus_clk); + +assert_reset: + reset_control_assert(info->reset); + + return ret; } static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, @@ -729,6 +794,12 @@ static int sun4i_gpadc_remove(struct platform_device *pdev) if (!info->no_irq) iio_map_array_unregister(indio_dev); + clk_disable_unprepare(info->mod_clk); + + clk_disable_unprepare(info->bus_clk); + + reset_control_assert(info->reset); + return 0; }