1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2995b72ddSStefan Roese /*
3995b72ddSStefan Roese * (C) Copyright 2009
4995b72ddSStefan Roese * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
5995b72ddSStefan Roese *
6995b72ddSStefan Roese * Copyright (C) 2012 Stefan Roese <sr@denx.de>
7995b72ddSStefan Roese */
8995b72ddSStefan Roese
9995b72ddSStefan Roese #include <common.h>
10f7c32e8eSStefan Roese #include <micrel.h>
11995b72ddSStefan Roese #include <nand.h>
12995b72ddSStefan Roese #include <netdev.h>
13995b72ddSStefan Roese #include <phy.h>
14995b72ddSStefan Roese #include <rtc.h>
15995b72ddSStefan Roese #include <asm/io.h>
16c62db35dSSimon Glass #include <asm/mach-types.h>
17995b72ddSStefan Roese #include <asm/arch/hardware.h>
18995b72ddSStefan Roese #include <asm/arch/spr_defs.h>
19995b72ddSStefan Roese #include <asm/arch/spr_misc.h>
20995b72ddSStefan Roese #include <linux/mtd/fsmc_nand.h>
21995b72ddSStefan Roese #include "fpga.h"
22995b72ddSStefan Roese
23995b72ddSStefan Roese static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE];
24995b72ddSStefan Roese
board_init(void)25995b72ddSStefan Roese int board_init(void)
26995b72ddSStefan Roese {
27995b72ddSStefan Roese /*
28995b72ddSStefan Roese * X600 is equipped with an M41T82 RTC. This RTC has the
29995b72ddSStefan Roese * HT bit (Halt Update), which needs to be cleared upon
30995b72ddSStefan Roese * power-up. Otherwise the RTC is halted.
31995b72ddSStefan Roese */
32995b72ddSStefan Roese rtc_reset();
33995b72ddSStefan Roese
34995b72ddSStefan Roese return spear_board_init(MACH_TYPE_SPEAR600);
35995b72ddSStefan Roese }
36995b72ddSStefan Roese
board_late_init(void)37995b72ddSStefan Roese int board_late_init(void)
38995b72ddSStefan Roese {
39995b72ddSStefan Roese /*
40995b72ddSStefan Roese * Monitor and env protection on by default
41995b72ddSStefan Roese */
42995b72ddSStefan Roese flash_protect(FLAG_PROTECT_SET,
43995b72ddSStefan Roese CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_BASE +
44995b72ddSStefan Roese CONFIG_SYS_SPL_LEN + CONFIG_SYS_MONITOR_LEN +
45995b72ddSStefan Roese 2 * CONFIG_ENV_SECT_SIZE - 1,
46995b72ddSStefan Roese &flash_info[0]);
47995b72ddSStefan Roese
48995b72ddSStefan Roese /* Init FPGA subsystem */
49995b72ddSStefan Roese x600_init_fpga();
50995b72ddSStefan Roese
51995b72ddSStefan Roese return 0;
52995b72ddSStefan Roese }
53995b72ddSStefan Roese
54995b72ddSStefan Roese /*
55995b72ddSStefan Roese * board_nand_init - Board specific NAND initialization
56995b72ddSStefan Roese * @nand: mtd private chip structure
57995b72ddSStefan Roese *
58995b72ddSStefan Roese * Called by nand_init_chip to initialize the board specific functions
59995b72ddSStefan Roese */
60995b72ddSStefan Roese
board_nand_init(void)61995b72ddSStefan Roese void board_nand_init(void)
62995b72ddSStefan Roese {
63995b72ddSStefan Roese struct misc_regs *const misc_regs_p =
64995b72ddSStefan Roese (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
65995b72ddSStefan Roese struct nand_chip *nand = &nand_chip[0];
66995b72ddSStefan Roese
67995b72ddSStefan Roese if (!(readl(&misc_regs_p->auto_cfg_reg) & MISC_NANDDIS))
68995b72ddSStefan Roese fsmc_nand_init(nand);
69995b72ddSStefan Roese }
70995b72ddSStefan Roese
board_phy_config(struct phy_device * phydev)7192a190aaSAlexey Brodkin int board_phy_config(struct phy_device *phydev)
72995b72ddSStefan Roese {
73f7c32e8eSStefan Roese unsigned short id1, id2;
74f7c32e8eSStefan Roese
75f7c32e8eSStefan Roese /* check whether KSZ9031 or AR8035 has to be configured */
76f7c32e8eSStefan Roese id1 = phy_read(phydev, MDIO_DEVAD_NONE, 2);
77f7c32e8eSStefan Roese id2 = phy_read(phydev, MDIO_DEVAD_NONE, 3);
78f7c32e8eSStefan Roese
79f7c32e8eSStefan Roese if ((id1 == 0x22) && ((id2 & 0xFFF0) == 0x1620)) {
80f7c32e8eSStefan Roese /* PHY configuration for Micrel KSZ9031 */
81f7c32e8eSStefan Roese printf("PHY KSZ9031 detected - ");
82f7c32e8eSStefan Roese
83f7c32e8eSStefan Roese phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0x1c00);
84f7c32e8eSStefan Roese
85f7c32e8eSStefan Roese /* control data pad skew - devaddr = 0x02, register = 0x04 */
86f7c32e8eSStefan Roese ksz9031_phy_extended_write(phydev, 0x02,
87f7c32e8eSStefan Roese MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW,
88f7c32e8eSStefan Roese MII_KSZ9031_MOD_DATA_NO_POST_INC,
89f7c32e8eSStefan Roese 0x0000);
90f7c32e8eSStefan Roese /* rx data pad skew - devaddr = 0x02, register = 0x05 */
91f7c32e8eSStefan Roese ksz9031_phy_extended_write(phydev, 0x02,
92f7c32e8eSStefan Roese MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW,
93f7c32e8eSStefan Roese MII_KSZ9031_MOD_DATA_NO_POST_INC,
94f7c32e8eSStefan Roese 0x0000);
95f7c32e8eSStefan Roese /* tx data pad skew - devaddr = 0x02, register = 0x05 */
96f7c32e8eSStefan Roese ksz9031_phy_extended_write(phydev, 0x02,
97f7c32e8eSStefan Roese MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW,
98f7c32e8eSStefan Roese MII_KSZ9031_MOD_DATA_NO_POST_INC,
99f7c32e8eSStefan Roese 0x0000);
100f7c32e8eSStefan Roese /* gtx and rx clock pad skew - devaddr = 0x02, reg = 0x08 */
101f7c32e8eSStefan Roese ksz9031_phy_extended_write(phydev, 0x02,
102f7c32e8eSStefan Roese MII_KSZ9031_EXT_RGMII_CLOCK_SKEW,
103f7c32e8eSStefan Roese MII_KSZ9031_MOD_DATA_NO_POST_INC,
104f7c32e8eSStefan Roese 0x03FF);
105f7c32e8eSStefan Roese } else {
106f7c32e8eSStefan Roese /* PHY configuration for Vitesse VSC8641 */
107f7c32e8eSStefan Roese printf("PHY VSC8641 detected - ");
108f7c32e8eSStefan Roese
109995b72ddSStefan Roese /* Extended PHY control 1, select GMII */
11092a190aaSAlexey Brodkin phy_write(phydev, MDIO_DEVAD_NONE, 23, 0x0020);
111995b72ddSStefan Roese
112995b72ddSStefan Roese /* Software reset necessary after GMII mode selction */
11392a190aaSAlexey Brodkin phy_reset(phydev);
114995b72ddSStefan Roese
115995b72ddSStefan Roese /* Enable extended page register access */
11692a190aaSAlexey Brodkin phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0001);
117995b72ddSStefan Roese
118995b72ddSStefan Roese /* 17e: Enhanced LED behavior, needs to be written twice */
11992a190aaSAlexey Brodkin phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x09ff);
12092a190aaSAlexey Brodkin phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x09ff);
121995b72ddSStefan Roese
122995b72ddSStefan Roese /* 16e: Enhanced LED method select */
12392a190aaSAlexey Brodkin phy_write(phydev, MDIO_DEVAD_NONE, 16, 0xe0ea);
124995b72ddSStefan Roese
125995b72ddSStefan Roese /* Disable extended page register access */
12692a190aaSAlexey Brodkin phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0000);
127995b72ddSStefan Roese
128995b72ddSStefan Roese /* Enable clock output pin */
12992a190aaSAlexey Brodkin phy_write(phydev, MDIO_DEVAD_NONE, 18, 0x0049);
130f7c32e8eSStefan Roese }
13192a190aaSAlexey Brodkin
13292a190aaSAlexey Brodkin if (phydev->drv->config)
13392a190aaSAlexey Brodkin phydev->drv->config(phydev);
134995b72ddSStefan Roese
135995b72ddSStefan Roese return 0;
136995b72ddSStefan Roese }
137995b72ddSStefan Roese
board_eth_init(bd_t * bis)138995b72ddSStefan Roese int board_eth_init(bd_t *bis)
139995b72ddSStefan Roese {
140995b72ddSStefan Roese int ret = 0;
141995b72ddSStefan Roese
14292a190aaSAlexey Brodkin if (designware_initialize(CONFIG_SPEAR_ETHBASE,
143995b72ddSStefan Roese PHY_INTERFACE_MODE_GMII) >= 0)
144995b72ddSStefan Roese ret++;
145995b72ddSStefan Roese
146995b72ddSStefan Roese return ret;
147995b72ddSStefan Roese }
148