Chris Packham | 5cd63ec | 2018-05-30 20:14:35 +1200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2010, 2018 |
| 4 | * Allied Telesis <www.alliedtelesis.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 0c36441 | 2019-12-28 10:44:48 -0700 | [diff] [blame] | 9 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 11 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 12 | #include <linux/delay.h> |
Chris Packham | 5cd63ec | 2018-05-30 20:14:35 +1200 | [diff] [blame] | 13 | #include <linux/io.h> |
| 14 | #include <miiphy.h> |
| 15 | #include <netdev.h> |
Simon Glass | e7872cb | 2019-11-14 12:57:11 -0700 | [diff] [blame] | 16 | #include <status_led.h> |
Chris Packham | 5cd63ec | 2018-05-30 20:14:35 +1200 | [diff] [blame] | 17 | #include <asm/arch/cpu.h> |
| 18 | #include <asm/arch/soc.h> |
| 19 | #include <asm/arch/mpp.h> |
| 20 | #include <asm/arch/gpio.h> |
| 21 | |
| 22 | /* Note: GPIO differences between specific boards |
| 23 | * |
| 24 | * We're trying to avoid having multiple build targets for all the Kirkwood |
| 25 | * based boards one area where things tend to differ is GPIO usage. For the |
| 26 | * most part the GPIOs driven by the bootloader are similar enough in function |
| 27 | * that there is no harm in driving them. |
| 28 | * |
| 29 | * XZ4 XS6 XS16 GS24A GT40 GP24A GT24A |
| 30 | * GPIO39 - INT(<) NC MUX_RST_N(>) NC POE_DIS_N(>) NC |
| 31 | */ |
| 32 | |
| 33 | #define SBX81LIFKW_OE_LOW ~(BIT(31) | BIT(30) | BIT(28) | BIT(27) | \ |
| 34 | BIT(18) | BIT(17) | BIT(13) | BIT(12) | \ |
| 35 | BIT(10)) |
| 36 | #define SBX81LIFKW_OE_HIGH ~(BIT(0) | BIT(1) | BIT(7)) |
| 37 | #define SBX81LIFKW_OE_VAL_LOW (BIT(31) | BIT(30) | BIT(28) | BIT(27)) |
| 38 | #define SBX81LIFKW_OE_VAL_HIGH (BIT(0) | BIT(1)) |
| 39 | |
| 40 | #define MV88E6097_RESET 27 |
| 41 | |
| 42 | DECLARE_GLOBAL_DATA_PTR; |
| 43 | |
| 44 | struct led { |
| 45 | u32 reg; |
| 46 | u32 value; |
| 47 | u32 mask; |
| 48 | }; |
| 49 | |
| 50 | struct led amber_solid = { |
| 51 | MVEBU_GPIO0_BASE, |
| 52 | BIT(10), |
| 53 | BIT(18) | BIT(10) |
| 54 | }; |
| 55 | |
| 56 | struct led green_solid = { |
| 57 | MVEBU_GPIO0_BASE, |
| 58 | BIT(18) | BIT(10), |
| 59 | BIT(18) | BIT(10) |
| 60 | }; |
| 61 | |
| 62 | struct led amber_flash = { |
| 63 | MVEBU_GPIO0_BASE, |
| 64 | 0, |
| 65 | BIT(18) | BIT(10) |
| 66 | }; |
| 67 | |
| 68 | struct led green_flash = { |
| 69 | MVEBU_GPIO0_BASE, |
| 70 | BIT(18), |
| 71 | BIT(18) | BIT(10) |
| 72 | }; |
| 73 | |
| 74 | static void status_led_set(struct led *led) |
| 75 | { |
| 76 | clrsetbits_le32(led->reg, led->mask, led->value); |
| 77 | } |
| 78 | |
| 79 | int board_early_init_f(void) |
| 80 | { |
| 81 | /* |
| 82 | * default gpio configuration |
| 83 | * There are maximum 64 gpios controlled through 2 sets of registers |
| 84 | * the below configuration configures mainly initial LED status |
| 85 | */ |
| 86 | mvebu_config_gpio(SBX81LIFKW_OE_VAL_LOW, |
| 87 | SBX81LIFKW_OE_VAL_HIGH, |
| 88 | SBX81LIFKW_OE_LOW, SBX81LIFKW_OE_HIGH); |
| 89 | |
| 90 | /* Multi-Purpose Pins Functionality configuration */ |
| 91 | static const u32 kwmpp_config[] = { |
| 92 | MPP0_SPI_SCn, |
| 93 | MPP1_SPI_MOSI, |
| 94 | MPP2_SPI_SCK, |
| 95 | MPP3_SPI_MISO, |
| 96 | MPP4_UART0_RXD, |
| 97 | MPP5_UART0_TXD, |
| 98 | MPP6_SYSRST_OUTn, |
| 99 | MPP7_PEX_RST_OUTn, |
| 100 | MPP8_TW_SDA, |
| 101 | MPP9_TW_SCK, |
| 102 | MPP10_GPO, |
| 103 | MPP11_GPIO, |
| 104 | MPP12_GPO, |
| 105 | MPP13_GPIO, |
| 106 | MPP14_GPIO, |
| 107 | MPP15_UART0_RTS, |
| 108 | MPP16_UART0_CTS, |
| 109 | MPP17_GPIO, |
| 110 | MPP18_GPO, |
| 111 | MPP19_GPO, |
| 112 | MPP20_GPIO, |
| 113 | MPP21_GPIO, |
| 114 | MPP22_GPIO, |
| 115 | MPP23_GPIO, |
| 116 | MPP24_GPIO, |
| 117 | MPP25_GPIO, |
| 118 | MPP26_GPIO, |
| 119 | MPP27_GPIO, |
| 120 | MPP28_GPIO, |
| 121 | MPP29_GPIO, |
| 122 | MPP30_GPIO, |
| 123 | MPP31_GPIO, |
| 124 | MPP32_GPIO, |
| 125 | MPP33_GPIO, |
| 126 | MPP34_GPIO, |
| 127 | MPP35_GPIO, |
| 128 | MPP36_GPIO, |
| 129 | MPP37_GPIO, |
| 130 | MPP38_GPIO, |
| 131 | MPP39_GPIO, |
| 132 | MPP40_GPIO, |
| 133 | MPP41_GPIO, |
| 134 | MPP42_GPIO, |
| 135 | MPP43_GPIO, |
| 136 | MPP44_GPIO, |
| 137 | MPP45_GPIO, |
| 138 | MPP46_GPIO, |
| 139 | MPP47_GPIO, |
| 140 | MPP48_GPIO, |
| 141 | MPP49_GPIO, |
| 142 | 0 |
| 143 | }; |
| 144 | |
| 145 | kirkwood_mpp_conf(kwmpp_config, NULL); |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | int board_init(void) |
| 150 | { |
| 151 | /* Power-down unused subsystems. The required |
| 152 | * subsystems are: |
| 153 | * |
| 154 | * GE0 b0 |
| 155 | * PEX0 PHY b1 |
| 156 | * PEX0.0 b2 |
| 157 | * TSU b5 |
| 158 | * SDRAM b6 |
| 159 | * RUNIT b7 |
| 160 | */ |
| 161 | writel((BIT(0) | BIT(1) | BIT(2) | |
| 162 | BIT(5) | BIT(6) | BIT(7)), |
| 163 | KW_CPU_REG_BASE + 0x1c); |
| 164 | |
| 165 | /* address of boot parameters */ |
| 166 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
| 167 | |
| 168 | status_led_set(&amber_solid); |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
Chris Packham | 83bfe79 | 2018-06-03 16:21:27 +1200 | [diff] [blame] | 173 | #ifdef CONFIG_RESET_PHY_R |
| 174 | /* automatically defined by kirkwood config.h */ |
Chris Packham | 5cd63ec | 2018-05-30 20:14:35 +1200 | [diff] [blame] | 175 | void reset_phy(void) |
| 176 | { |
Chris Packham | 83bfe79 | 2018-06-03 16:21:27 +1200 | [diff] [blame] | 177 | } |
| 178 | #endif |
| 179 | |
| 180 | #ifdef CONFIG_MV88E61XX_SWITCH |
| 181 | int mv88e61xx_hw_reset(struct phy_device *phydev) |
| 182 | { |
Chris Packham | 5cd63ec | 2018-05-30 20:14:35 +1200 | [diff] [blame] | 183 | /* Ensure the 88e6097 gets at least 10ms Reset |
| 184 | */ |
| 185 | kw_gpio_set_value(MV88E6097_RESET, 0); |
| 186 | mdelay(20); |
| 187 | kw_gpio_set_value(MV88E6097_RESET, 1); |
| 188 | mdelay(20); |
Chris Packham | 83bfe79 | 2018-06-03 16:21:27 +1200 | [diff] [blame] | 189 | |
| 190 | phydev->advertising = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full; |
| 191 | |
| 192 | return 0; |
Chris Packham | 5cd63ec | 2018-05-30 20:14:35 +1200 | [diff] [blame] | 193 | } |
| 194 | #endif |
| 195 | |
| 196 | #ifdef CONFIG_MISC_INIT_R |
| 197 | int misc_init_r(void) |
| 198 | { |
| 199 | status_led_set(&green_flash); |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | #endif |