imx51_gpio.c revision 1.2 1 1.2 dyoung /* $NetBSD: imx51_gpio.c,v 1.2 2011/07/01 20:27:50 dyoung Exp $ */
2 1.1 bsh
3 1.1 bsh /* derived from imx31_gpio.c */
4 1.1 bsh /*-
5 1.1 bsh * Copyright (c) 2007 The NetBSD Foundation, Inc.
6 1.1 bsh * All rights reserved.
7 1.1 bsh *
8 1.1 bsh * This code is derived from software contributed to The NetBSD Foundation
9 1.1 bsh * by Matt Thomas
10 1.1 bsh *
11 1.1 bsh * Redistribution and use in source and binary forms, with or without
12 1.1 bsh * modification, are permitted provided that the following conditions
13 1.1 bsh * are met:
14 1.1 bsh * 1. Redistributions of source code must retain the above copyright
15 1.1 bsh * notice, this list of conditions and the following disclaimer.
16 1.1 bsh * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 bsh * notice, this list of conditions and the following disclaimer in the
18 1.1 bsh * documentation and/or other materials provided with the distribution.
19 1.1 bsh *
20 1.1 bsh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 bsh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 bsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 bsh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 bsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 bsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 bsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 bsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 bsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 bsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 bsh * POSSIBILITY OF SUCH DAMAGE.
31 1.1 bsh */
32 1.1 bsh #include <sys/cdefs.h>
33 1.2 dyoung __KERNEL_RCSID(0, "$NetBSD: imx51_gpio.c,v 1.2 2011/07/01 20:27:50 dyoung Exp $");
34 1.1 bsh
35 1.1 bsh #include "locators.h"
36 1.1 bsh #include "gpio.h"
37 1.1 bsh
38 1.1 bsh #include <sys/param.h>
39 1.1 bsh #include <sys/evcnt.h>
40 1.1 bsh #include <sys/atomic.h>
41 1.1 bsh
42 1.1 bsh #include <machine/intr.h>
43 1.1 bsh
44 1.1 bsh #include <arm/cpu.h>
45 1.1 bsh #include <arm/armreg.h>
46 1.1 bsh #include <arm/cpufunc.h>
47 1.1 bsh
48 1.2 dyoung #include <sys/bus.h>
49 1.1 bsh
50 1.1 bsh #include <arm/imx/imx51reg.h>
51 1.1 bsh #include <arm/imx/imx51var.h>
52 1.1 bsh #include <arm/pic/picvar.h>
53 1.1 bsh
54 1.1 bsh #include <arm/imx/imxgpioreg.h>
55 1.1 bsh #include <arm/imx/imxgpiovar.h>
56 1.1 bsh
57 1.1 bsh #if NGPIO > 0
58 1.1 bsh #include <sys/gpio.h>
59 1.1 bsh #include <dev/gpio/gpiovar.h>
60 1.1 bsh #endif
61 1.1 bsh
62 1.1 bsh const int imxgpio_ngroups = GPIO_NGROUPS;
63 1.1 bsh
64 1.1 bsh int
65 1.1 bsh imxgpio_match(device_t parent, cfdata_t cfdata, void *aux)
66 1.1 bsh {
67 1.1 bsh struct axi_attach_args *aa = aux;
68 1.1 bsh
69 1.1 bsh switch(aa->aa_addr) {
70 1.1 bsh case GPIO1_BASE:
71 1.1 bsh case GPIO2_BASE:
72 1.1 bsh case GPIO3_BASE:
73 1.1 bsh case GPIO4_BASE:
74 1.1 bsh return 1;
75 1.1 bsh }
76 1.1 bsh
77 1.1 bsh return 0;
78 1.1 bsh }
79 1.1 bsh
80 1.1 bsh void
81 1.1 bsh imxgpio_attach(device_t parent, device_t self, void *aux)
82 1.1 bsh {
83 1.1 bsh struct axi_attach_args * const aa = aux;
84 1.1 bsh bus_space_handle_t ioh;
85 1.1 bsh int error;
86 1.1 bsh
87 1.1 bsh if (aa->aa_irq == AXICF_IRQ_DEFAULT &&
88 1.1 bsh aa->aa_irqbase != AXICF_IRQBASE_DEFAULT) {
89 1.1 bsh aprint_error_dev(self, "missing intr in config\n");
90 1.1 bsh return;
91 1.1 bsh }
92 1.1 bsh if (aa->aa_irq != AXICF_IRQ_DEFAULT &&
93 1.1 bsh aa->aa_irqbase == AXICF_IRQBASE_DEFAULT) {
94 1.1 bsh aprint_error_dev(self, "missing irqbase in config\n");
95 1.1 bsh return;
96 1.1 bsh }
97 1.1 bsh
98 1.1 bsh if (aa->aa_size == AXICF_SIZE_DEFAULT)
99 1.1 bsh aa->aa_size = GPIO_SIZE;
100 1.1 bsh
101 1.1 bsh error = bus_space_map(aa->aa_iot, aa->aa_addr, aa->aa_size,
102 1.1 bsh 0, &ioh);
103 1.1 bsh
104 1.1 bsh if (error) {
105 1.1 bsh aprint_error(": failed to map register %#lx@%#lx: %d\n",
106 1.1 bsh aa->aa_size, aa->aa_addr, error);
107 1.1 bsh return;
108 1.1 bsh }
109 1.1 bsh
110 1.1 bsh imxgpio_attach_common(self, aa->aa_iot, ioh,
111 1.1 bsh (aa->aa_addr - GPIO1_BASE) / 0x4000,
112 1.1 bsh aa->aa_irq, aa->aa_irqbase);
113 1.1 bsh }
114 1.1 bsh
115