pmc405de.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*
  2. * (C) Copyright 2009
  3. * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd.eu
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <console.h>
  9. #include <libfdt.h>
  10. #include <fdt_support.h>
  11. #include <asm/processor.h>
  12. #include <asm/io.h>
  13. #include <asm/ppc4xx-gpio.h>
  14. #include <asm/4xx_pci.h>
  15. #include <command.h>
  16. #include <malloc.h>
  17. /*
  18. * PMC405-DE cpld registers
  19. * - all registers are 8 bit
  20. * - all registers are on 32 bit addesses
  21. */
  22. struct pmc405de_cpld {
  23. /* cpld design version */
  24. u8 version;
  25. u8 reserved0[3];
  26. /* misc. status lines */
  27. u8 status;
  28. u8 reserved1[3];
  29. /*
  30. * gated control flags
  31. * gate bit(s) must be written with '1' to
  32. * access control flag
  33. */
  34. u8 control;
  35. u8 reserved2[3];
  36. };
  37. #define CPLD_VERSION_MASK 0x0f
  38. #define CPLD_CONTROL_POSTLED_N 0x01
  39. #define CPLD_CONTROL_POSTLED_GATE 0x02
  40. #define CPLD_CONTROL_RESETOUT_N 0x40
  41. #define CPLD_CONTROL_RESETOUT_N_GATE 0x80
  42. DECLARE_GLOBAL_DATA_PTR;
  43. extern void __ft_board_setup(void *blob, bd_t *bd);
  44. extern void pll_write(u32 a, u32 b);
  45. static int wait_for_pci_ready_done;
  46. static int is_monarch(void);
  47. static int pci_is_66mhz(void);
  48. static int board_revision(void);
  49. static int cpld_revision(void);
  50. static void upd_plb_pci_div(u32 pllmr0, u32 pllmr1, u32 div);
  51. int board_early_init_f(void)
  52. {
  53. u32 pllmr0, pllmr1;
  54. /*
  55. * check M66EN and patch PLB:PCI divider for 66MHz PCI
  56. *
  57. * fCPU==333MHz && fPCI==66MHz (PLBDiv==3 && M66EN==1): PLB/PCI=1
  58. * fCPU==333MHz && fPCI==33MHz (PLBDiv==3 && M66EN==0): PLB/PCI=2
  59. * fCPU==133|266MHz && fPCI==66MHz (PLBDiv==1|2 && M66EN==1): PLB/PCI=2
  60. * fCPU==133|266MHz && fPCI==33MHz (PLBDiv==1|2 && M66EN==0): PLB/PCI=3
  61. *
  62. * calling upd_plb_pci_div() may end in calling pll_write() which will
  63. * do a chip reset and never return.
  64. */
  65. pllmr0 = mfdcr(CPC0_PLLMR0);
  66. pllmr1 = mfdcr(CPC0_PLLMR1);
  67. if ((pllmr0 & PLLMR0_CPU_TO_PLB_MASK) == PLLMR0_CPU_PLB_DIV_3) {
  68. /* fCPU=333MHz, fPLB=111MHz */
  69. if (pci_is_66mhz())
  70. upd_plb_pci_div(pllmr0, pllmr1, PLLMR0_PCI_PLB_DIV_1);
  71. else
  72. upd_plb_pci_div(pllmr0, pllmr1, PLLMR0_PCI_PLB_DIV_2);
  73. } else {
  74. /* fCPU=133|266MHz, fPLB=133MHz */
  75. if (pci_is_66mhz())
  76. upd_plb_pci_div(pllmr0, pllmr1, PLLMR0_PCI_PLB_DIV_2);
  77. else
  78. upd_plb_pci_div(pllmr0, pllmr1, PLLMR0_PCI_PLB_DIV_3);
  79. }
  80. /*
  81. * IRQ 25 (EXT IRQ 0) PCI-INTA#; active low; level sensitive
  82. * IRQ 26 (EXT IRQ 1) PCI-INTB#; active low; level sensitive
  83. * IRQ 27 (EXT IRQ 2) PCI-INTC#; active low; level sensitive
  84. * IRQ 28 (EXT IRQ 3) PCI-INTD#; active low; level sensitive
  85. * IRQ 29 (EXT IRQ 4) ETH0-PHY-IRQ#; active low; level sensitive
  86. * IRQ 30 (EXT IRQ 5) ETH1-PHY-IRQ#; active low; level sensitive
  87. * IRQ 31 (EXT IRQ 6) PLD-IRQ#; active low; level sensitive
  88. */
  89. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  90. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  91. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
  92. mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */
  93. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  94. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0, INT0 highest prio */
  95. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  96. /*
  97. * EBC Configuration Register:
  98. * - set ready timeout to 512 ebc-clks -> ca. 15 us
  99. * - EBC lines are always driven
  100. */
  101. mtebc(EBC0_CFG, 0xa8400000);
  102. return 0;
  103. }
  104. static void upd_plb_pci_div(u32 pllmr0, u32 pllmr1, u32 div)
  105. {
  106. if ((pllmr0 & PLLMR0_PCI_TO_PLB_MASK) != div)
  107. pll_write((pllmr0 & ~PLLMR0_PCI_TO_PLB_MASK) | div, pllmr1);
  108. }
  109. int misc_init_r(void)
  110. {
  111. int i;
  112. struct ppc4xx_gpio *gpio0 = (struct ppc4xx_gpio *)GPIO_BASE;
  113. struct pmc405de_cpld *cpld =
  114. (struct pmc405de_cpld *)CONFIG_SYS_CPLD_BASE;
  115. if (!is_monarch()) {
  116. /* PCI configuration done: release EREADY */
  117. setbits_be32(&gpio0->or, CONFIG_SYS_GPIO_EREADY);
  118. setbits_be32(&gpio0->tcr, CONFIG_SYS_GPIO_EREADY);
  119. }
  120. /* turn off POST LED */
  121. out_8(&cpld->control,
  122. CPLD_CONTROL_POSTLED_N | CPLD_CONTROL_POSTLED_GATE);
  123. /* turn on LEDs: RUN, A, B */
  124. clrbits_be32(&gpio0->or,
  125. CONFIG_SYS_GPIO_LEDRUN_N |
  126. CONFIG_SYS_GPIO_LEDA_N |
  127. CONFIG_SYS_GPIO_LEDB_N);
  128. for (i=0; i < 200; i++)
  129. udelay(1000);
  130. /* turn off LEDs: A, B */
  131. setbits_be32(&gpio0->or,
  132. CONFIG_SYS_GPIO_LEDA_N |
  133. CONFIG_SYS_GPIO_LEDB_N);
  134. return (0);
  135. }
  136. static int is_monarch(void)
  137. {
  138. struct ppc4xx_gpio *gpio0 = (struct ppc4xx_gpio *)GPIO_BASE;
  139. return (in_be32(&gpio0->ir) & CONFIG_SYS_GPIO_MONARCH_N) == 0;
  140. }
  141. static int pci_is_66mhz(void)
  142. {
  143. struct ppc4xx_gpio *gpio0 = (struct ppc4xx_gpio *)GPIO_BASE;
  144. return (in_be32(&gpio0->ir) & CONFIG_SYS_GPIO_M66EN);
  145. }
  146. static int board_revision(void)
  147. {
  148. struct ppc4xx_gpio *gpio0 = (struct ppc4xx_gpio *)GPIO_BASE;
  149. return ((in_be32(&gpio0->ir) & CONFIG_SYS_GPIO_HWREV_MASK) >>
  150. CONFIG_SYS_GPIO_HWREV_SHIFT);
  151. }
  152. static int cpld_revision(void)
  153. {
  154. struct pmc405de_cpld *cpld =
  155. (struct pmc405de_cpld *)CONFIG_SYS_CPLD_BASE;
  156. return ((in_8(&cpld->version) & CPLD_VERSION_MASK));
  157. }
  158. /*
  159. * Check Board Identity
  160. */
  161. int checkboard(void)
  162. {
  163. puts("Board: esd GmbH - PMC-CPU/405-DE");
  164. gd->board_type = board_revision();
  165. printf(", Rev 1.%ld, ", gd->board_type);
  166. if (!is_monarch())
  167. puts("non-");
  168. printf("monarch, PCI=%s MHz, PLD-Rev 1.%d\n",
  169. pci_is_66mhz() ? "66" : "33", cpld_revision());
  170. return 0;
  171. }
  172. static void wait_for_pci_ready(void)
  173. {
  174. struct ppc4xx_gpio *gpio0 = (struct ppc4xx_gpio *)GPIO_BASE;
  175. int i;
  176. char *s = getenv("pcidelay");
  177. /* only wait once */
  178. if (wait_for_pci_ready_done)
  179. return;
  180. /*
  181. * We have our own handling of the pcidelay variable.
  182. * Using CONFIG_PCI_BOOTDELAY enables pausing for host
  183. * and adapter devices. For adapter devices we do not
  184. * want this.
  185. */
  186. if (s) {
  187. int ms = simple_strtoul(s, NULL, 10);
  188. printf("PCI: Waiting for %d ms\n", ms);
  189. for (i=0; i<ms; i++)
  190. udelay(1000);
  191. }
  192. if (!(in_be32(&gpio0->ir) & CONFIG_SYS_GPIO_EREADY)) {
  193. printf("PCI: Waiting for EREADY (CTRL-C to skip) ... ");
  194. while (1) {
  195. if (ctrlc()) {
  196. puts("abort\n");
  197. break;
  198. }
  199. if (in_be32(&gpio0->ir) & CONFIG_SYS_GPIO_EREADY) {
  200. printf("done\n");
  201. break;
  202. }
  203. }
  204. }
  205. wait_for_pci_ready_done = 1;
  206. }
  207. /*
  208. * Overwrite weak is_pci_host()
  209. *
  210. * This routine is called to determine if a pci scan should be
  211. * performed. With various hardware environments (especially cPCI and
  212. * PPMC) it's insufficient to depend on the state of the arbiter enable
  213. * bit in the strap register, or generic host/adapter assumptions.
  214. *
  215. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  216. */
  217. int is_pci_host(struct pci_controller *hose)
  218. {
  219. char *s;
  220. if (!is_monarch()) {
  221. /*
  222. * Overwrite PCI identification when running in
  223. * non-monarch mode
  224. * This should be moved into pci_target_init()
  225. * when it is sometimes available for 405 CPUs
  226. */
  227. pci_write_config_word(PCIDEVID_405GP,
  228. PCI_SUBSYSTEM_ID,
  229. CONFIG_SYS_PCI_SUBSYS_ID_NONMONARCH);
  230. pci_write_config_word(PCIDEVID_405GP,
  231. PCI_CLASS_SUB_CODE,
  232. CONFIG_SYS_PCI_CLASSCODE_NONMONARCH);
  233. }
  234. s = getenv("pciscan");
  235. if (s == NULL) {
  236. if (is_monarch()) {
  237. wait_for_pci_ready();
  238. return 1;
  239. } else {
  240. return 0;
  241. }
  242. } else {
  243. if (!strcmp(s, "yes"))
  244. return 1;
  245. }
  246. return 0;
  247. }
  248. /*
  249. * Overwrite weak pci_pre_init()
  250. *
  251. * The default implementation enables the 405EP
  252. * internal PCI arbiter. We do not want that
  253. * on a PMC module.
  254. */
  255. int pci_pre_init(struct pci_controller *hose)
  256. {
  257. return 1;
  258. }
  259. #ifdef CONFIG_OF_BOARD_SETUP
  260. int ft_board_setup(void *blob, bd_t *bd)
  261. {
  262. int rc;
  263. __ft_board_setup(blob, bd);
  264. /*
  265. * Disable PCI in non-monarch mode.
  266. */
  267. if (!is_monarch()) {
  268. rc = fdt_find_and_setprop(blob, "/plb/pci@ec000000", "status",
  269. "disabled", sizeof("disabled"), 1);
  270. if (rc) {
  271. printf("Unable to update property status in PCI node, "
  272. "err=%s\n",
  273. fdt_strerror(rc));
  274. }
  275. }
  276. return 0;
  277. }
  278. #endif /* CONFIG_OF_BOARD_SETUP */
  279. #if defined(CONFIG_SYS_EEPROM_WREN)
  280. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  281. * <state> -1: deliver current state
  282. * 0: disable write
  283. * 1: enable write
  284. * Returns: -1: wrong device address
  285. * 0: dis-/en- able done
  286. * 0/1: current state if <state> was -1.
  287. */
  288. int eeprom_write_enable(unsigned dev_addr, int state)
  289. {
  290. struct ppc4xx_gpio *gpio0 = (struct ppc4xx_gpio *)GPIO_BASE;
  291. if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) {
  292. return -1;
  293. } else {
  294. switch (state) {
  295. case 1:
  296. /* Enable write access, clear bit GPIO0. */
  297. clrbits_be32(&gpio0->or, CONFIG_SYS_GPIO_EEPROM_WP);
  298. state = 0;
  299. break;
  300. case 0:
  301. /* Disable write access, set bit GPIO0. */
  302. setbits_be32(&gpio0->or, CONFIG_SYS_GPIO_EEPROM_WP);
  303. state = 0;
  304. break;
  305. default:
  306. /* Read current status back. */
  307. state = (0 == (in_be32(&gpio0->or) &
  308. CONFIG_SYS_GPIO_EEPROM_WP));
  309. break;
  310. }
  311. }
  312. return state;
  313. }
  314. int do_eep_wren(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  315. {
  316. int query = argc == 1;
  317. int state = 0;
  318. if (query) {
  319. /* Query write access state. */
  320. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, - 1);
  321. if (state < 0) {
  322. puts("Query of write access state failed.\n");
  323. } else {
  324. printf("Write access for device 0x%0x is %sabled.\n",
  325. CONFIG_SYS_I2C_EEPROM_ADDR,
  326. state ? "en" : "dis");
  327. state = 0;
  328. }
  329. } else {
  330. if ('0' == argv[1][0]) {
  331. /* Disable write access. */
  332. state = eeprom_write_enable(
  333. CONFIG_SYS_I2C_EEPROM_ADDR, 0);
  334. } else {
  335. /* Enable write access. */
  336. state = eeprom_write_enable(
  337. CONFIG_SYS_I2C_EEPROM_ADDR, 1);
  338. }
  339. if (state < 0)
  340. puts ("Setup of write access state failed.\n");
  341. }
  342. return state;
  343. }
  344. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  345. "Enable / disable / query EEPROM write access",
  346. ""
  347. );
  348. #endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */
  349. #if defined(CONFIG_PRAM)
  350. #include <environment.h>
  351. int do_painit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  352. {
  353. u32 pram, nextbase, base;
  354. char *v;
  355. u32 param;
  356. ulong *lptr;
  357. v = getenv("pram");
  358. if (v)
  359. pram = simple_strtoul(v, NULL, 10);
  360. else {
  361. printf("Error: pram undefined. Please define pram in KiB\n");
  362. return 1;
  363. }
  364. base = gd->bd->bi_memsize;
  365. #if defined(CONFIG_LOGBUFFER)
  366. base -= LOGBUFF_LEN + LOGBUFF_OVERHEAD;
  367. #endif
  368. /*
  369. * gd->bd->bi_memsize == physical ram size - CONFIG_SYS_MM_TOP_HIDE
  370. */
  371. param = base - (pram << 10);
  372. printf("PARAM: @%08x\n", param);
  373. debug("memsize=0x%08x, base=0x%08x\n", (u32)gd->bd->bi_memsize, base);
  374. /* clear entire PA ram */
  375. memset((void*)param, 0, (pram << 10));
  376. /* reserve 4k for pointer field */
  377. nextbase = base - 4096;
  378. lptr = (ulong*)(base);
  379. /*
  380. * *(--lptr) = item_size;
  381. * *(--lptr) = base - item_base = distance from field top;
  382. */
  383. /* env is first (4k aligned) */
  384. nextbase -= ((CONFIG_ENV_SIZE + 4096 - 1) & ~(4096 - 1));
  385. memcpy((void*)nextbase, env_ptr, CONFIG_ENV_SIZE);
  386. *(--lptr) = CONFIG_ENV_SIZE; /* size */
  387. *(--lptr) = base - nextbase; /* offset | type=0 */
  388. /* free section */
  389. *(--lptr) = nextbase - param; /* size */
  390. *(--lptr) = (base - param) | 126; /* offset | type=126 */
  391. /* terminate pointer field */
  392. *(--lptr) = crc32(0, (void*)(base - 0x10), 0x10);
  393. *(--lptr) = 0; /* offset=0 -> terminator */
  394. return 0;
  395. }
  396. U_BOOT_CMD(
  397. painit, 1, 1, do_painit,
  398. "prepare PciAccess system",
  399. ""
  400. );
  401. #endif /* CONFIG_PRAM */
  402. int do_selfreset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  403. {
  404. struct ppc4xx_gpio *gpio0 = (struct ppc4xx_gpio *)GPIO_BASE;
  405. setbits_be32(&gpio0->tcr, CONFIG_SYS_GPIO_SELFRST_N);
  406. return 0;
  407. }
  408. U_BOOT_CMD(
  409. selfreset, 1, 1, do_selfreset,
  410. "assert self-reset# signal",
  411. ""
  412. );
  413. int do_resetout(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  414. {
  415. struct pmc405de_cpld *cpld =
  416. (struct pmc405de_cpld *)CONFIG_SYS_CPLD_BASE;
  417. if (argc > 1) {
  418. if (argv[1][0] == '0') {
  419. /* assert */
  420. printf("PMC-RESETOUT# asserted\n");
  421. out_8(&cpld->control,
  422. CPLD_CONTROL_RESETOUT_N_GATE);
  423. } else {
  424. /* deassert */
  425. printf("PMC-RESETOUT# deasserted\n");
  426. out_8(&cpld->control,
  427. CPLD_CONTROL_RESETOUT_N |
  428. CPLD_CONTROL_RESETOUT_N_GATE);
  429. }
  430. } else {
  431. printf("PMC-RESETOUT# is %s\n",
  432. (in_8(&cpld->control) & CPLD_CONTROL_RESETOUT_N) ?
  433. "inactive" : "active");
  434. }
  435. return 0;
  436. }
  437. U_BOOT_CMD(
  438. resetout, 2, 1, do_resetout,
  439. "assert PMC-RESETOUT# signal",
  440. ""
  441. );