1*ed9977b1Sdyoung /* $NetBSD: i80321_gpio.c,v 1.3 2011/07/01 20:32:51 dyoung Exp $ */
2d322684fSthorpej
3d322684fSthorpej /*
4d322684fSthorpej * Copyright (c) 2001, 2003 Wasabi Systems, Inc.
5d322684fSthorpej * All rights reserved.
6d322684fSthorpej *
7d322684fSthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8d322684fSthorpej *
9d322684fSthorpej * Redistribution and use in source and binary forms, with or without
10d322684fSthorpej * modification, are permitted provided that the following conditions
11d322684fSthorpej * are met:
12d322684fSthorpej * 1. Redistributions of source code must retain the above copyright
13d322684fSthorpej * notice, this list of conditions and the following disclaimer.
14d322684fSthorpej * 2. Redistributions in binary form must reproduce the above copyright
15d322684fSthorpej * notice, this list of conditions and the following disclaimer in the
16d322684fSthorpej * documentation and/or other materials provided with the distribution.
17d322684fSthorpej * 3. All advertising materials mentioning features or use of this software
18d322684fSthorpej * must display the following acknowledgement:
19d322684fSthorpej * This product includes software developed for the NetBSD Project by
20d322684fSthorpej * Wasabi Systems, Inc.
21d322684fSthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22d322684fSthorpej * or promote products derived from this software without specific prior
23d322684fSthorpej * written permission.
24d322684fSthorpej *
25d322684fSthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26d322684fSthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27d322684fSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28d322684fSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29d322684fSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30d322684fSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31d322684fSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32d322684fSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33d322684fSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34d322684fSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35d322684fSthorpej * POSSIBILITY OF SUCH DAMAGE.
36d322684fSthorpej */
37d322684fSthorpej
38d322684fSthorpej /*
39d322684fSthorpej * Intel i80321 I/O Processor general purpose I/O support.
40d322684fSthorpej */
41d322684fSthorpej
42d322684fSthorpej #include <sys/param.h>
43d322684fSthorpej #include <sys/systm.h>
44d322684fSthorpej
45*ed9977b1Sdyoung #include <sys/bus.h>
46d322684fSthorpej
47d322684fSthorpej #include <arm/xscale/i80321reg.h>
48d322684fSthorpej #include <arm/xscale/i80321var.h>
49d322684fSthorpej
50d322684fSthorpej /*
51d322684fSthorpej * i80321_gpio_set_direction:
52d322684fSthorpej *
53d322684fSthorpej * Set the direction of the indicated GPIO pins (1 == output).
54d322684fSthorpej */
55d322684fSthorpej void
i80321_gpio_set_direction(uint8_t which,uint8_t val)56d322684fSthorpej i80321_gpio_set_direction(uint8_t which, uint8_t val)
57d322684fSthorpej {
58d322684fSthorpej struct i80321_softc *sc = i80321_softc;
59d322684fSthorpej
60d322684fSthorpej sc->sc_gpio_dir = (sc->sc_gpio_dir & ~which) | val;
61d322684fSthorpej bus_space_write_1(sc->sc_st, sc->sc_sh, ICU_GPOE, ~sc->sc_gpio_dir);
62d322684fSthorpej }
63d322684fSthorpej
64d322684fSthorpej /*
65d322684fSthorpej * i80321_gpio_set_val:
66d322684fSthorpej *
67d322684fSthorpej * Set the value of the indicated GPIO pins.
68d322684fSthorpej */
69d322684fSthorpej void
i80321_gpio_set_val(uint8_t which,uint8_t val)70d322684fSthorpej i80321_gpio_set_val(uint8_t which, uint8_t val)
71d322684fSthorpej {
72d322684fSthorpej struct i80321_softc *sc = i80321_softc;
73d322684fSthorpej
74d322684fSthorpej sc->sc_gpio_val = (sc->sc_gpio_val & ~which) | val;
75d322684fSthorpej bus_space_write_1(sc->sc_st, sc->sc_sh, ICU_GPOD, sc->sc_gpio_val);
76d322684fSthorpej }
77d322684fSthorpej
78d322684fSthorpej /*
79d322684fSthorpej * i80321_gpio_get_val:
80d322684fSthorpej *
81d322684fSthorpej * Get the current state of the GPIO pins.
82d322684fSthorpej */
83d322684fSthorpej uint8_t
i80321_gpio_get_val(void)84d322684fSthorpej i80321_gpio_get_val(void)
85d322684fSthorpej {
86d322684fSthorpej struct i80321_softc *sc = i80321_softc;
87d322684fSthorpej
88d322684fSthorpej return (bus_space_read_1(sc->sc_st, sc->sc_sh, ICU_GPID));
89d322684fSthorpej }
90