platform.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * platform.c - DesignWare HS OTG Controller platform driver
  3. *
  4. * Copyright (C) Matthijs Kooijman <matthijs@stdin.nl>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions, and the following disclaimer,
  11. * without modification.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The names of the above-listed copyright holders may not be used
  16. * to endorse or promote products derived from this software without
  17. * specific prior written permission.
  18. *
  19. * ALTERNATIVELY, this software may be distributed under the terms of the
  20. * GNU General Public License ("GPL") as published by the Free Software
  21. * Foundation; either version 2 of the License, or (at your option) any
  22. * later version.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  25. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include "usb_os_adapter.h"
  37. #include "trace.h"
  38. #include <asm/dma-mapping.h>
  39. #include <linux/usb/ch9.h>
  40. #include <linux/usb/gadget.h>
  41. #include "core.h"
  42. #include "hcd.h"
  43. #include "amt630h.h"
  44. #include "aic.h"
  45. static int dwc2_get_dr_mode(struct dwc2_hsotg *hsotg)
  46. {
  47. hsotg->dr_mode = USB_DR_MODE_HOST;
  48. return 0;
  49. }
  50. //static QueueHandle_t usb_irq_queue;
  51. //static TaskHandle_t usb_irq_task;
  52. //static char first_irq = 1;
  53. static void ark_usb_interrupt(void *param)
  54. {
  55. struct dwc2_hsotg *hsotg = (struct dwc2_hsotg *)param;
  56. //printf("ark_usb_interrupt\r\n");
  57. dwc2_handle_common_intr(hsotg->irq, param);
  58. dwc2_hcd_irq(hsotg);
  59. /*if (first_irq) {
  60. dwc2_hcd_irq(hsotg);
  61. first_irq = 0;
  62. } else {
  63. portDISABLE_INTERRUPTS();
  64. xQueueSendFromISR(usb_irq_queue, NULL, 0);
  65. }*/
  66. }
  67. #if 0
  68. static void usb_irq_task_proc(void *pvParameters)
  69. {
  70. struct dwc2_hsotg *hsotg = (struct dwc2_hsotg *)pvParameters;
  71. int ret = -1;
  72. while(1) {
  73. ret = xQueueReceive(usb_irq_queue, NULL, portMAX_DELAY);
  74. if (pdFALSE == ret) {
  75. continue;
  76. }
  77. //portENTER_CRITICAL();
  78. dwc2_hcd_irq(hsotg);
  79. portENABLE_INTERRUPTS();
  80. //portEXIT_CRITICAL();
  81. }
  82. }
  83. #endif
  84. int dwc2_driver_init(struct dwc2_hsotg **dev, struct usb_hcd *hcd)
  85. {
  86. struct dwc2_hsotg *hsotg;
  87. int retval = -1;
  88. u32 size = sizeof(struct device);
  89. hsotg = devm_kzalloc(NULL, sizeof(*hsotg), GFP_KERNEL);
  90. if (!hsotg)
  91. return -ENOMEM;
  92. hsotg->dev = (struct device *)kzalloc(size, (__GFP_ZERO | GFP_KERNEL));
  93. if (NULL == hsotg->dev)
  94. goto error;
  95. hsotg->phyif = GUSBCFG_PHYIF16;
  96. hsotg->regs = REGS_USB_BASE;
  97. spin_lock_init(&(hsotg->lock));
  98. hsotg->irq = USB_IRQn;
  99. retval = request_irq(hsotg->irq, 0, ark_usb_interrupt, (void*)hsotg);
  100. if (retval)
  101. goto error;
  102. retval = dwc2_get_dr_mode(hsotg);
  103. if (retval)
  104. goto error;
  105. /*
  106. * Reset before dwc2_get_hwparams() then it could get power-on real
  107. * reset value form registers.
  108. */
  109. dwc2_core_reset_and_force_dr_mode(hsotg);
  110. /* Detect config values from hardware */
  111. retval = dwc2_get_hwparams(hsotg);
  112. if (retval)
  113. goto error;
  114. dwc2_force_dr_mode(hsotg);
  115. retval = dwc2_init_params(hsotg);
  116. if (retval)
  117. goto error;
  118. if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) {
  119. //usb_irq_queue = xQueueCreate(1, 0);
  120. //xTaskCreate(usb_irq_task_proc, "usb_irq_proc", configMINIMAL_STACK_SIZE * 5, (void*)dev, configMAX_PRIORITIES, &usb_irq_task);
  121. retval = dwc2_hcd_init(hsotg, hcd);
  122. if (retval) {
  123. goto error;
  124. }
  125. hsotg->hcd_enabled = 1;
  126. }
  127. if (dev) {
  128. *dev = hsotg;
  129. }
  130. return 0;
  131. error:
  132. if (hsotg && hsotg->dev) {
  133. kfree(hsotg->dev);
  134. }
  135. if (hsotg) {
  136. kfree(hsotg);
  137. }
  138. return retval;
  139. }
  140. int dwc2_driver_uninit(struct dwc2_hsotg *hsotg)
  141. {
  142. if (NULL == hsotg)
  143. return 0;
  144. if (hsotg->hcd_enabled)
  145. dwc2_hcd_remove(hsotg);
  146. if (hsotg->dev)
  147. kfree(hsotg->dev);
  148. kfree(hsotg);
  149. return 0;
  150. }