1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Broadcom
6 #include <linux/acpi.h>
7 #include <linux/module.h>
8 #include <linux/of_address.h>
9 #include <linux/platform_device.h>
10 #include <linux/thermal.h>
13 * In stingray thermal IO memory,
14 * Total Number of available TMONs MASK is at offset 0
15 * temperature registers BASE is at 4 byte offset.
16 * Each TMON temperature register size is 4.
18 #define SR_TMON_TEMP_BASE(id) ((id) * 0x4)
20 #define SR_TMON_MAX_LIST 6
23 struct thermal_zone_device *tz;
24 unsigned int crit_temp;
26 struct sr_thermal *priv;
31 unsigned int max_crit_temp;
32 struct sr_tmon tmon[SR_TMON_MAX_LIST];
35 static int sr_get_temp(void *data, int *temp)
37 struct sr_tmon *tmon = data;
38 struct sr_thermal *sr_thermal = tmon->priv;
40 *temp = readl(sr_thermal->regs + SR_TMON_TEMP_BASE(tmon->tmon_id));
45 static const struct thermal_zone_of_device_ops sr_tz_ops = {
46 .get_temp = sr_get_temp,
49 static int sr_thermal_probe(struct platform_device *pdev)
51 struct device *dev = &pdev->dev;
52 struct sr_thermal *sr_thermal;
59 sr_thermal = devm_kzalloc(dev, sizeof(*sr_thermal), GFP_KERNEL);
63 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
64 sr_thermal->regs = (void __iomem *)devm_memremap(&pdev->dev, res->start,
67 if (IS_ERR(sr_thermal->regs)) {
68 dev_err(dev, "failed to get io address\n");
69 return PTR_ERR(sr_thermal->regs);
72 ret = device_property_read_u32(dev, "brcm,tmon-mask", &sr_tmon_list);
76 tmon = sr_thermal->tmon;
77 for (i = 0; i < SR_TMON_MAX_LIST; i++, tmon++) {
78 if (!(sr_tmon_list & BIT(i)))
81 /* Flush temperature registers */
82 writel(0, sr_thermal->regs + SR_TMON_TEMP_BASE(i));
84 tmon->priv = sr_thermal;
85 tmon->tz = devm_thermal_zone_of_sensor_register(dev, i, tmon,
88 return PTR_ERR(tmon->tz);
90 dev_dbg(dev, "thermal sensor %d registered\n", i);
92 platform_set_drvdata(pdev, sr_thermal);
97 static const struct of_device_id sr_thermal_of_match[] = {
98 { .compatible = "brcm,sr-thermal", },
101 MODULE_DEVICE_TABLE(of, sr_thermal_of_match);
103 static const struct acpi_device_id sr_thermal_acpi_ids[] = {
104 { .id = "BRCM0500" },
107 MODULE_DEVICE_TABLE(acpi, sr_thermal_acpi_ids);
109 static struct platform_driver sr_thermal_driver = {
110 .probe = sr_thermal_probe,
112 .name = "sr-thermal",
113 .of_match_table = sr_thermal_of_match,
114 .acpi_match_table = ACPI_PTR(sr_thermal_acpi_ids),
117 module_platform_driver(sr_thermal_driver);
119 MODULE_AUTHOR("Pramod Kumar <pramod.kumar@broadcom.com>");
120 MODULE_DESCRIPTION("Stingray thermal driver");
121 MODULE_LICENSE("GPL v2");