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