blob: 5952d158b28b69c7c83e675c34e1d90e16565d1b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskar62634642009-07-16 20:58:00 +05302/*
Tony Dinh43e75bb2021-07-16 02:18:04 -07003 * Copyright (C) 2021 Tony Dinh <mibodhi@gmail.com>
Prafulla Wadaskar62634642009-07-16 20:58:00 +05304 * (C) Copyright 2009
5 * Marvell Semiconductor <www.marvell.com>
6 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
Prafulla Wadaskar62634642009-07-16 20:58:00 +05307 */
8
9#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Prafulla Wadaskar62634642009-07-16 20:58:00 +053011#include <miiphy.h>
Simon Glass0c364412019-12-28 10:44:48 -070012#include <net.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060014#include <asm/mach-types.h>
Lei Wen298ae912011-10-18 20:11:42 +053015#include <asm/arch/cpu.h>
Stefan Roesec2437842014-10-22 12:13:06 +020016#include <asm/arch/soc.h>
Prafulla Wadaskar62634642009-07-16 20:58:00 +053017#include <asm/arch/mpp.h>
18#include "sheevaplug.h"
19
20DECLARE_GLOBAL_DATA_PTR;
21
Prafulla Wadaskar44f4d432010-10-20 20:12:27 +053022int board_early_init_f(void)
Prafulla Wadaskar62634642009-07-16 20:58:00 +053023{
24 /*
25 * default gpio configuration
26 * There are maximum 64 gpios controlled through 2 sets of registers
27 * the below configuration configures mainly initial LED status
28 */
Stefan Roesec50ab392014-10-22 12:13:11 +020029 mvebu_config_gpio(SHEEVAPLUG_OE_VAL_LOW,
30 SHEEVAPLUG_OE_VAL_HIGH,
31 SHEEVAPLUG_OE_LOW, SHEEVAPLUG_OE_HIGH);
Prafulla Wadaskar62634642009-07-16 20:58:00 +053032
33 /* Multi-Purpose Pins Functionality configuration */
Albert ARIBAUD4d424312012-11-26 11:27:36 +000034 static const u32 kwmpp_config[] = {
Prafulla Wadaskar62634642009-07-16 20:58:00 +053035 MPP0_NF_IO2,
36 MPP1_NF_IO3,
37 MPP2_NF_IO4,
38 MPP3_NF_IO5,
39 MPP4_NF_IO6,
40 MPP5_NF_IO7,
41 MPP6_SYSRST_OUTn,
42 MPP7_GPO,
43 MPP8_UART0_RTS,
44 MPP9_UART0_CTS,
45 MPP10_UART0_TXD,
46 MPP11_UART0_RXD,
47 MPP12_SD_CLK,
48 MPP13_SD_CMD,
49 MPP14_SD_D0,
50 MPP15_SD_D1,
51 MPP16_SD_D2,
52 MPP17_SD_D3,
53 MPP18_NF_IO0,
54 MPP19_NF_IO1,
55 MPP20_GPIO,
56 MPP21_GPIO,
57 MPP22_GPIO,
58 MPP23_GPIO,
59 MPP24_GPIO,
60 MPP25_GPIO,
61 MPP26_GPIO,
62 MPP27_GPIO,
63 MPP28_GPIO,
64 MPP29_TSMP9,
65 MPP30_GPIO,
66 MPP31_GPIO,
67 MPP32_GPIO,
68 MPP33_GPIO,
69 MPP34_GPIO,
70 MPP35_GPIO,
71 MPP36_GPIO,
72 MPP37_GPIO,
73 MPP38_GPIO,
74 MPP39_GPIO,
75 MPP40_GPIO,
76 MPP41_GPIO,
77 MPP42_GPIO,
78 MPP43_GPIO,
79 MPP44_GPIO,
80 MPP45_GPIO,
81 MPP46_GPIO,
82 MPP47_GPIO,
83 MPP48_GPIO,
84 MPP49_GPIO,
85 0
86 };
Valentin Longchamp7d0d5022012-06-01 01:31:00 +000087 kirkwood_mpp_conf(kwmpp_config, NULL);
Prafulla Wadaskar44f4d432010-10-20 20:12:27 +053088 return 0;
89}
Prafulla Wadaskar62634642009-07-16 20:58:00 +053090
Prafulla Wadaskar44f4d432010-10-20 20:12:27 +053091int board_init(void)
92{
Prafulla Wadaskar62634642009-07-16 20:58:00 +053093 /*
94 * arch number of board
95 */
96 gd->bd->bi_arch_number = MACH_TYPE_SHEEVAPLUG;
97
98 /* adress of boot parameters */
Stefan Roese0b741752014-10-22 12:13:13 +020099 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
Prafulla Wadaskar62634642009-07-16 20:58:00 +0530100
101 return 0;
102}
103
Tony Dinh43e75bb2021-07-16 02:18:04 -0700104static int fdt_get_phy_addr(const char *path)
105{
106 const void *fdt = gd->fdt_blob;
107 const u32 *reg;
108 const u32 *val;
109 int node, phandle, addr;
110
111 /* Find the node by its full path */
112 node = fdt_path_offset(fdt, path);
113 if (node >= 0) {
114 /* Look up phy-handle */
115 val = fdt_getprop(fdt, node, "phy-handle", NULL);
116 if (val) {
117 phandle = fdt32_to_cpu(*val);
118 if (!phandle)
119 return -1;
120 /* Follow it to its node */
121 node = fdt_node_offset_by_phandle(fdt, phandle);
122 if (node) {
123 /* Look up reg */
124 reg = fdt_getprop(fdt, node, "reg", NULL);
125 if (reg) {
126 addr = fdt32_to_cpu(*reg);
127 return addr;
128 }
129 }
130 }
131 }
132 return -1;
133}
134
Prafulla Wadaskar62634642009-07-16 20:58:00 +0530135#ifdef CONFIG_RESET_PHY_R
136/* Configure and enable MV88E1116 PHY */
137void reset_phy(void)
138{
139 u16 reg;
Tony Dinh43e75bb2021-07-16 02:18:04 -0700140 int phyaddr;
141 char *name = "ethernet-controller@72000";
142 char *eth0_path = "/ocp@f1000000/ethernet-controller@72000/ethernet0-port@0";
Prafulla Wadaskar62634642009-07-16 20:58:00 +0530143
144 if (miiphy_set_current_dev(name))
145 return;
146
Tony Dinh43e75bb2021-07-16 02:18:04 -0700147 phyaddr = fdt_get_phy_addr(eth0_path);
148 if (phyaddr < 0)
Prafulla Wadaskar62634642009-07-16 20:58:00 +0530149 return;
Prafulla Wadaskar62634642009-07-16 20:58:00 +0530150
151 /*
152 * Enable RGMII delay on Tx and Rx for CPU port
153 * Ref: sec 4.7.2 of chip datasheet
154 */
Tony Dinh43e75bb2021-07-16 02:18:04 -0700155 miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 2);
156 miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, &reg);
Prafulla Wadaskar62634642009-07-16 20:58:00 +0530157 reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
Tony Dinh43e75bb2021-07-16 02:18:04 -0700158 miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg);
159 miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 0);
Prafulla Wadaskar62634642009-07-16 20:58:00 +0530160
161 /* reset the phy */
Tony Dinh43e75bb2021-07-16 02:18:04 -0700162 miiphy_reset(name, phyaddr);
Prafulla Wadaskar62634642009-07-16 20:58:00 +0530163
164 printf("88E1116 Initialized on %s\n", name);
165}
166#endif /* CONFIG_RESET_PHY_R */