Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com. |
| 5 | * |
| 6 | * Copyright (C) 2012 Stefan Roese <sr@denx.de> |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 8e20188 | 2020-05-10 11:39:54 -0600 | [diff] [blame] | 10 | #include <flash.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 11 | #include <init.h> |
Stefan Roese | fc5ce16 | 2016-04-27 09:10:42 +0200 | [diff] [blame] | 12 | #include <micrel.h> |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 13 | #include <nand.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 14 | #include <net.h> |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 15 | #include <netdev.h> |
| 16 | #include <phy.h> |
| 17 | #include <rtc.h> |
| 18 | #include <asm/io.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 19 | #include <asm/mach-types.h> |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 20 | #include <asm/arch/hardware.h> |
| 21 | #include <asm/arch/spr_defs.h> |
| 22 | #include <asm/arch/spr_misc.h> |
| 23 | #include <linux/mtd/fsmc_nand.h> |
| 24 | #include "fpga.h" |
| 25 | |
| 26 | static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE]; |
| 27 | |
| 28 | int board_init(void) |
| 29 | { |
| 30 | /* |
| 31 | * X600 is equipped with an M41T82 RTC. This RTC has the |
| 32 | * HT bit (Halt Update), which needs to be cleared upon |
| 33 | * power-up. Otherwise the RTC is halted. |
| 34 | */ |
| 35 | rtc_reset(); |
| 36 | |
| 37 | return spear_board_init(MACH_TYPE_SPEAR600); |
| 38 | } |
| 39 | |
| 40 | int board_late_init(void) |
| 41 | { |
| 42 | /* |
| 43 | * Monitor and env protection on by default |
| 44 | */ |
| 45 | flash_protect(FLAG_PROTECT_SET, |
| 46 | CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_BASE + |
| 47 | CONFIG_SYS_SPL_LEN + CONFIG_SYS_MONITOR_LEN + |
| 48 | 2 * CONFIG_ENV_SECT_SIZE - 1, |
| 49 | &flash_info[0]); |
| 50 | |
| 51 | /* Init FPGA subsystem */ |
| 52 | x600_init_fpga(); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * board_nand_init - Board specific NAND initialization |
| 59 | * @nand: mtd private chip structure |
| 60 | * |
| 61 | * Called by nand_init_chip to initialize the board specific functions |
| 62 | */ |
| 63 | |
| 64 | void board_nand_init(void) |
| 65 | { |
| 66 | struct misc_regs *const misc_regs_p = |
| 67 | (struct misc_regs *)CONFIG_SPEAR_MISCBASE; |
| 68 | struct nand_chip *nand = &nand_chip[0]; |
| 69 | |
| 70 | if (!(readl(&misc_regs_p->auto_cfg_reg) & MISC_NANDDIS)) |
| 71 | fsmc_nand_init(nand); |
| 72 | } |
| 73 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 74 | int board_phy_config(struct phy_device *phydev) |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 75 | { |
Stefan Roese | fc5ce16 | 2016-04-27 09:10:42 +0200 | [diff] [blame] | 76 | unsigned short id1, id2; |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 77 | |
Stefan Roese | fc5ce16 | 2016-04-27 09:10:42 +0200 | [diff] [blame] | 78 | /* check whether KSZ9031 or AR8035 has to be configured */ |
| 79 | id1 = phy_read(phydev, MDIO_DEVAD_NONE, 2); |
| 80 | id2 = phy_read(phydev, MDIO_DEVAD_NONE, 3); |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 81 | |
Stefan Roese | fc5ce16 | 2016-04-27 09:10:42 +0200 | [diff] [blame] | 82 | if ((id1 == 0x22) && ((id2 & 0xFFF0) == 0x1620)) { |
| 83 | /* PHY configuration for Micrel KSZ9031 */ |
| 84 | printf("PHY KSZ9031 detected - "); |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 85 | |
Stefan Roese | fc5ce16 | 2016-04-27 09:10:42 +0200 | [diff] [blame] | 86 | phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0x1c00); |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 87 | |
Stefan Roese | fc5ce16 | 2016-04-27 09:10:42 +0200 | [diff] [blame] | 88 | /* control data pad skew - devaddr = 0x02, register = 0x04 */ |
| 89 | ksz9031_phy_extended_write(phydev, 0x02, |
| 90 | MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW, |
| 91 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 92 | 0x0000); |
| 93 | /* rx data pad skew - devaddr = 0x02, register = 0x05 */ |
| 94 | ksz9031_phy_extended_write(phydev, 0x02, |
| 95 | MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW, |
| 96 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 97 | 0x0000); |
| 98 | /* tx data pad skew - devaddr = 0x02, register = 0x05 */ |
| 99 | ksz9031_phy_extended_write(phydev, 0x02, |
| 100 | MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW, |
| 101 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 102 | 0x0000); |
| 103 | /* gtx and rx clock pad skew - devaddr = 0x02, reg = 0x08 */ |
| 104 | ksz9031_phy_extended_write(phydev, 0x02, |
| 105 | MII_KSZ9031_EXT_RGMII_CLOCK_SKEW, |
| 106 | MII_KSZ9031_MOD_DATA_NO_POST_INC, |
| 107 | 0x03FF); |
| 108 | } else { |
| 109 | /* PHY configuration for Vitesse VSC8641 */ |
| 110 | printf("PHY VSC8641 detected - "); |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 111 | |
Stefan Roese | fc5ce16 | 2016-04-27 09:10:42 +0200 | [diff] [blame] | 112 | /* Extended PHY control 1, select GMII */ |
| 113 | phy_write(phydev, MDIO_DEVAD_NONE, 23, 0x0020); |
| 114 | |
| 115 | /* Software reset necessary after GMII mode selction */ |
| 116 | phy_reset(phydev); |
| 117 | |
| 118 | /* Enable extended page register access */ |
| 119 | phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0001); |
| 120 | |
| 121 | /* 17e: Enhanced LED behavior, needs to be written twice */ |
| 122 | phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x09ff); |
| 123 | phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x09ff); |
| 124 | |
| 125 | /* 16e: Enhanced LED method select */ |
| 126 | phy_write(phydev, MDIO_DEVAD_NONE, 16, 0xe0ea); |
| 127 | |
| 128 | /* Disable extended page register access */ |
| 129 | phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0000); |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 130 | |
Stefan Roese | fc5ce16 | 2016-04-27 09:10:42 +0200 | [diff] [blame] | 131 | /* Enable clock output pin */ |
| 132 | phy_write(phydev, MDIO_DEVAD_NONE, 18, 0x0049); |
| 133 | } |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 134 | |
| 135 | if (phydev->drv->config) |
| 136 | phydev->drv->config(phydev); |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 141 | int board_eth_init(struct bd_info *bis) |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 142 | { |
| 143 | int ret = 0; |
| 144 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 145 | if (designware_initialize(CONFIG_SPEAR_ETHBASE, |
Stefan Roese | 181e06b | 2012-05-30 22:59:08 +0000 | [diff] [blame] | 146 | PHY_INTERFACE_MODE_GMII) >= 0) |
| 147 | ret++; |
| 148 | |
| 149 | return ret; |
| 150 | } |