11.12Sthorpej/*	$NetBSD: ohci_s3c24x0.c,v 1.12 2021/08/07 16:18:45 thorpej 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.12Sthorpej__KERNEL_RCSID(0, "$NetBSD: ohci_s3c24x0.c,v 1.12 2021/08/07 16:18:45 thorpej 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.8Sdyoung#include <sys/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.2Sbsh	aprint_normal("\n");
931.7Sdyoung	aprint_naive("\n");
941.2Sbsh
951.5Sdrochner	sc->sc.sc_dev = self;
961.9Sskrll	sc->sc.sc_bus.ub_hcpriv = sc;
971.5Sdrochner
981.1Sbsh	sc->sc.iot = sa->sa_iot;
991.1Sbsh	/*ohcidebug=15;*/
1001.1Sbsh
1011.1Sbsh	/* Map I/O registers */
1021.1Sbsh	if (bus_space_map(sc->sc.iot, sa->sa_addr, 0x5c, 0, &sc->sc.ioh)) {
1031.4Sdogcow		aprint_error_dev(self, "can't map mem space\n");
1041.1Sbsh		return;
1051.1Sbsh	}
1061.1Sbsh
1071.1Sbsh	/* Disable interrupts, so we don't get any spurious ones. */
1081.1Sbsh	bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE,
1091.1Sbsh			  OHCI_ALL_INTRS);
1101.1Sbsh
1111.9Sskrll	sc->sc.sc_bus.ub_dmatag = sa->sa_dmat;
1121.1Sbsh
1131.1Sbsh	/* Enable the device. */
1141.1Sbsh	/* XXX: provide clock to USB block */
1151.1Sbsh
1161.1Sbsh	/* establish the interrupt. */
1171.1Sbsh	sc->sc_ih = s3c24x0_intr_establish(sa->sa_intr, IPL_USB, IST_NONE, ohci_intr, sc);
1181.1Sbsh	if (sc->sc_ih == NULL) {
1191.4Sdogcow		aprint_error_dev(self, "couldn't establish interrupt\n");
1201.1Sbsh		return;
1211.1Sbsh	}
1221.1Sbsh
1231.9Sskrll	int err = ohci_init(&sc->sc);
1241.9Sskrll	if (err) {
1251.9Sskrll		aprint_error_dev(self, "init failed, error=%d\n", err);
1261.1Sbsh		return;
1271.1Sbsh	}
1281.1Sbsh
1291.1Sbsh	/* Attach usb device. */
1301.11Sthorpej	sc->sc.sc_child = config_found(self, &sc->sc.sc_bus, usbctlprint,
1311.12Sthorpej	    CFARGS_NONE);
1321.1Sbsh}
1331.1Sbsh
1341.1Sbshint
1351.7Sdyoungohci_ssio_detach(device_t self, int flags)
1361.1Sbsh{
1371.9Sskrll	return 0;
1381.1Sbsh}
139