1 /* Lantiq cpu temperature sensor driver
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version
10 * This program is distributed in the hope that it will be useful
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>
19 #include <linux/bitops.h>
20 #include <linux/delay.h>
21 #include <linux/hwmon.h>
22 #include <linux/hwmon-sysfs.h>
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/of_device.h>
27 #include <lantiq_soc.h>
29 /* gphy1 configuration register contains cpu temperature */
30 #define CGU_GPHY1_CR 0x0040
31 #define CGU_TEMP_PD BIT(19)
33 static void ltq_cputemp_enable(void)
35 ltq_cgu_w32(ltq_cgu_r32(CGU_GPHY1_CR) | CGU_TEMP_PD, CGU_GPHY1_CR);
38 static void ltq_cputemp_disable(void *data)
40 ltq_cgu_w32(ltq_cgu_r32(CGU_GPHY1_CR) & ~CGU_TEMP_PD, CGU_GPHY1_CR);
43 static int ltq_read(struct device *dev, enum hwmon_sensor_types type,
44 u32 attr, int channel, long *temp)
49 case hwmon_temp_input:
50 /* get the temperature including one decimal place */
51 value = (ltq_cgu_r32(CGU_GPHY1_CR) >> 9) & 0x01FF;
53 /* range -38 to +154 °C, register value zero is -38.0 °C */
55 /* scale temp to millidegree */
66 static umode_t ltq_is_visible(const void *_data, enum hwmon_sensor_types type,
67 u32 attr, int channel)
69 if (type != hwmon_temp)
73 case hwmon_temp_input:
80 static const u32 ltq_chip_config[] = {
85 static const struct hwmon_channel_info ltq_chip = {
87 .config = ltq_chip_config,
90 static const u32 ltq_temp_config[] = {
95 static const struct hwmon_channel_info ltq_temp = {
97 .config = ltq_temp_config,
100 static const struct hwmon_channel_info *ltq_info[] = {
106 static const struct hwmon_ops ltq_hwmon_ops = {
107 .is_visible = ltq_is_visible,
111 static const struct hwmon_chip_info ltq_chip_info = {
112 .ops = <q_hwmon_ops,
116 static int ltq_cputemp_probe(struct platform_device *pdev)
118 struct device *hwmon_dev;
121 /* available on vr9 v1.2 SoCs only */
122 if (ltq_soc_type() != SOC_TYPE_VR9_2)
125 err = devm_add_action(&pdev->dev, ltq_cputemp_disable, NULL);
129 ltq_cputemp_enable();
131 hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev,
137 if (IS_ERR(hwmon_dev)) {
138 dev_err(&pdev->dev, "Failed to register as hwmon device");
139 return PTR_ERR(hwmon_dev);
145 const struct of_device_id ltq_cputemp_match[] = {
146 { .compatible = "lantiq,cputemp" },
149 MODULE_DEVICE_TABLE(of, ltq_cputemp_match);
151 static struct platform_driver ltq_cputemp_driver = {
152 .probe = ltq_cputemp_probe,
154 .name = "ltq-cputemp",
155 .of_match_table = ltq_cputemp_match,
159 module_platform_driver(ltq_cputemp_driver);
162 MODULE_DESCRIPTION("Lantiq cpu temperature sensor driver");
163 MODULE_LICENSE("GPL");