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 | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 29 | #include <linux/of_address.h> |
| 30 | #include <linux/of_irq.h> |
Amit Daniel Kachhap | 1b67864 | 2013-06-24 16:20:25 +0530 | [diff] [blame] | 31 | #include <linux/platform_device.h> |
Amit Daniel Kachhap | 498d22f | 2013-06-24 16:20:47 +0530 | [diff] [blame] | 32 | #include <linux/regulator/consumer.h> |
Amit Daniel Kachhap | 1b67864 | 2013-06-24 16:20:25 +0530 | [diff] [blame] | 33 | |
| 34 | #include "exynos_thermal_common.h" |
Amit Daniel Kachhap | 0c1836a | 2013-06-24 16:20:27 +0530 | [diff] [blame] | 35 | #include "exynos_tmu.h" |
Amit Daniel Kachhap | e6b7991 | 2013-06-24 16:20:28 +0530 | [diff] [blame] | 36 | #include "exynos_tmu_data.h" |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 37 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 38 | /** |
| 39 | * struct exynos_tmu_data : A structure to hold the private data of the TMU |
| 40 | driver |
| 41 | * @id: identifier of the one instance of the TMU controller. |
| 42 | * @pdata: pointer to the tmu platform/configuration data |
| 43 | * @base: base address of the single instance of the TMU controller. |
Naveen Krishna Chatradhi | 9025d56 | 2013-12-19 11:36:08 +0530 | [diff] [blame] | 44 | * @base_second: base address of the common registers of the TMU controller. |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 45 | * @irq: irq number of the TMU controller. |
| 46 | * @soc: id of the SOC type. |
| 47 | * @irq_work: pointer to the irq work structure. |
| 48 | * @lock: lock to implement synchronization. |
| 49 | * @clk: pointer to the clock structure. |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 50 | * @clk_sec: pointer to the clock structure for accessing the base_second. |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 51 | * @temp_error1: fused value of the first point trim. |
| 52 | * @temp_error2: fused value of the second point trim. |
Amit Daniel Kachhap | 498d22f | 2013-06-24 16:20:47 +0530 | [diff] [blame] | 53 | * @regulator: pointer to the TMU regulator structure. |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 54 | * @reg_conf: pointer to structure to register with core thermal. |
| 55 | */ |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 56 | struct exynos_tmu_data { |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 57 | int id; |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 58 | struct exynos_tmu_platform_data *pdata; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 59 | void __iomem *base; |
Naveen Krishna Chatradhi | 9025d56 | 2013-12-19 11:36:08 +0530 | [diff] [blame] | 60 | void __iomem *base_second; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 61 | int irq; |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 62 | enum soc_type soc; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 63 | struct work_struct irq_work; |
| 64 | struct mutex lock; |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 65 | struct clk *clk, *clk_sec; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 66 | u8 temp_error1, temp_error2; |
Amit Daniel Kachhap | 498d22f | 2013-06-24 16:20:47 +0530 | [diff] [blame] | 67 | struct regulator *regulator; |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 68 | struct thermal_sensor_conf *reg_conf; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /* |
| 72 | * TMU treats temperature as a mapped temperature code. |
| 73 | * The temperature is converted differently depending on the calibration type. |
| 74 | */ |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 75 | static int temp_to_code(struct exynos_tmu_data *data, u8 temp) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 76 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 77 | struct exynos_tmu_platform_data *pdata = data->pdata; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 78 | int temp_code; |
| 79 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 80 | switch (pdata->cal_type) { |
| 81 | case TYPE_TWO_POINT_TRIMMING: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 82 | temp_code = (temp - pdata->first_point_trim) * |
| 83 | (data->temp_error2 - data->temp_error1) / |
| 84 | (pdata->second_point_trim - pdata->first_point_trim) + |
| 85 | data->temp_error1; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 86 | break; |
| 87 | case TYPE_ONE_POINT_TRIMMING: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 88 | temp_code = temp + data->temp_error1 - pdata->first_point_trim; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 89 | break; |
| 90 | default: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 91 | temp_code = temp + pdata->default_temp_offset; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 92 | break; |
| 93 | } |
Bartlomiej Zolnierkiewicz | ddb31d4 | 2014-07-31 19:11:03 +0200 | [diff] [blame] | 94 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 95 | return temp_code; |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Calculate a temperature value from a temperature code. |
| 100 | * The unit of the temperature is degree Celsius. |
| 101 | */ |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 102 | 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] | 103 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 104 | struct exynos_tmu_platform_data *pdata = data->pdata; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 105 | int temp; |
| 106 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 107 | switch (pdata->cal_type) { |
| 108 | case TYPE_TWO_POINT_TRIMMING: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 109 | temp = (temp_code - data->temp_error1) * |
| 110 | (pdata->second_point_trim - pdata->first_point_trim) / |
| 111 | (data->temp_error2 - data->temp_error1) + |
| 112 | pdata->first_point_trim; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 113 | break; |
| 114 | case TYPE_ONE_POINT_TRIMMING: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 115 | temp = temp_code - data->temp_error1 + pdata->first_point_trim; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 116 | break; |
| 117 | default: |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 118 | temp = temp_code - pdata->default_temp_offset; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 119 | break; |
| 120 | } |
Bartlomiej Zolnierkiewicz | ddb31d4 | 2014-07-31 19:11:03 +0200 | [diff] [blame] | 121 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 122 | return temp; |
| 123 | } |
| 124 | |
Bartlomiej Zolnierkiewicz | b835ced | 2014-10-03 18:17:17 +0200 | [diff] [blame] | 125 | static void exynos_tmu_clear_irqs(struct exynos_tmu_data *data) |
| 126 | { |
| 127 | const struct exynos_tmu_registers *reg = data->pdata->registers; |
| 128 | unsigned int val_irq; |
| 129 | |
| 130 | val_irq = readl(data->base + reg->tmu_intstat); |
| 131 | /* |
| 132 | * Clear the interrupts. Please note that the documentation for |
| 133 | * Exynos3250, Exynos4412, Exynos5250 and Exynos5260 incorrectly |
| 134 | * states that INTCLEAR register has a different placing of bits |
| 135 | * responsible for FALL IRQs than INTSTAT register. Exynos5420 |
| 136 | * and Exynos5440 documentation is correct (Exynos4210 doesn't |
| 137 | * support FALL IRQs at all). |
| 138 | */ |
| 139 | writel(val_irq, data->base + reg->tmu_intclear); |
| 140 | } |
| 141 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 142 | static int exynos_tmu_initialize(struct platform_device *pdev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 143 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 144 | struct exynos_tmu_data *data = platform_get_drvdata(pdev); |
| 145 | struct exynos_tmu_platform_data *pdata = data->pdata; |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 146 | const struct exynos_tmu_registers *reg = pdata->registers; |
Chanwoo Choi | 56c64da | 2014-09-03 12:09:02 +0900 | [diff] [blame] | 147 | unsigned int status, trim_info = 0, con, ctrl; |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 148 | unsigned int rising_threshold = 0, falling_threshold = 0; |
Bartlomiej Zolnierkiewicz | ac951af | 2014-07-31 19:11:04 +0200 | [diff] [blame] | 149 | int ret = 0, threshold_code, i; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 150 | |
| 151 | mutex_lock(&data->lock); |
| 152 | clk_enable(data->clk); |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 153 | if (!IS_ERR(data->clk_sec)) |
| 154 | clk_enable(data->clk_sec); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 155 | |
Amit Daniel Kachhap | f4dae75 | 2013-06-24 16:20:40 +0530 | [diff] [blame] | 156 | if (TMU_SUPPORTS(pdata, READY_STATUS)) { |
Bartlomiej Zolnierkiewicz | 5d02206 | 2014-11-13 16:00:57 +0100 | [diff] [blame] | 157 | status = readb(data->base + EXYNOS_TMU_REG_STATUS); |
Amit Daniel Kachhap | f4dae75 | 2013-06-24 16:20:40 +0530 | [diff] [blame] | 158 | if (!status) { |
| 159 | ret = -EBUSY; |
| 160 | goto out; |
| 161 | } |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 162 | } |
| 163 | |
Chanwoo Choi | 56c64da | 2014-09-03 12:09:02 +0900 | [diff] [blame] | 164 | if (TMU_SUPPORTS(pdata, TRIM_RELOAD)) { |
Bartlomiej Zolnierkiewicz | 32f9520 | 2014-11-13 16:00:59 +0100 | [diff] [blame] | 165 | if (data->soc == SOC_ARCH_EXYNOS3250) { |
| 166 | ctrl = readl(data->base + EXYNOS_TMU_TRIMINFO_CON1); |
| 167 | ctrl |= EXYNOS_TRIMINFO_RELOAD_ENABLE; |
| 168 | writel(ctrl, data->base + EXYNOS_TMU_TRIMINFO_CON1); |
Chanwoo Choi | 56c64da | 2014-09-03 12:09:02 +0900 | [diff] [blame] | 169 | } |
Bartlomiej Zolnierkiewicz | 32f9520 | 2014-11-13 16:00:59 +0100 | [diff] [blame] | 170 | ctrl = readl(data->base + EXYNOS_TMU_TRIMINFO_CON2); |
| 171 | ctrl |= EXYNOS_TRIMINFO_RELOAD_ENABLE; |
| 172 | writel(ctrl, data->base + EXYNOS_TMU_TRIMINFO_CON2); |
Chanwoo Choi | 56c64da | 2014-09-03 12:09:02 +0900 | [diff] [blame] | 173 | } |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 174 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 175 | /* Save trimming info in order to perform calibration */ |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 176 | if (data->soc == SOC_ARCH_EXYNOS5440) { |
| 177 | /* |
| 178 | * For exynos5440 soc triminfo value is swapped between TMU0 and |
| 179 | * TMU2, so the below logic is needed. |
| 180 | */ |
| 181 | switch (data->id) { |
| 182 | case 0: |
| 183 | trim_info = readl(data->base + |
Bartlomiej Zolnierkiewicz | 7710941 | 2014-11-13 16:00:56 +0100 | [diff] [blame] | 184 | EXYNOS5440_EFUSE_SWAP_OFFSET + EXYNOS5440_TMU_S0_7_TRIM); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 185 | break; |
| 186 | case 1: |
Bartlomiej Zolnierkiewicz | 7710941 | 2014-11-13 16:00:56 +0100 | [diff] [blame] | 187 | trim_info = readl(data->base + EXYNOS5440_TMU_S0_7_TRIM); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 188 | break; |
| 189 | case 2: |
| 190 | trim_info = readl(data->base - |
Bartlomiej Zolnierkiewicz | 7710941 | 2014-11-13 16:00:56 +0100 | [diff] [blame] | 191 | EXYNOS5440_EFUSE_SWAP_OFFSET + EXYNOS5440_TMU_S0_7_TRIM); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 192 | } |
| 193 | } else { |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 194 | /* On exynos5420 the triminfo register is in the shared space */ |
| 195 | if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO) |
| 196 | trim_info = readl(data->base_second + |
Bartlomiej Zolnierkiewicz | 7710941 | 2014-11-13 16:00:56 +0100 | [diff] [blame] | 197 | EXYNOS_TMU_REG_TRIMINFO); |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 198 | else |
Bartlomiej Zolnierkiewicz | 7710941 | 2014-11-13 16:00:56 +0100 | [diff] [blame] | 199 | trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 200 | } |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 201 | data->temp_error1 = trim_info & EXYNOS_TMU_TEMP_MASK; |
Bartlomiej Zolnierkiewicz | 99d67fb | 2014-07-31 19:11:06 +0200 | [diff] [blame] | 202 | data->temp_error2 = ((trim_info >> EXYNOS_TRIMINFO_85_SHIFT) & |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 203 | EXYNOS_TMU_TEMP_MASK); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 204 | |
Amit Daniel Kachhap | 5000806 | 2013-06-24 16:20:45 +0530 | [diff] [blame] | 205 | if (!data->temp_error1 || |
| 206 | (pdata->min_efuse_value > data->temp_error1) || |
| 207 | (data->temp_error1 > pdata->max_efuse_value)) |
| 208 | data->temp_error1 = pdata->efuse_value & EXYNOS_TMU_TEMP_MASK; |
| 209 | |
| 210 | if (!data->temp_error2) |
| 211 | data->temp_error2 = |
Bartlomiej Zolnierkiewicz | 99d67fb | 2014-07-31 19:11:06 +0200 | [diff] [blame] | 212 | (pdata->efuse_value >> EXYNOS_TRIMINFO_85_SHIFT) & |
Amit Daniel Kachhap | 5000806 | 2013-06-24 16:20:45 +0530 | [diff] [blame] | 213 | EXYNOS_TMU_TEMP_MASK; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 214 | |
Tushar Behera | c65d347 | 2014-04-14 11:08:15 +0530 | [diff] [blame] | 215 | rising_threshold = readl(data->base + reg->threshold_th0); |
| 216 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 217 | if (data->soc == SOC_ARCH_EXYNOS4210) { |
| 218 | /* Write temperature code for threshold */ |
| 219 | threshold_code = temp_to_code(data, pdata->threshold); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 220 | writeb(threshold_code, |
Bartlomiej Zolnierkiewicz | 6b1fbbd | 2014-11-13 16:00:58 +0100 | [diff] [blame] | 221 | data->base + EXYNOS4210_TMU_REG_THRESHOLD_TEMP); |
Bartlomiej Zolnierkiewicz | ac951af | 2014-07-31 19:11:04 +0200 | [diff] [blame] | 222 | for (i = 0; i < pdata->non_hw_trigger_levels; i++) |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 223 | writeb(pdata->trigger_levels[i], data->base + |
| 224 | reg->threshold_th0 + i * sizeof(reg->threshold_th0)); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 225 | |
Bartlomiej Zolnierkiewicz | b835ced | 2014-10-03 18:17:17 +0200 | [diff] [blame] | 226 | exynos_tmu_clear_irqs(data); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 227 | } else { |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 228 | /* Write temperature code for rising and falling threshold */ |
Bartlomiej Zolnierkiewicz | ac951af | 2014-07-31 19:11:04 +0200 | [diff] [blame] | 229 | for (i = 0; i < pdata->non_hw_trigger_levels; i++) { |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 230 | threshold_code = temp_to_code(data, |
| 231 | pdata->trigger_levels[i]); |
Tushar Behera | c65d347 | 2014-04-14 11:08:15 +0530 | [diff] [blame] | 232 | rising_threshold &= ~(0xff << 8 * i); |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 233 | rising_threshold |= threshold_code << 8 * i; |
| 234 | if (pdata->threshold_falling) { |
| 235 | threshold_code = temp_to_code(data, |
| 236 | pdata->trigger_levels[i] - |
| 237 | pdata->threshold_falling); |
Bartlomiej Zolnierkiewicz | 8131a24 | 2014-07-31 19:11:02 +0200 | [diff] [blame] | 238 | falling_threshold |= threshold_code << 8 * i; |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 239 | } |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 240 | } |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 241 | |
| 242 | writel(rising_threshold, |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 243 | data->base + reg->threshold_th0); |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 244 | writel(falling_threshold, |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 245 | data->base + reg->threshold_th1); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 246 | |
Bartlomiej Zolnierkiewicz | b835ced | 2014-10-03 18:17:17 +0200 | [diff] [blame] | 247 | exynos_tmu_clear_irqs(data); |
Amit Daniel Kachhap | 7ca04e5 | 2013-06-24 16:20:32 +0530 | [diff] [blame] | 248 | |
| 249 | /* if last threshold limit is also present */ |
| 250 | i = pdata->max_trigger_level - 1; |
| 251 | if (pdata->trigger_levels[i] && |
| 252 | (pdata->trigger_type[i] == HW_TRIP)) { |
| 253 | threshold_code = temp_to_code(data, |
| 254 | pdata->trigger_levels[i]); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 255 | if (i == EXYNOS_MAX_TRIGGER_PER_REG - 1) { |
| 256 | /* 1-4 level to be assigned in th0 reg */ |
Tushar Behera | c65d347 | 2014-04-14 11:08:15 +0530 | [diff] [blame] | 257 | rising_threshold &= ~(0xff << 8 * i); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 258 | rising_threshold |= threshold_code << 8 * i; |
| 259 | writel(rising_threshold, |
| 260 | data->base + reg->threshold_th0); |
| 261 | } else if (i == EXYNOS_MAX_TRIGGER_PER_REG) { |
| 262 | /* 5th level to be assigned in th2 reg */ |
| 263 | rising_threshold = |
| 264 | threshold_code << reg->threshold_th3_l0_shift; |
| 265 | writel(rising_threshold, |
| 266 | data->base + reg->threshold_th2); |
| 267 | } |
Amit Daniel Kachhap | 7ca04e5 | 2013-06-24 16:20:32 +0530 | [diff] [blame] | 268 | con = readl(data->base + reg->tmu_ctrl); |
Bartlomiej Zolnierkiewicz | 77a37a9 | 2014-11-13 16:01:02 +0100 | [diff] [blame] | 269 | con |= (1 << EXYNOS_TMU_THERM_TRIP_EN_SHIFT); |
Amit Daniel Kachhap | 7ca04e5 | 2013-06-24 16:20:32 +0530 | [diff] [blame] | 270 | writel(con, data->base + reg->tmu_ctrl); |
| 271 | } |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 272 | } |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 273 | /*Clear the PMIN in the common TMU register*/ |
| 274 | if (reg->tmu_pmin && !data->id) |
Naveen Krishna Chatradhi | 9025d56 | 2013-12-19 11:36:08 +0530 | [diff] [blame] | 275 | writel(0, data->base_second + reg->tmu_pmin); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 276 | out: |
| 277 | clk_disable(data->clk); |
| 278 | mutex_unlock(&data->lock); |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 279 | if (!IS_ERR(data->clk_sec)) |
| 280 | clk_disable(data->clk_sec); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 281 | |
| 282 | return ret; |
| 283 | } |
| 284 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 285 | static void exynos_tmu_control(struct platform_device *pdev, bool on) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 286 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 287 | struct exynos_tmu_data *data = platform_get_drvdata(pdev); |
| 288 | struct exynos_tmu_platform_data *pdata = data->pdata; |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 289 | const struct exynos_tmu_registers *reg = pdata->registers; |
Bartlomiej Zolnierkiewicz | d37761e | 2014-07-31 19:11:00 +0200 | [diff] [blame] | 290 | unsigned int con, interrupt_en; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 291 | |
| 292 | mutex_lock(&data->lock); |
| 293 | clk_enable(data->clk); |
| 294 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 295 | con = readl(data->base + reg->tmu_ctrl); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 296 | |
Lukasz Majewski | 86f5362 | 2013-10-09 08:29:52 +0200 | [diff] [blame] | 297 | if (pdata->test_mux) |
Bartlomiej Zolnierkiewicz | bfb2b88 | 2014-11-13 16:01:00 +0100 | [diff] [blame] | 298 | con |= (pdata->test_mux << EXYNOS4412_MUX_ADDR_SHIFT); |
Lukasz Majewski | 86f5362 | 2013-10-09 08:29:52 +0200 | [diff] [blame] | 299 | |
Bartlomiej Zolnierkiewicz | 99d67fb | 2014-07-31 19:11:06 +0200 | [diff] [blame] | 300 | con &= ~(EXYNOS_TMU_REF_VOLTAGE_MASK << EXYNOS_TMU_REF_VOLTAGE_SHIFT); |
| 301 | con |= pdata->reference_voltage << EXYNOS_TMU_REF_VOLTAGE_SHIFT; |
Amit Daniel Kachhap | d0a0ce3 | 2013-06-24 16:20:29 +0530 | [diff] [blame] | 302 | |
Bartlomiej Zolnierkiewicz | 99d67fb | 2014-07-31 19:11:06 +0200 | [diff] [blame] | 303 | con &= ~(EXYNOS_TMU_BUF_SLOPE_SEL_MASK << EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT); |
| 304 | con |= (pdata->gain << EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT); |
Amit Daniel Kachhap | d0a0ce3 | 2013-06-24 16:20:29 +0530 | [diff] [blame] | 305 | |
| 306 | if (pdata->noise_cancel_mode) { |
Bartlomiej Zolnierkiewicz | b9504a6 | 2014-11-13 16:01:01 +0100 | [diff] [blame] | 307 | con &= ~(EXYNOS_TMU_TRIP_MODE_MASK << EXYNOS_TMU_TRIP_MODE_SHIFT); |
| 308 | con |= (pdata->noise_cancel_mode << EXYNOS_TMU_TRIP_MODE_SHIFT); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 309 | } |
| 310 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 311 | if (on) { |
Bartlomiej Zolnierkiewicz | 99d67fb | 2014-07-31 19:11:06 +0200 | [diff] [blame] | 312 | con |= (1 << EXYNOS_TMU_CORE_EN_SHIFT); |
Amit Daniel Kachhap | d0a0ce3 | 2013-06-24 16:20:29 +0530 | [diff] [blame] | 313 | interrupt_en = |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 314 | pdata->trigger_enable[3] << reg->inten_rise3_shift | |
| 315 | pdata->trigger_enable[2] << reg->inten_rise2_shift | |
| 316 | pdata->trigger_enable[1] << reg->inten_rise1_shift | |
| 317 | pdata->trigger_enable[0] << reg->inten_rise0_shift; |
Amit Daniel Kachhap | f4dae75 | 2013-06-24 16:20:40 +0530 | [diff] [blame] | 318 | if (TMU_SUPPORTS(pdata, FALLING_TRIP)) |
Amit Daniel Kachhap | d0a0ce3 | 2013-06-24 16:20:29 +0530 | [diff] [blame] | 319 | interrupt_en |= |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 320 | interrupt_en << reg->inten_fall0_shift; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 321 | } else { |
Bartlomiej Zolnierkiewicz | 99d67fb | 2014-07-31 19:11:06 +0200 | [diff] [blame] | 322 | con &= ~(1 << EXYNOS_TMU_CORE_EN_SHIFT); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 323 | interrupt_en = 0; /* Disable all interrupts */ |
| 324 | } |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 325 | writel(interrupt_en, data->base + reg->tmu_inten); |
| 326 | writel(con, data->base + reg->tmu_ctrl); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 327 | |
| 328 | clk_disable(data->clk); |
| 329 | mutex_unlock(&data->lock); |
| 330 | } |
| 331 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 332 | static int exynos_tmu_read(struct exynos_tmu_data *data) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 333 | { |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 334 | struct exynos_tmu_platform_data *pdata = data->pdata; |
| 335 | const struct exynos_tmu_registers *reg = pdata->registers; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 336 | u8 temp_code; |
| 337 | int temp; |
| 338 | |
| 339 | mutex_lock(&data->lock); |
| 340 | clk_enable(data->clk); |
| 341 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 342 | temp_code = readb(data->base + reg->tmu_cur_temp); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 343 | |
Bartlomiej Zolnierkiewicz | ddb31d4 | 2014-07-31 19:11:03 +0200 | [diff] [blame] | 344 | if (data->soc == SOC_ARCH_EXYNOS4210) |
| 345 | /* temp_code should range between 75 and 175 */ |
| 346 | if (temp_code < 75 || temp_code > 175) { |
| 347 | temp = -ENODATA; |
| 348 | goto out; |
| 349 | } |
| 350 | |
| 351 | temp = code_to_temp(data, temp_code); |
| 352 | out: |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 353 | clk_disable(data->clk); |
| 354 | mutex_unlock(&data->lock); |
| 355 | |
| 356 | return temp; |
| 357 | } |
| 358 | |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 359 | #ifdef CONFIG_THERMAL_EMULATION |
| 360 | static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) |
| 361 | { |
| 362 | struct exynos_tmu_data *data = drv_data; |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 363 | struct exynos_tmu_platform_data *pdata = data->pdata; |
| 364 | const struct exynos_tmu_registers *reg = pdata->registers; |
| 365 | unsigned int val; |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 366 | int ret = -EINVAL; |
| 367 | |
Amit Daniel Kachhap | f4dae75 | 2013-06-24 16:20:40 +0530 | [diff] [blame] | 368 | if (!TMU_SUPPORTS(pdata, EMULATION)) |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 369 | goto out; |
| 370 | |
| 371 | if (temp && temp < MCELSIUS) |
| 372 | goto out; |
| 373 | |
| 374 | mutex_lock(&data->lock); |
| 375 | clk_enable(data->clk); |
| 376 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 377 | val = readl(data->base + reg->emul_con); |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 378 | |
| 379 | if (temp) { |
| 380 | temp /= MCELSIUS; |
| 381 | |
Amit Daniel Kachhap | f4dae75 | 2013-06-24 16:20:40 +0530 | [diff] [blame] | 382 | if (TMU_SUPPORTS(pdata, EMUL_TIME)) { |
Bartlomiej Zolnierkiewicz | 6070c2c | 2014-11-13 16:01:04 +0100 | [diff] [blame^] | 383 | val &= ~(EXYNOS_EMUL_TIME_MASK << EXYNOS_EMUL_TIME_SHIFT); |
| 384 | val |= (EXYNOS_EMUL_TIME << EXYNOS_EMUL_TIME_SHIFT); |
Amit Daniel Kachhap | f4dae75 | 2013-06-24 16:20:40 +0530 | [diff] [blame] | 385 | } |
Bartlomiej Zolnierkiewicz | 9e288d6 | 2014-11-13 16:01:03 +0100 | [diff] [blame] | 386 | val &= ~(EXYNOS_EMUL_DATA_MASK << EXYNOS_EMUL_DATA_SHIFT); |
| 387 | val |= (temp_to_code(data, temp) << EXYNOS_EMUL_DATA_SHIFT) | |
Amit Daniel Kachhap | f4dae75 | 2013-06-24 16:20:40 +0530 | [diff] [blame] | 388 | EXYNOS_EMUL_ENABLE; |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 389 | } else { |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 390 | val &= ~EXYNOS_EMUL_ENABLE; |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 393 | writel(val, data->base + reg->emul_con); |
Amit Daniel Kachhap | bffd1f8 | 2013-02-11 03:54:23 +0000 | [diff] [blame] | 394 | |
| 395 | clk_disable(data->clk); |
| 396 | mutex_unlock(&data->lock); |
| 397 | return 0; |
| 398 | out: |
| 399 | return ret; |
| 400 | } |
| 401 | #else |
| 402 | static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) |
| 403 | { return -EINVAL; } |
| 404 | #endif/*CONFIG_THERMAL_EMULATION*/ |
| 405 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 406 | static void exynos_tmu_work(struct work_struct *work) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 407 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 408 | struct exynos_tmu_data *data = container_of(work, |
| 409 | struct exynos_tmu_data, irq_work); |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 410 | struct exynos_tmu_platform_data *pdata = data->pdata; |
| 411 | const struct exynos_tmu_registers *reg = pdata->registers; |
Bartlomiej Zolnierkiewicz | b835ced | 2014-10-03 18:17:17 +0200 | [diff] [blame] | 412 | unsigned int val_type; |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 413 | |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 414 | if (!IS_ERR(data->clk_sec)) |
| 415 | clk_enable(data->clk_sec); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 416 | /* Find which sensor generated this interrupt */ |
| 417 | if (reg->tmu_irqstatus) { |
Naveen Krishna Chatradhi | 9025d56 | 2013-12-19 11:36:08 +0530 | [diff] [blame] | 418 | val_type = readl(data->base_second + reg->tmu_irqstatus); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 419 | if (!((val_type >> data->id) & 0x1)) |
| 420 | goto out; |
| 421 | } |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 422 | if (!IS_ERR(data->clk_sec)) |
| 423 | clk_disable(data->clk_sec); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 424 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 425 | exynos_report_trigger(data->reg_conf); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 426 | mutex_lock(&data->lock); |
| 427 | clk_enable(data->clk); |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 428 | |
Amit Daniel Kachhap | a4463c4 | 2013-06-24 16:20:33 +0530 | [diff] [blame] | 429 | /* TODO: take action based on particular interrupt */ |
Bartlomiej Zolnierkiewicz | b835ced | 2014-10-03 18:17:17 +0200 | [diff] [blame] | 430 | exynos_tmu_clear_irqs(data); |
Amit Daniel Kachhap | b8d582b | 2013-06-24 16:20:31 +0530 | [diff] [blame] | 431 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 432 | clk_disable(data->clk); |
| 433 | mutex_unlock(&data->lock); |
Amit Daniel Kachhap | a0395ee | 2013-06-24 16:20:43 +0530 | [diff] [blame] | 434 | out: |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 435 | enable_irq(data->irq); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 436 | } |
| 437 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 438 | static irqreturn_t exynos_tmu_irq(int irq, void *id) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 439 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 440 | struct exynos_tmu_data *data = id; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 441 | |
| 442 | disable_irq_nosync(irq); |
| 443 | schedule_work(&data->irq_work); |
| 444 | |
| 445 | return IRQ_HANDLED; |
| 446 | } |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 447 | |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 448 | static const struct of_device_id exynos_tmu_match[] = { |
| 449 | { |
Chanwoo Choi | 1fe56dc | 2014-07-01 09:33:19 +0900 | [diff] [blame] | 450 | .compatible = "samsung,exynos3250-tmu", |
| 451 | .data = (void *)EXYNOS3250_TMU_DRV_DATA, |
| 452 | }, |
| 453 | { |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 454 | .compatible = "samsung,exynos4210-tmu", |
| 455 | .data = (void *)EXYNOS4210_TMU_DRV_DATA, |
| 456 | }, |
| 457 | { |
Sachin Kamat | b6cee53 | 2013-04-18 11:37:59 +0000 | [diff] [blame] | 458 | .compatible = "samsung,exynos4412-tmu", |
Lukasz Majewski | 14ddfae | 2013-10-09 08:29:51 +0200 | [diff] [blame] | 459 | .data = (void *)EXYNOS4412_TMU_DRV_DATA, |
Sachin Kamat | b6cee53 | 2013-04-18 11:37:59 +0000 | [diff] [blame] | 460 | }, |
| 461 | { |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 462 | .compatible = "samsung,exynos5250-tmu", |
Amit Daniel Kachhap | e6b7991 | 2013-06-24 16:20:28 +0530 | [diff] [blame] | 463 | .data = (void *)EXYNOS5250_TMU_DRV_DATA, |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 464 | }, |
Amit Daniel Kachhap | 9054254 | 2013-06-24 16:20:44 +0530 | [diff] [blame] | 465 | { |
Naveen Krishna Chatradhi | 923488a | 2013-12-20 17:49:10 +0530 | [diff] [blame] | 466 | .compatible = "samsung,exynos5260-tmu", |
| 467 | .data = (void *)EXYNOS5260_TMU_DRV_DATA, |
| 468 | }, |
| 469 | { |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 470 | .compatible = "samsung,exynos5420-tmu", |
| 471 | .data = (void *)EXYNOS5420_TMU_DRV_DATA, |
| 472 | }, |
| 473 | { |
| 474 | .compatible = "samsung,exynos5420-tmu-ext-triminfo", |
| 475 | .data = (void *)EXYNOS5420_TMU_DRV_DATA, |
| 476 | }, |
| 477 | { |
Amit Daniel Kachhap | 9054254 | 2013-06-24 16:20:44 +0530 | [diff] [blame] | 478 | .compatible = "samsung,exynos5440-tmu", |
| 479 | .data = (void *)EXYNOS5440_TMU_DRV_DATA, |
| 480 | }, |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 481 | {}, |
| 482 | }; |
| 483 | MODULE_DEVICE_TABLE(of, exynos_tmu_match); |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 484 | |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 485 | static inline struct exynos_tmu_platform_data *exynos_get_driver_data( |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 486 | struct platform_device *pdev, int id) |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 487 | { |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 488 | struct exynos_tmu_init_data *data_table; |
| 489 | struct exynos_tmu_platform_data *tmu_data; |
Sachin Kamat | 73b5b1d | 2013-08-19 11:58:43 +0530 | [diff] [blame] | 490 | const struct of_device_id *match; |
| 491 | |
| 492 | match = of_match_node(exynos_tmu_match, pdev->dev.of_node); |
| 493 | if (!match) |
| 494 | return NULL; |
| 495 | data_table = (struct exynos_tmu_init_data *) match->data; |
| 496 | if (!data_table || id >= data_table->tmu_count) |
| 497 | return NULL; |
| 498 | tmu_data = data_table->tmu_data; |
| 499 | return (struct exynos_tmu_platform_data *) (tmu_data + id); |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 500 | } |
Jonghwa Lee | bbf63be | 2012-11-21 13:31:01 +0900 | [diff] [blame] | 501 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 502 | static int exynos_map_dt_data(struct platform_device *pdev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 503 | { |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 504 | struct exynos_tmu_data *data = platform_get_drvdata(pdev); |
| 505 | struct exynos_tmu_platform_data *pdata; |
| 506 | struct resource res; |
Amit Daniel Kachhap | 498d22f | 2013-06-24 16:20:47 +0530 | [diff] [blame] | 507 | int ret; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 508 | |
Sachin Kamat | 73b5b1d | 2013-08-19 11:58:43 +0530 | [diff] [blame] | 509 | if (!data || !pdev->dev.of_node) |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 510 | return -ENODEV; |
Amit Daniel Kachhap | 17be868 | 2012-08-16 17:11:44 +0530 | [diff] [blame] | 511 | |
Amit Daniel Kachhap | 498d22f | 2013-06-24 16:20:47 +0530 | [diff] [blame] | 512 | /* |
| 513 | * Try enabling the regulator if found |
| 514 | * TODO: Add regulator as an SOC feature, so that regulator enable |
| 515 | * is a compulsory call. |
| 516 | */ |
| 517 | data->regulator = devm_regulator_get(&pdev->dev, "vtmu"); |
| 518 | if (!IS_ERR(data->regulator)) { |
| 519 | ret = regulator_enable(data->regulator); |
| 520 | if (ret) { |
| 521 | dev_err(&pdev->dev, "failed to enable vtmu\n"); |
| 522 | return ret; |
| 523 | } |
| 524 | } else { |
| 525 | dev_info(&pdev->dev, "Regulator node (vtmu) not found\n"); |
| 526 | } |
| 527 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 528 | data->id = of_alias_get_id(pdev->dev.of_node, "tmuctrl"); |
| 529 | if (data->id < 0) |
| 530 | data->id = 0; |
| 531 | |
| 532 | data->irq = irq_of_parse_and_map(pdev->dev.of_node, 0); |
| 533 | if (data->irq <= 0) { |
| 534 | dev_err(&pdev->dev, "failed to get IRQ\n"); |
| 535 | return -ENODEV; |
| 536 | } |
| 537 | |
| 538 | if (of_address_to_resource(pdev->dev.of_node, 0, &res)) { |
| 539 | dev_err(&pdev->dev, "failed to get Resource 0\n"); |
| 540 | return -ENODEV; |
| 541 | } |
| 542 | |
| 543 | data->base = devm_ioremap(&pdev->dev, res.start, resource_size(&res)); |
| 544 | if (!data->base) { |
| 545 | dev_err(&pdev->dev, "Failed to ioremap memory\n"); |
| 546 | return -EADDRNOTAVAIL; |
| 547 | } |
| 548 | |
| 549 | pdata = exynos_get_driver_data(pdev, data->id); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 550 | if (!pdata) { |
| 551 | dev_err(&pdev->dev, "No platform init data supplied.\n"); |
| 552 | return -ENODEV; |
| 553 | } |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 554 | data->pdata = pdata; |
Amit Daniel Kachhap | d9b6ee1 | 2013-06-24 16:20:42 +0530 | [diff] [blame] | 555 | /* |
| 556 | * Check if the TMU shares some registers and then try to map the |
| 557 | * memory of common registers. |
| 558 | */ |
Naveen Krishna Chatradhi | 9025d56 | 2013-12-19 11:36:08 +0530 | [diff] [blame] | 559 | if (!TMU_SUPPORTS(pdata, ADDRESS_MULTIPLE)) |
Amit Daniel Kachhap | d9b6ee1 | 2013-06-24 16:20:42 +0530 | [diff] [blame] | 560 | return 0; |
| 561 | |
| 562 | if (of_address_to_resource(pdev->dev.of_node, 1, &res)) { |
| 563 | dev_err(&pdev->dev, "failed to get Resource 1\n"); |
| 564 | return -ENODEV; |
| 565 | } |
| 566 | |
Naveen Krishna Chatradhi | 9025d56 | 2013-12-19 11:36:08 +0530 | [diff] [blame] | 567 | data->base_second = devm_ioremap(&pdev->dev, res.start, |
Amit Daniel Kachhap | d9b6ee1 | 2013-06-24 16:20:42 +0530 | [diff] [blame] | 568 | resource_size(&res)); |
Naveen Krishna Chatradhi | 9025d56 | 2013-12-19 11:36:08 +0530 | [diff] [blame] | 569 | if (!data->base_second) { |
Amit Daniel Kachhap | d9b6ee1 | 2013-06-24 16:20:42 +0530 | [diff] [blame] | 570 | dev_err(&pdev->dev, "Failed to ioremap memory\n"); |
| 571 | return -ENOMEM; |
| 572 | } |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 573 | |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | static int exynos_tmu_probe(struct platform_device *pdev) |
| 578 | { |
| 579 | struct exynos_tmu_data *data; |
| 580 | struct exynos_tmu_platform_data *pdata; |
| 581 | struct thermal_sensor_conf *sensor_conf; |
| 582 | int ret, i; |
| 583 | |
Amit Daniel Kachhap | 79e093c | 2012-08-16 05:41:45 -0600 | [diff] [blame] | 584 | data = devm_kzalloc(&pdev->dev, sizeof(struct exynos_tmu_data), |
| 585 | GFP_KERNEL); |
Jingoo Han | 2a9675b | 2014-05-07 15:04:48 +0900 | [diff] [blame] | 586 | if (!data) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 587 | return -ENOMEM; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 588 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 589 | platform_set_drvdata(pdev, data); |
| 590 | mutex_init(&data->lock); |
| 591 | |
| 592 | ret = exynos_map_dt_data(pdev); |
| 593 | if (ret) |
| 594 | return ret; |
| 595 | |
| 596 | pdata = data->pdata; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 597 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 598 | INIT_WORK(&data->irq_work, exynos_tmu_work); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 599 | |
Sachin Kamat | 2a16279 | 2013-04-18 11:37:58 +0000 | [diff] [blame] | 600 | data->clk = devm_clk_get(&pdev->dev, "tmu_apbif"); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 601 | if (IS_ERR(data->clk)) { |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 602 | dev_err(&pdev->dev, "Failed to get clock\n"); |
Amit Daniel Kachhap | 79e093c | 2012-08-16 05:41:45 -0600 | [diff] [blame] | 603 | return PTR_ERR(data->clk); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 604 | } |
| 605 | |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 606 | data->clk_sec = devm_clk_get(&pdev->dev, "tmu_triminfo_apbif"); |
| 607 | if (IS_ERR(data->clk_sec)) { |
| 608 | if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO) { |
| 609 | dev_err(&pdev->dev, "Failed to get triminfo clock\n"); |
| 610 | return PTR_ERR(data->clk_sec); |
| 611 | } |
| 612 | } else { |
| 613 | ret = clk_prepare(data->clk_sec); |
| 614 | if (ret) { |
| 615 | dev_err(&pdev->dev, "Failed to get clock\n"); |
| 616 | return ret; |
| 617 | } |
| 618 | } |
| 619 | |
Sachin Kamat | 2a16279 | 2013-04-18 11:37:58 +0000 | [diff] [blame] | 620 | ret = clk_prepare(data->clk); |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 621 | if (ret) { |
| 622 | dev_err(&pdev->dev, "Failed to get clock\n"); |
| 623 | goto err_clk_sec; |
| 624 | } |
Sachin Kamat | 2a16279 | 2013-04-18 11:37:58 +0000 | [diff] [blame] | 625 | |
Chanwoo Choi | 1fe56dc | 2014-07-01 09:33:19 +0900 | [diff] [blame] | 626 | if (pdata->type == SOC_ARCH_EXYNOS3250 || |
| 627 | pdata->type == SOC_ARCH_EXYNOS4210 || |
Lukasz Majewski | 14ddfae | 2013-10-09 08:29:51 +0200 | [diff] [blame] | 628 | pdata->type == SOC_ARCH_EXYNOS4412 || |
| 629 | pdata->type == SOC_ARCH_EXYNOS5250 || |
Naveen Krishna Chatradhi | 923488a | 2013-12-20 17:49:10 +0530 | [diff] [blame] | 630 | pdata->type == SOC_ARCH_EXYNOS5260 || |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 631 | pdata->type == SOC_ARCH_EXYNOS5420_TRIMINFO || |
Lukasz Majewski | 14ddfae | 2013-10-09 08:29:51 +0200 | [diff] [blame] | 632 | pdata->type == SOC_ARCH_EXYNOS5440) |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 633 | data->soc = pdata->type; |
| 634 | else { |
| 635 | ret = -EINVAL; |
| 636 | dev_err(&pdev->dev, "Platform not supported\n"); |
| 637 | goto err_clk; |
| 638 | } |
| 639 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 640 | ret = exynos_tmu_initialize(pdev); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 641 | if (ret) { |
| 642 | dev_err(&pdev->dev, "Failed to initialize TMU\n"); |
| 643 | goto err_clk; |
| 644 | } |
| 645 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 646 | exynos_tmu_control(pdev, true); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 647 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 648 | /* Allocate a structure to register with the exynos core thermal */ |
| 649 | sensor_conf = devm_kzalloc(&pdev->dev, |
| 650 | sizeof(struct thermal_sensor_conf), GFP_KERNEL); |
| 651 | if (!sensor_conf) { |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 652 | ret = -ENOMEM; |
| 653 | goto err_clk; |
| 654 | } |
| 655 | sprintf(sensor_conf->name, "therm_zone%d", data->id); |
| 656 | sensor_conf->read_temperature = (int (*)(void *))exynos_tmu_read; |
| 657 | sensor_conf->write_emul_temp = |
| 658 | (int (*)(void *, unsigned long))exynos_tmu_set_emulation; |
| 659 | sensor_conf->driver_data = data; |
| 660 | sensor_conf->trip_data.trip_count = pdata->trigger_enable[0] + |
Amit Daniel Kachhap | bb34b4c | 2013-06-24 16:20:30 +0530 | [diff] [blame] | 661 | pdata->trigger_enable[1] + pdata->trigger_enable[2]+ |
| 662 | pdata->trigger_enable[3]; |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 663 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 664 | for (i = 0; i < sensor_conf->trip_data.trip_count; i++) { |
| 665 | sensor_conf->trip_data.trip_val[i] = |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 666 | pdata->threshold + pdata->trigger_levels[i]; |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 667 | sensor_conf->trip_data.trip_type[i] = |
Amit Daniel Kachhap | 5c3cf55 | 2013-06-24 16:20:37 +0530 | [diff] [blame] | 668 | pdata->trigger_type[i]; |
| 669 | } |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 670 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 671 | sensor_conf->trip_data.trigger_falling = pdata->threshold_falling; |
Jonghwa Lee | 4f0a684 | 2013-02-08 01:13:06 +0000 | [diff] [blame] | 672 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 673 | sensor_conf->cooling_data.freq_clip_count = pdata->freq_tab_count; |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 674 | for (i = 0; i < pdata->freq_tab_count; i++) { |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 675 | sensor_conf->cooling_data.freq_data[i].freq_clip_max = |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 676 | pdata->freq_tab[i].freq_clip_max; |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 677 | sensor_conf->cooling_data.freq_data[i].temp_level = |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 678 | pdata->freq_tab[i].temp_level; |
| 679 | } |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 680 | sensor_conf->dev = &pdev->dev; |
| 681 | /* Register the sensor with thermal management interface */ |
| 682 | ret = exynos_register_thermal(sensor_conf); |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 683 | if (ret) { |
| 684 | dev_err(&pdev->dev, "Failed to register thermal interface\n"); |
| 685 | goto err_clk; |
| 686 | } |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 687 | data->reg_conf = sensor_conf; |
| 688 | |
| 689 | ret = devm_request_irq(&pdev->dev, data->irq, exynos_tmu_irq, |
| 690 | IRQF_TRIGGER_RISING | IRQF_SHARED, dev_name(&pdev->dev), data); |
| 691 | if (ret) { |
| 692 | dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq); |
| 693 | goto err_clk; |
| 694 | } |
Jonghwa Lee | bbf63be | 2012-11-21 13:31:01 +0900 | [diff] [blame] | 695 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 696 | return 0; |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 697 | err_clk: |
Sachin Kamat | 2a16279 | 2013-04-18 11:37:58 +0000 | [diff] [blame] | 698 | clk_unprepare(data->clk); |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 699 | err_clk_sec: |
| 700 | if (!IS_ERR(data->clk_sec)) |
| 701 | clk_unprepare(data->clk_sec); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 702 | return ret; |
| 703 | } |
| 704 | |
Greg Kroah-Hartman | 4eab7a9 | 2012-12-21 13:15:52 -0800 | [diff] [blame] | 705 | static int exynos_tmu_remove(struct platform_device *pdev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 706 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 707 | struct exynos_tmu_data *data = platform_get_drvdata(pdev); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 708 | |
Amit Daniel Kachhap | cebe737 | 2013-06-24 16:20:39 +0530 | [diff] [blame] | 709 | exynos_unregister_thermal(data->reg_conf); |
Amit Daniel Kachhap | 7e0b55e | 2012-08-16 17:11:43 +0530 | [diff] [blame] | 710 | |
Bartlomiej Zolnierkiewicz | 4215688 | 2014-07-08 15:09:56 +0200 | [diff] [blame] | 711 | exynos_tmu_control(pdev, false); |
| 712 | |
Sachin Kamat | 2a16279 | 2013-04-18 11:37:58 +0000 | [diff] [blame] | 713 | clk_unprepare(data->clk); |
Naveen Krishna Chatradhi | 14a11dc | 2013-12-19 11:36:31 +0530 | [diff] [blame] | 714 | if (!IS_ERR(data->clk_sec)) |
| 715 | clk_unprepare(data->clk_sec); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 716 | |
Amit Daniel Kachhap | 498d22f | 2013-06-24 16:20:47 +0530 | [diff] [blame] | 717 | if (!IS_ERR(data->regulator)) |
| 718 | regulator_disable(data->regulator); |
| 719 | |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 720 | return 0; |
| 721 | } |
| 722 | |
Rafael J. Wysocki | 08cd675 | 2012-07-08 21:48:15 +0200 | [diff] [blame] | 723 | #ifdef CONFIG_PM_SLEEP |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 724 | static int exynos_tmu_suspend(struct device *dev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 725 | { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 726 | exynos_tmu_control(to_platform_device(dev), false); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 727 | |
| 728 | return 0; |
| 729 | } |
| 730 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 731 | static int exynos_tmu_resume(struct device *dev) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 732 | { |
Rafael J. Wysocki | 08cd675 | 2012-07-08 21:48:15 +0200 | [diff] [blame] | 733 | struct platform_device *pdev = to_platform_device(dev); |
| 734 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 735 | exynos_tmu_initialize(pdev); |
| 736 | exynos_tmu_control(pdev, true); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 737 | |
| 738 | return 0; |
| 739 | } |
Rafael J. Wysocki | 08cd675 | 2012-07-08 21:48:15 +0200 | [diff] [blame] | 740 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 741 | static SIMPLE_DEV_PM_OPS(exynos_tmu_pm, |
| 742 | exynos_tmu_suspend, exynos_tmu_resume); |
| 743 | #define EXYNOS_TMU_PM (&exynos_tmu_pm) |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 744 | #else |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 745 | #define EXYNOS_TMU_PM NULL |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 746 | #endif |
| 747 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 748 | static struct platform_driver exynos_tmu_driver = { |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 749 | .driver = { |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 750 | .name = "exynos-tmu", |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 751 | .owner = THIS_MODULE, |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 752 | .pm = EXYNOS_TMU_PM, |
Sachin Kamat | 73b5b1d | 2013-08-19 11:58:43 +0530 | [diff] [blame] | 753 | .of_match_table = exynos_tmu_match, |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 754 | }, |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 755 | .probe = exynos_tmu_probe, |
Greg Kroah-Hartman | 4eab7a9 | 2012-12-21 13:15:52 -0800 | [diff] [blame] | 756 | .remove = exynos_tmu_remove, |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 757 | }; |
| 758 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 759 | module_platform_driver(exynos_tmu_driver); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 760 | |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 761 | MODULE_DESCRIPTION("EXYNOS TMU Driver"); |
Donggeun Kim | 9d97e5c | 2011-09-07 18:49:08 +0900 | [diff] [blame] | 762 | MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); |
| 763 | MODULE_LICENSE("GPL"); |
Amit Daniel Kachhap | f22d9c0 | 2012-08-16 17:11:42 +0530 | [diff] [blame] | 764 | MODULE_ALIAS("platform:exynos-tmu"); |