Received: by 10.223.176.46 with SMTP id f43csp818368wra; Fri, 26 Jan 2018 07:23:56 -0800 (PST) X-Google-Smtp-Source: AH8x227aXgWNfZLk4qjdUwUVT2cIR662hJCoqWtcq5BEPdZdfvAjXYMF6neZLJ2FR+pUXETkbPae X-Received: by 2002:a17:902:598e:: with SMTP id p14-v6mr13958559pli.289.1516980236273; Fri, 26 Jan 2018 07:23:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516980236; cv=none; d=google.com; s=arc-20160816; b=QMFZmeAsP24yZeT9RcW6a1zhuQF8AWY62KFZJcUe/VPrlNk/fXD0LpQfBAR3DYydmy P+Vzwiz/wfNsySMzUJsFw2Up6AIebwZFfGaRfNFe8aiceWAOFlgtJib88C0B5MNvhg/Y ZTjmfYrKd4+mAIeq1hcSP6K+fna4/FWDOsZIy803ewSCx7+Rdy+vbL6p4UatG+Q7dYJx W5A2sIPdXlYpIRlu/yC1AuewHD3oFNP8UZNbZS1Ze76P6XQmAYsOJyKI9jxSxxWr2NpV M0IjL5w2CDqVPFtqB5j2uSRDmHlotlxB1B4++yiHKn2XtlCeALty0s4wRJV2qimvayYR OWBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=6QlsTwEH9WAkK/tAe8j6pX7DZbuz5Yw81JMY2IxJKe8=; b=k+ET3K/8aa87I9hxYLIwIyAA3q0CAVk4lznxb2Rfnj0+zds3hATsYHbOH49Wb3Xe1z B8KzowYtSk8E3KI7/m7flgEtB2plDbjv0cgXKymgKdhc7NZYPNsInjdo4b0Z1s3VAD/4 K7Xv+S+90u6dBNmP8fdoeFu3FMRYAalhK25Jg+s+eEqcRKgMrJMlnySyNojNWWYXwYe5 9pqArqUwV/fR+s2JQf++BiXK9bEZ8U6BkFvJH8A8PUNCiygCjS7y1vWaRz8DUWAw8//9 6iI6EzBP6tNU/CXNwajAvQs51+gzPZttbg7hH6yJxQIegksGqHFjZePT44lajMQP9qSN wv6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cLc1mBVw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 129si3120638pgc.441.2018.01.26.07.23.41; Fri, 26 Jan 2018 07:23:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cLc1mBVw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752583AbeAZPUA (ORCPT + 99 others); Fri, 26 Jan 2018 10:20:00 -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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.11.0