From patchwork Tue Oct 10 18:02:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115444 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4047223qgn; Tue, 10 Oct 2017 11:13:24 -0700 (PDT) X-Received: by 10.99.125.23 with SMTP id y23mr13458266pgc.333.1507659204131; Tue, 10 Oct 2017 11:13:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507659204; cv=none; d=google.com; s=arc-20160816; b=icb14p2fLNn2lGx8UPTOGdNb8N7XJyxh5jh68uMOYC43sHniRmzoso2HXPvigcC8PR 9SZjhSTe2vbJc8Dg8QnyZOIaZAZCDhFfwD7w5P4+hhdCEf0LH0pikNASEMObJEmy/auw x3u+fiwms6sGFkmR33iQ2JQ4ZmVmzjeFAYVjDPfsXzhdQZ9O0RAg3IRZuconADoBdm7c w+V2Wd7yyW2RYEJHUbeA4+ADy38M1+kYmka3IIC4Ce3JY9usg3Ue1RQMSiftJ1suLGF4 tDNJpmptW3TerNN0/XNNcx7HgXszwn9chEnQX4KgVREAaC5cUfM3UIRIUjHvUTOb3cN5 gvPw== 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=SUvARAyx6EuIlE3IoE8ULdMxmF/0O2eyrnwx0wdYK3g5jMXJq5CM3R2tUed3WLQRce 9JOcOdqoDt/mNlCZkVf8XXEYfEyOWdBF2+oOMRECvUnkQ+znquLy7W9K5zduloQgWCCM ENdwnENfTStEXEWXEO+RrsoBKjif6y8eAfpRIqd4QRbEBZTxgJOKf4Kgmm/QqRK/f+Yh AZ4929mtgn/QMInPqFz/SetCLnhouHeeQEidBSz3gZ1i+TNikbeHOsVfF7vSlnsNSvrx ezxFiCk/IfSwWcA1et62q3WSGaT8VEkZGh//naCSVWkK22ETZkmgMQDyKSG2yY+lP3kr T4GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gUm0PaNw; 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 q81si9081475pfg.32.2017.10.10.11.13.23; Tue, 10 Oct 2017 11:13:24 -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=gUm0PaNw; 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 S932499AbdJJSNV (ORCPT + 12 others); Tue, 10 Oct 2017 14:13:21 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:53988 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932408AbdJJSE7 (ORCPT ); Tue, 10 Oct 2017 14:04:59 -0400 Received: by mail-wm0-f50.google.com with SMTP id q132so7695597wmd.2 for ; Tue, 10 Oct 2017 11:04:58 -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=gUm0PaNwKo3iuoGME7g8eog+wM47CvfieB7tsIdBATxviEB/OoEYZ1jBP2dEBqKJ5Z lGJksThUgZJ26l9I1mT1enIw5uy3VGn8I23t/ZAzE5ryZ2BKgINp934lXYVWA4xS81fw 8fEuMxs8/KNgFvnMJzSOuR27W2game2ULdgBg= 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=W7yOF8JUeT1WJU5A89Hf586CnhXgJGNT1dIkrBfXBG9Kd1r7q8NkzG7Lp0kPsX+gIR 8r2Mc/zyATNtOxbybNzsaGk05Fu/ueyrssPu+cLdZVH697M+yqnISwCVleJq686W0ikM Oz2vlBLUlsmH/yytwFoPFT4nd4U5HaadHAbvRgxi9wohPMWhx9ukf5Pwq15xGt+GwwF+ WH/+4wGDQIcVuOIVnYyTDXm2nVDA5Ut3WDC5ivglVNHLtxGAdCsBFZ82NN6xs7dcvVmb P0nM8cyFQ5iOE15iLFwnxl6maIUWR0t7F7tfzRD2DH23Bz0gw0IhuoSoW9XoiCibyvZG GuHg== X-Gm-Message-State: AMCzsaV2d6YK1nQ+DTqxV+F7+ImnPN758wrfwGyk8NZstBHsHztFa5lE 2mvhR35T5WxLYdGp+EwtAeeRpQ== X-Google-Smtp-Source: AOwi7QBXT2MWoATe+YRxKo6Wgy5I8tq3HGyN1RQ2bDmHQq5Ywl1pmBxpdWhuxa0o8QpE0QPHd8IaBg== X-Received: by 10.28.12.65 with SMTP id 62mr13393223wmm.129.1507658697850; Tue, 10 Oct 2017 11:04:57 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:4f9:3ae1:43d2:31ae]) by smtp.gmail.com with ESMTPSA id l73sm12513428wmd.47.2017.10.10.11.04.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:04:57 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kevin.wangtao@linaro.org Subject: [PATCH 07/25] thermal/drivers/hisi: Encapsulate register writes into helpers Date: Tue, 10 Oct 2017 20:02:32 +0200 Message-Id: <1507658570-32675-7-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507658570-32675-1-git-send-email-daniel.lezcano@linaro.org> References: <79a5f10c-0fb7-3e4f-caac-c1625904b137@linaro.org> <1507658570-32675-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); }