2018-10-16 15:13:34

by Srinath Mannam

[permalink] [raw]
Subject: [PATCH v5 0/3] Stingray thermal driver support

These patches adds the stingray thermal driver and its
corresponding DT nodes with documentation.

Changes from v4
- Addressed Rob Herring comments on DT parameters and
thermal driver architecture.
- Removed brcm,max-crit-temp DT parameter
- Changed driver to thermal sensor registration model.
- Added trip DT properties.

Changes from v3
- Addressed Daniel lezcano comments.
- Elaborated commit description of thermal driver patch.
- Added brcm,max-crit-temp DT parameter.

Changes from v2:
- All stingray TMON DT nodes are combine together into single.
Temperature registers are combined into one mem resource.
brcm,tmon-mask parameter has available TMONs mask value.
- All available TMONs are initialized together in single
instance of driver probe call.

Changes from v1:
- Fixed auto build sparce warning.

Pramod Kumar (3):
dt-bindings: thermal: Add binding document for SR thermal
thermal: broadcom: Add Stingray thermal driver
arm64: dts: stingray: Add Stingray Thermal DT support.

.../bindings/thermal/brcm,sr-thermal.txt | 105 ++++++++++++++++
.../arm64/boot/dts/broadcom/stingray/stingray.dtsi | 89 +++++++++++++
drivers/thermal/Kconfig | 3 +-
drivers/thermal/broadcom/Kconfig | 9 ++
drivers/thermal/broadcom/Makefile | 1 +
drivers/thermal/broadcom/sr-thermal.c | 138 +++++++++++++++++++++
6 files changed, 344 insertions(+), 1 deletion(-)
create mode 100644 Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
create mode 100644 drivers/thermal/broadcom/sr-thermal.c

--
2.7.4



2018-10-16 15:12:28

by Srinath Mannam

[permalink] [raw]
Subject: [PATCH v5 1/3] dt-bindings: thermal: Add binding document for SR thermal

From: Pramod Kumar <[email protected]>

Add binding document for supported thermal implementation
in Stingray.

Signed-off-by: Pramod Kumar <[email protected]>
Signed-off-by: Srinath Mannam <[email protected]>
Reviewed-by: Ray Jui <[email protected]>
Reviewed-by: Scott Branden <[email protected]>
---
.../bindings/thermal/brcm,sr-thermal.txt | 105 +++++++++++++++++++++
1 file changed, 105 insertions(+)
create mode 100644 Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt

diff --git a/Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt b/Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
new file mode 100644
index 0000000..3ab3302
--- /dev/null
+++ b/Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
@@ -0,0 +1,105 @@
+* Broadcom Stingray Thermal
+
+This binding describes thermal sensors that is part of Stingray SoCs.
+
+Required properties:
+- compatible : Must be "brcm,sr-thermal"
+- reg : Memory where tmon data will be available.
+- brcm,tmon-mask: A one cell bit mask of valid TMON sources.
+ Each bit represents single TMON source.
+- #thermal-sensor-cells : Thermal sensor phandler
+- polling-delay: Max number of milliseconds to wait between polls.
+- thermal-sensors: A list of thermal sensor phandles and specifier.
+ specifier value is tmon ID and it should be
+ in correspond with brcm,tmon-mask.
+- temperature: trip temperature threshold in millicelsius.
+
+Example:
+ tmons {
+ compatible = "simple-bus";
+ #address-cells = <1>;
+ #size-cells = <1>;
+ ranges = <0x0 0x0 0x8f100000 0x100>;
+
+ tmon: tmon@0 {
+ compatible = "brcm,sr-thermal";
+ reg = <0x0 0x40>;
+ brcm,tmon-mask = <0x3f>;
+ #thermal-sensor-cells = <1>;
+ };
+ };
+
+ thermal-zones {
+ ihost0_thermal: ihost0-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 0>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ ihost1_thermal: ihost1-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 1>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ ihost2_thermal: ihost2-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 2>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ ihost3_thermal: ihost3-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 3>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ crmu_thermal: crmu-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 4>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ nitro_thermal: nitro-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 5>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ };
--
2.7.4


2018-10-16 15:13:23

by Srinath Mannam

