From patchwork Tue Oct 10 18:02:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115445 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4047408qgn; Tue, 10 Oct 2017 11:13:38 -0700 (PDT) X-Received: by 10.159.204.147 with SMTP id t19mr12847656plo.7.1507659218543; Tue, 10 Oct 2017 11:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507659218; cv=none; d=google.com; s=arc-20160816; b=cXiynlDtfYFORPpwesFPI4c7trS5Py4d3cFDfmf6h1uLHsSLhpdqYCPpTwtaXOgmOQ Vyro2q7y9BsmQ9SfR0v++K5MhdcEJArNAgcB++hkUh/8tsEXtsKxqYCcs3yYtsvh1aHK YAc7RbUqO6x/5mkzMcsrfZkZL1mRkH/ECy7SmMiEP18n+/HxaY4IU3HEodIXm5RHwSu2 tKycizbadyqnokWQgqpy/+xsPKfwVYQvbcWFRgFrQ9I4IDsUDy5TWVeRU8DIO+t4Pv+S ANTpOV6ST4NsYgytseUHYmQctPWjgtzHZ4YuReBW/GxJTaJdoAoEg7zHsDICUBU15fSn 2prw== 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=b1XO1Q6oDJ+0Zqsb1mpoVsrFtWrFMVdCtEDLzYWAduw=; b=glFV4/igu+T2FbtUZono3qTHux0LHp9YdbivhdPmwXC0ji0I7YFKkV1F6qAx0MTv/y wiOcf0GqtQqgWTLoayCTnVMEkiL3oPovnMoqlrmyPpEORwBS3tAVN3Nn+QkrRX4cML/W gfpo6qhGuV8d2uwxSm/9ite9jNiBHuYvDyDRZRptxjiXqxZt5w8lJcOLDO+RorOLA6CV F5a1hv3PSlyUjpKF+ytG8nXBwSKFvHth3mQu60Y4WpdMCzbejwY3k5Jmi6EE2wumZbp4 svMh2A9cH45zPm2Iqmgrf9SXeKllaolodWQXa/rl3ZO9uwJ5EIgfneqL43ORPGlif3xJ PXkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RGSJ2dLE; 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 b3si5164584plr.706.2017.10.10.11.13.38; Tue, 10 Oct 2017 11:13:38 -0700 (PDT) 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=RGSJ2dLE; 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 S932391AbdJJSE6 (ORCPT + 26 others); Tue, 10 Oct 2017 14:04:58 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:53957 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756308AbdJJSEw (ORCPT ); Tue, 10 Oct 2017 14:04:52 -0400 Received: by mail-wm0-f51.google.com with SMTP id q132so7694866wmd.2 for ; Tue, 10 Oct 2017 11:04:52 -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=b1XO1Q6oDJ+0Zqsb1mpoVsrFtWrFMVdCtEDLzYWAduw=; b=RGSJ2dLEn2tnnP6ck9LJSVhlcnwcGdFpjo8wlKzle9+MhGuET7dqsgTto064+BHfxU 70eKK1TrT0jsmG/1nvE7KKN/745DI+cWjG52ndVQIDsRNNEdrsq8mRnoTRs0OnA708DZ Q5OTvzFKU9Hz7tRzT0DGytWnLKOhB1MQlWcDY= 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=b1XO1Q6oDJ+0Zqsb1mpoVsrFtWrFMVdCtEDLzYWAduw=; b=iut9NeYu043lLJnB+Ebc5Q1Ff4ctrG7Lw0hSEQ9tkdtQq1sdGkwLD4iPMLft1N+M88 gAwwKsEfgJBKNWL9V0FyasAnLIEqRFQHkViKgTX6hqLEr3xVgICcFRfMifvH9HMVO4bG srp3QoiC4RtX6lND+ohWggHoJGXhLH44FsInb/r2U0PAPvMnUrpq6C9mo8a48FSAZW3l FuG8XnFyZLTHTCojSddwM+VSmsnFuqpuK158IxyKYPoOL4Uat39NIZlWcSPIqQJQTV1H eNFNcxd9X9q5nuVzj8+EUv/PUfgKal6UDy3gZvv/r+cKOEwcHuG3Wk07KPiKfqn5xUN4 QWfA== X-Gm-Message-State: AMCzsaUDbjxNyIwDibI8MeBFcjS/W8Obfc5hqtwTqkbZ8hGVELmfGccg 5zU33E4nY618ykzaK7bWFlY+ig== X-Google-Smtp-Source: AOwi7QDtvhIeFItGV8n2b1lq7//u58BX+DoRpUCyhrc5EwHob40+ZHvgsPSFcpi+sFj2l2N/4lbPCA== X-Received: by 10.223.197.201 with SMTP id v9mr6451009wrg.82.1507658691603; Tue, 10 Oct 2017 11:04:51 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:04:51 -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, Leo Yan Subject: [PATCH 03/25] thermal/drivers/hisi: Fix kernel panic on alarm interrupt Date: Tue, 10 Oct 2017 20:02:28 +0200 Message-Id: <1507658570-32675-3-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The threaded interrupt for the alarm interrupt is requested before the temperature controller is setup. This one can fire an interrupt immediately leading to a kernel panic as the sensor data is not initialized. In order to prevent that, move the threaded irq after the Tsensor is setup. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 687efd4..feae552 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -287,15 +287,6 @@ static int hisi_thermal_probe(struct platform_device *pdev) if (data->irq < 0) return data->irq; - ret = devm_request_threaded_irq(&pdev->dev, data->irq, - hisi_thermal_alarm_irq, - hisi_thermal_alarm_irq_thread, - 0, "hisi_thermal", data); - if (ret < 0) { - dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); - return ret; - } - platform_set_drvdata(pdev, data); data->clk = devm_clk_get(&pdev->dev, "thermal_clk"); @@ -328,6 +319,15 @@ static int hisi_thermal_probe(struct platform_device *pdev) hisi_thermal_toggle_sensor(&data->sensors, true); + ret = devm_request_threaded_irq(&pdev->dev, data->irq, + hisi_thermal_alarm_irq, + hisi_thermal_alarm_irq_thread, + 0, "hisi_thermal", data); + if (ret < 0) { + dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); + return ret; + } + enable_irq(data->irq); return 0; From patchwork Tue Oct 10 18:02:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115447 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4048021qgn; Tue, 10 Oct 2017 11:14:11 -0700 (PDT) X-Received: by 10.98.19.24 with SMTP id b24mr14495216pfj.168.1507659251463; Tue, 10 Oct 2017 11:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507659251; cv=none; d=google.com; s=arc-20160816; b=EpRvB/bN7/yhGFExKxuK7lPZwDpXexgBwqJzaz/cdOAw/F0teTTe6rmzV6wOI02OEZ mEoshMKv1WxRakYN3RAp1PdJoKyWSPg0dGLMPLrGDwe0iJAfQS9uge1CrVEWeNcr7WqB qM7Z4lMwVXrNdSG8KAsG3DM9ryfOpPhlsHfRARz4dBg7aKb4nxZhW60o04qrlPW3RJjq RzkiX9T8RqGioZO7H8dwE2EbiAkLW47jVDMGZR5PP1e/QOxGc6v/QSX2SQ9CuVxKcBVG aAefMKLMQsbhZnxUPAJIVdpSyPe0BbnZl1l3YHVbda+cFJhPLxkbOv8T7ERPOD7h37Lb n57A== 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:arc-authentication-results; bh=EYuadkShQdCiMrX8H0Tm3wmurc4mV8xR4jVW+FYgK4Q=; b=ir2eK0BfhRES95xJEdS++GAyj7K4gKbDyfk49RNfZJrrl9r39Xz1IFazsbu/grQOL7 tT7/siMN2Pa/acdeRl/+G91s9LEUqN2++WhRy6ECW7LdSItO8yERes65QG0h5h2lj9/M 6kuhtnA3ULOxGhDVbHLGoNFMRTYTr9TI0orTS1hqAVtjXwN+rSuJpNxnDBnceyXfJWp4 WyKYT3EFDLjEpeTSh6iQ+ArRzIvmXufAl2ib4Esm9iljM3zILET5zAtV95Ymvu+J+u6k HNKqTtAMDYD7CHacOJfJhCKmgRfQwfl/LlaFky92HtK8LlDCnJIFgDmfBIBi74NhbWTG x4hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OZHlBROM; 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 67si9568645pfy.188.2017.10.10.11.14.11; Tue, 10 Oct 2017 11:14:11 -0700 (PDT) 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=OZHlBROM; 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 S932748AbdJJSOH (ORCPT + 26 others); Tue, 10 Oct 2017 14:14:07 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:46312 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756327AbdJJSEy (ORCPT ); Tue, 10 Oct 2017 14:04:54 -0400 Received: by mail-wm0-f49.google.com with SMTP id m72so7517260wmc.1 for ; Tue, 10 Oct 2017 11:04:54 -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 :mime-version:content-transfer-encoding; bh=EYuadkShQdCiMrX8H0Tm3wmurc4mV8xR4jVW+FYgK4Q=; b=OZHlBROMm0Sju2ivdHQ/wyPJ0ZKXnbGdfwAm0vK64fltKbOxmGkrCb/eV0t7iLb05n 7i5M7QxurZngL2hXthRxcWcvyepvAe2n6v1W/YHga0Y4kjTb3Q4y6ku6sVPeGi5M1iy1 Lkb4L2kMKWLQ61mciDJCkW07Pi8TPwPhhb9QQ= 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=EYuadkShQdCiMrX8H0Tm3wmurc4mV8xR4jVW+FYgK4Q=; b=uS99Nloc/Fs4gRHn+XIQ6vpVF1JRovF1F7JgCyCdPPfc75DKWX4vnO3mKFC7OY92G3 ZQoJdNmveqxb4J2Fz3d4NInLi+Jwd5ui4jPd8BnFT1j0FVNjdU68mCvBPaynSGfaBt4P 7O7cIIBOwNopZtQDc+qYV5CKm0X0DI4oakYwBRnsWZpk05kB+unccCJpxzdoyEi+p/I4 /po7J+IYzxLgS+WMckuBGXwQ+ZVR69iIfX7eeM5+8v4eJNaY4NjUR2ojT6/QFn3lW/n9 2Hz4RYVZFP+6t72brvUD+X+aR1MZH47tvQqdR+w1VINqKkpa3VEdKvNRF3v4WpSZWtEw fPvQ== X-Gm-Message-State: AMCzsaVsrc/YKCWdPynd+ER1Lrt1GFNLS0bsi68ji94SxKBGqhpfoG9B zgLUobyiIwOAzREUu47iWHwuQw== X-Google-Smtp-Source: AOwi7QAwcVhMkul0Otsbi4IN/QUwTDgxuHZJypzeMT4RT1FcweiMLZZczFeNb3IRyMTVrd23CUeaqw== X-Received: by 10.28.51.19 with SMTP id z19mr10766330wmz.18.1507658693204; Tue, 10 Oct 2017 11:04:53 -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.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:04:52 -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, Leo Yan Subject: [PATCH 04/25] thermal/drivers/hisi: Simplify the temperature/step computation Date: Tue, 10 Oct 2017 20:02:29 +0200 Message-Id: <1507658570-32675-4-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> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The step and the base temperature are fixed values, we can simplify the computation by converting the base temperature to milli celsius and use a pre-computed step value. That saves us a lot of mult + div for nothing at runtime. Take also the opportunity to change the function names to be consistent with the rest of the code. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index feae552..04eb5e2 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -35,8 +35,9 @@ #define TEMP0_RST_MSK (0x1C) #define TEMP0_VALUE (0x28) -#define HISI_TEMP_BASE (-60) +#define HISI_TEMP_BASE (-60000) #define HISI_TEMP_RESET (100000) +#define HISI_TEMP_STEP (784) #define HISI_MAX_SENSORS 4 #define HISI_DEFAULT_SENSOR 2 @@ -61,19 +62,32 @@ struct hisi_thermal_data { void __iomem *regs; }; -/* in millicelsius */ -static inline int _step_to_temp(int step) +/* + * The temperature computation on the tsensor is as follow: + * Unit: millidegree Celsius + * Step: 255/200 (0.7843) + * Temperature base: -60°C + * + * The register is programmed in temperature steps, every step is 784 + * millidegree and begins at -60 000 m°C + * + * The temperature from the steps: + * + * Temp = TempBase + (steps x 784) + * + * and the steps from the temperature: + * + * steps = (Temp - TempBase) / 784 + * + */ +static inline int hisi_thermal_step_to_temp(int step) { - /* - * Every step equals (1 * 200) / 255 celsius, and finally - * need convert to millicelsius. - */ - return (HISI_TEMP_BASE * 1000 + (step * 200000 / 255)); + return HISI_TEMP_BASE + (step * HISI_TEMP_STEP); } -static inline long _temp_to_step(long temp) +static inline long hisi_thermal_temp_to_step(long temp) { - return ((temp - HISI_TEMP_BASE * 1000) * 255) / 200000; + return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; } static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, @@ -99,7 +113,7 @@ static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, usleep_range(3000, 5000); val = readl(data->regs + TEMP0_VALUE); - val = _step_to_temp(val); + val = hisi_thermal_step_to_temp(val); mutex_unlock(&data->thermal_lock); @@ -126,10 +140,11 @@ static void hisi_thermal_enable_bind_irq_sensor writel((sensor->id << 12), data->regs + TEMP0_CFG); /* enable for interrupt */ - writel(_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, + writel(hisi_thermal_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, data->regs + TEMP0_TH); - writel(_temp_to_step(HISI_TEMP_RESET), data->regs + TEMP0_RST_TH); + writel(hisi_thermal_temp_to_step(HISI_TEMP_RESET), + data->regs + TEMP0_RST_TH); /* enable module */ writel(0x1, data->regs + TEMP0_RST_MSK); From patchwork Tue Oct 10 18:02:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115443 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4047043qgn; Tue, 10 Oct 2017 11:13:11 -0700 (PDT) X-Received: by 10.98.210.129 with SMTP id c123mr11521607pfg.77.1507659191892; Tue, 10 Oct 2017 11:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507659191; cv=none; d=google.com; s=arc-20160816; b=EBpPWHmuj0TfGGHuusyWMbLGytbIQqPTYuPzG2eoSVn2woyISyyIRMAseGPlJIJgjV eY168uHRbXwmyBY1EaZ7NNLdp3iafgzc2bHxBkEX70WZ8SBtue+xASCxROGHyERcm8C4 7KI9KEtXf50+6r0wiimbiqH9U3jX4ZC3AjcHvDLxXzn/L21sQyr7NWZ3lgxQUcwWwqBF D4EDlTnQuJ6QvhgMI4+LyggZRspPQVm0zzfh0F0NYF0GSbMXjwJPtV42xJeWrZnp9tp3 G+oc3PH/zeC3cXWkZ30JP40J+S2ugeKR4pdnjEtdjLWiBwY8XzhO0ZH91BhdHsTMBCaX 53vg== 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=LcCqOg6R5HLIWn70fOZmoXFqfJp/EJeqARoLFLmxNCE=; b=GvaPL31hcyJyiG1ZeEB3218pzb4JlRpx/6m5jjmlO9YqlMPkb48WkY3OseMqOt+lkr xh8soJD4lt0I3Byc/qou9omM0QjTd+OFZRx0BqLQK4xQEP3ZySsrEWPpzDPv3amDvcKa LaqvhRDPARvsQwI7SCdN747hHHO0nE3LYER+gtSxr+L1EWZPjtwQz02S4kcw83YYMTtD GN20UCENtmgCvB2TJyuScWQfbc14RkI0kt2p2e9dfCRC6LKF3ZP1nmtHW5H3PS/+shAG IRoNbKtR14GMb8IMSEWE49IuhlErceGQFBG8UJ2OkiAyFRGILUD4i6vtdIKKVra6whLl TYvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZzhh7os; 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 q81si9081475pfg.32.2017.10.10.11.13.11; Tue, 10 Oct 2017 11:13:11 -0700 (PDT) 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=IZzhh7os; 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 S932492AbdJJSFA (ORCPT + 26 others); Tue, 10 Oct 2017 14:05:00 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:54691 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756528AbdJJSE4 (ORCPT ); Tue, 10 Oct 2017 14:04:56 -0400 Received: by mail-wm0-f43.google.com with SMTP id i124so7673181wmf.3 for ; Tue, 10 Oct 2017 11:04:55 -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=LcCqOg6R5HLIWn70fOZmoXFqfJp/EJeqARoLFLmxNCE=; b=IZzhh7os62neEmnbVv0GnceX/VN9hawtAnNg/m7d2Qyz9zCLlDwbJrnxczb4vQBts5 pjs88il4iTVRBm/1UQzPS/LeYIr1bMrdOgUVdQkPxGM/HGH2SSQi7GlaP4u2A0/n9pdj XxBmXM9PPGmsJ0GLbuTnDsiFoiVjibE9owjhg= 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=LcCqOg6R5HLIWn70fOZmoXFqfJp/EJeqARoLFLmxNCE=; b=qRb9azhzF2uXLpCmuqq519DIde7XNN68Bkj2S89/WQFT3aVqaVQOwnuxo7/W8MV/H7 Kt04vbMCrIbp4YusgXd4ZKdlcBZy5/3A3AXX8DrCYsaA+1thYulH2FJtObgaw6pJAVhb BVPbpWovylKgDheKRdqBm5uNM7/GCtpnV1KCAdsr5biJmveyEuGzrb78re8YdYI4kdv2 aLinJ9MEjpGWejkMCnbX5IqP/FEKJjKKISpKqeomZbPmSxLOVV5xexnyoU/WpNXlmkAC 8ZiZROKWxFL6ncD5a0jWkDJU11yjG8AFAkP19Gkaa8LkDqFzf1N0huJEC6DpwhV/nPtJ EXXA== X-Gm-Message-State: AMCzsaWulw1xMFvWtel+83DU3u3lxexMv5dtCD9PQVlAFG+hAtSS5k/4 ptyHi0eluv+xWoGkD5+EzzvbMA== X-Google-Smtp-Source: AOwi7QDgVOnqnrHReNjkvusuTOc11CxneaW3HQ4P0kEZLFJN3AzJuZ6BpO+NieKZ9oclF56xq4QA6Q== X-Received: by 10.28.52.5 with SMTP id b5mr13035066wma.135.1507658694807; Tue, 10 Oct 2017 11:04:54 -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.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:04:54 -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, Leo Yan Subject: [PATCH 05/25] thermal/drivers/hisi: Fix multiple alarm interrupts firing Date: Tue, 10 Oct 2017 20:02:30 +0200 Message-Id: <1507658570-32675-5-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The DT specifies a threshold of 65000, we setup the register with a value in the temperature resolution for the controller, 64656. When we reach 64656, the interrupt fires, the interrupt is disabled. Then the irq thread runs and calls thermal_zone_device_update() which will call in turn hisi_thermal_get_temp(). The function will look if the temperature decreased, assuming it was more than 65000, but that is not the case because the current temperature is 64656 (because of the rounding when setting the threshold). This condition being true, we re-enable the interrupt which fires immediately after exiting the irq thread. That happens again and again until the temperature goes to more than 65000. Potentially, there is here an interrupt storm if the temperature stabilizes at this temperature. A very unlikely case but possible. In any case, it does not make sense to handle dozens of alarm interrupt for nothing. Fix this by rounding the threshold value to the controller resolution so the check against the threshold is consistent with the one set in the controller. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 04eb5e2..1b44bfe 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -90,6 +90,12 @@ static inline long hisi_thermal_temp_to_step(long temp) return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; } +static inline long hisi_thermal_round_temp(int temp) +{ + return hisi_thermal_step_to_temp( + hisi_thermal_temp_to_step(temp)); +} + static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor) { @@ -221,7 +227,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) sensor = &data->sensors; dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", - sensor->thres_temp / 1000); + sensor->thres_temp); mutex_unlock(&data->thermal_lock); thermal_zone_device_update(data->sensors.tzd, @@ -255,7 +261,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) { if (trip[i].type == THERMAL_TRIP_PASSIVE) { - sensor->thres_temp = trip[i].temperature; + sensor->thres_temp = hisi_thermal_round_temp(trip[i].temperature); break; } } From patchwork Tue Oct 10 18:02:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115442 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4046843qgn; Tue, 10 Oct 2017 11:12:58 -0700 (PDT) X-Received: by 10.84.230.134 with SMTP id e6mr13002629plk.46.1507659178117; Tue, 10 Oct 2017 11:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507659178; cv=none; d=google.com; s=arc-20160816; b=QY7+kerSwYpIFeu9Jg+urCxISQC9bKKhgaQCfr3Kp6FemXhGN1as4VhRV+Z32bLXax yNHyWjFSsZdtdkTgChr00yx2dgM5Uy+tD7ZRySs6XsR6ZVUER5ZMEGyPZjHdj/WvxNVg D5JM7F9XXcWf5iEV760S10zeDQYdXGp7ze+dwAELjO1kSlx0jYxHibihqTT1ZzuBt/Wt uAgh5crhEd83rGIuJL7ORJOlTIemdM+GMQ8uIF1+pb0DtjEwY+X8U5lyfo6cTwV4N1UF Do6UemWeCBrCSHCBSJuf+ihcwEFXPEPZbibfq6JRmosbj8nor9FtyU9SpVPOhoPabVOU GoCQ== 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=YptLcdGgKlhC498HPJAn9VWTrVbEotgv7lCmeTNIn60=; b=T1qaECBlRiXHyJLjKbjKEvqgY5lGoB7/dG0uFJZtPwsA/Irl+MrbppM764BxA6yngF EhLJVsVj0b9B4nyUzsw08ZhsgzJoAHXsKsgX1hORuJLpDhyo2yDoPrA9isTvygV9Q18U frrQdLJ7MZG67RG9XaE92ZzW1aIP6InTFvJUVKb7tDf6DXL7y1MoZndim8YYD5UDq9EY fzNzHrobzY7LD694zeESr+6L66uePy2imOWUzTak7PVklP3rjQ4x3lUii8sacf/OpHMF kjO3FpMpgm5JYs4b1wFT47Ks1jpKoeGb1yj3tBTMfyy2XKws2f095btaneUgo9RIJYIt Ml9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Zh7cKJ2h; 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 o9si8801009pgq.600.2017.10.10.11.12.57; Tue, 10 Oct 2017 11:12:58 -0700 (PDT) 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=Zh7cKJ2h; 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 S932735AbdJJSM4 (ORCPT + 26 others); Tue, 10 Oct 2017 14:12:56 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:46344 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932499AbdJJSFA (ORCPT ); Tue, 10 Oct 2017 14:05:00 -0400 Received: by mail-wm0-f54.google.com with SMTP id m72so7518013wmc.1 for ; Tue, 10 Oct 2017 11:05:00 -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=YptLcdGgKlhC498HPJAn9VWTrVbEotgv7lCmeTNIn60=; b=Zh7cKJ2hqQ5q1l61UnfQNDyyBcGG2Vtr0rqyN7Y2gajqrP/H2LF1ccNY3ZnQSJxNEC prpkuwr0ATLcKfLHFAwUA4NCsKs3lV1caWgJdBY5KM7ZZUPHhb/iYoUcu7HV/7jUrbx5 rNgkBbqhzqmG3Lh3CISpmL9MrQ3xR2TfJbYo0= 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=YptLcdGgKlhC498HPJAn9VWTrVbEotgv7lCmeTNIn60=; b=qF7oampOeOU8tvwqy8eWXK7aS0w6SRW0qrUAgAJGzUVXxZFEnXgdUTgA3xGUgbYDvc BNLHWe2rWQAkPNkDSnEJ5rjrIJYSjRN6DWVn6NdqiLAqm3I8xAqYhtcC2IECdaEzThtD g74uiZqxCnQyFDr+n8qQr+aYuBPNwj1nOWUCgV2iWvUNVoknxvpqrfgEHVC/oOJZYT8L iB57col+skwn9D6E72TM98pdIvRU18olqCbb1+kJmxeeXIvDYhRAMMak7hSYIH80rB6L vSdY0qlKaotIRqiv8kN4jRvr4Lwy5qGoz0P0NiTBt+5O4rHWV0vHwM0BKkkL9BpJom73 pp2A== X-Gm-Message-State: AMCzsaUGql0cH+FXVQ7FnrQUopkmoecqH4Nq0ZEZjE0mNt4OGntEm+DF 9xrA0MmtYt1TfUHJdsWbxIHwyQ== X-Google-Smtp-Source: AOwi7QC0Fdo/wgcfYKQuvJz4XVj4RLlYM6TQfWW0HVjgnNQslfIiGXof9fBCtr5gPeFiAUiDFstE3Q== X-Received: by 10.28.46.210 with SMTP id u201mr11301324wmu.64.1507658699375; Tue, 10 Oct 2017 11:04:59 -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.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:04:58 -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 08/25] thermal/drivers/hisi: Fix configuration register setting Date: Tue, 10 Oct 2017 20:02:33 +0200 Message-Id: <1507658570-32675-8-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 8e8a117..5688556 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -30,6 +30,8 @@ #define TEMP0_TH (0x4) #define TEMP0_RST_TH (0x8) #define TEMP0_CFG (0xC) +#define TEMP0_CFG_SS_MSK (0xF000) +#define TEMP0_CFG_HDAK_MSK (0x30) #define TEMP0_EN (0x10) #define TEMP0_INT_EN (0x14) #define TEMP0_INT_CLR (0x18) @@ -132,19 +134,41 @@ 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) & ~TEMP0_CFG_SS_MSK ) | + (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) & ~TEMP0_CFG_HDAK_MSK) | + (value << 4), addr + TEMP0_CFG); } static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, From patchwork Tue Oct 10 18:02:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115441 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4046216qgn; Tue, 10 Oct 2017 11:12:15 -0700 (PDT) X-Received: by 10.84.132.104 with SMTP id 95mr13224749ple.231.1507659134935; Tue, 10 Oct 2017 11:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507659134; cv=none; d=google.com; s=arc-20160816; b=VWAMvHWW6ePU8fDtv7yqmySWwah4pyisuUIJr5mtd98p4U91n8JSpTCIwraoxwoKhE Nya2cz4YEejgvl0Av+6Thmdc7FjckuNyxYPFq3rjCtvHukmvLqQrxyNT2RZjrtC8dZ/s 0wagD9fUwzeDcrBd7gqsKSVjo2abaE4s8tOMzOy6ABXTIXFDZPxYuP+cwlQdoGjC7q4P Z3q/shZ+HoPpwJuHr5XqljFbrWIAUmfm0KFnRlImpWn8cOfKl2jEjmyW8BQCHVnFcxXx xDh4A/x5+kVs5YhlIh8oUTXX+JPVu0cxHaHq+aUQ1aaERl5PGwWmQEjVgic2DnEb9+RQ y47Q== 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:arc-authentication-results; bh=+IkLSIuICz09yAqiYjWrVp/hC1VQn6ex5w3nx4pbILk=; b=P1v7C7OrW7K34p/y0Jzn0mIjirZwEIjpbgZVZ8s6Q3U6ERNYo/GLEo5j861FLEBt0p X4KMur5bo4hSaqT01OPFdaFvnFXFeP6KmotTWjwwAgGxEb11p6lAJNi2pVznRyAB3IZG jiGqKZyHmHnKm7YPPc87h8hkQvVYLc1aGSSyKEug008Jng9ke19AcMNjd/P9zifnmRA5 Zh4kyIBE9LsfIb3yX3C6AUmh0wgJ5dLjst27UHgKoOc+++kmU2v7afPWJN415pl4EZ4Y FHXa4Aa+D6tkgTUO8/Ri5yTh45vlFnbhvrYRbnkqNKvLM1os5LBlho4eO5jvtlklT06G 310w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bgeL6lxW; 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 u8si9578305plh.170.2017.10.10.11.12.14; Tue, 10 Oct 2017 11:12:14 -0700 (PDT) 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=bgeL6lxW; 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 S932689AbdJJSMN (ORCPT + 26 others); Tue, 10 Oct 2017 14:12:13 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:54006 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932411AbdJJSFC (ORCPT ); Tue, 10 Oct 2017 14:05:02 -0400 Received: by mail-wm0-f50.google.com with SMTP id q132so7696036wmd.2 for ; Tue, 10 Oct 2017 11:05:02 -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 :mime-version:content-transfer-encoding; bh=+IkLSIuICz09yAqiYjWrVp/hC1VQn6ex5w3nx4pbILk=; b=bgeL6lxW206T7MYuWNcwUBekkdJfUsHqQXK8jDy68X/tjKSRtR+mjXuokYP1UIdqPl 8QqwmdJ+UulVtcz5e3o871N18wPKlbmtI8ucG6MFJS/29L8+eJ8VukfIHOD5mNOQt4JW dIlqw3I4l272I16NvCJAcRLUc8Eh87DXiXwhc= 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=+IkLSIuICz09yAqiYjWrVp/hC1VQn6ex5w3nx4pbILk=; b=HYZ94U82ql74rZ7tKPXibs/ZsQgDlZY2Jq4gGT8Bd71xnCngxDuc828XhyFFDxkZ8A WDUNbEOV//jwAddcWD3JbHqeIIJYyfeyWhWnp7yp+bQxMtVhDJFuEpCSO3z5VBGJg3zT pWazvkgYVzkRm3aYK9VXL9YijE1Qsbw/G/kpeOadccBaRKXhrQiCt9PAYq2q5vQImMA2 ZgvGA14fHFfvSQk3BkUTr3luoyAvirj4lITy5/Ft4OqUCDw+7Iv1UMwddP9j2VMGIE/k NZKy/nugiN/lh2CNH9CHfhinj3Id9crpdPrY1g6fcBcFa5YW2u6gcSlxTuFuf/BQ+p90 RkRw== X-Gm-Message-State: AMCzsaWwFr9/bMsuoYbN4F8uEfGR0YxI73tFYsCkdDx/fUlAMTy/QoVy lnPeJpkAfQ70Y7oaJJ4jnK4Iug== X-Google-Smtp-Source: AOwi7QDiGQEIPhdeE8v+NUjtm4flTv6HmPAsZpqsMy2Xg5tGkDbg1S1v2d18kubNMeWj9yldBdYWkQ== X-Received: by 10.28.143.203 with SMTP id r194mr12943387wmd.39.1507658701329; Tue, 10 Oct 2017 11:05:01 -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.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:00 -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, Leo Yan Subject: [PATCH 09/25] thermal/drivers/hisi: Remove costly sensor inspection Date: Tue, 10 Oct 2017 20:02:34 +0200 Message-Id: <1507658570-32675-9-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> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sensor is all setup, bind, resetted, acked, etc... every single second. That was the way to workaround a problem with the interrupt bouncing again and again. With the following changes, we fix all in one: - Do the setup, one time, at probe time - Add the IRQF_ONESHOT, ack the interrupt in the threaded handler - Remove the interrupt handler - Set the correct value for the LAG register - Remove all the irq_enabled stuff in the code as the interruption handling is fixed - Remove the 3ms delay - Reorder the initialization routine to be in the right order It ends up to a nicer code and more efficient, the 3-5ms delay is removed from the get_temp() path. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 203 +++++++++++++++++++---------------------- 1 file changed, 93 insertions(+), 110 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 5688556..5b3e681 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -41,6 +41,7 @@ #define HISI_TEMP_BASE (-60000) #define HISI_TEMP_RESET (100000) #define HISI_TEMP_STEP (784) +#define HISI_TEMP_LAG (3500) #define HISI_MAX_SENSORS 4 #define HISI_DEFAULT_SENSOR 2 @@ -60,8 +61,6 @@ struct hisi_thermal_data { struct clk *clk; struct hisi_thermal_sensor sensors; int irq; - bool irq_enabled; - void __iomem *regs; }; @@ -99,9 +98,40 @@ static inline long hisi_thermal_round_temp(int temp) hisi_thermal_temp_to_step(temp)); } +/* + * The lag register contains 5 bits encoding the temperature in steps. + * + * Each time the temperature crosses the threshold boundary, an + * interrupt is raised. It could be when the temperature is going + * above the threshold or below. However, if the temperature is + * fluctuating around this value due to the load, we can receive + * several interrupts which may not desired. + * + * We can setup a temperature representing the delta between the + * threshold and the current temperature when the temperature is + * decreasing. + * + * For instance: the lag register is 5°C, the threshold is 65°C, when + * the temperature reaches 65°C an interrupt is raised and when the + * temperature decrease to 65°C - 5°C another interrupt is raised. + * + * A very short lag can lead to an interrupt storm, a long lag + * increase the latency to react to the temperature changes. In our + * case, that is not really a problem as we are polling the + * temperature. + * + * [0:4] : lag register + * + * The temperature is coded in steps, cf. HISI_TEMP_STEP. + * + * Min : 0x00 : 0.0 °C + * Max : 0x1F : 24.3 °C + * + * The 'value' parameter is in milliCelsius. + */ static inline void hisi_thermal_set_lag(void __iomem *addr, int value) { - writel(value, addr + TEMP0_LAG); + writel((value / HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG); } static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) @@ -171,71 +201,6 @@ static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) (value << 4), addr + TEMP0_CFG); } -static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, - struct hisi_thermal_sensor *sensor) -{ - long val; - - mutex_lock(&data->thermal_lock); - - /* disable interrupt */ - hisi_thermal_alarm_enable(data->regs, 0); - hisi_thermal_alarm_clear(data->regs, 1); - - /* disable module firstly */ - hisi_thermal_enable(data->regs, 0); - - /* select sensor id */ - hisi_thermal_sensor_select(data->regs, sensor->id); - - /* enable module */ - hisi_thermal_enable(data->regs, 1); - - usleep_range(3000, 5000); - - val = hisi_thermal_get_temperature(data->regs); - - mutex_unlock(&data->thermal_lock); - - return val; -} - -static void hisi_thermal_enable_bind_irq_sensor - (struct hisi_thermal_data *data) -{ - struct hisi_thermal_sensor *sensor; - - mutex_lock(&data->thermal_lock); - - sensor = &data->sensors; - - /* setting the hdak time */ - hisi_thermal_hdak_set(data->regs, 0); - - /* disable module firstly */ - hisi_thermal_reset_enable(data->regs, 0); - hisi_thermal_enable(data->regs, 0); - - /* select sensor id */ - hisi_thermal_sensor_select(data->regs, sensor->id); - - /* enable for interrupt */ - hisi_thermal_alarm_set(data->regs, sensor->thres_temp); - - hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); - - /* enable module */ - hisi_thermal_reset_enable(data->regs, 1); - hisi_thermal_enable(data->regs, 1); - - hisi_thermal_alarm_clear(data->regs, 0); - hisi_thermal_alarm_enable(data->regs, 1); - - usleep_range(3000, 5000); - - mutex_unlock(&data->thermal_lock); -} - static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) { mutex_lock(&data->thermal_lock); @@ -253,25 +218,10 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp) struct hisi_thermal_sensor *sensor = _sensor; struct hisi_thermal_data *data = sensor->thermal; - *temp = hisi_thermal_get_sensor_temp(data, sensor); - - dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%d, thres=%d\n", - sensor->id, data->irq_enabled, *temp, sensor->thres_temp); - /* - * Bind irq to sensor for two cases: - * Reenable alarm IRQ if temperature below threshold; - * if irq has been enabled, always set it; - */ - if (data->irq_enabled) { - hisi_thermal_enable_bind_irq_sensor(data); - return 0; - } + *temp = hisi_thermal_get_temperature(data->regs); - if (*temp < sensor->thres_temp) { - data->irq_enabled = true; - hisi_thermal_enable_bind_irq_sensor(data); - enable_irq(data->irq); - } + dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", + sensor->id, *temp, sensor->thres_temp); return 0; } @@ -280,26 +230,27 @@ static struct thermal_zone_of_device_ops hisi_of_thermal_ops = { .get_temp = hisi_thermal_get_temp, }; -static irqreturn_t hisi_thermal_alarm_irq(int irq, void *dev) +static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) { struct hisi_thermal_data *data = dev; + struct hisi_thermal_sensor *sensor = &data->sensors; + int temp; - disable_irq_nosync(irq); - data->irq_enabled = false; + hisi_thermal_alarm_clear(data->regs, 1); - return IRQ_WAKE_THREAD; -} + temp = hisi_thermal_get_temperature(data->regs); -static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) -{ - struct hisi_thermal_data *data = dev; - struct hisi_thermal_sensor *sensor = &data->sensors; + if (temp >= sensor->thres_temp) { + dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", + temp, sensor->thres_temp); - dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", - sensor->thres_temp); + thermal_zone_device_update(data->sensors.tzd, + THERMAL_EVENT_UNSPECIFIED); - thermal_zone_device_update(data->sensors.tzd, - THERMAL_EVENT_UNSPECIFIED); + } else if (temp < sensor->thres_temp) { + dev_crit(&data->pdev->dev, "THERMAL ALARM stopped: %d < %d\n", + temp, sensor->thres_temp); + } return IRQ_HANDLED; } @@ -352,6 +303,40 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); } +static int hisi_thermal_setup(struct hisi_thermal_data *data) +{ + struct hisi_thermal_sensor *sensor; + + sensor = &data->sensors; + + /* disable module firstly */ + hisi_thermal_reset_enable(data->regs, 0); + hisi_thermal_enable(data->regs, 0); + + /* select sensor id */ + hisi_thermal_sensor_select(data->regs, sensor->id); + + /* setting the hdak time */ + hisi_thermal_hdak_set(data->regs, 0); + + /* setting lag value between current temp and the threshold */ + hisi_thermal_set_lag(data->regs, HISI_TEMP_LAG); + + /* enable for interrupt */ + hisi_thermal_alarm_set(data->regs, sensor->thres_temp); + + hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); + + /* enable module */ + hisi_thermal_reset_enable(data->regs, 1); + hisi_thermal_enable(data->regs, 1); + + hisi_thermal_alarm_clear(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 1); + + return 0; +} + static int hisi_thermal_probe(struct platform_device *pdev) { struct hisi_thermal_data *data; @@ -394,9 +379,6 @@ static int hisi_thermal_probe(struct platform_device *pdev) return ret; } - hisi_thermal_enable_bind_irq_sensor(data); - data->irq_enabled = true; - ret = hisi_thermal_register_sensor(pdev, data, &data->sensors, HISI_DEFAULT_SENSOR); @@ -406,18 +388,21 @@ static int hisi_thermal_probe(struct platform_device *pdev) return ret; } - hisi_thermal_toggle_sensor(&data->sensors, true); + ret = hisi_thermal_setup(data); + if (ret) { + dev_err(&pdev->dev, "Failed to setup the sensor: %d\n", ret); + return ret; + } - ret = devm_request_threaded_irq(&pdev->dev, data->irq, - hisi_thermal_alarm_irq, + ret = devm_request_threaded_irq(&pdev->dev, data->irq, NULL, hisi_thermal_alarm_irq_thread, - 0, "hisi_thermal", data); + IRQF_ONESHOT, "hisi_thermal", data); if (ret < 0) { dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); return ret; } - enable_irq(data->irq); + hisi_thermal_toggle_sensor(&data->sensors, true); return 0; } @@ -440,7 +425,6 @@ static int hisi_thermal_suspend(struct device *dev) struct hisi_thermal_data *data = dev_get_drvdata(dev); hisi_thermal_disable_sensor(data); - data->irq_enabled = false; clk_disable_unprepare(data->clk); @@ -456,8 +440,7 @@ static int hisi_thermal_resume(struct device *dev) if (ret) return ret; - data->irq_enabled = true; - hisi_thermal_enable_bind_irq_sensor(data); + hisi_thermal_setup(data); return 0; } From patchwork Tue Oct 10 18:02:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115425 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4039063qgn; Tue, 10 Oct 2017 11:05:10 -0700 (PDT) X-Received: by 10.84.232.203 with SMTP id x11mr12844944plm.396.1507658710414; Tue, 10 Oct 2017 11:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658710; cv=none; d=google.com; s=arc-20160816; b=JJPJUogJJW8El7IWq3ZiSc10YE7tmx+/rw6JSGRcqH9ATG8E9vOz0esbjmdC6FbqCv QDmv98oiRHOqAyAfLRdWxC5v/J8hxNXokbCtJe8QM/uCId7Tx7IgL+2oBkReThhHwotb TpN3vb3SLOyZ9alO+ZJPvajA4hYDHPm8PmEwUdLrdlvcFvNk2Gj3rX9OMQAL1/lVSweE Xs+J7DEXFBqvJc2J9WGuR8MJTI2uI5OX+ox2LASeQmElrz+t/pfJdxATMovgAWGiaKVE OOGpNWef0+8mPpqLhFVrOMMi+NiO+AkjKkhjSssm2ZeW6m8ghh0kb38IxIhemsfj+Imc nyTQ== 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=1G2xHEuBbX6i9kBTr3QpkoabQbUUI5A3+20IBgzvXZ0=; b=KUm8me9KRV4wmgUsplv/TiETem8fxEFC+H8LjejsAeZ7lBMF44yacHc+3jSHUqygcv aURFck54VXgCsZBx1S5vijYkOAhKHVU+/N2IbkPqakH525ZnHrkEO6cu/rcBYDIKC0hz qOWwfng1vnhfqrXJW+YtNj7MdKHzZyuMbfAqgVH2A4P6YdXSKob9J2gJ96H8fsF8CpTz kkNu5zqQSNBpdKGme1mvzLhWify5UASRTX2bW3yeOW6CdAATsE+v1cwBV4yn8PMAI2/n tBOAk407c7mggzO+tAAHz4LuMHueIbjivL/mz4w+a4+/5hu5jJvGgiod5DjxJEjrGU5K XULw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i39jn3YU; 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 s4si8828206plp.584.2017.10.10.11.05.10; Tue, 10 Oct 2017 11:05:10 -0700 (PDT) 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=i39jn3YU; 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 S932590AbdJJSFH (ORCPT + 26 others); Tue, 10 Oct 2017 14:05:07 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:46363 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932569AbdJJSFE (ORCPT ); Tue, 10 Oct 2017 14:05:04 -0400 Received: by mail-wm0-f51.google.com with SMTP id m72so7518483wmc.1 for ; Tue, 10 Oct 2017 11:05:03 -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=1G2xHEuBbX6i9kBTr3QpkoabQbUUI5A3+20IBgzvXZ0=; b=i39jn3YUxxlCJEuIUyfg270z6JPFyhU2DLTbIfSHoNxxIBemiKlPEIp/wCpnRAZyZv hEAPmF11okTsZts8YTNRhcWmRnOEm72Kcylb/PMDfFldzdYpTLw8H/eLQYTnK93nXPvf IDgPMRuFNcl1Os9MNDOF9j1Kz+byQ2dzHi+q0= 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=1G2xHEuBbX6i9kBTr3QpkoabQbUUI5A3+20IBgzvXZ0=; b=EsgWiRMqtrn9m/tgS+dj71/NPVpnZSQOfwWuCz7bNLgos+mIrEq5KRPwgHA+X0zNiR rYDRPL0zwipR69K3g2dnLI/u7WR23HP+O8o9mJz7I9vN3BcxfN712bfoCYNWusAklzCv tnjQgQnuKIQ/0cLvFYy3pvSA4no4Q3Z9vCEB/BHki4v3aVcBc7tALI6iGGJMkYXQxTmM eiUiMTlTKcbZQgDVs2ZN3jj7ZrOzQu8+hjAKmKDm7oqrd4d7lWBAR2kMcl7CY4EtuYFP 4qjMTXYMeManYIJxRBgjkkqRCFtrxVNqrgP0Tsfw8dvwTaJONNKCesSmX4cEDtdEMTC2 +QKQ== X-Gm-Message-State: AMCzsaXszfGn1+7t/ZLmWvQLPIBp+tJfITXjC4ZBHt7f1kxGsn1ULKQw NdvYvfBE6vDyuiq6GZaNXyGNpTpWV+U= X-Google-Smtp-Source: AOwi7QCRHVScGeOKVOGkXFYmYcfF4JkjHs+HlZlsKPp7VaUMuLlIgB5movbR61BZVgjtm2vckP5/sA== X-Received: by 10.28.247.9 with SMTP id v9mr12737160wmh.104.1507658703217; Tue, 10 Oct 2017 11:05:03 -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.05.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:02 -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, Leo Yan Subject: [PATCH 10/25] thermal/drivers/hisi: Rename and remove unused field Date: Tue, 10 Oct 2017 20:02:35 +0200 Message-Id: <1507658570-32675-10-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rename the 'sensors' field to 'sensor' as we describe only one sensor. Remove the 'sensor_temp' as it is no longer used. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 5b3e681..70dc373 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -49,8 +49,6 @@ struct hisi_thermal_sensor { struct hisi_thermal_data *thermal; struct thermal_zone_device *tzd; - - long sensor_temp; uint32_t id; uint32_t thres_temp; }; @@ -59,9 +57,9 @@ struct hisi_thermal_data { struct mutex thermal_lock; /* protects register data */ struct platform_device *pdev; struct clk *clk; - struct hisi_thermal_sensor sensors; - int irq; + struct hisi_thermal_sensor sensor; void __iomem *regs; + int irq; }; /* @@ -233,7 +231,7 @@ static struct thermal_zone_of_device_ops hisi_of_thermal_ops = { static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) { struct hisi_thermal_data *data = dev; - struct hisi_thermal_sensor *sensor = &data->sensors; + struct hisi_thermal_sensor *sensor = &data->sensor; int temp; hisi_thermal_alarm_clear(data->regs, 1); @@ -244,7 +242,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", temp, sensor->thres_temp); - thermal_zone_device_update(data->sensors.tzd, + thermal_zone_device_update(data->sensor.tzd, THERMAL_EVENT_UNSPECIFIED); } else if (temp < sensor->thres_temp) { @@ -307,7 +305,7 @@ static int hisi_thermal_setup(struct hisi_thermal_data *data) { struct hisi_thermal_sensor *sensor; - sensor = &data->sensors; + sensor = &data->sensor; /* disable module firstly */ hisi_thermal_reset_enable(data->regs, 0); @@ -380,7 +378,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) } ret = hisi_thermal_register_sensor(pdev, data, - &data->sensors, + &data->sensor, HISI_DEFAULT_SENSOR); if (ret) { dev_err(&pdev->dev, "failed to register thermal sensor: %d\n", @@ -402,7 +400,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) return ret; } - hisi_thermal_toggle_sensor(&data->sensors, true); + hisi_thermal_toggle_sensor(&data->sensor, true); return 0; } @@ -410,7 +408,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) static int hisi_thermal_remove(struct platform_device *pdev) { struct hisi_thermal_data *data = platform_get_drvdata(pdev); - struct hisi_thermal_sensor *sensor = &data->sensors; + struct hisi_thermal_sensor *sensor = &data->sensor; hisi_thermal_toggle_sensor(sensor, false); hisi_thermal_disable_sensor(data); From patchwork Tue Oct 10 18:02:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115426 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4039120qgn; Tue, 10 Oct 2017 11:05:13 -0700 (PDT) X-Received: by 10.84.130.47 with SMTP id 44mr12844034plc.171.1507658713358; Tue, 10 Oct 2017 11:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658713; cv=none; d=google.com; s=arc-20160816; b=xidUtbATccmI3FGtZixQPxkPSwVQXwSofi6P1s3B5Vo5Zn9bZz8hBGrqP6RfpD9CaQ vie/bvXYSu21aPJJN2iBwDJZTqIPDa12rvfYgJhuLKOTRJMe2LTeFZp4kviOCxdqMrQ7 S0kbr0bfOD8SZaGhHJk2ymp61Frv2O4A5giRzyfLVFyDmYfsqrm9ALRfxbSGevOVXi1R kC1f34ESaRG+d3h1rOK1KWCOsUYzvlPb8ncXquM2u+DIBhKhKUXRfBC+WdHneXWRNbrN dzyFIdOBJqk84+II5GqjCbv27j1n7+r7JmWKrvt6eYYdvXAPe0Yn3N/TGyIKKy8BAIMn XnkQ== 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=gFJxPc9l2WI4+7dIfqBX+gvWPWfHAR1c3l6eVz+yowE=; b=FyaWtgnbh6Y9K7uMax/YEmanz2ObTWYDOWMey1BflBmfZWn/p2ximgZ+/UBxJJ6fds P61a5MxgRgwQEZ7OCg4huY2KKJnZzYfIMrF1+VXkZSKB+C60BY44CnDwbCaf41PuG88/ qHyx2lkgXVkTpm5JDvbCMyfp4kSBfC1ffs8Zg4S6x9RCqv6o/OhLM/5roYlsP5Vunx5e AaZ97m8T7znsRLLprranxpLaYTQjO7BqVDDNYQqcYyI2aQ66qZLFUddSXYYa1gsvqq+g yQ3oYA/kY1sUarpQjG9cigXx9TgyLAmp27WSr7hYFRyUL1fH1qAFgpdQpmTv0Nz3m+tB NwsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aQPr6rC1; 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 s4si8828206plp.584.2017.10.10.11.05.13; Tue, 10 Oct 2017 11:05:13 -0700 (PDT) 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=aQPr6rC1; 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 S932610AbdJJSFK (ORCPT + 26 others); Tue, 10 Oct 2017 14:05:10 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:47320 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932584AbdJJSFH (ORCPT ); Tue, 10 Oct 2017 14:05:07 -0400 Received: by mail-wm0-f48.google.com with SMTP id t69so7541612wmt.2 for ; Tue, 10 Oct 2017 11:05:06 -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=gFJxPc9l2WI4+7dIfqBX+gvWPWfHAR1c3l6eVz+yowE=; b=aQPr6rC1h+eLW+PkO/gr1++qhE4oyvFx8/mBkH9GhV3eN3YhAA/hgpWu6oufvJ2NU1 YS+qbooYblUdaCGD518bQbAfnxCe02Fp8+jUFPnH5YPgNg9f7ILF58iwS2lzodAs/XNN GtkDXJbasOcvbuNYPb04UizTdZ4g05zDh8AdM= 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=gFJxPc9l2WI4+7dIfqBX+gvWPWfHAR1c3l6eVz+yowE=; b=L1aVFjC6ipUfxAbDQRwLSj8m/u81ehpWL0HnjsVBr+CbC1PSdlpsFUfpSLPcsdW7S7 L3QLwCbYe4pxl/TxABDvNlefeLejcsbk2CLzXNrzdEq3caWy3p2SvHWHxDUQpmKYS7JQ L8g7oVDIuGWUSXEwGD1/JE0sV49P6ZZ/qKhnQ2QulWlxcO1EhnxzCvyBghYNjp3fhDLS OeHLPzcsxc0jwlPLx9XhJV2ILXhVQji5anWccLwEChKksSBukpbn6umSFnctXLjUixVu UbmNuYDtno/6ZEGibmgWMZNEv1c/w1tZ6Lv3TKzrWPpJMcyAgLkMbtpg6te6Fb2t1X57 ZUEg== X-Gm-Message-State: AMCzsaXFFjWSuvyYn/Dbjl4oKBYpJWX1C24tZ8OuwVwKkpuJ+VVBdTdS JpV3ee4pzVg/QtPAON9NQBRXsQ== X-Google-Smtp-Source: AOwi7QBsKMkm8lemrCNRXHnmDTL2B+mWjpWswkxxSy0vu1XrpQOvjesAPe/X6Zwwzgh3B85oxfRe5Q== X-Received: by 10.28.14.138 with SMTP id 132mr10955319wmo.7.1507658706212; Tue, 10 Oct 2017 11:05:06 -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.05.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:05 -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 12/25] thermal/drivers/hisi: Remove thermal data back pointer Date: Tue, 10 Oct 2017 20:02:37 +0200 Message-Id: <1507658570-32675-12-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The presence of the thermal data pointer in the sensor structure has the unique purpose of accessing the thermal data in the interrupt handler. The sensor pointer is passed when registering the interrupt handler, replace the cookie by the thermal data pointer, so the back pointer is no longer needed. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index dabe9a8..5b0b5be 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -47,7 +47,6 @@ #define HISI_DEFAULT_SENSOR 2 struct hisi_thermal_sensor { - struct hisi_thermal_data *thermal; struct thermal_zone_device *tzd; uint32_t id; uint32_t thres_temp; @@ -211,10 +210,10 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) mutex_unlock(&data->thermal_lock); } -static int hisi_thermal_get_temp(void *_sensor, int *temp) +static int hisi_thermal_get_temp(void *__data, int *temp) { - struct hisi_thermal_sensor *sensor = _sensor; - struct hisi_thermal_data *data = sensor->thermal; + struct hisi_thermal_data *data = __data; + struct hisi_thermal_sensor *sensor = &data->sensor; *temp = hisi_thermal_get_temperature(data->regs); @@ -262,10 +261,10 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, const struct thermal_trip *trip; sensor->id = index; - sensor->thermal = data; sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, - sensor->id, sensor, &hisi_of_thermal_ops); + sensor->id, data, + &hisi_of_thermal_ops); if (IS_ERR(sensor->tzd)) { ret = PTR_ERR(sensor->tzd); sensor->tzd = NULL; From patchwork Tue Oct 10 18:02:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115439 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4042781qgn; Tue, 10 Oct 2017 11:08:45 -0700 (PDT) X-Received: by 10.99.0.4 with SMTP id 4mr13311932pga.417.1507658925192; Tue, 10 Oct 2017 11:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658925; cv=none; d=google.com; s=arc-20160816; b=Vo23OgLnNu9fu70T9cjnJrY/KXzyFH8Ok4Y4Eb4NV2MnG8ObO9OLUlPritiEtOFV6h hRulmW6w07Mco430IwoRZWrH2/6gW0HTcOVvkv0QNdIPnGq4IEAtk/RXWdfyoWLzXZ5H 7IobRCUNgCQ2VGEXbZTduN1h9KhPkbvmRfbHse+be+sLgYq1DHF2bDJX+mGBDLyuX+vp B7znJaMMu3Oyj6FcOtDjfJZ0EqsGYtfznRYhxBS+pVB5NWxM1JJ6BbJxD676NOp5kXKi poZjLJO6sBKY8JEi2DIc/o8kuIHnTdN92nYp8RJFi/12dBZI59iVFCquW9KDcP6Wpu4s G2UA== 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=1Itw7Hfb8yHlpi+K32kxh++5/5hXqxwckE5cuRg4aMk=; b=L8VOTJFaIjF36tqn1WRTtWwj3A7sxRBMeRYFrwIm0ZpJIFM/ge5CZHIXj7P4FDl9jp 8NatvNoj+1Y7/vYMtTAeXBoOktcovj62TN8hP5llTkpAihdnbp9g3h5XaRdNwjYN2SpD viz4qX26zPDqKmmyhZ1sRc6mQzW7qIV0jMJX8X8ZEkZofk+fQsJfB0aTLys6KtIjyHGG RMQnNkzuqovNe+hQp8Ss3xO2mufsK4X2c84h9nzu1wdQkpJGLOVDuE1dwOL6qbeBYk4U /lMXyRYz2S4G2kCYGNBWHeKxKpXxJ5w4Dzj2jlICvhi6mOr/c58TKF5hDi5jPJXaHMXM XOCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XYK13c53; 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 5si9394989plx.272.2017.10.10.11.08.44; Tue, 10 Oct 2017 11:08:45 -0700 (PDT) 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=XYK13c53; 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 S932783AbdJJSIm (ORCPT + 26 others); Tue, 10 Oct 2017 14:08:42 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:57244 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932592AbdJJSFJ (ORCPT ); Tue, 10 Oct 2017 14:05:09 -0400 Received: by mail-wm0-f51.google.com with SMTP id l68so7685269wmd.5 for ; Tue, 10 Oct 2017 11:05:08 -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=1Itw7Hfb8yHlpi+K32kxh++5/5hXqxwckE5cuRg4aMk=; b=XYK13c53KNw2Dbpv1zdk2PlqQBK1vZ5C7O2dbuud46alIBtsuGifNfSv25Z+QnEGlQ eeNPmsaiO1tJiPUfJkOF71gSZXBM7jBCGeVjACAOZaP49Ly13bLfX8JV7GyTJn1KjraO Ox5FhgcKncfrHzl9HoWUCuxyxThilqDpSpHvc= 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=1Itw7Hfb8yHlpi+K32kxh++5/5hXqxwckE5cuRg4aMk=; b=E6ED4m4lGAO/hfGPHayAPMmTaJsoz8o14G2NOjYlPG1gvs3M5sCUB4c8Ht39rT/vcd knHTb7sc4yji3tyTT8Ro51i1TnQKopAw7V5vFmMm2rHSp+RpBLGz5G01R254f6OJ4R+w VvvLlGQtICFH3mG6/tDd9CgLvSDYD3r3HBl5eKMKm/zgIWhZPRF6K+N0JTb94Oky+oXC rnU57kVi1ea3yAE+iXfAffQUIsJHocM5aXMmxz/nOd5UeBwhhvAz214d+nTUYRz3VIHQ 4BzPs2Zod0yHIvZtK5mBCw+1oVPsYZIpT+nJXHlcTCJ39ReGgRyBurGAseWjLpwapBJU hC9Q== X-Gm-Message-State: AMCzsaUCRRbrjAwEocdzet6GoioQC9ViG45EkZKNmtYXGjt+EY3j289v tPJRwuURCoMvagvY9nul6rvPyw== X-Google-Smtp-Source: AOwi7QAng6uQ1G8BJd+/rvIOPfzbfD0S9OE/gVQtEE4N2k418wwb/vIr+8/+2Y47s3z9xYCA4lx3sQ== X-Received: by 10.223.158.8 with SMTP id u8mr14439552wre.16.1507658707802; Tue, 10 Oct 2017 11:05:07 -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.05.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:07 -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, Leo Yan Subject: [PATCH 13/25] thermal/drivers/hisi: Remove mutex_lock in the code Date: Tue, 10 Oct 2017 20:02:38 +0200 Message-Id: <1507658570-32675-13-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The mutex is used to protect against writes in the configuration register. That happens at probe time, with no possible race yet. Then when the module is unloaded and at suspend/resume. When the module is unloaded, it is an userspace operation, thus via a process. Suspending the system goes through the freezer to suspend all the tasks synchronously before continuing. So it is not possible to hit the suspend ops in this driver while we are unloading it. The resume is the same situation than the probe. In other words, even if there are several places where we write the configuration register, there is no situation where we can write it at the same time, so far as I can judge Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 6 ------ 1 file changed, 6 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 5b0b5be..241d42c 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -53,7 +53,6 @@ struct hisi_thermal_sensor { }; struct hisi_thermal_data { - struct mutex thermal_lock; /* protects register data */ struct platform_device *pdev; struct clk *clk; struct hisi_thermal_sensor sensor; @@ -200,14 +199,10 @@ static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) { - mutex_lock(&data->thermal_lock); - /* disable sensor module */ 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); } static int hisi_thermal_get_temp(void *__data, int *temp) @@ -344,7 +339,6 @@ static int hisi_thermal_probe(struct platform_device *pdev) if (!data) return -ENOMEM; - mutex_init(&data->thermal_lock); data->pdev = pdev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); From patchwork Tue Oct 10 18:02:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115437 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4042127qgn; Tue, 10 Oct 2017 11:08:06 -0700 (PDT) X-Received: by 10.98.32.212 with SMTP id m81mr14563895pfj.227.1507658886008; Tue, 10 Oct 2017 11:08:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658886; cv=none; d=google.com; s=arc-20160816; b=Exgdfq9KsQ1KWZhuztAeVGaU9CDbE5emupjjrArN5DUD7/w0ugbNkhpQFWtQVyxbCd GJSwfKBa2YCFo3M8SvB21T07L2WvYmXpo+3bsaldSL0F4Qw9qvnEiCwPAtmZcK6Of873 +0x6f476LWSCHgFzmn8f6wUGZZAXUIz086JCl5b6tnlliZqgUS7CTu/Z/VLtTniBy+5d qXpJcSqtG9ehvYxlSgfBjN3BQHCAM5V9lrlGhnLXb3VOOEa7Sh388PVDgJ1Makpc3gsI gMYU7j4D8kV2IWEcLfRc11HCPfvESpQXQyZ2285EwJJHm2mHrrv3Uu5BIJ3dNlzzviCZ ovtw== 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=YBGegqm2fHrZCHEZt7W/w8X5F/h/bUD75IbXg0MUAC8=; b=CcTrTk+r8mv4ncPydB67GcdWZ1YYf9oqqIHhmLZiWcnRbs1kEtGuIMA+tPY0g71Nm0 Aun+NYEXMdogdU1Cy6jqHsX0i4Y1/wdI6APD3OThFVylUiwiU3icpV042oV9Hx48ArCq xdzZFBamkYJ7pSJY1i/U2Myf0XcjNZDqd+W3PhM5bmBDmXRdo5sEnLkIZ6qEooHgyJ/s +DeT7NMA+Roqx7sIc1OyZxfva1vTYihu7uhxW22xv6C7Snyct5g+O3IE6jNvoI/n7U2g puVZpC7UUL1OeK1Ejx0N/Gy9hrpygxbTXmPOyKCoSLstVLVyn6d6JQvz+C/H4wk4oB3Y 0Zfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kB8jkiPT; 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 p15si5844989pll.96.2017.10.10.11.08.05; Tue, 10 Oct 2017 11:08:05 -0700 (PDT) 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=kB8jkiPT; 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 S932629AbdJJSFN (ORCPT + 26 others); Tue, 10 Oct 2017 14:05:13 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:43640 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932599AbdJJSFK (ORCPT ); Tue, 10 Oct 2017 14:05:10 -0400 Received: by mail-wm0-f51.google.com with SMTP id m72so16995416wmc.0 for ; Tue, 10 Oct 2017 11:05:10 -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=YBGegqm2fHrZCHEZt7W/w8X5F/h/bUD75IbXg0MUAC8=; b=kB8jkiPT/ZXgqxAnjtfETS/3RLCj00DdCcA2S6k910p69EQGQSQw0D92ykCqc+p3tl lCXChPW6WAKFB5wTxsvFBOPwt36hobCxNVFZprIagcWUqw6p7tG3cKFuCk7zM+ve6968 WoE8pv88aVJMnKFDsYZmT0RQs2nGrcAS86cWs= 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=YBGegqm2fHrZCHEZt7W/w8X5F/h/bUD75IbXg0MUAC8=; b=UXs89Rw0atMvPjnmJ2gn88bMNzIytr57IwMQdBhADw3hflX8+gg55cUbAGi8RIGFP9 4EAKHqHyB9fqFxKnmYwXks9mmwaHIlplT9ea4Pz09y+t4TTSqYiByKB3vnujPIK9jWzT TmgHhzVB83ttz58Kk5gyxjZDkFxoO6BIJlh2+HEbZ7/8+PlasZAhFU8AmTvM4pRaxNQ+ O/iP9jJJtP0v4efzrrGh7Z4o/iYp9p/1zRnZdnb85wWfZu6sLGm7uysRWpymHHcVkCwh +jKaGX6W6Chwsos7xUrTWQfHWgItJZ2nLmoN+l8S9usrsmUkDHAlo7mxeAiGSN1ef8so fqKw== X-Gm-Message-State: AMCzsaUv1g0sVo1VO81PEduD+siDFfirtULSve1h5V+UyX9jJN5wyo32 xFhvZkMQOoiATc5u/GKVYI/ZXQ== X-Google-Smtp-Source: AOwi7QAuJdwEqRw0YAt/BYitU3Gu5GB0pLIpQb6oDLdAKRGmt7WfQmozXTBRum5W+EZR5EcHpxUPFw== X-Received: by 10.223.143.66 with SMTP id p60mr7321447wrb.142.1507658709379; Tue, 10 Oct 2017 11:05:09 -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.05.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:08 -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, Laxman Dewangan Subject: [PATCH 14/25] thermal/drivers/generic-iio-adc: Switch tz request to devm version Date: Tue, 10 Oct 2017 20:02:39 +0200 Message-Id: <1507658570-32675-14-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Everything mentionned here: https://lkml.org/lkml/2016/4/20/850 This driver was added before the devm_iio_channel_get() function version was merged. The sensor should be released before the iio channel, thus we had to use the non-devm version of thermal_zone_of_sensor_register(). Now the devm_iio_channel_get() is available, do the corresponding change in this driver and remove gadc_thermal_remove(). [Compiled tested only] Acked-by: Laxman Dewangan Signed-off-by: Daniel Lezcano --- drivers/thermal/thermal-generic-adc.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c index 73f55d6..46d3005 100644 --- a/drivers/thermal/thermal-generic-adc.c +++ b/drivers/thermal/thermal-generic-adc.c @@ -126,38 +126,23 @@ static int gadc_thermal_probe(struct platform_device *pdev) gti->dev = &pdev->dev; platform_set_drvdata(pdev, gti); - gti->channel = iio_channel_get(&pdev->dev, "sensor-channel"); + gti->channel = devm_iio_channel_get(&pdev->dev, "sensor-channel"); if (IS_ERR(gti->channel)) { ret = PTR_ERR(gti->channel); dev_err(&pdev->dev, "IIO channel not found: %d\n", ret); return ret; } - gti->tz_dev = thermal_zone_of_sensor_register(&pdev->dev, 0, - gti, &gadc_thermal_ops); + gti->tz_dev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, gti, + &gadc_thermal_ops); if (IS_ERR(gti->tz_dev)) { ret = PTR_ERR(gti->tz_dev); dev_err(&pdev->dev, "Thermal zone sensor register failed: %d\n", ret); - goto sensor_fail; + return ret; } return 0; - -sensor_fail: - iio_channel_release(gti->channel); - - return ret; -} - -static int gadc_thermal_remove(struct platform_device *pdev) -{ - struct gadc_thermal_info *gti = platform_get_drvdata(pdev); - - thermal_zone_of_sensor_unregister(&pdev->dev, gti->tz_dev); - iio_channel_release(gti->channel); - - return 0; } static const struct of_device_id of_adc_thermal_match[] = { @@ -172,7 +157,6 @@ static struct platform_driver gadc_thermal_driver = { .of_match_table = of_adc_thermal_match, }, .probe = gadc_thermal_probe, - .remove = gadc_thermal_remove, }; module_platform_driver(gadc_thermal_driver); From patchwork Tue Oct 10 18:02:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115438 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4042311qgn; Tue, 10 Oct 2017 11:08:15 -0700 (PDT) X-Received: by 10.101.73.193 with SMTP id t1mr13055605pgs.97.1507658895505; Tue, 10 Oct 2017 11:08:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658895; cv=none; d=google.com; s=arc-20160816; b=o/5R8+3sJLfBHNhmmweR27f3OCoNTkQS7ncJ2Ek+izFVqtT1WWunWedyD1JyOfHaBC kMjjz831sPnXjn0gkuRfQfQ5e5o8pUN/+SYurMhVOQaLjadUEIZ8XefaRrzvhPSffF2c noQ5Pta0BT9QgGmiWMg48H2xpTEEfC90KdbC8VmiFdtb8Q9T6hgc3ZYnbHr1Jiyz+Irv 0rXaIlYL13yjriagN8oNlTJ2VHGtQESKC5PFBZhJC6uZEIkmMY6tjmfIUx0sMroNpwBS Uvzv2AmWKPAVYOhxpVNfs1kYcszuGQ4YDTUZFeId3xUE9JsnLjnol9XAc2wgU/FvIHmU /+FQ== 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:arc-authentication-results; bh=l9O69Zgu7L3MlYgYnT3L0ZtiItPcwtBEfH+iilZLcWQ=; b=HNJ6rcfBRI1lFMSo2/+AFzMRPNBuQPy/vABvcclN4MIUg9clsAnD+P1rBOrxZMw6ui 22fFSPLlYdurtJdj5gNyIMo2utt6E6piL9cUPY/mmAuFalGdAEwaAUS4NsBCybB16umT x7FRFKi6rWTeNkctmnNifBEk24ZKtuN1ljapzWulZf5oTkm2P1Rzr31twSfXMOvhrtcg MHAg2Ds414DfHhcvAKnAgozqgT4yjmvK5d2YT31vTBQwNyKB2pej4rvNxzrRS2YXMx3m 7eL42cfFlIW/G/qelfdwpbDhmdmIwTjEmjqrASyZQb0ZFCONzeiMrUOXpm/a1IPKVyU/ th9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QvEM4cT0; 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 p15si5844989pll.96.2017.10.10.11.08.15; Tue, 10 Oct 2017 11:08:15 -0700 (PDT) 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=QvEM4cT0; 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 S932777AbdJJSIN (ORCPT + 26 others); Tue, 10 Oct 2017 14:08:13 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:53012 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932584AbdJJSFM (ORCPT ); Tue, 10 Oct 2017 14:05:12 -0400 Received: by mail-wm0-f48.google.com with SMTP id k4so7703195wmc.1 for ; Tue, 10 Oct 2017 11:05:11 -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 :mime-version:content-transfer-encoding; bh=l9O69Zgu7L3MlYgYnT3L0ZtiItPcwtBEfH+iilZLcWQ=; b=QvEM4cT0biW1LkhTCJwaVrHBtQmqp6friRW/vTTO12yDCzqJJoT4/kxRjjwQIqYRFF v8Cxz4vw5EAP9H5gs+eDTUKDHE1jzi9mz8ktfCl7Qj7BBo5Z/dFovr/SiRY+O0vaiikZ 6CBtSN08L72ewBJQfOoaXBWi/7iTw6UpFd+vU= 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=l9O69Zgu7L3MlYgYnT3L0ZtiItPcwtBEfH+iilZLcWQ=; b=Ki2/bXvYLrQNA81vJ7WLrjcwZ3Wlme5/vnyaJtyeJI5YSjrZe4EQw+HFbQPemv3zzH dxAduBokX9lRmw377XFJr2xkNJw5EOmb0N/wqHWWpIIoyJF8e1r0a5z1ker5O2YLlRv7 CZ/YP80bLX2QGAwPM5MmmJTeQcTY/0G3vptTNVxrlUepsxtKEeETNG+NbEZogdWAcpuC EGhRqYMbZ1rIyLNFeEfIDnebq0Z6PpAQzREVQKm3nPIwnizaULbOyyQWG/WTYSMbppcR hhBTM/iv/LycYL28RFBmLb0/zdLZJDLLppZahvBnS4PEmimdLk5TrnpuB9KqG0eAp6s8 Sx1w== X-Gm-Message-State: AMCzsaWBGs3h8XaQlYbKAP8/pJF0AODvA0tEfNw3lDexzG/AWRCfPCXp wVktMNWFcaiUHgRwPS0aL0X0YQ== X-Google-Smtp-Source: AOwi7QDnXUIJha6E7ReMM1hc3tZs9d8//iVo25GJQD0vhCXOLrInN1ySAoklg3EQ9AHgjgbdmqt/wA== X-Received: by 10.28.68.135 with SMTP id r129mr10833861wma.28.1507658711092; Tue, 10 Oct 2017 11:05:11 -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.05.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:10 -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, Keerthy , John Stultz , Leo Yan Subject: [PATCH 15/25] thermal/drivers/step_wise: Fix temperature regulation misbehavior Date: Tue, 10 Oct 2017 20:02:40 +0200 Message-Id: <1507658570-32675-15-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> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a particular situation when the cooling device is cpufreq and the heat dissipation is not efficient enough where the temperature increases little by little until reaching the critical threshold and leading to a SoC reset. The behavior is reproducible on a hikey6220 with bad heat dissipation (eg. stacked with other boards). Running a simple C program doing while(1); for each CPU of the SoC makes the temperature to reach the passive regulation trip point and ends up to the maximum allowed temperature followed by a reset. This issue has been also reported by running the libhugetlbfs test suite. What is observed is a ping pong between two cpu frequencies, 1.2GHz and 900MHz while the temperature continues to grow. It appears the step wise governor calls get_target_state() the first time with the throttle set to true and the trend to 'raising'. The code selects logically the next state, so the cpu frequency decreases from 1.2GHz to 900MHz, so far so good. The temperature decreases immediately but still stays greater than the trip point, then get_target_state() is called again, this time with the throttle set to true *and* the trend to 'dropping'. From there the algorithm assumes we have to step down the state and the cpu frequency jumps back to 1.2GHz. But the temperature is still higher than the trip point, so get_target_state() is called with throttle=1 and trend='raising' again, we jump to 900MHz, then get_target_state() is called with throttle=1 and trend='dropping', we jump to 1.2GHz, etc ... but the temperature does not stabilizes and continues to increase. [ 237.922654] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 237.922678] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 237.922690] thermal cooling_device0: cur_state=0 [ 237.922701] thermal cooling_device0: old_target=0, target=1 [ 238.026656] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 238.026680] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=1 [ 238.026694] thermal cooling_device0: cur_state=1 [ 238.026707] thermal cooling_device0: old_target=1, target=0 [ 238.134647] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 238.134667] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 238.134679] thermal cooling_device0: cur_state=0 [ 238.134690] thermal cooling_device0: old_target=0, target=1 In this situation the temperature continues to increase while the trend is oscillating between 'dropping' and 'raising'. We need to keep the current state untouched if the throttle is set, so the temperature can decrease or a higher state could be selected, thus preventing this oscillation. Keeping the next_target untouched when 'throttle' is true at 'dropping' time fixes the issue. The following traces show the governor does not change the next state if trend==2 (dropping) and throttle==1. [ 2306.127987] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 2306.128009] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 2306.128021] thermal cooling_device0: cur_state=0 [ 2306.128031] thermal cooling_device0: old_target=0, target=1 [ 2306.231991] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 2306.232016] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=1 [ 2306.232030] thermal cooling_device0: cur_state=1 [ 2306.232042] thermal cooling_device0: old_target=1, target=1 [ 2306.335982] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=0,throttle=1 [ 2306.336006] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=0,throttle=1 [ 2306.336021] thermal cooling_device0: cur_state=1 [ 2306.336034] thermal cooling_device0: old_target=1, target=1 [ 2306.439984] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 2306.440008] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=0 [ 2306.440022] thermal cooling_device0: cur_state=1 [ 2306.440034] thermal cooling_device0: old_target=1, target=0 [ ... ] After a while, if the temperature continues to increase, the next state becomes 2 which is 720MHz on the hikey. That results in the temperature stabilizing around the trip point. [ 2455.831982] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 2455.832006] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=0 [ 2455.832019] thermal cooling_device0: cur_state=1 [ 2455.832032] thermal cooling_device0: old_target=1, target=1 [ 2455.935985] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=0,throttle=1 [ 2455.936013] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=0,throttle=0 [ 2455.936027] thermal cooling_device0: cur_state=1 [ 2455.936040] thermal cooling_device0: old_target=1, target=1 [ 2456.043984] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=0,throttle=1 [ 2456.044009] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=0,throttle=0 [ 2456.044023] thermal cooling_device0: cur_state=1 [ 2456.044036] thermal cooling_device0: old_target=1, target=1 [ 2456.148001] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 2456.148028] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 2456.148042] thermal cooling_device0: cur_state=1 [ 2456.148055] thermal cooling_device0: old_target=1, target=2 [ 2456.252009] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 2456.252041] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=0 [ 2456.252058] thermal cooling_device0: cur_state=2 [ 2456.252075] thermal cooling_device0: old_target=2, target=1 IOW, this change is needed to keep the state for a cooling device if the temperature trend is oscillating while the temperature increases slightly. Without this change, the situation above leads to a catastrophic crash by a hardware reset on hikey. This issue has been reported to happen on an OMAP dra7xx also. Signed-off-by: Daniel Lezcano Cc: Keerthy Cc: John Stultz Cc: Leo Yan Tested-by: Keerthy Reviewed-by: Keerthy --- drivers/thermal/step_wise.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c index be95826..ee047ca 100644 --- a/drivers/thermal/step_wise.c +++ b/drivers/thermal/step_wise.c @@ -31,8 +31,7 @@ * If the temperature is higher than a trip point, * a. if the trend is THERMAL_TREND_RAISING, use higher cooling * state for this trip point - * b. if the trend is THERMAL_TREND_DROPPING, use lower cooling - * state for this trip point + * b. if the trend is THERMAL_TREND_DROPPING, do nothing * c. if the trend is THERMAL_TREND_RAISE_FULL, use upper limit * for this trip point * d. if the trend is THERMAL_TREND_DROP_FULL, use lower limit @@ -94,9 +93,11 @@ static unsigned long get_target_state(struct thermal_instance *instance, if (!throttle) next_target = THERMAL_NO_TARGET; } else { - next_target = cur_state - 1; - if (next_target > instance->upper) - next_target = instance->upper; + if (!throttle) { + next_target = cur_state - 1; + if (next_target > instance->upper) + next_target = instance->upper; + } } break; case THERMAL_TREND_DROP_FULL: From patchwork Tue Oct 10 18:02:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115427 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4039249qgn; Tue, 10 Oct 2017 11:05:21 -0700 (PDT) X-Received: by 10.84.232.203 with SMTP id x11mr12845408plm.396.1507658721250; Tue, 10 Oct 2017 11:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658721; cv=none; d=google.com; s=arc-20160816; b=IJqWrLuYZAf7wuazwdEHg7AqdPdnwBpU+KNS8TgMVmhC1aGTKFDSqMqwDHrGrDGE8k 5AXuDCHChve5IHCkvKaONZQoMFBHGJJHZc4q+KOcrt3IHQiEOQBe5Lryo3jvXidU1HqH IYFzoor/NaQwB0ZEb4LJDXACrRLBfrWtOEGUxMJAeH44a7v2XDCW9iYr8nomdBh0IceY 083XEL1DYc0Vss9ld5IbTlK/XAEWJJKMJy+eU5UVzjxhwurd6+CIcrWxnJr6fvzciv+V 2NGRmo1I/nM3lo4pK+D9ZHtgFmB/NSvfMQVuH7ROdkYEHhkMEXbMwQOZEzLM/rm7n7hY oa8Q== 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=dohuYtmbBQqt09ape1TFhBpj7e534EG+iGnCtAT4Av4=; b=TVAlhvP4B9pjX9tFXDxHBKT8IxNJ3xyEo1+WTPp/0UTizOLBuBGLGAXVp0Ts/2HGWA QrR+HYvOEnbgh0uV+ZGojVUYlFSrWpjMs+e06FmLou2MG4z9rNu3csoaERufh4G+0uzZ p6DJm7bwJjmWle1TKYLsOSLK33IIs/Jl+J2g02469W2ozphFWFrdDLevDYJxYzRCCp3j tTZtFOjUcnm3GcA83Lan8poAW6q5khbfrJ9gGSzZooMiXxua7X+ryaJp3Cop830Hl4uw YlGgPnln98+ee06zur5aZLSy96WE4QOq+Wi/KsOp0Bgft6pyyEs4kBZMT8B9XOeRCrkL uHOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SnKfND9d; 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 s4si8828206plp.584.2017.10.10.11.05.20; Tue, 10 Oct 2017 11:05:21 -0700 (PDT) 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=SnKfND9d; 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 S932670AbdJJSFS (ORCPT + 26 others); Tue, 10 Oct 2017 14:05:18 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:50790 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932623AbdJJSFN (ORCPT ); Tue, 10 Oct 2017 14:05:13 -0400 Received: by mail-wm0-f49.google.com with SMTP id u138so7493455wmu.5 for ; Tue, 10 Oct 2017 11:05:13 -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=dohuYtmbBQqt09ape1TFhBpj7e534EG+iGnCtAT4Av4=; b=SnKfND9dB0H32TgbjSezsGJ2n+9jJGYjyFYrpctqLz8IiMZvm82iEvxBu9FqaS+UGC hS394lWiIyGn6X5fYHD4bE/aj4jxPordp4TuA+zji7ViV8jhdi23ljrmLFpHV+UDw+ay 4WFXfZba8VuA3yMWBY++mhBu+qPoW4InWUQjo= 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=dohuYtmbBQqt09ape1TFhBpj7e534EG+iGnCtAT4Av4=; b=gbFagaTzwgkHTz1Clya201H9VGxONxJs4ZeHdt0BlCTTyDYtLjA0W2C78rYxnJ+76q zB1Jd3TDOfu0Znn979jqdAdXY1wmPmzcD7rSSLaCgtVFmrItLw0L6OhIoxy6L0JLrhVP CEzVyhapWVP6z9ES4ohOr7Ee4RJviP5YW3039HUtB2xCH7FY4BrBIGnSFCrh0FmtH23d 2n8qFyWstxiBI2r5k++KgwwTE5UnO44VNujyTd+zv525HuaNZl6vGoHD3Y8awx2QOBHj olMxgPN3cfRYNf4F6PJWDubOQ30s6SDw5Xj+agdmBv6wet/Xv40YPmQJdjUWwlvNu7ue Ireg== X-Gm-Message-State: AMCzsaXJxJr9QLuPR3rbDfeh7KrZwg2M5CmfY9OrRT3rUT8sIt85wt2l YykpQvdLq+ATEi32JS2+paLMbg== X-Google-Smtp-Source: AOwi7QA37LAtp3K+Cuz006KWwc1KkdC5ETF3nU08aPqU6Cu+QKXEiv7KX59ndYKaA0Frr4E4W62VWQ== X-Received: by 10.28.197.201 with SMTP id v192mr12924380wmf.52.1507658712553; Tue, 10 Oct 2017 11:05:12 -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.05.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:12 -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 16/25] thermal/drivers/qcom-spmi: Use devm_iio_channel_get Date: Tue, 10 Oct 2017 20:02:41 +0200 Message-Id: <1507658570-32675-16-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The iio_channel_get() function has now its devm_ version. Use it and remove all the rollback code for iio_channel_release() as well as the .remove ops. [Compiled tested only] Signed-off-by: Daniel Lezcano --- drivers/thermal/qcom-spmi-temp-alarm.c | 43 +++++++++++----------------------- 1 file changed, 14 insertions(+), 29 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom-spmi-temp-alarm.c index f502419..95f987d 100644 --- a/drivers/thermal/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom-spmi-temp-alarm.c @@ -125,7 +125,7 @@ static int qpnp_tm_get_temp(void *data, int *temp) if (!temp) return -EINVAL; - if (IS_ERR(chip->adc)) { + if (!chip->adc) { ret = qpnp_tm_update_temp_no_adc(chip); if (ret < 0) return ret; @@ -224,67 +224,53 @@ static int qpnp_tm_probe(struct platform_device *pdev) return irq; /* ADC based measurements are optional */ - chip->adc = iio_channel_get(&pdev->dev, "thermal"); - if (PTR_ERR(chip->adc) == -EPROBE_DEFER) - return PTR_ERR(chip->adc); + chip->adc = devm_iio_channel_get(&pdev->dev, "thermal"); + if (IS_ERR(chip->adc)) { + ret = PTR_ERR(chip->adc); + chip->adc = NULL; + if (ret == -EPROBE_DEFER) + return ret; + } chip->base = res; ret = qpnp_tm_read(chip, QPNP_TM_REG_TYPE, &type); if (ret < 0) { dev_err(&pdev->dev, "could not read type\n"); - goto fail; + return ret; } ret = qpnp_tm_read(chip, QPNP_TM_REG_SUBTYPE, &subtype); if (ret < 0) { dev_err(&pdev->dev, "could not read subtype\n"); - goto fail; + return ret; } if (type != QPNP_TM_TYPE || subtype != QPNP_TM_SUBTYPE) { dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", type, subtype); - ret = -ENODEV; - goto fail; + return -ENODEV; } ret = qpnp_tm_init(chip); if (ret < 0) { dev_err(&pdev->dev, "init failed\n"); - goto fail; + return ret; } ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr, IRQF_ONESHOT, node->name, chip); if (ret < 0) - goto fail; + return ret; chip->tz_dev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, chip, &qpnp_tm_sensor_ops); if (IS_ERR(chip->tz_dev)) { dev_err(&pdev->dev, "failed to register sensor\n"); - ret = PTR_ERR(chip->tz_dev); - goto fail; + return PTR_ERR(chip->tz_dev); } return 0; - -fail: - if (!IS_ERR(chip->adc)) - iio_channel_release(chip->adc); - - return ret; -} - -static int qpnp_tm_remove(struct platform_device *pdev) -{ - struct qpnp_tm_chip *chip = dev_get_drvdata(&pdev->dev); - - if (!IS_ERR(chip->adc)) - iio_channel_release(chip->adc); - - return 0; } static const struct of_device_id qpnp_tm_match_table[] = { @@ -299,7 +285,6 @@ static struct platform_driver qpnp_tm_driver = { .of_match_table = qpnp_tm_match_table, }, .probe = qpnp_tm_probe, - .remove = qpnp_tm_remove, }; module_platform_driver(qpnp_tm_driver); From patchwork Tue Oct 10 18:02:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115435 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4041301qgn; Tue, 10 Oct 2017 11:07:18 -0700 (PDT) X-Received: by 10.84.130.35 with SMTP id 32mr12681177plc.368.1507658838644; Tue, 10 Oct 2017 11:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658838; cv=none; d=google.com; s=arc-20160816; b=p7IMft1pW8PeiEuA1iO9e5ucZd3BLuMCxfgrRHcgoHZS2MVScPDzbAXLPj7G4N7+OV DydQ1V7jhOVm78dpF+KmPout3ctqz4n53ni6QTFMNp7/O7hnGE09WRX527bvRGGMFhLq ETibpWcg/AVRCwtwMO+DQkvJgPesJBj7TohScqK59b/eQ2GBW9E7hHxjINILMeq58MTv E5e+3XW62DdIzWwGf7cDB1ysvgUj2Bojamk3vNSHuxlYZbFOm5KbpF9Jhg+R/WQ9RpaF T/WAfyTNxv3FhV4/UKAgI6dE4CVAb6CiNciiF95L5naBkliFH/dVtn6YEo59Bso1HZpf KCjw== 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:arc-authentication-results; bh=4jSU0ID7ZCGaW3jMpZz+24E3JTJrZbYKmN7VT1hVyDA=; b=ce1zncLj/gacK2KuYUquwAdSzK29FjYRiMWHwLC5IcWMkRsq+Aw0j0VvY0MvM1EW+t QcZk2YSXzFLws5Lv1vXFLn5dph4WLznAa7w50iysNS6kIIAZ47SzMnrapFMmEK95yiTH Tzb6Zta2Q2ZtcE0UDRO/kCQFJ06XiBYM0TOx4Bvm8h4iNEP6N44lzEjfMko9ZJOXrKnS G4lrn+7A2GUot+cIS5Reh8g8T25N2XIFbpDtPm5aiKjZgGANfiH0ZsqYtMwpnnhBSQaR GbqEeLECo8J15ZvzBR4KP3wnIHlblYCF+7tMRYk70XRfmeoFHFhDrane6hmm6Y8X6t2v jTYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PLymuOlr; 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 44si9460332pla.680.2017.10.10.11.07.18; Tue, 10 Oct 2017 11:07:18 -0700 (PDT) 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=PLymuOlr; 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 S932764AbdJJSHP (ORCPT + 26 others); Tue, 10 Oct 2017 14:07:15 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:45736 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932647AbdJJSFQ (ORCPT ); Tue, 10 Oct 2017 14:05:16 -0400 Received: by mail-wm0-f52.google.com with SMTP id q124so7517326wmb.0 for ; Tue, 10 Oct 2017 11:05:16 -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 :mime-version:content-transfer-encoding; bh=4jSU0ID7ZCGaW3jMpZz+24E3JTJrZbYKmN7VT1hVyDA=; b=PLymuOlrXGhD7Mrx+EaUxvSrXjZPLiGX8f7zeu0XyD/OafiUJqwRWcYHeGZRCwcK1q NLgtYpVA037E3/x/EoqM9rfnOcfnvgx41yWevg9/7usWrQogzAJaWOF0wjq4eQnERXPP JhK1zxmEnFHbxSCYIJW66Mnm2j7RCl2zzNPkw= 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=4jSU0ID7ZCGaW3jMpZz+24E3JTJrZbYKmN7VT1hVyDA=; b=Xkmn+fepk8vkG55ZSU8ETL/ktgJ+j6Q6GnsKUvVZV8qsNJ3TS3y9ceY2cqeYiHNTMI D1GHVEyv+Smcx3qfgc0yJIZT+dVch8Pz5y8DkkELlAvwEFl+7bHwKFzob3PY8/A4MCvh iGHi8uNlwXPXVH1T7WsrQsOUX/ESBGpVK2NzDjG/ch7urTuyhgoYayz5dyFHGfyMMmFR KUPV6lQ1Mf4lOR1Gx6abTtP0WtUO3RfwVVZRt2a2qo2Nv5Z3eYDTfTpnyNrct78zHqxW D34L4OzxXpIA74Mx9wba3CtIj2OKfwmXj5yPIEeEQguoJFxGXsJuscl/SfnorHe6HEJ/ gdbw== X-Gm-Message-State: AMCzsaUEig1CNY2RI25xKqJWoQZtBR2hVMw/Ody+ovNWwh12q2BhDsSc +7mlug5WuRB42Du5DRPZ8N/HUQ== X-Google-Smtp-Source: AOwi7QBYSWStoM81EnzIWt0eRCkkxK3KURBTCh07oHHX3JdgMWqzyInL+2R1JqyLGh8YGM30GLSY+Q== X-Received: by 10.223.131.65 with SMTP id 59mr12371622wrd.66.1507658715394; Tue, 10 Oct 2017 11:05:15 -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.05.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:14 -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 18/25] thermal/drivers/hisi: Use round up step value Date: Tue, 10 Oct 2017 20:02:43 +0200 Message-Id: <1507658570-32675-18-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> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Wangtao Use round up division to ensure the programmed value of threshold and the lag are not less than what we set, and in order to keep the accuracy while using round up division, the step value should be a rounded up value. There is no need to use hisi_thermal_round_temp. Signed-off-by: Kevin Wangtao Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 02d0ad8..befdb28 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -40,7 +40,7 @@ #define HISI_TEMP_BASE (-60000) #define HISI_TEMP_RESET (100000) -#define HISI_TEMP_STEP (784) +#define HISI_TEMP_STEP (785) #define HISI_TEMP_LAG (3500) #define HISI_MAX_SENSORS 4 @@ -63,19 +63,19 @@ struct hisi_thermal_data { /* * The temperature computation on the tsensor is as follow: * Unit: millidegree Celsius - * Step: 255/200 (0.7843) + * Step: 200/255 (0.7843) * Temperature base: -60°C * - * The register is programmed in temperature steps, every step is 784 + * The register is programmed in temperature steps, every step is 785 * millidegree and begins at -60 000 m°C * * The temperature from the steps: * - * Temp = TempBase + (steps x 784) + * Temp = TempBase + (steps x 785) * * and the steps from the temperature: * - * steps = (Temp - TempBase) / 784 + * steps = (Temp - TempBase) / 785 * */ static inline int hisi_thermal_step_to_temp(int step) @@ -85,13 +85,7 @@ static inline int hisi_thermal_step_to_temp(int step) static inline int hisi_thermal_temp_to_step(int temp) { - return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; -} - -static inline int hisi_thermal_round_temp(int temp) -{ - return hisi_thermal_step_to_temp( - hisi_thermal_temp_to_step(temp)); + return DIV_ROUND_UP(temp - HISI_TEMP_BASE, HISI_TEMP_STEP); } /* @@ -127,7 +121,7 @@ static inline int hisi_thermal_round_temp(int temp) */ static inline void hisi_thermal_set_lag(void __iomem *addr, int value) { - writel((value / HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG); + writel(DIV_ROUND_UP(value, HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG); } static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) @@ -274,7 +268,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) { if (trip[i].type == THERMAL_TRIP_PASSIVE) { - sensor->thres_temp = hisi_thermal_round_temp(trip[i].temperature); + sensor->thres_temp = trip[i].temperature; break; } } From patchwork Tue Oct 10 18:02:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115428 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4039288qgn; Tue, 10 Oct 2017 11:05:24 -0700 (PDT) X-Received: by 10.99.168.13 with SMTP id o13mr13152946pgf.435.1507658723924; Tue, 10 Oct 2017 11:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658723; cv=none; d=google.com; s=arc-20160816; b=Tu7GpZ9qB172N/PIDGjRvFMkyLyNcX/CirwCPpn5KGZBaUvyKB91cArIj+eKHPSsKR FvT33rw9NrER+TCeDJrdxzHdfQdz1aUGs2FhURSjNjWJXWoxE/DUrbH0ThpWamZqRFpN zlhvmfdOGLc8oXOL/K3W7i4yNBlilV+9mgPMgVs5Syo9umU+VSz4tpi8nNy/lEbGPoWd 9NL6seqMk+HXG2wcy2QNWMdJj8elr7pDvviNg2+hAbS/K5K7JVCuZGevt92HMHMHbHo/ bRG33r1ydmCa17SMU/tgDOSIlJ418ZViktGRc5XAErrO97PcbfbQ/I1eBLpyBwcOfbA7 K2Xg== 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=LVMPc6PvZ///EJBUOnr5Vy8p3tP3rB0lSv32gwuCQuc=; b=rswY1F1MHxYg7F5I244tZd4tVWK/AsZ6cttMa//KMIYQU7EevrOplA9OJma7JH2DyZ UlCgYincVJBtRhXaCEZ9w13NmfWZA11rUpC47bwGxTbhn4jUbYW2QQ8Sbcn/ClisTaCk s9gjc7KDW37Ukslrc6+lyRkjG1AG0QuDDZTjR4JFYRzx2cOs4ahrro2GOSIsXY+/iuD8 Z/cHwbXlfJK8pHWwI11OB8bCdiSoJ2Awgk7fsSzofHBul9EQkafGSZd2mrFkpYXZEXNo gccsTHBrjvSJ8rKSOx+SUmO1Jo93USWKfhPIl84lryK6lUaR0T7K2IqA/dIIOBBzsMkn yqPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a/DfNW8P; 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 s4si8828206plp.584.2017.10.10.11.05.23; Tue, 10 Oct 2017 11:05:23 -0700 (PDT) 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=a/DfNW8P; 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 S932688AbdJJSFV (ORCPT + 26 others); Tue, 10 Oct 2017 14:05:21 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:53042 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932663AbdJJSFS (ORCPT ); Tue, 10 Oct 2017 14:05:18 -0400 Received: by mail-wm0-f41.google.com with SMTP id k4so7703889wmc.1 for ; Tue, 10 Oct 2017 11:05:17 -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=LVMPc6PvZ///EJBUOnr5Vy8p3tP3rB0lSv32gwuCQuc=; b=a/DfNW8P1tovMNLWzW0/v2pMZ49Oca1cunJAzA1vc8byWUFffm0/C3dxm786UazgWP 6T052iIpR4g4ay8HAlM+obNmKq4MpJH6h47vEkQ5YX1qgRl7op1TgB/CSF5jPLk46S1Y uMxFEHc2OXns7/9tzBzbCczKl56bsUv0ImmII= 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=LVMPc6PvZ///EJBUOnr5Vy8p3tP3rB0lSv32gwuCQuc=; b=g11lMIOfPYHS8HtXKD/cAePSVnnNfzpLDJlDwEPZGkC7i7OEZRptL0oV1YLf5YjZWp q+BoSnMaCdz9CtN0Byc3bt8YoBi2WV/qOOY8PrV/hnVtCuNzZp6nfyXGbFs9UNW8uBrJ 4FFwMoD0RP5PeA1E9wL1w5ukfNGzsNh0Fd99Gfu5bvUaDy01hoR40Q0k6P/pB6ByBLAq I46vx5Wf64AM+j0tdP8xGs1yEwOkspe4cuNVA5rGYwchL5jzUvnDdJ9dILIgj4Gld3Xj d4yMFT/qzcQj536a3MLBSNN8Ru5BS8yw3KeqvjuEZzW1BfYCVuA7ll7/BmHyOaik/lIu TGnw== X-Gm-Message-State: AMCzsaULVIQfXUS34xwSFLvROpYS4Fb5Rr9VIEKfi0QcSGXonWOxmja/ T87REBy/g9IO0RT7TTq0s93EUA== X-Google-Smtp-Source: AOwi7QBOYRbcoDOOSHGqPwySQfRrr8+AYNw8AAUTWTGfayl7fycZdziIIvqm1wu3d1c8v+gy0W/PjA== X-Received: by 10.28.175.197 with SMTP id y188mr10644587wme.20.1507658716825; Tue, 10 Oct 2017 11:05:16 -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.05.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:16 -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 19/25] thermal/drivers/hisi: Put platform code together Date: Tue, 10 Oct 2017 20:02:44 +0200 Message-Id: <1507658570-32675-19-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Wangtao Reorganize the code for next patches by moving the functions upper in the file which will prevent a forward declaration. There is no functional change here. Signed-off-by: Kevin Wangtao Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 76 +++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 38 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index befdb28..ff9055a 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -201,6 +201,44 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) clk_disable_unprepare(data->clk); } + +static int hisi_thermal_setup(struct hisi_thermal_data *data) +{ + struct hisi_thermal_sensor *sensor = &data->sensor; + int ret; + + /* enable clock for tsensor */ + ret = clk_prepare_enable(data->clk); + if (ret) + return ret; + + /* disable module firstly */ + hisi_thermal_reset_enable(data->regs, 0); + hisi_thermal_enable(data->regs, 0); + + /* select sensor id */ + hisi_thermal_sensor_select(data->regs, sensor->id); + + /* setting the hdak time */ + hisi_thermal_hdak_set(data->regs, 0); + + /* setting lag value between current temp and the threshold */ + hisi_thermal_set_lag(data->regs, HISI_TEMP_LAG); + + /* enable for interrupt */ + hisi_thermal_alarm_set(data->regs, sensor->thres_temp); + + hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); + + /* enable module */ + hisi_thermal_reset_enable(data->regs, 1); + hisi_thermal_enable(data->regs, 1); + + hisi_thermal_alarm_clear(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 1); + + return 0; +} static int hisi_thermal_get_temp(void *__data, int *temp) { struct hisi_thermal_data *data = __data; @@ -291,44 +329,6 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); } -static int hisi_thermal_setup(struct hisi_thermal_data *data) -{ - struct hisi_thermal_sensor *sensor = &data->sensor; - int ret; - - /* enable clock for tsensor */ - ret = clk_prepare_enable(data->clk); - if (ret) - return ret; - - /* disable module firstly */ - hisi_thermal_reset_enable(data->regs, 0); - hisi_thermal_enable(data->regs, 0); - - /* select sensor id */ - hisi_thermal_sensor_select(data->regs, sensor->id); - - /* setting the hdak time */ - hisi_thermal_hdak_set(data->regs, 0); - - /* setting lag value between current temp and the threshold */ - hisi_thermal_set_lag(data->regs, HISI_TEMP_LAG); - - /* enable for interrupt */ - hisi_thermal_alarm_set(data->regs, sensor->thres_temp); - - hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); - - /* enable module */ - hisi_thermal_reset_enable(data->regs, 1); - hisi_thermal_enable(data->regs, 1); - - hisi_thermal_alarm_clear(data->regs, 0); - hisi_thermal_alarm_enable(data->regs, 1); - - return 0; -} - static int hisi_thermal_probe(struct platform_device *pdev) { struct hisi_thermal_data *data; From patchwork Tue Oct 10 18:02:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115434 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4040853qgn; Tue, 10 Oct 2017 11:06:53 -0700 (PDT) X-Received: by 10.101.64.4 with SMTP id f4mr5479520pgp.301.1507658813346; Tue, 10 Oct 2017 11:06:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658813; cv=none; d=google.com; s=arc-20160816; b=ZcSCuaoIt5bKhbD6ylN5tWAJlnir6SgdsO5huWjYhpK9uv3YsVW1WPrbXiW9+NUXGz fk8cs5phhllnQoKT7Lv0hVJftuJkSVP/r9PGk0IOYRCk92F1k69pz0iLFFSGO3yucsxU 2ht+FUR85nAaspEEEGp4ZGnLxYGraJyPlAX+2dAMKY32YI1KIwv/E7guRUMcTBeUFjWe 32LBbKzTJdL4XRiLzWiy9c90qsQqmjXh4B7D7YIyimkgEk+hsgOYBA6d/eKqMDb/JbiP U3PNfs/Z+mGopbf/YGLoAnr1HCRYC26aDJcXZofQGia6M27DQ8lMe99jUmb+Omv9mg6P M91Q== 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:arc-authentication-results; bh=aeZf6lGFLCqkg122v8PAGvQ4N80eAcaRlIP92kLqFE4=; b=I3yNsdcMWqWY+9p+NF6jj6EMgulv77YHIM8AUTR+/sJNYFJo1+l1kfW3lG0BeRPQud hhmpCc7qdkD5KgdoLgY4YMm2cFRZNy4y8BUH0Ts9QIfqT9JGzg5iuQ2SpSB7QYQ0zL6v CH3yf/F0DEwtKGkzP9hAv6s1qqRo+Dt/0Ut4aXYUjTr1gnrZHokyOSwJRc9FhEnO/9Sw yQAAQ5M4GllCEUvarSyZQIvvLEDYowoBF995HalJNFEjCcLQ1iyC7tIgxjQVYgyXJ43y aJEUaEe87vW6ZiK/fdWkCM/dijbfX6kFHFxlPgWdFBoqCaSiMKG29dskUKNqUJjefAJx iGjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DjUn531Y; 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 33si4873894ply.789.2017.10.10.11.06.53; Tue, 10 Oct 2017 11:06:53 -0700 (PDT) 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=DjUn531Y; 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 S932762AbdJJSGu (ORCPT + 26 others); Tue, 10 Oct 2017 14:06:50 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:50003 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932671AbdJJSFU (ORCPT ); Tue, 10 Oct 2017 14:05:20 -0400 Received: by mail-wm0-f52.google.com with SMTP id b189so7444489wmd.4 for ; Tue, 10 Oct 2017 11:05:19 -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 :mime-version:content-transfer-encoding; bh=aeZf6lGFLCqkg122v8PAGvQ4N80eAcaRlIP92kLqFE4=; b=DjUn531Y/9b+313R52PTBPAZuGLjAOmlfjbaHltqx6BeMsRApUGtWXquFlwySqQFcj SD4slP31wrZbfucfAck0lksbRo7tMRBVu518X75dDca+eQLUXe4fbQVMC677qMCaqqKJ JY8qNF+ALOTymUWqPTU32abnI5+Dde37rBF4I= 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=aeZf6lGFLCqkg122v8PAGvQ4N80eAcaRlIP92kLqFE4=; b=qJqzZRPF52CWm8pJVe5ZSMQiPnVOIbzRCHoEfpQuBVxhcXMPekrdLJPMvZ3ZMfISqZ VMSUykiKFbnRlrbthZD14r1FfMIpxk4BoTVZ18G/w+d/uDKpkXBYEABQXjBdgRXez1KN fDRvFIhk4mkrQWID/M4PrvaH+GkCqPlGJvre2s7D8895vbHsUMWEa5VALwxwND3SqGFS hEp7tEb8YEueV7KO5Od0a2vaUZkgwEa2IAasCVDj1rKjebPwUZzScHU2XlHpjBfjgOFW EXhn8rTaWiPnqCmCzfzzuyLCrEz3TRgKtO7voxqeOOEaNSirh9wyWvWZYweyLbR58Gwq jeuA== X-Gm-Message-State: AMCzsaXIGCm6WX/kMY8MsvJVX11KXUKFCOT/VQaEC9fPMJnRKZh5myMt ES96nmlyru1ZSeM+nPY4gUHTkRtmubU= X-Google-Smtp-Source: AOwi7QC7H8akjTXhysA07vUYjO4vyD97OnYWGJlSEd1V6qtfSk4PiJTBmroo9PvczFFGc7lp0S+l2g== X-Received: by 10.223.186.20 with SMTP id o20mr15730917wrg.3.1507658718431; Tue, 10 Oct 2017 11:05:18 -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.05.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:17 -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 20/25] thermal/drivers/hisi: Add platform prefix to function name Date: Tue, 10 Oct 2017 20:02:45 +0200 Message-Id: <1507658570-32675-20-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> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Wangtao As the next patches will provide support for the hikey3660's sensor, several functions with the same purpose but for different platforms will be introduced. In order to make a clear distinction between them, let's prefix the function names with the platform name. This patch has no functional changes. Signed-off-by: Kevin Wangtao Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 145 +++++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 72 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index ff9055a..8a70ab7 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -26,25 +26,24 @@ #include "thermal_core.h" -#define TEMP0_LAG (0x0) -#define TEMP0_TH (0x4) -#define TEMP0_RST_TH (0x8) -#define TEMP0_CFG (0xC) -#define TEMP0_CFG_SS_MSK (0xF000) -#define TEMP0_CFG_HDAK_MSK (0x30) -#define TEMP0_EN (0x10) -#define TEMP0_INT_EN (0x14) -#define TEMP0_INT_CLR (0x18) -#define TEMP0_RST_MSK (0x1C) -#define TEMP0_VALUE (0x28) - -#define HISI_TEMP_BASE (-60000) -#define HISI_TEMP_RESET (100000) -#define HISI_TEMP_STEP (785) -#define HISI_TEMP_LAG (3500) - -#define HISI_MAX_SENSORS 4 -#define HISI_DEFAULT_SENSOR 2 +#define HI6220_TEMP0_LAG (0x0) +#define HI6220_TEMP0_TH (0x4) +#define HI6220_TEMP0_RST_TH (0x8) +#define HI6220_TEMP0_CFG (0xC) +#define HI6220_TEMP0_CFG_SS_MSK (0xF000) +#define HI6220_TEMP0_CFG_HDAK_MSK (0x30) +#define HI6220_TEMP0_EN (0x10) +#define HI6220_TEMP0_INT_EN (0x14) +#define HI6220_TEMP0_INT_CLR (0x18) +#define HI6220_TEMP0_RST_MSK (0x1C) +#define HI6220_TEMP0_VALUE (0x28) + +#define HI6220_TEMP_BASE (-60000) +#define HI6220_TEMP_RESET (100000) +#define HI6220_TEMP_STEP (785) +#define HI6220_TEMP_LAG (3500) + +#define HI6220_DEFAULT_SENSOR 2 struct hisi_thermal_sensor { struct thermal_zone_device *tzd; @@ -78,14 +77,14 @@ struct hisi_thermal_data { * steps = (Temp - TempBase) / 785 * */ -static inline int hisi_thermal_step_to_temp(int step) +static inline int hi6220_thermal_step_to_temp(int step) { - return HISI_TEMP_BASE + (step * HISI_TEMP_STEP); + return HI6220_TEMP_BASE + (step * HI6220_TEMP_STEP); } -static inline int hisi_thermal_temp_to_step(int temp) +static inline int hi6220_thermal_temp_to_step(int temp) { - return DIV_ROUND_UP(temp - HISI_TEMP_BASE, HISI_TEMP_STEP); + return DIV_ROUND_UP(temp - HI6220_TEMP_BASE, HI6220_TEMP_STEP); } /* @@ -112,51 +111,53 @@ static inline int hisi_thermal_temp_to_step(int temp) * * [0:4] : lag register * - * The temperature is coded in steps, cf. HISI_TEMP_STEP. + * The temperature is coded in steps, cf. HI6220_TEMP_STEP. * * Min : 0x00 : 0.0 °C * Max : 0x1F : 24.3 °C * * The 'value' parameter is in milliCelsius. */ -static inline void hisi_thermal_set_lag(void __iomem *addr, int value) +static inline void hi6220_thermal_set_lag(void __iomem *addr, int value) { - writel(DIV_ROUND_UP(value, HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG); + writel(DIV_ROUND_UP(value, HI6220_TEMP_STEP) & 0x1F, + addr + HI6220_TEMP0_LAG); } -static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) +static inline void hi6220_thermal_alarm_clear(void __iomem *addr, int value) { - writel(value, addr + TEMP0_INT_CLR); + writel(value, addr + HI6220_TEMP0_INT_CLR); } -static inline void hisi_thermal_alarm_enable(void __iomem *addr, int value) +static inline void hi6220_thermal_alarm_enable(void __iomem *addr, int value) { - writel(value, addr + TEMP0_INT_EN); + writel(value, addr + HI6220_TEMP0_INT_EN); } -static inline void hisi_thermal_alarm_set(void __iomem *addr, int temp) +static inline void hi6220_thermal_alarm_set(void __iomem *addr, int temp) { - writel(hisi_thermal_temp_to_step(temp) | 0x0FFFFFF00, addr + TEMP0_TH); + writel(hi6220_thermal_temp_to_step(temp) | 0x0FFFFFF00, + addr + HI6220_TEMP0_TH); } -static inline void hisi_thermal_reset_set(void __iomem *addr, int temp) +static inline void hi6220_thermal_reset_set(void __iomem *addr, int temp) { - writel(hisi_thermal_temp_to_step(temp), addr + TEMP0_RST_TH); + writel(hi6220_thermal_temp_to_step(temp), addr + HI6220_TEMP0_RST_TH); } -static inline void hisi_thermal_reset_enable(void __iomem *addr, int value) +static inline void hi6220_thermal_reset_enable(void __iomem *addr, int value) { - writel(value, addr + TEMP0_RST_MSK); + writel(value, addr + HI6220_TEMP0_RST_MSK); } -static inline void hisi_thermal_enable(void __iomem *addr, int value) +static inline void hi6220_thermal_enable(void __iomem *addr, int value) { - writel(value, addr + TEMP0_EN); + writel(value, addr + HI6220_TEMP0_EN); } -static inline int hisi_thermal_get_temperature(void __iomem *addr) +static inline int hi6220_thermal_get_temperature(void __iomem *addr) { - return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); + return hi6220_thermal_step_to_temp(readl(addr + HI6220_TEMP0_VALUE)); } /* @@ -169,10 +170,10 @@ static inline int hisi_thermal_get_temperature(void __iomem *addr) * 0x2: remote sensor 2 (ACPU cluster 0) * 0x3: remote sensor 3 (G3D) */ -static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) +static inline void hi6220_thermal_sensor_select(void __iomem *addr, int sensor) { - writel((readl(addr + TEMP0_CFG) & ~TEMP0_CFG_SS_MSK ) | - (sensor << 12), addr + TEMP0_CFG); + writel((readl(addr + HI6220_TEMP0_CFG) & ~HI6220_TEMP0_CFG_SS_MSK) | + (sensor << 12), addr + HI6220_TEMP0_CFG); } /* @@ -185,24 +186,24 @@ static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) * 0x2 : 49.152 ms * 0x3 : 393.216 ms */ -static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) +static inline void hi6220_thermal_hdak_set(void __iomem *addr, int value) { - writel((readl(addr + TEMP0_CFG) & ~TEMP0_CFG_HDAK_MSK) | - (value << 4), addr + TEMP0_CFG); + writel((readl(addr + HI6220_TEMP0_CFG) & ~HI6220_TEMP0_CFG_HDAK_MSK) | + (value << 4), addr + HI6220_TEMP0_CFG); } -static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) +static void hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) { /* disable sensor module */ - hisi_thermal_enable(data->regs, 0); - hisi_thermal_alarm_enable(data->regs, 0); - hisi_thermal_reset_enable(data->regs, 0); + hi6220_thermal_enable(data->regs, 0); + hi6220_thermal_alarm_enable(data->regs, 0); + hi6220_thermal_reset_enable(data->regs, 0); clk_disable_unprepare(data->clk); } -static int hisi_thermal_setup(struct hisi_thermal_data *data) +static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) { struct hisi_thermal_sensor *sensor = &data->sensor; int ret; @@ -213,29 +214,29 @@ static int hisi_thermal_setup(struct hisi_thermal_data *data) return ret; /* disable module firstly */ - hisi_thermal_reset_enable(data->regs, 0); - hisi_thermal_enable(data->regs, 0); + hi6220_thermal_reset_enable(data->regs, 0); + hi6220_thermal_enable(data->regs, 0); /* select sensor id */ - hisi_thermal_sensor_select(data->regs, sensor->id); + hi6220_thermal_sensor_select(data->regs, sensor->id); /* setting the hdak time */ - hisi_thermal_hdak_set(data->regs, 0); + hi6220_thermal_hdak_set(data->regs, 0); /* setting lag value between current temp and the threshold */ - hisi_thermal_set_lag(data->regs, HISI_TEMP_LAG); + hi6220_thermal_set_lag(data->regs, HI6220_TEMP_LAG); /* enable for interrupt */ - hisi_thermal_alarm_set(data->regs, sensor->thres_temp); + hi6220_thermal_alarm_set(data->regs, sensor->thres_temp); - hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); + hi6220_thermal_reset_set(data->regs, HI6220_TEMP_RESET); /* enable module */ - hisi_thermal_reset_enable(data->regs, 1); - hisi_thermal_enable(data->regs, 1); + hi6220_thermal_reset_enable(data->regs, 1); + hi6220_thermal_enable(data->regs, 1); - hisi_thermal_alarm_clear(data->regs, 0); - hisi_thermal_alarm_enable(data->regs, 1); + hi6220_thermal_alarm_clear(data->regs, 0); + hi6220_thermal_alarm_enable(data->regs, 1); return 0; } @@ -244,7 +245,7 @@ static int hisi_thermal_get_temp(void *__data, int *temp) struct hisi_thermal_data *data = __data; struct hisi_thermal_sensor *sensor = &data->sensor; - *temp = hisi_thermal_get_temperature(data->regs); + *temp = hi6220_thermal_get_temperature(data->regs); dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", sensor->id, *temp, sensor->thres_temp); @@ -260,11 +261,11 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) { struct hisi_thermal_data *data = dev; struct hisi_thermal_sensor *sensor = &data->sensor; - int temp; + int temp = 0; - hisi_thermal_alarm_clear(data->regs, 1); + hi6220_thermal_alarm_clear(data->regs, 1); - temp = hisi_thermal_get_temperature(data->regs); + hisi_thermal_get_temp(data, &temp); if (temp >= sensor->thres_temp) { dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", @@ -273,7 +274,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) thermal_zone_device_update(data->sensor.tzd, THERMAL_EVENT_UNSPECIFIED); - } else if (temp < sensor->thres_temp) { + } else { dev_crit(&data->pdev->dev, "THERMAL ALARM stopped: %d < %d\n", temp, sensor->thres_temp); } @@ -365,14 +366,14 @@ static int hisi_thermal_probe(struct platform_device *pdev) ret = hisi_thermal_register_sensor(pdev, data, &data->sensor, - HISI_DEFAULT_SENSOR); + HI6220_DEFAULT_SENSOR); if (ret) { dev_err(&pdev->dev, "failed to register thermal sensor: %d\n", ret); return ret; } - ret = hisi_thermal_setup(data); + ret = hi6220_thermal_enable_sensor(data); if (ret) { dev_err(&pdev->dev, "Failed to setup the sensor: %d\n", ret); return ret; @@ -397,7 +398,7 @@ static int hisi_thermal_remove(struct platform_device *pdev) struct hisi_thermal_sensor *sensor = &data->sensor; hisi_thermal_toggle_sensor(sensor, false); - hisi_thermal_disable_sensor(data); + hi6220_thermal_disable_sensor(data); return 0; } @@ -407,7 +408,7 @@ static int hisi_thermal_suspend(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); - hisi_thermal_disable_sensor(data); + hi6220_thermal_disable_sensor(data); return 0; } @@ -416,7 +417,7 @@ static int hisi_thermal_resume(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); - return hisi_thermal_setup(data); + return hi6220_thermal_enable_sensor(data); } #endif From patchwork Tue Oct 10 18:02:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115431 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4039936qgn; Tue, 10 Oct 2017 11:06:00 -0700 (PDT) X-Received: by 10.98.68.133 with SMTP id m5mr14503678pfi.202.1507658760793; Tue, 10 Oct 2017 11:06:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658760; cv=none; d=google.com; s=arc-20160816; b=CCTc6a2a+pAQf8G60E3lUkIXjxjCOiqMjKmmECmd2qWt1NjoNUzrRyu31dQ+jo3nO+ 2KaM/Nv4zFulRI4yEMBPgKBUKkNFKmaew41kNt1x4qUnl0jrMzpA5bvHcU/MYWR+c2yT 3yMLi5pleXdk9nR2DgVvIBl4ob67VHROMIE7cVjXNwjNCcCznjQZDvWTxjmbh5jbqIj3 mXRmkpnFzRofeI+8GPAJd7VHQQmWdfFIWLx/qLakzCJBMlArT/0Uu/jCI5fg20YcwBTO joW2iUvhu2cOvC590ToB7Sk5Cnc4HdUdLGSEVGKTLfY0WSNwkkydaRUm3NacAwrW1+Hu vflA== 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=bd1RHNVPGlyQuynHVl3wHtCx5hjaCplfcoE6s+pCDAU=; b=Fs7eFjwSn4AfO9nU03EVbjiNtyBA9arIgtmK3Hn5A6CnV1P71O58zcKXtMs8lVGtQM SiALAfzP3M7n8g38c/mYZnqDVMN2STMQWbeqscQsnf9H1jj08Xmge3Xt1vmfs3mUgIKu 3EsSEZXOk+7LVtUs/cpnSEnWO55bUrKLUAGe03OyYBJ/q+PN6KOIWouKJqHTVFuqC5U5 BuRyZlC+8E6kYpOvuTe7QZap9qD04jfJxbkSVQjz1/rpcfViKn7+jPOQGRpKv+rlZ11x 8jNqKhJRbecVw8zLvgAdi2e30LLHzTCkaJkrn/UYGl7X6V7Lv9tbcHd1W7T1zki7uuH+ yayA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AvZ1q6GD; 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 m1si1401557pgq.230.2017.10.10.11.06.00; Tue, 10 Oct 2017 11:06:00 -0700 (PDT) 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=AvZ1q6GD; 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 S932709AbdJJSF0 (ORCPT + 26 others); Tue, 10 Oct 2017 14:05:26 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:57303 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932682AbdJJSFV (ORCPT ); Tue, 10 Oct 2017 14:05:21 -0400 Received: by mail-wm0-f53.google.com with SMTP id l68so7686685wmd.5 for ; Tue, 10 Oct 2017 11:05:21 -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=bd1RHNVPGlyQuynHVl3wHtCx5hjaCplfcoE6s+pCDAU=; b=AvZ1q6GDAmnm0VGGfSsV3D0hBeV92X4a7K0VfjieEUZL3kmdY1qRuQw/98JAUY+Jel z/D4ZTR0S8mUVTe6cFVHYrMlFr6PNRvQfMb9j1Uu1vZzkwdarnadgFn8X4MXqRhJOUyc hhTTH2fOodiDe/3ftVKGn/0wW7iNoabA+bzNw= 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=bd1RHNVPGlyQuynHVl3wHtCx5hjaCplfcoE6s+pCDAU=; b=pN9z4E89yCVUPOwfswYto0YVf4MRXnaphql0VRO1NvpMPDYS3lGR/NyE4oaVxvd4Sr pKfeq4yRi4RtF/rlgXVn+epWemPbDeSWQqxw+HYsX82U+agKxQ9ug7WktVu9zPD8dkZL YFWcatDI0voEPFsPAEj13+9UTRApnOzLgh8NYKGtMlKCduBol8fojcbGNHNpaD4WQDgG YLLBdsd82J6HZxoemKQC2Dv63HbNpT2LMC85G8z3O1ogC55V3dW7flI3zPIR++QrtGwu CWuTsXof8jREe0x5UWLjMXliCVNW0+MM6CwZxo1RwjPotSEAHFKFHnojHhuC9HsP58GR ebAw== X-Gm-Message-State: AMCzsaUEWx+f5refdPu8oDUZz22lu9eEuHUtF0QrgVUsZEQaPUCd7F4i dDlZqlzVVt/X2o9ka6HK3mO2Lg== X-Google-Smtp-Source: AOwi7QBKXnVtb1US/dcWa53NEBXJhbOJGcWT8RiKPyU4HHq6o9vi1xhzyrIQn8sOq58BMHWzFPEQ8A== X-Received: by 10.28.100.212 with SMTP id y203mr12255113wmb.64.1507658720322; Tue, 10 Oct 2017 11:05:20 -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.05.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:19 -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 21/25] thermal/drivers/hisi: Prepare to add support for other hisi platforms Date: Tue, 10 Oct 2017 20:02:46 +0200 Message-Id: <1507658570-32675-21-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Wangtao For platform compatibility, add the tsensor ops to a thermal data structure. Each platform has its own probe function to register proper tsensor ops function to the pointer, platform related resource request are also implemented in the platform probe function. Signed-off-by: Kevin Wangtao Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 135 +++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 46 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 8a70ab7..b5a7159 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "thermal_core.h" @@ -30,7 +31,7 @@ #define HI6220_TEMP0_TH (0x4) #define HI6220_TEMP0_RST_TH (0x8) #define HI6220_TEMP0_CFG (0xC) -#define HI6220_TEMP0_CFG_SS_MSK (0xF000) +#define HI6220_TEMP0_CFG_SS_MSK (0xF000) #define HI6220_TEMP0_CFG_HDAK_MSK (0x30) #define HI6220_TEMP0_EN (0x10) #define HI6220_TEMP0_INT_EN (0x14) @@ -41,7 +42,7 @@ #define HI6220_TEMP_BASE (-60000) #define HI6220_TEMP_RESET (100000) #define HI6220_TEMP_STEP (785) -#define HI6220_TEMP_LAG (3500) +#define HI6220_TEMP_LAG (3500) #define HI6220_DEFAULT_SENSOR 2 @@ -52,6 +53,10 @@ struct hisi_thermal_sensor { }; struct hisi_thermal_data { + int (*get_temp)(struct hisi_thermal_data *data); + int (*enable_sensor)(struct hisi_thermal_data *data); + int (*disable_sensor)(struct hisi_thermal_data *data); + int (*irq_handler)(struct hisi_thermal_data *data); struct platform_device *pdev; struct clk *clk; struct hisi_thermal_sensor sensor; @@ -59,6 +64,7 @@ struct hisi_thermal_data { int irq; }; + /* * The temperature computation on the tsensor is as follow: * Unit: millidegree Celsius @@ -192,7 +198,18 @@ static inline void hi6220_thermal_hdak_set(void __iomem *addr, int value) (value << 4), addr + HI6220_TEMP0_CFG); } -static void hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) +static int hi6220_thermal_irq_handler(struct hisi_thermal_data *data) +{ + hi6220_thermal_alarm_clear(data->regs, 1); + return 0; +} + +static int hi6220_thermal_get_temp(struct hisi_thermal_data *data) +{ + return hi6220_thermal_get_temperature(data->regs); +} + +static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) { /* disable sensor module */ hi6220_thermal_enable(data->regs, 0); @@ -200,9 +217,9 @@ static void hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) hi6220_thermal_reset_enable(data->regs, 0); clk_disable_unprepare(data->clk); + return 0; } - static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) { struct hisi_thermal_sensor *sensor = &data->sensor; @@ -240,12 +257,50 @@ static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) return 0; } + +static int hi6220_thermal_probe(struct hisi_thermal_data *data) +{ + struct platform_device *pdev = data->pdev; + struct device *dev = &pdev->dev; + struct resource *res; + int ret; + + data->get_temp = hi6220_thermal_get_temp; + data->enable_sensor = hi6220_thermal_enable_sensor; + data->disable_sensor = hi6220_thermal_disable_sensor; + data->irq_handler = hi6220_thermal_irq_handler; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + data->regs = devm_ioremap_resource(dev, res); + if (IS_ERR(data->regs)) { + dev_err(dev, "failed to get io address\n"); + return PTR_ERR(data->regs); + } + + data->clk = devm_clk_get(dev, "thermal_clk"); + if (IS_ERR(data->clk)) { + ret = PTR_ERR(data->clk); + if (ret != -EPROBE_DEFER) + dev_err(dev, "failed to get thermal clk: %d\n", ret); + return ret; + } + + data->irq = platform_get_irq(pdev, 0); + if (data->irq < 0) + return data->irq; + + data->sensor.id = HI6220_DEFAULT_SENSOR; + + return 0; +} + + static int hisi_thermal_get_temp(void *__data, int *temp) { struct hisi_thermal_data *data = __data; struct hisi_thermal_sensor *sensor = &data->sensor; - *temp = hi6220_thermal_get_temperature(data->regs); + *temp = data->get_temp(data); dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", sensor->id, *temp, sensor->thres_temp); @@ -263,7 +318,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) struct hisi_thermal_sensor *sensor = &data->sensor; int temp = 0; - hi6220_thermal_alarm_clear(data->regs, 1); + data->irq_handler(data); hisi_thermal_get_temp(data, &temp); @@ -284,14 +339,11 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) static int hisi_thermal_register_sensor(struct platform_device *pdev, struct hisi_thermal_data *data, - struct hisi_thermal_sensor *sensor, - int index) + struct hisi_thermal_sensor *sensor) { int ret, i; const struct thermal_trip *trip; - sensor->id = index; - sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, sensor->id, data, &hisi_of_thermal_ops); @@ -316,7 +368,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, } static const struct of_device_id of_hisi_thermal_match[] = { - { .compatible = "hisilicon,tsensor" }, + { .compatible = "hisilicon,tsensor", .data = hi6220_thermal_probe }, { /* end */ } }; MODULE_DEVICE_TABLE(of, of_hisi_thermal_match); @@ -333,58 +385,48 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, static int hisi_thermal_probe(struct platform_device *pdev) { struct hisi_thermal_data *data; - struct resource *res; + int (*platform_probe)(struct hisi_thermal_data *); + struct device *dev = &pdev->dev; int ret; - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; data->pdev = pdev; + platform_set_drvdata(pdev, data); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - data->regs = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(data->regs)) { - dev_err(&pdev->dev, "failed to get io address\n"); - return PTR_ERR(data->regs); + platform_probe = of_device_get_match_data(dev); + if (!platform_probe) { + dev_err(dev, "failed to get probe func\n"); + return -EINVAL; } - data->irq = platform_get_irq(pdev, 0); - if (data->irq < 0) - return data->irq; - - platform_set_drvdata(pdev, data); - - data->clk = devm_clk_get(&pdev->dev, "thermal_clk"); - if (IS_ERR(data->clk)) { - ret = PTR_ERR(data->clk); - if (ret != -EPROBE_DEFER) - dev_err(&pdev->dev, - "failed to get thermal clk: %d\n", ret); + ret = platform_probe(data); + if (ret) return ret; - } ret = hisi_thermal_register_sensor(pdev, data, - &data->sensor, - HI6220_DEFAULT_SENSOR); + &data->sensor); if (ret) { - dev_err(&pdev->dev, "failed to register thermal sensor: %d\n", - ret); + dev_err(dev, "failed to register thermal sensor: %d\n", ret); return ret; } - ret = hi6220_thermal_enable_sensor(data); + ret = data->enable_sensor(data); if (ret) { - dev_err(&pdev->dev, "Failed to setup the sensor: %d\n", ret); + dev_err(dev, "Failed to setup the sensor: %d\n", ret); return ret; } - ret = devm_request_threaded_irq(&pdev->dev, data->irq, NULL, - hisi_thermal_alarm_irq_thread, - IRQF_ONESHOT, "hisi_thermal", data); - if (ret < 0) { - dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); - return ret; + if (data->irq) { + ret = devm_request_threaded_irq(dev, data->irq, NULL, + hisi_thermal_alarm_irq_thread, + IRQF_ONESHOT, "hisi_thermal", data); + if (ret < 0) { + dev_err(dev, "failed to request alarm irq: %d\n", ret); + return ret; + } } hisi_thermal_toggle_sensor(&data->sensor, true); @@ -398,7 +440,8 @@ static int hisi_thermal_remove(struct platform_device *pdev) struct hisi_thermal_sensor *sensor = &data->sensor; hisi_thermal_toggle_sensor(sensor, false); - hi6220_thermal_disable_sensor(data); + + data->disable_sensor(data); return 0; } @@ -408,7 +451,7 @@ static int hisi_thermal_suspend(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); - hi6220_thermal_disable_sensor(data); + data->disable_sensor(data); return 0; } @@ -417,7 +460,7 @@ static int hisi_thermal_resume(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); - return hi6220_thermal_enable_sensor(data); + return data->enable_sensor(data); } #endif From patchwork Tue Oct 10 18:02:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115429 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4039370qgn; Tue, 10 Oct 2017 11:05:29 -0700 (PDT) X-Received: by 10.101.72.132 with SMTP id n4mr5977689pgs.245.1507658728964; Tue, 10 Oct 2017 11:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658728; cv=none; d=google.com; s=arc-20160816; b=YFdamOKP2IQisji6XdPymLcdM6JqXvffQv4vAdsE1yjQ2C3TuKvunSyqmmZM31Nkv3 zd+3LGt3DKmOt8cEvU4sF4NpRVRc/Dojvu3iLV9lvqohvodulXW4JbhJKblXhK/BXXZw vjfWjnqazzMna5mcNSNZUxtPhCMsjON/2VwCzM1nDh8z8az5fAqW4n8lUyEJzI8PHdrj RkKZ+fgbPPniOQ5P55eN17BoEBjedi2Zfe017fUbSe6GaDwtsvgCVKVuaYGDPIQZ2VsM w95Ir9x8Q667APIUod6EUcAHYLwJjXOjnK6sbXT4+h1Vw4ke50a1SJ51O12EYuNG7L8X 8vQw== 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=VNfithlJaR7JHlG4OPXBnwSU7MRKMhDCwL88J7IUMVQ=; b=VVxlewXXntyicLtNQtRyLWl0alMQMBH4NmCcP4zwJ0whk/y0yqOEI/D8kNlaKaOvK7 YGOjanZ7kJlmYW19e1sLPCRXqxWkxqXey7I7sMdz3OEDqfZBDEzgyBaXtucoUFsfl2gt FShrIH8288Zv+glQhC5bm3H30hwW95nVxtaEGCsmesUytYPf1i7uAWmBut5PfBvNUo1o aHVxq3UmD9fxj8R2Ai5AcAXoRBgPmtBAUBVLY5VHnSWcXOyJnjwR5HvzPF+7Q/VWEcp1 FLaai80v0leO7Yt9WiPIXSYcQ5Uaq7YkCrH99Im0S9H/f6gnbbtJgjK7M/6wjH0+6+5i rheg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yohx14x/; 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 s4si8828206plp.584.2017.10.10.11.05.28; Tue, 10 Oct 2017 11:05:28 -0700 (PDT) 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=Yohx14x/; 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 S932728AbdJJSF1 (ORCPT + 26 others); Tue, 10 Oct 2017 14:05:27 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:54110 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932689AbdJJSFX (ORCPT ); Tue, 10 Oct 2017 14:05:23 -0400 Received: by mail-wm0-f47.google.com with SMTP id q132so7698575wmd.2 for ; Tue, 10 Oct 2017 11:05:22 -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=VNfithlJaR7JHlG4OPXBnwSU7MRKMhDCwL88J7IUMVQ=; b=Yohx14x/r/D7VrtTKJtbceUyy54rKzOoQg6wrwZJH8cOGqRg6r/ZI8XM2VBNXG5L5O E94wpPJ3GrjBjvBrmWeHlCoKQy/mN7PEcV0BaGP36acuF/7yOO+lFPQ29jbBs+9NTWHe cW1h0fNJk3lt94OYZ2f0ZjziiirtUcG5sYrOo= 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=VNfithlJaR7JHlG4OPXBnwSU7MRKMhDCwL88J7IUMVQ=; b=sqQCBF6myHh5w7ri86hfGWsPZJQnggaR5XFPdIEh1m4+fPv1jT6QvZ1YPysM65rmcu +1fmFT836M13Y2Mb3D3bK7yloDWHvGwfArF3oTIB46QxvBbF+cpRVBytm8G9fJJ6T9j8 aIMiuARFqBqJ+5r1qfDpUvLqqXFjUvH1CmEQ+1uvlzIuD66hJ3VUGxfpDlel/8fI1BaG DFDdz6hAXrBq6WQDoADNGp8eyf4AYkT1k02X6xjLVi/76A+vtzpEAS5wwbisbvoKbSXM cno4WluM4VJBdfhceI65wNRvsG1E2xJGHpDS68iL4P6jlBvdcIdT/mQBhylEv+Nypu+A cVKA== X-Gm-Message-State: AMCzsaX6xzTo5Mus/kg37h8Q1czkMNqmbgbV0uJHgg4rCyJBN+GvrTHM /q8t5WMoHNqjY2dfdsJy99/2hw== X-Google-Smtp-Source: AOwi7QAdWjoyEAVbgXwVYFy+HTbc2csVngQc4tI4gYMioQFIY1fTEER1kF/mw/VFWKjcRdw2Irg0GA== X-Received: by 10.28.36.212 with SMTP id k203mr10565455wmk.127.1507658721816; Tue, 10 Oct 2017 11:05:21 -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.05.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:21 -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 22/25] thermal/drivers/hisi: Add support for multi temp threshold Date: Tue, 10 Oct 2017 20:02:47 +0200 Message-Id: <1507658570-32675-22-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Wangtao The next patches will provide the support for the hi3660 where the temperature sensor can have multiple alarm levels. In order to set the scene to support it, we have to convert the current code to be able to support multiple threshold values. [Daniel Lezcano: Restated the log] Signed-off-by: Kevin Wangtao Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index b5a7159..e87ca6c 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -46,10 +46,12 @@ #define HI6220_DEFAULT_SENSOR 2 +#define MAX_THRES_NUM 2 + struct hisi_thermal_sensor { struct thermal_zone_device *tzd; uint32_t id; - uint32_t thres_temp; + uint32_t thres_temp[MAX_THRES_NUM]; }; struct hisi_thermal_data { @@ -244,7 +246,7 @@ static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) hi6220_thermal_set_lag(data->regs, HI6220_TEMP_LAG); /* enable for interrupt */ - hi6220_thermal_alarm_set(data->regs, sensor->thres_temp); + hi6220_thermal_alarm_set(data->regs, sensor->thres_temp[0]); hi6220_thermal_reset_set(data->regs, HI6220_TEMP_RESET); @@ -303,7 +305,7 @@ static int hisi_thermal_get_temp(void *__data, int *temp) *temp = data->get_temp(data); dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", - sensor->id, *temp, sensor->thres_temp); + sensor->id, *temp, sensor->thres_temp[0]); return 0; } @@ -322,16 +324,16 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) hisi_thermal_get_temp(data, &temp); - if (temp >= sensor->thres_temp) { + if (temp >= sensor->thres_temp[0]) { dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", - temp, sensor->thres_temp); + temp, sensor->thres_temp[0]); thermal_zone_device_update(data->sensor.tzd, THERMAL_EVENT_UNSPECIFIED); } else { dev_crit(&data->pdev->dev, "THERMAL ALARM stopped: %d < %d\n", - temp, sensor->thres_temp); + temp, sensor->thres_temp[0]); } return IRQ_HANDLED; @@ -341,7 +343,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor) { - int ret, i; + int ret, i, thres_idx = 0; const struct thermal_trip *trip; sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, @@ -359,8 +361,9 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) { if (trip[i].type == THERMAL_TRIP_PASSIVE) { - sensor->thres_temp = trip[i].temperature; - break; + sensor->thres_temp[thres_idx++] = trip[i].temperature; + if (thres_idx >= MAX_THRES_NUM) + break; } } From patchwork Tue Oct 10 18:02:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115432 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4040004qgn; Tue, 10 Oct 2017 11:06:04 -0700 (PDT) X-Received: by 10.99.97.149 with SMTP id v143mr13382649pgb.413.1507658764328; Tue, 10 Oct 2017 11:06:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658764; cv=none; d=google.com; s=arc-20160816; b=R3OgweEOOFE0YsxvQqLoY2nyXjIXnjuHx/qTuHPi1tC7WH7LMLX7ihO3bXjgzo11O8 6JqJDcYcpSNRZ5bR6NdJpDpTEXlt5PVS4iQaiYFyrkk184uQ4v6MvW/14Wj40uQF861/ zBKo4l5K176Q1EL58oUpBZyoTGZAKYFEXXjLoQLauMFxwLlh8dUGnHYNMfXip8tbh6wS LcXHEFZKKMBUzXzMainGSYsUWEj4DdwYkRcnps8h5WJeGwfuNFjTIXbZ/gMXFPZvbWfx 2SCsTLdubCPZtYthTzHBG9FUqdioOeWc03TRgcjcimm7f/Yx9GRI62W2/PWOGu5ZI9Ui Fw5g== 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:arc-authentication-results; bh=J4tgdYdChDOIE8BSH2Zh0Ln13OVM2CbDsw5g9aVP6rA=; b=oq02P8vMgSZZ3PkXqftgX9t1Lu/F1U4mdmZYchHFy15k4EKo3R7rf3wpcag5nEPVsj MGDHns7i0+K+BWJLOjx3+TuOr6OiwHCwQh1qcss3pSvesbw1vCInt4X72/BgpAyK1kOs ByHuHQAeHHcU7j4q70F+EhVjHlwk8YLPz2BrS84R0hZBviiNeiC7EvX1wR+YySeQen4Y Q7nCHIm0ch55+Xmi+s4UNRKQYbqQBeKCyy/a+93VvVD6rmXEBrHF6XoxhlLXMwmEoq05 sphbbiLQy/pVSf5orA2oXmqnUsBDHV0vzPrJ2W1wy8x7q4Jw+wjrSoqtbFyoJhuZxOqy gF6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QDDNTsSZ; 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 m1si1401557pgq.230.2017.10.10.11.06.04; Tue, 10 Oct 2017 11:06:04 -0700 (PDT) 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=QDDNTsSZ; 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 S1756528AbdJJSGB (ORCPT + 26 others); Tue, 10 Oct 2017 14:06:01 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:50853 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932702AbdJJSF0 (ORCPT ); Tue, 10 Oct 2017 14:05:26 -0400 Received: by mail-wm0-f54.google.com with SMTP id u138so7495007wmu.5 for ; Tue, 10 Oct 2017 11:05:25 -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 :mime-version:content-transfer-encoding; bh=J4tgdYdChDOIE8BSH2Zh0Ln13OVM2CbDsw5g9aVP6rA=; b=QDDNTsSZCjoLTgosAZswMcPwzC6BlCTOZOUwFL9FGyMotsXr3RLfQdC13wHqmcjuK+ Ssfk1yt3Gt4QIQZIhHMTITqtBLeXJ6whU2Prw8UoKXM4w03jyQhl/vbsPll+4E4c+/Tu 6OHdE/JNCQ58DnxQZ2r3TBJZiF2CR4DL1CQKM= 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=J4tgdYdChDOIE8BSH2Zh0Ln13OVM2CbDsw5g9aVP6rA=; b=Q+VPULWgnQx0CziPMzBaYcsr33BuOpMlIOdAeiCbVyywcvDbq/SYvny4x4aNTVXaWH jOgLBK/YMuv0XzB9uJa67LZU5v1P5WdCb5R6J5PKAN9WP4LRnmtxhaEhZp2eI385DKoL 2+i3waVLLJ2f5ZylWcLw7hNRhs31egbez7Tw0TpuozcmzI53ZUzJ8Tqj5XTeuvqNyJbw 1gOZXE+b6ktQ3JRjNuqEFRiVXxTaa/B9JRo7EVjlHUAOGGPoFKY7K6eb6FEalzkyVO8v cPMI/Kq09s2ir4UNEfcGZBYWxD+WIWqLBl6hsw4NMg2IfbkzgnSlvRkdW2YBTPJr9RVO WqAg== X-Gm-Message-State: AMCzsaVVlKwGftBc7w6NC9copZdyBdceZDw53bzk//isJfBX7977sh4+ DXAnPX2/l+OU4Y3Ogvg6jGISBg== X-Google-Smtp-Source: AOwi7QD7B8LmUlbRK7uf+LvTbXq+bnUXGibf6XnsB+BeihMYKhOMK205DG7brkDhu8XMN2VsbYLOJw== X-Received: by 10.28.52.5 with SMTP id b5mr13036338wma.135.1507658724905; Tue, 10 Oct 2017 11:05:24 -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.05.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:24 -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 24/25] thermal/drivers/hisi: Add support for hi3660 SoC Date: Tue, 10 Oct 2017 20:02:49 +0200 Message-Id: <1507658570-32675-24-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> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Wangtao This patch adds the support for thermal sensor on the Hi3660 SoC. Hi3660 tsensor support alarm interrupt and have three configurable alarm thresholds, it also has a configurable hysteresis interval, interrupt will be triggered when temperature rise above the alarm threshold or fall below the hysteresis threshold. Signed-off-by: Kevin Wangtao Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 146 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index e87ca6c..10276f0 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -39,12 +39,24 @@ #define HI6220_TEMP0_RST_MSK (0x1C) #define HI6220_TEMP0_VALUE (0x28) +#define HI3660_OFFSET(chan) ((chan) * 0x40) +#define HI3660_TEMP(chan) (HI3660_OFFSET(chan) + 0x1C) +#define HI3660_TH(chan) (HI3660_OFFSET(chan) + 0x20) +#define HI3660_LAG(chan) (HI3660_OFFSET(chan) + 0x28) +#define HI3660_INT_EN(chan) (HI3660_OFFSET(chan) + 0x2C) +#define HI3660_INT_CLR(chan) (HI3660_OFFSET(chan) + 0x30) + #define HI6220_TEMP_BASE (-60000) #define HI6220_TEMP_RESET (100000) #define HI6220_TEMP_STEP (785) #define HI6220_TEMP_LAG (3500) +#define HI3660_TEMP_BASE (-63780) +#define HI3660_TEMP_STEP (205) +#define HI3660_TEMP_LAG (4000) + #define HI6220_DEFAULT_SENSOR 2 +#define HI3660_DEFAULT_SENSOR 1 #define MAX_THRES_NUM 2 @@ -96,6 +108,24 @@ static inline int hi6220_thermal_temp_to_step(int temp) } /* + * for Hi3660, + * Step: 189/922 (0.205) + * Temperature base: -63.780°C + * + * The register is programmed in temperature steps, every step is 205 + * millidegree and begins at -63 780 m°C + */ +static inline int hi3660_thermal_step_to_temp(int step) +{ + return HI3660_TEMP_BASE + step * HI3660_TEMP_STEP; +} + +static inline int hi3660_thermal_temp_to_step(int temp) +{ + return DIV_ROUND_UP(temp - HI3660_TEMP_BASE, HI3660_TEMP_STEP); +} + +/* * The lag register contains 5 bits encoding the temperature in steps. * * Each time the temperature crosses the threshold boundary, an @@ -169,6 +199,45 @@ static inline int hi6220_thermal_get_temperature(void __iomem *addr) } /* + * [0:6] lag register + * + * The temperature is coded in steps, cf. HI3660_TEMP_STEP. + * + * Min : 0x00 : 0.0 °C + * Max : 0x7F : 26.0 °C + * + */ +static inline void hi3660_thermal_set_lag(void __iomem *addr, + int id, int value) +{ + writel(DIV_ROUND_UP(value, HI3660_TEMP_STEP) & 0x7F, + addr + HI3660_LAG(id)); +} + +static inline void hi3660_thermal_alarm_clear(void __iomem *addr, + int id, int value) +{ + writel(value, addr + HI3660_INT_CLR(id)); +} + +static inline void hi3660_thermal_alarm_enable(void __iomem *addr, + int id, int value) +{ + writel(value, addr + HI3660_INT_EN(id)); +} + +static inline void hi3660_thermal_alarm_set(void __iomem *addr, + int id, int value) +{ + writel(value, addr + HI3660_TH(id)); +} + +static inline int hi3660_thermal_get_temperature(void __iomem *addr, int id) +{ + return hi3660_thermal_step_to_temp(readl(addr + HI3660_TEMP(id))); +} + +/* * Temperature configuration register - Sensor selection * * Bits [19:12] @@ -206,11 +275,22 @@ static int hi6220_thermal_irq_handler(struct hisi_thermal_data *data) return 0; } +static int hi3660_thermal_irq_handler(struct hisi_thermal_data *data) +{ + hi3660_thermal_alarm_clear(data->regs, data->sensor.id, 1); + return 0; +} + static int hi6220_thermal_get_temp(struct hisi_thermal_data *data) { return hi6220_thermal_get_temperature(data->regs); } +static int hi3660_thermal_get_temp(struct hisi_thermal_data *data) +{ + return hi3660_thermal_get_temperature(data->regs, data->sensor.id); +} + static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) { /* disable sensor module */ @@ -222,6 +302,13 @@ static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) return 0; } +static int hi3660_thermal_disable_sensor(struct hisi_thermal_data *data) +{ + /* disable sensor module */ + hi3660_thermal_alarm_enable(data->regs, data->sensor.id, 0); + return 0; +} + static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) { struct hisi_thermal_sensor *sensor = &data->sensor; @@ -260,6 +347,29 @@ static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) return 0; } +static int hi3660_thermal_enable_sensor(struct hisi_thermal_data *data) +{ + unsigned int value; + struct hisi_thermal_sensor *sensor = &data->sensor; + + /* disable interrupt */ + hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); + + /* setting lag value between current temp and the threshold */ + hi3660_thermal_set_lag(data->regs, sensor->id, HI3660_TEMP_LAG); + + /* set interrupt threshold */ + value = hi3660_thermal_temp_to_step(sensor->thres_temp[0]); + value |= hi3660_thermal_temp_to_step(sensor->thres_temp[1]) << 10; + hi3660_thermal_alarm_set(data->regs, sensor->id, value); + + /* enable interrupt */ + hi3660_thermal_alarm_clear(data->regs, sensor->id, 1); + hi3660_thermal_alarm_enable(data->regs, sensor->id, 1); + + return 0; +} + static int hi6220_thermal_probe(struct hisi_thermal_data *data) { struct platform_device *pdev = data->pdev; @@ -296,6 +406,33 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data) return 0; } +static int hi3660_thermal_probe(struct hisi_thermal_data *data) +{ + struct platform_device *pdev = data->pdev; + struct device *dev = &pdev->dev; + struct resource *res; + + data->get_temp = hi3660_thermal_get_temp; + data->enable_sensor = hi3660_thermal_enable_sensor; + data->disable_sensor = hi3660_thermal_disable_sensor; + data->irq_handler = hi3660_thermal_irq_handler; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + data->regs = devm_ioremap_resource(dev, res); + if (IS_ERR(data->regs)) { + dev_err(dev, "failed to get io address\n"); + return PTR_ERR(data->regs); + } + + data->irq = platform_get_irq(pdev, 0); + if (data->irq < 0) + return data->irq; + + data->sensor.id = HI3660_DEFAULT_SENSOR; + + return 0; +} + static int hisi_thermal_get_temp(void *__data, int *temp) { @@ -371,7 +508,14 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, } static const struct of_device_id of_hisi_thermal_match[] = { - { .compatible = "hisilicon,tsensor", .data = hi6220_thermal_probe }, + { + .compatible = "hisilicon,tsensor", + .data = hi6220_thermal_probe + }, + { + .compatible = "hisilicon,hi3660-tsensor", + .data = hi3660_thermal_probe + }, { /* end */ } }; MODULE_DEVICE_TABLE(of, of_hisi_thermal_match);