From patchwork Sat Feb 20 15:52:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 62457 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp375222lbl; Sat, 20 Feb 2016 07:53:10 -0800 (PST) X-Received: by 10.98.93.1 with SMTP id r1mr25979490pfb.57.1455983590840; Sat, 20 Feb 2016 07:53:10 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w71si24735439pfi.110.2016.02.20.07.53.10; Sat, 20 Feb 2016 07:53:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; 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; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758560AbcBTPxE (ORCPT + 30 others); Sat, 20 Feb 2016 10:53:04 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:35664 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758061AbcBTPws (ORCPT ); Sat, 20 Feb 2016 10:52:48 -0500 Received: by mail-pf0-f175.google.com with SMTP id c10so70026019pfc.2 for ; Sat, 20 Feb 2016 07:52:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=d+AB9+icMfjFu28JQDt/iyizb/2bpj9YqCmi+cUanvQ=; b=J42jdznMOut5jEtqzlilrKALxgMuesZt1LJ1SmpPph0HzfBD5XcqMvlbi0YZJQagLk 0+byswd7y37//K/LngdMhivBqZ95hMVxae3H+89aBmnnZfSXoqrUG2vElonKm+E2ybgp SlsW/J9eDURtuKCQ5u2EGNE2021+CDNunTOL0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=d+AB9+icMfjFu28JQDt/iyizb/2bpj9YqCmi+cUanvQ=; b=SbSrCF/THGoGd+8F0IFNwF+1g/GdYDWHuFFAOl53/wnvFK3ZLAP9Sm2gboJklb1u4N YqF6hSag3bHlZT56UX2pxIKbUmFvZdMA4NAiOEznaAOS1cg/3PLRn8aNKsJKT7ccSn60 Cv2XSJORZfZnTNaafMqYNSWnShCrstmeAD0TZ1kGHL7dgBMg6vaPIUOVGDf6rjQF6t83 1RYAaMfe+6GSI0BAYWRKQT/gwKBB3WAvCjPnAMbHM4NL51SOlCgwJGjH70VqY75Z6DjR 4sIrxD4CH9fFJuZoHCW91yjCSbSB+5TtO2dUHf0kPVr85+1K0wt9BIsL4sGJyQN/ODd7 CsRg== X-Gm-Message-State: AG10YOTAuTKBh3Pd+uxbEgUHw21QruYFO1QPMz8saHo1XBGqr5E3fmoZSL+UhhYW31nlDeSb X-Received: by 10.98.68.194 with SMTP id m63mr26053619pfi.153.1455983566094; Sat, 20 Feb 2016 07:52:46 -0800 (PST) Received: from localhost.localdomain (v17.blockcn.net. [192.241.236.26]) by smtp.gmail.com with ESMTPSA id n28sm17081299pfa.45.2016.02.20.07.52.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 20 Feb 2016 07:52:44 -0800 (PST) From: Leo Yan To: Wei Xu , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Catalin Marinas , Will Deacon , Zhang Rui , Eduardo Valentin , kongxinwei , Javi Merino , Punit Agrawal Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Leo Yan Subject: [PATCH 1/3] thermal: hisilicon: support to use any sensor Date: Sat, 20 Feb 2016 23:52:07 +0800 Message-Id: <1455983529-9559-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455983529-9559-1-git-send-email-leo.yan@linaro.org> References: <1455983529-9559-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In current code sensor driver registers all 4 sensors together and if any of them has not bound to thermal zone successfully then driver will return failure for driver's initialization. As a result, if DT binds thermal zone with only one sensor, then the thermal driver will not work well anymore. So this patch is to fix this issue. It allows the thermal sensor driver can register any number sensors at initialization phase, and fix up code for other related code to skip related sensor's accessing if the sensor has not been enabled in initialization phase. Signed-off-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) -- 1.9.1 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 5e820b5..7a3e5d8 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -160,7 +160,7 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp) struct hisi_thermal_sensor *sensor = _sensor; struct hisi_thermal_data *data = sensor->thermal; - int sensor_id = 0, i; + int sensor_id = -1, i; long max_temp = 0; *temp = hisi_thermal_get_sensor_temp(data, sensor); @@ -168,12 +168,19 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp) sensor->sensor_temp = *temp; for (i = 0; i < HISI_MAX_SENSORS; i++) { + if (!data->sensors[i].tzd) + continue; + if (data->sensors[i].sensor_temp >= max_temp) { max_temp = data->sensors[i].sensor_temp; sensor_id = i; } } + /* If no sensor has been enabled, then skip to enable irq */ + if (sensor_id == -1) + return 0; + mutex_lock(&data->thermal_lock); data->irq_bind_sensor = sensor_id; mutex_unlock(&data->thermal_lock); @@ -226,8 +233,12 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) sensor->thres_temp / 1000); mutex_unlock(&data->thermal_lock); - for (i = 0; i < HISI_MAX_SENSORS; i++) + for (i = 0; i < HISI_MAX_SENSORS; i++) { + if (!data->sensors[i].tzd) + continue; + thermal_zone_device_update(data->sensors[i].tzd); + } return IRQ_HANDLED; } @@ -247,6 +258,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, sensor, &hisi_of_thermal_ops); if (IS_ERR(sensor->tzd)) { ret = PTR_ERR(sensor->tzd); + sensor->tzd = NULL; dev_err(&pdev->dev, "failed to register sensor id %d: %d\n", sensor->id, ret); return ret; @@ -334,25 +346,17 @@ static int hisi_thermal_probe(struct platform_device *pdev) for (i = 0; i < HISI_MAX_SENSORS; ++i) { ret = hisi_thermal_register_sensor(pdev, data, &data->sensors[i], i); - if (ret) { + if (ret) dev_err(&pdev->dev, "failed to register thermal sensor: %d\n", ret); - goto err_get_sensor_data; - } + else + hisi_thermal_toggle_sensor(&data->sensors[i], true); } hisi_thermal_enable_bind_irq_sensor(data); data->irq_enabled = true; - for (i = 0; i < HISI_MAX_SENSORS; i++) - hisi_thermal_toggle_sensor(&data->sensors[i], true); - return 0; - -err_get_sensor_data: - clk_disable_unprepare(data->clk); - - return ret; } static int hisi_thermal_remove(struct platform_device *pdev) @@ -363,6 +367,9 @@ static int hisi_thermal_remove(struct platform_device *pdev) for (i = 0; i < HISI_MAX_SENSORS; i++) { struct hisi_thermal_sensor *sensor = &data->sensors[i]; + if (!sensor->tzd) + continue; + hisi_thermal_toggle_sensor(sensor, false); thermal_zone_of_sensor_unregister(&pdev->dev, sensor->tzd); }