blob: b133f7cb3bde856143f133f9d06de4215d2d0ef7 [file] [log] [blame]
Simon Guinot72198a32011-11-21 19:25:46 +05301/*
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>
Simon Guinot72198a32011-11-21 19:25:46 +053024#include <command.h>
Simon Guinot1dd67e62013-06-18 15:14:48 +020025#include <i2c.h>
Simon Guinot72198a32011-11-21 19:25:46 +053026#include <asm/arch/cpu.h>
27#include <asm/arch/kirkwood.h>
28#include <asm/arch/mpp.h>
29#include <asm/arch/gpio.h>
Simon Guinota35cb4c2011-11-21 19:25:47 +053030
Simon Guinot72198a32011-11-21 19:25:46 +053031#include "net2big_v2.h"
Simon Guinota35cb4c2011-11-21 19:25:47 +053032#include "../common/common.h"
Simon Guinotbfbf8862013-06-18 15:14:50 +020033#include "../common/cpld-gpio-bus.h"
Simon Guinot72198a32011-11-21 19:25:46 +053034
35DECLARE_GLOBAL_DATA_PTR;
36
37int board_early_init_f(void)
38{
39 /* GPIO configuration */
40 kw_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH,
41 NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH);
42
43 /* Multi-Purpose Pins Functionality configuration */
Albert ARIBAUD4d424312012-11-26 11:27:36 +000044 static const u32 kwmpp_config[] = {
Simon Guinot72198a32011-11-21 19:25:46 +053045 MPP0_SPI_SCn,
46 MPP1_SPI_MOSI,
47 MPP2_SPI_SCK,
48 MPP3_SPI_MISO,
49 MPP6_SYSRST_OUTn,
50 MPP7_GPO, /* Request power-off */
51 MPP8_TW_SDA,
52 MPP9_TW_SCK,
53 MPP10_UART0_TXD,
54 MPP11_UART0_RXD,
55 MPP13_GPIO, /* Rear power switch (on|auto) */
56 MPP14_GPIO, /* USB fuse alarm */
57 MPP15_GPIO, /* Rear power switch (auto|off) */
58 MPP16_GPIO, /* SATA HDD1 power */
59 MPP17_GPIO, /* SATA HDD2 power */
60 MPP20_SATA1_ACTn,
61 MPP21_SATA0_ACTn,
62 MPP24_GPIO, /* USB mode select */
63 MPP26_GPIO, /* USB device vbus */
64 MPP28_GPIO, /* USB enable host vbus */
Simon Guinotbfbf8862013-06-18 15:14:50 +020065 MPP29_GPIO, /* CPLD GPIO bus ALE */
Simon Guinot72198a32011-11-21 19:25:46 +053066 MPP34_GPIO, /* Rear Push button 0=on 1=off */
67 MPP35_GPIO, /* Inhibit switch power-off */
68 MPP36_GPIO, /* SATA HDD1 presence */
69 MPP37_GPIO, /* SATA HDD2 presence */
70 MPP40_GPIO, /* eSATA presence */
Simon Guinotbfbf8862013-06-18 15:14:50 +020071 MPP44_GPIO, /* CPLD GPIO bus (data 0) */
72 MPP45_GPIO, /* CPLD GPIO bus (data 1) */
73 MPP46_GPIO, /* CPLD GPIO bus (data 2) */
74 MPP47_GPIO, /* CPLD GPIO bus (addr 0) */
75 MPP48_GPIO, /* CPLD GPIO bus (addr 1) */
76 MPP49_GPIO, /* CPLD GPIO bus (addr 2) */
Simon Guinot72198a32011-11-21 19:25:46 +053077 0
78 };
79
Valentin Longchamp7d0d5022012-06-01 01:31:00 +000080 kirkwood_mpp_conf(kwmpp_config, NULL);
Simon Guinot72198a32011-11-21 19:25:46 +053081
82 return 0;
83}
84
85int board_init(void)
86{
87 /* Machine number */
88 gd->bd->bi_arch_number = MACH_TYPE_NET2BIG_V2;
89
90 /* Boot parameters address */
91 gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
92
93 return 0;
94}
95
Simon Guinota35cb4c2011-11-21 19:25:47 +053096#if defined(CONFIG_MISC_INIT_R)
Simon Guinot1dd67e62013-06-18 15:14:48 +020097
98#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR)
99/*
100 * Start I2C fan (GMT G762 controller)
101 */
102static void init_fan(void)
103{
104 u8 data;
105
106 i2c_set_bus_num(0);
107
108 /* Enable open-loop and PWM modes */
109 data = 0x20;
110 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
111 G762_REG_FAN_CMD1, 1, &data, 1) != 0)
112 goto err;
113 data = 0;
114 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
115 G762_REG_SET_CNT, 1, &data, 1) != 0)
116 goto err;
117 /*
118 * RPM to PWM (set_out register) fan speed conversion array:
119 * 0 0x00
120 * 1500 0x04
121 * 2800 0x08
122 * 3400 0x0C
123 * 3700 0x10
124 * 4400 0x20
125 * 4700 0x30
126 * 4800 0x50
127 * 5200 0x80
128 * 5400 0xC0
129 * 5500 0xFF
130 *
131 * Start fan at low speed (2800 RPM):
132 */
133 data = 0x08;
134 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
135 G762_REG_SET_OUT, 1, &data, 1) != 0)
136 goto err;
137
138 return;
139err:
140 printf("Error: failed to start I2C fan @%02x\n",
141 CONFIG_SYS_I2C_G762_ADDR);
142}
143#else
144static void init_fan(void) {}
145#endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */
146
Simon Guinotbfbf8862013-06-18 15:14:50 +0200147#if defined(CONFIG_NET2BIG_V2) && defined(CONFIG_KIRKWOOD_GPIO)
148/*
149 * CPLD GPIO bus:
150 *
151 * - address register : bit [0-2] -> GPIO [47-49]
152 * - data register : bit [0-2] -> GPIO [44-46]
153 * - enable register : GPIO 29
154 */
155static unsigned cpld_gpio_bus_addr[] = { 47, 48, 49 };
156static unsigned cpld_gpio_bus_data[] = { 44, 45, 46 };
157
158static struct cpld_gpio_bus cpld_gpio_bus = {
159 .addr = cpld_gpio_bus_addr,
160 .num_addr = ARRAY_SIZE(cpld_gpio_bus_addr),
161 .data = cpld_gpio_bus_data,
162 .num_data = ARRAY_SIZE(cpld_gpio_bus_data),
163 .enable = 29,
164};
165
166/*
167 * LEDs configuration:
168 *
169 * The LEDs are controlled by a CPLD and can be configured through
170 * the CPLD GPIO bus.
171 *
172 * Address register selection:
173 *
174 * addr | register
175 * ----------------------------
176 * 0 | front LED
177 * 1 | front LED brightness
178 * 2 | SATA LED brightness
179 * 3 | SATA0 LED
180 * 4 | SATA1 LED
181 * 5 | SATA2 LED
182 * 6 | SATA3 LED
183 * 7 | SATA4 LED
184 *
185 * Data register configuration:
186 *
187 * data | LED brightness
188 * -------------------------------------------------
189 * 0 | min (off)
190 * - | -
191 * 7 | max
192 *
193 * data | front LED mode
194 * -------------------------------------------------
195 * 0 | fix off
196 * 1 | fix blue on
197 * 2 | fix red on
198 * 3 | blink blue on=1 sec and blue off=1 sec
199 * 4 | blink red on=1 sec and red off=1 sec
200 * 5 | blink blue on=2.5 sec and red on=0.5 sec
201 * 6 | blink blue on=1 sec and red on=1 sec
202 * 7 | blink blue on=0.5 sec and blue off=2.5 sec
203 *
204 * data | SATA LED mode
205 * -------------------------------------------------
206 * 0 | fix off
207 * 1 | SATA activity blink
208 * 2 | fix red on
209 * 3 | blink blue on=1 sec and blue off=1 sec
210 * 4 | blink red on=1 sec and red off=1 sec
211 * 5 | blink blue on=2.5 sec and red on=0.5 sec
212 * 6 | blink blue on=1 sec and red on=1 sec
213 * 7 | fix blue on
214 */
215static void init_leds(void)
216{
217 /* Enable the front blue LED */
218 cpld_gpio_bus_write(&cpld_gpio_bus, 0, 1);
219 cpld_gpio_bus_write(&cpld_gpio_bus, 1, 3);
220
221 /* Configure SATA LEDs to blink in relation with the SATA activity */
222 cpld_gpio_bus_write(&cpld_gpio_bus, 3, 1);
223 cpld_gpio_bus_write(&cpld_gpio_bus, 4, 1);
224 cpld_gpio_bus_write(&cpld_gpio_bus, 2, 3);
225}
226#else
227static void init_leds(void) {}
228#endif /* CONFIG_NET2BIG_V2 && CONFIG_KIRKWOOD_GPIO */
229
Simon Guinot72198a32011-11-21 19:25:46 +0530230int misc_init_r(void)
231{
Simon Guinot1dd67e62013-06-18 15:14:48 +0200232 init_fan();
Simon Guinota35cb4c2011-11-21 19:25:47 +0530233#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
Simon Guinot72198a32011-11-21 19:25:46 +0530234 if (!getenv("ethaddr")) {
Simon Guinot72198a32011-11-21 19:25:46 +0530235 uchar mac[6];
Simon Guinota35cb4c2011-11-21 19:25:47 +0530236 if (lacie_read_mac_address(mac) == 0)
237 eth_setenv_enetaddr("ethaddr", mac);
Simon Guinot72198a32011-11-21 19:25:46 +0530238 }
Simon Guinota35cb4c2011-11-21 19:25:47 +0530239#endif
Simon Guinotbfbf8862013-06-18 15:14:50 +0200240 init_leds();
241
Simon Guinot72198a32011-11-21 19:25:46 +0530242 return 0;
243}
Simon Guinot1dd67e62013-06-18 15:14:48 +0200244#endif /* CONFIG_MISC_INIT_R */
Simon Guinot72198a32011-11-21 19:25:46 +0530245
Simon Guinota35cb4c2011-11-21 19:25:47 +0530246#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
Simon Guinot72198a32011-11-21 19:25:46 +0530247/* Configure and initialize PHY */
248void reset_phy(void)
249{
Simon Guinot0473b682012-06-05 13:16:00 +0000250 mv_phy_88e1116_init("egiga0", 8);
Simon Guinot72198a32011-11-21 19:25:46 +0530251}
Simon Guinota35cb4c2011-11-21 19:25:47 +0530252#endif
Simon Guinot72198a32011-11-21 19:25:46 +0530253
Simon Guinota35cb4c2011-11-21 19:25:47 +0530254#if defined(CONFIG_KIRKWOOD_GPIO)
Simon Guinot72198a32011-11-21 19:25:46 +0530255/* Return GPIO push button status */
256static int
257do_read_push_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
258{
259 return !kw_gpio_get_value(NET2BIG_V2_GPIO_PUSH_BUTTON);
260}
261
262U_BOOT_CMD(button, 1, 1, do_read_push_button,
263 "Return GPIO push button status 0=off 1=on", "");
Simon Guinota35cb4c2011-11-21 19:25:47 +0530264#endif