From patchwork Sun Feb 19 01:13:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9581423 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 44CFA6043A for ; Sun, 19 Feb 2017 01:13:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25355286E2 for ; Sun, 19 Feb 2017 01:13:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 062AF287BB; Sun, 19 Feb 2017 01:13:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 356FF286E2 for ; Sun, 19 Feb 2017 01:13:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750893AbdBSBNh (ORCPT ); Sat, 18 Feb 2017 20:13:37 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34413 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750812AbdBSBNg (ORCPT ); Sat, 18 Feb 2017 20:13:36 -0500 Received: by mail-pg0-f66.google.com with SMTP id v184so8323499pgv.1; Sat, 18 Feb 2017 17:13:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=2+3SDmOuhdPsdyLkUKC/3wStfKfm9qyzsslPZ5Xw8gI=; b=XAYmByG1LW0oUD36zpXsU0TXrwYO1Txj4+093xoJINWtwxGKhxvmwzWW5GYT/8qjne L9rkIj1xXwss1MmBNaSShir5nxO73eqD241s2ug/OjH1PXDd9nW1PdjDc3IidJq05K/X in21wWmb4QJMBJ8kG/Jqnp41Isgs5GZVzKBo7F9LTLxENOdezvdKlVR9DhYYuoQmTN66 8C5rmhi3bHSozSnXwcimfFgenB/jBtklf96jqDsTN+7yjhpSstLVUnkKZVFRj0a4llVN 9ESiEHv/EFoK9PS3HQI66Po6N6YKDG9AaUjEX1g2lw+mdh8X7G+IzDwT7HCmsP7GjA0q GIdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=2+3SDmOuhdPsdyLkUKC/3wStfKfm9qyzsslPZ5Xw8gI=; b=Udf4J9TsP4a3gbycdBf9G2iNP06H6lAaU+9omTgxRhT/yAziHsqXaIGF42tVT919yO yJuR1SwVEMBxu0ovuYgK7k4E60kuUbC+wfYkkxkHlK96SN/xSyDtflj+A0izfvk6LDOX 5ywGzXQelz2qwVlubPc45oVDggHxV7GqNzJEZ8f/kWbaPy+6tEeU237nk3FctS091H7R D/nYFGzRU1X4LEuND7/CJSaI4LAcT7GasEzhfTzpIy97qn7w98/PnyuJcQ26mb/86X+C M8wgiS9U8k0UwLVFjB78OQipTZoHsdPLWGohX7k1Y4huO9HR/oF9daTfLbPl7JykpjRZ Fcqw== X-Gm-Message-State: AMke39nIjTcp4myAUOfb1yWGHL1tkazGOE5FLWPJiVrYLdiwM/sqYuv2br9/2sMTpFu7Aw== X-Received: by 10.98.106.132 with SMTP id f126mr17895505pfc.1.1487466813752; Sat, 18 Feb 2017 17:13:33 -0800 (PST) Received: from localhost.localdomain ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id b73sm7406706pfl.132.2017.02.18.17.13.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Feb 2017 17:13:32 -0800 (PST) Date: Sat, 18 Feb 2017 17:13:29 -0800 From: Eduardo Valentin To: Eric Anholt Cc: Stefan Wahren , Zhang Rui , kernel@martin.sperl.org, Rob Herring , Frank Rowand , Florian Fainelli , linux-rpi-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH V2 1/2] dt-bindings: Add thermal zone to bcm2835-thermal example Message-ID: <20170219011328.GA21016@localhost.localdomain> References: <1486928328-25870-1-git-send-email-stefan.wahren@i2se.com> <878tp9kbt8.fsf@eliezer.anholt.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <878tp9kbt8.fsf@eliezer.anholt.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Feb 13, 2017 at 01:42:11PM -0800, Eric Anholt wrote: > Stefan Wahren writes: > > > Add a thermal zone in order to make the example complete. > > > > Signed-off-by: Stefan Wahren > > This looks fine to me. Eduardo, will this be enough to get the driver > in? Well, yes, but the driver needs to support the descriptors by registering to of-thermal. But that would actually simplify the driver as follows (patch on bcm2835 patch v9, so it supports the descriptors in this thread): ------------------------8------------------------ ------------------------8------------------------ diff --git a/drivers/thermal/bcm2835_thermal.c b/drivers/thermal/bcm2835_thermal.c index 5e2fea9..ffcf847 100644 --- a/drivers/thermal/bcm2835_thermal.c +++ b/drivers/thermal/bcm2835_thermal.c @@ -61,14 +61,8 @@ #define BCM2835_TS_TSENSSTAT_VALID BIT(10) #define BCM2835_TS_TSENSSTAT_INTERRUPT BIT(11) -struct bcm2835_thermal_info { - int offset; - int slope; - int trip_temp; -}; - struct bcm2835_thermal_data { - const struct bcm2835_thermal_info *info; + struct thermal_zone_device *tz; void __iomem *regs; struct clk *clk; struct dentry *debugfsdir; @@ -92,40 +86,9 @@ static int bcm2835_thermal_temp2adc(int temp, int offset, int slope) return temp; } -static int bcm2835_thermal_get_trip_type( - struct thermal_zone_device *tz, int trip, - enum thermal_trip_type *type) +static int bcm2835_thermal_get_temp(void *d, int *temp) { - *type = THERMAL_TRIP_CRITICAL; - return 0; -} - -static int bcm2835_thermal_get_trip_temp( - struct thermal_zone_device *tz, int trip, int *temp) -{ - struct bcm2835_thermal_data *data = tz->devdata; - u32 val = readl(data->regs + BCM2835_TS_TSENSCTL); - - /* get the THOLD bits */ - val &= BCM2835_TS_TSENSCTL_THOLD_MASK; - val >>= BCM2835_TS_TSENSCTL_THOLD_SHIFT; - - /* if it is zero then use the info value */ - if (val) - *temp = bcm2835_thermal_adc2temp( - val, - thermal_zone_get_offset(tz), - thermal_zone_get_slope(tz)); - else - *temp = data->info->trip_temp; - - return 0; -} - -static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, - int *temp) -{ - struct bcm2835_thermal_data *data = tz->devdata; + struct bcm2835_thermal_data *data = d; u32 val = readl(data->regs + BCM2835_TS_TSENSSTAT); if (!(val & BCM2835_TS_TSENSSTAT_VALID)) @@ -135,8 +98,8 @@ static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, *temp = bcm2835_thermal_adc2temp( val, - thermal_zone_get_offset(tz), - thermal_zone_get_slope(tz)); + thermal_zone_get_offset(data->tz), + thermal_zone_get_slope(data->tz)); return 0; } @@ -174,10 +137,8 @@ static void bcm2835_thermal_debugfs(struct platform_device *pdev) data->debugfsdir, regset); } -static struct thermal_zone_device_ops bcm2835_thermal_ops = { +static struct thermal_zone_of_device_ops bcm2835_thermal_ops = { .get_temp = bcm2835_thermal_get_temp, - .get_trip_temp = bcm2835_thermal_get_trip_temp, - .get_trip_type = bcm2835_thermal_get_trip_type, }; static const struct of_device_id bcm2835_thermal_of_match_table[]; @@ -186,10 +147,9 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) const struct of_device_id *match; struct thermal_zone_device *tz; struct thermal_zone_params *tzp; - const struct bcm2835_thermal_info *ti; struct bcm2835_thermal_data *data; struct resource *res; - int err; + int err = 0; u32 val; unsigned long rate; @@ -205,10 +165,6 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) &pdev->dev); if (!match) return -EINVAL; - ti = match->data; - data->info = ti; - tzp->slope = ti->slope; - tzp->offset = ti->offset; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); data->regs = devm_ioremap_resource(&pdev->dev, res); @@ -236,6 +192,17 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) "Clock %pCn running at %pCr Hz is outside of the recommended range: 1.92 to 5MHz\n", data->clk, data->clk); + /* register of thermal sensor and get info from DT */ + tz = thermal_zone_of_sensor_register(&pdev->dev, 0, data, + &bcm2835_thermal_ops); + if (IS_ERR(tz)) { + err = PTR_ERR(tz); + dev_err(&pdev->dev, + "Failed to register the thermal device: %d\n", + err); + goto err_clk; + } + /* * right now the FW does set up the HW-block, so we are not * touching the configuration registers. @@ -244,6 +211,23 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) */ val = readl(data->regs + BCM2835_TS_TSENSCTL); if (!(val & BCM2835_TS_TSENSCTL_RSTB)) { + int trip_temp, offset, slope; + + slope = thermal_zone_get_slope(tz); + offset = thermal_zone_get_offset(tz); + /* + * For now we deal only with critical, otherwise + * would need to iterate + */ + err = tz->ops->get_trip_temp(tz, 0, &trip_temp); + if (err < 0) { + err = PTR_ERR(tz); + dev_err(&pdev->dev, + "Not able to read trip_temp: %d\n", + err); + goto err_tz; + } + /* the basic required flags */ val = (BCM2835_TS_TSENSCTL_CTRL_DEFAULT << BCM2835_TS_TSENSCTL_CTRL_SHIFT) | @@ -256,9 +240,9 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) val |= (14 << BCM2835_TS_TSENSCTL_RSTDELAY_SHIFT); /* trip_adc value from info */ - val |= bcm2835_thermal_temp2adc(data->info->trip_temp, - data->info->offset, - data->info->slope) + val |= bcm2835_thermal_temp2adc(trip_temp, + offset, + slope) << BCM2835_TS_TSENSCTL_THOLD_SHIFT; /* write the value back to the register as 2 steps */ @@ -267,26 +251,18 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) writel(val, data->regs + BCM2835_TS_TSENSCTL); } - /* register thermal zone with 1 trip point an 1s polling */ - tz = thermal_zone_device_register("bcm2835_thermal", - 1, 0, data, - &bcm2835_thermal_ops, - tzp, - 0, 1000); - if (IS_ERR(tz)) { - clk_disable_unprepare(data->clk); - err = PTR_ERR(tz); - dev_err(&pdev->dev, - "Failed to register the thermal device: %d\n", - err); - return err; - } + data->tz = tz; platform_set_drvdata(pdev, tz); bcm2835_thermal_debugfs(pdev); - return 0; +err_tz: + thermal_zone_of_sensor_unregister(&pdev->dev, tz); +err_clk: + clk_disable_unprepare(data->clk); + + return err; } static int bcm2835_thermal_remove(struct platform_device *pdev) @@ -295,7 +271,7 @@ static int bcm2835_thermal_remove(struct platform_device *pdev) struct bcm2835_thermal_data *data = tz->devdata; debugfs_remove_recursive(data->debugfsdir); - thermal_zone_device_unregister(tz); + thermal_zone_of_sensor_unregister(&pdev->dev, tz); clk_disable_unprepare(data->clk); return 0; @@ -312,28 +288,12 @@ static int bcm2835_thermal_remove(struct platform_device *pdev) static const struct of_device_id bcm2835_thermal_of_match_table[] = { { .compatible = "brcm,bcm2835-thermal", - .data = &(struct bcm2835_thermal_info) { - .offset = 407000, - .slope = -538, - .trip_temp = 80000 - } }, { .compatible = "brcm,bcm2836-thermal", - .data = &(struct bcm2835_thermal_info) { - .offset = 407000, - .slope = -538, - .trip_temp = 80000 - } }, { .compatible = "brcm,bcm2837-thermal", - .data = &(struct bcm2835_thermal_info) { - /* the bcm2837 needs adjustment of +5C */ - .offset = 407000 + 5000, - .slope = -538, - .trip_temp = 80000 - } }, {}, };