mx6slevk: Add Ethernet support
authorFabio Estevam <fabio.estevam@freescale.com>
Fri, 13 Sep 2013 03:36:28 +0000 (00:36 -0300)
committerStefano Babic <sbabic@denx.de>
Fri, 20 Sep 2013 15:55:37 +0000 (17:55 +0200)
mx6slevk has a SMSC8720 connected in RMII mode.

Add support for it.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
arch/arm/cpu/armv7/mx6/clock.c
arch/arm/include/asm/arch-mx6/clock.h
arch/arm/include/asm/arch-mx6/iomux.h
arch/arm/include/asm/arch-mx6/mx6sl_pins.h
board/freescale/mx6slevk/mx6slevk.c
include/configs/mx6slevk.h

index 7a29c9b6921e3732cab5fd57530590c194e07e03..010d93208ecb46d71265016c738aa367c2b98116 100644 (file)
@@ -282,6 +282,36 @@ static u32 get_mmdc_ch0_clk(void)
        return freq / (podf + 1);
 
 }
+
+int enable_fec_anatop_clock(void)
+{
+       u32 reg = 0;
+       s32 timeout = 100000;
+
+       struct anatop_regs __iomem *anatop =
+               (struct anatop_regs __iomem *)ANATOP_BASE_ADDR;
+
+       reg = readl(&anatop->pll_enet);
+       if ((reg & BM_ANADIG_PLL_ENET_POWERDOWN) ||
+           (!(reg & BM_ANADIG_PLL_ENET_LOCK))) {
+               reg &= ~BM_ANADIG_PLL_ENET_POWERDOWN;
+               writel(reg, &anatop->pll_enet);
+               while (timeout--) {
+                       if (readl(&anatop->pll_enet) & BM_ANADIG_PLL_ENET_LOCK)
+                               break;
+               }
+               if (timeout < 0)
+                       return -ETIMEDOUT;
+       }
+
+       /* Enable FEC clock */
+       reg |= BM_ANADIG_PLL_ENET_ENABLE;
+       reg &= ~BM_ANADIG_PLL_ENET_BYPASS;
+       writel(reg, &anatop->pll_enet);
+
+       return 0;
+}
+
 #else
 static u32 get_mmdc_ch0_clk(void)
 {
index c49368765b261803e95c15574870b16eb24d5006..93f29a780f56dbe216265691875477714283cdb0 100644 (file)
@@ -50,4 +50,5 @@ void enable_usboh3_clk(unsigned char enable);
 int enable_sata_clock(void);
 int enable_i2c_clk(unsigned char enable, unsigned i2c_num);
 void enable_ipu_clock(void);
+int enable_fec_anatop_clock(void);
 #endif /* __ASM_ARCH_CLOCK_H */
index f4cfd4f92125b7d1b802a602a2570521eb73a35f..ff13a1ea9f27752901d1362d83ca8c8a07fdf73a 100644 (file)
 #define IOMUXC_GPR13_SATA_PHY_2_MASK   (0x1f<<2)
 #define IOMUXC_GPR13_SATA_PHY_1_MASK   (3<<0)
 
+#define IOMUX_GPR1_FEC_CLOCK_MUX1_SEL_MASK (0x3 << 17)
+#define IOMUX_GPR1_FEC_CLOCK_MUX2_SEL_MASK (0x1 << 14)
+#define IOMUX_GPR1_FEC_MASK    (IOMUX_GPR1_FEC_CLOCK_MUX1_SEL_MASK \
+                               | IOMUX_GPR1_FEC_CLOCK_MUX2_SEL_MASK)
+
 #define IOMUXC_GPR13_SATA_PHY_8_RXEQ_0P5DB     (0<<24)
 #define IOMUXC_GPR13_SATA_PHY_8_RXEQ_1P0DB     (1<<24)
 #define IOMUXC_GPR13_SATA_PHY_8_RXEQ_1P5DB     (2<<24)
index b39a354f39568b11ea010ae08485ded610b00f1a..5f9c90ad874a6568049ecdd27a4ea1f4324faa67 100644 (file)
@@ -18,5 +18,17 @@ enum {
        MX6_PAD_SD2_DAT3__USDHC2_DAT3                           = IOMUX_PAD(0x0570, 0x0268, 0, 0x0000, 0, 0),
        MX6_PAD_UART1_RXD__UART1_RXD                            = IOMUX_PAD(0x05A0, 0x0298, 0, 0x07FC, 0, 0),
        MX6_PAD_UART1_TXD__UART1_TXD                            = IOMUX_PAD(0x05A4, 0x029C, 0, 0x0000, 0, 0),
+
+       MX6_PAD_FEC_MDC__FEC_MDC                                = IOMUX_PAD(0x41c, 0x12c, 0, 0x000, 0, 0),
+       MX6_PAD_FEC_MDIO__FEC_MDIO                              = IOMUX_PAD(0x420, 0x130, 0, 0x6f4, 1, 0),
+       MX6_PAD_FEC_CRS_DV__FEC_RX_DV                           = IOMUX_PAD(0x418, 0x128, 0, 0x704, 1, 0),
+       MX6_PAD_FEC_RXD0__FEC_RX_DATA0                          = IOMUX_PAD(0x42c, 0x13c, 0, 0x6f8, 0, 0),
+       MX6_PAD_FEC_RXD1__FEC_RX_DATA1                          = IOMUX_PAD(0x430, 0x140, 0, 0x6fc, 1, 0),
+       MX6_PAD_FEC_TX_EN__FEC_TX_EN                            = IOMUX_PAD(0x438, 0x148, 0, 0x000, 0, 0),
+       MX6_PAD_FEC_TXD0__FEC_TX_DATA0                          = IOMUX_PAD(0x43c, 0x14c, 0, 0x000, 0, 0),
+       MX6_PAD_FEC_TXD1__FEC_TX_DATA1                          = IOMUX_PAD(0x440, 0x150, 0, 0x000, 0, 0),
+       MX6_PAD_FEC_REF_CLK__FEC_REF_OUT                        = IOMUX_PAD(0x424, 0x134, 0x10, 0x000, 0, 0),
+       MX6_PAD_FEC_RX_ER__GPIO_4_19                            = IOMUX_PAD(0x0428, 0x0138, 5, 0x0000, 0, 0),
+       MX6_PAD_FEC_TX_CLK__GPIO_4_21                           = IOMUX_PAD(0x0434, 0x0144, 5, 0x0000, 0, 0),
 };
 #endif /* __ASM_ARCH_MX6_MX6SL_PINS_H__ */
