From: Thierry Reding <thierry.reding@avionic-design.de>
To: "Philip, Avinash" <avinashphilip@ti.com>
Cc: linux-kernel@vger.kernel.org, nsekhar@ti.com, gururaja.hebbar@ti.com
Subject: Re: [PATCH 2/2] pwm: pwm-tiehrpwm: Add support for configuring polarity of PWM
Date: Fri, 24 Aug 2012 18:53:14 +0200 [thread overview]
Message-ID: <20120824165314.GA21435@avionic-0098.mockup.avionic-design.de> (raw)
In-Reply-To: <1345705251-10942-3-git-send-email-avinashphilip@ti.com>
[-- Attachment #1: Type: text/plain, Size: 4767 bytes --]
On Thu, Aug 23, 2012 at 12:30:51PM +0530, Philip, Avinash wrote:
[...]
> diff --git a/drivers/pwm/pwm-tiehrpwm.c b/drivers/pwm/pwm-tiehrpwm.c
[...]
> @@ -100,10 +109,17 @@
>
> #define NUM_PWM_CHANNEL 2 /* EHRPWM channels */
>
> +enum config {
> + config_dutycycle,
> + config_polarity,
> +};
> +
I don't think this makes sense, see below.
> @@ -165,38 +181,50 @@ static int set_prescale_div(unsigned long rqst_prescaler,
> }
>
> static void configure_chans(struct ehrpwm_pwm_chip *pc, int chan,
> - unsigned long duty_cycles)
> + enum config config)
> {
> - int cmp_reg, aqctl_reg;
> - unsigned short aqctl_val, aqctl_mask;
> + if (config == config_dutycycle) {
> + int cmp_reg;
> +
> + if (chan == 1)
> + /* Channel 1 configured with compare B register */
> + cmp_reg = CMPB;
> + else
> + /* Channel 0 configured with compare A register */
> + cmp_reg = CMPA;
> +
> + ehrpwm_write(pc->mmio_base, cmp_reg, pc->duty_cycles);
> + } else if (config == config_polarity) {
> + int aqctl_reg;
> + unsigned short aqctl_val, aqctl_mask;
> +
> + /*
> + * Configure PWM output to HIGH/LOW level on counter
> + * reaches compare register value and LOW/HIGH level
> + * on counter value reaches period register value and
> + * zero value on counter
> + */
> + if (chan == 1) {
> + aqctl_reg = AQCTLB;
> + aqctl_mask = AQCTL_CBU_MASK;
> +
> + if (pc->polarity == PWM_POLARITY_INVERSED)
> + aqctl_val = AQCTL_CHANB_POLINVERSED;
> + else
> + aqctl_val = AQCTL_CHANB_POLNORMAL;
> + } else {
> + aqctl_reg = AQCTLA;
> + aqctl_mask = AQCTL_CAU_MASK;
> +
> + if (pc->polarity == PWM_POLARITY_INVERSED)
> + aqctl_val = AQCTL_CHANA_POLINVERSED;
> + else
> + aqctl_val = AQCTL_CHANA_POLNORMAL;
> + }
>
> - /*
> - * Channels can be configured from action qualifier module.
> - * Channel 0 configured with compare A register and for
> - * up-counter mode.
> - * Channel 1 configured with compare B register and for
> - * up-counter mode.
> - */
> - if (chan == 1) {
> - aqctl_reg = AQCTLB;
> - cmp_reg = CMPB;
> - /* Configure PWM Low from compare B value */
> - aqctl_val = AQCTL_CBU_FRCLOW;
> - aqctl_mask = AQCTL_CBU_MASK;
> - } else {
> - cmp_reg = CMPA;
> - aqctl_reg = AQCTLA;
> - /* Configure PWM Low from compare A value*/
> - aqctl_val = AQCTL_CAU_FRCLOW;
> - aqctl_mask = AQCTL_CAU_MASK;
> + aqctl_mask |= AQCTL_PRD_MASK | AQCTL_ZRO_MASK;
> + ehrpwm_modify(pc->mmio_base, aqctl_reg, aqctl_mask, aqctl_val);
> }
> -
> - /* Configure PWM High from period value and zero value */
> - aqctl_val |= AQCTL_PRD_FRCHIGH | AQCTL_ZRO_FRCHIGH;
> - aqctl_mask |= AQCTL_PRD_MASK | AQCTL_ZRO_MASK;
> - ehrpwm_modify(pc->mmio_base, aqctl_reg, aqctl_mask, aqctl_val);
> -
> - ehrpwm_write(pc->mmio_base, cmp_reg, duty_cycles);
> }
I think it might be better to split this into two separate functions.
Both branches have absolutely no code in common, so splitting them off
would decrease the indentation level and make this much more readable
and wouldn't require the configuration enumeration from above.
>
> /*
> @@ -254,12 +282,24 @@ static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_CTRMODE_MASK,
> TBCTL_CTRMODE_UP);
>
> + pc->duty_cycles = duty_cycles;
> /* Configure the channel for duty cycle */
> - configure_chans(pc, pwm->hwpwm, duty_cycles);
> + configure_chans(pc, pwm->hwpwm, config_dutycycle);
> +
> pm_runtime_put_sync(chip->dev);
> return 0;
> }
>
> +static int ehrpwm_pwm_set_polarity(struct pwm_chip *chip,
> + struct pwm_device *pwm, enum pwm_polarity polarity)
> +{
> + struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
> +
> + /* Configuration of polarity in hardware delayed done at enable */
> + pc->polarity = polarity;
> + return 0;
> +}
> +
The problem here, which is true for both of the .set_polarity() and
.config() implementations is that both channels share a single duty
cycle and polarity. What if the two channels are configured with
conflicting settings? Shouldn't that at least give a warning or even
return an error?
> static int ehrpwm_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
> {
> struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
> @@ -283,6 +323,9 @@ static int ehrpwm_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
>
> ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val);
>
> + /* Channels Polarity can be configured from action qualifier module */
> + configure_chans(pc, pwm->hwpwm, config_polarity);
> +
What's this "action qualifier module"?
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-08-24 16:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-23 7:00 [PATCH 0/2] Support " Philip, Avinash
2012-08-23 7:00 ` [PATCH 1/2] pwm: pwm-tiecap: Add support " Philip, Avinash
2012-08-23 7:00 ` [PATCH 2/2] pwm: pwm-tiehrpwm: " Philip, Avinash
2012-08-24 16:53 ` Thierry Reding [this message]
2012-08-28 4:12 ` Philip, Avinash
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=20120824165314.GA21435@avionic-0098.mockup.avionic-design.de \
--to=thierry.reding@avionic-design.de \
--cc=avinashphilip@ti.com \
--cc=gururaja.hebbar@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nsekhar@ti.com \
/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
Powered by JetHome