Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Marvell Semiconductor <www.marvell.com> |
| 5 | * Prafulla Wadaskar <prafulla@marvell.com> |
| 6 | * |
| 7 | * (C) Copyright 2009 |
| 8 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 9 | * |
| 10 | * (C) Copyright 2010 |
| 11 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 15 | #include <env.h> |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 16 | #include <i2c.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 17 | #include <init.h> |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 18 | #include <nand.h> |
Simon Glass | 0c36441 | 2019-12-28 10:44:48 -0700 | [diff] [blame] | 19 | #include <net.h> |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 20 | #include <netdev.h> |
| 21 | #include <miiphy.h> |
Valentin Longchamp | 96957ef | 2012-06-13 03:01:03 +0000 | [diff] [blame] | 22 | #include <spi.h> |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 23 | #include <asm/io.h> |
Lei Wen | 298ae91 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 24 | #include <asm/arch/cpu.h> |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 25 | #include <asm/arch/soc.h> |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 26 | #include <asm/arch/mpp.h> |
| 27 | |
| 28 | #include "../common/common.h" |
| 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 32 | /* |
| 33 | * BOCO FPGA definitions |
| 34 | */ |
| 35 | #define BOCO 0x10 |
| 36 | #define REG_CTRL_H 0x02 |
| 37 | #define MASK_WRL_UNITRUN 0x01 |
| 38 | #define MASK_RBX_PGY_PRESENT 0x40 |
| 39 | #define REG_IRQ_CIRQ2 0x2d |
| 40 | #define MASK_RBI_DEFECT_16 0x01 |
| 41 | |
Tobias Müller | b0cab2d | 2015-11-13 15:01:15 +0100 | [diff] [blame] | 42 | /* |
| 43 | * PHY registers definitions |
| 44 | */ |
| 45 | #define PHY_MARVELL_OUI 0x5043 |
| 46 | #define PHY_MARVELL_88E1118_MODEL 0x0022 |
| 47 | #define PHY_MARVELL_88E1118R_MODEL 0x0024 |
| 48 | |
| 49 | #define PHY_MARVELL_PAGE_REG 0x0016 |
| 50 | #define PHY_MARVELL_DEFAULT_PAGE 0x0000 |
| 51 | |
| 52 | #define PHY_MARVELL_88E1118R_LED_CTRL_PAGE 0x0003 |
| 53 | #define PHY_MARVELL_88E1118R_LED_CTRL_REG 0x0010 |
| 54 | |
| 55 | #define PHY_MARVELL_88E1118R_LED_CTRL_RESERVED 0x1000 |
| 56 | #define PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB (0x7<<0) |
| 57 | #define PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT (0x3<<4) |
| 58 | #define PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK (0x0<<8) |
| 59 | |
Holger Brunck | 43cf329 | 2015-11-13 15:01:16 +0100 | [diff] [blame] | 60 | /* I/O pin to erase flash RGPP09 = MPP43 */ |
| 61 | #define KM_FLASH_ERASE_ENABLE 43 |
| 62 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 63 | /* Multi-Purpose Pins Functionality configuration */ |
Albert ARIBAUD | 4d42431 | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 64 | static const u32 kwmpp_config[] = { |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 65 | MPP0_NF_IO2, |
| 66 | MPP1_NF_IO3, |
| 67 | MPP2_NF_IO4, |
| 68 | MPP3_NF_IO5, |
| 69 | MPP4_NF_IO6, |
| 70 | MPP5_NF_IO7, |
| 71 | MPP6_SYSRST_OUTn, |
| 72 | MPP7_PEX_RST_OUTn, |
Heiko Schocher | 479a4cf | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 73 | #if defined(CONFIG_SYS_I2C_SOFT) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 74 | MPP8_GPIO, /* SDA */ |
| 75 | MPP9_GPIO, /* SCL */ |
| 76 | #endif |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 77 | MPP10_UART0_TXD, |
| 78 | MPP11_UART0_RXD, |
| 79 | MPP12_GPO, /* Reserved */ |
| 80 | MPP13_UART1_TXD, |
| 81 | MPP14_UART1_RXD, |
| 82 | MPP15_GPIO, /* Not used */ |
| 83 | MPP16_GPIO, /* Not used */ |
| 84 | MPP17_GPIO, /* Reserved */ |
| 85 | MPP18_NF_IO0, |
| 86 | MPP19_NF_IO1, |
| 87 | MPP20_GPIO, |
| 88 | MPP21_GPIO, |
| 89 | MPP22_GPIO, |
| 90 | MPP23_GPIO, |
| 91 | MPP24_GPIO, |
| 92 | MPP25_GPIO, |
| 93 | MPP26_GPIO, |
| 94 | MPP27_GPIO, |
| 95 | MPP28_GPIO, |
| 96 | MPP29_GPIO, |
| 97 | MPP30_GPIO, |
| 98 | MPP31_GPIO, |
| 99 | MPP32_GPIO, |
| 100 | MPP33_GPIO, |
| 101 | MPP34_GPIO, /* CDL1 (input) */ |
| 102 | MPP35_GPIO, /* CDL2 (input) */ |
| 103 | MPP36_GPIO, /* MAIN_IRQ (input) */ |
| 104 | MPP37_GPIO, /* BOARD_LED */ |
| 105 | MPP38_GPIO, /* Piggy3 LED[1] */ |
| 106 | MPP39_GPIO, /* Piggy3 LED[2] */ |
| 107 | MPP40_GPIO, /* Piggy3 LED[3] */ |
| 108 | MPP41_GPIO, /* Piggy3 LED[4] */ |
| 109 | MPP42_GPIO, /* Piggy3 LED[5] */ |
| 110 | MPP43_GPIO, /* Piggy3 LED[6] */ |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 111 | MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */ |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 112 | MPP45_GPIO, /* Piggy3 LED[8] */ |
| 113 | MPP46_GPIO, /* Reserved */ |
| 114 | MPP47_GPIO, /* Reserved */ |
| 115 | MPP48_GPIO, /* Reserved */ |
| 116 | MPP49_GPIO, /* SW_INTOUTn */ |
| 117 | 0 |
| 118 | }; |
| 119 | |
Valentin Longchamp | aea4bb5 | 2015-02-10 17:10:14 +0100 | [diff] [blame] | 120 | static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN]; |
| 121 | |
Holger Brunck | d896d0d | 2012-07-05 05:05:03 +0000 | [diff] [blame] | 122 | #if (defined(CONFIG_KM_PIGGY4_88E6061)|defined(CONFIG_KM_PIGGY4_88E6352)) |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 123 | /* |
Holger Brunck | 2ef4295 | 2012-07-05 05:37:46 +0000 | [diff] [blame] | 124 | * All boards with PIGGY4 connected via a simple switch have ethernet always |
| 125 | * present. |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 126 | */ |
| 127 | int ethernet_present(void) |
| 128 | { |
| 129 | return 1; |
| 130 | } |
| 131 | #else |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 132 | int ethernet_present(void) |
| 133 | { |
| 134 | uchar buf; |
| 135 | int ret = 0; |
| 136 | |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 137 | if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) { |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 138 | printf("%s: Error reading Boco\n", __func__); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 139 | return -1; |
| 140 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 141 | if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 142 | ret = 1; |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 143 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 144 | return ret; |
| 145 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 146 | #endif |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 147 | |
Holger Brunck | 03ab286 | 2013-05-06 15:04:51 +0200 | [diff] [blame] | 148 | static int initialize_unit_leds(void) |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 149 | { |
| 150 | /* |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 151 | * Init the unit LEDs per default they all are |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 152 | * ok apart from bootstat |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 153 | */ |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 154 | uchar buf; |
| 155 | |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 156 | if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) { |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 157 | printf("%s: Error reading Boco\n", __func__); |
| 158 | return -1; |
| 159 | } |
Holger Brunck | 4de3cdd | 2011-05-31 02:12:52 +0000 | [diff] [blame] | 160 | buf |= MASK_WRL_UNITRUN; |
| 161 | if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) { |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 162 | printf("%s: Error writing Boco\n", __func__); |
| 163 | return -1; |
| 164 | } |
| 165 | return 0; |
| 166 | } |
| 167 | |
Holger Brunck | 03ab286 | 2013-05-06 15:04:51 +0200 | [diff] [blame] | 168 | static void set_bootcount_addr(void) |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 169 | { |
| 170 | uchar buf[32]; |
| 171 | unsigned int bootcountaddr; |
| 172 | bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR; |
| 173 | sprintf((char *)buf, "0x%x", bootcountaddr); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 174 | env_set("bootcountaddr", (char *)buf); |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 175 | } |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 176 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 177 | int misc_init_r(void) |
| 178 | { |
Holger Brunck | 0340b6a | 2019-11-25 17:24:14 +0100 | [diff] [blame] | 179 | ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN, |
| 180 | CONFIG_PIGGY_MAC_ADDRESS_OFFSET); |
Valentin Longchamp | aea4bb5 | 2015-02-10 17:10:14 +0100 | [diff] [blame] | 181 | |
Heiko Schocher | e4533af | 2011-03-08 10:53:51 +0100 | [diff] [blame] | 182 | initialize_unit_leds(); |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 183 | set_km_env(); |
Valentin Longchamp | 184907a | 2011-05-31 02:12:47 +0000 | [diff] [blame] | 184 | set_bootcount_addr(); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | |
Heiko Schocher | 3ebd02b | 2010-10-20 19:33:26 +0530 | [diff] [blame] | 188 | int board_early_init_f(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 189 | { |
Heiko Schocher | 479a4cf | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 190 | #if defined(CONFIG_SYS_I2C_SOFT) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 191 | u32 tmp; |
| 192 | |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 193 | /* set the 2 bitbang i2c pins as output gpios */ |
Stefan Roese | c50ab39 | 2014-10-22 12:13:11 +0200 | [diff] [blame] | 194 | tmp = readl(MVEBU_GPIO0_BASE + 4); |
| 195 | writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS) , MVEBU_GPIO0_BASE + 4); |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 196 | #endif |
Holger Brunck | b59a955 | 2012-07-25 06:26:03 +0000 | [diff] [blame] | 197 | /* adjust SDRAM size for bank 0 */ |
Stefan Roese | 0b74175 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 198 | mvebu_sdram_size_adjust(0); |
Valentin Longchamp | 7d0d502 | 2012-06-01 01:31:00 +0000 | [diff] [blame] | 199 | kirkwood_mpp_conf(kwmpp_config, NULL); |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 200 | return 0; |
| 201 | } |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 202 | |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 203 | int board_init(void) |
| 204 | { |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 205 | /* address of boot parameters */ |
Stefan Roese | 0b74175 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 206 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 207 | |
| 208 | /* |
| 209 | * The KM_FLASH_GPIO_PIN switches between using a |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 210 | * NAND or a SPI FLASH. Set this pin on start |
| 211 | * to NAND mode. |
| 212 | */ |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 213 | kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1); |
| 214 | kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 215 | |
Heiko Schocher | 479a4cf | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 216 | #if defined(CONFIG_SYS_I2C_SOFT) |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 217 | /* |
| 218 | * Reinit the GPIO for I2C Bitbang driver so that the now |
| 219 | * available gpio framework is consistent. The calls to |
| 220 | * direction output in are not necessary, they are already done in |
| 221 | * board_early_init_f |
| 222 | */ |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 223 | kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1); |
| 224 | kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 225 | #endif |
Holger Brunck | 7d25a1a | 2012-07-05 05:05:11 +0000 | [diff] [blame] | 226 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 227 | #if defined(CONFIG_SYS_EEPROM_WREN) |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 228 | kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38); |
| 229 | kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 230 | #endif |
Heiko Schocher | 3ebd02b | 2010-10-20 19:33:26 +0530 | [diff] [blame] | 231 | |
Valentin Longchamp | 6633fed | 2012-07-05 05:05:05 +0000 | [diff] [blame] | 232 | #if defined(CONFIG_KM_FPGA_CONFIG) |
| 233 | trigger_fpga_config(); |
| 234 | #endif |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | int board_late_init(void) |
| 240 | { |
Holger Brunck | e306c67 | 2019-11-25 17:24:15 +0100 | [diff] [blame] | 241 | #if defined(CONFIG_KM_COGE5UN) |
Thomas Herzmann | 3ed5314 | 2012-07-05 05:05:10 +0000 | [diff] [blame] | 242 | u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE); |
| 243 | |
| 244 | /* if pin 1 do full erase */ |
| 245 | if (dip_switch != 0) { |
| 246 | /* start bootloader */ |
| 247 | puts("DIP: Enabled\n"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 248 | env_set("actual_bank", "0"); |
Thomas Herzmann | 3ed5314 | 2012-07-05 05:05:10 +0000 | [diff] [blame] | 249 | } |
| 250 | #endif |
| 251 | |
Valentin Longchamp | 6633fed | 2012-07-05 05:05:05 +0000 | [diff] [blame] | 252 | #if defined(CONFIG_KM_FPGA_CONFIG) |
| 253 | wait_for_fpga_config(); |
| 254 | fpga_reset(); |
| 255 | toggle_eeprom_spi_bus(); |
| 256 | #endif |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
Pascal Linder | 6adad98 | 2019-06-18 08:41:02 +0200 | [diff] [blame] | 260 | static const u32 spi_mpp_config[] = { |
| 261 | MPP1_SPI_MOSI, |
| 262 | MPP2_SPI_SCK, |
| 263 | MPP3_SPI_MISO, |
| 264 | 0 |
| 265 | }; |
| 266 | |
| 267 | static u32 spi_mpp_backup[4]; |
| 268 | |
| 269 | int mvebu_board_spi_claim_bus(struct udevice *dev) |
| 270 | { |
| 271 | spi_mpp_backup[3] = 0; |
| 272 | |
| 273 | /* set new spi mpp config and save current one */ |
| 274 | kirkwood_mpp_conf(spi_mpp_config, spi_mpp_backup); |
| 275 | |
| 276 | kw_gpio_set_value(KM_FLASH_GPIO_PIN, 0); |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | int mvebu_board_spi_release_bus(struct udevice *dev) |
| 282 | { |
| 283 | /* restore saved mpp config */ |
| 284 | kirkwood_mpp_conf(spi_mpp_backup, NULL); |
| 285 | |
| 286 | kw_gpio_set_value(KM_FLASH_GPIO_PIN, 1); |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
Holger Brunck | c9caa7f | 2012-07-05 05:05:04 +0000 | [diff] [blame] | 291 | #if (defined(CONFIG_KM_PIGGY4_88E6061)) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 292 | |
Valentin Longchamp | a7ef9af | 2012-07-05 05:05:07 +0000 | [diff] [blame] | 293 | #define PHY_LED_SEL_REG 0x18 |
| 294 | #define PHY_LED0_LINK (0x5) |
| 295 | #define PHY_LED1_ACT (0x8<<4) |
| 296 | #define PHY_LED2_INT (0xe<<8) |
| 297 | #define PHY_SPEC_CTRL_REG 0x1c |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 298 | #define PHY_RGMII_CLK_STABLE (0x1<<10) |
Valentin Longchamp | a7ef9af | 2012-07-05 05:05:07 +0000 | [diff] [blame] | 299 | #define PHY_CLSA (0x1<<1) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 300 | |
| 301 | /* Configure and enable MV88E3018 PHY */ |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 302 | void reset_phy(void) |
| 303 | { |
| 304 | char *name = "egiga0"; |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 305 | unsigned short reg; |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 306 | |
| 307 | if (miiphy_set_current_dev(name)) |
| 308 | return; |
| 309 | |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 310 | /* RGMII clk transition on data stable */ |
Holger Brunck | 7fef655 | 2014-01-27 16:58:26 +0100 | [diff] [blame] | 311 | if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, ®)) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 312 | printf("Error reading PHY spec ctrl reg\n"); |
Holger Brunck | 7fef655 | 2014-01-27 16:58:26 +0100 | [diff] [blame] | 313 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, |
| 314 | reg | PHY_RGMII_CLK_STABLE | PHY_CLSA)) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 315 | printf("Error writing PHY spec ctrl reg\n"); |
| 316 | |
| 317 | /* leds setup */ |
Holger Brunck | 7fef655 | 2014-01-27 16:58:26 +0100 | [diff] [blame] | 318 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL_REG, |
| 319 | PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT)) |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 320 | printf("Error writing PHY LED reg\n"); |
| 321 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 322 | /* reset the phy */ |
| 323 | miiphy_reset(name, CONFIG_PHY_BASE_ADR); |
| 324 | } |
Valentin Longchamp | 310164a | 2012-08-16 23:35:03 +0000 | [diff] [blame] | 325 | #elif defined(CONFIG_KM_PIGGY4_88E6352) |
| 326 | |
| 327 | #include <mv88e6352.h> |
| 328 | |
| 329 | #if defined(CONFIG_KM_NUSA) |
| 330 | struct mv88e_sw_reg extsw_conf[] = { |
| 331 | /* |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 332 | * port 0, PIGGY4, autoneg |
Valentin Longchamp | 310164a | 2012-08-16 23:35:03 +0000 | [diff] [blame] | 333 | * first the fix for the 1000Mbits Autoneg, this is from |
| 334 | * a Marvell errata, the regs are undocumented |
| 335 | */ |
| 336 | { PHY(0), PHY_PAGE, AN1000FIX_PAGE }, |
| 337 | { PHY(0), PHY_STATUS, AN1000FIX }, |
| 338 | { PHY(0), PHY_PAGE, 0 }, |
| 339 | /* now the real port and phy configuration */ |
| 340 | { PORT(0), PORT_PHY, NO_SPEED_FOR }, |
| 341 | { PORT(0), PORT_CTRL, FORWARDING | EGRS_FLD_ALL }, |
| 342 | { PHY(0), PHY_1000_CTRL, NO_ADV }, |
| 343 | { PHY(0), PHY_SPEC_CTRL, AUTO_MDIX_EN }, |
| 344 | { PHY(0), PHY_CTRL, PHY_100_MBPS | AUTONEG_EN | AUTONEG_RST | |
| 345 | FULL_DUPLEX }, |
| 346 | /* port 1, unused */ |
| 347 | { PORT(1), PORT_CTRL, PORT_DIS }, |
| 348 | { PHY(1), PHY_CTRL, PHY_PWR_DOWN }, |
| 349 | { PHY(1), PHY_SPEC_CTRL, SPEC_PWR_DOWN }, |
| 350 | /* port 2, unused */ |
| 351 | { PORT(2), PORT_CTRL, PORT_DIS }, |
| 352 | { PHY(2), PHY_CTRL, PHY_PWR_DOWN }, |
| 353 | { PHY(2), PHY_SPEC_CTRL, SPEC_PWR_DOWN }, |
| 354 | /* port 3, unused */ |
| 355 | { PORT(3), PORT_CTRL, PORT_DIS }, |
| 356 | { PHY(3), PHY_CTRL, PHY_PWR_DOWN }, |
| 357 | { PHY(3), PHY_SPEC_CTRL, SPEC_PWR_DOWN }, |
| 358 | /* port 4, ICNEV, SerDes, SGMII */ |
| 359 | { PORT(4), PORT_STATUS, NO_PHY_DETECT }, |
| 360 | { PORT(4), PORT_PHY, SPEED_1000_FOR }, |
| 361 | { PORT(4), PORT_CTRL, FORWARDING | EGRS_FLD_ALL }, |
| 362 | { PHY(4), PHY_CTRL, PHY_PWR_DOWN }, |
| 363 | { PHY(4), PHY_SPEC_CTRL, SPEC_PWR_DOWN }, |
| 364 | /* port 5, CPU_RGMII */ |
| 365 | { PORT(5), PORT_PHY, RX_RGMII_TIM | TX_RGMII_TIM | FLOW_CTRL_EN | |
| 366 | FLOW_CTRL_FOR | LINK_VAL | LINK_FOR | FULL_DPX | |
| 367 | FULL_DPX_FOR | SPEED_1000_FOR }, |
| 368 | { PORT(5), PORT_CTRL, FORWARDING | EGRS_FLD_ALL }, |
| 369 | /* port 6, unused, this port has no phy */ |
| 370 | { PORT(6), PORT_CTRL, PORT_DIS }, |
| 371 | }; |
| 372 | #else |
| 373 | struct mv88e_sw_reg extsw_conf[] = {}; |
| 374 | #endif |
| 375 | |
| 376 | void reset_phy(void) |
| 377 | { |
| 378 | #if defined(CONFIG_KM_MVEXTSW_ADDR) |
| 379 | char *name = "egiga0"; |
| 380 | |
| 381 | if (miiphy_set_current_dev(name)) |
| 382 | return; |
| 383 | |
| 384 | mv88e_sw_program(name, CONFIG_KM_MVEXTSW_ADDR, extsw_conf, |
| 385 | ARRAY_SIZE(extsw_conf)); |
| 386 | mv88e_sw_reset(name, CONFIG_KM_MVEXTSW_ADDR); |
| 387 | #endif |
| 388 | } |
| 389 | |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 390 | #else |
| 391 | /* Configure and enable MV88E1118 PHY on the piggy*/ |
| 392 | void reset_phy(void) |
| 393 | { |
Tobias Müller | b0cab2d | 2015-11-13 15:01:15 +0100 | [diff] [blame] | 394 | unsigned int oui; |
| 395 | unsigned char model, rev; |
| 396 | |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 397 | char *name = "egiga0"; |
| 398 | |
| 399 | if (miiphy_set_current_dev(name)) |
| 400 | return; |
| 401 | |
| 402 | /* reset the phy */ |
| 403 | miiphy_reset(name, CONFIG_PHY_BASE_ADR); |
Tobias Müller | b0cab2d | 2015-11-13 15:01:15 +0100 | [diff] [blame] | 404 | |
| 405 | /* get PHY model */ |
| 406 | if (miiphy_info(name, CONFIG_PHY_BASE_ADR, &oui, &model, &rev)) |
| 407 | return; |
| 408 | |
| 409 | /* check for Marvell 88E1118R Gigabit PHY (PIGGY3) */ |
| 410 | if ((oui == PHY_MARVELL_OUI) && |
| 411 | (model == PHY_MARVELL_88E1118R_MODEL)) { |
| 412 | /* set page register to 3 */ |
| 413 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, |
| 414 | PHY_MARVELL_PAGE_REG, |
| 415 | PHY_MARVELL_88E1118R_LED_CTRL_PAGE)) |
| 416 | printf("Error writing PHY page reg\n"); |
| 417 | |
| 418 | /* |
| 419 | * leds setup as printed on PCB: |
| 420 | * LED2 (Link): 0x0 (On Link, Off No Link) |
| 421 | * LED1 (Activity): 0x3 (On Activity, Off No Activity) |
| 422 | * LED0 (Speed): 0x7 (On 1000 MBits, Off Else) |
| 423 | */ |
| 424 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, |
| 425 | PHY_MARVELL_88E1118R_LED_CTRL_REG, |
| 426 | PHY_MARVELL_88E1118R_LED_CTRL_RESERVED | |
| 427 | PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB | |
| 428 | PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT | |
| 429 | PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK)) |
| 430 | printf("Error writing PHY LED reg\n"); |
| 431 | |
| 432 | /* set page register back to 0 */ |
| 433 | if (miiphy_write(name, CONFIG_PHY_BASE_ADR, |
| 434 | PHY_MARVELL_PAGE_REG, |
| 435 | PHY_MARVELL_DEFAULT_PAGE)) |
| 436 | printf("Error writing PHY page reg\n"); |
| 437 | } |
Valentin Longchamp | 3f29cbb | 2011-06-16 18:11:15 +0530 | [diff] [blame] | 438 | } |
| 439 | #endif |
| 440 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 441 | |
| 442 | #if defined(CONFIG_HUSH_INIT_VAR) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 443 | int hush_init_var(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 444 | { |
Valentin Longchamp | aea4bb5 | 2015-02-10 17:10:14 +0100 | [diff] [blame] | 445 | ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | #endif |
| 449 | |
Heiko Schocher | 479a4cf | 2013-01-29 08:53:15 +0100 | [diff] [blame] | 450 | #if defined(CONFIG_SYS_I2C_SOFT) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 451 | void set_sda(int state) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 452 | { |
| 453 | I2C_ACTIVE; |
| 454 | I2C_SDA(state); |
| 455 | } |
| 456 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 457 | void set_scl(int state) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 458 | { |
| 459 | I2C_SCL(state); |
| 460 | } |
| 461 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 462 | int get_sda(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 463 | { |
| 464 | I2C_TRISTATE; |
| 465 | return I2C_READ; |
| 466 | } |
| 467 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 468 | int get_scl(void) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 469 | { |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 470 | return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0; |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 471 | } |
| 472 | #endif |
| 473 | |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 474 | #if defined(CONFIG_POST) |
| 475 | |
| 476 | #define KM_POST_EN_L 44 |
| 477 | #define POST_WORD_OFF 8 |
| 478 | |
| 479 | int post_hotkeys_pressed(void) |
| 480 | { |
Holger Brunck | f065ce0 | 2012-07-05 05:05:02 +0000 | [diff] [blame] | 481 | #if defined(CONFIG_KM_COGE5UN) |
| 482 | return kw_gpio_get_value(KM_POST_EN_L); |
| 483 | #else |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 484 | return !kw_gpio_get_value(KM_POST_EN_L); |
Holger Brunck | f065ce0 | 2012-07-05 05:05:02 +0000 | [diff] [blame] | 485 | #endif |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | ulong post_word_load(void) |
| 489 | { |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 490 | void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 491 | return in_le32(addr); |
| 492 | |
| 493 | } |
| 494 | void post_word_store(ulong value) |
| 495 | { |
Holger Brunck | 763c2dc | 2011-12-14 05:31:20 +0000 | [diff] [blame] | 496 | void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); |
Valentin Longchamp | 24ec993 | 2011-09-12 04:18:42 +0000 | [diff] [blame] | 497 | out_le32(addr, value); |
| 498 | } |
| 499 | |
| 500 | int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset) |
| 501 | { |
| 502 | *vstart = CONFIG_SYS_SDRAM_BASE; |
| 503 | |
| 504 | /* we go up to relocation plus a 1 MB margin */ |
| 505 | *size = CONFIG_SYS_TEXT_BASE - (1<<20); |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | #endif |
| 510 | |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 511 | #if defined(CONFIG_SYS_EEPROM_WREN) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 512 | int eeprom_write_enable(unsigned dev_addr, int state) |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 513 | { |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 514 | kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 515 | |
Heiko Schocher | 9878f99 | 2011-02-22 09:13:00 +0100 | [diff] [blame] | 516 | return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP); |
Heiko Schocher | 6030119 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 517 | } |
| 518 | #endif |