blob: 52be64fb8c2f13d1eb2387416cbb3cb08df5448b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +00002/*
Tony Dinh1c383d52021-07-29 20:02:43 -07003 * Copyright (C) 2021
4 * Tony Dinh <mibodhi@gmail.com>
5 * Suriyan Ramasami <suriyan.r@gmail.com>
6 *
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +00007 * 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 Ramasamif0ec8af2013-04-11 07:17:25 +000016 */
17
18#include <common.h>
Simon Glass1ea97892020-05-10 11:40:00 -060019#include <bootstage.h>
Simon Glass97589732020-05-10 11:40:02 -060020#include <init.h>
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +000021#include <miiphy.h>
Simon Glass0c364412019-12-28 10:44:48 -070022#include <net.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060023#include <asm/global_data.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060024#include <asm/mach-types.h>
Stefan Roesec2437842014-10-22 12:13:06 +020025#include <asm/arch/soc.h>
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +000026#include <asm/arch/mpp.h>
27#include <asm/arch/cpu.h>
28#include <asm/io.h>
29
30DECLARE_GLOBAL_DATA_PTR;
31
32int 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 Roesec50ab392014-10-22 12:13:11 +020094 mvebu_config_gpio(GOFLEXHOME_OE_VAL_LOW,
95 GOFLEXHOME_OE_VAL_HIGH,
96 GOFLEXHOME_OE_LOW, GOFLEXHOME_OE_HIGH);
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +000097 kirkwood_mpp_conf(kwmpp_config, NULL);
98 return 0;
99}
100
101int board_init(void)
102{
Tom Rini48157342017-01-25 20:42:35 -0500103 /*
104 * arch number of board
105 */
106 gd->bd->bi_arch_number = MACH_TYPE_GOFLEXHOME;
107
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000108 /* address of boot parameters */
Stefan Roese0b741752014-10-22 12:13:13 +0200109 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000110
111 return 0;
112}
113
Tony Dinh1c383d52021-07-29 20:02:43 -0700114static 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 Ramasamif0ec8af2013-04-11 07:17:25 +0000145#ifdef CONFIG_RESET_PHY_R
146/* Configure and enable MV88E1116 PHY */
147void reset_phy(void)
148{
149 u16 reg;
Tony Dinh1c383d52021-07-29 20:02:43 -0700150 int phyaddr;
151 char *name = "ethernet-controller@72000";
152 char *eth0_path = "/ocp@f1000000/ethernet-controller@72000/ethernet0-port@0";
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000153
154 if (miiphy_set_current_dev(name))
155 return;
156
Tony Dinh1c383d52021-07-29 20:02:43 -0700157 phyaddr = fdt_get_phy_addr(eth0_path);
158 if (phyaddr < 0)
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000159 return;
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000160
161 /*
162 * Enable RGMII delay on Tx and Rx for CPU port
163 * Ref: sec 4.7.2 of chip datasheet
164 */
Tony Dinh1c383d52021-07-29 20:02:43 -0700165 miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 2);
166 miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, &reg);
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000167 reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
Tony Dinh1c383d52021-07-29 20:02:43 -0700168 miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg);
169 miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 0);
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000170
171 /* reset the phy */
Tony Dinh1c383d52021-07-29 20:02:43 -0700172 miiphy_reset(name, phyaddr);
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000173
174 printf("88E1116 Initialized on %s\n", name);
175}
176#endif /* CONFIG_RESET_PHY_R */
177
Tom Rinia9765d02021-05-03 16:48:58 -0400178#if CONFIG_IS_ENABLED(BOOTSTAGE)
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000179#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
184static void set_leds(u32 leds, u32 blinking)
185{
186 struct kwgpio_registers *r;
187 u32 oe;
188 u32 bl;
189
Stefan Roesec50ab392014-10-22 12:13:11 +0200190 r = (struct kwgpio_registers *)MVEBU_GPIO1_BASE;
Suriyan Ramasamif0ec8af2013-04-11 07:17:25 +0000191 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
197void 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 Rinia9765d02021-05-03 16:48:58 -0400212#endif