Source-Changes-HG archive

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

[src/trunk]: src/sys Add support for NXP i.MX 8M Dual/8M QuadLite/8M Quad fam...



details:   https://anonhg.NetBSD.org/src/rev/004eda611813
branches:  trunk
changeset: 467139:004eda611813
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Wed Jan 15 01:09:56 2020 +0000

description:
Add support for NXP i.MX 8M Dual/8M QuadLite/8M Quad family SoCs.

diffstat:

 sys/arch/arm/imx/fdt/files.imx6             |   26 ++-
 sys/arch/arm/imx/fdt/if_enet_imx.c          |   92 ++++++-
 sys/arch/arm/imx/fdt/imx6_com.c             |   23 +-
 sys/arch/arm/imx/fdt/imx6_gpio.c            |   10 +-
 sys/arch/arm/imx/fdt/imx6_iomux.c           |   22 +-
 sys/arch/arm/imx/fdt/imx6_sdhc.c            |   70 ++++-
 sys/arch/arm/imx/fdt/imx7_gpc.c             |  264 +++++++++++++++++++++++
 sys/arch/arm/imx/fdt/imx8mq_ccm.c           |  194 ++++++++++++++++
 sys/arch/arm/imx/fdt/imx8mq_ccm.h           |  321 ++++++++++++++++++++++++++++
 sys/arch/arm/imx/fdt/imx8mq_usbphy.c        |  184 ++++++++++++++++
 sys/arch/arm/imx/fdt/imx_ccm.c              |  306 ++++++++++++++++++++++++++
 sys/arch/arm/imx/fdt/imx_ccm.h              |  234 ++++++++++++++++++++
 sys/arch/arm/imx/fdt/imx_ccm_composite.c    |  201 +++++++++++++++++
 sys/arch/arm/imx/fdt/imx_ccm_extclk.c       |   99 ++++++++
 sys/arch/arm/imx/fdt/imx_ccm_fixed.c        |   48 ++++
 sys/arch/arm/imx/fdt/imx_ccm_fixed_factor.c |  103 ++++++++
 sys/arch/arm/imx/fdt/imx_ccm_gate.c         |   67 +++++
 sys/arch/arm/imx/if_enet.c                  |    6 +-
 sys/arch/arm/imx/if_enet_imx6.c             |    5 +-
 sys/arch/arm/imx/if_enet_imx7.c             |    5 +-
 sys/arch/arm/imx/if_enetvar.h               |    3 +-
 sys/arch/arm/imx/imx6_board.c               |    6 +-
 sys/arch/arm/imx/imx6_pcie.c                |    8 +-
 sys/arch/arm/imx/imx6_usdhc.c               |    6 +-
 sys/arch/arm/imx/imx7_usdhc.c               |    8 +-
 sys/arch/arm/imx/imxgpio.c                  |   29 +-
 sys/arch/arm/imx/imxgpiovar.h               |   12 +-
 sys/arch/arm/imx/imxuart.c                  |   12 +-
 sys/arch/evbarm/conf/GENERIC64              |   21 +-
 sys/arch/evbarm/conf/files.generic64        |    3 +-
 sys/dev/fdt/dwc3_fdt.c                      |   15 +-
 31 files changed, 2293 insertions(+), 110 deletions(-)

diffs (truncated from 3153 to 300 lines):

diff -r fa1a12f35167 -r 004eda611813 sys/arch/arm/imx/fdt/files.imx6
--- a/sys/arch/arm/imx/fdt/files.imx6   Tue Jan 14 23:13:36 2020 +0000
+++ b/sys/arch/arm/imx/fdt/files.imx6   Wed Jan 15 01:09:56 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.imx6,v 1.7 2019/10/12 06:46:13 skrll Exp $
+#      $NetBSD: files.imx6,v 1.8 2020/01/15 01:09:56 jmcneill Exp $
 #
 # Configuration info for the Freescale i.MX6
 #
@@ -15,11 +15,30 @@
 file   arch/arm/imx/imx6_ccm.c         imxccm
 file   arch/arm/imx/fdt/imx6_clk.c     imxccm
 
+
+# Common FDT clock framework
+define imx_ccm
+file   arch/arm/imx/fdt/imx_ccm.c              imx_ccm
+file   arch/arm/imx/fdt/imx_ccm_extclk.c       imx_ccm
+file   arch/arm/imx/fdt/imx_ccm_gate.c         imx_ccm
+file   arch/arm/imx/fdt/imx_ccm_composite.c    imx_ccm
+file   arch/arm/imx/fdt/imx_ccm_fixed.c        imx_ccm
+file   arch/arm/imx/fdt/imx_ccm_fixed_factor.c imx_ccm
+
+# CCM (iMX8MQ)
+device imx8mqccm: imx_ccm
+attach imx8mqccm at fdt with imx8mq_ccm
+file   arch/arm/imx/fdt/imx8mq_ccm.c   imx8mq_ccm
+
 # GPC
 device imxgpc
 attach imxgpc at fdt
 file   arch/arm/imx/fdt/imx6_gpc.c     imxgpc
 
