Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Add support for device tree.



details:   https://anonhg.NetBSD.org/src/rev/c1c4ec4e3267
branches:  trunk
changeset: 1000409:c1c4ec4e3267
user:      hkenken <hkenken%NetBSD.org@localhost>
date:      Wed Jul 24 13:12:33 2019 +0000

description:
Add support for device tree.

+ CCM (clk)
+ COM (uart)
+ GPIO
+ IOMUX (pin control)
+ PCIe
+ SDHC
+ USB Host
+ USB phy

diffstat:

 sys/arch/arm/imx/fdt/files.imx6      |   80 +++++
 sys/arch/arm/imx/fdt/if_enet_imx.c   |  173 ++++++++++++
 sys/arch/arm/imx/fdt/imx6_ahcisata.c |  480 +++++++++++++++++++++++++++++++++++
 sys/arch/arm/imx/fdt/imx6_clk.c      |  141 ++++++++++
 sys/arch/arm/imx/fdt/imx6_com.c      |  148 ++++++++++
 sys/arch/arm/imx/fdt/imx6_gpc.c      |  158 +++++++++++
 sys/arch/arm/imx/fdt/imx6_gpio.c     |  274 +++++++++++++++++++
 sys/arch/arm/imx/fdt/imx6_iomux.c    |  178 ++++++++++++
 sys/arch/arm/imx/fdt/imx6_pcie.c     |  248 ++++++++++++++++++
 sys/arch/arm/imx/fdt/imx6_platform.c |  200 ++++++++++++++
 sys/arch/arm/imx/fdt/imx6_platform.h |   35 ++
 sys/arch/arm/imx/fdt/imx6_sdhc.c     |  191 +++++++++++++
 sys/arch/arm/imx/fdt/imx6_usb.c      |  277 ++++++++++++++++++++
 sys/arch/arm/imx/fdt/imx6_usbphy.c   |  163 +++++++++++
 sys/arch/arm/imx/imx6_gpcreg.h       |   41 ++
 sys/arch/evbarm/conf/IMX             |  134 +++++++++
 sys/arch/evbarm/conf/files.imx       |   12 +
 sys/arch/evbarm/conf/mk.imx          |   34 ++
 sys/arch/evbarm/conf/std.imx         |   32 ++
 19 files changed, 2999 insertions(+), 0 deletions(-)

diffs (truncated from 3075 to 300 lines):

