usb.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 <linux/dma-mapping.h>
  10. #include <plat/ste_dma40.h>
  11. #include <mach/hardware.h>
  12. #include <mach/usb.h>
  13. #define MUSB_DMA40_RX_CH { \
  14. .mode = STEDMA40_MODE_LOGICAL, \
  15. .dir = STEDMA40_PERIPH_TO_MEM, \
  16. .dst_dev_type = STEDMA40_DEV_DST_MEMORY, \
  17. .src_info.data_width = STEDMA40_WORD_WIDTH, \
  18. .dst_info.data_width = STEDMA40_WORD_WIDTH, \
  19. .src_info.psize = STEDMA40_PSIZE_LOG_16, \
  20. .dst_info.psize = STEDMA40_PSIZE_LOG_16, \
  21. }
  22. #define MUSB_DMA40_TX_CH { \
  23. .mode = STEDMA40_MODE_LOGICAL, \
  24. .dir = STEDMA40_MEM_TO_PERIPH, \
  25. .src_dev_type = STEDMA40_DEV_SRC_MEMORY, \
  26. .src_info.data_width = STEDMA40_WORD_WIDTH, \
  27. .dst_info.data_width = STEDMA40_WORD_WIDTH, \
  28. .src_info.psize = STEDMA40_PSIZE_LOG_16, \
  29. .dst_info.psize = STEDMA40_PSIZE_LOG_16, \
  30. }
  31. static struct stedma40_chan_cfg musb_dma_rx_ch[UX500_MUSB_DMA_NUM_RX_CHANNELS]
  32. = {
  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. MUSB_DMA40_RX_CH
  41. };
  42. static struct stedma40_chan_cfg musb_dma_tx_ch[UX500_MUSB_DMA_NUM_TX_CHANNELS]
  43. = {
  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. MUSB_DMA40_TX_CH,
  52. };
  53. static void *ux500_dma_rx_param_array[UX500_MUSB_DMA_NUM_RX_CHANNELS] = {
  54. &musb_dma_rx_ch[0],
  55. &musb_dma_rx_ch[1],
  56. &musb_dma_rx_ch[2],
  57. &musb_dma_rx_ch[3],
  58. &musb_dma_rx_ch[4],
  59. &musb_dma_rx_ch[5],
  60. &musb_dma_rx_ch[6],
  61. &musb_dma_rx_ch[7]
  62. };
  63. static void *ux500_dma_tx_param_array[UX500_MUSB_DMA_NUM_TX_CHANNELS] = {
  64. &musb_dma_tx_ch[0],
  65. &musb_dma_tx_ch[1],
  66. &musb_dma_tx_ch[2],
  67. &musb_dma_tx_ch[3],
  68. &musb_dma_tx_ch[4],
  69. &musb_dma_tx_ch[5],
  70. &musb_dma_tx_ch[6],
  71. &musb_dma_tx_ch[7]
  72. };
  73. static struct ux500_musb_board_data musb_board_data = {
  74. .dma_rx_param_array = ux500_dma_rx_param_array,
  75. .dma_tx_param_array = ux500_dma_tx_param_array,
  76. .num_rx_channels = UX500_MUSB_DMA_NUM_RX_CHANNELS,
  77. .num_tx_channels = UX500_MUSB_DMA_NUM_TX_CHANNELS,
  78. .dma_filter = stedma40_filter,
  79. };
  80. static u64 ux500_musb_dmamask = DMA_BIT_MASK(32);
  81. static struct musb_hdrc_config musb_hdrc_config = {
  82. .multipoint = true,
  83. .dyn_fifo = true,
  84. .num_eps = 16,
  85. .ram_bits = 16,
  86. };
  87. static struct musb_hdrc_platform_data musb_platform_data = {
  88. .mode = MUSB_OTG,
  89. .config = &musb_hdrc_config,
  90. .board_data = &musb_board_data,
  91. };
  92. static struct resource usb_resources[] = {
  93. [0] = {
  94. .name = "usb-mem",
  95. .flags = IORESOURCE_MEM,
  96. },
  97. [1] = {
  98. .name = "mc", /* hard-coded in musb */
  99. .flags = IORESOURCE_IRQ,
  100. },
  101. };
  102. struct platform_device ux500_musb_device = {
  103. .name = "musb-ux500",
  104. .id = 0,
  105. .dev = {
  106. .platform_data = &musb_platform_data,
  107. .dma_mask = &ux500_musb_dmamask,
  108. .coherent_dma_mask = DMA_BIT_MASK(32),
  109. },
  110. .num_resources = ARRAY_SIZE(usb_resources),
  111. .resource = usb_resources,
  112. };
  113. static inline void ux500_usb_dma_update_rx_ch_config(int *src_dev_type)
  114. {
  115. u32 idx;
  116. for (idx = 0; idx < UX500_MUSB_DMA_NUM_RX_CHANNELS; idx++)
  117. musb_dma_rx_ch[idx].src_dev_type = src_dev_type[idx];
  118. }
  119. static inline void ux500_usb_dma_update_tx_ch_config(int *dst_dev_type)
  120. {
  121. u32 idx;
  122. for (idx = 0; idx < UX500_MUSB_DMA_NUM_TX_CHANNELS; idx++)
  123. musb_dma_tx_ch[idx].dst_dev_type = dst_dev_type[idx];
  124. }
  125. void ux500_add_usb(struct device *parent, resource_size_t base, int irq,
  126. int *dma_rx_cfg, int *dma_tx_cfg)
  127. {
  128. ux500_musb_device.resource[0].start = base;
  129. ux500_musb_device.resource[0].end = base + SZ_64K - 1;
  130. ux500_musb_device.resource[1].start = irq;
  131. ux500_musb_device.resource[1].end = irq;
  132. ux500_usb_dma_update_rx_ch_config(dma_rx_cfg);
  133. ux500_usb_dma_update_tx_ch_config(dma_tx_cfg);
  134. ux500_musb_device.dev.parent = parent;
  135. platform_device_register(&ux500_musb_device);
  136. }