Lines Matching +full:- +full:thermal
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2016, Fuzhou Rockchip Electronics Co., Ltd
4 * Caesar Wang <wxt@rock-chips.com>
19 #include <linux/thermal.h>
22 #include <linux/nvmem-consumer.h>
71 * struct chip_tsadc_table - hold information about chip-specific differences
90 * struct rockchip_tsadc_chip - hold the private data of tsadc chip
95 * @tshut_temp: the hardware-controlled shutdown temperature value
96 * @tshut_mode: the hardware-controlled shutdown mode (0:CRU 1:GPIO)
97 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
103 * @set_tshut_temp: set the hardware-controlled shutdown temperature
104 * @set_tshut_mode: set the hardware-controlled shutdown mode
107 * @table: the chip-specific conversion table
120 /* The hardware-controlled tshut property */
125 /* Chip-wide methods */
131 /* Per-sensor methods */
144 /* Per-table methods */
149 * struct rockchip_thermal_sensor - hold the information of thermal sensor
150 * @thermal: pointer to the platform/configuration data
151 * @tzd: pointer to a thermal zone
152 * @id: identifier of the thermal sensor
153 * @trim_temp: the trim temp of the thermal sensor
154 * @tshut_temp: the hardware-controlled shutdown temperature value
157 struct rockchip_thermal_data *thermal; member
165 * struct rockchip_thermal_data - hold the private data of thermal driver
167 * @pdev: platform device of thermal
169 * @sensors: array of thermal sensors
174 * @tshut_mode: the hardware-controlled shutdown mode (0:CRU 1:GPIO)
175 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
326 /* -40 to 125 is reliable, outside the range existed unreliability */
327 #define MIN_TEMP (-60000)
331 * struct tsadc_table - code to temperature conversion table
348 {396, -40000},
359 {374, -40000},
360 {382, -35000},
361 {389, -30000},
362 {397, -25000},
363 {405, -20000},
364 {413, -15000},
365 {421, -10000},
366 {429, -5000},
400 {3455, -40000},
401 {3463, -35000},
402 {3471, -30000},
403 {3479, -25000},
404 {3487, -20000},
405 {3495, -15000},
406 {3503, -10000},
407 {3511, -5000},
441 {588, -40000},
442 {593, -35000},
443 {598, -30000},
444 {603, -25000},
445 {608, -20000},
446 {613, -15000},
447 {618, -10000},
448 {623, -5000},
482 {3800, -40000},
483 {3792, -35000},
484 {3783, -30000},
485 {3774, -25000},
486 {3765, -20000},
487 {3756, -15000},
488 {3747, -10000},
489 {3737, -5000},
525 {296, -40000},
526 {304, -35000},
527 {313, -30000},
528 {331, -20000},
529 {340, -15000},
530 {349, -10000},
531 {359, -5000},
567 {106, -40000},
568 {108, -35000},
569 {110, -30000},
570 {112, -25000},
571 {114, -20000},
572 {116, -15000},
573 {118, -10000},
574 {120, -5000},
608 {402, -40000},
609 {410, -35000},
610 {419, -30000},
611 {427, -25000},
612 {436, -20000},
613 {444, -15000},
614 {453, -10000},
615 {461, -5000},
649 {1419, -40000},
650 {1427, -35000},
651 {1435, -30000},
652 {1443, -25000},
653 {1452, -20000},
654 {1460, -15000},
655 {1468, -10000},
656 {1477, -5000},
690 {1419, -40000},
691 {1428, -35000},
692 {1436, -30000},
693 {1445, -25000},
694 {1453, -20000},
695 {1462, -15000},
696 {1470, -10000},
697 {1479, -5000},
731 {1584, -40000},
732 {1620, -35000},
733 {1652, -30000},
734 {1688, -25000},
735 {1720, -20000},
736 {1756, -15000},
737 {1788, -10000},
738 {1824, -5000},
772 {215, -40000},
786 u32 error = table->data_mask; in rk_tsadcv2_temp_to_code()
788 if (table->kNum) in rk_tsadcv2_temp_to_code()
789 return (((temp / 1000) * table->kNum) / 1000 + table->bNum); in rk_tsadcv2_temp_to_code()
792 high = (table->length - 1) - 1; /* ignore the last check for table */ in rk_tsadcv2_temp_to_code()
796 if (temp < table->id[low].temp || temp > table->id[high].temp) in rk_tsadcv2_temp_to_code()
800 if (temp == table->id[mid].temp) in rk_tsadcv2_temp_to_code()
801 return table->id[mid].code; in rk_tsadcv2_temp_to_code()
802 else if (temp < table->id[mid].temp) in rk_tsadcv2_temp_to_code()
803 high = mid - 1; in rk_tsadcv2_temp_to_code()
815 num = abs(table->id[mid + 1].code - table->id[mid].code); in rk_tsadcv2_temp_to_code()
816 num *= temp - table->id[mid].temp; in rk_tsadcv2_temp_to_code()
817 denom = table->id[mid + 1].temp - table->id[mid].temp; in rk_tsadcv2_temp_to_code()
819 switch (table->mode) { in rk_tsadcv2_temp_to_code()
821 return table->id[mid].code - (num / denom); in rk_tsadcv2_temp_to_code()
823 return table->id[mid].code + (num / denom); in rk_tsadcv2_temp_to_code()
825 pr_err("%s: unknown table mode: %d\n", __func__, table->mode); in rk_tsadcv2_temp_to_code()
839 unsigned int high = table->length - 1; in rk_tsadcv2_code_to_temp()
844 if (table->kNum) { in rk_tsadcv2_code_to_temp()
845 *temp = (((int)code - table->bNum) * 10000 / table->kNum) * 100; in rk_tsadcv2_code_to_temp()
847 return -EAGAIN; in rk_tsadcv2_code_to_temp()
851 WARN_ON(table->length < 2); in rk_tsadcv2_code_to_temp()
853 switch (table->mode) { in rk_tsadcv2_code_to_temp()
855 code &= table->data_mask; in rk_tsadcv2_code_to_temp()
856 if (code <= table->id[high].code) in rk_tsadcv2_code_to_temp()
857 return -EAGAIN; /* Incorrect reading */ in rk_tsadcv2_code_to_temp()
860 if (code >= table->id[mid].code && in rk_tsadcv2_code_to_temp()
861 code < table->id[mid - 1].code) in rk_tsadcv2_code_to_temp()
863 else if (code < table->id[mid].code) in rk_tsadcv2_code_to_temp()
866 high = mid - 1; in rk_tsadcv2_code_to_temp()
872 code &= table->data_mask; in rk_tsadcv2_code_to_temp()
873 if (code < table->id[low].code) in rk_tsadcv2_code_to_temp()
874 return -EAGAIN; /* Incorrect reading */ in rk_tsadcv2_code_to_temp()
877 if (code <= table->id[mid].code && in rk_tsadcv2_code_to_temp()
878 code > table->id[mid - 1].code) in rk_tsadcv2_code_to_temp()
880 else if (code > table->id[mid].code) in rk_tsadcv2_code_to_temp()
883 high = mid - 1; in rk_tsadcv2_code_to_temp()
889 pr_err("%s: unknown table mode: %d\n", __func__, table->mode); in rk_tsadcv2_code_to_temp()
890 return -EINVAL; in rk_tsadcv2_code_to_temp()
899 num = table->id[mid].temp - table->id[mid - 1].temp; in rk_tsadcv2_code_to_temp()
900 num *= abs(table->id[mid - 1].code - code); in rk_tsadcv2_code_to_temp()
901 denom = abs(table->id[mid - 1].code - table->id[mid].code); in rk_tsadcv2_code_to_temp()
902 *temp = table->id[mid - 1].temp + (num / denom); in rk_tsadcv2_code_to_temp()
908 * rk_tsadcv2_initialize - initialize TASDC Controller.
911 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
945 * rk_tsadcv3_initialize - initialize TASDC Controller.
948 * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
1256 * rk_tsadcv3_control - the tsadc controller is enabled or disabled.
1261 * tsadc_q_sel bit on TSADCV2_AUTO_CON[1]. The (1024 - tsadc_q) as output
1317 * set_trips will pass {-INT_MAX, INT_MAX} to trigger tsadc alarm in rk_tsadcv2_alarm_temp()
1330 if (alarm_value == table->data_mask) in rk_tsadcv2_alarm_temp()
1331 return -ERANGE; in rk_tsadcv2_alarm_temp()
1333 writel_relaxed(alarm_value & table->data_mask, in rk_tsadcv2_alarm_temp()
1350 * set_trips will pass {-INT_MAX, INT_MAX} to trigger tsadc alarm in rk_tsadcv3_alarm_temp()
1361 if (alarm_value == table->data_mask) in rk_tsadcv3_alarm_temp()
1362 return -ERANGE; in rk_tsadcv3_alarm_temp()
1363 writel_relaxed(alarm_value & table->data_mask, in rk_tsadcv3_alarm_temp()
1377 if (tshut_value == table->data_mask) in rk_tsadcv2_tshut_temp()
1378 return -ERANGE; in rk_tsadcv2_tshut_temp()
1396 if (tshut_value == table->data_mask) in rk_tsadcv3_tshut_temp()
1397 return -ERANGE; in rk_tsadcv3_tshut_temp()
1470 u32 base_code = (trim_base * table->kNum + in rk_tsadcv1_get_trim_code()
1471 trim_base_frac * table->kNum / 10) / 1000 + table->bNum; in rk_tsadcv1_get_trim_code()
1473 return code - base_code; in rk_tsadcv1_get_trim_code()
1482 return code - base_code; in rk_tsadcv2_get_trim_code()
1493 return (TSADCV3_Q_MAX_VAL - code) - base_code; in rk_tsadcv3_get_trim_code()
1501 clk = devm_clk_get(&pdev->dev, "tsadc"); in rk_tsadcv1_set_clk_rate()
1504 dev_err(&pdev->dev, "failed to get tsadc clock\n"); in rk_tsadcv1_set_clk_rate()
1509 devm_clk_put(&pdev->dev, clk); in rk_tsadcv1_set_clk_rate()
1510 dev_err(&pdev->dev, in rk_tsadcv1_set_clk_rate()
1514 devm_clk_put(&pdev->dev, clk); in rk_tsadcv1_set_clk_rate()
1960 { .compatible = "rockchip,px30-tsadc",
1963 { .compatible = "rockchip,px30s-tsadc",
1969 .compatible = "rockchip,rv1106-tsadc",
1975 .compatible = "rockchip,rv1108-tsadc",
1981 .compatible = "rockchip,rv1126-tsadc",
1987 .compatible = "rockchip,rk1808-tsadc",
1993 .compatible = "rockchip,rk3228-tsadc",
1999 .compatible = "rockchip,rk3288-tsadc",
2005 .compatible = "rockchip,rk3308-tsadc",
2009 .compatible = "rockchip,rk3308bs-tsadc",
2015 .compatible = "rockchip,rk3328-tsadc",
2021 .compatible = "rockchip,rk3366-tsadc",
2027 .compatible = "rockchip,rk3368-tsadc",
2033 .compatible = "rockchip,rk3399-tsadc",
2039 .compatible = "rockchip,rk3528-tsadc",
2045 .compatible = "rockchip,rk3562-tsadc",
2051 .compatible = "rockchip,rk3568-tsadc",
2057 .compatible = "rockchip,rk3588-tsadc",
2068 struct thermal_zone_device *tzd = sensor->tzd; in rockchip_thermal_toggle_sensor()
2078 struct rockchip_thermal_data *thermal = dev; in rockchip_thermal_alarm_irq_thread() local
2081 dev_dbg(&thermal->pdev->dev, "thermal alarm\n"); in rockchip_thermal_alarm_irq_thread()
2083 thermal->chip->irq_ack(thermal->regs); in rockchip_thermal_alarm_irq_thread()
2085 for (i = 0; i < thermal->chip->chn_num; i++) in rockchip_thermal_alarm_irq_thread()
2086 thermal_zone_device_update(thermal->sensors[i].tzd, in rockchip_thermal_alarm_irq_thread()
2095 struct rockchip_thermal_data *thermal = sensor->thermal; in rockchip_thermal_set_trips() local
2096 const struct rockchip_tsadc_chip *tsadc = thermal->chip; in rockchip_thermal_set_trips()
2098 dev_dbg(&thermal->pdev->dev, "%s: sensor %d: low: %d, high %d\n", in rockchip_thermal_set_trips()
2099 __func__, sensor->id, low, high); in rockchip_thermal_set_trips()
2101 high += sensor->trim_temp; in rockchip_thermal_set_trips()
2103 return tsadc->set_alarm_temp(&tsadc->table, in rockchip_thermal_set_trips()
2104 sensor->id, thermal->regs, high); in rockchip_thermal_set_trips()
2110 struct rockchip_thermal_data *thermal = sensor->thermal; in rockchip_thermal_get_temp() local
2111 const struct rockchip_tsadc_chip *tsadc = sensor->thermal->chip; in rockchip_thermal_get_temp()
2114 retval = tsadc->get_temp(&tsadc->table, in rockchip_thermal_get_temp()
2115 sensor->id, thermal->regs, out_temp); in rockchip_thermal_get_temp()
2116 *out_temp -= sensor->trim_temp; in rockchip_thermal_get_temp()
2117 dev_dbg(&thermal->pdev->dev, "sensor %d - temp: %d, retval: %d\n", in rockchip_thermal_get_temp()
2118 sensor->id, *out_temp, retval); in rockchip_thermal_get_temp()
2128 static void thermal_pinctrl_select_otp(struct rockchip_thermal_data *thermal) in thermal_pinctrl_select_otp() argument
2130 if (!IS_ERR(thermal->pinctrl) && !IS_ERR_OR_NULL(thermal->otp_state)) in thermal_pinctrl_select_otp()
2131 pinctrl_select_state(thermal->pinctrl, in thermal_pinctrl_select_otp()
2132 thermal->otp_state); in thermal_pinctrl_select_otp()
2135 static void thermal_pinctrl_select_gpio(struct rockchip_thermal_data *thermal) in thermal_pinctrl_select_gpio() argument
2137 if (!IS_ERR(thermal->pinctrl) && !IS_ERR_OR_NULL(thermal->gpio_state)) in thermal_pinctrl_select_gpio()
2138 pinctrl_select_state(thermal->pinctrl, in thermal_pinctrl_select_gpio()
2139 thermal->gpio_state); in thermal_pinctrl_select_gpio()
2169 struct rockchip_thermal_data *thermal) in rockchip_get_trim_configure() argument
2171 const struct rockchip_tsadc_chip *tsadc = thermal->chip; in rockchip_get_trim_configure()
2177 if (!tsadc->get_trim_code) in rockchip_get_trim_configure()
2196 trim_code = tsadc->get_trim_code(&tsadc->table, in rockchip_get_trim_configure()
2199 trim_temp = thermal->chip->trim_slope * trim_code; in rockchip_get_trim_configure()
2200 for (i = 0; i < thermal->chip->chn_num; i++) { in rockchip_get_trim_configure()
2201 thermal->sensors[i].trim_temp = trim_temp; in rockchip_get_trim_configure()
2202 thermal->sensors[i].tshut_temp += trim_temp; in rockchip_get_trim_configure()
2203 if (thermal->sensors[i].tshut_temp > MAX_TEMP) in rockchip_get_trim_configure()
2204 thermal->sensors[i].tshut_temp = MAX_TEMP; in rockchip_get_trim_configure()
2226 trim_code = tsadc->get_trim_code(&tsadc->table, in rockchip_get_trim_configure()
2230 trim_temp = thermal->chip->trim_slope * trim_code; in rockchip_get_trim_configure()
2231 thermal->sensors[id].trim_temp = trim_temp; in rockchip_get_trim_configure()
2232 thermal->sensors[id].tshut_temp += trim_temp; in rockchip_get_trim_configure()
2233 if (thermal->sensors[id].tshut_temp > MAX_TEMP) in rockchip_get_trim_configure()
2234 thermal->sensors[id].tshut_temp = MAX_TEMP; in rockchip_get_trim_configure()
2243 struct rockchip_thermal_data *thermal) in rockchip_configure_from_dt() argument
2248 if (of_property_read_u32(np, "rockchip,hw-tshut-temp", &shut_temp)) { in rockchip_configure_from_dt()
2251 thermal->chip->tshut_temp); in rockchip_configure_from_dt()
2252 shut_temp = thermal->chip->tshut_temp; in rockchip_configure_from_dt()
2257 return -ERANGE; in rockchip_configure_from_dt()
2259 for (i = 0; i < thermal->chip->chn_num; i++) in rockchip_configure_from_dt()
2260 thermal->sensors[i].tshut_temp = shut_temp; in rockchip_configure_from_dt()
2262 if (of_property_read_u32(np, "rockchip,hw-tshut-mode", &tshut_mode)) { in rockchip_configure_from_dt()
2265 thermal->chip->tshut_mode == TSHUT_MODE_OTP ? in rockchip_configure_from_dt()
2267 thermal->tshut_mode = thermal->chip->tshut_mode; in rockchip_configure_from_dt()
2269 thermal->tshut_mode = tshut_mode; in rockchip_configure_from_dt()
2272 if (thermal->tshut_mode > 1) { in rockchip_configure_from_dt()
2274 thermal->tshut_mode); in rockchip_configure_from_dt()
2275 return -EINVAL; in rockchip_configure_from_dt()
2278 if (of_property_read_u32(np, "rockchip,hw-tshut-polarity", in rockchip_configure_from_dt()
2281 "Missing tshut-polarity property, using default (%s)\n", in rockchip_configure_from_dt()
2282 thermal->chip->tshut_polarity == TSHUT_LOW_ACTIVE ? in rockchip_configure_from_dt()
2284 thermal->tshut_polarity = thermal->chip->tshut_polarity; in rockchip_configure_from_dt()
2286 thermal->tshut_polarity = tshut_polarity; in rockchip_configure_from_dt()
2289 if (thermal->tshut_polarity > 1) { in rockchip_configure_from_dt()
2290 dev_err(dev, "Invalid tshut-polarity specified: %d\n", in rockchip_configure_from_dt()
2291 thermal->tshut_polarity); in rockchip_configure_from_dt()
2292 return -EINVAL; in rockchip_configure_from_dt()
2298 thermal->grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf"); in rockchip_configure_from_dt()
2299 if (IS_ERR(thermal->grf)) in rockchip_configure_from_dt()
2302 rockchip_get_trim_configure(dev, np, thermal); in rockchip_configure_from_dt()
2309 struct rockchip_thermal_data *thermal, in rockchip_thermal_register_sensor() argument
2313 const struct rockchip_tsadc_chip *tsadc = thermal->chip; in rockchip_thermal_register_sensor()
2316 tsadc->set_tshut_mode(thermal->grf, id, thermal->regs, in rockchip_thermal_register_sensor()
2317 thermal->tshut_mode); in rockchip_thermal_register_sensor()
2319 error = tsadc->set_tshut_temp(&tsadc->table, id, thermal->regs, in rockchip_thermal_register_sensor()
2320 sensor->tshut_temp); in rockchip_thermal_register_sensor()
2322 dev_err(&pdev->dev, "%s: invalid tshut=%d, error=%d\n", in rockchip_thermal_register_sensor()
2323 __func__, sensor->tshut_temp, error); in rockchip_thermal_register_sensor()
2325 sensor->thermal = thermal; in rockchip_thermal_register_sensor()
2326 sensor->id = id; in rockchip_thermal_register_sensor()
2327 sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, id, in rockchip_thermal_register_sensor()
2329 if (IS_ERR(sensor->tzd)) { in rockchip_thermal_register_sensor()
2330 error = PTR_ERR(sensor->tzd); in rockchip_thermal_register_sensor()
2331 dev_err(&pdev->dev, "failed to register sensor %d: %d\n", in rockchip_thermal_register_sensor()
2350 static void rockchip_dump_temperature(struct rockchip_thermal_data *thermal) in rockchip_dump_temperature() argument
2355 if (!thermal) in rockchip_dump_temperature()
2358 pdev = thermal->pdev; in rockchip_dump_temperature()
2360 for (i = 0; i < thermal->chip->chn_num; i++) { in rockchip_dump_temperature()
2361 struct rockchip_thermal_sensor *sensor = &thermal->sensors[i]; in rockchip_dump_temperature()
2362 struct thermal_zone_device *tz = sensor->tzd; in rockchip_dump_temperature()
2364 if (tz->temperature != THERMAL_TEMP_INVALID) in rockchip_dump_temperature()
2365 dev_warn(&pdev->dev, "channal %d: temperature(%d C)\n", in rockchip_dump_temperature()
2366 i, tz->temperature / 1000); in rockchip_dump_temperature()
2369 if (thermal->regs) { in rockchip_dump_temperature()
2370 pr_warn("THERMAL REGS:\n"); in rockchip_dump_temperature()
2372 32, 4, thermal->regs, 0x88, false); in rockchip_dump_temperature()
2379 struct rockchip_thermal_data *thermal; in rockchip_thermal_panic() local
2381 thermal = container_of(this, struct rockchip_thermal_data, panic_nb); in rockchip_thermal_panic()
2382 rockchip_dump_temperature(thermal); in rockchip_thermal_panic()
2389 struct device_node *np = pdev->dev.of_node; in rockchip_thermal_probe()
2390 struct rockchip_thermal_data *thermal; in rockchip_thermal_probe() local
2399 return -ENXIO; in rockchip_thermal_probe()
2403 return -EINVAL; in rockchip_thermal_probe()
2405 thermal = devm_kzalloc(&pdev->dev, sizeof(struct rockchip_thermal_data), in rockchip_thermal_probe()
2407 if (!thermal) in rockchip_thermal_probe()
2408 return -ENOMEM; in rockchip_thermal_probe()
2410 thermal->pdev = pdev; in rockchip_thermal_probe()
2412 thermal->chip = (const struct rockchip_tsadc_chip *)match->data; in rockchip_thermal_probe()
2413 if (!thermal->chip) in rockchip_thermal_probe()
2414 return -EINVAL; in rockchip_thermal_probe()
2416 thermal->chip = &px30s_tsadc_data; in rockchip_thermal_probe()
2418 thermal->chip = &rk3308bs_tsadc_data; in rockchip_thermal_probe()
2421 thermal->regs = devm_ioremap_resource(&pdev->dev, res); in rockchip_thermal_probe()
2422 if (IS_ERR(thermal->regs)) in rockchip_thermal_probe()
2423 return PTR_ERR(thermal->regs); in rockchip_thermal_probe()
2425 thermal->reset = devm_reset_control_array_get(&pdev->dev, false, false); in rockchip_thermal_probe()
2426 if (IS_ERR(thermal->reset)) { in rockchip_thermal_probe()
2427 if (PTR_ERR(thermal->reset) != -EPROBE_DEFER) in rockchip_thermal_probe()
2428 dev_err(&pdev->dev, "failed to get tsadc reset lines\n"); in rockchip_thermal_probe()
2429 return PTR_ERR(thermal->reset); in rockchip_thermal_probe()
2432 thermal->num_clks = devm_clk_bulk_get_all(&pdev->dev, &thermal->clks); in rockchip_thermal_probe()
2433 if (thermal->num_clks < 1) in rockchip_thermal_probe()
2434 return -ENODEV; in rockchip_thermal_probe()
2436 error = clk_bulk_prepare_enable(thermal->num_clks, thermal->clks); in rockchip_thermal_probe()
2438 dev_err(&pdev->dev, "failed to prepare enable tsadc bulk clks: %d\n", in rockchip_thermal_probe()
2442 platform_set_drvdata(pdev, thermal); in rockchip_thermal_probe()
2444 if (thermal->chip->set_clk_rate) in rockchip_thermal_probe()
2445 thermal->chip->set_clk_rate(pdev); in rockchip_thermal_probe()
2447 thermal->chip->control(thermal->regs, false); in rockchip_thermal_probe()
2449 rockchip_thermal_reset_controller(thermal->reset); in rockchip_thermal_probe()
2451 error = rockchip_configure_from_dt(&pdev->dev, np, thermal); in rockchip_thermal_probe()
2453 dev_err(&pdev->dev, "failed to parse device tree data: %d\n", in rockchip_thermal_probe()
2458 thermal->chip->initialize(thermal->grf, thermal->regs, in rockchip_thermal_probe()
2459 thermal->tshut_polarity); in rockchip_thermal_probe()
2461 if (thermal->tshut_mode == TSHUT_MODE_OTP) { in rockchip_thermal_probe()
2462 thermal->pinctrl = devm_pinctrl_get(&pdev->dev); in rockchip_thermal_probe()
2463 if (IS_ERR(thermal->pinctrl)) in rockchip_thermal_probe()
2464 dev_err(&pdev->dev, "failed to find thermal pinctrl\n"); in rockchip_thermal_probe()
2466 thermal->gpio_state = pinctrl_lookup_state(thermal->pinctrl, in rockchip_thermal_probe()
2468 if (IS_ERR_OR_NULL(thermal->gpio_state)) in rockchip_thermal_probe()
2469 dev_err(&pdev->dev, "failed to find thermal gpio state\n"); in rockchip_thermal_probe()
2471 thermal->otp_state = pinctrl_lookup_state(thermal->pinctrl, in rockchip_thermal_probe()
2473 if (IS_ERR_OR_NULL(thermal->otp_state)) in rockchip_thermal_probe()
2474 dev_err(&pdev->dev, "failed to find thermal otpout state\n"); in rockchip_thermal_probe()
2476 thermal_pinctrl_select_otp(thermal); in rockchip_thermal_probe()
2479 for (i = 0; i < thermal->chip->chn_num; i++) { in rockchip_thermal_probe()
2480 error = rockchip_thermal_register_sensor(pdev, thermal, in rockchip_thermal_probe()
2481 &thermal->sensors[i], in rockchip_thermal_probe()
2482 thermal->chip->chn_id[i]); in rockchip_thermal_probe()
2484 dev_err(&pdev->dev, in rockchip_thermal_probe()
2491 error = devm_request_threaded_irq(&pdev->dev, irq, NULL, in rockchip_thermal_probe()
2494 "rockchip_thermal", thermal); in rockchip_thermal_probe()
2496 dev_err(&pdev->dev, in rockchip_thermal_probe()
2501 thermal->chip->control(thermal->regs, true); in rockchip_thermal_probe()
2502 if (thermal->chip->conversion_time) in rockchip_thermal_probe()
2503 usleep_range(thermal->chip->conversion_time, in rockchip_thermal_probe()
2504 thermal->chip->conversion_time + 50); in rockchip_thermal_probe()
2506 for (i = 0; i < thermal->chip->chn_num; i++) { in rockchip_thermal_probe()
2507 rockchip_thermal_toggle_sensor(&thermal->sensors[i], true); in rockchip_thermal_probe()
2508 thermal->sensors[i].tzd->tzp->no_hwmon = false; in rockchip_thermal_probe()
2509 error = thermal_add_hwmon_sysfs(thermal->sensors[i].tzd); in rockchip_thermal_probe()
2511 dev_warn(&pdev->dev, in rockchip_thermal_probe()
2516 thermal->panic_nb.notifier_call = rockchip_thermal_panic; in rockchip_thermal_probe()
2518 &thermal->panic_nb); in rockchip_thermal_probe()
2520 dev_info(&pdev->dev, "tsadc is probed successfully!\n"); in rockchip_thermal_probe()
2525 clk_bulk_disable_unprepare(thermal->num_clks, thermal->clks); in rockchip_thermal_probe()
2532 struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev); in rockchip_thermal_remove() local
2535 for (i = 0; i < thermal->chip->chn_num; i++) { in rockchip_thermal_remove()
2536 struct rockchip_thermal_sensor *sensor = &thermal->sensors[i]; in rockchip_thermal_remove()
2538 thermal_remove_hwmon_sysfs(sensor->tzd); in rockchip_thermal_remove()
2542 thermal->chip->control(thermal->regs, false); in rockchip_thermal_remove()
2544 clk_bulk_disable_unprepare(thermal->num_clks, thermal->clks); in rockchip_thermal_remove()
2551 struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev); in rockchip_thermal_shutdown() local
2554 for (i = 0; i < thermal->chip->chn_num; i++) { in rockchip_thermal_shutdown()
2555 int id = thermal->sensors[i].id; in rockchip_thermal_shutdown()
2557 if (thermal->tshut_mode != TSHUT_MODE_CRU) in rockchip_thermal_shutdown()
2558 thermal->chip->set_tshut_mode(thermal->grf, id, in rockchip_thermal_shutdown()
2559 thermal->regs, in rockchip_thermal_shutdown()
2562 if (thermal->tshut_mode == TSHUT_MODE_OTP) in rockchip_thermal_shutdown()
2563 thermal_pinctrl_select_gpio(thermal); in rockchip_thermal_shutdown()
2568 struct rockchip_thermal_data *thermal = dev_get_drvdata(dev); in rockchip_thermal_suspend() local
2571 for (i = 0; i < thermal->chip->chn_num; i++) in rockchip_thermal_suspend()
2572 rockchip_thermal_toggle_sensor(&thermal->sensors[i], false); in rockchip_thermal_suspend()
2574 thermal->chip->control(thermal->regs, false); in rockchip_thermal_suspend()
2576 clk_bulk_disable(thermal->num_clks, thermal->clks); in rockchip_thermal_suspend()
2578 if (thermal->tshut_mode == TSHUT_MODE_OTP) in rockchip_thermal_suspend()
2579 thermal_pinctrl_select_gpio(thermal); in rockchip_thermal_suspend()
2586 struct rockchip_thermal_data *thermal = dev_get_drvdata(dev); in rockchip_thermal_resume() local
2590 error = clk_bulk_enable(thermal->num_clks, thermal->clks); in rockchip_thermal_resume()
2597 rockchip_thermal_reset_controller(thermal->reset); in rockchip_thermal_resume()
2599 thermal->chip->initialize(thermal->grf, thermal->regs, in rockchip_thermal_resume()
2600 thermal->tshut_polarity); in rockchip_thermal_resume()
2602 for (i = 0; i < thermal->chip->chn_num; i++) { in rockchip_thermal_resume()
2603 int id = thermal->sensors[i].id; in rockchip_thermal_resume()
2604 int tshut_temp = thermal->sensors[i].tshut_temp; in rockchip_thermal_resume()
2606 thermal->chip->set_tshut_mode(thermal->grf, id, thermal->regs, in rockchip_thermal_resume()
2607 thermal->tshut_mode); in rockchip_thermal_resume()
2609 error = thermal->chip->set_tshut_temp(&thermal->chip->table, in rockchip_thermal_resume()
2610 id, thermal->regs, in rockchip_thermal_resume()
2617 thermal->chip->control(thermal->regs, true); in rockchip_thermal_resume()
2618 if (thermal->chip->conversion_time) in rockchip_thermal_resume()
2619 usleep_range(thermal->chip->conversion_time, in rockchip_thermal_resume()
2620 thermal->chip->conversion_time + 50); in rockchip_thermal_resume()
2622 for (i = 0; i < thermal->chip->chn_num; i++) in rockchip_thermal_resume()
2623 rockchip_thermal_toggle_sensor(&thermal->sensors[i], true); in rockchip_thermal_resume()
2625 if (thermal->tshut_mode == TSHUT_MODE_OTP) in rockchip_thermal_resume()
2626 thermal_pinctrl_select_otp(thermal); in rockchip_thermal_resume()
2636 .name = "rockchip-thermal",
2657 MODULE_DESCRIPTION("ROCKCHIP THERMAL Driver");
2660 MODULE_ALIAS("platform:rockchip-thermal");