1213239Sgonzo/*-
2213239Sgonzo * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3213239Sgonzo * Copyright (c) 2009, Luiz Otavio O Souza.
4213239Sgonzo * All rights reserved.
5213239Sgonzo *
6213239Sgonzo * Redistribution and use in source and binary forms, with or without
7213239Sgonzo * modification, are permitted provided that the following conditions
8213239Sgonzo * are met:
9213239Sgonzo * 1. Redistributions of source code must retain the above copyright
10213239Sgonzo *    notice unmodified, this list of conditions, and the following
11213239Sgonzo *    disclaimer.
12213239Sgonzo * 2. Redistributions in binary form must reproduce the above copyright
13213239Sgonzo *    notice, this list of conditions and the following disclaimer in the
14213239Sgonzo *    documentation and/or other materials provided with the distribution.
15213239Sgonzo *
16213239Sgonzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17213239Sgonzo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18213239Sgonzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19213239Sgonzo * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20213239Sgonzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21213239Sgonzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22213239Sgonzo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23213239Sgonzo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24213239Sgonzo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25213239Sgonzo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26213239Sgonzo * SUCH DAMAGE.
27213239Sgonzo *
28213239Sgonzo * $FreeBSD$
29213239Sgonzo *
30213239Sgonzo */
31213239Sgonzo
32213239Sgonzo#ifndef __AR71XX_GPIOVAR_H__
33213239Sgonzo#define __AR71XX_GPIOVAR_H__
34213239Sgonzo
35213239Sgonzo#define GPIO_LOCK(_sc)		mtx_lock(&(_sc)->gpio_mtx)
36213239Sgonzo#define GPIO_UNLOCK(_sc)	mtx_unlock(&(_sc)->gpio_mtx)
37213239Sgonzo#define GPIO_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->gpio_mtx, MA_OWNED)
38213239Sgonzo
39213239Sgonzo/*
40213239Sgonzo * register space access macros
41213239Sgonzo */
42213239Sgonzo#define GPIO_WRITE(sc, reg, val)	do {	\
43213239Sgonzo		bus_write_4(sc->gpio_mem_res, (reg), (val)); \
44213239Sgonzo	} while (0)
45213239Sgonzo
46213239Sgonzo#define GPIO_READ(sc, reg)	 bus_read_4(sc->gpio_mem_res, (reg))
47213239Sgonzo
48213239Sgonzo#define GPIO_SET_BITS(sc, reg, bits)	\
49213239Sgonzo	GPIO_WRITE(sc, reg, GPIO_READ(sc, (reg)) | (bits))
50213239Sgonzo
51213239Sgonzo#define GPIO_CLEAR_BITS(sc, reg, bits)	\
52213239Sgonzo	GPIO_WRITE(sc, reg, GPIO_READ(sc, (reg)) & ~(bits))
53213239Sgonzo
54213239Sgonzo#define	AR71XX_GPIO_PINS	12
55221518Sadrian#define	AR724X_GPIO_PINS	18
56221518Sadrian#define	AR91XX_GPIO_PINS	22
57213239Sgonzo
58213239Sgonzostruct ar71xx_gpio_softc {
59213239Sgonzo	device_t		dev;
60277996Sloos	device_t		busdev;
61277971Sloos	struct mtx		gpio_mtx;
62277971Sloos	struct resource		*gpio_mem_res;
63277971Sloos	int			gpio_mem_rid;
64277971Sloos	struct resource		*gpio_irq_res;
65277971Sloos	int			gpio_irq_rid;
66277971Sloos	void			*gpio_ih;
67213239Sgonzo	int			gpio_npins;
68255335Sloos	struct gpio_pin		*gpio_pins;
69213239Sgonzo};
70213239Sgonzo
71213239Sgonzo#endif	/* __AR71XX_GPIOVAR_H__ */
72