usb-da8xx.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * DA8xx USB
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/delay.h>
  7. #include <linux/dma-mapping.h>
  8. #include <linux/init.h>
  9. #include <linux/mfd/da8xx-cfgchip.h>
  10. #include <linux/mfd/syscon.h>
  11. #include <linux/phy/phy.h>
  12. #include <linux/platform_data/clk-da8xx-cfgchip.h>
  13. #include <linux/platform_data/phy-da8xx-usb.h>
  14. #include <linux/platform_data/usb-davinci.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/usb/musb.h>
  17. #include <mach/common.h>
  18. #include <mach/cputype.h>
  19. #include <mach/da8xx.h>
  20. #include <mach/irqs.h>
  21. #define DA8XX_USB0_BASE 0x01e00000
  22. #define DA8XX_USB1_BASE 0x01e25000
  23. #ifndef CONFIG_COMMON_CLK
  24. static struct clk *usb20_clk;
  25. #endif
  26. static struct da8xx_usb_phy_platform_data da8xx_usb_phy_pdata;
  27. static struct platform_device da8xx_usb_phy = {
  28. .name = "da8xx-usb-phy",
  29. .id = -1,
  30. .dev = {
  31. /*
  32. * Setting init_name so that clock lookup will work in
  33. * da8xx_register_usb11_phy_clk() even if this device is not
  34. * registered yet.
  35. */
  36. .init_name = "da8xx-usb-phy",
  37. .platform_data = &da8xx_usb_phy_pdata,
  38. },
  39. };
  40. int __init da8xx_register_usb_phy(void)
  41. {
  42. da8xx_usb_phy_pdata.cfgchip = da8xx_get_cfgchip();
  43. return platform_device_register(&da8xx_usb_phy);
  44. }
  45. static struct musb_hdrc_config musb_config = {
  46. .multipoint = true,
  47. .num_eps = 5,
  48. .ram_bits = 10,
  49. };
  50. static struct musb_hdrc_platform_data usb_data = {
  51. /* OTG requires a Mini-AB connector */
  52. .mode = MUSB_OTG,
  53. .clock = "usb20",
  54. .config = &musb_config,
  55. };
  56. static struct resource da8xx_usb20_resources[] = {
  57. {
  58. .start = DA8XX_USB0_BASE,
  59. .end = DA8XX_USB0_BASE + SZ_64K - 1,
  60. .flags = IORESOURCE_MEM,
  61. },
  62. {
  63. .start = IRQ_DA8XX_USB_INT,
  64. .flags = IORESOURCE_IRQ,
  65. .name = "mc",
  66. },
  67. };
  68. static u64 usb_dmamask = DMA_BIT_MASK(32);
  69. static struct platform_device da8xx_usb20_dev = {
  70. .name = "musb-da8xx",
  71. .id = -1,
  72. .dev = {
  73. .platform_data = &usb_data,
  74. .dma_mask = &usb_dmamask,
  75. .coherent_dma_mask = DMA_BIT_MASK(32),
  76. },
  77. .resource = da8xx_usb20_resources,
  78. .num_resources = ARRAY_SIZE(da8xx_usb20_resources),
  79. };
  80. int __init da8xx_register_usb20(unsigned int mA, unsigned int potpgt)
  81. {
  82. usb_data.power = mA > 510 ? 255 : mA / 2;
  83. usb_data.potpgt = (potpgt + 1) / 2;
  84. return platform_device_register(&da8xx_usb20_dev);
  85. }
  86. static struct resource da8xx_usb11_resources[] = {
  87. [0] = {
  88. .start = DA8XX_USB1_BASE,
  89. .end = DA8XX_USB1_BASE + SZ_4K - 1,
  90. .flags = IORESOURCE_MEM,
  91. },
  92. [1] = {
  93. .start = IRQ_DA8XX_IRQN,
  94. .end = IRQ_DA8XX_IRQN,
  95. .flags = IORESOURCE_IRQ,
  96. },
  97. };
  98. static u64 da8xx_usb11_dma_mask = DMA_BIT_MASK(32);
  99. static struct platform_device da8xx_usb11_device = {
  100. .name = "ohci-da8xx",
  101. .id = -1,
  102. .dev = {
  103. .dma_mask = &da8xx_usb11_dma_mask,
  104. .coherent_dma_mask = DMA_BIT_MASK(32),
  105. },
  106. .num_resources = ARRAY_SIZE(da8xx_usb11_resources),
  107. .resource = da8xx_usb11_resources,
  108. };
  109. int __init da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata)
  110. {
  111. da8xx_usb11_device.dev.platform_data = pdata;
  112. return platform_device_register(&da8xx_usb11_device);
  113. }
  114. static struct platform_device da8xx_usb_phy_clks_device = {
  115. .name = "da830-usb-phy-clks",
  116. .id = -1,
  117. };
  118. int __init da8xx_register_usb_phy_clocks(void)
  119. {
  120. struct da8xx_cfgchip_clk_platform_data pdata;
  121. pdata.cfgchip = da8xx_get_cfgchip();
  122. da8xx_usb_phy_clks_device.dev.platform_data = &pdata;
  123. return platform_device_register(&da8xx_usb_phy_clks_device);
  124. }