From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Paul Zimmerman <Paul.Zimmerman@synopsys.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-samsung-soc@vger.kernel.org"
<linux-samsung-soc@vger.kernel.org>
Cc: Kyungmin Park <kyungmin.park@samsung.com>,
Robert Baldyga <r.baldyga@samsung.com>,
Krzysztof Kozlowski <k.kozlowski@samsung.com>,
Felipe Balbi <balbi@ti.com>
Subject: Re: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls
Date: Fri, 14 Nov 2014 10:19:24 +0100 [thread overview]
Message-ID: <5465C91C.7050409@samsung.com> (raw)
In-Reply-To: <A2CA0424C0A6F04399FB9E1CD98E0304844EB636@US01WEMBX2.internal.synopsys.com>
Hello,
On 2014-11-13 21:55, Paul Zimmerman wrote:
>> From: Marek Szyprowski [mailto:m.szyprowski@samsung.com]
>> Sent: Thursday, November 13, 2014 7:18 AM
>>
>> On 2014-10-31 19:46, Paul Zimmerman wrote:
>>>> From: Marek Szyprowski [mailto:m.szyprowski@samsung.com]
>>>> Sent: Friday, October 31, 2014 3:13 AM
>>>>
>>>> This patch adds mutex, which protects initialization and
>>>> deinitialization procedures against suspend/resume methods.
>>>>
>>>> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
>>>> ---
>>>> drivers/usb/dwc2/core.h | 1 +
>>>> drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++
>>>> 2 files changed, 21 insertions(+)
>>>>
>>>> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
>>>> index 9f77b4d1c5ff..58732a9a0019 100644
>>>> --- a/drivers/usb/dwc2/core.h
>>>> +++ b/drivers/usb/dwc2/core.h
>>>> @@ -187,6 +187,7 @@ struct s3c_hsotg {
>>>> struct s3c_hsotg_plat *plat;
>>>>
>>>> spinlock_t lock;
>>>> + struct mutex init_mutex;
>>>>
>>>> void __iomem *regs;
>>>> int irq;
>>>> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
>>>> index d8dda39c9e16..a2e4272a904e 100644
>>>> --- a/drivers/usb/dwc2/gadget.c
>>>> +++ b/drivers/usb/dwc2/gadget.c
>>>> @@ -21,6 +21,7 @@
>>>> #include <linux/platform_device.h>
>>>> #include <linux/dma-mapping.h>
>>>> #include <linux/debugfs.h>
>>>> +#include <linux/mutex.h>
>>>> #include <linux/seq_file.h>
>>>> #include <linux/delay.h>
>>>> #include <linux/io.h>
>>>> @@ -2908,6 +2909,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
>>>> return -EINVAL;
>>>> }
>>>>
>>>> + mutex_lock(&hsotg->init_mutex);
>>>> WARN_ON(hsotg->driver);
>>>>
>>>> driver->driver.bus = NULL;
>>>> @@ -2933,9 +2935,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
>>>>
>>>> dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name);
>>>>
>>>> + mutex_unlock(&hsotg->init_mutex);
>>>> +
>>>> return 0;
>>>>
>>>> err:
>>>> + mutex_unlock(&hsotg->init_mutex);
>>>> hsotg->driver = NULL;
>>>> return ret;
>>>> }
>>>> @@ -2957,6 +2962,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
>>>> if (!hsotg)
>>>> return -ENODEV;
>>>>
>>>> + mutex_lock(&hsotg->init_mutex);
>>>> +
>>>> /* all endpoints should be shutdown */
>>>> for (ep = 1; ep < hsotg->num_of_eps; ep++)
>>>> s3c_hsotg_ep_disable(&hsotg->eps[ep].ep);
>>>> @@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
>>>>
>>>> clk_disable(hsotg->clk);
>>>>
>>>> + mutex_unlock(&hsotg->init_mutex);
>>>> +
>>>> return 0;
>>>> }
>>>>
>>>> @@ -3002,6 +3011,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)
>>>>
>>>> dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on);
>>>>
>>>> + mutex_lock(&hsotg->init_mutex);
>>>> spin_lock_irqsave(&hsotg->lock, flags);
>>>> if (is_on) {
>>>> clk_enable(hsotg->clk);
>>>> @@ -3013,6 +3023,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)
>>>>
>>>> hsotg->gadget.speed = USB_SPEED_UNKNOWN;
>>>> spin_unlock_irqrestore(&hsotg->lock, flags);
>>>> + mutex_unlock(&hsotg->init_mutex);
>>>>
>>>> return 0;
>>>> }
>>>> @@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
>>>> }
>>>>
>>>> spin_lock_init(&hsotg->lock);
>>>> + mutex_init(&hsotg->init_mutex);
>>>>
>>>> hsotg->irq = ret;
>>>>
>>>> @@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t
>> state)
>>>> unsigned long flags;
>>>> int ret = 0;
>>>>
>>>> + mutex_lock(&hsotg->init_mutex);
>>>> +
>>>> if (hsotg->driver)
>>>> dev_info(hsotg->dev, "suspending usb gadget %s\n",
>>>> hsotg->driver->driver.name);
>>>> @@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t
>> state)
>>>> clk_disable(hsotg->clk);
>>>> }
>>>>
>>>> + mutex_unlock(&hsotg->init_mutex);
>>>> +
>>>> return ret;
>>>> }
>>>>
>>>> @@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev)
>>>> unsigned long flags;
>>>> int ret = 0;
>>>>
>>>> + mutex_lock(&hsotg->init_mutex);
>>>> if (hsotg->driver) {
>>>> +
>>>> dev_info(hsotg->dev, "resuming usb gadget %s\n",
>>>> hsotg->driver->driver.name);
>>>>
>>>> @@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)
>>>> s3c_hsotg_core_connect(hsotg);
>>>> spin_unlock_irqrestore(&hsotg->lock, flags);
>>>>
>>>> + mutex_unlock(&hsotg->init_mutex);
>>>> +
>>>> return ret;
>>>> }
>>>>
>>> Hmm. I can't find any other UDC driver that uses a mutex in its
>>> suspend/resume functions. Can you explain why this is needed only
>>> for dwc2?
>> I've posted this version because I thought you were not convinced that
>> the patch
>> "usb: dwc2/gadget: rework suspend/resume code to correctly restore
>> gadget state"
>> can add code for initialization and deinitialization in suspend/resume
>> paths.
> My problem with that patch was that you were checking the ->enabled
> flag outside of the spinlock. To address that, you only need to move
> the check inside of the spinlock. I don't see why a mutex is needed.
It is not that simple. I can add spin_lock() before checking enabled,
but then
I would need to spin_unlock() to call regulator_bulk_enable() and
phy_enable(),
because both cannot be called from atomic context. This means that the
spinlock
in such case will not protect anything and is simply useless.
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
next prev parent reply other threads:[~2014-11-14 9:19 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-20 10:45 [PATCH v2 00/10] more dwc2/gadget fixes Marek Szyprowski
2014-10-20 10:45 ` [PATCH v2 01/10] usb: dwc2/gadget: report disconnect event from 'end session' irq Marek Szyprowski
[not found] ` <1413801940-31086-2-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-10-25 1:23 ` Paul Zimmerman
[not found] ` <A2CA0424C0A6F04399FB9E1CD98E0304844E5C19-Yu2iAY70zvrYN67daEjeMPufCSb+aD3WLzEdoUbNIic@public.gmane.org>
2014-10-31 7:45 ` Marek Szyprowski
2014-10-31 8:04 ` [PATCH v3] " Marek Szyprowski
2014-10-31 18:15 ` Paul Zimmerman
2014-11-13 13:39 ` Marek Szyprowski
[not found] ` <5464B496.9010000-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-11-13 20:50 ` Paul Zimmerman
2014-11-14 10:31 ` Marek Szyprowski
2014-11-14 12:00 ` Marek Szyprowski
[not found] ` <5465EEF3.7060902-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-11-14 12:20 ` [PATCH v4] usb: dwc2/gadget: rework disconnect event handling Marek Szyprowski
[not found] ` <1415967607-6174-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-11-14 19:01 ` Paul Zimmerman
2014-11-14 19:04 ` Felipe Balbi
2014-11-14 21:21 ` Paul Zimmerman
2014-11-14 22:09 ` Paul Zimmerman
2014-11-17 6:27 ` Marek Szyprowski
2014-11-17 8:59 ` [PATCH v5] " Marek Szyprowski
[not found] ` <1416214782-13911-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-11-18 20:56 ` Paul Zimmerman
2014-11-20 19:53 ` Felipe Balbi
[not found] ` <1413801940-31086-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-10-20 10:45 ` [PATCH v2 02/10] usb: dwc2/gadget: fix enumeration issues Marek Szyprowski
[not found] ` <1413801940-31086-3-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-10-25 0:21 ` Paul Zimmerman
2014-10-20 10:45 ` [PATCH v2 03/10] usb: dwc2/gadget: fix gadget unregistration in udc_stop() function Marek Szyprowski
[not found] ` <1413801940-31086-4-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-10-23 15:01 ` Felipe Balbi
2014-10-23 18:18 ` Paul Zimmerman
[not found] ` <A2CA0424C0A6F04399FB9E1CD98E0304844E5483-Yu2iAY70zvrYN67daEjeMPufCSb+aD3WLzEdoUbNIic@public.gmane.org>
2014-10-23 18:56 ` Felipe Balbi
2014-10-20 10:45 ` [PATCH v2 04/10] usb: dwc2/gadget: disable phy before turning off power regulators Marek Szyprowski
[not found] ` <1413801940-31086-5-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-10-23 15:01 ` Felipe Balbi
2014-10-23 18:15 ` Paul Zimmerman
2014-10-23 18:58 ` Felipe Balbi
2014-10-20 10:45 ` [PATCH v2 06/10] usb: dwc2/gadget: decouple setting soft-disconnect from s3c_hsotg_core_init Marek Szyprowski
2014-10-25 0:35 ` Paul Zimmerman
2014-10-27 13:52 ` Marek Szyprowski
2014-10-20 10:45 ` [PATCH v2 09/10] usb: dwc2/gadget: fix calls to phy control functions in suspend/resume code Marek Szyprowski
2014-10-25 0:45 ` Paul Zimmerman
2014-10-20 10:45 ` [PATCH v2 10/10] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state Marek Szyprowski
2014-10-25 1:16 ` Paul Zimmerman
2014-10-27 7:18 ` Marek Szyprowski
2014-10-31 10:08 ` Marek Szyprowski
2014-10-31 10:12 ` [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls Marek Szyprowski
2014-10-31 10:12 ` [PATCH v3 2/2] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state Marek Szyprowski
2014-10-31 18:46 ` [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls Paul Zimmerman
[not found] ` <A2CA0424C0A6F04399FB9E1CD98E0304844E7FDD-Yu2iAY70zvrYN67daEjeMPufCSb+aD3WLzEdoUbNIic@public.gmane.org>
2014-11-13 15:17 ` Marek Szyprowski
2014-11-13 20:55 ` Paul Zimmerman
2014-11-14 9:19 ` Marek Szyprowski [this message]
2014-11-14 19:43 ` Paul Zimmerman
2014-11-14 19:51 ` Felipe Balbi
[not found] ` <1414750354-19571-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-11-18 21:00 ` Paul Zimmerman
2014-11-20 19:53 ` Felipe Balbi
2014-10-20 10:45 ` [PATCH v2 05/10] usb: dwc2/gadget: move setting last reset time to s3c_hsotg_core_init Marek Szyprowski
[not found] ` <1413801940-31086-6-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-10-25 0:23 ` Paul Zimmerman
2014-10-20 10:45 ` [PATCH v2 07/10] usb: dwc2/gadget: move phy control calls out of pullup() method Marek Szyprowski
2014-10-25 0:36 ` Paul Zimmerman
2014-10-20 10:45 ` [PATCH v2 08/10] usb: dwc2/gadget: use soft-disconnect udc feature in " Marek Szyprowski
2014-10-25 0:43 ` Paul Zimmerman
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=5465C91C.7050409@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=Paul.Zimmerman@synopsys.com \
--cc=balbi@ti.com \
--cc=k.kozlowski@samsung.com \
--cc=kyungmin.park@samsung.com \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=r.baldyga@samsung.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.