Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marcin Niestroj | ab38bf6 | 2017-01-25 09:53:08 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/ |
| 4 | * Copyright (C) 2017, Grinn - http://grinn-global.com/ |
Marcin Niestroj | ab38bf6 | 2017-01-25 09:53:08 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/arch/chilisom.h> |
| 9 | #include <asm/arch/cpu.h> |
| 10 | #include <asm/arch/hardware.h> |
| 11 | #include <asm/arch/omap.h> |
| 12 | #include <asm/arch/mem.h> |
| 13 | #include <asm/arch/mmc_host_def.h> |
| 14 | #include <asm/arch/mux.h> |
| 15 | #include <asm/arch/sys_proto.h> |
| 16 | #include <asm/emif.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <cpsw.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame^] | 19 | #include <env.h> |
Marcin Niestroj | ab38bf6 | 2017-01-25 09:53:08 +0100 | [diff] [blame] | 20 | #include <environment.h> |
| 21 | #include <errno.h> |
| 22 | #include <miiphy.h> |
Marcin Niestroj | ab38bf6 | 2017-01-25 09:53:08 +0100 | [diff] [blame] | 23 | #include <spl.h> |
| 24 | #include <watchdog.h> |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | static __maybe_unused struct ctrl_dev *cdev = |
| 29 | (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 30 | |
| 31 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 32 | static struct module_pin_mux uart0_pin_mux[] = { |
| 33 | {OFFSET(uart0_rxd), (MODE(0) | PULLUP_EN | RXACTIVE)}, /* UART0_RXD */ |
| 34 | {OFFSET(uart0_txd), (MODE(0) | PULLUDEN)}, /* UART0_TXD */ |
| 35 | {-1}, |
| 36 | }; |
| 37 | |
| 38 | static struct module_pin_mux mmc0_pin_mux[] = { |
| 39 | {OFFSET(mmc0_dat3), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT3 */ |
| 40 | {OFFSET(mmc0_dat2), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT2 */ |
| 41 | {OFFSET(mmc0_dat1), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT1 */ |
| 42 | {OFFSET(mmc0_dat0), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT0 */ |
| 43 | {OFFSET(mmc0_clk), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_CLK */ |
| 44 | {OFFSET(mmc0_cmd), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_CMD */ |
| 45 | {-1}, |
| 46 | }; |
| 47 | |
| 48 | static struct module_pin_mux rmii1_pin_mux[] = { |
| 49 | {OFFSET(mii1_crs), MODE(1) | RXACTIVE}, /* RMII1_CRS */ |
| 50 | {OFFSET(mii1_rxerr), MODE(1) | RXACTIVE}, /* RMII1_RXERR */ |
| 51 | {OFFSET(mii1_txen), MODE(1)}, /* RMII1_TXEN */ |
| 52 | {OFFSET(mii1_txd1), MODE(1)}, /* RMII1_TXD1 */ |
| 53 | {OFFSET(mii1_txd0), MODE(1)}, /* RMII1_TXD0 */ |
| 54 | {OFFSET(mii1_rxd1), MODE(1) | RXACTIVE}, /* RMII1_RXD1 */ |
| 55 | {OFFSET(mii1_rxd0), MODE(1) | RXACTIVE}, /* RMII1_RXD0 */ |
| 56 | {OFFSET(mdio_data), MODE(0) | RXACTIVE | PULLUP_EN}, /* MDIO_DATA */ |
| 57 | {OFFSET(mdio_clk), MODE(0) | PULLUP_EN}, /* MDIO_CLK */ |
| 58 | {OFFSET(rmii1_refclk), MODE(0) | RXACTIVE}, /* RMII1_REFCLK */ |
| 59 | {-1}, |
| 60 | }; |
| 61 | |
| 62 | static void enable_board_pin_mux(void) |
| 63 | { |
| 64 | chilisom_enable_pin_mux(); |
| 65 | |
| 66 | /* chiliboard pinmux */ |
| 67 | configure_module_pin_mux(rmii1_pin_mux); |
| 68 | configure_module_pin_mux(mmc0_pin_mux); |
| 69 | } |
| 70 | #endif /* CONFIG_SKIP_LOWLEVEL_INIT */ |
| 71 | |
Marcin Niestroj | ab38bf6 | 2017-01-25 09:53:08 +0100 | [diff] [blame] | 72 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 73 | void set_uart_mux_conf(void) |
| 74 | { |
| 75 | configure_module_pin_mux(uart0_pin_mux); |
| 76 | } |
| 77 | |
| 78 | void set_mux_conf_regs(void) |
| 79 | { |
| 80 | enable_board_pin_mux(); |
| 81 | } |
| 82 | |
| 83 | void am33xx_spl_board_init(void) |
| 84 | { |
| 85 | chilisom_spl_board_init(); |
| 86 | } |
| 87 | #endif |
| 88 | |
| 89 | /* |
| 90 | * Basic board specific setup. Pinmux has been handled already. |
| 91 | */ |
| 92 | int board_init(void) |
| 93 | { |
| 94 | #if defined(CONFIG_HW_WATCHDOG) |
| 95 | hw_watchdog_init(); |
| 96 | #endif |
| 97 | |
| 98 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 99 | gpmc_init(); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | #ifdef CONFIG_BOARD_LATE_INIT |
| 105 | int board_late_init(void) |
| 106 | { |
| 107 | #if !defined(CONFIG_SPL_BUILD) |
| 108 | uint8_t mac_addr[6]; |
| 109 | uint32_t mac_hi, mac_lo; |
| 110 | |
| 111 | /* try reading mac address from efuse */ |
| 112 | mac_lo = readl(&cdev->macid0l); |
| 113 | mac_hi = readl(&cdev->macid0h); |
| 114 | mac_addr[0] = mac_hi & 0xFF; |
| 115 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 116 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 117 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 118 | mac_addr[4] = mac_lo & 0xFF; |
| 119 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 120 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 121 | if (!env_get("ethaddr")) { |
Marcin Niestroj | ab38bf6 | 2017-01-25 09:53:08 +0100 | [diff] [blame] | 122 | printf("<ethaddr> not set. Validating first E-fuse MAC\n"); |
| 123 | |
| 124 | if (is_valid_ethaddr(mac_addr)) |
Simon Glass | fd1e959 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 125 | eth_env_set_enetaddr("ethaddr", mac_addr); |
Marcin Niestroj | ab38bf6 | 2017-01-25 09:53:08 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | mac_lo = readl(&cdev->macid1l); |
| 129 | mac_hi = readl(&cdev->macid1h); |
| 130 | mac_addr[0] = mac_hi & 0xFF; |
| 131 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 132 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 133 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 134 | mac_addr[4] = mac_lo & 0xFF; |
| 135 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 136 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 137 | if (!env_get("eth1addr")) { |
Marcin Niestroj | ab38bf6 | 2017-01-25 09:53:08 +0100 | [diff] [blame] | 138 | if (is_valid_ethaddr(mac_addr)) |
Simon Glass | fd1e959 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 139 | eth_env_set_enetaddr("eth1addr", mac_addr); |
Marcin Niestroj | ab38bf6 | 2017-01-25 09:53:08 +0100 | [diff] [blame] | 140 | } |
| 141 | #endif |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | #endif |