From patchwork Mon Dec 3 13:31:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael David Tinoco X-Patchwork-Id: 152704 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6814607ljp; Mon, 3 Dec 2018 05:31:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/WaIHngpQ3xa293m96MM1BoQ0jtJBfOMnUyeLKF1NRsYChvnZfzaudXvnh6YSGbuyhvDute X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr15673739plg.222.1543843886974; Mon, 03 Dec 2018 05:31:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543843886; cv=none; d=google.com; s=arc-20160816; b=V12Wf2bgdt4kkCE393dGuFw5MJZrMw9wA4ZBq90fBMG32H3oWeHdM2vtIAaZ4sxdvU m9SlxM9VSx/yQMh+i7Vh0ElRCqT35Q55APal4lFDF3tc9F4AB1QDGk9dKNXE1ckifNnr R2wH4U9lyBJgvUvNun5iLIDMm55TJCz5KQQrzcL7Suj7LX1PF8Q8ciEFULkdAsUc9GzI zOB95H7NV8OWQAUQB+9hD3DE5GS7VjjebWP4UiW2FnVkhD6Qh1ODDI8unB/XFTcm8KdN 6FYe0kLuxtCsqAw65Ykpaz/OVketcy8DAegzpMpc9w7i7pn2UhZbNrRGFj43hbNcb585 t12g== 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 t65si14244081pfb.247.2018.12.03.05.31.26; Mon, 03 Dec 2018 05:31:26 -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 S1726416AbeLCNcZ (ORCPT + 32 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 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(-) -- 2.20.0.rc1 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); }