summaryrefslogtreecommitdiff
path: root/drivers/thermal/rockchip_thermal.c
diff options
context:
space:
mode:
authorElaine Zhang <zhangqing@rock-chips.com>2018-12-28 19:48:32 +0800
committerElaine Zhang <zhangqing@rock-chips.com>2018-12-29 10:18:46 +0800
commit35ae31482a56c6975a9884c2220982eb9b678eb4 (patch)
tree297c12d13e7f75d9e7a90417c7c9da63f8d63ebe /drivers/thermal/rockchip_thermal.c
parent75b880e190a6446e219ba1aab9fc28898774b69a (diff)
thermal: rockchip: add pinctrl control
Based on the TSADC Tshut mode to select pinctrl, instead of setting pinctrl based on architecture (Not depends on pinctrl setting by "init" or "default"). And it requires setting the tshut polarity before select pinctrl. Change-Id: Iac9ca05073b0181ee13b0048d0c2a54204f82bca Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
Diffstat (limited to 'drivers/thermal/rockchip_thermal.c')
-rw-r--r--drivers/thermal/rockchip_thermal.c66
1 files changed, 53 insertions, 13 deletions
diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c
index d5825c09ba6f..073e5b545c9d 100644
--- a/drivers/thermal/rockchip_thermal.c
+++ b/drivers/thermal/rockchip_thermal.c
@@ -34,7 +34,7 @@
*/
enum tshut_mode {
TSHUT_MODE_CRU = 0,
- TSHUT_MODE_GPIO,
+ TSHUT_MODE_OTP,
};
/**
@@ -172,6 +172,9 @@ struct rockchip_thermal_data {
int tshut_temp;
enum tshut_mode tshut_mode;
enum tshut_polarity tshut_polarity;
+ struct pinctrl *pinctrl;
+ struct pinctrl_state *gpio_state;
+ struct pinctrl_state *otp_state;
};
/**
@@ -943,7 +946,7 @@ static void rk_tsadcv2_tshut_mode(int chn, void __iomem *regs,
u32 val;
val = readl_relaxed(regs + TSADCV2_INT_EN);
- if (mode == TSHUT_MODE_GPIO) {
+ if (mode == TSHUT_MODE_OTP) {
val &= ~TSADCV2_SHUT_2CRU_SRC_EN(chn);
val |= TSADCV2_SHUT_2GPIO_SRC_EN(chn);
} else {
@@ -958,7 +961,7 @@ 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 */
- .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
+ .tshut_mode = TSHUT_MODE_OTP, /* default TSHUT via GPIO give PMIC */
.tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
.tshut_temp = 95000,
@@ -982,7 +985,7 @@ static const struct rockchip_tsadc_chip rk3228_tsadc_data = {
.chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */
.chn_num = 1, /* one channel for tsadc */
- .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
+ .tshut_mode = TSHUT_MODE_OTP, /* default TSHUT via GPIO give PMIC */
.tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
.tshut_temp = 95000,
@@ -1007,7 +1010,7 @@ static const struct rockchip_tsadc_chip rk3288_tsadc_data = {
.chn_id[SENSOR_GPU] = 2, /* gpu sensor is channel 2 */
.chn_num = 2, /* two channels for tsadc */
- .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
+ .tshut_mode = TSHUT_MODE_OTP, /* default TSHUT via GPIO give PMIC */
.tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
.tshut_temp = 95000,
@@ -1103,7 +1106,7 @@ static const struct rockchip_tsadc_chip rk3366_tsadc_data = {
.chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */
.chn_num = 2, /* two channels for tsadc */
- .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
+ .tshut_mode = TSHUT_MODE_OTP, /* default TSHUT via GPIO give PMIC */
.tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
.tshut_temp = 95000,
@@ -1128,7 +1131,7 @@ static const struct rockchip_tsadc_chip rk3368_tsadc_data = {
.chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */
.chn_num = 2, /* two channels for tsadc */
- .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
+ .tshut_mode = TSHUT_MODE_OTP, /* default TSHUT via GPIO give PMIC */
.tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
.tshut_temp = 95000,
@@ -1153,7 +1156,7 @@ static const struct rockchip_tsadc_chip rk3399_tsadc_data = {
.chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */
.chn_num = 2, /* two channels for tsadc */
- .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
+ .tshut_mode = TSHUT_MODE_OTP, /* default TSHUT via GPIO give PMIC */
.tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
.tshut_temp = 95000,
@@ -1177,7 +1180,7 @@ static const struct rockchip_tsadc_chip rv1108_tsadc_data = {
.chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */
.chn_num = 1, /* one channel for tsadc */
- .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
+ .tshut_mode = TSHUT_MODE_OTP, /* default TSHUT via GPIO give PMIC */
.tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
.tshut_temp = 95000,
@@ -1301,6 +1304,20 @@ static const struct thermal_zone_of_device_ops rockchip_of_thermal_ops = {
.set_trips = rockchip_thermal_set_trips,
};
+static void thermal_pinctrl_select_otp(struct rockchip_thermal_data *thermal)
+{
+ if (!IS_ERR(thermal->pinctrl) && !IS_ERR_OR_NULL(thermal->otp_state))
+ pinctrl_select_state(thermal->pinctrl,
+ thermal->otp_state);
+}
+
+static void thermal_pinctrl_select_gpio(struct rockchip_thermal_data *thermal)
+{
+ if (!IS_ERR(thermal->pinctrl) && !IS_ERR_OR_NULL(thermal->gpio_state))
+ pinctrl_select_state(thermal->pinctrl,
+ thermal->gpio_state);
+}
+
static int rockchip_configure_from_dt(struct device *dev,
struct device_node *np,
struct rockchip_thermal_data *thermal)
@@ -1324,7 +1341,7 @@ static int rockchip_configure_from_dt(struct device *dev,
if (of_property_read_u32(np, "rockchip,hw-tshut-mode", &tshut_mode)) {
dev_warn(dev,
"Missing tshut mode property, using default (%s)\n",
- thermal->chip->tshut_mode == TSHUT_MODE_GPIO ?
+ thermal->chip->tshut_mode == TSHUT_MODE_OTP ?
"gpio" : "cru");
thermal->tshut_mode = thermal->chip->tshut_mode;
} else {
@@ -1501,6 +1518,8 @@ static int rockchip_thermal_probe(struct platform_device *pdev)
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",
@@ -1526,6 +1545,24 @@ static int rockchip_thermal_probe(struct platform_device *pdev)
thermal->chip->initialize(thermal->grf, thermal->regs,
thermal->tshut_polarity);
+ if (thermal->tshut_mode == TSHUT_MODE_OTP) {
+ thermal->pinctrl = devm_pinctrl_get(&pdev->dev);
+ if (IS_ERR(thermal->pinctrl))
+ dev_err(&pdev->dev, "failed to find thermal pinctrl\n");
+
+ thermal->gpio_state = pinctrl_lookup_state(thermal->pinctrl,
+ "gpio");
+ if (IS_ERR_OR_NULL(thermal->gpio_state))
+ dev_err(&pdev->dev, "failed to find thermal gpio state\n");
+
+ thermal->otp_state = pinctrl_lookup_state(thermal->pinctrl,
+ "otpout");
+ if (IS_ERR_OR_NULL(thermal->otp_state))
+ dev_err(&pdev->dev, "failed to find thermal otpout state\n");
+
+ thermal_pinctrl_select_otp(thermal);
+ }
+
for (i = 0; i < thermal->chip->chn_num; i++) {
error = rockchip_thermal_register_sensor(pdev, thermal,
&thermal->sensors[i],
@@ -1603,7 +1640,8 @@ static void rockchip_thermal_shutdown(struct platform_device *pdev)
thermal->chip->set_tshut_mode(id, thermal->regs,
TSHUT_MODE_CRU);
}
- pinctrl_pm_select_sleep_state(&pdev->dev);
+ if (thermal->tshut_mode == TSHUT_MODE_OTP)
+ thermal_pinctrl_select_gpio(thermal);
}
static int __maybe_unused rockchip_thermal_suspend(struct device *dev)
@@ -1620,7 +1658,8 @@ static int __maybe_unused rockchip_thermal_suspend(struct device *dev)
clk_disable(thermal->pclk);
clk_disable(thermal->clk);
- pinctrl_pm_select_sleep_state(dev);
+ if (thermal->tshut_mode == TSHUT_MODE_OTP)
+ thermal_pinctrl_select_gpio(thermal);
return 0;
}
@@ -1662,7 +1701,8 @@ static int __maybe_unused rockchip_thermal_resume(struct device *dev)
for (i = 0; i < thermal->chip->chn_num; i++)
rockchip_thermal_toggle_sensor(&thermal->sensors[i], true);
- pinctrl_pm_select_default_state(dev);
+ if (thermal->tshut_mode == TSHUT_MODE_OTP)
+ thermal_pinctrl_select_otp(thermal);
return 0;
}