dev-usb.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Atheros AR7XXX/AR9XXX USB Host Controller device
  3. *
  4. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6. *
  7. * Parts of this file are based on Atheros' 2.6.15 BSP
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/delay.h>
  16. #include <linux/irq.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/platform_device.h>
  19. #include <asm/mach-ath79/ath79.h>
  20. #include <asm/mach-ath79/ar71xx_regs.h>
  21. #include "common.h"
  22. #include "dev-usb.h"
  23. static struct resource ath79_ohci_resources[] = {
  24. [0] = {
  25. /* .start and .end fields are filled dynamically */
  26. .flags = IORESOURCE_MEM,
  27. },
  28. [1] = {
  29. .start = ATH79_MISC_IRQ_OHCI,
  30. .end = ATH79_MISC_IRQ_OHCI,
  31. .flags = IORESOURCE_IRQ,
  32. },
  33. };
  34. static u64 ath79_ohci_dmamask = DMA_BIT_MASK(32);
  35. static struct platform_device ath79_ohci_device = {
  36. .name = "ath79-ohci",
  37. .id = -1,
  38. .resource = ath79_ohci_resources,
  39. .num_resources = ARRAY_SIZE(ath79_ohci_resources),
  40. .dev = {
  41. .dma_mask = &ath79_ohci_dmamask,
  42. .coherent_dma_mask = DMA_BIT_MASK(32),
  43. },
  44. };
  45. static struct resource ath79_ehci_resources[] = {
  46. [0] = {
  47. /* .start and .end fields are filled dynamically */
  48. .flags = IORESOURCE_MEM,
  49. },
  50. [1] = {
  51. .start = ATH79_CPU_IRQ_USB,
  52. .end = ATH79_CPU_IRQ_USB,
  53. .flags = IORESOURCE_IRQ,
  54. },
  55. };
  56. static u64 ath79_ehci_dmamask = DMA_BIT_MASK(32);
  57. static struct platform_device ath79_ehci_device = {
  58. .name = "ath79-ehci",
  59. .id = -1,
  60. .resource = ath79_ehci_resources,
  61. .num_resources = ARRAY_SIZE(ath79_ehci_resources),
  62. .dev = {
  63. .dma_mask = &ath79_ehci_dmamask,
  64. .coherent_dma_mask = DMA_BIT_MASK(32),
  65. },
  66. };
  67. #define AR71XX_USB_RESET_MASK (AR71XX_RESET_USB_HOST | \
  68. AR71XX_RESET_USB_PHY | \
  69. AR71XX_RESET_USB_OHCI_DLL)
  70. static void __init ath79_usb_setup(void)
  71. {
  72. void __iomem *usb_ctrl_base;
  73. ath79_device_reset_set(AR71XX_USB_RESET_MASK);
  74. mdelay(1000);
  75. ath79_device_reset_clear(AR71XX_USB_RESET_MASK);
  76. usb_ctrl_base = ioremap(AR71XX_USB_CTRL_BASE, AR71XX_USB_CTRL_SIZE);
  77. /* Turning on the Buff and Desc swap bits */
  78. __raw_writel(0xf0000, usb_ctrl_base + AR71XX_USB_CTRL_REG_CONFIG);
  79. /* WAR for HW bug. Here it adjusts the duration between two SOFS */
  80. __raw_writel(0x20c00, usb_ctrl_base + AR71XX_USB_CTRL_REG_FLADJ);
  81. iounmap(usb_ctrl_base);
  82. mdelay(900);
  83. ath79_ohci_resources[0].start = AR71XX_OHCI_BASE;
  84. ath79_ohci_resources[0].end = AR71XX_OHCI_BASE + AR71XX_OHCI_SIZE - 1;
  85. platform_device_register(&ath79_ohci_device);
  86. ath79_ehci_resources[0].start = AR71XX_EHCI_BASE;
  87. ath79_ehci_resources[0].end = AR71XX_EHCI_BASE + AR71XX_EHCI_SIZE - 1;
  88. ath79_ehci_device.name = "ar71xx-ehci";
  89. platform_device_register(&ath79_ehci_device);
  90. }
  91. static void __init ar7240_usb_setup(void)
  92. {
  93. void __iomem *usb_ctrl_base;
  94. ath79_device_reset_clear(AR7240_RESET_OHCI_DLL);
  95. ath79_device_reset_set(AR7240_RESET_USB_HOST);
  96. mdelay(1000);
  97. ath79_device_reset_set(AR7240_RESET_OHCI_DLL);
  98. ath79_device_reset_clear(AR7240_RESET_USB_HOST);
  99. usb_ctrl_base = ioremap(AR7240_USB_CTRL_BASE, AR7240_USB_CTRL_SIZE);
  100. /* WAR for HW bug. Here it adjusts the duration between two SOFS */
  101. __raw_writel(0x3, usb_ctrl_base + AR71XX_USB_CTRL_REG_FLADJ);
  102. iounmap(usb_ctrl_base);
  103. ath79_ohci_resources[0].start = AR7240_OHCI_BASE;
  104. ath79_ohci_resources[0].end = AR7240_OHCI_BASE + AR7240_OHCI_SIZE - 1;
  105. platform_device_register(&ath79_ohci_device);
  106. }
  107. static void __init ar724x_usb_setup(void)
  108. {
  109. ath79_device_reset_set(AR724X_RESET_USBSUS_OVERRIDE);
  110. mdelay(10);
  111. ath79_device_reset_clear(AR724X_RESET_USB_HOST);
  112. mdelay(10);
  113. ath79_device_reset_clear(AR724X_RESET_USB_PHY);
  114. mdelay(10);
  115. ath79_ehci_resources[0].start = AR724X_EHCI_BASE;
  116. ath79_ehci_resources[0].end = AR724X_EHCI_BASE + AR724X_EHCI_SIZE - 1;
  117. ath79_ehci_device.name = "ar724x-ehci";
  118. platform_device_register(&ath79_ehci_device);
  119. }
  120. static void __init ar913x_usb_setup(void)
  121. {
  122. ath79_device_reset_set(AR913X_RESET_USBSUS_OVERRIDE);
  123. mdelay(10);
  124. ath79_device_reset_clear(AR913X_RESET_USB_HOST);
  125. mdelay(10);
  126. ath79_device_reset_clear(AR913X_RESET_USB_PHY);
  127. mdelay(10);
  128. ath79_ehci_resources[0].start = AR913X_EHCI_BASE;
  129. ath79_ehci_resources[0].end = AR913X_EHCI_BASE + AR913X_EHCI_SIZE - 1;
  130. ath79_ehci_device.name = "ar913x-ehci";
  131. platform_device_register(&ath79_ehci_device);
  132. }
  133. static void __init ar933x_usb_setup(void)
  134. {
  135. ath79_device_reset_set(AR933X_RESET_USBSUS_OVERRIDE);
  136. mdelay(10);
  137. ath79_device_reset_clear(AR933X_RESET_USB_HOST);
  138. mdelay(10);
  139. ath79_device_reset_clear(AR933X_RESET_USB_PHY);
  140. mdelay(10);
  141. ath79_ehci_resources[0].start = AR933X_EHCI_BASE;
  142. ath79_ehci_resources[0].end = AR933X_EHCI_BASE + AR933X_EHCI_SIZE - 1;
  143. ath79_ehci_device.name = "ar933x-ehci";
  144. platform_device_register(&ath79_ehci_device);
  145. }
  146. void __init ath79_register_usb(void)
  147. {
  148. if (soc_is_ar71xx())
  149. ath79_usb_setup();
  150. else if (soc_is_ar7240())
  151. ar7240_usb_setup();
  152. else if (soc_is_ar7241() || soc_is_ar7242())
  153. ar724x_usb_setup();
  154. else if (soc_is_ar913x())
  155. ar913x_usb_setup();
  156. else if (soc_is_ar933x())
  157. ar933x_usb_setup();
  158. else
  159. BUG();
  160. }