Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 1 | /* |
Amit Daniel Kachhap | 59dfa54 | 2013-06-24 16:20:26 +0530 | [diff] [blame] | 2 | * exynos_tmu.c - Samsung EXYNOS TMU (Thermal Management Unit) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2011 Samsung Electronics |
| 5 | * Donggeun Kim <dg77.kim@samsung.com> |
Amit Daniel Kachhap | c48cbba | 2012-08-16 17:11:41 +0530 | [diff] [blame] | 6 | * Amit Daniel Kachhap <amit.kachhap@linaro.org> |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 24 | #include <linux/clk.h> |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 25 | #include <linux/io.h> |
Amit Daniel Kachhap | 1b67864 | 2013-06-24 16:20:25 +0530 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/module.h> |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 28 | #include <linux/of.h> |
Amit Daniel Kachhap | 1b67864 | 2013-06-24 16:20:25 +0530 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
Amit Daniel Kachhap | 1b67864 | 2013-06-24 16:20:25 +0530 | [diff] [blame] | 30 | |
| 31 | #include "exynos_thermal_common.h" |
Amit Daniel Kachhap | 0c1836a | 2013-06-24 16:20:27 +0530 | [diff] [blame] | 32 | #include "exynos_tmu.h" |
Amit Daniel Kachhap | e6b7991 | 2013-06-24 16:20:28 +0530 | [diff] [blame] | 33 | #include "exynos_tmu_data.h" |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 34 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 35 | struct exynos_tmu_data { |
| 36 | struct exynos_tmu_platform_data *pdata; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 37 | struct resource *mem; |
| 38 | void __iomem *base; |
| 39 | int irq; |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 40 | enum soc_type soc; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 41 | struct work_struct irq_work; |
| 42 | struct mutex lock; |
| 43 | struct clk *clk; |
| 44 | u8 temp_error1, temp_error2; |
| 45 | }; |
| 46 | |
| 47 | /* |
| 48 | * TMU treats temperature as a mapped temperature code. |
| 49 | * The temperature is converted differently depending on the calibration type. |
| 50 | */ |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 51 | static int temp_to_code(struct exynos_tmu_data *data, u8 temp) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 52 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 53 | struct exynos_tmu_platform_data *pdata = data->pdata; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 54 | int temp_code; |
| 55 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 56 | if (data->soc == SOC_ARCH_EXYNOS4210) |
| 57 | /* temp should range between 25 and 125 */ |
| 58 | if (temp < 25 || temp > 125) { |
| 59 | temp_code = -EINVAL; |
| 60 | goto out; |
| 61 | } |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 62 | |
| 63 | switch (pdata->cal_type) { |
| 64 | case TYPE_TWO_POINT_TRIMMING: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 65 | temp_code = (temp - pdata->first_point_trim) * |
| 66 | (data->temp_error2 - data->temp_error1) / |
| 67 | (pdata->second_point_trim - pdata->first_point_trim) + |
| 68 | data->temp_error1; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 69 | break; |
| 70 | case TYPE_ONE_POINT_TRIMMING: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 71 | temp_code = temp + data->temp_error1 - pdata->first_point_trim; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 72 | break; |
| 73 | default: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 74 | temp_code = temp + pdata->default_temp_offset; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 75 | break; |
| 76 | } |
| 77 | out: |
| 78 | return temp_code; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * Calculate a temperature value from a temperature code. |
| 83 | * The unit of the temperature is degree Celsius. |
| 84 | */ |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 85 | static int code_to_temp(struct exynos_tmu_data *data, u8 temp_code) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 86 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 87 | struct exynos_tmu_platform_data *pdata = data->pdata; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 88 | int temp; |
| 89 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 90 | if (data->soc == SOC_ARCH_EXYNOS4210) |
| 91 | /* temp_code should range between 75 and 175 */ |
| 92 | if (temp_code < 75 || temp_code > 175) { |
| 93 | temp = -ENODATA; |
| 94 | goto out; |
| 95 | } |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 96 | |
| 97 | switch (pdata->cal_type) { |
| 98 | case TYPE_TWO_POINT_TRIMMING: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 99 | temp = (temp_code - data->temp_error1) * |
| 100 | (pdata->second_point_trim - pdata->first_point_trim) / |
| 101 | (data->temp_error2 - data->temp_error1) + |
| 102 | pdata->first_point_trim; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 103 | break; |
| 104 | case TYPE_ONE_POINT_TRIMMING: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 105 | temp = temp_code - data->temp_error1 + pdata->first_point_trim; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 106 | break; |
| 107 | default: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 108 | temp = temp_code - pdata->default_temp_offset; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 109 | break; |
| 110 | } |
| 111 | out: |
| 112 | return temp; |
| 113 | } |
| 114 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 115 | static int exynos_tmu_initialize(struct platform_device *pdev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 116 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 117 | struct exynos_tmu_data *data = platform_get_drvdata(pdev); |
| 118 | struct exynos_tmu_platform_data *pdata = data->pdata; |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 119 | const struct exynos_tmu_registers *reg = pdata->registers; |
Amit Daniel Kachhap | 7ca04e5 | 2013-06-24 16:20:32 +0530 | [diff] [blame] | 120 | unsigned int status, trim_info = 0, con; |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 121 | unsigned int rising_threshold = 0, falling_threshold = 0; |
| 122 | int ret = 0, threshold_code, i, trigger_levs = 0; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 123 | |
| 124 | mutex_lock(&data->lock); |
| 125 | clk_enable(data->clk); |
| 126 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 127 | status = readb(data->base + reg->tmu_status); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 128 | if (!status) { |
| 129 | ret = -EBUSY; |
| 130 | goto out; |
| 131 | } |
| 132 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 133 | if (data->soc == SOC_ARCH_EXYNOS) |
| 134 | __raw_writel(1, data->base + reg->triminfo_ctrl); |
| 135 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 136 | /* Save trimming info in order to perform calibration */ |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 137 | trim_info = readl(data->base + reg->triminfo_data); |
| 138 | data->temp_error1 = trim_info & EXYNOS_TMU_TEMP_MASK; |
| 139 | data->temp_error2 = ((trim_info >> reg->triminfo_85_shift) & |
| 140 | EXYNOS_TMU_TEMP_MASK); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 141 | |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 142 | if ((pdata->min_efuse_value > data->temp_error1) || |
| 143 | (data->temp_error1 > pdata->max_efuse_value) || |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 144 | (data->temp_error2 != 0)) |
| 145 | data->temp_error1 = pdata->efuse_value; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 146 | |
Amit Daniel Kachhap | 7ca04e5 | 2013-06-24 16:20:32 +0530 | [diff] [blame] | 147 | if (pdata->max_trigger_level > MAX_THRESHOLD_LEVS) { |
| 148 | dev_err(&pdev->dev, "Invalid max trigger level\n"); |
| 149 | goto out; |
| 150 | } |
| 151 | |
| 152 | for (i = 0; i < pdata->max_trigger_level; i++) { |
| 153 | if (!pdata->trigger_levels[i]) |
| 154 | continue; |
| 155 | |
| 156 | if ((pdata->trigger_type[i] == HW_TRIP) && |
| 157 | (!pdata->trigger_levels[pdata->max_trigger_level - 1])) { |
| 158 | dev_err(&pdev->dev, "Invalid hw trigger level\n"); |
| 159 | ret = -EINVAL; |
| 160 | goto out; |
| 161 | } |
| 162 | |
| 163 | /* Count trigger levels except the HW trip*/ |
| 164 | if (!(pdata->trigger_type[i] == HW_TRIP)) |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 165 | trigger_levs++; |
Amit Daniel Kachhap | 7ca04e5 | 2013-06-24 16:20:32 +0530 | [diff] [blame] | 166 | } |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 167 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 168 | if (data->soc == SOC_ARCH_EXYNOS4210) { |
| 169 | /* Write temperature code for threshold */ |
| 170 | threshold_code = temp_to_code(data, pdata->threshold); |
| 171 | if (threshold_code < 0) { |
| 172 | ret = threshold_code; |
| 173 | goto out; |
| 174 | } |
| 175 | writeb(threshold_code, |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 176 | data->base + reg->threshold_temp); |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 177 | for (i = 0; i < trigger_levs; i++) |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 178 | writeb(pdata->trigger_levels[i], data->base + |
| 179 | reg->threshold_th0 + i * sizeof(reg->threshold_th0)); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 180 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 181 | writel(reg->inten_rise_mask, data->base + reg->tmu_intclear); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 182 | } else if (data->soc == SOC_ARCH_EXYNOS) { |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 183 | /* Write temperature code for rising and falling threshold */ |
Amit Daniel Kachhap | 7ca04e5 | 2013-06-24 16:20:32 +0530 | [diff] [blame] | 184 | for (i = 0; |
| 185 | i < trigger_levs && i < EXYNOS_MAX_TRIGGER_PER_REG; i++) { |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 186 | threshold_code = temp_to_code(data, |
| 187 | pdata->trigger_levels[i]); |
| 188 | if (threshold_code < 0) { |
| 189 | ret = threshold_code; |
| 190 | goto out; |
| 191 | } |
| 192 | rising_threshold |= threshold_code << 8 * i; |
| 193 | if (pdata->threshold_falling) { |
| 194 | threshold_code = temp_to_code(data, |
| 195 | pdata->trigger_levels[i] - |
| 196 | pdata->threshold_falling); |
| 197 | if (threshold_code > 0) |
| 198 | falling_threshold |= |
| 199 | threshold_code << 8 * i; |
| 200 | } |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 201 | } |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 202 | |
| 203 | writel(rising_threshold, |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 204 | data->base + reg->threshold_th0); |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 205 | writel(falling_threshold, |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 206 | data->base + reg->threshold_th1); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 207 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 208 | writel((reg->inten_rise_mask << reg->inten_rise_shift) | |
| 209 | (reg->inten_fall_mask << reg->inten_fall_shift), |
| 210 | data->base + reg->tmu_intclear); |
Amit Daniel Kachhap | 7ca04e5 | 2013-06-24 16:20:32 +0530 | [diff] [blame] | 211 | |
| 212 | /* if last threshold limit is also present */ |
| 213 | i = pdata->max_trigger_level - 1; |
| 214 | if (pdata->trigger_levels[i] && |
| 215 | (pdata->trigger_type[i] == HW_TRIP)) { |
| 216 | threshold_code = temp_to_code(data, |
| 217 | pdata->trigger_levels[i]); |
| 218 | if (threshold_code < 0) { |
| 219 | ret = threshold_code; |
| 220 | goto out; |
| 221 | } |
| 222 | rising_threshold |= threshold_code << 8 * i; |
| 223 | writel(rising_threshold, |
| 224 | data->base + reg->threshold_th0); |
| 225 | con = readl(data->base + reg->tmu_ctrl); |
| 226 | con |= (1 << reg->therm_trip_en_shift); |
| 227 | writel(con, data->base + reg->tmu_ctrl); |
| 228 | } |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 229 | } |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 230 | out: |
| 231 | clk_disable(data->clk); |
| 232 | mutex_unlock(&data->lock); |
| 233 | |
| 234 | return ret; |
| 235 | } |
| 236 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 237 | static void exynos_tmu_control(struct platform_device *pdev, bool on) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 238 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 239 | struct exynos_tmu_data *data = platform_get_drvdata(pdev); |
| 240 | struct exynos_tmu_platform_data *pdata = data->pdata; |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 241 | const struct exynos_tmu_registers *reg = pdata->registers; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 242 | unsigned int con, interrupt_en; |
| 243 | |
| 244 | mutex_lock(&data->lock); |
| 245 | clk_enable(data->clk); |
| 246 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 247 | con = readl(data->base + reg->tmu_ctrl); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 248 | |
Amit Daniel Kachhap | d0a0ce3 | 2013-06-24 16:20:29 +0530 | [diff] [blame] | 249 | if (pdata->reference_voltage) { |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 250 | con &= ~(reg->buf_vref_sel_mask << reg->buf_vref_sel_shift); |
| 251 | con |= pdata->reference_voltage << reg->buf_vref_sel_shift; |
Amit Daniel Kachhap | d0a0ce3 | 2013-06-24 16:20:29 +0530 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | if (pdata->gain) { |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 255 | con &= ~(reg->buf_slope_sel_mask << reg->buf_slope_sel_shift); |
| 256 | con |= (pdata->gain << reg->buf_slope_sel_shift); |
Amit Daniel Kachhap | d0a0ce3 | 2013-06-24 16:20:29 +0530 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | if (pdata->noise_cancel_mode) { |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 260 | con &= ~(reg->therm_trip_mode_mask << |
| 261 | reg->therm_trip_mode_shift); |
| 262 | con |= (pdata->noise_cancel_mode << reg->therm_trip_mode_shift); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 263 | } |
| 264 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 265 | if (on) { |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 266 | con |= (1 << reg->core_en_shift); |
Amit Daniel Kachhap | d0a0ce3 | 2013-06-24 16:20:29 +0530 | [diff] [blame] | 267 | interrupt_en = |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 268 | pdata->trigger_enable[3] << reg->inten_rise3_shift | |
| 269 | pdata->trigger_enable[2] << reg->inten_rise2_shift | |
| 270 | pdata->trigger_enable[1] << reg->inten_rise1_shift | |
| 271 | pdata->trigger_enable[0] << reg->inten_rise0_shift; |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 272 | if (pdata->threshold_falling) |
Amit Daniel Kachhap | d0a0ce3 | 2013-06-24 16:20:29 +0530 | [diff] [blame] | 273 | interrupt_en |= |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 274 | interrupt_en << reg->inten_fall0_shift; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 275 | } else { |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 276 | con &= ~(1 << reg->core_en_shift); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 277 | interrupt_en = 0; /* Disable all interrupts */ |
| 278 | } |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 279 | writel(interrupt_en, data->base + reg->tmu_inten); |
| 280 | writel(con, data->base + reg->tmu_ctrl); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 281 | |
| 282 | clk_disable(data->clk); |
| 283 | mutex_unlock(&data->lock); |
| 284 | } |
| 285 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 286 | static int exynos_tmu_read(struct exynos_tmu_data *data) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 287 | { |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 288 | struct exynos_tmu_platform_data *pdata = data->pdata; |
| 289 | const struct exynos_tmu_registers *reg = pdata->registers; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 290 | u8 temp_code; |
| 291 | int temp; |
| 292 | |
| 293 | mutex_lock(&data->lock); |
| 294 | clk_enable(data->clk); |
| 295 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 296 | temp_code = readb(data->base + reg->tmu_cur_temp); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 297 | temp = code_to_temp(data, temp_code); |
| 298 | |
| 299 | clk_disable(data->clk); |
| 300 | mutex_unlock(&data->lock); |
| 301 | |
| 302 | return temp; |
| 303 | } |
| 304 | |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 305 | #ifdef CONFIG_THERMAL_EMULATION |
| 306 | static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) |
| 307 | { |
| 308 | struct exynos_tmu_data *data = drv_data; |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 309 | struct exynos_tmu_platform_data *pdata = data->pdata; |
| 310 | const struct exynos_tmu_registers *reg = pdata->registers; |
| 311 | unsigned int val; |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 312 | int ret = -EINVAL; |
| 313 | |
| 314 | if (data->soc == SOC_ARCH_EXYNOS4210) |
| 315 | goto out; |
| 316 | |
| 317 | if (temp && temp < MCELSIUS) |
| 318 | goto out; |
| 319 | |
| 320 | mutex_lock(&data->lock); |
| 321 | clk_enable(data->clk); |
| 322 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 323 | val = readl(data->base + reg->emul_con); |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 324 | |
| 325 | if (temp) { |
| 326 | temp /= MCELSIUS; |
| 327 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 328 | val = (EXYNOS_EMUL_TIME << reg->emul_time_shift) | |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 329 | (temp_to_code(data, temp) |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 330 | << reg->emul_temp_shift) | EXYNOS_EMUL_ENABLE; |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 331 | } else { |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 332 | val &= ~EXYNOS_EMUL_ENABLE; |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 335 | writel(val, data->base + reg->emul_con); |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 336 | |
| 337 | clk_disable(data->clk); |
| 338 | mutex_unlock(&data->lock); |
| 339 | return 0; |
| 340 | out: |
| 341 | return ret; |
| 342 | } |
| 343 | #else |
| 344 | static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) |
| 345 | { return -EINVAL; } |
| 346 | #endif/*CONFIG_THERMAL_EMULATION*/ |
| 347 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 348 | static void exynos_tmu_work(struct work_struct *work) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 349 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 350 | struct exynos_tmu_data *data = container_of(work, |
| 351 | struct exynos_tmu_data, irq_work); |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 352 | struct exynos_tmu_platform_data *pdata = data->pdata; |
| 353 | const struct exynos_tmu_registers *reg = pdata->registers; |
Amit Daniel Kachhap | a4463c4 | 2013-06-24 16:20:33 +0530 | [diff] [blame^] | 354 | unsigned int val_irq; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 355 | |
Amit Daniel Kachhap | 3ad9524 | 2013-01-17 01:42:18 +0000 | [diff] [blame] | 356 | exynos_report_trigger(); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 357 | mutex_lock(&data->lock); |
| 358 | clk_enable(data->clk); |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 359 | |
Amit Daniel Kachhap | a4463c4 | 2013-06-24 16:20:33 +0530 | [diff] [blame^] | 360 | /* TODO: take action based on particular interrupt */ |
| 361 | val_irq = readl(data->base + reg->tmu_intstat); |
| 362 | /* clear the interrupts */ |
| 363 | writel(val_irq, data->base + reg->tmu_intclear); |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 364 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 365 | clk_disable(data->clk); |
| 366 | mutex_unlock(&data->lock); |
Amit Daniel Kachhap | 3ad9524 | 2013-01-17 01:42:18 +0000 | [diff] [blame] | 367 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 368 | enable_irq(data->irq); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 369 | } |
| 370 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 371 | static irqreturn_t exynos_tmu_irq(int irq, void *id) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 372 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 373 | struct exynos_tmu_data *data = id; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 374 | |
| 375 | disable_irq_nosync(irq); |
| 376 | schedule_work(&data->irq_work); |
| 377 | |
| 378 | return IRQ_HANDLED; |
| 379 | } |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 380 | static struct thermal_sensor_conf exynos_sensor_conf = { |
| 381 | .name = "exynos-therm", |
| 382 | .read_temperature = (int (*)(void *))exynos_tmu_read, |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 383 | .write_emul_temp = exynos_tmu_set_emulation, |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 384 | }; |
| 385 | |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 386 | #ifdef CONFIG_OF |
| 387 | static const struct of_device_id exynos_tmu_match[] = { |
| 388 | { |
| 389 | .compatible = "samsung,exynos4210-tmu", |
| 390 | .data = (void *)EXYNOS4210_TMU_DRV_DATA, |
| 391 | }, |
| 392 | { |
Sachin Kamat | b6cee53 | 2013-04-18 11:37:59 +0000 | [diff] [blame] | 393 | .compatible = "samsung,exynos4412-tmu", |
Amit Daniel Kachhap | e6b7991 | 2013-06-24 16:20:28 +0530 | [diff] [blame] | 394 | .data = (void *)EXYNOS5250_TMU_DRV_DATA, |
Sachin Kamat | b6cee53 | 2013-04-18 11:37:59 +0000 | [diff] [blame] | 395 | }, |
| 396 | { |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 397 | .compatible = "samsung,exynos5250-tmu", |
Amit Daniel Kachhap | e6b7991 | 2013-06-24 16:20:28 +0530 | [diff] [blame] | 398 | .data = (void *)EXYNOS5250_TMU_DRV_DATA, |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 399 | }, |
| 400 | {}, |
| 401 | }; |
| 402 | MODULE_DEVICE_TABLE(of, exynos_tmu_match); |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 403 | #endif |
| 404 | |
| 405 | static struct platform_device_id exynos_tmu_driver_ids[] = { |
| 406 | { |
| 407 | .name = "exynos4210-tmu", |
| 408 | .driver_data = (kernel_ulong_t)EXYNOS4210_TMU_DRV_DATA, |
| 409 | }, |
| 410 | { |
| 411 | .name = "exynos5250-tmu", |
Amit Daniel Kachhap | e6b7991 | 2013-06-24 16:20:28 +0530 | [diff] [blame] | 412 | .driver_data = (kernel_ulong_t)EXYNOS5250_TMU_DRV_DATA, |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 413 | }, |
| 414 | { }, |
| 415 | }; |
Jonghwan Choi | 3ae53b1 | 2012-10-23 14:54:42 +0800 | [diff] [blame] | 416 | MODULE_DEVICE_TABLE(platform, exynos_tmu_driver_ids); |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 417 | |
| 418 | static inline struct exynos_tmu_platform_data *exynos_get_driver_data( |
| 419 | struct platform_device *pdev) |
| 420 | { |
| 421 | #ifdef CONFIG_OF |
| 422 | if (pdev->dev.of_node) { |
| 423 | const struct of_device_id *match; |
| 424 | match = of_match_node(exynos_tmu_match, pdev->dev.of_node); |
| 425 | if (!match) |
| 426 | return NULL; |
| 427 | return (struct exynos_tmu_platform_data *) match->data; |
| 428 | } |
| 429 | #endif |
| 430 | return (struct exynos_tmu_platform_data *) |
| 431 | platform_get_device_id(pdev)->driver_data; |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 432 | } |
Jonghwa Lee | bbf63be | 2012-11-21 13:31:01 +0900 | [diff] [blame] | 433 | |
Greg Kroah-Hartman | 4eab7a9e | 2012-12-21 13:15:52 -0800 | [diff] [blame] | 434 | static int exynos_tmu_probe(struct platform_device *pdev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 435 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 436 | struct exynos_tmu_data *data; |
| 437 | struct exynos_tmu_platform_data *pdata = pdev->dev.platform_data; |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 438 | int ret, i; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 439 | |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 440 | if (!pdata) |
| 441 | pdata = exynos_get_driver_data(pdev); |
| 442 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 443 | if (!pdata) { |
| 444 | dev_err(&pdev->dev, "No platform init data supplied.\n"); |
| 445 | return -ENODEV; |
| 446 | } |
Amit Daniel Kachhap | 79e093c | 2012-08-16 05:41:45 -0600 | [diff] [blame] | 447 | data = devm_kzalloc(&pdev->dev, sizeof(struct exynos_tmu_data), |
| 448 | GFP_KERNEL); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 449 | if (!data) { |
| 450 | dev_err(&pdev->dev, "Failed to allocate driver structure\n"); |
| 451 | return -ENOMEM; |
| 452 | } |
| 453 | |
| 454 | data->irq = platform_get_irq(pdev, 0); |
| 455 | if (data->irq < 0) { |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 456 | dev_err(&pdev->dev, "Failed to get platform irq\n"); |
Amit Daniel Kachhap | 79e093c | 2012-08-16 05:41:45 -0600 | [diff] [blame] | 457 | return data->irq; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 458 | } |
| 459 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 460 | INIT_WORK(&data->irq_work, exynos_tmu_work); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 461 | |
| 462 | data->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | ca36b1b | 2013-01-21 11:09:20 +0100 | [diff] [blame] | 463 | data->base = devm_ioremap_resource(&pdev->dev, data->mem); |
| 464 | if (IS_ERR(data->base)) |
| 465 | return PTR_ERR(data->base); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 466 | |
Amit Daniel Kachhap | 79e093c | 2012-08-16 05:41:45 -0600 | [diff] [blame] | 467 | ret = devm_request_irq(&pdev->dev, data->irq, exynos_tmu_irq, |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 468 | IRQF_TRIGGER_RISING, "exynos-tmu", data); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 469 | if (ret) { |
| 470 | dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq); |
Amit Daniel Kachhap | 79e093c | 2012-08-16 05:41:45 -0600 | [diff] [blame] | 471 | return ret; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 472 | } |
| 473 | |
Sachin Kamat | 2a16279 | 2013-04-18 11:37:58 +0000 | [diff] [blame] | 474 | data->clk = devm_clk_get(&pdev->dev, "tmu_apbif"); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 475 | if (IS_ERR(data->clk)) { |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 476 | dev_err(&pdev->dev, "Failed to get clock\n"); |
Amit Daniel Kachhap | 79e093c | 2012-08-16 05:41:45 -0600 | [diff] [blame] | 477 | return PTR_ERR(data->clk); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 478 | } |
| 479 | |
Sachin Kamat | 2a16279 | 2013-04-18 11:37:58 +0000 | [diff] [blame] | 480 | ret = clk_prepare(data->clk); |
| 481 | if (ret) |
| 482 | return ret; |
| 483 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 484 | if (pdata->type == SOC_ARCH_EXYNOS || |
| 485 | pdata->type == SOC_ARCH_EXYNOS4210) |
| 486 | data->soc = pdata->type; |
| 487 | else { |
| 488 | ret = -EINVAL; |
| 489 | dev_err(&pdev->dev, "Platform not supported\n"); |
| 490 | goto err_clk; |
| 491 | } |
| 492 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 493 | data->pdata = pdata; |
| 494 | platform_set_drvdata(pdev, data); |
| 495 | mutex_init(&data->lock); |
| 496 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 497 | ret = exynos_tmu_initialize(pdev); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 498 | if (ret) { |
| 499 | dev_err(&pdev->dev, "Failed to initialize TMU\n"); |
| 500 | goto err_clk; |
| 501 | } |
| 502 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 503 | exynos_tmu_control(pdev, true); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 504 | |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 505 | /* Register the sensor with thermal management interface */ |
| 506 | (&exynos_sensor_conf)->private_data = data; |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 507 | exynos_sensor_conf.trip_data.trip_count = pdata->trigger_enable[0] + |
| 508 | pdata->trigger_enable[1] + pdata->trigger_enable[2]+ |
| 509 | pdata->trigger_enable[3]; |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 510 | |
| 511 | for (i = 0; i < exynos_sensor_conf.trip_data.trip_count; i++) |
| 512 | exynos_sensor_conf.trip_data.trip_val[i] = |
| 513 | pdata->threshold + pdata->trigger_levels[i]; |
| 514 | |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 515 | exynos_sensor_conf.trip_data.trigger_falling = pdata->threshold_falling; |
| 516 | |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 517 | exynos_sensor_conf.cooling_data.freq_clip_count = |
| 518 | pdata->freq_tab_count; |
| 519 | for (i = 0; i < pdata->freq_tab_count; i++) { |
| 520 | exynos_sensor_conf.cooling_data.freq_data[i].freq_clip_max = |
| 521 | pdata->freq_tab[i].freq_clip_max; |
| 522 | exynos_sensor_conf.cooling_data.freq_data[i].temp_level = |
| 523 | pdata->freq_tab[i].temp_level; |
| 524 | } |
| 525 | |
| 526 | ret = exynos_register_thermal(&exynos_sensor_conf); |
| 527 | if (ret) { |
| 528 | dev_err(&pdev->dev, "Failed to register thermal interface\n"); |
| 529 | goto err_clk; |
| 530 | } |
Jonghwa Lee | bbf63be | 2012-11-21 13:31:01 +0900 | [diff] [blame] | 531 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 532 | return 0; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 533 | err_clk: |
Sachin Kamat | 2a16279 | 2013-04-18 11:37:58 +0000 | [diff] [blame] | 534 | clk_unprepare(data->clk); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 535 | return ret; |
| 536 | } |
| 537 | |
Greg Kroah-Hartman | 4eab7a9e | 2012-12-21 13:15:52 -0800 | [diff] [blame] | 538 | static int exynos_tmu_remove(struct platform_device *pdev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 539 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 540 | struct exynos_tmu_data *data = platform_get_drvdata(pdev); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 541 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 542 | exynos_tmu_control(pdev, false); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 543 | |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 544 | exynos_unregister_thermal(); |
| 545 | |
Sachin Kamat | 2a16279 | 2013-04-18 11:37:58 +0000 | [diff] [blame] | 546 | clk_unprepare(data->clk); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 547 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
Rafael J. Wysocki | 08cd675 | 2012-07-08 21:48:15 +0200 | [diff] [blame] | 551 | #ifdef CONFIG_PM_SLEEP |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 552 | static int exynos_tmu_suspend(struct device *dev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 553 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 554 | exynos_tmu_control(to_platform_device(dev), false); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 555 | |
| 556 | return 0; |
| 557 | } |
| 558 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 559 | static int exynos_tmu_resume(struct device *dev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 560 | { |
Rafael J. Wysocki | 08cd675 | 2012-07-08 21:48:15 +0200 | [diff] [blame] | 561 | struct platform_device *pdev = to_platform_device(dev); |
| 562 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 563 | exynos_tmu_initialize(pdev); |
| 564 | exynos_tmu_control(pdev, true); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 565 | |
| 566 | return 0; |
| 567 | } |
Rafael J. Wysocki | 08cd675 | 2012-07-08 21:48:15 +0200 | [diff] [blame] | 568 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 569 | static SIMPLE_DEV_PM_OPS(exynos_tmu_pm, |
| 570 | exynos_tmu_suspend, exynos_tmu_resume); |
| 571 | #define EXYNOS_TMU_PM (&exynos_tmu_pm) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 572 | #else |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 573 | #define EXYNOS_TMU_PM NULL |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 574 | #endif |
| 575 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 576 | static struct platform_driver exynos_tmu_driver = { |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 577 | .driver = { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 578 | .name = "exynos-tmu", |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 579 | .owner = THIS_MODULE, |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 580 | .pm = EXYNOS_TMU_PM, |
Sachin Kamat | caa5cbd | 2012-12-12 15:54:24 +0530 | [diff] [blame] | 581 | .of_match_table = of_match_ptr(exynos_tmu_match), |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 582 | }, |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 583 | .probe = exynos_tmu_probe, |
Greg Kroah-Hartman | 4eab7a9e | 2012-12-21 13:15:52 -0800 | [diff] [blame] | 584 | .remove = exynos_tmu_remove, |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 585 | .id_table = exynos_tmu_driver_ids, |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 586 | }; |
| 587 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 588 | module_platform_driver(exynos_tmu_driver); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 589 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 590 | MODULE_DESCRIPTION("EXYNOS TMU Driver"); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 591 | MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); |
| 592 | MODULE_LICENSE("GPL"); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 593 | MODULE_ALIAS("platform:exynos-tmu"); |