2 * Board functions for Compulab CM-FX6 board
4 * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
6 * Author: Nikita Kiryanov <nikita@compulab.co.il>
8 * SPDX-License-Identifier: GPL-2.0+
12 #include <fsl_esdhc.h>
15 #include <fdt_support.h>
17 #include <asm/arch/crm_regs.h>
18 #include <asm/arch/sys_proto.h>
19 #include <asm/arch/iomux.h>
20 #include <asm/imx-common/mxc_i2c.h>
21 #include <asm/imx-common/sata.h>
25 #include "../common/eeprom.h"
27 DECLARE_GLOBAL_DATA_PTR;
29 #ifdef CONFIG_DWC_AHSATA
30 static int cm_fx6_issd_gpios[] = {
31 /* The order of the GPIOs in the array is important! */
35 CM_FX6_SATA_NSTANDBY1,
36 CM_FX6_SATA_NSTANDBY2,
40 static void cm_fx6_sata_power(int on)
44 if (!on) { /* tell the iSSD that the power will be removed */
45 gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 1);
49 for (i = 0; i < ARRAY_SIZE(cm_fx6_issd_gpios); i++) {
50 gpio_direction_output(cm_fx6_issd_gpios[i], on);
54 if (!on) /* for compatibility lower the power loss interrupt */
55 gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 0);
58 static iomux_v3_cfg_t const sata_pads[] = {
60 IOMUX_PADS(PAD_ENET_TX_EN__GPIO1_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
61 IOMUX_PADS(PAD_EIM_A22__GPIO2_IO16 | MUX_PAD_CTRL(NO_PAD_CTRL)),
62 IOMUX_PADS(PAD_EIM_D20__GPIO3_IO20 | MUX_PAD_CTRL(NO_PAD_CTRL)),
63 IOMUX_PADS(PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
65 IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | MUX_PAD_CTRL(NO_PAD_CTRL)),
66 IOMUX_PADS(PAD_EIM_D23__GPIO3_IO23 | MUX_PAD_CTRL(NO_PAD_CTRL)),
67 IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
68 IOMUX_PADS(PAD_EIM_A23__GPIO6_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
69 IOMUX_PADS(PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NO_PAD_CTRL)),
72 static void cm_fx6_setup_issd(void)
74 SETUP_IOMUX_PADS(sata_pads);
75 /* Make sure this gpio has logical 0 value */
76 gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 0);
84 #define CM_FX6_SATA_INIT_RETRIES 10
85 int sata_initialize(void)
90 for (i = 0; i < CM_FX6_SATA_INIT_RETRIES; i++) {
93 printf("SATA setup failed: %d\n", err);
99 err = __sata_initialize();
103 /* There is no device on the SATA port */
104 if (sata_port_status(0, 0) == 0)
107 /* There's a device, but link not established. Retry */
114 #ifdef CONFIG_SYS_I2C_MXC
115 #define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
116 PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
117 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
120 PAD_EIM_D21__I2C1_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
121 PAD_EIM_D21__GPIO3_IO21 | MUX_PAD_CTRL(I2C_PAD_CTRL),
123 PAD_EIM_D28__I2C1_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
124 PAD_EIM_D28__GPIO3_IO28 | MUX_PAD_CTRL(I2C_PAD_CTRL),
128 PAD_KEY_COL3__I2C2_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
129 PAD_KEY_COL3__GPIO4_IO12 | MUX_PAD_CTRL(I2C_PAD_CTRL),
131 PAD_KEY_ROW3__I2C2_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
132 PAD_KEY_ROW3__GPIO4_IO13 | MUX_PAD_CTRL(I2C_PAD_CTRL),
136 PAD_GPIO_3__I2C3_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
137 PAD_GPIO_3__GPIO1_IO03 | MUX_PAD_CTRL(I2C_PAD_CTRL),
139 PAD_GPIO_6__I2C3_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
140 PAD_GPIO_6__GPIO1_IO06 | MUX_PAD_CTRL(I2C_PAD_CTRL),
144 static void cm_fx6_setup_i2c(void)
146 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, I2C_PADS_INFO(i2c0_pads));
147 setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, I2C_PADS_INFO(i2c1_pads));
148 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, I2C_PADS_INFO(i2c2_pads));
151 static void cm_fx6_setup_i2c(void) { }
154 #ifdef CONFIG_USB_EHCI_MX6
155 #define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \
156 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
157 PAD_CTL_HYS | PAD_CTL_SRE_SLOW)
159 static int cm_fx6_usb_hub_reset(void)
163 err = gpio_request(CM_FX6_USB_HUB_RST, "usb hub rst");
165 printf("USB hub rst gpio request failed: %d\n", err);
169 SETUP_IOMUX_PAD(PAD_SD3_RST__GPIO7_IO08 | MUX_PAD_CTRL(NO_PAD_CTRL));
170 gpio_direction_output(CM_FX6_USB_HUB_RST, 0);
172 gpio_direction_output(CM_FX6_USB_HUB_RST, 1);
178 static int cm_fx6_init_usb_otg(void)
181 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
183 ret = gpio_request(SB_FX6_USB_OTG_PWR, "usb-pwr");
185 printf("USB OTG pwr gpio request failed: %d\n", ret);
189 SETUP_IOMUX_PAD(PAD_EIM_D22__GPIO3_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL));
190 SETUP_IOMUX_PAD(PAD_ENET_RX_ER__USB_OTG_ID |
191 MUX_PAD_CTRL(WEAK_PULLDOWN));
192 clrbits_le32(&iomux->gpr[1], IOMUXC_GPR1_OTG_ID_MASK);
193 /* disable ext. charger detect, or it'll affect signal quality at dp. */
194 return gpio_direction_output(SB_FX6_USB_OTG_PWR, 0);
197 #define MX6_USBNC_BASEADDR 0x2184800
198 #define USBNC_USB_H1_PWR_POL (1 << 9)
199 int board_ehci_hcd_init(int port)
201 u32 *usbnc_usb_uh1_ctrl = (u32 *)(MX6_USBNC_BASEADDR + 4);
205 return cm_fx6_init_usb_otg();
207 SETUP_IOMUX_PAD(PAD_GPIO_0__USB_H1_PWR |
208 MUX_PAD_CTRL(NO_PAD_CTRL));
210 /* Set PWR polarity to match power switch's enable polarity */
211 setbits_le32(usbnc_usb_uh1_ctrl, USBNC_USB_H1_PWR_POL);
212 return cm_fx6_usb_hub_reset();
220 int board_ehci_power(int port, int on)
223 return gpio_direction_output(SB_FX6_USB_OTG_PWR, on);
229 #ifdef CONFIG_FEC_MXC
230 #define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
231 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
233 static int mx6_rgmii_rework(struct phy_device *phydev)
237 /* Ar8031 phy SmartEEE feature cause link status generates glitch,
238 * which cause ethernet link down/up issue, so disable SmartEEE
240 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x3);
241 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x805d);
242 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4003);
243 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
245 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
247 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
248 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
249 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
250 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
252 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
255 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
257 /* introduce tx clock delay */
258 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
259 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
261 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
266 int board_phy_config(struct phy_device *phydev)
268 mx6_rgmii_rework(phydev);
270 if (phydev->drv->config)
271 return phydev->drv->config(phydev);
276 static iomux_v3_cfg_t const enet_pads[] = {
277 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
278 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
279 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
280 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
281 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
282 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
283 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
284 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
285 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
286 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
287 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
288 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
289 IOMUX_PADS(PAD_GPIO_0__CCM_CLKO1 | MUX_PAD_CTRL(NO_PAD_CTRL)),
290 IOMUX_PADS(PAD_GPIO_3__CCM_CLKO2 | MUX_PAD_CTRL(NO_PAD_CTRL)),
291 IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(0x84)),
292 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
293 MUX_PAD_CTRL(ENET_PAD_CTRL)),
294 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
295 MUX_PAD_CTRL(ENET_PAD_CTRL)),
296 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
297 MUX_PAD_CTRL(ENET_PAD_CTRL)),
300 static int handle_mac_address(void)
302 unsigned char enetaddr[6];
305 rc = eth_getenv_enetaddr("ethaddr", enetaddr);
309 rc = cl_eeprom_read_mac_addr(enetaddr);
313 if (!is_valid_ether_addr(enetaddr))
316 return eth_setenv_enetaddr("ethaddr", enetaddr);
319 int board_eth_init(bd_t *bis)
321 int res = handle_mac_address();
323 puts("No MAC address found\n");
325 SETUP_IOMUX_PADS(enet_pads);
327 gpio_direction_output(CM_FX6_ENET_NRST, 0);
329 gpio_set_value(CM_FX6_ENET_NRST, 1);
331 return cpu_eth_init(bis);
335 #ifdef CONFIG_NAND_MXS
336 static iomux_v3_cfg_t const nand_pads[] = {
337 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
338 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
339 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
340 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
341 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
342 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
343 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
344 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
345 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
346 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
347 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
348 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
349 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
350 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
353 static void cm_fx6_setup_gpmi_nand(void)
355 SETUP_IOMUX_PADS(nand_pads);
356 /* Enable clock roots */
357 enable_usdhc_clk(1, 3);
358 enable_usdhc_clk(1, 4);
360 setup_gpmi_io_clk(MXC_CCM_CS2CDR_ENFC_CLK_PODF(0xf) |
361 MXC_CCM_CS2CDR_ENFC_CLK_PRED(1) |
362 MXC_CCM_CS2CDR_ENFC_CLK_SEL(0));
365 static void cm_fx6_setup_gpmi_nand(void) {}
368 #ifdef CONFIG_FSL_ESDHC
369 static struct fsl_esdhc_cfg usdhc_cfg[3] = {
375 static enum mxc_clock usdhc_clk[3] = {
381 int board_mmc_init(bd_t *bis)
385 cm_fx6_set_usdhc_iomux();
386 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
387 usdhc_cfg[i].sdhc_clk = mxc_get_clock(usdhc_clk[i]);
388 usdhc_cfg[i].max_bus_width = 4;
389 fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
390 enable_usdhc_clk(1, i);
397 #ifdef CONFIG_OF_BOARD_SETUP
398 void ft_board_setup(void *blob, bd_t *bd)
403 if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
404 fdt_find_and_setprop(blob, "/fec", "local-mac-address",
412 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
413 cm_fx6_setup_gpmi_nand();
421 puts("Board: CM-FX6\n");
425 void dram_init_banksize(void)
427 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
428 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
430 switch (gd->ram_size) {
431 case 0x10000000: /* DDR_16BIT_256MB */
432 gd->bd->bi_dram[0].size = 0x10000000;
433 gd->bd->bi_dram[1].size = 0;
435 case 0x20000000: /* DDR_32BIT_512MB */
436 gd->bd->bi_dram[0].size = 0x20000000;
437 gd->bd->bi_dram[1].size = 0;
440 if (is_cpu_type(MXC_CPU_MX6SOLO)) { /* DDR_32BIT_1GB */
441 gd->bd->bi_dram[0].size = 0x20000000;
442 gd->bd->bi_dram[1].size = 0x20000000;
443 } else { /* DDR_64BIT_1GB */
444 gd->bd->bi_dram[0].size = 0x40000000;
445 gd->bd->bi_dram[1].size = 0;
448 case 0x80000000: /* DDR_64BIT_2GB */
449 gd->bd->bi_dram[0].size = 0x40000000;
450 gd->bd->bi_dram[1].size = 0x40000000;
452 case 0xEFF00000: /* DDR_64BIT_4GB */
453 gd->bd->bi_dram[0].size = 0x70000000;
454 gd->bd->bi_dram[1].size = 0x7FF00000;
461 gd->ram_size = imx_ddr_size();
462 switch (gd->ram_size) {
469 gd->ram_size -= 0x100000;
472 printf("ERROR: Unsupported DRAM size 0x%lx\n", gd->ram_size);
479 u32 get_board_rev(void)
481 return cl_eeprom_get_board_rev();