1/*- 2 * Copyright (c) 2008 Sam Leffler. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25/* 26 * IXP435 attachment driver for the USB Enhanced Host Controller. 27 */ 28 29#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 2008 Sam Leffler. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25/* 26 * IXP435 attachment driver for the USB Enhanced Host Controller. 27 */ 28 29#include <sys/cdefs.h>
|
84 85static uint8_t ehci_bs_r_1(void *, bus_space_handle_t, bus_size_t); 86static void ehci_bs_w_1(void *, bus_space_handle_t, bus_size_t, u_int8_t); 87static uint16_t ehci_bs_r_2(void *, bus_space_handle_t, bus_size_t); 88static void ehci_bs_w_2(void *, bus_space_handle_t, bus_size_t, uint16_t); 89static uint32_t ehci_bs_r_4(void *, bus_space_handle_t, bus_size_t); 90static void ehci_bs_w_4(void *, bus_space_handle_t, bus_size_t, uint32_t); 91 92static int
| 81 82static uint8_t ehci_bs_r_1(void *, bus_space_handle_t, bus_size_t); 83static void ehci_bs_w_1(void *, bus_space_handle_t, bus_size_t, u_int8_t); 84static uint16_t ehci_bs_r_2(void *, bus_space_handle_t, bus_size_t); 85static void ehci_bs_w_2(void *, bus_space_handle_t, bus_size_t, uint16_t); 86static uint32_t ehci_bs_r_4(void *, bus_space_handle_t, bus_size_t); 87static void ehci_bs_w_4(void *, bus_space_handle_t, bus_size_t, uint32_t); 88 89static int
|
132ehci_ixp_probe(device_t self) 133{ 134 135 device_set_desc(self, EHCI_HC_DEVSTR); 136 137 return (BUS_PROBE_DEFAULT); 138} 139 140static int 141ehci_ixp_attach(device_t self) 142{ 143 struct ixp_ehci_softc *isc = device_get_softc(self); 144 ehci_softc_t *sc = &isc->base; 145 int err; 146 int rid; 147 148 /* initialise some bus fields */ 149 sc->sc_bus.parent = self; 150 sc->sc_bus.devices = sc->sc_devices; 151 sc->sc_bus.devices_max = EHCI_MAX_DEVICES; 152 153 /* get all DMA memory */ 154 if (usb_bus_mem_alloc_all(&sc->sc_bus, 155 USB_GET_DMA_TAG(self), &ehci_iterate_hw_softc)) { 156 return (ENOMEM); 157 } 158 159 /* NB: hints fix the memory location and irq */ 160 161 rid = 0; 162 sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid, RF_ACTIVE); 163 if (!sc->sc_io_res) { 164 device_printf(self, "Could not map memory\n"); 165 goto error; 166 } 167 168 /* 169 * Craft special resource for bus space ops that handle 170 * byte-alignment of non-word addresses. Also, since 171 * we're already intercepting bus space ops we handle 172 * the register window offset that could otherwise be 173 * done with bus_space_subregion. 174 */ 175 isc->iot = rman_get_bustag(sc->sc_io_res); 176 isc->tag.bs_cookie = isc->iot; 177 /* read single */ 178 isc->tag.bs_r_1 = ehci_bs_r_1, 179 isc->tag.bs_r_2 = ehci_bs_r_2, 180 isc->tag.bs_r_4 = ehci_bs_r_4, 181 /* write (single) */ 182 isc->tag.bs_w_1 = ehci_bs_w_1, 183 isc->tag.bs_w_2 = ehci_bs_w_2, 184 isc->tag.bs_w_4 = ehci_bs_w_4, 185 186 sc->sc_io_tag = &isc->tag; 187 sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res); 188 sc->sc_io_size = IXP435_USB1_SIZE - 0x100; 189 190 rid = 0; 191 sc->sc_irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid, 192 RF_ACTIVE); 193 if (sc->sc_irq_res == NULL) { 194 device_printf(self, "Could not allocate irq\n"); 195 goto error; 196 } 197 sc->sc_bus.bdev = device_add_child(self, "usbus", -1); 198 if (!sc->sc_bus.bdev) { 199 device_printf(self, "Could not add USB device\n"); 200 goto error; 201 } 202 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); 203 device_set_desc(sc->sc_bus.bdev, EHCI_HC_DEVSTR); 204 205 sprintf(sc->sc_vendor, "Intel"); 206 207 208 err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, 209 NULL, (driver_intr_t *)ehci_interrupt, sc, &sc->sc_intr_hdl); 210 if (err) { 211 device_printf(self, "Could not setup irq, %d\n", err); 212 sc->sc_intr_hdl = NULL; 213 goto error; 214 } 215 216 /* 217 * Arrange to force Host mode, select big-endian byte alignment, 218 * and arrange to not terminate reset operations (the adapter 219 * will ignore it if we do but might as well save a reg write). 220 * Also, the controller has an embedded Transaction Translator 221 * which means port speed must be read from the Port Status 222 * register following a port enable. 223 */ 224 sc->sc_flags |= EHCI_SCFLG_TT 225 | EHCI_SCFLG_SETMODE 226 | EHCI_SCFLG_BIGEDESC 227 | EHCI_SCFLG_BIGEMMIO 228 | EHCI_SCFLG_NORESTERM 229 ; 230 231 err = ehci_init(sc); 232 if (!err) { 233 err = device_probe_and_attach(sc->sc_bus.bdev); 234 } 235 if (err) { 236 device_printf(self, "USB init failed err=%d\n", err); 237 goto error; 238 } 239 return (0); 240 241error: 242 ehci_ixp_detach(self); 243 return (ENXIO); 244} 245 246static int 247ehci_ixp_detach(device_t self) 248{ 249 struct ixp_ehci_softc *isc = device_get_softc(self); 250 ehci_softc_t *sc = &isc->base; 251 device_t bdev; 252 int err; 253 254 if (sc->sc_bus.bdev) { 255 bdev = sc->sc_bus.bdev; 256 device_detach(bdev); 257 device_delete_child(self, bdev); 258 } 259 /* during module unload there are lots of children leftover */ 260 device_delete_children(self); 261 262 if (sc->sc_irq_res && sc->sc_intr_hdl) { 263 /* 264 * only call ehci_detach() after ehci_init() 265 */ 266 ehci_detach(sc); 267 268 err = bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl); 269 270 if (err) 271 /* XXX or should we panic? */ 272 device_printf(self, "Could not tear down irq, %d\n", 273 err); 274 sc->sc_intr_hdl = NULL; 275 } 276 277 if (sc->sc_irq_res) { 278 bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res); 279 sc->sc_irq_res = NULL; 280 } 281 if (sc->sc_io_res) { 282 bus_release_resource(self, SYS_RES_MEMORY, 0, 283 sc->sc_io_res); 284 sc->sc_io_res = NULL; 285 } 286 usb_bus_mem_free_all(&sc->sc_bus, &ehci_iterate_hw_softc); 287 288 return (0); 289} 290 291/* 292 * Bus space accessors for PIO operations. 293 */ 294 295static uint8_t 296ehci_bs_r_1(void *t, bus_space_handle_t h, bus_size_t o) 297{ 298 return bus_space_read_1((bus_space_tag_t) t, h, 299 0x100 + (o &~ 3) + (3 - (o & 3))); 300} 301 302static void 303ehci_bs_w_1(void *t, bus_space_handle_t h, bus_size_t o, u_int8_t v) 304{ 305 panic("%s", __func__); 306} 307 308static uint16_t 309ehci_bs_r_2(void *t, bus_space_handle_t h, bus_size_t o) 310{ 311 return bus_space_read_2((bus_space_tag_t) t, h, 312 0x100 + (o &~ 3) + (2 - (o & 3))); 313} 314 315static void 316ehci_bs_w_2(void *t, bus_space_handle_t h, bus_size_t o, uint16_t v) 317{ 318 panic("%s", __func__); 319} 320 321static uint32_t 322ehci_bs_r_4(void *t, bus_space_handle_t h, bus_size_t o) 323{ 324 return bus_space_read_4((bus_space_tag_t) t, h, 0x100 + o); 325} 326 327static void 328ehci_bs_w_4(void *t, bus_space_handle_t h, bus_size_t o, uint32_t v) 329{ 330 bus_space_write_4((bus_space_tag_t) t, h, 0x100 + o, v); 331} 332 333static device_method_t ehci_methods[] = { 334 /* Device interface */ 335 DEVMETHOD(device_probe, ehci_ixp_probe), 336 DEVMETHOD(device_attach, ehci_ixp_attach), 337 DEVMETHOD(device_detach, ehci_ixp_detach),
| 90ehci_ixp_probe(device_t self) 91{ 92 93 device_set_desc(self, EHCI_HC_DEVSTR); 94 95 return (BUS_PROBE_DEFAULT); 96} 97 98static int 99ehci_ixp_attach(device_t self) 100{ 101 struct ixp_ehci_softc *isc = device_get_softc(self); 102 ehci_softc_t *sc = &isc->base; 103 int err; 104 int rid; 105 106 /* initialise some bus fields */ 107 sc->sc_bus.parent = self; 108 sc->sc_bus.devices = sc->sc_devices; 109 sc->sc_bus.devices_max = EHCI_MAX_DEVICES; 110 111 /* get all DMA memory */ 112 if (usb_bus_mem_alloc_all(&sc->sc_bus, 113 USB_GET_DMA_TAG(self), &ehci_iterate_hw_softc)) { 114 return (ENOMEM); 115 } 116 117 /* NB: hints fix the memory location and irq */ 118 119 rid = 0; 120 sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid, RF_ACTIVE); 121 if (!sc->sc_io_res) { 122 device_printf(self, "Could not map memory\n"); 123 goto error; 124 } 125 126 /* 127 * Craft special resource for bus space ops that handle 128 * byte-alignment of non-word addresses. Also, since 129 * we're already intercepting bus space ops we handle 130 * the register window offset that could otherwise be 131 * done with bus_space_subregion. 132 */ 133 isc->iot = rman_get_bustag(sc->sc_io_res); 134 isc->tag.bs_cookie = isc->iot; 135 /* read single */ 136 isc->tag.bs_r_1 = ehci_bs_r_1, 137 isc->tag.bs_r_2 = ehci_bs_r_2, 138 isc->tag.bs_r_4 = ehci_bs_r_4, 139 /* write (single) */ 140 isc->tag.bs_w_1 = ehci_bs_w_1, 141 isc->tag.bs_w_2 = ehci_bs_w_2, 142 isc->tag.bs_w_4 = ehci_bs_w_4, 143 144 sc->sc_io_tag = &isc->tag; 145 sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res); 146 sc->sc_io_size = IXP435_USB1_SIZE - 0x100; 147 148 rid = 0; 149 sc->sc_irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid, 150 RF_ACTIVE); 151 if (sc->sc_irq_res == NULL) { 152 device_printf(self, "Could not allocate irq\n"); 153 goto error; 154 } 155 sc->sc_bus.bdev = device_add_child(self, "usbus", -1); 156 if (!sc->sc_bus.bdev) { 157 device_printf(self, "Could not add USB device\n"); 158 goto error; 159 } 160 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); 161 device_set_desc(sc->sc_bus.bdev, EHCI_HC_DEVSTR); 162 163 sprintf(sc->sc_vendor, "Intel"); 164 165 166 err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, 167 NULL, (driver_intr_t *)ehci_interrupt, sc, &sc->sc_intr_hdl); 168 if (err) { 169 device_printf(self, "Could not setup irq, %d\n", err); 170 sc->sc_intr_hdl = NULL; 171 goto error; 172 } 173 174 /* 175 * Arrange to force Host mode, select big-endian byte alignment, 176 * and arrange to not terminate reset operations (the adapter 177 * will ignore it if we do but might as well save a reg write). 178 * Also, the controller has an embedded Transaction Translator 179 * which means port speed must be read from the Port Status 180 * register following a port enable. 181 */ 182 sc->sc_flags |= EHCI_SCFLG_TT 183 | EHCI_SCFLG_SETMODE 184 | EHCI_SCFLG_BIGEDESC 185 | EHCI_SCFLG_BIGEMMIO 186 | EHCI_SCFLG_NORESTERM 187 ; 188 189 err = ehci_init(sc); 190 if (!err) { 191 err = device_probe_and_attach(sc->sc_bus.bdev); 192 } 193 if (err) { 194 device_printf(self, "USB init failed err=%d\n", err); 195 goto error; 196 } 197 return (0); 198 199error: 200 ehci_ixp_detach(self); 201 return (ENXIO); 202} 203 204static int 205ehci_ixp_detach(device_t self) 206{ 207 struct ixp_ehci_softc *isc = device_get_softc(self); 208 ehci_softc_t *sc = &isc->base; 209 device_t bdev; 210 int err; 211 212 if (sc->sc_bus.bdev) { 213 bdev = sc->sc_bus.bdev; 214 device_detach(bdev); 215 device_delete_child(self, bdev); 216 } 217 /* during module unload there are lots of children leftover */ 218 device_delete_children(self); 219 220 if (sc->sc_irq_res && sc->sc_intr_hdl) { 221 /* 222 * only call ehci_detach() after ehci_init() 223 */ 224 ehci_detach(sc); 225 226 err = bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl); 227 228 if (err) 229 /* XXX or should we panic? */ 230 device_printf(self, "Could not tear down irq, %d\n", 231 err); 232 sc->sc_intr_hdl = NULL; 233 } 234 235 if (sc->sc_irq_res) { 236 bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res); 237 sc->sc_irq_res = NULL; 238 } 239 if (sc->sc_io_res) { 240 bus_release_resource(self, SYS_RES_MEMORY, 0, 241 sc->sc_io_res); 242 sc->sc_io_res = NULL; 243 } 244 usb_bus_mem_free_all(&sc->sc_bus, &ehci_iterate_hw_softc); 245 246 return (0); 247} 248 249/* 250 * Bus space accessors for PIO operations. 251 */ 252 253static uint8_t 254ehci_bs_r_1(void *t, bus_space_handle_t h, bus_size_t o) 255{ 256 return bus_space_read_1((bus_space_tag_t) t, h, 257 0x100 + (o &~ 3) + (3 - (o & 3))); 258} 259 260static void 261ehci_bs_w_1(void *t, bus_space_handle_t h, bus_size_t o, u_int8_t v) 262{ 263 panic("%s", __func__); 264} 265 266static uint16_t 267ehci_bs_r_2(void *t, bus_space_handle_t h, bus_size_t o) 268{ 269 return bus_space_read_2((bus_space_tag_t) t, h, 270 0x100 + (o &~ 3) + (2 - (o & 3))); 271} 272 273static void 274ehci_bs_w_2(void *t, bus_space_handle_t h, bus_size_t o, uint16_t v) 275{ 276 panic("%s", __func__); 277} 278 279static uint32_t 280ehci_bs_r_4(void *t, bus_space_handle_t h, bus_size_t o) 281{ 282 return bus_space_read_4((bus_space_tag_t) t, h, 0x100 + o); 283} 284 285static void 286ehci_bs_w_4(void *t, bus_space_handle_t h, bus_size_t o, uint32_t v) 287{ 288 bus_space_write_4((bus_space_tag_t) t, h, 0x100 + o, v); 289} 290 291static device_method_t ehci_methods[] = { 292 /* Device interface */ 293 DEVMETHOD(device_probe, ehci_ixp_probe), 294 DEVMETHOD(device_attach, ehci_ixp_attach), 295 DEVMETHOD(device_detach, ehci_ixp_detach),
|