Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | */ |
| 9 | |
Anson Huang | 329fe7b | 2013-12-23 15:49:22 -0500 | [diff] [blame] | 10 | #include <linux/clk.h> |
Viresh Kumar | 4d753aa | 2017-04-25 15:57:14 +0530 | [diff] [blame] | 11 | #include <linux/cpufreq.h> |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 12 | #include <linux/cpu_cooling.h> |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 13 | #include <linux/delay.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/init.h> |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 17 | #include <linux/io.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/mfd/syscon.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/of.h> |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 22 | #include <linux/of_device.h> |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/regmap.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/thermal.h> |
| 27 | #include <linux/types.h> |
| 28 | |
| 29 | #define REG_SET 0x4 |
| 30 | #define REG_CLR 0x8 |
| 31 | #define REG_TOG 0xc |
| 32 | |
| 33 | #define MISC0 0x0150 |
| 34 | #define MISC0_REFTOP_SELBIASOFF (1 << 3) |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 35 | #define MISC1 0x0160 |
| 36 | #define MISC1_IRQ_TEMPHIGH (1 << 29) |
| 37 | /* Below LOW and PANIC bits are only for TEMPMON_IMX6SX */ |
| 38 | #define MISC1_IRQ_TEMPLOW (1 << 28) |
| 39 | #define MISC1_IRQ_TEMPPANIC (1 << 27) |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 40 | |
| 41 | #define TEMPSENSE0 0x0180 |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 42 | #define TEMPSENSE0_ALARM_VALUE_SHIFT 20 |
| 43 | #define TEMPSENSE0_ALARM_VALUE_MASK (0xfff << TEMPSENSE0_ALARM_VALUE_SHIFT) |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 44 | #define TEMPSENSE0_TEMP_CNT_SHIFT 8 |
| 45 | #define TEMPSENSE0_TEMP_CNT_MASK (0xfff << TEMPSENSE0_TEMP_CNT_SHIFT) |
| 46 | #define TEMPSENSE0_FINISHED (1 << 2) |
| 47 | #define TEMPSENSE0_MEASURE_TEMP (1 << 1) |
| 48 | #define TEMPSENSE0_POWER_DOWN (1 << 0) |
| 49 | |
| 50 | #define TEMPSENSE1 0x0190 |
| 51 | #define TEMPSENSE1_MEASURE_FREQ 0xffff |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 52 | /* Below TEMPSENSE2 is only for TEMPMON_IMX6SX */ |
| 53 | #define TEMPSENSE2 0x0290 |
| 54 | #define TEMPSENSE2_LOW_VALUE_SHIFT 0 |
| 55 | #define TEMPSENSE2_LOW_VALUE_MASK 0xfff |
| 56 | #define TEMPSENSE2_PANIC_VALUE_SHIFT 16 |
| 57 | #define TEMPSENSE2_PANIC_VALUE_MASK 0xfff0000 |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 58 | |
Tim Harvey | a2291ba | 2015-11-19 06:49:40 -0800 | [diff] [blame] | 59 | #define OCOTP_MEM0 0x0480 |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 60 | #define OCOTP_ANA1 0x04e0 |
| 61 | |
| 62 | /* The driver supports 1 passive trip point and 1 critical trip point */ |
| 63 | enum imx_thermal_trip { |
| 64 | IMX_TRIP_PASSIVE, |
| 65 | IMX_TRIP_CRITICAL, |
| 66 | IMX_TRIP_NUM, |
| 67 | }; |
| 68 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 69 | #define IMX_POLLING_DELAY 2000 /* millisecond */ |
| 70 | #define IMX_PASSIVE_DELAY 1000 |
| 71 | |
Anson Huang | 749e8be | 2014-02-12 18:06:35 +0800 | [diff] [blame] | 72 | #define FACTOR0 10000000 |
| 73 | #define FACTOR1 15976 |
| 74 | #define FACTOR2 4297157 |
| 75 | |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 76 | #define TEMPMON_IMX6Q 1 |
| 77 | #define TEMPMON_IMX6SX 2 |
| 78 | |
| 79 | struct thermal_soc_data { |
| 80 | u32 version; |
| 81 | }; |
| 82 | |
| 83 | static struct thermal_soc_data thermal_imx6q_data = { |
| 84 | .version = TEMPMON_IMX6Q, |
| 85 | }; |
| 86 | |
| 87 | static struct thermal_soc_data thermal_imx6sx_data = { |
| 88 | .version = TEMPMON_IMX6SX, |
| 89 | }; |
| 90 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 91 | struct imx_thermal_data { |
Viresh Kumar | 4d753aa | 2017-04-25 15:57:14 +0530 | [diff] [blame] | 92 | struct cpufreq_policy *policy; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 93 | struct thermal_zone_device *tz; |
| 94 | struct thermal_cooling_device *cdev; |
| 95 | enum thermal_device_mode mode; |
| 96 | struct regmap *tempmon; |
Anson Huang | 749e8be | 2014-02-12 18:06:35 +0800 | [diff] [blame] | 97 | u32 c1, c2; /* See formula in imx_get_sensor_data() */ |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 98 | int temp_passive; |
| 99 | int temp_critical; |
Tim Harvey | a2291ba | 2015-11-19 06:49:40 -0800 | [diff] [blame] | 100 | int temp_max; |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 101 | int alarm_temp; |
| 102 | int last_temp; |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 103 | bool irq_enabled; |
| 104 | int irq; |
Anson Huang | 329fe7b | 2013-12-23 15:49:22 -0500 | [diff] [blame] | 105 | struct clk *thermal_clk; |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 106 | const struct thermal_soc_data *socdata; |
Tim Harvey | a2291ba | 2015-11-19 06:49:40 -0800 | [diff] [blame] | 107 | const char *temp_grade; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 108 | }; |
| 109 | |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 110 | static void imx_set_panic_temp(struct imx_thermal_data *data, |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 111 | int panic_temp) |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 112 | { |
| 113 | struct regmap *map = data->tempmon; |
| 114 | int critical_value; |
| 115 | |
| 116 | critical_value = (data->c2 - panic_temp) / data->c1; |
| 117 | regmap_write(map, TEMPSENSE2 + REG_CLR, TEMPSENSE2_PANIC_VALUE_MASK); |
| 118 | regmap_write(map, TEMPSENSE2 + REG_SET, critical_value << |
| 119 | TEMPSENSE2_PANIC_VALUE_SHIFT); |
| 120 | } |
| 121 | |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 122 | static void imx_set_alarm_temp(struct imx_thermal_data *data, |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 123 | int alarm_temp) |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 124 | { |
| 125 | struct regmap *map = data->tempmon; |
| 126 | int alarm_value; |
| 127 | |
| 128 | data->alarm_temp = alarm_temp; |
Anson Huang | 749e8be | 2014-02-12 18:06:35 +0800 | [diff] [blame] | 129 | alarm_value = (data->c2 - alarm_temp) / data->c1; |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 130 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_ALARM_VALUE_MASK); |
| 131 | regmap_write(map, TEMPSENSE0 + REG_SET, alarm_value << |
| 132 | TEMPSENSE0_ALARM_VALUE_SHIFT); |
| 133 | } |
| 134 | |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 135 | static int imx_get_temp(struct thermal_zone_device *tz, int *temp) |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 136 | { |
| 137 | struct imx_thermal_data *data = tz->devdata; |
| 138 | struct regmap *map = data->tempmon; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 139 | unsigned int n_meas; |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 140 | bool wait; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 141 | u32 val; |
| 142 | |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 143 | if (data->mode == THERMAL_DEVICE_ENABLED) { |
| 144 | /* Check if a measurement is currently in progress */ |
| 145 | regmap_read(map, TEMPSENSE0, &val); |
| 146 | wait = !(val & TEMPSENSE0_FINISHED); |
| 147 | } else { |
| 148 | /* |
| 149 | * Every time we measure the temperature, we will power on the |
| 150 | * temperature sensor, enable measurements, take a reading, |
| 151 | * disable measurements, power off the temperature sensor. |
| 152 | */ |
| 153 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); |
| 154 | regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); |
| 155 | |
| 156 | wait = true; |
| 157 | } |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * According to the temp sensor designers, it may require up to ~17us |
| 161 | * to complete a measurement. |
| 162 | */ |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 163 | if (wait) |
| 164 | usleep_range(20, 50); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 165 | |
| 166 | regmap_read(map, TEMPSENSE0, &val); |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 167 | |
| 168 | if (data->mode != THERMAL_DEVICE_ENABLED) { |
| 169 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); |
| 170 | regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); |
| 171 | } |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 172 | |
| 173 | if ((val & TEMPSENSE0_FINISHED) == 0) { |
| 174 | dev_dbg(&tz->device, "temp measurement never finished\n"); |
| 175 | return -EAGAIN; |
| 176 | } |
| 177 | |
| 178 | n_meas = (val & TEMPSENSE0_TEMP_CNT_MASK) >> TEMPSENSE0_TEMP_CNT_SHIFT; |
| 179 | |
| 180 | /* See imx_get_sensor_data() for formula derivation */ |
Anson Huang | 749e8be | 2014-02-12 18:06:35 +0800 | [diff] [blame] | 181 | *temp = data->c2 - n_meas * data->c1; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 182 | |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 183 | /* Update alarm value to next higher trip point for TEMPMON_IMX6Q */ |
| 184 | if (data->socdata->version == TEMPMON_IMX6Q) { |
| 185 | if (data->alarm_temp == data->temp_passive && |
| 186 | *temp >= data->temp_passive) |
| 187 | imx_set_alarm_temp(data, data->temp_critical); |
| 188 | if (data->alarm_temp == data->temp_critical && |
| 189 | *temp < data->temp_passive) { |
| 190 | imx_set_alarm_temp(data, data->temp_passive); |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 191 | dev_dbg(&tz->device, "thermal alarm off: T < %d\n", |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 192 | data->alarm_temp / 1000); |
| 193 | } |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | if (*temp != data->last_temp) { |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 197 | dev_dbg(&tz->device, "millicelsius: %d\n", *temp); |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 198 | data->last_temp = *temp; |
| 199 | } |
| 200 | |
| 201 | /* Reenable alarm IRQ if temperature below alarm temperature */ |
| 202 | if (!data->irq_enabled && *temp < data->alarm_temp) { |
| 203 | data->irq_enabled = true; |
| 204 | enable_irq(data->irq); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | static int imx_get_mode(struct thermal_zone_device *tz, |
| 211 | enum thermal_device_mode *mode) |
| 212 | { |
| 213 | struct imx_thermal_data *data = tz->devdata; |
| 214 | |
| 215 | *mode = data->mode; |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static int imx_set_mode(struct thermal_zone_device *tz, |
| 221 | enum thermal_device_mode mode) |
| 222 | { |
| 223 | struct imx_thermal_data *data = tz->devdata; |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 224 | struct regmap *map = data->tempmon; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 225 | |
| 226 | if (mode == THERMAL_DEVICE_ENABLED) { |
| 227 | tz->polling_delay = IMX_POLLING_DELAY; |
| 228 | tz->passive_delay = IMX_PASSIVE_DELAY; |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 229 | |
| 230 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); |
| 231 | regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); |
| 232 | |
| 233 | if (!data->irq_enabled) { |
| 234 | data->irq_enabled = true; |
| 235 | enable_irq(data->irq); |
| 236 | } |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 237 | } else { |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 238 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); |
| 239 | regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); |
| 240 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 241 | tz->polling_delay = 0; |
| 242 | tz->passive_delay = 0; |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 243 | |
| 244 | if (data->irq_enabled) { |
| 245 | disable_irq(data->irq); |
| 246 | data->irq_enabled = false; |
| 247 | } |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | data->mode = mode; |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 251 | thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static int imx_get_trip_type(struct thermal_zone_device *tz, int trip, |
| 257 | enum thermal_trip_type *type) |
| 258 | { |
| 259 | *type = (trip == IMX_TRIP_PASSIVE) ? THERMAL_TRIP_PASSIVE : |
| 260 | THERMAL_TRIP_CRITICAL; |
| 261 | return 0; |
| 262 | } |
| 263 | |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 264 | static int imx_get_crit_temp(struct thermal_zone_device *tz, int *temp) |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 265 | { |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 266 | struct imx_thermal_data *data = tz->devdata; |
| 267 | |
| 268 | *temp = data->temp_critical; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static int imx_get_trip_temp(struct thermal_zone_device *tz, int trip, |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 273 | int *temp) |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 274 | { |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 275 | struct imx_thermal_data *data = tz->devdata; |
| 276 | |
| 277 | *temp = (trip == IMX_TRIP_PASSIVE) ? data->temp_passive : |
| 278 | data->temp_critical; |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip, |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 283 | int temp) |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 284 | { |
| 285 | struct imx_thermal_data *data = tz->devdata; |
| 286 | |
Tim Harvey | a2291ba | 2015-11-19 06:49:40 -0800 | [diff] [blame] | 287 | /* do not allow changing critical threshold */ |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 288 | if (trip == IMX_TRIP_CRITICAL) |
| 289 | return -EPERM; |
| 290 | |
Tim Harvey | a2291ba | 2015-11-19 06:49:40 -0800 | [diff] [blame] | 291 | /* do not allow passive to be set higher than critical */ |
| 292 | if (temp < 0 || temp > data->temp_critical) |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 293 | return -EINVAL; |
| 294 | |
| 295 | data->temp_passive = temp; |
| 296 | |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 297 | imx_set_alarm_temp(data, temp); |
| 298 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static int imx_bind(struct thermal_zone_device *tz, |
| 303 | struct thermal_cooling_device *cdev) |
| 304 | { |
| 305 | int ret; |
| 306 | |
| 307 | ret = thermal_zone_bind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev, |
| 308 | THERMAL_NO_LIMIT, |
Kapileshwar Singh | 6cd9e9f | 2015-02-18 16:04:21 +0000 | [diff] [blame] | 309 | THERMAL_NO_LIMIT, |
| 310 | THERMAL_WEIGHT_DEFAULT); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 311 | if (ret) { |
| 312 | dev_err(&tz->device, |
| 313 | "binding zone %s with cdev %s failed:%d\n", |
| 314 | tz->type, cdev->type, ret); |
| 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static int imx_unbind(struct thermal_zone_device *tz, |
| 322 | struct thermal_cooling_device *cdev) |
| 323 | { |
| 324 | int ret; |
| 325 | |
| 326 | ret = thermal_zone_unbind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev); |
| 327 | if (ret) { |
| 328 | dev_err(&tz->device, |
| 329 | "unbinding zone %s with cdev %s failed:%d\n", |
| 330 | tz->type, cdev->type, ret); |
| 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
Eduardo Valentin | cbb07bb | 2014-01-06 08:54:34 -0400 | [diff] [blame] | 337 | static struct thermal_zone_device_ops imx_tz_ops = { |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 338 | .bind = imx_bind, |
| 339 | .unbind = imx_unbind, |
| 340 | .get_temp = imx_get_temp, |
| 341 | .get_mode = imx_get_mode, |
| 342 | .set_mode = imx_set_mode, |
| 343 | .get_trip_type = imx_get_trip_type, |
| 344 | .get_trip_temp = imx_get_trip_temp, |
| 345 | .get_crit_temp = imx_get_crit_temp, |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 346 | .set_trip_temp = imx_set_trip_temp, |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | static int imx_get_sensor_data(struct platform_device *pdev) |
| 350 | { |
| 351 | struct imx_thermal_data *data = platform_get_drvdata(pdev); |
| 352 | struct regmap *map; |
Anson Huang | d0f9d64 | 2014-06-20 15:03:06 +0800 | [diff] [blame] | 353 | int t1, n1; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 354 | int ret; |
| 355 | u32 val; |
Anson Huang | 749e8be | 2014-02-12 18:06:35 +0800 | [diff] [blame] | 356 | u64 temp64; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 357 | |
| 358 | map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, |
| 359 | "fsl,tempmon-data"); |
| 360 | if (IS_ERR(map)) { |
| 361 | ret = PTR_ERR(map); |
| 362 | dev_err(&pdev->dev, "failed to get sensor regmap: %d\n", ret); |
| 363 | return ret; |
| 364 | } |
| 365 | |
| 366 | ret = regmap_read(map, OCOTP_ANA1, &val); |
| 367 | if (ret) { |
| 368 | dev_err(&pdev->dev, "failed to read sensor data: %d\n", ret); |
| 369 | return ret; |
| 370 | } |
| 371 | |
| 372 | if (val == 0 || val == ~0) { |
| 373 | dev_err(&pdev->dev, "invalid sensor calibration data\n"); |
| 374 | return -EINVAL; |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | * Sensor data layout: |
| 379 | * [31:20] - sensor value @ 25C |
Anson Huang | 749e8be | 2014-02-12 18:06:35 +0800 | [diff] [blame] | 380 | * Use universal formula now and only need sensor value @ 25C |
| 381 | * slope = 0.4297157 - (0.0015976 * 25C fuse) |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 382 | */ |
| 383 | n1 = val >> 20; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 384 | t1 = 25; /* t1 always 25C */ |
| 385 | |
| 386 | /* |
Anson Huang | 749e8be | 2014-02-12 18:06:35 +0800 | [diff] [blame] | 387 | * Derived from linear interpolation: |
| 388 | * slope = 0.4297157 - (0.0015976 * 25C fuse) |
| 389 | * slope = (FACTOR2 - FACTOR1 * n1) / FACTOR0 |
| 390 | * (Nmeas - n1) / (Tmeas - t1) = slope |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 391 | * We want to reduce this down to the minimum computation necessary |
| 392 | * for each temperature read. Also, we want Tmeas in millicelsius |
| 393 | * and we don't want to lose precision from integer division. So... |
Anson Huang | 749e8be | 2014-02-12 18:06:35 +0800 | [diff] [blame] | 394 | * Tmeas = (Nmeas - n1) / slope + t1 |
| 395 | * milli_Tmeas = 1000 * (Nmeas - n1) / slope + 1000 * t1 |
| 396 | * milli_Tmeas = -1000 * (n1 - Nmeas) / slope + 1000 * t1 |
| 397 | * Let constant c1 = (-1000 / slope) |
| 398 | * milli_Tmeas = (n1 - Nmeas) * c1 + 1000 * t1 |
| 399 | * Let constant c2 = n1 *c1 + 1000 * t1 |
| 400 | * milli_Tmeas = c2 - Nmeas * c1 |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 401 | */ |
Anson Huang | 749e8be | 2014-02-12 18:06:35 +0800 | [diff] [blame] | 402 | temp64 = FACTOR0; |
| 403 | temp64 *= 1000; |
| 404 | do_div(temp64, FACTOR1 * n1 - FACTOR2); |
| 405 | data->c1 = temp64; |
| 406 | data->c2 = n1 * data->c1 + 1000 * t1; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 407 | |
Tim Harvey | a2291ba | 2015-11-19 06:49:40 -0800 | [diff] [blame] | 408 | /* use OTP for thermal grade */ |
| 409 | ret = regmap_read(map, OCOTP_MEM0, &val); |
| 410 | if (ret) { |
| 411 | dev_err(&pdev->dev, "failed to read temp grade: %d\n", ret); |
| 412 | return ret; |
| 413 | } |
| 414 | |
| 415 | /* The maximum die temp is specified by the Temperature Grade */ |
| 416 | switch ((val >> 6) & 0x3) { |
| 417 | case 0: /* Commercial (0 to 95C) */ |
| 418 | data->temp_grade = "Commercial"; |
| 419 | data->temp_max = 95000; |
| 420 | break; |
| 421 | case 1: /* Extended Commercial (-20 to 105C) */ |
| 422 | data->temp_grade = "Extended Commercial"; |
| 423 | data->temp_max = 105000; |
| 424 | break; |
| 425 | case 2: /* Industrial (-40 to 105C) */ |
| 426 | data->temp_grade = "Industrial"; |
| 427 | data->temp_max = 105000; |
| 428 | break; |
| 429 | case 3: /* Automotive (-40 to 125C) */ |
| 430 | data->temp_grade = "Automotive"; |
| 431 | data->temp_max = 125000; |
| 432 | break; |
| 433 | } |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 434 | |
| 435 | /* |
Tim Harvey | a2291ba | 2015-11-19 06:49:40 -0800 | [diff] [blame] | 436 | * Set the critical trip point at 5C under max |
| 437 | * Set the passive trip point at 10C under max (can change via sysfs) |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 438 | */ |
Tim Harvey | a2291ba | 2015-11-19 06:49:40 -0800 | [diff] [blame] | 439 | data->temp_critical = data->temp_max - (1000 * 5); |
| 440 | data->temp_passive = data->temp_max - (1000 * 10); |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 441 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 445 | static irqreturn_t imx_thermal_alarm_irq(int irq, void *dev) |
| 446 | { |
| 447 | struct imx_thermal_data *data = dev; |
| 448 | |
| 449 | disable_irq_nosync(irq); |
| 450 | data->irq_enabled = false; |
| 451 | |
| 452 | return IRQ_WAKE_THREAD; |
| 453 | } |
| 454 | |
| 455 | static irqreturn_t imx_thermal_alarm_irq_thread(int irq, void *dev) |
| 456 | { |
| 457 | struct imx_thermal_data *data = dev; |
| 458 | |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 459 | dev_dbg(&data->tz->device, "THERMAL ALARM: T > %d\n", |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 460 | data->alarm_temp / 1000); |
| 461 | |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 462 | thermal_zone_device_update(data->tz, THERMAL_EVENT_UNSPECIFIED); |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 463 | |
| 464 | return IRQ_HANDLED; |
| 465 | } |
| 466 | |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 467 | static const struct of_device_id of_imx_thermal_match[] = { |
| 468 | { .compatible = "fsl,imx6q-tempmon", .data = &thermal_imx6q_data, }, |
| 469 | { .compatible = "fsl,imx6sx-tempmon", .data = &thermal_imx6sx_data, }, |
| 470 | { /* end */ } |
| 471 | }; |
| 472 | MODULE_DEVICE_TABLE(of, of_imx_thermal_match); |
| 473 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 474 | static int imx_thermal_probe(struct platform_device *pdev) |
| 475 | { |
| 476 | struct imx_thermal_data *data; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 477 | struct regmap *map; |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 478 | int measure_freq; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 479 | int ret; |
| 480 | |
| 481 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
| 482 | if (!data) |
| 483 | return -ENOMEM; |
| 484 | |
| 485 | map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "fsl,tempmon"); |
| 486 | if (IS_ERR(map)) { |
| 487 | ret = PTR_ERR(map); |
| 488 | dev_err(&pdev->dev, "failed to get tempmon regmap: %d\n", ret); |
| 489 | return ret; |
| 490 | } |
| 491 | data->tempmon = map; |
| 492 | |
Corentin LABBE | 829bc78a | 2016-08-16 10:51:38 +0200 | [diff] [blame] | 493 | data->socdata = of_device_get_match_data(&pdev->dev); |
Shailendra Verma | 8b051ec | 2017-01-30 10:34:58 +0530 | [diff] [blame] | 494 | if (!data->socdata) { |
| 495 | dev_err(&pdev->dev, "no device match found\n"); |
| 496 | return -ENODEV; |
| 497 | } |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 498 | |
| 499 | /* make sure the IRQ flag is clear before enabling irq on i.MX6SX */ |
| 500 | if (data->socdata->version == TEMPMON_IMX6SX) { |
| 501 | regmap_write(map, MISC1 + REG_CLR, MISC1_IRQ_TEMPHIGH | |
| 502 | MISC1_IRQ_TEMPLOW | MISC1_IRQ_TEMPPANIC); |
| 503 | /* |
| 504 | * reset value of LOW ALARM is incorrect, set it to lowest |
| 505 | * value to avoid false trigger of low alarm. |
| 506 | */ |
| 507 | regmap_write(map, TEMPSENSE2 + REG_SET, |
| 508 | TEMPSENSE2_LOW_VALUE_MASK); |
| 509 | } |
| 510 | |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 511 | data->irq = platform_get_irq(pdev, 0); |
| 512 | if (data->irq < 0) |
| 513 | return data->irq; |
| 514 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 515 | platform_set_drvdata(pdev, data); |
| 516 | |
| 517 | ret = imx_get_sensor_data(pdev); |
| 518 | if (ret) { |
| 519 | dev_err(&pdev->dev, "failed to get sensor data\n"); |
| 520 | return ret; |
| 521 | } |
| 522 | |
| 523 | /* Make sure sensor is in known good state for measurements */ |
| 524 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); |
| 525 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); |
| 526 | regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ); |
| 527 | regmap_write(map, MISC0 + REG_SET, MISC0_REFTOP_SELBIASOFF); |
| 528 | regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); |
| 529 | |
Viresh Kumar | 4d753aa | 2017-04-25 15:57:14 +0530 | [diff] [blame] | 530 | data->policy = cpufreq_cpu_get(0); |
| 531 | if (!data->policy) { |
| 532 | pr_debug("%s: CPUFreq policy not found\n", __func__); |
| 533 | return -EPROBE_DEFER; |
| 534 | } |
| 535 | |
| 536 | data->cdev = cpufreq_cooling_register(data->policy); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 537 | if (IS_ERR(data->cdev)) { |
| 538 | ret = PTR_ERR(data->cdev); |
Viresh Kumar | 4d753aa | 2017-04-25 15:57:14 +0530 | [diff] [blame] | 539 | dev_err(&pdev->dev, |
| 540 | "failed to register cpufreq cooling device: %d\n", ret); |
| 541 | cpufreq_cpu_put(data->policy); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 542 | return ret; |
| 543 | } |
| 544 | |
Heiner Kallweit | 90a21ff | 2014-11-08 20:35:54 +0100 | [diff] [blame] | 545 | data->thermal_clk = devm_clk_get(&pdev->dev, NULL); |
| 546 | if (IS_ERR(data->thermal_clk)) { |
| 547 | ret = PTR_ERR(data->thermal_clk); |
| 548 | if (ret != -EPROBE_DEFER) |
| 549 | dev_err(&pdev->dev, |
| 550 | "failed to get thermal clk: %d\n", ret); |
| 551 | cpufreq_cooling_unregister(data->cdev); |
Viresh Kumar | 4d753aa | 2017-04-25 15:57:14 +0530 | [diff] [blame] | 552 | cpufreq_cpu_put(data->policy); |
Heiner Kallweit | 90a21ff | 2014-11-08 20:35:54 +0100 | [diff] [blame] | 553 | return ret; |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | * Thermal sensor needs clk on to get correct value, normally |
| 558 | * we should enable its clk before taking measurement and disable |
| 559 | * clk after measurement is done, but if alarm function is enabled, |
| 560 | * hardware will auto measure the temperature periodically, so we |
| 561 | * need to keep the clk always on for alarm function. |
| 562 | */ |
| 563 | ret = clk_prepare_enable(data->thermal_clk); |
| 564 | if (ret) { |
| 565 | dev_err(&pdev->dev, "failed to enable thermal clk: %d\n", ret); |
| 566 | cpufreq_cooling_unregister(data->cdev); |
Viresh Kumar | 4d753aa | 2017-04-25 15:57:14 +0530 | [diff] [blame] | 567 | cpufreq_cpu_put(data->policy); |
Heiner Kallweit | 90a21ff | 2014-11-08 20:35:54 +0100 | [diff] [blame] | 568 | return ret; |
| 569 | } |
| 570 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 571 | data->tz = thermal_zone_device_register("imx_thermal_zone", |
Philipp Zabel | 017e514 | 2013-08-01 18:33:11 +0200 | [diff] [blame] | 572 | IMX_TRIP_NUM, |
| 573 | BIT(IMX_TRIP_PASSIVE), data, |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 574 | &imx_tz_ops, NULL, |
| 575 | IMX_PASSIVE_DELAY, |
| 576 | IMX_POLLING_DELAY); |
| 577 | if (IS_ERR(data->tz)) { |
| 578 | ret = PTR_ERR(data->tz); |
| 579 | dev_err(&pdev->dev, |
| 580 | "failed to register thermal zone device %d\n", ret); |
Heiner Kallweit | 90a21ff | 2014-11-08 20:35:54 +0100 | [diff] [blame] | 581 | clk_disable_unprepare(data->thermal_clk); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 582 | cpufreq_cooling_unregister(data->cdev); |
Viresh Kumar | 4d753aa | 2017-04-25 15:57:14 +0530 | [diff] [blame] | 583 | cpufreq_cpu_put(data->policy); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 584 | return ret; |
| 585 | } |
| 586 | |
Tim Harvey | a2291ba | 2015-11-19 06:49:40 -0800 | [diff] [blame] | 587 | dev_info(&pdev->dev, "%s CPU temperature grade - max:%dC" |
| 588 | " critical:%dC passive:%dC\n", data->temp_grade, |
| 589 | data->temp_max / 1000, data->temp_critical / 1000, |
| 590 | data->temp_passive / 1000); |
| 591 | |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 592 | /* Enable measurements at ~ 10 Hz */ |
| 593 | regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ); |
| 594 | measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */ |
| 595 | regmap_write(map, TEMPSENSE1 + REG_SET, measure_freq); |
| 596 | imx_set_alarm_temp(data, data->temp_passive); |
Anson Huang | 3c94f17 | 2014-08-06 15:12:09 +0800 | [diff] [blame] | 597 | |
| 598 | if (data->socdata->version == TEMPMON_IMX6SX) |
| 599 | imx_set_panic_temp(data, data->temp_critical); |
| 600 | |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 601 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); |
| 602 | regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); |
| 603 | |
Bai Ping | 84866ee | 2015-09-14 19:09:51 +0800 | [diff] [blame] | 604 | ret = devm_request_threaded_irq(&pdev->dev, data->irq, |
| 605 | imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, |
| 606 | 0, "imx_thermal", data); |
| 607 | if (ret < 0) { |
| 608 | dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); |
| 609 | clk_disable_unprepare(data->thermal_clk); |
| 610 | thermal_zone_device_unregister(data->tz); |
| 611 | cpufreq_cooling_unregister(data->cdev); |
Viresh Kumar | 4d753aa | 2017-04-25 15:57:14 +0530 | [diff] [blame] | 612 | cpufreq_cpu_put(data->policy); |
Bai Ping | 84866ee | 2015-09-14 19:09:51 +0800 | [diff] [blame] | 613 | return ret; |
| 614 | } |
| 615 | |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 616 | data->irq_enabled = true; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 617 | data->mode = THERMAL_DEVICE_ENABLED; |
| 618 | |
| 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | static int imx_thermal_remove(struct platform_device *pdev) |
| 623 | { |
| 624 | struct imx_thermal_data *data = platform_get_drvdata(pdev); |
Philipp Zabel | 37713a1 | 2013-08-01 18:33:12 +0200 | [diff] [blame] | 625 | struct regmap *map = data->tempmon; |
| 626 | |
| 627 | /* Disable measurements */ |
| 628 | regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); |
Anson Huang | 329fe7b | 2013-12-23 15:49:22 -0500 | [diff] [blame] | 629 | if (!IS_ERR(data->thermal_clk)) |
| 630 | clk_disable_unprepare(data->thermal_clk); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 631 | |
| 632 | thermal_zone_device_unregister(data->tz); |
| 633 | cpufreq_cooling_unregister(data->cdev); |
Viresh Kumar | 4d753aa | 2017-04-25 15:57:14 +0530 | [diff] [blame] | 634 | cpufreq_cpu_put(data->policy); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | #ifdef CONFIG_PM_SLEEP |
| 640 | static int imx_thermal_suspend(struct device *dev) |
| 641 | { |
| 642 | struct imx_thermal_data *data = dev_get_drvdata(dev); |
| 643 | struct regmap *map = data->tempmon; |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 644 | |
Anson Huang | b46cce5 | 2013-12-24 09:43:24 -0500 | [diff] [blame] | 645 | /* |
| 646 | * Need to disable thermal sensor, otherwise, when thermal core |
| 647 | * try to get temperature before thermal sensor resume, a wrong |
| 648 | * temperature will be read as the thermal sensor is powered |
| 649 | * down. |
| 650 | */ |
| 651 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); |
| 652 | regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); |
| 653 | data->mode = THERMAL_DEVICE_DISABLED; |
Anson Huang | d26eef8 | 2015-01-06 18:50:22 +0800 | [diff] [blame] | 654 | clk_disable_unprepare(data->thermal_clk); |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static int imx_thermal_resume(struct device *dev) |
| 660 | { |
Anson Huang | b46cce5 | 2013-12-24 09:43:24 -0500 | [diff] [blame] | 661 | struct imx_thermal_data *data = dev_get_drvdata(dev); |
| 662 | struct regmap *map = data->tempmon; |
Arvind Yadav | e3bdc8d | 2017-06-06 15:12:37 +0530 | [diff] [blame] | 663 | int ret; |
Anson Huang | b46cce5 | 2013-12-24 09:43:24 -0500 | [diff] [blame] | 664 | |
Arvind Yadav | e3bdc8d | 2017-06-06 15:12:37 +0530 | [diff] [blame] | 665 | ret = clk_prepare_enable(data->thermal_clk); |
| 666 | if (ret) |
| 667 | return ret; |
Anson Huang | b46cce5 | 2013-12-24 09:43:24 -0500 | [diff] [blame] | 668 | /* Enabled thermal sensor after resume */ |
| 669 | regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); |
| 670 | regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); |
| 671 | data->mode = THERMAL_DEVICE_ENABLED; |
| 672 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 673 | return 0; |
| 674 | } |
| 675 | #endif |
| 676 | |
| 677 | static SIMPLE_DEV_PM_OPS(imx_thermal_pm_ops, |
| 678 | imx_thermal_suspend, imx_thermal_resume); |
| 679 | |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 680 | static struct platform_driver imx_thermal = { |
| 681 | .driver = { |
| 682 | .name = "imx_thermal", |
Shawn Guo | ca3de46 | 2013-06-24 14:30:44 +0800 | [diff] [blame] | 683 | .pm = &imx_thermal_pm_ops, |
| 684 | .of_match_table = of_imx_thermal_match, |
| 685 | }, |
| 686 | .probe = imx_thermal_probe, |
| 687 | .remove = imx_thermal_remove, |
| 688 | }; |
| 689 | module_platform_driver(imx_thermal); |
| 690 | |
| 691 | MODULE_AUTHOR("Freescale Semiconductor, Inc."); |
| 692 | MODULE_DESCRIPTION("Thermal driver for Freescale i.MX SoCs"); |
| 693 | MODULE_LICENSE("GPL v2"); |
| 694 | MODULE_ALIAS("platform:imx-thermal"); |