+device imx7gpc
+attach imx7gpc at fdt
+file   arch/arm/imx/fdt/imx7_gpc.c     imx7gpc
+
 # IOMUX
 device imxiomux
 attach imxiomux at fdt
@@ -61,6 +80,11 @@
 attach imxusbphy at fdt
 file   arch/arm/imx/fdt/imx6_usbphy.c  imxusbphy
 
+device imx8mqusbphy
+attach imx8mqusbphy at fdt
+file   arch/arm/imx/fdt/imx8mq_usbphy.c        imx8mqusbphy
+
+
 # SDMMC
 attach sdhc at fdt with imx6_sdhc
 file   arch/arm/imx/fdt/imx6_sdhc.c    imx6_sdhc
diff -r fa1a12f35167 -r 004eda611813 sys/arch/arm/imx/fdt/if_enet_imx.c
--- a/sys/arch/arm/imx/fdt/if_enet_imx.c        Tue Jan 14 23:13:36 2020 +0000
+++ b/sys/arch/arm/imx/fdt/if_enet_imx.c        Wed Jan 15 01:09:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_enet_imx.c,v 1.8 2019/11/14 06:00:16 hkenken Exp $  */
+/*     $NetBSD: if_enet_imx.c,v 1.9 2020/01/15 01:09:56 jmcneill Exp $ */
 /*-
  * Copyright (c) 2019 Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_enet_imx.c,v 1.8 2019/11/14 06:00:16 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_enet_imx.c,v 1.9 2020/01/15 01:09:56 jmcneill Exp $");
 
 #include "opt_fdt.h"
 
@@ -49,20 +49,24 @@
 CFATTACH_DECL_NEW(enet_fdt, sizeof(struct enet_fdt_softc),
     enet_match, enet_attach, NULL, NULL);
 
-static const char * const compatible[] = {
-       "fsl,imx6q-fec",
-       NULL
+static const struct of_compat_data compat_data[] = {
+       /* compatible                   imxtype */
+       { "fsl,imx6q-fec",              6 },
+       { "fsl,imx6sx-fec",             7 },
+       { NULL }
 };
 
 static int enet_init_clocks(struct enet_softc *);
 static void enet_phy_reset(struct enet_fdt_softc *, const int);
+static int enet_phy_id(struct enet_softc *, const int);
+static void *enet_intr_establish(struct enet_softc *, int, u_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);
+       return of_match_compat_data(faa->faa_phandle, compat_data);
 }
 
 void
@@ -100,12 +104,21 @@
                aprint_error(": couldn't get clock ahb\n");
                goto failure;
        }
-       sc->sc_clk_enet_ref= fdtbus_clock_get(phandle, "ptp");
+       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;
        }
 
+       if (fdtbus_clock_enable(phandle, "enet_clk_ref", false) != 0) {
+               aprint_error(": couldn't enable clock enet_clk_ref\n");
+               goto failure;
+       }
+       if (fdtbus_clock_enable(phandle, "enet_out", false) != 0) {
+               aprint_error(": couldn't enable clock enet_out\n");
+               goto failure;
+       }
+
        aprint_naive("\n");
        aprint_normal(": Gigabit Ethernet Controller\n");
 
@@ -114,8 +127,9 @@
        sc->sc_ioh = bsh;
        sc->sc_dmat = faa->faa_dmat;
 
-       sc->sc_imxtype = 6;     /* i.MX6 */
+       sc->sc_imxtype = of_search_compatible(phandle, compat_data)->data;
        sc->sc_unit = 0;
+       sc->sc_phyid = enet_phy_id(sc, phandle);
 
        const char *phy_mode = fdtbus_get_string(phandle, "phy-mode");
        if (phy_mode == NULL) {
@@ -139,19 +153,16 @@
                sc->sc_rgmii = 0;
        }
 
-       char intrstr[128];
-       if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
-               aprint_error_dev(self, "failed to decode interrupt\n");
+       sc->sc_ih = enet_intr_establish(sc, phandle, 0);
+       if (sc->sc_ih == NULL)
                goto failure;
+
+       if (sc->sc_imxtype == 7) {
+               sc->sc_ih2 = enet_intr_establish(sc, phandle, 1);
+               sc->sc_ih3 = enet_intr_establish(sc, phandle, 2);
+               if (sc->sc_ih2 == NULL || sc->sc_ih3 == NULL)
+                       goto failure;
        }
-       sc->sc_ih = fdtbus_intr_establish(phandle, 0, IPL_NET,
-           FDT_INTR_MPSAFE, 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_clock = clk_get_rate(sc->sc_clk_ipg);
@@ -168,6 +179,29 @@
        return;
 }
 
