diff mbox

[U-Boot] usb_ether: register usb ethernet gadget at each eth init

Message ID 1291218223-22511-1-git-send-email-leiwen@marvell.com
State Accepted
Commit 988ee3e3f024f4565f98584b9026df73c459c268
Headers show

Commit Message

Lei Wen Dec. 1, 2010, 3:43 p.m. UTC
Since the ether may not be the only one usb gadget would be used
in the uboot, it is neccessary to do the register each time the
eth begin to work to make usb gadget driver less confussed when
we want to use two different usb gadget at the same time.

Usb gadget driver could simple ignore the register operation, if
it find the driver has been registered already.

Signed-off-by: Lei Wen <leiwen@marvell.com>
---
V1: delete the usb_gadget_register_driver in usb_eth_initialize,
    and judge whether gadget is registered at eth_halt.

 drivers/usb/gadget/ether.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

Comments

Vitaly Kuzmichev Dec. 2, 2010, 4:34 p.m. UTC | #1
Hi Lei,

Lei Wen wrote:
> Since the ether may not be the only one usb gadget would be used
> in the uboot, it is neccessary to do the register each time the
> eth begin to work to make usb gadget driver less confussed when
> we want to use two different usb gadget at the same time.
> 
> Usb gadget driver could simple ignore the register operation, if
> it find the driver has been registered already.
> 
> Signed-off-by: Lei Wen <leiwen@marvell.com>

Tested, works fine on my board.

BTW, for future reference the tags in the subject should be [U-Boot]
[PATCH v2]. v2 points to that this is an improved/fixed version of a
patch previously submitted.
This can be reached using --subject-prefix="U-Boot] [PATCH v2" passed to
git format-patch command.
Lei Wen Dec. 3, 2010, 2:35 a.m. UTC | #2
Hi Vitaly,

On Fri, Dec 3, 2010 at 12:34 AM, Vitaly Kuzmichev <vkuzmichev@mvista.com> wrote:
> Hi Lei,
>
> Lei Wen wrote:
>> Since the ether may not be the only one usb gadget would be used
>> in the uboot, it is neccessary to do the register each time the
>> eth begin to work to make usb gadget driver less confussed when
>> we want to use two different usb gadget at the same time.
>>
>> Usb gadget driver could simple ignore the register operation, if
>> it find the driver has been registered already.
>>
>> Signed-off-by: Lei Wen <leiwen@marvell.com>
>
> Tested, works fine on my board.
>
> BTW, for future reference the tags in the subject should be [U-Boot]
> [PATCH v2]. v2 points to that this is an improved/fixed version of a
> patch previously submitted.
> This can be reached using --subject-prefix="U-Boot] [PATCH v2" passed to
> git format-patch command.
>

Got that. Thanks for testing. :-)

Best regards,
Lei
Remy Bohmer Dec. 9, 2010, 6:53 p.m. UTC | #3
Hi,

2010/12/1 Lei Wen <leiwen@marvell.com>:
> Since the ether may not be the only one usb gadget would be used
> in the uboot, it is neccessary to do the register each time the
> eth begin to work to make usb gadget driver less confussed when
> we want to use two different usb gadget at the same time.
>
> Usb gadget driver could simple ignore the register operation, if
> it find the driver has been registered already.
>
> Signed-off-by: Lei Wen <leiwen@marvell.com>
> ---
> V1: delete the usb_gadget_register_driver in usb_eth_initialize,
>    and judge whether gadget is registered at eth_halt.
>
>  drivers/usb/gadget/ether.c |   12 ++++++++----
>  1 files changed, 8 insertions(+), 4 deletions(-)
>

Applied to u-boot-usb.
Thanks.

Remy
diff mbox

Patch

diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 5a18e03..261cf7e 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -1456,6 +1456,7 @@  static void eth_unbind(struct usb_gadget *gadget)
 /*	unregister_netdev (dev->net);*/
 /*	free_netdev(dev->net);*/
 
+	dev->gadget = NULL;
 	set_gadget_data(gadget, NULL);
 }
 
@@ -1788,6 +1789,8 @@  static int usb_eth_init(struct eth_device *netdev, bd_t *bd)
 		error("received NULL ptr");
 		goto fail;
 	}
+	if (usb_gadget_register_driver(&eth_driver) < 0)
+		goto fail;
 
 	dev->network_started = 0;
 
@@ -1895,7 +1898,12 @@  void usb_eth_halt(struct eth_device *netdev)
 		return;
 	}
 
+	/* If the gadget not registered, simple return */
+	if (!dev->gadget)
+		return;
+
 	usb_gadget_disconnect(dev->gadget);
+	usb_gadget_unregister_driver(&eth_driver);
 }
 
 static struct usb_gadget_driver eth_driver = {
@@ -1957,10 +1965,6 @@  int usb_eth_initialize(bd_t *bi)
 	if (status)
 		goto fail;
 
-	status = usb_gadget_register_driver(&eth_driver);
-	if (status < 0)
-		goto fail;
-
 	eth_register(netdev);
 	return 0;