Module Name: src Committed By: marty Date: Wed Dec 30 04:23:39 UTC 2015
Modified Files: src/sys/dev/fdt: fdtvar.h files.fdt Added Files: src/sys/dev/fdt: fdt_pinctrl.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_pinctrl.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/fdtvar.h cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/files.fdt Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/fdt/fdtvar.h diff -u src/sys/dev/fdt/fdtvar.h:1.4 src/sys/dev/fdt/fdtvar.h:1.5 --- src/sys/dev/fdt/fdtvar.h:1.4 Tue Dec 22 22:19:07 2015 +++ src/sys/dev/fdt/fdtvar.h Wed Dec 30 04:23:39 2015 @@ -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 <jmcne...@invisible.ca> @@ -76,6 +76,20 @@ struct fdtbus_gpio_controller_func { 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 @@ int fdtbus_register_i2c_controller(devi 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 @@ int fdtbus_gpio_read(struct fdtbus_gpio 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 *); Index: src/sys/dev/fdt/files.fdt diff -u src/sys/dev/fdt/files.fdt:1.6 src/sys/dev/fdt/files.fdt:1.7 --- src/sys/dev/fdt/files.fdt:1.6 Wed Dec 23 11:31:45 2015 +++ src/sys/dev/fdt/files.fdt Wed Dec 30 04:23:39 2015 @@ -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_i2c.c fdtbus 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 Added files: Index: src/sys/dev/fdt/fdt_pinctrl.c diff -u /dev/null src/sys/dev/fdt/fdt_pinctrl.c:1.1 --- /dev/null Wed Dec 30 04:23:39 2015 +++ src/sys/dev/fdt/fdt_pinctrl.c Wed Dec 30 04:23:39 2015 @@ -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 <jmcne...@invisible.ca> + * 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); +}