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 enabling modules specified in ti, hw...



details:   https://anonhg.NetBSD.org/src/rev/90c1cc211114
branches:  trunk
changeset: 827404:90c1cc211114
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Thu Oct 26 23:28:14 2017 +0000

description:
Add support for enabling modules specified in ti,hwmods property. Very
primitive am3xxx prcm driver added to validate it, needs work.

diffstat:

 sys/arch/arm/ti/am3_prcm.c |  139 ++++++++++++++++++++++++
 sys/arch/arm/ti/files.ti   |   14 ++-
 sys/arch/arm/ti/ti_com.c   |   14 ++-
 sys/arch/arm/ti/ti_prcm.c  |  257 +++++++++++++++++++++++++++++++++++++++++++++
 sys/arch/arm/ti/ti_prcm.h  |  169 +++++++++++++++++++++++++++++
 sys/arch/evbarm/conf/TI    |    6 +-
 6 files changed, 593 insertions(+), 6 deletions(-)

diffs (truncated from 687 to 300 lines):

diff -r 54986fb0cc2c -r 90c1cc211114 sys/arch/arm/ti/am3_prcm.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/ti/am3_prcm.c        Thu Oct 26 23:28:14 2017 +0000
@@ -0,0 +1,139 @@
+/* $NetBSD: am3_prcm.c,v 1.1 2017/10/26 23:28:15 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * 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(1, "$NetBSD: am3_prcm.c,v 1.1 2017/10/26 23:28:15 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+
+#include <dev/fdt/fdtvar.h>
+
+#define        TI_PRCM_PRIVATE
+#include <arm/ti/ti_prcm.h>
+
+#define        AM3_PRCM_CM_PER         0x0000
+#define        AM3_PRCM_CM_WKUP        0x0400
+#define        AM3_PRCM_CM_DPLL        0x0500
+#define        AM3_PRCM_CM_MPU         0x0600
+#define        AM3_PRCM_CM_DEVICE      0x0700
+#define        AM3_PRCM_CM_RTC         0x0800
+#define        AM3_PRCM_CM_GFX         0x0900
+#define        AM3_PRCM_CM_CEFUSE      0x0a00
+
+#define        AM3_PRCM_CLKCTRL_MODULEMODE             __BITS(1,0)
+#define        AM3_PRCM_CLKCTRL_MODULEMODE_ENABLE      0x2
+
+static int am3_prcm_match(device_t, cfdata_t, void *);
+static void am3_prcm_attach(device_t, device_t, void *);
+
+static int
+am3_prcm_hwmod_enable(struct ti_prcm_softc *sc, struct ti_prcm_clk *tc, int enable)
+{
+       uint32_t val;
+
+       val = PRCM_READ(sc, tc->u.hwmod.reg);
+       val &= ~AM3_PRCM_CLKCTRL_MODULEMODE;
+       if (enable)
+               val |= __SHIFTIN(AM3_PRCM_CLKCTRL_MODULEMODE_ENABLE,
+                                AM3_PRCM_CLKCTRL_MODULEMODE);
+       PRCM_WRITE(sc, tc->u.hwmod.reg, val);
+
+       return 0;
+}
+
+#define        AM3_PRCM_HWMOD_PER(_name, _reg, _parent)        \
+       TI_PRCM_HWMOD((_name), AM3_PRCM_CM_PER + (_reg), (_parent), am3_prcm_hwmod_enable)
+#define        AM3_PRCM_HWMOD_WKUP(_name, _reg, _parent)       \
+       TI_PRCM_HWMOD((_name), AM3_PRCM_CM_WKUP + (_reg), (_parent), am3_prcm_hwmod_enable)
+
+static const char * const compatible[] = {
+       "ti,am3-prcm",
+       NULL
+};
+
+CFATTACH_DECL_NEW(am3_prcm, sizeof(struct ti_prcm_softc),
+       am3_prcm_match, am3_prcm_attach, NULL, NULL);
+
+static struct ti_prcm_clk am3_prcm_clks[] = {
+       /* XXX until we get a proper clock tree */
+       TI_PRCM_FIXED("FIXED_32K", 32768),
+       TI_PRCM_FIXED("FIXED_48MHZ", 48000000),
+       TI_PRCM_FIXED("FIXED_96MHZ", 96000000),
+       TI_PRCM_FIXED_FACTOR("PERIPH_CLK", 1, 1, "FIXED_48MHZ"),
+       TI_PRCM_FIXED_FACTOR("MMC_CLK", 1, 1, "FIXED_96MHZ"),
+
+       AM3_PRCM_HWMOD_PER("uart1", 0x6c, "PERIPH_CLK"),
+       AM3_PRCM_HWMOD_PER("uart2", 0x70, "PERIPH_CLK"),
+       AM3_PRCM_HWMOD_PER("uart3", 0x74, "PERIPH_CLK"),
+       AM3_PRCM_HWMOD_PER("uart4", 0x78, "PERIPH_CLK"),
+       AM3_PRCM_HWMOD_PER("uart5", 0x38, "PERIPH_CLK"),
+
+       AM3_PRCM_HWMOD_WKUP("timer0", 0x10, "FIXED_32K"),
+       AM3_PRCM_HWMOD_PER("timer2", 0x80, "PERIPH_CLK"),
+       AM3_PRCM_HWMOD_PER("timer3", 0x84, "PERIPH_CLK"),
+       AM3_PRCM_HWMOD_PER("timer4", 0x88, "PERIPH_CLK"),
+       AM3_PRCM_HWMOD_PER("timer5", 0xec, "PERIPH_CLK"),
+       AM3_PRCM_HWMOD_PER("timer6", 0xf0, "PERIPH_CLK"),
+       AM3_PRCM_HWMOD_PER("timer7", 0x7c, "PERIPH_CLK"),
+
+       AM3_PRCM_HWMOD_PER("mmc0", 0x3c, "MMC_CLK"),
+       AM3_PRCM_HWMOD_PER("mmc1", 0xf4, "MMC_CLK"),
+       AM3_PRCM_HWMOD_PER("mmc2", 0xf8, "MMC_CLK"),
+};
+
+static int
+am3_prcm_match(device_t parent, cfdata_t cf, void *aux)
+{
+       struct fdt_attach_args * const faa = aux;
+
+       return of_match_compatible(faa->faa_phandle, compatible);
+}
+
+static void
+am3_prcm_attach(device_t parent, device_t self, void *aux)
+{
+       struct ti_prcm_softc * const sc = device_private(self);
+       struct fdt_attach_args * const faa = aux;
+
+       sc->sc_dev = self;
+       sc->sc_phandle = faa->faa_phandle;
+       sc->sc_bst = faa->faa_bst;
+
+       sc->sc_clks = am3_prcm_clks;
+       sc->sc_nclks = __arraycount(am3_prcm_clks);
+
+       if (ti_prcm_attach(sc) != 0)
+               return;
+
+       aprint_naive("\n");
+       aprint_normal(": AM3xxx PRCM\n");
+}
diff -r 54986fb0cc2c -r 90c1cc211114 sys/arch/arm/ti/files.ti
--- a/sys/arch/arm/ti/files.ti  Thu Oct 26 22:45:00 2017 +0000
+++ b/sys/arch/arm/ti/files.ti  Thu Oct 26 23:28:14 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.ti,v 1.1 2017/10/26 01:16:32 jakllsch Exp $
+#      $NetBSD: files.ti,v 1.2 2017/10/26 23:28:15 jmcneill Exp $
 #
 
 include arch/arm/pic/files.pic
