Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 13 | #include <command.h> |
Simon Guinot | 2af4d0f | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 14 | #include <i2c.h> |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 15 | #include <asm/arch/cpu.h> |
Stefan Roese | 3dc23f7 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 16 | #include <asm/arch/soc.h> |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 17 | #include <asm/arch/mpp.h> |
| 18 | #include <asm/arch/gpio.h> |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 19 | |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 20 | #include "net2big_v2.h" |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 21 | #include "../common/common.h" |
Simon Guinot | 7737c99 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 22 | #include "../common/cpld-gpio-bus.h" |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | int board_early_init_f(void) |
| 27 | { |
| 28 | /* GPIO configuration */ |
Stefan Roese | d5c5132 | 2014-10-22 12:13:11 +0200 | [diff] [blame] | 29 | mvebu_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH, |
| 30 | NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH); |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 31 | |
| 32 | /* Multi-Purpose Pins Functionality configuration */ |
Albert ARIBAUD | 9d86f0c | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 33 | static const u32 kwmpp_config[] = { |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 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 */ |
Simon Guinot | 7737c99 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 54 | MPP29_GPIO, /* CPLD GPIO bus ALE */ |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 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 */ |
Simon Guinot | 7737c99 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 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) */ |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 66 | 0 |
| 67 | }; |
| 68 | |
Valentin Longchamp | 8468363 | 2012-06-01 01:31:00 +0000 | [diff] [blame] | 69 | kirkwood_mpp_conf(kwmpp_config, NULL); |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | int board_init(void) |
| 75 | { |
| 76 | /* Machine number */ |
| 77 | gd->bd->bi_arch_number = MACH_TYPE_NET2BIG_V2; |
| 78 | |
| 79 | /* Boot parameters address */ |
Stefan Roese | 96c5f08 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 80 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 85 | #if defined(CONFIG_MISC_INIT_R) |
Simon Guinot | 2af4d0f | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 86 | |
| 87 | #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR) |
| 88 | /* |
| 89 | * Start I2C fan (GMT G762 controller) |
| 90 | */ |
| 91 | static 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; |
| 128 | err: |
| 129 | printf("Error: failed to start I2C fan @%02x\n", |
| 130 | CONFIG_SYS_I2C_G762_ADDR); |
| 131 | } |
| 132 | #else |
| 133 | static void init_fan(void) {} |
| 134 | #endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */ |
| 135 | |
Simon Guinot | 7737c99 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 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 | */ |
| 144 | static unsigned cpld_gpio_bus_addr[] = { 47, 48, 49 }; |
| 145 | static unsigned cpld_gpio_bus_data[] = { 44, 45, 46 }; |
| 146 | |
| 147 | static 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 | */ |
| 204 | static 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 |
| 216 | static void init_leds(void) {} |
| 217 | #endif /* CONFIG_NET2BIG_V2 && CONFIG_KIRKWOOD_GPIO */ |
| 218 | |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 219 | int misc_init_r(void) |
| 220 | { |
Simon Guinot | 2af4d0f | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 221 | init_fan(); |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 222 | #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR) |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 223 | if (!getenv("ethaddr")) { |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 224 | uchar mac[6]; |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 225 | if (lacie_read_mac_address(mac) == 0) |
| 226 | eth_setenv_enetaddr("ethaddr", mac); |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 227 | } |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 228 | #endif |
Simon Guinot | 7737c99 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 229 | init_leds(); |
| 230 | |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 231 | return 0; |
| 232 | } |
Simon Guinot | 2af4d0f | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 233 | #endif /* CONFIG_MISC_INIT_R */ |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 234 | |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 235 | #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R) |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 236 | /* Configure and initialize PHY */ |
| 237 | void reset_phy(void) |
| 238 | { |
Simon Guinot | c59c085 | 2012-06-05 13:16:00 +0000 | [diff] [blame] | 239 | mv_phy_88e1116_init("egiga0", 8); |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 240 | } |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 241 | #endif |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 242 | |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 243 | #if defined(CONFIG_KIRKWOOD_GPIO) |
Simon Guinot | 5628fb7 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 244 | /* Return GPIO push button status */ |
| 245 | static int |
| 246 | do_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 | |
| 251 | U_BOOT_CMD(button, 1, 1, do_read_push_button, |
| 252 | "Return GPIO push button status 0=off 1=on", ""); |
Simon Guinot | 77ea071 | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 253 | #endif |