pmc405de.c 13 KB

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