1 /*
2  * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com>
3  *
4  * Based on Kirkwood support:
5  * (C) Copyright 2009
6  * Marvell Semiconductor <www.marvell.com>
7  * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  */
22 
23 #include <common.h>
24 #include <command.h>
25 #include <asm/arch/cpu.h>
26 #include <asm/arch/kirkwood.h>
27 #include <asm/arch/mpp.h>
28 #include <asm/arch/gpio.h>
29 
30 #include "netspace_v2.h"
31 #include "../common/common.h"
32 
33 DECLARE_GLOBAL_DATA_PTR;
34 
35 int board_early_init_f(void)
36 {
37 	/* Gpio configuration */
38 	kw_config_gpio(NETSPACE_V2_OE_VAL_LOW, NETSPACE_V2_OE_VAL_HIGH,
39 			NETSPACE_V2_OE_LOW, NETSPACE_V2_OE_HIGH);
40 
41 	/* Multi-Purpose Pins Functionality configuration */
42 	u32 kwmpp_config[] = {
43 		MPP0_SPI_SCn,
44 		MPP1_SPI_MOSI,
45 		MPP2_SPI_SCK,
46 		MPP3_SPI_MISO,
47 		MPP4_NF_IO6,
48 		MPP5_NF_IO7,
49 		MPP6_SYSRST_OUTn,
50 		MPP7_GPO,		/* Fan speed (bit 1) */
51 		MPP8_TW_SDA,
52 		MPP9_TW_SCK,
53 		MPP10_UART0_TXD,
54 		MPP11_UART0_RXD,
55 		MPP12_GPO,		/* Red led */
56 		MPP14_GPIO,		/* USB fuse */
57 		MPP16_GPIO,		/* SATA 0 power */
58 		MPP17_GPIO,		/* SATA 1 power */
59 		MPP18_NF_IO0,
60 		MPP19_NF_IO1,
61 		MPP20_SATA1_ACTn,
62 		MPP21_SATA0_ACTn,
63 		MPP22_GPIO,		/* Fan speed (bit 0) */
64 		MPP23_GPIO,		/* Fan power */
65 		MPP24_GPIO,		/* USB mode select */
66 		MPP25_GPIO,		/* Fan rotation fail */
67 		MPP26_GPIO,		/* USB vbus-in detection */
68 		MPP28_GPIO,		/* USB enable vbus-out */
69 		MPP29_GPIO,		/* Blue led (slow register) */
70 		MPP30_GPIO,		/* Blue led (command register) */
71 		MPP31_GPIO,		/* Board power off */
72 		MPP32_GPIO,		/* Button (0 = Released, 1 = Pushed) */
73 		MPP33_GPIO,		/* Fan speed (bit 2) */
74 		0
75 	};
76 	kirkwood_mpp_conf(kwmpp_config);
77 
78 	return 0;
79 }
80 
81 int board_init(void)
82 {
83 	/* Machine number */
84 	gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
85 
86 	/* Boot parameters address */
87 	gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
88 
89 	return 0;
90 }
91 
92 #if defined(CONFIG_MISC_INIT_R)
93 int misc_init_r(void)
94 {
95 #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
96 	if (!getenv("ethaddr")) {
97 		uchar mac[6];
98 		if (lacie_read_mac_address(mac) == 0)
99 			eth_setenv_enetaddr("ethaddr", mac);
100 	}
101 #endif
102 	return 0;
103 }
104 #endif
105 
106 #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
107 /* Configure and initialize PHY */
108 void reset_phy(void)
109 {
110 	mv_phy_88e1116_init("egiga0");
111 }
112 #endif
113 
114 #if defined(CONFIG_KIRKWOOD_GPIO)
115 /* Return GPIO button status */
116 static int
117 do_read_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
118 {
119 	return kw_gpio_get_value(NETSPACE_V2_GPIO_BUTTON);
120 }
121 
122 U_BOOT_CMD(button, 1, 1, do_read_button,
123 	   "Return GPIO button status 0=off 1=on", "");
124 #endif
125