blob: 208065899f0ec38baa07f2ed59685d3868bf2346 [file] [log] [blame]
Albert ARIBAUD1e5b9952012-11-26 11:27:37 +00001/*
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 "../common/common.h"
31#include "netdev.h"
32
33DECLARE_GLOBAL_DATA_PTR;
34
35/* GPIO configuration: start FAN at low speed, USB and HDD */
36
37#define WIRELESS_SPACE_OE_LOW 0xFF006808
38#define WIRELESS_SPACE_OE_HIGH 0x0000F989
39#define WIRELESS_SPACE_OE_VAL_LOW 0x00010080
40#define WIRELESS_SPACE_OE_VAL_HIGH 0x00000240
41
42#define WIRELESS_SPACE_REAR_BUTTON 13
43#define WIRELESS_SPACE_FRONT_BUTTON 43
44
45const u32 kwmpp_config[] = {
46 MPP0_NF_IO2,
47 MPP1_NF_IO3,
48 MPP2_NF_IO4,
49 MPP3_NF_IO5,
50 MPP4_NF_IO6,
51 MPP5_NF_IO7,
52 MPP6_SYSRST_OUTn,
53 MPP7_GPO, /* Fan speed (bit 1) */
54 MPP8_TW_SDA,
55 MPP9_TW_SCK,
56 MPP10_UART0_TXD,
57 MPP11_UART0_RXD,
58 MPP13_GPIO, /* Red led */
59 MPP14_GPIO, /* USB fuse */
60 MPP15_SATA0_ACTn,
61 MPP16_GPIO, /* SATA 0 power */
62 MPP17_GPIO, /* SATA 1 power */
63 MPP18_NF_IO0,
64 MPP19_NF_IO1,
65 MPP20_GE1_0, /* Gigabit Ethernet 1 */
66 MPP21_GE1_1,
67 MPP22_GE1_2,
68 MPP23_GE1_3,
69 MPP24_GE1_4,
70 MPP25_GE1_5,
71 MPP26_GE1_6,
72 MPP27_GE1_7,
73 MPP28_GE1_8,
74 MPP29_GE1_9,
75 MPP30_GE1_10,
76 MPP31_GE1_11,
77 MPP32_GE1_12,
78 MPP33_GE1_13,
79 MPP34_GE1_14,
80 MPP35_GE1_15,
81 MPP36_GPIO, /* Fan speed (bit 2) */
82 MPP37_GPIO, /* Fan speed (bit 0) */
83 MPP38_GPIO, /* Fan power */
84 MPP39_GPIO, /* Fan rotation fail */
85 MPP40_GPIO, /* Ethernet switch link */
86 MPP41_GPIO, /* USB enable host vbus */
87 MPP42_GPIO, /* LED clock control */
88 MPP43_GPIO, /* WPS button (0=Pushed, 1=Released) */
89 MPP44_GPIO, /* Red LED on/off */
90 MPP45_GPIO, /* Red LED timer blink (on=off=100ms) */
91 MPP46_GPIO, /* Green LED on/off */
92 MPP47_GPIO, /* LED (blue, green) SATA activity blink */
93 MPP48_GPIO, /* Blue LED on/off */
94 0
95};
96
97struct mv88e61xx_config swcfg = {
98 .name = "egiga0",
99 .vlancfg = MV88E61XX_VLANCFG_ROUTER,
100 .rgmii_delay = MV88E61XX_RGMII_DELAY_EN,
101 .led_init = MV88E61XX_LED_INIT_EN,
102 .mdip = MV88E61XX_MDIP_NOCHANGE,
103 .portstate = MV88E61XX_PORTSTT_FORWARDING,
104 .cpuport = 0x20,
105 .ports_enabled = 0x3F,
106};
107
108int board_early_init_f(void)
109{
110 /* Gpio configuration */
111 kw_config_gpio(WIRELESS_SPACE_OE_VAL_LOW, WIRELESS_SPACE_OE_VAL_HIGH,
112 WIRELESS_SPACE_OE_LOW, WIRELESS_SPACE_OE_HIGH);
113
114 /* Multi-Purpose Pins Functionality configuration */
115 kirkwood_mpp_conf(kwmpp_config, NULL);
116
117 return 0;
118}
119
120int board_init(void)
121{
122 /* Machine number */
123 gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
124
125 /* Boot parameters address */
126 gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
127
128 return 0;
129}
130
131#if defined(CONFIG_MISC_INIT_R)
132int misc_init_r(void)
133{
134#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
135 if (!getenv("ethaddr")) {
136 uchar mac[6];
137 if (lacie_read_mac_address(mac) == 0)
138 eth_setenv_enetaddr("ethaddr", mac);
139 }
140#endif
141 return 0;
142}
143#endif
144
145#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
146/* Configure and initialize PHY */
147void reset_phy(void)
148{
149 /* configure switch on egiga0 */
150 mv88e61xx_switch_initialize(&swcfg);
151}
152#endif
153
154#if defined(CONFIG_KIRKWOOD_GPIO) && defined(CONFIG_WIRELESS_SPACE_CMD)
155/* Return GPIO button status */
156static int
157do_ws(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
158{
159 if (strcmp(argv[1], "button") == 0) {
160 if (strcmp(argv[2], "rear") == 0)
161 /* invert GPIO result for intuitive while/until use */
162 return !kw_gpio_get_value(WIRELESS_SPACE_REAR_BUTTON);
163 else if (strcmp(argv[2], "front") == 0)
164 return kw_gpio_get_value(WIRELESS_SPACE_FRONT_BUTTON);
165 else
166 return -1;
167 } else {
168 return -1;
169 }
170}
171
172U_BOOT_CMD(ws, 3, 0, do_ws,
173 "Return GPIO button status 0=off 1=on",
174 "- ws button rear|front: test buttons' states\n"
175);
176#endif