From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8576D18E025 for ; Fri, 22 Aug 2025 19:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755889530; cv=none; b=IlbrHLVSXAalT5nOYROY78nbHy42aTOC5OYdnyH5B3OsqH+nSZKEdfZHzDUZxenDRrR59Vn8irXosmPjJgeqBwXOqCfIEXgiJCE1mv8leUMc8ONe5LLeVFgTk6Wk+ec/mIzO+x4K+Mytii72irzUPlw67b1nKT/jRzU+rN3uxKs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755889530; c=relaxed/simple; bh=kJzkhH2Ud9tboOjYnAagWWlU3/xTdzPh2ZVUkWwsVZc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j+4tnr+ggBF99nGa5oiAB4dy7vAx1K1xvqFxj4oco+F71ZorU1+9mbE40Vhncm8WpegT6QVLOgvhq7o/Nw/Wp9f8kA48XEJrDw5a3B+XEcV3YFhsvfGRiz7JbN5rsUAiAXp8xR2CyGCrKJPQNUnRSDDBS2RXaLJsDu4tIqUQZZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iVYzxRID; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iVYzxRID" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8473FC113CF; Fri, 22 Aug 2025 19:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755889530; bh=kJzkhH2Ud9tboOjYnAagWWlU3/xTdzPh2ZVUkWwsVZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iVYzxRIDl/njZc2T5yobzyR1fG0YK8jT1Kwr4hkbBYi1WZBT55F3Ajm68+RB6cx3H Ub7hFHJ6/xavtx7vkJ1wb2WIDxByZrFPQDuG4uqiUv8SKPqHYFAzgLNpN2zM81yrq0 I4t/e5lfMeOKQbFm31QPRp6xKDsavD/najLFMRX6Ef4U5M4Hy/27fuq/nrHXeBE5mD EiV7yXkxnuG5aCGwbuLert3g9HzwAn/suil3VKfmGkdYkS/ODTl4fyujJ5uxOPcqm4 s+fFEHXPd2ZjUIHXRlTvQtpNhWknjzplm/Safj5XjHfngIkb8pu1+uBygXLRrQQxM6 YzQ0YTWPOBjuw== From: Sasha Levin To: stable@vger.kernel.org Cc: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , AngeloGioacchino Del Regno , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Sasha Levin Subject: [PATCH 5.4.y 2/3] pwm: mediatek: Handle hardware enable and clock enable separately Date: Fri, 22 Aug 2025 15:05:26 -0400 Message-ID: <20250822190527.1408882-2-sashal@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250822190527.1408882-1-sashal@kernel.org> References: <2025082143-creature-relay-7247@gregkh> <20250822190527.1408882-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Uwe Kleine-König [ Upstream commit 704d918341c378c5f9505dfdf32d315e256d3846 ] Stop handling the clocks in pwm_mediatek_enable() and pwm_mediatek_disable(). This is a preparing change for the next commit that requires that clocks and the enable bit are handled separately. Also move these two functions a bit further up in the source file to make them usable in pwm_mediatek_config(), which is needed in the next commit, too. Signed-off-by: Uwe Kleine-König Reviewed-by: AngeloGioacchino Del Regno Link: https://lore.kernel.org/r/55c94fe2917ece152ee1e998f4675642a7716f13.1753717973.git.u.kleine-koenig@baylibre.com Cc: stable@vger.kernel.org Signed-off-by: Uwe Kleine-König Stable-dep-of: f21d136caf81 ("pwm: mediatek: Fix duty and period setting") Signed-off-by: Sasha Levin --- drivers/pwm/pwm-mediatek.c | 60 ++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c index 69616224a5fa..203e5c13a0d1 100644 --- a/drivers/pwm/pwm-mediatek.c +++ b/drivers/pwm/pwm-mediatek.c @@ -119,6 +119,26 @@ static inline void pwm_mediatek_writel(struct pwm_mediatek_chip *chip, writel(value, chip->regs + pwm_mediatek_reg_offset[num] + offset); } +static void pwm_mediatek_enable(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip); + u32 value; + + value = readl(pc->regs); + value |= BIT(pwm->hwpwm); + writel(value, pc->regs); +} + +static void pwm_mediatek_disable(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip); + u32 value; + + value = readl(pc->regs); + value &= ~BIT(pwm->hwpwm); + writel(value, pc->regs); +} + static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm, int duty_ns, int period_ns) { @@ -181,35 +201,6 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm, return ret; } -static int pwm_mediatek_enable(struct pwm_chip *chip, struct pwm_device *pwm) -{ - struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip); - u32 value; - int ret; - - ret = pwm_mediatek_clk_enable(chip, pwm); - if (ret < 0) - return ret; - - value = readl(pc->regs); - value |= BIT(pwm->hwpwm); - writel(value, pc->regs); - - return 0; -} - -static void pwm_mediatek_disable(struct pwm_chip *chip, struct pwm_device *pwm) -{ - struct pwm_mediatek_chip *pc = to_pwm_mediatek_chip(chip); - u32 value; - - value = readl(pc->regs); - value &= ~BIT(pwm->hwpwm); - writel(value, pc->regs); - - pwm_mediatek_clk_disable(chip, pwm); -} - static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) { @@ -219,8 +210,10 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm, return -EINVAL; if (!state->enabled) { - if (pwm->state.enabled) + if (pwm->state.enabled) { pwm_mediatek_disable(chip, pwm); + pwm_mediatek_clk_disable(chip, pwm); + } return 0; } @@ -229,8 +222,11 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (err) return err; - if (!pwm->state.enabled) - err = pwm_mediatek_enable(chip, pwm); + if (!pwm->state.enabled) { + err = pwm_mediatek_clk_enable(chip, pwm); + if (!err) + pwm_mediatek_enable(chip, pwm); + } return err; } -- 2.50.1