Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp662873ybm; Tue, 21 May 2019 01:06:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxOW4cVEK1MbARpO257etFC+0LdP/4hA16eGpc5VZsFk1TppWASBJslRbxKNuFMQt0xyli X-Received: by 2002:a17:902:d896:: with SMTP id b22mr68005698plz.40.1558426017377; Tue, 21 May 2019 01:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558426017; cv=none; d=google.com; s=arc-20160816; b=NEVGcbH0bhKIpJnUrsOX/hCBi7GFkH9FJpl+IdvlQFFY+z1qZ6znqGWD1GeowAmG0X Eemb0xt+Gpqx4w6Pq8j0k9QG6iJw6faQ5GzfS9LDzv+yr7Q1aTF3DC7PjGxVMGWrn3Q5 NmomG484qUhDmvZYz4/+x+rcREYM1reIUn/MVUpInoOjLDXv3D7MFvyeVE4epvJ/S3VM nc4bu3C0orOPj/L1QpQei63GIK3HQnLvDiTGbNWDNzlsyZrFem1/vbhAccWiy43/ZI3a mwtCmcOnUFI3fkror6NKWl7xhzPwrEuhTJIDt1rHpJOlNj+9DRMa6hWc+4p31+X8JtF1 36Zw== 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; bh=cFmBq/0dPx+zBirBdkZYRdxdjcfm8B+NX9llgwq7FI8=; b=TqnqleKdblRgyyY7K1+glOGqKUMPnaYj6aWa/QW4YYX756/o02TCkCawfrKOUcRA7Y HSJIOVbuSQX4v4D3qi2PUTfa8I9P0MZfbXhbIM0mIiNCL8ObjWeWmtkWB/Vzt8wHuWh7 AEYA5c67H+9ew3297Nr6ue69TwApSvJgC7vaUCaVHTbQhiO3NViZNIlZXdRGSPZFeKM2 WiW+nh5CHJ2s2SWEmzJ/wmxzVmcjjlZVrl1sRLyrB6kCjErFcxtPjd2ZaIK+WMzYapn+ bz0NxndJql8DKePErLf8lH0sjRpRRoVwVDpVi7qDcpobojeFkgoSfeAMNDkUuy19mbyD 4OYA== 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 i98si20628062plb.104.2019.05.21.01.06.42; Tue, 21 May 2019 01:06:57 -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 S1726941AbfEUIFh (ORCPT + 99 others); Tue, 21 May 2019 04:05:37 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:41615 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726138AbfEUIFh (ORCPT ); Tue, 21 May 2019 04:05:37 -0400 Received: from localhost (aaubervilliers-681-1-80-185.w90-88.abo.wanadoo.fr [90.88.22.185]) (Authenticated sender: maxime.ripard@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 5170D10002B; Tue, 21 May 2019 08:05:16 +0000 (UTC) Date: Tue, 21 May 2019 10:05:15 +0200 From: Maxime Ripard To: Frank Lee Cc: rui.zhang@intel.com, Eduardo Valentin , Daniel Lezcano , robh+dt@kernel.org, Mark Rutland , Chen-Yu Tsai , catalin.marinas@arm.com, will.deacon@arm.com, David Miller , Mauro Carvalho Chehab , Greg Kroah-Hartman , Jonathan.Cameron@huawei.com, Nicolas Ferre , paulmck@linux.ibm.com, Andy Gross , olof@lixom.net, bjorn.andersson@linaro.org, Jagan Teki , marc.w.gonzalez@free.fr, stefan.wahren@i2se.com, enric.balletbo@collabora.com, Linux PM , devicetree@vger.kernel.org, Linux ARM , Linux Kernel Mailing List Subject: Re: [PATCH 2/3] thermal: sun50i: add thermal driver for h6 Message-ID: <20190521080515.qlni2lnmcwh7itl7@flea> References: <20190512082614.9045-1-tiny.windzz@gmail.com> <20190512082614.9045-3-tiny.windzz@gmail.com> <20190512133930.t5txssl7mou2gljt@flea> <20190517073634.izdmba3yqvxviyg3@flea> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wynwzlv2suaup6a4" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --wynwzlv2suaup6a4 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, May 18, 2019 at 01:27:39AM +0800, Frank Lee wrote: > On Fri, May 17, 2019 at 3:36 PM Maxime Ripard = wrote: > > > > On Fri, May 17, 2019 at 01:51:56AM +0800, Frank Lee wrote: > > > > > +struct sun50i_thermal_chip { > > > > > + int sensor_num; > > > > > + int offset; > > > > > + int scale; > > > > > + int ft_deviation; > > > > > + int temp_calib_base; > > > > > + int temp_data_base; > > > > > + int (*enable)(struct tsens_device *tmdev); > > > > > + int (*disable)(struct tsens_device *tmdev); > > > > > +}; > > > > > > > > I'm not super fond of having a lot of quirks that are not needed. If > > > > we ever need those quirks when adding support for a new SoC, then > > > > yeah, we should totally have some, but only when and if it's needed. > > > > > > > > Otherwise, the driver is more complicated for no particular reason. > > > > > > This is unavoidable because of the difference in soc. > > > > I know, but this isn't my point. > > > > My point is that at this time of the driver development, we don't know > > what is going to be needed to support all of those SoCs. > > > > Some of the parameters you added might not be needed, some parameters > > might be missing, we don't know. So let's keep it simple for now. > > > > > > > +static int tsens_probe(struct platform_device *pdev) > > > > > +{ > > > > > + struct tsens_device *tmdev; > > > > > + struct device *dev =3D &pdev->dev; > > > > > + int ret; > > > > > + > > > > > + tmdev =3D devm_kzalloc(dev, sizeof(*tmdev), GFP_KERNEL); > > > > > + if (!tmdev) > > > > > + return -ENOMEM; > > > > > + > > > > > + tmdev->dev =3D dev; > > > > > + tmdev->chip =3D of_device_get_match_data(&pdev->dev); > > > > > + if (!tmdev->chip) > > > > > + return -EINVAL; > > > > > + > > > > > + ret =3D tsens_init(tmdev); > > > > > + if (ret) > > > > > + return ret; > > > > > + > > > > > + ret =3D tsens_register(tmdev); > > > > > + if (ret) > > > > > + return ret; > > > > > + > > > > > + ret =3D tmdev->chip->enable(tmdev); > > > > > + if (ret) > > > > > + return ret; > > > > > > > > > > + platform_set_drvdata(pdev, tmdev); > > > > > > > > Your registration should be the very last thing you do. Otherwise, = you > > > > have a small window where the get_temp callback can be called, but = the > > > > driver will not be functional yet. > > > > > > No. Anyway, ths data qcquisition is ms level. > > > > That's kind of irrelevant. There's nothing preventing get_temp to be > > called right away. > > As Ond=C5=99ej said, > > Registration after enabling will lead to call tz update on non-registered= tz > from an interrupt handler. I'm probably missing something but you're not using the interrupts, so how could an interrupt handler call it? Also, other drivers seem to be doing that just fine (mtk_thermal for example), so surely there's a way? > > > > > + ret =3D tsens_calibrate(tmdev); > > > > > + if (ret) > > > > > + return ret; > > > > > + > > > > > + /* > > > > > + * clkin =3D 24MHz > > > > > + * T acquire =3D clkin / (SUN50I_THS_CTRL0_T_ACQ + 1) > > > > > + * =3D 20us > > > > > + */ > > > > > + regmap_write(tmdev->regmap, SUN50I_THS_CTRL0, > > > > > + SUN50I_THS_CTRL0_T_ACQ(479)); > > > > > + /* average over 4 samples */ > > > > > + regmap_write(tmdev->regmap, SUN50I_H6_THS_MFC, > > > > > + SUN50I_THS_FILTER_EN | > > > > > + SUN50I_THS_FILTER_TYPE(1)); > > > > > + /* period =3D (SUN50I_H6_THS_PC_TEMP_PERIOD + 1) * 4096 / c= lkin; ~10ms */ > > > > > + regmap_write(tmdev->regmap, SUN50I_H6_THS_PC, > > > > > + SUN50I_H6_THS_PC_TEMP_PERIOD(58)); > > > > > + /* enable sensor */ > > > > > + val =3D GENMASK(tmdev->chip->sensor_num - 1, 0); > > > > > + regmap_write(tmdev->regmap, SUN50I_H6_THS_ENABLE, val); > > > > > + > > > > > + return 0; > > > > > + > > > > > +assert_reset: > > > > > + reset_control_assert(tmdev->reset); > > > > > + > > > > > + return ret; > > > > > > > > Can't we do that with runtime_pm? > > > > > > Saving energy doesn't make much sense compared to system security. > > > > I'm not sure what you mean by security. > > Protect system hardware from damage. The point of runtime_pm is to keep the device on as long as it is used, so it wouldn't change anything there. I mean, you can even enable it in the probe if you want, my point is that the hooks that you have are exact equivalents to the one provided by runtime_pm already, so there's no need to define them in the first place. Maxime -- Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com --wynwzlv2suaup6a4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCXOOxOwAKCRDj7w1vZxhR xRMtAP91ilrEN2/Up1pDVPYLzGtsG5/5TylmGwA16kfxTf866gEA4vv7/OZHgBoU X5DcfJ4w/u+4LrKYfnWPnhbt0ITqrAY= =2LZ/ -----END PGP SIGNATURE----- --wynwzlv2suaup6a4--