Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 2 | /* |
Tony Dinh | 43e75bb | 2021-07-16 02:18:04 -0700 | [diff] [blame] | 3 | * Copyright (C) 2021 Tony Dinh <mibodhi@gmail.com> |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 4 | * (C) Copyright 2009 |
| 5 | * Marvell Semiconductor <www.marvell.com> |
| 6 | * Written-by: Prafulla Wadaskar <prafulla@marvell.com> |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 11 | #include <miiphy.h> |
Simon Glass | 0c36441 | 2019-12-28 10:44:48 -0700 | [diff] [blame] | 12 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 14 | #include <asm/mach-types.h> |
Lei Wen | 298ae91 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 15 | #include <asm/arch/cpu.h> |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 16 | #include <asm/arch/soc.h> |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 17 | #include <asm/arch/mpp.h> |
| 18 | #include "sheevaplug.h" |
| 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Prafulla Wadaskar | 44f4d43 | 2010-10-20 20:12:27 +0530 | [diff] [blame] | 22 | int board_early_init_f(void) |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 23 | { |
| 24 | /* |
| 25 | * default gpio configuration |
| 26 | * There are maximum 64 gpios controlled through 2 sets of registers |
| 27 | * the below configuration configures mainly initial LED status |
| 28 | */ |
Stefan Roese | c50ab39 | 2014-10-22 12:13:11 +0200 | [diff] [blame] | 29 | mvebu_config_gpio(SHEEVAPLUG_OE_VAL_LOW, |
| 30 | SHEEVAPLUG_OE_VAL_HIGH, |
| 31 | SHEEVAPLUG_OE_LOW, SHEEVAPLUG_OE_HIGH); |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +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[] = { |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 35 | MPP0_NF_IO2, |
| 36 | MPP1_NF_IO3, |
| 37 | MPP2_NF_IO4, |
| 38 | MPP3_NF_IO5, |
| 39 | MPP4_NF_IO6, |
| 40 | MPP5_NF_IO7, |
| 41 | MPP6_SYSRST_OUTn, |
| 42 | MPP7_GPO, |
| 43 | MPP8_UART0_RTS, |
| 44 | MPP9_UART0_CTS, |
| 45 | MPP10_UART0_TXD, |
| 46 | MPP11_UART0_RXD, |
| 47 | MPP12_SD_CLK, |
| 48 | MPP13_SD_CMD, |
| 49 | MPP14_SD_D0, |
| 50 | MPP15_SD_D1, |
| 51 | MPP16_SD_D2, |
| 52 | MPP17_SD_D3, |
| 53 | MPP18_NF_IO0, |
| 54 | MPP19_NF_IO1, |
| 55 | MPP20_GPIO, |
| 56 | MPP21_GPIO, |
| 57 | MPP22_GPIO, |
| 58 | MPP23_GPIO, |
| 59 | MPP24_GPIO, |
| 60 | MPP25_GPIO, |
| 61 | MPP26_GPIO, |
| 62 | MPP27_GPIO, |
| 63 | MPP28_GPIO, |
| 64 | MPP29_TSMP9, |
| 65 | MPP30_GPIO, |
| 66 | MPP31_GPIO, |
| 67 | MPP32_GPIO, |
| 68 | MPP33_GPIO, |
| 69 | MPP34_GPIO, |
| 70 | MPP35_GPIO, |
| 71 | MPP36_GPIO, |
| 72 | MPP37_GPIO, |
| 73 | MPP38_GPIO, |
| 74 | MPP39_GPIO, |
| 75 | MPP40_GPIO, |
| 76 | MPP41_GPIO, |
| 77 | MPP42_GPIO, |
| 78 | MPP43_GPIO, |
| 79 | MPP44_GPIO, |
| 80 | MPP45_GPIO, |
| 81 | MPP46_GPIO, |
| 82 | MPP47_GPIO, |
| 83 | MPP48_GPIO, |
| 84 | MPP49_GPIO, |
| 85 | 0 |
| 86 | }; |
Valentin Longchamp | 7d0d502 | 2012-06-01 01:31:00 +0000 | [diff] [blame] | 87 | kirkwood_mpp_conf(kwmpp_config, NULL); |
Prafulla Wadaskar | 44f4d43 | 2010-10-20 20:12:27 +0530 | [diff] [blame] | 88 | return 0; |
| 89 | } |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 90 | |
Prafulla Wadaskar | 44f4d43 | 2010-10-20 20:12:27 +0530 | [diff] [blame] | 91 | int board_init(void) |
| 92 | { |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 93 | /* |
| 94 | * arch number of board |
| 95 | */ |
| 96 | gd->bd->bi_arch_number = MACH_TYPE_SHEEVAPLUG; |
| 97 | |
| 98 | /* adress of boot parameters */ |
Stefan Roese | 0b74175 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 99 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
Tony Dinh | 43e75bb | 2021-07-16 02:18:04 -0700 | [diff] [blame] | 104 | static int fdt_get_phy_addr(const char *path) |
| 105 | { |
| 106 | const void *fdt = gd->fdt_blob; |
| 107 | const u32 *reg; |
| 108 | const u32 *val; |
| 109 | int node, phandle, addr; |
| 110 | |
| 111 | /* Find the node by its full path */ |
| 112 | node = fdt_path_offset(fdt, path); |
| 113 | if (node >= 0) { |
| 114 | /* Look up phy-handle */ |
| 115 | val = fdt_getprop(fdt, node, "phy-handle", NULL); |
| 116 | if (val) { |
| 117 | phandle = fdt32_to_cpu(*val); |
| 118 | if (!phandle) |
| 119 | return -1; |
| 120 | /* Follow it to its node */ |
| 121 | node = fdt_node_offset_by_phandle(fdt, phandle); |
| 122 | if (node) { |
| 123 | /* Look up reg */ |
| 124 | reg = fdt_getprop(fdt, node, "reg", NULL); |
| 125 | if (reg) { |
| 126 | addr = fdt32_to_cpu(*reg); |
| 127 | return addr; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | return -1; |
| 133 | } |
| 134 | |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 135 | #ifdef CONFIG_RESET_PHY_R |
| 136 | /* Configure and enable MV88E1116 PHY */ |
| 137 | void reset_phy(void) |
| 138 | { |
| 139 | u16 reg; |
Tony Dinh | 43e75bb | 2021-07-16 02:18:04 -0700 | [diff] [blame] | 140 | int phyaddr; |
| 141 | char *name = "ethernet-controller@72000"; |
| 142 | char *eth0_path = "/ocp@f1000000/ethernet-controller@72000/ethernet0-port@0"; |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 143 | |
| 144 | if (miiphy_set_current_dev(name)) |
| 145 | return; |
| 146 | |
Tony Dinh | 43e75bb | 2021-07-16 02:18:04 -0700 | [diff] [blame] | 147 | phyaddr = fdt_get_phy_addr(eth0_path); |
| 148 | if (phyaddr < 0) |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 149 | return; |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * Enable RGMII delay on Tx and Rx for CPU port |
| 153 | * Ref: sec 4.7.2 of chip datasheet |
| 154 | */ |
Tony Dinh | 43e75bb | 2021-07-16 02:18:04 -0700 | [diff] [blame] | 155 | miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 2); |
| 156 | miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, ®); |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 157 | reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL); |
Tony Dinh | 43e75bb | 2021-07-16 02:18:04 -0700 | [diff] [blame] | 158 | miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg); |
| 159 | miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 0); |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 160 | |
| 161 | /* reset the phy */ |
Tony Dinh | 43e75bb | 2021-07-16 02:18:04 -0700 | [diff] [blame] | 162 | miiphy_reset(name, phyaddr); |
Prafulla Wadaskar | 6263464 | 2009-07-16 20:58:00 +0530 | [diff] [blame] | 163 | |
| 164 | printf("88E1116 Initialized on %s\n", name); |
| 165 | } |
| 166 | #endif /* CONFIG_RESET_PHY_R */ |