summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2018-05-02 15:17:30 +0000
committerpatrick <patrick@openbsd.org>2018-05-02 15:17:30 +0000
commit31051c90324a574d88398246f10ad1f9da0740b9 (patch)
treeb971cdbab98346b7f4920bd97827af8547427d5b
parentImplement a power domain framework to turn on/off so-called power (diff)
downloadwireguard-openbsd-31051c90324a574d88398246f10ad1f9da0740b9.tar.xz
wireguard-openbsd-31051c90324a574d88398246f10ad1f9da0740b9.zip
Add imxpd(4) which is a power domain controller driver that
essentially calls into ATF to make it supply power. ok kettenis@
-rw-r--r--sys/arch/arm64/conf/GENERIC3
-rw-r--r--sys/arch/arm64/conf/RAMDISK3
-rw-r--r--sys/arch/arm64/include/cpufunc.h4
-rw-r--r--sys/dev/fdt/files.fdt6
-rw-r--r--sys/dev/fdt/imxpd.c84
5 files changed, 96 insertions, 4 deletions
diff --git a/sys/arch/arm64/conf/GENERIC b/sys/arch/arm64/conf/GENERIC
index eb3ff619fcf..d7b7dca12bf 100644
--- a/sys/arch/arm64/conf/GENERIC
+++ b/sys/arch/arm64/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.68 2018/04/24 11:23:27 kettenis Exp $
+# $OpenBSD: GENERIC,v 1.69 2018/05/02 15:17:30 patrick Exp $
#
# GENERIC machine description file
#
@@ -98,6 +98,7 @@ imxiic* at fdt?
iic* at imxiic?
imxesdhc* at fdt?
sdmmc* at imxesdhc?
+imxpd* at fdt?
# Raspberry Pi 3
bcmaux* at fdt?
diff --git a/sys/arch/arm64/conf/RAMDISK b/sys/arch/arm64/conf/RAMDISK
index c7b6621994a..1211e7245d9 100644
--- a/sys/arch/arm64/conf/RAMDISK
+++ b/sys/arch/arm64/conf/RAMDISK
@@ -1,4 +1,4 @@
-# $OpenBSD: RAMDISK,v 1.57 2018/04/07 18:31:22 kettenis Exp $
+# $OpenBSD: RAMDISK,v 1.58 2018/05/02 15:17:30 patrick Exp $
#
# GENERIC machine description file
#
@@ -104,6 +104,7 @@ imxiic* at fdt?
iic* at imxiic?
imxesdhc* at fdt?
sdmmc* at imxesdhc?
+imxpd* at fdt?
# Raspberry Pi 3
bcmaux* at fdt?
diff --git a/sys/arch/arm64/include/cpufunc.h b/sys/arch/arm64/include/cpufunc.h
index b8beb85c831..055350a56df 100644
--- a/sys/arch/arm64/include/cpufunc.h
+++ b/sys/arch/arm64/include/cpufunc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpufunc.h,v 1.3 2018/01/10 23:27:18 kettenis Exp $ */
+/* $OpenBSD: cpufunc.h,v 1.4 2018/05/02 15:17:30 patrick Exp $ */
/*-
* Copyright (c) 2014 Andrew Turner
* All rights reserved.
@@ -50,5 +50,7 @@ void cpu_dcache_wbinv_range(vaddr_t, vsize_t);
void cpu_dcache_inv_range(vaddr_t, vsize_t);
void cpu_dcache_wb_range(vaddr_t, vsize_t);
+register_t smc_call(register_t, register_t, register_t, register_t);
+
#endif /* _KERNEL */
#endif /* _MACHINE_CPUFUNC_H_ */
diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt
index 4c58981bb48..995c17ca45a 100644
--- a/sys/dev/fdt/files.fdt
+++ b/sys/dev/fdt/files.fdt
@@ -1,4 +1,4 @@
-# $OpenBSD: files.fdt,v 1.58 2018/04/20 04:37:21 dlg Exp $
+# $OpenBSD: files.fdt,v 1.59 2018/05/02 15:17:30 patrick Exp $
#
# Config file and device description for machine-independent FDT code.
# Included by ports that need it.
@@ -222,6 +222,10 @@ device imxiomuxc
attach imxiomuxc at fdt
file dev/fdt/imxiomuxc.c imxiomuxc
+device imxpd: fdt
+attach imxpd at fdt
+file dev/fdt/imxpd.c imxpd
+
device imxuart
attach imxuart at fdt
file dev/fdt/imxuart.c imxuart
diff --git a/sys/dev/fdt/imxpd.c b/sys/dev/fdt/imxpd.c
new file mode 100644
index 00000000000..caccc3a996b
--- /dev/null
+++ b/sys/dev/fdt/imxpd.c
@@ -0,0 +1,84 @@
+/* $OpenBSD: imxpd.c,v 1.1 2018/05/02 15:17:30 patrick Exp $ */
+/*
+ * Copyright (c) 2018 Patrick Wildt <patrick@blueri.se>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+
+#include <machine/cpufunc.h>
+#include <machine/fdt.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_power.h>
+
+#define FSL_SIP_GPC 0xc2000000
+#define FSL_SIP_CONFIG_GPC_PM_DOMAIN 0x03
+
+struct imxpd_softc {
+ struct device sc_dev;
+ struct power_domain_device sc_pd;
+ int sc_domain_id;
+};
+
+int imxpd_match(struct device *, void *, void *);
+void imxpd_attach(struct device *, struct device *, void *);
+
+void imxpd_enable(void *, uint32_t *, int);
+
+
+struct cfattach imxpd_ca = {
+ sizeof (struct imxpd_softc), imxpd_match, imxpd_attach
+};
+
+struct cfdriver imxpd_cd = {
+ NULL, "imxpd", DV_DULL
+};
+
+int
+imxpd_match(struct device *parent, void *match, void *aux)
+{
+ struct fdt_attach_args *faa = aux;
+
+ return OF_is_compatible(faa->fa_node, "fsl,imx8mq-pm-domain");
+}
+
+void
+imxpd_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct imxpd_softc *sc = (struct imxpd_softc *)self;
+ struct fdt_attach_args *faa = aux;
+
+ sc->sc_domain_id = OF_getpropint(faa->fa_node, "domain-id", 0);
+
+ sc->sc_pd.pd_node = faa->fa_node;
+ sc->sc_pd.pd_cookie = sc;
+ sc->sc_pd.pd_enable = imxpd_enable;
+ power_domain_register(&sc->sc_pd);
+
+ printf("\n");
+}
+
+void
+imxpd_enable(void *cookie, uint32_t *cells, int on)
+{
+ struct imxpd_softc *sc = cookie;
+
+ /* Set up power domain */
+ smc_call(FSL_SIP_GPC, FSL_SIP_CONFIG_GPC_PM_DOMAIN,
+ sc->sc_domain_id, on);
+}