1 --- a/drivers/hwmon/Makefile
2 +++ b/drivers/hwmon/Makefile
3 @@ -107,6 +107,7 @@ obj-$(CONFIG_SENSORS_LTC4222) += ltc4222
4 obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o
5 obj-$(CONFIG_SENSORS_LTC4260) += ltc4260.o
6 obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o
7 +obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
8 obj-$(CONFIG_SENSORS_MAX1111) += max1111.o
9 obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
10 obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
11 --- a/drivers/hwmon/Kconfig
12 +++ b/drivers/hwmon/Kconfig
13 @@ -753,6 +753,14 @@ config SENSORS_LTC4261
14 This driver can also be built as a module. If so, the module will
17 +config SENSORS_LTQ_CPUTEMP
18 + bool "Lantiq CPU temperature sensor"
22 + If you say yes here you get support for the temperature
23 + sensor inside your CPU.
25 config SENSORS_MAX1111
26 tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles"
29 +++ b/drivers/hwmon/ltq-cputemp.c
31 +/* Lantiq CPU Temperatur sensor driver for xrx200
33 + * Copyright (C) 2016 Florian Eckert <feckert@tdt.de>
35 + * This program is free software; you can redistribute it and/or modify
36 + * it under the terms of the GNU General Public License as published by
37 + * the Free Software Foundation; either version 2 of the License, or
38 + * (at your option) any later version
40 + * This program is distributed in the hope that it will be useful
41 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 + * GNU General Public License for more details
45 + * You should have received a copy of the GNU General Public License
46 + * along with this program; if not, see <http://www.gnu.org/licenses/>
49 +#include <linux/module.h>
50 +#include <linux/init.h>
51 +#include <linux/delay.h>
52 +#include <linux/of_device.h>
53 +#include <linux/hwmon.h>
54 +#include <linux/hwmon-sysfs.h>
56 +#include <lantiq_soc.h>
58 +/* gphy1 configuration register contains cpu temperature */
59 +#define CGU_GPHY1_CR 0x0040
60 +#define CGU_TEMP_PD BIT(19)
62 +static void ltq_cputemp_enable(void)
64 + ltq_cgu_w32(ltq_cgu_r32(CGU_GPHY1_CR) | CGU_TEMP_PD, CGU_GPHY1_CR);
66 + /* wait a short moment to let the SoC get the first temperatur value */
70 +static void ltq_cputemp_disable(void)
72 + ltq_cgu_w32(ltq_cgu_r32(CGU_GPHY1_CR) & ~CGU_TEMP_PD, CGU_GPHY1_CR);
75 +static int ltq_cputemp_read(void)
79 + /* get the temperature including one decimal place */
80 + value = (ltq_cgu_r32(CGU_GPHY1_CR) >> 9) & 0x01FF;
81 + value = (value << 2 ) + value;
83 + /* range -38 to +154 °C, register value zero is -38.0 °C */
89 +static ssize_t show_cputemp(struct device *dev,
90 + struct device_attribute *attr, char *buf)
94 + value = ltq_cputemp_read();
95 + /* scale temp to millidegree */
96 + value = value * 100;
98 + return sprintf(buf, "%d\n", value);
101 +static DEVICE_ATTR(temp1_input, S_IRUGO, show_cputemp, NULL);
103 +static struct attribute *ltq_cputemp_attrs[] = {
104 + &dev_attr_temp1_input.attr,
108 +ATTRIBUTE_GROUPS(ltq_cputemp);
110 +static int ltq_cputemp_probe(struct platform_device *pdev)
114 + struct device *hwmon_dev;
116 + /* available on vr9 v1.2 SoCs only */
117 + if (ltq_soc_type() != SOC_TYPE_VR9_2)
120 + hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
123 + ltq_cputemp_groups);
125 + if (IS_ERR(hwmon_dev)) {
126 + dev_err(&pdev->dev, "Failed to register as hwmon device");
127 + ret = PTR_ERR(hwmon_dev);
131 + ltq_cputemp_enable();
132 + value = ltq_cputemp_read();
133 + dev_info(&pdev->dev, "Current CPU die temperature: %d.%d °C", value / 10, value % 10);
141 +static int ltq_cputemp_release(struct platform_device *pdev)
143 + hwmon_device_unregister(&pdev->dev);
144 + ltq_cputemp_disable();
148 +const struct of_device_id ltq_cputemp_match[] = {
149 + { .compatible = "lantiq,cputemp" },
152 +MODULE_DEVICE_TABLE(of, ltq_cputemp_match);
154 +static struct platform_driver ltq_cputemp_driver = {
155 + .probe = ltq_cputemp_probe,
156 + .remove = ltq_cputemp_release,
158 + .name = "ltq-cputemp",
159 + .owner = THIS_MODULE,
160 + .of_match_table = ltq_cputemp_match,
164 +int __init init_ltq_cputemp(void)
168 + ret = platform_driver_register(<q_cputemp_driver);
172 +void clean_ltq_cputemp(void)
174 + platform_driver_unregister(<q_cputemp_driver);
178 +module_init(init_ltq_cputemp);
179 +module_exit(clean_ltq_cputemp);
181 +MODULE_AUTHOR("Florian Eckert <feckert@tdt.de>");
183 +MODULE_DESCRIPTION("Lantiq Temperature Sensor");
184 +MODULE_LICENSE("GPL");