Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6950002imu; Mon, 3 Dec 2018 05:32:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/W2LJwKzY0rHGfu1DUI6ToUSc3E1irW7OvYueD4XOiwwNlA1O44AJXDPJDD2pWFcF6ChHNn X-Received: by 2002:a63:101d:: with SMTP id f29mr13387157pgl.38.1543843959914; Mon, 03 Dec 2018 05:32:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543843959; cv=none; d=google.com; s=arc-20160816; b=HIFQw45EzCuJQ0kGBhrrWkaoEWqUMvzgj2HWWMQZm9bJC8RfGpbl6NjmH7nsjeFT6i yGIvIsvXwjWER3+sfCVi+3D5Dr30t50KyALbn60fOmzblOP35PQXZOcCM48B+QwEWWQi 4ZuWP2rvIsh80sCWj4GlI2ZG5P9O4vdzMb2ZbZ6y/g3BRF6FdGWQk7ZMZ5s0iGiqtmzM e3wHAZULWFUldX8hRLiRL5QYRb4zJ35WljbN60OK3IaRl/tjB2wEtB4E+ngW2az8iC0p ODnO6E6wFCYm/61XWTRwpLWd+RgZCP9lSpwDOIM2Pzl05bxU7YE+a/cBQHmojhJgDuJz eCrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dMs6Mb/3EH6NUddI4Qk37lptneQwe896iQcc6U4t5qc=; b=llXUJCYfxTfZeTqOJajO8jzLNcMFjOvUuW8svpLMP3aI4r+zhr/9Pq/nc0l4sggJ04 e2SkdwZnjGR2nvFFwqtgjb+yDJ/onBtjM/Zqe+bJozdOHOgbatxH9tnSw19yLJpMJ2KX IUO7SxdbNwtFUKRQKUrN+y5mRqeTba5qM7HehutROPU1IAP8PZzSpforokvEhH8z8hsY lgb1jnQSMbQPCopSb3QcDlENVSKi+0YEiEnIJFWGiCLQi1qt0Z4el0LhE45KxMBVKS6m Su6rAXVFN0qhd/glSVHyKiVM3U8LYKBEVw4HDF/jsnOws5BC7FC7ZAnALPGnAGHHJ/42 9w0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IX1aMkR4; 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 y29si12857073pgk.376.2018.12.03.05.32.22; Mon, 03 Dec 2018 05:32:39 -0800 (PST) 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=IX1aMkR4; 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 S1726373AbeLCNcZ (ORCPT + 99 others); Mon, 3 Dec 2018 08:32:25 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:35489 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726277AbeLCNcY (ORCPT ); Mon, 3 Dec 2018 08:32:24 -0500 Received: by mail-qt1-f195.google.com with SMTP id v11so13657811qtc.2 for ; Mon, 03 Dec 2018 05:31:22 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=dMs6Mb/3EH6NUddI4Qk37lptneQwe896iQcc6U4t5qc=; b=IX1aMkR49adgWwDGCUFOduoMyliyULnW1mVjUixl9fBhZ17qW9z3vlEpJGLUait8y6 /Wa3Cqp00fMO752D082/hqMoEWFtM1Zn7qLUEC1OvWH4Xb+Lwn8SUOb0y0duzXdZxGxt FDZD/s2lgACH9n6j9hnUTEy4IZLirFEgy1FHI= 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:mime-version:content-transfer-encoding; bh=dMs6Mb/3EH6NUddI4Qk37lptneQwe896iQcc6U4t5qc=; b=P56EH989vWBqeQdFgO7bqXcQXoTOXB/ayR91CeRr79HXoSGWJnuW2BXFAvEbF+rlvA 7SbjOzJosELi4Uh4jLzPsInBp1/sfVfbe5KwVxs84uqURNfKtwTlJ1rhMc5VUuVfHX9z Lr+Yp9foODW7/q+PDbLY0pDQyR8wVyLXHRW6UGbMu3i/AIFyBgZsHam4eVZY1UnaD2e0 ee91y/inzi4ykfFiSYpSLMqi0wdID5xLv4OhKx7ciHyBWuqZ36aH7NeR0X+3K+WiRmRE wxXob+9MdXjwoDtP/30tzG0sg4QHlmCoJMTtrx/LvMoqefVC+0vVuqFLSGhMesutEZ51 gNIQ== X-Gm-Message-State: AA+aEWZD7Yp7AWoZz4STbBi5TVKSj66DXQ9jtW9LTW2r9jr84wNE6XwJ cbJdh83NEPZkTKGGrylVXpUvmg== X-Received: by 2002:ad4:510f:: with SMTP id g15mr16041641qvp.46.1543843881781; Mon, 03 Dec 2018 05:31:21 -0800 (PST) Received: from workstation.celeiro.br ([138.204.25.29]) by smtp.gmail.com with ESMTPSA id r56sm8619112qtj.30.2018.12.03.05.31.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 05:31:21 -0800 (PST) From: Rafael David Tinoco To: sashal@kernel.org Cc: rafael.tinoco@linaro.org, gregkh@linuxfoundation.org, rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 3/5] thermal/drivers/hisi: Encapsulate register writes into helpers Date: Mon, 3 Dec 2018 11:31:05 -0200 Message-Id: <20181203133107.4002-4-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181203133107.4002-1-rafael.tinoco@linaro.org> References: <20181203133107.4002-1-rafael.tinoco@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Lezcano commit 1e11b014271ceccb5ea04ae58f4829ac8209a86d upstream. Hopefully, the function name can help to clarify the semantic of the operations when writing in the register. Link: https://bugs.linaro.org/show_bug.cgi?id=4053 (PATCH 3/5) Signed-off-by: Daniel Lezcano Signed-off-by: Eduardo Valentin (cherry picked from commit 1e11b014271ceccb5ea04ae58f4829ac8209a86d) Signed-off-by: Rafael David Tinoco --- drivers/thermal/hisi_thermal.c | 92 ++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 0c2966c285b1..a803043f37ae 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); } -- 2.20.0.rc1