devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Chanwoo Choi <cw00.choi@samsung.com>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	Rob Herring <rob.herring@calxeda.com>,
	Pawel Moll <pawel.moll@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Stephen Warren <swarren@wwwdotorg.org>,
	Ian Campbell <ian.campbell@citrix.com>,
	MyungJoo Ham <myungjoo.ham@samsung.com>,
	Grant Likely <grant.likely@linaro.org>
Subject: Re: [PATCH 2/6] extcon-gpio: If the gpio driver/chip supports debounce, use it
Date: Tue, 10 Sep 2013 18:57:28 -0700	[thread overview]
Message-ID: <522FCE08.5000704@roeck-us.net> (raw)
In-Reply-To: <522FC476.7060100@samsung.com>

On 09/10/2013 06:16 PM, Chanwoo Choi wrote:
> Hi Guenter
>
> I agree to use gpio_set_debounce() API but, I suggest following patch to code clean.
> and I'd like you to use declarative sentence on patch name instead of 'If ...'.
>
> On 08/30/2013 01:29 PM, Guenter Roeck wrote:
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>>   drivers/extcon/extcon-gpio.c |    5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
>> index 77d35a7..973600e 100644
>> --- a/drivers/extcon/extcon-gpio.c
>> +++ b/drivers/extcon/extcon-gpio.c
>> @@ -111,6 +111,11 @@ static int gpio_extcon_probe(struct platform_device *pdev)
>>   	if (ret < 0)
>>   		goto err;
>>
>> +	/* Use gpio debounce if available. If so, don't debounce in software. */
>> +	if (pdata->debounce &&
>> +	    !gpio_set_debounce(extcon_data->gpio, pdata->debounce * 1000))
>> +		extcon_data->debounce_jiffies = 0;
>> +
>>   	INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
>>
>>   	extcon_data->irq = gpio_to_irq(extcon_data->gpio);
>>
>
> diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
> index 3943ce2..0777e72 100644
> --- a/drivers/extcon/extcon-gpio.c
> +++ b/drivers/extcon/extcon-gpio.c
> @@ -56,8 +56,10 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
>   {
>          struct gpio_extcon_data *extcon_data = dev_id;
>
> -       queue_delayed_work(system_power_efficient_wq, &extcon_data->work,
> -                             extcon_data->debounce_jiffies);
> +       if (extcon_data->debounce_jiffies)
> +               queue_delayed_work(system_power_efficient_wq,
> +                                  &extcon_data->work,
> +                                  extcon_data->debounce_jiffies);

I am a bit lost about this one. The above means that the workqueue would not be executed
at all if debounce_jiffies is 0 (and if pdata->debounce is 0), meaning an event would
never be generated. With the original code, the workqueue will be executed immediately
if debounce_jiffies is 0, which I think is exactly what we need.

>          return IRQ_HANDLED;
>   }
>
> @@ -100,7 +102,14 @@ static int gpio_extcon_probe(struct platform_device *pdev)
>          extcon_data->state_off = pdata->state_off;
>          if (pdata->state_on && pdata->state_off)
>                  extcon_data->edev.print_state = extcon_gpio_print_state;
> -       extcon_data->debounce_jiffies = msecs_to_jiffies(pdata->debounce);
> +       extcon_data->debounce_jiffies = 0;
> +       if (pdata->debounce) {
> +               ret = gpio_set_debounce(extcon_data->gpio,
> +                                       pdata->debounce * 1000);
> +               if (ret < 0)
> +                       extcon_data->debounce_jiffies =
> +                               msecs_to_jiffies(pdata->debounce);
> +       }
>
Ok, though it is unnecessary to initialize debounce_jiffies (it is pre-initialized
from the allocation), so I'll drop that line.

