blob: b71de4e11f0c14951201b5e635148647d535951c [file] [log] [blame]
Tom Rini299f8f82021-07-07 22:55:41 -04001// SPDX-License-Identifier: GPL-2.0+
2/*
Tony Dinhde3ab5e2021-07-07 02:06:47 -07003 * Copyright (C) 2015, 2021 Tony Dinh <mibodhi@gmail.com>
4 * Copyright (C) 2015 Gerald Kerma <dreagle@doukki.net>
Tom Rini299f8f82021-07-07 22:55:41 -04005 */
6
7#include <common.h>
8#include <init.h>
9#include <miiphy.h>
10#include <net.h>
11#include <asm/arch/cpu.h>
12#include <asm/arch/soc.h>
13#include <asm/arch/mpp.h>
14#include <asm/global_data.h>
15#include <asm/io.h>
16#include "nsa310s.h"
17
18DECLARE_GLOBAL_DATA_PTR;
19
20int board_early_init_f(void)
21{
22 /*
23 * default gpio configuration
24 * There are maximum 64 gpios controlled through 2 sets of registers
25 * the below configuration configures mainly initial LED status
26 */
27 mvebu_config_gpio(NSA310S_VAL_LOW, NSA310S_VAL_HIGH,
28 NSA310S_OE_LOW, NSA310S_OE_HIGH);
29
30 /* (all LEDs & power off active high) */
31 /* Multi-Purpose Pins Functionality configuration */
32 static const u32 kwmpp_config[] = {
33 MPP0_NF_IO2,
34 MPP1_NF_IO3,
35 MPP2_NF_IO4,
36 MPP3_NF_IO5,
37 MPP4_NF_IO6,
38 MPP5_NF_IO7,
39 MPP6_SYSRST_OUTn,
40 MPP7_GPO,
41 MPP8_TW_SDA,
42 MPP9_TW_SCK,
43 MPP10_UART0_TXD,
44 MPP11_UART0_RXD,
45 MPP12_GPO,
46 MPP13_GPIO,
47 MPP14_GPIO,
48 MPP15_GPIO,
49 MPP16_GPIO,
50 MPP17_GPIO,
51 MPP18_NF_IO0,
52 MPP19_NF_IO1,
53 MPP20_GPIO,
54 MPP21_GPIO,
55 MPP22_GPIO,
56 MPP23_GPIO,
57 MPP24_GPIO,
58 MPP25_GPIO,
59 MPP26_GPIO,
60 MPP27_GPIO,
61 MPP28_GPIO,
62 MPP29_GPIO,
63 MPP30_GPIO,
64 MPP31_GPIO,
65 MPP32_GPIO,
66 MPP33_GPIO,
67 MPP34_GPIO,
68 MPP35_GPIO,
69 0
70 };
71 kirkwood_mpp_conf(kwmpp_config, NULL);
72 return 0;
73}
74
75int board_init(void)
76{
77 /* address of boot parameters */
78 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
79
80 return 0;
81}
82
Tony Dinhde3ab5e2021-07-07 02:06:47 -070083static int fdt_get_phy_addr(const char *path)
84{
85 const void *fdt = gd->fdt_blob;
86 const u32 *reg;
87 const u32 *val;
88 int node, phandle, addr;
89
90 /* Find the node by its full path */
91 node = fdt_path_offset(fdt, path);
92 if (node >= 0) {
93 /* Look up phy-handle */
94 val = fdt_getprop(fdt, node, "phy-handle", NULL);
95 if (val) {
96 phandle = fdt32_to_cpu(*val);
97 if (!phandle)
98 return -1;
99 /* Follow it to its node */
100 node = fdt_node_offset_by_phandle(fdt, phandle);
101 if (node) {
102 /* Look up reg */
103 reg = fdt_getprop(fdt, node, "reg", NULL);
104 if (reg) {
105 addr = fdt32_to_cpu(*reg);
106 return addr;
107 }
108 }
109 }
110 }
111 return -1;
112}
113
Tom Rini299f8f82021-07-07 22:55:41 -0400114#ifdef CONFIG_RESET_PHY_R
115void reset_phy(void)
116{
117 u16 reg;
118 u16 phyaddr;
Tony Dinhde3ab5e2021-07-07 02:06:47 -0700119 char *name = "ethernet-controller@72000";
120 char *eth0_path = "/ocp@f1000000/ethernet-controller@72000/ethernet0-port@0";
Tom Rini299f8f82021-07-07 22:55:41 -0400121
122 if (miiphy_set_current_dev(name))
123 return;
124
Tony Dinhde3ab5e2021-07-07 02:06:47 -0700125 phyaddr = fdt_get_phy_addr(eth0_path);
126 if (phyaddr < 0)
Tom Rini299f8f82021-07-07 22:55:41 -0400127 return;
Tom Rini299f8f82021-07-07 22:55:41 -0400128
129 /* set RGMII delay */
130 miiphy_write(name, phyaddr, MV88E1318_PGADR_REG, MV88E1318_MAC_CTRL_PG);
131 miiphy_read(name, phyaddr, MV88E1318_MAC_CTRL_REG, &reg);
132 reg |= (MV88E1318_RGMII_RX_CTRL | MV88E1318_RGMII_TX_CTRL);
133 miiphy_write(name, phyaddr, MV88E1318_MAC_CTRL_REG, reg);
134 miiphy_write(name, phyaddr, MV88E1318_PGADR_REG, 0);
135
136 /* reset PHY */
137 if (miiphy_reset(name, phyaddr))
138 return;
139
140 /*
141 * ZyXEL NSA310S uses the 88E1310S Alaska (interface identical to 88E1318)
142 * and has an MCU attached to the LED[2] via tristate interrupt
143 */
144
145 /* switch to LED register page */
146 miiphy_write(name, phyaddr, MV88E1318_PGADR_REG, MV88E1318_LED_PG);
147 /* read out LED polarity register */
148 miiphy_read(name, phyaddr, MV88E1318_LED_POL_REG, &reg);
149 /* clear 4, set 5 - LED2 low, tri-state */
150 reg &= ~(MV88E1318_LED2_4);
151 reg |= (MV88E1318_LED2_5);
152 /* write back LED polarity register */
153 miiphy_write(name, phyaddr, MV88E1318_LED_POL_REG, reg);
154 /* jump back to page 0, per the PHY chip documenation. */
155 miiphy_write(name, phyaddr, MV88E1318_PGADR_REG, 0);
156
157 /* set PHY back to auto-negotiation mode */
158 miiphy_write(name, phyaddr, 0x4, 0x1e1);
159 miiphy_write(name, phyaddr, 0x9, 0x300);
160 /* downshift */
161 miiphy_write(name, phyaddr, 0x10, 0x3860);
162 miiphy_write(name, phyaddr, 0x0, 0x9140);
Tony Dinhde3ab5e2021-07-07 02:06:47 -0700163
164 printf("MV88E1318 PHY initialized on %s\n", name);
Tom Rini299f8f82021-07-07 22:55:41 -0400165}
166#endif /* CONFIG_RESET_PHY_R */