index 5b6ef81a4bc065d8a7b1c03a78431c46723e17c7..643fdac2b36c2044919508915d09cf32d6962d8c 100644 (file)
@@ -18,6 +18,7 @@
 #include <common.h>
 #include <fsl_esdhc.h>
 #include <mmc.h>
+#include <netdev.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -29,6 +30,12 @@ DECLARE_GLOBAL_DATA_PTR;
        PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm |                 \
        PAD_CTL_SRE_FAST  | PAD_CTL_HYS)
 
+#define ENET_PAD_CTRL  (PAD_CTL_PKE | PAD_CTL_PUE |             \
+       PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED   |             \
+       PAD_CTL_DSE_40ohm   | PAD_CTL_HYS)
+
+#define ETH_PHY_RESET  IMX_GPIO_NR(4, 21)
+
 int dram_init(void)
 {
        gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
@@ -50,11 +57,35 @@ static iomux_v3_cfg_t const usdhc2_pads[] = {
        MX6_PAD_SD2_DAT3__USDHC2_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
 };
 
+static iomux_v3_cfg_t const fec_pads[] = {
+       MX6_PAD_FEC_MDC__FEC_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
+       MX6_PAD_FEC_MDIO__FEC_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
+       MX6_PAD_FEC_CRS_DV__FEC_RX_DV | MUX_PAD_CTRL(ENET_PAD_CTRL),
+       MX6_PAD_FEC_RXD0__FEC_RX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
+       MX6_PAD_FEC_RXD1__FEC_RX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
+       MX6_PAD_FEC_TX_EN__FEC_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),
+       MX6_PAD_FEC_TXD0__FEC_TX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
+       MX6_PAD_FEC_TXD1__FEC_TX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
+       MX6_PAD_FEC_REF_CLK__FEC_REF_OUT | MUX_PAD_CTRL(ENET_PAD_CTRL),
+       MX6_PAD_FEC_RX_ER__GPIO_4_19 | MUX_PAD_CTRL(NO_PAD_CTRL),
+       MX6_PAD_FEC_TX_CLK__GPIO_4_21 | MUX_PAD_CTRL(NO_PAD_CTRL),
+};
+
 static void setup_iomux_uart(void)
 {
        imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
 }
 
+static void setup_iomux_fec(void)
+{
+       imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
+
+       /* Reset LAN8720 PHY */
+       gpio_direction_output(ETH_PHY_RESET , 0);
+       udelay(1000);
+       gpio_set_value(ETH_PHY_RESET, 1);
+}
+
 static struct fsl_esdhc_cfg usdhc_cfg[1] = {
        {USDHC2_BASE_ADDR},
 };
@@ -72,6 +103,40 @@ int board_mmc_init(bd_t *bis)
        return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
 }
 
+#ifdef CONFIG_FEC_MXC
+int board_eth_init(bd_t *bis)
+{
+       int ret;
+
+       setup_iomux_fec();
+
+       ret = cpu_eth_init(bis);
+       if (ret) {
+               printf("FEC MXC: %s:failed\n", __func__);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int setup_fec(void)
+{
+       struct iomuxc_base_regs *iomuxc_regs =
+                               (struct iomuxc_base_regs *)IOMUXC_BASE_ADDR;
+       int ret;
+
+       /* clear gpr1[14], gpr1[18:17] to select anatop clock */
+       clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC_MASK, 0);
+
+       ret = enable_fec_anatop_clock();
+       if (ret)
+               return ret;
+
+       return 0;
+}
+#endif
+
+
 int board_early_init_f(void)
 {
        setup_iomux_uart();
@@ -83,6 +148,9 @@ int board_init(void)
        /* address of boot parameters */
        gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
 
+#ifdef CONFIG_FEC_MXC
+       setup_fec();
+#endif
        return 0;
 }
 
index ca8f2f607d9af4631b9c8b31b5ae49d317dcc308..792f17cea4cecfe087bb4e0c381a35ba77246944 100644 (file)
 #define CONFIG_CMD_FAT
 #define CONFIG_DOS_PARTITION
 
+#define CONFIG_CMD_PING
+#define CONFIG_CMD_DHCP
+#define CONFIG_CMD_MII
+#define CONFIG_CMD_NET
+#define CONFIG_FEC_MXC
+#define CONFIG_MII
+#define IMX_FEC_BASE                   ENET_BASE_ADDR
+#define CONFIG_FEC_XCV_TYPE            RMII
+#define CONFIG_ETHPRIME                        "FEC"
+#define CONFIG_FEC_MXC_PHYADDR         0
+
+#define CONFIG_PHYLIB
+#define CONFIG_PHY_SMSC
+
 /* allow to overwrite serial and ethaddr */
 #define CONFIG_ENV_OVERWRITE
 #define CONFIG_CONS_INDEX              1