From: Song Chen <chensong_2000@189.cn>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: johan@kernel.org, elder@kernel.org, gregkh@linuxfoundation.org,
thierry.reding@gmail.com, lee.jones@linaro.org,
greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: Re: [PATCH] staging: greybus: introduce pwm_ops::apply
Date: Fri, 11 Feb 2022 11:06:33 +0800 [thread overview]
Message-ID: <6acc4f74-31a1-75b2-f7e8-610aac7b0ec8@189.cn> (raw)
In-Reply-To: <20220210100342.q2t4ykgyymjzr3fj@pengutronix.de>
在 2022/2/10 18:03, Uwe Kleine-König 写道:
> On Thu, Feb 10, 2022 at 05:05:02PM +0800, Song Chen wrote:
>> Introduce apply in pwm_ops to replace legacy operations,
>> like enable, disable, config and set_polarity.
>>
>> Signed-off-by: Song Chen <chensong_2000@189.cn>
>> ---
>> drivers/staging/greybus/pwm.c | 46 +++++++++++++++--------------------
>> 1 file changed, 19 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c
>> index 891a6a672378..e1889cf979b2 100644
>> --- a/drivers/staging/greybus/pwm.c
>> +++ b/drivers/staging/greybus/pwm.c
>> @@ -204,43 +204,35 @@ static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
>> gb_pwm_deactivate_operation(pwmc, pwm->hwpwm);
>> }
>>
>> -static int gb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>> - int duty_ns, int period_ns)
>> -{
>> - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
>> -
>> - return gb_pwm_config_operation(pwmc, pwm->hwpwm, duty_ns, period_ns);
>> -};
>> -
>> -static int gb_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
>> - enum pwm_polarity polarity)
>> +static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>> + const struct pwm_state *state)
>> {
>> + int ret;
>> struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
>>
>> - return gb_pwm_set_polarity_operation(pwmc, pwm->hwpwm, polarity);
>> -};
>> -
>> -static int gb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
>> -{
>> - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
>> + /* set period and duty cycle*/
>> + ret = gb_pwm_config_operation(pwmc, pwm->hwpwm, state->duty_cycle, state->period);
>
> gb_pwm_config_operation's 3rd parameter is an u32, so you're loosing
> bits here as state->duty_cycle is a u64. Ditto for period.
originally, pwm_apply_state --> pwm_apply_legacy --> gb_pwm_config -->
gb_pwm_config_operation is also loosing bits, does it mean greybus can
live with that?
Or redefine gb_pwm_config_request, switch duty and period to __le64?
>
> Also it would be nice if you go from
>
> .duty_cycle = A, .period = B, .enabled = 1
>
> to
>
> .duty_cycle = C, .period = D, .enabled = 0
>
> that C/D wasn't visible on the output pin. So please disable earlier
> (but keep enable at the end).
sorry, i don't quite understand this part, but is below code looking
good to you?
static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state)
{
int err;
bool enabled = pwm->state.enabled;
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
/* set polarity */
if (state->polarity != pwm->state.polarity) {
if (enabled) {
gb_pwm_disable_operation(pwmc, pwm->hwpwm);
enabled = false;
}
err = gb_pwm_set_polarity_operation(pwmc, pwm->hwpwm, state->polarity);
if (err)
return err;
}
if (!state->enabled) {
if (enabled)
gb_pwm_disable_operation(pwmc, pwm->hwpwm);
return 0;
}
/* set period and duty cycle*/
err = gb_pwm_config_operation(pwmc, pwm->hwpwm, state->duty_cycle,
state->period);
if (err)
return err;
/* enable/disable */
if (!enabled)
return gb_pwm_enable_operation(pwmc, pwm->hwpwm);
return 0;
}
>
> Best regards
> Uwe
>
next prev parent reply other threads:[~2022-02-11 3:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-10 9:05 [PATCH] staging: greybus: introduce pwm_ops::apply Song Chen
2022-02-10 10:03 ` Uwe Kleine-König
2022-02-11 3:06 ` Song Chen [this message]
2022-02-11 7:16 ` Uwe Kleine-König
2022-02-11 7:48 ` Song Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6acc4f74-31a1-75b2-f7e8-610aac7b0ec8@189.cn \
--to=chensong_2000@189.cn \
--cc=elder@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=johan@kernel.org \
--cc=lee.jones@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).