From patchwork Tue Mar 29 11:27:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 8685851 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C22529F44D for ; Tue, 29 Mar 2016 11:28:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3FDDD2026F for ; Tue, 29 Mar 2016 11:28:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CA412010C for ; Tue, 29 Mar 2016 11:28:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756986AbcC2L1x (ORCPT ); Tue, 29 Mar 2016 07:27:53 -0400 Received: from mail-vk0-f45.google.com ([209.85.213.45]:36426 "EHLO mail-vk0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756978AbcC2L1v (ORCPT ); Tue, 29 Mar 2016 07:27:51 -0400 Received: by mail-vk0-f45.google.com with SMTP id z68so14156160vkg.3 for ; Tue, 29 Mar 2016 04:27:51 -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=QIVw+NoKQTTaZzxTwxz4jfCxqfQOIN4fJ38iPZ3L/VM=; b=PK6vPLHcq/+nD+DYviDeBDaYrn8CYrnoK4yzD5dmXo4yZy8jdU91MkOP8KjF5AMEZA Fs5r/EZ3ykuPRVsZ7NepecjBjGMsf03E7q9b+mPWzCBwhRi5gFg9UxzGwCgmcwNJ4FAV aRDXKIMqNpGC3G9Q95PnhYVCZw0ApixnGOF8E= 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=QIVw+NoKQTTaZzxTwxz4jfCxqfQOIN4fJ38iPZ3L/VM=; b=FvY321b67nfOf287ADlyb7UL0Ha4g5ZdmVqUS6kL6nn4JDGbMz9GMjh1hTUdPEWv6A YqhQ3dBhmyoFTWVuIDNYDiCrFxUGMQTJcamjcBVZKSySrLEyQYqnGXXh6gzHwrD6aKii 5dkxlJO+BwGg+TOdKzHG6N2ECq9SKm6q6frJENiHyPSbZqFp40Mq/7B57tGi2YsoSIWY y1osgh0GkjQJw4X0REKT3jNTGV8f+ZyjTCL1PdU2T1z6OixlZoraFPI4rvfBULsWD1VO oQLIXOKf1EPwWPi3DSPDG7AUPuDsgbhu5d089SwUe6T46/cIJBDBltFRcClvkQYCcjjg h3Lw== X-Gm-Message-State: AD7BkJKlQOtGzhQ//2xRPVYbxzAPI4N7T6kM/IEX1sF/+/ULGvQLG4iJcgeWoTp/V8Q5x9QH X-Received: by 10.31.60.134 with SMTP id j128mr824612vka.43.1459250870485; Tue, 29 Mar 2016 04:27:50 -0700 (PDT) Received: from leoy-linaro.a1.60in.com ([66.155.104.79]) by smtp.gmail.com with ESMTPSA id 97sm4665954uat.9.2016.03.29.04.27.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Mar 2016 04:27:49 -0700 (PDT) From: Leo Yan To: Wei Xu , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Catalin Marinas , Will Deacon , Zhang Rui , Eduardo Valentin Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Leo Yan Subject: [PATCH v3 1/4] thermal: hisilicon: support to use any sensor Date: Tue, 29 Mar 2016 19:27:12 +0800 Message-Id: <1459250835-25561-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459250835-25561-1-git-send-email-leo.yan@linaro.org> References: <1459250835-25561-1-git-send-email-leo.yan@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 36d0729..0fed5cf 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); }