0ff8a9053e7d6659d96eda092333ee72a76e9144
[pandora-u-boot.git] / board / Seagate / dockstar / dockstar.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2010  Eric C. Cooper <ecc@cmu.edu>
4  *
5  * Based on sheevaplug.c originally written by
6  * Prafulla Wadaskar <prafulla@marvell.com>
7  * (C) Copyright 2009
8  * Marvell Semiconductor <www.marvell.com>
9  */
10
11 #include <common.h>
12 #include <bootstage.h>
13 #include <miiphy.h>
14 #include <net.h>
15 #include <asm/arch/soc.h>
16 #include <asm/arch/mpp.h>
17 #include <asm/arch/cpu.h>
18 #include <asm/io.h>
19 #include <asm/mach-types.h>
20 #include "dockstar.h"
21
22 DECLARE_GLOBAL_DATA_PTR;
23
24 int board_early_init_f(void)
25 {
26         /*
27          * default gpio configuration
28          * There are maximum 64 gpios controlled through 2 sets of registers
29          * the  below configuration configures mainly initial LED status
30          */
31         mvebu_config_gpio(DOCKSTAR_OE_VAL_LOW,
32                           DOCKSTAR_OE_VAL_HIGH,
33                           DOCKSTAR_OE_LOW, DOCKSTAR_OE_HIGH);
34
35         /* Multi-Purpose Pins Functionality configuration */
36         static const u32 kwmpp_config[] = {
37                 MPP0_NF_IO2,
38                 MPP1_NF_IO3,
39                 MPP2_NF_IO4,
40                 MPP3_NF_IO5,
41                 MPP4_NF_IO6,
42                 MPP5_NF_IO7,
43                 MPP6_SYSRST_OUTn,
44                 MPP7_GPO,
45                 MPP8_UART0_RTS,
46                 MPP9_UART0_CTS,
47                 MPP10_UART0_TXD,
48                 MPP11_UART0_RXD,
49                 MPP12_SD_CLK,
50                 MPP13_SD_CMD,
51                 MPP14_SD_D0,
52                 MPP15_SD_D1,
53                 MPP16_SD_D2,
54                 MPP17_SD_D3,
55                 MPP18_NF_IO0,
56                 MPP19_NF_IO1,
57                 MPP20_GPIO,
58                 MPP21_GPIO,
59                 MPP22_GPIO,
60                 MPP23_GPIO,
61                 MPP24_GPIO,
62                 MPP25_GPIO,
63                 MPP26_GPIO,
64                 MPP27_GPIO,
65                 MPP28_GPIO,
66                 MPP29_TSMP9,
67                 MPP30_GPIO,
68                 MPP31_GPIO,
69                 MPP32_GPIO,
70                 MPP33_GPIO,
71                 MPP34_GPIO,
72                 MPP35_GPIO,
73                 MPP36_GPIO,
74                 MPP37_GPIO,
75                 MPP38_GPIO,
76                 MPP39_GPIO,
77                 MPP40_GPIO,
78                 MPP41_GPIO,
79                 MPP42_GPIO,
80                 MPP43_GPIO,
81                 MPP44_GPIO,
82                 MPP45_GPIO,
83                 MPP46_GPIO,
84                 MPP47_GPIO,
85                 MPP48_GPIO,
86                 MPP49_GPIO,
87                 0
88         };
89         kirkwood_mpp_conf(kwmpp_config, NULL);
90         return 0;
91 }
92
93 int board_init(void)
94 {
95         /*
96          * arch number of board
97          */
98         gd->bd->bi_arch_number = MACH_TYPE_DOCKSTAR;
99
100         /* address of boot parameters */
101         gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
102
103         return 0;
104 }
105
106 #ifdef CONFIG_RESET_PHY_R
107 /* Configure and enable MV88E1116 PHY */
108 void reset_phy(void)
109 {
110         u16 reg;
111         u16 devadr;
112         char *name = "egiga0";
113
114         if (miiphy_set_current_dev(name))
115                 return;
116
117         /* command to read PHY dev address */
118         if (miiphy_read(name, 0xEE, 0xEE, (u16 *) &devadr)) {
119                 printf("Err..%s could not read PHY dev address\n",
120                         __FUNCTION__);
121                 return;
122         }
123
124         /*
125          * Enable RGMII delay on Tx and Rx for CPU port
126          * Ref: sec 4.7.2 of chip datasheet
127          */
128         miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2);
129         miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, &reg);
130         reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
131         miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg);
132         miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0);
133
134         /* reset the phy */
135         miiphy_reset(name, devadr);
136
137         printf("88E1116 Initialized on %s\n", name);
138 }
139 #endif /* CONFIG_RESET_PHY_R */
140
141 #define GREEN_LED       (1 << 14)
142 #define ORANGE_LED      (1 << 15)
143 #define BOTH_LEDS       (GREEN_LED | ORANGE_LED)
144 #define NEITHER_LED     0
145
146 static void set_leds(u32 leds, u32 blinking)
147 {
148         struct kwgpio_registers *r = (struct kwgpio_registers *)MVEBU_GPIO1_BASE;
149         u32 oe = readl(&r->oe) | BOTH_LEDS;
150         writel(oe & ~leds, &r->oe);     /* active low */
151         u32 bl = readl(&r->blink_en) & ~BOTH_LEDS;
152         writel(bl | blinking, &r->blink_en);
153 }
154
155 void show_boot_progress(int val)
156 {
157         switch (val) {
158         case BOOTSTAGE_ID_RUN_OS:               /* booting Linux */
159                 set_leds(BOTH_LEDS, NEITHER_LED);
160                 break;
161         case BOOTSTAGE_ID_NET_ETH_START:        /* Ethernet initialization */
162                 set_leds(GREEN_LED, GREEN_LED);
163                 break;
164         default:
165                 if (val < 0)    /* error */
166                         set_leds(ORANGE_LED, ORANGE_LED);
167                 break;
168         }
169 }