blob: 263bb5426c0d1a7086b9ed28ea7085e7ee0a96ed [file] [log] [blame]
Simon Guinot5628fb72011-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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Simon Guinot5628fb72011-11-21 19:25:46 +053010 */
11
12#include <common.h>
Simon Guinot5628fb72011-11-21 19:25:46 +053013#include <command.h>
Simon Guinot2af4d0f2013-06-18 15:14:48 +020014#include <i2c.h>
Simon Guinot5628fb72011-11-21 19:25:46 +053015#include <asm/arch/cpu.h>
Stefan Roese3dc23f72014-10-22 12:13:06 +020016#include <asm/arch/soc.h>
Simon Guinot5628fb72011-11-21 19:25:46 +053017#include <asm/arch/mpp.h>
18#include <asm/arch/gpio.h>
Simon Guinot77ea0712011-11-21 19:25:47 +053019
Simon Guinot5628fb72011-11-21 19:25:46 +053020#include "net2big_v2.h"
Simon Guinot77ea0712011-11-21 19:25:47 +053021#include "../common/common.h"
Simon Guinot7737c992013-06-18 15:14:50 +020022#include "../common/cpld-gpio-bus.h"
Simon Guinot5628fb72011-11-21 19:25:46 +053023
24DECLARE_GLOBAL_DATA_PTR;
25
26int board_early_init_f(void)
27{
28 /* GPIO configuration */
Stefan Roesed5c51322014-10-22 12:13:11 +020029 mvebu_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH,
30 NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH);
Simon Guinot5628fb72011-11-21 19:25:46 +053031
32 /* Multi-Purpose Pins Functionality configuration */
Albert ARIBAUD9d86f0c2012-11-26 11:27:36 +000033 static const u32 kwmpp_config[] = {
Simon Guinot5628fb72011-11-21 19:25:46 +053034 MPP0_SPI_SCn,
35 MPP1_SPI_MOSI,
36 MPP2_SPI_SCK,
37 MPP3_SPI_MISO,
38 MPP6_SYSRST_OUTn,
39 MPP7_GPO, /* Request power-off */
40 MPP8_TW_SDA,
41 MPP9_TW_SCK,
42 MPP10_UART0_TXD,
43 MPP11_UART0_RXD,
44 MPP13_GPIO, /* Rear power switch (on|auto) */
45 MPP14_GPIO, /* USB fuse alarm */
46 MPP15_GPIO, /* Rear power switch (auto|off) */
47 MPP16_GPIO, /* SATA HDD1 power */
48 MPP17_GPIO, /* SATA HDD2 power */
49 MPP20_SATA1_ACTn,
50 MPP21_SATA0_ACTn,
51 MPP24_GPIO, /* USB mode select */
52 MPP26_GPIO, /* USB device vbus */
53 MPP28_GPIO, /* USB enable host vbus */
Simon Guinot7737c992013-06-18 15:14:50 +020054 MPP29_GPIO, /* CPLD GPIO bus ALE */
Simon Guinot5628fb72011-11-21 19:25:46 +053055 MPP34_GPIO, /* Rear Push button 0=on 1=off */
56 MPP35_GPIO, /* Inhibit switch power-off */
57 MPP36_GPIO, /* SATA HDD1 presence */
58 MPP37_GPIO, /* SATA HDD2 presence */
59 MPP40_GPIO, /* eSATA presence */
Simon Guinot7737c992013-06-18 15:14:50 +020060 MPP44_GPIO, /* CPLD GPIO bus (data 0) */
61 MPP45_GPIO, /* CPLD GPIO bus (data 1) */
62 MPP46_GPIO, /* CPLD GPIO bus (data 2) */
63 MPP47_GPIO, /* CPLD GPIO bus (addr 0) */
64 MPP48_GPIO, /* CPLD GPIO bus (addr 1) */
65 MPP49_GPIO, /* CPLD GPIO bus (addr 2) */
Simon Guinot5628fb72011-11-21 19:25:46 +053066 0
67 };
68
Valentin Longchamp84683632012-06-01 01:31:00 +000069 kirkwood_mpp_conf(kwmpp_config, NULL);
Simon Guinot5628fb72011-11-21 19:25:46 +053070
71 return 0;
72}
73
74int board_init(void)
75{
76 /* Machine number */
77 gd->bd->bi_arch_number = MACH_TYPE_NET2BIG_V2;
78
79 /* Boot parameters address */
Stefan Roese96c5f082014-10-22 12:13:13 +020080 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
Simon Guinot5628fb72011-11-21 19:25:46 +053081
82 return 0;
83}
84
Simon Guinot77ea0712011-11-21 19:25:47 +053085#if defined(CONFIG_MISC_INIT_R)
Simon Guinot2af4d0f2013-06-18 15:14:48 +020086
87#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR)
88/*
89 * Start I2C fan (GMT G762 controller)
90 */
91static void init_fan(void)
92{
93 u8 data;
94
95 i2c_set_bus_num(0);
96
97 /* Enable open-loop and PWM modes */
98 data = 0x20;
99 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
100 G762_REG_FAN_CMD1, 1, &data, 1) != 0)
101 goto err;
102 data = 0;
103 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
104 G762_REG_SET_CNT, 1, &data, 1) != 0)
105 goto err;
106 /*
107 * RPM to PWM (set_out register) fan speed conversion array:
108 * 0 0x00
109 * 1500 0x04
110 * 2800 0x08
111 * 3400 0x0C
112 * 3700 0x10
113 * 4400 0x20
114 * 4700 0x30
115 * 4800 0x50
116 * 5200 0x80
117 * 5400 0xC0
118 * 5500 0xFF
119 *
120 * Start fan at low speed (2800 RPM):
121 */
122 data = 0x08;
123 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
124 G762_REG_SET_OUT, 1, &data, 1) != 0)
125 goto err;
126
127 return;
128err:
129 printf("Error: failed to start I2C fan @%02x\n",
130 CONFIG_SYS_I2C_G762_ADDR);
131}
132#else
133static void init_fan(void) {}
134#endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */
135
Simon Guinot7737c992013-06-18 15:14:50 +0200136#if defined(CONFIG_NET2BIG_V2) && defined(CONFIG_KIRKWOOD_GPIO)
137/*
138 * CPLD GPIO bus:
139 *
140 * - address register : bit [0-2] -> GPIO [47-49]
141 * - data register : bit [0-2] -> GPIO [44-46]
142 * - enable register : GPIO 29
143 */
144static unsigned cpld_gpio_bus_addr[] = { 47, 48, 49 };
145static unsigned cpld_gpio_bus_data[] = { 44, 45, 46 };
146
147static struct cpld_gpio_bus cpld_gpio_bus = {
148 .addr = cpld_gpio_bus_addr,
149 .num_addr = ARRAY_SIZE(cpld_gpio_bus_addr),
150 .data = cpld_gpio_bus_data,
151 .num_data = ARRAY_SIZE(cpld_gpio_bus_data),
152 .enable = 29,
153};
154
155/*
156 * LEDs configuration:
157 *
158 * The LEDs are controlled by a CPLD and can be configured through
159 * the CPLD GPIO bus.
160 *
161 * Address register selection:
162 *
163 * addr | register
164 * ----------------------------
165 * 0 | front LED
166 * 1 | front LED brightness
167 * 2 | SATA LED brightness
168 * 3 | SATA0 LED
169 * 4 | SATA1 LED
170 * 5 | SATA2 LED
171 * 6 | SATA3 LED
172 * 7 | SATA4 LED
173 *
174 * Data register configuration:
175 *
176 * data | LED brightness
177 * -------------------------------------------------
178 * 0 | min (off)
179 * - | -
180 * 7 | max
181 *
182 * data | front LED mode
183 * -------------------------------------------------
184 * 0 | fix off
185 * 1 | fix blue on
186 * 2 | fix red on
187 * 3 | blink blue on=1 sec and blue off=1 sec
188 * 4 | blink red on=1 sec and red off=1 sec
189 * 5 | blink blue on=2.5 sec and red on=0.5 sec
190 * 6 | blink blue on=1 sec and red on=1 sec
191 * 7 | blink blue on=0.5 sec and blue off=2.5 sec
192 *
193 * data | SATA LED mode
194 * -------------------------------------------------
195 * 0 | fix off
196 * 1 | SATA activity blink
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 | fix blue on
203 */
204static void init_leds(void)
205{
206 /* Enable the front blue LED */
207 cpld_gpio_bus_write(&cpld_gpio_bus, 0, 1);
208 cpld_gpio_bus_write(&cpld_gpio_bus, 1, 3);
209
210 /* Configure SATA LEDs to blink in relation with the SATA activity */
211 cpld_gpio_bus_write(&cpld_gpio_bus, 3, 1);
212 cpld_gpio_bus_write(&cpld_gpio_bus, 4, 1);
213 cpld_gpio_bus_write(&cpld_gpio_bus, 2, 3);
214}
215#else
216static void init_leds(void) {}
217#endif /* CONFIG_NET2BIG_V2 && CONFIG_KIRKWOOD_GPIO */
218
Simon Guinot5628fb72011-11-21 19:25:46 +0530219int misc_init_r(void)
220{
Simon Guinot2af4d0f2013-06-18 15:14:48 +0200221 init_fan();
Simon Guinot77ea0712011-11-21 19:25:47 +0530222#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
Simon Guinot5628fb72011-11-21 19:25:46 +0530223 if (!getenv("ethaddr")) {
Simon Guinot5628fb72011-11-21 19:25:46 +0530224 uchar mac[6];
Simon Guinot77ea0712011-11-21 19:25:47 +0530225 if (lacie_read_mac_address(mac) == 0)
226 eth_setenv_enetaddr("ethaddr", mac);
Simon Guinot5628fb72011-11-21 19:25:46 +0530227 }
Simon Guinot77ea0712011-11-21 19:25:47 +0530228#endif
Simon Guinot7737c992013-06-18 15:14:50 +0200229 init_leds();
230
Simon Guinot5628fb72011-11-21 19:25:46 +0530231 return 0;
232}
Simon Guinot2af4d0f2013-06-18 15:14:48 +0200233#endif /* CONFIG_MISC_INIT_R */
Simon Guinot5628fb72011-11-21 19:25:46 +0530234
Simon Guinot77ea0712011-11-21 19:25:47 +0530235#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
Simon Guinot5628fb72011-11-21 19:25:46 +0530236/* Configure and initialize PHY */
237void reset_phy(void)
238{
Simon Guinotc59c0852012-06-05 13:16:00 +0000239 mv_phy_88e1116_init("egiga0", 8);
Simon Guinot5628fb72011-11-21 19:25:46 +0530240}
Simon Guinot77ea0712011-11-21 19:25:47 +0530241#endif
Simon Guinot5628fb72011-11-21 19:25:46 +0530242
Simon Guinot77ea0712011-11-21 19:25:47 +0530243#if defined(CONFIG_KIRKWOOD_GPIO)
Simon Guinot5628fb72011-11-21 19:25:46 +0530244/* Return GPIO push button status */
245static int
246do_read_push_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
247{
248 return !kw_gpio_get_value(NET2BIG_V2_GPIO_PUSH_BUTTON);
249}
250
251U_BOOT_CMD(button, 1, 1, do_read_push_button,
252 "Return GPIO push button status 0=off 1=on", "");
Simon Guinot77ea0712011-11-21 19:25:47 +0530253#endif