Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp350359imm; Fri, 31 Aug 2018 02:04:35 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbXZ0elMr+c/GyXEh+BA1e97tU8Okd7NNxZVNetMOp0/Dcvl2XPftAeIVUZB5ONGZQZhmY3 X-Received: by 2002:a65:6550:: with SMTP id a16-v6mr13120158pgw.22.1535706275265; Fri, 31 Aug 2018 02:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535706275; cv=none; d=google.com; s=arc-20160816; b=YprbGrurJnsqa70Kj21GOjVGvlGwhVWu6/zqkn/yRix6S0UgMSUdCOQHkEuN7Nd52c MstTHgickQ7HhRyvusF2k+csQdB5U7MtxcKnVoMi5/x0kQU9mRGL97GixA8aGZBRhIk9 aOxYx31lF+/aFNMZD8vKDjTgfkAecT/yeNFnN7OKKlTgVFxzmBTyg5+Fis4amoxFlX06 IQ7rP8znA/1NoE12Dy2xiU2m0lH2bheiWc7YrbzUC6HUZ2nwM3ScwuahZ5Wf6x1QVPS2 +FOiAFINPnYcdVMeoFPno2BOxrG9A1wkKjdAutmZHzMPPRWa2JbaKvtPCZIgwChQprBw 8+iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=1S9iQ941w/KOZJBYjFGQ6vzv5vK4b/C95fndT2BYkGE=; b=T0fz2gUMmtwvlIOOilqOZQAW+eRaqkBH7HvmU4pLGJrKgRmuH+r5Wy0QNWBEzXxIvA x74ucJq5RWVowJHnzrSP0Td63FTEmJ5I4xcueQHhiDsalW2IUasLprvYyx2Qfau1FtVg 0YW5M+PpaYLSeG85vOEwtR79H36p/vuPFC78xMtBYk4qSFo/0cxWwI9tFJ9f0A89X+OE YYSakYYBN1CAVMFBEii67JFMd0z2zCrmHQwRcyv8lT0Yd/GbcXZtblurVeSpqIlZCdvL 0Cme6AAw0eep6RrSs7YkhmoSu9LHguSvGOBg96FAyeSeicGtGALMRSS6Rx2IGQuiVhVQ Z0Bw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6-v6si8861889plk.31.2018.08.31.02.04.20; Fri, 31 Aug 2018 02:04:35 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727758AbeHaNJj (ORCPT + 99 others); Fri, 31 Aug 2018 09:09:39 -0400 Received: from mail.bootlin.com ([62.4.15.54]:33028 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727542AbeHaNJj (ORCPT ); Fri, 31 Aug 2018 09:09:39 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id EA8B320877; Fri, 31 Aug 2018 11:03:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (AAubervilliers-681-1-92-107.w90-88.abo.wanadoo.fr [90.88.33.107]) by mail.bootlin.com (Postfix) with ESMTPSA id B3309207EB; Fri, 31 Aug 2018 11:03:08 +0200 (CEST) Date: Fri, 31 Aug 2018 11:03:07 +0200 From: Maxime Ripard To: Philipp Rossak Cc: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.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, 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: Re: [PATCH v3 17/30] iio: adc: sun4i-gpadc-iio: rework: support clocks and reset Message-ID: <20180831090307.v3bp445sgugquh6f@flea> References: <20180830154518.29507-1-embed3d@gmail.com> <20180830154518.29507-18-embed3d@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="o4ox2v23labjh637" Content-Disposition: inline In-Reply-To: <20180830154518.29507-18-embed3d@gmail.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --o4ox2v23labjh637 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 30, 2018 at 05:45:05PM +0200, Philipp Rossak wrote: > For adding newer sensor some basic rework of the code is necessary. >=20 > 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. >=20 > This commit reworks the code, adds the process of the clocks and resets. >=20 > Signed-off-by: Philipp Rossak > --- > drivers/iio/adc/sun4i-gpadc-iio.c | 72 +++++++++++++++++++++++++++++++++= ++++-- > 1 file changed, 70 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gp= adc-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. > */ > =20 > +#include > #include > #include > #include > @@ -31,6 +32,7 @@ > #include > #include > #include > +#include > #include > #include > =20 > @@ -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; > }; > =20 > @@ -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; > }; > =20 > static const struct iio_chan_spec sun4i_gpadc_channels[] =3D { > @@ -472,8 +480,13 @@ static int sun4i_gpadc_probe_dt(struct platform_devi= ce *pdev, > if (IS_ERR(base)) > return PTR_ERR(base); > =20 > - info->regmap =3D devm_regmap_init_mmio(&pdev->dev, base, > - &sun4i_gpadc_regmap_config); > + if (info->data->has_bus_clk) > + info->regmap =3D devm_regmap_init_mmio_clk(&pdev->dev, "bus", > + base, &sun4i_gpadc_regmap_config); > + else > + info->regmap =3D devm_regmap_init_mmio(&pdev->dev, base, > + &sun4i_gpadc_regmap_config); > + > if (IS_ERR(info->regmap)) { > ret =3D 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_devi= ce *pdev, > } > } > =20 > + if (info->data->has_bus_rst) { > + info->reset =3D devm_reset_control_get(&pdev->dev, NULL); > + if (IS_ERR(info->reset)) { > + ret =3D PTR_ERR(info->reset); > + return ret; > + } > + > + ret =3D reset_control_deassert(info->reset); > + if (ret) > + return ret; > + } > + > + if (info->data->has_bus_clk) { > + info->bus_clk =3D devm_clk_get(&pdev->dev, "bus"); > + if (IS_ERR(info->bus_clk)) { > + ret =3D PTR_ERR(info->bus_clk); > + goto assert_reset; > + } > + > + ret =3D clk_prepare_enable(info->bus_clk); > + if (ret) > + goto assert_reset; That should be done in the runtime_resume hook > + } > + > + if (info->data->has_mod_clk) { > + info->mod_clk =3D devm_clk_get(&pdev->dev, "mod"); > + if (IS_ERR(info->mod_clk)) { > + ret =3D PTR_ERR(info->mod_clk); > + goto disable_bus_clk; > + } > + > + /* Running at 4MHz */ > + ret =3D clk_set_rate(info->mod_clk, 4000000); > + if (ret) > + goto disable_bus_clk; Why? > + ret =3D clk_prepare_enable(info->mod_clk); > + if (ret) > + goto disable_bus_clk; > + } > + > info->sensor_device =3D &pdev->dev; > =20 > return 0; > + > +disable_bus_clk: > + clk_disable_unprepare(info->bus_clk); > + > +assert_reset: > + reset_control_assert(info->reset); You should check for the variables here before calling those functions, if you end up here with your variable not set, you'll have improper refcounting. Maxime --=20 Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com --o4ox2v23labjh637 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE0VqZU19dR2zEVaqr0rTAlCFNr3QFAluJBEsACgkQ0rTAlCFN r3Sy0w//QZInrgKvIlcZrtJ5CgqUW1VCq32Wo8LuWKyy2oRDMcfmc2HdSaIPKDpJ OTfzIh/l8yx9DLkFZu/UHpZbeqhZSi9471uFzbyZv8GubpDP+IPP9lhWlr8YnxPh 3ZlQy+x/jQ5CG0FTGMI+WfmgTAUezTh+XyjFoEsNsd6n0Kf4htzPQgu1yXHeu1+G 6XemmN+1chO9AqKOBZwyyOnrDfxYSmuxybCHSwlqv2sN5kldgklnV1FL1N/VGSQg NrKidawvuTriY42xFI6hvc48T5uSDNUCOeyn5oss80EVpsXtb4zkrL+jYWLqMOCm iw9VHioVZA/UekDnwyuPWb3NyOCgE3gnSTvl97ftplUxyrmx7UYuHvP7gX0TVnUH cpDBeQSJhbPrBTqwG7QJzNgaBCdu/frNFTtP6YN4CBX1X/RsLtYFr257l88DopsC uupPPulQCcBMOjAuve63PqaEhI1SiG4qdQA9syYL2Kb+oWp9AOq5WTmaB6Nm78Uk 7BkFjJegYIy3AC0/Qap/joOH/qM+CC7LE+Q4c6624CMJK4ZWOfs9KJ87ty3zXGTG zceMZ8xmyKs2OvRh7a4paEam4Wpgjws5tyo0zWyG4pm+BPnxQBR41q17HmnRgLvB bu9/DZXjjpO0H8walsuoRT07gESiwaxz7FxFIc9xdQJKY7a5W1c= =30Zm -----END PGP SIGNATURE----- --o4ox2v23labjh637--