@@ -15,11 +15,20 @@
 
 file   arch/arm/ti/ti_platform.c
 
-# interrupt controller
+# Interrupt controller
 device omapintc: pic, pic_splfuncs
 attach  omapintc at fdt
 file   arch/arm/ti/ti_omapintc.c omapintc
 
+# PRCM
+define ti_prcm
+file   arch/arm/ti/ti_prcm.c           ti_prcm
+
+# PRCM (AM3xxx)
+device am3prcm: ti_prcm
+attach am3prcm at fdt with am3_prcm
+file   arch/arm/ti/am3_prcm.c          am3_prcm
+
 # UART
 attach com at fdt with ti_com
 file   arch/arm/ti/ti_com.c    ti_com needs-flag
@@ -29,6 +38,7 @@
 attach  omaptimer at fdt
 file   arch/arm/ti/ti_omaptimer.c      omaptimer
 
+# Ethernet
 device  cpsw: ether, ifnet, arp, mii, mii_phy
 attach  cpsw at fdt
 file    arch/arm/ti/if_cpsw.c                 cpsw
diff -r 54986fb0cc2c -r 90c1cc211114 sys/arch/arm/ti/ti_com.c
--- a/sys/arch/arm/ti/ti_com.c  Thu Oct 26 22:45:00 2017 +0000
+++ b/sys/arch/arm/ti/ti_com.c  Thu Oct 26 23:28:14 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ti_com.c,v 1.2 2017/10/26 10:56:57 jmcneill Exp $ */
+/* $NetBSD: ti_com.c,v 1.3 2017/10/26 23:28:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(1, "$NetBSD: ti_com.c,v 1.2 2017/10/26 10:56:57 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: ti_com.c,v 1.3 2017/10/26 23:28:15 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -42,6 +42,8 @@
 
 #include <dev/fdt/fdtvar.h>
 
+#include <arch/arm/ti/ti_prcm.h>
+
 static int ti_com_match(device_t, cfdata_t, void *);
 static void ti_com_attach(device_t, device_t, void *);
 
@@ -77,6 +79,7 @@
        bus_space_handle_t bsh;
        bus_space_tag_t bst;
        char intrstr[128];
+       struct clk *hwmod;
        bus_addr_t addr;
        bus_size_t size;
        int error;
@@ -103,6 +106,13 @@
                return;
        }
 
+       hwmod = ti_prcm_get_hwmod(phandle, 0);
+       KASSERT(hwmod != NULL);
+       if (clk_enable(hwmod) != 0) {
+               aprint_error(": couldn't enable module\n");
+               return;
+       }
+
        COM_INIT_REGS(sc->sc_regs, bst, bsh, addr);
 
        com_attach_subr(sc);
diff -r 54986fb0cc2c -r 90c1cc211114 sys/arch/arm/ti/ti_prcm.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/ti/ti_prcm.c Thu Oct 26 23:28:14 2017 +0000
@@ -0,0 +1,257 @@
+/* $NetBSD: ti_prcm.c,v 1.1 2017/10/26 23:28:15 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * 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: ti_prcm.c,v 1.1 2017/10/26 23:28:15 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/cpu.h>
+#include <sys/device.h>
+
+#include <dev/fdt/fdtvar.h>
+
+#include <dev/clk/clk_backend.h>
+
+#define        TI_PRCM_PRIVATE
+#include <arm/ti/ti_prcm.h>
+
+static struct ti_prcm_softc *prcm_softc = NULL;
+
+static struct clk *
+ti_prcm_clock_get(void *priv, const char *name)
+{
+       struct ti_prcm_softc * const sc = priv;
+       struct ti_prcm_clk *clk;
+
+       clk = ti_prcm_clock_find(sc, name);
+       if (clk == NULL)
+               return NULL;
+
+       return &clk->base;
+}
+
+static void
+ti_prcm_clock_put(void *priv, struct clk *clk)
+{
+}
+
+static u_int
+ti_prcm_clock_get_rate(void *priv, struct clk *clkp)



Home | Main Index | Thread Index | Old Index