Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/samsung Adjust to new pinctrl API
details: https://anonhg.NetBSD.org/src/rev/a4deddfd0a6c
branches: trunk
changeset: 825177:a4deddfd0a6c
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sun Jul 02 16:19:46 2017 +0000
description:
Adjust to new pinctrl API
diffstat:
sys/arch/arm/samsung/exynos_pinctrl.c | 112 ++++++++++++---------------------
1 files changed, 40 insertions(+), 72 deletions(-)
diffs (164 lines):
diff -r f848fdc7ebca -r a4deddfd0a6c sys/arch/arm/samsung/exynos_pinctrl.c
--- a/sys/arch/arm/samsung/exynos_pinctrl.c Sun Jul 02 16:16:44 2017 +0000
+++ b/sys/arch/arm/samsung/exynos_pinctrl.c Sun Jul 02 16:19:46 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exynos_pinctrl.c,v 1.10 2017/06/22 06:42:38 skrll Exp $ */
+/* $NetBSD: exynos_pinctrl.c,v 1.11 2017/07/02 16:19:46 jmcneill Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#include "gpio.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exynos_pinctrl.c,v 1.10 2017/06/22 06:42:38 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exynos_pinctrl.c,v 1.11 2017/07/02 16:19:46 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -55,16 +55,15 @@
struct exynos_pinctrl_config {
int pc_phandle;
- struct exynos_gpio_pin_cfg *pc_pincfg;
+ struct exynos_gpio_pin_cfg pc_pincfg;
struct exynos_pinctrl_softc *pc_sc;
};
static int exynos_pinctrl_match(device_t, cfdata_t, void *);
static void exynos_pinctrl_attach(device_t, device_t, void *);
-static int exynos_pinctrl_set_cfg(void *);
-static struct exynos_gpio_pin_cfg *
-exynos_parse_config(struct exynos_pinctrl_config *pc);
+static int exynos_pinctrl_set_cfg(device_t, const void *, size_t);
+static void exynos_parse_config(int, struct exynos_gpio_pin_cfg *);
static struct fdtbus_pinctrl_controller_func exynos_pinctrl_controller_func = {
.set_config = exynos_pinctrl_set_cfg
@@ -128,90 +127,59 @@
}
if (is_pinctrl(child)) {
- struct exynos_pinctrl_config *pc;
- pc = kmem_alloc(sizeof(*pc), KM_SLEEP);
- pc->pc_phandle = child;
- pc->pc_sc = sc;
- pc->pc_pincfg = exynos_parse_config(pc);
- fdtbus_register_pinctrl_config(pc, child,
+ fdtbus_register_pinctrl_config(self, child,
&exynos_pinctrl_controller_func);
}
}
}
-static struct exynos_gpio_pin_cfg *
-exynos_parse_config(struct exynos_pinctrl_config *pc)
+static void
+exynos_parse_config(int phandle, struct exynos_gpio_pin_cfg *gc)
{
- struct exynos_gpio_pin_cfg *gc = kmem_zalloc(sizeof(*gc), KM_SLEEP);
- int len;
- int value;
-
- len = OF_getprop(pc->pc_phandle, "samsung,pin-function",
- &value, sizeof(value));
- if (len > 0) {
- gc->cfg = be32toh(value);
- }
-
- len = OF_getprop(pc->pc_phandle, "samsung,pin-pud", &value,
- sizeof(&value));
- if (len > 0) {
- gc->pud = be32toh(value);
- }
-
- len = OF_getprop(pc->pc_phandle, "samsung,pin-drv", &value,
- sizeof(&value));
- if (len > 0) {
- gc->drv = be32toh(value);
- }
-
- len = OF_getprop(pc->pc_phandle, "samsung,pin-conpwd", &value,
- sizeof(&value));
- if (len > 0) {
- gc->conpwd = be32toh(value);
- }
-
- len = OF_getprop(pc->pc_phandle, "samsung,pin-pudpwd", &value,
- sizeof(&value));
- if (len > 0) {
- gc->pudpwd = be32toh(value);
- }
- return gc;
+ of_getprop_uint32(phandle, "samsung,pin-function", &gc->cfg);
+ of_getprop_uint32(phandle, "samsung,pin-pud", &gc->pud);
+ of_getprop_uint32(phandle, "samsung,pin-drv", &gc->drv);
+ of_getprop_uint32(phandle, "samsung,pin-conpwd", &gc->conpwd);
+ of_getprop_uint32(phandle, "samsung,pin-pudpwd", &gc->pudpwd);
}
static int
exynos_do_config(struct exynos_pinctrl_config *pc)
{
- struct exynos_gpio_pin_cfg *gc = pc->pc_pincfg;
+ struct exynos_gpio_pin_cfg *gc = &pc->pc_pincfg;
struct exynos_gpio_bank *bank;
- int len;
- char result[20];
+ const char *pins;
+
+ int pins_len = OF_getproplen(pc->pc_phandle, "samsung,pins");
+ if (pins_len <= 0)
+ return -1;
- if (gc == NULL) {
- printf("%s: No configuration available\n", __func__);
- return -1;
+ for (pins = fdtbus_get_string(pc->pc_phandle, "samsung,pins");
+ pins_len > 0;
+ pins_len -= strlen(pins) + 1, pins += strlen(pins) + 1) {
+ bank = exynos_gpio_bank_lookup(pins);
+ if (bank == NULL) {
+ aprint_error_dev(pc->pc_sc->sc_dev,
+ "unknown pin name '%s'\n", pins);
+ continue;
+ }
+ exynos_gpio_pin_ctl_write(bank, gc);
}
- len = OF_getprop(pc->pc_phandle, "samsung,pins", result,
- sizeof(result));
- if (len <= 0) {
- printf("%s: couldn't get pins. (%d)\n", __func__,
- pc->pc_phandle);
- return -1;
- }
-
- bank = exynos_gpio_bank_lookup(&result[0]);
- if (!bank) {
- printf("%s: Couldn't get bank \"%s\".\n", __func__, result);
- return -1;
- }
-
- exynos_gpio_pin_ctl_write(bank, gc);
return 0;
}
static int
-exynos_pinctrl_set_cfg(void *cookie)
+exynos_pinctrl_set_cfg(device_t dev, const void *data, size_t len)
{
- struct exynos_pinctrl_config *pc = cookie;
- return exynos_do_config(pc);
+ struct exynos_pinctrl_config pc;
+
+ if (len != 4)
+ return -1;
+
+ pc.pc_phandle = fdtbus_get_phandle_from_native(be32dec(data));
+ pc.pc_sc = device_private(dev);
+ exynos_parse_config(pc.pc_phandle, &pc.pc_pincfg);
+
+ return exynos_do_config(&pc);
}
Home |
Main Index |
Thread Index |
Old Index