/*-
* Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Cliff Neighbors
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*/
/*
* fail attach if USB interface is disabled GPIO LOW_PWR_DIS reg
*/
r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_LOW_PWR_DIS);
if ((r & RMIXL_GPIO_LOW_PWR_DIS_USB) != 0) {
aprint_error(": USB_DIS set in LOW_PWR_DIS, abort attach\n");
return;
}
/*
* fail attach if USB interface BIST failed
*/
r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_BIST_EACH_STS);
aprint_normal(": BIST status=%s,",
(r & __BIT(18)) ? "OK" : "FAIL"); /* XXX USB_BIST */
/*
* set BYTESWAP_EN register nonzero when software is little endian
*/
#if BYTE_ORDER == BIG_ENDIAN
r = 0;
#else
r = 1;
#endif
RMIXL_USBI_GEN_WRITE(RMIXL_USB_BYTESWAP_EN, r);
aprint_normal(" byteswap enable=%d", r);
for (int intr=0; intr <= RMIXL_UB_INTERRUPT_MAX; intr++) {
evcnt_attach_dynamic(&sc->sc_dispatch[intr].count,
EVCNT_TYPE_INTR, NULL, "rmixl_usbi",
rmixl_usbi_intrnames[intr]);
}
/* Disable all usb interface interrupts */
RMIXL_USBI_GEN_WRITE(RMIXL_USB_INTERRUPT_ENABLE, 0);
/* establish interrupt */
if (obio->obio_intr != OBIOCF_INTR_DEFAULT) {
ih = rmixl_intr_establish(obio->obio_intr, obio->obio_tmsk,
IPL_USB, RMIXL_TRIG_LEVEL, RMIXL_POLR_HIGH,
rmixl_usbi_intr, sc, false);
if (ih == NULL)
panic("%s: couldn't establish interrupt",
device_xname(self));
}
aprint_normal("\n");
/* attach any children */
config_search(self, NULL,
CFARGS(.search = rmixl_usbi_search));
}
for (intr=0; intr <= RMIXL_UB_INTERRUPT_MAX; intr++) {
if (ih == &sc->sc_dispatch[intr]) {
uint32_t r;
/* disable this interrupt in the usb interface */
r = RMIXL_USBI_GEN_READ(RMIXL_USB_INTERRUPT_ENABLE);
r &= 1 << intr;
RMIXL_USBI_GEN_WRITE(RMIXL_USB_INTERRUPT_ENABLE, r);
sc->sc_dispatch[intr].func = func;
sc->sc_dispatch[intr].arg = arg;
ih = &sc->sc_dispatch[intr];
/* enable this interrupt in the usb interface */
r = RMIXL_USBI_GEN_READ(RMIXL_USB_INTERRUPT_ENABLE);
r |= 1 << intr;
RMIXL_USBI_GEN_WRITE(RMIXL_USB_INTERRUPT_ENABLE, r);
out:
splx(s);
return ih;
}
static int
rmixl_usbi_intr(void *arg)
{
rmixl_usbi_softc_t *sc = arg;
uint32_t r;
int intr;
int rv = 0;
r = RMIXL_USBI_GEN_READ(RMIXL_USB_INTERRUPT_STATUS);
if (r != 0) {
for (intr=0; intr <= RMIXL_UB_INTERRUPT_MAX; intr++) {
uint32_t bit = 1 << intr;
if ((r & bit) != 0) {
int (*f)(void *) = sc->sc_dispatch[intr].func;
void *a = sc->sc_dispatch[intr].arg;
if (f != NULL) {
(void)(*f)(a);
sc->sc_dispatch[intr].count.ev_count++;
rv = 1;
}
}
}
}