Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/fdt FDT pinctrl
details: https://anonhg.NetBSD.org/src/rev/49ebb5cd5c6c
branches: trunk
changeset: 342583:49ebb5cd5c6c
user: marty <marty%NetBSD.org@localhost>
date: Wed Dec 30 04:23:39 2015 +0000
description:
FDT pinctrl
Add a pinctrl bus to FDT. This works against exynos, but someone(tm) needs
to think about whether it is general enough or too specific to exynos.
diffstat:
sys/dev/fdt/fdt_pinctrl.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/fdt/fdtvar.h | 22 ++++++++-
sys/dev/fdt/files.fdt | 3 +-
3 files changed, 134 insertions(+), 2 deletions(-)
diffs (179 lines):
diff -r ee1b77ffe62a -r 49ebb5cd5c6c sys/dev/fdt/fdt_pinctrl.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/fdt/fdt_pinctrl.c Wed Dec 30 04:23:39 2015 +0000
@@ -0,0 +1,111 @@
+/* $NetBSD: fdt_pinctrl.c,v 1.1 2015/12/30 04:23:39 marty Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. 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: fdt_pinctrl.c,v 1.1 2015/12/30 04:23:39 marty Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kmem.h>
+
+#include <libfdt.h>
+#include <dev/fdt/fdtvar.h>
+
+struct fdtbus_pinctrl_controller {
+ device_t pc_dev;
+ int pc_phandle;
+ const struct fdtbus_pinctrl_controller_func *pc_funcs;
+
+ struct fdtbus_pinctrl_controller *pc_next;
+};
+
+static struct fdtbus_pinctrl_controller *fdtbus_pc = NULL;
+
+int
+fdtbus_register_pinctrl_controller(device_t dev, int phandle,
+ const struct fdtbus_pinctrl_controller_func *funcs)
+{
+ struct fdtbus_pinctrl_controller *pc;
+
+ pc = kmem_alloc(sizeof(*pc), KM_SLEEP);
+ pc->pc_dev = dev;
+ pc->pc_phandle = phandle;
+ pc->pc_funcs = funcs;
+
+ pc->pc_next = fdtbus_pc;
+ fdtbus_pc = pc;
+
+ return 0;
+}
+
+struct fdtbus_pinctrl_pin *
+fdtbus_pinctrl_acquire(int phandle, const char *prop)
+{
+ struct fdtbus_pinctrl_controller *pc;
+ struct fdtbus_pinctrl_pin *gp;
+
+ gp = kmem_alloc(sizeof(*gp), KM_SLEEP);
+ for (pc = fdtbus_pc; pc; pc = pc->pc_next) {
+ gp->pp_pc = pc;
+ gp->pp_priv = pc->pc_funcs->acquire(pc->pc_dev, prop);
+ if (gp->pp_priv != NULL)
+ break;
+ }
+
+ if (gp->pp_priv == NULL) {
+ kmem_free(gp, sizeof(*gp));
+ return NULL;
+ }
+
+ return gp;
+}
+
+void
+fdtbus_pinctrl_release(struct fdtbus_pinctrl_pin *gp)
+{
+ struct fdtbus_pinctrl_controller *pc = gp->pp_pc;
+
+ pc->pc_funcs->release(pc->pc_dev, gp->pp_priv);
+ kmem_free(gp, sizeof(*gp));
+}
+
+void
+fdtbus_pinctrl_get_cfg(struct fdtbus_pinctrl_pin *gp, void *cookie)
+{
+ struct fdtbus_pinctrl_controller *pc = gp->pp_pc;
+
+ pc->pc_funcs->get(gp, cookie);
+}
+
+void
+fdtbus_pinctrl_set_cfg(struct fdtbus_pinctrl_pin *gp, void *cookie)
+{
+ struct fdtbus_pinctrl_controller *pc = gp->pp_pc;
+
+ pc->pc_funcs->set(gp, cookie);
+}
diff -r ee1b77ffe62a -r 49ebb5cd5c6c sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h Tue Dec 29 21:49:58 2015 +0000
+++ b/sys/dev/fdt/fdtvar.h Wed Dec 30 04:23:39 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.4 2015/12/22 22:19:07 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.5 2015/12/30 04:23:39 marty Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -76,6 +76,20 @@
void (*write)(device_t, void *, int, bool);
};
+struct fdtbus_pinctrl_controller;
+
+struct fdtbus_pinctrl_pin {
+ struct fdtbus_pinctrl_controller *pp_pc;
+ void *pp_priv;
+};
+
+struct fdtbus_pinctrl_controller_func {
+ void * (*acquire)(device_t, const char *);
+ void (*release)(device_t, void *);
+ void (*get)(struct fdtbus_pinctrl_pin *, void *);
+ void (*set)(struct fdtbus_pinctrl_pin *, void *);
+};
+
struct fdtbus_regulator_controller;
struct fdtbus_regulator {
@@ -112,6 +126,8 @@
const struct fdtbus_i2c_controller_func *);
int fdtbus_register_gpio_controller(device_t, int,
const struct fdtbus_gpio_controller_func *);
+int fdtbus_register_pinctrl_controller(device_t, int,
+ const struct fdtbus_pinctrl_controller_func *);
int fdtbus_register_regulator_controller(device_t, int,
const struct fdtbus_regulator_controller_func *);
int fdtbus_register_clock_controller(device_t, int,
@@ -133,6 +149,10 @@
void fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);
int fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *);
void fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *, int);
+struct fdtbus_pinctrl_pin *fdtbus_pinctrl_acquire(int, const char *);
+void fdtbus_pinctrl_release(struct fdtbus_pinctrl_pin *);
+void fdtbus_pinctrl_set_cfg(struct fdtbus_pinctrl_pin *, void *);
+void fdtbus_pinctrl_get_cfg(struct fdtbus_pinctrl_pin *, void *);
struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *);
void fdtbus_regulator_release(struct fdtbus_regulator *);
int fdtbus_regulator_enable(struct fdtbus_regulator *);
diff -r ee1b77ffe62a -r 49ebb5cd5c6c sys/dev/fdt/files.fdt
--- a/sys/dev/fdt/files.fdt Tue Dec 29 21:49:58 2015 +0000
+++ b/sys/dev/fdt/files.fdt Wed Dec 30 04:23:39 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.6 2015/12/23 11:31:45 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.7 2015/12/30 04:23:39 marty Exp $
include "external/bsd/libfdt/conf/files.libfdt"
@@ -30,3 +30,4 @@
file dev/fdt/fdt_intr.c fdtbus
file dev/fdt/fdt_regulator.c fdtbus
file dev/fdt/fdt_reset.c fdtbus
+file dev/fdt/fdt_pinctrl.c fdtbus
Home |
Main Index |
Thread Index |
Old Index