blob: 681b1eeb49fbb8799825ef3143837f79751c90bb [file] [log] [blame]
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +03001/*
2 * Board functions for Compulab CM-FX6 board
3 *
4 * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
5 *
6 * Author: Nikita Kiryanov <nikita@compulab.co.il>
7 *
8 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11#include <common.h>
12#include <fsl_esdhc.h>
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030013#include <miiphy.h>
14#include <netdev.h>
15#include <fdt_support.h>
Nikita Kiryanov59d06092014-08-20 15:09:01 +030016#include <asm/arch/crm_regs.h>
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +030017#include <asm/arch/sys_proto.h>
Nikita Kiryanov59d06092014-08-20 15:09:01 +030018#include <asm/io.h>
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030019#include <asm/gpio.h>
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +030020#include "common.h"
21
22DECLARE_GLOBAL_DATA_PTR;
23
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030024#ifdef CONFIG_FEC_MXC
25#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
26 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
27
28static int mx6_rgmii_rework(struct phy_device *phydev)
29{
30 unsigned short val;
31
32 /* Ar8031 phy SmartEEE feature cause link status generates glitch,
33 * which cause ethernet link down/up issue, so disable SmartEEE
34 */
35 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x3);
36 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x805d);
37 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4003);
38 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
39 val &= ~(0x1 << 8);
40 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
41
42 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
43 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
44 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
45 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
46
47 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
48 val &= 0xffe3;
49 val |= 0x18;
50 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
51
52 /* introduce tx clock delay */
53 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
54 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
55 val |= 0x0100;
56 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
57
58 return 0;
59}
60
61int board_phy_config(struct phy_device *phydev)
62{
63 mx6_rgmii_rework(phydev);
64
65 if (phydev->drv->config)
66 return phydev->drv->config(phydev);
67
68 return 0;
69}
70
71static iomux_v3_cfg_t const enet_pads[] = {
72 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
73 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
74 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
76 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
77 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
78 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
79 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
80 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
81 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
82 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
83 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
84 IOMUX_PADS(PAD_GPIO_0__CCM_CLKO1 | MUX_PAD_CTRL(NO_PAD_CTRL)),
85 IOMUX_PADS(PAD_GPIO_3__CCM_CLKO2 | MUX_PAD_CTRL(NO_PAD_CTRL)),
86 IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(0x84)),
87 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
88 MUX_PAD_CTRL(ENET_PAD_CTRL)),
89 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
90 MUX_PAD_CTRL(ENET_PAD_CTRL)),
91 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
92 MUX_PAD_CTRL(ENET_PAD_CTRL)),
93};
94
95int board_eth_init(bd_t *bis)
96{
97 SETUP_IOMUX_PADS(enet_pads);
98 /* phy reset */
99 gpio_direction_output(CM_FX6_ENET_NRST, 0);
100 udelay(500);
101 gpio_set_value(CM_FX6_ENET_NRST, 1);
102 enable_enet_clk(1);
103 return cpu_eth_init(bis);
104}
105#endif
106
Nikita Kiryanov59d06092014-08-20 15:09:01 +0300107#ifdef CONFIG_NAND_MXS
108static iomux_v3_cfg_t const nand_pads[] = {
109 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
110 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
111 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
112 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
113 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
114 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
115 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
116 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
117 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
118 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
119 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
120 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
121 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
122 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
123};
124
125static void cm_fx6_setup_gpmi_nand(void)
126{
127 SETUP_IOMUX_PADS(nand_pads);
128 /* Enable clock roots */
129 enable_usdhc_clk(1, 3);
130 enable_usdhc_clk(1, 4);
131
132 setup_gpmi_io_clk(MXC_CCM_CS2CDR_ENFC_CLK_PODF(0xf) |
133 MXC_CCM_CS2CDR_ENFC_CLK_PRED(1) |
134 MXC_CCM_CS2CDR_ENFC_CLK_SEL(0));
135}
136#else
137static void cm_fx6_setup_gpmi_nand(void) {}
138#endif
139
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300140#ifdef CONFIG_FSL_ESDHC
141static struct fsl_esdhc_cfg usdhc_cfg[3] = {
142 {USDHC1_BASE_ADDR},
143 {USDHC2_BASE_ADDR},
144 {USDHC3_BASE_ADDR},
145};
146
147static enum mxc_clock usdhc_clk[3] = {
148 MXC_ESDHC_CLK,
149 MXC_ESDHC2_CLK,
150 MXC_ESDHC3_CLK,
151};
152
153int board_mmc_init(bd_t *bis)
154{
155 int i;
156
157 cm_fx6_set_usdhc_iomux();
158 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
159 usdhc_cfg[i].sdhc_clk = mxc_get_clock(usdhc_clk[i]);
160 usdhc_cfg[i].max_bus_width = 4;
161 fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
162 enable_usdhc_clk(1, i);
163 }
164
165 return 0;
166}
167#endif
168
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300169#ifdef CONFIG_OF_BOARD_SETUP
170void ft_board_setup(void *blob, bd_t *bd)
171{
172 uint8_t enetaddr[6];
173
174 /* MAC addr */
175 if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
176 fdt_find_and_setprop(blob, "/fec", "local-mac-address",
177 enetaddr, 6, 1);
178 }
179}
180#endif
181
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300182int board_init(void)
183{
184 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
Nikita Kiryanov59d06092014-08-20 15:09:01 +0300185 cm_fx6_setup_gpmi_nand();
186
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300187 return 0;
188}
189
190int checkboard(void)
191{
192 puts("Board: CM-FX6\n");
193 return 0;
194}
195
196void dram_init_banksize(void)
197{
198 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
199 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
200
201 switch (gd->ram_size) {
202 case 0x10000000: /* DDR_16BIT_256MB */
203 gd->bd->bi_dram[0].size = 0x10000000;
204 gd->bd->bi_dram[1].size = 0;
205 break;
206 case 0x20000000: /* DDR_32BIT_512MB */
207 gd->bd->bi_dram[0].size = 0x20000000;
208 gd->bd->bi_dram[1].size = 0;
209 break;
210 case 0x40000000:
211 if (is_cpu_type(MXC_CPU_MX6SOLO)) { /* DDR_32BIT_1GB */
212 gd->bd->bi_dram[0].size = 0x20000000;
213 gd->bd->bi_dram[1].size = 0x20000000;
214 } else { /* DDR_64BIT_1GB */
215 gd->bd->bi_dram[0].size = 0x40000000;
216 gd->bd->bi_dram[1].size = 0;
217 }
218 break;
219 case 0x80000000: /* DDR_64BIT_2GB */
220 gd->bd->bi_dram[0].size = 0x40000000;
221 gd->bd->bi_dram[1].size = 0x40000000;
222 break;
223 case 0xEFF00000: /* DDR_64BIT_4GB */
224 gd->bd->bi_dram[0].size = 0x70000000;
225 gd->bd->bi_dram[1].size = 0x7FF00000;
226 break;
227 }
228}
229
230int dram_init(void)
231{
232 gd->ram_size = imx_ddr_size();
233 switch (gd->ram_size) {
234 case 0x10000000:
235 case 0x20000000:
236 case 0x40000000:
237 case 0x80000000:
238 break;
239 case 0xF0000000:
240 gd->ram_size -= 0x100000;
241 break;
242 default:
243 printf("ERROR: Unsupported DRAM size 0x%lx\n", gd->ram_size);
244 return -1;
245 }
246
247 return 0;
248}