ehci_arbus.c revision 1.1
11.1Smatt/*	$NetBSD: ehci_arbus.c,v 1.1 2011/07/10 06:26:02 matt Exp $	*/
21.1Smatt
31.1Smatt/*-
41.1Smatt * Copyright (c) 2011 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 Matt Thomas of 3am Software Foundry.
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 <sys/cdefs.h>
331.1Smatt__KERNEL_RCSID(0, "$NetBSD: ehci_arbus.c,v 1.1 2011/07/10 06:26:02 matt Exp $");
341.1Smatt
351.1Smatt#include "locators.h"
361.1Smatt
371.1Smatt#include <sys/param.h>
381.1Smatt#include <sys/bus.h>
391.1Smatt#include <sys/device.h>
401.1Smatt#include <sys/systm.h>
411.1Smatt
421.1Smatt#include <mips/atheros/include/ar9344reg.h>
431.1Smatt#include <mips/atheros/include/arbusvar.h>
441.1Smatt
451.1Smatt#include <dev/usb/usb.h>
461.1Smatt#include <dev/usb/usbdi.h>
471.1Smatt#include <dev/usb/usbdivar.h>
481.1Smatt#include <dev/usb/usb_mem.h>
491.1Smatt
501.1Smatt#include <dev/usb/ehcireg.h>
511.1Smatt#include <dev/usb/ehcivar.h>
521.1Smatt
531.1Smattstatic int	ehci_arbus_match(device_t, cfdata_t, void *);
541.1Smattstatic void	ehci_arbus_attach(device_t, device_t, void *);
551.1Smatt
561.1SmattCFATTACH_DECL_NEW(ehci_arbus, sizeof (ehci_softc_t),
571.1Smatt    ehci_arbus_match, ehci_arbus_attach, NULL, NULL);
581.1Smatt
591.1Smattint
601.1Smattehci_arbus_match(device_t parent, cfdata_t cf, void *aux)
611.1Smatt{
621.1Smatt	struct arbus_attach_args *aa = aux;
631.1Smatt
641.1Smatt	if (strcmp(aa->aa_name, cf->cf_name) != 0)
651.1Smatt		return 0;
661.1Smatt
671.1Smatt	if (badaddr((void *)MIPS_PHYS_TO_KSEG1(aa->aa_addr), 4))
681.1Smatt		return 0;
691.1Smatt
701.1Smatt        return 1;	/* XXX */
711.1Smatt}
721.1Smatt
731.1Smattvoid
741.1Smattehci_arbus_attach(device_t parent, device_t self, void *aux)
751.1Smatt{
761.1Smatt	ehci_softc_t *sc = device_private(self);
771.1Smatt	struct arbus_attach_args * const aa = aux;
781.1Smatt	void *ih = NULL;
791.1Smatt	int error;
801.1Smatt	int status;
811.1Smatt
821.1Smatt	sc->iot = aa->aa_bst_le;
831.1Smatt	sc->sc_size = aa->aa_size;
841.1Smatt	//sc->sc_bus.hci_private = sc;
851.1Smatt	sc->sc_bus.dmatag = aa->aa_dmat;
861.1Smatt	sc->sc_bus.usbrev = USBREV_1_0;
871.1Smatt	sc->sc_flags |= EHCIF_ETTF;
881.1Smatt
891.1Smatt	error = bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0,
901.1Smatt	    &sc->ioh);
911.1Smatt
921.1Smatt	if (error) {
931.1Smatt		aprint_error(": failed to map registers: %d\n", error);
941.1Smatt		return;
951.1Smatt	}
961.1Smatt
971.1Smatt	/* The recommended value is 0x20 for both ports and the host */
981.1Smatt	REGVAL(AR9344_USB_CONFIG_BASE) = 0x20c00;	/* magic */
991.1Smatt	DELAY(1000);
1001.1Smatt
1011.1Smatt	/* get offset to operational regs */
1021.1Smatt	uint32_t r = bus_space_read_4(aa->aa_bst, sc->ioh, 0);
1031.1Smatt	if (r != 0x40) {
1041.1Smatt		aprint_error(": error: CAPLENGTH (%#x) != 0x40\n", sc->sc_offs);
1051.1Smatt		return;
1061.1Smatt	}
1071.1Smatt
1081.1Smatt	sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH);
1091.1Smatt
1101.1Smatt	aprint_normal("\n");
1111.1Smatt
1121.1Smatt	/* Disable EHCI interrupts */
1131.1Smatt	EOWRITE2(sc, EHCI_USBINTR, 0);
1141.1Smatt
1151.1Smatt	/* establish interrupt */
1161.1Smatt	ih = arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, ehci_intr, sc);
1171.1Smatt	if (ih == NULL)
1181.1Smatt		panic("%s: couldn't establish interrupt",
1191.1Smatt		    device_xname(self));
1201.1Smatt
1211.1Smatt	/*
1221.1Smatt	 * There are no companion controllers
1231.1Smatt	 */
1241.1Smatt	sc->sc_ncomp = 0;
1251.1Smatt
1261.1Smatt	status = ehci_init(sc);
1271.1Smatt	if (status != USBD_NORMAL_COMPLETION) {
1281.1Smatt		aprint_error("%s: init failed, error=%d\n", device_xname(self),
1291.1Smatt		    status);
1301.1Smatt		if (ih != NULL)
1311.1Smatt			arbus_intr_disestablish(ih);
1321.1Smatt		return;
1331.1Smatt	}
1341.1Smatt
1351.1Smatt	/* Attach USB device */
1361.1Smatt	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
1371.1Smatt}
1381.1Smatt
139