Tuesday, August 12, 2014

FEC ethernet driver on L4 Linux using Freescale imx6 Quad SABRE SD

Welcome document imx6q-fec.patch was made to load FEC ethernet driver on L4 Linux.
Author: Taeung Song <treeze.taeung@gmail.com>, Yeongchann Han <yeongchann@xsinc.co.kr>
Date:   Tue May 15 17:20:18 2014

This patch is 

to change UART2 to UART1 for imx6q sabresd (learned by Ahmed Ammar) and
to fix compile error(fiasco and l4linux),
to modify source related to FEC ethernet. 

diff -uNr a/src/kernel/fiasco/src/kern/arm/bsp/imx/mem_layout-arm-imx.cpp b/src/kernel/fiasco/src/kern/arm/bsp/imx/mem_layout-arm-imx.cpp
--- a/src/kernel/fiasco/src/kern/arm/bsp/imx/mem_layout-arm-imx.cpp 2014-03-01 02:17:42.000000000 +0900
+++ b/src/kernel/fiasco/src/kern/arm/bsp/imx/mem_layout-arm-imx.cpp 2014-05-15 21:12:50.814787510 +0900
@@ -80,6 +80,6 @@
     Gpt_phys_base        = 0x02098000,
     Src_phys_base        = 0x020d8000,
     Uart2_phys_base      = 0x021e8000, // uart2
-    Uart_phys_base       = Uart2_phys_base,
+    Uart_phys_base       = Uart1_phys_base, //imx6q use UART1
   };
 };
diff -uNr a/src/kernel/fiasco/src/kern/arm/bsp/imx/uart-imx.cpp b/src/kernel/fiasco/src/kern/arm/bsp/imx/uart-imx.cpp
--- a/src/kernel/fiasco/src/kern/arm/bsp/imx/uart-imx.cpp   2014-03-01 02:17:42.000000000 +0900
+++ b/src/kernel/fiasco/src/kern/arm/bsp/imx/uart-imx.cpp   2014-05-16 12:21:50.700017375 +0900
@@ -41,7 +41,8 @@

 #include "uart_imx.h"

