From patchwork Thu Nov 5 05:18:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caesar Wang X-Patchwork-Id: 7557481 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5CA9EBEEA4 for ; Thu, 5 Nov 2015 05:19:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C94F20808 for ; Thu, 5 Nov 2015 05:19:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 819B920801 for ; Thu, 5 Nov 2015 05:19:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZuCxe-00064t-Rg; Thu, 05 Nov 2015 05:19:46 +0000 Received: from mail-pa0-f68.google.com ([209.85.220.68]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZuCxM-0005iE-9y; Thu, 05 Nov 2015 05:19:36 +0000 Received: by pabfh17 with SMTP id fh17so9383865pab.3; Wed, 04 Nov 2015 21:19:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tfqpnkNEu+i1u5TQGRrKp5tNOchbyMMNMqaEVTFSon8=; b=G4kApgm8MY0iL7bSGEfcFXTSkQ3kQVa/8j/RjXsGFUG8+uC48zv/6dWSZqD4IeRf86 xge4soCJtDyBjKySwpMyn9znmt1ZtTx08xDZhl5hMzZNh0hN3Oo1HPh//dBZAUKJPezq IxNSASVFfsttYk1zxQlQ9cewU1hnXFGaHAFw9ONbESumLPQnKntgMSnL0hfvmMrxN7BN aJCKUvOvT9TIFS9dd/Z0blK0HcDatpTwJnA5RAhQzCFxmCRQfbyFZOgWkDx0XauFVK9p pAzllWXuBrSdteo1/lqodcBaSAE1kmfP/bzdiDp8Gc3wCnYupLX4tgbMVQ4AGAyxX6jw yLTw== X-Received: by 10.68.179.228 with SMTP id dj4mr7081109pbc.112.1446700747298; Wed, 04 Nov 2015 21:19:07 -0800 (PST) Received: from localhost.localdomain ([103.47.144.40]) by smtp.gmail.com with ESMTPSA id ix1sm5234147pbd.40.2015.11.04.21.19.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Nov 2015 21:19:06 -0800 (PST) From: Caesar Wang To: Heiko Stuebner , Eduardo Valentin Subject: [PATCH v2 5/9] thermal: rockchip: Add the flag for adc value increment or decrement Date: Thu, 5 Nov 2015 13:18:01 +0800 Message-Id: <1446700685-18017-6-git-send-email-wxt@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446700685-18017-1-git-send-email-wxt@rock-chips.com> References: <1446700685-18017-1-git-send-email-wxt@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151104_211928_903928_2C516989 X-CRM114-Status: GOOD ( 15.94 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Zhang Rui , linux-arm-kernel@lists.infradead.org, Caesar Wang MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The conversion table has the adc value and temperature. In fact, the adc value only has the increment or decrement mode in conversion table. Moment, we can add the flag to be better support the *code_to_temp* for differenr SoCs. Signed-off-by: Caesar Wang --- Changes in v2: None Changes in v1: None drivers/thermal/rockchip_thermal.c | 64 ++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index e828f18..9df027f 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -53,6 +53,16 @@ enum sensor_id { }; /** +* The conversion table has the adc value and temperature. +* ADC_DECREMENT is the adc value decremnet.(e.g. v2_code_table) +* ADC_INCREMNET is the adc value incremnet.(e.g. v3_code_table) +*/ +enum adc_flag { + ADC_DECREMENT = 0, + ADC_INCREMENT, +}; + +/** * The max sensors is two in rockchip SoCs. * Two sensors: CPU and GPU sensor. */ @@ -66,6 +76,9 @@ struct chip_tsadc_table { /* that analogic mask data */ unsigned long data_mask; + + /* adc value is increment or decrement */ + unsigned int flag; }; struct rockchip_tsadc_chip { @@ -223,19 +236,43 @@ static int rk_tsadcv2_code_to_temp(struct chip_tsadc_table table, u32 code, WARN_ON(table.length < 2); - code &= table.data_mask; - if (code < table.id[high].code) + switch (table.flag) { + case ADC_DECREMENT: + code &= table.data_mask; + if (code < table.id[high].code) return -EAGAIN; /* Incorrect reading */ - while (low <= high) { - if (code >= table.id[mid].code && - code < table.id[mid - 1].code) - break; - else if (code < table.id[mid].code) - low = mid + 1; - else - high = mid - 1; - mid = (low + high) / 2; + while (low <= high) { + if (code >= table.id[mid].code && + code < table.id[mid - 1].code) + break; + else if (code < table.id[mid].code) + low = mid + 1; + else + high = mid - 1; + + mid = (low + high) / 2; + } + break; + case ADC_INCREMENT: + code &= table.data_mask; + if (code < table.id[low].code) + return -EAGAIN; /* Incorrect reading */ + + while (low <= high) { + if (code >= table.id[mid - 1].code && + code < table.id[mid].code) + break; + else if (code > table.id[mid].code) + low = mid + 1; + else + high = mid - 1; + + mid = (low + high) / 2; + } + break; + default: + pr_err("Invalid the table conversion\n"); } /* @@ -245,8 +282,8 @@ static int rk_tsadcv2_code_to_temp(struct chip_tsadc_table table, u32 code, * to produce less granular result. */ num = table.id[mid].temp - v2_code_table[mid - 1].temp; - num *= table.id[mid - 1].code - code; - denom = table.id[mid - 1].code - table.id[mid].code; + num *= abs(table.id[mid - 1].code - code); + denom = abs(table.id[mid - 1].code - table.id[mid].code); *temp = table.id[mid - 1].temp + (num / denom); return 0; @@ -367,6 +404,7 @@ static const struct rockchip_tsadc_chip rk3288_tsadc_data = { .id = v2_code_table, .length = ARRAY_SIZE(v2_code_table), .data_mask = TSADCV2_DATA_MASK, + .flag = ADC_DECREMENT, }, };