exynos_pinctrl.c revision 1.3 1 /* $NetBSD: exynos_pinctrl.c,v 1.3 2015/12/21 04:58:50 marty Exp $ */
2
3 /*-
4 * Copyright (c) 2015 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Marty Fouts
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "opt_exynos.h"
33 #include "opt_arm_debug.h"
34 #include "gpio.h"
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(1, "$NetBSD: exynos_pinctrl.c,v 1.3 2015/12/21 04:58:50 marty Exp $");
38
39 #include <sys/param.h>
40 #include <sys/bus.h>
41 #include <sys/device.h>
42 #include <sys/intr.h>
43 #include <sys/systm.h>
44 #include <sys/kmem.h>
45 #include <sys/gpio.h>
46
47 #include <dev/gpio/gpiovar.h>
48
49 #include <arm/samsung/exynos_reg.h>
50 #include <arm/samsung/exynos_var.h>
51 #include <arm/samsung/exynos_intr.h>
52 #include <arm/samsung/exynos_pinctrl.h>
53
54 #include <dev/fdt/fdtvar.h>
55
56 static int exynos_pinctrl_match(device_t, cfdata_t, void *);
57 static void exynos_pinctrl_attach(device_t, device_t, void *);
58
59 CFATTACH_DECL_NEW(exynos_pinctrl, sizeof(struct exynos_pinctrl_softc),
60 exynos_pinctrl_match, exynos_pinctrl_attach, NULL, NULL);
61
62 static int
63 exynos_pinctrl_match(device_t parent, cfdata_t cf, void *aux)
64 {
65 const char * const compatible[] = { "samsung,exynos5422-pinctrl",
66 NULL };
67 struct fdt_attach_args * const faa = aux;
68 return of_match_compatible(faa->faa_phandle, compatible);
69 }
70
71 static void
72 exynos_pinctrl_attach(device_t parent, device_t self, void *aux)
73 {
74 struct exynos_pinctrl_softc * const sc
75 = kmem_zalloc(sizeof(*sc), KM_SLEEP);
76 struct fdt_attach_args * const faa = aux;
77 bus_addr_t addr;
78 bus_size_t size;
79 int error;
80 int child;
81
82 if (fdtbus_get_reg(faa->faa_phandle, 0, &addr, &size) != 0) {
83 aprint_error(": couldn't get registers\n");
84 return;
85 }
86
87 aprint_normal(" pinctl @ 0x%08x", (uint)addr);
88 sc->sc_dev = self;
89 sc->sc_bst = faa->faa_bst;
90 error = bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh);
91 if (error) {
92 aprint_error(": couldn't map %#llx: %d",
93 (uint64_t)addr, error);
94 return;
95 }
96
97 for (child = OF_child(faa->faa_phandle); child;
98 child = OF_peer(child)) {
99 char result[64];
100 error = OF_getprop(child, "gpio-controller", result,
101 sizeof(result));
102 if (error == -1)
103 continue;
104 exynos_gpio_bank_config(sc,child);
105 }
106
107 aprint_naive("\n");
108 aprint_normal("\n");
109
110 }
111