usb.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2011
  3. *
  4. * Author: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
  5. * License terms: GNU General Public License (GPL) version 2
  6. */
  7. #include <linux/platform_device.h>
  8. #include <linux/usb/musb.h>
  9. #include <plat/ste_dma40.h>
  10. #include <mach/hardware.h>
  11. #include <mach/usb.h>
  12. #define MUSB_DMA40_RX_CH { \
  13. .mode = STEDMA40_MODE_LOGICAL, \
  14. .dir = STEDMA40_PERIPH_TO_MEM, \
  15. .dst_dev_type = STEDMA40_DEV_DST_MEMORY, \
  16. .src_info.data_width = STEDMA40_WORD_WIDTH, \
  17. .dst_info.data_width = STEDMA40_WORD_WIDTH, \
  18. .src_info.psize = STEDMA40_PSIZE_LOG_16, \
  19. .dst_info.psize = STEDMA40_PSIZE_LOG_16, \
  20. }
  21. #define MUSB_DMA40_TX_CH { \
  22. .mode = STEDMA40_MODE_LOGICAL, \
  23. .dir = STEDMA40_MEM_TO_PERIPH, \
  24. .src_dev_type = STEDMA40_DEV_SRC_MEMORY, \
  25. .src_info.data_width = STEDMA40_WORD_WIDTH, \
  26. .dst_info.data_width = STEDMA40_WORD_WIDTH, \
  27. .src_info.psize = STEDMA40_PSIZE_LOG_16, \
  28. .dst_info.psize = STEDMA40_PSIZE_LOG_16, \
  29. }
  30. static struct stedma40_chan_cfg musb_dma_rx_ch[UX500_MUSB_DMA_NUM_RX_CHANNELS]
  31. = {
  32. MUSB_DMA40_RX_CH,
  33. MUSB_DMA40_RX_CH,
  34. MUSB_DMA40_RX_CH,
  35. MUSB_DMA40_RX_CH,
  36. MUSB_DMA40_RX_CH,
  37. MUSB_DMA40_RX_CH,
  38. MUSB_DMA40_RX_CH,
  39. MUSB_DMA40_RX_CH
  40. };
  41. static struct stedma40_chan_cfg musb_dma_tx_ch[UX500_MUSB_DMA_NUM_TX_CHANNELS]
  42. = {
  43. MUSB_DMA40_TX_CH,
  44. MUSB_DMA40_TX_CH,
  45. MUSB_DMA40_TX_CH,
  46. MUSB_DMA40_TX_CH,
  47. MUSB_DMA40_TX_CH,
  48. MUSB_DMA40_TX_CH,
  49. MUSB_DMA40_TX_CH,
  50. MUSB_DMA40_TX_CH,
  51. };
  52. static void *ux500_dma_rx_param_array[UX500_MUSB_DMA_NUM_RX_CHANNELS] = {
  53. &musb_dma_rx_ch[0],
  54. &musb_dma_rx_ch[1],
  55. &musb_dma_rx_ch[2],
  56. &musb_dma_rx_ch[3],
  57. &musb_dma_rx_ch[4],
  58. &musb_dma_rx_ch[5],
  59. &musb_dma_rx_ch[6],
  60. &musb_dma_rx_ch[7]
  61. };
  62. static void *ux500_dma_tx_param_array[UX500_MUSB_DMA_NUM_TX_CHANNELS] = {
  63. &musb_dma_tx_ch[0],
  64. &musb_dma_tx_ch[1],
  65. &musb_dma_tx_ch[2],
  66. &musb_dma_tx_ch[3],
  67. &musb_dma_tx_ch[4],
  68. &musb_dma_tx_ch[5],
  69. &musb_dma_tx_ch[6],
  70. &musb_dma_tx_ch[7]
  71. };
  72. static struct ux500_musb_board_data musb_board_data = {
  73. .dma_rx_param_array = ux500_dma_rx_param_array,
  74. .dma_tx_param_array = ux500_dma_tx_param_array,
  75. .num_rx_channels = UX500_MUSB_DMA_NUM_RX_CHANNELS,
  76. .num_tx_channels = UX500_MUSB_DMA_NUM_TX_CHANNELS,
  77. .dma_filter = stedma40_filter,
  78. };
  79. static u64 ux500_musb_dmamask = DMA_BIT_MASK(32);
  80. static struct musb_hdrc_config musb_hdrc_config = {
  81. .multipoint = true,
  82. .dyn_fifo = true,
  83. .num_eps = 16,
  84. .ram_bits = 16,
  85. };
  86. static struct musb_hdrc_platform_data musb_platform_data = {
  87. #if defined(CONFIG_USB_MUSB_OTG)
  88. .mode = MUSB_OTG,
  89. #elif defined(CONFIG_USB_MUSB_PERIPHERAL)
  90. .mode = MUSB_PERIPHERAL,
  91. #else /* defined(CONFIG_USB_MUSB_HOST) */
  92. .mode = MUSB_HOST,
  93. #endif
  94. .config = &musb_hdrc_config,
  95. .board_data = &musb_board_data,
  96. };
  97. static struct resource usb_resources[] = {
  98. [0] = {
  99. .name = "usb-mem",
  100. .flags = IORESOURCE_MEM,
  101. },
  102. [1] = {
  103. .name = "mc", /* hard-coded in musb */
  104. .flags = IORESOURCE_IRQ,
  105. },
  106. };
  107. struct platform_device ux500_musb_device = {
  108. .name = "musb-ux500",
  109. .id = 0,
  110. .dev = {
  111. .platform_data = &musb_platform_data,
  112. .dma_mask = &ux500_musb_dmamask,
  113. .coherent_dma_mask = DMA_BIT_MASK(32),
  114. },
  115. .num_resources = ARRAY_SIZE(usb_resources),
  116. .resource = usb_resources,
  117. };
  118. static inline void ux500_usb_dma_update_rx_ch_config(int *src_dev_type)
  119. {
  120. u32 idx;
  121. for (idx = 0; idx < UX500_MUSB_DMA_NUM_RX_CHANNELS; idx++)
  122. musb_dma_rx_ch[idx].src_dev_type = src_dev_type[idx];
  123. }
  124. static inline void ux500_usb_dma_update_tx_ch_config(int *dst_dev_type)
  125. {
  126. u32 idx;
  127. for (idx = 0; idx < UX500_MUSB_DMA_NUM_TX_CHANNELS; idx++)
  128. musb_dma_tx_ch[idx].dst_dev_type = dst_dev_type[idx];
  129. }
  130. void ux500_add_usb(resource_size_t base, int irq, int *dma_rx_cfg,
  131. int *dma_tx_cfg)
  132. {
  133. ux500_musb_device.resource[0].start = base;
  134. ux500_musb_device.resource[0].end = base + SZ_64K - 1;
  135. ux500_musb_device.resource[1].start = irq;
  136. ux500_musb_device.resource[1].end = irq;
  137. ux500_usb_dma_update_rx_ch_config(dma_rx_cfg);
  138. ux500_usb_dma_update_tx_ch_config(dma_tx_cfg);
  139. platform_device_register(&ux500_musb_device);
  140. }