1*ed9977b1Sdyoung /* $NetBSD: i80312_gpio.c,v 1.4 2011/07/01 20:32:51 dyoung Exp $ */
28ae5055eSthorpej
38ae5055eSthorpej /*
48ae5055eSthorpej * Copyright (c) 2001 Wasabi Systems, Inc.
58ae5055eSthorpej * All rights reserved.
68ae5055eSthorpej *
78ae5055eSthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
88ae5055eSthorpej *
98ae5055eSthorpej * Redistribution and use in source and binary forms, with or without
108ae5055eSthorpej * modification, are permitted provided that the following conditions
118ae5055eSthorpej * are met:
128ae5055eSthorpej * 1. Redistributions of source code must retain the above copyright
138ae5055eSthorpej * notice, this list of conditions and the following disclaimer.
148ae5055eSthorpej * 2. Redistributions in binary form must reproduce the above copyright
158ae5055eSthorpej * notice, this list of conditions and the following disclaimer in the
168ae5055eSthorpej * documentation and/or other materials provided with the distribution.
178ae5055eSthorpej * 3. All advertising materials mentioning features or use of this software
188ae5055eSthorpej * must display the following acknowledgement:
198ae5055eSthorpej * This product includes software developed for the NetBSD Project by
208ae5055eSthorpej * Wasabi Systems, Inc.
218ae5055eSthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
228ae5055eSthorpej * or promote products derived from this software without specific prior
238ae5055eSthorpej * written permission.
248ae5055eSthorpej *
258ae5055eSthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
268ae5055eSthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
278ae5055eSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
288ae5055eSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
298ae5055eSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
308ae5055eSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
318ae5055eSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
328ae5055eSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
338ae5055eSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
348ae5055eSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
358ae5055eSthorpej * POSSIBILITY OF SUCH DAMAGE.
368ae5055eSthorpej */
378ae5055eSthorpej
388ae5055eSthorpej /*
398ae5055eSthorpej * Intel i80312 Companion I/O general purpose I/O support.
408ae5055eSthorpej */
418ae5055eSthorpej
4208716eaeSlukem #include <sys/cdefs.h>
43*ed9977b1Sdyoung __KERNEL_RCSID(0, "$NetBSD: i80312_gpio.c,v 1.4 2011/07/01 20:32:51 dyoung Exp $");
4408716eaeSlukem
458ae5055eSthorpej #include <sys/param.h>
468ae5055eSthorpej #include <sys/systm.h>
478ae5055eSthorpej
48*ed9977b1Sdyoung #include <sys/bus.h>
498ae5055eSthorpej
508ae5055eSthorpej #include <arm/xscale/i80312reg.h>
518ae5055eSthorpej #include <arm/xscale/i80312var.h>
528ae5055eSthorpej
538ae5055eSthorpej /*
548ae5055eSthorpej * i80312_gpio_set_direction:
558ae5055eSthorpej *
568ae5055eSthorpej * Set the direction of the indicated GPIO pins (1 == output).
578ae5055eSthorpej */
588ae5055eSthorpej void
i80312_gpio_set_direction(uint8_t which,uint8_t val)598ae5055eSthorpej i80312_gpio_set_direction(uint8_t which, uint8_t val)
608ae5055eSthorpej {
618ae5055eSthorpej struct i80312_softc *sc = i80312_softc;
628ae5055eSthorpej
638ae5055eSthorpej sc->sc_gpio_dir = (sc->sc_gpio_dir & ~which) | val;
648ae5055eSthorpej bus_space_write_1(sc->sc_st, sc->sc_intc_sh, I80312_INTC_GOE,
658ae5055eSthorpej ~sc->sc_gpio_dir);
668ae5055eSthorpej }
678ae5055eSthorpej
688ae5055eSthorpej /*
698ae5055eSthorpej * i80312_gpio_set_val:
708ae5055eSthorpej *
718ae5055eSthorpej * Set the value of the indicated GPIO pins.
728ae5055eSthorpej */
738ae5055eSthorpej void
i80312_gpio_set_val(uint8_t which,uint8_t val)748ae5055eSthorpej i80312_gpio_set_val(uint8_t which, uint8_t val)
758ae5055eSthorpej {
768ae5055eSthorpej struct i80312_softc *sc = i80312_softc;
778ae5055eSthorpej
788ae5055eSthorpej sc->sc_gpio_val = (sc->sc_gpio_val & ~which) | val;
798ae5055eSthorpej bus_space_write_1(sc->sc_st, sc->sc_intc_sh, I80312_INTC_GOD,
808ae5055eSthorpej ~sc->sc_gpio_val);
818ae5055eSthorpej }
828ae5055eSthorpej
838ae5055eSthorpej /*
848ae5055eSthorpej * i80312_gpio_get_val:
858ae5055eSthorpej *
868ae5055eSthorpej * Get the current state of the GPIO pins.
878ae5055eSthorpej */
888ae5055eSthorpej uint8_t
i80312_gpio_get_val(void)898ae5055eSthorpej i80312_gpio_get_val(void)
908ae5055eSthorpej {
918ae5055eSthorpej struct i80312_softc *sc = i80312_softc;
928ae5055eSthorpej
938ae5055eSthorpej return (bus_space_read_1(sc->sc_st, sc->sc_intc_sh, I80312_INTC_GID));
948ae5055eSthorpej }
95