Received: by 10.223.176.5 with SMTP id f5csp2363624wra; Sun, 28 Jan 2018 18:56:11 -0800 (PST) X-Google-Smtp-Source: AH8x224XhEoppgj24J6fcCh1nBs6R1ViW+W7GpXgJfj921Yrdf53yzZfg+Ol+E9e6jOg6uU0WUYi X-Received: by 10.98.23.23 with SMTP id 23mr25856516pfx.179.1517194571254; Sun, 28 Jan 2018 18:56:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517194571; cv=none; d=google.com; s=arc-20160816; b=vlE3knU7DIrmHV740lBHeQtM/iESvYLkKuQTUFnbjlXvesXPklKpWBa94d4qr1QxnJ pFkWsY00kYcu32MoNWBzsURcxRLhbYxo4QgTQP1eKlO9nJNv4BYULHW6q+OUenRsjVLg Gb+bcRrjFVyFCkQaDW7S6UWiLMba3Q1K7YoGOJ5XL8/+XwNq41nLzNSQgVezDF0Kyqw+ hdO1bSGhFieEK79ZduXEokhxnjZgkG+6RdUjMrppi+Lf/IpvFKd6gImZBpr5xgFERlCz Z8H5Z9bWIzo4NSkfkSlWXBHZynItXme9r5fbruAms1YLE9znF6BTaJMNng5x6eickHrZ AAxA== 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=ZFKdW+6uq9GD3by7X0blyEx7auA7daBvwuw9wBZxcV8=; b=i4uccC3v7VuCdkUzh77R7PZdLGSLcw70GqpqJhNnmI1h0YfNTGQJ3sygPJ5yUiJ8f6 aLbj6Bzx7S8SMikSBWwSyDpo5ZjIhAqrQrXjMuT9qU1KLzp/AHGG9ZPXHZzlNQJ9pQqw ujnKnay0QX9Rr8EXZvI5Nh1e/37sb5GBok8FQoRfN2wuCEBGzJD9uLcBLpWt2qO1jfyK h6+5MKKjWJzQ/859pFN+aJfJ0kEwLAqGmzbLqm6+R0DWwmJFNWA4RdqakmXl4seurWTJ eGh053qMeo1K8TzHsGZJJhYER2MxjhCE7XcpaNCZL0Qm0/u2L4l+uHg/o/4e1WwFbviq OmIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D5mOPstR; 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 bh4-v6si248098plb.14.2018.01.28.18.55.57; Sun, 28 Jan 2018 18:56:11 -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=D5mOPstR; 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 S1752811AbeA1X3i (ORCPT + 99 others); Sun, 28 Jan 2018 18:29:38 -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-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-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 | 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; } -- 2.11.0