Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / board / Marvell / openrd / openrd.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2009
4  * Net Insight <www.netinsight.net>
5  * Written-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
6  *
7  * Based on sheevaplug.c:
8  * (C) Copyright 2009
9  * Marvell Semiconductor <www.marvell.com>
10  * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
11  */
12
13 #include <common.h>
14 #include <init.h>
15 #include <miiphy.h>
16 #include <net.h>
17 #include <asm/mach-types.h>
18 #include <asm/arch/cpu.h>
19 #include <asm/arch/soc.h>
20 #include <asm/arch/mpp.h>
21 #include "openrd.h"
22
23 DECLARE_GLOBAL_DATA_PTR;
24
25 int board_early_init_f(void)
26 {
27         /*
28          * default gpio configuration
29          * There are maximum 64 gpios controlled through 2 sets of registers
30          * the  below configuration configures mainly initial LED status
31          */
32         mvebu_config_gpio(OPENRD_OE_VAL_LOW,
33                           OPENRD_OE_VAL_HIGH,
34                           OPENRD_OE_LOW, OPENRD_OE_HIGH);
35
36         /* Multi-Purpose Pins Functionality configuration */
37         static const u32 kwmpp_config[] = {
38                 MPP0_NF_IO2,
39                 MPP1_NF_IO3,
40                 MPP2_NF_IO4,
41                 MPP3_NF_IO5,
42                 MPP4_NF_IO6,
43                 MPP5_NF_IO7,
44                 MPP6_SYSRST_OUTn,
45                 MPP7_GPO,
46                 MPP8_TW_SDA,
47                 MPP9_TW_SCK,
48                 MPP10_UART0_TXD,
49                 MPP11_UART0_RXD,
50                 MPP12_SD_CLK,
51                 MPP13_SD_CMD, /* Alt UART1_TXD */
52                 MPP14_SD_D0,  /* Alt UART1_RXD */
53                 MPP15_SD_D1,
54                 MPP16_SD_D2,
55                 MPP17_SD_D3,
56                 MPP18_NF_IO0,
57                 MPP19_NF_IO1,
58                 MPP20_GE1_0,
59                 MPP21_GE1_1,
60                 MPP22_GE1_2,
61                 MPP23_GE1_3,
62                 MPP24_GE1_4,
63                 MPP25_GE1_5,
64                 MPP26_GE1_6,
65                 MPP27_GE1_7,
66                 MPP28_GPIO,
67                 MPP29_TSMP9,
68                 MPP30_GE1_10,
69                 MPP31_GE1_11,
70                 MPP32_GE1_12,
71                 MPP33_GE1_13,
72                 MPP34_GPIO,   /* UART1 / SD sel */
73                 MPP35_TDM_CH0_TX_QL,
74                 MPP36_TDM_SPI_CS1,
75                 MPP37_TDM_CH2_TX_QL,
76                 MPP38_TDM_CH2_RX_QL,
77                 MPP39_AUDIO_I2SBCLK,
78                 MPP40_AUDIO_I2SDO,
79                 MPP41_AUDIO_I2SLRC,
80                 MPP42_AUDIO_I2SMCLK,
81                 MPP43_AUDIO_I2SDI,
82                 MPP44_AUDIO_EXTCLK,
83                 MPP45_TDM_PCLK,
84                 MPP46_TDM_FS,
85                 MPP47_TDM_DRX,
86                 MPP48_TDM_DTX,
87                 MPP49_TDM_CH0_RX_QL,
88                 0
89         };
90
91         kirkwood_mpp_conf(kwmpp_config, NULL);
92         return 0;
93 }
94
95 int board_init(void)
96 {
97         /*
98          * arch number of board
99          */
100 #if defined(CONFIG_BOARD_IS_OPENRD_BASE)
101         gd->bd->bi_arch_number = MACH_TYPE_OPENRD_BASE;
102 #elif defined(CONFIG_BOARD_IS_OPENRD_CLIENT)
103         gd->bd->bi_arch_number = MACH_TYPE_OPENRD_CLIENT;
104 #elif defined(CONFIG_BOARD_IS_OPENRD_ULTIMATE)
105         gd->bd->bi_arch_number = MACH_TYPE_OPENRD_ULTIMATE;
106 #endif
107
108         /* adress of boot parameters */
109         gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
110         return 0;
111 }
112
113 #ifdef CONFIG_RESET_PHY_R
114 /* Configure and enable MV88E1116/88E1121 PHY */
115 void mv_phy_init(char *name)
116 {
117         u16 reg;
118         u16 devadr;
119
120         if (miiphy_set_current_dev(name))
121                 return;
122
123         /* command to read PHY dev address */
124         if (miiphy_read(name, 0xEE, 0xEE, (u16 *)&devadr)) {
125                 printf("Err..%s could not read PHY dev address\n", __func__);
126                 return;
127         }
128
129         /*
130          * Enable RGMII delay on Tx and Rx for CPU port
131          * Ref: sec 4.7.2 of chip datasheet
132          */
133         miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2);
134         miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, &reg);
135         reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
136         miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg);
137         miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0);
138
139         /* reset the phy */
140         miiphy_reset(name, devadr);
141
142         printf(PHY_NO" Initialized on %s\n", name);
143 }
144
145 void reset_phy(void)
146 {
147         mv_phy_init("egiga0");
148
149 #ifdef CONFIG_BOARD_IS_OPENRD_CLIENT
150         /* Kirkwood ethernet driver is written with the assumption that in case
151          * of multiple PHYs, their addresses are consecutive. But unfortunately
152          * in case of OpenRD-Client, PHY addresses are not consecutive.*/
153         miiphy_write("egiga1", 0xEE, 0xEE, 24);
154 #endif
155
156 #if defined(CONFIG_BOARD_IS_OPENRD_CLIENT) || \
157         defined(CONFIG_BOARD_IS_OPENRD_ULTIMATE)
158         /* configure and initialize both PHY's */
159         mv_phy_init("egiga1");
160 #endif
161 }
162 #endif /* CONFIG_RESET_PHY_R */