4xx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. /*
  2. * Copyright 2007 David Gibson, IBM Corporation.
  3. *
  4. * Based on earlier code:
  5. * Matt Porter <mporter@kernel.crashing.org>
  6. * Copyright 2002-2005 MontaVista Software Inc.
  7. *
  8. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  9. * Copyright (c) 2003, 2004 Zultys Technologies
  10. *
  11. * Copyright (C) 2009 Wind River Systems, Inc.
  12. * Updated for supporting PPC405EX on Kilauea.
  13. * Tiejun Chen <tiejun.chen@windriver.com>
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <stddef.h>
  21. #include "types.h"
  22. #include "string.h"
  23. #include "stdio.h"
  24. #include "ops.h"
  25. #include "reg.h"
  26. #include "dcr.h"
  27. static unsigned long chip_11_errata(unsigned long memsize)
  28. {
  29. unsigned long pvr;
  30. pvr = mfpvr();
  31. switch (pvr & 0xf0000ff0) {
  32. case 0x40000850:
  33. case 0x400008d0:
  34. case 0x200008d0:
  35. memsize -= 4096;
  36. break;
  37. default:
  38. break;
  39. }
  40. return memsize;
  41. }
  42. /* Read the 4xx SDRAM controller to get size of system memory. */
  43. void ibm4xx_sdram_fixup_memsize(void)
  44. {
  45. int i;
  46. unsigned long memsize, bank_config;
  47. memsize = 0;
  48. for (i = 0; i < ARRAY_SIZE(sdram_bxcr); i++) {
  49. bank_config = SDRAM0_READ(sdram_bxcr[i]);
  50. if (bank_config & SDRAM_CONFIG_BANK_ENABLE)
  51. memsize += SDRAM_CONFIG_BANK_SIZE(bank_config);
  52. }
  53. memsize = chip_11_errata(memsize);
  54. dt_fixup_memory(0, memsize);
  55. }
  56. /* Read the 440SPe MQ controller to get size of system memory. */
  57. #define DCRN_MQ0_B0BAS 0x40
  58. #define DCRN_MQ0_B1BAS 0x41
  59. #define DCRN_MQ0_B2BAS 0x42
  60. #define DCRN_MQ0_B3BAS 0x43
  61. static u64 ibm440spe_decode_bas(u32 bas)
  62. {
  63. u64 base = ((u64)(bas & 0xFFE00000u)) << 2;
  64. /* open coded because I'm paranoid about invalid values */
  65. switch ((bas >> 4) & 0xFFF) {
  66. case 0:
  67. return 0;
  68. case 0xffc:
  69. return base + 0x000800000ull;
  70. case 0xff8:
  71. return base + 0x001000000ull;
  72. case 0xff0:
  73. return base + 0x002000000ull;
  74. case 0xfe0:
  75. return base + 0x004000000ull;
  76. case 0xfc0:
  77. return base + 0x008000000ull;
  78. case 0xf80:
  79. return base + 0x010000000ull;
  80. case 0xf00:
  81. return base + 0x020000000ull;
  82. case 0xe00:
  83. return base + 0x040000000ull;
  84. case 0xc00:
  85. return base + 0x080000000ull;
  86. case 0x800:
  87. return base + 0x100000000ull;
  88. }
  89. printf("Memory BAS value 0x%08x unsupported !\n", bas);
  90. return 0;
  91. }
  92. void ibm440spe_fixup_memsize(void)
  93. {
  94. u64 banktop, memsize = 0;
  95. /* Ultimately, we should directly construct the memory node
  96. * so we are able to handle holes in the memory address space
  97. */
  98. banktop = ibm440spe_decode_bas(mfdcr(DCRN_MQ0_B0BAS));
  99. if (banktop > memsize)
  100. memsize = banktop;
  101. banktop = ibm440spe_decode_bas(mfdcr(DCRN_MQ0_B1BAS));
  102. if (banktop > memsize)
  103. memsize = banktop;
  104. banktop = ibm440spe_decode_bas(mfdcr(DCRN_MQ0_B2BAS));
  105. if (banktop > memsize)
  106. memsize = banktop;
  107. banktop = ibm440spe_decode_bas(mfdcr(DCRN_MQ0_B3BAS));
  108. if (banktop > memsize)
  109. memsize = banktop;
  110. dt_fixup_memory(0, memsize);
  111. }
  112. /* 4xx DDR1/2 Denali memory controller support */
  113. /* DDR0 registers */
  114. #define DDR0_02 2
  115. #define DDR0_08 8
  116. #define DDR0_10 10
  117. #define DDR0_14 14
  118. #define DDR0_42 42
  119. #define DDR0_43 43
  120. /* DDR0_02 */
  121. #define DDR_START 0x1
  122. #define DDR_START_SHIFT 0
  123. #define DDR_MAX_CS_REG 0x3
  124. #define DDR_MAX_CS_REG_SHIFT 24
  125. #define DDR_MAX_COL_REG 0xf
  126. #define DDR_MAX_COL_REG_SHIFT 16
  127. #define DDR_MAX_ROW_REG 0xf
  128. #define DDR_MAX_ROW_REG_SHIFT 8
  129. /* DDR0_08 */
  130. #define DDR_DDR2_MODE 0x1
  131. #define DDR_DDR2_MODE_SHIFT 0
  132. /* DDR0_10 */
  133. #define DDR_CS_MAP 0x3
  134. #define DDR_CS_MAP_SHIFT 8
  135. /* DDR0_14 */
  136. #define DDR_REDUC 0x1
  137. #define DDR_REDUC_SHIFT 16
  138. /* DDR0_42 */
  139. #define DDR_APIN 0x7
  140. #define DDR_APIN_SHIFT 24
  141. /* DDR0_43 */
  142. #define DDR_COL_SZ 0x7
  143. #define DDR_COL_SZ_SHIFT 8
  144. #define DDR_BANK8 0x1
  145. #define DDR_BANK8_SHIFT 0
  146. #define DDR_GET_VAL(val, mask, shift) (((val) >> (shift)) & (mask))
  147. /*
  148. * Some U-Boot versions set the number of chipselects to two
  149. * for Sequoia/Rainier boards while they only have one chipselect
  150. * hardwired. Hardcode the number of chipselects to one
  151. * for sequioa/rainer board models or read the actual value
  152. * from the memory controller register DDR0_10 otherwise.
  153. */
  154. static inline u32 ibm4xx_denali_get_cs(void)
  155. {
  156. void *devp;
  157. char model[64];
  158. u32 val, cs;
  159. devp = finddevice("/");
  160. if (!devp)
  161. goto read_cs;
  162. if (getprop(devp, "model", model, sizeof(model)) <= 0)
  163. goto read_cs;
  164. model[sizeof(model)-1] = 0;
  165. if (!strcmp(model, "amcc,sequoia") ||
  166. !strcmp(model, "amcc,rainier"))
  167. return 1;
  168. read_cs:
  169. /* get CS value */
  170. val = SDRAM0_READ(DDR0_10);
  171. val = DDR_GET_VAL(val, DDR_CS_MAP, DDR_CS_MAP_SHIFT);
  172. cs = 0;
  173. while (val) {
  174. if (val & 0x1)
  175. cs++;
  176. val = val >> 1;
  177. }
  178. return cs;
  179. }
  180. void ibm4xx_denali_fixup_memsize(void)
  181. {
  182. u32 val, max_cs, max_col, max_row;
  183. u32 cs, col, row, bank, dpath;
  184. unsigned long memsize;
  185. val = SDRAM0_READ(DDR0_02);
  186. if (!DDR_GET_VAL(val, DDR_START, DDR_START_SHIFT))
  187. fatal("DDR controller is not initialized\n");
  188. /* get maximum cs col and row values */
  189. max_cs = DDR_GET_VAL(val, DDR_MAX_CS_REG, DDR_MAX_CS_REG_SHIFT);
  190. max_col = DDR_GET_VAL(val, DDR_MAX_COL_REG, DDR_MAX_COL_REG_SHIFT);
  191. max_row = DDR_GET_VAL(val, DDR_MAX_ROW_REG, DDR_MAX_ROW_REG_SHIFT);
  192. cs = ibm4xx_denali_get_cs();
  193. if (!cs)
  194. fatal("No memory installed\n");
  195. if (cs > max_cs)
  196. fatal("DDR wrong CS configuration\n");
  197. /* get data path bytes */
  198. val = SDRAM0_READ(DDR0_14);
  199. if (DDR_GET_VAL(val, DDR_REDUC, DDR_REDUC_SHIFT))
  200. dpath = 4; /* 32 bits */
  201. else
  202. dpath = 8; /* 64 bits */
  203. /* get address pins (rows) */
  204. val = SDRAM0_READ(DDR0_42);
  205. row = DDR_GET_VAL(val, DDR_APIN, DDR_APIN_SHIFT);
  206. if (row > max_row)
  207. fatal("DDR wrong APIN configuration\n");
  208. row = max_row - row;
  209. /* get collomn size and banks */
  210. val = SDRAM0_READ(DDR0_43);
  211. col = DDR_GET_VAL(val, DDR_COL_SZ, DDR_COL_SZ_SHIFT);
  212. if (col > max_col)
  213. fatal("DDR wrong COL configuration\n");
  214. col = max_col - col;
  215. if (DDR_GET_VAL(val, DDR_BANK8, DDR_BANK8_SHIFT))
  216. bank = 8; /* 8 banks */
  217. else
  218. bank = 4; /* 4 banks */
  219. memsize = cs * (1 << (col+row)) * bank * dpath;
  220. memsize = chip_11_errata(memsize);
  221. dt_fixup_memory(0, memsize);
  222. }
  223. #define SPRN_DBCR0_40X 0x3F2
  224. #define SPRN_DBCR0_44X 0x134
  225. #define DBCR0_RST_SYSTEM 0x30000000
  226. void ibm44x_dbcr_reset(void)
  227. {
  228. unsigned long tmp;
  229. asm volatile (
  230. "mfspr %0,%1\n"
  231. "oris %0,%0,%2@h\n"
  232. "mtspr %1,%0"
  233. : "=&r"(tmp) : "i"(SPRN_DBCR0_44X), "i"(DBCR0_RST_SYSTEM)
  234. );
  235. }
  236. void ibm40x_dbcr_reset(void)
  237. {
  238. unsigned long tmp;
  239. asm volatile (
  240. "mfspr %0,%1\n"
  241. "oris %0,%0,%2@h\n"
  242. "mtspr %1,%0"
  243. : "=&r"(tmp) : "i"(SPRN_DBCR0_40X), "i"(DBCR0_RST_SYSTEM)
  244. );
  245. }
  246. #define EMAC_RESET 0x20000000
  247. void ibm4xx_quiesce_eth(u32 *emac0, u32 *emac1)
  248. {
  249. /* Quiesce the MAL and EMAC(s) since PIBS/OpenBIOS don't
  250. * do this for us
  251. */
  252. if (emac0)
  253. *emac0 = EMAC_RESET;
  254. if (emac1)
  255. *emac1 = EMAC_RESET;
  256. mtdcr(DCRN_MAL0_CFG, MAL_RESET);
  257. while (mfdcr(DCRN_MAL0_CFG) & MAL_RESET)
  258. ; /* loop until reset takes effect */
  259. }
  260. /* Read 4xx EBC bus bridge registers to get mappings of the peripheral
  261. * banks into the OPB address space */
  262. void ibm4xx_fixup_ebc_ranges(const char *ebc)
  263. {
  264. void *devp;
  265. u32 bxcr;
  266. u32 ranges[EBC_NUM_BANKS*4];
  267. u32 *p = ranges;
  268. int i;
  269. for (i = 0; i < EBC_NUM_BANKS; i++) {
  270. mtdcr(DCRN_EBC0_CFGADDR, EBC_BXCR(i));
  271. bxcr = mfdcr(DCRN_EBC0_CFGDATA);
  272. if ((bxcr & EBC_BXCR_BU) != EBC_BXCR_BU_OFF) {
  273. *p++ = i;
  274. *p++ = 0;
  275. *p++ = bxcr & EBC_BXCR_BAS;
  276. *p++ = EBC_BXCR_BANK_SIZE(bxcr);
  277. }
  278. }
  279. devp = finddevice(ebc);
  280. if (! devp)
  281. fatal("Couldn't locate EBC node %s\n\r", ebc);
  282. setprop(devp, "ranges", ranges, (p - ranges) * sizeof(u32));
  283. }
  284. /* Calculate 440GP clocks */
  285. void ibm440gp_fixup_clocks(unsigned int sys_clk, unsigned int ser_clk)
  286. {
  287. u32 sys0 = mfdcr(DCRN_CPC0_SYS0);
  288. u32 cr0 = mfdcr(DCRN_CPC0_CR0);
  289. u32 cpu, plb, opb, ebc, tb, uart0, uart1, m;
  290. u32 opdv = CPC0_SYS0_OPDV(sys0);
  291. u32 epdv = CPC0_SYS0_EPDV(sys0);
  292. if (sys0 & CPC0_SYS0_BYPASS) {
  293. /* Bypass system PLL */
  294. cpu = plb = sys_clk;
  295. } else {
  296. if (sys0 & CPC0_SYS0_EXTSL)
  297. /* PerClk */
  298. m = CPC0_SYS0_FWDVB(sys0) * opdv * epdv;
  299. else
  300. /* CPU clock */
  301. m = CPC0_SYS0_FBDV(sys0) * CPC0_SYS0_FWDVA(sys0);
  302. cpu = sys_clk * m / CPC0_SYS0_FWDVA(sys0);
  303. plb = sys_clk * m / CPC0_SYS0_FWDVB(sys0);
  304. }
  305. opb = plb / opdv;
  306. ebc = opb / epdv;
  307. /* FIXME: Check if this is for all 440GP, or just Ebony */
  308. if ((mfpvr() & 0xf0000fff) == 0x40000440)
  309. /* Rev. B 440GP, use external system clock */
  310. tb = sys_clk;
  311. else
  312. /* Rev. C 440GP, errata force us to use internal clock */
  313. tb = cpu;
  314. if (cr0 & CPC0_CR0_U0EC)
  315. /* External UART clock */
  316. uart0 = ser_clk;
  317. else
  318. /* Internal UART clock */
  319. uart0 = plb / CPC0_CR0_UDIV(cr0);
  320. if (cr0 & CPC0_CR0_U1EC)
  321. /* External UART clock */
  322. uart1 = ser_clk;
  323. else
  324. /* Internal UART clock */
  325. uart1 = plb / CPC0_CR0_UDIV(cr0);
  326. printf("PPC440GP: SysClk = %dMHz (%x)\n\r",
  327. (sys_clk + 500000) / 1000000, sys_clk);
  328. dt_fixup_cpu_clocks(cpu, tb, 0);
  329. dt_fixup_clock("/plb", plb);
  330. dt_fixup_clock("/plb/opb", opb);
  331. dt_fixup_clock("/plb/opb/ebc", ebc);
  332. dt_fixup_clock("/plb/opb/serial@40000200", uart0);
  333. dt_fixup_clock("/plb/opb/serial@40000300", uart1);
  334. }
  335. #define SPRN_CCR1 0x378
  336. static inline u32 __fix_zero(u32 v, u32 def)
  337. {
  338. return v ? v : def;
  339. }
  340. static unsigned int __ibm440eplike_fixup_clocks(unsigned int sys_clk,
  341. unsigned int tmr_clk,
  342. int per_clk_from_opb)
  343. {
  344. /* PLL config */
  345. u32 pllc = CPR0_READ(DCRN_CPR0_PLLC);
  346. u32 plld = CPR0_READ(DCRN_CPR0_PLLD);
  347. /* Dividers */
  348. u32 fbdv = __fix_zero((plld >> 24) & 0x1f, 32);
  349. u32 fwdva = __fix_zero((plld >> 16) & 0xf, 16);
  350. u32 fwdvb = __fix_zero((plld >> 8) & 7, 8);
  351. u32 lfbdv = __fix_zero(plld & 0x3f, 64);
  352. u32 pradv0 = __fix_zero((CPR0_READ(DCRN_CPR0_PRIMAD) >> 24) & 7, 8);
  353. u32 prbdv0 = __fix_zero((CPR0_READ(DCRN_CPR0_PRIMBD) >> 24) & 7, 8);
  354. u32 opbdv0 = __fix_zero((CPR0_READ(DCRN_CPR0_OPBD) >> 24) & 3, 4);
  355. u32 perdv0 = __fix_zero((CPR0_READ(DCRN_CPR0_PERD) >> 24) & 3, 4);
  356. /* Input clocks for primary dividers */
  357. u32 clk_a, clk_b;
  358. /* Resulting clocks */
  359. u32 cpu, plb, opb, ebc, vco;
  360. /* Timebase */
  361. u32 ccr1, tb = tmr_clk;
  362. if (pllc & 0x40000000) {
  363. u32 m;
  364. /* Feedback path */
  365. switch ((pllc >> 24) & 7) {
  366. case 0:
  367. /* PLLOUTx */
  368. m = ((pllc & 0x20000000) ? fwdvb : fwdva) * lfbdv;
  369. break;
  370. case 1:
  371. /* CPU */
  372. m = fwdva * pradv0;
  373. break;
  374. case 5:
  375. /* PERClk */
  376. m = fwdvb * prbdv0 * opbdv0 * perdv0;
  377. break;
  378. default:
  379. printf("WARNING ! Invalid PLL feedback source !\n");
  380. goto bypass;
  381. }
  382. m *= fbdv;
  383. vco = sys_clk * m;
  384. clk_a = vco / fwdva;
  385. clk_b = vco / fwdvb;
  386. } else {
  387. bypass:
  388. /* Bypass system PLL */
  389. vco = 0;
  390. clk_a = clk_b = sys_clk;
  391. }
  392. cpu = clk_a / pradv0;
  393. plb = clk_b / prbdv0;
  394. opb = plb / opbdv0;
  395. ebc = (per_clk_from_opb ? opb : plb) / perdv0;
  396. /* Figure out timebase. Either CPU or default TmrClk */
  397. ccr1 = mfspr(SPRN_CCR1);
  398. /* If passed a 0 tmr_clk, force CPU clock */
  399. if (tb == 0) {
  400. ccr1 &= ~0x80u;
  401. mtspr(SPRN_CCR1, ccr1);
  402. }
  403. if ((ccr1 & 0x0080) == 0)
  404. tb = cpu;
  405. dt_fixup_cpu_clocks(cpu, tb, 0);
  406. dt_fixup_clock("/plb", plb);
  407. dt_fixup_clock("/plb/opb", opb);
  408. dt_fixup_clock("/plb/opb/ebc", ebc);
  409. return plb;
  410. }
  411. static void eplike_fixup_uart_clk(int index, const char *path,
  412. unsigned int ser_clk,
  413. unsigned int plb_clk)
  414. {
  415. unsigned int sdr;
  416. unsigned int clock;
  417. switch (index) {
  418. case 0:
  419. sdr = SDR0_READ(DCRN_SDR0_UART0);
  420. break;
  421. case 1:
  422. sdr = SDR0_READ(DCRN_SDR0_UART1);
  423. break;
  424. case 2:
  425. sdr = SDR0_READ(DCRN_SDR0_UART2);
  426. break;
  427. case 3:
  428. sdr = SDR0_READ(DCRN_SDR0_UART3);
  429. break;
  430. default:
  431. return;
  432. }
  433. if (sdr & 0x00800000u)
  434. clock = ser_clk;
  435. else
  436. clock = plb_clk / __fix_zero(sdr & 0xff, 256);
  437. dt_fixup_clock(path, clock);
  438. }
  439. void ibm440ep_fixup_clocks(unsigned int sys_clk,
  440. unsigned int ser_clk,
  441. unsigned int tmr_clk)
  442. {
  443. unsigned int plb_clk = __ibm440eplike_fixup_clocks(sys_clk, tmr_clk, 0);
  444. /* serial clocks need fixup based on int/ext */
  445. eplike_fixup_uart_clk(0, "/plb/opb/serial@ef600300", ser_clk, plb_clk);
  446. eplike_fixup_uart_clk(1, "/plb/opb/serial@ef600400", ser_clk, plb_clk);
  447. eplike_fixup_uart_clk(2, "/plb/opb/serial@ef600500", ser_clk, plb_clk);
  448. eplike_fixup_uart_clk(3, "/plb/opb/serial@ef600600", ser_clk, plb_clk);
  449. }
  450. void ibm440gx_fixup_clocks(unsigned int sys_clk,
  451. unsigned int ser_clk,
  452. unsigned int tmr_clk)
  453. {
  454. unsigned int plb_clk = __ibm440eplike_fixup_clocks(sys_clk, tmr_clk, 1);
  455. /* serial clocks need fixup based on int/ext */
  456. eplike_fixup_uart_clk(0, "/plb/opb/serial@40000200", ser_clk, plb_clk);
  457. eplike_fixup_uart_clk(1, "/plb/opb/serial@40000300", ser_clk, plb_clk);
  458. }
  459. void ibm440spe_fixup_clocks(unsigned int sys_clk,
  460. unsigned int ser_clk,
  461. unsigned int tmr_clk)
  462. {
  463. unsigned int plb_clk = __ibm440eplike_fixup_clocks(sys_clk, tmr_clk, 1);
  464. /* serial clocks need fixup based on int/ext */
  465. eplike_fixup_uart_clk(0, "/plb/opb/serial@f0000200", ser_clk, plb_clk);
  466. eplike_fixup_uart_clk(1, "/plb/opb/serial@f0000300", ser_clk, plb_clk);
  467. eplike_fixup_uart_clk(2, "/plb/opb/serial@f0000600", ser_clk, plb_clk);
  468. }
  469. void ibm405gp_fixup_clocks(unsigned int sys_clk, unsigned int ser_clk)
  470. {
  471. u32 pllmr = mfdcr(DCRN_CPC0_PLLMR);
  472. u32 cpc0_cr0 = mfdcr(DCRN_405_CPC0_CR0);
  473. u32 cpc0_cr1 = mfdcr(DCRN_405_CPC0_CR1);
  474. u32 psr = mfdcr(DCRN_405_CPC0_PSR);
  475. u32 cpu, plb, opb, ebc, tb, uart0, uart1, m;
  476. u32 fwdv, fwdvb, fbdv, cbdv, opdv, epdv, ppdv, udiv;
  477. fwdv = (8 - ((pllmr & 0xe0000000) >> 29));
  478. fbdv = (pllmr & 0x1e000000) >> 25;
  479. if (fbdv == 0)
  480. fbdv = 16;
  481. cbdv = ((pllmr & 0x00060000) >> 17) + 1; /* CPU:PLB */
  482. opdv = ((pllmr & 0x00018000) >> 15) + 1; /* PLB:OPB */
  483. ppdv = ((pllmr & 0x00001800) >> 13) + 1; /* PLB:PCI */
  484. epdv = ((pllmr & 0x00001800) >> 11) + 2; /* PLB:EBC */
  485. udiv = ((cpc0_cr0 & 0x3e) >> 1) + 1;
  486. /* check for 405GPr */
  487. if ((mfpvr() & 0xfffffff0) == (0x50910951 & 0xfffffff0)) {
  488. fwdvb = 8 - (pllmr & 0x00000007);
  489. if (!(psr & 0x00001000)) /* PCI async mode enable == 0 */
  490. if (psr & 0x00000020) /* New mode enable */
  491. m = fwdvb * 2 * ppdv;
  492. else
  493. m = fwdvb * cbdv * ppdv;
  494. else if (psr & 0x00000020) /* New mode enable */
  495. if (psr & 0x00000800) /* PerClk synch mode */
  496. m = fwdvb * 2 * epdv;
  497. else
  498. m = fbdv * fwdv;
  499. else if (epdv == fbdv)
  500. m = fbdv * cbdv * epdv;
  501. else
  502. m = fbdv * fwdvb * cbdv;
  503. cpu = sys_clk * m / fwdv;
  504. plb = sys_clk * m / (fwdvb * cbdv);
  505. } else {
  506. m = fwdv * fbdv * cbdv;
  507. cpu = sys_clk * m / fwdv;
  508. plb = cpu / cbdv;
  509. }
  510. opb = plb / opdv;
  511. ebc = plb / epdv;
  512. if (cpc0_cr0 & 0x80)
  513. /* uart0 uses the external clock */
  514. uart0 = ser_clk;
  515. else
  516. uart0 = cpu / udiv;
  517. if (cpc0_cr0 & 0x40)
  518. /* uart1 uses the external clock */
  519. uart1 = ser_clk;
  520. else
  521. uart1 = cpu / udiv;
  522. /* setup the timebase clock to tick at the cpu frequency */
  523. cpc0_cr1 = cpc0_cr1 & ~0x00800000;
  524. mtdcr(DCRN_405_CPC0_CR1, cpc0_cr1);
  525. tb = cpu;
  526. dt_fixup_cpu_clocks(cpu, tb, 0);
  527. dt_fixup_clock("/plb", plb);
  528. dt_fixup_clock("/plb/opb", opb);
  529. dt_fixup_clock("/plb/ebc", ebc);
  530. dt_fixup_clock("/plb/opb/serial@ef600300", uart0);
  531. dt_fixup_clock("/plb/opb/serial@ef600400", uart1);
  532. }
  533. void ibm405ep_fixup_clocks(unsigned int sys_clk)
  534. {
  535. u32 pllmr0 = mfdcr(DCRN_CPC0_PLLMR0);
  536. u32 pllmr1 = mfdcr(DCRN_CPC0_PLLMR1);
  537. u32 cpc0_ucr = mfdcr(DCRN_CPC0_UCR);
  538. u32 cpu, plb, opb, ebc, uart0, uart1;
  539. u32 fwdva, fwdvb, fbdv, cbdv, opdv, epdv;
  540. u32 pllmr0_ccdv, tb, m;
  541. fwdva = 8 - ((pllmr1 & 0x00070000) >> 16);
  542. fwdvb = 8 - ((pllmr1 & 0x00007000) >> 12);
  543. fbdv = (pllmr1 & 0x00f00000) >> 20;
  544. if (fbdv == 0)
  545. fbdv = 16;
  546. cbdv = ((pllmr0 & 0x00030000) >> 16) + 1; /* CPU:PLB */
  547. epdv = ((pllmr0 & 0x00000300) >> 8) + 2; /* PLB:EBC */
  548. opdv = ((pllmr0 & 0x00003000) >> 12) + 1; /* PLB:OPB */
  549. m = fbdv * fwdvb;
  550. pllmr0_ccdv = ((pllmr0 & 0x00300000) >> 20) + 1;
  551. if (pllmr1 & 0x80000000)
  552. cpu = sys_clk * m / (fwdva * pllmr0_ccdv);
  553. else
  554. cpu = sys_clk / pllmr0_ccdv;
  555. plb = cpu / cbdv;
  556. opb = plb / opdv;
  557. ebc = plb / epdv;
  558. tb = cpu;
  559. uart0 = cpu / (cpc0_ucr & 0x0000007f);
  560. uart1 = cpu / ((cpc0_ucr & 0x00007f00) >> 8);
  561. dt_fixup_cpu_clocks(cpu, tb, 0);
  562. dt_fixup_clock("/plb", plb);
  563. dt_fixup_clock("/plb/opb", opb);
  564. dt_fixup_clock("/plb/ebc", ebc);
  565. dt_fixup_clock("/plb/opb/serial@ef600300", uart0);
  566. dt_fixup_clock("/plb/opb/serial@ef600400", uart1);
  567. }
  568. static u8 ibm405ex_fwdv_multi_bits[] = {
  569. /* values for: 1 - 16 */
  570. 0x01, 0x02, 0x0e, 0x09, 0x04, 0x0b, 0x10, 0x0d, 0x0c, 0x05,
  571. 0x06, 0x0f, 0x0a, 0x07, 0x08, 0x03
  572. };
  573. u32 ibm405ex_get_fwdva(unsigned long cpr_fwdv)
  574. {
  575. u32 index;
  576. for (index = 0; index < ARRAY_SIZE(ibm405ex_fwdv_multi_bits); index++)
  577. if (cpr_fwdv == (u32)ibm405ex_fwdv_multi_bits[index])
  578. return index + 1;
  579. return 0;
  580. }
  581. static u8 ibm405ex_fbdv_multi_bits[] = {
  582. /* values for: 1 - 100 */
  583. 0x00, 0xff, 0x7e, 0xfd, 0x7a, 0xf5, 0x6a, 0xd5, 0x2a, 0xd4,
  584. 0x29, 0xd3, 0x26, 0xcc, 0x19, 0xb3, 0x67, 0xce, 0x1d, 0xbb,
  585. 0x77, 0xee, 0x5d, 0xba, 0x74, 0xe9, 0x52, 0xa5, 0x4b, 0x96,
  586. 0x2c, 0xd8, 0x31, 0xe3, 0x46, 0x8d, 0x1b, 0xb7, 0x6f, 0xde,
  587. 0x3d, 0xfb, 0x76, 0xed, 0x5a, 0xb5, 0x6b, 0xd6, 0x2d, 0xdb,
  588. 0x36, 0xec, 0x59, 0xb2, 0x64, 0xc9, 0x12, 0xa4, 0x48, 0x91,
  589. 0x23, 0xc7, 0x0e, 0x9c, 0x38, 0xf0, 0x61, 0xc2, 0x05, 0x8b,
  590. 0x17, 0xaf, 0x5f, 0xbe, 0x7c, 0xf9, 0x72, 0xe5, 0x4a, 0x95,
  591. 0x2b, 0xd7, 0x2e, 0xdc, 0x39, 0xf3, 0x66, 0xcd, 0x1a, 0xb4,
  592. 0x68, 0xd1, 0x22, 0xc4, 0x09, 0x93, 0x27, 0xcf, 0x1e, 0xbc,
  593. /* values for: 101 - 200 */
  594. 0x78, 0xf1, 0x62, 0xc5, 0x0a, 0x94, 0x28, 0xd0, 0x21, 0xc3,
  595. 0x06, 0x8c, 0x18, 0xb0, 0x60, 0xc1, 0x02, 0x84, 0x08, 0x90,
  596. 0x20, 0xc0, 0x01, 0x83, 0x07, 0x8f, 0x1f, 0xbf, 0x7f, 0xfe,
  597. 0x7d, 0xfa, 0x75, 0xea, 0x55, 0xaa, 0x54, 0xa9, 0x53, 0xa6,
  598. 0x4c, 0x99, 0x33, 0xe7, 0x4e, 0x9d, 0x3b, 0xf7, 0x6e, 0xdd,
  599. 0x3a, 0xf4, 0x69, 0xd2, 0x25, 0xcb, 0x16, 0xac, 0x58, 0xb1,
  600. 0x63, 0xc6, 0x0d, 0x9b, 0x37, 0xef, 0x5e, 0xbd, 0x7b, 0xf6,
  601. 0x6d, 0xda, 0x35, 0xeb, 0x56, 0xad, 0x5b, 0xb6, 0x6c, 0xd9,
  602. 0x32, 0xe4, 0x49, 0x92, 0x24, 0xc8, 0x11, 0xa3, 0x47, 0x8e,
  603. 0x1c, 0xb8, 0x70, 0xe1, 0x42, 0x85, 0x0b, 0x97, 0x2f, 0xdf,
  604. /* values for: 201 - 255 */
  605. 0x3e, 0xfc, 0x79, 0xf2, 0x65, 0xca, 0x15, 0xab, 0x57, 0xae,
  606. 0x5c, 0xb9, 0x73, 0xe6, 0x4d, 0x9a, 0x34, 0xe8, 0x51, 0xa2,
  607. 0x44, 0x89, 0x13, 0xa7, 0x4f, 0x9e, 0x3c, 0xf8, 0x71, 0xe2,
  608. 0x45, 0x8a, 0x14, 0xa8, 0x50, 0xa1, 0x43, 0x86, 0x0c, 0x98,
  609. 0x30, 0xe0, 0x41, 0x82, 0x04, 0x88, 0x10, 0xa0, 0x40, 0x81,
  610. 0x03, 0x87, 0x0f, 0x9f, 0x3f /* END */
  611. };
  612. u32 ibm405ex_get_fbdv(unsigned long cpr_fbdv)
  613. {
  614. u32 index;
  615. for (index = 0; index < ARRAY_SIZE(ibm405ex_fbdv_multi_bits); index++)
  616. if (cpr_fbdv == (u32)ibm405ex_fbdv_multi_bits[index])
  617. return index + 1;
  618. return 0;
  619. }
  620. void ibm405ex_fixup_clocks(unsigned int sys_clk, unsigned int uart_clk)
  621. {
  622. /* PLL config */
  623. u32 pllc = CPR0_READ(DCRN_CPR0_PLLC);
  624. u32 plld = CPR0_READ(DCRN_CPR0_PLLD);
  625. u32 cpud = CPR0_READ(DCRN_CPR0_PRIMAD);
  626. u32 plbd = CPR0_READ(DCRN_CPR0_PRIMBD);
  627. u32 opbd = CPR0_READ(DCRN_CPR0_OPBD);
  628. u32 perd = CPR0_READ(DCRN_CPR0_PERD);
  629. /* Dividers */
  630. u32 fbdv = ibm405ex_get_fbdv(__fix_zero((plld >> 24) & 0xff, 1));
  631. u32 fwdva = ibm405ex_get_fwdva(__fix_zero((plld >> 16) & 0x0f, 1));
  632. u32 cpudv0 = __fix_zero((cpud >> 24) & 7, 8);
  633. /* PLBDV0 is hardwared to 010. */
  634. u32 plbdv0 = 2;
  635. u32 plb2xdv0 = __fix_zero((plbd >> 16) & 7, 8);
  636. u32 opbdv0 = __fix_zero((opbd >> 24) & 3, 4);
  637. u32 perdv0 = __fix_zero((perd >> 24) & 3, 4);
  638. /* Resulting clocks */
  639. u32 cpu, plb, opb, ebc, vco, tb, uart0, uart1;
  640. /* PLL's VCO is the source for primary forward ? */
  641. if (pllc & 0x40000000) {
  642. u32 m;
  643. /* Feedback path */
  644. switch ((pllc >> 24) & 7) {
  645. case 0:
  646. /* PLLOUTx */
  647. m = fbdv;
  648. break;
  649. case 1:
  650. /* CPU */
  651. m = fbdv * fwdva * cpudv0;
  652. break;
  653. case 5:
  654. /* PERClk */
  655. m = fbdv * fwdva * plb2xdv0 * plbdv0 * opbdv0 * perdv0;
  656. break;
  657. default:
  658. printf("WARNING ! Invalid PLL feedback source !\n");
  659. goto bypass;
  660. }
  661. vco = (unsigned int)(sys_clk * m);
  662. } else {
  663. bypass:
  664. /* Bypass system PLL */
  665. vco = 0;
  666. }
  667. /* CPU = VCO / ( FWDVA x CPUDV0) */
  668. cpu = vco / (fwdva * cpudv0);
  669. /* PLB = VCO / ( FWDVA x PLB2XDV0 x PLBDV0) */
  670. plb = vco / (fwdva * plb2xdv0 * plbdv0);
  671. /* OPB = PLB / OPBDV0 */
  672. opb = plb / opbdv0;
  673. /* EBC = OPB / PERDV0 */
  674. ebc = opb / perdv0;
  675. tb = cpu;
  676. uart0 = uart1 = uart_clk;
  677. dt_fixup_cpu_clocks(cpu, tb, 0);
  678. dt_fixup_clock("/plb", plb);
  679. dt_fixup_clock("/plb/opb", opb);
  680. dt_fixup_clock("/plb/opb/ebc", ebc);
  681. dt_fixup_clock("/plb/opb/serial@ef600200", uart0);
  682. dt_fixup_clock("/plb/opb/serial@ef600300", uart1);
  683. }