Browse Source

增加通知接口让应用层启动usb恢复机制,解决usb 插拔出现错误无法识别的问题

huangliang 2 years ago
parent
commit
6e1dc15b85
1 changed files with 16 additions and 1 deletions
  1. 16 1
      linux/drivers/usb/core/hub.c

+ 16 - 1
linux/drivers/usb/core/hub.c

@@ -2818,6 +2818,20 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
 	return 0;
 }
 
+static void hub_port_error_notify(struct usb_device *udev)
+{
+	char port_state[32] = { 0 };
+	char *envp[] = { port_state, NULL };
+
+	if (udev && udev->bus) {
+		snprintf(port_state, ARRAY_SIZE(port_state),
+					 "USB_ERR_PORT_NUM=%d", udev->bus->busnum - 1);
+		printk("hub port error notify name:%s at bus:%d\n", dev_name(&udev->dev), udev->bus->busnum);
+	
+		kobject_uevent_env(&udev->dev.kobj, KOBJ_CHANGE, envp);
+	}
+}
+
 /* Handle port reset and port warm(BH) reset (for USB3 protocol ports) */
 static int hub_port_reset(struct usb_hub *hub, int port1,
 			struct usb_device *udev, unsigned int delay, bool warm)
@@ -2914,7 +2928,8 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
 				warm ? "warm " : "");
 		delay = HUB_LONG_RESET_TIME;
 	}
-
+	
+	hub_port_error_notify(udev);
 	dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n");
 
 done: