ohci_s3c24x0.c revision 1.2
11.2Sbsh/*	$NetBSD: ohci_s3c24x0.c,v 1.2 2003/08/29 12:38:48 bsh Exp $ */
21.1Sbsh
31.1Sbsh/* derived from ohci_pci.c */
41.1Sbsh
51.1Sbsh/*
61.1Sbsh * Copyright (c) 1998 The NetBSD Foundation, Inc.
71.1Sbsh * All rights reserved.
81.1Sbsh *
91.1Sbsh * This code is derived from software contributed to The NetBSD Foundation
101.1Sbsh * by Lennart Augustsson (lennart@augustsson.net) at
111.1Sbsh * Carlstedt Research & Technology.
121.1Sbsh *
131.1Sbsh * Redistribution and use in source and binary forms, with or without
141.1Sbsh * modification, are permitted provided that the following conditions
151.1Sbsh * are met:
161.1Sbsh * 1. Redistributions of source code must retain the above copyright
171.1Sbsh *    notice, this list of conditions and the following disclaimer.
181.1Sbsh * 2. Redistributions in binary form must reproduce the above copyright
191.1Sbsh *    notice, this list of conditions and the following disclaimer in the
201.1Sbsh *    documentation and/or other materials provided with the distribution.
211.1Sbsh * 3. All advertising materials mentioning features or use of this software
221.1Sbsh *    must display the following acknowledgement:
231.1Sbsh *        This product includes software developed by the NetBSD
241.1Sbsh *        Foundation, Inc. and its contributors.
251.1Sbsh * 4. Neither the name of The NetBSD Foundation nor the names of its
261.1Sbsh *    contributors may be used to endorse or promote products derived
271.1Sbsh *    from this software without specific prior written permission.
281.1Sbsh *
291.1Sbsh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
301.1Sbsh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
311.1Sbsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
321.1Sbsh * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
331.1Sbsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
341.1Sbsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
351.1Sbsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
361.1Sbsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
371.1Sbsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
381.1Sbsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
391.1Sbsh * POSSIBILITY OF SUCH DAMAGE.
401.1Sbsh */
411.1Sbsh
421.1Sbsh#include <sys/cdefs.h>
431.2Sbsh__KERNEL_RCSID(0, "$NetBSD: ohci_s3c24x0.c,v 1.2 2003/08/29 12:38:48 bsh Exp $");
441.1Sbsh
451.1Sbsh#include <sys/param.h>
461.1Sbsh#include <sys/systm.h>
471.1Sbsh#include <sys/kernel.h>
481.1Sbsh#include <sys/device.h>
491.1Sbsh#include <sys/proc.h>
501.1Sbsh#include <sys/queue.h>
511.1Sbsh
521.1Sbsh#include <machine/bus.h>
531.1Sbsh
541.1Sbsh#include <arm/s3c2xx0/s3c24x0var.h>
551.1Sbsh
561.1Sbsh#include <dev/usb/usb.h>
571.1Sbsh#include <dev/usb/usbdi.h>
581.1Sbsh#include <dev/usb/usbdivar.h>
591.1Sbsh#include <dev/usb/usb_mem.h>
601.1Sbsh
611.1Sbsh#include <dev/usb/ohcireg.h>
621.1Sbsh#include <dev/usb/ohcivar.h>
631.1Sbsh
641.1Sbshint	ohci_ssio_match(struct device *, struct cfdata *, void *);
651.1Sbshvoid	ohci_ssio_attach(struct device *, struct device *, void *);
661.1Sbshint	ohci_ssio_detach(device_ptr_t, int);
671.1Sbsh
681.1Sbshextern	int ohcidebug;
691.1Sbsh
701.1Sbshstruct ohci_ssio_softc {
711.1Sbsh	ohci_softc_t		sc;
721.1Sbsh
731.1Sbsh	void 			*sc_ih;		/* interrupt vectoring */
741.1Sbsh};
751.1Sbsh
761.1SbshCFATTACH_DECL(ohci_ssio, sizeof(struct ohci_ssio_softc),
771.1Sbsh    ohci_ssio_match, ohci_ssio_attach, ohci_ssio_detach, ohci_activate);
781.1Sbsh
791.1Sbshint
801.1Sbshohci_ssio_match(struct device *parent, struct cfdata *match, void *aux)
811.1Sbsh{
821.1Sbsh	struct s3c2xx0_attach_args *sa = (struct s3c2xx0_attach_args *)aux;
831.1Sbsh	/* XXX: check some registers */
841.1Sbsh
851.1Sbsh	if (sa->sa_dmat == NULL) {
861.1Sbsh		/* busdma tag is not initialized. */
871.1Sbsh		return 0;
881.1Sbsh	}
891.1Sbsh
901.1Sbsh	return 1;
911.1Sbsh}
921.1Sbsh
931.1Sbshvoid
941.1Sbshohci_ssio_attach(struct device *parent, struct device *self, void *aux)
951.1Sbsh{
961.1Sbsh	struct ohci_ssio_softc *sc = (struct ohci_ssio_softc *)self;
971.1Sbsh	struct s3c2xx0_attach_args *sa = (struct s3c2xx0_attach_args *)aux;
981.1Sbsh
991.1Sbsh	usbd_status r;
1001.1Sbsh	char *devname = sc->sc.sc_bus.bdev.dv_xname;
1011.1Sbsh
1021.2Sbsh	aprint_normal("\n");
1031.2Sbsh
1041.1Sbsh	sc->sc.iot = sa->sa_iot;
1051.1Sbsh	/*ohcidebug=15;*/
1061.1Sbsh
1071.1Sbsh	/* Map I/O registers */
1081.1Sbsh	if (bus_space_map(sc->sc.iot, sa->sa_addr, 0x5c, 0, &sc->sc.ioh)) {
1091.1Sbsh		printf("%s: can't map mem space\n", devname);
1101.1Sbsh		return;
1111.1Sbsh	}
1121.1Sbsh
1131.1Sbsh	/* Disable interrupts, so we don't get any spurious ones. */
1141.1Sbsh	bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE,
1151.1Sbsh			  OHCI_ALL_INTRS);
1161.1Sbsh
1171.1Sbsh	sc->sc.sc_bus.dmatag = sa->sa_dmat;
1181.1Sbsh
1191.1Sbsh	/* Enable the device. */
1201.1Sbsh	/* XXX: provide clock to USB block */
1211.1Sbsh
1221.1Sbsh	/* establish the interrupt. */
1231.1Sbsh	sc->sc_ih = s3c24x0_intr_establish(sa->sa_intr, IPL_USB, IST_NONE, ohci_intr, sc);
1241.1Sbsh	if (sc->sc_ih == NULL) {
1251.1Sbsh		printf("%s: couldn't establish interrupt\n", devname);
1261.1Sbsh		return;
1271.1Sbsh	}
1281.1Sbsh
1291.2Sbsh	strlcpy(sc->sc.sc_vendor, "Samsung", sizeof sc->sc.sc_vendor);
1301.1Sbsh
1311.1Sbsh	r = ohci_init(&sc->sc);
1321.1Sbsh	if (r != USBD_NORMAL_COMPLETION) {
1331.1Sbsh		printf("%s: init failed, error=%d\n", devname, r);
1341.1Sbsh		return;
1351.1Sbsh	}
1361.1Sbsh
1371.1Sbsh	/* Attach usb device. */
1381.1Sbsh	sc->sc.sc_child = config_found((void *)sc, &sc->sc.sc_bus,
1391.1Sbsh				       usbctlprint);
1401.1Sbsh}
1411.1Sbsh
1421.1Sbshint
1431.1Sbshohci_ssio_detach(device_ptr_t self, int flags)
1441.1Sbsh{
1451.1Sbsh	return (0);
1461.1Sbsh}
147