Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751767AbbHEKUv (ORCPT ); Wed, 5 Aug 2015 06:20:51 -0400 Received: from metis.ext.pengutronix.de ([92.198.50.35]:36956 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750794AbbHEKUu (ORCPT ); Wed, 5 Aug 2015 06:20:50 -0400 Date: Wed, 5 Aug 2015 12:20:39 +0200 From: Sascha Hauer To: Daniel Kurtz Cc: "Hanyi.Wu" , linux-pm@vger.kernel.org, Zhang Rui , Eduardo Valentin , "linux-kernel@vger.kernel.org" , Sasha Hauer , linux-mediatek@lists.infradead.org, "linux-arm-kernel@lists.infradead.org" , Matthias Brugger Subject: Re: [PATCH 2/3] thermal: Add Mediatek thermal controller support Message-ID: <20150805102039.GH18700@pengutronix.de> References: <1437465566-16299-1-git-send-email-s.hauer@pengutronix.de> <1437465566-16299-3-git-send-email-s.hauer@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 11:00:46 up 41 days, 3:22, 107 users, load average: 0.07, 0.12, 0.13 User-Agent: Mutt/1.5.21 (2010-09-15) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2545 Lines: 90 On Tue, Jul 21, 2015 at 11:13:22PM +0800, Daniel Kurtz wrote: > Hi Sascha, > > Review comments inline... > > > + * > > + * This converts the raw ADC value to mcelsius using the SoC specific > > + * calibration constants > > + */ > > +static int raw_to_mcelsius(struct mtk_thermal *mt, u32 raw) > > +{ > > + s32 format_1, format_2, format_3, format_4; > > The formula would be easier to follow with better variable names than > "format_X". > > > + s32 xtoomt; > > What does "xtoomt" mean? > > > + s32 gain; > > + > > + raw &= 0xfff; > > + > > + gain = (10000 + mt->adc_ge); > > no outer () > > > + > > + xtoomt = ((((mt->vts + 3350 - mt->adc_oe) * 10000) / 4096) * 10000) / > > + gain; > > + > > + format_1 = ((mt->degc_cali * 10) >> 1); > > When doing computations, I think "A / 2" is preferred over "A >> 1". > Also, no outer (). > > > + format_2 = (raw - mt->adc_oe); > > + format_3 = (((((format_2) * 10000) >> 12) * 10000) / gain) - xtoomt; > > This is just: > format_3 = ((((raw - mt->vts - 3350) * 10000) / 4096) * 10000) / gain; > > No wonder mt->adc_oe = 512-512 = 0... it just cancels itself out here, anyway. > > > + format_3 = format_3 * 15 / 18; > > Of course we should multiply by 15/18! > What is going on here? Why this magic 5/6 ratio? > > > + format_4 = ((format_3 * 100) / (165 + mt->o_slope)); > > no outer () > > > + format_4 = format_4 - (format_4 << 1); > > Hmm... > A = X - 2*X; > otherwise known as: > A = -X; > > > + return (format_1 + format_4) * 100; > > Or just: > return (format_1 - format_4) * 100; I must admit I took this calculation from the original driver and never looked at it. Simplifying this further this goes down to: static int raw_to_mcelsius(struct mtk_thermal *mt, u32 raw) { return mt->calib_b + mt->calib_a * (raw & 0xfff); } with calib_a = -123 and calib_b = 465124. I'll address this and the other comments in v2. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/