Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/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/gpio.h>
20 #include <asm/io.h>
21 #include <asm/setup.h>
22 #include <asm/arch/imx-regs.h>
23 #include <asm/arch/iomux-mx28.h>
24 #include <asm/arch/clock.h>
25 #include <asm/arch/sys_proto.h>
26 #include <env.h>
27 #include <linux/mii.h>
28 #include <miiphy.h>
29 #include <netdev.h>
30 #include <errno.h>
31
32 DECLARE_GLOBAL_DATA_PTR;
33
34 /* Functions */
35 int board_early_init_f(void)
36 {
37         /* IO0 clock at 480MHz */
38         mxs_set_ioclk(MXC_IOCLK0, 480000);
39         /* IO1 clock at 480MHz */
40         mxs_set_ioclk(MXC_IOCLK1, 480000);
41
42         /* SSP0 clock at 96MHz */
43         mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
44
45         return 0;
46 }
47
48 int dram_init(void)
49 {
50         return mxs_dram_init();
51 }
52
53 int board_init(void)
54 {
55         /* Adress of boot parameters */
56         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
57
58         return 0;
59 }
60
61 #ifdef CONFIG_CMD_MMC
62 int board_mmc_init(bd_t *bis)
63 {
64         return mxsmmc_initialize(bis, 0, NULL, NULL);
65 }
66 #endif
67
68
69 #ifdef CONFIG_CMD_NET
70
71 #define MII_PHY_CTRL2 0x1f
72 int fecmxc_mii_postcall(int phy)
73 {
74         /* change PHY RMII clock to 50MHz */
75         miiphy_write("FEC", 0, MII_PHY_CTRL2, 0x8180);
76
77         return 0;
78 }
79
80 int board_eth_init(bd_t *bis)
81 {
82         int ret;
83         struct eth_device *dev;
84
85         ret = cpu_eth_init(bis);
86         if (ret) {
87                 printf("FEC MXS: Unable to init FEC clocks\n");
88                 return ret;
89         }
90
91         ret = fecmxc_initialize(bis);
92         if (ret) {
93                 printf("FEC MXS: Unable to init FEC\n");
94                 return ret;
95         }
96
97         dev = eth_get_dev_by_name("FEC");
98         if (!dev) {
99                 printf("FEC MXS: Unable to get FEC device entry\n");
100                 return -EINVAL;
101         }
102
103         ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
104         if (ret) {
105                 printf("FEC MXS: Unable to register FEC MII postcall\n");
106                 return ret;
107         }
108
109         return ret;
110 }
111 #endif
112
113 #ifdef CONFIG_SERIAL_TAG
114 #define MXS_OCOTP_MAX_TIMEOUT 1000000
115 void get_board_serial(struct tag_serialnr *serialnr)
116 {
117         struct mxs_ocotp_regs *ocotp_regs =
118                 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
119
120         serialnr->high = 0;
121         serialnr->low = 0;
122
123         writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
124
125         if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
126                 MXS_OCOTP_MAX_TIMEOUT)) {
127                 printf("MXS: Can't get serial number from OCOTP\n");
128                 return;
129         }
130
131         serialnr->low = readl(&ocotp_regs->hw_ocotp_cust3);
132 }
133 #endif
134
135 #ifdef CONFIG_REVISION_TAG
136 u32 get_board_rev(void)
137 {
138         if (env_get("revision#") != NULL)
139                 return simple_strtoul(env_get("revision#"), NULL, 10);
140         return 0;
141 }
142 #endif