diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index f8c45bb3b998..d85a9994f426 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -163,8 +163,8 @@ struct rockchip_thermal_data { struct rockchip_thermal_sensor sensors[SOC_MAX_SENSORS]; - struct clk *clk; - struct clk *pclk; + struct clk_bulk_data *clks; + int num_clks; struct regmap *grf; void __iomem *regs; @@ -308,6 +308,45 @@ static const struct tsadc_table rv1108_table[] = { {TSADCV2_DATA_MASK, 125000}, }; +static const struct tsadc_table rv1126_code_table[] = { + {0, -40000}, + {2623, -40000}, + {2635, -35000}, + {2646, -30000}, + {2657, -25000}, + {2669, -20000}, + {2680, -15000}, + {2691, -10000}, + {2703, -5000}, + {2714, 0}, + {2725, 5000}, + {2737, 10000}, + {2748, 15000}, + {2759, 20000}, + {2770, 25000}, + {2782, 30000}, + {2793, 35000}, + {2804, 40000}, + {2816, 45000}, + {2827, 50000}, + {2838, 55000}, + {2850, 60000}, + {2861, 65000}, + {2872, 70000}, + {2884, 75000}, + {2895, 80000}, + {2906, 85000}, + {2918, 90000}, + {2929, 95000}, + {2940, 100000}, + {2952, 105000}, + {2963, 110000}, + {2974, 115000}, + {2985, 120000}, + {2997, 125000}, + {TSADCV2_DATA_MASK, 125000}, +}; + static const struct tsadc_table rk1808_code_table[] = { {0, -40000}, {3455, -40000}, @@ -1026,6 +1065,30 @@ static const struct rockchip_tsadc_chip rv1108_tsadc_data = { }, }; +static const struct rockchip_tsadc_chip rv1126_tsadc_data = { + .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */ + .chn_num = 1, /* one channel for tsadc */ + + .tshut_mode = TSHUT_MODE_CRU, /* default TSHUT via CRU */ + .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */ + .tshut_temp = 95000, + + .initialize = rk_tsadcv2_initialize, + .irq_ack = rk_tsadcv3_irq_ack, + .control = rk_tsadcv3_control, + .get_temp = rk_tsadcv2_get_temp, + .set_alarm_temp = rk_tsadcv2_alarm_temp, + .set_tshut_temp = rk_tsadcv2_tshut_temp, + .set_tshut_mode = rk_tsadcv2_tshut_mode, + + .table = { + .id = rv1126_code_table, + .length = ARRAY_SIZE(rv1126_code_table), + .data_mask = TSADCV2_DATA_MASK, + .mode = ADC_INCREMENT, + }, +}; + static const struct rockchip_tsadc_chip rk1808_tsadc_data = { .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */ .chn_num = 1, /* one channel for tsadc */ @@ -1250,6 +1313,10 @@ static const struct of_device_id of_rockchip_thermal_match[] = { .compatible = "rockchip,rv1108-tsadc", .data = (void *)&rv1108_tsadc_data, }, + { + .compatible = "rockchip,rv1126-tsadc", + .data = (void *)&rv1126_tsadc_data, + }, { .compatible = "rockchip,px30-tsadc", .data = (void *)&px30_tsadc_data, }, @@ -1538,50 +1605,33 @@ static int rockchip_thermal_probe(struct platform_device *pdev) if (IS_ERR(thermal->regs)) return PTR_ERR(thermal->regs); - thermal->reset = devm_reset_control_get(&pdev->dev, "tsadc-apb"); + thermal->reset = devm_reset_control_array_get(&pdev->dev, false, false); if (IS_ERR(thermal->reset)) { - error = PTR_ERR(thermal->reset); - dev_err(&pdev->dev, "failed to get tsadc reset: %d\n", error); - return error; + if (PTR_ERR(thermal->reset) != -EPROBE_DEFER) + dev_err(&pdev->dev, "failed to get tsadc reset lines\n"); + return PTR_ERR(thermal->reset); } - thermal->clk = devm_clk_get(&pdev->dev, "tsadc"); - if (IS_ERR(thermal->clk)) { - error = PTR_ERR(thermal->clk); - dev_err(&pdev->dev, "failed to get tsadc clock: %d\n", error); - return error; - } + thermal->num_clks = devm_clk_bulk_get_all(&pdev->dev, &thermal->clks); + if (thermal->num_clks < 1) + return -ENODEV; - thermal->pclk = devm_clk_get(&pdev->dev, "apb_pclk"); - if (IS_ERR(thermal->pclk)) { - error = PTR_ERR(thermal->pclk); - dev_err(&pdev->dev, "failed to get apb_pclk clock: %d\n", + error = clk_bulk_prepare_enable(thermal->num_clks, thermal->clks); + if (error) { + dev_err(&pdev->dev, "failed to prepare enable tsadc bulk clks: %d\n", error); return error; } thermal->chip->control(thermal->regs, false); - error = clk_prepare_enable(thermal->clk); - if (error) { - dev_err(&pdev->dev, "failed to enable converter clock: %d\n", - error); - return error; - } - - error = clk_prepare_enable(thermal->pclk); - if (error) { - dev_err(&pdev->dev, "failed to enable pclk: %d\n", error); - goto err_disable_clk; - } - rockchip_thermal_reset_controller(thermal->reset); error = rockchip_configure_from_dt(&pdev->dev, np, thermal); if (error) { dev_err(&pdev->dev, "failed to parse device tree data: %d\n", error); - goto err_disable_pclk; + goto err_disable_clocks; } thermal->chip->initialize(thermal->grf, thermal->regs, @@ -1613,7 +1663,7 @@ static int rockchip_thermal_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to register sensor[%d] : error = %d\n", i, error); - goto err_disable_pclk; + goto err_disable_clocks; } } @@ -1624,7 +1674,7 @@ static int rockchip_thermal_probe(struct platform_device *pdev) if (error) { dev_err(&pdev->dev, "failed to request tsadc irq: %d\n", error); - goto err_disable_pclk; + goto err_disable_clocks; } thermal->chip->control(thermal->regs, true); @@ -1642,10 +1692,8 @@ static int rockchip_thermal_probe(struct platform_device *pdev) return 0; -err_disable_pclk: - clk_disable_unprepare(thermal->pclk); -err_disable_clk: - clk_disable_unprepare(thermal->clk); +err_disable_clocks: + clk_bulk_disable_unprepare(thermal->num_clks, thermal->clks); return error; } @@ -1663,8 +1711,7 @@ static int rockchip_thermal_remove(struct platform_device *pdev) thermal->chip->control(thermal->regs, false); - clk_disable_unprepare(thermal->pclk); - clk_disable_unprepare(thermal->clk); + clk_bulk_disable_unprepare(thermal->num_clks, thermal->clks); return 0; } @@ -1696,8 +1743,7 @@ static int __maybe_unused rockchip_thermal_suspend(struct device *dev) thermal->chip->control(thermal->regs, false); - clk_disable(thermal->pclk); - clk_disable(thermal->clk); + clk_bulk_disable(thermal->num_clks, thermal->clks); if (thermal->tshut_mode == TSHUT_MODE_OTP) thermal_pinctrl_select_gpio(thermal); @@ -1712,13 +1758,10 @@ static int __maybe_unused rockchip_thermal_resume(struct device *dev) int i; int error; - error = clk_enable(thermal->clk); - if (error) - return error; - - error = clk_enable(thermal->pclk); + error = clk_bulk_enable(thermal->num_clks, thermal->clks); if (error) { - clk_disable(thermal->clk); + dev_err(&pdev->dev, "failed to enable tsadc bulk clks: %d\n", + error); return error; }