Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1542739yba; Fri, 17 May 2019 00:38:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7xi63rnk7BW6aV5K+amK5dsVuPuPnEmFwr1P4dvD3iBBsYbeSHwoJ5djnXBC/3qgaHRpQ X-Received: by 2002:a65:5347:: with SMTP id w7mr6016892pgr.375.1558078726321; Fri, 17 May 2019 00:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558078726; cv=none; d=google.com; s=arc-20160816; b=qkxEyhWQ1NwPlU2lPLMhaneGZ10cOQpRw4We18tnH9sFfX3Cqz812PXiMrEWeDXJBi /mRdHacpqZyXkP65+sbKf4BCfFNUVuPyRKdZkGGFswyAipDH+k39zGKccD2lzx2//3Po +c4iZwVRvLKJqHJVSVAOIK1vQ2ZAWfukSS1a7TztJTfacHsh8GZr+t5mQFLIyrpF3TaU Tx6retqjR209DBBVEInSoMCGKhJ++DxeImJ6Fgmlrr2RbVnmbTuoo8hpUWxnCmFcvGV6 x3ylm19t3O6cXJvCqrgkL0UuoNwDEqno9sRCCCpTC3fo2vP65IXzPGIWsVOmkfjh7K7I BHeQ== 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=6IaYk1iORoRPXKkuy6kLtDczAh5tq6MZsP8uKfMLqv8=; b=anCH4rv9H18CZPODxZTUvNgJvAdhVkqCd/jkBlf9U3cPqltEmG9KO7s3JVSkTYY0og PcCrKThCBR/91B9fxBXSLgCgUMxFjUbxww+jmdNRJYon4dn33LAx9fhd1zquFdfxdFrH 4NlaEgbb4A6wVfDz6xXhgyibzIxa3SG5hTeRVn9vGMU734ZiuBjnttJTce2fF0iP21Bn r2jyP8HCYz3XoIIGEzZntUm5S9SeWRVhWVuiUxwiYGEdKhxiE0WKrOLoXwv5/P7nVtat 0s/76IVqd3/B8g8X3MbLpRlZU472TAK3nrkf93fErQhk7njD8Ya29I6uvuYsIb6MwBie VDLg== 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 h27si7572440pgm.297.2019.05.17.00.38.31; Fri, 17 May 2019 00:38:46 -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 S1728542AbfEQHgt (ORCPT + 99 others); Fri, 17 May 2019 03:36:49 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:55927 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727500AbfEQHgs (ORCPT ); Fri, 17 May 2019 03:36:48 -0400 X-Originating-IP: 80.215.154.25 Received: from localhost (unknown [80.215.154.25]) (Authenticated sender: maxime.ripard@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 93CA424000E; Fri, 17 May 2019 07:36:35 +0000 (UTC) Date: Fri, 17 May 2019 09:36:34 +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: <20190517073634.izdmba3yqvxviyg3@flea> References: <20190512082614.9045-1-tiny.windzz@gmail.com> <20190512082614.9045-3-tiny.windzz@gmail.com> <20190512133930.t5txssl7mou2gljt@flea> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="k3cws7k6b2j4fvaj" 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 --k3cws7k6b2j4fvaj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 = &pdev->dev; > > > + int ret; > > > + > > > + tmdev = devm_kzalloc(dev, sizeof(*tmdev), GFP_KERNEL); > > > + if (!tmdev) > > > + return -ENOMEM; > > > + > > > + tmdev->dev = dev; > > > + tmdev->chip = of_device_get_match_data(&pdev->dev); > > > + if (!tmdev->chip) > > > + return -EINVAL; > > > + > > > + ret = tsens_init(tmdev); > > > + if (ret) > > > + return ret; > > > + > > > + ret = tsens_register(tmdev); > > > + if (ret) > > > + return ret; > > > + > > > + ret = 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. > > > + ret = tsens_calibrate(tmdev); > > > + if (ret) > > > + return ret; > > > + > > > + /* > > > + * clkin = 24MHz > > > + * T acquire = clkin / (SUN50I_THS_CTRL0_T_ACQ + 1) > > > + * = 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 = (SUN50I_H6_THS_PC_TEMP_PERIOD + 1) * 4096 / clkin; ~10ms */ > > > + regmap_write(tmdev->regmap, SUN50I_H6_THS_PC, > > > + SUN50I_H6_THS_PC_TEMP_PERIOD(58)); > > > + /* enable sensor */ > > > + val = 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. Maxime -- Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com --k3cws7k6b2j4fvaj Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCXN5kggAKCRDj7w1vZxhR xSjEAP0ROb9O13AokItNEnWe0Lv3GDFB7l31wQEb3cxsP3Vh7QEAr1e8+X/0WwOo AWNOgr6T4osFIe+fzrg7yYJbVXsPogc= =AWAL -----END PGP SIGNATURE----- --k3cws7k6b2j4fvaj--