lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230309010410.2106525-1-lorenz@brun.one>
Date:   Thu,  9 Mar 2023 02:04:10 +0100
From:   Lorenz Brun <lorenz@...n.one>
To:     Thierry Reding <thierry.reding@...il.com>,
        Uwe Kleine-König 
        <u.kleine-koenig@...gutronix.de>,
        Matthias Brugger <matthias.bgg@...il.com>,
        AngeloGioacchino Del Regno 
        <angelogioacchino.delregno@...labora.com>
Cc:     linux-pwm@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org,
        linux-mediatek@...ts.infradead.org
Subject: [PATCH v2] pwm: mediatek: support inverted polarity

According to the MT7986 Reference Manual the Mediatek PWM controller
doesn't appear to have support for inverted polarity.

To still support inverted PWM for common use cases, this relaxes the
check for inverted polarity within the driver to allow it to work in
case usage_power is set to true, i.e. the exact waveform does not
matter. If usage_power is true and the polarity is inverted the duty
cycle is mathematically inverted before being applied to the hardware.

Signed-off-by: Lorenz Brun <lorenz@...n.one>
---
V2: Only allow mathematically inverted PWM if usage_power is true
---
 drivers/pwm/pwm-mediatek.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
index 5b5eeaff35da..18791304d1ca 100644
--- a/drivers/pwm/pwm-mediatek.c
+++ b/drivers/pwm/pwm-mediatek.c
@@ -202,8 +202,16 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 			      const struct pwm_state *state)
 {
 	int err;
-
-	if (state->polarity != PWM_POLARITY_NORMAL)
+	u64 duty_cycle;
+
+	/* According to the MT7986 Reference Manual the peripheral does not
+	 * appear to have the capability to invert the output.
+	 * This means that inverted mode can not be fully supported as the
+	 * waveform will always start with the low period and end with the high
+	 * period. Thus reject non-normal polarity if the shape of the waveform
+	 * matters, i.e. usage_power is not set.
+	 */
+	if (state->polarity != PWM_POLARITY_NORMAL && !state->usage_power)
 		return -EINVAL;
 
 	if (!state->enabled) {
@@ -213,7 +221,11 @@ static int pwm_mediatek_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 		return 0;
 	}
 
-	err = pwm_mediatek_config(pwm->chip, pwm, state->duty_cycle, state->period);
+	duty_cycle = state->duty_cycle;
+	if (state->polarity == PWM_POLARITY_INVERSED)
+		duty_cycle = state->period - state->duty_cycle;
+
+	err = pwm_mediatek_config(pwm->chip, pwm, duty_cycle, state->period);
 	if (err)
 		return err;
 
-- 
2.39.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