Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 2 | /* |
| 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 Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 12 | #include <command.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame^] | 13 | #include <env.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 14 | #include <environment.h> |
Simon Guinot | 1dd67e6 | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 15 | #include <i2c.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 16 | #include <asm/mach-types.h> |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 17 | #include <asm/arch/cpu.h> |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 18 | #include <asm/arch/soc.h> |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 19 | #include <asm/arch/mpp.h> |
| 20 | #include <asm/arch/gpio.h> |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 21 | |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 22 | #include "net2big_v2.h" |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 23 | #include "../common/common.h" |
Simon Guinot | bfbf886 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 24 | #include "../common/cpld-gpio-bus.h" |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | int board_early_init_f(void) |
| 29 | { |
| 30 | /* GPIO configuration */ |
Stefan Roese | c50ab39 | 2014-10-22 12:13:11 +0200 | [diff] [blame] | 31 | mvebu_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH, |
| 32 | NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH); |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 33 | |
| 34 | /* Multi-Purpose Pins Functionality configuration */ |
Albert ARIBAUD | 4d42431 | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 35 | static const u32 kwmpp_config[] = { |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 36 | MPP0_SPI_SCn, |
| 37 | MPP1_SPI_MOSI, |
| 38 | MPP2_SPI_SCK, |
| 39 | MPP3_SPI_MISO, |
| 40 | MPP6_SYSRST_OUTn, |
| 41 | MPP7_GPO, /* Request power-off */ |
| 42 | MPP8_TW_SDA, |
| 43 | MPP9_TW_SCK, |
| 44 | MPP10_UART0_TXD, |
| 45 | MPP11_UART0_RXD, |
| 46 | MPP13_GPIO, /* Rear power switch (on|auto) */ |
| 47 | MPP14_GPIO, /* USB fuse alarm */ |
| 48 | MPP15_GPIO, /* Rear power switch (auto|off) */ |
| 49 | MPP16_GPIO, /* SATA HDD1 power */ |
| 50 | MPP17_GPIO, /* SATA HDD2 power */ |
| 51 | MPP20_SATA1_ACTn, |
| 52 | MPP21_SATA0_ACTn, |
| 53 | MPP24_GPIO, /* USB mode select */ |
| 54 | MPP26_GPIO, /* USB device vbus */ |
| 55 | MPP28_GPIO, /* USB enable host vbus */ |
Simon Guinot | bfbf886 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 56 | MPP29_GPIO, /* CPLD GPIO bus ALE */ |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 57 | MPP34_GPIO, /* Rear Push button 0=on 1=off */ |
| 58 | MPP35_GPIO, /* Inhibit switch power-off */ |
| 59 | MPP36_GPIO, /* SATA HDD1 presence */ |
| 60 | MPP37_GPIO, /* SATA HDD2 presence */ |
| 61 | MPP40_GPIO, /* eSATA presence */ |
Simon Guinot | bfbf886 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 62 | MPP44_GPIO, /* CPLD GPIO bus (data 0) */ |
| 63 | MPP45_GPIO, /* CPLD GPIO bus (data 1) */ |
| 64 | MPP46_GPIO, /* CPLD GPIO bus (data 2) */ |
| 65 | MPP47_GPIO, /* CPLD GPIO bus (addr 0) */ |
| 66 | MPP48_GPIO, /* CPLD GPIO bus (addr 1) */ |
| 67 | MPP49_GPIO, /* CPLD GPIO bus (addr 2) */ |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 68 | 0 |
| 69 | }; |
| 70 | |
Valentin Longchamp | 7d0d502 | 2012-06-01 01:31:00 +0000 | [diff] [blame] | 71 | kirkwood_mpp_conf(kwmpp_config, NULL); |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | int board_init(void) |
| 77 | { |
| 78 | /* Machine number */ |
| 79 | gd->bd->bi_arch_number = MACH_TYPE_NET2BIG_V2; |
| 80 | |
| 81 | /* Boot parameters address */ |
Stefan Roese | 0b74175 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 82 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 87 | #if defined(CONFIG_MISC_INIT_R) |
Simon Guinot | 1dd67e6 | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 88 | |
| 89 | #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR) |
| 90 | /* |
| 91 | * Start I2C fan (GMT G762 controller) |
| 92 | */ |
| 93 | static void init_fan(void) |
| 94 | { |
| 95 | u8 data; |
| 96 | |
| 97 | i2c_set_bus_num(0); |
| 98 | |
| 99 | /* Enable open-loop and PWM modes */ |
| 100 | data = 0x20; |
| 101 | if (i2c_write(CONFIG_SYS_I2C_G762_ADDR, |
| 102 | G762_REG_FAN_CMD1, 1, &data, 1) != 0) |
| 103 | goto err; |
| 104 | data = 0; |
| 105 | if (i2c_write(CONFIG_SYS_I2C_G762_ADDR, |
| 106 | G762_REG_SET_CNT, 1, &data, 1) != 0) |
| 107 | goto err; |
| 108 | /* |
| 109 | * RPM to PWM (set_out register) fan speed conversion array: |
| 110 | * 0 0x00 |
| 111 | * 1500 0x04 |
| 112 | * 2800 0x08 |
| 113 | * 3400 0x0C |
| 114 | * 3700 0x10 |
| 115 | * 4400 0x20 |
| 116 | * 4700 0x30 |
| 117 | * 4800 0x50 |
| 118 | * 5200 0x80 |
| 119 | * 5400 0xC0 |
| 120 | * 5500 0xFF |
| 121 | * |
| 122 | * Start fan at low speed (2800 RPM): |
| 123 | */ |
| 124 | data = 0x08; |
| 125 | if (i2c_write(CONFIG_SYS_I2C_G762_ADDR, |
| 126 | G762_REG_SET_OUT, 1, &data, 1) != 0) |
| 127 | goto err; |
| 128 | |
| 129 | return; |
| 130 | err: |
| 131 | printf("Error: failed to start I2C fan @%02x\n", |
| 132 | CONFIG_SYS_I2C_G762_ADDR); |
| 133 | } |
| 134 | #else |
| 135 | static void init_fan(void) {} |
| 136 | #endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */ |
| 137 | |
Simon Guinot | bfbf886 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 138 | #if defined(CONFIG_NET2BIG_V2) && defined(CONFIG_KIRKWOOD_GPIO) |
| 139 | /* |
| 140 | * CPLD GPIO bus: |
| 141 | * |
| 142 | * - address register : bit [0-2] -> GPIO [47-49] |
| 143 | * - data register : bit [0-2] -> GPIO [44-46] |
| 144 | * - enable register : GPIO 29 |
| 145 | */ |
| 146 | static unsigned cpld_gpio_bus_addr[] = { 47, 48, 49 }; |
| 147 | static unsigned cpld_gpio_bus_data[] = { 44, 45, 46 }; |
| 148 | |
| 149 | static struct cpld_gpio_bus cpld_gpio_bus = { |
| 150 | .addr = cpld_gpio_bus_addr, |
| 151 | .num_addr = ARRAY_SIZE(cpld_gpio_bus_addr), |
| 152 | .data = cpld_gpio_bus_data, |
| 153 | .num_data = ARRAY_SIZE(cpld_gpio_bus_data), |
| 154 | .enable = 29, |
| 155 | }; |
| 156 | |
| 157 | /* |
| 158 | * LEDs configuration: |
| 159 | * |
| 160 | * The LEDs are controlled by a CPLD and can be configured through |
| 161 | * the CPLD GPIO bus. |
| 162 | * |
| 163 | * Address register selection: |
| 164 | * |
| 165 | * addr | register |
| 166 | * ---------------------------- |
| 167 | * 0 | front LED |
| 168 | * 1 | front LED brightness |
| 169 | * 2 | SATA LED brightness |
| 170 | * 3 | SATA0 LED |
| 171 | * 4 | SATA1 LED |
| 172 | * 5 | SATA2 LED |
| 173 | * 6 | SATA3 LED |
| 174 | * 7 | SATA4 LED |
| 175 | * |
| 176 | * Data register configuration: |
| 177 | * |
| 178 | * data | LED brightness |
| 179 | * ------------------------------------------------- |
| 180 | * 0 | min (off) |
| 181 | * - | - |
| 182 | * 7 | max |
| 183 | * |
| 184 | * data | front LED mode |
| 185 | * ------------------------------------------------- |
| 186 | * 0 | fix off |
| 187 | * 1 | fix blue on |
| 188 | * 2 | fix red on |
| 189 | * 3 | blink blue on=1 sec and blue off=1 sec |
| 190 | * 4 | blink red on=1 sec and red off=1 sec |
| 191 | * 5 | blink blue on=2.5 sec and red on=0.5 sec |
| 192 | * 6 | blink blue on=1 sec and red on=1 sec |
| 193 | * 7 | blink blue on=0.5 sec and blue off=2.5 sec |
| 194 | * |
| 195 | * data | SATA LED mode |
| 196 | * ------------------------------------------------- |
| 197 | * 0 | fix off |
| 198 | * 1 | SATA activity blink |
| 199 | * 2 | fix red on |
| 200 | * 3 | blink blue on=1 sec and blue off=1 sec |
| 201 | * 4 | blink red on=1 sec and red off=1 sec |
| 202 | * 5 | blink blue on=2.5 sec and red on=0.5 sec |
| 203 | * 6 | blink blue on=1 sec and red on=1 sec |
| 204 | * 7 | fix blue on |
| 205 | */ |
| 206 | static void init_leds(void) |
| 207 | { |
| 208 | /* Enable the front blue LED */ |
| 209 | cpld_gpio_bus_write(&cpld_gpio_bus, 0, 1); |
| 210 | cpld_gpio_bus_write(&cpld_gpio_bus, 1, 3); |
| 211 | |
| 212 | /* Configure SATA LEDs to blink in relation with the SATA activity */ |
| 213 | cpld_gpio_bus_write(&cpld_gpio_bus, 3, 1); |
| 214 | cpld_gpio_bus_write(&cpld_gpio_bus, 4, 1); |
| 215 | cpld_gpio_bus_write(&cpld_gpio_bus, 2, 3); |
| 216 | } |
| 217 | #else |
| 218 | static void init_leds(void) {} |
| 219 | #endif /* CONFIG_NET2BIG_V2 && CONFIG_KIRKWOOD_GPIO */ |
| 220 | |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 221 | int misc_init_r(void) |
| 222 | { |
Simon Guinot | 1dd67e6 | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 223 | init_fan(); |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 224 | #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR) |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 225 | if (!env_get("ethaddr")) { |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 226 | uchar mac[6]; |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 227 | if (lacie_read_mac_address(mac) == 0) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 228 | eth_env_set_enetaddr("ethaddr", mac); |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 229 | } |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 230 | #endif |
Simon Guinot | bfbf886 | 2013-06-18 15:14:50 +0200 | [diff] [blame] | 231 | init_leds(); |
| 232 | |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 233 | return 0; |
| 234 | } |
Simon Guinot | 1dd67e6 | 2013-06-18 15:14:48 +0200 | [diff] [blame] | 235 | #endif /* CONFIG_MISC_INIT_R */ |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 236 | |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 237 | #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R) |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 238 | /* Configure and initialize PHY */ |
| 239 | void reset_phy(void) |
| 240 | { |
Simon Guinot | 0473b68 | 2012-06-05 13:16:00 +0000 | [diff] [blame] | 241 | mv_phy_88e1116_init("egiga0", 8); |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 242 | } |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 243 | #endif |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 244 | |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 245 | #if defined(CONFIG_KIRKWOOD_GPIO) |
Simon Guinot | 72198a3 | 2011-11-21 19:25:46 +0530 | [diff] [blame] | 246 | /* Return GPIO push button status */ |
| 247 | static int |
| 248 | do_read_push_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 249 | { |
| 250 | return !kw_gpio_get_value(NET2BIG_V2_GPIO_PUSH_BUTTON); |
| 251 | } |
| 252 | |
| 253 | U_BOOT_CMD(button, 1, 1, do_read_push_button, |
| 254 | "Return GPIO push button status 0=off 1=on", ""); |
Simon Guinot | a35cb4c | 2011-11-21 19:25:47 +0530 | [diff] [blame] | 255 | #endif |