From patchwork Wed Aug 30 08:47:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111284 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp595217qge; Wed, 30 Aug 2017 01:49:03 -0700 (PDT) X-Received: by 10.84.224.7 with SMTP id r7mr1029423plj.273.1504082943687; Wed, 30 Aug 2017 01:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504082943; cv=none; d=google.com; s=arc-20160816; b=ke/LnvWrJ3bhVIgxjQK6UOyHP6qIjPkf5TQ0HGyIin784SqdZkjlh869fZBl1H8ZfO Gng99unyGSecNL1OepXiUWCdv4Qe2m0FVqziiEHOMCkfcMpnl0WC41PD07UOZQJZ/75B wA54VMYen19JaIdePJozNohyx7rAe/iRWskIOI+dg+jSeMomtfmp0y2fsHUBKKStWzxn nfpczcxEODAldXV+2zC2Oz13j34TagzT09sWfgEikY37ngDYIA6QakI39KEoq9vQXQ8m OLfLkWZcgWshTiV6UgO1/8xHaEOs+sSIjodxXS7Y9x7ryA3tLzrqF/OI16NCqXKMg0+o vPgA== 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=H7Rq81WC7FRzqlHCumAXThd9aHoX8pIoG37+155ge1U=; b=Eyr3Q8EWSKXLp18BGWb+5f4vA+YgX7tzLkB29aM3bcDFqoMntVCklfYpvMkL5cUtFQ 29X7H4EQkExko2tmiEdmuf0R7JwuT/YIMbFV41mnkBdEIMAOfUWR/piWt1522AxErOJa UYnyWD0PmiGkv+fm+DkGGI+H4wsiGPDRrNQ841yQSttpvvwG1I6zhZKcfDM4YDQybYT1 RNRgLE8K4X5yauscp9MYx4WYZ9p3bD6l34BUmD6JaISgXUkbtczbC7V1e64nuXwosYba +6jRSiHs84kVp+qhfiW1bWcOq6gm1GPuIDphEMTs18T5YKw3v4+opJjr4oqPATBifFRI jLSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ntxa88zL; 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; 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 h185si3913779pfb.398.2017.08.30.01.49.03; Wed, 30 Aug 2017 01:49:03 -0700 (PDT) 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=@linaro.org header.s=google header.b=Ntxa88zL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751655AbdH3ItA (ORCPT + 26 others); Wed, 30 Aug 2017 04:49:00 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:35055 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751523AbdH3Isz (ORCPT ); Wed, 30 Aug 2017 04:48:55 -0400 Received: by mail-wm0-f53.google.com with SMTP id a80so5553042wma.0 for ; Wed, 30 Aug 2017 01:48:54 -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=H7Rq81WC7FRzqlHCumAXThd9aHoX8pIoG37+155ge1U=; b=Ntxa88zLXh5TtMyQiAh3wz/VFXtkSZ3zke9g/K3T0sjg/d07SHMxqOLhh6kp/qlmQD zBIjb/qsJyRzh5i33HBjfUL1LHpE71hBB/XrWuRHOLClF6Z5sYy8OKOJNkG96rShSjjf ormiiUbHp6ShvWQCmw9vmy3jlaJrQZF7ktde4= 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=H7Rq81WC7FRzqlHCumAXThd9aHoX8pIoG37+155ge1U=; b=ohgAWjsFtwsX5KzNT2l41r/agI5qcafu4TwafYODkcWrEzDOg/43ArdDeCQERfJJCG Z+8pWHyUlpiacRjfwuOzztnBtjXtc2OcRD4q00uJrQN+MyqLg2T+T3Oyhq4a1nEDys71 QiCdRfFprcMzFANkaOtBSDgxD6I1M4tM0CJzAnrlf4iAxxiPCyGEFAi8ANjXQ7jJ9LSm RUC/BrlG8meKzXPs+Ns0jSDB3bU9TKMlEp+XvmxVh9Dxh7QM1twJ8uhT0rxCLUkfgasX dnI0vK6EJMZNOei9kcq0t9Zjxfyo4w8SKcltfT9pmaM4UlPWgXziCjvEjWwH92kMu453 GcuQ== X-Gm-Message-State: AHYfb5hKOmG4rVOx+OZIz+/4OYEZoz4yOCpjWqtMniK9p5Ddme8ylpQ9 Q5Lz8ZfDUPQYs+DU X-Received: by 10.28.210.9 with SMTP id j9mr754965wmg.134.1504082933990; Wed, 30 Aug 2017 01:48:53 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:53 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org (open list) Subject: [PATCH 07/13] thermal/drivers/hisi: Encapsulate register writes into helpers Date: Wed, 30 Aug 2017 10:47:31 +0200 Message-Id: <1504082857-21702-7-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 96 +++++++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 24 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 6f0dab1..d77a938 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,29 +186,27 @@ 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); - - writel(0x0, data->regs + TEMP0_INT_CLR); - writel(0x1, data->regs + TEMP0_INT_EN); + hisi_thermal_reset_enable(data->regs, 1); + hisi_thermal_enable(data->regs, 1); + hisi_thermal_alarm_clear(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 1); + usleep_range(3000, 5000); mutex_unlock(&data->thermal_lock); @@ -169,10 +217,10 @@ 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); }