+static void *
+enet_intr_establish(struct enet_softc *sc, int phandle, u_int index)
+{
+       char intrstr[128];
+       void *ih;
+
+       if (!fdtbus_intr_str(phandle, index, intrstr, sizeof(intrstr))) {
+               aprint_error_dev(sc->sc_dev, "failed to decode interrupt %d\n",
+                   index);
+               return NULL;
+       }
+
+       ih = fdtbus_intr_establish(phandle, index, IPL_NET, 0, enet_intr, sc);
+       if (ih == NULL) {
+               aprint_error_dev(sc->sc_dev, "failed to establish interrupt on %s\n",
+                   intrstr);
+               return NULL;
+       }
+       aprint_normal_dev(sc->sc_dev, "interrupting on %s\n", intrstr);
+
+       return ih;
+}
+
 static int
 enet_init_clocks(struct enet_softc *sc)
 {
@@ -198,8 +232,10 @@
        u_int msec;
 
        sc->sc_pin_reset = fdtbus_gpio_acquire(phandle, "phy-reset-gpios", GPIO_PIN_OUTPUT);
-       if (sc->sc_pin_reset == NULL)
+       if (sc->sc_pin_reset == NULL) {
+               aprint_error_dev(sc->sc_enet.sc_dev, "couldn't find phy reset gpios\n");
                return;
+       }
 
        if (of_getprop_uint32(phandle, "phy-reset-duration", &msec))
                msec = 1;
@@ -215,3 +251,19 @@
 
        delay(msec * 1000);
 }
+
+static int
+enet_phy_id(struct enet_softc *sc, const int phandle)
+{
+       int phy_phandle;
+       bus_addr_t addr;
+
+       phy_phandle = fdtbus_get_phandle(phandle, "phy-handle");
+       if (phy_phandle == -1)
+               return MII_PHY_ANY;
+
+       if (fdtbus_get_reg(phy_phandle, 0, &addr, NULL) != 0)
+               return MII_PHY_ANY;
+
+       return (int)addr;
+}
diff -r fa1a12f35167 -r 004eda611813 sys/arch/arm/imx/fdt/imx6_com.c
--- a/sys/arch/arm/imx/fdt/imx6_com.c   Tue Jan 14 23:13:36 2020 +0000
+++ b/sys/arch/arm/imx/fdt/imx6_com.c   Wed Jan 15 01:09:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_com.c,v 1.2 2019/11/28 14:13:37 hkenken Exp $     */
+/*     $NetBSD: imx6_com.c,v 1.3 2020/01/15 01:09:56 jmcneill Exp $    */
 /*-
  * Copyright (c) 2019 Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx6_com.c,v 1.2 2019/11/28 14:13:37 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imx6_com.c,v 1.3 2020/01/15 01:09:56 jmcneill Exp $");
 
 #include "opt_fdt.h"
 #include "opt_imxuart.h"
@@ -70,6 +70,7 @@
        bus_space_tag_t bst = faa->faa_bst;
        bus_space_handle_t bsh;
        char intrstr[128];
+       struct clk *per;
        bus_addr_t addr;
        bus_size_t size;
 
@@ -83,11 +84,28 @@
                return;
        }
 
+       if (fdtbus_clock_enable(phandle, "ipg", false) != 0) {
+               aprint_error(": couldn't enable ipg clock\n");
+               return;
+       }
+
+       per = fdtbus_clock_get(phandle, "per");
+       if (per != NULL && clk_enable(per) != 0) {
+               aprint_error(": couldn't enable per clock\n");
+               return;
+       }
+
        sc->sc_dev = self;
        regsp->ur_iot = bst;
        regsp->ur_iobase = addr;
        regsp->ur_ioh = bsh;
 
+       if (per != NULL) {
+               aprint_normal(", %u Hz", clk_get_rate(per));
+               /* XXX */
+               imxuart_set_frequency(clk_get_rate(per), 2);
+       }
+
        if (imxuart_is_console(regsp->ur_iot, regsp->ur_iobase, &regsp->ur_ioh))
                aprint_normal(" (console)");
 
@@ -108,7 +126,6 @@
        aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
        imxuart_attach_subr(sc);
-
 }
 
 /*
diff -r fa1a12f35167 -r 004eda611813 sys/arch/arm/imx/fdt/imx6_gpio.c
--- a/sys/arch/arm/imx/fdt/imx6_gpio.c  Tue Jan 14 23:13:36 2020 +0000
+++ b/sys/arch/arm/imx/fdt/imx6_gpio.c  Wed Jan 15 01:09:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imx6_gpio.c,v 1.4 2019/11/27 07:26:08 hkenken Exp $    */
+/*     $NetBSD: imx6_gpio.c,v 1.5 2020/01/15 01:09:56 jmcneill Exp $   */
 /*-
  * Copyright (c) 2019 Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imx6_gpio.c,v 1.4 2019/11/27 07:26:08 hkenken Exp $");



Home | Main Index | Thread Index | Old Index