hww1u1a.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Copyright 2009-2011 eXMeritus, A Boeing Company
  3. * Copyright 2007-2009 Freescale Semiconductor, Inc.
  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 <command.h>
  25. #include <pci.h>
  26. #include <asm/processor.h>
  27. #include <asm/mmu.h>
  28. #include <asm/cache.h>
  29. #include <asm/immap_85xx.h>
  30. #include <asm/fsl_pci.h>
  31. #include <asm/fsl_ddr_sdram.h>
  32. #include <asm/io.h>
  33. #include <miiphy.h>
  34. #include <libfdt.h>
  35. #include <linux/ctype.h>
  36. #include <fdt_support.h>
  37. #include <fsl_mdio.h>
  38. #include <tsec.h>
  39. #include <asm/fsl_law.h>
  40. #include <netdev.h>
  41. #include <malloc.h>
  42. #include <i2c.h>
  43. #include <pca953x.h>
  44. #include "gpios.h"
  45. DECLARE_GLOBAL_DATA_PTR;
  46. int checkboard(void)
  47. {
  48. unsigned int gpio_high = 0;
  49. unsigned int gpio_low = 0;
  50. unsigned int gpio_in = 0;
  51. unsigned int i;
  52. puts("Board: HWW-1U-1A ");
  53. /*
  54. * First just figure out which CPU we're on, then use that to
  55. * configure the lists of other GPIOs to be programmed.
  56. */
  57. mpc85xx_gpio_set_in(GPIO_CPU_ID);
  58. if (hww1u1a_is_cpu_a()) {
  59. puts("CPU A\n");
  60. /* We want to turn on some LEDs */
  61. gpio_high |= GPIO_CPUA_CPU_READY;
  62. gpio_low |= GPIO_CPUA_DEBUG_LED1;
  63. gpio_low |= GPIO_CPUA_DEBUG_LED2;
  64. /* Disable the unused transmitters */
  65. gpio_low |= GPIO_CPUA_TDIS1A;
  66. gpio_high |= GPIO_CPUA_TDIS1B;
  67. gpio_low |= GPIO_CPUA_TDIS2A;
  68. gpio_high |= GPIO_CPUA_TDIS2B;
  69. } else {
  70. puts("CPU B\n");
  71. /* We want to turn on some LEDs */
  72. gpio_high |= GPIO_CPUB_CPU_READY;
  73. gpio_low |= GPIO_CPUB_DEBUG_LED1;
  74. gpio_low |= GPIO_CPUB_DEBUG_LED2;
  75. /* Enable the appropriate receivers */
  76. gpio_high |= GPIO_CPUB_RMUX_SEL0A;
  77. gpio_high |= GPIO_CPUB_RMUX_SEL0B;
  78. gpio_low |= GPIO_CPUB_RMUX_SEL1A;
  79. gpio_low |= GPIO_CPUB_RMUX_SEL1B;
  80. }
  81. /* These GPIOs are common */
  82. gpio_in |= IRQ_I2CINT | IRQ_FANINT | IRQ_DIMM_EVENT;
  83. gpio_low |= GPIO_RS422_RE;
  84. gpio_high |= GPIO_RS422_DE;
  85. /* Ok, now go ahead and program all of those in one go */
  86. mpc85xx_gpio_set(gpio_high|gpio_low|gpio_in,
  87. gpio_high|gpio_low,
  88. gpio_high);
  89. /*
  90. * If things have been taken out of reset early (for example, by one
  91. * of the BDI3000 debuggers), then we need to put them back in reset
  92. * and delay a while before we continue.
  93. */
  94. if (mpc85xx_gpio_get(GPIO_RESETS)) {
  95. ccsr_ddr_t *ddr = (ccsr_ddr_t *)CONFIG_SYS_MPC85xx_DDR_ADDR;
  96. puts("Debugger detected... extra device reset enabled!\n");
  97. /* Put stuff into reset and disable the DDR controller */
  98. mpc85xx_gpio_set_low(GPIO_RESETS);
  99. out_be32(&ddr->sdram_cfg, 0x00000000);
  100. puts(" Waiting 1 sec for reset...");
  101. for (i = 0; i < 10; i++) {
  102. udelay(100000);
  103. puts(".");
  104. }
  105. puts("\n");
  106. }
  107. /* Now bring everything back out of reset again */
  108. mpc85xx_gpio_set_high(GPIO_RESETS);
  109. return 0;
  110. }
  111. /*
  112. * This little shell function just returns whether or not it's CPU A.
  113. * It can be used to select the right device-tree when booting, etc.
  114. */
  115. int do_hww1u1a_test_cpu_a(cmd_tbl_t *cmdtp, int flag,
  116. int argc, char * const argv[])
  117. {
  118. if (argc > 1)
  119. cmd_usage(cmdtp);
  120. if (hww1u1a_is_cpu_a())
  121. return 0;
  122. else
  123. return 1;
  124. }
  125. U_BOOT_CMD(
  126. test_cpu_a, 1, 0, do_hww1u1a_test_cpu_a,
  127. "Test if this is CPU A (versus B) on the eXMeritus HWW-1U-1A board",
  128. ""
  129. );
  130. /* Create a prompt-like string: "uboot@HOSTNAME% " */
  131. #define PROMPT_PREFIX "uboot@exm"
  132. #define PROMPT_SUFFIX "% "
  133. /* This function returns a PS1 prompt based on the serial number */
  134. static char *hww1u1a_prompt;
  135. const char *hww1u1a_get_ps1(void)
  136. {
  137. unsigned long len, i, j;
  138. const char *serialnr;
  139. /* If our prompt was already set, just use that */
  140. if (hww1u1a_prompt)
  141. return hww1u1a_prompt;
  142. /* Use our serial number if present, otherwise a default */
  143. serialnr = getenv("serial#");
  144. if (!serialnr || !serialnr[0])
  145. serialnr = "999999-X";
  146. /*
  147. * We will turn the serial number into a hostname by:
  148. * (A) Delete all non-alphanumerics.
  149. * (B) Lowercase all letters.
  150. * (C) Prefix "exm".
  151. * (D) Suffix "a" for CPU A and "b" for CPU B.
  152. */
  153. for (i = 0, len = 0; serialnr[i]; i++) {
  154. if (isalnum(serialnr[i]))
  155. len++;
  156. }
  157. len += sizeof(PROMPT_PREFIX PROMPT_SUFFIX) + 1; /* Includes NUL */
  158. hww1u1a_prompt = malloc(len);
  159. if (!hww1u1a_prompt)
  160. return PROMPT_PREFIX "UNKNOWN(ENOMEM)" PROMPT_SUFFIX;
  161. /* Now actually fill it in */
  162. i = 0;
  163. /* Handle the prefix */
  164. for (j = 0; j < sizeof(PROMPT_PREFIX) - 1; j++)
  165. hww1u1a_prompt[i++] = PROMPT_PREFIX[j];
  166. /* Now the serial# part of the hostname */
  167. for (j = 0; serialnr[j]; j++)
  168. if (isalnum(serialnr[j]))
  169. hww1u1a_prompt[i++] = tolower(serialnr[j]);
  170. /* Now the CPU id ("a" or "b") */
  171. hww1u1a_prompt[i++] = hww1u1a_is_cpu_a() ? 'a' : 'b';
  172. /* Finally the suffix */
  173. for (j = 0; j < sizeof(PROMPT_SUFFIX); j++)
  174. hww1u1a_prompt[i++] = PROMPT_SUFFIX[j];
  175. /* This should all have added up, but just in case */
  176. hww1u1a_prompt[len - 1] = '\0';
  177. /* Now we're done */
  178. return hww1u1a_prompt;
  179. }
  180. void pci_init_board(void)
  181. {
  182. fsl_pcie_init_board(0);
  183. }
  184. int board_early_init_r(void)
  185. {
  186. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  187. const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
  188. /*
  189. * Remap bootflash region to caching-inhibited
  190. * so that flash can be erased properly.
  191. */
  192. /* Flush d-cache and invalidate i-cache of any FLASH data */
  193. flush_dcache();
  194. invalidate_icache();
  195. /* invalidate existing TLB entry for FLASH */
  196. disable_tlb(flash_esel);
  197. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  198. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  199. 0, flash_esel, BOOKE_PAGESZ_256M, 1);
  200. return 0;
  201. }
  202. int board_eth_init(bd_t *bis)
  203. {
  204. struct tsec_info_struct tsec_info[4];
  205. struct fsl_pq_mdio_info mdio_info;
  206. SET_STD_TSEC_INFO(tsec_info[0], 1);
  207. SET_STD_TSEC_INFO(tsec_info[1], 2);
  208. SET_STD_TSEC_INFO(tsec_info[2], 3);
  209. if (hww1u1a_is_cpu_a())
  210. tsec_info[2].phyaddr = TSEC3_PHY_ADDR_CPUA;
  211. else
  212. tsec_info[2].phyaddr = TSEC3_PHY_ADDR_CPUB;
  213. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  214. mdio_info.name = DEFAULT_MII_NAME;
  215. fsl_pq_mdio_init(bis, &mdio_info);
  216. tsec_eth_init(bis, tsec_info, 3);
  217. return pci_eth_init(bis);
  218. }
  219. void ft_board_setup(void *blob, bd_t *bd)
  220. {
  221. phys_addr_t base;
  222. phys_size_t size;
  223. ft_cpu_setup(blob, bd);
  224. base = getenv_bootm_low();
  225. size = getenv_bootm_size();
  226. fdt_fixup_memory(blob, (u64)base, (u64)size);
  227. FT_FSL_PCI_SETUP;
  228. }