ingenic_ohci.c revision 1.1 1 /* $NetBSD: ingenic_ohci.c,v 1.1 2015/03/08 17:14:27 macallan Exp $ */
2
3 /*-
4 * Copyright (c) 2015 Michael Lorenz
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: ingenic_ohci.c,v 1.1 2015/03/08 17:14:27 macallan Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 #include <sys/mutex.h>
36 #include <sys/bus.h>
37 #include <sys/workqueue.h>
38
39 #include <mips/ingenic/ingenic_var.h>
40 #include <mips/ingenic/ingenic_regs.h>
41
42 #include <dev/usb/usb.h>
43 #include <dev/usb/usbdi.h>
44 #include <dev/usb/usbdivar.h>
45 #include <dev/usb/usb_mem.h>
46
47 #include <dev/usb/ohcireg.h>
48 #include <dev/usb/ohcivar.h>
49
50 #include "opt_ingenic.h"
51
52 static int ingenic_ohci_match(device_t, struct cfdata *, void *);
53 static void ingenic_ohci_attach(device_t, device_t, void *);
54
55 CFATTACH_DECL_NEW(ingenic_ohci, sizeof(struct ohci_softc),
56 ingenic_ohci_match, ingenic_ohci_attach, NULL, NULL);
57
58 device_t ingenic_ohci = NULL;
59
60 /* ARGSUSED */
61 static int
62 ingenic_ohci_match(device_t parent, struct cfdata *match, void *aux)
63 {
64 struct apbus_attach_args *aa = aux;
65
66 if (strcmp(aa->aa_name, "ohci") != 0)
67 return 0;
68
69 return 1;
70 }
71
72 /* ARGSUSED */
73 static void
74 ingenic_ohci_attach(device_t parent, device_t self, void *aux)
75 {
76 struct ohci_softc *sc = device_private(self);
77 struct apbus_attach_args *aa = aux;
78 void *ih;
79 int error, status;
80
81 sc->sc_dev = self;
82
83 sc->iot = aa->aa_bst;
84 sc->sc_bus.dmatag = aa->aa_dmat;
85 sc->sc_bus.hci_private = sc;
86 sc->sc_size = 0x1000;
87
88 if (aa->aa_addr == 0)
89 aa->aa_addr = JZ_OHCI_BASE;
90
91 error = bus_space_map(aa->aa_bst, aa->aa_addr, 0x1000, 0, &sc->ioh);
92 if (error) {
93 aprint_error_dev(self,
94 "can't map registers for %s: %d\n", aa->aa_name, error);
95 return;
96 }
97
98 aprint_naive(": OHCI USB controller\n");
99 aprint_normal(": OHCI USB controller\n");
100
101 /* Disable OHCI interrupts */
102 bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
103 OHCI_ALL_INTRS);
104
105 ih = evbmips_intr_establish(5, ohci_intr, sc);
106
107 if (ih == NULL) {
108 aprint_error_dev(self, "failed to establish interrupt %d\n",
109 5);
110 goto fail;
111 }
112
113 /* we don't handle endianess in bus space */
114 sc->sc_endian = OHCI_LITTLE_ENDIAN;
115
116 status = ohci_init(sc);
117 if (status != USBD_NORMAL_COMPLETION) {
118 aprint_error_dev(self, "init failed, error=%d\n", status);
119 goto fail;
120 }
121
122 /* Attach USB device */
123 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
124 ingenic_ohci = self;
125 return;
126
127 fail:
128 if (ih) {
129 evbmips_intr_disestablish(ih);
130 }
131 bus_space_unmap(sc->iot, sc->ioh, 0x1000);
132 }
133