From patchwork Thu Oct 19 17:05:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116417 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp721734qgn; Thu, 19 Oct 2017 10:08:45 -0700 (PDT) X-Received: by 10.84.197.131 with SMTP id n3mr2013935pld.227.1508432925070; Thu, 19 Oct 2017 10:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508432925; cv=none; d=google.com; s=arc-20160816; b=bLsJrRWpf5b+wkj8kd9U+BqIuW95REsjmHJGGyimCDWFmk61bUJb4VLRi+SVu4fsJj QBJBA7j/QPVxpmeS6GsKlTnD6rgizileaXymEcNqdWYX5RdC75dVanDUCKIu3h8ocWqf yUYGQUo/TER4adkIMbobKrnl9OFTy+eLWrZz6BUv1fOgl0s9KEm3VUy2Dic/jtUPHaFD o/vGE+uNwCh/JcfxtlPx/oAlQ4tWzjkSV31lZ5z3iUc8lc8VbWdz8V7zmE7xV2/FoJd8 IA8gWA6wV6PIkUUlXRnTnerNpAsSCbedu0fKeN+PN24qNnhTNAm1TL9z3v/89KV2+4zo V5vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=myNl1kd3kkDnlKDudMbJudZ0nM85VsriuAjESUtGHGE=; b=nyvrRsPR3OtsIpxO+N0AALA8I3xRmTKbIWyKIhOifRlK9AejiHx83Y73VrQjq7dckc VoRpbqpREOxeFum51Mf2O2yiQCFT25gIi9ZQsOWVwhL8oCnWNB+qO4lhemvSedxJOaCF hUiU3oZfbFJ4hAvMdXF8j280VCECrn4eCcIb3bCPCZoFEuyrCDLQiZOjmzDNlC79clHH Ml+rFHSpBJ8a28cjCxOm1J7rb57yU9W3wTQkfGoiVnoRiLIBkRF1gw+6Ghmkyb+7qi+C 5tWCey2e7yaiNrxN9xbeAPA0+z3v5vqWgKVsH/+BGTsMXMJ9vZipf9gwcQpIRmYSDjWd JSLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TKzHXFbw; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v22si9602054pfd.212.2017.10.19.10.08.44; Thu, 19 Oct 2017 10:08:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=@linaro.org header.s=google header.b=TKzHXFbw; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755065AbdJSRIm (ORCPT + 12 others); Thu, 19 Oct 2017 13:08:42 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:51915 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753422AbdJSRIk (ORCPT ); Thu, 19 Oct 2017 13:08:40 -0400 Received: by mail-wr0-f194.google.com with SMTP id j14so9041822wre.8 for ; Thu, 19 Oct 2017 10:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=myNl1kd3kkDnlKDudMbJudZ0nM85VsriuAjESUtGHGE=; b=TKzHXFbwqpjPxkMZvWpcc3VUu5vqCl0SW4ves4Ai5nJP0Hkl3yXvn5zfKanv6jiS30 YM6ynvzmLD9N/2mZ+hFcTZRKEOJ94Yf+IOiqtNGoG4vbtxPrI25ymVcQHViizPwnbOUb CqqUoczzWhZQl7hjZp8Zf3f01RD9SftqGnH08= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=myNl1kd3kkDnlKDudMbJudZ0nM85VsriuAjESUtGHGE=; b=CmZUZpxOim1a/6g1EmAjR7Rvzq61ng5MXB4iuofyOF/rEpD8UqlMi635mzQcPrnr6I sJD9Nq7GDQdNsrRAok40oDedOa9qGTBTyTXKfZYRKwabAhYsHCk6+XDlT5F5d5nJIiTY AuyUaiVVgeZgHl7//P21S26xmbpI6Py1cW3mbOhOIrddaEcE8W/y1pS3lqVDHcpo5U0u YzyCeRQRLB/sdZe0E9wkSU8M9/SQWrntgzE+HmW+R37G9RTYW8zNJbyQv5MaMvFeYU7X /4LJTo1NFILU3bFf/gTIlx1zwKCUEh+P0m/J2QTDDkjXaC7yJI5VngOukRhGnmqBfHQg P5Lg== X-Gm-Message-State: AMCzsaV5e2/x+eYQ5wMQdwa9rqIwoK0GwsnlD8mALAizX+ukRK230IRA SNLSB+cSozZadP9fL+qMarcxbg== X-Google-Smtp-Source: ABhQp+RFhn7BjFvgzvW75rZmqVk/XdqU75Rf+dUfbwlrkW1CI3awWNQrjbzMMI46xrCyByeMM6jpLg== X-Received: by 10.223.134.68 with SMTP id 4mr2391352wrw.67.1508432919126; Thu, 19 Oct 2017 10:08:39 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:51c7:d9b7:e14b:6840]) by smtp.gmail.com with ESMTPSA id g16sm14277394wrd.72.2017.10.19.10.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:38 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/18] thermal/drivers/hisi: Encapsulate register writes into helpers Date: Thu, 19 Oct 2017 19:05:49 +0200 Message-Id: <1508432760-17847-7-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> References: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Hopefully, the function name can help to clarify the semantic of the operations when writing in the register. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 92 ++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 22 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index b657ae4..8e8a117 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -26,6 +26,7 @@ #include "thermal_core.h" +#define TEMP0_LAG (0x0) #define TEMP0_TH (0x4) #define TEMP0_RST_TH (0x8) #define TEMP0_CFG (0xC) @@ -96,6 +97,56 @@ static inline long hisi_thermal_round_temp(int temp) hisi_thermal_temp_to_step(temp)); } +static inline void hisi_thermal_set_lag(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_LAG); +} + +static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_INT_CLR); +} + +static inline void hisi_thermal_alarm_enable(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_INT_EN); +} + +static inline void hisi_thermal_alarm_set(void __iomem *addr, int temp) +{ + writel(hisi_thermal_temp_to_step(temp) | 0x0FFFFFF00, addr + TEMP0_TH); +} + +static inline void hisi_thermal_reset_set(void __iomem *addr, int temp) +{ + writel(hisi_thermal_temp_to_step(temp), addr + TEMP0_RST_TH); +} + +static inline void hisi_thermal_reset_enable(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_RST_MSK); +} + +static inline void hisi_thermal_enable(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_EN); +} + +static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) +{ + writel((sensor << 12), addr + TEMP0_CFG); +} + +static inline int hisi_thermal_get_temperature(void __iomem *addr) +{ + return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); +} + +static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_CFG); +} + static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor) { @@ -104,22 +155,21 @@ static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, mutex_lock(&data->thermal_lock); /* disable interrupt */ - writel(0x0, data->regs + TEMP0_INT_EN); - writel(0x1, data->regs + TEMP0_INT_CLR); + hisi_thermal_alarm_enable(data->regs, 0); + hisi_thermal_alarm_clear(data->regs, 1); /* disable module firstly */ - writel(0x0, data->regs + TEMP0_EN); + hisi_thermal_enable(data->regs, 0); /* select sensor id */ - writel((sensor->id << 12), data->regs + TEMP0_CFG); + hisi_thermal_sensor_select(data->regs, sensor->id); /* enable module */ - writel(0x1, data->regs + TEMP0_EN); + hisi_thermal_enable(data->regs, 1); usleep_range(3000, 5000); - val = readl(data->regs + TEMP0_VALUE); - val = hisi_thermal_step_to_temp(val); + val = hisi_thermal_get_temperature(data->regs); mutex_unlock(&data->thermal_lock); @@ -136,28 +186,26 @@ static void hisi_thermal_enable_bind_irq_sensor sensor = &data->sensors; /* setting the hdak time */ - writel(0x0, data->regs + TEMP0_CFG); + hisi_thermal_hdak_set(data->regs, 0); /* disable module firstly */ - writel(0x0, data->regs + TEMP0_RST_MSK); - writel(0x0, data->regs + TEMP0_EN); + hisi_thermal_reset_enable(data->regs, 0); + hisi_thermal_enable(data->regs, 0); /* select sensor id */ - writel((sensor->id << 12), data->regs + TEMP0_CFG); + hisi_thermal_sensor_select(data->regs, sensor->id); /* enable for interrupt */ - writel(hisi_thermal_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, - data->regs + TEMP0_TH); + hisi_thermal_alarm_set(data->regs, sensor->thres_temp); - writel(hisi_thermal_temp_to_step(HISI_TEMP_RESET), - data->regs + TEMP0_RST_TH); + hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); /* enable module */ - writel(0x1, data->regs + TEMP0_RST_MSK); - writel(0x1, data->regs + TEMP0_EN); + hisi_thermal_reset_enable(data->regs, 1); + hisi_thermal_enable(data->regs, 1); - writel(0x0, data->regs + TEMP0_INT_CLR); - writel(0x1, data->regs + TEMP0_INT_EN); + hisi_thermal_alarm_clear(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 1); usleep_range(3000, 5000); @@ -169,9 +217,9 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) mutex_lock(&data->thermal_lock); /* disable sensor module */ - writel(0x0, data->regs + TEMP0_INT_EN); - writel(0x0, data->regs + TEMP0_RST_MSK); - writel(0x0, data->regs + TEMP0_EN); + hisi_thermal_enable(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 0); + hisi_thermal_reset_enable(data->regs, 0); mutex_unlock(&data->thermal_lock); }