Received: by 10.223.176.5 with SMTP id f5csp1553054wra; Sun, 28 Jan 2018 03:36:14 -0800 (PST) X-Google-Smtp-Source: AH8x224fnBwwlkpstW4pcQjNC3CUI+poIpBDyX+eZw0FuMkOIEmKo157r/hURu7lD6YsN/t4nq/+ X-Received: by 10.98.62.69 with SMTP id l66mr24198283pfa.20.1517139374524; Sun, 28 Jan 2018 03:36:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517139374; cv=none; d=google.com; s=arc-20160816; b=mdHq+pUTxiTRaAgmYfy/9CZCZr2d/dpb32TL4WHpfdBpO7pNkGLL5dYIm+l19CkOt+ apxmPvRKtTr0A+1YaaCmVaqOeD0BqblKZIq1GmQLyiHTaMCq+aKqCA0XDZ8dF4phfqnc 5ZQ0BX+WUTLGR4mbY9rUfCM89+1Q8qgHJHd23Hq4PSvp405rR76LVeea0Kr6/E9A0fiu Kuda3ozUdxschxHXQ+YlYmVVFbtqwgueXvSH0lPv7uPraq2PgtK/S7lt57/6n0zWZXIm fujDsFc128aMxVV0I/J8eqgJq2rpTQB8OQ30hk2EhRLk5eEpO3DIeoW2yRFxfYp+DKYD N8og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=NBtGzEPLm1SQM+ZcsmtNY8810vd8uuoc0Pqq+BcPtds=; b=X19IJMkjdBpjfLrUYW4eIEBttejWSgjw5h0A9Dvsou1qU9t1qcJbB749V7Ypo3G0/x Wi7UENb4aLJnz0YhP2cAzJ95759Mll/SF79PqW1p6wTqy5h//2BjeuaatVgu/CjyRYXv 8AcKMz1IZKUz3rXyYzxklpJgxiOtIlNVJ7Ew6PleJRh8MfpeGJmC/nKuN5dL5fwZ6eTg BrpMqHmES9r3zoX5aW46r1EM3rRhWJqDhEptqI2fH2xmJJ4JojEzZzG8jWWqwMun+ynJ oIJU0SQXoe2J6aGR8tCMsoVXU80eHaVSRC5Hx/QwQDzTIgj7T8qODewQzVMWG3L9P0uT 6ZkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DuWJYFCd; 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 u185si5633402pgc.101.2018.01.28.03.35.29; Sun, 28 Jan 2018 03:36:14 -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=DuWJYFCd; 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 S1751654AbeA1Lee (ORCPT + 99 others); Sun, 28 Jan 2018 06:34:34 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:45783 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751298AbeA1Lec (ORCPT ); Sun, 28 Jan 2018 06:34:32 -0500 Received: by mail-wr0-f195.google.com with SMTP id 16so4175942wry.12; Sun, 28 Jan 2018 03:34:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=NBtGzEPLm1SQM+ZcsmtNY8810vd8uuoc0Pqq+BcPtds=; b=DuWJYFCdrkmcJL9OVdk+Lh/CRj0jGK7Kb2jYyOEyrHaRSlZ3+Y3vYc9ZxVjeRGGruC T044TtyM9DzmZJC/vJTLVIlQncTvpwkGQR0RLsJRq+T6dcVJfjaVBDaGrsH4IRLqo1AC 26g3AiFztFxJvx+n1jK+5cEwK0O9o71VQzFia5hIvz/YEqamIc19WDu1RNrYkdpqs/rJ TdKSAga7BdfoI02IUtgV0Mi2tWSsevrCTFaoiBldpgmhamgkgTAoQIHFMVbV9ab10Ihu /PzNDT7sO3HLj0zbqE8MlcGnrd3J6JV2eylOFARWg2wcvbuX4dh+mYl3rH8hkMDBak9c VdQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=NBtGzEPLm1SQM+ZcsmtNY8810vd8uuoc0Pqq+BcPtds=; b=ras6Kz+p7sJqL+UlGf24ke4qP34hz9GtLFYTuJ2VcPudFkSVtN8j5N3Oy+TchaRtzg A3MIQkUg40meVZFECOQUfY+rew6Vx34I8eD9pCnppPpXGzSOYINItfCP4++JZAPlU6ne 3qs0o7Llq4qjIQqXE/cvIJ5yehnBxhPSy+EhLZQfOaglIRMQhUDuJTwpju2w/BAkq7XT xaysHx50bbdF4DqpsEg4KMrzbHSe65TSo1IvdaxQpqOS8KIEIk7/Pb+JKJGDY146+g5I 3ABmm9W3zjgDKxROv8ZX4aev/52TJ/3n57Y5ZZZXjz3t+dAh9psU5iEo56o8aAz5P1nE xuXQ== X-Gm-Message-State: AKwxyteIvgxy93U2lgC2OGZG2NZmqvwJR3bTp6EhV6xq8R383Y6PTxhr g1l1BnCT6Gclwr0jqQO7xNs= X-Received: by 10.223.128.231 with SMTP id 94mr15810949wrl.64.1517139270211; Sun, 28 Jan 2018 03:34:30 -0800 (PST) Received: from [192.168.2.62] (p578F04D2.dip0.t-ipconnect.de. [87.143.4.210]) by smtp.gmail.com with ESMTPSA id x203sm22298269wmd.11.2018.01.28.03.34.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jan 2018 03:34:29 -0800 (PST) Subject: Re: [PATCH 05/16] iio: adc: sun4i-gpadc-iio: rework: support clocks and reset To: Jonathan Cameron Cc: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@free-electrons.com, wens@csie.org, linux@armlinux.org.uk, 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, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com References: <20180126151941.12183-1-embed3d@gmail.com> <20180126151941.12183-6-embed3d@gmail.com> <20180128085036.389c2dfb@archlinux> From: Philipp Rossak Message-ID: <489c4e33-13ca-e6fe-bb49-8795fb793fd0@gmail.com> Date: Sun, 28 Jan 2018 12:34:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20180128085036.389c2dfb@archlinux> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28.01.2018 09:50, Jonathan Cameron wrote: > On Fri, 26 Jan 2018 16:19:30 +0100 > Philipp Rossak wrote: > >> 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 > > Both clock and reset code is safe against null parameters, so you can > drop a lot of 'is it here' checks in this. They could be argued to > act as documentation of the fact we really don't expect them in some cases > I suppose... > Ok, this sounds good for me! I will fix that in the next version of this patch series. >> --- >> 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); > > Safe against null parameter... (see below) > >> + >> + 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); > > clk_enable is safe against null parameter so could do without the checks. > >> + >> + 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); > > clk_disable_unprepare is safe against a null parameter > so I don't think the checks are needed. > >> + >> + if (info->data->has_bus_clk) >> + clk_disable_unprepare(info->bus_clk); >> + >> + if (info->data->has_bus_rst) >> + reset_control_assert(info->reset); > > Safe against null parameter... > >> + >> return 0; >> } >> > Thanks, Philipp