blob: f639a37d4da01416dc26f6ad63198c1716c14345 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Simon Guinot72198a32011-11-21 19:25:46 +053010 */
11
12#include <common.h>
Simon Guinot72198a32011-11-21 19:25:46 +053013#include <command.h>
Simon Guinot1dd67e62013-06-18 15:14:48 +020014#include <i2c.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060015#include <asm/mach-types.h>
Simon Guinot72198a32011-11-21 19:25:46 +053016#include <asm/arch/cpu.h>
Stefan Roesec2437842014-10-22 12:13:06 +020017#include <asm/arch/soc.h>
Simon Guinot72198a32011-11-21 19:25:46 +053018#include <asm/arch/mpp.h>
19#include <asm/arch/gpio.h>
Simon Guinota35cb4c2011-11-21 19:25:47 +053020
Simon Guinot72198a32011-11-21 19:25:46 +053021#include "net2big_v2.h"
Simon Guinota35cb4c2011-11-21 19:25:47 +053022#include "../common/common.h"
Simon Guinotbfbf8862013-06-18 15:14:50 +020023#include "../common/cpld-gpio-bus.h"
Simon Guinot72198a32011-11-21 19:25:46 +053024
25DECLARE_GLOBAL_DATA_PTR;
26
27int board_early_init_f(void)
28{
29 /* GPIO configuration */
Stefan Roesec50ab392014-10-22 12:13:11 +020030 mvebu_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH,
31 NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH);
Simon Guinot72198a32011-11-21 19:25:46 +053032
33 /* Multi-Purpose Pins Functionality configuration */
Albert ARIBAUD4d424312012-11-26 11:27:36 +000034 static const u32 kwmpp_config[] = {
Simon Guinot72198a32011-11-21 19:25:46 +053035 MPP0_SPI_SCn,
36 MPP1_SPI_MOSI,
37 MPP2_SPI_SCK,
38 MPP3_SPI_MISO,
39 MPP6_SYSRST_OUTn,
40 MPP7_GPO, /* Request power-off */
41 MPP8_TW_SDA,
42 MPP9_TW_SCK,
43 MPP10_UART0_TXD,
44 MPP11_UART0_RXD,
45 MPP13_GPIO, /* Rear power switch (on|auto) */
46 MPP14_GPIO, /* USB fuse alarm */
47 MPP15_GPIO, /* Rear power switch (auto|off) */
48 MPP16_GPIO, /* SATA HDD1 power */
49 MPP17_GPIO, /* SATA HDD2 power */
50 MPP20_SATA1_ACTn,
51 MPP21_SATA0_ACTn,
52 MPP24_GPIO, /* USB mode select */
53 MPP26_GPIO, /* USB device vbus */
54 MPP28_GPIO, /* USB enable host vbus */
Simon Guinotbfbf8862013-06-18 15:14:50 +020055 MPP29_GPIO, /* CPLD GPIO bus ALE */
Simon Guinot72198a32011-11-21 19:25:46 +053056 MPP34_GPIO, /* Rear Push button 0=on 1=off */
57 MPP35_GPIO, /* Inhibit switch power-off */
58 MPP36_GPIO, /* SATA HDD1 presence */
59 MPP37_GPIO, /* SATA HDD2 presence */
60 MPP40_GPIO, /* eSATA presence */
Simon Guinotbfbf8862013-06-18 15:14:50 +020061 MPP44_GPIO, /* CPLD GPIO bus (data 0) */
62 MPP45_GPIO, /* CPLD GPIO bus (data 1) */
63 MPP46_GPIO, /* CPLD GPIO bus (data 2) */
64 MPP47_GPIO, /* CPLD GPIO bus (addr 0) */
65 MPP48_GPIO, /* CPLD GPIO bus (addr 1) */
66 MPP49_GPIO, /* CPLD GPIO bus (addr 2) */
Simon Guinot72198a32011-11-21 19:25:46 +053067 0
68 };
69
Valentin Longchamp7d0d5022012-06-01 01:31:00 +000070 kirkwood_mpp_conf(kwmpp_config, NULL);
Simon Guinot72198a32011-11-21 19:25:46 +053071
72 return 0;
73}
74
75int board_init(void)
76{
77 /* Machine number */
78 gd->bd->bi_arch_number = MACH_TYPE_NET2BIG_V2;
79
80 /* Boot parameters address */
Stefan Roese0b741752014-10-22 12:13:13 +020081 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
Simon Guinot72198a32011-11-21 19:25:46 +053082
83 return 0;
84}
85
Simon Guinota35cb4c2011-11-21 19:25:47 +053086#if defined(CONFIG_MISC_INIT_R)
Simon Guinot1dd67e62013-06-18 15:14:48 +020087
88#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR)
89/*
90 * Start I2C fan (GMT G762 controller)
91 */
92static void init_fan(void)
93{
94 u8 data;
95
96 i2c_set_bus_num(0);
97
98 /* Enable open-loop and PWM modes */
99 data = 0x20;
100 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
101 G762_REG_FAN_CMD1, 1, &data, 1) != 0)
102 goto err;
103 data = 0;
104 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
105 G762_REG_SET_CNT, 1, &data, 1) != 0)
106 goto err;
107 /*
108 * RPM to PWM (set_out register) fan speed conversion array:
109 * 0 0x00
110 * 1500 0x04
111 * 2800 0x08
112 * 3400 0x0C
113 * 3700 0x10
114 * 4400 0x20
115 * 4700 0x30
116 * 4800 0x50
117 * 5200 0x80
118 * 5400 0xC0
119 * 5500 0xFF
120 *
121 * Start fan at low speed (2800 RPM):
122 */
123 data = 0x08;
124 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
125 G762_REG_SET_OUT, 1, &data, 1) != 0)
126 goto err;
127
128 return;
129err:
130 printf("Error: failed to start I2C fan @%02x\n",
131 CONFIG_SYS_I2C_G762_ADDR);
132}
133#else
134static void init_fan(void) {}
135#endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */
136
Simon Guinotbfbf8862013-06-18 15:14:50 +0200137#if defined(CONFIG_NET2BIG_V2) && defined(CONFIG_KIRKWOOD_GPIO)
138/*
139 * CPLD GPIO bus:
140 *
141 * - address register : bit [0-2] -> GPIO [47-49]
142 * - data register : bit [0-2] -> GPIO [44-46]
143 * - enable register : GPIO 29
144 */
145static unsigned cpld_gpio_bus_addr[] = { 47, 48, 49 };
146static unsigned cpld_gpio_bus_data[] = { 44, 45, 46 };
147
148static struct cpld_gpio_bus cpld_gpio_bus = {
149 .addr = cpld_gpio_bus_addr,
150 .num_addr = ARRAY_SIZE(cpld_gpio_bus_addr),
151 .data = cpld_gpio_bus_data,
152 .num_data = ARRAY_SIZE(cpld_gpio_bus_data),
153 .enable = 29,
154};
155
156/*
157 * LEDs configuration:
158 *
159 * The LEDs are controlled by a CPLD and can be configured through
160 * the CPLD GPIO bus.
161 *
162 * Address register selection:
163 *
164 * addr | register
165 * ----------------------------
166 * 0 | front LED
167 * 1 | front LED brightness
168 * 2 | SATA LED brightness
169 * 3 | SATA0 LED
170 * 4 | SATA1 LED
171 * 5 | SATA2 LED
172 * 6 | SATA3 LED
173 * 7 | SATA4 LED
174 *
175 * Data register configuration:
176 *
177 * data | LED brightness
178 * -------------------------------------------------
179 * 0 | min (off)
180 * - | -
181 * 7 | max
182 *
183 * data | front LED mode
184 * -------------------------------------------------
185 * 0 | fix off
186 * 1 | fix blue on
187 * 2 | fix red on
188 * 3 | blink blue on=1 sec and blue off=1 sec
189 * 4 | blink red on=1 sec and red off=1 sec
190 * 5 | blink blue on=2.5 sec and red on=0.5 sec
191 * 6 | blink blue on=1 sec and red on=1 sec
192 * 7 | blink blue on=0.5 sec and blue off=2.5 sec
193 *
194 * data | SATA LED mode
195 * -------------------------------------------------
196 * 0 | fix off
197 * 1 | SATA activity blink
198 * 2 | fix red on
199 * 3 | blink blue on=1 sec and blue off=1 sec
200 * 4 | blink red on=1 sec and red off=1 sec
201 * 5 | blink blue on=2.5 sec and red on=0.5 sec
202 * 6 | blink blue on=1 sec and red on=1 sec
203 * 7 | fix blue on
204 */
205static void init_leds(void)
206{
207 /* Enable the front blue LED */
208 cpld_gpio_bus_write(&cpld_gpio_bus, 0, 1);
209 cpld_gpio_bus_write(&cpld_gpio_bus, 1, 3);
210
211 /* Configure SATA LEDs to blink in relation with the SATA activity */
212 cpld_gpio_bus_write(&cpld_gpio_bus, 3, 1);
213 cpld_gpio_bus_write(&cpld_gpio_bus, 4, 1);
214 cpld_gpio_bus_write(&cpld_gpio_bus, 2, 3);
215}
216#else
217static void init_leds(void) {}
218#endif /* CONFIG_NET2BIG_V2 && CONFIG_KIRKWOOD_GPIO */
219
Simon Guinot72198a32011-11-21 19:25:46 +0530220int misc_init_r(void)
221{
Simon Guinot1dd67e62013-06-18 15:14:48 +0200222 init_fan();
Simon Guinota35cb4c2011-11-21 19:25:47 +0530223#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
Simon Glass64b723f2017-08-03 12:22:12 -0600224 if (!env_get("ethaddr")) {
Simon Guinot72198a32011-11-21 19:25:46 +0530225 uchar mac[6];
Simon Guinota35cb4c2011-11-21 19:25:47 +0530226 if (lacie_read_mac_address(mac) == 0)
Simon Glass8551d552017-08-03 12:22:11 -0600227 eth_env_set_enetaddr("ethaddr", mac);
Simon Guinot72198a32011-11-21 19:25:46 +0530228 }
Simon Guinota35cb4c2011-11-21 19:25:47 +0530229#endif
Simon Guinotbfbf8862013-06-18 15:14:50 +0200230 init_leds();
231
Simon Guinot72198a32011-11-21 19:25:46 +0530232 return 0;
233}
Simon Guinot1dd67e62013-06-18 15:14:48 +0200234#endif /* CONFIG_MISC_INIT_R */
Simon Guinot72198a32011-11-21 19:25:46 +0530235
Simon Guinota35cb4c2011-11-21 19:25:47 +0530236#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
Simon Guinot72198a32011-11-21 19:25:46 +0530237/* Configure and initialize PHY */
238void reset_phy(void)
239{
Simon Guinot0473b682012-06-05 13:16:00 +0000240 mv_phy_88e1116_init("egiga0", 8);
Simon Guinot72198a32011-11-21 19:25:46 +0530241}
Simon Guinota35cb4c2011-11-21 19:25:47 +0530242#endif
Simon Guinot72198a32011-11-21 19:25:46 +0530243
Simon Guinota35cb4c2011-11-21 19:25:47 +0530244#if defined(CONFIG_KIRKWOOD_GPIO)
Simon Guinot72198a32011-11-21 19:25:46 +0530245/* Return GPIO push button status */
246static int
247do_read_push_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
248{
249 return !kw_gpio_get_value(NET2BIG_V2_GPIO_PUSH_BUTTON);
250}
251
252U_BOOT_CMD(button, 1, 1, do_read_push_button,
253 "Return GPIO push button status 0=off 1=on", "");
Simon Guinota35cb4c2011-11-21 19:25:47 +0530254#endif