11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 259dfa54cSAmit Daniel Kachhap /* 3ca07ee4eSKrzysztof Kozlowski * exynos_tmu.c - Samsung Exynos TMU (Thermal Management Unit) 459dfa54cSAmit Daniel Kachhap * 53b6a1a80SLukasz Majewski * Copyright (C) 2014 Samsung Electronics 63b6a1a80SLukasz Majewski * Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> 73b6a1a80SLukasz Majewski * Lukasz Majewski <l.majewski@samsung.com> 83b6a1a80SLukasz Majewski * 959dfa54cSAmit Daniel Kachhap * Copyright (C) 2011 Samsung Electronics 1059dfa54cSAmit Daniel Kachhap * Donggeun Kim <dg77.kim@samsung.com> 1159dfa54cSAmit Daniel Kachhap * Amit Daniel Kachhap <amit.kachhap@linaro.org> 1259dfa54cSAmit Daniel Kachhap */ 1359dfa54cSAmit Daniel Kachhap 1459dfa54cSAmit Daniel Kachhap #include <linux/clk.h> 1559dfa54cSAmit Daniel Kachhap #include <linux/io.h> 1659dfa54cSAmit Daniel Kachhap #include <linux/interrupt.h> 1759dfa54cSAmit Daniel Kachhap #include <linux/module.h> 18fee88e2bSMaciej Purski #include <linux/of_device.h> 19cebe7373SAmit Daniel Kachhap #include <linux/of_address.h> 20cebe7373SAmit Daniel Kachhap #include <linux/of_irq.h> 2159dfa54cSAmit Daniel Kachhap #include <linux/platform_device.h> 22498d22f6SAmit Daniel Kachhap #include <linux/regulator/consumer.h> 2359dfa54cSAmit Daniel Kachhap 247efd18a2SBartlomiej Zolnierkiewicz #include <dt-bindings/thermal/thermal_exynos.h> 257efd18a2SBartlomiej Zolnierkiewicz 263b6a1a80SLukasz Majewski #include "../thermal_core.h" 272845f6ecSBartlomiej Zolnierkiewicz 282845f6ecSBartlomiej Zolnierkiewicz /* Exynos generic registers */ 292845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_TRIMINFO 0x0 302845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_CONTROL 0x20 312845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_STATUS 0x28 322845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_CURRENT_TEMP 0x40 332845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_INTEN 0x70 342845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_INTSTAT 0x74 352845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_INTCLEAR 0x78 362845f6ecSBartlomiej Zolnierkiewicz 372845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TEMP_MASK 0xff 382845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REF_VOLTAGE_SHIFT 24 392845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REF_VOLTAGE_MASK 0x1f 402845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_BUF_SLOPE_SEL_MASK 0xf 412845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT 8 422845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_CORE_EN_SHIFT 0 432845f6ecSBartlomiej Zolnierkiewicz 442845f6ecSBartlomiej Zolnierkiewicz /* Exynos3250 specific registers */ 452845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TRIMINFO_CON1 0x10 462845f6ecSBartlomiej Zolnierkiewicz 472845f6ecSBartlomiej Zolnierkiewicz /* Exynos4210 specific registers */ 482845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS4210_TMU_REG_THRESHOLD_TEMP 0x44 492845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS4210_TMU_REG_TRIG_LEVEL0 0x50 502845f6ecSBartlomiej Zolnierkiewicz 512845f6ecSBartlomiej Zolnierkiewicz /* Exynos5250, Exynos4412, Exynos3250 specific registers */ 522845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TRIMINFO_CON2 0x14 532845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_THD_TEMP_RISE 0x50 542845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_THD_TEMP_FALL 0x54 552845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_CON 0x80 562845f6ecSBartlomiej Zolnierkiewicz 572845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TRIMINFO_RELOAD_ENABLE 1 582845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TRIMINFO_25_SHIFT 0 592845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TRIMINFO_85_SHIFT 8 602845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TRIP_MODE_SHIFT 13 612845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TRIP_MODE_MASK 0x7 622845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_THERM_TRIP_EN_SHIFT 12 632845f6ecSBartlomiej Zolnierkiewicz 642845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_INTEN_RISE0_SHIFT 0 652845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_INTEN_FALL0_SHIFT 16 662845f6ecSBartlomiej Zolnierkiewicz 672845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_TIME 0x57F0 682845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_TIME_MASK 0xffff 692845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_TIME_SHIFT 16 702845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_DATA_SHIFT 8 712845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_DATA_MASK 0xFF 722845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_ENABLE 0x1 732845f6ecSBartlomiej Zolnierkiewicz 742845f6ecSBartlomiej Zolnierkiewicz /* Exynos5260 specific */ 752845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS5260_TMU_REG_INTEN 0xC0 762845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS5260_TMU_REG_INTSTAT 0xC4 772845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS5260_TMU_REG_INTCLEAR 0xC8 782845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS5260_EMUL_CON 0x100 792845f6ecSBartlomiej Zolnierkiewicz 802845f6ecSBartlomiej Zolnierkiewicz /* Exynos4412 specific */ 812845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS4412_MUX_ADDR_VALUE 6 822845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS4412_MUX_ADDR_SHIFT 20 832845f6ecSBartlomiej Zolnierkiewicz 84488c7455SChanwoo Choi /* Exynos5433 specific registers */ 85488c7455SChanwoo Choi #define EXYNOS5433_THD_TEMP_RISE3_0 0x050 86488c7455SChanwoo Choi #define EXYNOS5433_THD_TEMP_RISE7_4 0x054 87488c7455SChanwoo Choi #define EXYNOS5433_THD_TEMP_FALL3_0 0x060 88488c7455SChanwoo Choi #define EXYNOS5433_THD_TEMP_FALL7_4 0x064 89488c7455SChanwoo Choi #define EXYNOS5433_TMU_REG_INTEN 0x0c0 90488c7455SChanwoo Choi #define EXYNOS5433_TMU_REG_INTPEND 0x0c8 91488c7455SChanwoo Choi #define EXYNOS5433_TMU_EMUL_CON 0x110 92488c7455SChanwoo Choi #define EXYNOS5433_TMU_PD_DET_EN 0x130 93488c7455SChanwoo Choi 94488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_SENSOR_ID_SHIFT 16 95488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_CALIB_SEL_SHIFT 23 96488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_SENSOR_ID_MASK \ 97488c7455SChanwoo Choi (0xf << EXYNOS5433_TRIMINFO_SENSOR_ID_SHIFT) 98488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_CALIB_SEL_MASK BIT(23) 99488c7455SChanwoo Choi 100488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_ONE_POINT_TRIMMING 0 101488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_TWO_POINT_TRIMMING 1 102488c7455SChanwoo Choi 103488c7455SChanwoo Choi #define EXYNOS5433_PD_DET_EN 1 104488c7455SChanwoo Choi 10561020d18SBartlomiej Zolnierkiewicz #define EXYNOS5433_G3D_BASE 0x10070000 10659dfa54cSAmit Daniel Kachhap 1076c247393SAbhilash Kesavan /* Exynos7 specific registers */ 1086c247393SAbhilash Kesavan #define EXYNOS7_THD_TEMP_RISE7_6 0x50 1096c247393SAbhilash Kesavan #define EXYNOS7_THD_TEMP_FALL7_6 0x60 1106c247393SAbhilash Kesavan #define EXYNOS7_TMU_REG_INTEN 0x110 1116c247393SAbhilash Kesavan #define EXYNOS7_TMU_REG_INTPEND 0x118 1126c247393SAbhilash Kesavan #define EXYNOS7_TMU_REG_EMUL_CON 0x160 1136c247393SAbhilash Kesavan 1146c247393SAbhilash Kesavan #define EXYNOS7_TMU_TEMP_MASK 0x1ff 1156c247393SAbhilash Kesavan #define EXYNOS7_PD_DET_EN_SHIFT 23 1166c247393SAbhilash Kesavan #define EXYNOS7_TMU_INTEN_RISE0_SHIFT 0 1176c247393SAbhilash Kesavan #define EXYNOS7_EMUL_DATA_SHIFT 7 1186c247393SAbhilash Kesavan #define EXYNOS7_EMUL_DATA_MASK 0x1ff 1196c247393SAbhilash Kesavan 120718b4ca1SBartlomiej Zolnierkiewicz #define EXYNOS_FIRST_POINT_TRIM 25 121718b4ca1SBartlomiej Zolnierkiewicz #define EXYNOS_SECOND_POINT_TRIM 85 122718b4ca1SBartlomiej Zolnierkiewicz 12309d29426SBartlomiej Zolnierkiewicz #define EXYNOS_NOISE_CANCEL_MODE 4 12409d29426SBartlomiej Zolnierkiewicz 1253b6a1a80SLukasz Majewski #define MCELSIUS 1000 1267efd18a2SBartlomiej Zolnierkiewicz 1277efd18a2SBartlomiej Zolnierkiewicz enum soc_type { 1287efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS3250 = 1, 1297efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS4210, 1307efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS4412, 1317efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5250, 1327efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5260, 1337efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5420, 1347efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5420_TRIMINFO, 1357efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5433, 1367efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS7, 1377efd18a2SBartlomiej Zolnierkiewicz }; 1387efd18a2SBartlomiej Zolnierkiewicz 139cebe7373SAmit Daniel Kachhap /** 140cebe7373SAmit Daniel Kachhap * struct exynos_tmu_data : A structure to hold the private data of the TMU 1419625e9e6SAmit Kucheria * driver 142cebe7373SAmit Daniel Kachhap * @id: identifier of the one instance of the TMU controller. 143cebe7373SAmit Daniel Kachhap * @base: base address of the single instance of the TMU controller. 1449025d563SNaveen Krishna Chatradhi * @base_second: base address of the common registers of the TMU controller. 145cebe7373SAmit Daniel Kachhap * @irq: irq number of the TMU controller. 146cebe7373SAmit Daniel Kachhap * @soc: id of the SOC type. 147cebe7373SAmit Daniel Kachhap * @irq_work: pointer to the irq work structure. 148cebe7373SAmit Daniel Kachhap * @lock: lock to implement synchronization. 149cebe7373SAmit Daniel Kachhap * @clk: pointer to the clock structure. 15014a11dc7SNaveen Krishna Chatradhi * @clk_sec: pointer to the clock structure for accessing the base_second. 1516c247393SAbhilash Kesavan * @sclk: pointer to the clock structure for accessing the tmu special clk. 152199b3e3cSBartlomiej Zolnierkiewicz * @cal_type: calibration type for temperature 153e3ed3649SBartlomiej Zolnierkiewicz * @efuse_value: SoC defined fuse value 154e3ed3649SBartlomiej Zolnierkiewicz * @min_efuse_value: minimum valid trimming data 155e3ed3649SBartlomiej Zolnierkiewicz * @max_efuse_value: maximum valid trimming data 156cebe7373SAmit Daniel Kachhap * @temp_error1: fused value of the first point trim. 157cebe7373SAmit Daniel Kachhap * @temp_error2: fused value of the second point trim. 158fccfe099SBartlomiej Zolnierkiewicz * @gain: gain of amplifier in the positive-TC generator block 159fccfe099SBartlomiej Zolnierkiewicz * 0 < gain <= 15 16061020d18SBartlomiej Zolnierkiewicz * @reference_voltage: reference voltage of amplifier 16161020d18SBartlomiej Zolnierkiewicz * in the positive-TC generator block 16261020d18SBartlomiej Zolnierkiewicz * 0 < reference_voltage <= 31 163498d22f6SAmit Daniel Kachhap * @regulator: pointer to the TMU regulator structure. 164cebe7373SAmit Daniel Kachhap * @reg_conf: pointer to structure to register with core thermal. 1659625e9e6SAmit Kucheria * @tzd: pointer to thermal_zone_device structure 1663a3a5f15SKrzysztof Kozlowski * @ntrip: number of supported trip points. 16788fc6f73SMarek Szyprowski * @enabled: current status of TMU device 1689625e9e6SAmit Kucheria * @tmu_set_trip_temp: SoC specific method to set trip (rising threshold) 1699625e9e6SAmit Kucheria * @tmu_set_trip_hyst: SoC specific to set hysteresis (falling threshold) 17072d1100bSBartlomiej Zolnierkiewicz * @tmu_initialize: SoC specific TMU initialization method 17137f9034fSBartlomiej Zolnierkiewicz * @tmu_control: SoC specific TMU control method 172b79985caSBartlomiej Zolnierkiewicz * @tmu_read: SoC specific TMU temperature read method 173285d994aSBartlomiej Zolnierkiewicz * @tmu_set_emulation: SoC specific TMU emulation setting method 174a7331f72SBartlomiej Zolnierkiewicz * @tmu_clear_irqs: SoC specific TMU interrupts clearing method 175cebe7373SAmit Daniel Kachhap */ 17659dfa54cSAmit Daniel Kachhap struct exynos_tmu_data { 177cebe7373SAmit Daniel Kachhap int id; 17859dfa54cSAmit Daniel Kachhap void __iomem *base; 1799025d563SNaveen Krishna Chatradhi void __iomem *base_second; 18059dfa54cSAmit Daniel Kachhap int irq; 18159dfa54cSAmit Daniel Kachhap enum soc_type soc; 18259dfa54cSAmit Daniel Kachhap struct work_struct irq_work; 18359dfa54cSAmit Daniel Kachhap struct mutex lock; 1846c247393SAbhilash Kesavan struct clk *clk, *clk_sec, *sclk; 185199b3e3cSBartlomiej Zolnierkiewicz u32 cal_type; 186e3ed3649SBartlomiej Zolnierkiewicz u32 efuse_value; 187e3ed3649SBartlomiej Zolnierkiewicz u32 min_efuse_value; 188e3ed3649SBartlomiej Zolnierkiewicz u32 max_efuse_value; 1896c247393SAbhilash Kesavan u16 temp_error1, temp_error2; 190fccfe099SBartlomiej Zolnierkiewicz u8 gain; 19161020d18SBartlomiej Zolnierkiewicz u8 reference_voltage; 192498d22f6SAmit Daniel Kachhap struct regulator *regulator; 1933b6a1a80SLukasz Majewski struct thermal_zone_device *tzd; 1943a3a5f15SKrzysztof Kozlowski unsigned int ntrip; 19588fc6f73SMarek Szyprowski bool enabled; 1963b6a1a80SLukasz Majewski 197c8f8f768SBartlomiej Zolnierkiewicz void (*tmu_set_trip_temp)(struct exynos_tmu_data *data, int trip, 198c8f8f768SBartlomiej Zolnierkiewicz u8 temp); 199c8f8f768SBartlomiej Zolnierkiewicz void (*tmu_set_trip_hyst)(struct exynos_tmu_data *data, int trip, 200c8f8f768SBartlomiej Zolnierkiewicz u8 temp, u8 hyst); 201c35268f5SBartlomiej Zolnierkiewicz void (*tmu_initialize)(struct platform_device *pdev); 20237f9034fSBartlomiej Zolnierkiewicz void (*tmu_control)(struct platform_device *pdev, bool on); 203b79985caSBartlomiej Zolnierkiewicz int (*tmu_read)(struct exynos_tmu_data *data); 20417e8351aSSascha Hauer void (*tmu_set_emulation)(struct exynos_tmu_data *data, int temp); 205a7331f72SBartlomiej Zolnierkiewicz void (*tmu_clear_irqs)(struct exynos_tmu_data *data); 20659dfa54cSAmit Daniel Kachhap }; 20759dfa54cSAmit Daniel Kachhap 20859dfa54cSAmit Daniel Kachhap /* 20959dfa54cSAmit Daniel Kachhap * TMU treats temperature as a mapped temperature code. 21059dfa54cSAmit Daniel Kachhap * The temperature is converted differently depending on the calibration type. 21159dfa54cSAmit Daniel Kachhap */ 21259dfa54cSAmit Daniel Kachhap static int temp_to_code(struct exynos_tmu_data *data, u8 temp) 21359dfa54cSAmit Daniel Kachhap { 214199b3e3cSBartlomiej Zolnierkiewicz if (data->cal_type == TYPE_ONE_POINT_TRIMMING) 215718b4ca1SBartlomiej Zolnierkiewicz return temp + data->temp_error1 - EXYNOS_FIRST_POINT_TRIM; 21659dfa54cSAmit Daniel Kachhap 217718b4ca1SBartlomiej Zolnierkiewicz return (temp - EXYNOS_FIRST_POINT_TRIM) * 21859dfa54cSAmit Daniel Kachhap (data->temp_error2 - data->temp_error1) / 219718b4ca1SBartlomiej Zolnierkiewicz (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) + 220bb34b4c8SAmit Daniel Kachhap data->temp_error1; 22159dfa54cSAmit Daniel Kachhap } 22259dfa54cSAmit Daniel Kachhap 22359dfa54cSAmit Daniel Kachhap /* 22459dfa54cSAmit Daniel Kachhap * Calculate a temperature value from a temperature code. 22559dfa54cSAmit Daniel Kachhap * The unit of the temperature is degree Celsius. 22659dfa54cSAmit Daniel Kachhap */ 2276c247393SAbhilash Kesavan static int code_to_temp(struct exynos_tmu_data *data, u16 temp_code) 22859dfa54cSAmit Daniel Kachhap { 229199b3e3cSBartlomiej Zolnierkiewicz if (data->cal_type == TYPE_ONE_POINT_TRIMMING) 230718b4ca1SBartlomiej Zolnierkiewicz return temp_code - data->temp_error1 + EXYNOS_FIRST_POINT_TRIM; 23159dfa54cSAmit Daniel Kachhap 2329c933b1bSBartlomiej Zolnierkiewicz return (temp_code - data->temp_error1) * 233718b4ca1SBartlomiej Zolnierkiewicz (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) / 234bb34b4c8SAmit Daniel Kachhap (data->temp_error2 - data->temp_error1) + 235718b4ca1SBartlomiej Zolnierkiewicz EXYNOS_FIRST_POINT_TRIM; 23659dfa54cSAmit Daniel Kachhap } 23759dfa54cSAmit Daniel Kachhap 2388328a4b1SBartlomiej Zolnierkiewicz static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info) 239b835ced1SBartlomiej Zolnierkiewicz { 240aef27b65SBartlomiej Zolnierkiewicz u16 tmu_temp_mask = 241aef27b65SBartlomiej Zolnierkiewicz (data->soc == SOC_ARCH_EXYNOS7) ? EXYNOS7_TMU_TEMP_MASK 242aef27b65SBartlomiej Zolnierkiewicz : EXYNOS_TMU_TEMP_MASK; 24359dfa54cSAmit Daniel Kachhap 244aef27b65SBartlomiej Zolnierkiewicz data->temp_error1 = trim_info & tmu_temp_mask; 24599d67fb9SBartlomiej Zolnierkiewicz data->temp_error2 = ((trim_info >> EXYNOS_TRIMINFO_85_SHIFT) & 246b8d582b9SAmit Daniel Kachhap EXYNOS_TMU_TEMP_MASK); 24759dfa54cSAmit Daniel Kachhap 2485000806cSAmit Daniel Kachhap if (!data->temp_error1 || 249e3ed3649SBartlomiej Zolnierkiewicz (data->min_efuse_value > data->temp_error1) || 250e3ed3649SBartlomiej Zolnierkiewicz (data->temp_error1 > data->max_efuse_value)) 251e3ed3649SBartlomiej Zolnierkiewicz data->temp_error1 = data->efuse_value & EXYNOS_TMU_TEMP_MASK; 2525000806cSAmit Daniel Kachhap 2535000806cSAmit Daniel Kachhap if (!data->temp_error2) 2545000806cSAmit Daniel Kachhap data->temp_error2 = 255e3ed3649SBartlomiej Zolnierkiewicz (data->efuse_value >> EXYNOS_TRIMINFO_85_SHIFT) & 2565000806cSAmit Daniel Kachhap EXYNOS_TMU_TEMP_MASK; 2578328a4b1SBartlomiej Zolnierkiewicz } 25859dfa54cSAmit Daniel Kachhap 25959dfa54cSAmit Daniel Kachhap static int exynos_tmu_initialize(struct platform_device *pdev) 26059dfa54cSAmit Daniel Kachhap { 26159dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 26275e0f100SBartlomiej Zolnierkiewicz struct thermal_zone_device *tzd = data->tzd; 26397b3881bSBartlomiej Zolnierkiewicz unsigned int status; 264*ca38255eSDaniel Lezcano int ret = 0, temp; 26575e0f100SBartlomiej Zolnierkiewicz 2668f1c404bSBartlomiej Zolnierkiewicz if (data->soc != SOC_ARCH_EXYNOS5433) /* FIXME */ 2678f1c404bSBartlomiej Zolnierkiewicz ret = tzd->ops->get_crit_temp(tzd, &temp); 2688f1c404bSBartlomiej Zolnierkiewicz if (ret) { 2698f1c404bSBartlomiej Zolnierkiewicz dev_err(&pdev->dev, 2708f1c404bSBartlomiej Zolnierkiewicz "No CRITICAL trip point defined in device tree!\n"); 2718f1c404bSBartlomiej Zolnierkiewicz goto out; 2728f1c404bSBartlomiej Zolnierkiewicz } 2738f1c404bSBartlomiej Zolnierkiewicz 27475e0f100SBartlomiej Zolnierkiewicz if (of_thermal_get_ntrips(tzd) > data->ntrip) { 2753a3a5f15SKrzysztof Kozlowski dev_info(&pdev->dev, 2763a3a5f15SKrzysztof Kozlowski "More trip points than supported by this TMU.\n"); 2773a3a5f15SKrzysztof Kozlowski dev_info(&pdev->dev, 2783a3a5f15SKrzysztof Kozlowski "%d trip points should be configured in polling mode.\n", 27975e0f100SBartlomiej Zolnierkiewicz (of_thermal_get_ntrips(tzd) - data->ntrip)); 2803a3a5f15SKrzysztof Kozlowski } 2813a3a5f15SKrzysztof Kozlowski 28259dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 28359dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 28459dfa54cSAmit Daniel Kachhap if (!IS_ERR(data->clk_sec)) 28559dfa54cSAmit Daniel Kachhap clk_enable(data->clk_sec); 28697b3881bSBartlomiej Zolnierkiewicz 28797b3881bSBartlomiej Zolnierkiewicz status = readb(data->base + EXYNOS_TMU_REG_STATUS); 288fac36bacSBartlomiej Zolnierkiewicz if (!status) { 28997b3881bSBartlomiej Zolnierkiewicz ret = -EBUSY; 290fac36bacSBartlomiej Zolnierkiewicz } else { 291c8f8f768SBartlomiej Zolnierkiewicz int i, ntrips = 292c8f8f768SBartlomiej Zolnierkiewicz min_t(int, of_thermal_get_ntrips(tzd), data->ntrip); 293c8f8f768SBartlomiej Zolnierkiewicz 294c35268f5SBartlomiej Zolnierkiewicz data->tmu_initialize(pdev); 295c8f8f768SBartlomiej Zolnierkiewicz 296c8f8f768SBartlomiej Zolnierkiewicz /* Write temperature code for rising and falling threshold */ 297c8f8f768SBartlomiej Zolnierkiewicz for (i = 0; i < ntrips; i++) { 298c8f8f768SBartlomiej Zolnierkiewicz 299*ca38255eSDaniel Lezcano struct thermal_trip trip; 300*ca38255eSDaniel Lezcano 301*ca38255eSDaniel Lezcano ret = thermal_zone_get_trip(tzd, i, &trip); 30289335c20SBartlomiej Zolnierkiewicz if (ret) 30389335c20SBartlomiej Zolnierkiewicz goto err; 304*ca38255eSDaniel Lezcano 305*ca38255eSDaniel Lezcano data->tmu_set_trip_temp(data, i, trip.temperature / MCELSIUS); 306*ca38255eSDaniel Lezcano data->tmu_set_trip_hyst(data, i, trip.temperature / MCELSIUS, 307*ca38255eSDaniel Lezcano trip.hysteresis / MCELSIUS); 308c8f8f768SBartlomiej Zolnierkiewicz } 309c8f8f768SBartlomiej Zolnierkiewicz 310fac36bacSBartlomiej Zolnierkiewicz data->tmu_clear_irqs(data); 311fac36bacSBartlomiej Zolnierkiewicz } 31289335c20SBartlomiej Zolnierkiewicz err: 31359dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 31459dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 31514a11dc7SNaveen Krishna Chatradhi if (!IS_ERR(data->clk_sec)) 31614a11dc7SNaveen Krishna Chatradhi clk_disable(data->clk_sec); 3178f1c404bSBartlomiej Zolnierkiewicz out: 31859dfa54cSAmit Daniel Kachhap return ret; 31959dfa54cSAmit Daniel Kachhap } 32059dfa54cSAmit Daniel Kachhap 321d00671c3SBartlomiej Zolnierkiewicz static u32 get_con_reg(struct exynos_tmu_data *data, u32 con) 32259dfa54cSAmit Daniel Kachhap { 3237575983cSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS4412 || 3247575983cSBartlomiej Zolnierkiewicz data->soc == SOC_ARCH_EXYNOS3250) 3257575983cSBartlomiej Zolnierkiewicz con |= (EXYNOS4412_MUX_ADDR_VALUE << EXYNOS4412_MUX_ADDR_SHIFT); 32686f5362eSLukasz Majewski 32799d67fb9SBartlomiej Zolnierkiewicz con &= ~(EXYNOS_TMU_REF_VOLTAGE_MASK << EXYNOS_TMU_REF_VOLTAGE_SHIFT); 32861020d18SBartlomiej Zolnierkiewicz con |= data->reference_voltage << EXYNOS_TMU_REF_VOLTAGE_SHIFT; 329d0a0ce3eSAmit Daniel Kachhap 33099d67fb9SBartlomiej Zolnierkiewicz con &= ~(EXYNOS_TMU_BUF_SLOPE_SEL_MASK << EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT); 331fccfe099SBartlomiej Zolnierkiewicz con |= (data->gain << EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT); 332d0a0ce3eSAmit Daniel Kachhap 333b9504a6aSBartlomiej Zolnierkiewicz con &= ~(EXYNOS_TMU_TRIP_MODE_MASK << EXYNOS_TMU_TRIP_MODE_SHIFT); 33409d29426SBartlomiej Zolnierkiewicz con |= (EXYNOS_NOISE_CANCEL_MODE << EXYNOS_TMU_TRIP_MODE_SHIFT); 33559dfa54cSAmit Daniel Kachhap 336d00671c3SBartlomiej Zolnierkiewicz return con; 337d00671c3SBartlomiej Zolnierkiewicz } 338d00671c3SBartlomiej Zolnierkiewicz 339d00671c3SBartlomiej Zolnierkiewicz static void exynos_tmu_control(struct platform_device *pdev, bool on) 340d00671c3SBartlomiej Zolnierkiewicz { 341d00671c3SBartlomiej Zolnierkiewicz struct exynos_tmu_data *data = platform_get_drvdata(pdev); 342d00671c3SBartlomiej Zolnierkiewicz 343d00671c3SBartlomiej Zolnierkiewicz mutex_lock(&data->lock); 344d00671c3SBartlomiej Zolnierkiewicz clk_enable(data->clk); 34537f9034fSBartlomiej Zolnierkiewicz data->tmu_control(pdev, on); 34688fc6f73SMarek Szyprowski data->enabled = on; 34759dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 34859dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 34959dfa54cSAmit Daniel Kachhap } 35059dfa54cSAmit Daniel Kachhap 351a503a10fSBartlomiej Zolnierkiewicz static void exynos4210_tmu_set_trip_temp(struct exynos_tmu_data *data, 352*ca38255eSDaniel Lezcano int trip_id, u8 temp) 35372d1100bSBartlomiej Zolnierkiewicz { 354*ca38255eSDaniel Lezcano struct thermal_trip trip; 355a503a10fSBartlomiej Zolnierkiewicz u8 ref, th_code; 35672d1100bSBartlomiej Zolnierkiewicz 357*ca38255eSDaniel Lezcano if (thermal_zone_get_trip(data->tzd, 0, &trip)) 358*ca38255eSDaniel Lezcano return; 359a503a10fSBartlomiej Zolnierkiewicz 360*ca38255eSDaniel Lezcano ref = trip.temperature / MCELSIUS; 361*ca38255eSDaniel Lezcano 362*ca38255eSDaniel Lezcano if (trip_id == 0) { 363a503a10fSBartlomiej Zolnierkiewicz th_code = temp_to_code(data, ref); 364a503a10fSBartlomiej Zolnierkiewicz writeb(th_code, data->base + EXYNOS4210_TMU_REG_THRESHOLD_TEMP); 36572d1100bSBartlomiej Zolnierkiewicz } 36672d1100bSBartlomiej Zolnierkiewicz 367a503a10fSBartlomiej Zolnierkiewicz temp -= ref; 368*ca38255eSDaniel Lezcano writeb(temp, data->base + EXYNOS4210_TMU_REG_TRIG_LEVEL0 + trip_id * 4); 369a503a10fSBartlomiej Zolnierkiewicz } 370a503a10fSBartlomiej Zolnierkiewicz 371c8f8f768SBartlomiej Zolnierkiewicz /* failing thresholds are not supported on Exynos4210 */ 372c8f8f768SBartlomiej Zolnierkiewicz static void exynos4210_tmu_set_trip_hyst(struct exynos_tmu_data *data, 373c8f8f768SBartlomiej Zolnierkiewicz int trip, u8 temp, u8 hyst) 374c8f8f768SBartlomiej Zolnierkiewicz { 375c8f8f768SBartlomiej Zolnierkiewicz } 376c8f8f768SBartlomiej Zolnierkiewicz 377c35268f5SBartlomiej Zolnierkiewicz static void exynos4210_tmu_initialize(struct platform_device *pdev) 37859dfa54cSAmit Daniel Kachhap { 37959dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 38072d1100bSBartlomiej Zolnierkiewicz 38172d1100bSBartlomiej Zolnierkiewicz sanitize_temp_error(data, readl(data->base + EXYNOS_TMU_REG_TRIMINFO)); 38272d1100bSBartlomiej Zolnierkiewicz } 38372d1100bSBartlomiej Zolnierkiewicz 384a503a10fSBartlomiej Zolnierkiewicz static void exynos4412_tmu_set_trip_temp(struct exynos_tmu_data *data, 385a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp) 386a503a10fSBartlomiej Zolnierkiewicz { 387a503a10fSBartlomiej Zolnierkiewicz u32 th, con; 388a503a10fSBartlomiej Zolnierkiewicz 389a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + EXYNOS_THD_TEMP_RISE); 390a503a10fSBartlomiej Zolnierkiewicz th &= ~(0xff << 8 * trip); 391a503a10fSBartlomiej Zolnierkiewicz th |= temp_to_code(data, temp) << 8 * trip; 392a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + EXYNOS_THD_TEMP_RISE); 393a503a10fSBartlomiej Zolnierkiewicz 394a503a10fSBartlomiej Zolnierkiewicz if (trip == 3) { 395a503a10fSBartlomiej Zolnierkiewicz con = readl(data->base + EXYNOS_TMU_REG_CONTROL); 396a503a10fSBartlomiej Zolnierkiewicz con |= (1 << EXYNOS_TMU_THERM_TRIP_EN_SHIFT); 397a503a10fSBartlomiej Zolnierkiewicz writel(con, data->base + EXYNOS_TMU_REG_CONTROL); 398a503a10fSBartlomiej Zolnierkiewicz } 399a503a10fSBartlomiej Zolnierkiewicz } 400a503a10fSBartlomiej Zolnierkiewicz 401a503a10fSBartlomiej Zolnierkiewicz static void exynos4412_tmu_set_trip_hyst(struct exynos_tmu_data *data, 402a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp, u8 hyst) 403a503a10fSBartlomiej Zolnierkiewicz { 404a503a10fSBartlomiej Zolnierkiewicz u32 th; 405a503a10fSBartlomiej Zolnierkiewicz 406a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + EXYNOS_THD_TEMP_FALL); 407a503a10fSBartlomiej Zolnierkiewicz th &= ~(0xff << 8 * trip); 408a503a10fSBartlomiej Zolnierkiewicz if (hyst) 409a503a10fSBartlomiej Zolnierkiewicz th |= temp_to_code(data, temp - hyst) << 8 * trip; 410a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + EXYNOS_THD_TEMP_FALL); 411a503a10fSBartlomiej Zolnierkiewicz } 412a503a10fSBartlomiej Zolnierkiewicz 413c35268f5SBartlomiej Zolnierkiewicz static void exynos4412_tmu_initialize(struct platform_device *pdev) 41472d1100bSBartlomiej Zolnierkiewicz { 41572d1100bSBartlomiej Zolnierkiewicz struct exynos_tmu_data *data = platform_get_drvdata(pdev); 416a503a10fSBartlomiej Zolnierkiewicz unsigned int trim_info, ctrl; 41772d1100bSBartlomiej Zolnierkiewicz 41872d1100bSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS3250 || 41972d1100bSBartlomiej Zolnierkiewicz data->soc == SOC_ARCH_EXYNOS4412 || 42072d1100bSBartlomiej Zolnierkiewicz data->soc == SOC_ARCH_EXYNOS5250) { 42172d1100bSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS3250) { 42272d1100bSBartlomiej Zolnierkiewicz ctrl = readl(data->base + EXYNOS_TMU_TRIMINFO_CON1); 42372d1100bSBartlomiej Zolnierkiewicz ctrl |= EXYNOS_TRIMINFO_RELOAD_ENABLE; 42472d1100bSBartlomiej Zolnierkiewicz writel(ctrl, data->base + EXYNOS_TMU_TRIMINFO_CON1); 42572d1100bSBartlomiej Zolnierkiewicz } 42672d1100bSBartlomiej Zolnierkiewicz ctrl = readl(data->base + EXYNOS_TMU_TRIMINFO_CON2); 42772d1100bSBartlomiej Zolnierkiewicz ctrl |= EXYNOS_TRIMINFO_RELOAD_ENABLE; 42872d1100bSBartlomiej Zolnierkiewicz writel(ctrl, data->base + EXYNOS_TMU_TRIMINFO_CON2); 42972d1100bSBartlomiej Zolnierkiewicz } 43072d1100bSBartlomiej Zolnierkiewicz 43172d1100bSBartlomiej Zolnierkiewicz /* On exynos5420 the triminfo register is in the shared space */ 43272d1100bSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO) 43372d1100bSBartlomiej Zolnierkiewicz trim_info = readl(data->base_second + EXYNOS_TMU_REG_TRIMINFO); 43472d1100bSBartlomiej Zolnierkiewicz else 43572d1100bSBartlomiej Zolnierkiewicz trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); 43672d1100bSBartlomiej Zolnierkiewicz 43772d1100bSBartlomiej Zolnierkiewicz sanitize_temp_error(data, trim_info); 4383b6a1a80SLukasz Majewski } 4393b6a1a80SLukasz Majewski 440a503a10fSBartlomiej Zolnierkiewicz static void exynos5433_tmu_set_trip_temp(struct exynos_tmu_data *data, 441a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp) 442a503a10fSBartlomiej Zolnierkiewicz { 443a503a10fSBartlomiej Zolnierkiewicz unsigned int reg_off, j; 444a503a10fSBartlomiej Zolnierkiewicz u32 th; 445a503a10fSBartlomiej Zolnierkiewicz 446a503a10fSBartlomiej Zolnierkiewicz if (trip > 3) { 447a503a10fSBartlomiej Zolnierkiewicz reg_off = EXYNOS5433_THD_TEMP_RISE7_4; 448a503a10fSBartlomiej Zolnierkiewicz j = trip - 4; 449a503a10fSBartlomiej Zolnierkiewicz } else { 450a503a10fSBartlomiej Zolnierkiewicz reg_off = EXYNOS5433_THD_TEMP_RISE3_0; 451a503a10fSBartlomiej Zolnierkiewicz j = trip; 4523b6a1a80SLukasz Majewski } 4533b6a1a80SLukasz Majewski 454a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + reg_off); 455a503a10fSBartlomiej Zolnierkiewicz th &= ~(0xff << j * 8); 456a503a10fSBartlomiej Zolnierkiewicz th |= (temp_to_code(data, temp) << j * 8); 457a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + reg_off); 45872d1100bSBartlomiej Zolnierkiewicz } 45972d1100bSBartlomiej Zolnierkiewicz 460a503a10fSBartlomiej Zolnierkiewicz static void exynos5433_tmu_set_trip_hyst(struct exynos_tmu_data *data, 461a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp, u8 hyst) 462a503a10fSBartlomiej Zolnierkiewicz { 463a503a10fSBartlomiej Zolnierkiewicz unsigned int reg_off, j; 464a503a10fSBartlomiej Zolnierkiewicz u32 th; 465a503a10fSBartlomiej Zolnierkiewicz 466a503a10fSBartlomiej Zolnierkiewicz if (trip > 3) { 467a503a10fSBartlomiej Zolnierkiewicz reg_off = EXYNOS5433_THD_TEMP_FALL7_4; 468a503a10fSBartlomiej Zolnierkiewicz j = trip - 4; 469a503a10fSBartlomiej Zolnierkiewicz } else { 470a503a10fSBartlomiej Zolnierkiewicz reg_off = EXYNOS5433_THD_TEMP_FALL3_0; 471a503a10fSBartlomiej Zolnierkiewicz j = trip; 472a503a10fSBartlomiej Zolnierkiewicz } 473a503a10fSBartlomiej Zolnierkiewicz 474a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + reg_off); 475a503a10fSBartlomiej Zolnierkiewicz th &= ~(0xff << j * 8); 476a503a10fSBartlomiej Zolnierkiewicz th |= (temp_to_code(data, temp - hyst) << j * 8); 477a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + reg_off); 47872d1100bSBartlomiej Zolnierkiewicz } 47972d1100bSBartlomiej Zolnierkiewicz 480c35268f5SBartlomiej Zolnierkiewicz static void exynos5433_tmu_initialize(struct platform_device *pdev) 481488c7455SChanwoo Choi { 482488c7455SChanwoo Choi struct exynos_tmu_data *data = platform_get_drvdata(pdev); 48397b3881bSBartlomiej Zolnierkiewicz unsigned int trim_info; 484c8f8f768SBartlomiej Zolnierkiewicz int sensor_id, cal_type; 485488c7455SChanwoo Choi 486488c7455SChanwoo Choi trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); 487488c7455SChanwoo Choi sanitize_temp_error(data, trim_info); 488488c7455SChanwoo Choi 489488c7455SChanwoo Choi /* Read the temperature sensor id */ 490488c7455SChanwoo Choi sensor_id = (trim_info & EXYNOS5433_TRIMINFO_SENSOR_ID_MASK) 491488c7455SChanwoo Choi >> EXYNOS5433_TRIMINFO_SENSOR_ID_SHIFT; 492488c7455SChanwoo Choi dev_info(&pdev->dev, "Temperature sensor ID: 0x%x\n", sensor_id); 493488c7455SChanwoo Choi 494488c7455SChanwoo Choi /* Read the calibration mode */ 495488c7455SChanwoo Choi writel(trim_info, data->base + EXYNOS_TMU_REG_TRIMINFO); 496488c7455SChanwoo Choi cal_type = (trim_info & EXYNOS5433_TRIMINFO_CALIB_SEL_MASK) 497488c7455SChanwoo Choi >> EXYNOS5433_TRIMINFO_CALIB_SEL_SHIFT; 498488c7455SChanwoo Choi 499488c7455SChanwoo Choi switch (cal_type) { 500488c7455SChanwoo Choi case EXYNOS5433_TRIMINFO_TWO_POINT_TRIMMING: 501199b3e3cSBartlomiej Zolnierkiewicz data->cal_type = TYPE_TWO_POINT_TRIMMING; 502488c7455SChanwoo Choi break; 503199b3e3cSBartlomiej Zolnierkiewicz case EXYNOS5433_TRIMINFO_ONE_POINT_TRIMMING: 504488c7455SChanwoo Choi default: 505199b3e3cSBartlomiej Zolnierkiewicz data->cal_type = TYPE_ONE_POINT_TRIMMING; 506488c7455SChanwoo Choi break; 507baba1ebbSKrzysztof Kozlowski } 508488c7455SChanwoo Choi 509488c7455SChanwoo Choi dev_info(&pdev->dev, "Calibration type is %d-point calibration\n", 510488c7455SChanwoo Choi cal_type ? 2 : 1); 511488c7455SChanwoo Choi } 512488c7455SChanwoo Choi 513a503a10fSBartlomiej Zolnierkiewicz static void exynos7_tmu_set_trip_temp(struct exynos_tmu_data *data, 514a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp) 51572d1100bSBartlomiej Zolnierkiewicz { 5166c247393SAbhilash Kesavan unsigned int reg_off, bit_off; 517a503a10fSBartlomiej Zolnierkiewicz u32 th; 5186c247393SAbhilash Kesavan 519a503a10fSBartlomiej Zolnierkiewicz reg_off = ((7 - trip) / 2) * 4; 520a503a10fSBartlomiej Zolnierkiewicz bit_off = ((8 - trip) % 2); 521a503a10fSBartlomiej Zolnierkiewicz 522a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + EXYNOS7_THD_TEMP_RISE7_6 + reg_off); 523a503a10fSBartlomiej Zolnierkiewicz th &= ~(EXYNOS7_TMU_TEMP_MASK << (16 * bit_off)); 524a503a10fSBartlomiej Zolnierkiewicz th |= temp_to_code(data, temp) << (16 * bit_off); 525a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + EXYNOS7_THD_TEMP_RISE7_6 + reg_off); 5266c247393SAbhilash Kesavan } 5276c247393SAbhilash Kesavan 528a503a10fSBartlomiej Zolnierkiewicz static void exynos7_tmu_set_trip_hyst(struct exynos_tmu_data *data, 529a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp, u8 hyst) 530a503a10fSBartlomiej Zolnierkiewicz { 531a503a10fSBartlomiej Zolnierkiewicz unsigned int reg_off, bit_off; 532a503a10fSBartlomiej Zolnierkiewicz u32 th; 533a503a10fSBartlomiej Zolnierkiewicz 534a503a10fSBartlomiej Zolnierkiewicz reg_off = ((7 - trip) / 2) * 4; 535a503a10fSBartlomiej Zolnierkiewicz bit_off = ((8 - trip) % 2); 536a503a10fSBartlomiej Zolnierkiewicz 537a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + EXYNOS7_THD_TEMP_FALL7_6 + reg_off); 538a503a10fSBartlomiej Zolnierkiewicz th &= ~(EXYNOS7_TMU_TEMP_MASK << (16 * bit_off)); 539a503a10fSBartlomiej Zolnierkiewicz th |= temp_to_code(data, temp - hyst) << (16 * bit_off); 540a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + EXYNOS7_THD_TEMP_FALL7_6 + reg_off); 541a503a10fSBartlomiej Zolnierkiewicz } 542a503a10fSBartlomiej Zolnierkiewicz 543c35268f5SBartlomiej Zolnierkiewicz static void exynos7_tmu_initialize(struct platform_device *pdev) 5446c247393SAbhilash Kesavan { 5456c247393SAbhilash Kesavan struct exynos_tmu_data *data = platform_get_drvdata(pdev); 54697b3881bSBartlomiej Zolnierkiewicz unsigned int trim_info; 5476c247393SAbhilash Kesavan 5486c247393SAbhilash Kesavan trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); 549aef27b65SBartlomiej Zolnierkiewicz sanitize_temp_error(data, trim_info); 5506c247393SAbhilash Kesavan } 5516c247393SAbhilash Kesavan 55237f9034fSBartlomiej Zolnierkiewicz static void exynos4210_tmu_control(struct platform_device *pdev, bool on) 55337f9034fSBartlomiej Zolnierkiewicz { 55437f9034fSBartlomiej Zolnierkiewicz struct exynos_tmu_data *data = platform_get_drvdata(pdev); 5553b6a1a80SLukasz Majewski struct thermal_zone_device *tz = data->tzd; 55664e94192SBartlomiej Zolnierkiewicz unsigned int con, interrupt_en = 0, i; 55737f9034fSBartlomiej Zolnierkiewicz 55837f9034fSBartlomiej Zolnierkiewicz con = get_con_reg(data, readl(data->base + EXYNOS_TMU_REG_CONTROL)); 55937f9034fSBartlomiej Zolnierkiewicz 56059dfa54cSAmit Daniel Kachhap if (on) { 56164e94192SBartlomiej Zolnierkiewicz for (i = 0; i < data->ntrip; i++) { 56264e94192SBartlomiej Zolnierkiewicz if (!of_thermal_is_trip_valid(tz, i)) 56364e94192SBartlomiej Zolnierkiewicz continue; 56464e94192SBartlomiej Zolnierkiewicz 56564e94192SBartlomiej Zolnierkiewicz interrupt_en |= 56664e94192SBartlomiej Zolnierkiewicz (1 << (EXYNOS_TMU_INTEN_RISE0_SHIFT + i * 4)); 56764e94192SBartlomiej Zolnierkiewicz } 5683b6a1a80SLukasz Majewski 569e0761533SBartlomiej Zolnierkiewicz if (data->soc != SOC_ARCH_EXYNOS4210) 57059dfa54cSAmit Daniel Kachhap interrupt_en |= 57137f9034fSBartlomiej Zolnierkiewicz interrupt_en << EXYNOS_TMU_INTEN_FALL0_SHIFT; 57264e94192SBartlomiej Zolnierkiewicz 57364e94192SBartlomiej Zolnierkiewicz con |= (1 << EXYNOS_TMU_CORE_EN_SHIFT); 57459dfa54cSAmit Daniel Kachhap } else { 57559dfa54cSAmit Daniel Kachhap con &= ~(1 << EXYNOS_TMU_CORE_EN_SHIFT); 57659dfa54cSAmit Daniel Kachhap } 57764e94192SBartlomiej Zolnierkiewicz 57837f9034fSBartlomiej Zolnierkiewicz writel(interrupt_en, data->base + EXYNOS_TMU_REG_INTEN); 57937f9034fSBartlomiej Zolnierkiewicz writel(con, data->base + EXYNOS_TMU_REG_CONTROL); 58037f9034fSBartlomiej Zolnierkiewicz } 58159dfa54cSAmit Daniel Kachhap 582488c7455SChanwoo Choi static void exynos5433_tmu_control(struct platform_device *pdev, bool on) 583488c7455SChanwoo Choi { 584488c7455SChanwoo Choi struct exynos_tmu_data *data = platform_get_drvdata(pdev); 585488c7455SChanwoo Choi struct thermal_zone_device *tz = data->tzd; 58664e94192SBartlomiej Zolnierkiewicz unsigned int con, interrupt_en = 0, pd_det_en, i; 587488c7455SChanwoo Choi 588488c7455SChanwoo Choi con = get_con_reg(data, readl(data->base + EXYNOS_TMU_REG_CONTROL)); 589488c7455SChanwoo Choi 590488c7455SChanwoo Choi if (on) { 59164e94192SBartlomiej Zolnierkiewicz for (i = 0; i < data->ntrip; i++) { 59264e94192SBartlomiej Zolnierkiewicz if (!of_thermal_is_trip_valid(tz, i)) 59364e94192SBartlomiej Zolnierkiewicz continue; 59464e94192SBartlomiej Zolnierkiewicz 59564e94192SBartlomiej Zolnierkiewicz interrupt_en |= 59664e94192SBartlomiej Zolnierkiewicz (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i)); 59764e94192SBartlomiej Zolnierkiewicz } 598488c7455SChanwoo Choi 599488c7455SChanwoo Choi interrupt_en |= 600488c7455SChanwoo Choi interrupt_en << EXYNOS_TMU_INTEN_FALL0_SHIFT; 60164e94192SBartlomiej Zolnierkiewicz 60264e94192SBartlomiej Zolnierkiewicz con |= (1 << EXYNOS_TMU_CORE_EN_SHIFT); 60364e94192SBartlomiej Zolnierkiewicz } else 604488c7455SChanwoo Choi con &= ~(1 << EXYNOS_TMU_CORE_EN_SHIFT); 605488c7455SChanwoo Choi 606488c7455SChanwoo Choi pd_det_en = on ? EXYNOS5433_PD_DET_EN : 0; 607488c7455SChanwoo Choi 608488c7455SChanwoo Choi writel(pd_det_en, data->base + EXYNOS5433_TMU_PD_DET_EN); 609488c7455SChanwoo Choi writel(interrupt_en, data->base + EXYNOS5433_TMU_REG_INTEN); 610488c7455SChanwoo Choi writel(con, data->base + EXYNOS_TMU_REG_CONTROL); 611488c7455SChanwoo Choi } 612488c7455SChanwoo Choi 6136c247393SAbhilash Kesavan static void exynos7_tmu_control(struct platform_device *pdev, bool on) 6146c247393SAbhilash Kesavan { 6156c247393SAbhilash Kesavan struct exynos_tmu_data *data = platform_get_drvdata(pdev); 6166c247393SAbhilash Kesavan struct thermal_zone_device *tz = data->tzd; 61764e94192SBartlomiej Zolnierkiewicz unsigned int con, interrupt_en = 0, i; 6186c247393SAbhilash Kesavan 6196c247393SAbhilash Kesavan con = get_con_reg(data, readl(data->base + EXYNOS_TMU_REG_CONTROL)); 6206c247393SAbhilash Kesavan 6216c247393SAbhilash Kesavan if (on) { 62264e94192SBartlomiej Zolnierkiewicz for (i = 0; i < data->ntrip; i++) { 62364e94192SBartlomiej Zolnierkiewicz if (!of_thermal_is_trip_valid(tz, i)) 62464e94192SBartlomiej Zolnierkiewicz continue; 62564e94192SBartlomiej Zolnierkiewicz 62664e94192SBartlomiej Zolnierkiewicz interrupt_en |= 62764e94192SBartlomiej Zolnierkiewicz (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i)); 62864e94192SBartlomiej Zolnierkiewicz } 6296c247393SAbhilash Kesavan 6306c247393SAbhilash Kesavan interrupt_en |= 6316c247393SAbhilash Kesavan interrupt_en << EXYNOS_TMU_INTEN_FALL0_SHIFT; 63264e94192SBartlomiej Zolnierkiewicz 63364e94192SBartlomiej Zolnierkiewicz con |= (1 << EXYNOS_TMU_CORE_EN_SHIFT); 63464e94192SBartlomiej Zolnierkiewicz con |= (1 << EXYNOS7_PD_DET_EN_SHIFT); 6356c247393SAbhilash Kesavan } else { 6366c247393SAbhilash Kesavan con &= ~(1 << EXYNOS_TMU_CORE_EN_SHIFT); 63742b696e8SChanwoo Choi con &= ~(1 << EXYNOS7_PD_DET_EN_SHIFT); 6386c247393SAbhilash Kesavan } 6396c247393SAbhilash Kesavan 6406c247393SAbhilash Kesavan writel(interrupt_en, data->base + EXYNOS7_TMU_REG_INTEN); 6416c247393SAbhilash Kesavan writel(con, data->base + EXYNOS_TMU_REG_CONTROL); 6426c247393SAbhilash Kesavan } 6436c247393SAbhilash Kesavan 6447ea98f70SDaniel Lezcano static int exynos_get_temp(struct thermal_zone_device *tz, int *temp) 64559dfa54cSAmit Daniel Kachhap { 6467ea98f70SDaniel Lezcano struct exynos_tmu_data *data = tz->devdata; 647c8da6cdeSMarek Szyprowski int value, ret = 0; 6483b6a1a80SLukasz Majewski 6493b5236ccSMarek Szyprowski if (!data || !data->tmu_read) 6503b6a1a80SLukasz Majewski return -EINVAL; 651ffe6e16fSKrzysztof Kozlowski else if (!data->enabled) 652ffe6e16fSKrzysztof Kozlowski /* 653ffe6e16fSKrzysztof Kozlowski * Called too early, probably 654ffe6e16fSKrzysztof Kozlowski * from thermal_zone_of_sensor_register(). 655ffe6e16fSKrzysztof Kozlowski */ 656ffe6e16fSKrzysztof Kozlowski return -EAGAIN; 65759dfa54cSAmit Daniel Kachhap 65859dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 65959dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 6603b6a1a80SLukasz Majewski 661c8da6cdeSMarek Szyprowski value = data->tmu_read(data); 662c8da6cdeSMarek Szyprowski if (value < 0) 663c8da6cdeSMarek Szyprowski ret = value; 664c8da6cdeSMarek Szyprowski else 665c8da6cdeSMarek Szyprowski *temp = code_to_temp(data, value) * MCELSIUS; 6663b6a1a80SLukasz Majewski 66759dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 66859dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 66959dfa54cSAmit Daniel Kachhap 670c8da6cdeSMarek Szyprowski return ret; 67159dfa54cSAmit Daniel Kachhap } 67259dfa54cSAmit Daniel Kachhap 67359dfa54cSAmit Daniel Kachhap #ifdef CONFIG_THERMAL_EMULATION 674154013eaSBartlomiej Zolnierkiewicz static u32 get_emul_con_reg(struct exynos_tmu_data *data, unsigned int val, 67517e8351aSSascha Hauer int temp) 676154013eaSBartlomiej Zolnierkiewicz { 677154013eaSBartlomiej Zolnierkiewicz if (temp) { 678154013eaSBartlomiej Zolnierkiewicz temp /= MCELSIUS; 679154013eaSBartlomiej Zolnierkiewicz 680154013eaSBartlomiej Zolnierkiewicz val &= ~(EXYNOS_EMUL_TIME_MASK << EXYNOS_EMUL_TIME_SHIFT); 681154013eaSBartlomiej Zolnierkiewicz val |= (EXYNOS_EMUL_TIME << EXYNOS_EMUL_TIME_SHIFT); 6826c247393SAbhilash Kesavan if (data->soc == SOC_ARCH_EXYNOS7) { 6836c247393SAbhilash Kesavan val &= ~(EXYNOS7_EMUL_DATA_MASK << 6846c247393SAbhilash Kesavan EXYNOS7_EMUL_DATA_SHIFT); 6856c247393SAbhilash Kesavan val |= (temp_to_code(data, temp) << 6866c247393SAbhilash Kesavan EXYNOS7_EMUL_DATA_SHIFT) | 687154013eaSBartlomiej Zolnierkiewicz EXYNOS_EMUL_ENABLE; 688154013eaSBartlomiej Zolnierkiewicz } else { 6896c247393SAbhilash Kesavan val &= ~(EXYNOS_EMUL_DATA_MASK << 6906c247393SAbhilash Kesavan EXYNOS_EMUL_DATA_SHIFT); 6916c247393SAbhilash Kesavan val |= (temp_to_code(data, temp) << 6926c247393SAbhilash Kesavan EXYNOS_EMUL_DATA_SHIFT) | 6936c247393SAbhilash Kesavan EXYNOS_EMUL_ENABLE; 6946c247393SAbhilash Kesavan } 6956c247393SAbhilash Kesavan } else { 696154013eaSBartlomiej Zolnierkiewicz val &= ~EXYNOS_EMUL_ENABLE; 697154013eaSBartlomiej Zolnierkiewicz } 698154013eaSBartlomiej Zolnierkiewicz 699154013eaSBartlomiej Zolnierkiewicz return val; 700154013eaSBartlomiej Zolnierkiewicz } 701154013eaSBartlomiej Zolnierkiewicz 702285d994aSBartlomiej Zolnierkiewicz static void exynos4412_tmu_set_emulation(struct exynos_tmu_data *data, 70317e8351aSSascha Hauer int temp) 704285d994aSBartlomiej Zolnierkiewicz { 705285d994aSBartlomiej Zolnierkiewicz unsigned int val; 706285d994aSBartlomiej Zolnierkiewicz u32 emul_con; 707285d994aSBartlomiej Zolnierkiewicz 708285d994aSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS5260) 709285d994aSBartlomiej Zolnierkiewicz emul_con = EXYNOS5260_EMUL_CON; 710b28fec13SSudip Mukherjee else if (data->soc == SOC_ARCH_EXYNOS5433) 711488c7455SChanwoo Choi emul_con = EXYNOS5433_TMU_EMUL_CON; 7126c247393SAbhilash Kesavan else if (data->soc == SOC_ARCH_EXYNOS7) 7136c247393SAbhilash Kesavan emul_con = EXYNOS7_TMU_REG_EMUL_CON; 714285d994aSBartlomiej Zolnierkiewicz else 715285d994aSBartlomiej Zolnierkiewicz emul_con = EXYNOS_EMUL_CON; 716285d994aSBartlomiej Zolnierkiewicz 717285d994aSBartlomiej Zolnierkiewicz val = readl(data->base + emul_con); 718285d994aSBartlomiej Zolnierkiewicz val = get_emul_con_reg(data, val, temp); 719285d994aSBartlomiej Zolnierkiewicz writel(val, data->base + emul_con); 720285d994aSBartlomiej Zolnierkiewicz } 721285d994aSBartlomiej Zolnierkiewicz 7227ea98f70SDaniel Lezcano static int exynos_tmu_set_emulation(struct thermal_zone_device *tz, int temp) 72359dfa54cSAmit Daniel Kachhap { 7247ea98f70SDaniel Lezcano struct exynos_tmu_data *data = tz->devdata; 72559dfa54cSAmit Daniel Kachhap int ret = -EINVAL; 72659dfa54cSAmit Daniel Kachhap 727ef3f80fcSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS4210) 72859dfa54cSAmit Daniel Kachhap goto out; 72959dfa54cSAmit Daniel Kachhap 73059dfa54cSAmit Daniel Kachhap if (temp && temp < MCELSIUS) 73159dfa54cSAmit Daniel Kachhap goto out; 73259dfa54cSAmit Daniel Kachhap 73359dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 73459dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 735285d994aSBartlomiej Zolnierkiewicz data->tmu_set_emulation(data, temp); 73659dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 73759dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 73859dfa54cSAmit Daniel Kachhap return 0; 73959dfa54cSAmit Daniel Kachhap out: 74059dfa54cSAmit Daniel Kachhap return ret; 74159dfa54cSAmit Daniel Kachhap } 74259dfa54cSAmit Daniel Kachhap #else 743285d994aSBartlomiej Zolnierkiewicz #define exynos4412_tmu_set_emulation NULL 7447ea98f70SDaniel Lezcano static int exynos_tmu_set_emulation(struct thermal_zone_device *tz, int temp) 74559dfa54cSAmit Daniel Kachhap { return -EINVAL; } 74659dfa54cSAmit Daniel Kachhap #endif /* CONFIG_THERMAL_EMULATION */ 74759dfa54cSAmit Daniel Kachhap 748b79985caSBartlomiej Zolnierkiewicz static int exynos4210_tmu_read(struct exynos_tmu_data *data) 749b79985caSBartlomiej Zolnierkiewicz { 750b79985caSBartlomiej Zolnierkiewicz int ret = readb(data->base + EXYNOS_TMU_REG_CURRENT_TEMP); 751b79985caSBartlomiej Zolnierkiewicz 752b79985caSBartlomiej Zolnierkiewicz /* "temp_code" should range between 75 and 175 */ 753b79985caSBartlomiej Zolnierkiewicz return (ret < 75 || ret > 175) ? -ENODATA : ret; 754b79985caSBartlomiej Zolnierkiewicz } 755b79985caSBartlomiej Zolnierkiewicz 756b79985caSBartlomiej Zolnierkiewicz static int exynos4412_tmu_read(struct exynos_tmu_data *data) 757b79985caSBartlomiej Zolnierkiewicz { 758b79985caSBartlomiej Zolnierkiewicz return readb(data->base + EXYNOS_TMU_REG_CURRENT_TEMP); 759b79985caSBartlomiej Zolnierkiewicz } 760b79985caSBartlomiej Zolnierkiewicz 7616c247393SAbhilash Kesavan static int exynos7_tmu_read(struct exynos_tmu_data *data) 7626c247393SAbhilash Kesavan { 7636c247393SAbhilash Kesavan return readw(data->base + EXYNOS_TMU_REG_CURRENT_TEMP) & 7646c247393SAbhilash Kesavan EXYNOS7_TMU_TEMP_MASK; 7656c247393SAbhilash Kesavan } 7666c247393SAbhilash Kesavan 76759dfa54cSAmit Daniel Kachhap static void exynos_tmu_work(struct work_struct *work) 76859dfa54cSAmit Daniel Kachhap { 76959dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = container_of(work, 77059dfa54cSAmit Daniel Kachhap struct exynos_tmu_data, irq_work); 771a0395eeeSAmit Daniel Kachhap 772b43e3cfeSBartlomiej Zolnierkiewicz thermal_zone_device_update(data->tzd, THERMAL_EVENT_UNSPECIFIED); 773b43e3cfeSBartlomiej Zolnierkiewicz 77459dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 77559dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 776b8d582b9SAmit Daniel Kachhap 777a4463c4fSAmit Daniel Kachhap /* TODO: take action based on particular interrupt */ 778a7331f72SBartlomiej Zolnierkiewicz data->tmu_clear_irqs(data); 779b8d582b9SAmit Daniel Kachhap 78059dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 78159dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 78259dfa54cSAmit Daniel Kachhap enable_irq(data->irq); 78359dfa54cSAmit Daniel Kachhap } 78459dfa54cSAmit Daniel Kachhap 785a7331f72SBartlomiej Zolnierkiewicz static void exynos4210_tmu_clear_irqs(struct exynos_tmu_data *data) 786a7331f72SBartlomiej Zolnierkiewicz { 787a7331f72SBartlomiej Zolnierkiewicz unsigned int val_irq; 788a7331f72SBartlomiej Zolnierkiewicz u32 tmu_intstat, tmu_intclear; 789a7331f72SBartlomiej Zolnierkiewicz 790a7331f72SBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS5260) { 791a7331f72SBartlomiej Zolnierkiewicz tmu_intstat = EXYNOS5260_TMU_REG_INTSTAT; 792a7331f72SBartlomiej Zolnierkiewicz tmu_intclear = EXYNOS5260_TMU_REG_INTCLEAR; 7936c247393SAbhilash Kesavan } else if (data->soc == SOC_ARCH_EXYNOS7) { 7946c247393SAbhilash Kesavan tmu_intstat = EXYNOS7_TMU_REG_INTPEND; 7956c247393SAbhilash Kesavan tmu_intclear = EXYNOS7_TMU_REG_INTPEND; 796488c7455SChanwoo Choi } else if (data->soc == SOC_ARCH_EXYNOS5433) { 797488c7455SChanwoo Choi tmu_intstat = EXYNOS5433_TMU_REG_INTPEND; 798488c7455SChanwoo Choi tmu_intclear = EXYNOS5433_TMU_REG_INTPEND; 799a7331f72SBartlomiej Zolnierkiewicz } else { 800a7331f72SBartlomiej Zolnierkiewicz tmu_intstat = EXYNOS_TMU_REG_INTSTAT; 801a7331f72SBartlomiej Zolnierkiewicz tmu_intclear = EXYNOS_TMU_REG_INTCLEAR; 802a7331f72SBartlomiej Zolnierkiewicz } 803a7331f72SBartlomiej Zolnierkiewicz 804a7331f72SBartlomiej Zolnierkiewicz val_irq = readl(data->base + tmu_intstat); 805a7331f72SBartlomiej Zolnierkiewicz /* 806a7331f72SBartlomiej Zolnierkiewicz * Clear the interrupts. Please note that the documentation for 807a7331f72SBartlomiej Zolnierkiewicz * Exynos3250, Exynos4412, Exynos5250 and Exynos5260 incorrectly 808a7331f72SBartlomiej Zolnierkiewicz * states that INTCLEAR register has a different placing of bits 809a7331f72SBartlomiej Zolnierkiewicz * responsible for FALL IRQs than INTSTAT register. Exynos5420 810a7331f72SBartlomiej Zolnierkiewicz * and Exynos5440 documentation is correct (Exynos4210 doesn't 811a7331f72SBartlomiej Zolnierkiewicz * support FALL IRQs at all). 812a7331f72SBartlomiej Zolnierkiewicz */ 813a7331f72SBartlomiej Zolnierkiewicz writel(val_irq, data->base + tmu_intclear); 814a7331f72SBartlomiej Zolnierkiewicz } 815a7331f72SBartlomiej Zolnierkiewicz 81659dfa54cSAmit Daniel Kachhap static irqreturn_t exynos_tmu_irq(int irq, void *id) 81759dfa54cSAmit Daniel Kachhap { 81859dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = id; 81959dfa54cSAmit Daniel Kachhap 82059dfa54cSAmit Daniel Kachhap disable_irq_nosync(irq); 82159dfa54cSAmit Daniel Kachhap schedule_work(&data->irq_work); 82259dfa54cSAmit Daniel Kachhap 82359dfa54cSAmit Daniel Kachhap return IRQ_HANDLED; 82459dfa54cSAmit Daniel Kachhap } 82559dfa54cSAmit Daniel Kachhap 82659dfa54cSAmit Daniel Kachhap static const struct of_device_id exynos_tmu_match[] = { 827fee88e2bSMaciej Purski { 828fee88e2bSMaciej Purski .compatible = "samsung,exynos3250-tmu", 829fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS3250, 830fee88e2bSMaciej Purski }, { 831fee88e2bSMaciej Purski .compatible = "samsung,exynos4210-tmu", 832fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS4210, 833fee88e2bSMaciej Purski }, { 834fee88e2bSMaciej Purski .compatible = "samsung,exynos4412-tmu", 835fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS4412, 836fee88e2bSMaciej Purski }, { 837fee88e2bSMaciej Purski .compatible = "samsung,exynos5250-tmu", 838fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5250, 839fee88e2bSMaciej Purski }, { 840fee88e2bSMaciej Purski .compatible = "samsung,exynos5260-tmu", 841fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5260, 842fee88e2bSMaciej Purski }, { 843fee88e2bSMaciej Purski .compatible = "samsung,exynos5420-tmu", 844fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5420, 845fee88e2bSMaciej Purski }, { 846fee88e2bSMaciej Purski .compatible = "samsung,exynos5420-tmu-ext-triminfo", 847fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5420_TRIMINFO, 848fee88e2bSMaciej Purski }, { 849fee88e2bSMaciej Purski .compatible = "samsung,exynos5433-tmu", 850fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5433, 851fee88e2bSMaciej Purski }, { 852fee88e2bSMaciej Purski .compatible = "samsung,exynos7-tmu", 853fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS7, 854fee88e2bSMaciej Purski }, 855fee88e2bSMaciej Purski { }, 85659dfa54cSAmit Daniel Kachhap }; 85759dfa54cSAmit Daniel Kachhap MODULE_DEVICE_TABLE(of, exynos_tmu_match); 85859dfa54cSAmit Daniel Kachhap 859cebe7373SAmit Daniel Kachhap static int exynos_map_dt_data(struct platform_device *pdev) 86059dfa54cSAmit Daniel Kachhap { 861cebe7373SAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 862cebe7373SAmit Daniel Kachhap struct resource res; 86359dfa54cSAmit Daniel Kachhap 86473b5b1d7SSachin Kamat if (!data || !pdev->dev.of_node) 865cebe7373SAmit Daniel Kachhap return -ENODEV; 86659dfa54cSAmit Daniel Kachhap 867cebe7373SAmit Daniel Kachhap data->id = of_alias_get_id(pdev->dev.of_node, "tmuctrl"); 868cebe7373SAmit Daniel Kachhap if (data->id < 0) 869cebe7373SAmit Daniel Kachhap data->id = 0; 870cebe7373SAmit Daniel Kachhap 871cebe7373SAmit Daniel Kachhap data->irq = irq_of_parse_and_map(pdev->dev.of_node, 0); 872cebe7373SAmit Daniel Kachhap if (data->irq <= 0) { 873cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "failed to get IRQ\n"); 874cebe7373SAmit Daniel Kachhap return -ENODEV; 875cebe7373SAmit Daniel Kachhap } 876cebe7373SAmit Daniel Kachhap 877cebe7373SAmit Daniel Kachhap if (of_address_to_resource(pdev->dev.of_node, 0, &res)) { 878cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "failed to get Resource 0\n"); 879cebe7373SAmit Daniel Kachhap return -ENODEV; 880cebe7373SAmit Daniel Kachhap } 881cebe7373SAmit Daniel Kachhap 882cebe7373SAmit Daniel Kachhap data->base = devm_ioremap(&pdev->dev, res.start, resource_size(&res)); 883cebe7373SAmit Daniel Kachhap if (!data->base) { 884cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to ioremap memory\n"); 885cebe7373SAmit Daniel Kachhap return -EADDRNOTAVAIL; 886cebe7373SAmit Daniel Kachhap } 887cebe7373SAmit Daniel Kachhap 888fee88e2bSMaciej Purski data->soc = (enum soc_type)of_device_get_match_data(&pdev->dev); 88956adb9efSBartlomiej Zolnierkiewicz 89056adb9efSBartlomiej Zolnierkiewicz switch (data->soc) { 89156adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS4210: 892c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_temp = exynos4210_tmu_set_trip_temp; 893c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_hyst = exynos4210_tmu_set_trip_hyst; 89456adb9efSBartlomiej Zolnierkiewicz data->tmu_initialize = exynos4210_tmu_initialize; 89556adb9efSBartlomiej Zolnierkiewicz data->tmu_control = exynos4210_tmu_control; 89656adb9efSBartlomiej Zolnierkiewicz data->tmu_read = exynos4210_tmu_read; 89756adb9efSBartlomiej Zolnierkiewicz data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; 8983a3a5f15SKrzysztof Kozlowski data->ntrip = 4; 899fccfe099SBartlomiej Zolnierkiewicz data->gain = 15; 90061020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 7; 901e3ed3649SBartlomiej Zolnierkiewicz data->efuse_value = 55; 902e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 40; 903e3ed3649SBartlomiej Zolnierkiewicz data->max_efuse_value = 100; 90456adb9efSBartlomiej Zolnierkiewicz break; 90556adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS3250: 90656adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS4412: 90756adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS5250: 90856adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS5260: 90956adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS5420: 91056adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS5420_TRIMINFO: 911c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_temp = exynos4412_tmu_set_trip_temp; 912c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_hyst = exynos4412_tmu_set_trip_hyst; 91356adb9efSBartlomiej Zolnierkiewicz data->tmu_initialize = exynos4412_tmu_initialize; 91456adb9efSBartlomiej Zolnierkiewicz data->tmu_control = exynos4210_tmu_control; 91556adb9efSBartlomiej Zolnierkiewicz data->tmu_read = exynos4412_tmu_read; 91656adb9efSBartlomiej Zolnierkiewicz data->tmu_set_emulation = exynos4412_tmu_set_emulation; 91756adb9efSBartlomiej Zolnierkiewicz data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; 9183a3a5f15SKrzysztof Kozlowski data->ntrip = 4; 919fccfe099SBartlomiej Zolnierkiewicz data->gain = 8; 92061020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 16; 921e3ed3649SBartlomiej Zolnierkiewicz data->efuse_value = 55; 922e3ed3649SBartlomiej Zolnierkiewicz if (data->soc != SOC_ARCH_EXYNOS5420 && 923e3ed3649SBartlomiej Zolnierkiewicz data->soc != SOC_ARCH_EXYNOS5420_TRIMINFO) 924e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 40; 925e3ed3649SBartlomiej Zolnierkiewicz else 926e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 0; 927e3ed3649SBartlomiej Zolnierkiewicz data->max_efuse_value = 100; 92856adb9efSBartlomiej Zolnierkiewicz break; 929488c7455SChanwoo Choi case SOC_ARCH_EXYNOS5433: 930c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_temp = exynos5433_tmu_set_trip_temp; 931c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_hyst = exynos5433_tmu_set_trip_hyst; 932488c7455SChanwoo Choi data->tmu_initialize = exynos5433_tmu_initialize; 933488c7455SChanwoo Choi data->tmu_control = exynos5433_tmu_control; 934488c7455SChanwoo Choi data->tmu_read = exynos4412_tmu_read; 935488c7455SChanwoo Choi data->tmu_set_emulation = exynos4412_tmu_set_emulation; 936488c7455SChanwoo Choi data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; 9373a3a5f15SKrzysztof Kozlowski data->ntrip = 8; 938fccfe099SBartlomiej Zolnierkiewicz data->gain = 8; 93961020d18SBartlomiej Zolnierkiewicz if (res.start == EXYNOS5433_G3D_BASE) 94061020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 23; 94161020d18SBartlomiej Zolnierkiewicz else 94261020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 16; 943e3ed3649SBartlomiej Zolnierkiewicz data->efuse_value = 75; 944e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 40; 945e3ed3649SBartlomiej Zolnierkiewicz data->max_efuse_value = 150; 94656adb9efSBartlomiej Zolnierkiewicz break; 9476c247393SAbhilash Kesavan case SOC_ARCH_EXYNOS7: 948c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_temp = exynos7_tmu_set_trip_temp; 949c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_hyst = exynos7_tmu_set_trip_hyst; 9506c247393SAbhilash Kesavan data->tmu_initialize = exynos7_tmu_initialize; 9516c247393SAbhilash Kesavan data->tmu_control = exynos7_tmu_control; 9526c247393SAbhilash Kesavan data->tmu_read = exynos7_tmu_read; 9536c247393SAbhilash Kesavan data->tmu_set_emulation = exynos4412_tmu_set_emulation; 9546c247393SAbhilash Kesavan data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; 9553a3a5f15SKrzysztof Kozlowski data->ntrip = 8; 956fccfe099SBartlomiej Zolnierkiewicz data->gain = 9; 95761020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 17; 958e3ed3649SBartlomiej Zolnierkiewicz data->efuse_value = 75; 959e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 15; 960e3ed3649SBartlomiej Zolnierkiewicz data->max_efuse_value = 100; 9616c247393SAbhilash Kesavan break; 96256adb9efSBartlomiej Zolnierkiewicz default: 96356adb9efSBartlomiej Zolnierkiewicz dev_err(&pdev->dev, "Platform not supported\n"); 96456adb9efSBartlomiej Zolnierkiewicz return -EINVAL; 96556adb9efSBartlomiej Zolnierkiewicz } 96656adb9efSBartlomiej Zolnierkiewicz 967199b3e3cSBartlomiej Zolnierkiewicz data->cal_type = TYPE_ONE_POINT_TRIMMING; 968199b3e3cSBartlomiej Zolnierkiewicz 969d9b6ee14SAmit Daniel Kachhap /* 970d9b6ee14SAmit Daniel Kachhap * Check if the TMU shares some registers and then try to map the 971d9b6ee14SAmit Daniel Kachhap * memory of common registers. 972d9b6ee14SAmit Daniel Kachhap */ 9738014220dSKrzysztof Kozlowski if (data->soc != SOC_ARCH_EXYNOS5420_TRIMINFO) 974d9b6ee14SAmit Daniel Kachhap return 0; 975d9b6ee14SAmit Daniel Kachhap 976d9b6ee14SAmit Daniel Kachhap if (of_address_to_resource(pdev->dev.of_node, 1, &res)) { 977d9b6ee14SAmit Daniel Kachhap dev_err(&pdev->dev, "failed to get Resource 1\n"); 978d9b6ee14SAmit Daniel Kachhap return -ENODEV; 979d9b6ee14SAmit Daniel Kachhap } 980d9b6ee14SAmit Daniel Kachhap 9819025d563SNaveen Krishna Chatradhi data->base_second = devm_ioremap(&pdev->dev, res.start, 982d9b6ee14SAmit Daniel Kachhap resource_size(&res)); 9839025d563SNaveen Krishna Chatradhi if (!data->base_second) { 984d9b6ee14SAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to ioremap memory\n"); 985d9b6ee14SAmit Daniel Kachhap return -ENOMEM; 986d9b6ee14SAmit Daniel Kachhap } 987cebe7373SAmit Daniel Kachhap 988cebe7373SAmit Daniel Kachhap return 0; 989cebe7373SAmit Daniel Kachhap } 990cebe7373SAmit Daniel Kachhap 9917ea98f70SDaniel Lezcano static const struct thermal_zone_device_ops exynos_sensor_ops = { 9923b6a1a80SLukasz Majewski .get_temp = exynos_get_temp, 9933b6a1a80SLukasz Majewski .set_emul_temp = exynos_tmu_set_emulation, 9943b6a1a80SLukasz Majewski }; 9953b6a1a80SLukasz Majewski 996cebe7373SAmit Daniel Kachhap static int exynos_tmu_probe(struct platform_device *pdev) 997cebe7373SAmit Daniel Kachhap { 9983b6a1a80SLukasz Majewski struct exynos_tmu_data *data; 9993b6a1a80SLukasz Majewski int ret; 1000cebe7373SAmit Daniel Kachhap 100159dfa54cSAmit Daniel Kachhap data = devm_kzalloc(&pdev->dev, sizeof(struct exynos_tmu_data), 100259dfa54cSAmit Daniel Kachhap GFP_KERNEL); 10032a9675b3SJingoo Han if (!data) 100459dfa54cSAmit Daniel Kachhap return -ENOMEM; 100559dfa54cSAmit Daniel Kachhap 1006cebe7373SAmit Daniel Kachhap platform_set_drvdata(pdev, data); 1007cebe7373SAmit Daniel Kachhap mutex_init(&data->lock); 1008cebe7373SAmit Daniel Kachhap 1009824ead03SKrzysztof Kozlowski /* 1010824ead03SKrzysztof Kozlowski * Try enabling the regulator if found 1011824ead03SKrzysztof Kozlowski * TODO: Add regulator as an SOC feature, so that regulator enable 1012824ead03SKrzysztof Kozlowski * is a compulsory call. 1013824ead03SKrzysztof Kozlowski */ 10144d3583cdSJavier Martinez Canillas data->regulator = devm_regulator_get_optional(&pdev->dev, "vtmu"); 1015824ead03SKrzysztof Kozlowski if (!IS_ERR(data->regulator)) { 1016824ead03SKrzysztof Kozlowski ret = regulator_enable(data->regulator); 1017824ead03SKrzysztof Kozlowski if (ret) { 1018824ead03SKrzysztof Kozlowski dev_err(&pdev->dev, "failed to enable vtmu\n"); 1019824ead03SKrzysztof Kozlowski return ret; 10203b6a1a80SLukasz Majewski } 1021824ead03SKrzysztof Kozlowski } else { 1022ccb361d2SJavier Martinez Canillas if (PTR_ERR(data->regulator) == -EPROBE_DEFER) 1023ccb361d2SJavier Martinez Canillas return -EPROBE_DEFER; 1024824ead03SKrzysztof Kozlowski dev_info(&pdev->dev, "Regulator node (vtmu) not found\n"); 1025824ead03SKrzysztof Kozlowski } 1026824ead03SKrzysztof Kozlowski 1027cebe7373SAmit Daniel Kachhap ret = exynos_map_dt_data(pdev); 1028cebe7373SAmit Daniel Kachhap if (ret) 10293b6a1a80SLukasz Majewski goto err_sensor; 1030cebe7373SAmit Daniel Kachhap 103159dfa54cSAmit Daniel Kachhap INIT_WORK(&data->irq_work, exynos_tmu_work); 103259dfa54cSAmit Daniel Kachhap 103359dfa54cSAmit Daniel Kachhap data->clk = devm_clk_get(&pdev->dev, "tmu_apbif"); 103459dfa54cSAmit Daniel Kachhap if (IS_ERR(data->clk)) { 103559dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to get clock\n"); 10363b6a1a80SLukasz Majewski ret = PTR_ERR(data->clk); 10373b6a1a80SLukasz Majewski goto err_sensor; 103859dfa54cSAmit Daniel Kachhap } 103959dfa54cSAmit Daniel Kachhap 104014a11dc7SNaveen Krishna Chatradhi data->clk_sec = devm_clk_get(&pdev->dev, "tmu_triminfo_apbif"); 104114a11dc7SNaveen Krishna Chatradhi if (IS_ERR(data->clk_sec)) { 104214a11dc7SNaveen Krishna Chatradhi if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO) { 104314a11dc7SNaveen Krishna Chatradhi dev_err(&pdev->dev, "Failed to get triminfo clock\n"); 10443b6a1a80SLukasz Majewski ret = PTR_ERR(data->clk_sec); 10453b6a1a80SLukasz Majewski goto err_sensor; 104614a11dc7SNaveen Krishna Chatradhi } 104714a11dc7SNaveen Krishna Chatradhi } else { 104814a11dc7SNaveen Krishna Chatradhi ret = clk_prepare(data->clk_sec); 104914a11dc7SNaveen Krishna Chatradhi if (ret) { 105014a11dc7SNaveen Krishna Chatradhi dev_err(&pdev->dev, "Failed to get clock\n"); 10513b6a1a80SLukasz Majewski goto err_sensor; 105214a11dc7SNaveen Krishna Chatradhi } 105314a11dc7SNaveen Krishna Chatradhi } 105414a11dc7SNaveen Krishna Chatradhi 105514a11dc7SNaveen Krishna Chatradhi ret = clk_prepare(data->clk); 105614a11dc7SNaveen Krishna Chatradhi if (ret) { 105714a11dc7SNaveen Krishna Chatradhi dev_err(&pdev->dev, "Failed to get clock\n"); 105814a11dc7SNaveen Krishna Chatradhi goto err_clk_sec; 105914a11dc7SNaveen Krishna Chatradhi } 106059dfa54cSAmit Daniel Kachhap 1061488c7455SChanwoo Choi switch (data->soc) { 1062488c7455SChanwoo Choi case SOC_ARCH_EXYNOS5433: 1063488c7455SChanwoo Choi case SOC_ARCH_EXYNOS7: 10646c247393SAbhilash Kesavan data->sclk = devm_clk_get(&pdev->dev, "tmu_sclk"); 10656c247393SAbhilash Kesavan if (IS_ERR(data->sclk)) { 10666c247393SAbhilash Kesavan dev_err(&pdev->dev, "Failed to get sclk\n"); 106702d438f6SDan Carpenter ret = PTR_ERR(data->sclk); 10686c247393SAbhilash Kesavan goto err_clk; 10696c247393SAbhilash Kesavan } else { 10706c247393SAbhilash Kesavan ret = clk_prepare_enable(data->sclk); 10716c247393SAbhilash Kesavan if (ret) { 10726c247393SAbhilash Kesavan dev_err(&pdev->dev, "Failed to enable sclk\n"); 10736c247393SAbhilash Kesavan goto err_clk; 10746c247393SAbhilash Kesavan } 10756c247393SAbhilash Kesavan } 1076488c7455SChanwoo Choi break; 1077488c7455SChanwoo Choi default: 1078488c7455SChanwoo Choi break; 1079baba1ebbSKrzysztof Kozlowski } 10806c247393SAbhilash Kesavan 10819e4249b4SKrzysztof Kozlowski /* 10829e4249b4SKrzysztof Kozlowski * data->tzd must be registered before calling exynos_tmu_initialize(), 10839e4249b4SKrzysztof Kozlowski * requesting irq and calling exynos_tmu_control(). 10849e4249b4SKrzysztof Kozlowski */ 10857ea98f70SDaniel Lezcano data->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, data, 10869e4249b4SKrzysztof Kozlowski &exynos_sensor_ops); 10879e4249b4SKrzysztof Kozlowski if (IS_ERR(data->tzd)) { 10889e4249b4SKrzysztof Kozlowski ret = PTR_ERR(data->tzd); 108982bdde8eSMarek Szyprowski if (ret != -EPROBE_DEFER) 109082bdde8eSMarek Szyprowski dev_err(&pdev->dev, "Failed to register sensor: %d\n", 109182bdde8eSMarek Szyprowski ret); 10929e4249b4SKrzysztof Kozlowski goto err_sclk; 10939e4249b4SKrzysztof Kozlowski } 109459dfa54cSAmit Daniel Kachhap 109559dfa54cSAmit Daniel Kachhap ret = exynos_tmu_initialize(pdev); 109659dfa54cSAmit Daniel Kachhap if (ret) { 109759dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to initialize TMU\n"); 10987ea98f70SDaniel Lezcano goto err_sclk; 109959dfa54cSAmit Daniel Kachhap } 110059dfa54cSAmit Daniel Kachhap 1101cebe7373SAmit Daniel Kachhap ret = devm_request_irq(&pdev->dev, data->irq, exynos_tmu_irq, 1102cebe7373SAmit Daniel Kachhap IRQF_TRIGGER_RISING | IRQF_SHARED, dev_name(&pdev->dev), data); 1103cebe7373SAmit Daniel Kachhap if (ret) { 1104cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq); 11057ea98f70SDaniel Lezcano goto err_sclk; 1106cebe7373SAmit Daniel Kachhap } 110759dfa54cSAmit Daniel Kachhap 11083b6a1a80SLukasz Majewski exynos_tmu_control(pdev, true); 110959dfa54cSAmit Daniel Kachhap return 0; 11109e4249b4SKrzysztof Kozlowski 11116c247393SAbhilash Kesavan err_sclk: 11126c247393SAbhilash Kesavan clk_disable_unprepare(data->sclk); 111359dfa54cSAmit Daniel Kachhap err_clk: 111459dfa54cSAmit Daniel Kachhap clk_unprepare(data->clk); 111514a11dc7SNaveen Krishna Chatradhi err_clk_sec: 111614a11dc7SNaveen Krishna Chatradhi if (!IS_ERR(data->clk_sec)) 111714a11dc7SNaveen Krishna Chatradhi clk_unprepare(data->clk_sec); 11183b6a1a80SLukasz Majewski err_sensor: 1119bfa26838SKrzysztof Kozlowski if (!IS_ERR(data->regulator)) 11205f09a5cbSKrzysztof Kozlowski regulator_disable(data->regulator); 11213b6a1a80SLukasz Majewski 112259dfa54cSAmit Daniel Kachhap return ret; 112359dfa54cSAmit Daniel Kachhap } 112459dfa54cSAmit Daniel Kachhap 112559dfa54cSAmit Daniel Kachhap static int exynos_tmu_remove(struct platform_device *pdev) 112659dfa54cSAmit Daniel Kachhap { 112759dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 112859dfa54cSAmit Daniel Kachhap 11294215688eSBartlomiej Zolnierkiewicz exynos_tmu_control(pdev, false); 11304215688eSBartlomiej Zolnierkiewicz 11316c247393SAbhilash Kesavan clk_disable_unprepare(data->sclk); 113259dfa54cSAmit Daniel Kachhap clk_unprepare(data->clk); 113314a11dc7SNaveen Krishna Chatradhi if (!IS_ERR(data->clk_sec)) 113414a11dc7SNaveen Krishna Chatradhi clk_unprepare(data->clk_sec); 113559dfa54cSAmit Daniel Kachhap 1136498d22f6SAmit Daniel Kachhap if (!IS_ERR(data->regulator)) 1137498d22f6SAmit Daniel Kachhap regulator_disable(data->regulator); 1138498d22f6SAmit Daniel Kachhap 113959dfa54cSAmit Daniel Kachhap return 0; 114059dfa54cSAmit Daniel Kachhap } 114159dfa54cSAmit Daniel Kachhap 114259dfa54cSAmit Daniel Kachhap #ifdef CONFIG_PM_SLEEP 114359dfa54cSAmit Daniel Kachhap static int exynos_tmu_suspend(struct device *dev) 114459dfa54cSAmit Daniel Kachhap { 114559dfa54cSAmit Daniel Kachhap exynos_tmu_control(to_platform_device(dev), false); 114659dfa54cSAmit Daniel Kachhap 114759dfa54cSAmit Daniel Kachhap return 0; 114859dfa54cSAmit Daniel Kachhap } 114959dfa54cSAmit Daniel Kachhap 115059dfa54cSAmit Daniel Kachhap static int exynos_tmu_resume(struct device *dev) 115159dfa54cSAmit Daniel Kachhap { 115259dfa54cSAmit Daniel Kachhap struct platform_device *pdev = to_platform_device(dev); 115359dfa54cSAmit Daniel Kachhap 115459dfa54cSAmit Daniel Kachhap exynos_tmu_initialize(pdev); 115559dfa54cSAmit Daniel Kachhap exynos_tmu_control(pdev, true); 115659dfa54cSAmit Daniel Kachhap 115759dfa54cSAmit Daniel Kachhap return 0; 115859dfa54cSAmit Daniel Kachhap } 115959dfa54cSAmit Daniel Kachhap 116059dfa54cSAmit Daniel Kachhap static SIMPLE_DEV_PM_OPS(exynos_tmu_pm, 116159dfa54cSAmit Daniel Kachhap exynos_tmu_suspend, exynos_tmu_resume); 116259dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_PM (&exynos_tmu_pm) 116359dfa54cSAmit Daniel Kachhap #else 116459dfa54cSAmit Daniel Kachhap #define EXYNOS_TMU_PM NULL 116559dfa54cSAmit Daniel Kachhap #endif 116659dfa54cSAmit Daniel Kachhap 116759dfa54cSAmit Daniel Kachhap static struct platform_driver exynos_tmu_driver = { 116859dfa54cSAmit Daniel Kachhap .driver = { 116959dfa54cSAmit Daniel Kachhap .name = "exynos-tmu", 117059dfa54cSAmit Daniel Kachhap .pm = EXYNOS_TMU_PM, 117173b5b1d7SSachin Kamat .of_match_table = exynos_tmu_match, 117259dfa54cSAmit Daniel Kachhap }, 117359dfa54cSAmit Daniel Kachhap .probe = exynos_tmu_probe, 117459dfa54cSAmit Daniel Kachhap .remove = exynos_tmu_remove, 117559dfa54cSAmit Daniel Kachhap }; 117659dfa54cSAmit Daniel Kachhap 117759dfa54cSAmit Daniel Kachhap module_platform_driver(exynos_tmu_driver); 117859dfa54cSAmit Daniel Kachhap 1179ca07ee4eSKrzysztof Kozlowski MODULE_DESCRIPTION("Exynos TMU Driver"); 118059dfa54cSAmit Daniel Kachhap MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); 118159dfa54cSAmit Daniel Kachhap MODULE_LICENSE("GPL"); 118259dfa54cSAmit Daniel Kachhap MODULE_ALIAS("platform:exynos-tmu"); 1183