common: Drop asm/global_data.h from common header
[platform/kernel/u-boot.git] / board / bluegiga / apx4devkit / apx4devkit.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Bluegiga APX4 Development Kit
4  *
5  * Copyright (C) 2012 Bluegiga Technologies Oy
6  *
7  * Authors:
8  * Veli-Pekka Peltola <veli-pekka.peltola@bluegiga.com>
9  * Lauri Hintsala <lauri.hintsala@bluegiga.com>
10  *
11  * Based on m28evk.c:
12  * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
13  * on behalf of DENX Software Engineering GmbH
14  */
15
16 #include <common.h>
17 #include <init.h>
18 #include <net.h>
19 #include <asm/global_data.h>
20 #include <asm/gpio.h>
21 #include <asm/io.h>
22 #include <asm/setup.h>
23 #include <asm/arch/imx-regs.h>
24 #include <asm/arch/iomux-mx28.h>
25 #include <asm/arch/clock.h>
26 #include <asm/arch/sys_proto.h>
27 #include <env.h>
28 #include <linux/mii.h>
29 #include <miiphy.h>
30 #include <netdev.h>
31 #include <errno.h>
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 /* Functions */
36 int board_early_init_f(void)
37 {
38         /* IO0 clock at 480MHz */
39         mxs_set_ioclk(MXC_IOCLK0, 480000);
40         /* IO1 clock at 480MHz */
41         mxs_set_ioclk(MXC_IOCLK1, 480000);
42
43         /* SSP0 clock at 96MHz */
44         mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
45
46         return 0;
47 }
48
49 int dram_init(void)
50 {
51         return mxs_dram_init();
52 }
53
54 int board_init(void)
55 {
56         /* Adress of boot parameters */
57         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
58
59         return 0;
60 }
61
62 #ifdef CONFIG_CMD_MMC
63 int board_mmc_init(struct bd_info *bis)
64 {
65         return mxsmmc_initialize(bis, 0, NULL, NULL);
66 }
67 #endif
68
69
70 #ifdef CONFIG_CMD_NET
71
72 #define MII_PHY_CTRL2 0x1f
73 int fecmxc_mii_postcall(int phy)
74 {
75         /* change PHY RMII clock to 50MHz */
76         miiphy_write("FEC", 0, MII_PHY_CTRL2, 0x8180);
77
78         return 0;
79 }
80
81 int board_eth_init(struct bd_info *bis)
82 {
83         int ret;
84         struct eth_device *dev;
85
86         ret = cpu_eth_init(bis);
87         if (ret) {
88                 printf("FEC MXS: Unable to init FEC clocks\n");
89                 return ret;
90         }
91
92         ret = fecmxc_initialize(bis);
93         if (ret) {
94                 printf("FEC MXS: Unable to init FEC\n");
95                 return ret;
96         }
97
98         dev = eth_get_dev_by_name("FEC");
99         if (!dev) {
100                 printf("FEC MXS: Unable to get FEC device entry\n");
101                 return -EINVAL;
102         }
103
104         ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
105         if (ret) {
106                 printf("FEC MXS: Unable to register FEC MII postcall\n");
107                 return ret;
108         }
109
110         return ret;
111 }
112 #endif
113
114 #ifdef CONFIG_SERIAL_TAG
115 #define MXS_OCOTP_MAX_TIMEOUT 1000000
116 void get_board_serial(struct tag_serialnr *serialnr)
117 {
118         struct mxs_ocotp_regs *ocotp_regs =
119                 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
120
121         serialnr->high = 0;
122         serialnr->low = 0;
123
124         writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
125
126         if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
127                 MXS_OCOTP_MAX_TIMEOUT)) {
128                 printf("MXS: Can't get serial number from OCOTP\n");
129                 return;
130         }
131
132         serialnr->low = readl(&ocotp_regs->hw_ocotp_cust3);
133 }
134 #endif
135
136 #ifdef CONFIG_REVISION_TAG
137 u32 get_board_rev(void)
138 {
139         if (env_get("revision#") != NULL)
140                 return simple_strtoul(env_get("revision#"), NULL, 10);
141         return 0;
142 }
143 #endif