Skip to contentSkip to conversation

usb: properly re-initialize the USB keyboard.

PATCH New Simon Glass 3 participants 7 messages May 11, 2013 – May 13, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 usb: properly re-initialize the USB keyboard.

From: Vincent Palatin <[email protected]>

Allow to reconfigure properly the USB keyboard driver when we enumerate several times the USB devices and its position in the device tree has changes.

---
 common/usb_kbd.c | 1 +
 1 file changed, 1 insertion(+)
common/usb_kbd.c +1 -0
index b962849..188763d 100644
@@ -496,6 +496,7 @@ int drv_usb_kbd_init(void)
 		if (old_dev) {
 			/* Already registered, just return ok. */
 			debug("USB KBD: is already registered.\n");
+			usb_kbd_deregister();
 			return 1;
 		}
 
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH 2/3 usb: workaround non-working keyboards.

From: Vincent Palatin <[email protected]>

If the USB keyboard is not answering properly the first request on its interrupt endpoint, just skip it and try the next one.

This workarounds an issue with a wireless mouse dongle which presents itself both as a keyboard and a mouse but has a non-functional keyboard interface.

(cherry picked from commit 012bbf0ce0301be2482857e3f03b481dd15c2340)

Rebased to upstream/master:

---
 common/usb_kbd.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
common/usb_kbd.c +7 -2
index 188763d..3174b5e 100644
@@ -461,8 +461,13 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum)
 	usb_set_idle(dev, iface->desc.bInterfaceNumber, REPEAT_RATE, 0);
 
 	debug("USB KBD: enable interrupt pipe...\n");
-	usb_submit_int_msg(dev, pipe, data->new, maxp > 8 ? 8 : maxp,
-				ep->bInterval);
+	if (usb_submit_int_msg(dev, pipe, data->new, maxp > 8 ? 8 : maxp,
+			       ep->bInterval) < 0) {
+		printf("Failed to get keyboard state from device %04x:%04x\n",
+		       dev->descriptor.idVendor, dev->descriptor.idProduct);
+		/* Abort, we don't want to use that non-functional keyboard. */
+		return 0;
+	}
 
 	/* Success. */
 	return 1;
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH 3/3 usb: Correct CLEAR_FEATURE code in ehci-hcd

In reply to Simon Glass

This commit broke USB2 on link (Chromebook Pixel):

020bbcb usb: hub: Power-cycle on root-hub ports

However the root cause seems to be a missing mask and missing 'break' in ehci-hcd.c. This patch fixes both.

On link, 'usb start' with a USB keyboard and memory stick inserted now finds both. The keyboard works as expected. Also ext2ls shows a directory listing from the memory stick.

---
 drivers/usb/host/ehci-hcd.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/usb/host/ehci-hcd.c +6 -4
index e0f3e4b..445759b 100644
@@ -809,21 +809,23 @@ ehci_submit_root(struct usb_device *dev, unsigned long pipe, void *buffer,
 		break;
 	case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8):
 		reg = ehci_readl(status_reg);
+		reg &= ~EHCI_PS_CLEAR;
 		switch (le16_to_cpu(req->value)) {
 		case USB_PORT_FEAT_ENABLE:
 			reg &= ~EHCI_PS_PE;
 			break;
 		case USB_PORT_FEAT_C_ENABLE:
-			reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_PE;
+			reg |= EHCI_PS_PE;
 			break;
 		case USB_PORT_FEAT_POWER:
 			if (HCS_PPC(ehci_readl(&ctrl->hccr->cr_hcsparams)))
-				reg = reg & ~(EHCI_PS_CLEAR | EHCI_PS_PP);
+				reg &= ~EHCI_PS_PP;
+			break;
 		case USB_PORT_FEAT_C_CONNECTION:
-			reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_CSC;
+			reg |= EHCI_PS_CSC;
 			break;
 		case USB_PORT_FEAT_OVER_CURRENT:
-			reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_OCC;
+			reg |= EHCI_PS_OCC;
 			break;
 		case USB_PORT_FEAT_C_RESET:
 			ctrl->portreset &= ~(1 << port);
Signature · 1 line
1.8.2.1
#3 lore raw

PATCH 3/3 usb: Correct CLEAR_FEATURE code in ehci-hcd

Dear Simon Glass,

Quoted 4 lines

This commit broke USB2 on link (Chromebook Pixel):

020bbcb usb: hub: Power-cycle on root-hub ports

Quoted 8 lines

However the root cause seems to be a missing mask and missing 'break' in ehci-hcd.c. This patch fixes both.

On link, 'usb start' with a USB keyboard and memory stick inserted now finds both. The keyboard works as expected. Also ext2ls shows a directory listing from the memory stick.

Picking up all three, thanks!

Best regards,
Marek Vasut

#4 lore raw

PATCH 3/3 usb: Correct CLEAR_FEATURE code in ehci-hcd

Quoted 9 lines · Marek Vasut

Dear Simon Glass,

Quoted 7 lines

This commit broke USB2 on link (Chromebook Pixel):

020bbcb usb: hub: Power-cycle on root-hub ports

However the root cause seems to be a missing mask and missing 'break' in ehci-hcd.c. This patch fixes both.

Quoted 7 lines
Quoted 5 lines

On link, 'usb start' with a USB keyboard and memory stick inserted now finds both. The keyboard works as expected. Also ext2ls shows a directory listing from the memory stick.

Picking up all three, thanks!

Thanks, also Julius may have some comments on Monday. Two of the patches were reviewed by him, but not the last one, although he suggested it.

Regards,
Simon

Quoted 3 lines

Best regards,
Marek Vasut

#5 lore raw

PATCH 3/3 usb: Correct CLEAR_FEATURE code in ehci-hcd

Dear Simon Glass,

Quoted 13 lines · Marek Vasut
Quoted 12 lines

Dear Simon Glass,

Quoted 10 lines

This commit broke USB2 on link (Chromebook Pixel):
020bbcb usb: hub: Power-cycle on root-hub ports

However the root cause seems to be a missing mask and missing 'break' in ehci-hcd.c. This patch fixes both.

On link, 'usb start' with a USB keyboard and memory stick inserted now finds both. The keyboard works as expected. Also ext2ls shows a directory listing from the memory stick.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Picking up all three, thanks!

Thanks, also Julius may have some comments on Monday. Two of the patches were reviewed by him, but not the last one, although he suggested it.

I just build-tested them, seem OK.

btw. I might be less available this month, sorry about that.

Best regards,
Marek Vasut

#6 lore raw

PATCH 3/3 usb: Correct CLEAR_FEATURE code in ehci-hcd

Thanks for taking charge of this Simon, looks good to me. Good catch with the missing break!

Now that I look at it, the FEAT_C_ENABLE section seems to be broken as well, it should be setting EHCI_PS_PEC instead of EHCI_PS_PE. Maybe that code path is never used in practice.