From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [patch 1/2] fix USB initialisation procedure
Date: Thu, 9 Oct 2008 14:10:44 +0200 [thread overview]
Message-ID: <20081009121044.GA25278@game.jcrosoft.org> (raw)
In-Reply-To: <20081008091415.451775709@bohmer.net>
On 10:54 Wed 08 Oct , Remy Bohmer wrote:
> The max packet size is encoded as 0,1,2,3 for 8,16,32,64 bytes.
> At some places directly 8,16,32,64 was used instead of the encoded
> value. Made a enum for the options to make this more clear and to help
> preventing similar errors in the future.
>
> After fixing this bug it became clear that another bug existed where
> the 'pipe' is and-ed with PIPE_* flags, where it should have been
> 'usb_pipetype(pipe)', or even better usb_pipeint(pipe).
>
> Also removed the triple 'get_device_descriptor' sequence, it has no use,
> and Windows nor Linux behaves that way.
> There is also a poll going on with a timeout when usb_control_msg() fails.
> However, the poll is useless, because the flag will never be set on a error,
> because there is no code that runs in a parallel that can set this flag.
> Changed this to something more logical.
>
> Tested on AT91SAM9261ek and compared the flow on the USB bus to what
> Linux is doing. There is no difference anymore in the early initialisation
> sequence.
>
> Signed-off-by: Remy Bohmer <linux@bohmer.net>
> ---
> common/usb.c | 50 +++++++++++++++++++++++--------------------------
> drivers/usb/usb_ohci.c | 14 +++++--------
> include/usb.h | 16 ++++++++++++---
> 3 files changed, 43 insertions(+), 37 deletions(-)
>
> Index: u-boot-git-22092008/common/usb.c
> ===================================================================
> --- u-boot-git-22092008.orig/common/usb.c 2008-10-08 10:51:49.000000000 +0200
> +++ u-boot-git-22092008/common/usb.c 2008-10-08 10:51:50.000000000 +0200
> @@ -196,15 +196,14 @@ int usb_control_msg(struct usb_device *d
> if (timeout == 0)
> return (int)size;
>
> - while (timeout--) {
> - if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
> - break;
> - wait_ms(1);
> - }
> if (dev->status == 0)
> return dev->act_len;
please add {}?to if too or remove the else
> - else
> + else {
> + /* Let's wait a while for the timeout to elaps.
> + * it has no real use, but it keeps the interface happy. */
> + wait_ms(timeout);
> return -1;
> + }
> }
>
> /*-------------------------------------------------------------------
> @@ -442,14 +441,14 @@ int usb_get_configuration_no(struct usb_
>
>
> config = (struct usb_config_descriptor *)&buffer[0];
> - result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 8);
> struct usb_device *parent = dev->parent;
> @@ -809,20 +805,22 @@ int usb_new_device(struct usb_device *de
>
> desc = (struct usb_device_descriptor *)tmpbuf;
> dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */
> - dev->maxpacketsize = 64; /* Default to 64 byte max packet size */
> + /* Default to 64 byte max packet size */
> + dev->maxpacketsize = PACKET_SIZE_64;
> dev->epmaxpacketin [0] = 64;
> dev->epmaxpacketout[0] = 64;
> - for (j = 0; j < 3; ++j) {
> - err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
> - if (err < 0) {
> - USB_PRINTF("usb_new_device: 64 byte descr\n");
> - break;
> - }
> +
> + err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
> + if (err < 0) {
> + USB_PRINTF("usb_new_device: usb_get_descriptor() failed\n");
> + return 1;
> }
> +
> Index: u-boot-git-22092008/include/usb.h
> ===================================================================
> --- u-boot-git-22092008.orig/include/usb.h 2008-10-08 10:51:45.000000000 +0200
> +++ u-boot-git-22092008/include/usb.h 2008-10-08 10:51:50.000000000 +0200
> @@ -129,6 +129,13 @@ struct usb_config_descriptor {
> struct usb_interface_descriptor if_desc[USB_MAXINTERFACES];
> } __attribute__ ((packed));
>
> +enum {
> + /* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
> + PACKET_SIZE_8 = 0,
> + PACKET_SIZE_16 = 1,
> + PACKET_SIZE_32 = 2,
> + PACKET_SIZE_64 = 3,
why not diectly the value?
> +};
>
> struct usb_device {
> int devnum; /* Device number on USB bus */
> @@ -137,9 +144,12 @@ struct usb_device {
> char prod[32]; /* product */
> char serial[32]; /* serial number */
>
> - int maxpacketsize; /* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
Best Regards,
J.
next prev parent reply other threads:[~2008-10-09 12:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-08 8:54 [U-Boot] [patch 0/2] Some more USB-OHCI bugfixes Remy Bohmer
2008-10-08 8:54 ` [U-Boot] [patch 1/2] fix USB initialisation procedure Remy Bohmer
2008-10-09 12:10 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2008-10-09 13:19 ` Wolfgang Denk
2008-10-09 14:43 ` Markus Klotzbücher
2008-10-09 14:59 ` Stefan Roese
2008-10-09 15:09 ` Markus Klotzbücher
2008-10-09 15:22 ` Jerry Van Baren
2008-10-09 18:45 ` Wolfgang Denk
2008-10-09 19:52 ` Markus Klotzbücher
2008-10-10 7:30 ` Remy Bohmer
2008-10-09 18:42 ` Wolfgang Denk
2008-10-08 8:54 ` [U-Boot] [patch 2/2] The PIPE_INTERRUPT flag is used wrong Remy Bohmer
2008-10-08 10:12 ` [U-Boot] [patch 0/2] Some more USB-OHCI bugfixes Markus Klotzbücher
2008-10-08 10:41 ` Stelian Pop
2008-10-09 8:33 ` Stelian Pop
2008-10-09 9:51 ` Remy Bohmer
2008-10-09 15:01 ` Stelian Pop
2008-10-10 7:21 ` Remy Bohmer
2008-10-10 8:25 ` Stelian Pop
2008-10-10 8:33 ` Remy Bohmer
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=20081009121044.GA25278@game.jcrosoft.org \
--to=plagnioj@jcrosoft.com \
--cc=u-boot@lists.denx.de \
/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