1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com>
4 *
5 * Based on Kirkwood support:
6 * (C) Copyright 2009
7 * Marvell Semiconductor <www.marvell.com>
8 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
9 */
10
11 #include <command.h>
12 #include <env.h>
13 #include <init.h>
14 #include <net.h>
15 #include <asm/global_data.h>
16 #include <asm/mach-types.h>
17 #include <asm/arch/cpu.h>
18 #include <asm/arch/soc.h>
19 #include <asm/arch/mpp.h>
20 #include <asm/arch/gpio.h>
21
22 #include "netspace_v2.h"
23 #include "../common/common.h"
24
25 DECLARE_GLOBAL_DATA_PTR;
26
board_early_init_f(void)27 int board_early_init_f(void)
28 {
29 /* Gpio configuration */
30 mvebu_config_gpio(NETSPACE_V2_OE_VAL_LOW, NETSPACE_V2_OE_VAL_HIGH,
31 NETSPACE_V2_OE_LOW, NETSPACE_V2_OE_HIGH);
32
33 /* Multi-Purpose Pins Functionality configuration */
34 static const u32 kwmpp_config[] = {
35 MPP0_SPI_SCn,
36 MPP1_SPI_MOSI,
37 MPP2_SPI_SCK,
38 MPP3_SPI_MISO,
39 MPP4_NF_IO6,
40 MPP5_NF_IO7,
41 MPP6_SYSRST_OUTn,
42 MPP7_GPO, /* Fan speed (bit 1) */
43 MPP8_TW_SDA,
44 MPP9_TW_SCK,
45 MPP10_UART0_TXD,
46 MPP11_UART0_RXD,
47 MPP12_GPO, /* Red led */
48 MPP14_GPIO, /* USB fuse */
49 MPP16_GPIO, /* SATA 0 power */
50 MPP17_GPIO, /* SATA 1 power */
51 MPP18_NF_IO0,
52 MPP19_NF_IO1,
53 MPP20_SATA1_ACTn,
54 MPP21_SATA0_ACTn,
55 MPP22_GPIO, /* Fan speed (bit 0) */
56 MPP23_GPIO, /* Fan power */
57 MPP24_GPIO, /* USB mode select */
58 MPP25_GPIO, /* Fan rotation fail */
59 MPP26_GPIO, /* USB vbus-in detection */
60 MPP28_GPIO, /* USB enable vbus-out */
61 MPP29_GPIO, /* Blue led (slow register) */
62 MPP30_GPIO, /* Blue led (command register) */
63 MPP31_GPIO, /* Board power off */
64 MPP32_GPIO, /* Button (0 = Released, 1 = Pushed) */
65 MPP33_GPIO, /* Fan speed (bit 2) */
66 0
67 };
68 kirkwood_mpp_conf(kwmpp_config, NULL);
69
70 return 0;
71 }
72
board_init(void)73 int board_init(void)
74 {
75 #ifdef CONFIG_MACH_TYPE
76 /* Machine number */
77 gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
78 #endif
79
80 /* Boot parameters address */
81 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
82
83 return 0;
84 }
85
86 #if defined(CONFIG_MISC_INIT_R)
misc_init_r(void)87 int misc_init_r(void)
88 {
89 #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
90 if (!env_get("ethaddr")) {
91 uchar mac[6];
92 if (lacie_read_mac_address(mac) == 0)
93 eth_env_set_enetaddr("ethaddr", mac);
94 }
95 #endif
96 return 0;
97 }
98 #endif
99
100 #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
101 /* Configure and initialize PHY */
reset_phy(void)102 void reset_phy(void)
103 {
104 #if defined(CONFIG_NETSPACE_LITE_V2) || defined(CONFIG_NETSPACE_MINI_V2)
105 mv_phy_88e1318_init("ethernet-controller@72000", 0);
106 #else
107 mv_phy_88e1116_init("ethernet-controller@72000", 8);
108 #endif
109 }
110 #endif
111
112 #if defined(CONFIG_KIRKWOOD_GPIO)
113 /* Return GPIO button status */
114 static int
do_read_button(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])115 do_read_button(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
116 {
117 return kw_gpio_get_value(NETSPACE_V2_GPIO_BUTTON);
118 }
119
120 U_BOOT_CMD(button, 1, 1, do_read_button,
121 "Return GPIO button status 0=off 1=on", "");
122 #endif
123