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