xref: /openbsd-src/sys/arch/octeon/dev/octehci.c (revision 0b7734b3d77bb9b21afec6f4621cae6c805dbd45)
1 /*	$OpenBSD: octehci.c,v 1.1 2016/03/18 05:38:10 jmatthew Exp $ */
2 
3 /*
4  * Copyright (c) 2015 Jonathan Matthew  <jmatthew@openbsd.org>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/param.h>
20 #include <sys/systm.h>
21 #include <sys/device.h>
22 
23 #include <machine/intr.h>
24 #include <machine/bus.h>
25 #include <machine/octeonreg.h>
26 #include <machine/octeonvar.h>
27 
28 #include <octeon/dev/octuctlreg.h>
29 #include <octeon/dev/octuctlvar.h>
30 
31 #include <dev/usb/usb.h>
32 #include <dev/usb/usbdi.h>
33 #include <dev/usb/usbdivar.h>
34 
35 #include <sys/rwlock.h>
36 #include <dev/usb/ehcireg.h>
37 #include <dev/usb/ehcivar.h>
38 
39 struct octehci_softc {
40 	struct ehci_softc	sc_ehci;
41 
42 	void			*sc_ih;
43 };
44 
45 int		octehci_match(struct device *, void *, void *);
46 void		octehci_attach(struct device *, struct device *, void *);
47 
48 const struct cfattach octehci_ca = {
49 	sizeof(struct octehci_softc), octehci_match, octehci_attach,
50 };
51 
52 struct cfdriver octehci_cd = {
53 	NULL, "ehci", DV_DULL
54 };
55 
56 int
57 octehci_match(struct device *parent, void *match, void *aux)
58 {
59 	struct octuctl_attach_args *aa = aux;
60 
61 	if (strcmp(aa->aa_name, "ehci") != 0)
62 		return (0);
63 
64 	return (1);
65 }
66 
67 void
68 octehci_attach(struct device *parent, struct device *self, void *aux)
69 {
70 	struct octehci_softc *sc = (struct octehci_softc *)self;
71 	struct octuctl_attach_args *aa = aux;
72 	uint64_t port_ctl;
73 	int rc;
74 	int s;
75 
76 	sc->sc_ehci.iot = aa->aa_bust;
77 	sc->sc_ehci.sc_bus.pipe_size = sizeof(struct usbd_pipe);
78 	sc->sc_ehci.sc_bus.dmatag = aa->aa_dmat;
79 
80 	rc = bus_space_map(sc->sc_ehci.iot, UCTL_EHCI_BASE, UCTL_EHCI_SIZE,
81 	    0, &sc->sc_ehci.ioh);
82 	KASSERT(rc == 0);
83 
84 	port_ctl = bus_space_read_8(aa->aa_octuctl_bust, aa->aa_ioh,
85 	    UCTL_EHCI_CTL);
86 	port_ctl &= ~UCTL_EHCI_CTL_L2C_ADDR_MSB_MASK;
87 	port_ctl |= (1 << UCTL_EHCI_CTL_L2C_DESC_EMOD_SHIFT);
88 	port_ctl |= (1 << UCTL_EHCI_CTL_L2C_BUFF_EMOD_SHIFT);
89 	port_ctl |= UCTL_EHCI_CTL_EHCI_64B_ADDR_EN;
90 	bus_space_write_8(aa->aa_octuctl_bust, aa->aa_ioh, UCTL_EHCI_CTL,
91 	    port_ctl);
92 
93 	s = splhardusb();
94 	sc->sc_ehci.sc_offs = EREAD1(&sc->sc_ehci, EHCI_CAPLENGTH);
95 	EOWRITE2(&sc->sc_ehci, EHCI_USBINTR, 0);
96 
97 	sc->sc_ehci.sc_id_vendor = 0;
98 	strlcpy(sc->sc_ehci.sc_vendor, "Octeon", sizeof(sc->sc_ehci.sc_vendor));
99 
100 	sc->sc_ih = octeon_intr_establish(CIU_INT_USB, IPL_USB, ehci_intr,
101 	    (void *)&sc->sc_ehci, sc->sc_ehci.sc_bus.bdev.dv_xname);
102 	KASSERT(sc->sc_ih != NULL);
103 
104 	rc = ehci_init(&sc->sc_ehci);
105 	if (rc != USBD_NORMAL_COMPLETION) {
106 		printf(": init failed, error=%d\n", rc);
107 		octeon_intr_disestablish(sc->sc_ih);
108 		bus_space_unmap(sc->sc_ehci.iot, sc->sc_ehci.ioh,
109 		    UCTL_EHCI_SIZE);
110 		splx(s);
111 		return;
112 	}
113 
114 	printf("\n");
115 	if (rc == 0)
116 		config_found(self, &sc->sc_ehci.sc_bus, usbctlprint);
117 	splx(s);
118 }
119