2 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
4 * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd
5 * Caesar Wang <wxt@rock-chips.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 #include <linux/clk.h>
18 #include <linux/delay.h>
19 #include <linux/interrupt.h>
21 #include <linux/module.h>
23 #include <linux/of_address.h>
24 #include <linux/of_irq.h>
25 #include <linux/platform_device.h>
26 #include <linux/reset.h>
27 #include <linux/thermal.h>
28 #include <linux/pinctrl/consumer.h>
31 * If the temperature over a period of time High,
32 * the resulting TSHUT gave CRU module,let it reset the entire chip,
33 * or via GPIO give PMIC.
41 * The system Temperature Sensors tshut(tshut) polarity
42 * the bit 8 is tshut polarity.
43 * 0: low active, 1: high active
51 * The system has two Temperature Sensors.
52 * sensor0 is for CPU, and sensor1 is for GPU.
60 * The conversion table has the adc value and temperature.
61 * ADC_DECREMENT: the adc value is of diminishing.(e.g. rk3288_code_table)
62 * ADC_INCREMENT: the adc value is incremental.(e.g. rk3368_code_table)
70 * The max sensors is two in rockchip SoCs.
71 * Two sensors: CPU and GPU sensor.
73 #define SOC_MAX_SENSORS 2
76 * struct chip_tsadc_table: hold information about chip-specific differences
77 * @id: conversion table
78 * @length: size of conversion table
79 * @data_mask: mask to apply on data inputs
80 * @mode: sort mode of this adc variant (incrementing or decrementing)
82 struct chip_tsadc_table {
83 const struct tsadc_table *id;
86 enum adc_sort_mode mode;
89 struct rockchip_tsadc_chip {
90 /* The sensor id of chip correspond to the ADC channel */
91 int chn_id[SOC_MAX_SENSORS];
94 /* The hardware-controlled tshut property */
96 enum tshut_mode tshut_mode;
97 enum tshut_polarity tshut_polarity;
99 /* Chip-wide methods */
100 void (*initialize)(void __iomem *reg, enum tshut_polarity p);
101 void (*irq_ack)(void __iomem *reg);
102 void (*control)(void __iomem *reg, bool on);
104 /* Per-sensor methods */
105 int (*get_temp)(struct chip_tsadc_table table,
106 int chn, void __iomem *reg, int *temp);
107 void (*set_tshut_temp)(struct chip_tsadc_table table,
108 int chn, void __iomem *reg, int temp);
109 void (*set_tshut_mode)(int chn, void __iomem *reg, enum tshut_mode m);
111 /* Per-table methods */
112 struct chip_tsadc_table table;
115 struct rockchip_thermal_sensor {
116 struct rockchip_thermal_data *thermal;
117 struct thermal_zone_device *tzd;
121 struct rockchip_thermal_data {
122 const struct rockchip_tsadc_chip *chip;
123 struct platform_device *pdev;
124 struct reset_control *reset;
126 struct rockchip_thermal_sensor sensors[SOC_MAX_SENSORS];
134 enum tshut_mode tshut_mode;
135 enum tshut_polarity tshut_polarity;
139 * TSADC Sensor Register description:
141 * TSADCV2_* are used for RK3288 SoCs, the other chips can reuse it.
142 * TSADCV3_* are used for newer SoCs than RK3288. (e.g: RK3228, RK3399)
145 #define TSADCV2_AUTO_CON 0x04
146 #define TSADCV2_INT_EN 0x08
147 #define TSADCV2_INT_PD 0x0c
148 #define TSADCV2_DATA(chn) (0x20 + (chn) * 0x04)
149 #define TSADCV2_COMP_SHUT(chn) (0x40 + (chn) * 0x04)
150 #define TSADCV2_HIGHT_INT_DEBOUNCE 0x60
151 #define TSADCV2_HIGHT_TSHUT_DEBOUNCE 0x64
152 #define TSADCV2_AUTO_PERIOD 0x68
153 #define TSADCV2_AUTO_PERIOD_HT 0x6c
155 #define TSADCV2_AUTO_EN BIT(0)
156 #define TSADCV2_AUTO_SRC_EN(chn) BIT(4 + (chn))
157 #define TSADCV2_AUTO_TSHUT_POLARITY_HIGH BIT(8)
159 #define TSADCV2_INT_SRC_EN(chn) BIT(chn)
160 #define TSADCV2_SHUT_2GPIO_SRC_EN(chn) BIT(4 + (chn))
161 #define TSADCV2_SHUT_2CRU_SRC_EN(chn) BIT(8 + (chn))
163 #define TSADCV2_INT_PD_CLEAR_MASK ~BIT(8)
164 #define TSADCV3_INT_PD_CLEAR_MASK ~BIT(16)
166 #define TSADCV2_DATA_MASK 0xfff
167 #define TSADCV3_DATA_MASK 0x3ff
169 #define TSADCV2_HIGHT_INT_DEBOUNCE_COUNT 4
170 #define TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT 4
171 #define TSADCV2_AUTO_PERIOD_TIME 250 /* msec */
172 #define TSADCV2_AUTO_PERIOD_HT_TIME 50 /* msec */
181 * Code to Temperature mapping of the Temperature sensor is a piece wise linear
182 * curve.Any temperature, code faling between to 2 give temperatures can be
183 * linearly interpolated.
184 * Code to Temperature mapping should be updated based on sillcon results.
186 static const struct tsadc_table rk3228_code_table[] = {
187 {TSADCV3_DATA_MASK, -40000},
224 static const struct tsadc_table rk3288_code_table[] = {
225 {TSADCV2_DATA_MASK, -40000},
262 static const struct tsadc_table rk3368_code_table[] = {
298 {TSADCV3_DATA_MASK, 125000},
301 static const struct tsadc_table rk3399_code_table[] = {
302 {TSADCV3_DATA_MASK, -40000},
339 static u32 rk_tsadcv2_temp_to_code(struct chip_tsadc_table table,
345 high = table.length - 1;
346 mid = (high + low) / 2;
348 if (temp < table.id[low].temp || temp > table.id[high].temp)
351 while (low <= high) {
352 if (temp == table.id[mid].temp)
353 return table.id[mid].code;
354 else if (temp < table.id[mid].temp)
358 mid = (low + high) / 2;
364 static int rk_tsadcv2_code_to_temp(struct chip_tsadc_table table, u32 code,
367 unsigned int low = 1;
368 unsigned int high = table.length - 1;
369 unsigned int mid = (low + high) / 2;
373 WARN_ON(table.length < 2);
375 switch (table.mode) {
377 code &= table.data_mask;
378 if (code < table.id[high].code)
379 return -EAGAIN; /* Incorrect reading */
381 while (low <= high) {
382 if (code >= table.id[mid].code &&
383 code < table.id[mid - 1].code)
385 else if (code < table.id[mid].code)
390 mid = (low + high) / 2;
394 code &= table.data_mask;
395 if (code < table.id[low].code)
396 return -EAGAIN; /* Incorrect reading */
398 while (low <= high) {
399 if (code >= table.id[mid - 1].code &&
400 code < table.id[mid].code)
402 else if (code > table.id[mid].code)
407 mid = (low + high) / 2;
411 pr_err("Invalid the conversion table\n");
415 * The 5C granularity provided by the table is too much. Let's
416 * assume that the relationship between sensor readings and
417 * temperature between 2 table entries is linear and interpolate
418 * to produce less granular result.
420 num = table.id[mid].temp - table.id[mid - 1].temp;
421 num *= abs(table.id[mid - 1].code - code);
422 denom = abs(table.id[mid - 1].code - table.id[mid].code);
423 *temp = table.id[mid - 1].temp + (num / denom);
429 * rk_tsadcv2_initialize - initialize TASDC Controller.
431 * (1) Set TSADC_V2_AUTO_PERIOD:
432 * Configure the interleave between every two accessing of
433 * TSADC in normal operation.
435 * (2) Set TSADCV2_AUTO_PERIOD_HT:
436 * Configure the interleave between every two accessing of
437 * TSADC after the temperature is higher than COM_SHUT or COM_INT.
439 * (3) Set TSADCV2_HIGH_INT_DEBOUNCE and TSADC_HIGHT_TSHUT_DEBOUNCE:
440 * If the temperature is higher than COMP_INT or COMP_SHUT for
441 * "debounce" times, TSADC controller will generate interrupt or TSHUT.
443 static void rk_tsadcv2_initialize(void __iomem *regs,
444 enum tshut_polarity tshut_polarity)
446 if (tshut_polarity == TSHUT_HIGH_ACTIVE)
447 writel_relaxed(0U | TSADCV2_AUTO_TSHUT_POLARITY_HIGH,
448 regs + TSADCV2_AUTO_CON);
450 writel_relaxed(0U & ~TSADCV2_AUTO_TSHUT_POLARITY_HIGH,
451 regs + TSADCV2_AUTO_CON);
453 writel_relaxed(TSADCV2_AUTO_PERIOD_TIME, regs + TSADCV2_AUTO_PERIOD);
454 writel_relaxed(TSADCV2_HIGHT_INT_DEBOUNCE_COUNT,
455 regs + TSADCV2_HIGHT_INT_DEBOUNCE);
456 writel_relaxed(TSADCV2_AUTO_PERIOD_HT_TIME,
457 regs + TSADCV2_AUTO_PERIOD_HT);
458 writel_relaxed(TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT,
459 regs + TSADCV2_HIGHT_TSHUT_DEBOUNCE);
462 static void rk_tsadcv2_irq_ack(void __iomem *regs)
466 val = readl_relaxed(regs + TSADCV2_INT_PD);
467 writel_relaxed(val & TSADCV2_INT_PD_CLEAR_MASK, regs + TSADCV2_INT_PD);
470 static void rk_tsadcv3_irq_ack(void __iomem *regs)
474 val = readl_relaxed(regs + TSADCV2_INT_PD);
475 writel_relaxed(val & TSADCV3_INT_PD_CLEAR_MASK, regs + TSADCV2_INT_PD);
478 static void rk_tsadcv2_control(void __iomem *regs, bool enable)
482 val = readl_relaxed(regs + TSADCV2_AUTO_CON);
484 val |= TSADCV2_AUTO_EN;
486 val &= ~TSADCV2_AUTO_EN;
488 writel_relaxed(val, regs + TSADCV2_AUTO_CON);
491 static int rk_tsadcv2_get_temp(struct chip_tsadc_table table,
492 int chn, void __iomem *regs, int *temp)
496 val = readl_relaxed(regs + TSADCV2_DATA(chn));
498 return rk_tsadcv2_code_to_temp(table, val, temp);
501 static void rk_tsadcv2_tshut_temp(struct chip_tsadc_table table,
502 int chn, void __iomem *regs, int temp)
504 u32 tshut_value, val;
506 tshut_value = rk_tsadcv2_temp_to_code(table, temp);
507 writel_relaxed(tshut_value, regs + TSADCV2_COMP_SHUT(chn));
509 /* TSHUT will be valid */
510 val = readl_relaxed(regs + TSADCV2_AUTO_CON);
511 writel_relaxed(val | TSADCV2_AUTO_SRC_EN(chn), regs + TSADCV2_AUTO_CON);
514 static void rk_tsadcv2_tshut_mode(int chn, void __iomem *regs,
515 enum tshut_mode mode)
519 val = readl_relaxed(regs + TSADCV2_INT_EN);
520 if (mode == TSHUT_MODE_GPIO) {
521 val &= ~TSADCV2_SHUT_2CRU_SRC_EN(chn);
522 val |= TSADCV2_SHUT_2GPIO_SRC_EN(chn);
524 val &= ~TSADCV2_SHUT_2GPIO_SRC_EN(chn);
525 val |= TSADCV2_SHUT_2CRU_SRC_EN(chn);
528 writel_relaxed(val, regs + TSADCV2_INT_EN);
531 static const struct rockchip_tsadc_chip rk3228_tsadc_data = {
532 .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */
533 .chn_num = 1, /* one channel for tsadc */
535 .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
536 .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
539 .initialize = rk_tsadcv2_initialize,
540 .irq_ack = rk_tsadcv3_irq_ack,
541 .control = rk_tsadcv2_control,
542 .get_temp = rk_tsadcv2_get_temp,
543 .set_tshut_temp = rk_tsadcv2_tshut_temp,
544 .set_tshut_mode = rk_tsadcv2_tshut_mode,
547 .id = rk3228_code_table,
548 .length = ARRAY_SIZE(rk3228_code_table),
549 .data_mask = TSADCV3_DATA_MASK,
550 .mode = ADC_DECREMENT,
554 static const struct rockchip_tsadc_chip rk3288_tsadc_data = {
555 .chn_id[SENSOR_CPU] = 1, /* cpu sensor is channel 1 */
556 .chn_id[SENSOR_GPU] = 2, /* gpu sensor is channel 2 */
557 .chn_num = 2, /* two channels for tsadc */
559 .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
560 .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
563 .initialize = rk_tsadcv2_initialize,
564 .irq_ack = rk_tsadcv2_irq_ack,
565 .control = rk_tsadcv2_control,
566 .get_temp = rk_tsadcv2_get_temp,
567 .set_tshut_temp = rk_tsadcv2_tshut_temp,
568 .set_tshut_mode = rk_tsadcv2_tshut_mode,
571 .id = rk3288_code_table,
572 .length = ARRAY_SIZE(rk3288_code_table),
573 .data_mask = TSADCV2_DATA_MASK,
574 .mode = ADC_DECREMENT,
578 static const struct rockchip_tsadc_chip rk3368_tsadc_data = {
579 .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */
580 .chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */
581 .chn_num = 2, /* two channels for tsadc */
583 .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
584 .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
587 .initialize = rk_tsadcv2_initialize,
588 .irq_ack = rk_tsadcv2_irq_ack,
589 .control = rk_tsadcv2_control,
590 .get_temp = rk_tsadcv2_get_temp,
591 .set_tshut_temp = rk_tsadcv2_tshut_temp,
592 .set_tshut_mode = rk_tsadcv2_tshut_mode,
595 .id = rk3368_code_table,
596 .length = ARRAY_SIZE(rk3368_code_table),
597 .data_mask = TSADCV3_DATA_MASK,
598 .mode = ADC_INCREMENT,
602 static const struct rockchip_tsadc_chip rk3399_tsadc_data = {
603 .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */
604 .chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */
605 .chn_num = 2, /* two channels for tsadc */
607 .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
608 .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
611 .initialize = rk_tsadcv2_initialize,
612 .irq_ack = rk_tsadcv3_irq_ack,
613 .control = rk_tsadcv2_control,
614 .get_temp = rk_tsadcv2_get_temp,
615 .set_tshut_temp = rk_tsadcv2_tshut_temp,
616 .set_tshut_mode = rk_tsadcv2_tshut_mode,
619 .id = rk3399_code_table,
620 .length = ARRAY_SIZE(rk3399_code_table),
621 .data_mask = TSADCV3_DATA_MASK,
622 .mode = ADC_DECREMENT,
626 static const struct of_device_id of_rockchip_thermal_match[] = {
628 .compatible = "rockchip,rk3228-tsadc",
629 .data = (void *)&rk3228_tsadc_data,
632 .compatible = "rockchip,rk3288-tsadc",
633 .data = (void *)&rk3288_tsadc_data,
636 .compatible = "rockchip,rk3368-tsadc",
637 .data = (void *)&rk3368_tsadc_data,
640 .compatible = "rockchip,rk3399-tsadc",
641 .data = (void *)&rk3399_tsadc_data,
645 MODULE_DEVICE_TABLE(of, of_rockchip_thermal_match);
648 rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on)
650 struct thermal_zone_device *tzd = sensor->tzd;
652 tzd->ops->set_mode(tzd,
653 on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
656 static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev)
658 struct rockchip_thermal_data *thermal = dev;
661 dev_dbg(&thermal->pdev->dev, "thermal alarm\n");
663 thermal->chip->irq_ack(thermal->regs);
665 for (i = 0; i < thermal->chip->chn_num; i++)
666 thermal_zone_device_update(thermal->sensors[i].tzd);
671 static int rockchip_thermal_get_temp(void *_sensor, int *out_temp)
673 struct rockchip_thermal_sensor *sensor = _sensor;
674 struct rockchip_thermal_data *thermal = sensor->thermal;
675 const struct rockchip_tsadc_chip *tsadc = sensor->thermal->chip;
678 retval = tsadc->get_temp(tsadc->table,
679 sensor->id, thermal->regs, out_temp);
680 dev_dbg(&thermal->pdev->dev, "sensor %d - temp: %d, retval: %d\n",
681 sensor->id, *out_temp, retval);
686 static const struct thermal_zone_of_device_ops rockchip_of_thermal_ops = {
687 .get_temp = rockchip_thermal_get_temp,
690 static int rockchip_configure_from_dt(struct device *dev,
691 struct device_node *np,
692 struct rockchip_thermal_data *thermal)
694 u32 shut_temp, tshut_mode, tshut_polarity;
696 if (of_property_read_u32(np, "rockchip,hw-tshut-temp", &shut_temp)) {
698 "Missing tshut temp property, using default %d\n",
699 thermal->chip->tshut_temp);
700 thermal->tshut_temp = thermal->chip->tshut_temp;
702 if (shut_temp > INT_MAX) {
703 dev_err(dev, "Invalid tshut temperature specified: %d\n",
707 thermal->tshut_temp = shut_temp;
710 if (of_property_read_u32(np, "rockchip,hw-tshut-mode", &tshut_mode)) {
712 "Missing tshut mode property, using default (%s)\n",
713 thermal->chip->tshut_mode == TSHUT_MODE_GPIO ?
715 thermal->tshut_mode = thermal->chip->tshut_mode;
717 thermal->tshut_mode = tshut_mode;
720 if (thermal->tshut_mode > 1) {
721 dev_err(dev, "Invalid tshut mode specified: %d\n",
722 thermal->tshut_mode);
726 if (of_property_read_u32(np, "rockchip,hw-tshut-polarity",
729 "Missing tshut-polarity property, using default (%s)\n",
730 thermal->chip->tshut_polarity == TSHUT_LOW_ACTIVE ?
732 thermal->tshut_polarity = thermal->chip->tshut_polarity;
734 thermal->tshut_polarity = tshut_polarity;
737 if (thermal->tshut_polarity > 1) {
738 dev_err(dev, "Invalid tshut-polarity specified: %d\n",
739 thermal->tshut_polarity);
747 rockchip_thermal_register_sensor(struct platform_device *pdev,
748 struct rockchip_thermal_data *thermal,
749 struct rockchip_thermal_sensor *sensor,
752 const struct rockchip_tsadc_chip *tsadc = thermal->chip;
755 tsadc->set_tshut_mode(id, thermal->regs, thermal->tshut_mode);
756 tsadc->set_tshut_temp(tsadc->table, id, thermal->regs,
757 thermal->tshut_temp);
759 sensor->thermal = thermal;
761 sensor->tzd = thermal_zone_of_sensor_register(&pdev->dev, id, sensor,
762 &rockchip_of_thermal_ops);
763 if (IS_ERR(sensor->tzd)) {
764 error = PTR_ERR(sensor->tzd);
765 dev_err(&pdev->dev, "failed to register sensor %d: %d\n",
774 * Reset TSADC Controller, reset all tsadc registers.
776 static void rockchip_thermal_reset_controller(struct reset_control *reset)
778 reset_control_assert(reset);
779 usleep_range(10, 20);
780 reset_control_deassert(reset);
783 static int rockchip_thermal_probe(struct platform_device *pdev)
785 struct device_node *np = pdev->dev.of_node;
786 struct rockchip_thermal_data *thermal;
787 const struct of_device_id *match;
788 struct resource *res;
793 match = of_match_node(of_rockchip_thermal_match, np);
797 irq = platform_get_irq(pdev, 0);
799 dev_err(&pdev->dev, "no irq resource?\n");
803 thermal = devm_kzalloc(&pdev->dev, sizeof(struct rockchip_thermal_data),
808 thermal->pdev = pdev;
810 thermal->chip = (const struct rockchip_tsadc_chip *)match->data;
814 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
815 thermal->regs = devm_ioremap_resource(&pdev->dev, res);
816 if (IS_ERR(thermal->regs))
817 return PTR_ERR(thermal->regs);
819 thermal->reset = devm_reset_control_get(&pdev->dev, "tsadc-apb");
820 if (IS_ERR(thermal->reset)) {
821 error = PTR_ERR(thermal->reset);
822 dev_err(&pdev->dev, "failed to get tsadc reset: %d\n", error);
826 thermal->clk = devm_clk_get(&pdev->dev, "tsadc");
827 if (IS_ERR(thermal->clk)) {
828 error = PTR_ERR(thermal->clk);
829 dev_err(&pdev->dev, "failed to get tsadc clock: %d\n", error);
833 thermal->pclk = devm_clk_get(&pdev->dev, "apb_pclk");
834 if (IS_ERR(thermal->pclk)) {
835 error = PTR_ERR(thermal->pclk);
836 dev_err(&pdev->dev, "failed to get apb_pclk clock: %d\n",
841 error = clk_prepare_enable(thermal->clk);
843 dev_err(&pdev->dev, "failed to enable converter clock: %d\n",
848 error = clk_prepare_enable(thermal->pclk);
850 dev_err(&pdev->dev, "failed to enable pclk: %d\n", error);
851 goto err_disable_clk;
854 rockchip_thermal_reset_controller(thermal->reset);
856 error = rockchip_configure_from_dt(&pdev->dev, np, thermal);
858 dev_err(&pdev->dev, "failed to parse device tree data: %d\n",
860 goto err_disable_pclk;
863 thermal->chip->initialize(thermal->regs, thermal->tshut_polarity);
865 for (i = 0; i < thermal->chip->chn_num; i++) {
866 error = rockchip_thermal_register_sensor(pdev, thermal,
867 &thermal->sensors[i],
868 thermal->chip->chn_id[i]);
871 "failed to register sensor[%d] : error = %d\n",
873 for (j = 0; j < i; j++)
874 thermal_zone_of_sensor_unregister(&pdev->dev,
875 thermal->sensors[j].tzd);
876 goto err_disable_pclk;
880 error = devm_request_threaded_irq(&pdev->dev, irq, NULL,
881 &rockchip_thermal_alarm_irq_thread,
883 "rockchip_thermal", thermal);
886 "failed to request tsadc irq: %d\n", error);
887 goto err_unregister_sensor;
890 thermal->chip->control(thermal->regs, true);
892 for (i = 0; i < thermal->chip->chn_num; i++)
893 rockchip_thermal_toggle_sensor(&thermal->sensors[i], true);
895 platform_set_drvdata(pdev, thermal);
899 err_unregister_sensor:
901 thermal_zone_of_sensor_unregister(&pdev->dev,
902 thermal->sensors[i].tzd);
905 clk_disable_unprepare(thermal->pclk);
907 clk_disable_unprepare(thermal->clk);
912 static int rockchip_thermal_remove(struct platform_device *pdev)
914 struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev);
917 for (i = 0; i < thermal->chip->chn_num; i++) {
918 struct rockchip_thermal_sensor *sensor = &thermal->sensors[i];
920 rockchip_thermal_toggle_sensor(sensor, false);
921 thermal_zone_of_sensor_unregister(&pdev->dev, sensor->tzd);
924 thermal->chip->control(thermal->regs, false);
926 clk_disable_unprepare(thermal->pclk);
927 clk_disable_unprepare(thermal->clk);
932 static int __maybe_unused rockchip_thermal_suspend(struct device *dev)
934 struct platform_device *pdev = to_platform_device(dev);
935 struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev);
938 for (i = 0; i < thermal->chip->chn_num; i++)
939 rockchip_thermal_toggle_sensor(&thermal->sensors[i], false);
941 thermal->chip->control(thermal->regs, false);
943 clk_disable(thermal->pclk);
944 clk_disable(thermal->clk);
946 pinctrl_pm_select_sleep_state(dev);
951 static int __maybe_unused rockchip_thermal_resume(struct device *dev)
953 struct platform_device *pdev = to_platform_device(dev);
954 struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev);
958 error = clk_enable(thermal->clk);
962 error = clk_enable(thermal->pclk);
966 rockchip_thermal_reset_controller(thermal->reset);
968 thermal->chip->initialize(thermal->regs, thermal->tshut_polarity);
970 for (i = 0; i < thermal->chip->chn_num; i++) {
971 int id = thermal->sensors[i].id;
973 thermal->chip->set_tshut_mode(id, thermal->regs,
974 thermal->tshut_mode);
975 thermal->chip->set_tshut_temp(thermal->chip->table,
977 thermal->tshut_temp);
980 thermal->chip->control(thermal->regs, true);
982 for (i = 0; i < thermal->chip->chn_num; i++)
983 rockchip_thermal_toggle_sensor(&thermal->sensors[i], true);
985 pinctrl_pm_select_default_state(dev);
990 static SIMPLE_DEV_PM_OPS(rockchip_thermal_pm_ops,
991 rockchip_thermal_suspend, rockchip_thermal_resume);
993 static struct platform_driver rockchip_thermal_driver = {
995 .name = "rockchip-thermal",
996 .pm = &rockchip_thermal_pm_ops,
997 .of_match_table = of_rockchip_thermal_match,
999 .probe = rockchip_thermal_probe,
1000 .remove = rockchip_thermal_remove,
1003 module_platform_driver(rockchip_thermal_driver);
1005 MODULE_DESCRIPTION("ROCKCHIP THERMAL Driver");
1006 MODULE_AUTHOR("Rockchip, Inc.");
1007 MODULE_LICENSE("GPL v2");
1008 MODULE_ALIAS("platform:rockchip-thermal");