]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/LaCie/net2big_v2/net2big_v2.c
arm: Add explicit include of <asm/mach-types.h>
[people/ms/u-boot.git] / board / LaCie / net2big_v2 / net2big_v2.c
CommitLineData
5628fb75
SG
1/*
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 *
1a459660 9 * SPDX-License-Identifier: GPL-2.0+
5628fb75
SG
10 */
11
12#include <common.h>
5628fb75 13#include <command.h>
2af4d0f4 14#include <i2c.h>
c62db35d 15#include <asm/mach-types.h>
5628fb75 16#include <asm/arch/cpu.h>
3dc23f78 17#include <asm/arch/soc.h>
5628fb75
SG
18#include <asm/arch/mpp.h>
19#include <asm/arch/gpio.h>
77ea071f 20
5628fb75 21#include "net2big_v2.h"
77ea071f 22#include "../common/common.h"
7737c994 23#include "../common/cpld-gpio-bus.h"
5628fb75
SG
24
25DECLARE_GLOBAL_DATA_PTR;
26
27int board_early_init_f(void)
28{
29 /* GPIO configuration */
d5c5132f
SR
30 mvebu_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH,
31 NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH);
5628fb75
SG
32
33 /* Multi-Purpose Pins Functionality configuration */
9d86f0c3 34 static const u32 kwmpp_config[] = {
5628fb75
SG
35 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 */
7737c994 55 MPP29_GPIO, /* CPLD GPIO bus ALE */
5628fb75
SG
56 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 */
7737c994
SG
61 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) */
5628fb75
SG
67 0
68 };
69
84683638 70 kirkwood_mpp_conf(kwmpp_config, NULL);
5628fb75
SG
71
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 */
96c5f081 81 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
5628fb75
SG
82
83 return 0;
84}
85
77ea071f 86#if defined(CONFIG_MISC_INIT_R)
2af4d0f4
SG
87
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
7737c994
SG
137#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
5628fb75
SG
220int misc_init_r(void)
221{
2af4d0f4 222 init_fan();
77ea071f 223#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
5628fb75 224 if (!getenv("ethaddr")) {
5628fb75 225 uchar mac[6];
77ea071f
SG
226 if (lacie_read_mac_address(mac) == 0)
227 eth_setenv_enetaddr("ethaddr", mac);
5628fb75 228 }
77ea071f 229#endif
7737c994
SG
230 init_leds();
231
5628fb75
SG
232 return 0;
233}
2af4d0f4 234#endif /* CONFIG_MISC_INIT_R */
5628fb75 235
77ea071f 236#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
5628fb75
SG
237/* Configure and initialize PHY */
238void reset_phy(void)
239{
c59c0857 240 mv_phy_88e1116_init("egiga0", 8);
5628fb75 241}
77ea071f 242#endif
5628fb75 243
77ea071f 244#if defined(CONFIG_KIRKWOOD_GPIO)
5628fb75
SG
245/* 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", "");
77ea071f 254#endif