>          ret = extcon_dev_register(&extcon_data->edev, &pdev->dev);
>          if (ret < 0)
> @@ -111,11 +120,6 @@ static int gpio_extcon_probe(struct platform_device *pdev)
>          if (ret < 0)
>                  goto err;
>
> -       /* Use gpio debounce if available. If so, don't debounce in software. */
> -       if (pdata->debounce &&
> -           !gpio_set_debounce(extcon_data->gpio, pdata->debounce * 1000))
> -               extcon_data->debounce_jiffies = 0;
> -
>          INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
>
>          extcon_data->irq = gpio_to_irq(extcon_data->gpio);
> @@ -146,7 +150,8 @@ static int gpio_extcon_remove(struct platform_device *pdev)
>   {
>          struct gpio_extcon_data *extcon_data = platform_get_drvdata(pdev);
>
> -       cancel_delayed_work_sync(&extcon_data->work);
> +       if (extcon_data->debounce_jiffies)
> +               cancel_delayed_work_sync(&extcon_data->work);

I think we would have to call cancel_work_sync() in the else case to make sure
that no work is in the process of being executed - which just turns out to execute
the same code as cancel_delayed_work_sync(). So the if/else would just add complexity
with no real gain.

Thanks,
Guenter

>          free_irq(extcon_data->irq, extcon_data);
>          extcon_dev_unregister(&extcon_data->edev);
>
>
> Thanks,
> Chanwoo Choi
>
>

  reply	other threads:[~2013-09-11  1:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-30  4:29 [PATCH 0/6] extcon-gpio: Add devicetree support Guenter Roeck
2013-08-30  4:29 ` [PATCH 1/6] extcon-gpio: Do not unnecessarily initialize variables Guenter Roeck
2013-09-11  1:16   ` Chanwoo Choi
2013-08-30  4:29 ` [PATCH 2/6] extcon-gpio: If the gpio driver/chip supports debounce, use it Guenter Roeck
2013-09-11  1:16   ` Chanwoo Choi
2013-09-11  1:57     ` Guenter Roeck [this message]
2013-09-11  2:03       ` Chanwoo Choi
2013-08-30  4:29 ` [PATCH 3/6] extcon-gpio: Add support for active-low presence detect pins Guenter Roeck
2013-09-11  2:14   ` Chanwoo Choi
2013-09-11  2:25     ` [PATCH v2 " Guenter Roeck
2013-09-11 23:57       ` Chanwoo Choi
2013-09-12  0:23         ` Guenter Roeck
2013-08-30  4:29 ` [RFC PATCH 4/6] extcon-gpio: Add devicetree support Guenter Roeck
2013-09-12 16:45   ` Mark Rutland
2013-09-12 17:00     ` Guenter Roeck
2013-08-30  4:29 ` [RFC PATCH 5/6] extcon-gpio: Describe devicetree bindings Guenter Roeck
2013-09-12 16:41   ` Mark Rutland
2013-09-12 16:53     ` Guenter Roeck
2013-09-16 14:21       ` Mark Rutland
     [not found]         ` <20130916142147.GF30650-NuALmloUBlrZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2013-09-16 15:19           ` Guenter Roeck
     [not found]             ` <20130916151953.GA5801-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2013-09-18 15:38               ` Mark Rutland
     [not found]                 ` <20130918153828.GB17453-NuALmloUBlrZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2013-09-19 16:42                   ` Mark Brown
     [not found]                     ` <20130919164245.GG21013-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-09-19 18:28                       ` Guenter Roeck
     [not found]                         ` <20130919182850.GA22775-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2013-09-19 18:35                           ` Mark Brown
2013-08-30  4:29 ` [RFC PATCH 6/6] extcon-gpio: Describe possible properties to support multi-type cables Guenter Roeck

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=522FCE08.5000704@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=cw00.choi@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=grant.likely@linaro.org \
    --cc=ian.campbell@citrix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=pawel.moll@arm.com \
    --cc=rob.herring@calxeda.com \
    --cc=swarren@wwwdotorg.org \
    /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).