From patchwork Tue Sep 26 12:52:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 114263 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3794240qgf; Tue, 26 Sep 2017 05:53:02 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBM8XsN7o7uxW6mK7nxGAjZLWepdYCHkze0czQBzXgQ0O7Z4+PCXP49qiEd2uKC9ztvaOne X-Received: by 10.98.21.150 with SMTP id 144mr10755285pfv.188.1506430382632; Tue, 26 Sep 2017 05:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506430382; cv=none; d=google.com; s=arc-20160816; b=CY4OkLyLGn8tMtt85NzVH6qqD02q231Lo1ONRsTZX6NZF1aCZeW2zZxSwjdY3j5K2C yeRwdTBR+qWOKw4xeIF7euVmJqkkff1PYZ+oJax974DXSkRY523xrdl18HjdUBfSpESE v7UxqKpFoGKIa4RksduzbIML+UsDwPxlu0jVTxa2WzQYLGgdvbLdRKHDDeBUQ4Ff9mLQ u2kFaqSaqfVikqbkSqoLhzSe+4aSz8f//VckKhAcxINBN9CRS+uDE5+Wf8+rRV1H5qfP g1Cus+PlBMObh8yY2l110xzlpSza3QNaty/1VHikVEA+Ku1tex/3eZzjw1u28IVLR+2L X4nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=w60vgkidURL4wPEr+wDA8sAitYyfvftkA68RWf2jP20=; b=J2HiqXVLd5eKWLRkiQmQ67bTqQbFPmC1KkzK9ZP7kmt3wHPS4ij0HlFpcnhXpZ2kIc F1yz/A/QRItKP+1Q7qnIdT2oHUxa7zTadi1Y0NzOr4lYOUppUPS9JtizZCRPT9lM17sr cwgUv1S6p+eh6zayBq9eZnufnGZipTEOGP1ff3gCn4JF2g2C+WnFQCYM2I009wbrJ5IQ jSBsQRIsMczsheIzymKAc6kTdOU0WMDGtVQIM8WeMyaid+D1ErZTMdeDEi/5KVczYRIM YhzPFfGIb5WNeAQbfsCYOTGE9PFUexeJ+iJrnnM2r6jJ00tIJImXOPH20Ys8WjG0+jsy 71bA== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s185si5816853pgb.399.2017.09.26.05.53.02; Tue, 26 Sep 2017 05:53:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968860AbdIZMws (ORCPT + 26 others); Tue, 26 Sep 2017 08:52:48 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:53546 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966144AbdIZMwp (ORCPT ); Tue, 26 Sep 2017 08:52:45 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 93F54208DE; Tue, 26 Sep 2017 14:52:43 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 41D212074A; Tue, 26 Sep 2017 14:52:33 +0200 (CEST) From: Quentin Schulz To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, maxime.ripard@free-electrons.com, wens@csie.org Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, thomas.petazzoni@free-electrons.com, icenowy@aosc.io, Quentin Schulz Subject: [PATCH 1/2] iio: adc: sun4i-gpadc-iio: register in the thermal after registering in pm Date: Tue, 26 Sep 2017 14:52:18 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This driver has a get_temp function used by the thermal framework that uses pm functions. However, the driver isn't registered in pm before it is registered in thermal framework, resulting in the pm_resume not being called and thus the IP not enabled. When the IP is disabled, the raw temp value is always 0. With the devices currently supported, it isn't a problem since with their respective formula, they return a really cold SoC temperature which isn't a problem for the thermal framework. But for future SoC that have a different formula, it could return a critically hot temperature, forcing the thermal framework to shutdown the board. Signed-off-by: Quentin Schulz --- drivers/iio/adc/sun4i-gpadc-iio.c | 34 ++++++++++++++------------------ 1 file changed, 15 insertions(+), 19 deletions(-) base-commit: 1f183459b5144384e2669a3f757d36bacab108cf -- git-series 0.9.1 diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 137f577..392d47f 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -529,17 +529,10 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, return ret; } - if (!IS_ENABLED(CONFIG_THERMAL_OF)) - return 0; + if (IS_ENABLED(CONFIG_THERMAL_OF)) + info->sensor_device = &pdev->dev; - info->sensor_device = &pdev->dev; - info->tzd = thermal_zone_of_sensor_register(info->sensor_device, 0, - info, &sun4i_ts_tz_ops); - if (IS_ERR(info->tzd)) - dev_err(&pdev->dev, "could not register thermal sensor: %ld\n", - PTR_ERR(info->tzd)); - - return PTR_ERR_OR_ZERO(info->tzd); + return 0; } static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, @@ -586,15 +579,6 @@ static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, * return the temperature. */ info->sensor_device = pdev->dev.parent; - info->tzd = thermal_zone_of_sensor_register(info->sensor_device, - 0, info, - &sun4i_ts_tz_ops); - if (IS_ERR(info->tzd)) { - dev_err(&pdev->dev, - "could not register thermal sensor: %ld\n", - PTR_ERR(info->tzd)); - return PTR_ERR(info->tzd); - } } else { indio_dev->num_channels = ARRAY_SIZE(sun4i_gpadc_channels_no_temp); @@ -664,6 +648,18 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) pm_runtime_set_suspended(&pdev->dev); pm_runtime_enable(&pdev->dev); + if (IS_ENABLED(CONFIG_THERMAL_OF)) { + info->tzd = thermal_zone_of_sensor_register(info->sensor_device, + 0, info, + &sun4i_ts_tz_ops); + if (IS_ERR(info->tzd)) { + dev_err(&pdev->dev, + "could not register thermal sensor: %ld\n", + PTR_ERR(info->tzd)); + return PTR_ERR(info->tzd); + } + } + ret = devm_iio_device_register(&pdev->dev, indio_dev); if (ret < 0) { dev_err(&pdev->dev, "could not register the device\n");