summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/arm64/conf/files.arm643
-rw-r--r--sys/arch/armv7/conf/files.armv73
-rw-r--r--sys/dev/ofw/ofw_power.c106
-rw-r--r--sys/dev/ofw/ofw_power.h36
4 files changed, 146 insertions, 2 deletions
diff --git a/sys/arch/arm64/conf/files.arm64 b/sys/arch/arm64/conf/files.arm64
index 9aa00165995..9b840ba9190 100644
--- a/sys/arch/arm64/conf/files.arm64
+++ b/sys/arch/arm64/conf/files.arm64
@@ -1,4 +1,4 @@
-# $OpenBSD: files.arm64,v 1.19 2018/02/15 00:03:06 jsg Exp $
+# $OpenBSD: files.arm64,v 1.20 2018/05/02 15:16:31 patrick Exp $
maxpartitions 16
maxusers 2 8 64
@@ -68,6 +68,7 @@ file dev/ofw/ofw_clock.c
file dev/ofw/ofw_gpio.c
file dev/ofw/ofw_misc.c
file dev/ofw/ofw_pinctrl.c
+file dev/ofw/ofw_power.c
file dev/ofw/ofw_regulator.c
# Machine-independent SCSI drivers
diff --git a/sys/arch/armv7/conf/files.armv7 b/sys/arch/armv7/conf/files.armv7
index cc2cf356dce..429d93b5428 100644
--- a/sys/arch/armv7/conf/files.armv7
+++ b/sys/arch/armv7/conf/files.armv7
@@ -1,4 +1,4 @@
-# $OpenBSD: files.armv7,v 1.33 2017/06/14 13:12:49 patrick Exp $
+# $OpenBSD: files.armv7,v 1.34 2018/05/02 15:16:31 patrick Exp $
maxpartitions 16
maxusers 2 8 64
@@ -31,6 +31,7 @@ file dev/ofw/ofw_clock.c
file dev/ofw/ofw_gpio.c
file dev/ofw/ofw_misc.c
file dev/ofw/ofw_pinctrl.c
+file dev/ofw/ofw_power.c
file dev/ofw/ofw_regulator.c
include "dev/sdmmc/files.sdmmc"
diff --git a/sys/dev/ofw/ofw_power.c b/sys/dev/ofw/ofw_power.c
new file mode 100644
index 00000000000..96aa74dd929
--- /dev/null
+++ b/sys/dev/ofw/ofw_power.c
@@ -0,0 +1,106 @@
+/* $OpenBSD: ofw_power.c,v 1.1 2018/05/02 15:16:31 patrick Exp $ */
+/*
+ * Copyright (c) 2016 Mark Kettenis
+ * 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/malloc.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_power.h>
+
+LIST_HEAD(, power_domain_device) power_domain_devices =
+ LIST_HEAD_INITIALIZER(power_domain_devices);
+
+void
+power_domain_register(struct power_domain_device *pd)
+{
+ pd->pd_cells = OF_getpropint(pd->pd_node, "#power-domain-cells", 0);
+ pd->pd_phandle = OF_getpropint(pd->pd_node, "phandle", 0);
+ if (pd->pd_phandle == 0)
+ return;
+
+ LIST_INSERT_HEAD(&power_domain_devices, pd, pd_list);
+}
+
+void
+power_domain_enable_cells(uint32_t *cells, int on)
+{
+ struct power_domain_device *pd;
+ uint32_t phandle = cells[0];
+
+ LIST_FOREACH(pd, &power_domain_devices, pd_list) {
+ if (pd->pd_phandle == phandle)
+ break;
+ }
+
+ if (pd && pd->pd_enable)
+ pd->pd_enable(pd->pd_cookie, &cells[1], on);
+}
+
+uint32_t *
+power_domain_next_domain(uint32_t *cells)
+{
+ uint32_t phandle = cells[0];
+ int node, ncells;
+
+ node = OF_getnodebyphandle(phandle);
+ if (node == 0)
+ return NULL;
+
+ ncells = OF_getpropint(node, "#power-domain-cells", 0);
+ return cells + ncells + 1;
+}
+
+void
+power_domain_do_enable_idx(int node, int idx, int on)
+{
+ uint32_t *domains;
+ uint32_t *domain;
+ int len;
+
+ len = OF_getproplen(node, "power-domains");
+ if (len <= 0)
+ return;
+
+ domains = malloc(len, M_TEMP, M_WAITOK);
+ OF_getpropintarray(node, "power-domains", domains, len);
+
+ domain = domains;
+ while (domain && domain < domains + (len / sizeof(uint32_t))) {
+ if (idx <= 0)
+ power_domain_enable_cells(domain, on);
+ if (idx == 0)
+ break;
+ domain = power_domain_next_domain(domain);
+ idx--;
+ }
+
+ free(domains, M_TEMP, len);
+}
+
+void
+power_domain_enable(int node)
+{
+ power_domain_do_enable_idx(node, 0, 1);
+}
+
+void
+power_domain_disable(int node)
+{
+ power_domain_do_enable_idx(node, 0, 0);
+}
diff --git a/sys/dev/ofw/ofw_power.h b/sys/dev/ofw/ofw_power.h
new file mode 100644
index 00000000000..f18871375a0
--- /dev/null
+++ b/sys/dev/ofw/ofw_power.h
@@ -0,0 +1,36 @@
+/* $OpenBSD: ofw_power.h,v 1.1 2018/05/02 15:16:31 patrick Exp $ */
+/*
+ * Copyright (c) 2016 Mark Kettenis
+ * 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.
+ */
+
+#ifndef _DEV_OFW_POWER_H_
+#define _DEV_OFW_POWER_H_
+
+struct power_domain_device {
+ int pd_node;
+ void *pd_cookie;
+ void (*pd_enable)(void *, uint32_t *, int);
+
+ LIST_ENTRY(power_domain_device) pd_list;
+ uint32_t pd_phandle;
+ uint32_t pd_cells;
+};
+
+void power_domain_register(struct power_domain_device *);
+void power_domain_enable(int);
+void power_domain_disable(int);
+
+#endif /* _DEV_OFW_POWER_H_ */