Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp500139imu; Thu, 3 Jan 2019 01:48:37 -0800 (PST) X-Google-Smtp-Source: ALg8bN5xiYN9XvzqInJTbXhypNzRAuCr+CAf6unJRNc+b7VaKyUH4VmtNdycz7yP/gIVyzPfxaKM X-Received: by 2002:a65:434d:: with SMTP id k13mr16547640pgq.269.1546508916998; Thu, 03 Jan 2019 01:48:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546508916; cv=none; d=google.com; s=arc-20160816; b=oDwP3SgHgKX0O58FLyk9/tKglgDKeebO1LxhXEsJwNB72oS3RjYU/zt1Hlxmt5KpJI n73JP8i7UvjQUvfIJkC++lmP6GQvrbBtsmnd9FEgcZr0c0EEs3Ji8CX7NG5hyCi1CcDM pV8tNng93Fmo3wJvps24Vrnrnl8bNwLpO+W5ZFr5b6izTWXdiB7mJtORBjb2tG6e9d4E /gixwwy0aq1CdH7NdW+qj+YEj0Vxb9Qj610s9zOYhF7CieAZVKOe3fBtVZOyEXtMkHVv AohGUBWWLgeKQIgmBZfGDxuzg8pEPWwGhmaXxIoXapFWm4qP1ZhDlW5/vHurWZ4zovLS EbgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=y6EoJPAai4B6OShuzBPRF2rX81g0eupnWAIxSczxknE=; b=sjqTbgmLDXQvjH9/wDxZ/joweK45IqmF6TgPtd9TGRDWla+IpNAdWNFQqKCHrKuzzZ 7sa71NCZJN/NrOC4y62lmMx8CqoMH3/D3e+QKiOH9J+lz88GuSXy/f8rnTTQpJtAKT1I 8H6ikSRTCvLTynWEAFGVyQ9wAgDR4APcJ/L3LYXLDKK8nzMYE101KKIIuHgnjP5ncx5U VC8CtiNDLrvl/UKmE4Tnq3Xywui/ZqLjJ4lr9lacd/LIbhvvP68lBN2GvszT69dsQq4i OqMIWRJXznD70LEczjDgBGSz4KiHCcwB9Y4s/rssk4yDJB/oUfSDTEgmMndfpk7ngVF5 qJoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=NQbh6Yey; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b91si13324982plb.11.2019.01.03.01.48.22; Thu, 03 Jan 2019 01:48:36 -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; dkim=pass header.i=@broadcom.com header.s=google header.b=NQbh6Yey; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729741AbfACG2k (ORCPT + 99 others); Thu, 3 Jan 2019 01:28:40 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43436 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727787AbfACG2j (ORCPT ); Thu, 3 Jan 2019 01:28:39 -0500 Received: by mail-wr1-f68.google.com with SMTP id r10so32519282wrs.10 for ; Wed, 02 Jan 2019 22:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=y6EoJPAai4B6OShuzBPRF2rX81g0eupnWAIxSczxknE=; b=NQbh6YeyENP+uG2N9R5XoOJW49QZBZBpAvP0otXO0uOVdttPWArEUI7TCjr4njjeqR 0I1IzSBxB23S+40Xn7tReaf7KFduovWUzCOhQ/O+MnUfZ0xOUTJ2xa96fMq4auHXjwFa un7/l3+gpnMKLISxQ1+rSAbF4Gufe7ANW/eho= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=y6EoJPAai4B6OShuzBPRF2rX81g0eupnWAIxSczxknE=; b=FLwkCf9O9ukY0CkOqbBYkOG6ARxop+mGGUoOede9Lx+Y3BrkeTArHXWCqb6Z3gT4u5 AudhfBxBbL7hjd1PU/0ksmkNRrW7aFmj3Zbg9ptBfBZIvsqy2ieLGho35KHuXdU7epjt ulsnRaCT/Wh9ikX7jG49JQ4YGHREydsVrKp9m8yXkczKAa3X8EJH10eoJFJr+OYp0O+b L52alZjxEP4Yl2PxhIuq19V0tnUCHceRjNyBGBaJc2JwMHtfjaefodmdieIz4QRGrHb4 0FvnAa1Pss+bMvaQ8BawOVHIokJN4L+wEvi2aICqYbdn3/x71DCGW85UYZIn2SpxxVss TgQg== X-Gm-Message-State: AJcUukegCtmlGnxcyPTIHBO/FHOuxWpQ4ADx4+eDK6Ek0SSYbZXoBxPw 1RYB2pKmLFKVi+23tm6BVhmy0lLnONa40AW2O/vMUw== X-Received: by 2002:a5d:504f:: with SMTP id h15mr40751696wrt.83.1546496917188; Wed, 02 Jan 2019 22:28:37 -0800 (PST) MIME-Version: 1.0 References: <1539702680-3746-1-git-send-email-srinath.mannam@broadcom.com> <1539702680-3746-3-git-send-email-srinath.mannam@broadcom.com> <20190102200306.GB2024@localhost.localdomain> In-Reply-To: <20190102200306.GB2024@localhost.localdomain> From: Srinath Mannam Date: Thu, 3 Jan 2019 11:58:26 +0530 Message-ID: Subject: Re: [PATCH v5 2/3] thermal: broadcom: Add Stingray thermal driver To: Eduardo Valentin Cc: Daniel Lezcano , Zhang Rui , Rob Herring , Mark Rutland , devicetree@vger.kernel.org, Linux Kernel Mailing List , BCM Kernel Feedback , Pramod Kumar Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Eduardo Valentin, Thank you for the review. I will address your comments in next patchset. Please find my comments in lined. On Thu, Jan 3, 2019 at 1:33 AM Eduardo Valentin wrote: > > On Tue, Oct 16, 2018 at 08:41:19PM +0530, Srinath Mannam wrote: > > From: Pramod Kumar > > > > Stingray SoC has six temperature sensor and those are > > configured, controlled and accessed to read temperature > > and update in DDR memory using m0 firmware. > > All six sensors has been given 4 bytes of memory in DDR > > to write temperature in millivolts. > > > > This thermal driver read temperature values from DDR > > because no direct access to sensors. > > Like this all temparature sensors are monitored and > > trips at critical temperature. > > > > If driver can't handle thermal runaways because of > > any unknown reason, then firmware in m0 Processor > > will handle. > > > > Signed-off-by: Pramod Kumar > > Signed-off-by: Srinath Mannam > > Reviewed-by: Ray Jui > > Reviewed-by: Scott Branden > > Reviewed-by: Vikram Prakash > > --- > > drivers/thermal/Kconfig | 3 +- > > drivers/thermal/broadcom/Kconfig | 9 +++ > > drivers/thermal/broadcom/Makefile | 1 + > > drivers/thermal/broadcom/sr-thermal.c | 138 ++++++++++++++++++++++++++++++++++ > > 4 files changed, 150 insertions(+), 1 deletion(-) > > create mode 100644 drivers/thermal/broadcom/sr-thermal.c > > > > diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig > > index 0e69edc..5f9f070 100644 > > --- a/drivers/thermal/Kconfig > > +++ b/drivers/thermal/Kconfig > > @@ -416,7 +416,8 @@ config MTK_THERMAL > > controller present in Mediatek SoCs > > > > menu "Broadcom thermal drivers" > > -depends on ARCH_BCM || ARCH_BRCMSTB || ARCH_BCM2835 || COMPILE_TEST > > +depends on ARCH_BCM || ARCH_BRCMSTB || ARCH_BCM2835 || ARCH_BCM_IPROC || \ > > + COMPILE_TEST > > source "drivers/thermal/broadcom/Kconfig" > > endmenu > > > > diff --git a/drivers/thermal/broadcom/Kconfig b/drivers/thermal/broadcom/Kconfig > > index c106a15..dc9a9bd 100644 > > --- a/drivers/thermal/broadcom/Kconfig > > +++ b/drivers/thermal/broadcom/Kconfig > > @@ -22,3 +22,12 @@ config BCM_NS_THERMAL > > BCM4708, BCM4709, BCM5301x, BCM95852X, etc). It contains DMU (Device > > Management Unit) block with a thermal sensor that allows checking CPU > > temperature. > > + > > +config BCM_SR_THERMAL > > + tristate "Stingray thermal driver" > > + depends on ARCH_BCM_IPROC || COMPILE_TEST > > + default ARCH_BCM_IPROC > > + help > > + Support for the Stingray family of SoCs. Its different blocks like > > + iHost, CRMU and NITRO has thermal sensor that allows checking its > > + temperature. > > diff --git a/drivers/thermal/broadcom/Makefile b/drivers/thermal/broadcom/Makefile > > index fae10ec..79df69e 100644 > > --- a/drivers/thermal/broadcom/Makefile > > +++ b/drivers/thermal/broadcom/Makefile > > @@ -1,3 +1,4 @@ > > obj-$(CONFIG_BCM2835_THERMAL) += bcm2835_thermal.o > > obj-$(CONFIG_BRCMSTB_THERMAL) += brcmstb_thermal.o > > obj-$(CONFIG_BCM_NS_THERMAL) += ns-thermal.o > > +obj-$(CONFIG_BCM_SR_THERMAL) += sr-thermal.o > > diff --git a/drivers/thermal/broadcom/sr-thermal.c b/drivers/thermal/broadcom/sr-thermal.c > > new file mode 100644 > > index 0000000..f45e12e > > --- /dev/null > > +++ b/drivers/thermal/broadcom/sr-thermal.c > > @@ -0,0 +1,138 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (C) 2018 Broadcom > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +/* > > + * In stingray thermal IO memory, > > + * Total Number of available TMONs MASK is at offset 0 > > + * temperature registers BASE is at 4 byte offset. > > + * Each TMON temperature register size is 4. > > + */ > > +#define SR_TMON_TEMP_BASE(id) ((id) * 0x4) > > + > > +#define SR_TMON_MAX_LIST 6 > > + > > +struct sr_tmon { > > + struct thermal_zone_device *tz; > > + unsigned int crit_temp; > > + unsigned int tmon_id; > > + struct sr_thermal *priv; > > +}; > > + > > +struct sr_thermal { > > + void __iomem *regs; > > + unsigned int max_crit_temp; > > + struct sr_tmon tmon[SR_TMON_MAX_LIST]; > > +}; > > + > > +static int sr_get_temp(void *data, int *temp) > > +{ > > + struct sr_tmon *tmon = data; > > + struct sr_thermal *sr_thermal = tmon->priv; > > + > > + *temp = readl(sr_thermal->regs + SR_TMON_TEMP_BASE(tmon->tmon_id)); > > + > > + return 0; > > +} > > + > > +static const struct thermal_zone_of_device_ops sr_tz_ops = { > > + .get_temp = sr_get_temp, > > +}; > > + > > +static int sr_thermal_probe(struct platform_device *pdev) > > +{ > > + struct device *dev = &pdev->dev; > > + struct sr_thermal *sr_thermal; > > + struct sr_tmon *tmon; > > + struct resource *res; > > + uint32_t sr_tmon_list = 0; > > + unsigned int i; > > + int ret; > > + > > + sr_thermal = devm_kzalloc(dev, sizeof(*sr_thermal), GFP_KERNEL); > > + if (!sr_thermal) > > + return -ENOMEM; > > + > > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > + sr_thermal->regs = (void __iomem *)devm_memremap(&pdev->dev, res->start, > > + resource_size(res), > > + MEMREMAP_WB); > > + if (IS_ERR(sr_thermal->regs)) { > > + dev_err(dev, "failed to get io address\n"); > > + return PTR_ERR(sr_thermal->regs); > > + } > > + > > + ret = device_property_read_u32(dev, "brcm,tmon-mask", &sr_tmon_list); > > + if (ret) > > + return ret; > > + > > + tmon = sr_thermal->tmon; > > + for (i = 0; i < SR_TMON_MAX_LIST; i++, tmon++) { > > + > > + if (!(sr_tmon_list & BIT(i))) > > + continue; > > + > > + /* Flush temperature registers */ > > + writel(0, sr_thermal->regs + SR_TMON_TEMP_BASE(i)); > > + tmon->tmon_id = i; > > + tmon->priv = sr_thermal; > > + tmon->tz = devm_thermal_zone_of_sensor_register(dev, i, tmon, > > + &sr_tz_ops); > > + if (IS_ERR(tmon->tz)) > > + return PTR_ERR(tmon->tz); > > + > > + dev_info(dev, "thermal sensor %d registered\n", i); > > > > Does this really need to be dev_info() level? Usually just pollutes boot > message logs.. I will change dev_info to dev_dbg. > > + } > > + platform_set_drvdata(pdev, sr_thermal); > > + > > + return 0; > > +} > > + > > +static int sr_thermal_remove(struct platform_device *pdev) > > +{ > > + struct sr_thermal *sr_thermal = platform_get_drvdata(pdev); > > + unsigned int i; > > + struct sr_tmon *tmon; > > + > > + tmon = sr_thermal->tmon; > > + for (i = 0; i < SR_TMON_MAX_LIST; i++, tmon++) > > + if (tmon->tz) > > + devm_thermal_zone_of_sensor_unregister(&pdev->dev, > > + tmon->tz); > > Why did you need to explicitly call devm_.*unregister()? Yes, this call is not required I will remove sr_thermal_remove function completely. > > > + > > + return 0; > > +} > > + > > +static const struct of_device_id sr_thermal_of_match[] = { > > + { .compatible = "brcm,sr-thermal", }, > > + {}, > > +}; > > +MODULE_DEVICE_TABLE(of, sr_thermal_of_match); > > + > > +static const struct acpi_device_id sr_thermal_acpi_ids[] = { > > + { .id = "BRCM0500" }, > > + { /* sentinel */ } > > +}; > > +MODULE_DEVICE_TABLE(acpi, sr_thermal_acpi_ids); > > + > > +static struct platform_driver sr_thermal_driver = { > > + .probe = sr_thermal_probe, > > + .remove = sr_thermal_remove, > > + .driver = { > > + .name = "sr-thermal", > > + .of_match_table = sr_thermal_of_match, > > + .acpi_match_table = ACPI_PTR(sr_thermal_acpi_ids), > > + }, > > +}; > > +module_platform_driver(sr_thermal_driver); > > + > > +MODULE_AUTHOR("Pramod Kumar "); > > +MODULE_DESCRIPTION("Stingray thermal driver"); > > +MODULE_LICENSE("GPL v2"); > > -- > > 2.7.4 > > Regards, Srinath.