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