mtk_thermal.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. * Author: Hanyi Wu <hanyi.wu@mediatek.com>
  4. * Sascha Hauer <s.hauer@pengutronix.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/clk.h>
  16. #include <linux/delay.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/nvmem-consumer.h>
  21. #include <linux/of.h>
  22. #include <linux/of_address.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/slab.h>
  25. #include <linux/io.h>
  26. #include <linux/thermal.h>
  27. #include <linux/reset.h>
  28. #include <linux/types.h>
  29. #include <linux/nvmem-consumer.h>
  30. /* AUXADC Registers */
  31. #define AUXADC_CON0_V 0x000
  32. #define AUXADC_CON1_V 0x004
  33. #define AUXADC_CON1_SET_V 0x008
  34. #define AUXADC_CON1_CLR_V 0x00c
  35. #define AUXADC_CON2_V 0x010
  36. #define AUXADC_DATA(channel) (0x14 + (channel) * 4)
  37. #define AUXADC_MISC_V 0x094
  38. #define AUXADC_CON1_CHANNEL(x) BIT(x)
  39. #define APMIXED_SYS_TS_CON1 0x604
  40. /* Thermal Controller Registers */
  41. #define TEMP_MONCTL0 0x000
  42. #define TEMP_MONCTL1 0x004
  43. #define TEMP_MONCTL2 0x008
  44. #define TEMP_MONIDET0 0x014
  45. #define TEMP_MONIDET1 0x018
  46. #define TEMP_MSRCTL0 0x038
  47. #define TEMP_AHBPOLL 0x040
  48. #define TEMP_AHBTO 0x044
  49. #define TEMP_ADCPNP0 0x048
  50. #define TEMP_ADCPNP1 0x04c
  51. #define TEMP_ADCPNP2 0x050
  52. #define TEMP_ADCPNP3 0x0b4
  53. #define TEMP_ADCMUX 0x054
  54. #define TEMP_ADCEN 0x060
  55. #define TEMP_PNPMUXADDR 0x064
  56. #define TEMP_ADCMUXADDR 0x068
  57. #define TEMP_ADCENADDR 0x074
  58. #define TEMP_ADCVALIDADDR 0x078
  59. #define TEMP_ADCVOLTADDR 0x07c
  60. #define TEMP_RDCTRL 0x080
  61. #define TEMP_ADCVALIDMASK 0x084
  62. #define TEMP_ADCVOLTAGESHIFT 0x088
  63. #define TEMP_ADCWRITECTRL 0x08c
  64. #define TEMP_MSR0 0x090
  65. #define TEMP_MSR1 0x094
  66. #define TEMP_MSR2 0x098
  67. #define TEMP_MSR3 0x0B8
  68. #define TEMP_SPARE0 0x0f0
  69. #define PTPCORESEL 0x400
  70. #define TEMP_MONCTL1_PERIOD_UNIT(x) ((x) & 0x3ff)
  71. #define TEMP_MONCTL2_FILTER_INTERVAL(x) (((x) & 0x3ff) << 16)
  72. #define TEMP_MONCTL2_SENSOR_INTERVAL(x) ((x) & 0x3ff)
  73. #define TEMP_AHBPOLL_ADC_POLL_INTERVAL(x) (x)
  74. #define TEMP_ADCWRITECTRL_ADC_PNP_WRITE BIT(0)
  75. #define TEMP_ADCWRITECTRL_ADC_MUX_WRITE BIT(1)
  76. #define TEMP_ADCVALIDMASK_VALID_HIGH BIT(5)
  77. #define TEMP_ADCVALIDMASK_VALID_POS(bit) (bit)
  78. #define MT8173_TS1 0
  79. #define MT8173_TS2 1
  80. #define MT8173_TS3 2
  81. #define MT8173_TS4 3
  82. #define MT8173_TSABB 4
  83. /* AUXADC channel 11 is used for the temperature sensors */
  84. #define MT8173_TEMP_AUXADC_CHANNEL 11
  85. /* The total number of temperature sensors in the MT8173 */
  86. #define MT8173_NUM_SENSORS 5
  87. /* The number of banks in the MT8173 */
  88. #define MT8173_NUM_ZONES 4
  89. /* The number of sensing points per bank */
  90. #define MT8173_NUM_SENSORS_PER_ZONE 4
  91. /* Layout of the fuses providing the calibration data */
  92. #define MT8173_CALIB_BUF0_VALID BIT(0)
  93. #define MT8173_CALIB_BUF1_ADC_GE(x) (((x) >> 22) & 0x3ff)
  94. #define MT8173_CALIB_BUF0_VTS_TS1(x) (((x) >> 17) & 0x1ff)
  95. #define MT8173_CALIB_BUF0_VTS_TS2(x) (((x) >> 8) & 0x1ff)
  96. #define MT8173_CALIB_BUF1_VTS_TS3(x) (((x) >> 0) & 0x1ff)
  97. #define MT8173_CALIB_BUF2_VTS_TS4(x) (((x) >> 23) & 0x1ff)
  98. #define MT8173_CALIB_BUF2_VTS_TSABB(x) (((x) >> 14) & 0x1ff)
  99. #define MT8173_CALIB_BUF0_DEGC_CALI(x) (((x) >> 1) & 0x3f)
  100. #define MT8173_CALIB_BUF0_O_SLOPE(x) (((x) >> 26) & 0x3f)
  101. #define THERMAL_NAME "mtk-thermal"
  102. struct mtk_thermal;
  103. struct mtk_thermal_bank {
  104. struct mtk_thermal *mt;
  105. int id;
  106. };
  107. struct mtk_thermal {
  108. struct device *dev;
  109. void __iomem *thermal_base;
  110. struct clk *clk_peri_therm;
  111. struct clk *clk_auxadc;
  112. struct mtk_thermal_bank banks[MT8173_NUM_ZONES];
  113. /* lock: for getting and putting banks */
  114. struct mutex lock;
  115. /* Calibration values */
  116. s32 adc_ge;
  117. s32 degc_cali;
  118. s32 o_slope;
  119. s32 vts[MT8173_NUM_SENSORS];
  120. struct thermal_zone_device *tzd;
  121. };
  122. struct mtk_thermal_bank_cfg {
  123. unsigned int num_sensors;
  124. unsigned int sensors[MT8173_NUM_SENSORS_PER_ZONE];
  125. };
  126. static const int sensor_mux_values[MT8173_NUM_SENSORS] = { 0, 1, 2, 3, 16 };
  127. /*
  128. * The MT8173 thermal controller has four banks. Each bank can read up to
  129. * four temperature sensors simultaneously. The MT8173 has a total of 5
  130. * temperature sensors. We use each bank to measure a certain area of the
  131. * SoC. Since TS2 is located centrally in the SoC it is influenced by multiple
  132. * areas, hence is used in different banks.
  133. *
  134. * The thermal core only gets the maximum temperature of all banks, so
  135. * the bank concept wouldn't be necessary here. However, the SVS (Smart
  136. * Voltage Scaling) unit makes its decisions based on the same bank
  137. * data, and this indeed needs the temperatures of the individual banks
  138. * for making better decisions.
  139. */
  140. static const struct mtk_thermal_bank_cfg bank_data[] = {
  141. {
  142. .num_sensors = 2,
  143. .sensors = { MT8173_TS2, MT8173_TS3 },
  144. }, {
  145. .num_sensors = 2,
  146. .sensors = { MT8173_TS2, MT8173_TS4 },
  147. }, {
  148. .num_sensors = 3,
  149. .sensors = { MT8173_TS1, MT8173_TS2, MT8173_TSABB },
  150. }, {
  151. .num_sensors = 1,
  152. .sensors = { MT8173_TS2 },
  153. },
  154. };
  155. struct mtk_thermal_sense_point {
  156. int msr;
  157. int adcpnp;
  158. };
  159. static const struct mtk_thermal_sense_point
  160. sensing_points[MT8173_NUM_SENSORS_PER_ZONE] = {
  161. {
  162. .msr = TEMP_MSR0,
  163. .adcpnp = TEMP_ADCPNP0,
  164. }, {
  165. .msr = TEMP_MSR1,
  166. .adcpnp = TEMP_ADCPNP1,
  167. }, {
  168. .msr = TEMP_MSR2,
  169. .adcpnp = TEMP_ADCPNP2,
  170. }, {
  171. .msr = TEMP_MSR3,
  172. .adcpnp = TEMP_ADCPNP3,
  173. },
  174. };
  175. /**
  176. * raw_to_mcelsius - convert a raw ADC value to mcelsius
  177. * @mt: The thermal controller
  178. * @raw: raw ADC value
  179. *
  180. * This converts the raw ADC value to mcelsius using the SoC specific
  181. * calibration constants
  182. */
  183. static int raw_to_mcelsius(struct mtk_thermal *mt, int sensno, s32 raw)
  184. {
  185. s32 tmp;
  186. raw &= 0xfff;
  187. tmp = 203450520 << 3;
  188. tmp /= 165 + mt->o_slope;
  189. tmp /= 10000 + mt->adc_ge;
  190. tmp *= raw - mt->vts[sensno] - 3350;
  191. tmp >>= 3;
  192. return mt->degc_cali * 500 - tmp;
  193. }
  194. /**
  195. * mtk_thermal_get_bank - get bank
  196. * @bank: The bank
  197. *
  198. * The bank registers are banked, we have to select a bank in the
  199. * PTPCORESEL register to access it.
  200. */
  201. static void mtk_thermal_get_bank(struct mtk_thermal_bank *bank)
  202. {
  203. struct mtk_thermal *mt = bank->mt;
  204. u32 val;
  205. mutex_lock(&mt->lock);
  206. val = readl(mt->thermal_base + PTPCORESEL);
  207. val &= ~0xf;
  208. val |= bank->id;
  209. writel(val, mt->thermal_base + PTPCORESEL);
  210. }
  211. /**
  212. * mtk_thermal_put_bank - release bank
  213. * @bank: The bank
  214. *
  215. * release a bank previously taken with mtk_thermal_get_bank,
  216. */
  217. static void mtk_thermal_put_bank(struct mtk_thermal_bank *bank)
  218. {
  219. struct mtk_thermal *mt = bank->mt;
  220. mutex_unlock(&mt->lock);
  221. }
  222. /**
  223. * mtk_thermal_bank_temperature - get the temperature of a bank
  224. * @bank: The bank
  225. *
  226. * The temperature of a bank is considered the maximum temperature of
  227. * the sensors associated to the bank.
  228. */
  229. static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
  230. {
  231. struct mtk_thermal *mt = bank->mt;
  232. int i, temp = INT_MIN, max = INT_MIN;
  233. u32 raw;
  234. for (i = 0; i < bank_data[bank->id].num_sensors; i++) {
  235. raw = readl(mt->thermal_base + sensing_points[i].msr);
  236. temp = raw_to_mcelsius(mt, bank_data[bank->id].sensors[i], raw);
  237. /*
  238. * The first read of a sensor often contains very high bogus
  239. * temperature value. Filter these out so that the system does
  240. * not immediately shut down.
  241. */
  242. if (temp > 200000)
  243. temp = 0;
  244. if (temp > max)
  245. max = temp;
  246. }
  247. return max;
  248. }
  249. static int mtk_read_temp(void *data, int *temperature)
  250. {
  251. struct mtk_thermal *mt = data;
  252. int i;
  253. int tempmax = INT_MIN;
  254. for (i = 0; i < MT8173_NUM_ZONES; i++) {
  255. struct mtk_thermal_bank *bank = &mt->banks[i];
  256. mtk_thermal_get_bank(bank);
  257. tempmax = max(tempmax, mtk_thermal_bank_temperature(bank));
  258. mtk_thermal_put_bank(bank);
  259. }
  260. *temperature = tempmax;
  261. return 0;
  262. }
  263. static const struct thermal_zone_of_device_ops mtk_thermal_ops = {
  264. .get_temp = mtk_read_temp,
  265. };
  266. static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
  267. u32 apmixed_phys_base, u32 auxadc_phys_base)
  268. {
  269. struct mtk_thermal_bank *bank = &mt->banks[num];
  270. const struct mtk_thermal_bank_cfg *cfg = &bank_data[num];
  271. int i;
  272. bank->id = num;
  273. bank->mt = mt;
  274. mtk_thermal_get_bank(bank);
  275. /* bus clock 66M counting unit is 12 * 15.15ns * 256 = 46.540us */
  276. writel(TEMP_MONCTL1_PERIOD_UNIT(12), mt->thermal_base + TEMP_MONCTL1);
  277. /*
  278. * filt interval is 1 * 46.540us = 46.54us,
  279. * sen interval is 429 * 46.540us = 19.96ms
  280. */
  281. writel(TEMP_MONCTL2_FILTER_INTERVAL(1) |
  282. TEMP_MONCTL2_SENSOR_INTERVAL(429),
  283. mt->thermal_base + TEMP_MONCTL2);
  284. /* poll is set to 10u */
  285. writel(TEMP_AHBPOLL_ADC_POLL_INTERVAL(768),
  286. mt->thermal_base + TEMP_AHBPOLL);
  287. /* temperature sampling control, 1 sample */
  288. writel(0x0, mt->thermal_base + TEMP_MSRCTL0);
  289. /* exceed this polling time, IRQ would be inserted */
  290. writel(0xffffffff, mt->thermal_base + TEMP_AHBTO);
  291. /* number of interrupts per event, 1 is enough */
  292. writel(0x0, mt->thermal_base + TEMP_MONIDET0);
  293. writel(0x0, mt->thermal_base + TEMP_MONIDET1);
  294. /*
  295. * The MT8173 thermal controller does not have its own ADC. Instead it
  296. * uses AHB bus accesses to control the AUXADC. To do this the thermal
  297. * controller has to be programmed with the physical addresses of the
  298. * AUXADC registers and with the various bit positions in the AUXADC.
  299. * Also the thermal controller controls a mux in the APMIXEDSYS register
  300. * space.
  301. */
  302. /*
  303. * this value will be stored to TEMP_PNPMUXADDR (TEMP_SPARE0)
  304. * automatically by hw
  305. */
  306. writel(BIT(MT8173_TEMP_AUXADC_CHANNEL), mt->thermal_base + TEMP_ADCMUX);
  307. /* AHB address for auxadc mux selection */
  308. writel(auxadc_phys_base + AUXADC_CON1_CLR_V,
  309. mt->thermal_base + TEMP_ADCMUXADDR);
  310. /* AHB address for pnp sensor mux selection */
  311. writel(apmixed_phys_base + APMIXED_SYS_TS_CON1,
  312. mt->thermal_base + TEMP_PNPMUXADDR);
  313. /* AHB value for auxadc enable */
  314. writel(BIT(MT8173_TEMP_AUXADC_CHANNEL), mt->thermal_base + TEMP_ADCEN);
  315. /* AHB address for auxadc enable (channel 0 immediate mode selected) */
  316. writel(auxadc_phys_base + AUXADC_CON1_SET_V,
  317. mt->thermal_base + TEMP_ADCENADDR);
  318. /* AHB address for auxadc valid bit */
  319. writel(auxadc_phys_base + AUXADC_DATA(MT8173_TEMP_AUXADC_CHANNEL),
  320. mt->thermal_base + TEMP_ADCVALIDADDR);
  321. /* AHB address for auxadc voltage output */
  322. writel(auxadc_phys_base + AUXADC_DATA(MT8173_TEMP_AUXADC_CHANNEL),
  323. mt->thermal_base + TEMP_ADCVOLTADDR);
  324. /* read valid & voltage are at the same register */
  325. writel(0x0, mt->thermal_base + TEMP_RDCTRL);
  326. /* indicate where the valid bit is */
  327. writel(TEMP_ADCVALIDMASK_VALID_HIGH | TEMP_ADCVALIDMASK_VALID_POS(12),
  328. mt->thermal_base + TEMP_ADCVALIDMASK);
  329. /* no shift */
  330. writel(0x0, mt->thermal_base + TEMP_ADCVOLTAGESHIFT);
  331. /* enable auxadc mux write transaction */
  332. writel(TEMP_ADCWRITECTRL_ADC_MUX_WRITE,
  333. mt->thermal_base + TEMP_ADCWRITECTRL);
  334. for (i = 0; i < cfg->num_sensors; i++)
  335. writel(sensor_mux_values[cfg->sensors[i]],
  336. mt->thermal_base + sensing_points[i].adcpnp);
  337. writel((1 << cfg->num_sensors) - 1, mt->thermal_base + TEMP_MONCTL0);
  338. writel(TEMP_ADCWRITECTRL_ADC_PNP_WRITE |
  339. TEMP_ADCWRITECTRL_ADC_MUX_WRITE,
  340. mt->thermal_base + TEMP_ADCWRITECTRL);
  341. mtk_thermal_put_bank(bank);
  342. }
  343. static u64 of_get_phys_base(struct device_node *np)
  344. {
  345. u64 size64;
  346. const __be32 *regaddr_p;
  347. regaddr_p = of_get_address(np, 0, &size64, NULL);
  348. if (!regaddr_p)
  349. return OF_BAD_ADDR;
  350. return of_translate_address(np, regaddr_p);
  351. }
  352. static int mtk_thermal_get_calibration_data(struct device *dev,
  353. struct mtk_thermal *mt)
  354. {
  355. struct nvmem_cell *cell;
  356. u32 *buf;
  357. size_t len;
  358. int i, ret = 0;
  359. /* Start with default values */
  360. mt->adc_ge = 512;
  361. for (i = 0; i < MT8173_NUM_SENSORS; i++)
  362. mt->vts[i] = 260;
  363. mt->degc_cali = 40;
  364. mt->o_slope = 0;
  365. cell = nvmem_cell_get(dev, "calibration-data");
  366. if (IS_ERR(cell)) {
  367. if (PTR_ERR(cell) == -EPROBE_DEFER)
  368. return PTR_ERR(cell);
  369. return 0;
  370. }
  371. buf = (u32 *)nvmem_cell_read(cell, &len);
  372. nvmem_cell_put(cell);
  373. if (IS_ERR(buf))
  374. return PTR_ERR(buf);
  375. if (len < 3 * sizeof(u32)) {
  376. dev_warn(dev, "invalid calibration data\n");
  377. ret = -EINVAL;
  378. goto out;
  379. }
  380. if (buf[0] & MT8173_CALIB_BUF0_VALID) {
  381. mt->adc_ge = MT8173_CALIB_BUF1_ADC_GE(buf[1]);
  382. mt->vts[MT8173_TS1] = MT8173_CALIB_BUF0_VTS_TS1(buf[0]);
  383. mt->vts[MT8173_TS2] = MT8173_CALIB_BUF0_VTS_TS2(buf[0]);
  384. mt->vts[MT8173_TS3] = MT8173_CALIB_BUF1_VTS_TS3(buf[1]);
  385. mt->vts[MT8173_TS4] = MT8173_CALIB_BUF2_VTS_TS4(buf[2]);
  386. mt->vts[MT8173_TSABB] = MT8173_CALIB_BUF2_VTS_TSABB(buf[2]);
  387. mt->degc_cali = MT8173_CALIB_BUF0_DEGC_CALI(buf[0]);
  388. mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
  389. } else {
  390. dev_info(dev, "Device not calibrated, using default calibration values\n");
  391. }
  392. out:
  393. kfree(buf);
  394. return ret;
  395. }
  396. static int mtk_thermal_probe(struct platform_device *pdev)
  397. {
  398. int ret, i;
  399. struct device_node *auxadc, *apmixedsys, *np = pdev->dev.of_node;
  400. struct mtk_thermal *mt;
  401. struct resource *res;
  402. u64 auxadc_phys_base, apmixed_phys_base;
  403. mt = devm_kzalloc(&pdev->dev, sizeof(*mt), GFP_KERNEL);
  404. if (!mt)
  405. return -ENOMEM;
  406. mt->clk_peri_therm = devm_clk_get(&pdev->dev, "therm");
  407. if (IS_ERR(mt->clk_peri_therm))
  408. return PTR_ERR(mt->clk_peri_therm);
  409. mt->clk_auxadc = devm_clk_get(&pdev->dev, "auxadc");
  410. if (IS_ERR(mt->clk_auxadc))
  411. return PTR_ERR(mt->clk_auxadc);
  412. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  413. mt->thermal_base = devm_ioremap_resource(&pdev->dev, res);
  414. if (IS_ERR(mt->thermal_base))
  415. return PTR_ERR(mt->thermal_base);
  416. ret = mtk_thermal_get_calibration_data(&pdev->dev, mt);
  417. if (ret)
  418. return ret;
  419. mutex_init(&mt->lock);
  420. mt->dev = &pdev->dev;
  421. auxadc = of_parse_phandle(np, "mediatek,auxadc", 0);
  422. if (!auxadc) {
  423. dev_err(&pdev->dev, "missing auxadc node\n");
  424. return -ENODEV;
  425. }
  426. auxadc_phys_base = of_get_phys_base(auxadc);
  427. of_node_put(auxadc);
  428. if (auxadc_phys_base == OF_BAD_ADDR) {
  429. dev_err(&pdev->dev, "Can't get auxadc phys address\n");
  430. return -EINVAL;
  431. }
  432. apmixedsys = of_parse_phandle(np, "mediatek,apmixedsys", 0);
  433. if (!apmixedsys) {
  434. dev_err(&pdev->dev, "missing apmixedsys node\n");
  435. return -ENODEV;
  436. }
  437. apmixed_phys_base = of_get_phys_base(apmixedsys);
  438. of_node_put(apmixedsys);
  439. if (apmixed_phys_base == OF_BAD_ADDR) {
  440. dev_err(&pdev->dev, "Can't get auxadc phys address\n");
  441. return -EINVAL;
  442. }
  443. ret = clk_prepare_enable(mt->clk_auxadc);
  444. if (ret) {
  445. dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret);
  446. return ret;
  447. }
  448. ret = device_reset(&pdev->dev);
  449. if (ret)
  450. goto err_disable_clk_auxadc;
  451. ret = clk_prepare_enable(mt->clk_peri_therm);
  452. if (ret) {
  453. dev_err(&pdev->dev, "Can't enable peri clk: %d\n", ret);
  454. goto err_disable_clk_auxadc;
  455. }
  456. for (i = 0; i < MT8173_NUM_ZONES; i++)
  457. mtk_thermal_init_bank(mt, i, apmixed_phys_base,
  458. auxadc_phys_base);
  459. platform_set_drvdata(pdev, mt);
  460. mt->tzd = thermal_zone_of_sensor_register(&pdev->dev, 0, mt,
  461. &mtk_thermal_ops);
  462. if (IS_ERR(mt->tzd))
  463. goto err_register;
  464. return 0;
  465. err_register:
  466. clk_disable_unprepare(mt->clk_peri_therm);
  467. err_disable_clk_auxadc:
  468. clk_disable_unprepare(mt->clk_auxadc);
  469. return ret;
  470. }
  471. static int mtk_thermal_remove(struct platform_device *pdev)
  472. {
  473. struct mtk_thermal *mt = platform_get_drvdata(pdev);
  474. thermal_zone_of_sensor_unregister(&pdev->dev, mt->tzd);
  475. clk_disable_unprepare(mt->clk_peri_therm);
  476. clk_disable_unprepare(mt->clk_auxadc);
  477. return 0;
  478. }
  479. static const struct of_device_id mtk_thermal_of_match[] = {
  480. {
  481. .compatible = "mediatek,mt8173-thermal",
  482. }, {
  483. },
  484. };
  485. static struct platform_driver mtk_thermal_driver = {
  486. .probe = mtk_thermal_probe,
  487. .remove = mtk_thermal_remove,
  488. .driver = {
  489. .name = THERMAL_NAME,
  490. .of_match_table = mtk_thermal_of_match,
  491. },
  492. };
  493. module_platform_driver(mtk_thermal_driver);
  494. MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de");
  495. MODULE_AUTHOR("Hanyi Wu <hanyi.wu@mediatek.com>");
  496. MODULE_DESCRIPTION("Mediatek thermal driver");
  497. MODULE_LICENSE("GPL v2");