0039-MIPS-lantiq-initialize-usb-on-boot.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. --- a/arch/mips/lantiq/xway/reset.c
  2. +++ b/arch/mips/lantiq/xway/reset.c
  3. @@ -44,6 +44,37 @@
  4. #define RCU_BOOT_SEL(x) ((x >> 18) & 0x7)
  5. #define RCU_BOOT_SEL_XRX200(x) (((x >> 17) & 0xf) | ((x >> 8) & 0x10))
  6. +/* dwc2 USB configuration registers */
  7. +#define RCU_USB1CFG 0x0018
  8. +#define RCU_USB2CFG 0x0034
  9. +
  10. +/* USB DMA endianness bits */
  11. +#define RCU_USBCFG_HDSEL_BIT BIT(11)
  12. +#define RCU_USBCFG_HOST_END_BIT BIT(10)
  13. +#define RCU_USBCFG_SLV_END_BIT BIT(9)
  14. +
  15. +/* USB reset bits */
  16. +#define RCU_USBRESET 0x0010
  17. +
  18. +#define USBRESET_BIT BIT(4)
  19. +
  20. +#define RCU_USBRESET2 0x0048
  21. +
  22. +#define USB1RESET_BIT BIT(4)
  23. +#define USB2RESET_BIT BIT(5)
  24. +
  25. +#define RCU_CFG1A 0x0038
  26. +#define RCU_CFG1B 0x003C
  27. +
  28. +/* USB PMU devices */
  29. +#define PMU_AHBM BIT(15)
  30. +#define PMU_USB0 BIT(6)
  31. +#define PMU_USB1 BIT(27)
  32. +
  33. +/* USB PHY PMU devices */
  34. +#define PMU_USB0_P BIT(0)
  35. +#define PMU_USB1_P BIT(26)
  36. +
  37. /* remapped base addr of the reset control unit */
  38. static void __iomem *ltq_rcu_membase;
  39. static struct device_node *ltq_rcu_np;
  40. @@ -200,6 +231,45 @@ static void ltq_machine_power_off(void)
  41. unreachable();
  42. }
  43. +static void ltq_usb_init(void)
  44. +{
  45. + /* Power for USB cores 1 & 2 */
  46. + ltq_pmu_enable(PMU_AHBM);
  47. + ltq_pmu_enable(PMU_USB0);
  48. + ltq_pmu_enable(PMU_USB1);
  49. +
  50. + ltq_rcu_w32(ltq_rcu_r32(RCU_CFG1A) | BIT(0), RCU_CFG1A);
  51. + ltq_rcu_w32(ltq_rcu_r32(RCU_CFG1B) | BIT(0), RCU_CFG1B);
  52. +
  53. + /* Enable USB PHY power for cores 1 & 2 */
  54. + ltq_pmu_enable(PMU_USB0_P);
  55. + ltq_pmu_enable(PMU_USB1_P);
  56. +
  57. + /* Configure cores to host mode */
  58. + ltq_rcu_w32(ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_HDSEL_BIT,
  59. + RCU_USB1CFG);
  60. + ltq_rcu_w32(ltq_rcu_r32(RCU_USB2CFG) & ~RCU_USBCFG_HDSEL_BIT,
  61. + RCU_USB2CFG);
  62. +
  63. + /* Select DMA endianness (Host-endian: big-endian) */
  64. + ltq_rcu_w32((ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_SLV_END_BIT)
  65. + | RCU_USBCFG_HOST_END_BIT, RCU_USB1CFG);
  66. + ltq_rcu_w32(ltq_rcu_r32((RCU_USB2CFG) & ~RCU_USBCFG_SLV_END_BIT)
  67. + | RCU_USBCFG_HOST_END_BIT, RCU_USB2CFG);
  68. +
  69. + /* Hard reset USB state machines */
  70. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET) | USBRESET_BIT, RCU_USBRESET);
  71. + udelay(50 * 1000);
  72. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET) & ~USBRESET_BIT, RCU_USBRESET);
  73. +
  74. + /* Soft reset USB state machines */
  75. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET2)
  76. + | USB1RESET_BIT | USB2RESET_BIT, RCU_USBRESET2);
  77. + udelay(50 * 1000);
  78. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET2)
  79. + & ~(USB1RESET_BIT | USB2RESET_BIT), RCU_USBRESET2);
  80. +}
  81. +
  82. static int __init mips_reboot_setup(void)
  83. {
  84. struct resource res;
  85. @@ -223,6 +293,9 @@ static int __init mips_reboot_setup(void
  86. if (!ltq_rcu_membase)
  87. panic("Failed to remap core memory");
  88. + if (of_machine_is_compatible("lantiq,vr9"))
  89. + ltq_usb_init();
  90. +
  91. _machine_restart = ltq_machine_restart;
  92. _machine_halt = ltq_machine_halt;
  93. pm_power_off = ltq_machine_power_off;