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