ohci_s3c24x0.c revision 1.7
11.7Sdyoung/*	$NetBSD: ohci_s3c24x0.c,v 1.7 2010/11/11 15:58:41 dyoung 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 *
221.1Sbsh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
231.1Sbsh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
241.1Sbsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
251.1Sbsh * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
261.1Sbsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
271.1Sbsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
281.1Sbsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
291.1Sbsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
301.1Sbsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
311.1Sbsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
321.1Sbsh * POSSIBILITY OF SUCH DAMAGE.
331.1Sbsh */
341.1Sbsh
351.1Sbsh#include <sys/cdefs.h>
361.7Sdyoung__KERNEL_RCSID(0, "$NetBSD: ohci_s3c24x0.c,v 1.7 2010/11/11 15:58:41 dyoung Exp $");
371.1Sbsh
381.1Sbsh#include <sys/param.h>
391.1Sbsh#include <sys/systm.h>
401.1Sbsh#include <sys/kernel.h>
411.1Sbsh#include <sys/device.h>
421.1Sbsh#include <sys/proc.h>
431.1Sbsh#include <sys/queue.h>
441.1Sbsh
451.1Sbsh#include <machine/bus.h>
461.1Sbsh
471.1Sbsh#include <arm/s3c2xx0/s3c24x0var.h>
481.1Sbsh
491.1Sbsh#include <dev/usb/usb.h>
501.1Sbsh#include <dev/usb/usbdi.h>
511.1Sbsh#include <dev/usb/usbdivar.h>
521.1Sbsh#include <dev/usb/usb_mem.h>
531.1Sbsh
541.1Sbsh#include <dev/usb/ohcireg.h>
551.1Sbsh#include <dev/usb/ohcivar.h>
561.1Sbsh
571.7Sdyoungint	ohci_ssio_match(device_t, cfdata_t, void *);
581.7Sdyoungvoid	ohci_ssio_attach(device_t, device_t, void *);
591.7Sdyoungint	ohci_ssio_detach(device_t, int);
601.1Sbsh
611.1Sbshextern	int ohcidebug;
621.1Sbsh
631.1Sbshstruct ohci_ssio_softc {
641.1Sbsh	ohci_softc_t		sc;
651.1Sbsh
661.1Sbsh	void 			*sc_ih;		/* interrupt vectoring */
671.1Sbsh};
681.1Sbsh
691.5SdrochnerCFATTACH_DECL_NEW(ohci_ssio, sizeof(struct ohci_ssio_softc),
701.1Sbsh    ohci_ssio_match, ohci_ssio_attach, ohci_ssio_detach, ohci_activate);
711.1Sbsh
721.1Sbshint
731.7Sdyoungohci_ssio_match(device_t parent, cfdata_t match, void *aux)
741.1Sbsh{
751.1Sbsh	struct s3c2xx0_attach_args *sa = (struct s3c2xx0_attach_args *)aux;
761.1Sbsh	/* XXX: check some registers */
771.1Sbsh
781.1Sbsh	if (sa->sa_dmat == NULL) {
791.1Sbsh		/* busdma tag is not initialized. */
801.1Sbsh		return 0;
811.1Sbsh	}
821.1Sbsh
831.1Sbsh	return 1;
841.1Sbsh}
851.1Sbsh
861.1Sbshvoid
871.7Sdyoungohci_ssio_attach(device_t parent, device_t self, void *aux)
881.1Sbsh{
891.5Sdrochner	struct ohci_ssio_softc *sc = device_private(self);
901.1Sbsh	struct s3c2xx0_attach_args *sa = (struct s3c2xx0_attach_args *)aux;
911.1Sbsh
921.1Sbsh	usbd_status r;
931.1Sbsh
941.2Sbsh	aprint_normal("\n");
951.7Sdyoung	aprint_naive("\n");
961.2Sbsh
971.5Sdrochner	sc->sc.sc_dev = self;
981.5Sdrochner	sc->sc.sc_bus.hci_private = sc;
991.5Sdrochner
1001.1Sbsh	sc->sc.iot = sa->sa_iot;
1011.1Sbsh	/*ohcidebug=15;*/
1021.1Sbsh
1031.1Sbsh	/* Map I/O registers */
1041.1Sbsh	if (bus_space_map(sc->sc.iot, sa->sa_addr, 0x5c, 0, &sc->sc.ioh)) {
1051.4Sdogcow		aprint_error_dev(self, "can't map mem space\n");
1061.1Sbsh		return;
1071.1Sbsh	}
1081.1Sbsh
1091.1Sbsh	/* Disable interrupts, so we don't get any spurious ones. */
1101.1Sbsh	bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE,
1111.1Sbsh			  OHCI_ALL_INTRS);
1121.1Sbsh
1131.1Sbsh	sc->sc.sc_bus.dmatag = sa->sa_dmat;
1141.1Sbsh
1151.1Sbsh	/* Enable the device. */
1161.1Sbsh	/* XXX: provide clock to USB block */
1171.1Sbsh
1181.1Sbsh	/* establish the interrupt. */
1191.1Sbsh	sc->sc_ih = s3c24x0_intr_establish(sa->sa_intr, IPL_USB, IST_NONE, ohci_intr, sc);
1201.1Sbsh	if (sc->sc_ih == NULL) {
1211.4Sdogcow		aprint_error_dev(self, "couldn't establish interrupt\n");
1221.1Sbsh		return;
1231.1Sbsh	}
1241.1Sbsh
1251.2Sbsh	strlcpy(sc->sc.sc_vendor, "Samsung", sizeof sc->sc.sc_vendor);
1261.1Sbsh
1271.1Sbsh	r = ohci_init(&sc->sc);
1281.1Sbsh	if (r != USBD_NORMAL_COMPLETION) {
1291.4Sdogcow		aprint_error_dev(self, "init failed, error=%d\n", r);
1301.1Sbsh		return;
1311.1Sbsh	}
1321.1Sbsh
1331.1Sbsh	/* Attach usb device. */
1341.5Sdrochner	sc->sc.sc_child = config_found(self, &sc->sc.sc_bus, usbctlprint);
1351.1Sbsh}
1361.1Sbsh
1371.1Sbshint
1381.7Sdyoungohci_ssio_detach(device_t self, int flags)
1391.1Sbsh{
1401.1Sbsh	return (0);
1411.1Sbsh}
142