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