Browse Source

Merge git://git.denx.de/u-boot-usb

Tom Rini 10 years ago
parent
commit
48f892dc73

+ 19 - 4
common/cmd_dfu.c

@@ -15,6 +15,8 @@
 
 
 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 {
+	bool dfu_reset = false;
+
 	if (argc < 4)
 	if (argc < 4)
 		return CMD_RET_USAGE;
 		return CMD_RET_USAGE;
 
 
@@ -36,17 +38,28 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 
 	int controller_index = simple_strtoul(usb_controller, NULL, 0);
 	int controller_index = simple_strtoul(usb_controller, NULL, 0);
 	board_usb_init(controller_index, USB_INIT_DEVICE);
 	board_usb_init(controller_index, USB_INIT_DEVICE);
-
+	dfu_clear_detach();
 	g_dnl_register("usb_dnl_dfu");
 	g_dnl_register("usb_dnl_dfu");
 	while (1) {
 	while (1) {
-		if (dfu_reset())
+		if (dfu_detach()) {
+			/*
+			 * Check if USB bus reset is performed after detach,
+			 * which indicates that -R switch has been passed to
+			 * dfu-util. In this case reboot the device
+			 */
+			if (dfu_usb_get_reset()) {
+				dfu_reset = true;
+				goto exit;
+			}
+
 			/*
 			/*
 			 * This extra number of usb_gadget_handle_interrupts()
 			 * This extra number of usb_gadget_handle_interrupts()
 			 * calls is necessary to assure correct transmission
 			 * calls is necessary to assure correct transmission
 			 * completion with dfu-util
 			 * completion with dfu-util
 			 */
 			 */
-			if (++i == 10)
+			if (++i == 10000)
 				goto exit;
 				goto exit;
+		}
 
 
 		if (ctrlc())
 		if (ctrlc())
 			goto exit;
 			goto exit;
@@ -58,9 +71,11 @@ exit:
 done:
 done:
 	dfu_free_entities();
 	dfu_free_entities();
 
 
-	if (dfu_reset())
+	if (dfu_reset)
 		run_command("reset", 0);
 		run_command("reset", 0);
 
 
+	dfu_clear_detach();
+
 	return ret;
 	return ret;
 }
 }
 
 

+ 26 - 5
drivers/dfu/dfu.c

@@ -17,20 +17,41 @@
 #include <linux/list.h>
 #include <linux/list.h>
 #include <linux/compiler.h>
 #include <linux/compiler.h>
 
 
-static bool dfu_reset_request;
+static bool dfu_detach_request;
 static LIST_HEAD(dfu_list);
 static LIST_HEAD(dfu_list);
 static int dfu_alt_num;
 static int dfu_alt_num;
 static int alt_num_cnt;
 static int alt_num_cnt;
 static struct hash_algo *dfu_hash_algo;
 static struct hash_algo *dfu_hash_algo;
 
 
-bool dfu_reset(void)
+/*
+ * The purpose of the dfu_usb_get_reset() function is to
+ * provide information if after USB_DETACH request
+ * being sent the dfu-util performed reset of USB
+ * bus.
+ *
+ * Described behaviour is the only way to distinct if
+ * user has typed -e (detach) or -R (reset) when invoking
+ * dfu-util command.
+ *
+ */
+__weak bool dfu_usb_get_reset(void)
+{
+	return true;
+}
+
+bool dfu_detach(void)
+{
+	return dfu_detach_request;
+}
+
+void dfu_trigger_detach(void)
 {
 {
-	return dfu_reset_request;
+	dfu_detach_request = true;
 }
 }
 
 
-void dfu_trigger_reset()
+void dfu_clear_detach(void)
 {
 {
-	dfu_reset_request = true;
+	dfu_detach_request = false;
 }
 }
 
 
 static int dfu_find_alt_num(const char *s)
 static int dfu_find_alt_num(const char *s)

+ 6 - 6
drivers/usb/gadget/atmel_usba_udc.c

@@ -171,7 +171,7 @@ usba_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
 {
 {
 	struct usba_ep *ep = to_usba_ep(_ep);
 	struct usba_ep *ep = to_usba_ep(_ep);
 	struct usba_udc *udc = ep->udc;
 	struct usba_udc *udc = ep->udc;
-	unsigned long flags, ept_cfg, maxpacket;
+	unsigned long flags = 0, ept_cfg, maxpacket;
 	unsigned int nr_trans;
 	unsigned int nr_trans;
 
 
 	DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc);
 	DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc);
@@ -274,7 +274,7 @@ static int usba_ep_disable(struct usb_ep *_ep)
 	struct usba_ep *ep = to_usba_ep(_ep);
 	struct usba_ep *ep = to_usba_ep(_ep);
 	struct usba_udc *udc = ep->udc;
 	struct usba_udc *udc = ep->udc;
 	LIST_HEAD(req_list);
 	LIST_HEAD(req_list);
-	unsigned long flags;
+	unsigned long flags = 0;
 
 
 	DBG(DBG_GADGET, "ep_disable: %s\n", ep->ep.name);
 	DBG(DBG_GADGET, "ep_disable: %s\n", ep->ep.name);
 
 
@@ -339,7 +339,7 @@ usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 	struct usba_request *req = to_usba_req(_req);
 	struct usba_request *req = to_usba_req(_req);
 	struct usba_ep *ep = to_usba_ep(_ep);
 	struct usba_ep *ep = to_usba_ep(_ep);
 	struct usba_udc *udc = ep->udc;
 	struct usba_udc *udc = ep->udc;
-	unsigned long flags;
+	unsigned long flags = 0;
 	int ret;
 	int ret;
 
 
 	DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ, "%s: queue req %p, len %u\n",
 	DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ, "%s: queue req %p, len %u\n",
@@ -401,7 +401,7 @@ static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 static int usba_ep_set_halt(struct usb_ep *_ep, int value)
 static int usba_ep_set_halt(struct usb_ep *_ep, int value)
 {
 {
 	struct usba_ep *ep = to_usba_ep(_ep);
 	struct usba_ep *ep = to_usba_ep(_ep);
-	unsigned long flags;
+	unsigned long flags = 0;
 	int ret = 0;
 	int ret = 0;
 
 
 	DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep->ep.name,
 	DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep->ep.name,
@@ -480,7 +480,7 @@ static int usba_udc_get_frame(struct usb_gadget *gadget)
 static int usba_udc_wakeup(struct usb_gadget *gadget)
 static int usba_udc_wakeup(struct usb_gadget *gadget)
 {
 {
 	struct usba_udc *udc = to_usba_udc(gadget);
 	struct usba_udc *udc = to_usba_udc(gadget);
-	unsigned long flags;
+	unsigned long flags = 0;
 	u32 ctrl;
 	u32 ctrl;
 	int ret = -EINVAL;
 	int ret = -EINVAL;
 
 
@@ -499,7 +499,7 @@ static int
 usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
 usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
 {
 {
 	struct usba_udc *udc = to_usba_udc(gadget);
 	struct usba_udc *udc = to_usba_udc(gadget);
-	unsigned long flags;
+	unsigned long flags = 0;
 
 
 	spin_lock_irqsave(&udc->lock, flags);
 	spin_lock_irqsave(&udc->lock, flags);
 	if (is_selfpowered)
 	if (is_selfpowered)

+ 7 - 0
drivers/usb/gadget/ci_udc.c

@@ -919,3 +919,10 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 
 
 	return 0;
 	return 0;
 }
 }
+
+bool dfu_usb_get_reset(void)
+{
+	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
+
+	return !!(readl(&udc->usbsts) & STS_URI);
+}

+ 1 - 1
drivers/usb/gadget/f_dfu.c

@@ -372,7 +372,7 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
 		to_runtime_mode(f_dfu);
 		to_runtime_mode(f_dfu);
 		f_dfu->dfu_state = DFU_STATE_appIDLE;
 		f_dfu->dfu_state = DFU_STATE_appIDLE;
 
 
-		dfu_trigger_reset();
+		dfu_trigger_detach();
 		break;
 		break;
 	default:
 	default:
 		f_dfu->dfu_state = DFU_STATE_dfuERROR;
 		f_dfu->dfu_state = DFU_STATE_dfuERROR;

+ 10 - 5
drivers/usb/gadget/s3c_udc_otg.c

@@ -149,6 +149,11 @@ struct s3c_usbotg_reg *reg;
 struct s3c_usbotg_phy *phy;
 struct s3c_usbotg_phy *phy;
 static unsigned int usb_phy_ctrl;
 static unsigned int usb_phy_ctrl;
 
 
+bool dfu_usb_get_reset(void)
+{
+	return !!(readl(&reg->gintsts) & INT_RESET);
+}
+
 void otg_phy_init(struct s3c_udc *dev)
 void otg_phy_init(struct s3c_udc *dev)
 {
 {
 	dev->pdata->phy_control(1);
 	dev->pdata->phy_control(1);
@@ -283,7 +288,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 {
 {
 	struct s3c_udc *dev = the_controller;
 	struct s3c_udc *dev = the_controller;
 	int retval = 0;
 	int retval = 0;
-	unsigned long flags;
+	unsigned long flags = 0;
 
 
 	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 	debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
 
 
@@ -331,7 +336,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 {
 {
 	struct s3c_udc *dev = the_controller;
 	struct s3c_udc *dev = the_controller;
-	unsigned long flags;
+	unsigned long flags = 0;
 
 
 	if (!dev)
 	if (!dev)
 		return -ENODEV;
 		return -ENODEV;
@@ -575,7 +580,7 @@ static int s3c_ep_enable(struct usb_ep *_ep,
 {
 {
 	struct s3c_ep *ep;
 	struct s3c_ep *ep;
 	struct s3c_udc *dev;
 	struct s3c_udc *dev;
-	unsigned long flags;
+	unsigned long flags = 0;
 
 
 	debug("%s: %p\n", __func__, _ep);
 	debug("%s: %p\n", __func__, _ep);
 
 
@@ -639,7 +644,7 @@ static int s3c_ep_enable(struct usb_ep *_ep,
 static int s3c_ep_disable(struct usb_ep *_ep)
 static int s3c_ep_disable(struct usb_ep *_ep)
 {
 {
 	struct s3c_ep *ep;
 	struct s3c_ep *ep;
-	unsigned long flags;
+	unsigned long flags = 0;
 
 
 	debug("%s: %p\n", __func__, _ep);
 	debug("%s: %p\n", __func__, _ep);
 
 
@@ -697,7 +702,7 @@ static int s3c_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 {
 {
 	struct s3c_ep *ep;
 	struct s3c_ep *ep;
 	struct s3c_request *req;
 	struct s3c_request *req;
-	unsigned long flags;
+	unsigned long flags = 0;
 
 
 	debug("%s: %p\n", __func__, _ep);
 	debug("%s: %p\n", __func__, _ep);
 
 

+ 3 - 3
drivers/usb/gadget/s3c_udc_otg_xfer_dma.c

@@ -466,7 +466,7 @@ static int s3c_udc_irq(int irq, void *_dev)
 	struct s3c_udc *dev = _dev;
 	struct s3c_udc *dev = _dev;
 	u32 intr_status;
 	u32 intr_status;
 	u32 usb_status, gintmsk;
 	u32 usb_status, gintmsk;
-	unsigned long flags;
+	unsigned long flags = 0;
 
 
 	spin_lock_irqsave(&dev->lock, flags);
 	spin_lock_irqsave(&dev->lock, flags);
 
 
@@ -585,7 +585,7 @@ static int s3c_queue(struct usb_ep *_ep, struct usb_request *_req,
 	struct s3c_request *req;
 	struct s3c_request *req;
 	struct s3c_ep *ep;
 	struct s3c_ep *ep;
 	struct s3c_udc *dev;
 	struct s3c_udc *dev;
-	unsigned long flags;
+	unsigned long flags = 0;
 	u32 ep_num, gintsts;
 	u32 ep_num, gintsts;
 
 
 	req = container_of(_req, struct s3c_request, req);
 	req = container_of(_req, struct s3c_request, req);
@@ -1033,7 +1033,7 @@ static int s3c_udc_set_halt(struct usb_ep *_ep, int value)
 {
 {
 	struct s3c_ep	*ep;
 	struct s3c_ep	*ep;
 	struct s3c_udc	*dev;
 	struct s3c_udc	*dev;
-	unsigned long	flags;
+	unsigned long	flags = 0;
 	u8		ep_num;
 	u8		ep_num;
 
 
 	ep = container_of(_ep, struct s3c_ep, ep);
 	ep = container_of(_ep, struct s3c_ep, ep);

+ 4 - 1
include/dfu.h

@@ -150,11 +150,14 @@ struct dfu_entity *dfu_get_entity(int alt);
 char *dfu_extract_token(char** e, int *n);
 char *dfu_extract_token(char** e, int *n);
 void dfu_trigger_reset(void);
 void dfu_trigger_reset(void);
 int dfu_get_alt(char *name);
 int dfu_get_alt(char *name);
-bool dfu_reset(void);
+bool dfu_detach(void);
+void dfu_trigger_detach(void);
+void dfu_clear_detach(void);
 int dfu_init_env_entities(char *interface, char *devstr);
 int dfu_init_env_entities(char *interface, char *devstr);
 unsigned char *dfu_get_buf(struct dfu_entity *dfu);
 unsigned char *dfu_get_buf(struct dfu_entity *dfu);
 unsigned char *dfu_free_buf(void);
 unsigned char *dfu_free_buf(void);
 unsigned long dfu_get_buf_size(void);
 unsigned long dfu_get_buf_size(void);
+bool dfu_usb_get_reset(void);
 
 
 int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
 int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
 int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
 int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);