Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 2 | /* |
Tony Dinh | 1c383d5 | 2021-07-29 20:02:43 -0700 | [diff] [blame] | 3 | * Copyright (C) 2021 |
| 4 | * Tony Dinh <mibodhi@gmail.com> |
| 5 | * Suriyan Ramasami <suriyan.r@gmail.com> |
| 6 | * |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 7 | * Copyright (C) 2013 Suriyan Ramasami <suriyan.r@gmail.com> |
| 8 | * |
| 9 | * Based on dockstar.c originally written by |
| 10 | * Copyright (C) 2010 Eric C. Cooper <ecc@cmu.edu> |
| 11 | * |
| 12 | * Based on sheevaplug.c originally written by |
| 13 | * Prafulla Wadaskar <prafulla@marvell.com> |
| 14 | * (C) Copyright 2009 |
| 15 | * Marvell Semiconductor <www.marvell.com> |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <common.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 19 | #include <bootstage.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 20 | #include <init.h> |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 21 | #include <miiphy.h> |
Simon Glass | 0c36441 | 2019-12-28 10:44:48 -0700 | [diff] [blame] | 22 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 23 | #include <asm/global_data.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 24 | #include <asm/mach-types.h> |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 25 | #include <asm/arch/soc.h> |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 26 | #include <asm/arch/mpp.h> |
| 27 | #include <asm/arch/cpu.h> |
| 28 | #include <asm/io.h> |
| 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
| 32 | int board_early_init_f(void) |
| 33 | { |
| 34 | /* Multi-Purpose Pins Functionality configuration */ |
| 35 | static const u32 kwmpp_config[] = { |
| 36 | MPP0_NF_IO2, |
| 37 | MPP1_NF_IO3, |
| 38 | MPP2_NF_IO4, |
| 39 | MPP3_NF_IO5, |
| 40 | MPP4_NF_IO6, |
| 41 | MPP5_NF_IO7, |
| 42 | MPP6_SYSRST_OUTn, |
| 43 | MPP7_GPO, |
| 44 | MPP8_UART0_RTS, |
| 45 | MPP9_UART0_CTS, |
| 46 | MPP10_UART0_TXD, |
| 47 | MPP11_UART0_RXD, |
| 48 | MPP12_SD_CLK, |
| 49 | MPP13_SD_CMD, |
| 50 | MPP14_SD_D0, |
| 51 | MPP15_SD_D1, |
| 52 | MPP16_SD_D2, |
| 53 | MPP17_SD_D3, |
| 54 | MPP18_NF_IO0, |
| 55 | MPP19_NF_IO1, |
| 56 | MPP20_GPIO, |
| 57 | MPP21_GPIO, |
| 58 | MPP22_GPIO, |
| 59 | MPP23_GPIO, |
| 60 | MPP24_GPIO, |
| 61 | MPP25_GPIO, |
| 62 | MPP26_GPIO, |
| 63 | MPP27_GPIO, |
| 64 | MPP28_GPIO, |
| 65 | MPP29_TSMP9, |
| 66 | MPP30_GPIO, |
| 67 | MPP31_GPIO, |
| 68 | MPP32_GPIO, |
| 69 | MPP33_GPIO, |
| 70 | MPP34_GPIO, |
| 71 | MPP35_GPIO, |
| 72 | MPP36_GPIO, |
| 73 | MPP37_GPIO, |
| 74 | MPP38_GPIO, |
| 75 | MPP39_GPIO, |
| 76 | MPP40_GPIO, |
| 77 | MPP41_GPIO, |
| 78 | MPP42_GPIO, |
| 79 | MPP43_GPIO, |
| 80 | MPP44_GPIO, |
| 81 | MPP45_GPIO, |
| 82 | MPP46_GPIO, |
| 83 | MPP47_GPIO, |
| 84 | MPP48_GPIO, |
| 85 | MPP49_GPIO, |
| 86 | 0 |
| 87 | }; |
| 88 | |
| 89 | /* |
| 90 | * default gpio configuration |
| 91 | * There are maximum 64 gpios controlled through 2 sets of registers |
| 92 | * the below configuration configures mainly initial LED status |
| 93 | */ |
Stefan Roese | c50ab39 | 2014-10-22 12:13:11 +0200 | [diff] [blame] | 94 | mvebu_config_gpio(GOFLEXHOME_OE_VAL_LOW, |
| 95 | GOFLEXHOME_OE_VAL_HIGH, |
| 96 | GOFLEXHOME_OE_LOW, GOFLEXHOME_OE_HIGH); |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 97 | kirkwood_mpp_conf(kwmpp_config, NULL); |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | int board_init(void) |
| 102 | { |
Tom Rini | 4815734 | 2017-01-25 20:42:35 -0500 | [diff] [blame] | 103 | /* |
| 104 | * arch number of board |
| 105 | */ |
| 106 | gd->bd->bi_arch_number = MACH_TYPE_GOFLEXHOME; |
| 107 | |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 108 | /* address of boot parameters */ |
Stefan Roese | 0b74175 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 109 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
Tony Dinh | 1c383d5 | 2021-07-29 20:02:43 -0700 | [diff] [blame] | 114 | static int fdt_get_phy_addr(const char *path) |
| 115 | { |
| 116 | const void *fdt = gd->fdt_blob; |
| 117 | const u32 *reg; |
| 118 | const u32 *val; |
| 119 | int node, phandle, addr; |
| 120 | |
| 121 | /* Find the node by its full path */ |
| 122 | node = fdt_path_offset(fdt, path); |
| 123 | if (node >= 0) { |
| 124 | /* Look up phy-handle */ |
| 125 | val = fdt_getprop(fdt, node, "phy-handle", NULL); |
| 126 | if (val) { |
| 127 | phandle = fdt32_to_cpu(*val); |
| 128 | if (!phandle) |
| 129 | return -1; |
| 130 | /* Follow it to its node */ |
| 131 | node = fdt_node_offset_by_phandle(fdt, phandle); |
| 132 | if (node) { |
| 133 | /* Look up reg */ |
| 134 | reg = fdt_getprop(fdt, node, "reg", NULL); |
| 135 | if (reg) { |
| 136 | addr = fdt32_to_cpu(*reg); |
| 137 | return addr; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | return -1; |
| 143 | } |
| 144 | |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 145 | #ifdef CONFIG_RESET_PHY_R |
| 146 | /* Configure and enable MV88E1116 PHY */ |
| 147 | void reset_phy(void) |
| 148 | { |
| 149 | u16 reg; |
Tony Dinh | 1c383d5 | 2021-07-29 20:02:43 -0700 | [diff] [blame] | 150 | int phyaddr; |
| 151 | char *name = "ethernet-controller@72000"; |
| 152 | char *eth0_path = "/ocp@f1000000/ethernet-controller@72000/ethernet0-port@0"; |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 153 | |
| 154 | if (miiphy_set_current_dev(name)) |
| 155 | return; |
| 156 | |
Tony Dinh | 1c383d5 | 2021-07-29 20:02:43 -0700 | [diff] [blame] | 157 | phyaddr = fdt_get_phy_addr(eth0_path); |
| 158 | if (phyaddr < 0) |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 159 | return; |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * Enable RGMII delay on Tx and Rx for CPU port |
| 163 | * Ref: sec 4.7.2 of chip datasheet |
| 164 | */ |
Tony Dinh | 1c383d5 | 2021-07-29 20:02:43 -0700 | [diff] [blame] | 165 | miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 2); |
| 166 | miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, ®); |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 167 | reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL); |
Tony Dinh | 1c383d5 | 2021-07-29 20:02:43 -0700 | [diff] [blame] | 168 | miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg); |
| 169 | miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 0); |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 170 | |
| 171 | /* reset the phy */ |
Tony Dinh | 1c383d5 | 2021-07-29 20:02:43 -0700 | [diff] [blame] | 172 | miiphy_reset(name, phyaddr); |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 173 | |
| 174 | printf("88E1116 Initialized on %s\n", name); |
| 175 | } |
| 176 | #endif /* CONFIG_RESET_PHY_R */ |
| 177 | |
Tom Rini | a9765d0 | 2021-05-03 16:48:58 -0400 | [diff] [blame] | 178 | #if CONFIG_IS_ENABLED(BOOTSTAGE) |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 179 | #define GREEN_LED (1 << 14) |
| 180 | #define ORANGE_LED (1 << 15) |
| 181 | #define BOTH_LEDS (GREEN_LED | ORANGE_LED) |
| 182 | #define NEITHER_LED 0 |
| 183 | |
| 184 | static void set_leds(u32 leds, u32 blinking) |
| 185 | { |
| 186 | struct kwgpio_registers *r; |
| 187 | u32 oe; |
| 188 | u32 bl; |
| 189 | |
Stefan Roese | c50ab39 | 2014-10-22 12:13:11 +0200 | [diff] [blame] | 190 | r = (struct kwgpio_registers *)MVEBU_GPIO1_BASE; |
Suriyan Ramasami | f0ec8af | 2013-04-11 07:17:25 +0000 | [diff] [blame] | 191 | oe = readl(&r->oe) | BOTH_LEDS; |
| 192 | writel(oe & ~leds, &r->oe); /* active low */ |
| 193 | bl = readl(&r->blink_en) & ~BOTH_LEDS; |
| 194 | writel(bl | blinking, &r->blink_en); |
| 195 | } |
| 196 | |
| 197 | void show_boot_progress(int val) |
| 198 | { |
| 199 | switch (val) { |
| 200 | case BOOTSTAGE_ID_RUN_OS: /* booting Linux */ |
| 201 | set_leds(BOTH_LEDS, NEITHER_LED); |
| 202 | break; |
| 203 | case BOOTSTAGE_ID_NET_ETH_START: /* Ethernet initialization */ |
| 204 | set_leds(GREEN_LED, GREEN_LED); |
| 205 | break; |
| 206 | default: |
| 207 | if (val < 0) /* error */ |
| 208 | set_leds(ORANGE_LED, ORANGE_LED); |
| 209 | break; |
| 210 | } |
| 211 | } |
Tom Rini | a9765d0 | 2021-05-03 16:48:58 -0400 | [diff] [blame] | 212 | #endif |