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