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> 2959dfa54cSAmit Daniel Kachhap #include <linux/platform_device.h> 3059dfa54cSAmit Daniel Kachhap 3159dfa54cSAmit Daniel Kachhap #include "exynos_thermal_common.h" 32*0c1836a6SAmit Daniel Kachhap #include "exynos_tmu.h" 3359dfa54cSAmit Daniel Kachhap 3459dfa54cSAmit Daniel Kachhap /* Exynos generic registers */ 3559dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_REG_TRIMINFO 0x0 3659dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_REG_CONTROL 0x20 3759dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_REG_STATUS 0x28 3859dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_REG_CURRENT_TEMP 0x40 3959dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_REG_INTEN 0x70 4059dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_REG_INTSTAT 0x74 4159dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_REG_INTCLEAR 0x78 4259dfa54cSAmit Daniel Kachhap 4359dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_TRIM_TEMP_MASK 0xff 4459dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_GAIN_SHIFT 8 4559dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_REF_VOLTAGE_SHIFT 24 4659dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_CORE_ON 3 4759dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_CORE_OFF 2 4859dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_DEF_CODE_TO_TEMP_OFFSET 50 4959dfa54cSAmit Daniel Kachhap 5059dfa54cSAmit Daniel Kachhap /* Exynos4210 specific registers */ 5159dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_REG_THRESHOLD_TEMP 0x44 5259dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_REG_TRIG_LEVEL0 0x50 5359dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_REG_TRIG_LEVEL1 0x54 5459dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_REG_TRIG_LEVEL2 0x58 5559dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_REG_TRIG_LEVEL3 0x5C 5659dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_REG_PAST_TEMP0 0x60 5759dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_REG_PAST_TEMP1 0x64 5859dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_REG_PAST_TEMP2 0x68 5959dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_REG_PAST_TEMP3 0x6C 6059dfa54cSAmit Daniel Kachhap 6159dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_TRIG_LEVEL0_MASK 0x1 6259dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_TRIG_LEVEL1_MASK 0x10 6359dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_TRIG_LEVEL2_MASK 0x100 6459dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_TRIG_LEVEL3_MASK 0x1000 6559dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_INTCLEAR_VAL 0x1111 6659dfa54cSAmit Daniel Kachhap 6759dfa54cSAmit Daniel Kachhap /* Exynos5250 and Exynos4412 specific registers */ 6859dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_TRIMINFO_CON 0x14 6959dfa54cSAmit Daniel Kachhap #define EXYNOS_THD_TEMP_RISE 0x50 7059dfa54cSAmit Daniel Kachhap #define EXYNOS_THD_TEMP_FALL 0x54 7159dfa54cSAmit Daniel Kachhap #define EXYNOS_EMUL_CON 0x80 7259dfa54cSAmit Daniel Kachhap 7359dfa54cSAmit Daniel Kachhap #define EXYNOS_TRIMINFO_RELOAD 0x1 7459dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_CLEAR_RISE_INT 0x111 7559dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_CLEAR_FALL_INT (0x111 << 12) 7659dfa54cSAmit Daniel Kachhap #define EXYNOS_MUX_ADDR_VALUE 6 7759dfa54cSAmit Daniel Kachhap #define EXYNOS_MUX_ADDR_SHIFT 20 7859dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_TRIP_MODE_SHIFT 13 7959dfa54cSAmit Daniel Kachhap 8059dfa54cSAmit Daniel Kachhap #define EFUSE_MIN_VALUE 40 8159dfa54cSAmit Daniel Kachhap #define EFUSE_MAX_VALUE 100 8259dfa54cSAmit Daniel Kachhap 8359dfa54cSAmit Daniel Kachhap #ifdef CONFIG_THERMAL_EMULATION 8459dfa54cSAmit Daniel Kachhap #define EXYNOS_EMUL_TIME 0x57F0 8559dfa54cSAmit Daniel Kachhap #define EXYNOS_EMUL_TIME_SHIFT 16 8659dfa54cSAmit Daniel Kachhap #define EXYNOS_EMUL_DATA_SHIFT 8 8759dfa54cSAmit Daniel Kachhap #define EXYNOS_EMUL_DATA_MASK 0xFF 8859dfa54cSAmit Daniel Kachhap #define EXYNOS_EMUL_ENABLE 0x1 8959dfa54cSAmit Daniel Kachhap #endif /* CONFIG_THERMAL_EMULATION */ 9059dfa54cSAmit Daniel Kachhap 9159dfa54cSAmit Daniel Kachhap struct exynos_tmu_data { 9259dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata; 9359dfa54cSAmit Daniel Kachhap struct resource *mem; 9459dfa54cSAmit Daniel Kachhap void __iomem *base; 9559dfa54cSAmit Daniel Kachhap int irq; 9659dfa54cSAmit Daniel Kachhap enum soc_type soc; 9759dfa54cSAmit Daniel Kachhap struct work_struct irq_work; 9859dfa54cSAmit Daniel Kachhap struct mutex lock; 9959dfa54cSAmit Daniel Kachhap struct clk *clk; 10059dfa54cSAmit Daniel Kachhap u8 temp_error1, temp_error2; 10159dfa54cSAmit Daniel Kachhap }; 10259dfa54cSAmit Daniel Kachhap 10359dfa54cSAmit Daniel Kachhap /* 10459dfa54cSAmit Daniel Kachhap * TMU treats temperature as a mapped temperature code. 10559dfa54cSAmit Daniel Kachhap * The temperature is converted differently depending on the calibration type. 10659dfa54cSAmit Daniel Kachhap */ 10759dfa54cSAmit Daniel Kachhap static int temp_to_code(struct exynos_tmu_data *data, u8 temp) 10859dfa54cSAmit Daniel Kachhap { 10959dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 11059dfa54cSAmit Daniel Kachhap int temp_code; 11159dfa54cSAmit Daniel Kachhap 11259dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS4210) 11359dfa54cSAmit Daniel Kachhap /* temp should range between 25 and 125 */ 11459dfa54cSAmit Daniel Kachhap if (temp < 25 || temp > 125) { 11559dfa54cSAmit Daniel Kachhap temp_code = -EINVAL; 11659dfa54cSAmit Daniel Kachhap goto out; 11759dfa54cSAmit Daniel Kachhap } 11859dfa54cSAmit Daniel Kachhap 11959dfa54cSAmit Daniel Kachhap switch (pdata->cal_type) { 12059dfa54cSAmit Daniel Kachhap case TYPE_TWO_POINT_TRIMMING: 12159dfa54cSAmit Daniel Kachhap temp_code = (temp - 25) * 12259dfa54cSAmit Daniel Kachhap (data->temp_error2 - data->temp_error1) / 12359dfa54cSAmit Daniel Kachhap (85 - 25) + data->temp_error1; 12459dfa54cSAmit Daniel Kachhap break; 12559dfa54cSAmit Daniel Kachhap case TYPE_ONE_POINT_TRIMMING: 12659dfa54cSAmit Daniel Kachhap temp_code = temp + data->temp_error1 - 25; 12759dfa54cSAmit Daniel Kachhap break; 12859dfa54cSAmit Daniel Kachhap default: 12959dfa54cSAmit Daniel Kachhap temp_code = temp + EXYNOS_TMU_DEF_CODE_TO_TEMP_OFFSET; 13059dfa54cSAmit Daniel Kachhap break; 13159dfa54cSAmit Daniel Kachhap } 13259dfa54cSAmit Daniel Kachhap out: 13359dfa54cSAmit Daniel Kachhap return temp_code; 13459dfa54cSAmit Daniel Kachhap } 13559dfa54cSAmit Daniel Kachhap 13659dfa54cSAmit Daniel Kachhap /* 13759dfa54cSAmit Daniel Kachhap * Calculate a temperature value from a temperature code. 13859dfa54cSAmit Daniel Kachhap * The unit of the temperature is degree Celsius. 13959dfa54cSAmit Daniel Kachhap */ 14059dfa54cSAmit Daniel Kachhap static int code_to_temp(struct exynos_tmu_data *data, u8 temp_code) 14159dfa54cSAmit Daniel Kachhap { 14259dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 14359dfa54cSAmit Daniel Kachhap int temp; 14459dfa54cSAmit Daniel Kachhap 14559dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS4210) 14659dfa54cSAmit Daniel Kachhap /* temp_code should range between 75 and 175 */ 14759dfa54cSAmit Daniel Kachhap if (temp_code < 75 || temp_code > 175) { 14859dfa54cSAmit Daniel Kachhap temp = -ENODATA; 14959dfa54cSAmit Daniel Kachhap goto out; 15059dfa54cSAmit Daniel Kachhap } 15159dfa54cSAmit Daniel Kachhap 15259dfa54cSAmit Daniel Kachhap switch (pdata->cal_type) { 15359dfa54cSAmit Daniel Kachhap case TYPE_TWO_POINT_TRIMMING: 15459dfa54cSAmit Daniel Kachhap temp = (temp_code - data->temp_error1) * (85 - 25) / 15559dfa54cSAmit Daniel Kachhap (data->temp_error2 - data->temp_error1) + 25; 15659dfa54cSAmit Daniel Kachhap break; 15759dfa54cSAmit Daniel Kachhap case TYPE_ONE_POINT_TRIMMING: 15859dfa54cSAmit Daniel Kachhap temp = temp_code - data->temp_error1 + 25; 15959dfa54cSAmit Daniel Kachhap break; 16059dfa54cSAmit Daniel Kachhap default: 16159dfa54cSAmit Daniel Kachhap temp = temp_code - EXYNOS_TMU_DEF_CODE_TO_TEMP_OFFSET; 16259dfa54cSAmit Daniel Kachhap break; 16359dfa54cSAmit Daniel Kachhap } 16459dfa54cSAmit Daniel Kachhap out: 16559dfa54cSAmit Daniel Kachhap return temp; 16659dfa54cSAmit Daniel Kachhap } 16759dfa54cSAmit Daniel Kachhap 16859dfa54cSAmit Daniel Kachhap static int exynos_tmu_initialize(struct platform_device *pdev) 16959dfa54cSAmit Daniel Kachhap { 17059dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 17159dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 17259dfa54cSAmit Daniel Kachhap unsigned int status, trim_info; 17359dfa54cSAmit Daniel Kachhap unsigned int rising_threshold = 0, falling_threshold = 0; 17459dfa54cSAmit Daniel Kachhap int ret = 0, threshold_code, i, trigger_levs = 0; 17559dfa54cSAmit Daniel Kachhap 17659dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 17759dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 17859dfa54cSAmit Daniel Kachhap 17959dfa54cSAmit Daniel Kachhap status = readb(data->base + EXYNOS_TMU_REG_STATUS); 18059dfa54cSAmit Daniel Kachhap if (!status) { 18159dfa54cSAmit Daniel Kachhap ret = -EBUSY; 18259dfa54cSAmit Daniel Kachhap goto out; 18359dfa54cSAmit Daniel Kachhap } 18459dfa54cSAmit Daniel Kachhap 18559dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS) { 18659dfa54cSAmit Daniel Kachhap __raw_writel(EXYNOS_TRIMINFO_RELOAD, 18759dfa54cSAmit Daniel Kachhap data->base + EXYNOS_TMU_TRIMINFO_CON); 18859dfa54cSAmit Daniel Kachhap } 18959dfa54cSAmit Daniel Kachhap /* Save trimming info in order to perform calibration */ 19059dfa54cSAmit Daniel Kachhap trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); 19159dfa54cSAmit Daniel Kachhap data->temp_error1 = trim_info & EXYNOS_TMU_TRIM_TEMP_MASK; 19259dfa54cSAmit Daniel Kachhap data->temp_error2 = ((trim_info >> 8) & EXYNOS_TMU_TRIM_TEMP_MASK); 19359dfa54cSAmit Daniel Kachhap 19459dfa54cSAmit Daniel Kachhap if ((EFUSE_MIN_VALUE > data->temp_error1) || 19559dfa54cSAmit Daniel Kachhap (data->temp_error1 > EFUSE_MAX_VALUE) || 19659dfa54cSAmit Daniel Kachhap (data->temp_error2 != 0)) 19759dfa54cSAmit Daniel Kachhap data->temp_error1 = pdata->efuse_value; 19859dfa54cSAmit Daniel Kachhap 19959dfa54cSAmit Daniel Kachhap /* Count trigger levels to be enabled */ 20059dfa54cSAmit Daniel Kachhap for (i = 0; i < MAX_THRESHOLD_LEVS; i++) 20159dfa54cSAmit Daniel Kachhap if (pdata->trigger_levels[i]) 20259dfa54cSAmit Daniel Kachhap trigger_levs++; 20359dfa54cSAmit Daniel Kachhap 20459dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS4210) { 20559dfa54cSAmit Daniel Kachhap /* Write temperature code for threshold */ 20659dfa54cSAmit Daniel Kachhap threshold_code = temp_to_code(data, pdata->threshold); 20759dfa54cSAmit Daniel Kachhap if (threshold_code < 0) { 20859dfa54cSAmit Daniel Kachhap ret = threshold_code; 20959dfa54cSAmit Daniel Kachhap goto out; 21059dfa54cSAmit Daniel Kachhap } 21159dfa54cSAmit Daniel Kachhap writeb(threshold_code, 21259dfa54cSAmit Daniel Kachhap data->base + EXYNOS4210_TMU_REG_THRESHOLD_TEMP); 21359dfa54cSAmit Daniel Kachhap for (i = 0; i < trigger_levs; i++) 21459dfa54cSAmit Daniel Kachhap writeb(pdata->trigger_levels[i], 21559dfa54cSAmit Daniel Kachhap data->base + EXYNOS4210_TMU_REG_TRIG_LEVEL0 + i * 4); 21659dfa54cSAmit Daniel Kachhap 21759dfa54cSAmit Daniel Kachhap writel(EXYNOS4210_TMU_INTCLEAR_VAL, 21859dfa54cSAmit Daniel Kachhap data->base + EXYNOS_TMU_REG_INTCLEAR); 21959dfa54cSAmit Daniel Kachhap } else if (data->soc == SOC_ARCH_EXYNOS) { 22059dfa54cSAmit Daniel Kachhap /* Write temperature code for rising and falling threshold */ 22159dfa54cSAmit Daniel Kachhap for (i = 0; i < trigger_levs; i++) { 22259dfa54cSAmit Daniel Kachhap threshold_code = temp_to_code(data, 22359dfa54cSAmit Daniel Kachhap pdata->trigger_levels[i]); 22459dfa54cSAmit Daniel Kachhap if (threshold_code < 0) { 22559dfa54cSAmit Daniel Kachhap ret = threshold_code; 22659dfa54cSAmit Daniel Kachhap goto out; 22759dfa54cSAmit Daniel Kachhap } 22859dfa54cSAmit Daniel Kachhap rising_threshold |= threshold_code << 8 * i; 22959dfa54cSAmit Daniel Kachhap if (pdata->threshold_falling) { 23059dfa54cSAmit Daniel Kachhap threshold_code = temp_to_code(data, 23159dfa54cSAmit Daniel Kachhap pdata->trigger_levels[i] - 23259dfa54cSAmit Daniel Kachhap pdata->threshold_falling); 23359dfa54cSAmit Daniel Kachhap if (threshold_code > 0) 23459dfa54cSAmit Daniel Kachhap falling_threshold |= 23559dfa54cSAmit Daniel Kachhap threshold_code << 8 * i; 23659dfa54cSAmit Daniel Kachhap } 23759dfa54cSAmit Daniel Kachhap } 23859dfa54cSAmit Daniel Kachhap 23959dfa54cSAmit Daniel Kachhap writel(rising_threshold, 24059dfa54cSAmit Daniel Kachhap data->base + EXYNOS_THD_TEMP_RISE); 24159dfa54cSAmit Daniel Kachhap writel(falling_threshold, 24259dfa54cSAmit Daniel Kachhap data->base + EXYNOS_THD_TEMP_FALL); 24359dfa54cSAmit Daniel Kachhap 24459dfa54cSAmit Daniel Kachhap writel(EXYNOS_TMU_CLEAR_RISE_INT | EXYNOS_TMU_CLEAR_FALL_INT, 24559dfa54cSAmit Daniel Kachhap data->base + EXYNOS_TMU_REG_INTCLEAR); 24659dfa54cSAmit Daniel Kachhap } 24759dfa54cSAmit Daniel Kachhap out: 24859dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 24959dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 25059dfa54cSAmit Daniel Kachhap 25159dfa54cSAmit Daniel Kachhap return ret; 25259dfa54cSAmit Daniel Kachhap } 25359dfa54cSAmit Daniel Kachhap 25459dfa54cSAmit Daniel Kachhap static void exynos_tmu_control(struct platform_device *pdev, bool on) 25559dfa54cSAmit Daniel Kachhap { 25659dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 25759dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = data->pdata; 25859dfa54cSAmit Daniel Kachhap unsigned int con, interrupt_en; 25959dfa54cSAmit Daniel Kachhap 26059dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 26159dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 26259dfa54cSAmit Daniel Kachhap 26359dfa54cSAmit Daniel Kachhap con = pdata->reference_voltage << EXYNOS_TMU_REF_VOLTAGE_SHIFT | 26459dfa54cSAmit Daniel Kachhap pdata->gain << EXYNOS_TMU_GAIN_SHIFT; 26559dfa54cSAmit Daniel Kachhap 26659dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS) { 26759dfa54cSAmit Daniel Kachhap con |= pdata->noise_cancel_mode << EXYNOS_TMU_TRIP_MODE_SHIFT; 26859dfa54cSAmit Daniel Kachhap con |= (EXYNOS_MUX_ADDR_VALUE << EXYNOS_MUX_ADDR_SHIFT); 26959dfa54cSAmit Daniel Kachhap } 27059dfa54cSAmit Daniel Kachhap 27159dfa54cSAmit Daniel Kachhap if (on) { 27259dfa54cSAmit Daniel Kachhap con |= EXYNOS_TMU_CORE_ON; 27359dfa54cSAmit Daniel Kachhap interrupt_en = pdata->trigger_level3_en << 12 | 27459dfa54cSAmit Daniel Kachhap pdata->trigger_level2_en << 8 | 27559dfa54cSAmit Daniel Kachhap pdata->trigger_level1_en << 4 | 27659dfa54cSAmit Daniel Kachhap pdata->trigger_level0_en; 27759dfa54cSAmit Daniel Kachhap if (pdata->threshold_falling) 27859dfa54cSAmit Daniel Kachhap interrupt_en |= interrupt_en << 16; 27959dfa54cSAmit Daniel Kachhap } else { 28059dfa54cSAmit Daniel Kachhap con |= EXYNOS_TMU_CORE_OFF; 28159dfa54cSAmit Daniel Kachhap interrupt_en = 0; /* Disable all interrupts */ 28259dfa54cSAmit Daniel Kachhap } 28359dfa54cSAmit Daniel Kachhap writel(interrupt_en, data->base + EXYNOS_TMU_REG_INTEN); 28459dfa54cSAmit Daniel Kachhap writel(con, data->base + EXYNOS_TMU_REG_CONTROL); 28559dfa54cSAmit Daniel Kachhap 28659dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 28759dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 28859dfa54cSAmit Daniel Kachhap } 28959dfa54cSAmit Daniel Kachhap 29059dfa54cSAmit Daniel Kachhap static int exynos_tmu_read(struct exynos_tmu_data *data) 29159dfa54cSAmit Daniel Kachhap { 29259dfa54cSAmit Daniel Kachhap u8 temp_code; 29359dfa54cSAmit Daniel Kachhap int temp; 29459dfa54cSAmit Daniel Kachhap 29559dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 29659dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 29759dfa54cSAmit Daniel Kachhap 29859dfa54cSAmit Daniel Kachhap temp_code = readb(data->base + EXYNOS_TMU_REG_CURRENT_TEMP); 29959dfa54cSAmit Daniel Kachhap temp = code_to_temp(data, temp_code); 30059dfa54cSAmit Daniel Kachhap 30159dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 30259dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 30359dfa54cSAmit Daniel Kachhap 30459dfa54cSAmit Daniel Kachhap return temp; 30559dfa54cSAmit Daniel Kachhap } 30659dfa54cSAmit Daniel Kachhap 30759dfa54cSAmit Daniel Kachhap #ifdef CONFIG_THERMAL_EMULATION 30859dfa54cSAmit Daniel Kachhap static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) 30959dfa54cSAmit Daniel Kachhap { 31059dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = drv_data; 31159dfa54cSAmit Daniel Kachhap unsigned int reg; 31259dfa54cSAmit Daniel Kachhap int ret = -EINVAL; 31359dfa54cSAmit Daniel Kachhap 31459dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS4210) 31559dfa54cSAmit Daniel Kachhap goto out; 31659dfa54cSAmit Daniel Kachhap 31759dfa54cSAmit Daniel Kachhap if (temp && temp < MCELSIUS) 31859dfa54cSAmit Daniel Kachhap goto out; 31959dfa54cSAmit Daniel Kachhap 32059dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 32159dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 32259dfa54cSAmit Daniel Kachhap 32359dfa54cSAmit Daniel Kachhap reg = readl(data->base + EXYNOS_EMUL_CON); 32459dfa54cSAmit Daniel Kachhap 32559dfa54cSAmit Daniel Kachhap if (temp) { 32659dfa54cSAmit Daniel Kachhap temp /= MCELSIUS; 32759dfa54cSAmit Daniel Kachhap 32859dfa54cSAmit Daniel Kachhap reg = (EXYNOS_EMUL_TIME << EXYNOS_EMUL_TIME_SHIFT) | 32959dfa54cSAmit Daniel Kachhap (temp_to_code(data, temp) 33059dfa54cSAmit Daniel Kachhap << EXYNOS_EMUL_DATA_SHIFT) | EXYNOS_EMUL_ENABLE; 33159dfa54cSAmit Daniel Kachhap } else { 33259dfa54cSAmit Daniel Kachhap reg &= ~EXYNOS_EMUL_ENABLE; 33359dfa54cSAmit Daniel Kachhap } 33459dfa54cSAmit Daniel Kachhap 33559dfa54cSAmit Daniel Kachhap writel(reg, data->base + EXYNOS_EMUL_CON); 33659dfa54cSAmit Daniel Kachhap 33759dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 33859dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 33959dfa54cSAmit Daniel Kachhap return 0; 34059dfa54cSAmit Daniel Kachhap out: 34159dfa54cSAmit Daniel Kachhap return ret; 34259dfa54cSAmit Daniel Kachhap } 34359dfa54cSAmit Daniel Kachhap #else 34459dfa54cSAmit Daniel Kachhap static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp) 34559dfa54cSAmit Daniel Kachhap { return -EINVAL; } 34659dfa54cSAmit Daniel Kachhap #endif/*CONFIG_THERMAL_EMULATION*/ 34759dfa54cSAmit Daniel Kachhap 34859dfa54cSAmit Daniel Kachhap static void exynos_tmu_work(struct work_struct *work) 34959dfa54cSAmit Daniel Kachhap { 35059dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = container_of(work, 35159dfa54cSAmit Daniel Kachhap struct exynos_tmu_data, irq_work); 35259dfa54cSAmit Daniel Kachhap 35359dfa54cSAmit Daniel Kachhap exynos_report_trigger(); 35459dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 35559dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 35659dfa54cSAmit Daniel Kachhap if (data->soc == SOC_ARCH_EXYNOS) 35759dfa54cSAmit Daniel Kachhap writel(EXYNOS_TMU_CLEAR_RISE_INT | 35859dfa54cSAmit Daniel Kachhap EXYNOS_TMU_CLEAR_FALL_INT, 35959dfa54cSAmit Daniel Kachhap data->base + EXYNOS_TMU_REG_INTCLEAR); 36059dfa54cSAmit Daniel Kachhap else 36159dfa54cSAmit Daniel Kachhap writel(EXYNOS4210_TMU_INTCLEAR_VAL, 36259dfa54cSAmit Daniel Kachhap data->base + EXYNOS_TMU_REG_INTCLEAR); 36359dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 36459dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 36559dfa54cSAmit Daniel Kachhap 36659dfa54cSAmit Daniel Kachhap enable_irq(data->irq); 36759dfa54cSAmit Daniel Kachhap } 36859dfa54cSAmit Daniel Kachhap 36959dfa54cSAmit Daniel Kachhap static irqreturn_t exynos_tmu_irq(int irq, void *id) 37059dfa54cSAmit Daniel Kachhap { 37159dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = id; 37259dfa54cSAmit Daniel Kachhap 37359dfa54cSAmit Daniel Kachhap disable_irq_nosync(irq); 37459dfa54cSAmit Daniel Kachhap schedule_work(&data->irq_work); 37559dfa54cSAmit Daniel Kachhap 37659dfa54cSAmit Daniel Kachhap return IRQ_HANDLED; 37759dfa54cSAmit Daniel Kachhap } 37859dfa54cSAmit Daniel Kachhap static struct thermal_sensor_conf exynos_sensor_conf = { 37959dfa54cSAmit Daniel Kachhap .name = "exynos-therm", 38059dfa54cSAmit Daniel Kachhap .read_temperature = (int (*)(void *))exynos_tmu_read, 38159dfa54cSAmit Daniel Kachhap .write_emul_temp = exynos_tmu_set_emulation, 38259dfa54cSAmit Daniel Kachhap }; 38359dfa54cSAmit Daniel Kachhap 38459dfa54cSAmit Daniel Kachhap #if defined(CONFIG_CPU_EXYNOS4210) 38559dfa54cSAmit Daniel Kachhap static struct exynos_tmu_platform_data const exynos4210_default_tmu_data = { 38659dfa54cSAmit Daniel Kachhap .threshold = 80, 38759dfa54cSAmit Daniel Kachhap .trigger_levels[0] = 5, 38859dfa54cSAmit Daniel Kachhap .trigger_levels[1] = 20, 38959dfa54cSAmit Daniel Kachhap .trigger_levels[2] = 30, 39059dfa54cSAmit Daniel Kachhap .trigger_level0_en = 1, 39159dfa54cSAmit Daniel Kachhap .trigger_level1_en = 1, 39259dfa54cSAmit Daniel Kachhap .trigger_level2_en = 1, 39359dfa54cSAmit Daniel Kachhap .trigger_level3_en = 0, 39459dfa54cSAmit Daniel Kachhap .gain = 15, 39559dfa54cSAmit Daniel Kachhap .reference_voltage = 7, 39659dfa54cSAmit Daniel Kachhap .cal_type = TYPE_ONE_POINT_TRIMMING, 39759dfa54cSAmit Daniel Kachhap .freq_tab[0] = { 39859dfa54cSAmit Daniel Kachhap .freq_clip_max = 800 * 1000, 39959dfa54cSAmit Daniel Kachhap .temp_level = 85, 40059dfa54cSAmit Daniel Kachhap }, 40159dfa54cSAmit Daniel Kachhap .freq_tab[1] = { 40259dfa54cSAmit Daniel Kachhap .freq_clip_max = 200 * 1000, 40359dfa54cSAmit Daniel Kachhap .temp_level = 100, 40459dfa54cSAmit Daniel Kachhap }, 40559dfa54cSAmit Daniel Kachhap .freq_tab_count = 2, 40659dfa54cSAmit Daniel Kachhap .type = SOC_ARCH_EXYNOS4210, 40759dfa54cSAmit Daniel Kachhap }; 40859dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_DRV_DATA (&exynos4210_default_tmu_data) 40959dfa54cSAmit Daniel Kachhap #else 41059dfa54cSAmit Daniel Kachhap #define EXYNOS4210_TMU_DRV_DATA (NULL) 41159dfa54cSAmit Daniel Kachhap #endif 41259dfa54cSAmit Daniel Kachhap 41359dfa54cSAmit Daniel Kachhap #if defined(CONFIG_SOC_EXYNOS5250) || defined(CONFIG_SOC_EXYNOS4412) || \ 41459dfa54cSAmit Daniel Kachhap defined(CONFIG_SOC_EXYNOS4212) 41559dfa54cSAmit Daniel Kachhap static struct exynos_tmu_platform_data const exynos_default_tmu_data = { 41659dfa54cSAmit Daniel Kachhap .threshold_falling = 10, 41759dfa54cSAmit Daniel Kachhap .trigger_levels[0] = 85, 41859dfa54cSAmit Daniel Kachhap .trigger_levels[1] = 103, 41959dfa54cSAmit Daniel Kachhap .trigger_levels[2] = 110, 42059dfa54cSAmit Daniel Kachhap .trigger_level0_en = 1, 42159dfa54cSAmit Daniel Kachhap .trigger_level1_en = 1, 42259dfa54cSAmit Daniel Kachhap .trigger_level2_en = 1, 42359dfa54cSAmit Daniel Kachhap .trigger_level3_en = 0, 42459dfa54cSAmit Daniel Kachhap .gain = 8, 42559dfa54cSAmit Daniel Kachhap .reference_voltage = 16, 42659dfa54cSAmit Daniel Kachhap .noise_cancel_mode = 4, 42759dfa54cSAmit Daniel Kachhap .cal_type = TYPE_ONE_POINT_TRIMMING, 42859dfa54cSAmit Daniel Kachhap .efuse_value = 55, 42959dfa54cSAmit Daniel Kachhap .freq_tab[0] = { 43059dfa54cSAmit Daniel Kachhap .freq_clip_max = 800 * 1000, 43159dfa54cSAmit Daniel Kachhap .temp_level = 85, 43259dfa54cSAmit Daniel Kachhap }, 43359dfa54cSAmit Daniel Kachhap .freq_tab[1] = { 43459dfa54cSAmit Daniel Kachhap .freq_clip_max = 200 * 1000, 43559dfa54cSAmit Daniel Kachhap .temp_level = 103, 43659dfa54cSAmit Daniel Kachhap }, 43759dfa54cSAmit Daniel Kachhap .freq_tab_count = 2, 43859dfa54cSAmit Daniel Kachhap .type = SOC_ARCH_EXYNOS, 43959dfa54cSAmit Daniel Kachhap }; 44059dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_DRV_DATA (&exynos_default_tmu_data) 44159dfa54cSAmit Daniel Kachhap #else 44259dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_DRV_DATA (NULL) 44359dfa54cSAmit Daniel Kachhap #endif 44459dfa54cSAmit Daniel Kachhap 44559dfa54cSAmit Daniel Kachhap #ifdef CONFIG_OF 44659dfa54cSAmit Daniel Kachhap static const struct of_device_id exynos_tmu_match[] = { 44759dfa54cSAmit Daniel Kachhap { 44859dfa54cSAmit Daniel Kachhap .compatible = "samsung,exynos4210-tmu", 44959dfa54cSAmit Daniel Kachhap .data = (void *)EXYNOS4210_TMU_DRV_DATA, 45059dfa54cSAmit Daniel Kachhap }, 45159dfa54cSAmit Daniel Kachhap { 45259dfa54cSAmit Daniel Kachhap .compatible = "samsung,exynos4412-tmu", 45359dfa54cSAmit Daniel Kachhap .data = (void *)EXYNOS_TMU_DRV_DATA, 45459dfa54cSAmit Daniel Kachhap }, 45559dfa54cSAmit Daniel Kachhap { 45659dfa54cSAmit Daniel Kachhap .compatible = "samsung,exynos5250-tmu", 45759dfa54cSAmit Daniel Kachhap .data = (void *)EXYNOS_TMU_DRV_DATA, 45859dfa54cSAmit Daniel Kachhap }, 45959dfa54cSAmit Daniel Kachhap {}, 46059dfa54cSAmit Daniel Kachhap }; 46159dfa54cSAmit Daniel Kachhap MODULE_DEVICE_TABLE(of, exynos_tmu_match); 46259dfa54cSAmit Daniel Kachhap #endif 46359dfa54cSAmit Daniel Kachhap 46459dfa54cSAmit Daniel Kachhap static struct platform_device_id exynos_tmu_driver_ids[] = { 46559dfa54cSAmit Daniel Kachhap { 46659dfa54cSAmit Daniel Kachhap .name = "exynos4210-tmu", 46759dfa54cSAmit Daniel Kachhap .driver_data = (kernel_ulong_t)EXYNOS4210_TMU_DRV_DATA, 46859dfa54cSAmit Daniel Kachhap }, 46959dfa54cSAmit Daniel Kachhap { 47059dfa54cSAmit Daniel Kachhap .name = "exynos5250-tmu", 47159dfa54cSAmit Daniel Kachhap .driver_data = (kernel_ulong_t)EXYNOS_TMU_DRV_DATA, 47259dfa54cSAmit Daniel Kachhap }, 47359dfa54cSAmit Daniel Kachhap { }, 47459dfa54cSAmit Daniel Kachhap }; 47559dfa54cSAmit Daniel Kachhap MODULE_DEVICE_TABLE(platform, exynos_tmu_driver_ids); 47659dfa54cSAmit Daniel Kachhap 47759dfa54cSAmit Daniel Kachhap static inline struct exynos_tmu_platform_data *exynos_get_driver_data( 47859dfa54cSAmit Daniel Kachhap struct platform_device *pdev) 47959dfa54cSAmit Daniel Kachhap { 48059dfa54cSAmit Daniel Kachhap #ifdef CONFIG_OF 48159dfa54cSAmit Daniel Kachhap if (pdev->dev.of_node) { 48259dfa54cSAmit Daniel Kachhap const struct of_device_id *match; 48359dfa54cSAmit Daniel Kachhap match = of_match_node(exynos_tmu_match, pdev->dev.of_node); 48459dfa54cSAmit Daniel Kachhap if (!match) 48559dfa54cSAmit Daniel Kachhap return NULL; 48659dfa54cSAmit Daniel Kachhap return (struct exynos_tmu_platform_data *) match->data; 48759dfa54cSAmit Daniel Kachhap } 48859dfa54cSAmit Daniel Kachhap #endif 48959dfa54cSAmit Daniel Kachhap return (struct exynos_tmu_platform_data *) 49059dfa54cSAmit Daniel Kachhap platform_get_device_id(pdev)->driver_data; 49159dfa54cSAmit Daniel Kachhap } 49259dfa54cSAmit Daniel Kachhap 49359dfa54cSAmit Daniel Kachhap static int exynos_tmu_probe(struct platform_device *pdev) 49459dfa54cSAmit Daniel Kachhap { 49559dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data; 49659dfa54cSAmit Daniel Kachhap struct exynos_tmu_platform_data *pdata = pdev->dev.platform_data; 49759dfa54cSAmit Daniel Kachhap int ret, i; 49859dfa54cSAmit Daniel Kachhap 49959dfa54cSAmit Daniel Kachhap if (!pdata) 50059dfa54cSAmit Daniel Kachhap pdata = exynos_get_driver_data(pdev); 50159dfa54cSAmit Daniel Kachhap 50259dfa54cSAmit Daniel Kachhap if (!pdata) { 50359dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "No platform init data supplied.\n"); 50459dfa54cSAmit Daniel Kachhap return -ENODEV; 50559dfa54cSAmit Daniel Kachhap } 50659dfa54cSAmit Daniel Kachhap data = devm_kzalloc(&pdev->dev, sizeof(struct exynos_tmu_data), 50759dfa54cSAmit Daniel Kachhap GFP_KERNEL); 50859dfa54cSAmit Daniel Kachhap if (!data) { 50959dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to allocate driver structure\n"); 51059dfa54cSAmit Daniel Kachhap return -ENOMEM; 51159dfa54cSAmit Daniel Kachhap } 51259dfa54cSAmit Daniel Kachhap 51359dfa54cSAmit Daniel Kachhap data->irq = platform_get_irq(pdev, 0); 51459dfa54cSAmit Daniel Kachhap if (data->irq < 0) { 51559dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to get platform irq\n"); 51659dfa54cSAmit Daniel Kachhap return data->irq; 51759dfa54cSAmit Daniel Kachhap } 51859dfa54cSAmit Daniel Kachhap 51959dfa54cSAmit Daniel Kachhap INIT_WORK(&data->irq_work, exynos_tmu_work); 52059dfa54cSAmit Daniel Kachhap 52159dfa54cSAmit Daniel Kachhap data->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 52259dfa54cSAmit Daniel Kachhap data->base = devm_ioremap_resource(&pdev->dev, data->mem); 52359dfa54cSAmit Daniel Kachhap if (IS_ERR(data->base)) 52459dfa54cSAmit Daniel Kachhap return PTR_ERR(data->base); 52559dfa54cSAmit Daniel Kachhap 52659dfa54cSAmit Daniel Kachhap ret = devm_request_irq(&pdev->dev, data->irq, exynos_tmu_irq, 52759dfa54cSAmit Daniel Kachhap IRQF_TRIGGER_RISING, "exynos-tmu", data); 52859dfa54cSAmit Daniel Kachhap if (ret) { 52959dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq); 53059dfa54cSAmit Daniel Kachhap return ret; 53159dfa54cSAmit Daniel Kachhap } 53259dfa54cSAmit Daniel Kachhap 53359dfa54cSAmit Daniel Kachhap data->clk = devm_clk_get(&pdev->dev, "tmu_apbif"); 53459dfa54cSAmit Daniel Kachhap if (IS_ERR(data->clk)) { 53559dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to get clock\n"); 53659dfa54cSAmit Daniel Kachhap return PTR_ERR(data->clk); 53759dfa54cSAmit Daniel Kachhap } 53859dfa54cSAmit Daniel Kachhap 53959dfa54cSAmit Daniel Kachhap ret = clk_prepare(data->clk); 54059dfa54cSAmit Daniel Kachhap if (ret) 54159dfa54cSAmit Daniel Kachhap return ret; 54259dfa54cSAmit Daniel Kachhap 54359dfa54cSAmit Daniel Kachhap if (pdata->type == SOC_ARCH_EXYNOS || 54459dfa54cSAmit Daniel Kachhap pdata->type == SOC_ARCH_EXYNOS4210) 54559dfa54cSAmit Daniel Kachhap data->soc = pdata->type; 54659dfa54cSAmit Daniel Kachhap else { 54759dfa54cSAmit Daniel Kachhap ret = -EINVAL; 54859dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Platform not supported\n"); 54959dfa54cSAmit Daniel Kachhap goto err_clk; 55059dfa54cSAmit Daniel Kachhap } 55159dfa54cSAmit Daniel Kachhap 55259dfa54cSAmit Daniel Kachhap data->pdata = pdata; 55359dfa54cSAmit Daniel Kachhap platform_set_drvdata(pdev, data); 55459dfa54cSAmit Daniel Kachhap mutex_init(&data->lock); 55559dfa54cSAmit Daniel Kachhap 55659dfa54cSAmit Daniel Kachhap ret = exynos_tmu_initialize(pdev); 55759dfa54cSAmit Daniel Kachhap if (ret) { 55859dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to initialize TMU\n"); 55959dfa54cSAmit Daniel Kachhap goto err_clk; 56059dfa54cSAmit Daniel Kachhap } 56159dfa54cSAmit Daniel Kachhap 56259dfa54cSAmit Daniel Kachhap exynos_tmu_control(pdev, true); 56359dfa54cSAmit Daniel Kachhap 56459dfa54cSAmit Daniel Kachhap /* Register the sensor with thermal management interface */ 56559dfa54cSAmit Daniel Kachhap (&exynos_sensor_conf)->private_data = data; 56659dfa54cSAmit Daniel Kachhap exynos_sensor_conf.trip_data.trip_count = pdata->trigger_level0_en + 56759dfa54cSAmit Daniel Kachhap pdata->trigger_level1_en + pdata->trigger_level2_en + 56859dfa54cSAmit Daniel Kachhap pdata->trigger_level3_en; 56959dfa54cSAmit Daniel Kachhap 57059dfa54cSAmit Daniel Kachhap for (i = 0; i < exynos_sensor_conf.trip_data.trip_count; i++) 57159dfa54cSAmit Daniel Kachhap exynos_sensor_conf.trip_data.trip_val[i] = 57259dfa54cSAmit Daniel Kachhap pdata->threshold + pdata->trigger_levels[i]; 57359dfa54cSAmit Daniel Kachhap 57459dfa54cSAmit Daniel Kachhap exynos_sensor_conf.trip_data.trigger_falling = pdata->threshold_falling; 57559dfa54cSAmit Daniel Kachhap 57659dfa54cSAmit Daniel Kachhap exynos_sensor_conf.cooling_data.freq_clip_count = 57759dfa54cSAmit Daniel Kachhap pdata->freq_tab_count; 57859dfa54cSAmit Daniel Kachhap for (i = 0; i < pdata->freq_tab_count; i++) { 57959dfa54cSAmit Daniel Kachhap exynos_sensor_conf.cooling_data.freq_data[i].freq_clip_max = 58059dfa54cSAmit Daniel Kachhap pdata->freq_tab[i].freq_clip_max; 58159dfa54cSAmit Daniel Kachhap exynos_sensor_conf.cooling_data.freq_data[i].temp_level = 58259dfa54cSAmit Daniel Kachhap pdata->freq_tab[i].temp_level; 58359dfa54cSAmit Daniel Kachhap } 58459dfa54cSAmit Daniel Kachhap 58559dfa54cSAmit Daniel Kachhap ret = exynos_register_thermal(&exynos_sensor_conf); 58659dfa54cSAmit Daniel Kachhap if (ret) { 58759dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to register thermal interface\n"); 58859dfa54cSAmit Daniel Kachhap goto err_clk; 58959dfa54cSAmit Daniel Kachhap } 59059dfa54cSAmit Daniel Kachhap 59159dfa54cSAmit Daniel Kachhap return 0; 59259dfa54cSAmit Daniel Kachhap err_clk: 59359dfa54cSAmit Daniel Kachhap clk_unprepare(data->clk); 59459dfa54cSAmit Daniel Kachhap return ret; 59559dfa54cSAmit Daniel Kachhap } 59659dfa54cSAmit Daniel Kachhap 59759dfa54cSAmit Daniel Kachhap static int exynos_tmu_remove(struct platform_device *pdev) 59859dfa54cSAmit Daniel Kachhap { 59959dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 60059dfa54cSAmit Daniel Kachhap 60159dfa54cSAmit Daniel Kachhap exynos_tmu_control(pdev, false); 60259dfa54cSAmit Daniel Kachhap 60359dfa54cSAmit Daniel Kachhap exynos_unregister_thermal(); 60459dfa54cSAmit Daniel Kachhap 60559dfa54cSAmit Daniel Kachhap clk_unprepare(data->clk); 60659dfa54cSAmit Daniel Kachhap 60759dfa54cSAmit Daniel Kachhap return 0; 60859dfa54cSAmit Daniel Kachhap } 60959dfa54cSAmit Daniel Kachhap 61059dfa54cSAmit Daniel Kachhap #ifdef CONFIG_PM_SLEEP 61159dfa54cSAmit Daniel Kachhap static int exynos_tmu_suspend(struct device *dev) 61259dfa54cSAmit Daniel Kachhap { 61359dfa54cSAmit Daniel Kachhap exynos_tmu_control(to_platform_device(dev), false); 61459dfa54cSAmit Daniel Kachhap 61559dfa54cSAmit Daniel Kachhap return 0; 61659dfa54cSAmit Daniel Kachhap } 61759dfa54cSAmit Daniel Kachhap 61859dfa54cSAmit Daniel Kachhap static int exynos_tmu_resume(struct device *dev) 61959dfa54cSAmit Daniel Kachhap { 62059dfa54cSAmit Daniel Kachhap struct platform_device *pdev = to_platform_device(dev); 62159dfa54cSAmit Daniel Kachhap 62259dfa54cSAmit Daniel Kachhap exynos_tmu_initialize(pdev); 62359dfa54cSAmit Daniel Kachhap exynos_tmu_control(pdev, true); 62459dfa54cSAmit Daniel Kachhap 62559dfa54cSAmit Daniel Kachhap return 0; 62659dfa54cSAmit Daniel Kachhap } 62759dfa54cSAmit Daniel Kachhap 62859dfa54cSAmit Daniel Kachhap static SIMPLE_DEV_PM_OPS(exynos_tmu_pm, 62959dfa54cSAmit Daniel Kachhap exynos_tmu_suspend, exynos_tmu_resume); 63059dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_PM (&exynos_tmu_pm) 63159dfa54cSAmit Daniel Kachhap #else 63259dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_PM NULL 63359dfa54cSAmit Daniel Kachhap #endif 63459dfa54cSAmit Daniel Kachhap 63559dfa54cSAmit Daniel Kachhap static struct platform_driver exynos_tmu_driver = { 63659dfa54cSAmit Daniel Kachhap .driver = { 63759dfa54cSAmit Daniel Kachhap .name = "exynos-tmu", 63859dfa54cSAmit Daniel Kachhap .owner = THIS_MODULE, 63959dfa54cSAmit Daniel Kachhap .pm = EXYNOS_TMU_PM, 64059dfa54cSAmit Daniel Kachhap .of_match_table = of_match_ptr(exynos_tmu_match), 64159dfa54cSAmit Daniel Kachhap }, 64259dfa54cSAmit Daniel Kachhap .probe = exynos_tmu_probe, 64359dfa54cSAmit Daniel Kachhap .remove = exynos_tmu_remove, 64459dfa54cSAmit Daniel Kachhap .id_table = exynos_tmu_driver_ids, 64559dfa54cSAmit Daniel Kachhap }; 64659dfa54cSAmit Daniel Kachhap 64759dfa54cSAmit Daniel Kachhap module_platform_driver(exynos_tmu_driver); 64859dfa54cSAmit Daniel Kachhap 64959dfa54cSAmit Daniel Kachhap MODULE_DESCRIPTION("EXYNOS TMU Driver"); 65059dfa54cSAmit Daniel Kachhap MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); 65159dfa54cSAmit Daniel Kachhap MODULE_LICENSE("GPL"); 65259dfa54cSAmit Daniel Kachhap MODULE_ALIAS("platform:exynos-tmu"); 653