From patchwork Thu Aug 30 15:45:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Rossak X-Patchwork-Id: 10582193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 109D214BD for ; Thu, 30 Aug 2018 15:59:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F272C2C0EE for ; Thu, 30 Aug 2018 15:58:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E572A2C0F3; Thu, 30 Aug 2018 15:58:59 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 695F92C0EE for ; Thu, 30 Aug 2018 15:58:59 +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=6+9atuhb5eSEDmHi+VyP9FJaauvbR0uCKMiJ2fyA74I=; b=g5zZUwBKUJX/8Tr+cD7HPv0Xg5 rFuitJuOMQvaRkcrMVx2CpETw5qJsjC6hdAFjJcSSgRszLHJDne87yykd+OjelNAxDhwIqVUZA7EZ /qixgtDtA2FcyjE9z/34VohYs1kGwmSz/MTBtbhxUE7k9IuPJWBjJYk6plOVNb/74eEofLTkhpe5k UWJIvIXWieD9vKgzEqDHR/Fnah647w6thamHAfic3p3uypkUnIPuSlMRF3ZD1+s3Ccfv5a4BpLuEa 2yNrG8RrgpF/rdAgqHrDrIy1AI2Ts+nNlOgQjjofQTsvZT9vgLzbBFytIQeX/dQo1yZ0aoXcrp1DL /ymzXkUQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvPLO-000102-QJ; Thu, 30 Aug 2018 15:58:50 +0000 Received: from mail-wm0-f68.google.com ([74.125.82.68]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvP8n-0001fs-DP for linux-arm-kernel@lists.infradead.org; Thu, 30 Aug 2018 15:45:51 +0000 Received: by mail-wm0-f68.google.com with SMTP id c14-v6so2472731wmb.4 for ; Thu, 30 Aug 2018 08:45:39 -0700 (PDT) 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=awc7lOb1lT80drwezjxAgYVu4AbsJ53UXF1LdxXOCho=; b=X0MxvQAWNa/QHG1a/x8gvN03aFC9bPKcstD3++OvpK/mWPr/Nu71ydd6Bi41ISzadw qIrOAT4F4OdsZ2kzh+q00Iis58hoEqbdTQiaJXXSzS2z9xTXQ5TxEH5tqgZjYazGaWjL bgRuTIATJ9oEsL4Wiu0TCg4IYGtnZMurHeihga0x6jkxCqTnuwwGYQJO+iPhrO6Es8uG PfJfsu2w7Xck8vTApyDRlNjCvRFoI5IwEtRAnxtxmXrFhmaoTmiGArLtORnF021wvrAd TAL+o92qdd4pPHPE+vbp5YWVnctSPkhqkJ92iBaWO2vxPhz1KGnXaQA3f6nl67oaEha3 JKrQ== 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=awc7lOb1lT80drwezjxAgYVu4AbsJ53UXF1LdxXOCho=; b=eVvinShrX3W1JFCoTPRPILnzV1M9mhrNfPhJyiPPGtvChHVE136wq4C6LfmnVQZDil eWD5cm179hQL+QWak9rCP8vNjkLVIxSGZsdFRE4fe8mSRO6s+f4QFQaG25z6mOhfFUXS u4yhSNirmDuxNnzM7xgoN53q5Ve4g25zWrE7wMhcWa9M+z44y+VHpFJWzQo1iGOAAQmn 97VOHWGVO89Lo8IpyD+BNb9l2/Bby/Ni3Bfw2Kij4chFE91vftbdNCbJ9+3I9xFReDPR SfXDHT6YiaadUF22fv5APi5YkQUGYR4YeeWl876o1Y7vzu5q+1olkNLTTEpmlnYGrQm/ /YNQ== X-Gm-Message-State: APzg51BSPLLb1dmxJS9csV3EF5z79t3O6yljlOBMOkh2peqy0DuILj3u pfjzDfHSOB1NhrHtpYgUMzE= X-Google-Smtp-Source: ANB0VdZ9TFSjSij1veJmjfSvCzyhdYiErnmAIpTWPnan95g96ps8uKTdevRe8LnmmxEcbDyC2EYNlg== X-Received: by 2002:a1c:7e13:: with SMTP id z19-v6mr2044367wmc.156.1535643937235; Thu, 30 Aug 2018 08:45:37 -0700 (PDT) Received: from debian-hp.wlan.uni-ulm.de (eduroam170-020.wlan.uni-ulm.de. [134.60.170.20]) by smtp.gmail.com with ESMTPSA id j20-v6sm1362759wmh.9.2018.08.30.08.45.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 08:45:36 -0700 (PDT) From: Philipp Rossak To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, linux@armlinux.org.uk, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, eugen.hristev@microchip.com, rdunlap@infradead.org, vilhelm.gray@gmail.com, clabbe.montjoie@gmail.com, quentin.schulz@bootlin.com, geert+renesas@glider.be, lukas@wunner.de, icenowy@aosc.io, arnd@arndb.de, broonie@kernel.org, arnaud.pouliquen@st.com Subject: [PATCH v3 17/30] iio: adc: sun4i-gpadc-iio: rework: support clocks and reset Date: Thu, 30 Aug 2018 17:45:05 +0200 Message-Id: <20180830154518.29507-18-embed3d@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180830154518.29507-1-embed3d@gmail.com> References: <20180830154518.29507-1-embed3d@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180830_084549_611721_9A7D09C4 X-CRM114-Status: GOOD ( 18.49 ) 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 --- drivers/iio/adc/sun4i-gpadc-iio.c | 72 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index c278e165e161..c12de48c4e86 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 @@ -63,6 +65,9 @@ struct gpadc_data { int (*ths_suspend)(struct sun4i_gpadc_iio *info); int (*ths_resume)(struct sun4i_gpadc_iio *info); bool support_irq; + bool has_bus_clk; + bool has_bus_rst; + bool has_mod_clk; u32 temp_data_base; }; @@ -127,6 +132,9 @@ struct sun4i_gpadc_iio { struct mutex mutex; struct thermal_zone_device *tzd; struct device *sensor_device; + struct clk *bus_clk; + struct clk *mod_clk; + struct reset_control *reset; }; static const struct iio_chan_spec sun4i_gpadc_channels[] = { @@ -472,8 +480,13 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, if (IS_ERR(base)) return PTR_ERR(base); - info->regmap = devm_regmap_init_mmio(&pdev->dev, base, - &sun4i_gpadc_regmap_config); + if (info->data->has_bus_clk) + info->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "bus", + base, &sun4i_gpadc_regmap_config); + else + info->regmap = devm_regmap_init_mmio(&pdev->dev, base, + &sun4i_gpadc_regmap_config); + if (IS_ERR(info->regmap)) { ret = PTR_ERR(info->regmap); dev_err(&pdev->dev, "failed to init regmap: %d\n", ret); @@ -498,9 +511,58 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, } } + 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 4MHz */ + 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; + } + 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(struct platform_device *pdev) @@ -586,6 +648,12 @@ static int sun4i_gpadc_remove(struct platform_device *pdev) if (!info->data->support_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; }