Lines Matching full:thermal

19 #include <linux/thermal.h>
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
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
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()
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()
2115 sensor->id, thermal->regs, out_temp); in rockchip_thermal_get_temp()
2117 dev_dbg(&thermal->pdev->dev, "sensor %d - temp: %d, retval: %d\n", 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()
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()
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
2251 thermal->chip->tshut_temp); in rockchip_configure_from_dt()
2252 shut_temp = thermal->chip->tshut_temp; 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()
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()
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()
2291 thermal->tshut_polarity); 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()
2325 sensor->thermal = thermal; 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()
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()
2390 struct rockchip_thermal_data *thermal; in rockchip_thermal_probe() local
2405 thermal = devm_kzalloc(&pdev->dev, sizeof(struct rockchip_thermal_data), in rockchip_thermal_probe()
2407 if (!thermal) 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()
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()
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()
2436 error = clk_bulk_prepare_enable(thermal->num_clks, thermal->clks); 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()
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()
2494 "rockchip_thermal", thermal); 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()
2516 thermal->panic_nb.notifier_call = rockchip_thermal_panic; in rockchip_thermal_probe()
2518 &thermal->panic_nb); 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()
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");