0025-arx100-cgu-fixes.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. From patchwork Tue Jan 20 11:28:45 2015
  2. Content-Type: text/plain; charset="utf-8"
  3. MIME-Version: 1.0
  4. Content-Transfer-Encoding: 7bit
  5. Subject: [OpenWrt-Devel] uboot-lantiq cgu settings for ramboot image
  6. From: Ben Mulvihill <ben.mulvihill@gmail.com>
  7. X-Patchwork-Id: 431024
  8. Message-Id: <1421753325.25187.58.camel@merveille.lan>
  9. To: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  10. Cc: OpenWrt Development List <openwrt-devel@lists.openwrt.org>
  11. Date: Tue, 20 Jan 2015 12:28:45 +0100
  12. On Tue, 2015-01-20 at 00:39 +0100, Ben Mulvihill wrote:
  13. > On Mon, 2015-01-19 at 19:21 +0100, Ben Mulvihill wrote:
  14. > > On Mon, 2015-01-19 at 16:47 +0100, Daniel Schwierzeck wrote:
  15. > > > 2015-01-19 15:44 GMT+01:00 Ben Mulvihill <ben.mulvihill@gmail.com>:
  16. > > > > On Mon, 2015-01-19 at 11:51 +0000, Conor O'Gorman wrote:
  17. > > > >> On 19/01/15 10:46, Ben Mulvihill wrote:
  18. > > > >> > Hello,
  19. > > > >> >
  20. > > > >> > I am trying to build uboot-lantiq for the BT Home Hub 3A (lantiq
  21. > > > >> > ar9), and am wondering where to initialise the cgu, in the case
  22. > > > >> > of a ramboot image for uart booting. Normally the cgu is initialised
  23. > > > >> > in lowlevel_init, but that code is bypassed in ramboot images. The
  24. > > > >> > result is that the board boots with the wrong cgu settings, which
  25. > > > >> > sends the console haywire. So far I have tried two solutions:
  26. > > > >>
  27. > > > >> Another option is to try and not change anything. The console is already
  28. > > > >> configured and running. The ram does need config.
  29. > > > >>
  30. > > > >> I was used to seeing the ramboot version running at half clock speed, at
  31. > > > >> least on danube, previous to ar9.
  32. > > > >>
  33. > > > >> Conor
  34. > > > >
  35. > > > > Hi Conor,
  36. > > > >
  37. > > > > Thanks for the reply. But with the latest uboot-lantiq, not changing
  38. > > > > anything means that I don't get a usable console. With an older
  39. > > > > version I do at least get a uboot console, but no linux console when
  40. > > > > I boot openwrt. Correcting the cgu settings solves both problems.
  41. > > > >
  42. > > >
  43. > > > could you try this?
  44. > > >
  45. > > > diff --git a/arch/mips/cpu/mips32/arx100/cgu.c
  46. > > > b/arch/mips/cpu/mips32/arx100/cgu.c
  47. > > > index 6e71ee7..e0afbda 100644
  48. > > > --- a/arch/mips/cpu/mips32/arx100/cgu.c
  49. > > > +++ b/arch/mips/cpu/mips32/arx100/cgu.c
  50. > > > @@ -95,15 +95,5 @@ unsigned long ltq_get_cpu_clock(void)
  51. > > >
  52. > > > unsigned long ltq_get_bus_clock(void)
  53. > > > {
  54. > > > - u32 fpi_sel;
  55. > > > - unsigned long clk;
  56. > > > -
  57. > > > - fpi_sel = ltq_cgu_sys_readl(1, CGU_SYS_FPI_SEL);
  58. > > > -
  59. > > > - if (fpi_sel)
  60. > > > - clk = ltq_get_io_region_clock() / 2;
  61. > > > - else
  62. > > > - clk = ltq_get_io_region_clock();
  63. > > > -
  64. > > > - return clk;
  65. > > > + return ltq_get_io_region_clock();
  66. > > > }
  67. > > >
  68. > > > the UART driver calculates the baudrate from the FPI bus clock, but
  69. > > > FPI_SEL is not available on AR9. FPI bus clock is always the same as
  70. > > > DDR clock, Obviously a copy&paste error from VR9 code ;)
  71. > > >
  72. > >
  73. > > No, even with this patch, I still don't get a working console I'm
  74. > > afraid. If I don't set anything explicitly, the board comes up with
  75. > > CGU_SYS set to 0x05, ie CGU_SYS_SYSSEL_PLL0_333_MHZ |
  76. > > CGU_SYS_CPUSEL_EQUAL_DDRCLK | CGU_SYS_DDRSEL_THIRD_SYSCLK.
  77. > > Is this a valid combination without CGU_SYS_PPESEL_250_MHZ ?
  78. > > I don't understand what CGU_SYS_PPESEL_250_MHZ does?
  79. > > The "right setting", as set by the stock uboot, is 0x80.
  80. >
  81. > P.S. There also seems to be a discrepancy between the uboot and
  82. > linux code. I take it from what you say above that fpi clock, ddr
  83. > clock and io region clock are all the same. Now if the least
  84. > significant bit of CGU_SYS is set, then according to the uboot
  85. > code - function ltq_get_bus_clock() - their value is one
  86. > third of the system clock. But according to the linux code
  87. > - function ltq_ar9_fpi_hz() in arch/mips/lantiq/xway/clk.c -
  88. > their value in this case is equal to the system clock.
  89. >
  90. > Or am I getting muddled? It's past my bedtime!
  91. >
  92. >
  93. Some of the bitshifting in arch/mips/cpu/mips32/arx100/cgu.c is 1
  94. out. A patch along these lines should fix it:
  95. --- a/arch/mips/cpu/mips32/arx100/cgu.c
  96. +++ b/arch/mips/cpu/mips32/arx100/cgu.c
  97. @@ -10,12 +10,17 @@
  98. #include <asm/lantiq/clk.h>
  99. #include <asm/lantiq/io.h>
  100. -#define CGU_SYS_DDR_SEL (1 << 0)
  101. -#define CGU_SYS_CPU_SEL (1 << 2)
  102. +#define CGU_SYS_DDR_SHIFT 0
  103. +#define CGU_SYS_CPU_SHIFT 2
  104. #define CGU_SYS_SYS_SHIFT 3
  105. +#define CGU_SYS_FPI_SHIFT 6
  106. +#define CGU_SYS_PPE_SHIFT 7
  107. +
  108. +#define CGU_SYS_DDR_MASK (1 << CGU_SYS_DDR_SHIFT)
  109. +#define CGU_SYS_CPU_MASK (1 << CGU_SYS_CPU_SHIFT)
  110. #define CGU_SYS_SYS_MASK (0x3 << CGU_SYS_SYS_SHIFT)
  111. -#define CGU_SYS_FPI_SEL (1 << 6)
  112. -#define CGU_SYS_PPE_SEL (1 << 7)
  113. +#define CGU_SYS_FPI_MASK (1 << CGU_SYS_FPI_SHIFT)
  114. +#define CGU_SYS_PPE_MASK (1 << CGU_SYS_PPE_SHIFT)
  115. struct ltq_cgu_regs {
  116. u32 rsvd0;
  117. @@ -68,7 +73,7 @@ unsigned long ltq_get_io_region_clock(vo
  118. u32 ddr_sel;
  119. unsigned long clk;
  120. - ddr_sel = ltq_cgu_sys_readl(1, CGU_SYS_DDR_SEL);
  121. + ddr_sel = ltq_cgu_sys_readl(CGU_SYS_DDR_MASK, CGU_SYS_DDR_SHIFT);
  122. if (ddr_sel)
  123. clk = ltq_get_system_clock() / 3;
  124. @@ -83,7 +88,7 @@ unsigned long ltq_get_cpu_clock(void)
  125. u32 cpu_sel;
  126. unsigned long clk;
  127. - cpu_sel = ltq_cgu_sys_readl(1, CGU_SYS_CPU_SEL);
  128. + cpu_sel = ltq_cgu_sys_readl(CGU_SYS_CPU_MASK, CGU_SYS_CPU_SHIFT);
  129. if (cpu_sel)
  130. clk = ltq_get_io_region_clock();
  131. @@ -98,7 +103,7 @@ unsigned long ltq_get_bus_clock(void)
  132. u32 fpi_sel;
  133. unsigned long clk;
  134. - fpi_sel = ltq_cgu_sys_readl(1, CGU_SYS_FPI_SEL);
  135. + fpi_sel = ltq_cgu_sys_readl(CGU_SYS_FPI_MASK, CGU_SYS_FPI_SHIFT);
  136. if (fpi_sel)
  137. clk = ltq_get_io_region_clock() / 2;