70870797bbf113d792fa39eadcefef7936a66b10
[oweals/u-boot.git] / board / ppcag / bg0900 / bg0900.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * PPC-AG BG0900 board
4  *
5  * Copyright (C) 2013 Marek Vasut <marex@denx.de>
6  */
7
8 #include <common.h>
9 #include <init.h>
10 #include <net.h>
11 #include <asm/gpio.h>
12 #include <asm/io.h>
13 #include <asm/arch/imx-regs.h>
14 #include <asm/arch/iomux-mx28.h>
15 #include <asm/arch/clock.h>
16 #include <asm/arch/sys_proto.h>
17 #include <linux/mii.h>
18 #include <miiphy.h>
19 #include <netdev.h>
20 #include <errno.h>
21
22 DECLARE_GLOBAL_DATA_PTR;
23
24 /*
25  * Functions
26  */
27 int board_early_init_f(void)
28 {
29         /* IO0 clock at 480MHz */
30         mxs_set_ioclk(MXC_IOCLK0, 480000);
31         /* IO1 clock at 480MHz */
32         mxs_set_ioclk(MXC_IOCLK1, 480000);
33
34         /* SSP2 clock at 160MHz */
35         mxs_set_sspclk(MXC_SSPCLK2, 160000, 0);
36
37         return 0;
38 }
39
40 int dram_init(void)
41 {
42         return mxs_dram_init();
43 }
44
45 int board_init(void)
46 {
47         /* Adress of boot parameters */
48         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
49
50         return 0;
51 }
52
53 #ifdef CONFIG_CMD_NET
54 int board_eth_init(bd_t *bis)
55 {
56         struct mxs_clkctrl_regs *clkctrl_regs =
57                 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
58         struct eth_device *dev;
59         int ret;
60
61         ret = cpu_eth_init(bis);
62
63         /* BG0900 uses ENET_CLK PAD to drive FEC clock */
64         writel(CLKCTRL_ENET_TIME_SEL_RMII_CLK | CLKCTRL_ENET_CLK_OUT_EN,
65                &clkctrl_regs->hw_clkctrl_enet);
66
67         /* Reset FEC PHYs */
68         gpio_direction_output(MX28_PAD_ENET0_RX_CLK__GPIO_4_13, 0);
69         udelay(200);
70         gpio_set_value(MX28_PAD_ENET0_RX_CLK__GPIO_4_13, 1);
71
72         ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE);
73         if (ret) {
74                 puts("FEC MXS: Unable to init FEC0\n");
75                 return ret;
76         }
77
78         dev = eth_get_dev_by_name("FEC0");
79         if (!dev) {
80                 puts("FEC MXS: Unable to get FEC0 device entry\n");
81                 return -EINVAL;
82         }
83
84         return ret;
85 }
86
87 #endif