ohci_arbus.c revision 1.1
11.1Smatt/*	$NetBSD: ohci_arbus.c,v 1.1 2011/07/07 05:06:44 matt Exp $	*/
21.1Smatt
31.1Smatt/*-
41.1Smatt * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
51.1Smatt * All rights reserved.
61.1Smatt *
71.1Smatt * This code is derived from software contributed to The NetBSD Foundation
81.1Smatt * by Herb Peyerl of Middle Digital Inc.
91.1Smatt *
101.1Smatt * Redistribution and use in source and binary forms, with or without
111.1Smatt * modification, are permitted provided that the following conditions
121.1Smatt * are met:
131.1Smatt * 1. Redistributions of source code must retain the above copyright
141.1Smatt *    notice, this list of conditions and the following disclaimer.
151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
161.1Smatt *    notice, this list of conditions and the following disclaimer in the
171.1Smatt *    documentation and/or other materials provided with the distribution.
181.1Smatt *
191.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Smatt * POSSIBILITY OF SUCH DAMAGE.
301.1Smatt */
311.1Smatt
321.1Smatt#include "locators.h"
331.1Smatt
341.1Smatt#include <sys/cdefs.h>
351.1Smatt__KERNEL_RCSID(0, "$NetBSD: ohci_arbus.c,v 1.1 2011/07/07 05:06:44 matt Exp $");
361.1Smatt
371.1Smatt#include <sys/param.h>
381.1Smatt#include <sys/systm.h>
391.1Smatt#include <sys/device.h>
401.1Smatt
411.1Smatt#include <sys/bus.h>
421.1Smatt
431.1Smatt#include <dev/usb/usb.h>
441.1Smatt#include <dev/usb/usbdi.h>
451.1Smatt#include <dev/usb/usbdivar.h>
461.1Smatt#include <dev/usb/usb_mem.h>
471.1Smatt
481.1Smatt#include <dev/usb/ohcireg.h>
491.1Smatt#include <dev/usb/ohcivar.h>
501.1Smatt
511.1Smatt#include <mips/atheros/include/arbusvar.h>
521.1Smatt
531.1Smattstatic int	ohci_arbus_match(device_t, cfdata_t, void *);
541.1Smattstatic void	ohci_arbus_attach(device_t, device_t, void *);
551.1Smatt
561.1SmattCFATTACH_DECL_NEW(ohci_arbus, sizeof (ohci_softc_t),
571.1Smatt    ohci_arbus_match, ohci_arbus_attach, NULL, NULL);
581.1Smatt
591.1Smattint
601.1Smattohci_arbus_match(device_t parent, cfdata_t cf, void *aux)
611.1Smatt{
621.1Smatt	struct arbus_attach_args *aa = aux;
631.1Smatt	bus_space_handle_t bsh;
641.1Smatt
651.1Smatt	if (strcmp(aa->aa_name, cf->cf_name))
661.1Smatt		return 0;
671.1Smatt
681.1Smatt	if (bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0, &bsh) != 0)
691.1Smatt		return 0;
701.1Smatt
711.1Smatt	return 0; /* XXX */
721.1Smatt
731.1Smatt	if (badaddr((void *)bsh, 4) == -1) {
741.1Smatt		bus_space_unmap(aa->aa_bst, bsh, aa->aa_size);
751.1Smatt		return 0;
761.1Smatt	}
771.1Smatt
781.1Smatt	bus_space_unmap(aa->aa_bst, bsh, aa->aa_size);
791.1Smatt	return 1;
801.1Smatt}
811.1Smatt
821.1Smattvoid
831.1Smattohci_arbus_attach(device_t parent, device_t self, void *aux)
841.1Smatt{
851.1Smatt	ohci_softc_t * const sc = device_private(self);
861.1Smatt	struct arbus_attach_args * const aa = aux;
871.1Smatt	void *ih = NULL;
881.1Smatt	usbd_status status;
891.1Smatt
901.1Smatt	sc->sc_dev = self;
911.1Smatt	sc->iot = aa->aa_bst;
921.1Smatt	sc->sc_size = aa->aa_size;
931.1Smatt	sc->sc_bus.dmatag = aa->aa_dmat;
941.1Smatt	sc->sc_bus.hci_private = sc;
951.1Smatt
961.1Smatt	if (bus_space_map(sc->iot, aa->aa_addr, sc->sc_size, 0, &sc->ioh)) {
971.1Smatt		aprint_error_dev(self, "unable to map registers\n");
981.1Smatt		return;
991.1Smatt	}
1001.1Smatt
1011.1Smatt	/* Disable OHCI interrupts */
1021.1Smatt	bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
1031.1Smatt	    OHCI_ALL_INTRS);
1041.1Smatt
1051.1Smatt	/* establish interrupt */
1061.1Smatt	ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ohci_intr, sc);
1071.1Smatt	if (ih == NULL)
1081.1Smatt		panic("%s: couldn't establish interrupt", device_xname(self));
1091.1Smatt
1101.1Smatt	/* we don't handle endianess in bus space */
1111.1Smatt	sc->sc_endian = OHCI_LITTLE_ENDIAN;
1121.1Smatt
1131.1Smatt	status = ohci_init(sc);
1141.1Smatt	if (status != USBD_NORMAL_COMPLETION) {
1151.1Smatt		aprint_error_dev(self, "init failed, error=%d\n", status);
1161.1Smatt		if (ih != NULL)
1171.1Smatt			arbus_intr_disestablish(ih);
1181.1Smatt		return;
1191.1Smatt	}
1201.1Smatt
1211.1Smatt#if 0
1221.1Smatt	if (psc->sc_ohci_devs[0] == NULL) {
1231.1Smatt		psc->sc_ohci_devs[0] = self;
1241.1Smatt	} else if (psc->sc_ohci_devs[1] == NULL) {
1251.1Smatt		psc->sc_ohci_devs[1] = self;
1261.1Smatt	} else {
1271.1Smatt		panic("%s: too many ohci devices", __func__);
1281.1Smatt	}
1291.1Smatt#endif
1301.1Smatt
1311.1Smatt	/* Attach USB device */
1321.1Smatt	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
1331.1Smatt}
134