-IMPLEMENT int Uart::irq() const { return 59; }
+//imx6q uses UART1 which uses (irq=58)
+IMPLEMENT int Uart::irq() const { return 58; }

 IMPLEMENT L4::Uart *Uart::uart()
 {
diff -uNr a/src/kernel/fiasco/src/kern/tb_entry_output.cc b/src/kernel/fiasco/src/kern/tb_entry_output.cc
--- a/src/kernel/fiasco/src/kern/tb_entry_output.cc 2014-03-01 02:17:42.000000000 +0900
+++ b/src/kernel/fiasco/src/kern/tb_entry_output.cc 2014-05-15 18:00:42.338421257 +0900
@@ -110,6 +110,7 @@
 class Tb_entry_ipc_fmt : public Tb_entry_formatter
 {
 public:
+  Tb_entry_ipc_fmt(){};
   void print(String_buffer *, Tb_entry const *) const {}
   Group_order has_partner(Tb_entry const *) const
   { return Tb_entry::Group_order::first(); }
@@ -126,6 +127,7 @@
 class Tb_entry_ipc_res_fmt : public Tb_entry_formatter
 {
 public:
+  Tb_entry_ipc_res_fmt(){};
   void print(String_buffer *, Tb_entry const *) const {}
   Group_order has_partner(Tb_entry const *) const
   { return Tb_entry::Group_order::last(); }
diff -uNr a/src/l4/conf/examples/imx6q.io b/src/l4/conf/examples/imx6q.io
--- a/src/l4/conf/examples/imx6q.io 1970-01-01 09:00:00.000000000 +0900
+++ b/src/l4/conf/examples/imx6q.io 2014-05-15 22:06:12.586889228 +0900
@@ -0,0 +1,22 @@
+hw-root
+{
+  NIC => new Device()
+  {
+    .hid = "imx6q-fec.0";
+    new-res Mmio(0x02188000 .. 0x0218BFFF);
+    new-res Irq(150);
+    new-res Irq(151);
+  }
+
+  DMAMEM => new Device()
+  {
+    .hid = "dmamem";
+    new-res Mmio_ram(0x80000, 0);
+  }
+}
+
+l4linux => new System_bus()
+{
+  "imx6q-fec.dev" => wrap(hw-root.NIC);
+  "dmamem" => wrap(hw-root.DMAMEM);
+} 
diff -uNr a/src/l4/conf/examples/l4lx-imx6q.cfg b/src/l4/conf/examples/l4lx-imx6q.cfg
--- a/src/l4/conf/examples/l4lx-imx6q.cfg   1970-01-01 09:00:00.000000000 +0900
+++ b/src/l4/conf/examples/l4lx-imx6q.cfg   2014-05-15 22:06:02.202888898 +0900
@@ -0,0 +1,30 @@
+-- vim:set ft=lua:
+
+loader = L4.default_loader;
+vbus_l4linux = loader:new_channel();
+
+local lxname = "vmlinuz";
+if L4.Info.arch() == "arm" then
+  lxname = "vmlinuz.arm";
+end
+
+loader:start(
+{
+   caps = {
+       sigma0  = L4.cast(L4.Proto.Factory, L4.Env.sigma0):create(L4.Proto.Sigma0);
+       icu     = L4.Env.icu;
+        l4linux = vbus_l4linux:svr();
+   },
+   log      = { "IO", "y" },
+   l4re_dbg = L4.Dbg.Warn,
+},"rom/io -vvv rom/imx6q.io");
+
+L4.default_loader:start(
+  { caps = {
+      vbus = vbus_l4linux; 
+      log = L4.Env.log:m("rws"),
+    },
+    l4re_dbg = L4.Dbg.Warn,
+    log = { "l4linux", "yellow" },
+  },
+  "rom/" .. lxname .. " mem=64M console=ttyLv0 l4x_rd=rom/ramdisk-" ..  L4.Info.arch() .. ".rd root=1:0 ramdisk_size=4000 ip=dhcp init=/bin/sh");
diff -uNr a/src/l4/conf/modules.list b/src/l4/conf/modules.list
--- a/src/l4/conf/modules.list  2014-03-01 02:17:42.000000000 +0900
+++ b/src/l4/conf/modules.list  2014-05-15 21:53:32.966865095 +0900
@@ -88,6 +88,16 @@
 module vmlinuz.arm
 module ramdisk-arm.rd

+entry L4Linux-imx6q
+roottask moe rom/l4lx-imx6q.cfg
+module l4re
+module ned
+module l4lx-imx6q.cfg
+module io
+module imx6q.io
+module vmlinuz.arm
+module ramdisk-arm.rd
+
 entry L4Linux-mag-x86
 roottask moe rom/l4lx-gfx.cfg
 module l4re
diff -uNr a/src/l4/pkg/bootstrap/server/src/platform/imx.cc b/src/l4/pkg/bootstrap/server/src/platform/imx.cc
--- a/src/l4/pkg/bootstrap/server/src/platform/imx.cc   2014-03-01 02:17:42.000000000 +0900
+++ b/src/l4/pkg/bootstrap/server/src/platform/imx.cc   2014-05-15 21:12:02.030785960 +0900
@@ -37,8 +37,9 @@
     static L4::Io_register_block_mmio r(0x73fbc000);
     static L4::Uart_imx51 _uart;
 #elif defined(PLATFORM_TYPE_imx6)
-    //static L4::Io_register_block_mmio r(0x02020000); // UART1
-    static L4::Io_register_block_mmio r(0x021e8000); // UART2
+    //imx6q use UART1
+    static L4::Io_register_block_mmio r(0x02020000); // UART1
+    //static L4::Io_register_block_mmio r(0x021e8000); // UART2
     static L4::Uart_imx6 _uart;
 #else
 #error Which platform type?
diff -uNr a/src/l4linux/arch/l4/Kconfig b/src/l4linux/arch/l4/Kconfig
--- a/src/l4linux/arch/l4/Kconfig   2014-03-01 02:17:42.000000000 +0900
+++ b/src/l4linux/arch/l4/Kconfig   2014-05-16 15:31:04.448378077 +0900
@@ -63,16 +63,20 @@
    config L4_PLATFORM_GENERIC
        bool "Generic"
        select CLKDEV_LOOKUP
-       select L4_CLK_NOOP
+       select HAVE_CLK_PREPARE
+       select HAVE_MACH_CLKDEV
+       select COMMON_CLK

    config L4_PLATFORM_REALVIEW
        bool "Realview"
        select CLKDEV_LOOKUP
        select OUTER_CACHE
-       select L4_CLK_NOOP

 endchoice

+config L4_CLK_NOOP
+   bool "L4 Clock Noop"
+   depends on (L4_PLATFORM_GENERIC || L4_PLATFORM_REALVIEW)

 menu "Features"

diff -uNr a/src/l4linux/arch/l4/kernel/arch-arm/mach_setup.c b/src/l4linux/arch/l4/kernel/arch-arm/mach_setup.c
--- a/src/l4linux/arch/l4/kernel/arch-arm/mach_setup.c  2014-03-01 02:17:42.000000000 +0900
+++ b/src/l4linux/arch/l4/kernel/arch-arm/mach_setup.c  2014-05-16 12:20:05.428014031 +0900
@@ -5,6 +5,7 @@
 #include <linux/platform_device.h>
 #include <linux/ata_platform.h>
 #include <linux/smsc911x.h>
+#include <linux/fec.h>
 #include <linux/slab.h>
 #include <linux/list.h>

@@ -228,6 +229,74 @@
 }
 #endif

+static struct resource imx6q_fec_resources[] = {
+   {
+       .start = 0x02188000,
+       .end = 0x0218BFFF,
+       .name = "imx6q-fec mem",
+       .flags = IORESOURCE_MEM
+   },
+   {
+       .start = 150,
+       .end = 151,
+       .name = "imx6q-fec irq",
+       .flags = IORESOURCE_IRQ
+   }
+};
+
+static struct fec_platform_data imx6q_fec_pd = {
+   .phy = PHY_INTERFACE_MODE_RGMII
+};
+
+static struct platform_device imx6q_fec_dev = {
+   .name = "imx6q-fec",
+   .id = 0,
+   .resource = imx6q_fec_resources,
+   .num_resources = ARRAY_SIZE(imx6q_fec_resources),
+   .dev = {
+       .platform_data = &imx6q_fec_pd,
+   },
+};
+
+static int ar8031_phy_fixup(struct phy_device *dev)
+{
+   u16 val;
+
+   /* To enable AR8031 output a 125MHz clk from CLK_25M */
+   phy_write(dev, 0xd, 0x7);
+   phy_write(dev, 0xe, 0x8016);
+   phy_write(dev, 0xd, 0x4007);
+
+   val = phy_read(dev, 0xe);
+   val &= 0xffe3;
+   val |= 0x18;
+   phy_write(dev, 0xe, val);
+
+   /* introduce tx clock delay */
+   phy_write(dev, 0x1d, 0x5);
+   val = phy_read(dev, 0x1e);
+   val |= 0x0100;
+   phy_write(dev, 0x1e, val);
+
+   return 0;
+}
+
+#define PHY_ID_AR8031  0x004dd074
+
+static void __init imx6q_enet_phy_init(void)
+{
+   if (IS_BUILTIN(CONFIG_PHYLIB)) {
+       phy_register_fixup_for_uid(PHY_ID_AR8031, 0xffffffff,
+               ar8031_phy_fixup);
+   }
+}
+
+static L4X_DEVICE_CB(imx6q_device_cb_fec)
+{
+   platform_device_register(&imx6q_fec_dev);
+   imx6q_enet_phy_init();
+}
+
 static void register_platform_callbacks(void)
 {
 #ifdef CONFIG_L4_DMAPOOL
@@ -239,6 +308,7 @@
    l4x_register_platform_device_callback("smsc911x",     realview_device_cb_smsc);
    l4x_register_platform_device_callback("aaci",         aaci_cb);
 #endif
+   l4x_register_platform_device_callback("imx6q-fec.dev",imx6q_device_cb_fec);
 }

 static void
diff -uNr a/src/l4linux/drivers/net/ethernet/freescale/fec.h b/src/l4linux/drivers/net/ethernet/freescale/fec.h
--- a/src/l4linux/drivers/net/ethernet/freescale/fec.h  2014-03-01 02:17:42.000000000 +0900
+++ b/src/l4linux/drivers/net/ethernet/freescale/fec.h  2014-05-15 18:31:45.018480434 +0900
@@ -19,7 +19,7 @@

 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
     defined(CONFIG_M520x) || defined(CONFIG_M532x) || \
-    defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
+    defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28) || CONFIG_L4
 /*
  * Just figures, Motorola would have to change the offsets for
  * registers in the same peripheral device on different models
@@ -147,7 +147,7 @@
 /*
  * Define the buffer descriptor structure.
  */
-#if defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
+#if defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28) || defined(CONFIG_L4)
 struct bufdesc {
    unsigned short cbd_datlen;  /* Data length */
    unsigned short cbd_sc;  /* Control and status info */
diff -uNr a/src/l4linux/drivers/net/ethernet/freescale/fec_main.c b/src/l4linux/drivers/net/ethernet/freescale/fec_main.c
--- a/src/l4linux/drivers/net/ethernet/freescale/fec_main.c 2014-03-01 02:17:42.000000000 +0900
+++ b/src/l4linux/drivers/net/ethernet/freescale/fec_main.c 2014-05-15 18:31:07.446479240 +0900
@@ -60,6 +60,11 @@

 #include "fec.h"

+#ifdef CONFIG_L4
+//ahb clock
+#define clk_get_rate(x)                132000000
+#endif
+
 static void set_multicast_list(struct net_device *ndev);

 #if defined(CONFIG_ARM)
@@ -2138,6 +2143,15 @@
        fep->phy_interface = ret;
    }

+   #ifdef CONFIG_L4
+       //Do no setup Clocks or regulator
+       fep->clk_ahb = NULL;
+       fep->clk_ipg = NULL;
+       fep->clk_enet_out = NULL;
+       fep->clk_ptp = NULL;
+       fep->reg_phy = NULL;
+   #else
+
    fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
    if (IS_ERR(fep->clk_ipg)) {
        ret = PTR_ERR(fep->clk_ipg);
@@ -2195,6 +2209,8 @@
        fep->reg_phy = NULL;
    }

+   #endif
+
    fec_reset_phy(pdev);

    if (fep->bufdesc_ex)
diff -uNr a/src/l4linux/drivers/net/ethernet/freescale/fec_ptp.c b/src/l4linux/drivers/net/ethernet/freescale/fec_ptp.c
--- a/src/l4linux/drivers/net/ethernet/freescale/fec_ptp.c  2014-03-01 02:17:42.000000000 +0900
+++ b/src/l4linux/drivers/net/ethernet/freescale/fec_ptp.c  2014-05-15 18:30:38.826478331 +0900
@@ -49,6 +49,9 @@

 #include "fec.h"

+//ahb clock
+#define clk_get_rate(x)                132000000
+
 /* FEC 1588 register bits */
 #define FEC_T_CTRL_SLAVE                0x00002000
 #define FEC_T_CTRL_CAPTURE              0x00000800
diff -uNr a/src/l4linux/drivers/net/ethernet/freescale/Kconfig b/src/l4linux/drivers/net/ethernet/freescale/Kconfig
--- a/src/l4linux/drivers/net/ethernet/freescale/Kconfig    2014-03-01 02:17:42.000000000 +0900
+++ b/src/l4linux/drivers/net/ethernet/freescale/Kconfig    2014-05-15 18:33:37.014483992 +0900
@@ -7,7 +7,7 @@
    default y
    depends on FSL_SOC || QUICC_ENGINE || CPM1 || CPM2 || PPC_MPC512x || \
           M523x || M527x || M5272 || M528x || M520x || M532x || \
-          ARCH_MXC || ARCH_MXS || (PPC_MPC52xx && PPC_BESTCOMM)
+          ARCH_MXC || ARCH_MXS || (PPC_MPC52xx && PPC_BESTCOMM) || L4 
    ---help---
      If you have a network (Ethernet) card belonging to this class, say Y
      and read the Ethernet-HOWTO, available from
@@ -23,7 +23,7 @@
 config FEC
    tristate "FEC ethernet controller (of ColdFire and some i.MX CPUs)"
    depends on (M523x || M527x || M5272 || M528x || M520x || M532x || \
-          ARCH_MXC || SOC_IMX28)
+          ARCH_MXC || SOC_IMX28) || L4 
    default ARCH_MXC || SOC_IMX28 if ARM
    select PHYLIB
    select PTP_1588_CLOCK

No comments:

Post a Comment