Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4715467yba; Tue, 30 Apr 2019 03:13:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbpGvgjBTDAPbEeGwiXBSMFaynEi4vNOAV/Wp8PZ+umnBBGx07MzXb8TDKKhiFlRLlVplY X-Received: by 2002:a17:902:784d:: with SMTP id e13mr69252313pln.152.1556619215653; Tue, 30 Apr 2019 03:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556619215; cv=none; d=google.com; s=arc-20160816; b=agdAz7dw5yPqADfTWjsrZQiORJctpQnAfp2daRejA8EGZhT8Tl4Xr1IfvPVyj5H/qE 3BkAS8wvPpz6gg3vfo96wUXBqPG+E5YktthpowuqA+nQTgYDTbd/4CqWpTWel8KTjyuV qzKb7PpyH2ObvtRfcVhv/X/BvWqJWMVzQavw8G0EV4iskonGfdWvmTzQ38t2zxa8EEUs ysAa4LXH+5/eZxBahlbC3QGDguBqQI3w9X4i3D5Ahlao0Mc0KlnT91v/lOIurNIQNBIs naUy8zNeVGMTLI7gaNLb8wMDeL0V3aCsnPoz80IAaqeTXggNCpYBO9cft29grEaBB5g7 xGkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=vUxCQm4Wse3bIwyzTmBkLL06y6Btg1mA8Kzvp18IA8U=; b=RhHi8ITRN2yiA3ISeccluTXSciMv8xM2F5XMaCuy+wZqXJKAradcWly3hbMJOmvPVv QVHc1gkeL/mB1SPC9+nEU+9VqQgP4yJUzfBPCWUcWkQ+WN0/X4JjtBsPlYrsnsnraNbE 2DXfXXlOzuP4NuiAoevR9JV1NGrkE6ZwNINuKcAVYEdLabtdU4UrV+GI93WGRSvsz2zT 8KBNQI8iqPtByWFIi695qfWapOiBSshhPEXUU3UWEiTcxgP2x+T1Yr14SgA83JM+ZlE8 Usso4yJ8BVJ00ZmOh8YfSncWq6M4hMhvfxS3JsJdF71sFQ8T9T/NAlSAuPU6/EXSgCiM rbSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13si7988343plo.175.2019.04.30.03.13.19; Tue, 30 Apr 2019 03:13:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727165AbfD3KKJ (ORCPT + 99 others); Tue, 30 Apr 2019 06:10:09 -0400 Received: from regular1.263xmail.com ([211.150.70.195]:38008 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726129AbfD3KJ4 (ORCPT ); Tue, 30 Apr 2019 06:09:56 -0400 Received: from zhangqing?rock-chips.com (unknown [192.168.167.190]) by regular1.263xmail.com (Postfix) with ESMTP id EF68396B; Tue, 30 Apr 2019 18:09:49 +0800 (CST) X-263anti-spam: KSV:0;BIG:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ADDR-CHECKED4: 1 X-ABS-CHECKED: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P7395T139736951809792S1556618984950678_; Tue, 30 Apr 2019 18:09:49 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <1a219faec73236b1307ac64632798b14> X-RL-SENDER: zhangqing@rock-chips.com X-SENDER: zhangqing@rock-chips.com X-LOGIN-NAME: zhangqing@rock-chips.com X-FST-TO: heiko@sntech.de X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Elaine Zhang To: heiko@sntech.de Cc: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, xxx@rock-chips.com, xf@rock-chips.com, huangtao@rock-chips.com, Elaine Zhang Subject: [PATCH v3 1/3] thermal: rockchip: fix up the tsadc pinctrl setting error Date: Tue, 30 Apr 2019 18:09:44 +0800 Message-Id: <1556618986-18923-2-git-send-email-zhangqing@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1556618986-18923-1-git-send-email-zhangqing@rock-chips.com> References: <1556618986-18923-1-git-send-email-zhangqing@rock-chips.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Explicitly use the pinctrl to set/unset the right mode instead of relying on the pinctrl init mode. And it requires setting the tshut polarity before select pinctrl. When the temperature sensor mode is set to 0, it will automatically reset the board via the Clock-Reset-Unit (CRU) if the over temperature threshold is reached. However, when the pinctrl initializes, it does a transition to "otp_out" which may lead the SoC restart all the time. "otp_out" IO may be connected to the RESET circuit on the hardware. If the IO is in the wrong state, it will trigger RESET. (similar to the effect of pressing the RESET button) which will cause the soc to restart all the time. Signed-off-by: Elaine Zhang --- drivers/thermal/rockchip_thermal.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index 9c7643d62ed7..6dc7fc516abf 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -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; }; /** @@ -1242,6 +1245,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", @@ -1267,6 +1272,30 @@ 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_GPIO) { + thermal->pinctrl = devm_pinctrl_get(&pdev->dev); + if (IS_ERR(thermal->pinctrl)) { + dev_err(&pdev->dev, "failed to find thermal pinctrl\n"); + return PTR_ERR(thermal->pinctrl); + } + + 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"); + return -EINVAL; + } + + 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"); + return -EINVAL; + } + + pinctrl_select_state(thermal->pinctrl, thermal->otp_state); + } + for (i = 0; i < thermal->chip->chn_num; i++) { error = rockchip_thermal_register_sensor(pdev, thermal, &thermal->sensors[i], @@ -1337,8 +1366,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_GPIO) + pinctrl_select_state(thermal->pinctrl, thermal->gpio_state); return 0; } @@ -1383,7 +1412,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_GPIO) + pinctrl_select_state(thermal->pinctrl, thermal->otp_state); return 0; } -- 1.9.1