From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA8B9C61DA4 for ; Fri, 3 Mar 2023 22:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Cc:To:Subject: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jP+DE2aGeRsiKby89SI01ZerumDxZelYSr+aKSJN/m0=; b=Y4cotEX7E9Adu00y6Q6RJDH1Wg af3TdiWDvpTBRzrlCvIrSdUQW7P8qu2HQ8DvR0GREDuTxJeYS+pCq4nsZlZ0Q9FhPbEx42vDBsCQd KgaOEwVBSsJE0qA1OULLNGyglMEr/jouFd6YEtsCn51Xfc+jCEZxBPZzyJcxrt6iMKsIarpQErFiV kKix5U6jpSEA0mghw0Pfqu9KsTN5yhnZKeH+ba9uDjlzN4e65luWizD2QkALxwsGGLKncT86RqS9V mBWUb4FkNJkJHOCFPV8koA0eWMITYm/kiomC18GdOgNd3PKYHTfNKl7dcNIiMfWBYt5B65WJ2TT4N zfkDXtyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pYDoI-007ihX-Kr; Fri, 03 Mar 2023 22:23:30 +0000 Received: from s2.dolansoft.org ([212.51.146.245] helo=mx.dolansoft.org) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pYDo8-007ifW-Hi; Fri, 03 Mar 2023 22:23:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=brun.one; s=s1; h=MIME-Version:References:In-Reply-To:Message-Id:Cc:To:Subject:From: Date:From:To:Subject:Date:Message-ID:Reply-To; bh=jP+DE2aGeRsiKby89SI01ZerumDxZelYSr+aKSJN/m0=; b=T1WQkKSmlCH8TgABX1xfiMaNX9 8ks/E7QcjaEHAyg1RfCDCfUoaG+IXnaC2MItUs2U2PftpwLxCyv+8FUO4c8Qmm9iae+XuTn+jXWN3 o3Na3/cvIsbWFoORdTrFPFbpd2EoM404ZhY/YpAEQH/w/TbTbAbrRBK3p6cnpy/parCWky2qARmKF FSDjBw9bQolLKCfdl30/jCh/IzD1J/ikDFWA8ICk5Cne1onGTLBvR6KVfGkHF0dqu/mF7Zi1Y1P9S 32TuYaKHlUR2Ad243XkGanhOCiAnqVJPT+ArwqMT/VxjsYtT69uJzPmjO0yfkD5FKVmPbHU4RJfM5 LHgKOLYA==; Received: from [212.51.153.89] (helo=[192.168.12.54]) by mx.dolansoft.org with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pYDo1-00163h-1Q; Fri, 03 Mar 2023 22:23:13 +0000 Date: Fri, 03 Mar 2023 23:23:07 +0100 From: Lorenz Brun Subject: Re: [PATCH] pwm: mediatek: support inverted polarity To: Uwe =?iso-8859-1?q?Kleine-K=F6nig?= Cc: Thierry Reding , Matthias Brugger , AngeloGioacchino Del Regno , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Message-Id: In-Reply-To: <20230303211725.7wtxdxjqpxlrp77b@pengutronix.de> References: <20230303205821.2285418-1-lorenz@brun.one> <20230303211725.7wtxdxjqpxlrp77b@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230303_142320_632660_217CC8E3 X-CRM114-Status: GOOD ( 22.05 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org On Fri, Mar 3 2023 at 22:17:25 +01:00:00, Uwe Kleine-K=F6nig=20 wrote: > On Fri, Mar 03, 2023 at 09:58:21PM +0100, Lorenz Brun wrote: >> According to the MT7986 Reference Manual the Mediatek PWM=20 >> controller >> doesn't appear to have support for inverted polarity. >>=20 >> This implements the same solution as in pwm-meson and just inverts=20 >> the >> duty cycle instead, which results in the same outcome. >=20 > This idea is broken. This was recently discussed on the linux-pwm list > and I hope will be fixed soon. See > https://lore.kernel.org/linux-pwm/20230228093911.bh2sbp4tyfir2z5g@pengutr= onix.de/T/#meda75ffbd4ef2048991ea2cd091c0c14b1bb09c2 >=20 Is the issue here emulating PWM_POLARITY_INVERSED by inverting the=20 period or the overflow issues? This driver currently rejects PWM_POLARITY_INVERSED, but the problem is=20 that I have a board which inverts the output of the PWM peripheral=20 (low-side MOSFET for higher-voltage open-drain output), thus I need to=20 set the PWM node to output an inverted signal so that the final=20 open-drain output behaves correctly as the signal has been inverted=20 twice now. In my specific case this logic could also be added to pwm-fan, but this=20 would lead to more complexity there as this type of circuit is=20 generally handled by the PWM driver. > So this patch won't be accepted, still pointing out a style problem > below. >=20 >> Signed-off-by: Lorenz Brun >> --- >> drivers/pwm/pwm-mediatek.c | 13 +++++++++---- >> 1 file changed, 9 insertions(+), 4 deletions(-) >>=20 >> diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c >> index 5b5eeaff35da..6f4a54c8299f 100644 >> --- a/drivers/pwm/pwm-mediatek.c >> +++ b/drivers/pwm/pwm-mediatek.c >> @@ -202,9 +202,7 @@ static int pwm_mediatek_apply(struct pwm_chip=20 >> *chip, struct pwm_device *pwm, >> const struct pwm_state *state) >> { >> int err; >> - >> - if (state->polarity !=3D PWM_POLARITY_NORMAL) >> - return -EINVAL; >> + u64 duty_cycle; >>=20 >> if (!state->enabled) { >> if (pwm->state.enabled) >> @@ -213,7 +211,14 @@ static int pwm_mediatek_apply(struct pwm_chip=20 >> *chip, struct pwm_device *pwm, >> return 0; >> } >>=20 >> - err =3D pwm_mediatek_config(pwm->chip, pwm, state->duty_cycle,=20 >> state->period); >> + // According to the MT7986 Reference Manual the peripheral does=20 >> not >> + // appear to have the capability to invert the output. Instead=20 >> just >> + // invert the duty cycle. >=20 > Wrong commenting style, please stick to C-style comments (/* ... */) I can fix that if I end up submitting a V2 of this patch, but this=20 didn't get picked up by checkpatch. >=20 >> + duty_cycle =3D state->duty_cycle; >> + if (state->polarity =3D=3D PWM_POLARITY_INVERSED) >> + duty_cycle =3D state->period - state->duty_cycle; >> + >> + err =3D pwm_mediatek_config(pwm->chip, pwm, duty_cycle,=20 >> state->period); >> if (err) >> return err; >=20 > Best regards > Uwe >=20 > -- > Pengutronix e.K. | Uwe Kleine-K=F6nig =20 > | > Industrial Linux Solutions |=20 > https://www.pengutronix.de/ | Regards, Lorenz From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2F26C61DA3 for ; Fri, 3 Mar 2023 22:24:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Cc:To :Subject:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pzLYcyxlcjkYXA9Amf7apFFmzdq+dSPq7wbP7kBn5H8=; b=fjfeLmF6r2JB9vPRitrUkBU0C7 XwhH7+RlLRb93qqRCF5nDeRgLVQFEhf3y13y/1wkZnzDOWuFDddmU7zJFhHrZmviEmJNsKGKVpcus CLNoCWbW+Xq45qg7PexZiGrfTvq8uMvwlh3K6t23VMBex604QU6ByVCR2XPEV+pWLDWwVtCCmF/ij /4oqqTYcVMrKgVYf7SHEepX6itSN/BmNFpwHH40JAsalElXWj7lAsQTzyXGGi+DqoFULx1uC1jEUE qvrhfesrnxBAFrtNXHUuMT2+fBNJbPbnPhGLTCXIY4G0H5sB9jEUhv/NDEiIGucI1xWDTzeFv/T7b uYMJdfww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pYDoB-007igB-QK; Fri, 03 Mar 2023 22:23:23 +0000 Received: from s2.dolansoft.org ([212.51.146.245] helo=mx.dolansoft.org) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pYDo8-007ifW-Hi; Fri, 03 Mar 2023 22:23:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=brun.one; s=s1; h=MIME-Version:References:In-Reply-To:Message-Id:Cc:To:Subject:From: Date:From:To:Subject:Date:Message-ID:Reply-To; bh=jP+DE2aGeRsiKby89SI01ZerumDxZelYSr+aKSJN/m0=; b=T1WQkKSmlCH8TgABX1xfiMaNX9 8ks/E7QcjaEHAyg1RfCDCfUoaG+IXnaC2MItUs2U2PftpwLxCyv+8FUO4c8Qmm9iae+XuTn+jXWN3 o3Na3/cvIsbWFoORdTrFPFbpd2EoM404ZhY/YpAEQH/w/TbTbAbrRBK3p6cnpy/parCWky2qARmKF FSDjBw9bQolLKCfdl30/jCh/IzD1J/ikDFWA8ICk5Cne1onGTLBvR6KVfGkHF0dqu/mF7Zi1Y1P9S 32TuYaKHlUR2Ad243XkGanhOCiAnqVJPT+ArwqMT/VxjsYtT69uJzPmjO0yfkD5FKVmPbHU4RJfM5 LHgKOLYA==; Received: from [212.51.153.89] (helo=[192.168.12.54]) by mx.dolansoft.org with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pYDo1-00163h-1Q; Fri, 03 Mar 2023 22:23:13 +0000 Date: Fri, 03 Mar 2023 23:23:07 +0100 From: Lorenz Brun Subject: Re: [PATCH] pwm: mediatek: support inverted polarity To: Uwe =?iso-8859-1?q?Kleine-K=F6nig?= Cc: Thierry Reding , Matthias Brugger , AngeloGioacchino Del Regno , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Message-Id: In-Reply-To: <20230303211725.7wtxdxjqpxlrp77b@pengutronix.de> References: <20230303205821.2285418-1-lorenz@brun.one> <20230303211725.7wtxdxjqpxlrp77b@pengutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230303_142320_632660_217CC8E3 X-CRM114-Status: GOOD ( 22.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Mar 3 2023 at 22:17:25 +01:00:00, Uwe Kleine-K=F6nig = wrote: > On Fri, Mar 03, 2023 at 09:58:21PM +0100, Lorenz Brun wrote: >> According to the MT7986 Reference Manual the Mediatek PWM = >> controller >> doesn't appear to have support for inverted polarity. >> = >> This implements the same solution as in pwm-meson and just inverts = >> the >> duty cycle instead, which results in the same outcome. > = > This idea is broken. This was recently discussed on the linux-pwm list > and I hope will be fixed soon. See > https://lore.kernel.org/linux-pwm/20230228093911.bh2sbp4tyfir2z5g@pengutr= onix.de/T/#meda75ffbd4ef2048991ea2cd091c0c14b1bb09c2 > = Is the issue here emulating PWM_POLARITY_INVERSED by inverting the = period or the overflow issues? This driver currently rejects PWM_POLARITY_INVERSED, but the problem is = that I have a board which inverts the output of the PWM peripheral = (low-side MOSFET for higher-voltage open-drain output), thus I need to = set the PWM node to output an inverted signal so that the final = open-drain output behaves correctly as the signal has been inverted = twice now. In my specific case this logic could also be added to pwm-fan, but this = would lead to more complexity there as this type of circuit is = generally handled by the PWM driver. > So this patch won't be accepted, still pointing out a style problem > below. > = >> Signed-off-by: Lorenz Brun >> --- >> drivers/pwm/pwm-mediatek.c | 13 +++++++++---- >> 1 file changed, 9 insertions(+), 4 deletions(-) >> = >> diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c >> index 5b5eeaff35da..6f4a54c8299f 100644 >> --- a/drivers/pwm/pwm-mediatek.c >> +++ b/drivers/pwm/pwm-mediatek.c >> @@ -202,9 +202,7 @@ static int pwm_mediatek_apply(struct pwm_chip = >> *chip, struct pwm_device *pwm, >> const struct pwm_state *state) >> { >> int err; >> - >> - if (state->polarity !=3D PWM_POLARITY_NORMAL) >> - return -EINVAL; >> + u64 duty_cycle; >> = >> if (!state->enabled) { >> if (pwm->state.enabled) >> @@ -213,7 +211,14 @@ static int pwm_mediatek_apply(struct pwm_chip = >> *chip, struct pwm_device *pwm, >> return 0; >> } >> = >> - err =3D pwm_mediatek_config(pwm->chip, pwm, state->duty_cycle, = >> state->period); >> + // According to the MT7986 Reference Manual the peripheral does = >> not >> + // appear to have the capability to invert the output. Instead = >> just >> + // invert the duty cycle. > = > Wrong commenting style, please stick to C-style comments (/* ... */) I can fix that if I end up submitting a V2 of this patch, but this = didn't get picked up by checkpatch. > = >> + duty_cycle =3D state->duty_cycle; >> + if (state->polarity =3D=3D PWM_POLARITY_INVERSED) >> + duty_cycle =3D state->period - state->duty_cycle; >> + >> + err =3D pwm_mediatek_config(pwm->chip, pwm, duty_cycle, = >> state->period); >> if (err) >> return err; > = > Best regards > Uwe > = > -- > Pengutronix e.K. | Uwe Kleine-K=F6nig = > | > Industrial Linux Solutions | = > https://www.pengutronix.de/ | Regards, Lorenz _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel