mpc8308rdb.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (C) 2010 Freescale Semiconductor, Inc.
  3. * Copyright (C) 2010 Ilya Yanok, Emcraft Systems, yanok@emcraft.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <hwconfig.h>
  9. #include <i2c.h>
  10. #include <spi.h>
  11. #include <libfdt.h>
  12. #include <fdt_support.h>
  13. #include <pci.h>
  14. #include <mpc83xx.h>
  15. #include <vsc7385.h>
  16. #include <netdev.h>
  17. #include <fsl_esdhc.h>
  18. #include <asm/io.h>
  19. #include <asm/fsl_serdes.h>
  20. #include <asm/fsl_mpc83xx_serdes.h>
  21. DECLARE_GLOBAL_DATA_PTR;
  22. /*
  23. * The following are used to control the SPI chip selects for the SPI command.
  24. */
  25. #ifdef CONFIG_MPC8XXX_SPI
  26. #define SPI_CS_MASK 0x00400000
  27. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  28. {
  29. return bus == 0 && cs == 0;
  30. }
  31. void spi_cs_activate(struct spi_slave *slave)
  32. {
  33. immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  34. /* active low */
  35. clrbits_be32(&immr->gpio[0].dat, SPI_CS_MASK);
  36. }
  37. void spi_cs_deactivate(struct spi_slave *slave)
  38. {
  39. immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  40. /* inactive high */
  41. setbits_be32(&immr->gpio[0].dat, SPI_CS_MASK);
  42. }
  43. #endif /* CONFIG_MPC8XXX_SPI */
  44. #ifdef CONFIG_FSL_ESDHC
  45. int board_mmc_init(bd_t *bd)
  46. {
  47. return fsl_esdhc_mmc_init(bd);
  48. }
  49. #endif
  50. static u8 read_board_info(void)
  51. {
  52. u8 val8;
  53. i2c_set_bus_num(0);
  54. if (i2c_read(CONFIG_SYS_I2C_PCF8574A_ADDR, 0, 0, &val8, 1) == 0)
  55. return val8;
  56. else
  57. return 0;
  58. }
  59. int checkboard(void)
  60. {
  61. static const char * const rev_str[] = {
  62. "1.0",
  63. "<reserved>",
  64. "<reserved>",
  65. "<reserved>",
  66. "<unknown>",
  67. };
  68. u8 info;
  69. int i;
  70. info = read_board_info();
  71. i = (!info) ? 4 : info & 0x03;
  72. printf("Board: Freescale MPC8308RDB Rev %s\n", rev_str[i]);
  73. return 0;
  74. }
  75. static struct pci_region pcie_regions_0[] = {
  76. {
  77. .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
  78. .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
  79. .size = CONFIG_SYS_PCIE1_MEM_SIZE,
  80. .flags = PCI_REGION_MEM,
  81. },
  82. {
  83. .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
  84. .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
  85. .size = CONFIG_SYS_PCIE1_IO_SIZE,
  86. .flags = PCI_REGION_IO,
  87. },
  88. };
  89. void pci_init_board(void)
  90. {
  91. immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  92. sysconf83xx_t *sysconf = &immr->sysconf;
  93. law83xx_t *pcie_law = sysconf->pcielaw;
  94. struct pci_region *pcie_reg[] = { pcie_regions_0 };
  95. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
  96. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  97. /* Deassert the resets in the control register */
  98. out_be32(&sysconf->pecr1, 0xE0008000);
  99. udelay(2000);
  100. /* Configure PCI Express Local Access Windows */
  101. out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
  102. out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
  103. mpc83xx_pcie_init(1, pcie_reg);
  104. }
  105. /*
  106. * Miscellaneous late-boot configurations
  107. *
  108. * If a VSC7385 microcode image is present, then upload it.
  109. */
  110. int misc_init_r(void)
  111. {
  112. #ifdef CONFIG_MPC8XXX_SPI
  113. immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  114. sysconf83xx_t *sysconf = &immr->sysconf;
  115. /*
  116. * Set proper bits in SICRH to allow SPI on header J8
  117. *
  118. * NOTE: this breaks the TSEC2 interface, attached to the Vitesse
  119. * switch. The pinmux configuration does not have a fine enough
  120. * granularity to support both simultaneously.
  121. */
  122. clrsetbits_be32(&sysconf->sicrh, SICRH_GPIO_A_TSEC2, SICRH_GPIO_A_GPIO);
  123. puts("WARNING: SPI enabled, TSEC2 support is broken\n");
  124. /* Set header J8 SPI chip select output, disabled */
  125. setbits_be32(&immr->gpio[0].dir, SPI_CS_MASK);
  126. setbits_be32(&immr->gpio[0].dat, SPI_CS_MASK);
  127. #endif
  128. #ifdef CONFIG_VSC7385_IMAGE
  129. if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
  130. CONFIG_VSC7385_IMAGE_SIZE)) {
  131. puts("Failure uploading VSC7385 microcode.\n");
  132. return 1;
  133. }
  134. #endif
  135. return 0;
  136. }
  137. #if defined(CONFIG_OF_BOARD_SETUP)
  138. int ft_board_setup(void *blob, bd_t *bd)
  139. {
  140. ft_cpu_setup(blob, bd);
  141. fsl_fdt_fixup_dr_usb(blob, bd);
  142. fdt_fixup_esdhc(blob, bd);
  143. return 0;
  144. }
  145. #endif
  146. int board_eth_init(bd_t *bis)
  147. {
  148. int rv, num_if = 0;
  149. /* Initialize TSECs first */
  150. rv = cpu_eth_init(bis);
  151. if (rv >= 0)
  152. num_if += rv;
  153. else
  154. printf("ERROR: failed to initialize TSECs.\n");
  155. rv = pci_eth_init(bis);
  156. if (rv >= 0)
  157. num_if += rv;
  158. else
  159. printf("ERROR: failed to initialize PCI Ethernet.\n");
  160. return num_if;
  161. }