From: nicolas.ferre@atmel.com (Nicolas Ferre)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv6 5/5] USB: gadget: atmel_usba_udc: Add suspend/resume with wakeup support
Date: Thu, 5 Feb 2015 18:20:45 +0100 [thread overview]
Message-ID: <54D3A66D.3050000@atmel.com> (raw)
In-Reply-To: <1421945805-31129-6-git-send-email-sylvain.rochet@finsecur.com>
Le 22/01/2015 17:56, Sylvain Rochet a ?crit :
> This patch add suspend/resume with wakeup support for Atmel USBA.
>
> On suspend: We stay continuously clocked if Vbus signal is not
> available. If Vbus signal is available we set the Vbus signal as a wake
> up source then we stop the USBA itself and all clocks used by USBA.
>
> On resume: We recover clocks and USBA if we stopped them. If a device is
> currently connected at resume time we enable the controller.
>
> Signed-off-by: Sylvain Rochet <sylvain.rochet@finsecur.com>
> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> drivers/usb/gadget/udc/atmel_usba_udc.c | 68 +++++++++++++++++++++++++++++++++
> 1 file changed, 68 insertions(+)
>
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index 361f740..7942c2f 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -2178,6 +2178,7 @@ static int usba_udc_probe(struct platform_device *pdev)
> ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
> if (ret)
> return ret;
> + device_init_wakeup(&pdev->dev, 1);
>
> usba_init_debugfs(udc);
> for (i = 1; i < udc->num_ep; i++)
> @@ -2193,6 +2194,7 @@ static int __exit usba_udc_remove(struct platform_device *pdev)
>
> udc = platform_get_drvdata(pdev);
>
> + device_init_wakeup(&pdev->dev, 0);
> usb_del_gadget_udc(&udc->gadget);
>
> for (i = 1; i < udc->num_ep; i++)
> @@ -2202,10 +2204,76 @@ static int __exit usba_udc_remove(struct platform_device *pdev)
> return 0;
> }
>
> +#ifdef CONFIG_PM
> +static int usba_udc_suspend(struct device *dev)
> +{
> + struct usba_udc *udc = dev_get_drvdata(dev);
> +
> + /* Not started */
> + if (!udc->driver)
> + return 0;
> +
> + mutex_lock(&udc->vbus_mutex);
> +
> + if (!device_may_wakeup(dev)) {
> + usba_stop(udc);
> + goto out;
> + }
> +
> + /*
> + * Device may wake up. We stay clocked if we failed
> + * to request vbus irq, assuming always on.
> + */
> + if (gpio_is_valid(udc->vbus_pin)) {
> + usba_stop(udc);
> + /* Only wake up on device connection */
> + if (udc->caps && udc->caps->irq_single_edge_support)
> + irq_set_irq_type(gpio_to_irq(udc->vbus_pin),
> + udc->vbus_pin_inverted ?
> + IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING);
As said earlier, let's try another approach for this.
Bye,
> +
> + enable_irq_wake(gpio_to_irq(udc->vbus_pin));
> + }
> +
> +out:
> + mutex_unlock(&udc->vbus_mutex);
> + return 0;
> +}
> +
> +static int usba_udc_resume(struct device *dev)
> +{
> + struct usba_udc *udc = dev_get_drvdata(dev);
> +
> + /* Not started */
> + if (!udc->driver)
> + return 0;
> +
> + if (device_may_wakeup(dev) && gpio_is_valid(udc->vbus_pin)) {
> + disable_irq_wake(gpio_to_irq(udc->vbus_pin));
> +
> + if (udc->caps && udc->caps->irq_single_edge_support)
> + irq_set_irq_type(gpio_to_irq(udc->vbus_pin),
> + IRQ_TYPE_EDGE_BOTH);
> + }
> +
> + /* If Vbus is present, enable the controller and wait for reset */
> + mutex_lock(&udc->vbus_mutex);
> + udc->vbus_prev = vbus_is_present(udc);
> + if (udc->vbus_prev)
> + usba_start(udc);
> + mutex_unlock(&udc->vbus_mutex);
> +
> + return 0;
> +}
> +#endif
> +
> +static SIMPLE_DEV_PM_OPS(usba_udc_pm_ops, usba_udc_suspend, usba_udc_resume);
> +
> static struct platform_driver udc_driver = {
> .remove = __exit_p(usba_udc_remove),
> .driver = {
> .name = "atmel_usba_udc",
> + .pm = &usba_udc_pm_ops,
> .of_match_table = of_match_ptr(atmel_udc_dt_ids),
> },
> };
>
--
Nicolas Ferre
prev parent reply other threads:[~2015-02-05 17:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-22 16:56 [PATCHv6 0/5] USB: gadget: atmel_usba_udc: Driver improvements Sylvain Rochet
2015-01-22 16:56 ` [PATCHv6 1/5] USB: gadget: atmel_usba_udc: Fixed vbus_prev initial state Sylvain Rochet
2015-01-22 16:56 ` [PATCHv6 2/5] USB: gadget: atmel_usba_udc: Request an auto disabled Vbus signal IRQ instead of an auto enabled IRQ request followed by IRQ disable Sylvain Rochet
2015-01-23 7:43 ` Jean-Christophe PLAGNIOL-VILLARD
2015-01-23 8:59 ` Nicolas Ferre
2015-01-23 9:39 ` Sylvain Rochet
2015-02-05 11:28 ` Nicolas Ferre
2015-01-22 16:56 ` [PATCHv6 3/5] USB: gadget: atmel_usba_udc: Start clocks on rising edge of the Vbus signal, stop clocks on falling edge of the Vbus signal Sylvain Rochet
2015-01-22 16:56 ` [PATCHv6 4/5] USB: gadget: atmel_usba_udc: Prepare for IRQ single edge support Sylvain Rochet
2015-01-22 17:14 ` Boris Brezillon
2015-02-05 17:19 ` Nicolas Ferre
2015-02-07 19:37 ` Sylvain Rochet
2015-02-08 9:24 ` Boris Brezillon
2015-02-12 18:00 ` Sylvain Rochet
2015-01-22 16:56 ` [PATCHv6 5/5] USB: gadget: atmel_usba_udc: Add suspend/resume with wakeup support Sylvain Rochet
2015-02-05 17:20 ` Nicolas Ferre [this message]
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=54D3A66D.3050000@atmel.com \
--to=nicolas.ferre@atmel.com \
--cc=linux-arm-kernel@lists.infradead.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 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.