From patchwork Wed Apr 16 14:15:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 4001841 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B73C1BFF02 for ; Wed, 16 Apr 2014 14:16:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DB1CB2034A for ; Wed, 16 Apr 2014 14:16:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01BFE20306 for ; Wed, 16 Apr 2014 14:16:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161417AbaDPOQF (ORCPT ); Wed, 16 Apr 2014 10:16:05 -0400 Received: from top.free-electrons.com ([176.31.233.9]:48881 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1161272AbaDPOQD (ORCPT ); Wed, 16 Apr 2014 10:16:03 -0400 Received: by mail.free-electrons.com (Postfix, from userid 106) id 9E8A17D9; Wed, 16 Apr 2014 16:16:03 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from localhost.localdomain (unknown [190.2.108.73]) by mail.free-electrons.com (Postfix) with ESMTPSA id 6182C60F; Wed, 16 Apr 2014 16:15:59 +0200 (CEST) From: Ezequiel Garcia To: , , Zhang Rui , Jason Cooper Cc: Sebastian Hesselbarth , Andrew Lunn , Arnd Bergmann , , Thomas Petazzoni , Gregory Clement , Jason Gunthorpe , Lior Amsalem , Tawfik Bayouk , Ezequiel Garcia Subject: [PATCH 2/6] thermal: armada: Add infrastructure to support generic formulas Date: Wed, 16 Apr 2014 11:15:16 -0300 Message-Id: <1397657720-10893-3-git-send-email-ezequiel.garcia@free-electrons.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1397657720-10893-1-git-send-email-ezequiel.garcia@free-electrons.com> References: <1397657720-10893-1-git-send-email-ezequiel.garcia@free-electrons.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to support other similar SoC, with different sensor coeficients, this commit adds the coeficients to the per-variant structure, instead of having the formula hardcoded. Signed-off-by: Ezequiel Garcia --- drivers/thermal/armada_thermal.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index c5db071..4de6e56 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -53,6 +53,11 @@ struct armada_thermal_data { /* Test for a valid sensor value (optional) */ bool (*is_valid)(struct armada_thermal_priv *); + + /* Formula coeficients: temp = (b + m * reg) / div */ + unsigned long coef_b; + unsigned long coef_m; + unsigned long coef_div; }; static void armadaxp_init_sensor(struct armada_thermal_priv *priv) @@ -111,6 +116,7 @@ static int armada_get_temp(struct thermal_zone_device *thermal, { struct armada_thermal_priv *priv = thermal->devdata; unsigned long reg; + unsigned long m, b, div; /* Valid check */ if (priv->data->is_valid && !priv->data->is_valid(priv)) { @@ -121,7 +127,13 @@ static int armada_get_temp(struct thermal_zone_device *thermal, reg = readl_relaxed(priv->sensor); reg = (reg >> THERMAL_TEMP_OFFSET) & THERMAL_TEMP_MASK; - *temp = (3153000000UL - (10000000UL*reg)) / 13825; + + /* Get formula coeficients */ + b = priv->data->coef_b; + m = priv->data->coef_m; + div = priv->data->coef_div; + + *temp = (b - (m * reg)) / div; return 0; } @@ -131,11 +143,17 @@ static struct thermal_zone_device_ops ops = { static const struct armada_thermal_data armadaxp_data = { .init_sensor = armadaxp_init_sensor, + .coef_b = 3153000000UL, + .coef_m = 10000000UL, + .coef_div = 13825, }; static const struct armada_thermal_data armada370_data = { .is_valid = armada_is_valid, .init_sensor = armada370_init_sensor, + .coef_b = 3153000000UL, + .coef_m = 10000000UL, + .coef_div = 13825, }; static const struct of_device_id armada_thermal_id_table[] = {