dwc3: core: add support for multiple dwc3 controllers
authorKishon Vijay Abraham I <kishon@ti.com>
Mon, 23 Feb 2015 13:10:05 +0000 (18:40 +0530)
committerMarek Vasut <marex@denx.de>
Tue, 14 Apr 2015 03:48:10 +0000 (05:48 +0200)
Added support for multiple dwc3 controllers. This gives uboot
the capability to control multiple dwc3 controllers.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
drivers/usb/dwc3/core.c
drivers/usb/dwc3/core.h
include/dwc3-uboot.h

index 58c3bfdbfed6deff4bb803f40068a13f6e392552..bd34dbd23c877e345da16daf58b73d7f31643ee1 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "linux-compat.h"
 
-struct dwc3 *dwc;
+static LIST_HEAD(dwc3_list);
 /* -------------------------------------------------------------------------- */
 
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
@@ -612,6 +612,7 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
  */
 int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 {
+       struct dwc3             *dwc;
        struct device           *dev;
        u8                      lpm_nyet_threshold;
        u8                      tx_de_emphasis;
@@ -678,6 +679,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
        dwc->hird_threshold = hird_threshold
                | (dwc->is_utmi_l1_suspend << 4);
 
+       dwc->index = dwc3_dev->index;
+
        dwc3_cache_hwparams(dwc);
 
        ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
@@ -710,6 +713,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
        if (ret)
                goto err2;
 
+       list_add_tail(&dwc->list, &dwc3_list);
+
        return 0;
 
 err2:
@@ -729,17 +734,28 @@ err0:
  * @index: index of this controller
  *
  * Performs cleanup of memory allocated in dwc3_uboot_init and other misc
- * cleanups (equivalent to dwc3_remove in linux).
+ * cleanups (equivalent to dwc3_remove in linux). index of _this_ controller
+ * should be passed and should match with the index passed in
+ * dwc3_device during init.
  *
  * Generally called from board file.
  */
-void dwc3_uboot_exit()
+void dwc3_uboot_exit(int index)
 {
-       dwc3_core_exit_mode(dwc);
-       dwc3_event_buffers_cleanup(dwc);
-       dwc3_free_event_buffers(dwc);
-       dwc3_core_exit(dwc);
-       kfree(dwc->mem);
+       struct dwc3 *dwc;
+
+       list_for_each_entry(dwc, &dwc3_list, list) {
+               if (dwc->index != index)
+                       continue;
+
+               dwc3_core_exit_mode(dwc);
+               dwc3_event_buffers_cleanup(dwc);
+               dwc3_free_event_buffers(dwc);
+               dwc3_core_exit(dwc);
+               list_del(&dwc->list);
+               kfree(dwc->mem);
+               break;
+       }
 }
 
 MODULE_ALIAS("platform:dwc3");
index 0d507c106ee38b05577ac8577a010b0df1020ce4..c5debf7d28e58ec82e53aaec6dc302765e2a365e 100644 (file)
@@ -695,6 +695,8 @@ struct dwc3_scratchpad_array {
  *     1       - -3.5dB de-emphasis
  *     2       - No de-emphasis
  *     3       - Reserved
+ * @index: index of _this_ controller
+ * @list: to maintain the list of dwc3 controllers
  */
 struct dwc3 {
        struct usb_ctrlrequest  *ctrl_req;
@@ -811,6 +813,8 @@ struct dwc3 {
 
        unsigned                tx_de_emphasis_quirk:1;
        unsigned                tx_de_emphasis:2;
+       int                     index;
+       struct list_head        list;
 };
 
 /* -------------------------------------------------------------------------- */
index 6d1b42af0395efccaf9ba07013c054a380287922..272a0207b37fab98514d84a7f1f13755db04f166 100644 (file)
@@ -33,8 +33,9 @@ struct dwc3_device {
        unsigned dis_u2_susphy_quirk;
        unsigned tx_de_emphasis_quirk;
        unsigned tx_de_emphasis;
+       int index;
 };
 
 int dwc3_uboot_init(struct dwc3_device *dev);
-void dwc3_uboot_exit(void);
+void dwc3_uboot_exit(int index);
 #endif /* __DWC3_UBOOT_H_ */