blob: e94c9a6dce96b8ba901e8a802682087bf446e554 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Guinot72198a32011-11-21 19:25:46 +05302/*
3 * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com>
4 *
5 * Based on Kirkwood support:
6 * (C) Copyright 2009
7 * Marvell Semiconductor <www.marvell.com>
8 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
Simon Guinot72198a32011-11-21 19:25:46 +05309 */
10
11#include <common.h>
Simon Guinot72198a32011-11-21 19:25:46 +053012#include <command.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060013#include <env.h>
Simon Guinot1dd67e62013-06-18 15:14:48 +020014#include <i2c.h>
Simon Glass97589732020-05-10 11:40:02 -060015#include <init.h>
Simon Glass0c364412019-12-28 10:44:48 -070016#include <net.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060017#include <asm/mach-types.h>
Simon Guinot72198a32011-11-21 19:25:46 +053018#include <asm/arch/cpu.h>
Stefan Roesec2437842014-10-22 12:13:06 +020019#include <asm/arch/soc.h>
Simon Guinot72198a32011-11-21 19:25:46 +053020#include <asm/arch/mpp.h>
21#include <asm/arch/gpio.h>
Simon Guinota35cb4c2011-11-21 19:25:47 +053022
Simon Guinot72198a32011-11-21 19:25:46 +053023#include "net2big_v2.h"
Simon Guinota35cb4c2011-11-21 19:25:47 +053024#include "../common/common.h"
Simon Guinotbfbf8862013-06-18 15:14:50 +020025#include "../common/cpld-gpio-bus.h"
Simon Guinot72198a32011-11-21 19:25:46 +053026
27DECLARE_GLOBAL_DATA_PTR;
28
29int board_early_init_f(void)
30{
31 /* GPIO configuration */
Stefan Roesec50ab392014-10-22 12:13:11 +020032 mvebu_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH,
33 NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH);
Simon Guinot72198a32011-11-21 19:25:46 +053034
35 /* Multi-Purpose Pins Functionality configuration */
Albert ARIBAUD4d424312012-11-26 11:27:36 +000036 static const u32 kwmpp_config[] = {
Simon Guinot72198a32011-11-21 19:25:46 +053037 MPP0_SPI_SCn,
38 MPP1_SPI_MOSI,
39 MPP2_SPI_SCK,
40 MPP3_SPI_MISO,
41 MPP6_SYSRST_OUTn,
42 MPP7_GPO, /* Request power-off */
43 MPP8_TW_SDA,
44 MPP9_TW_SCK,
45 MPP10_UART0_TXD,
46 MPP11_UART0_RXD,
47 MPP13_GPIO, /* Rear power switch (on|auto) */
48 MPP14_GPIO, /* USB fuse alarm */
49 MPP15_GPIO, /* Rear power switch (auto|off) */
50 MPP16_GPIO, /* SATA HDD1 power */
51 MPP17_GPIO, /* SATA HDD2 power */
52 MPP20_SATA1_ACTn,
53 MPP21_SATA0_ACTn,
54 MPP24_GPIO, /* USB mode select */
55 MPP26_GPIO, /* USB device vbus */
56 MPP28_GPIO, /* USB enable host vbus */
Simon Guinotbfbf8862013-06-18 15:14:50 +020057 MPP29_GPIO, /* CPLD GPIO bus ALE */
Simon Guinot72198a32011-11-21 19:25:46 +053058 MPP34_GPIO, /* Rear Push button 0=on 1=off */
59 MPP35_GPIO, /* Inhibit switch power-off */
60 MPP36_GPIO, /* SATA HDD1 presence */
61 MPP37_GPIO, /* SATA HDD2 presence */
62 MPP40_GPIO, /* eSATA presence */
Simon Guinotbfbf8862013-06-18 15:14:50 +020063 MPP44_GPIO, /* CPLD GPIO bus (data 0) */
64 MPP45_GPIO, /* CPLD GPIO bus (data 1) */
65 MPP46_GPIO, /* CPLD GPIO bus (data 2) */
66 MPP47_GPIO, /* CPLD GPIO bus (addr 0) */
67 MPP48_GPIO, /* CPLD GPIO bus (addr 1) */
68 MPP49_GPIO, /* CPLD GPIO bus (addr 2) */
Simon Guinot72198a32011-11-21 19:25:46 +053069 0
70 };
71
Valentin Longchamp7d0d5022012-06-01 01:31:00 +000072 kirkwood_mpp_conf(kwmpp_config, NULL);
Simon Guinot72198a32011-11-21 19:25:46 +053073
74 return 0;
75}
76
77int board_init(void)
78{
79 /* Machine number */
80 gd->bd->bi_arch_number = MACH_TYPE_NET2BIG_V2;
81
82 /* Boot parameters address */
Stefan Roese0b741752014-10-22 12:13:13 +020083 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
Simon Guinot72198a32011-11-21 19:25:46 +053084
85 return 0;
86}
87
Simon Guinota35cb4c2011-11-21 19:25:47 +053088#if defined(CONFIG_MISC_INIT_R)
Simon Guinot1dd67e62013-06-18 15:14:48 +020089
90#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR)
91/*
92 * Start I2C fan (GMT G762 controller)
93 */
94static void init_fan(void)
95{
96 u8 data;
97
98 i2c_set_bus_num(0);
99
100 /* Enable open-loop and PWM modes */
101 data = 0x20;
102 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
103 G762_REG_FAN_CMD1, 1, &data, 1) != 0)
104 goto err;
105 data = 0;
106 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
107 G762_REG_SET_CNT, 1, &data, 1) != 0)
108 goto err;
109 /*
110 * RPM to PWM (set_out register) fan speed conversion array:
111 * 0 0x00
112 * 1500 0x04
113 * 2800 0x08
114 * 3400 0x0C
115 * 3700 0x10
116 * 4400 0x20
117 * 4700 0x30
118 * 4800 0x50
119 * 5200 0x80
120 * 5400 0xC0
121 * 5500 0xFF
122 *
123 * Start fan at low speed (2800 RPM):
124 */
125 data = 0x08;
126 if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
127 G762_REG_SET_OUT, 1, &data, 1) != 0)
128 goto err;
129
130 return;
131err:
132 printf("Error: failed to start I2C fan @%02x\n",
133 CONFIG_SYS_I2C_G762_ADDR);
134}
135#else
136static void init_fan(void) {}
137#endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */
138
Simon Guinotbfbf8862013-06-18 15:14:50 +0200139#if defined(CONFIG_NET2BIG_V2) && defined(CONFIG_KIRKWOOD_GPIO)
140/*
141 * CPLD GPIO bus:
142 *
143 * - address register : bit [0-2] -> GPIO [47-49]
144 * - data register : bit [0-2] -> GPIO [44-46]
145 * - enable register : GPIO 29
146 */
147static unsigned cpld_gpio_bus_addr[] = { 47, 48, 49 };
148static unsigned cpld_gpio_bus_data[] = { 44, 45, 46 };
149
150static struct cpld_gpio_bus cpld_gpio_bus = {
151 .addr = cpld_gpio_bus_addr,
152 .num_addr = ARRAY_SIZE(cpld_gpio_bus_addr),
153 .data = cpld_gpio_bus_data,
154 .num_data = ARRAY_SIZE(cpld_gpio_bus_data),
155 .enable = 29,
156};
157
158/*
159 * LEDs configuration:
160 *
161 * The LEDs are controlled by a CPLD and can be configured through
162 * the CPLD GPIO bus.
163 *
164 * Address register selection:
165 *
166 * addr | register
167 * ----------------------------
168 * 0 | front LED
169 * 1 | front LED brightness
170 * 2 | SATA LED brightness
171 * 3 | SATA0 LED
172 * 4 | SATA1 LED
173 * 5 | SATA2 LED
174 * 6 | SATA3 LED
175 * 7 | SATA4 LED
176 *
177 * Data register configuration:
178 *
179 * data | LED brightness
180 * -------------------------------------------------
181 * 0 | min (off)
182 * - | -
183 * 7 | max
184 *
185 * data | front LED mode
186 * -------------------------------------------------
187 * 0 | fix off
188 * 1 | fix blue on
189 * 2 | fix red on
190 * 3 | blink blue on=1 sec and blue off=1 sec
191 * 4 | blink red on=1 sec and red off=1 sec
192 * 5 | blink blue on=2.5 sec and red on=0.5 sec
193 * 6 | blink blue on=1 sec and red on=1 sec
194 * 7 | blink blue on=0.5 sec and blue off=2.5 sec
195 *
196 * data | SATA LED mode
197 * -------------------------------------------------
198 * 0 | fix off
199 * 1 | SATA activity blink
200 * 2 | fix red on
201 * 3 | blink blue on=1 sec and blue off=1 sec
202 * 4 | blink red on=1 sec and red off=1 sec
203 * 5 | blink blue on=2.5 sec and red on=0.5 sec
204 * 6 | blink blue on=1 sec and red on=1 sec
205 * 7 | fix blue on
206 */
207static void init_leds(void)
208{
209 /* Enable the front blue LED */
210 cpld_gpio_bus_write(&cpld_gpio_bus, 0, 1);
211 cpld_gpio_bus_write(&cpld_gpio_bus, 1, 3);
212
213 /* Configure SATA LEDs to blink in relation with the SATA activity */
214 cpld_gpio_bus_write(&cpld_gpio_bus, 3, 1);
215 cpld_gpio_bus_write(&cpld_gpio_bus, 4, 1);
216 cpld_gpio_bus_write(&cpld_gpio_bus, 2, 3);
217}
218#else
219static void init_leds(void) {}
220#endif /* CONFIG_NET2BIG_V2 && CONFIG_KIRKWOOD_GPIO */
221
Simon Guinot72198a32011-11-21 19:25:46 +0530222int misc_init_r(void)
223{
Simon Guinot1dd67e62013-06-18 15:14:48 +0200224 init_fan();
Simon Guinota35cb4c2011-11-21 19:25:47 +0530225#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
Simon Glass64b723f2017-08-03 12:22:12 -0600226 if (!env_get("ethaddr")) {
Simon Guinot72198a32011-11-21 19:25:46 +0530227 uchar mac[6];
Simon Guinota35cb4c2011-11-21 19:25:47 +0530228 if (lacie_read_mac_address(mac) == 0)
Simon Glass8551d552017-08-03 12:22:11 -0600229 eth_env_set_enetaddr("ethaddr", mac);
Simon Guinot72198a32011-11-21 19:25:46 +0530230 }
Simon Guinota35cb4c2011-11-21 19:25:47 +0530231#endif
Simon Guinotbfbf8862013-06-18 15:14:50 +0200232 init_leds();
233
Simon Guinot72198a32011-11-21 19:25:46 +0530234 return 0;
235}
Simon Guinot1dd67e62013-06-18 15:14:48 +0200236#endif /* CONFIG_MISC_INIT_R */
Simon Guinot72198a32011-11-21 19:25:46 +0530237
Simon Guinota35cb4c2011-11-21 19:25:47 +0530238#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
Simon Guinot72198a32011-11-21 19:25:46 +0530239/* Configure and initialize PHY */
240void reset_phy(void)
241{
Simon Guinotab07aa22020-06-28 19:00:31 +0200242 mv_phy_88e1116_init("ethernet-controller@72000", 8);
Simon Guinot72198a32011-11-21 19:25:46 +0530243}
Simon Guinota35cb4c2011-11-21 19:25:47 +0530244#endif
Simon Guinot72198a32011-11-21 19:25:46 +0530245
Simon Guinota35cb4c2011-11-21 19:25:47 +0530246#if defined(CONFIG_KIRKWOOD_GPIO)
Simon Guinot72198a32011-11-21 19:25:46 +0530247/* Return GPIO push button status */
248static int
Simon Glassed38aef2020-05-10 11:40:03 -0600249do_read_push_button(struct cmd_tbl *cmdtp, int flag, int argc,
250 char *const argv[])
Simon Guinot72198a32011-11-21 19:25:46 +0530251{
252 return !kw_gpio_get_value(NET2BIG_V2_GPIO_PUSH_BUTTON);
253}
254
255U_BOOT_CMD(button, 1, 1, do_read_push_button,
256 "Return GPIO push button status 0=off 1=on", "");
Simon Guinota35cb4c2011-11-21 19:25:47 +0530257#endif