1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/* $NetBSD: ohci_aubus.c,v 1.18 2021/08/07 16:18:58 thorpej Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Herb Peyerl of Middle Digital Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ohci_aubus.c,v 1.18 2021/08/07 16:18:58 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/bus.h>
#include <mips/alchemy/include/aureg.h>
#include <mips/alchemy/include/auvar.h>
#include <mips/alchemy/include/aubusvar.h>
#include <mips/alchemy/dev/ohcireg.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdivar.h>
#include <dev/usb/usb_mem.h>
#include <dev/usb/ohcireg.h>
#include <dev/usb/ohcivar.h>
static int ohci_aubus_match(device_t, cfdata_t, void *);
static void ohci_aubus_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(ohci_aubus, sizeof (ohci_softc_t),
ohci_aubus_match, ohci_aubus_attach, NULL, NULL);
int
ohci_aubus_match(device_t parent, cfdata_t match, void *aux)
{
struct aubus_attach_args *aa = aux;
if (strcmp(aa->aa_name, match->cf_name) == 0)
return 1;
return 0;
}
void
ohci_aubus_attach(device_t parent, device_t self, void *aux)
{
ohci_softc_t *sc = device_private(self);
void *ih;
uint32_t x, tmp;
bus_addr_t usbh_base, usbh_enable;
struct aubus_attach_args *aa = aux;
usbh_base = aa->aa_addrs[0];
usbh_enable = aa->aa_addrs[1];
sc->sc_size = aa->aa_addrs[2];
sc->iot = aa->aa_st;
sc->sc_bus.ub_dmatag = (bus_dma_tag_t)aa->aa_dt;
sc->sc_dev = self;
sc->sc_bus.ub_hcpriv = sc;
if (bus_space_map(sc->iot, usbh_base, sc->sc_size, 0, &sc->ioh)) {
aprint_error_dev(self, "unable to map USBH registers\n");
return;
}
/*
* Enable the USB Host controller here.
* As per 7.2 in the Au1500 manual:
*
* (1) Set CE bit to enable clocks.
* (2) Set E to enable OHCI
* (3) Clear HCFS in OHCI_CONTROL.
* (4) Wait for RD bit to be set.
*/
x = bus_space_read_4(sc->iot, sc->ioh, usbh_enable);
x |= UE_CE;
bus_space_write_4(sc->iot, sc->ioh, usbh_enable, x);
delay(10);
x |= UE_E;
#ifdef __MIPSEB__
x |= UE_BE;
#endif
bus_space_write_4(sc->iot, sc->ioh, usbh_enable, x);
delay(10);
x = bus_space_read_4(sc->iot, sc->ioh, OHCI_CONTROL);
x &= ~(OHCI_HCFS_MASK);
bus_space_write_4(sc->iot, sc->ioh, OHCI_CONTROL, x);
delay(10);
/* Need to read USBH_ENABLE twice in succession according to
* au1500 Errata #7.
*/
for (x = 100; x; x--) {
bus_space_read_4(sc->iot, sc->ioh, usbh_enable);
tmp = bus_space_read_4(sc->iot, sc->ioh, usbh_enable);
if (tmp&UE_RD)
break;
delay(1000);
}
if (x == 0) {
aprint_error_dev(self, "device not ready\n");
return;
}
printf(": Alchemy OHCI\n");
/* Disable OHCI interrupts */
bus_space_write_4(sc->iot, sc->ioh, OHCI_INTERRUPT_DISABLE,
OHCI_ALL_INTRS);
/* hook interrupt */
ih = au_intr_establish(aa->aa_irq[0], 0, IPL_USB, IST_LEVEL_LOW,
ohci_intr, sc);
if (ih == NULL) {
aprint_error_dev(self,"couldn't establish interrupt\n");
}
sc->sc_endian = OHCI_HOST_ENDIAN;
int err = ohci_init(sc);
if (err != USBD_NORMAL_COMPLETION) {
aprint_error_dev(self, "init failed, error=%d\n", err);
au_intr_disestablish(ih);
return;
}
/* Attach USB device */
sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, CFARGS_NONE);
}
|