Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp825170ybl; Wed, 4 Dec 2019 11:30:20 -0800 (PST) X-Google-Smtp-Source: APXvYqzzZl1bQoeBQSmXEjQDW28t+Caf374axBpr7MwxUAsF00Pi45k70YIIqPEIs4iGKPKIpExz X-Received: by 2002:a54:4595:: with SMTP id z21mr4129688oib.136.1575487819982; Wed, 04 Dec 2019 11:30:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575487819; cv=none; d=google.com; s=arc-20160816; b=wns7x57sKsya0HA30TI1jIz7fvGA/vbzpvHMK8XRZr8nHtA7qOOo43kaKnGsI+9YpE TM4BLFILV4GopiGK/KED30HtW5AL8t/HRw/v09+r0lMjUXT0sqYnql5pObQtoUFhCFaP ImNhh5s4YleDoZv32/32Pg44MAKDUSbcZg1EWb51n0/lkjHkqGG9kQKqS9wisJIdeIGv NsG6PYqmRSnVD7FSSDZnStS4QP0UyZ4ksG/jcH38sD/Ggr1fZ79ervKqIfRMMbvc1k7D 3AgqEqKxmdC4Dq0u052x7DKmTYEM7IuWK+YlsQvgTQmxWM2r1lBXoQ6TZZm3WcnxFL0F c+Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=kLLyy4J1Ke9PrZQ4Qj04E9LcGP1qYhIJ+e8+Ik/qzcQ=; b=ZSWFaMefyWfCn5yRtq6TyxBPI3XD07N1BSjAdUM63rrPmLQAB5FRctdepYWNjw5aDU +j2/HObjzFZyUnDk+L08nfWLkh8gJI3Dc8+VlduW/g7qazNxRTR7740/kgU5Nx+5WpQg q7L98FUzzIEFT9SKiG55OIsd3faRoBvPrImA1D6MbmUyA9TSxOLGMETjTnhn3WX7gb/T QP84mQIkhvv+D/lfLiwNeS0tf0DOMaIxhR6ezgBQnp8d8b7yH54lY0oMa9MJFIeqfuz9 vrcGni7rPKv+QBQ3FEsbs9qZxuroFaWe9C/YoMKGMtgxKVdqBSttxd40PwZR9KWHzvPd uXhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b=zvKuifqq; 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 h203si1076255oif.3.2019.12.04.11.30.07; Wed, 04 Dec 2019 11:30:19 -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=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b=zvKuifqq; 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 S1728407AbfLDTBY (ORCPT + 99 others); Wed, 4 Dec 2019 14:01:24 -0500 Received: from mail-ua1-f66.google.com ([209.85.222.66]:40025 "EHLO mail-ua1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728389AbfLDTBX (ORCPT ); Wed, 4 Dec 2019 14:01:23 -0500 Received: by mail-ua1-f66.google.com with SMTP id p18so185073uar.7 for ; Wed, 04 Dec 2019 11:01:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verdurent-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kLLyy4J1Ke9PrZQ4Qj04E9LcGP1qYhIJ+e8+Ik/qzcQ=; b=zvKuifqq2fTHKGaaySG8Ii7zKmTTY9KKpiGE8IyRXZiOwcFumS4AWFjMNkscTipP8G gTGDombWwvw1Z+YF38r87v7LJjM4hOMwpNu4XSvVd0lAcMpkab47C1XxotXliGl0Yzu5 l8tWJhjBrk7Mwbr0JGLCsugek5MhtWEZD0zFOIsavSkPrJUkk2ouWFD+IHjYjfJAR/3W RO54ryk3Fh90qb1ZPrAw7iAxKkWDad/YNn3tiA6Cgf9XwVzZv3WoF4r+rbkV9YR8OiG7 ojNZMcczVKCGSzgnwC3IzyYr8c84tPdMij/fTS9Qcr+GaM2OTnLw2USSCLIgrP1HBYLt 8HVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kLLyy4J1Ke9PrZQ4Qj04E9LcGP1qYhIJ+e8+Ik/qzcQ=; b=oYpyT92GcWlbektH5FvXEA1SVJIcxfSTx9Y/oR56CcHkPND7bpn51xbRtkSyH1OLmH 7Qh71qBcjfYUkC0MniT/UCLyGH/JNQR4Uc0oXHWBvQ+FiK5+v50MUNGY9xY1mOKt8if8 HJbipWhHRjxrvxer8cdqj1Tfx0++D+fg5Ov/AZsRFnU6iwilSyYwTfQlPzUxmXIx+YyM UZx8+UQl02SgYAtks0kdWFos//x8YdFDDQgnXsfYMg7JuU8jXfs+mDPd00olzTJH6c7p CFsOW0rt5si4/1f+/MmpFTtrbpCfu2UCdYv8s5JF1FgGCBQ78a2xha2yFV8DesIzTBrd hQIQ== X-Gm-Message-State: APjAAAVWl6K1pIQ12hnx9wlzGZX8ciRRNZNe8iI9LaZQVmoZ9vgwIiwF s1bM4hsYruY9dsGmK16dW/dU2MAnF+lRZYncC2eyOg== X-Received: by 2002:a9f:3f46:: with SMTP id i6mr3792634uaj.60.1575486082135; Wed, 04 Dec 2019 11:01:22 -0800 (PST) MIME-Version: 1.0 References: <20191030182132.25763-1-f.fainelli@gmail.com> <20191030182132.25763-2-f.fainelli@gmail.com> <9adf0bd8-99ee-0f38-4608-67c92ba42c88@gmail.com> In-Reply-To: <9adf0bd8-99ee-0f38-4608-67c92ba42c88@gmail.com> From: Amit Kucheria Date: Thu, 5 Dec 2019 00:31:11 +0530 Message-ID: Subject: Re: [PATCH 1/6] thermal: brcmstb_thermal: Do not use DT coefficients To: Florian Fainelli Cc: LKML , Markus Mayer , "maintainer:BROADCOM STB AVS TMON DRIVER" , Zhang Rui , Eduardo Valentin , Daniel Lezcano , Rob Herring , Mark Rutland , "open list:BROADCOM STB AVS TMON DRIVER" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "moderated list:BROADCOM BCM7XXX ARM ARCHITECTURE" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 4, 2019 at 11:12 PM Florian Fainelli wrote: > > On 12/4/19 12:41 AM, Amit Kucheria wrote: > > On Wed, Oct 30, 2019 at 11:51 PM Florian Fainelli wrote: > >> > >> At the time the brcmstb_thermal driver and its binding were merged, the > >> DT binding did not make the coefficients properties a mandatory one, > >> therefore all users of the brcmstb_thermal driver out there have a non > >> functional implementation with zero coefficients. Even if these > >> properties were provided, the formula used for computation is incorrect. > >> > >> The coefficients are entirely process specific (right now, only 28nm is > >> supported) and not board or SoC specific, it is therefore appropriate to > >> hard code them in the driver given the compatibility string we are > >> probed with which has to be updated whenever a new process is > >> introduced. > >> > >> We remove the existing coefficients definition since subsequent patches > >> are going to add support for a new process and will introduce new > >> coefficients as well. > >> > >> Fixes: 9e03cf1b2dd5 ("thermal: add brcmstb AVS TMON driver") > > > > I think you should fix the computation formula as the first patch and > > then merge the rest of this patch into your second patch. > > > > I don't think the intermediate state of converting named constants to > > magic numbers is needed just to convert it over to another set of > > parameters. > > ok, so you would rather see this patch using the defined constants while > fixing the formula, and in a subsequent patch getting rid of the > constant names since they are going to be added to a per-process table, > does that sound reasonable? Yes, that way the first patch would fix a bug (and with a Fixes tag potentially gets backported to stable), the second would convert over to the per-process table. Regards, Amit > > > > Regards, > > Amit > > > >> Signed-off-by: Florian Fainelli > >> --- > >> drivers/thermal/broadcom/brcmstb_thermal.c | 37 ++++------------------ > >> 1 file changed, 6 insertions(+), 31 deletions(-) > >> > >> diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c > >> index 5825ac581f56..42482af0422e 100644 > >> --- a/drivers/thermal/broadcom/brcmstb_thermal.c > >> +++ b/drivers/thermal/broadcom/brcmstb_thermal.c > >> @@ -48,15 +48,6 @@ > >> #define AVS_TMON_TEMP_INT_CODE 0x1c > >> #define AVS_TMON_TP_TEST_ENABLE 0x20 > >> > >> -/* Default coefficients */ > >> -#define AVS_TMON_TEMP_SLOPE -487 > >> -#define AVS_TMON_TEMP_OFFSET 410040 > >> - > >> -/* HW related temperature constants */ > >> -#define AVS_TMON_TEMP_MAX 0x3ff > >> -#define AVS_TMON_TEMP_MIN -88161 > >> -#define AVS_TMON_TEMP_MASK AVS_TMON_TEMP_MAX > >> - > >> enum avs_tmon_trip_type { > >> TMON_TRIP_TYPE_LOW = 0, > >> TMON_TRIP_TYPE_HIGH, > >> @@ -108,23 +99,11 @@ struct brcmstb_thermal_priv { > >> struct thermal_zone_device *thermal; > >> }; > >> > >> -static void avs_tmon_get_coeffs(struct thermal_zone_device *tz, int *slope, > >> - int *offset) > >> -{ > >> - *slope = thermal_zone_get_slope(tz); > >> - *offset = thermal_zone_get_offset(tz); > >> -} > >> - > >> /* Convert a HW code to a temperature reading (millidegree celsius) */ > >> static inline int avs_tmon_code_to_temp(struct thermal_zone_device *tz, > >> u32 code) > >> { > >> - const int val = code & AVS_TMON_TEMP_MASK; > >> - int slope, offset; > >> - > >> - avs_tmon_get_coeffs(tz, &slope, &offset); > >> - > >> - return slope * val + offset; > >> + return (410040 - (int)((code & 0x3FF) * 487)); > >> } > >>l > >> /* > >> @@ -136,20 +115,16 @@ static inline int avs_tmon_code_to_temp(struct thermal_zone_device *tz, > >> static inline u32 avs_tmon_temp_to_code(struct thermal_zone_device *tz, > >> int temp, bool low) > >> { > >> - int slope, offset; > >> - > >> - if (temp < AVS_TMON_TEMP_MIN) > >> - return AVS_TMON_TEMP_MAX; /* Maximum code value */ > >> - > >> - avs_tmon_get_coeffs(tz, &slope, &offset); > >> + if (temp < -88161) > >> + return 0x3FF; /* Maximum code value */ > >> > >> - if (temp >= offset) > >> + if (temp >= 410040) > >> return 0; /* Minimum code value */ > >> > >> if (low) > >> - return (u32)(DIV_ROUND_UP(offset - temp, abs(slope))); > >> + return (u32)(DIV_ROUND_UP(410040 - temp, 487)); > >> else > >> - return (u32)((offset - temp) / abs(slope)); > >> + return (u32)((410040 - temp) / 487); > >> } > >> > >> static int brcmstb_get_temp(void *data, int *temp) > >> -- > >> 2.17.1 > >> > > > -- > Florian