1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+ 2e58fe957SKim Phillips /* 3e58fe957SKim Phillips * Copyright (C) Freescale Semiconductor, Inc. 2006-2007 4e58fe957SKim Phillips * 5e58fe957SKim Phillips * Author: Scott Wood <scottwood@freescale.com> 6e58fe957SKim Phillips */ 7e58fe957SKim Phillips 8e58fe957SKim Phillips #include <common.h> 9b3458d2cSKim Phillips #if defined(CONFIG_OF_LIBFDT) 10b08c8c48SMasahiro Yamada #include <linux/libfdt.h> 11e58fe957SKim Phillips #endif 12e58fe957SKim Phillips #include <pci.h> 13e58fe957SKim Phillips #include <mpc83xx.h> 1489c7784eSTimur Tabi #include <vsc7385.h> 15e4c09508SScott Wood #include <ns16550.h> 16e4c09508SScott Wood #include <nand.h> 1722f4442dSScott Wood #if defined(CONFIG_MPC83XX_GPIO) && !defined(CONFIG_SPL_BUILD) 180eaf8f9eSJoe Hershberger #include <asm/gpio.h> 190eaf8f9eSJoe Hershberger #endif 20e58fe957SKim Phillips 21e58fe957SKim Phillips DECLARE_GLOBAL_DATA_PTR; 22e58fe957SKim Phillips 23e58fe957SKim Phillips int board_early_init_f(void) 24e58fe957SKim Phillips { 256d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_SYS_8313ERDB_BROKEN_PMC 266d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; 27e58fe957SKim Phillips 28e58fe957SKim Phillips if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) 29e58fe957SKim Phillips gd->flags |= GD_FLG_SILENT; 30e58fe957SKim Phillips #endif 3122f4442dSScott Wood #if defined(CONFIG_MPC83XX_GPIO) && !defined(CONFIG_SPL_BUILD) 320eaf8f9eSJoe Hershberger mpc83xx_gpio_init_f(); 330eaf8f9eSJoe Hershberger #endif 340eaf8f9eSJoe Hershberger 350eaf8f9eSJoe Hershberger return 0; 360eaf8f9eSJoe Hershberger } 370eaf8f9eSJoe Hershberger 380eaf8f9eSJoe Hershberger int board_early_init_r(void) 390eaf8f9eSJoe Hershberger { 4022f4442dSScott Wood #if defined(CONFIG_MPC83XX_GPIO) && !defined(CONFIG_SPL_BUILD) 410eaf8f9eSJoe Hershberger mpc83xx_gpio_init_r(); 420eaf8f9eSJoe Hershberger #endif 43e58fe957SKim Phillips 44e58fe957SKim Phillips return 0; 45e58fe957SKim Phillips } 46e58fe957SKim Phillips 47e58fe957SKim Phillips int checkboard(void) 48e58fe957SKim Phillips { 49e58fe957SKim Phillips puts("Board: Freescale MPC8313ERDB\n"); 50e58fe957SKim Phillips return 0; 51e58fe957SKim Phillips } 52e58fe957SKim Phillips 5322f4442dSScott Wood #ifndef CONFIG_SPL_BUILD 54e58fe957SKim Phillips static struct pci_region pci_regions[] = { 55e58fe957SKim Phillips { 56a2873bdeSKim Phillips .bus_start = CONFIG_SYS_PCI1_MEM_BASE, 57a2873bdeSKim Phillips .phys_start = CONFIG_SYS_PCI1_MEM_PHYS, 58a2873bdeSKim Phillips .size = CONFIG_SYS_PCI1_MEM_SIZE, 59a2873bdeSKim Phillips .flags = PCI_REGION_MEM | PCI_REGION_PREFETCH 60e58fe957SKim Phillips }, 61e58fe957SKim Phillips { 62a2873bdeSKim Phillips .bus_start = CONFIG_SYS_PCI1_MMIO_BASE, 63a2873bdeSKim Phillips .phys_start = CONFIG_SYS_PCI1_MMIO_PHYS, 64a2873bdeSKim Phillips .size = CONFIG_SYS_PCI1_MMIO_SIZE, 65a2873bdeSKim Phillips .flags = PCI_REGION_MEM 66e58fe957SKim Phillips }, 67e58fe957SKim Phillips { 68a2873bdeSKim Phillips .bus_start = CONFIG_SYS_PCI1_IO_BASE, 69a2873bdeSKim Phillips .phys_start = CONFIG_SYS_PCI1_IO_PHYS, 70a2873bdeSKim Phillips .size = CONFIG_SYS_PCI1_IO_SIZE, 71a2873bdeSKim Phillips .flags = PCI_REGION_IO 72e58fe957SKim Phillips } 73e58fe957SKim Phillips }; 74e58fe957SKim Phillips 75e58fe957SKim Phillips void pci_init_board(void) 76e58fe957SKim Phillips { 776d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; 78e58fe957SKim Phillips volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; 79e58fe957SKim Phillips volatile law83xx_t *pci_law = immr->sysconf.pcilaw; 80e58fe957SKim Phillips struct pci_region *reg[] = { pci_regions }; 81e58fe957SKim Phillips 82e58fe957SKim Phillips /* Enable all 3 PCI_CLK_OUTPUTs. */ 83e58fe957SKim Phillips clk->occr |= 0xe0000000; 84e58fe957SKim Phillips 85e58fe957SKim Phillips /* 86e58fe957SKim Phillips * Configure PCI Local Access Windows 87e58fe957SKim Phillips */ 886d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR; 89e58fe957SKim Phillips pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB; 90e58fe957SKim Phillips 916d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR; 92e58fe957SKim Phillips pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB; 93e58fe957SKim Phillips 946aa3d3bfSPeter Tyser mpc83xx_pci_init(1, reg); 95e58fe957SKim Phillips } 96e58fe957SKim Phillips 9789c7784eSTimur Tabi /* 9889c7784eSTimur Tabi * Miscellaneous late-boot configurations 9989c7784eSTimur Tabi * 10089c7784eSTimur Tabi * If a VSC7385 microcode image is present, then upload it. 10189c7784eSTimur Tabi */ 10289c7784eSTimur Tabi int misc_init_r(void) 10389c7784eSTimur Tabi { 10489c7784eSTimur Tabi int rc = 0; 10589c7784eSTimur Tabi 10689c7784eSTimur Tabi #ifdef CONFIG_VSC7385_IMAGE 10789c7784eSTimur Tabi if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE, 10889c7784eSTimur Tabi CONFIG_VSC7385_IMAGE_SIZE)) { 10989c7784eSTimur Tabi puts("Failure uploading VSC7385 microcode.\n"); 11089c7784eSTimur Tabi rc = 1; 11189c7784eSTimur Tabi } 11289c7784eSTimur Tabi #endif 11389c7784eSTimur Tabi 11489c7784eSTimur Tabi return rc; 11589c7784eSTimur Tabi } 11689c7784eSTimur Tabi 117e58fe957SKim Phillips #if defined(CONFIG_OF_BOARD_SETUP) 118e895a4b0SSimon Glass int ft_board_setup(void *blob, bd_t *bd) 119e58fe957SKim Phillips { 120e58fe957SKim Phillips ft_cpu_setup(blob, bd); 121e58fe957SKim Phillips #ifdef CONFIG_PCI 122e58fe957SKim Phillips ft_pci_setup(blob, bd); 123e58fe957SKim Phillips #endif 124e895a4b0SSimon Glass 125e895a4b0SSimon Glass return 0; 126e58fe957SKim Phillips } 127e58fe957SKim Phillips #endif 12822f4442dSScott Wood #else /* CONFIG_SPL_BUILD */ 129e4c09508SScott Wood void board_init_f(ulong bootflag) 130e4c09508SScott Wood { 131e4c09508SScott Wood board_early_init_f(); 1326d0f6bcfSJean-Christophe PLAGNIOL-VILLARD NS16550_init((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), 1336d0f6bcfSJean-Christophe PLAGNIOL-VILLARD CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); 134e4c09508SScott Wood puts("NAND boot... "); 13570e2aaf3SSimon Glass timer_init(); 136f1683aa7SSimon Glass dram_init(); 1376e1385d5SMingkai Hu relocate_code(CONFIG_SYS_NAND_U_BOOT_RELOC_SP, (gd_t *)gd, 1386d0f6bcfSJean-Christophe PLAGNIOL-VILLARD CONFIG_SYS_NAND_U_BOOT_RELOC); 139e4c09508SScott Wood } 140e4c09508SScott Wood 141e4c09508SScott Wood void board_init_r(gd_t *gd, ulong dest_addr) 142e4c09508SScott Wood { 143e4c09508SScott Wood nand_boot(); 144e4c09508SScott Wood } 145e4c09508SScott Wood 146e4c09508SScott Wood void putc(char c) 147e4c09508SScott Wood { 148e4c09508SScott Wood if (gd->flags & GD_FLG_SILENT) 149e4c09508SScott Wood return; 150e4c09508SScott Wood 151e4c09508SScott Wood if (c == '\n') 1526d0f6bcfSJean-Christophe PLAGNIOL-VILLARD NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), '\r'); 153e4c09508SScott Wood 1546d0f6bcfSJean-Christophe PLAGNIOL-VILLARD NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), c); 155e4c09508SScott Wood } 156e4c09508SScott Wood #endif 157