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> 18f6a756e8SRob Herring #include <linux/of.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> 239272d2d4SDaniel Lezcano #include <linux/thermal.h> 2459dfa54cSAmit Daniel Kachhap 257efd18a2SBartlomiej Zolnierkiewicz #include <dt-bindings/thermal/thermal_exynos.h> 267efd18a2SBartlomiej Zolnierkiewicz 272845f6ecSBartlomiej Zolnierkiewicz /* Exynos generic registers */ 282845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_TRIMINFO 0x0 292845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_CONTROL 0x20 302845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_STATUS 0x28 312845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_CURRENT_TEMP 0x40 322845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_INTEN 0x70 332845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_INTSTAT 0x74 342845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REG_INTCLEAR 0x78 352845f6ecSBartlomiej Zolnierkiewicz 362845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TEMP_MASK 0xff 372845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REF_VOLTAGE_SHIFT 24 382845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_REF_VOLTAGE_MASK 0x1f 392845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_BUF_SLOPE_SEL_MASK 0xf 402845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT 8 412845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_CORE_EN_SHIFT 0 422845f6ecSBartlomiej Zolnierkiewicz 432845f6ecSBartlomiej Zolnierkiewicz /* Exynos3250 specific registers */ 442845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TRIMINFO_CON1 0x10 452845f6ecSBartlomiej Zolnierkiewicz 462845f6ecSBartlomiej Zolnierkiewicz /* Exynos4210 specific registers */ 472845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS4210_TMU_REG_THRESHOLD_TEMP 0x44 482845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS4210_TMU_REG_TRIG_LEVEL0 0x50 492845f6ecSBartlomiej Zolnierkiewicz 502845f6ecSBartlomiej Zolnierkiewicz /* Exynos5250, Exynos4412, Exynos3250 specific registers */ 512845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TRIMINFO_CON2 0x14 522845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_THD_TEMP_RISE 0x50 532845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_THD_TEMP_FALL 0x54 542845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_CON 0x80 552845f6ecSBartlomiej Zolnierkiewicz 562845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TRIMINFO_RELOAD_ENABLE 1 572845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TRIMINFO_25_SHIFT 0 582845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TRIMINFO_85_SHIFT 8 592845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TRIP_MODE_SHIFT 13 602845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_TRIP_MODE_MASK 0x7 612845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_THERM_TRIP_EN_SHIFT 12 622845f6ecSBartlomiej Zolnierkiewicz 632845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_INTEN_RISE0_SHIFT 0 642845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_TMU_INTEN_FALL0_SHIFT 16 652845f6ecSBartlomiej Zolnierkiewicz 662845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_TIME 0x57F0 672845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_TIME_MASK 0xffff 682845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_TIME_SHIFT 16 692845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_DATA_SHIFT 8 702845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_DATA_MASK 0xFF 712845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS_EMUL_ENABLE 0x1 722845f6ecSBartlomiej Zolnierkiewicz 732845f6ecSBartlomiej Zolnierkiewicz /* Exynos5260 specific */ 742845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS5260_TMU_REG_INTEN 0xC0 752845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS5260_TMU_REG_INTSTAT 0xC4 762845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS5260_TMU_REG_INTCLEAR 0xC8 772845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS5260_EMUL_CON 0x100 782845f6ecSBartlomiej Zolnierkiewicz 792845f6ecSBartlomiej Zolnierkiewicz /* Exynos4412 specific */ 802845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS4412_MUX_ADDR_VALUE 6 812845f6ecSBartlomiej Zolnierkiewicz #define EXYNOS4412_MUX_ADDR_SHIFT 20 822845f6ecSBartlomiej Zolnierkiewicz 83488c7455SChanwoo Choi /* Exynos5433 specific registers */ 84488c7455SChanwoo Choi #define EXYNOS5433_THD_TEMP_RISE3_0 0x050 85488c7455SChanwoo Choi #define EXYNOS5433_THD_TEMP_RISE7_4 0x054 86488c7455SChanwoo Choi #define EXYNOS5433_THD_TEMP_FALL3_0 0x060 87488c7455SChanwoo Choi #define EXYNOS5433_THD_TEMP_FALL7_4 0x064 88488c7455SChanwoo Choi #define EXYNOS5433_TMU_REG_INTEN 0x0c0 89488c7455SChanwoo Choi #define EXYNOS5433_TMU_REG_INTPEND 0x0c8 90488c7455SChanwoo Choi #define EXYNOS5433_TMU_EMUL_CON 0x110 91488c7455SChanwoo Choi #define EXYNOS5433_TMU_PD_DET_EN 0x130 92488c7455SChanwoo Choi 93488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_SENSOR_ID_SHIFT 16 94488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_CALIB_SEL_SHIFT 23 95488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_SENSOR_ID_MASK \ 96488c7455SChanwoo Choi (0xf << EXYNOS5433_TRIMINFO_SENSOR_ID_SHIFT) 97488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_CALIB_SEL_MASK BIT(23) 98488c7455SChanwoo Choi 99488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_ONE_POINT_TRIMMING 0 100488c7455SChanwoo Choi #define EXYNOS5433_TRIMINFO_TWO_POINT_TRIMMING 1 101488c7455SChanwoo Choi 102488c7455SChanwoo Choi #define EXYNOS5433_PD_DET_EN 1 103488c7455SChanwoo Choi 10461020d18SBartlomiej Zolnierkiewicz #define EXYNOS5433_G3D_BASE 0x10070000 10559dfa54cSAmit Daniel Kachhap 1066c247393SAbhilash Kesavan /* Exynos7 specific registers */ 1076c247393SAbhilash Kesavan #define EXYNOS7_THD_TEMP_RISE7_6 0x50 1086c247393SAbhilash Kesavan #define EXYNOS7_THD_TEMP_FALL7_6 0x60 1096c247393SAbhilash Kesavan #define EXYNOS7_TMU_REG_INTEN 0x110 1106c247393SAbhilash Kesavan #define EXYNOS7_TMU_REG_INTPEND 0x118 1116c247393SAbhilash Kesavan #define EXYNOS7_TMU_REG_EMUL_CON 0x160 1126c247393SAbhilash Kesavan 1136c247393SAbhilash Kesavan #define EXYNOS7_TMU_TEMP_MASK 0x1ff 1146c247393SAbhilash Kesavan #define EXYNOS7_PD_DET_EN_SHIFT 23 1156c247393SAbhilash Kesavan #define EXYNOS7_TMU_INTEN_RISE0_SHIFT 0 1166c247393SAbhilash Kesavan #define EXYNOS7_EMUL_DATA_SHIFT 7 1176c247393SAbhilash Kesavan #define EXYNOS7_EMUL_DATA_MASK 0x1ff 1186c247393SAbhilash Kesavan 119718b4ca1SBartlomiej Zolnierkiewicz #define EXYNOS_FIRST_POINT_TRIM 25 120718b4ca1SBartlomiej Zolnierkiewicz #define EXYNOS_SECOND_POINT_TRIM 85 121718b4ca1SBartlomiej Zolnierkiewicz 12209d29426SBartlomiej Zolnierkiewicz #define EXYNOS_NOISE_CANCEL_MODE 4 12309d29426SBartlomiej Zolnierkiewicz 1243b6a1a80SLukasz Majewski #define MCELSIUS 1000 1257efd18a2SBartlomiej Zolnierkiewicz 1267efd18a2SBartlomiej Zolnierkiewicz enum soc_type { 1277efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS3250 = 1, 1287efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS4210, 1297efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS4412, 1307efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5250, 1317efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5260, 1327efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5420, 1337efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5420_TRIMINFO, 1347efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS5433, 1357efd18a2SBartlomiej Zolnierkiewicz SOC_ARCH_EXYNOS7, 1367efd18a2SBartlomiej Zolnierkiewicz }; 1377efd18a2SBartlomiej Zolnierkiewicz 138cebe7373SAmit Daniel Kachhap /** 139cebe7373SAmit Daniel Kachhap * struct exynos_tmu_data : A structure to hold the private data of the TMU 1409625e9e6SAmit Kucheria * driver 141cebe7373SAmit Daniel Kachhap * @id: identifier of the one instance of the TMU controller. 142cebe7373SAmit Daniel Kachhap * @base: base address of the single instance of the TMU controller. 1439025d563SNaveen Krishna Chatradhi * @base_second: base address of the common registers of the TMU controller. 144cebe7373SAmit Daniel Kachhap * @irq: irq number of the TMU controller. 145cebe7373SAmit Daniel Kachhap * @soc: id of the SOC type. 146cebe7373SAmit Daniel Kachhap * @irq_work: pointer to the irq work structure. 147cebe7373SAmit Daniel Kachhap * @lock: lock to implement synchronization. 148cebe7373SAmit Daniel Kachhap * @clk: pointer to the clock structure. 14914a11dc7SNaveen Krishna Chatradhi * @clk_sec: pointer to the clock structure for accessing the base_second. 1506c247393SAbhilash Kesavan * @sclk: pointer to the clock structure for accessing the tmu special clk. 151199b3e3cSBartlomiej Zolnierkiewicz * @cal_type: calibration type for temperature 152e3ed3649SBartlomiej Zolnierkiewicz * @efuse_value: SoC defined fuse value 153e3ed3649SBartlomiej Zolnierkiewicz * @min_efuse_value: minimum valid trimming data 154e3ed3649SBartlomiej Zolnierkiewicz * @max_efuse_value: maximum valid trimming data 155cebe7373SAmit Daniel Kachhap * @temp_error1: fused value of the first point trim. 156cebe7373SAmit Daniel Kachhap * @temp_error2: fused value of the second point trim. 157fccfe099SBartlomiej Zolnierkiewicz * @gain: gain of amplifier in the positive-TC generator block 158fccfe099SBartlomiej Zolnierkiewicz * 0 < gain <= 15 15961020d18SBartlomiej Zolnierkiewicz * @reference_voltage: reference voltage of amplifier 16061020d18SBartlomiej Zolnierkiewicz * in the positive-TC generator block 16161020d18SBartlomiej Zolnierkiewicz * 0 < reference_voltage <= 31 162498d22f6SAmit Daniel Kachhap * @regulator: pointer to the TMU regulator structure. 163cebe7373SAmit Daniel Kachhap * @reg_conf: pointer to structure to register with core thermal. 1649625e9e6SAmit Kucheria * @tzd: pointer to thermal_zone_device structure 1653a3a5f15SKrzysztof Kozlowski * @ntrip: number of supported trip points. 16688fc6f73SMarek Szyprowski * @enabled: current status of TMU device 1679625e9e6SAmit Kucheria * @tmu_set_trip_temp: SoC specific method to set trip (rising threshold) 1689625e9e6SAmit Kucheria * @tmu_set_trip_hyst: SoC specific to set hysteresis (falling threshold) 16972d1100bSBartlomiej Zolnierkiewicz * @tmu_initialize: SoC specific TMU initialization method 17037f9034fSBartlomiej Zolnierkiewicz * @tmu_control: SoC specific TMU control method 171b79985caSBartlomiej Zolnierkiewicz * @tmu_read: SoC specific TMU temperature read method 172285d994aSBartlomiej Zolnierkiewicz * @tmu_set_emulation: SoC specific TMU emulation setting method 173a7331f72SBartlomiej Zolnierkiewicz * @tmu_clear_irqs: SoC specific TMU interrupts clearing method 174cebe7373SAmit Daniel Kachhap */ 17559dfa54cSAmit Daniel Kachhap struct exynos_tmu_data { 176cebe7373SAmit Daniel Kachhap int id; 17759dfa54cSAmit Daniel Kachhap void __iomem *base; 1789025d563SNaveen Krishna Chatradhi void __iomem *base_second; 17959dfa54cSAmit Daniel Kachhap int irq; 18059dfa54cSAmit Daniel Kachhap enum soc_type soc; 18159dfa54cSAmit Daniel Kachhap struct work_struct irq_work; 18259dfa54cSAmit Daniel Kachhap struct mutex lock; 1836c247393SAbhilash Kesavan struct clk *clk, *clk_sec, *sclk; 184199b3e3cSBartlomiej Zolnierkiewicz u32 cal_type; 185e3ed3649SBartlomiej Zolnierkiewicz u32 efuse_value; 186e3ed3649SBartlomiej Zolnierkiewicz u32 min_efuse_value; 187e3ed3649SBartlomiej Zolnierkiewicz u32 max_efuse_value; 1886c247393SAbhilash Kesavan u16 temp_error1, temp_error2; 189fccfe099SBartlomiej Zolnierkiewicz u8 gain; 19061020d18SBartlomiej Zolnierkiewicz u8 reference_voltage; 191498d22f6SAmit Daniel Kachhap struct regulator *regulator; 1923b6a1a80SLukasz Majewski struct thermal_zone_device *tzd; 1933a3a5f15SKrzysztof Kozlowski unsigned int ntrip; 19488fc6f73SMarek Szyprowski bool enabled; 1953b6a1a80SLukasz Majewski 196c8f8f768SBartlomiej Zolnierkiewicz void (*tmu_set_trip_temp)(struct exynos_tmu_data *data, int trip, 197c8f8f768SBartlomiej Zolnierkiewicz u8 temp); 198c8f8f768SBartlomiej Zolnierkiewicz void (*tmu_set_trip_hyst)(struct exynos_tmu_data *data, int trip, 199c8f8f768SBartlomiej Zolnierkiewicz u8 temp, u8 hyst); 200c35268f5SBartlomiej Zolnierkiewicz void (*tmu_initialize)(struct platform_device *pdev); 20137f9034fSBartlomiej Zolnierkiewicz void (*tmu_control)(struct platform_device *pdev, bool on); 202b79985caSBartlomiej Zolnierkiewicz int (*tmu_read)(struct exynos_tmu_data *data); 20317e8351aSSascha Hauer void (*tmu_set_emulation)(struct exynos_tmu_data *data, int temp); 204a7331f72SBartlomiej Zolnierkiewicz void (*tmu_clear_irqs)(struct exynos_tmu_data *data); 20559dfa54cSAmit Daniel Kachhap }; 20659dfa54cSAmit Daniel Kachhap 20759dfa54cSAmit Daniel Kachhap /* 20859dfa54cSAmit Daniel Kachhap * TMU treats temperature as a mapped temperature code. 20959dfa54cSAmit Daniel Kachhap * The temperature is converted differently depending on the calibration type. 21059dfa54cSAmit Daniel Kachhap */ 21159dfa54cSAmit Daniel Kachhap static int temp_to_code(struct exynos_tmu_data *data, u8 temp) 21259dfa54cSAmit Daniel Kachhap { 213199b3e3cSBartlomiej Zolnierkiewicz if (data->cal_type == TYPE_ONE_POINT_TRIMMING) 214718b4ca1SBartlomiej Zolnierkiewicz return temp + data->temp_error1 - EXYNOS_FIRST_POINT_TRIM; 21559dfa54cSAmit Daniel Kachhap 216718b4ca1SBartlomiej Zolnierkiewicz return (temp - EXYNOS_FIRST_POINT_TRIM) * 21759dfa54cSAmit Daniel Kachhap (data->temp_error2 - data->temp_error1) / 218718b4ca1SBartlomiej Zolnierkiewicz (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) + 219bb34b4c8SAmit Daniel Kachhap data->temp_error1; 22059dfa54cSAmit Daniel Kachhap } 22159dfa54cSAmit Daniel Kachhap 22259dfa54cSAmit Daniel Kachhap /* 22359dfa54cSAmit Daniel Kachhap * Calculate a temperature value from a temperature code. 22459dfa54cSAmit Daniel Kachhap * The unit of the temperature is degree Celsius. 22559dfa54cSAmit Daniel Kachhap */ 2266c247393SAbhilash Kesavan static int code_to_temp(struct exynos_tmu_data *data, u16 temp_code) 22759dfa54cSAmit Daniel Kachhap { 228199b3e3cSBartlomiej Zolnierkiewicz if (data->cal_type == TYPE_ONE_POINT_TRIMMING) 229718b4ca1SBartlomiej Zolnierkiewicz return temp_code - data->temp_error1 + EXYNOS_FIRST_POINT_TRIM; 23059dfa54cSAmit Daniel Kachhap 2319c933b1bSBartlomiej Zolnierkiewicz return (temp_code - data->temp_error1) * 232718b4ca1SBartlomiej Zolnierkiewicz (EXYNOS_SECOND_POINT_TRIM - EXYNOS_FIRST_POINT_TRIM) / 233bb34b4c8SAmit Daniel Kachhap (data->temp_error2 - data->temp_error1) + 234718b4ca1SBartlomiej Zolnierkiewicz EXYNOS_FIRST_POINT_TRIM; 23559dfa54cSAmit Daniel Kachhap } 23659dfa54cSAmit Daniel Kachhap 2378328a4b1SBartlomiej Zolnierkiewicz static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info) 238b835ced1SBartlomiej Zolnierkiewicz { 239aef27b65SBartlomiej Zolnierkiewicz u16 tmu_temp_mask = 240aef27b65SBartlomiej Zolnierkiewicz (data->soc == SOC_ARCH_EXYNOS7) ? EXYNOS7_TMU_TEMP_MASK 241aef27b65SBartlomiej Zolnierkiewicz : EXYNOS_TMU_TEMP_MASK; 24259dfa54cSAmit Daniel Kachhap 243aef27b65SBartlomiej Zolnierkiewicz data->temp_error1 = trim_info & tmu_temp_mask; 24499d67fb9SBartlomiej Zolnierkiewicz data->temp_error2 = ((trim_info >> EXYNOS_TRIMINFO_85_SHIFT) & 245b8d582b9SAmit Daniel Kachhap EXYNOS_TMU_TEMP_MASK); 24659dfa54cSAmit Daniel Kachhap 2475000806cSAmit Daniel Kachhap if (!data->temp_error1 || 248e3ed3649SBartlomiej Zolnierkiewicz (data->min_efuse_value > data->temp_error1) || 249e3ed3649SBartlomiej Zolnierkiewicz (data->temp_error1 > data->max_efuse_value)) 250e3ed3649SBartlomiej Zolnierkiewicz data->temp_error1 = data->efuse_value & EXYNOS_TMU_TEMP_MASK; 2515000806cSAmit Daniel Kachhap 2525000806cSAmit Daniel Kachhap if (!data->temp_error2) 2535000806cSAmit Daniel Kachhap data->temp_error2 = 254e3ed3649SBartlomiej Zolnierkiewicz (data->efuse_value >> EXYNOS_TRIMINFO_85_SHIFT) & 2555000806cSAmit Daniel Kachhap EXYNOS_TMU_TEMP_MASK; 2568328a4b1SBartlomiej Zolnierkiewicz } 25759dfa54cSAmit Daniel Kachhap 25859dfa54cSAmit Daniel Kachhap static int exynos_tmu_initialize(struct platform_device *pdev) 25959dfa54cSAmit Daniel Kachhap { 26059dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 26175e0f100SBartlomiej Zolnierkiewicz struct thermal_zone_device *tzd = data->tzd; 262a3b3dd38SDaniel Lezcano int num_trips = thermal_zone_get_num_trips(tzd); 26397b3881bSBartlomiej Zolnierkiewicz unsigned int status; 264ca38255eSDaniel Lezcano int ret = 0, temp; 26575e0f100SBartlomiej Zolnierkiewicz 266a1c30637SDaniel Lezcano ret = thermal_zone_get_crit_temp(tzd, &temp); 267a1c30637SDaniel Lezcano if (ret && data->soc != SOC_ARCH_EXYNOS5433) { /* FIXME */ 2688f1c404bSBartlomiej Zolnierkiewicz dev_err(&pdev->dev, 2698f1c404bSBartlomiej Zolnierkiewicz "No CRITICAL trip point defined in device tree!\n"); 2708f1c404bSBartlomiej Zolnierkiewicz goto out; 2718f1c404bSBartlomiej Zolnierkiewicz } 2728f1c404bSBartlomiej Zolnierkiewicz 273a3b3dd38SDaniel Lezcano if (num_trips > data->ntrip) { 2743a3a5f15SKrzysztof Kozlowski dev_info(&pdev->dev, 2753a3a5f15SKrzysztof Kozlowski "More trip points than supported by this TMU.\n"); 2763a3a5f15SKrzysztof Kozlowski dev_info(&pdev->dev, 2773a3a5f15SKrzysztof Kozlowski "%d trip points should be configured in polling mode.\n", 278a3b3dd38SDaniel Lezcano num_trips - data->ntrip); 2793a3a5f15SKrzysztof Kozlowski } 2803a3a5f15SKrzysztof Kozlowski 28159dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 28259dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 28359dfa54cSAmit Daniel Kachhap if (!IS_ERR(data->clk_sec)) 28459dfa54cSAmit Daniel Kachhap clk_enable(data->clk_sec); 28597b3881bSBartlomiej Zolnierkiewicz 28697b3881bSBartlomiej Zolnierkiewicz status = readb(data->base + EXYNOS_TMU_REG_STATUS); 287fac36bacSBartlomiej Zolnierkiewicz if (!status) { 28897b3881bSBartlomiej Zolnierkiewicz ret = -EBUSY; 289fac36bacSBartlomiej Zolnierkiewicz } else { 290c8f8f768SBartlomiej Zolnierkiewicz int i, ntrips = 291a3b3dd38SDaniel Lezcano min_t(int, num_trips, data->ntrip); 292c8f8f768SBartlomiej Zolnierkiewicz 293c35268f5SBartlomiej Zolnierkiewicz data->tmu_initialize(pdev); 294c8f8f768SBartlomiej Zolnierkiewicz 295c8f8f768SBartlomiej Zolnierkiewicz /* Write temperature code for rising and falling threshold */ 296c8f8f768SBartlomiej Zolnierkiewicz for (i = 0; i < ntrips; i++) { 297c8f8f768SBartlomiej Zolnierkiewicz 298ca38255eSDaniel Lezcano struct thermal_trip trip; 299ca38255eSDaniel Lezcano 300ca38255eSDaniel Lezcano ret = thermal_zone_get_trip(tzd, i, &trip); 30189335c20SBartlomiej Zolnierkiewicz if (ret) 30289335c20SBartlomiej Zolnierkiewicz goto err; 303ca38255eSDaniel Lezcano 304ca38255eSDaniel Lezcano data->tmu_set_trip_temp(data, i, trip.temperature / MCELSIUS); 305ca38255eSDaniel Lezcano data->tmu_set_trip_hyst(data, i, trip.temperature / MCELSIUS, 306ca38255eSDaniel Lezcano trip.hysteresis / MCELSIUS); 307c8f8f768SBartlomiej Zolnierkiewicz } 308c8f8f768SBartlomiej Zolnierkiewicz 309fac36bacSBartlomiej Zolnierkiewicz data->tmu_clear_irqs(data); 310fac36bacSBartlomiej Zolnierkiewicz } 31189335c20SBartlomiej Zolnierkiewicz err: 31259dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 31359dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 31414a11dc7SNaveen Krishna Chatradhi if (!IS_ERR(data->clk_sec)) 31514a11dc7SNaveen Krishna Chatradhi clk_disable(data->clk_sec); 3168f1c404bSBartlomiej Zolnierkiewicz out: 31759dfa54cSAmit Daniel Kachhap return ret; 31859dfa54cSAmit Daniel Kachhap } 31959dfa54cSAmit Daniel Kachhap 320d00671c3SBartlomiej Zolnierkiewicz static u32 get_con_reg(struct exynos_tmu_data *data, u32 con) 32159dfa54cSAmit Daniel Kachhap { 3227575983cSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS4412 || 3237575983cSBartlomiej Zolnierkiewicz data->soc == SOC_ARCH_EXYNOS3250) 3247575983cSBartlomiej Zolnierkiewicz con |= (EXYNOS4412_MUX_ADDR_VALUE << EXYNOS4412_MUX_ADDR_SHIFT); 32586f5362eSLukasz Majewski 32699d67fb9SBartlomiej Zolnierkiewicz con &= ~(EXYNOS_TMU_REF_VOLTAGE_MASK << EXYNOS_TMU_REF_VOLTAGE_SHIFT); 32761020d18SBartlomiej Zolnierkiewicz con |= data->reference_voltage << EXYNOS_TMU_REF_VOLTAGE_SHIFT; 328d0a0ce3eSAmit Daniel Kachhap 32999d67fb9SBartlomiej Zolnierkiewicz con &= ~(EXYNOS_TMU_BUF_SLOPE_SEL_MASK << EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT); 330fccfe099SBartlomiej Zolnierkiewicz con |= (data->gain << EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT); 331d0a0ce3eSAmit Daniel Kachhap 332b9504a6aSBartlomiej Zolnierkiewicz con &= ~(EXYNOS_TMU_TRIP_MODE_MASK << EXYNOS_TMU_TRIP_MODE_SHIFT); 33309d29426SBartlomiej Zolnierkiewicz con |= (EXYNOS_NOISE_CANCEL_MODE << EXYNOS_TMU_TRIP_MODE_SHIFT); 33459dfa54cSAmit Daniel Kachhap 335d00671c3SBartlomiej Zolnierkiewicz return con; 336d00671c3SBartlomiej Zolnierkiewicz } 337d00671c3SBartlomiej Zolnierkiewicz 338d00671c3SBartlomiej Zolnierkiewicz static void exynos_tmu_control(struct platform_device *pdev, bool on) 339d00671c3SBartlomiej Zolnierkiewicz { 340d00671c3SBartlomiej Zolnierkiewicz struct exynos_tmu_data *data = platform_get_drvdata(pdev); 341d00671c3SBartlomiej Zolnierkiewicz 342d00671c3SBartlomiej Zolnierkiewicz mutex_lock(&data->lock); 343d00671c3SBartlomiej Zolnierkiewicz clk_enable(data->clk); 34437f9034fSBartlomiej Zolnierkiewicz data->tmu_control(pdev, on); 34588fc6f73SMarek Szyprowski data->enabled = on; 34659dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 34759dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 34859dfa54cSAmit Daniel Kachhap } 34959dfa54cSAmit Daniel Kachhap 350a503a10fSBartlomiej Zolnierkiewicz static void exynos4210_tmu_set_trip_temp(struct exynos_tmu_data *data, 351ca38255eSDaniel Lezcano int trip_id, u8 temp) 35272d1100bSBartlomiej Zolnierkiewicz { 353ca38255eSDaniel Lezcano struct thermal_trip trip; 354a503a10fSBartlomiej Zolnierkiewicz u8 ref, th_code; 35572d1100bSBartlomiej Zolnierkiewicz 356ca38255eSDaniel Lezcano if (thermal_zone_get_trip(data->tzd, 0, &trip)) 357ca38255eSDaniel Lezcano return; 358a503a10fSBartlomiej Zolnierkiewicz 359ca38255eSDaniel Lezcano ref = trip.temperature / MCELSIUS; 360ca38255eSDaniel Lezcano 361ca38255eSDaniel Lezcano if (trip_id == 0) { 362a503a10fSBartlomiej Zolnierkiewicz th_code = temp_to_code(data, ref); 363a503a10fSBartlomiej Zolnierkiewicz writeb(th_code, data->base + EXYNOS4210_TMU_REG_THRESHOLD_TEMP); 36472d1100bSBartlomiej Zolnierkiewicz } 36572d1100bSBartlomiej Zolnierkiewicz 366a503a10fSBartlomiej Zolnierkiewicz temp -= ref; 367ca38255eSDaniel Lezcano writeb(temp, data->base + EXYNOS4210_TMU_REG_TRIG_LEVEL0 + trip_id * 4); 368a503a10fSBartlomiej Zolnierkiewicz } 369a503a10fSBartlomiej Zolnierkiewicz 370c8f8f768SBartlomiej Zolnierkiewicz /* failing thresholds are not supported on Exynos4210 */ 371c8f8f768SBartlomiej Zolnierkiewicz static void exynos4210_tmu_set_trip_hyst(struct exynos_tmu_data *data, 372c8f8f768SBartlomiej Zolnierkiewicz int trip, u8 temp, u8 hyst) 373c8f8f768SBartlomiej Zolnierkiewicz { 374c8f8f768SBartlomiej Zolnierkiewicz } 375c8f8f768SBartlomiej Zolnierkiewicz 376c35268f5SBartlomiej Zolnierkiewicz static void exynos4210_tmu_initialize(struct platform_device *pdev) 37759dfa54cSAmit Daniel Kachhap { 37859dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 37972d1100bSBartlomiej Zolnierkiewicz 38072d1100bSBartlomiej Zolnierkiewicz sanitize_temp_error(data, readl(data->base + EXYNOS_TMU_REG_TRIMINFO)); 38172d1100bSBartlomiej Zolnierkiewicz } 38272d1100bSBartlomiej Zolnierkiewicz 383a503a10fSBartlomiej Zolnierkiewicz static void exynos4412_tmu_set_trip_temp(struct exynos_tmu_data *data, 384a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp) 385a503a10fSBartlomiej Zolnierkiewicz { 386a503a10fSBartlomiej Zolnierkiewicz u32 th, con; 387a503a10fSBartlomiej Zolnierkiewicz 388a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + EXYNOS_THD_TEMP_RISE); 389a503a10fSBartlomiej Zolnierkiewicz th &= ~(0xff << 8 * trip); 390a503a10fSBartlomiej Zolnierkiewicz th |= temp_to_code(data, temp) << 8 * trip; 391a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + EXYNOS_THD_TEMP_RISE); 392a503a10fSBartlomiej Zolnierkiewicz 393a503a10fSBartlomiej Zolnierkiewicz if (trip == 3) { 394a503a10fSBartlomiej Zolnierkiewicz con = readl(data->base + EXYNOS_TMU_REG_CONTROL); 395a503a10fSBartlomiej Zolnierkiewicz con |= (1 << EXYNOS_TMU_THERM_TRIP_EN_SHIFT); 396a503a10fSBartlomiej Zolnierkiewicz writel(con, data->base + EXYNOS_TMU_REG_CONTROL); 397a503a10fSBartlomiej Zolnierkiewicz } 398a503a10fSBartlomiej Zolnierkiewicz } 399a503a10fSBartlomiej Zolnierkiewicz 400a503a10fSBartlomiej Zolnierkiewicz static void exynos4412_tmu_set_trip_hyst(struct exynos_tmu_data *data, 401a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp, u8 hyst) 402a503a10fSBartlomiej Zolnierkiewicz { 403a503a10fSBartlomiej Zolnierkiewicz u32 th; 404a503a10fSBartlomiej Zolnierkiewicz 405a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + EXYNOS_THD_TEMP_FALL); 406a503a10fSBartlomiej Zolnierkiewicz th &= ~(0xff << 8 * trip); 407a503a10fSBartlomiej Zolnierkiewicz if (hyst) 408a503a10fSBartlomiej Zolnierkiewicz th |= temp_to_code(data, temp - hyst) << 8 * trip; 409a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + EXYNOS_THD_TEMP_FALL); 410a503a10fSBartlomiej Zolnierkiewicz } 411a503a10fSBartlomiej Zolnierkiewicz 412c35268f5SBartlomiej Zolnierkiewicz static void exynos4412_tmu_initialize(struct platform_device *pdev) 41372d1100bSBartlomiej Zolnierkiewicz { 41472d1100bSBartlomiej Zolnierkiewicz struct exynos_tmu_data *data = platform_get_drvdata(pdev); 415a503a10fSBartlomiej Zolnierkiewicz unsigned int trim_info, ctrl; 41672d1100bSBartlomiej Zolnierkiewicz 41772d1100bSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS3250 || 41872d1100bSBartlomiej Zolnierkiewicz data->soc == SOC_ARCH_EXYNOS4412 || 41972d1100bSBartlomiej Zolnierkiewicz data->soc == SOC_ARCH_EXYNOS5250) { 42072d1100bSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS3250) { 42172d1100bSBartlomiej Zolnierkiewicz ctrl = readl(data->base + EXYNOS_TMU_TRIMINFO_CON1); 42272d1100bSBartlomiej Zolnierkiewicz ctrl |= EXYNOS_TRIMINFO_RELOAD_ENABLE; 42372d1100bSBartlomiej Zolnierkiewicz writel(ctrl, data->base + EXYNOS_TMU_TRIMINFO_CON1); 42472d1100bSBartlomiej Zolnierkiewicz } 42572d1100bSBartlomiej Zolnierkiewicz ctrl = readl(data->base + EXYNOS_TMU_TRIMINFO_CON2); 42672d1100bSBartlomiej Zolnierkiewicz ctrl |= EXYNOS_TRIMINFO_RELOAD_ENABLE; 42772d1100bSBartlomiej Zolnierkiewicz writel(ctrl, data->base + EXYNOS_TMU_TRIMINFO_CON2); 42872d1100bSBartlomiej Zolnierkiewicz } 42972d1100bSBartlomiej Zolnierkiewicz 43072d1100bSBartlomiej Zolnierkiewicz /* On exynos5420 the triminfo register is in the shared space */ 43172d1100bSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO) 43272d1100bSBartlomiej Zolnierkiewicz trim_info = readl(data->base_second + EXYNOS_TMU_REG_TRIMINFO); 43372d1100bSBartlomiej Zolnierkiewicz else 43472d1100bSBartlomiej Zolnierkiewicz trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); 43572d1100bSBartlomiej Zolnierkiewicz 43672d1100bSBartlomiej Zolnierkiewicz sanitize_temp_error(data, trim_info); 4373b6a1a80SLukasz Majewski } 4383b6a1a80SLukasz Majewski 439a503a10fSBartlomiej Zolnierkiewicz static void exynos5433_tmu_set_trip_temp(struct exynos_tmu_data *data, 440a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp) 441a503a10fSBartlomiej Zolnierkiewicz { 442a503a10fSBartlomiej Zolnierkiewicz unsigned int reg_off, j; 443a503a10fSBartlomiej Zolnierkiewicz u32 th; 444a503a10fSBartlomiej Zolnierkiewicz 445a503a10fSBartlomiej Zolnierkiewicz if (trip > 3) { 446a503a10fSBartlomiej Zolnierkiewicz reg_off = EXYNOS5433_THD_TEMP_RISE7_4; 447a503a10fSBartlomiej Zolnierkiewicz j = trip - 4; 448a503a10fSBartlomiej Zolnierkiewicz } else { 449a503a10fSBartlomiej Zolnierkiewicz reg_off = EXYNOS5433_THD_TEMP_RISE3_0; 450a503a10fSBartlomiej Zolnierkiewicz j = trip; 4513b6a1a80SLukasz Majewski } 4523b6a1a80SLukasz Majewski 453a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + reg_off); 454a503a10fSBartlomiej Zolnierkiewicz th &= ~(0xff << j * 8); 455a503a10fSBartlomiej Zolnierkiewicz th |= (temp_to_code(data, temp) << j * 8); 456a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + reg_off); 45772d1100bSBartlomiej Zolnierkiewicz } 45872d1100bSBartlomiej Zolnierkiewicz 459a503a10fSBartlomiej Zolnierkiewicz static void exynos5433_tmu_set_trip_hyst(struct exynos_tmu_data *data, 460a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp, u8 hyst) 461a503a10fSBartlomiej Zolnierkiewicz { 462a503a10fSBartlomiej Zolnierkiewicz unsigned int reg_off, j; 463a503a10fSBartlomiej Zolnierkiewicz u32 th; 464a503a10fSBartlomiej Zolnierkiewicz 465a503a10fSBartlomiej Zolnierkiewicz if (trip > 3) { 466a503a10fSBartlomiej Zolnierkiewicz reg_off = EXYNOS5433_THD_TEMP_FALL7_4; 467a503a10fSBartlomiej Zolnierkiewicz j = trip - 4; 468a503a10fSBartlomiej Zolnierkiewicz } else { 469a503a10fSBartlomiej Zolnierkiewicz reg_off = EXYNOS5433_THD_TEMP_FALL3_0; 470a503a10fSBartlomiej Zolnierkiewicz j = trip; 471a503a10fSBartlomiej Zolnierkiewicz } 472a503a10fSBartlomiej Zolnierkiewicz 473a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + reg_off); 474a503a10fSBartlomiej Zolnierkiewicz th &= ~(0xff << j * 8); 475a503a10fSBartlomiej Zolnierkiewicz th |= (temp_to_code(data, temp - hyst) << j * 8); 476a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + reg_off); 47772d1100bSBartlomiej Zolnierkiewicz } 47872d1100bSBartlomiej Zolnierkiewicz 479c35268f5SBartlomiej Zolnierkiewicz static void exynos5433_tmu_initialize(struct platform_device *pdev) 480488c7455SChanwoo Choi { 481488c7455SChanwoo Choi struct exynos_tmu_data *data = platform_get_drvdata(pdev); 48297b3881bSBartlomiej Zolnierkiewicz unsigned int trim_info; 483c8f8f768SBartlomiej Zolnierkiewicz int sensor_id, cal_type; 484488c7455SChanwoo Choi 485488c7455SChanwoo Choi trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); 486488c7455SChanwoo Choi sanitize_temp_error(data, trim_info); 487488c7455SChanwoo Choi 488488c7455SChanwoo Choi /* Read the temperature sensor id */ 489488c7455SChanwoo Choi sensor_id = (trim_info & EXYNOS5433_TRIMINFO_SENSOR_ID_MASK) 490488c7455SChanwoo Choi >> EXYNOS5433_TRIMINFO_SENSOR_ID_SHIFT; 491488c7455SChanwoo Choi dev_info(&pdev->dev, "Temperature sensor ID: 0x%x\n", sensor_id); 492488c7455SChanwoo Choi 493488c7455SChanwoo Choi /* Read the calibration mode */ 494488c7455SChanwoo Choi writel(trim_info, data->base + EXYNOS_TMU_REG_TRIMINFO); 495488c7455SChanwoo Choi cal_type = (trim_info & EXYNOS5433_TRIMINFO_CALIB_SEL_MASK) 496488c7455SChanwoo Choi >> EXYNOS5433_TRIMINFO_CALIB_SEL_SHIFT; 497488c7455SChanwoo Choi 498488c7455SChanwoo Choi switch (cal_type) { 499488c7455SChanwoo Choi case EXYNOS5433_TRIMINFO_TWO_POINT_TRIMMING: 500199b3e3cSBartlomiej Zolnierkiewicz data->cal_type = TYPE_TWO_POINT_TRIMMING; 501488c7455SChanwoo Choi break; 502199b3e3cSBartlomiej Zolnierkiewicz case EXYNOS5433_TRIMINFO_ONE_POINT_TRIMMING: 503488c7455SChanwoo Choi default: 504199b3e3cSBartlomiej Zolnierkiewicz data->cal_type = TYPE_ONE_POINT_TRIMMING; 505488c7455SChanwoo Choi break; 506baba1ebbSKrzysztof Kozlowski } 507488c7455SChanwoo Choi 508488c7455SChanwoo Choi dev_info(&pdev->dev, "Calibration type is %d-point calibration\n", 509488c7455SChanwoo Choi cal_type ? 2 : 1); 510488c7455SChanwoo Choi } 511488c7455SChanwoo Choi 512a503a10fSBartlomiej Zolnierkiewicz static void exynos7_tmu_set_trip_temp(struct exynos_tmu_data *data, 513a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp) 51472d1100bSBartlomiej Zolnierkiewicz { 5156c247393SAbhilash Kesavan unsigned int reg_off, bit_off; 516a503a10fSBartlomiej Zolnierkiewicz u32 th; 5176c247393SAbhilash Kesavan 518a503a10fSBartlomiej Zolnierkiewicz reg_off = ((7 - trip) / 2) * 4; 519a503a10fSBartlomiej Zolnierkiewicz bit_off = ((8 - trip) % 2); 520a503a10fSBartlomiej Zolnierkiewicz 521a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + EXYNOS7_THD_TEMP_RISE7_6 + reg_off); 522a503a10fSBartlomiej Zolnierkiewicz th &= ~(EXYNOS7_TMU_TEMP_MASK << (16 * bit_off)); 523a503a10fSBartlomiej Zolnierkiewicz th |= temp_to_code(data, temp) << (16 * bit_off); 524a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + EXYNOS7_THD_TEMP_RISE7_6 + reg_off); 5256c247393SAbhilash Kesavan } 5266c247393SAbhilash Kesavan 527a503a10fSBartlomiej Zolnierkiewicz static void exynos7_tmu_set_trip_hyst(struct exynos_tmu_data *data, 528a503a10fSBartlomiej Zolnierkiewicz int trip, u8 temp, u8 hyst) 529a503a10fSBartlomiej Zolnierkiewicz { 530a503a10fSBartlomiej Zolnierkiewicz unsigned int reg_off, bit_off; 531a503a10fSBartlomiej Zolnierkiewicz u32 th; 532a503a10fSBartlomiej Zolnierkiewicz 533a503a10fSBartlomiej Zolnierkiewicz reg_off = ((7 - trip) / 2) * 4; 534a503a10fSBartlomiej Zolnierkiewicz bit_off = ((8 - trip) % 2); 535a503a10fSBartlomiej Zolnierkiewicz 536a503a10fSBartlomiej Zolnierkiewicz th = readl(data->base + EXYNOS7_THD_TEMP_FALL7_6 + reg_off); 537a503a10fSBartlomiej Zolnierkiewicz th &= ~(EXYNOS7_TMU_TEMP_MASK << (16 * bit_off)); 538a503a10fSBartlomiej Zolnierkiewicz th |= temp_to_code(data, temp - hyst) << (16 * bit_off); 539a503a10fSBartlomiej Zolnierkiewicz writel(th, data->base + EXYNOS7_THD_TEMP_FALL7_6 + reg_off); 540a503a10fSBartlomiej Zolnierkiewicz } 541a503a10fSBartlomiej Zolnierkiewicz 542c35268f5SBartlomiej Zolnierkiewicz static void exynos7_tmu_initialize(struct platform_device *pdev) 5436c247393SAbhilash Kesavan { 5446c247393SAbhilash Kesavan struct exynos_tmu_data *data = platform_get_drvdata(pdev); 54597b3881bSBartlomiej Zolnierkiewicz unsigned int trim_info; 5466c247393SAbhilash Kesavan 5476c247393SAbhilash Kesavan trim_info = readl(data->base + EXYNOS_TMU_REG_TRIMINFO); 548aef27b65SBartlomiej Zolnierkiewicz sanitize_temp_error(data, trim_info); 5496c247393SAbhilash Kesavan } 5506c247393SAbhilash Kesavan 55137f9034fSBartlomiej Zolnierkiewicz static void exynos4210_tmu_control(struct platform_device *pdev, bool on) 55237f9034fSBartlomiej Zolnierkiewicz { 55337f9034fSBartlomiej Zolnierkiewicz struct exynos_tmu_data *data = platform_get_drvdata(pdev); 5543b6a1a80SLukasz Majewski struct thermal_zone_device *tz = data->tzd; 55503ef4855SDaniel Lezcano struct thermal_trip trip; 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++) { 56203ef4855SDaniel Lezcano if (thermal_zone_get_trip(tz, i, &trip)) 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; 58603ef4855SDaniel Lezcano struct thermal_trip trip; 58764e94192SBartlomiej Zolnierkiewicz unsigned int con, interrupt_en = 0, pd_det_en, i; 588488c7455SChanwoo Choi 589488c7455SChanwoo Choi con = get_con_reg(data, readl(data->base + EXYNOS_TMU_REG_CONTROL)); 590488c7455SChanwoo Choi 591488c7455SChanwoo Choi if (on) { 59264e94192SBartlomiej Zolnierkiewicz for (i = 0; i < data->ntrip; i++) { 59303ef4855SDaniel Lezcano if (thermal_zone_get_trip(tz, i, &trip)) 59464e94192SBartlomiej Zolnierkiewicz continue; 59564e94192SBartlomiej Zolnierkiewicz 59664e94192SBartlomiej Zolnierkiewicz interrupt_en |= 59764e94192SBartlomiej Zolnierkiewicz (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i)); 59864e94192SBartlomiej Zolnierkiewicz } 599488c7455SChanwoo Choi 600488c7455SChanwoo Choi interrupt_en |= 601488c7455SChanwoo Choi interrupt_en << EXYNOS_TMU_INTEN_FALL0_SHIFT; 60264e94192SBartlomiej Zolnierkiewicz 60364e94192SBartlomiej Zolnierkiewicz con |= (1 << EXYNOS_TMU_CORE_EN_SHIFT); 60464e94192SBartlomiej Zolnierkiewicz } else 605488c7455SChanwoo Choi con &= ~(1 << EXYNOS_TMU_CORE_EN_SHIFT); 606488c7455SChanwoo Choi 607488c7455SChanwoo Choi pd_det_en = on ? EXYNOS5433_PD_DET_EN : 0; 608488c7455SChanwoo Choi 609488c7455SChanwoo Choi writel(pd_det_en, data->base + EXYNOS5433_TMU_PD_DET_EN); 610488c7455SChanwoo Choi writel(interrupt_en, data->base + EXYNOS5433_TMU_REG_INTEN); 611488c7455SChanwoo Choi writel(con, data->base + EXYNOS_TMU_REG_CONTROL); 612488c7455SChanwoo Choi } 613488c7455SChanwoo Choi 6146c247393SAbhilash Kesavan static void exynos7_tmu_control(struct platform_device *pdev, bool on) 6156c247393SAbhilash Kesavan { 6166c247393SAbhilash Kesavan struct exynos_tmu_data *data = platform_get_drvdata(pdev); 6176c247393SAbhilash Kesavan struct thermal_zone_device *tz = data->tzd; 61803ef4855SDaniel Lezcano struct thermal_trip trip; 61964e94192SBartlomiej Zolnierkiewicz unsigned int con, interrupt_en = 0, i; 6206c247393SAbhilash Kesavan 6216c247393SAbhilash Kesavan con = get_con_reg(data, readl(data->base + EXYNOS_TMU_REG_CONTROL)); 6226c247393SAbhilash Kesavan 6236c247393SAbhilash Kesavan if (on) { 62464e94192SBartlomiej Zolnierkiewicz for (i = 0; i < data->ntrip; i++) { 62503ef4855SDaniel Lezcano if (thermal_zone_get_trip(tz, i, &trip)) 62664e94192SBartlomiej Zolnierkiewicz continue; 62764e94192SBartlomiej Zolnierkiewicz 62864e94192SBartlomiej Zolnierkiewicz interrupt_en |= 62964e94192SBartlomiej Zolnierkiewicz (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i)); 63064e94192SBartlomiej Zolnierkiewicz } 6316c247393SAbhilash Kesavan 6326c247393SAbhilash Kesavan interrupt_en |= 6336c247393SAbhilash Kesavan interrupt_en << EXYNOS_TMU_INTEN_FALL0_SHIFT; 63464e94192SBartlomiej Zolnierkiewicz 63564e94192SBartlomiej Zolnierkiewicz con |= (1 << EXYNOS_TMU_CORE_EN_SHIFT); 63664e94192SBartlomiej Zolnierkiewicz con |= (1 << EXYNOS7_PD_DET_EN_SHIFT); 6376c247393SAbhilash Kesavan } else { 6386c247393SAbhilash Kesavan con &= ~(1 << EXYNOS_TMU_CORE_EN_SHIFT); 63942b696e8SChanwoo Choi con &= ~(1 << EXYNOS7_PD_DET_EN_SHIFT); 6406c247393SAbhilash Kesavan } 6416c247393SAbhilash Kesavan 6426c247393SAbhilash Kesavan writel(interrupt_en, data->base + EXYNOS7_TMU_REG_INTEN); 6436c247393SAbhilash Kesavan writel(con, data->base + EXYNOS_TMU_REG_CONTROL); 6446c247393SAbhilash Kesavan } 6456c247393SAbhilash Kesavan 6467ea98f70SDaniel Lezcano static int exynos_get_temp(struct thermal_zone_device *tz, int *temp) 64759dfa54cSAmit Daniel Kachhap { 6485f68d078SDaniel Lezcano struct exynos_tmu_data *data = thermal_zone_device_priv(tz); 649c8da6cdeSMarek Szyprowski int value, ret = 0; 6503b6a1a80SLukasz Majewski 6513b5236ccSMarek Szyprowski if (!data || !data->tmu_read) 6523b6a1a80SLukasz Majewski return -EINVAL; 653ffe6e16fSKrzysztof Kozlowski else if (!data->enabled) 654ffe6e16fSKrzysztof Kozlowski /* 655ffe6e16fSKrzysztof Kozlowski * Called too early, probably 656ffe6e16fSKrzysztof Kozlowski * from thermal_zone_of_sensor_register(). 657ffe6e16fSKrzysztof Kozlowski */ 658ffe6e16fSKrzysztof Kozlowski return -EAGAIN; 65959dfa54cSAmit Daniel Kachhap 66059dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 66159dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 6623b6a1a80SLukasz Majewski 663c8da6cdeSMarek Szyprowski value = data->tmu_read(data); 664c8da6cdeSMarek Szyprowski if (value < 0) 665c8da6cdeSMarek Szyprowski ret = value; 666c8da6cdeSMarek Szyprowski else 667c8da6cdeSMarek Szyprowski *temp = code_to_temp(data, value) * MCELSIUS; 6683b6a1a80SLukasz Majewski 66959dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 67059dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 67159dfa54cSAmit Daniel Kachhap 672c8da6cdeSMarek Szyprowski return ret; 67359dfa54cSAmit Daniel Kachhap } 67459dfa54cSAmit Daniel Kachhap 67559dfa54cSAmit Daniel Kachhap #ifdef CONFIG_THERMAL_EMULATION 676154013eaSBartlomiej Zolnierkiewicz static u32 get_emul_con_reg(struct exynos_tmu_data *data, unsigned int val, 67717e8351aSSascha Hauer int temp) 678154013eaSBartlomiej Zolnierkiewicz { 679154013eaSBartlomiej Zolnierkiewicz if (temp) { 680154013eaSBartlomiej Zolnierkiewicz temp /= MCELSIUS; 681154013eaSBartlomiej Zolnierkiewicz 682154013eaSBartlomiej Zolnierkiewicz val &= ~(EXYNOS_EMUL_TIME_MASK << EXYNOS_EMUL_TIME_SHIFT); 683154013eaSBartlomiej Zolnierkiewicz val |= (EXYNOS_EMUL_TIME << EXYNOS_EMUL_TIME_SHIFT); 6846c247393SAbhilash Kesavan if (data->soc == SOC_ARCH_EXYNOS7) { 6856c247393SAbhilash Kesavan val &= ~(EXYNOS7_EMUL_DATA_MASK << 6866c247393SAbhilash Kesavan EXYNOS7_EMUL_DATA_SHIFT); 6876c247393SAbhilash Kesavan val |= (temp_to_code(data, temp) << 6886c247393SAbhilash Kesavan EXYNOS7_EMUL_DATA_SHIFT) | 689154013eaSBartlomiej Zolnierkiewicz EXYNOS_EMUL_ENABLE; 690154013eaSBartlomiej Zolnierkiewicz } else { 6916c247393SAbhilash Kesavan val &= ~(EXYNOS_EMUL_DATA_MASK << 6926c247393SAbhilash Kesavan EXYNOS_EMUL_DATA_SHIFT); 6936c247393SAbhilash Kesavan val |= (temp_to_code(data, temp) << 6946c247393SAbhilash Kesavan EXYNOS_EMUL_DATA_SHIFT) | 6956c247393SAbhilash Kesavan EXYNOS_EMUL_ENABLE; 6966c247393SAbhilash Kesavan } 6976c247393SAbhilash Kesavan } else { 698154013eaSBartlomiej Zolnierkiewicz val &= ~EXYNOS_EMUL_ENABLE; 699154013eaSBartlomiej Zolnierkiewicz } 700154013eaSBartlomiej Zolnierkiewicz 701154013eaSBartlomiej Zolnierkiewicz return val; 702154013eaSBartlomiej Zolnierkiewicz } 703154013eaSBartlomiej Zolnierkiewicz 704285d994aSBartlomiej Zolnierkiewicz static void exynos4412_tmu_set_emulation(struct exynos_tmu_data *data, 70517e8351aSSascha Hauer int temp) 706285d994aSBartlomiej Zolnierkiewicz { 707285d994aSBartlomiej Zolnierkiewicz unsigned int val; 708285d994aSBartlomiej Zolnierkiewicz u32 emul_con; 709285d994aSBartlomiej Zolnierkiewicz 710285d994aSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS5260) 711285d994aSBartlomiej Zolnierkiewicz emul_con = EXYNOS5260_EMUL_CON; 712b28fec13SSudip Mukherjee else if (data->soc == SOC_ARCH_EXYNOS5433) 713488c7455SChanwoo Choi emul_con = EXYNOS5433_TMU_EMUL_CON; 7146c247393SAbhilash Kesavan else if (data->soc == SOC_ARCH_EXYNOS7) 7156c247393SAbhilash Kesavan emul_con = EXYNOS7_TMU_REG_EMUL_CON; 716285d994aSBartlomiej Zolnierkiewicz else 717285d994aSBartlomiej Zolnierkiewicz emul_con = EXYNOS_EMUL_CON; 718285d994aSBartlomiej Zolnierkiewicz 719285d994aSBartlomiej Zolnierkiewicz val = readl(data->base + emul_con); 720285d994aSBartlomiej Zolnierkiewicz val = get_emul_con_reg(data, val, temp); 721285d994aSBartlomiej Zolnierkiewicz writel(val, data->base + emul_con); 722285d994aSBartlomiej Zolnierkiewicz } 723285d994aSBartlomiej Zolnierkiewicz 7247ea98f70SDaniel Lezcano static int exynos_tmu_set_emulation(struct thermal_zone_device *tz, int temp) 72559dfa54cSAmit Daniel Kachhap { 7265f68d078SDaniel Lezcano struct exynos_tmu_data *data = thermal_zone_device_priv(tz); 72759dfa54cSAmit Daniel Kachhap int ret = -EINVAL; 72859dfa54cSAmit Daniel Kachhap 729ef3f80fcSBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS4210) 73059dfa54cSAmit Daniel Kachhap goto out; 73159dfa54cSAmit Daniel Kachhap 73259dfa54cSAmit Daniel Kachhap if (temp && temp < MCELSIUS) 73359dfa54cSAmit Daniel Kachhap goto out; 73459dfa54cSAmit Daniel Kachhap 73559dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 73659dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 737285d994aSBartlomiej Zolnierkiewicz data->tmu_set_emulation(data, temp); 73859dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 73959dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 74059dfa54cSAmit Daniel Kachhap return 0; 74159dfa54cSAmit Daniel Kachhap out: 74259dfa54cSAmit Daniel Kachhap return ret; 74359dfa54cSAmit Daniel Kachhap } 74459dfa54cSAmit Daniel Kachhap #else 745285d994aSBartlomiej Zolnierkiewicz #define exynos4412_tmu_set_emulation NULL 7467ea98f70SDaniel Lezcano static int exynos_tmu_set_emulation(struct thermal_zone_device *tz, int temp) 74759dfa54cSAmit Daniel Kachhap { return -EINVAL; } 74859dfa54cSAmit Daniel Kachhap #endif /* CONFIG_THERMAL_EMULATION */ 74959dfa54cSAmit Daniel Kachhap 750b79985caSBartlomiej Zolnierkiewicz static int exynos4210_tmu_read(struct exynos_tmu_data *data) 751b79985caSBartlomiej Zolnierkiewicz { 752b79985caSBartlomiej Zolnierkiewicz int ret = readb(data->base + EXYNOS_TMU_REG_CURRENT_TEMP); 753b79985caSBartlomiej Zolnierkiewicz 754b79985caSBartlomiej Zolnierkiewicz /* "temp_code" should range between 75 and 175 */ 755b79985caSBartlomiej Zolnierkiewicz return (ret < 75 || ret > 175) ? -ENODATA : ret; 756b79985caSBartlomiej Zolnierkiewicz } 757b79985caSBartlomiej Zolnierkiewicz 758b79985caSBartlomiej Zolnierkiewicz static int exynos4412_tmu_read(struct exynos_tmu_data *data) 759b79985caSBartlomiej Zolnierkiewicz { 760b79985caSBartlomiej Zolnierkiewicz return readb(data->base + EXYNOS_TMU_REG_CURRENT_TEMP); 761b79985caSBartlomiej Zolnierkiewicz } 762b79985caSBartlomiej Zolnierkiewicz 7636c247393SAbhilash Kesavan static int exynos7_tmu_read(struct exynos_tmu_data *data) 7646c247393SAbhilash Kesavan { 7656c247393SAbhilash Kesavan return readw(data->base + EXYNOS_TMU_REG_CURRENT_TEMP) & 7666c247393SAbhilash Kesavan EXYNOS7_TMU_TEMP_MASK; 7676c247393SAbhilash Kesavan } 7686c247393SAbhilash Kesavan 76959dfa54cSAmit Daniel Kachhap static void exynos_tmu_work(struct work_struct *work) 77059dfa54cSAmit Daniel Kachhap { 77159dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = container_of(work, 77259dfa54cSAmit Daniel Kachhap struct exynos_tmu_data, irq_work); 773a0395eeeSAmit Daniel Kachhap 774b43e3cfeSBartlomiej Zolnierkiewicz thermal_zone_device_update(data->tzd, THERMAL_EVENT_UNSPECIFIED); 775b43e3cfeSBartlomiej Zolnierkiewicz 77659dfa54cSAmit Daniel Kachhap mutex_lock(&data->lock); 77759dfa54cSAmit Daniel Kachhap clk_enable(data->clk); 778b8d582b9SAmit Daniel Kachhap 779a4463c4fSAmit Daniel Kachhap /* TODO: take action based on particular interrupt */ 780a7331f72SBartlomiej Zolnierkiewicz data->tmu_clear_irqs(data); 781b8d582b9SAmit Daniel Kachhap 78259dfa54cSAmit Daniel Kachhap clk_disable(data->clk); 78359dfa54cSAmit Daniel Kachhap mutex_unlock(&data->lock); 78459dfa54cSAmit Daniel Kachhap enable_irq(data->irq); 78559dfa54cSAmit Daniel Kachhap } 78659dfa54cSAmit Daniel Kachhap 787a7331f72SBartlomiej Zolnierkiewicz static void exynos4210_tmu_clear_irqs(struct exynos_tmu_data *data) 788a7331f72SBartlomiej Zolnierkiewicz { 789a7331f72SBartlomiej Zolnierkiewicz unsigned int val_irq; 790a7331f72SBartlomiej Zolnierkiewicz u32 tmu_intstat, tmu_intclear; 791a7331f72SBartlomiej Zolnierkiewicz 792a7331f72SBartlomiej Zolnierkiewicz if (data->soc == SOC_ARCH_EXYNOS5260) { 793a7331f72SBartlomiej Zolnierkiewicz tmu_intstat = EXYNOS5260_TMU_REG_INTSTAT; 794a7331f72SBartlomiej Zolnierkiewicz tmu_intclear = EXYNOS5260_TMU_REG_INTCLEAR; 7956c247393SAbhilash Kesavan } else if (data->soc == SOC_ARCH_EXYNOS7) { 7966c247393SAbhilash Kesavan tmu_intstat = EXYNOS7_TMU_REG_INTPEND; 7976c247393SAbhilash Kesavan tmu_intclear = EXYNOS7_TMU_REG_INTPEND; 798488c7455SChanwoo Choi } else if (data->soc == SOC_ARCH_EXYNOS5433) { 799488c7455SChanwoo Choi tmu_intstat = EXYNOS5433_TMU_REG_INTPEND; 800488c7455SChanwoo Choi tmu_intclear = EXYNOS5433_TMU_REG_INTPEND; 801a7331f72SBartlomiej Zolnierkiewicz } else { 802a7331f72SBartlomiej Zolnierkiewicz tmu_intstat = EXYNOS_TMU_REG_INTSTAT; 803a7331f72SBartlomiej Zolnierkiewicz tmu_intclear = EXYNOS_TMU_REG_INTCLEAR; 804a7331f72SBartlomiej Zolnierkiewicz } 805a7331f72SBartlomiej Zolnierkiewicz 806a7331f72SBartlomiej Zolnierkiewicz val_irq = readl(data->base + tmu_intstat); 807a7331f72SBartlomiej Zolnierkiewicz /* 808a7331f72SBartlomiej Zolnierkiewicz * Clear the interrupts. Please note that the documentation for 809a7331f72SBartlomiej Zolnierkiewicz * Exynos3250, Exynos4412, Exynos5250 and Exynos5260 incorrectly 810a7331f72SBartlomiej Zolnierkiewicz * states that INTCLEAR register has a different placing of bits 811a7331f72SBartlomiej Zolnierkiewicz * responsible for FALL IRQs than INTSTAT register. Exynos5420 812a7331f72SBartlomiej Zolnierkiewicz * and Exynos5440 documentation is correct (Exynos4210 doesn't 813a7331f72SBartlomiej Zolnierkiewicz * support FALL IRQs at all). 814a7331f72SBartlomiej Zolnierkiewicz */ 815a7331f72SBartlomiej Zolnierkiewicz writel(val_irq, data->base + tmu_intclear); 816a7331f72SBartlomiej Zolnierkiewicz } 817a7331f72SBartlomiej Zolnierkiewicz 81859dfa54cSAmit Daniel Kachhap static irqreturn_t exynos_tmu_irq(int irq, void *id) 81959dfa54cSAmit Daniel Kachhap { 82059dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = id; 82159dfa54cSAmit Daniel Kachhap 82259dfa54cSAmit Daniel Kachhap disable_irq_nosync(irq); 82359dfa54cSAmit Daniel Kachhap schedule_work(&data->irq_work); 82459dfa54cSAmit Daniel Kachhap 82559dfa54cSAmit Daniel Kachhap return IRQ_HANDLED; 82659dfa54cSAmit Daniel Kachhap } 82759dfa54cSAmit Daniel Kachhap 82859dfa54cSAmit Daniel Kachhap static const struct of_device_id exynos_tmu_match[] = { 829fee88e2bSMaciej Purski { 830fee88e2bSMaciej Purski .compatible = "samsung,exynos3250-tmu", 831fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS3250, 832fee88e2bSMaciej Purski }, { 833fee88e2bSMaciej Purski .compatible = "samsung,exynos4210-tmu", 834fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS4210, 835fee88e2bSMaciej Purski }, { 836fee88e2bSMaciej Purski .compatible = "samsung,exynos4412-tmu", 837fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS4412, 838fee88e2bSMaciej Purski }, { 839fee88e2bSMaciej Purski .compatible = "samsung,exynos5250-tmu", 840fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5250, 841fee88e2bSMaciej Purski }, { 842fee88e2bSMaciej Purski .compatible = "samsung,exynos5260-tmu", 843fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5260, 844fee88e2bSMaciej Purski }, { 845fee88e2bSMaciej Purski .compatible = "samsung,exynos5420-tmu", 846fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5420, 847fee88e2bSMaciej Purski }, { 848fee88e2bSMaciej Purski .compatible = "samsung,exynos5420-tmu-ext-triminfo", 849fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5420_TRIMINFO, 850fee88e2bSMaciej Purski }, { 851fee88e2bSMaciej Purski .compatible = "samsung,exynos5433-tmu", 852fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS5433, 853fee88e2bSMaciej Purski }, { 854fee88e2bSMaciej Purski .compatible = "samsung,exynos7-tmu", 855fee88e2bSMaciej Purski .data = (const void *)SOC_ARCH_EXYNOS7, 856fee88e2bSMaciej Purski }, 857fee88e2bSMaciej Purski { }, 85859dfa54cSAmit Daniel Kachhap }; 85959dfa54cSAmit Daniel Kachhap MODULE_DEVICE_TABLE(of, exynos_tmu_match); 86059dfa54cSAmit Daniel Kachhap 861cebe7373SAmit Daniel Kachhap static int exynos_map_dt_data(struct platform_device *pdev) 86259dfa54cSAmit Daniel Kachhap { 863cebe7373SAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 864cebe7373SAmit Daniel Kachhap struct resource res; 86559dfa54cSAmit Daniel Kachhap 86673b5b1d7SSachin Kamat if (!data || !pdev->dev.of_node) 867cebe7373SAmit Daniel Kachhap return -ENODEV; 86859dfa54cSAmit Daniel Kachhap 869cebe7373SAmit Daniel Kachhap data->id = of_alias_get_id(pdev->dev.of_node, "tmuctrl"); 870cebe7373SAmit Daniel Kachhap if (data->id < 0) 871cebe7373SAmit Daniel Kachhap data->id = 0; 872cebe7373SAmit Daniel Kachhap 873cebe7373SAmit Daniel Kachhap data->irq = irq_of_parse_and_map(pdev->dev.of_node, 0); 874cebe7373SAmit Daniel Kachhap if (data->irq <= 0) { 875cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "failed to get IRQ\n"); 876cebe7373SAmit Daniel Kachhap return -ENODEV; 877cebe7373SAmit Daniel Kachhap } 878cebe7373SAmit Daniel Kachhap 879cebe7373SAmit Daniel Kachhap if (of_address_to_resource(pdev->dev.of_node, 0, &res)) { 880cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "failed to get Resource 0\n"); 881cebe7373SAmit Daniel Kachhap return -ENODEV; 882cebe7373SAmit Daniel Kachhap } 883cebe7373SAmit Daniel Kachhap 884cebe7373SAmit Daniel Kachhap data->base = devm_ioremap(&pdev->dev, res.start, resource_size(&res)); 885cebe7373SAmit Daniel Kachhap if (!data->base) { 886cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to ioremap memory\n"); 887cebe7373SAmit Daniel Kachhap return -EADDRNOTAVAIL; 888cebe7373SAmit Daniel Kachhap } 889cebe7373SAmit Daniel Kachhap 8901892f9f0SKrzysztof Kozlowski data->soc = (uintptr_t)of_device_get_match_data(&pdev->dev); 89156adb9efSBartlomiej Zolnierkiewicz 89256adb9efSBartlomiej Zolnierkiewicz switch (data->soc) { 89356adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS4210: 894c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_temp = exynos4210_tmu_set_trip_temp; 895c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_hyst = exynos4210_tmu_set_trip_hyst; 89656adb9efSBartlomiej Zolnierkiewicz data->tmu_initialize = exynos4210_tmu_initialize; 89756adb9efSBartlomiej Zolnierkiewicz data->tmu_control = exynos4210_tmu_control; 89856adb9efSBartlomiej Zolnierkiewicz data->tmu_read = exynos4210_tmu_read; 89956adb9efSBartlomiej Zolnierkiewicz data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; 9003a3a5f15SKrzysztof Kozlowski data->ntrip = 4; 901fccfe099SBartlomiej Zolnierkiewicz data->gain = 15; 90261020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 7; 903e3ed3649SBartlomiej Zolnierkiewicz data->efuse_value = 55; 904e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 40; 905e3ed3649SBartlomiej Zolnierkiewicz data->max_efuse_value = 100; 90656adb9efSBartlomiej Zolnierkiewicz break; 90756adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS3250: 90856adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS4412: 90956adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS5250: 91056adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS5260: 91156adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS5420: 91256adb9efSBartlomiej Zolnierkiewicz case SOC_ARCH_EXYNOS5420_TRIMINFO: 913c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_temp = exynos4412_tmu_set_trip_temp; 914c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_hyst = exynos4412_tmu_set_trip_hyst; 91556adb9efSBartlomiej Zolnierkiewicz data->tmu_initialize = exynos4412_tmu_initialize; 91656adb9efSBartlomiej Zolnierkiewicz data->tmu_control = exynos4210_tmu_control; 91756adb9efSBartlomiej Zolnierkiewicz data->tmu_read = exynos4412_tmu_read; 91856adb9efSBartlomiej Zolnierkiewicz data->tmu_set_emulation = exynos4412_tmu_set_emulation; 91956adb9efSBartlomiej Zolnierkiewicz data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; 9203a3a5f15SKrzysztof Kozlowski data->ntrip = 4; 921fccfe099SBartlomiej Zolnierkiewicz data->gain = 8; 92261020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 16; 923e3ed3649SBartlomiej Zolnierkiewicz data->efuse_value = 55; 924e3ed3649SBartlomiej Zolnierkiewicz if (data->soc != SOC_ARCH_EXYNOS5420 && 925e3ed3649SBartlomiej Zolnierkiewicz data->soc != SOC_ARCH_EXYNOS5420_TRIMINFO) 926e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 40; 927e3ed3649SBartlomiej Zolnierkiewicz else 928e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 0; 929e3ed3649SBartlomiej Zolnierkiewicz data->max_efuse_value = 100; 93056adb9efSBartlomiej Zolnierkiewicz break; 931488c7455SChanwoo Choi case SOC_ARCH_EXYNOS5433: 932c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_temp = exynos5433_tmu_set_trip_temp; 933c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_hyst = exynos5433_tmu_set_trip_hyst; 934488c7455SChanwoo Choi data->tmu_initialize = exynos5433_tmu_initialize; 935488c7455SChanwoo Choi data->tmu_control = exynos5433_tmu_control; 936488c7455SChanwoo Choi data->tmu_read = exynos4412_tmu_read; 937488c7455SChanwoo Choi data->tmu_set_emulation = exynos4412_tmu_set_emulation; 938488c7455SChanwoo Choi data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; 9393a3a5f15SKrzysztof Kozlowski data->ntrip = 8; 940fccfe099SBartlomiej Zolnierkiewicz data->gain = 8; 94161020d18SBartlomiej Zolnierkiewicz if (res.start == EXYNOS5433_G3D_BASE) 94261020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 23; 94361020d18SBartlomiej Zolnierkiewicz else 94461020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 16; 945e3ed3649SBartlomiej Zolnierkiewicz data->efuse_value = 75; 946e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 40; 947e3ed3649SBartlomiej Zolnierkiewicz data->max_efuse_value = 150; 94856adb9efSBartlomiej Zolnierkiewicz break; 9496c247393SAbhilash Kesavan case SOC_ARCH_EXYNOS7: 950c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_temp = exynos7_tmu_set_trip_temp; 951c8f8f768SBartlomiej Zolnierkiewicz data->tmu_set_trip_hyst = exynos7_tmu_set_trip_hyst; 9526c247393SAbhilash Kesavan data->tmu_initialize = exynos7_tmu_initialize; 9536c247393SAbhilash Kesavan data->tmu_control = exynos7_tmu_control; 9546c247393SAbhilash Kesavan data->tmu_read = exynos7_tmu_read; 9556c247393SAbhilash Kesavan data->tmu_set_emulation = exynos4412_tmu_set_emulation; 9566c247393SAbhilash Kesavan data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; 9573a3a5f15SKrzysztof Kozlowski data->ntrip = 8; 958fccfe099SBartlomiej Zolnierkiewicz data->gain = 9; 95961020d18SBartlomiej Zolnierkiewicz data->reference_voltage = 17; 960e3ed3649SBartlomiej Zolnierkiewicz data->efuse_value = 75; 961e3ed3649SBartlomiej Zolnierkiewicz data->min_efuse_value = 15; 962e3ed3649SBartlomiej Zolnierkiewicz data->max_efuse_value = 100; 9636c247393SAbhilash Kesavan break; 96456adb9efSBartlomiej Zolnierkiewicz default: 96556adb9efSBartlomiej Zolnierkiewicz dev_err(&pdev->dev, "Platform not supported\n"); 96656adb9efSBartlomiej Zolnierkiewicz return -EINVAL; 96756adb9efSBartlomiej Zolnierkiewicz } 96856adb9efSBartlomiej Zolnierkiewicz 969199b3e3cSBartlomiej Zolnierkiewicz data->cal_type = TYPE_ONE_POINT_TRIMMING; 970199b3e3cSBartlomiej Zolnierkiewicz 971d9b6ee14SAmit Daniel Kachhap /* 972d9b6ee14SAmit Daniel Kachhap * Check if the TMU shares some registers and then try to map the 973d9b6ee14SAmit Daniel Kachhap * memory of common registers. 974d9b6ee14SAmit Daniel Kachhap */ 9758014220dSKrzysztof Kozlowski if (data->soc != SOC_ARCH_EXYNOS5420_TRIMINFO) 976d9b6ee14SAmit Daniel Kachhap return 0; 977d9b6ee14SAmit Daniel Kachhap 978d9b6ee14SAmit Daniel Kachhap if (of_address_to_resource(pdev->dev.of_node, 1, &res)) { 979d9b6ee14SAmit Daniel Kachhap dev_err(&pdev->dev, "failed to get Resource 1\n"); 980d9b6ee14SAmit Daniel Kachhap return -ENODEV; 981d9b6ee14SAmit Daniel Kachhap } 982d9b6ee14SAmit Daniel Kachhap 9839025d563SNaveen Krishna Chatradhi data->base_second = devm_ioremap(&pdev->dev, res.start, 984d9b6ee14SAmit Daniel Kachhap resource_size(&res)); 9859025d563SNaveen Krishna Chatradhi if (!data->base_second) { 986d9b6ee14SAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to ioremap memory\n"); 987d9b6ee14SAmit Daniel Kachhap return -ENOMEM; 988d9b6ee14SAmit Daniel Kachhap } 989cebe7373SAmit Daniel Kachhap 990cebe7373SAmit Daniel Kachhap return 0; 991cebe7373SAmit Daniel Kachhap } 992cebe7373SAmit Daniel Kachhap 9937ea98f70SDaniel Lezcano static const struct thermal_zone_device_ops exynos_sensor_ops = { 9943b6a1a80SLukasz Majewski .get_temp = exynos_get_temp, 9953b6a1a80SLukasz Majewski .set_emul_temp = exynos_tmu_set_emulation, 9963b6a1a80SLukasz Majewski }; 9973b6a1a80SLukasz Majewski 998cebe7373SAmit Daniel Kachhap static int exynos_tmu_probe(struct platform_device *pdev) 999cebe7373SAmit Daniel Kachhap { 10003b6a1a80SLukasz Majewski struct exynos_tmu_data *data; 10013b6a1a80SLukasz Majewski int ret; 1002cebe7373SAmit Daniel Kachhap 100359dfa54cSAmit Daniel Kachhap data = devm_kzalloc(&pdev->dev, sizeof(struct exynos_tmu_data), 100459dfa54cSAmit Daniel Kachhap GFP_KERNEL); 10052a9675b3SJingoo Han if (!data) 100659dfa54cSAmit Daniel Kachhap return -ENOMEM; 100759dfa54cSAmit Daniel Kachhap 1008cebe7373SAmit Daniel Kachhap platform_set_drvdata(pdev, data); 1009cebe7373SAmit Daniel Kachhap mutex_init(&data->lock); 1010cebe7373SAmit Daniel Kachhap 1011824ead03SKrzysztof Kozlowski /* 1012824ead03SKrzysztof Kozlowski * Try enabling the regulator if found 1013824ead03SKrzysztof Kozlowski * TODO: Add regulator as an SOC feature, so that regulator enable 1014824ead03SKrzysztof Kozlowski * is a compulsory call. 1015824ead03SKrzysztof Kozlowski */ 10164d3583cdSJavier Martinez Canillas data->regulator = devm_regulator_get_optional(&pdev->dev, "vtmu"); 1017824ead03SKrzysztof Kozlowski if (!IS_ERR(data->regulator)) { 1018824ead03SKrzysztof Kozlowski ret = regulator_enable(data->regulator); 1019824ead03SKrzysztof Kozlowski if (ret) { 1020824ead03SKrzysztof Kozlowski dev_err(&pdev->dev, "failed to enable vtmu\n"); 1021824ead03SKrzysztof Kozlowski return ret; 10223b6a1a80SLukasz Majewski } 1023824ead03SKrzysztof Kozlowski } else { 1024ccb361d2SJavier Martinez Canillas if (PTR_ERR(data->regulator) == -EPROBE_DEFER) 1025ccb361d2SJavier Martinez Canillas return -EPROBE_DEFER; 1026824ead03SKrzysztof Kozlowski dev_info(&pdev->dev, "Regulator node (vtmu) not found\n"); 1027824ead03SKrzysztof Kozlowski } 1028824ead03SKrzysztof Kozlowski 1029cebe7373SAmit Daniel Kachhap ret = exynos_map_dt_data(pdev); 1030cebe7373SAmit Daniel Kachhap if (ret) 10313b6a1a80SLukasz Majewski goto err_sensor; 1032cebe7373SAmit Daniel Kachhap 103359dfa54cSAmit Daniel Kachhap INIT_WORK(&data->irq_work, exynos_tmu_work); 103459dfa54cSAmit Daniel Kachhap 103559dfa54cSAmit Daniel Kachhap data->clk = devm_clk_get(&pdev->dev, "tmu_apbif"); 103659dfa54cSAmit Daniel Kachhap if (IS_ERR(data->clk)) { 103759dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to get clock\n"); 10383b6a1a80SLukasz Majewski ret = PTR_ERR(data->clk); 10393b6a1a80SLukasz Majewski goto err_sensor; 104059dfa54cSAmit Daniel Kachhap } 104159dfa54cSAmit Daniel Kachhap 104214a11dc7SNaveen Krishna Chatradhi data->clk_sec = devm_clk_get(&pdev->dev, "tmu_triminfo_apbif"); 104314a11dc7SNaveen Krishna Chatradhi if (IS_ERR(data->clk_sec)) { 104414a11dc7SNaveen Krishna Chatradhi if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO) { 104514a11dc7SNaveen Krishna Chatradhi dev_err(&pdev->dev, "Failed to get triminfo clock\n"); 10463b6a1a80SLukasz Majewski ret = PTR_ERR(data->clk_sec); 10473b6a1a80SLukasz Majewski goto err_sensor; 104814a11dc7SNaveen Krishna Chatradhi } 104914a11dc7SNaveen Krishna Chatradhi } else { 105014a11dc7SNaveen Krishna Chatradhi ret = clk_prepare(data->clk_sec); 105114a11dc7SNaveen Krishna Chatradhi if (ret) { 105214a11dc7SNaveen Krishna Chatradhi dev_err(&pdev->dev, "Failed to get clock\n"); 10533b6a1a80SLukasz Majewski goto err_sensor; 105414a11dc7SNaveen Krishna Chatradhi } 105514a11dc7SNaveen Krishna Chatradhi } 105614a11dc7SNaveen Krishna Chatradhi 105714a11dc7SNaveen Krishna Chatradhi ret = clk_prepare(data->clk); 105814a11dc7SNaveen Krishna Chatradhi if (ret) { 105914a11dc7SNaveen Krishna Chatradhi dev_err(&pdev->dev, "Failed to get clock\n"); 106014a11dc7SNaveen Krishna Chatradhi goto err_clk_sec; 106114a11dc7SNaveen Krishna Chatradhi } 106259dfa54cSAmit Daniel Kachhap 1063488c7455SChanwoo Choi switch (data->soc) { 1064488c7455SChanwoo Choi case SOC_ARCH_EXYNOS5433: 1065488c7455SChanwoo Choi case SOC_ARCH_EXYNOS7: 10666c247393SAbhilash Kesavan data->sclk = devm_clk_get(&pdev->dev, "tmu_sclk"); 10676c247393SAbhilash Kesavan if (IS_ERR(data->sclk)) { 10686c247393SAbhilash Kesavan dev_err(&pdev->dev, "Failed to get sclk\n"); 106902d438f6SDan Carpenter ret = PTR_ERR(data->sclk); 10706c247393SAbhilash Kesavan goto err_clk; 10716c247393SAbhilash Kesavan } else { 10726c247393SAbhilash Kesavan ret = clk_prepare_enable(data->sclk); 10736c247393SAbhilash Kesavan if (ret) { 10746c247393SAbhilash Kesavan dev_err(&pdev->dev, "Failed to enable sclk\n"); 10756c247393SAbhilash Kesavan goto err_clk; 10766c247393SAbhilash Kesavan } 10776c247393SAbhilash Kesavan } 1078488c7455SChanwoo Choi break; 1079488c7455SChanwoo Choi default: 1080488c7455SChanwoo Choi break; 1081baba1ebbSKrzysztof Kozlowski } 10826c247393SAbhilash Kesavan 10839e4249b4SKrzysztof Kozlowski /* 10849e4249b4SKrzysztof Kozlowski * data->tzd must be registered before calling exynos_tmu_initialize(), 10859e4249b4SKrzysztof Kozlowski * requesting irq and calling exynos_tmu_control(). 10869e4249b4SKrzysztof Kozlowski */ 10877ea98f70SDaniel Lezcano data->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, data, 10889e4249b4SKrzysztof Kozlowski &exynos_sensor_ops); 10899e4249b4SKrzysztof Kozlowski if (IS_ERR(data->tzd)) { 10909e4249b4SKrzysztof Kozlowski ret = PTR_ERR(data->tzd); 109182bdde8eSMarek Szyprowski if (ret != -EPROBE_DEFER) 109282bdde8eSMarek Szyprowski dev_err(&pdev->dev, "Failed to register sensor: %d\n", 109382bdde8eSMarek Szyprowski ret); 10949e4249b4SKrzysztof Kozlowski goto err_sclk; 10959e4249b4SKrzysztof Kozlowski } 109659dfa54cSAmit Daniel Kachhap 109759dfa54cSAmit Daniel Kachhap ret = exynos_tmu_initialize(pdev); 109859dfa54cSAmit Daniel Kachhap if (ret) { 109959dfa54cSAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to initialize TMU\n"); 11007ea98f70SDaniel Lezcano goto err_sclk; 110159dfa54cSAmit Daniel Kachhap } 110259dfa54cSAmit Daniel Kachhap 1103cebe7373SAmit Daniel Kachhap ret = devm_request_irq(&pdev->dev, data->irq, exynos_tmu_irq, 1104cebe7373SAmit Daniel Kachhap IRQF_TRIGGER_RISING | IRQF_SHARED, dev_name(&pdev->dev), data); 1105cebe7373SAmit Daniel Kachhap if (ret) { 1106cebe7373SAmit Daniel Kachhap dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq); 11077ea98f70SDaniel Lezcano goto err_sclk; 1108cebe7373SAmit Daniel Kachhap } 110959dfa54cSAmit Daniel Kachhap 11103b6a1a80SLukasz Majewski exynos_tmu_control(pdev, true); 111159dfa54cSAmit Daniel Kachhap return 0; 11129e4249b4SKrzysztof Kozlowski 11136c247393SAbhilash Kesavan err_sclk: 11146c247393SAbhilash Kesavan clk_disable_unprepare(data->sclk); 111559dfa54cSAmit Daniel Kachhap err_clk: 111659dfa54cSAmit Daniel Kachhap clk_unprepare(data->clk); 111714a11dc7SNaveen Krishna Chatradhi err_clk_sec: 111814a11dc7SNaveen Krishna Chatradhi if (!IS_ERR(data->clk_sec)) 111914a11dc7SNaveen Krishna Chatradhi clk_unprepare(data->clk_sec); 11203b6a1a80SLukasz Majewski err_sensor: 1121bfa26838SKrzysztof Kozlowski if (!IS_ERR(data->regulator)) 11225f09a5cbSKrzysztof Kozlowski regulator_disable(data->regulator); 11233b6a1a80SLukasz Majewski 112459dfa54cSAmit Daniel Kachhap return ret; 112559dfa54cSAmit Daniel Kachhap } 112659dfa54cSAmit Daniel Kachhap 1127*0b478d7bSUwe Kleine-König static void exynos_tmu_remove(struct platform_device *pdev) 112859dfa54cSAmit Daniel Kachhap { 112959dfa54cSAmit Daniel Kachhap struct exynos_tmu_data *data = platform_get_drvdata(pdev); 113059dfa54cSAmit Daniel Kachhap 11314215688eSBartlomiej Zolnierkiewicz exynos_tmu_control(pdev, false); 11324215688eSBartlomiej Zolnierkiewicz 11336c247393SAbhilash Kesavan clk_disable_unprepare(data->sclk); 113459dfa54cSAmit Daniel Kachhap clk_unprepare(data->clk); 113514a11dc7SNaveen Krishna Chatradhi if (!IS_ERR(data->clk_sec)) 113614a11dc7SNaveen Krishna Chatradhi clk_unprepare(data->clk_sec); 113759dfa54cSAmit Daniel Kachhap 1138498d22f6SAmit Daniel Kachhap if (!IS_ERR(data->regulator)) 1139498d22f6SAmit Daniel Kachhap regulator_disable(data->regulator); 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, 1174*0b478d7bSUwe Kleine-König .remove_new = 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