From 718382dfea9571b2f019aeb621c3fdcb3d3af2a0 Mon Sep 17 00:00:00 2001 From: Damon Ding Date: Tue, 23 Apr 2024 14:49:14 +0800 Subject: [PATCH] pwm: rockchip: keep the mode fixed in capture mode although pwm is disabled The PWM io input/output state is controlled by PWM mode configuration. In order to avoid the antagonistic drive state between the PWM pin and the external pin, keep the PWM mode fixed in capture mode although PWM is disabled. Change-Id: I6183987c9bef6f444726643f878c5384f63844d0 Signed-off-by: Damon Ding --- drivers/pwm/pwm-rockchip.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/pwm/pwm-rockchip.c b/drivers/pwm/pwm-rockchip.c index 21739f45e25a..d89dce9db1d8 100644 --- a/drivers/pwm/pwm-rockchip.c +++ b/drivers/pwm/pwm-rockchip.c @@ -604,10 +604,18 @@ static int rockchip_pwm_enable_v1(struct pwm_chip *chip, struct pwm_device *pwm, enable_conf |= PWM_CAPTURE; } - if (enable) + if (enable) { val |= enable_conf; - else - val &= ~enable_conf; + } else { + /* + * The PWM io input/output state is controlled by PWM mode + * configuration. In order to avoid the antagonistic drive + * state between the PWM pin and the external pin, keep the + * PWM mode fixed in capture mode although PWM is disabled. + */ + if (pc->capture_en) + val |= PWM_CAPTURE; + } writel_relaxed(val, pc->base + PWM_CTRL_V1); if (pc->data->vop_pwm) @@ -919,8 +927,13 @@ static void rockchip_pwm_set_capture_v4(struct pwm_chip *chip, struct pwm_device pc->capture_cnt = 0; - writel_relaxed(enable ? PWM_MODE(CAPTURE_MODE) : PWM_MODE(CONTINUOUS_MODE), - pc->base + CTRL_V4); + /* + * The PWM io input/output state is controlled by PWM mode + * configuration. In order to avoid the antagonistic drive + * state between the PWM pin and the external pin, keep the + * PWM mode fixed in capture mode although PWM is disabled. + */ + writel_relaxed(PWM_MODE(CAPTURE_MODE), pc->base + CTRL_V4); writel_relaxed(CAP_LPR_INT_EN(enable) | CAP_HPR_INT_EN(enable) | PWM_IN_SEL(channel_sel), pc->base + INT_EN); }