159dfa54cSAmit Daniel Kachhap /* 259dfa54cSAmit Daniel Kachhap * exynos_tmu.c - Samsung EXYNOS TMU (Thermal Management Unit) 359dfa54cSAmit Daniel Kachhap * 459dfa54cSAmit Daniel Kachhap * Copyright (C) 2011 Samsung Electronics 559dfa54cSAmit Daniel Kachhap * Donggeun Kim <dg77.kim@samsung.com> 659dfa54cSAmit Daniel Kachhap * Amit Daniel Kachhap <amit.kachhap@linaro.org> 759dfa54cSAmit Daniel Kachhap * 859dfa54cSAmit Daniel Kachhap * This program is free software; you can redistribute it and/or modify 959dfa54cSAmit Daniel Kachhap * it under the terms of the GNU General Public License as published by 1059dfa54cSAmit Daniel Kachhap * the Free Software Foundation; either version 2 of the License, or 1159dfa54cSAmit Daniel Kachhap * (at your option) any later version. 1259dfa54cSAmit Daniel Kachhap * 1359dfa54cSAmit Daniel Kachhap * This program is distributed in the hope that it will be useful, 1459dfa54cSAmit Daniel Kachhap * but WITHOUT ANY WARRANTY; without even the implied warranty of 1559dfa54cSAmit Daniel Kachhap * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1659dfa54cSAmit Daniel Kachhap * GNU General Public License for more details. 1759dfa54cSAmit Daniel Kachhap * 1859dfa54cSAmit Daniel Kachhap * You should have received a copy of the GNU General Public License 1959dfa54cSAmit Daniel Kachhap * along with this program; if not, write to the Free Software 2059dfa54cSAmit Daniel Kachhap * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2159dfa54cSAmit Daniel Kachhap * 2259dfa54cSAmit Daniel Kachhap */ 2359dfa54cSAmit Daniel Kachhap 2459dfa54cSAmit Daniel Kachhap #include <linux/clk.h> 2559dfa54cSAmit Daniel Kachhap #include <linux/io.h> 2659dfa54cSAmit Daniel Kachhap #include <linux/interrupt.h> 2759dfa54cSAmit Daniel Kachhap #include <linux/module.h> 2859dfa54cSAmit Daniel Kachhap #include <linux/of.h> 29cebe7373SAmit Daniel Kachhap #include <linux/of_address.h> 30cebe7373SAmit Daniel Kachhap #include <linux/of_irq.h> 3159dfa54cSAmit Daniel Kachhap #include <linux/platform_device.h> 3259dfa54cSAmit Daniel Kachhap 3359dfa54cSAmit Daniel Kachhap #include "exynos_thermal_common.h" 340c1836a6SAmit Daniel Kachhap #include "exynos_tmu.h" 35e6b7991eSAmit Daniel Kachhap #include "exynos_tmu_data.h" 3659dfa54cSAmit Daniel Kachhap 37cebe7373SAmit Daniel Kachhap /** 38cebe7373SAmit Daniel Kachhap * struct exynos_tmu_data : A structure to hold the private data of the TMU 39cebe7373SAmit Daniel Kachhap driver 40cebe7373SAmit Daniel Kachhap * @id: identifier of the one instance of the TMU controller. 41cebe7373SAmit Daniel Kachhap * @pdata: pointer to the tmu platform/configuration data 42cebe7373SAmit Daniel Kachhap * @base: base address of the single instance of the TMU controller. 43cebe7373SAmit Daniel Kachhap * @irq: irq number of the TMU controller. 44cebe7373SAmit Daniel Kachhap * @soc: id of the SOC type. 45cebe7373SAmit Daniel Kachhap * @irq_work: pointer to the irq work structure. 46cebe7373SAmit Daniel Kachhap * @lock: lock to implement synchronization. 47cebe7373SAmit Daniel Kachhap * @clk: pointer to the clock structure. 48cebe7373SAmit Daniel Kachhap * @temp_error1: fused value of the first point trim. 49cebe7373SAmit Daniel Kachhap * @temp_error2: fused value of the second point trim. 50cebe7373SAmit Daniel Kachhap * @reg_conf: pointer to structure to register with core thermal. 51cebe7373SAmit Daniel Kachhap */ 5259dfa54cSAmit Daniel Kachhap struct exynos_tmu_data { 53cebe7373SAmit Daniel Kachhap int id; 5459dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata; 5559dfa54cSAmit Daniel Kachhap void __iomem *base; 5659dfa54cSAmit Daniel Kachhap int irq; 5759dfa54cSAmit Daniel Kachhap enum soc_type soc; 5859dfa54cSAmit Daniel Kachhap struct work_struct irq_work; 5959dfa54cSAmit Daniel Kachhap struct mutex lock; 6059dfa54cSAmit Daniel Kachhap struct clk *clk; 6159dfa54cSAmit Daniel Kachhap u8 temp_error1, temp_error2; 62cebe7373SAmit Daniel Kachhap struct thermal_sensor_conf *reg_conf; 6359dfa54cSAmit Daniel Kachhap }; 6459dfa54cSAmit Daniel Kachhap 6559dfa54cSAmit Daniel Kachhap /* 6659dfa54cSAmit Daniel Kachhap * TMU treats temperature as a mapped temperature code. 6759dfa54cSAmit Daniel Kachhap * The temperature is converted differently depending on the calibration type. 6859dfa54cSAmit Daniel Kachhap */ 6959dfa54cSAmit Daniel Kachhap static int temp_to_code(struct exynos_tmu_data *data, u8 temp) 7059dfa54cSAmit Daniel Kachhap { 7159dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 7259dfa54cSAmit Daniel Kachhap int temp_code; 7359dfa54cSAmit Daniel Kachhap 7459dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS4210) 7559dfa54cSAmit Daniel Kachhap /* temp should range between 25 and 125 */ 7659dfa54cSAmit Daniel Kachhap if (temp < 25 || temp > 125) { 7759dfa54cSAmit Daniel Kachhap temp_code = -EINVAL; 7859dfa54cSAmit Daniel Kachhap goto out; 7959dfa54cSAmit Daniel Kachhap } 8059dfa54cSAmit Daniel Kachhap 8159dfa54cSAmit Daniel Kachhap switch (pdata->cal_type) { 8259dfa54cSAmit Daniel Kachhap case TYPE_TWO_POINT_TRIMMING: 83bb34b4c8SAmit Daniel Kachhap temp_code = (temp - pdata->first_point_trim) * 8459dfa54cSAmit Daniel Kachhap (data->temp_error2 - data->temp_error1) / 85bb34b4c8SAmit Daniel Kachhap (pdata->second_point_trim - pdata->first_point_trim) + 86bb34b4c8SAmit Daniel Kachhap data->temp_error1; 8759dfa54cSAmit Daniel Kachhap break; 8859dfa54cSAmit Daniel Kachhap case TYPE_ONE_POINT_TRIMMING: 89bb34b4c8SAmit Daniel Kachhap temp_code = temp + data->temp_error1 - pdata->first_point_trim; 9059dfa54cSAmit Daniel Kachhap break; 9159dfa54cSAmit Daniel Kachhap default: 92bb34b4c8SAmit Daniel Kachhap temp_code = temp + pdata->default_temp_offset; 9359dfa54cSAmit Daniel Kachhap break; 9459dfa54cSAmit Daniel Kachhap } 9559dfa54cSAmit Daniel Kachhap out: 9659dfa54cSAmit Daniel Kachhap return temp_code; 9759dfa54cSAmit Daniel Kachhap } 9859dfa54cSAmit Daniel Kachhap 9959dfa54cSAmit Daniel Kachhap /* 10059dfa54cSAmit Daniel Kachhap * Calculate a temperature value from a temperature code. 10159dfa54cSAmit Daniel Kachhap * The unit of the temperature is degree Celsius. 10259dfa54cSAmit Daniel Kachhap */ 10359dfa54cSAmit Daniel Kachhap static int code_to_temp(struct exynos_tmu_data *data, u8 temp_code) 10459dfa54cSAmit Daniel Kachhap { 10559dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 10659dfa54cSAmit Daniel Kachhap int temp; 10759dfa54cSAmit Daniel Kachhap 10859dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS4210) 10959dfa54cSAmit Daniel Kachhap /* temp_code should range between 75 and 175 */ 11059dfa54cSAmit Daniel Kachhap if (temp_code < 75 || temp_code > 175) { 11159dfa54cSAmit Daniel Kachhap temp = -ENODATA; 11259dfa54cSAmit Daniel Kachhap goto out; 11359dfa54cSAmit Daniel Kachhap } 11459dfa54cSAmit Daniel Kachhap 11559dfa54cSAmit Daniel Kachhap switch (pdata->cal_type) { 11659dfa54cSAmit Daniel Kachhap case TYPE_TWO_POINT_TRIMMING: 117bb34b4c8SAmit Daniel Kachhap temp = (temp_code - data->temp_error1) * 118bb34b4c8SAmit Daniel Kachhap (pdata->second_point_trim - pdata->first_point_trim) / 119bb34b4c8SAmit Daniel Kachhap (data->temp_error2 - data->temp_error1) + 120bb34b4c8SAmit Daniel Kachhap pdata->first_point_trim; 12159dfa54cSAmit Daniel Kachhap break; 12259dfa54cSAmit Daniel Kachhap case TYPE_ONE_POINT_TRIMMING: 123bb34b4c8SAmit Daniel Kachhap temp = temp_code - data->temp_error1 + pdata->first_point_trim; 12459dfa54cSAmit Daniel Kachhap break; 12559dfa54cSAmit Daniel Kachhap default: 126bb34b4c8SAmit Daniel Kachhap temp = temp_code - pdata->default_temp_offset; 12759dfa54cSAmit Daniel Kachhap break; 12859dfa54cSAmit Daniel Kachhap } 12959dfa54cSAmit Daniel Kachhap out: 13059dfa54cSAmit Daniel Kachhap return temp; 13159dfa54cSAmit Daniel Kachhap } 13259dfa54cSAmit Daniel Kachhap 13359dfa54cSAmit Daniel Kachhap static int exynos_tmu_initialize(struct platform_device *pdev) 13459dfa54cSAmit Daniel Kachhap { 13559dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 13659dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 137b8d582b9SAmit Daniel Kachhap const struct exynos_tmu_registers *reg = pdata->registers; 1387ca04e58SAmit Daniel Kachhap unsigned int status, trim_info = 0, con; 13959dfa54cSAmit Daniel Kachhap unsigned int rising_threshold = 0, falling_threshold = 0; 14059dfa54cSAmit Daniel Kachhap int ret = 0, threshold_code, i, trigger_levs = 0; 14159dfa54cSAmit Daniel Kachhap 14259dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 14359dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 14459dfa54cSAmit Daniel Kachhap 145*f4dae753SAmit Daniel Kachhap if (TMU_SUPPORTS(pdata, READY_STATUS)) { 146b8d582b9SAmit Daniel Kachhap status = readb(data->base + reg->tmu_status); 14759dfa54cSAmit Daniel Kachhap if (!status) { 14859dfa54cSAmit Daniel Kachhap ret = -EBUSY; 14959dfa54cSAmit Daniel Kachhap goto out; 15059dfa54cSAmit Daniel Kachhap } 151*f4dae753SAmit Daniel Kachhap } 15259dfa54cSAmit Daniel Kachhap 153*f4dae753SAmit Daniel Kachhap if (TMU_SUPPORTS(pdata, TRIM_RELOAD)) 154b8d582b9SAmit Daniel Kachhap __raw_writel(1, data->base + reg->triminfo_ctrl); 155b8d582b9SAmit Daniel Kachhap 15659dfa54cSAmit Daniel Kachhap /* Save trimming info in order to perform calibration */ 157b8d582b9SAmit Daniel Kachhap trim_info = readl(data->base + reg->triminfo_data); 158b8d582b9SAmit Daniel Kachhap data->temp_error1 = trim_info & EXYNOS_TMU_TEMP_MASK; 159b8d582b9SAmit Daniel Kachhap data->temp_error2 = ((trim_info >> reg->triminfo_85_shift) & 160b8d582b9SAmit Daniel Kachhap EXYNOS_TMU_TEMP_MASK); 16159dfa54cSAmit Daniel Kachhap 162bb34b4c8SAmit Daniel Kachhap if ((pdata->min_efuse_value > data->temp_error1) || 163bb34b4c8SAmit Daniel Kachhap (data->temp_error1 > pdata->max_efuse_value) || 16459dfa54cSAmit Daniel Kachhap (data->temp_error2 != 0)) 16559dfa54cSAmit Daniel Kachhap data->temp_error1 = pdata->efuse_value; 16659dfa54cSAmit Daniel Kachhap 1677ca04e58SAmit Daniel Kachhap if (pdata->max_trigger_level > MAX_THRESHOLD_LEVS) { 1687ca04e58SAmit Daniel Kachhap dev_err(&pdev->dev, "Invalid max trigger level\n"); 1697ca04e58SAmit Daniel Kachhap goto out; 1707ca04e58SAmit Daniel Kachhap } 1717ca04e58SAmit Daniel Kachhap 1727ca04e58SAmit Daniel Kachhap for (i = 0; i < pdata->max_trigger_level; i++) { 1737ca04e58SAmit Daniel Kachhap if (!pdata->trigger_levels[i]) 1747ca04e58SAmit Daniel Kachhap continue; 1757ca04e58SAmit Daniel Kachhap 1767ca04e58SAmit Daniel Kachhap if ((pdata->trigger_type[i] == HW_TRIP) && 1777ca04e58SAmit Daniel Kachhap (!pdata->trigger_levels[pdata->max_trigger_level - 1])) { 1787ca04e58SAmit Daniel Kachhap dev_err(&pdev->dev, "Invalid hw trigger level\n"); 1797ca04e58SAmit Daniel Kachhap ret = -EINVAL; 1807ca04e58SAmit Daniel Kachhap goto out; 1817ca04e58SAmit Daniel Kachhap } 1827ca04e58SAmit Daniel Kachhap 1837ca04e58SAmit Daniel Kachhap /* Count trigger levels except the HW trip*/ 1847ca04e58SAmit Daniel Kachhap if (!(pdata->trigger_type[i] == HW_TRIP)) 18559dfa54cSAmit Daniel Kachhap trigger_levs++; 1867ca04e58SAmit Daniel Kachhap } 18759dfa54cSAmit Daniel Kachhap 18859dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS4210) { 18959dfa54cSAmit Daniel Kachhap /* Write temperature code for threshold */ 19059dfa54cSAmit Daniel Kachhap threshold_code = temp_to_code(data, pdata->threshold); 19159dfa54cSAmit Daniel Kachhap if (threshold_code < 0) { 19259dfa54cSAmit Daniel Kachhap ret = threshold_code; 19359dfa54cSAmit Daniel Kachhap goto out; 19459dfa54cSAmit Daniel Kachhap } 19559dfa54cSAmit Daniel Kachhap writeb(threshold_code, 196b8d582b9SAmit Daniel Kachhap data->base + reg->threshold_temp); 19759dfa54cSAmit Daniel Kachhap for (i = 0; i < trigger_levs; i++) 198b8d582b9SAmit Daniel Kachhap writeb(pdata->trigger_levels[i], data->base + 199b8d582b9SAmit Daniel Kachhap reg->threshold_th0 + i * sizeof(reg->threshold_th0)); 20059dfa54cSAmit Daniel Kachhap 201b8d582b9SAmit Daniel Kachhap writel(reg->inten_rise_mask, data->base + reg->tmu_intclear); 20259dfa54cSAmit Daniel Kachhap } else if (data->soc == SOC_ARCH_EXYNOS) { 20359dfa54cSAmit Daniel Kachhap /* Write temperature code for rising and falling threshold */ 2047ca04e58SAmit Daniel Kachhap for (i = 0; 2057ca04e58SAmit Daniel Kachhap i < trigger_levs && i < EXYNOS_MAX_TRIGGER_PER_REG; i++) { 20659dfa54cSAmit Daniel Kachhap threshold_code = temp_to_code(data, 20759dfa54cSAmit Daniel Kachhap pdata->trigger_levels[i]); 20859dfa54cSAmit Daniel Kachhap if (threshold_code < 0) { 20959dfa54cSAmit Daniel Kachhap ret = threshold_code; 21059dfa54cSAmit Daniel Kachhap goto out; 21159dfa54cSAmit Daniel Kachhap } 21259dfa54cSAmit Daniel Kachhap rising_threshold |= threshold_code << 8 * i; 21359dfa54cSAmit Daniel Kachhap if (pdata->threshold_falling) { 21459dfa54cSAmit Daniel Kachhap threshold_code = temp_to_code(data, 21559dfa54cSAmit Daniel Kachhap pdata->trigger_levels[i] - 21659dfa54cSAmit Daniel Kachhap pdata->threshold_falling); 21759dfa54cSAmit Daniel Kachhap if (threshold_code > 0) 21859dfa54cSAmit Daniel Kachhap falling_threshold |= 21959dfa54cSAmit Daniel Kachhap threshold_code << 8 * i; 22059dfa54cSAmit Daniel Kachhap } 22159dfa54cSAmit Daniel Kachhap } 22259dfa54cSAmit Daniel Kachhap 22359dfa54cSAmit Daniel Kachhap writel(rising_threshold, 224b8d582b9SAmit Daniel Kachhap data->base + reg->threshold_th0); 22559dfa54cSAmit Daniel Kachhap writel(falling_threshold, 226b8d582b9SAmit Daniel Kachhap data->base + reg->threshold_th1); 22759dfa54cSAmit Daniel Kachhap 228b8d582b9SAmit Daniel Kachhap writel((reg->inten_rise_mask << reg->inten_rise_shift) | 229b8d582b9SAmit Daniel Kachhap (reg->inten_fall_mask << reg->inten_fall_shift), 230b8d582b9SAmit Daniel Kachhap data->base + reg->tmu_intclear); 2317ca04e58SAmit Daniel Kachhap 2327ca04e58SAmit Daniel Kachhap /* if last threshold limit is also present */ 2337ca04e58SAmit Daniel Kachhap i = pdata->max_trigger_level - 1; 2347ca04e58SAmit Daniel Kachhap if (pdata->trigger_levels[i] && 2357ca04e58SAmit Daniel Kachhap (pdata->trigger_type[i] == HW_TRIP)) { 2367ca04e58SAmit Daniel Kachhap threshold_code = temp_to_code(data, 2377ca04e58SAmit Daniel Kachhap pdata->trigger_levels[i]); 2387ca04e58SAmit Daniel Kachhap if (threshold_code < 0) { 2397ca04e58SAmit Daniel Kachhap ret = threshold_code; 2407ca04e58SAmit Daniel Kachhap goto out; 2417ca04e58SAmit Daniel Kachhap } 2427ca04e58SAmit Daniel Kachhap rising_threshold |= threshold_code << 8 * i; 2437ca04e58SAmit Daniel Kachhap writel(rising_threshold, 2447ca04e58SAmit Daniel Kachhap data->base + reg->threshold_th0); 2457ca04e58SAmit Daniel Kachhap con = readl(data->base + reg->tmu_ctrl); 2467ca04e58SAmit Daniel Kachhap con |= (1 << reg->therm_trip_en_shift); 2477ca04e58SAmit Daniel Kachhap writel(con, data->base + reg->tmu_ctrl); 2487ca04e58SAmit Daniel Kachhap } 24959dfa54cSAmit Daniel Kachhap } 25059dfa54cSAmit Daniel Kachhap out: 25159dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 25259dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 25359dfa54cSAmit Daniel Kachhap 25459dfa54cSAmit Daniel Kachhap return ret; 25559dfa54cSAmit Daniel Kachhap } 25659dfa54cSAmit Daniel Kachhap 25759dfa54cSAmit Daniel Kachhap static void exynos_tmu_control(struct platform_device *pdev, bool on) 25859dfa54cSAmit Daniel Kachhap { 25959dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 26059dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 261b8d582b9SAmit Daniel Kachhap const struct exynos_tmu_registers *reg = pdata->registers; 26259dfa54cSAmit Daniel Kachhap unsigned int con, interrupt_en; 26359dfa54cSAmit Daniel Kachhap 26459dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 26559dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 26659dfa54cSAmit Daniel Kachhap 267b8d582b9SAmit Daniel Kachhap con = readl(data->base + reg->tmu_ctrl); 26859dfa54cSAmit Daniel Kachhap 269d0a0ce3eSAmit Daniel Kachhap if (pdata->reference_voltage) { 270b8d582b9SAmit Daniel Kachhap con &= ~(reg->buf_vref_sel_mask << reg->buf_vref_sel_shift); 271b8d582b9SAmit Daniel Kachhap con |= pdata->reference_voltage << reg->buf_vref_sel_shift; 272d0a0ce3eSAmit Daniel Kachhap } 273d0a0ce3eSAmit Daniel Kachhap 274d0a0ce3eSAmit Daniel Kachhap if (pdata->gain) { 275b8d582b9SAmit Daniel Kachhap con &= ~(reg->buf_slope_sel_mask << reg->buf_slope_sel_shift); 276b8d582b9SAmit Daniel Kachhap con |= (pdata->gain << reg->buf_slope_sel_shift); 277d0a0ce3eSAmit Daniel Kachhap } 278d0a0ce3eSAmit Daniel Kachhap 279d0a0ce3eSAmit Daniel Kachhap if (pdata->noise_cancel_mode) { 280b8d582b9SAmit Daniel Kachhap con &= ~(reg->therm_trip_mode_mask << 281b8d582b9SAmit Daniel Kachhap reg->therm_trip_mode_shift); 282b8d582b9SAmit Daniel Kachhap con |= (pdata->noise_cancel_mode << reg->therm_trip_mode_shift); 28359dfa54cSAmit Daniel Kachhap } 28459dfa54cSAmit Daniel Kachhap 28559dfa54cSAmit Daniel Kachhap if (on) { 286b8d582b9SAmit Daniel Kachhap con |= (1 << reg->core_en_shift); 287d0a0ce3eSAmit Daniel Kachhap interrupt_en = 288b8d582b9SAmit Daniel Kachhap pdata->trigger_enable[3] << reg->inten_rise3_shift | 289b8d582b9SAmit Daniel Kachhap pdata->trigger_enable[2] << reg->inten_rise2_shift | 290b8d582b9SAmit Daniel Kachhap pdata->trigger_enable[1] << reg->inten_rise1_shift | 291b8d582b9SAmit Daniel Kachhap pdata->trigger_enable[0] << reg->inten_rise0_shift; 292*f4dae753SAmit Daniel Kachhap if (TMU_SUPPORTS(pdata, FALLING_TRIP)) 293d0a0ce3eSAmit Daniel Kachhap interrupt_en |= 294b8d582b9SAmit Daniel Kachhap interrupt_en << reg->inten_fall0_shift; 29559dfa54cSAmit Daniel Kachhap } else { 296b8d582b9SAmit Daniel Kachhap con &= ~(1 << reg->core_en_shift); 29759dfa54cSAmit Daniel Kachhap interrupt_en = 0; /* Disable all interrupts */ 29859dfa54cSAmit Daniel Kachhap } 299b8d582b9SAmit Daniel Kachhap writel(interrupt_en, data->base + reg->tmu_inten); 300b8d582b9SAmit Daniel Kachhap writel(con, data->base + reg->tmu_ctrl); 30159dfa54cSAmit Daniel Kachhap 30259dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 30359dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 30459dfa54cSAmit Daniel Kachhap } 30559dfa54cSAmit Daniel Kachhap 30659dfa54cSAmit Daniel Kachhap static int exynos_tmu_read(struct exynos_tmu_data *data) 30759dfa54cSAmit Daniel Kachhap { 308b8d582b9SAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 309b8d582b9SAmit Daniel Kachhap const struct exynos_tmu_registers *reg = pdata->registers; 31059dfa54cSAmit Daniel Kachhap u8 temp_code; 31159dfa54cSAmit Daniel Kachhap int temp; 31259dfa54cSAmit Daniel Kachhap 31359dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 31459dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 31559dfa54cSAmit Daniel Kachhap 316b8d582b9SAmit Daniel Kachhap temp_code = readb(data->base + reg->tmu_cur_temp); 31759dfa54cSAmit Daniel Kachhap temp = code_to_temp(data, temp_code); 31859dfa54cSAmit Daniel Kachhap 31959dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 32059dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 32159dfa54cSAmit Daniel Kachhap 32259dfa54cSAmit Daniel Kachhap return temp; 32359dfa54cSAmit Daniel Kachhap } 32459dfa54cSAmit Daniel Kachhap 32559dfa54cSAmit Daniel Kachhap #ifdef CONFIG_THERMAL_EMULATION 32659dfa54cSAmit Daniel Kachhap static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) 32759dfa54cSAmit Daniel Kachhap { 32859dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = drv_data; 329b8d582b9SAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 330b8d582b9SAmit Daniel Kachhap const struct exynos_tmu_registers *reg = pdata->registers; 331b8d582b9SAmit Daniel Kachhap unsigned int val; 33259dfa54cSAmit Daniel Kachhap int ret = -EINVAL; 33359dfa54cSAmit Daniel Kachhap 334*f4dae753SAmit Daniel Kachhap if (!TMU_SUPPORTS(pdata, EMULATION)) 33559dfa54cSAmit Daniel Kachhap goto out; 33659dfa54cSAmit Daniel Kachhap 33759dfa54cSAmit Daniel Kachhap if (temp && temp < MCELSIUS) 33859dfa54cSAmit Daniel Kachhap goto out; 33959dfa54cSAmit Daniel Kachhap 34059dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 34159dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 34259dfa54cSAmit Daniel Kachhap 343b8d582b9SAmit Daniel Kachhap val = readl(data->base + reg->emul_con); 34459dfa54cSAmit Daniel Kachhap 34559dfa54cSAmit Daniel Kachhap if (temp) { 34659dfa54cSAmit Daniel Kachhap temp /= MCELSIUS; 34759dfa54cSAmit Daniel Kachhap 348*f4dae753SAmit Daniel Kachhap if (TMU_SUPPORTS(pdata, EMUL_TIME)) { 349*f4dae753SAmit Daniel Kachhap val &= ~(EXYNOS_EMUL_TIME_MASK << reg->emul_time_shift); 350*f4dae753SAmit Daniel Kachhap val |= (EXYNOS_EMUL_TIME << reg->emul_time_shift); 351*f4dae753SAmit Daniel Kachhap } 352*f4dae753SAmit Daniel Kachhap val &= ~(EXYNOS_EMUL_DATA_MASK << reg->emul_temp_shift); 353*f4dae753SAmit Daniel Kachhap val |= (temp_to_code(data, temp) << reg->emul_temp_shift) | 354*f4dae753SAmit Daniel Kachhap EXYNOS_EMUL_ENABLE; 35559dfa54cSAmit Daniel Kachhap } else { 356b8d582b9SAmit Daniel Kachhap val &= ~EXYNOS_EMUL_ENABLE; 35759dfa54cSAmit Daniel Kachhap } 35859dfa54cSAmit Daniel Kachhap 359b8d582b9SAmit Daniel Kachhap writel(val, data->base + reg->emul_con); 36059dfa54cSAmit Daniel Kachhap 36159dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 36259dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 36359dfa54cSAmit Daniel Kachhap return 0; 36459dfa54cSAmit Daniel Kachhap out: 36559dfa54cSAmit Daniel Kachhap return ret; 36659dfa54cSAmit Daniel Kachhap } 36759dfa54cSAmit Daniel Kachhap #else 36859dfa54cSAmit Daniel Kachhap static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) 36959dfa54cSAmit Daniel Kachhap { return -EINVAL; } 37059dfa54cSAmit Daniel Kachhap #endif/*CONFIG_THERMAL_EMULATION*/ 37159dfa54cSAmit Daniel Kachhap 37259dfa54cSAmit Daniel Kachhap static void exynos_tmu_work(struct work_struct *work) 37359dfa54cSAmit Daniel Kachhap { 37459dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = container_of(work, 37559dfa54cSAmit Daniel Kachhap struct exynos_tmu_data, irq_work); 376b8d582b9SAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 377b8d582b9SAmit Daniel Kachhap const struct exynos_tmu_registers *reg = pdata->registers; 378a4463c4fSAmit Daniel Kachhap unsigned int val_irq; 37959dfa54cSAmit Daniel Kachhap 380cebe7373SAmit Daniel Kachhap exynos_report_trigger(data->reg_conf); 38159dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 38259dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 383b8d582b9SAmit Daniel Kachhap 384a4463c4fSAmit Daniel Kachhap /* TODO: take action based on particular interrupt */ 385a4463c4fSAmit Daniel Kachhap val_irq = readl(data->base + reg->tmu_intstat); 386a4463c4fSAmit Daniel Kachhap /* clear the interrupts */ 387a4463c4fSAmit Daniel Kachhap writel(val_irq, data->base + reg->tmu_intclear); 388b8d582b9SAmit Daniel Kachhap 38959dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 39059dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 39159dfa54cSAmit Daniel Kachhap 39259dfa54cSAmit Daniel Kachhap enable_irq(data->irq); 39359dfa54cSAmit Daniel Kachhap } 39459dfa54cSAmit Daniel Kachhap 39559dfa54cSAmit Daniel Kachhap static irqreturn_t exynos_tmu_irq(int irq, void *id) 39659dfa54cSAmit Daniel Kachhap { 39759dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = id; 39859dfa54cSAmit Daniel Kachhap 39959dfa54cSAmit Daniel Kachhap disable_irq_nosync(irq); 40059dfa54cSAmit Daniel Kachhap schedule_work(&data->irq_work); 40159dfa54cSAmit Daniel Kachhap 40259dfa54cSAmit Daniel Kachhap return IRQ_HANDLED; 40359dfa54cSAmit Daniel Kachhap } 40459dfa54cSAmit Daniel Kachhap 40559dfa54cSAmit Daniel Kachhap #ifdef CONFIG_OF 40659dfa54cSAmit Daniel Kachhap static const struct of_device_id exynos_tmu_match[] = { 40759dfa54cSAmit Daniel Kachhap { 40859dfa54cSAmit Daniel Kachhap .compatible = "samsung,exynos4210-tmu", 40959dfa54cSAmit Daniel Kachhap .data = (void *)EXYNOS4210_TMU_DRV_DATA, 41059dfa54cSAmit Daniel Kachhap }, 41159dfa54cSAmit Daniel Kachhap { 41259dfa54cSAmit Daniel Kachhap .compatible = "samsung,exynos4412-tmu", 413e6b7991eSAmit Daniel Kachhap .data = (void *)EXYNOS5250_TMU_DRV_DATA, 41459dfa54cSAmit Daniel Kachhap }, 41559dfa54cSAmit Daniel Kachhap { 41659dfa54cSAmit Daniel Kachhap .compatible = "samsung,exynos5250-tmu", 417e6b7991eSAmit Daniel Kachhap .data = (void *)EXYNOS5250_TMU_DRV_DATA, 41859dfa54cSAmit Daniel Kachhap }, 41959dfa54cSAmit Daniel Kachhap {}, 42059dfa54cSAmit Daniel Kachhap }; 42159dfa54cSAmit Daniel Kachhap MODULE_DEVICE_TABLE(of, exynos_tmu_match); 42259dfa54cSAmit Daniel Kachhap #endif 42359dfa54cSAmit Daniel Kachhap 42459dfa54cSAmit Daniel Kachhap static inline struct exynos_tmu_platform_data *exynos_get_driver_data( 425cebe7373SAmit Daniel Kachhap struct platform_device *pdev, int id) 42659dfa54cSAmit Daniel Kachhap { 42759dfa54cSAmit Daniel Kachhap #ifdef CONFIG_OF 428cebe7373SAmit Daniel Kachhap struct exynos_tmu_init_data *data_table; 429cebe7373SAmit Daniel Kachhap struct exynos_tmu_platform_data *tmu_data; 43059dfa54cSAmit Daniel Kachhap if (pdev->dev.of_node) { 43159dfa54cSAmit Daniel Kachhap const struct of_device_id *match; 43259dfa54cSAmit Daniel Kachhap match = of_match_node(exynos_tmu_match, pdev->dev.of_node); 43359dfa54cSAmit Daniel Kachhap if (!match) 43459dfa54cSAmit Daniel Kachhap return NULL; 435cebe7373SAmit Daniel Kachhap data_table = (struct exynos_tmu_init_data *) match->data; 436cebe7373SAmit Daniel Kachhap if (!data_table || id >= data_table->tmu_count) 437cebe7373SAmit Daniel Kachhap return NULL; 438cebe7373SAmit Daniel Kachhap tmu_data = data_table->tmu_data; 439cebe7373SAmit Daniel Kachhap return (struct exynos_tmu_platform_data *) (tmu_data + id); 44059dfa54cSAmit Daniel Kachhap } 44159dfa54cSAmit Daniel Kachhap #endif 4421cd1ecb6SAmit Daniel Kachhap return NULL; 44359dfa54cSAmit Daniel Kachhap } 44459dfa54cSAmit Daniel Kachhap 445cebe7373SAmit Daniel Kachhap static int exynos_map_dt_data(struct platform_device *pdev) 44659dfa54cSAmit Daniel Kachhap { 447cebe7373SAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 448cebe7373SAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata; 449cebe7373SAmit Daniel Kachhap struct resource res; 45059dfa54cSAmit Daniel Kachhap 451cebe7373SAmit Daniel Kachhap if (!data) 452cebe7373SAmit Daniel Kachhap return -ENODEV; 45359dfa54cSAmit Daniel Kachhap 454cebe7373SAmit Daniel Kachhap data->id = of_alias_get_id(pdev->dev.of_node, "tmuctrl"); 455cebe7373SAmit Daniel Kachhap if (data->id < 0) 456cebe7373SAmit Daniel Kachhap data->id = 0; 457cebe7373SAmit Daniel Kachhap 458cebe7373SAmit Daniel Kachhap data->irq = irq_of_parse_and_map(pdev->dev.of_node, 0); 459cebe7373SAmit Daniel Kachhap if (data->irq <= 0) { 460cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "failed to get IRQ\n"); 461cebe7373SAmit Daniel Kachhap return -ENODEV; 462cebe7373SAmit Daniel Kachhap } 463cebe7373SAmit Daniel Kachhap 464cebe7373SAmit Daniel Kachhap if (of_address_to_resource(pdev->dev.of_node, 0, &res)) { 465cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "failed to get Resource 0\n"); 466cebe7373SAmit Daniel Kachhap return -ENODEV; 467cebe7373SAmit Daniel Kachhap } 468cebe7373SAmit Daniel Kachhap 469cebe7373SAmit Daniel Kachhap data->base = devm_ioremap(&pdev->dev, res.start, resource_size(&res)); 470cebe7373SAmit Daniel Kachhap if (!data->base) { 471cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to ioremap memory\n"); 472cebe7373SAmit Daniel Kachhap return -EADDRNOTAVAIL; 473cebe7373SAmit Daniel Kachhap } 474cebe7373SAmit Daniel Kachhap 475cebe7373SAmit Daniel Kachhap pdata = exynos_get_driver_data(pdev, data->id); 47659dfa54cSAmit Daniel Kachhap if (!pdata) { 47759dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "No platform init data supplied.\n"); 47859dfa54cSAmit Daniel Kachhap return -ENODEV; 47959dfa54cSAmit Daniel Kachhap } 480cebe7373SAmit Daniel Kachhap data->pdata = pdata; 481cebe7373SAmit Daniel Kachhap 482cebe7373SAmit Daniel Kachhap return 0; 483cebe7373SAmit Daniel Kachhap } 484cebe7373SAmit Daniel Kachhap 485cebe7373SAmit Daniel Kachhap static int exynos_tmu_probe(struct platform_device *pdev) 486cebe7373SAmit Daniel Kachhap { 487cebe7373SAmit Daniel Kachhap struct exynos_tmu_data *data; 488cebe7373SAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata; 489cebe7373SAmit Daniel Kachhap struct thermal_sensor_conf *sensor_conf; 490cebe7373SAmit Daniel Kachhap int ret, i; 491cebe7373SAmit Daniel Kachhap 49259dfa54cSAmit Daniel Kachhap data = devm_kzalloc(&pdev->dev, sizeof(struct exynos_tmu_data), 49359dfa54cSAmit Daniel Kachhap GFP_KERNEL); 49459dfa54cSAmit Daniel Kachhap if (!data) { 49559dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to allocate driver structure\n"); 49659dfa54cSAmit Daniel Kachhap return -ENOMEM; 49759dfa54cSAmit Daniel Kachhap } 49859dfa54cSAmit Daniel Kachhap 499cebe7373SAmit Daniel Kachhap platform_set_drvdata(pdev, data); 500cebe7373SAmit Daniel Kachhap mutex_init(&data->lock); 501cebe7373SAmit Daniel Kachhap 502cebe7373SAmit Daniel Kachhap ret = exynos_map_dt_data(pdev); 503cebe7373SAmit Daniel Kachhap if (ret) 504cebe7373SAmit Daniel Kachhap return ret; 505cebe7373SAmit Daniel Kachhap 506cebe7373SAmit Daniel Kachhap pdata = data->pdata; 50759dfa54cSAmit Daniel Kachhap 50859dfa54cSAmit Daniel Kachhap INIT_WORK(&data->irq_work, exynos_tmu_work); 50959dfa54cSAmit Daniel Kachhap 51059dfa54cSAmit Daniel Kachhap data->clk = devm_clk_get(&pdev->dev, "tmu_apbif"); 51159dfa54cSAmit Daniel Kachhap if (IS_ERR(data->clk)) { 51259dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to get clock\n"); 51359dfa54cSAmit Daniel Kachhap return PTR_ERR(data->clk); 51459dfa54cSAmit Daniel Kachhap } 51559dfa54cSAmit Daniel Kachhap 51659dfa54cSAmit Daniel Kachhap ret = clk_prepare(data->clk); 51759dfa54cSAmit Daniel Kachhap if (ret) 51859dfa54cSAmit Daniel Kachhap return ret; 51959dfa54cSAmit Daniel Kachhap 52059dfa54cSAmit Daniel Kachhap if (pdata->type == SOC_ARCH_EXYNOS || 52159dfa54cSAmit Daniel Kachhap pdata->type == SOC_ARCH_EXYNOS4210) 52259dfa54cSAmit Daniel Kachhap data->soc = pdata->type; 52359dfa54cSAmit Daniel Kachhap else { 52459dfa54cSAmit Daniel Kachhap ret = -EINVAL; 52559dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Platform not supported\n"); 52659dfa54cSAmit Daniel Kachhap goto err_clk; 52759dfa54cSAmit Daniel Kachhap } 52859dfa54cSAmit Daniel Kachhap 52959dfa54cSAmit Daniel Kachhap ret = exynos_tmu_initialize(pdev); 53059dfa54cSAmit Daniel Kachhap if (ret) { 53159dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to initialize TMU\n"); 53259dfa54cSAmit Daniel Kachhap goto err_clk; 53359dfa54cSAmit Daniel Kachhap } 53459dfa54cSAmit Daniel Kachhap 53559dfa54cSAmit Daniel Kachhap exynos_tmu_control(pdev, true); 53659dfa54cSAmit Daniel Kachhap 537cebe7373SAmit Daniel Kachhap /* Allocate a structure to register with the exynos core thermal */ 538cebe7373SAmit Daniel Kachhap sensor_conf = devm_kzalloc(&pdev->dev, 539cebe7373SAmit Daniel Kachhap sizeof(struct thermal_sensor_conf), GFP_KERNEL); 540cebe7373SAmit Daniel Kachhap if (!sensor_conf) { 541cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to allocate registration struct\n"); 542cebe7373SAmit Daniel Kachhap ret = -ENOMEM; 543cebe7373SAmit Daniel Kachhap goto err_clk; 544cebe7373SAmit Daniel Kachhap } 545cebe7373SAmit Daniel Kachhap sprintf(sensor_conf->name, "therm_zone%d", data->id); 546cebe7373SAmit Daniel Kachhap sensor_conf->read_temperature = (int (*)(void *))exynos_tmu_read; 547cebe7373SAmit Daniel Kachhap sensor_conf->write_emul_temp = 548cebe7373SAmit Daniel Kachhap (int (*)(void *, unsigned long))exynos_tmu_set_emulation; 549cebe7373SAmit Daniel Kachhap sensor_conf->driver_data = data; 550cebe7373SAmit Daniel Kachhap sensor_conf->trip_data.trip_count = pdata->trigger_enable[0] + 551bb34b4c8SAmit Daniel Kachhap pdata->trigger_enable[1] + pdata->trigger_enable[2]+ 552bb34b4c8SAmit Daniel Kachhap pdata->trigger_enable[3]; 55359dfa54cSAmit Daniel Kachhap 554cebe7373SAmit Daniel Kachhap for (i = 0; i < sensor_conf->trip_data.trip_count; i++) { 555cebe7373SAmit Daniel Kachhap sensor_conf->trip_data.trip_val[i] = 55659dfa54cSAmit Daniel Kachhap pdata->threshold + pdata->trigger_levels[i]; 557cebe7373SAmit Daniel Kachhap sensor_conf->trip_data.trip_type[i] = 5585c3cf552SAmit Daniel Kachhap pdata->trigger_type[i]; 5595c3cf552SAmit Daniel Kachhap } 56059dfa54cSAmit Daniel Kachhap 561cebe7373SAmit Daniel Kachhap sensor_conf->trip_data.trigger_falling = pdata->threshold_falling; 56259dfa54cSAmit Daniel Kachhap 563cebe7373SAmit Daniel Kachhap sensor_conf->cooling_data.freq_clip_count = pdata->freq_tab_count; 56459dfa54cSAmit Daniel Kachhap for (i = 0; i < pdata->freq_tab_count; i++) { 565cebe7373SAmit Daniel Kachhap sensor_conf->cooling_data.freq_data[i].freq_clip_max = 56659dfa54cSAmit Daniel Kachhap pdata->freq_tab[i].freq_clip_max; 567cebe7373SAmit Daniel Kachhap sensor_conf->cooling_data.freq_data[i].temp_level = 56859dfa54cSAmit Daniel Kachhap pdata->freq_tab[i].temp_level; 56959dfa54cSAmit Daniel Kachhap } 570cebe7373SAmit Daniel Kachhap sensor_conf->dev = &pdev->dev; 571cebe7373SAmit Daniel Kachhap /* Register the sensor with thermal management interface */ 572cebe7373SAmit Daniel Kachhap ret = exynos_register_thermal(sensor_conf); 57359dfa54cSAmit Daniel Kachhap if (ret) { 57459dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to register thermal interface\n"); 57559dfa54cSAmit Daniel Kachhap goto err_clk; 57659dfa54cSAmit Daniel Kachhap } 577cebe7373SAmit Daniel Kachhap data->reg_conf = sensor_conf; 578cebe7373SAmit Daniel Kachhap 579cebe7373SAmit Daniel Kachhap ret = devm_request_irq(&pdev->dev, data->irq, exynos_tmu_irq, 580cebe7373SAmit Daniel Kachhap IRQF_TRIGGER_RISING | IRQF_SHARED, dev_name(&pdev->dev), data); 581cebe7373SAmit Daniel Kachhap if (ret) { 582cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq); 583cebe7373SAmit Daniel Kachhap goto err_clk; 584cebe7373SAmit Daniel Kachhap } 58559dfa54cSAmit Daniel Kachhap 58659dfa54cSAmit Daniel Kachhap return 0; 58759dfa54cSAmit Daniel Kachhap err_clk: 58859dfa54cSAmit Daniel Kachhap clk_unprepare(data->clk); 58959dfa54cSAmit Daniel Kachhap return ret; 59059dfa54cSAmit Daniel Kachhap } 59159dfa54cSAmit Daniel Kachhap 59259dfa54cSAmit Daniel Kachhap static int exynos_tmu_remove(struct platform_device *pdev) 59359dfa54cSAmit Daniel Kachhap { 59459dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 59559dfa54cSAmit Daniel Kachhap 59659dfa54cSAmit Daniel Kachhap exynos_tmu_control(pdev, false); 59759dfa54cSAmit Daniel Kachhap 598cebe7373SAmit Daniel Kachhap exynos_unregister_thermal(data->reg_conf); 59959dfa54cSAmit Daniel Kachhap 60059dfa54cSAmit Daniel Kachhap clk_unprepare(data->clk); 60159dfa54cSAmit Daniel Kachhap 60259dfa54cSAmit Daniel Kachhap return 0; 60359dfa54cSAmit Daniel Kachhap } 60459dfa54cSAmit Daniel Kachhap 60559dfa54cSAmit Daniel Kachhap #ifdef CONFIG_PM_SLEEP 60659dfa54cSAmit Daniel Kachhap static int exynos_tmu_suspend(struct device *dev) 60759dfa54cSAmit Daniel Kachhap { 60859dfa54cSAmit Daniel Kachhap exynos_tmu_control(to_platform_device(dev), false); 60959dfa54cSAmit Daniel Kachhap 61059dfa54cSAmit Daniel Kachhap return 0; 61159dfa54cSAmit Daniel Kachhap } 61259dfa54cSAmit Daniel Kachhap 61359dfa54cSAmit Daniel Kachhap static int exynos_tmu_resume(struct device *dev) 61459dfa54cSAmit Daniel Kachhap { 61559dfa54cSAmit Daniel Kachhap struct platform_device *pdev = to_platform_device(dev); 61659dfa54cSAmit Daniel Kachhap 61759dfa54cSAmit Daniel Kachhap exynos_tmu_initialize(pdev); 61859dfa54cSAmit Daniel Kachhap exynos_tmu_control(pdev, true); 61959dfa54cSAmit Daniel Kachhap 62059dfa54cSAmit Daniel Kachhap return 0; 62159dfa54cSAmit Daniel Kachhap } 62259dfa54cSAmit Daniel Kachhap 62359dfa54cSAmit Daniel Kachhap static SIMPLE_DEV_PM_OPS(exynos_tmu_pm, 62459dfa54cSAmit Daniel Kachhap exynos_tmu_suspend, exynos_tmu_resume); 62559dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_PM (&exynos_tmu_pm) 62659dfa54cSAmit Daniel Kachhap #else 62759dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_PM NULL 62859dfa54cSAmit Daniel Kachhap #endif 62959dfa54cSAmit Daniel Kachhap 63059dfa54cSAmit Daniel Kachhap static struct platform_driver exynos_tmu_driver = { 63159dfa54cSAmit Daniel Kachhap .driver = { 63259dfa54cSAmit Daniel Kachhap .name = "exynos-tmu", 63359dfa54cSAmit Daniel Kachhap .owner = THIS_MODULE, 63459dfa54cSAmit Daniel Kachhap .pm = EXYNOS_TMU_PM, 63559dfa54cSAmit Daniel Kachhap .of_match_table = of_match_ptr(exynos_tmu_match), 63659dfa54cSAmit Daniel Kachhap }, 63759dfa54cSAmit Daniel Kachhap .probe = exynos_tmu_probe, 63859dfa54cSAmit Daniel Kachhap .remove = exynos_tmu_remove, 63959dfa54cSAmit Daniel Kachhap }; 64059dfa54cSAmit Daniel Kachhap 64159dfa54cSAmit Daniel Kachhap module_platform_driver(exynos_tmu_driver); 64259dfa54cSAmit Daniel Kachhap 64359dfa54cSAmit Daniel Kachhap MODULE_DESCRIPTION("EXYNOS TMU Driver"); 64459dfa54cSAmit Daniel Kachhap MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); 64559dfa54cSAmit Daniel Kachhap MODULE_LICENSE("GPL"); 64659dfa54cSAmit Daniel Kachhap MODULE_ALIAS("platform:exynos-tmu"); 647