From patchwork Fri Feb 26 03:43:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 8431191 X-Patchwork-Delegate: eduardo.valentin@ti.com 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 ADAFC9F314 for ; Fri, 26 Feb 2016 03:47:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DDC9620392 for ; Fri, 26 Feb 2016 03:47:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 032942037C for ; Fri, 26 Feb 2016 03:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751554AbcBZDrJ (ORCPT ); Thu, 25 Feb 2016 22:47:09 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36504 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753325AbcBZDpy (ORCPT ); Thu, 25 Feb 2016 22:45:54 -0500 Received: by mail-pf0-f170.google.com with SMTP id e127so44425247pfe.3 for ; Thu, 25 Feb 2016 19:45:54 -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=UzG7ZxIOP8ZvjtsNI2T3HiICWA+yKUOK/0hbagWQ6ZWAywyiJMvXw/qYNcMWtPmS6j k0hFFam7MRPhah9MfAHTAU4ZDpUf6z1Eph21E3pQgB8B+SLplthow6OIqJ2JKNwXuvkx FwkulLG39AODrmCzL4CG+XN7BkumA+OXrT0fM= 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=J5uNSfWXz+PeTjTfDonj9P+npIUqJD1xJjjBhbn6e+XukavSBj8sR7UK3+JsSzLMGM qDOjKUISBCSu7hEB6ANlz0aPMKsSy2OJtFhCuqIV0C6gdaWK2L4//fsdz2ztN/+VlGdB X7s25uFteQ2t831pitAWRRMuOEs2qNvJwUirY4RNyi8IAnQjD43rN2V1IL4KhexXMr2J Jk21iT+lOtqqve2cFZk4YTvZP98SGSzHp5cXlBH6F91JNhVpV6gLLS+8McmqA+KdJsOp QVtV5j0LnvdLSb/OTQ8tBmD37NLETi6WIpOdBLkLyRmPlifSUX4EFDvCM5NmjlyJnPGK OSig== X-Gm-Message-State: AG10YOTS/eynrGLLN1vmRqyKypFN/EazYbqVYN2lZcz4v2d7MXt8HqALmwb+cP6bennsI6qs X-Received: by 10.98.73.149 with SMTP id r21mr68514843pfi.140.1456458354040; Thu, 25 Feb 2016 19:45:54 -0800 (PST) Received: from leoy-linaro.a1.60in.com (li401-178.members.linode.com. [106.187.51.178]) by smtp.gmail.com with ESMTPSA id fn3sm15295884pab.20.2016.02.25.19.45.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Feb 2016 19:45:53 -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 v2 2/5] thermal: hisilicon: support to use any sensor Date: Fri, 26 Feb 2016 11:43:44 +0800 Message-Id: <1456458227-12950-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456458227-12950-1-git-send-email-leo.yan@linaro.org> References: <1456458227-12950-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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, UNPARSEABLE_RELAY autolearn=no 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 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); }