From: Thierry Reding <thierry.reding@gmail.com>
To: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com,
ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
linux-pwm@vger.kernel.org, linux-sh@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v5 2/2] pwm: Add support for R-Car PWM Timer
Date: Mon, 17 Aug 2015 16:15:35 +0200 [thread overview]
Message-ID: <20150817141533.GB6891@ulmo.nvidia.com> (raw)
In-Reply-To: <1434359324-2964-3-git-send-email-yoshihiro.shimoda.uh@renesas.com>
[-- Attachment #1: Type: text/plain, Size: 2533 bytes --]
Sorry for taking an awful long time to get around to this. The driver
looks generally okay, but I have a few minor comments...
On Mon, Jun 15, 2015 at 06:08:44PM +0900, Yoshihiro Shimoda wrote:
> This patch adds support for R-Car SoCs PWM Timer.
This could be a little more verbose. You could say for example how many
channels the driver exposes, or mention typical use-cases (if any).
> diff --git a/drivers/pwm/pwm-rcar.c b/drivers/pwm/pwm-rcar.c
[...]
> +static int rcar_pwm_get_clock_division(struct rcar_pwm_chip *rp, int period_ns)
> +{
> + int div;
Can be unsigned int.
> + unsigned long clk_rate = clk_get_rate(rp->clk);
> + unsigned long long max; /* max cycle / nanoseconds */
> +
> + if (!clk_rate)
I prefer it when these are explicit: clk_rate == 0. This goes for
numerical comparisons. For booleans, or NULL pointer comparisons the
!expression is fine.
> +static int rcar_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> + int duty_ns, int period_ns)
> +{
> + struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip);
> + int div = rcar_pwm_get_clock_division(rp, period_ns);
> + int ret;
> +
> + if (div < 0)
> + return div;
> +
> + /* Let the core driver set pwm->period if disabled and duty_ns == 0 */
> + if (!test_bit(PWMF_ENABLED, &pwm->flags) && !duty_ns)
> + return 0;
> +
> + rcar_pwm_bit_modify(rp, RCAR_PWMCR_SYNC, RCAR_PWMCR_SYNC, RCAR_PWMCR);
> + ret = rcar_pwm_set_counter(rp, div, duty_ns, period_ns);
> + rcar_pwm_set_clock_control(rp, div);
> + rcar_pwm_bit_modify(rp, RCAR_PWMCR_SYNC, 0, RCAR_PWMCR);
> +
> + return ret;
> +}
> +
> +static int rcar_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
> +{
> + struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip);
> + u32 pwmcnt;
> +
> + /* Don't enable the PWM device if CYC0 or PH0 is 0 */
> + pwmcnt = rcar_pwm_read(rp, RCAR_PWMCNT);
> + if (!(pwmcnt & RCAR_PWMCNT_CYC0_MASK) ||
> + !(pwmcnt & RCAR_PWMCNT_PH0_MASK))
> + return -EINVAL;
This looks wrong. Any errors in configuration should've been caught by
the ->config() implementation. Why can't you return -EINVAL on this
condition in ->config()? ->enable() failing should only be the case if
truly the PWM can't be enabled, not if it's badly configured.
> +static struct platform_driver rcar_pwm_driver = {
> + .probe = rcar_pwm_probe,
> + .remove = rcar_pwm_remove,
> + .driver = {
> + .name = "pwm-rcar",
> + .of_match_table = of_match_ptr(rcar_pwm_of_table),
> + }
> +};
This doesn't need the artificial padding. A single space around = is
enough.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: Thierry Reding <thierry.reding@gmail.com>
To: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com,
ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
linux-pwm@vger.kernel.org, linux-sh@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v5 2/2] pwm: Add support for R-Car PWM Timer
Date: Mon, 17 Aug 2015 14:15:35 +0000 [thread overview]
Message-ID: <20150817141533.GB6891@ulmo.nvidia.com> (raw)
In-Reply-To: <1434359324-2964-3-git-send-email-yoshihiro.shimoda.uh@renesas.com>
[-- Attachment #1: Type: text/plain, Size: 2533 bytes --]
Sorry for taking an awful long time to get around to this. The driver
looks generally okay, but I have a few minor comments...
On Mon, Jun 15, 2015 at 06:08:44PM +0900, Yoshihiro Shimoda wrote:
> This patch adds support for R-Car SoCs PWM Timer.
This could be a little more verbose. You could say for example how many
channels the driver exposes, or mention typical use-cases (if any).
> diff --git a/drivers/pwm/pwm-rcar.c b/drivers/pwm/pwm-rcar.c
[...]
> +static int rcar_pwm_get_clock_division(struct rcar_pwm_chip *rp, int period_ns)
> +{
> + int div;
Can be unsigned int.
> + unsigned long clk_rate = clk_get_rate(rp->clk);
> + unsigned long long max; /* max cycle / nanoseconds */
> +
> + if (!clk_rate)
I prefer it when these are explicit: clk_rate == 0. This goes for
numerical comparisons. For booleans, or NULL pointer comparisons the
!expression is fine.
> +static int rcar_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> + int duty_ns, int period_ns)
> +{
> + struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip);
> + int div = rcar_pwm_get_clock_division(rp, period_ns);
> + int ret;
> +
> + if (div < 0)
> + return div;
> +
> + /* Let the core driver set pwm->period if disabled and duty_ns == 0 */
> + if (!test_bit(PWMF_ENABLED, &pwm->flags) && !duty_ns)
> + return 0;
> +
> + rcar_pwm_bit_modify(rp, RCAR_PWMCR_SYNC, RCAR_PWMCR_SYNC, RCAR_PWMCR);
> + ret = rcar_pwm_set_counter(rp, div, duty_ns, period_ns);
> + rcar_pwm_set_clock_control(rp, div);
> + rcar_pwm_bit_modify(rp, RCAR_PWMCR_SYNC, 0, RCAR_PWMCR);
> +
> + return ret;
> +}
> +
> +static int rcar_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
> +{
> + struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip);
> + u32 pwmcnt;
> +
> + /* Don't enable the PWM device if CYC0 or PH0 is 0 */
> + pwmcnt = rcar_pwm_read(rp, RCAR_PWMCNT);
> + if (!(pwmcnt & RCAR_PWMCNT_CYC0_MASK) ||
> + !(pwmcnt & RCAR_PWMCNT_PH0_MASK))
> + return -EINVAL;
This looks wrong. Any errors in configuration should've been caught by
the ->config() implementation. Why can't you return -EINVAL on this
condition in ->config()? ->enable() failing should only be the case if
truly the PWM can't be enabled, not if it's badly configured.
> +static struct platform_driver rcar_pwm_driver = {
> + .probe = rcar_pwm_probe,
> + .remove = rcar_pwm_remove,
> + .driver = {
> + .name = "pwm-rcar",
> + .of_match_table = of_match_ptr(rcar_pwm_of_table),
> + }
> +};
This doesn't need the artificial padding. A single space around = is
enough.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2015-08-17 14:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-15 9:08 [PATCH v5 0/2] pwm: Add support for R-Car PWM Timer Yoshihiro Shimoda
2015-06-15 9:08 ` Yoshihiro Shimoda
2015-06-15 9:08 ` [PATCH v5 1/2] pwm: Add device tree binding document " Yoshihiro Shimoda
2015-06-15 9:08 ` Yoshihiro Shimoda
2015-06-15 9:08 ` [PATCH v5 2/2] pwm: Add support " Yoshihiro Shimoda
2015-06-15 9:08 ` Yoshihiro Shimoda
2015-08-17 14:15 ` Thierry Reding [this message]
2015-08-17 14:15 ` Thierry Reding
2015-08-18 1:54 ` Yoshihiro Shimoda
2015-08-18 1:54 ` Yoshihiro Shimoda
2015-07-07 1:06 ` [PATCH v5 0/2] " Simon Horman
2015-07-07 1:06 ` Simon Horman
2015-07-27 10:38 ` Yoshihiro Shimoda
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=20150817141533.GB6891@ulmo.nvidia.com \
--to=thierry.reding@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=galak@codeaurora.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pawel.moll@arm.com \
--cc=robh+dt@kernel.org \
--cc=yoshihiro.shimoda.uh@renesas.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.