diff -r 02a36323d5a4 -r c1c4ec4e3267 sys/arch/arm/imx/fdt/files.imx6
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/imx/fdt/files.imx6   Wed Jul 24 13:12:33 2019 +0000
@@ -0,0 +1,80 @@
+#      $NetBSD: files.imx6,v 1.1 2019/07/24 13:12:33 hkenken Exp $
+#
+# Configuration info for the Freescale i.MX6
+#
+
+file   arch/arm/arm32/arm32_boot.c
+file   arch/arm/arm32/arm32_kvminit.c
+file   arch/arm/arm32/arm32_reboot.c
+file   arch/arm/arm32/irq_dispatch.S
+file   arch/arm/arm32/armv7_generic_space.c
+file   arch/arm/arm/arm_generic_dma.c
+file   arch/arm/arm/bus_space_a4x.S
+
+file   arch/arm/imx/fdt/imx6_platform.c        soc_imx
+
+# SOC parameters
+defflag        opt_soc.h                       SOC_IMX
+defflag        opt_soc.h                       SOC_IMX6QDL: SOC_IMX
+
+# Clock
+device imxccm : clk
+attach imxccm at fdt
+file   arch/arm/imx/imx6_ccm.c         imxccm
+file   arch/arm/imx/fdt/imx6_clk.c     imxccm
+
+# GPC
+device imxgpc
+attach imxgpc at fdt
+file   arch/arm/imx/fdt/imx6_gpc.c     imxgpc
+
+# IOMUX
+device imxiomux
+attach imxiomux at fdt
+file   arch/arm/imx/fdt/imx6_iomux.c   imxiomux
+
+# GPIO controller
+device imxgpio: gpiobus
+attach imxgpio at fdt
+file   arch/arm/imx/imxgpio.c          imxgpio
+file   arch/arm/imx/fdt/imx6_gpio.c    imxgpio
+
+# UART
+device imxuart { } : bus_space_generic
+attach imxuart at fdt with imx6_com
+file   arch/arm/imx/imxuart.c          imxuart needs-flag
+file   arch/arm/imx/fdt/imx6_com.c     imx6_com needs-flag
+defflag opt_imxuart.h                  IMXUARTCONSOLE
+
+# FEC
+device enet: ether, ifnet, arp, mii, bus_dma_generic
+attach enet at fdt
+file   arch/arm/imx/if_enet.c          enet
+file   arch/arm/imx/fdt/if_enet_imx.c  enet
+
+# SATA
+attach ahcisata at fdt with imx6_ahcisata
+file   arch/arm/imx/fdt/imx6_ahcisata.c        imx6_ahcisata
+
+# USB Controller
+device imxusbc { [unit=-1], [irq=-1] } : bus_dma_generic
+attach imxusbc at fdt with imxusbc_fdt
+file   arch/arm/imx/fdt/imx6_usb.c             imxusbc_fdt
+
+attach ehci at imxusbc with imxehci
+file   arch/arm/imx/imxusb.c                   imxehci
+
+# USB PHY
+device imxusbphy
+attach imxusbphy at fdt
+file   arch/arm/imx/fdt/imx6_usbphy.c  imxusbphy
+
+# SDMMC
+attach sdhc at fdt with imx6_sdhc
+file   arch/arm/imx/fdt/imx6_sdhc.c    imx6_sdhc
+
+# PCIe
+device imxpcie: pcibus
+attach imxpcie at fdt with imxpcie_fdt
+file   arch/arm/imx/imxpcie.c                  imxpcie
+file   arch/arm/imx/fdt/imx6_pcie.c            imxpcie_fdt
diff -r 02a36323d5a4 -r c1c4ec4e3267 sys/arch/arm/imx/fdt/if_enet_imx.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/imx/fdt/if_enet_imx.c        Wed Jul 24 13:12:33 2019 +0000
@@ -0,0 +1,173 @@
+/*     $NetBSD: if_enet_imx.c,v 1.1 2019/07/24 13:12:33 hkenken Exp $  */
+/*-
+ * Copyright (c) 2019 Genetec Corporation.  All rights reserved.
+ * Written by Hashimoto Kenichi for Genetec Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_enet_imx.c,v 1.1 2019/07/24 13:12:33 hkenken Exp $");
+
+#include "opt_fdt.h"
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+
+#include <arm/imx/imx6var.h>
+#include <arm/imx/imx6_reg.h>
+#include <arm/imx/if_enetreg.h>
+#include <arm/imx/if_enetvar.h>
+
+#include <dev/fdt/fdtvar.h>
+
+static const char * const compatible[] = {
+       "fsl,imx6q-fec",
+       NULL
+};
+
+static int enet_init_clocks(struct enet_softc *);
+static void enet_phy_reset(const int);
+
+int
+enet_match(device_t parent, cfdata_t cf, void *aux)
+{
+       struct fdt_attach_args * const faa = aux;
+
+       return of_match_compatible(faa->faa_phandle, compatible);
+}
+
+void
+enet_attach(device_t parent, device_t self, void *aux)
+{
+       struct enet_softc *sc = device_private(self);
+       struct fdt_attach_args * const faa = aux;
+       const int phandle = faa->faa_phandle;
+       bus_space_tag_t bst = faa->faa_bst;
+       bus_space_handle_t bsh;
+       bus_addr_t addr;
+       bus_size_t size;
+       int error;
+
+       if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
+               aprint_error(": couldn't get enet registers\n");
+               return;
+       }
+
+       error = bus_space_map(bst, addr, size, 0, &bsh);
+       if (error) {
+               aprint_error(": couldn't map enet registers: %d\n", error);
+               return;
+       }
+
+       sc->sc_clk_enet = fdtbus_clock_get(phandle, "ahb");
+       if (sc->sc_clk_enet == NULL) {
+               aprint_error(": couldn't get clock ahb\n");
+               goto failure;
+       }
+       sc->sc_clk_enet_ref= fdtbus_clock_get(phandle, "ptp");
+       if (sc->sc_clk_enet_ref == NULL) {
+               aprint_error(": couldn't get clock ptp\n");
+               goto failure;
+       }
+
+       aprint_naive("\n");
+       aprint_normal(": Gigabit Ethernet Controller\n");
+
+       enet_phy_reset(phandle);
+
+       sc->sc_dev = self;
+       sc->sc_iot = bst;
+       sc->sc_ioh = bsh;
+       sc->sc_dmat = faa->faa_dmat;
+
+       sc->sc_imxtype = 6;     /* i.MX6 */
+       sc->sc_rgmii = 1;
+
+       char intrstr[128];
+       if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
+               aprint_error_dev(self, "failed to decode interrupt\n");
+               goto failure;
+       }
+       sc->sc_ih = fdtbus_intr_establish(phandle, 0, IPL_NET, 0,
+           enet_intr, sc);
+       if (sc->sc_ih == NULL) {
+               aprint_error_dev(self, "failed to establish interrupt on %s\n",
+                   intrstr);
+               goto failure;
+       }
+       aprint_normal_dev(self, "interrupting on %s\n", intrstr);
+
+       enet_init_clocks(sc);
+       sc->sc_pllclock = clk_get_rate(sc->sc_clk_enet);
+
+       if (enet_attach_common(self) != 0)
+               goto failure;
+
+       return;
+
+failure:
+       bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
+       return;
+}
+
+static int
+enet_init_clocks(struct enet_softc *sc)
+{
+       int error;
+
+       error = clk_enable(sc->sc_clk_enet);
+       if (error) {
+               aprint_error_dev(sc->sc_dev, "couldn't enable enet: %d\n", error);
+               return error;
+       }
+       error = clk_enable(sc->sc_clk_enet_ref);
+       if (error) {
+               aprint_error_dev(sc->sc_dev, "couldn't enable enet_ref: %d\n", error);
+               return error;
+       }
+
+       return 0;
+}
+
+static void
+enet_phy_reset(const int phandle)
+{
+       struct fdtbus_gpio_pin *reset;
+       int error;
+
+       reset = fdtbus_gpio_acquire(phandle, "phy-reset-gpios", GPIO_PIN_OUTPUT);
+       if (reset == NULL)
+               return;
+
+       u_int msec;
+       error = of_getprop_uint32(phandle, "phy-reset-duration", &msec);
+       if (error)
+               msec = 1;
+
+       /* Reset */
+       fdtbus_gpio_write(reset, 1);
+       delay(msec * 1000);
+       fdtbus_gpio_write(reset, 0);
+
+       fdtbus_gpio_release(reset);
+}
diff -r 02a36323d5a4 -r c1c4ec4e3267 sys/arch/arm/imx/fdt/imx6_ahcisata.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/imx/fdt/imx6_ahcisata.c      Wed Jul 24 13:12:33 2019 +0000
@@ -0,0 +1,480 @@
+/*     $NetBSD: imx6_ahcisata.c,v 1.1 2019/07/24 13:12:33 hkenken Exp $        */
+/*-
+ * Copyright (c) 2019 Genetec Corporation.  All rights reserved.
+ * Written by Hashimoto Kenichi for Genetec Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: imx6_ahcisata.c,v 1.1 2019/07/24 13:12:33 hkenken Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/intr.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>



Home | Main Index | Thread Index | Old Index