From patchwork Mon Sep 4 19:56:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111613 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1936585qge; Mon, 4 Sep 2017 12:59:36 -0700 (PDT) X-Received: by 10.84.238.16 with SMTP id u16mr1784768plk.217.1504555176430; Mon, 04 Sep 2017 12:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555176; cv=none; d=google.com; s=arc-20160816; b=QpVzXSgXG70j2RgZafobwKW/5oT/h1NjM7nqWWjc6wLkPQPk5L4X4nPdw6JucbmcNz YToZ6cUBW/+pem8gjlyw+St3onzqB0m8MQsK8K1r73uIk2kB3PzDpGzLRXVzLuk1IE9w CfrXV3GnDyUaggbHTVQ2C/SvxDEbf3/F4Xa8PtO1C2mKST1ZLrADhTO+qjxrabas9HSL COXYhebchWxPvKnUsLvtZnv8lplkTuzAxvr86UdIgY5LEcI/9Y9bBhX+Svj/6FomKNUc Bkz151XSnGqPapFRqGRPkBS3QQoBTZHgYqpe8jBBjhYZQNXbp5KM2SOTVkrUp3OWPB29 tsFQ== 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=uzREllr6QWICFAknjY66duz84hhhLpYMQZr2MlXYubA=; b=QWgma3hwIC0n32sYhY0ML9ChqTP6Gj2T2Kasu1gpObI7NWY9OEaFbJy23PNtp6wUa/ HmCWWEoJIapO6oZ8LsFh3Q4VININpAzdQFB5LboTiNhOrZsECfOwxFAi8V+Hkm7V82xC G/y6qmyRgyl0lSoWmTWy1uj3gsHvtlFC9d0esAq7p/0+DcPPB32ub7j8uk2XGU4CglOk so9SkJvrCz3A/u5r6T4rzfe/hZyIkClno16qIUzLiwjYfLINyueByonvp8NMxt/ahDvH HYENawa2Pf6dJj5FD8eT302Zo7kQlw+bbyo8VJfEj31MPyofnsXvN7Po8iww82A2v1DM dBqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rc1OZcqe; 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 5si5701843plx.823.2017.09.04.12.59.36; Mon, 04 Sep 2017 12:59:36 -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=Rc1OZcqe; 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 S1754039AbdIDT5t (ORCPT + 12 others); Mon, 4 Sep 2017 15:57:49 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:38641 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753988AbdIDT5n (ORCPT ); Mon, 4 Sep 2017 15:57:43 -0400 Received: by mail-wr0-f170.google.com with SMTP id 108so3966801wra.5 for ; Mon, 04 Sep 2017 12:57:43 -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=uzREllr6QWICFAknjY66duz84hhhLpYMQZr2MlXYubA=; b=Rc1OZcqexgyOegxIyyGTAhIOpuLV5Lr2WE2LnDnFLSpzg2AsCU6yj75c/6qOBv6LOn ipR5Am/tcHllneAfzhj01rEeVwFm2DcfT0b8D0xP7qJe0KoOGuBPX03pn5epYmM8FxZB jQ9F35AIPF6bHGJd6GMKOfpNcND5J0WpfPPqk= 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=uzREllr6QWICFAknjY66duz84hhhLpYMQZr2MlXYubA=; b=GTp69rVMQQrcRG1PYapcliqRuGXieByEQpWzKB1BamTZ+rornJaCIX1mreiTQBE3u4 jRC6+AhNxw6JLOHDZ1sM1cwK8C+jjIXzvZK98PxnT2O0sFf6WBk6ulg8V74EjVEVXlHV 3ildLQpR3F4WjSd3mOOvU1G3mCLrSHCRsS8cBTq7KFU4r6akEu1Y+Eitn/DScYInhxNK 8JT+tWTdwyUrgREsVH07z1ID5V/heL/4SgxPnWPPQfdIoWEvfgrRZl9vTcCQ0uVVFY2v G6mMYOflwDQfnrE13liqq598yxTSYrGSdtiQz267BvZWTbj6BqAAYb3vpL62unEkebRB 17wQ== X-Gm-Message-State: AHPjjUiBlASEtqF0z62qXdvFojSMKajrzY0eK4XAzpB9izOxKJ+s4Tl5 P3mV17ckmOqW22uZ X-Google-Smtp-Source: ADKCNb5LjUxGpAecLxlxrc4wVMexP3IzLp36ZMOfblrlE1E449s2+I0A0Y2625bYP6NT75/91l9+TA== X-Received: by 10.223.142.82 with SMTP id n76mr933565wrb.272.1504555062400; Mon, 04 Sep 2017 12:57:42 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:41 -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 Subject: [PATCH V2 07/13] thermal/drivers/hisi: Encapsulate register writes into helpers Date: Mon, 4 Sep 2017 21:56:06 +0200 Message-Id: <1504554972-2624-7-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> References: <1504554972-2624-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 9ec5f29..7747b96 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); }