blob: 12480f5729d6d4b4e532f567a46a3f8c3df4b9fa [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marcin Niestroj20315d22017-01-25 09:53:08 +01002/*
3 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
4 * Copyright (C) 2017, Grinn - http://grinn-global.com/
Marcin Niestroj20315d22017-01-25 09:53:08 +01005 */
6
7#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Marcin Niestroj20315d22017-01-25 09:53:08 +010010#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>
Simon Glass3ba929a2020-10-30 21:38:53 -060019#include <asm/global_data.h>
Marcin Niestroj20315d22017-01-25 09:53:08 +010020#include <asm/io.h>
21#include <cpsw.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060022#include <env.h>
Marcin Niestroj20315d22017-01-25 09:53:08 +010023#include <errno.h>
24#include <miiphy.h>
Marcin Niestroj20315d22017-01-25 09:53:08 +010025#include <spl.h>
26#include <watchdog.h>
27
28DECLARE_GLOBAL_DATA_PTR;
29
30static __maybe_unused struct ctrl_dev *cdev =
31 (struct ctrl_dev *)CTRL_DEVICE_BASE;
32
33#ifndef CONFIG_SKIP_LOWLEVEL_INIT
34static struct module_pin_mux uart0_pin_mux[] = {
35 {OFFSET(uart0_rxd), (MODE(0) | PULLUP_EN | RXACTIVE)}, /* UART0_RXD */
36 {OFFSET(uart0_txd), (MODE(0) | PULLUDEN)}, /* UART0_TXD */
37 {-1},
38};
39
40static struct module_pin_mux mmc0_pin_mux[] = {
41 {OFFSET(mmc0_dat3), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT3 */
42 {OFFSET(mmc0_dat2), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT2 */
43 {OFFSET(mmc0_dat1), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT1 */
44 {OFFSET(mmc0_dat0), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_DAT0 */
45 {OFFSET(mmc0_clk), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_CLK */
46 {OFFSET(mmc0_cmd), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* MMC0_CMD */
47 {-1},
48};
49
50static struct module_pin_mux rmii1_pin_mux[] = {
51 {OFFSET(mii1_crs), MODE(1) | RXACTIVE}, /* RMII1_CRS */
52 {OFFSET(mii1_rxerr), MODE(1) | RXACTIVE}, /* RMII1_RXERR */
53 {OFFSET(mii1_txen), MODE(1)}, /* RMII1_TXEN */
54 {OFFSET(mii1_txd1), MODE(1)}, /* RMII1_TXD1 */
55 {OFFSET(mii1_txd0), MODE(1)}, /* RMII1_TXD0 */
56 {OFFSET(mii1_rxd1), MODE(1) | RXACTIVE}, /* RMII1_RXD1 */
57 {OFFSET(mii1_rxd0), MODE(1) | RXACTIVE}, /* RMII1_RXD0 */
58 {OFFSET(mdio_data), MODE(0) | RXACTIVE | PULLUP_EN}, /* MDIO_DATA */
59 {OFFSET(mdio_clk), MODE(0) | PULLUP_EN}, /* MDIO_CLK */
60 {OFFSET(rmii1_refclk), MODE(0) | RXACTIVE}, /* RMII1_REFCLK */
61 {-1},
62};
63
64static void enable_board_pin_mux(void)
65{
66 chilisom_enable_pin_mux();
67
68 /* chiliboard pinmux */
69 configure_module_pin_mux(rmii1_pin_mux);
70 configure_module_pin_mux(mmc0_pin_mux);
71}
72#endif /* CONFIG_SKIP_LOWLEVEL_INIT */
73
Marcin Niestroj20315d22017-01-25 09:53:08 +010074#ifndef CONFIG_SKIP_LOWLEVEL_INIT
75void set_uart_mux_conf(void)
76{
77 configure_module_pin_mux(uart0_pin_mux);
78}
79
80void set_mux_conf_regs(void)
81{
82 enable_board_pin_mux();
83}
84
85void am33xx_spl_board_init(void)
86{
87 chilisom_spl_board_init();
88}
89#endif
90
91/*
92 * Basic board specific setup. Pinmux has been handled already.
93 */
94int board_init(void)
95{
96#if defined(CONFIG_HW_WATCHDOG)
97 hw_watchdog_init();
98#endif
99
100 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
101 gpmc_init();
102
103 return 0;
104}
105
106#ifdef CONFIG_BOARD_LATE_INIT
107int board_late_init(void)
108{
109#if !defined(CONFIG_SPL_BUILD)
110 uint8_t mac_addr[6];
111 uint32_t mac_hi, mac_lo;
112
113 /* try reading mac address from efuse */
114 mac_lo = readl(&cdev->macid0l);
115 mac_hi = readl(&cdev->macid0h);
116 mac_addr[0] = mac_hi & 0xFF;
117 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
118 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
119 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
120 mac_addr[4] = mac_lo & 0xFF;
121 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
122
Simon Glass64b723f2017-08-03 12:22:12 -0600123 if (!env_get("ethaddr")) {
Marcin Niestroj20315d22017-01-25 09:53:08 +0100124 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
125
126 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600127 eth_env_set_enetaddr("ethaddr", mac_addr);
Marcin Niestroj20315d22017-01-25 09:53:08 +0100128 }
129
130 mac_lo = readl(&cdev->macid1l);
131 mac_hi = readl(&cdev->macid1h);
132 mac_addr[0] = mac_hi & 0xFF;
133 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
134 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
135 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
136 mac_addr[4] = mac_lo & 0xFF;
137 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
138
Simon Glass64b723f2017-08-03 12:22:12 -0600139 if (!env_get("eth1addr")) {
Marcin Niestroj20315d22017-01-25 09:53:08 +0100140 if (is_valid_ethaddr(mac_addr))
Simon Glass8551d552017-08-03 12:22:11 -0600141 eth_env_set_enetaddr("eth1addr", mac_addr);
Marcin Niestroj20315d22017-01-25 09:53:08 +0100142 }
143#endif
144
145 return 0;
146}
147#endif