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