From patchwork Wed Aug 30 08:47: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: 111290 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp596683qge; Wed, 30 Aug 2017 01:50:31 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7llmslduV9qeEpTFr6RJSOJ3MSf42y3EyfruJ+7Xcatbx7B27FLe9lw3ghZcHlgEbAynv6 X-Received: by 10.99.126.91 with SMTP id o27mr810330pgn.303.1504083030986; Wed, 30 Aug 2017 01:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504083030; cv=none; d=google.com; s=arc-20160816; b=D8zpneGHZXiEDY/jdDm+pFPFEaK6HpgIZwPZ6oD+ydHSpTBqvIMxKKn9X7jhRmbGEx mUqOq4hel09HBgb9UmMuJrmFR6iDGo2o2B8vPS3CT+lyBYSe9FKrQaVEwyiv69jdpJJ6 Bn5znw70MJ/noQMKaz4Fn1IOoftSb5H8TCYClIRFal8d5qgSPjImZGhUl/L2ZJ4hxYcm FrcAvVmJ09aAX9cTqL5jciUP5Kp5p0vCSeh9YaYdL0ezZu1ozOF4NOKHwRp8bgFedJND aRv9aDVzAO00Ty0uTtoJfx0pCi4gmgUyodaf2EvU00KaZZ17oiKy9lfWtf3WHtHKWDN+ S4dg== 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=sWYO6EitAyPiMvIpQ1GOQhd07ArsKV2hWYnc8iKouvc=; b=BthdE2YC7+WTDBPxCngGLp7ALfVCd6XLLjXQX0Z0I6bv+5lBKlgsm713bsHcH2Jop6 8CokWsqFXjVMECxWFXf6rO15DZd4y/Gpg8aFkD3PkCe3QbYKkzmq4dql8DQGeWKDjMBx Yy3Dx3IIh58ggxMMN4nc2FTUEy8SLVd7RvEIZdCXb/3UgUg6IpcnjtGGw1fVQ8riad2u oQTuD9z0tSeAt6k0OylR+xyjN1WD49CmkqzkTqOz/Qv0JPbaa5y9QUWRFCEIqRBanb/d AX081H23iklPqguuhLeDdPTOCZS2X3CKKRQdesLv/WpnKhPMSMWeFKU8RjvPQSjZOrcg IIaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HZAVuY9I; 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 t6si3973304pgt.643.2017.08.30.01.50.30; Wed, 30 Aug 2017 01:50:30 -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=HZAVuY9I; 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 S1751843AbdH3Iu3 (ORCPT + 12 others); Wed, 30 Aug 2017 04:50:29 -0400 Received: from mail-wr0-f169.google.com ([209.85.128.169]:38384 "EHLO mail-wr0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751550AbdH3Is5 (ORCPT ); Wed, 30 Aug 2017 04:48:57 -0400 Received: by mail-wr0-f169.google.com with SMTP id 40so15984604wrv.5 for ; Wed, 30 Aug 2017 01:48:56 -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=sWYO6EitAyPiMvIpQ1GOQhd07ArsKV2hWYnc8iKouvc=; b=HZAVuY9Iop6dNhjNOl/ln7F4c5MXaZOLyCI1LWZPmVvdtc8ngB3cXt2o8fm6vDQkxN qNXGq86eNogPj2PifBD1EX0qFq2QYwVp3u6vyKBx9SHxvy85sRf5TZXXzsXNQhkagKOm 74RGAadUNMYGowaiF/l649rY/T+U1gLAwWhUU= 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=sWYO6EitAyPiMvIpQ1GOQhd07ArsKV2hWYnc8iKouvc=; b=gMNHlTsgDP10LBHGmPLg+rrYVykeQ/mgEiL2rUXZnvDGVeXMvPfoyIw7/5KvySd66w m733I8Xpw5PruSjO1ZyztaaX9YO7liuCUtQWWHRcpZB951E/g66xb9SHnK7Sjotkny8I OuHSrYPG7xemcmR2GkvYOsMCZ/y32s6HEPpzXIESJigYuYNbUawR0cTYoHz2Q3yW6uGZ WVD74b7HVfrhWHhlR2iqhmUx+fuw2RGeiVm7sX5IxlDzXzkaGRNefaGmaaEkgXD1hKlY sz+lCBkzH/cmcalGedBg6Hae1/RekNKcluoyoFXCSK2iPYKkXVcpGsEyBjKecCVIEvB+ uirw== X-Gm-Message-State: AHYfb5gk53FRBWbzRai8AgeZQcapy6NMoOonnpuCghEYDm3QqD3jnF39 zReyKqiNieq7LhQn X-Received: by 10.223.132.132 with SMTP id 4mr527270wrg.253.1504082935637; Wed, 30 Aug 2017 01:48:55 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:55 -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 08/13] thermal/drivers/hisi: Fix configuration register setting Date: Wed, 30 Aug 2017 10:47:32 +0200 Message-Id: <1504082857-21702-8-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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The TEMP0_CFG configuration register contains different field to set up the temperature controller. However in the code, nothing prevents a setup to overwrite the previous one: eg. writing the hdak value overwrites the sensor selection, the sensor selection overwrites the hdak value. In order to prevent such thing, use a regmap-like mechanism by reading the value before, set the corresponding bits and write the result. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index d77a938..3e03908 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -132,19 +132,39 @@ 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) +static inline int hisi_thermal_get_temperature(void __iomem *addr) { - writel((sensor << 12), addr + TEMP0_CFG); + return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); } -static inline int hisi_thermal_get_temperature(void __iomem *addr) +/* + * Temperature configuration register - Sensor selection + * + * Bits [19:12] + * + * 0x0: local sensor (default) + * 0x1: remote sensor 1 (ACPU cluster 1) + * 0x2: remote sensor 2 (ACPU cluster 0) + * 0x3: remote sensor 3 (G3D) + */ +static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) { - return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); + writel(readl(addr + TEMP0_CFG) | (sensor << 12), addr + TEMP0_CFG); } +/* + * Temperature configuration register - Hdak conversion polling interval + * + * Bits [5:4] + * + * 0x0 : 0.768 ms + * 0x1 : 6.144 ms + * 0x2 : 49.152 ms + * 0x3 : 393.216 ms + */ static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) { - writel(value, addr + TEMP0_CFG); + writel(readl(addr + TEMP0_CFG) | (value << 4), addr + TEMP0_CFG); } static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data,