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: 10188599 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 D446960383 for ; Sun, 28 Jan 2018 23:33:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB008286D1 for ; Sun, 28 Jan 2018 23:33:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF9E1286D7; Sun, 28 Jan 2018 23:33:01 +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 3C5BD286D1 for ; Sun, 28 Jan 2018 23:33:01 +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=Fmu150CCy4CkIgZa3/7TEttOFEWBAl44l87ZQafQR1I=; b=sY+aNfwL/Xoel0bPjJjhLr0wKJ ug33Za4oa8o7oxCScNj9ZmaAp1FYNh7a61TQM1s4Xghs8sMT0fCgxF4wSNYE0TctMh4S8V385l8UU nrz1iNrLSEh2W15SjaJYsV2/ag5Jmpr0gWgfm83fPrsQ1AbsiWEBaMbyzxIquqFiqWlaC7utTtSCg zUllLf/FF28jhhM34tFDYSJnygV+wBGZEOXZDSHUkLJX4FIzV853vC8O7bQKOScCIjitwNfqBuYyE rFmVio12rCLdiVSQ9wMx2OdETo951e/zbz7DYclXb6W0tM3rAzNf9r1QACa2+T47N7pYz2MPfQEZG 2DIjpxWg==; 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 1efwRW-0000Df-OD; Sun, 28 Jan 2018 23:32:58 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1efwON-0004Jm-P7 for linux-arm-kernel@lists.infradead.org; Sun, 28 Jan 2018 23:29:51 +0000 Received: by mail-wr0-x243.google.com with SMTP id 36so5294967wrh.1 for ; Sun, 28 Jan 2018 15:29:33 -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=CfsTtSDgzz0Ez2La25PWOGYk4ko70dZr6zHerTm4KGLAjMLHfsnIMv9K49ff7/sgQE /7kr8E8CBnuXp9+IEE59LhXaQcL2aJBYVS+e8B+r6boUylo5eXuoJFklR7eRRuH9fpfY finS7uU02Mc+X9TVOZDt+gdr/XoxuPMZku5m8neK5z3hZiVv7SewkK/eXhdLXgQh+BNl QUViGFOmVfICx6bAUiuKuQ5FYh57PG9KZyHsFuuJsH2If0tJBQCvZHFrhYXk8LaY/Jnh nNTg8ThTPdIpRdH0Piw0WfWZMaglIlEFtl0BA1Qb+7gOsadOgNMIVycV6f415fj/rc7i Nm3w== X-Gm-Message-State: AKwxyteVeIdGs/oU6jaPaiw+UZjosvoKdR6rLiWAWWufEo4wrXA2h8Oy jKJDUElCDnmM57uJ9lhmzOs= 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 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> 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 | 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; }