Home | History | Annotate | Line # | Download | only in s3c2xx0
      1 /*	$NetBSD: ohci_s3c24x0.c,v 1.12 2021/08/07 16:18:45 thorpej Exp $ */
      2 
      3 /* derived from ohci_pci.c */
      4 
      5 /*
      6  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      7  * All rights reserved.
      8  *
      9  * This code is derived from software contributed to The NetBSD Foundation
     10  * by Lennart Augustsson (lennart (at) augustsson.net) at
     11  * Carlstedt Research & Technology.
     12  *
     13  * Redistribution and use in source and binary forms, with or without
     14  * modification, are permitted provided that the following conditions
     15  * are met:
     16  * 1. Redistributions of source code must retain the above copyright
     17  *    notice, this list of conditions and the following disclaimer.
     18  * 2. Redistributions in binary form must reproduce the above copyright
     19  *    notice, this list of conditions and the following disclaimer in the
     20  *    documentation and/or other materials provided with the distribution.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32  * POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: ohci_s3c24x0.c,v 1.12 2021/08/07 16:18:45 thorpej Exp $");
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/kernel.h>
     41 #include <sys/device.h>
     42 #include <sys/proc.h>
     43 #include <sys/queue.h>
     44 
     45 #include <sys/bus.h>
     46 
     47 #include <arm/s3c2xx0/s3c24x0var.h>
     48 
     49 #include <dev/usb/usb.h>
     50 #include <dev/usb/usbdi.h>
     51 #include <dev/usb/usbdivar.h>
     52 #include <dev/usb/usb_mem.h>
     53 
     54 #include <dev/usb/ohcireg.h>
     55 #include <dev/usb/ohcivar.h>
     56 
     57 int	ohci_ssio_match(device_t, cfdata_t, void *);
     58 void	ohci_ssio_attach(device_t, device_t, void *);
     59 int	ohci_ssio_detach(device_t, int);
     60 
     61 extern	int ohcidebug;
     62 
     63 struct ohci_ssio_softc {
     64 	ohci_softc_t		sc;
     65 
     66 	void 			*sc_ih;		/* interrupt vectoring */
     67 };
     68 
     69 CFATTACH_DECL_NEW(ohci_ssio, sizeof(struct ohci_ssio_softc),
     70     ohci_ssio_match, ohci_ssio_attach, ohci_ssio_detach, ohci_activate);
     71 
     72 int
     73 ohci_ssio_match(device_t parent, cfdata_t match, void *aux)
     74 {
     75 	struct s3c2xx0_attach_args *sa = (struct s3c2xx0_attach_args *)aux;
     76 	/* XXX: check some registers */
     77 
     78 	if (sa->sa_dmat == NULL) {
     79 		/* busdma tag is not initialized. */
     80 		return 0;
     81 	}
     82 
     83 	return 1;
     84 }
     85 
     86 void
     87 ohci_ssio_attach(device_t parent, device_t self, void *aux)
     88 {
     89 	struct ohci_ssio_softc *sc = device_private(self);
     90 	struct s3c2xx0_attach_args *sa = (struct s3c2xx0_attach_args *)aux;
     91 
     92 	aprint_normal("\n");
     93 	aprint_naive("\n");
     94 
     95 	sc->sc.sc_dev = self;
     96 	sc->sc.sc_bus.ub_hcpriv = sc;
     97 
     98 	sc->sc.iot = sa->sa_iot;
     99 	/*ohcidebug=15;*/
    100 
    101 	/* Map I/O registers */
    102 	if (bus_space_map(sc->sc.iot, sa->sa_addr, 0x5c, 0, &sc->sc.ioh)) {
    103 		aprint_error_dev(self, "can't map mem space\n");
    104 		return;
    105 	}
    106 
    107 	/* Disable interrupts, so we don't get any spurious ones. */
    108 	bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE,
    109 			  OHCI_ALL_INTRS);
    110 
    111 	sc->sc.sc_bus.ub_dmatag = sa->sa_dmat;
    112 
    113 	/* Enable the device. */
    114 	/* XXX: provide clock to USB block */
    115 
    116 	/* establish the interrupt. */
    117 	sc->sc_ih = s3c24x0_intr_establish(sa->sa_intr, IPL_USB, IST_NONE, ohci_intr, sc);
    118 	if (sc->sc_ih == NULL) {
    119 		aprint_error_dev(self, "couldn't establish interrupt\n");
    120 		return;
    121 	}
    122 
    123 	int err = ohci_init(&sc->sc);
    124 	if (err) {
    125 		aprint_error_dev(self, "init failed, error=%d\n", err);
    126 		return;
    127 	}
    128 
    129 	/* Attach usb device. */
    130 	sc->sc.sc_child = config_found(self, &sc->sc.sc_bus, usbctlprint,
    131 	    CFARGS_NONE);
    132 }
    133 
    134 int
    135 ohci_ssio_detach(device_t self, int flags)
    136 {
    137 	return 0;
    138 }
    139