1 // SPDX-License-Identifier: GPL-2.0-only
6 #include <linux/module.h>
7 #include <linux/of_address.h>
8 #include <linux/platform_device.h>
9 #include <linux/thermal.h>
11 #define PVTMON_CONTROL0 0x00
12 #define PVTMON_CONTROL0_SEL_MASK 0x0000000e
13 #define PVTMON_CONTROL0_SEL_TEMP_MONITOR 0x00000000
14 #define PVTMON_CONTROL0_SEL_TEST_MODE 0x0000000e
15 #define PVTMON_STATUS 0x08
17 static int ns_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
19 void __iomem *pvtmon = thermal_zone_device_priv(tz);
20 int offset = thermal_zone_get_offset(tz);
21 int slope = thermal_zone_get_slope(tz);
24 val = readl(pvtmon + PVTMON_CONTROL0);
25 if ((val & PVTMON_CONTROL0_SEL_MASK) != PVTMON_CONTROL0_SEL_TEMP_MONITOR) {
26 /* Clear current mode selection */
27 val &= ~PVTMON_CONTROL0_SEL_MASK;
29 /* Set temp monitor mode (it's the default actually) */
30 val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;
32 writel(val, pvtmon + PVTMON_CONTROL0);
35 val = readl(pvtmon + PVTMON_STATUS);
36 *temp = slope * val + offset;
41 static const struct thermal_zone_device_ops ns_thermal_ops = {
42 .get_temp = ns_thermal_get_temp,
45 static int ns_thermal_probe(struct platform_device *pdev)
47 struct device *dev = &pdev->dev;
48 struct thermal_zone_device *tz;
51 pvtmon = of_iomap(dev_of_node(dev), 0);
55 tz = devm_thermal_of_zone_register(dev, 0,
63 platform_set_drvdata(pdev, pvtmon);
68 static int ns_thermal_remove(struct platform_device *pdev)
70 void __iomem *pvtmon = platform_get_drvdata(pdev);
77 static const struct of_device_id ns_thermal_of_match[] = {
78 { .compatible = "brcm,ns-thermal", },
81 MODULE_DEVICE_TABLE(of, ns_thermal_of_match);
83 static struct platform_driver ns_thermal_driver = {
84 .probe = ns_thermal_probe,
85 .remove = ns_thermal_remove,
88 .of_match_table = ns_thermal_of_match,
91 module_platform_driver(ns_thermal_driver);
94 MODULE_DESCRIPTION("Northstar thermal driver");
95 MODULE_LICENSE("GPL v2");