public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Bill Gatliff <bgat@billgatliff.com>
To: "Stanislav O. Bezzubtsev" <stas@lvk.cs.msu.su>
Cc: linux-embedded@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PWM PATCH 2/7] Emulates PWM hardware using a high-resolution timer and a GPIO pin
Date: Wed, 10 Feb 2010 07:42:57 -0600	[thread overview]
Message-ID: <4B72B7E1.40907@billgatliff.com> (raw)
In-Reply-To: <8B7FF140-BE6E-4AD1-86BC-161488675DFB@lvk.cs.msu.su>

Stanislav O. Bezzubtsev wrote:
>> +
>> +struct gpio_pwm {
>> +	struct pwm_device pwm;
>> +	struct hrtimer t;
>>     
>
> Wouldn't a little bit longer name "timer" instead of simple "t" increase readability?
>   

Couldn't hurt.  Done.

>> +static void
>> +gpio_pwm_work (struct work_struct *work)
>> +{
>> +	struct gpio_pwm *gp = container_of(work, struct gpio_pwm, work);
>> +
>> +	if (gp->active)
>> +		gpio_direction_output(gp->gpio, gp->polarity ? 1 : 0);
>> +	else
>> +		gpio_direction_output(gp->gpio, gp->polarity ? 0 : 1);
>>     
>
> Maybe the following would be better:
> gpio_direction_output(gp->gpio, gp->polarity ^ gp->active)
> Instead of doing several comparisons.
>   

... except that I'm trying to guarantee that only the values '1' or '0'
get sent to gpio_direction_output.  There's nothing in the spec that
says other values are legal, although I'll admit that any nonzero value
is unlikely to cause problems.  Should I be pedantic here?

>> +
>> +	if (gp->active)
>> +		hrtimer_start(&gp->t,
>> +			      ktime_set(0, gp->pwm.channels[0].duty_ticks),
>> +			      HRTIMER_MODE_REL);
>> +	else
>> +		hrtimer_start(&gp->t,
>> +			      ktime_set(0,gp->pwm.channels[0].period_ticks
>> +					- gp->pwm.channels[0].duty_ticks),
>> +			      HRTIMER_MODE_REL);
>>     
>
> if (gp->active)
> 	t =  ktime_set(0, gp->pwm.channels[0].duty_ticks));
> else
> 	t = ktime_set(0, gp->pwm.channels[0].period_ticks - gp->pwm.channels[0].duty_ticks));
>
> htimer_start(&gp->t, t, HRTIMER_MODE_REL);
>   

Excellent.


>> +
>> +	ret = pwm_register(&gp->pwm);
>> +	if (ret)
>> +		goto err_pwm_register;
>> +
>> +	return 0;
>> +
>> +err_pwm_register:
>>     
>
> platform_set_drvdata(pdev, 0);
>   

Good catch!


>> +static int __devexit
>> +gpio_pwm_remove(struct platform_device *pdev)
>> +{
>> +	struct gpio_pwm *gp = platform_get_drvdata(pdev);
>> +	int ret;
>> +
>> +	ret = pwm_unregister(&gp->pwm);
>> +	hrtimer_cancel(&gp->t);
>> +	cancel_work_sync(&gp->work);
>>     
>
> platform_set_drvdata(pdev, 0);
>   

Ditto.

> And there are too much pr_debug & dev_dbg calls. Several of them are inside critical sections or in functions called from critical sections (inside spin_lock_irqsave - spin_lock_irqrestore block I mean). Don't think it is good.
>   

Ok.  Now that the code is relatively mature, they're unnecessary anyway.


b.g.

-- 
Bill Gatliff
Embedded systems training and consulting
http://billgatliff.com
bgat@billgatliff.com


  parent reply	other threads:[~2010-02-10 13:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-09 20:46 [PWM PATCH 0/7] Generic PWM API Bill Gatliff
2010-02-09 20:46 ` [PWM PATCH 1/7] API to consolidate PWM devices behind a common user and kernel interface Bill Gatliff
2010-02-10  2:41   ` H Hartley Sweeten
2010-02-10  4:12     ` Bill Gatliff
2010-02-10  4:18       ` Bill Gatliff
2010-02-10 17:34       ` H Hartley Sweeten
2010-02-10 13:55     ` Bill Gatliff
2010-02-10 18:33   ` H Hartley Sweeten
2010-02-09 20:46 ` [PWM PATCH 2/7] Emulates PWM hardware using a high-resolution timer and a GPIO pin Bill Gatliff
     [not found]   ` <8B7FF140-BE6E-4AD1-86BC-161488675DFB@lvk.cs.msu.su>
2010-02-10 13:42     ` Bill Gatliff [this message]
2010-02-09 20:46 ` [PWM PATCH 3/7] Expunge old Atmel PWMC driver, replacing it with one that conforms to the PWM API Bill Gatliff
2010-02-09 20:46 ` [PWM PATCH 4/7] Implements PWM-based LED control Bill Gatliff
2010-02-09 20:46 ` [PWM PATCH 5/7] LED "dim" trigger based on PWM control of the LED Bill Gatliff
2010-02-09 20:46 ` [PWM PATCH 6/7] Incorporate PWM API code into KBuild Bill Gatliff
2010-02-09 20:46 ` [PWM PATCH 7/7] PWM API driver for MPC52xx GPT peripheral Bill Gatliff

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=4B72B7E1.40907@billgatliff.com \
    --to=bgat@billgatliff.com \
    --cc=linux-embedded@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stas@lvk.cs.msu.su \
    /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