[permalink] [raw]
Subject: [PATCH v5 2/3] thermal: broadcom: Add Stingray thermal driver

From: Pramod Kumar <[email protected]>

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 <[email protected]>
Signed-off-by: Srinath Mannam <[email protected]>
Reviewed-by: Ray Jui <[email protected]>
Reviewed-by: Scott Branden <[email protected]>
Reviewed-by: Vikram Prakash <[email protected]>
---
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 <linux/acpi.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+/*
+ * 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);
+ }
+ 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);
+
+ 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 <[email protected]>");
+MODULE_DESCRIPTION("Stingray thermal driver");
+MODULE_LICENSE("GPL v2");
--
2.7.4


2018-10-16 15:14:07

by Srinath Mannam

[permalink] [raw]
Subject: [PATCH v5 3/3] arm64: dts: stingray: Add Stingray Thermal DT support.

From: Pramod Kumar <[email protected]>

Add DT nodes for thermal zones memory base address
to read temperature.

Signed-off-by: Pramod Kumar <[email protected]>
Signed-off-by: Srinath Mannam <[email protected]>
Reviewed-by: Ray Jui <[email protected]>
Reviewed-by: Scott Branden <[email protected]>
---
.../arm64/boot/dts/broadcom/stingray/stingray.dtsi | 89 ++++++++++++++++++++++
1 file changed, 89 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/stingray/stingray.dtsi b/arch/arm64/boot/dts/broadcom/stingray/stingray.dtsi
index e283480..0d246ba 100644
--- a/arch/arm64/boot/dts/broadcom/stingray/stingray.dtsi
+++ b/arch/arm64/boot/dts/broadcom/stingray/stingray.dtsi
@@ -612,4 +612,93 @@
status = "disabled";
};
};
+
+ tmons {
+ compatible = "simple-bus";
+ #address-cells = <1>;
+ #size-cells = <1>;
+ ranges = <0x0 0x0 0x8f100000 0x100>;
+
+ tmon: tmon@0 {
+ compatible = "brcm,sr-thermal";
+ reg = <0x0 0x40>;
+ brcm,tmon-mask = <0x3f>;
+ #thermal-sensor-cells = <1>;
+ };
+ };
+
+ thermal-zones {
+ ihost0_thermal: ihost0-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 0>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ ihost1_thermal: ihost1-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 1>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ ihost2_thermal: ihost2-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 2>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ ihost3_thermal: ihost3-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 3>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ crmu_thermal: crmu-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 4>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ nitro_thermal: nitro-thermal {
+ polling-delay-passive = <0>;
+ polling-delay = <1000>;
+ thermal-sensors = <&tmon 5>;
+ trips {
+ cpu-crit {
+ temperature = <105000>;
+ hysteresis = <0>;
+ type = "critical";
+ };
+ };
+ };
+ };
};
--
2.7.4


2018-10-18 14:37:23

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v5 1/3] dt-bindings: thermal: Add binding document for SR thermal

On Tue, 16 Oct 2018 20:41:18 +0530, Srinath Mannam wrote:
> From: Pramod Kumar <[email protected]>
>
> Add binding document for supported thermal implementation
> in Stingray.
>
> Signed-off-by: Pramod Kumar <[email protected]>
> Signed-off-by: Srinath Mannam <[email protected]>
> Reviewed-by: Ray Jui <[email protected]>
> Reviewed-by: Scott Branden <[email protected]>
> ---
> .../bindings/thermal/brcm,sr-thermal.txt | 105 +++++++++++++++++++++
> 1 file changed, 105 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
>

Reviewed-by: Rob Herring <[email protected]>

2018-10-18 19:11:27

by Scott Branden

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] Stingray thermal driver support

All Acked-by: Scott Branden <[email protected]>

On 2018-10-16 8:11 a.m., Srinath Mannam wrote:
> These patches adds the stingray thermal driver and its
> corresponding DT nodes with documentation.
>
> Changes from v4
> - Addressed Rob Herring comments on DT parameters and
> thermal driver architecture.
> - Removed brcm,max-crit-temp DT parameter
> - Changed driver to thermal sensor registration model.
> - Added trip DT properties.
>
> Changes from v3
> - Addressed Daniel lezcano comments.
> - Elaborated commit description of thermal driver patch.
> - Added brcm,max-crit-temp DT parameter.
>
> Changes from v2:
> - All stingray TMON DT nodes are combine together into single.
> Temperature registers are combined into one mem resource.
> brcm,tmon-mask parameter has available TMONs mask value.
> - All available TMONs are initialized together in single
> instance of driver probe call.
>
> Changes from v1:
> - Fixed auto build sparce warning.
>
> Pramod Kumar (3):
> dt-bindings: thermal: Add binding document for SR thermal
> thermal: broadcom: Add Stingray thermal driver
> arm64: dts: stingray: Add Stingray Thermal DT support.
>
> .../bindings/thermal/brcm,sr-thermal.txt | 105 ++++++++++++++++
> .../arm64/boot/dts/broadcom/stingray/stingray.dtsi | 89 +++++++++++++
> drivers/thermal/Kconfig | 3 +-
> drivers/thermal/broadcom/Kconfig | 9 ++
> drivers/thermal/broadcom/Makefile | 1 +
> drivers/thermal/broadcom/sr-thermal.c | 138 +++++++++++++++++++++
> 6 files changed, 344 insertions(+), 1 deletion(-)
> create mode 100644 Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
> create mode 100644 drivers/thermal/broadcom/sr-thermal.c
>

2018-11-07 22:16:11

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] Stingray thermal driver support



On 10/16/2018 8:11 AM, Srinath Mannam wrote:
> These patches adds the stingray thermal driver and its
> corresponding DT nodes with documentation.

Can we get feedback from the thermal maintains whether this is
acceptable or not?

>
> Changes from v4
> - Addressed Rob Herring comments on DT parameters and
> thermal driver architecture.
> - Removed brcm,max-crit-temp DT parameter
> - Changed driver to thermal sensor registration model.
> - Added trip DT properties.
>
> Changes from v3
> - Addressed Daniel lezcano comments.
> - Elaborated commit description of thermal driver patch.
> - Added brcm,max-crit-temp DT parameter.
>
> Changes from v2:
> - All stingray TMON DT nodes are combine together into single.
> Temperature registers are combined into one mem resource.
> brcm,tmon-mask parameter has available TMONs mask value.
> - All available TMONs are initialized together in single
> instance of driver probe call.
>
> Changes from v1:
> - Fixed auto build sparce warning.
>
> Pramod Kumar (3):
> dt-bindings: thermal: Add binding document for SR thermal
> thermal: broadcom: Add Stingray thermal driver
> arm64: dts: stingray: Add Stingray Thermal DT support.
>
> .../bindings/thermal/brcm,sr-thermal.txt | 105 ++++++++++++++++
> .../arm64/boot/dts/broadcom/stingray/stingray.dtsi | 89 +++++++++++++
> drivers/thermal/Kconfig | 3 +-
> drivers/thermal/broadcom/Kconfig | 9 ++
> drivers/thermal/broadcom/Makefile | 1 +
> drivers/thermal/broadcom/sr-thermal.c | 138 +++++++++++++++++++++
> 6 files changed, 344 insertions(+), 1 deletion(-)
> create mode 100644 Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
> create mode 100644 drivers/thermal/broadcom/sr-thermal.c
>

--
Florian

2018-12-05 03:18:56

by Srinath Mannam

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] Stingray thermal driver support

Hi,

Could you please provide your feedback to this patch series?

Regards,
Srinath.
On Thu, Nov 8, 2018 at 3:45 AM Florian Fainelli <[email protected]> wrote:
>
>
>
> On 10/16/2018 8:11 AM, Srinath Mannam wrote:
> > These patches adds the stingray thermal driver and its
> > corresponding DT nodes with documentation.
>
> Can we get feedback from the thermal maintains whether this is
> acceptable or not?
>
> >
> > Changes from v4
> > - Addressed Rob Herring comments on DT parameters and
> > thermal driver architecture.
> > - Removed brcm,max-crit-temp DT parameter
> > - Changed driver to thermal sensor registration model.
> > - Added trip DT properties.
> >
> > Changes from v3
> > - Addressed Daniel lezcano comments.
> > - Elaborated commit description of thermal driver patch.
> > - Added brcm,max-crit-temp DT parameter.
> >
> > Changes from v2:
> > - All stingray TMON DT nodes are combine together into single.
> > Temperature registers are combined into one mem resource.
> > brcm,tmon-mask parameter has available TMONs mask value.
> > - All available TMONs are initialized together in single
> > instance of driver probe call.
> >
> > Changes from v1:
> > - Fixed auto build sparce warning.
> >
> > Pramod Kumar (3):
> > dt-bindings: thermal: Add binding document for SR thermal
> > thermal: broadcom: Add Stingray thermal driver
> > arm64: dts: stingray: Add Stingray Thermal DT support.
> >
> > .../bindings/thermal/brcm,sr-thermal.txt | 105 ++++++++++++++++
> > .../arm64/boot/dts/broadcom/stingray/stingray.dtsi | 89 +++++++++++++
> > drivers/thermal/Kconfig | 3 +-
> > drivers/thermal/broadcom/Kconfig | 9 ++
> > drivers/thermal/broadcom/Makefile | 1 +
> > drivers/thermal/broadcom/sr-thermal.c | 138 +++++++++++++++++++++
> > 6 files changed, 344 insertions(+), 1 deletion(-)
> > create mode 100644 Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
> > create mode 100644 drivers/thermal/broadcom/sr-thermal.c
> >
>
> --
> Florian

2018-12-31 23:56:06

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] Stingray thermal driver support



On 04/12/2018 19:17, Srinath Mannam wrote:
> Hi,
>
> Could you please provide your feedback to this patch series?

Rui or Eduardo can we get either one of you to review the thermal driver
parts of this patch series? Why do we constantly have to chase people to
respond in this specific subsystem?

>
> Regards,
> Srinath.
> On Thu, Nov 8, 2018 at 3:45 AM Florian Fainelli <[email protected]> wrote:
>>
>>
>>
>> On 10/16/2018 8:11 AM, Srinath Mannam wrote:
>>> These patches adds the stingray thermal driver and its
>>> corresponding DT nodes with documentation.
>>
>> Can we get feedback from the thermal maintains whether this is
>> acceptable or not?
>>
>>>
>>> Changes from v4
>>> - Addressed Rob Herring comments on DT parameters and
>>> thermal driver architecture.
>>> - Removed brcm,max-crit-temp DT parameter
>>> - Changed driver to thermal sensor registration model.
>>> - Added trip DT properties.
>>>
>>> Changes from v3
>>> - Addressed Daniel lezcano comments.
>>> - Elaborated commit description of thermal driver patch.
>>> - Added brcm,max-crit-temp DT parameter.
>>>
>>> Changes from v2:
>>> - All stingray TMON DT nodes are combine together into single.
>>> Temperature registers are combined into one mem resource.
>>> brcm,tmon-mask parameter has available TMONs mask value.
>>> - All available TMONs are initialized together in single
>>> instance of driver probe call.
>>>
>>> Changes from v1:
>>> - Fixed auto build sparce warning.
>>>
>>> Pramod Kumar (3):
>>> dt-bindings: thermal: Add binding document for SR thermal
>>> thermal: broadcom: Add Stingray thermal driver
>>> arm64: dts: stingray: Add Stingray Thermal DT support.
>>>
>>> .../bindings/thermal/brcm,sr-thermal.txt | 105 ++++++++++++++++
>>> .../arm64/boot/dts/broadcom/stingray/stingray.dtsi | 89 +++++++++++++
>>> drivers/thermal/Kconfig | 3 +-
>>> drivers/thermal/broadcom/Kconfig | 9 ++
>>> drivers/thermal/broadcom/Makefile | 1 +
>>> drivers/thermal/broadcom/sr-thermal.c | 138 +++++++++++++++++++++
>>> 6 files changed, 344 insertions(+), 1 deletion(-)
>>> create mode 100644 Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
>>> create mode 100644 drivers/thermal/broadcom/sr-thermal.c
>>>
>>
>> --
>> Florian

--
Florian

2019-01-01 16:56:48

by Zhang, Rui

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] Stingray thermal driver support

On 一, 2018-12-31 at 14:15 -0800, Florian Fainelli wrote:
>
> On 04/12/2018 19:17, Srinath Mannam wrote:
> >
> > Hi,
> >
> > Could you please provide your feedback to this patch series?
> Rui or Eduardo can we get either one of you to review the thermal
> driver
> parts of this patch series? Why do we constantly have to chase people
> to
> respond in this specific subsystem?
>
Eduardo, can you please take a look at this patch series?

thanks,
rui
> >
> >
> > Regards,
> > Srinath.
> > On Thu, Nov 8, 2018 at 3:45 AM Florian Fainelli <[email protected]
> > om> wrote:
> > >
> > >
> > >
> > >
> > > On 10/16/2018 8:11 AM, Srinath Mannam wrote:
> > > >
> > > > These patches adds the stingray thermal driver and its
> > > > corresponding DT nodes with documentation.
> > > Can we get feedback from the thermal maintains whether this is
> > > acceptable or not?
> > >
> > > >
> > > >
> > > > Changes from v4
> > > >   - Addressed Rob Herring comments on DT parameters and
> > > >     thermal driver architecture.
> > > >   - Removed brcm,max-crit-temp DT parameter
> > > >   - Changed driver to thermal sensor registration model.
> > > >   - Added trip DT properties.
> > > >
> > > > Changes from v3
> > > >   - Addressed Daniel lezcano comments.
> > > >   - Elaborated commit description of thermal driver patch.
> > > >   - Added brcm,max-crit-temp DT parameter.
> > > >
> > > > Changes from v2:
> > > >   - All stingray TMON DT nodes are combine together into
> > > > single.
> > > >     Temperature registers are combined into one mem resource.
> > > >     brcm,tmon-mask parameter has available TMONs mask value.
> > > >   - All available TMONs are initialized together in single
> > > >     instance of driver probe call.
> > > >
> > > > Changes from v1:
> > > >   - Fixed auto build sparce warning.
> > > >
> > > > Pramod Kumar (3):
> > > >   dt-bindings: thermal: Add binding document for SR thermal
> > > >   thermal: broadcom: Add Stingray thermal driver
> > > >   arm64: dts: stingray: Add Stingray Thermal DT support.
> > > >
> > > >  .../bindings/thermal/brcm,sr-thermal.txt           | 105
> > > > ++++++++++++++++
> > > >  .../arm64/boot/dts/broadcom/stingray/stingray.dtsi |  89
> > > > +++++++++++++
> > > >  drivers/thermal/Kconfig                            |   3 +-
> > > >  drivers/thermal/broadcom/Kconfig                   |   9 ++
> > > >  drivers/thermal/broadcom/Makefile                  |   1 +
> > > >  drivers/thermal/broadcom/sr-thermal.c              | 138
> > > > +++++++++++++++++++++
> > > >  6 files changed, 344 insertions(+), 1 deletion(-)
> > > >  create mode 100644
> > > > Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
> > > >  create mode 100644 drivers/thermal/broadcom/sr-thermal.c
> > > >
> > > --
> > > Florian

2019-01-01 19:31:48

by Eduardo Valentin

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] Stingray thermal driver support

On Tue, Jan 01, 2019 at 10:04:39PM +0800, Zhang Rui wrote:
> On 一, 2018-12-31 at 14:15 -0800, Florian Fainelli wrote:
> >
> > On 04/12/2018 19:17, Srinath Mannam wrote:
> > >
> > > Hi,
> > >
> > > Could you please provide your feedback to this patch series?
> > Rui or Eduardo can we get either one of you to review the thermal
> > driver
> > parts of this patch series? Why do we constantly have to chase people
> > to
> > respond in this specific subsystem?
> >
> Eduardo, can you please take a look at this patch series?

Yup, I will take a look.

>
> thanks,
> rui
> > >
> > >
> > > Regards,
> > > Srinath.
> > > On Thu, Nov 8, 2018 at 3:45 AM Florian Fainelli <[email protected]
> > > om> wrote:
> > > >
> > > >
> > > >
> > > >
> > > > On 10/16/2018 8:11 AM, Srinath Mannam wrote:
> > > > >
> > > > > These patches adds the stingray thermal driver and its
> > > > > corresponding DT nodes with documentation.
> > > > Can we get feedback from the thermal maintains whether this is
> > > > acceptable or not?
> > > >
> > > > >
> > > > >
> > > > > Changes from v4
> > > > >   - Addressed Rob Herring comments on DT parameters and
> > > > >     thermal driver architecture.
> > > > >   - Removed brcm,max-crit-temp DT parameter
> > > > >   - Changed driver to thermal sensor registration model.
> > > > >   - Added trip DT properties.
> > > > >
> > > > > Changes from v3
> > > > >   - Addressed Daniel lezcano comments.
> > > > >   - Elaborated commit description of thermal driver patch.
> > > > >   - Added brcm,max-crit-temp DT parameter.
> > > > >
> > > > > Changes from v2:
> > > > >   - All stingray TMON DT nodes are combine together into
> > > > > single.
> > > > >     Temperature registers are combined into one mem resource.
> > > > >     brcm,tmon-mask parameter has available TMONs mask value.
> > > > >   - All available TMONs are initialized together in single
> > > > >     instance of driver probe call.
> > > > >
> > > > > Changes from v1:
> > > > >   - Fixed auto build sparce warning.
> > > > >
> > > > > Pramod Kumar (3):
> > > > >   dt-bindings: thermal: Add binding document for SR thermal
> > > > >   thermal: broadcom: Add Stingray thermal driver
> > > > >   arm64: dts: stingray: Add Stingray Thermal DT support.
> > > > >
> > > > >  .../bindings/thermal/brcm,sr-thermal.txt           | 105
> > > > > ++++++++++++++++
> > > > >  .../arm64/boot/dts/broadcom/stingray/stingray.dtsi |  89
> > > > > +++++++++++++
> > > > >  drivers/thermal/Kconfig                            |   3 +-
> > > > >  drivers/thermal/broadcom/Kconfig                   |   9 ++
> > > > >  drivers/thermal/broadcom/Makefile                  |   1 +
> > > > >  drivers/thermal/broadcom/sr-thermal.c              | 138
> > > > > +++++++++++++++++++++
> > > > >  6 files changed, 344 insertions(+), 1 deletion(-)
> > > > >  create mode 100644
> > > > > Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
> > > > >  create mode 100644 drivers/thermal/broadcom/sr-thermal.c
> > > > >
> > > > --
> > > > Florian

2019-01-02 05:47:21

by Srinath Mannam

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] Stingray thermal driver support

Hi Rui, Eduardo,

Wish you very happy new year and Thank you very much for your response.

Regards,
Srinath.

On Tue, Jan 1, 2019 at 9:37 PM Eduardo Valentin <[email protected]> wrote:
>
> On Tue, Jan 01, 2019 at 10:04:39PM +0800, Zhang Rui wrote:
> > On 一, 2018-12-31 at 14:15 -0800, Florian Fainelli wrote:
> > >
> > > On 04/12/2018 19:17, Srinath Mannam wrote:
> > > >
> > > > Hi,
> > > >
> > > > Could you please provide your feedback to this patch series?
> > > Rui or Eduardo can we get either one of you to review the thermal
> > > driver
> > > parts of this patch series? Why do we constantly have to chase people
> > > to
> > > respond in this specific subsystem?
> > >
> > Eduardo, can you please take a look at this patch series?
>
> Yup, I will take a look.
>
> >
> > thanks,
> > rui
> > > >
> > > >
> > > > Regards,
> > > > Srinath.
> > > > On Thu, Nov 8, 2018 at 3:45 AM Florian Fainelli <[email protected]
> > > > om> wrote:
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On 10/16/2018 8:11 AM, Srinath Mannam wrote:
> > > > > >
> > > > > > These patches adds the stingray thermal driver and its
> > > > > > corresponding DT nodes with documentation.
> > > > > Can we get feedback from the thermal maintains whether this is
> > > > > acceptable or not?
> > > > >
> > > > > >
> > > > > >
> > > > > > Changes from v4
> > > > > > - Addressed Rob Herring comments on DT parameters and
> > > > > > thermal driver architecture.
> > > > > > - Removed brcm,max-crit-temp DT parameter
> > > > > > - Changed driver to thermal sensor registration model.
> > > > > > - Added trip DT properties.
> > > > > >
> > > > > > Changes from v3
> > > > > > - Addressed Daniel lezcano comments.
> > > > > > - Elaborated commit description of thermal driver patch.
> > > > > > - Added brcm,max-crit-temp DT parameter.
> > > > > >
> > > > > > Changes from v2:
> > > > > > - All stingray TMON DT nodes are combine together into
> > > > > > single.
> > > > > > Temperature registers are combined into one mem resource.
> > > > > > brcm,tmon-mask parameter has available TMONs mask value.
> > > > > > - All available TMONs are initialized together in single
> > > > > > instance of driver probe call.
> > > > > >
> > > > > > Changes from v1:
> > > > > > - Fixed auto build sparce warning.
> > > > > >
> > > > > > Pramod Kumar (3):
> > > > > > dt-bindings: thermal: Add binding document for SR thermal
> > > > > > thermal: broadcom: Add Stingray thermal driver
> > > > > > arm64: dts: stingray: Add Stingray Thermal DT support.
> > > > > >
> > > > > > .../bindings/thermal/brcm,sr-thermal.txt | 105
> > > > > > ++++++++++++++++
> > > > > > .../arm64/boot/dts/broadcom/stingray/stingray.dtsi | 89
> > > > > > +++++++++++++
> > > > > > drivers/thermal/Kconfig | 3 +-
> > > > > > drivers/thermal/broadcom/Kconfig | 9 ++
> > > > > > drivers/thermal/broadcom/Makefile | 1 +
> > > > > > drivers/thermal/broadcom/sr-thermal.c | 138
> > > > > > +++++++++++++++++++++
> > > > > > 6 files changed, 344 insertions(+), 1 deletion(-)
> > > > > > create mode 100644
> > > > > > Documentation/devicetree/bindings/thermal/brcm,sr-thermal.txt
> > > > > > create mode 100644 drivers/thermal/broadcom/sr-thermal.c
> > > > > >
> > > > > --
> > > > > Florian

2019-01-02 22:05:38

by Eduardo Valentin

[permalink] [raw]
Subject: Re: [PATCH v5 2/3] thermal: broadcom: Add Stingray thermal driver

On Tue, Oct 16, 2018 at 08:41:19PM +0530, Srinath Mannam wrote:
> From: Pramod Kumar <[email protected]>
>
> 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 <[email protected]>
> Signed-off-by: Srinath Mannam <[email protected]>
> Reviewed-by: Ray Jui <[email protected]>
> Reviewed-by: Scott Branden <[email protected]>
> Reviewed-by: Vikram Prakash <[email protected]>
> ---
> 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 <linux/acpi.h>
> +#include <linux/module.h>
> +#include <linux/of_address.h>
> +#include <linux/platform_device.h>
> +#include <linux/thermal.h>
> +
> +/*
> + * 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..

+ }
> + 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()?

> +
> + 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 <[email protected]>");
> +MODULE_DESCRIPTION("Stingray thermal driver");
> +MODULE_LICENSE("GPL v2");
> --
> 2.7.4
>

2019-01-03 09:48:37

by Srinath Mannam

[permalink] [raw]
Subject: Re: [PATCH v5 2/3] thermal: broadcom: Add Stingray thermal driver

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 <[email protected]> wrote:
>
> On Tue, Oct 16, 2018 at 08:41:19PM +0530, Srinath Mannam wrote:
> > From: Pramod Kumar <[email protected]>
> >
> > 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 <[email protected]>
> > Signed-off-by: Srinath Mannam <[email protected]>
> > Reviewed-by: Ray Jui <[email protected]>
> > Reviewed-by: Scott Branden <[email protected]>
> > Reviewed-by: Vikram Prakash <[email protected]>
> > ---
> > 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 <linux/acpi.h>
> > +#include <linux/module.h>
> > +#include <linux/of_address.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/thermal.h>
> > +
> > +/*
> > + * 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 <[email protected]>");
> > +MODULE_DESCRIPTION("Stingray thermal driver");
> > +MODULE_LICENSE("GPL v2");
> > --
> > 2.7.4
> >
Regards,
Srinath.