/*-
* Copyright (c) 2006 Garrett D'Amore
* All rights reserved.
*
* Written by Garrett D'Amore.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse
* or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
if (sc->sc_ledpin) {
sc->sc_ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq,
argpio_intr, sc);
if (sc->sc_ih == NULL) {
aprint_error_dev(sc->sc_dev,
"couldn't establish interrupt\n");
}
}
if (sc->sc_ih) {
sysmon_task_queue_init();
sc->sc_resetbtn.smpsw_name = device_xname(sc->sc_dev);
sc->sc_resetbtn.smpsw_type = PSWITCH_TYPE_RESET;
if (sysmon_pswitch_register(&sc->sc_resetbtn) != 0) {
aprint_normal_dev(sc->sc_dev,
"unable to register reset button\n");
}
}
reg = GETREG(sc, GPIO_CR);
for (i = 0; i < sc->sc_npins; i++) {
gpio_pin_t *pp;
pp = &sc->sc_pins[i];
if (i == sc->sc_rstpin) {
/* configure as interrupt for reset */
pp->pin_caps = GPIO_PIN_INPUT;
reg &= ~SERIAL(i);
reg |= INPUT(i);
/* only if we were able to set up the handler, tho' */
if (sc->sc_ih != NULL)
reg |= INTR(i);
} else if (i == sc->sc_ledpin) {
/* configure as output for LED */
pp->pin_caps = GPIO_PIN_OUTPUT;
reg &= ~SERIAL(i);
reg &= ~INPUT(i);
reg &= ~INTR(i);
} else {
if (reg & SERIAL(i)) {
/* pin multiplexed with serial bit */
pp->pin_caps = 0;
} else {
pp->pin_caps = GPIO_PIN_INPUT |
GPIO_PIN_OUTPUT;
}
}
}