musb_otg.c (187172) | musb_otg.c (187173) |
---|---|
1/* $FreeBSD: head/sys/dev/usb2/controller/musb2_otg.c 187172 2009-01-13 19:03:01Z thompsa $ */ | 1/* $FreeBSD: head/sys/dev/usb2/controller/musb2_otg.c 187173 2009-01-13 19:03:12Z thompsa $ */ |
2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 189 unchanged lines hidden (view full) --- 199 sc->sc_flags.d_pulled_up = 0; 200 musbotg_pull_common(sc, 0); 201 } 202} 203 204static void 205musbotg_wakeup_peer(struct usb2_xfer *xfer) 206{ | 2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 189 unchanged lines hidden (view full) --- 199 sc->sc_flags.d_pulled_up = 0; 200 musbotg_pull_common(sc, 0); 201 } 202} 203 204static void 205musbotg_wakeup_peer(struct usb2_xfer *xfer) 206{ |
207 struct musbotg_softc *sc = xfer->usb2_sc; | 207 struct musbotg_softc *sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
208 uint8_t temp; 209 uint8_t use_polling; 210 211 if (!(sc->sc_flags.status_suspend)) { 212 return; 213 } | 208 uint8_t temp; 209 uint8_t use_polling; 210 211 if (!(sc->sc_flags.status_suspend)) { 212 return; 213 } |
214 use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0; | 214 use_polling = mtx_owned(xfer->xroot->xfer_mtx) ? 1 : 0; |
215 216 temp = MUSB2_READ_1(sc, MUSB2_REG_POWER); 217 temp |= MUSB2_MASK_RESUME; 218 MUSB2_WRITE_1(sc, MUSB2_REG_POWER, temp); 219 220 /* wait 8 milliseconds */ 221 if (use_polling) { 222 /* polling */ --- 703 unchanged lines hidden (view full) --- 926 * some flags to the next transfer descriptor 927 */ 928 td = td->obj_next; 929 xfer->td_transfer_cache = td; 930 } 931 return (1); /* not complete */ 932 933done: | 215 216 temp = MUSB2_READ_1(sc, MUSB2_REG_POWER); 217 temp |= MUSB2_MASK_RESUME; 218 MUSB2_WRITE_1(sc, MUSB2_REG_POWER, temp); 219 220 /* wait 8 milliseconds */ 221 if (use_polling) { 222 /* polling */ --- 703 unchanged lines hidden (view full) --- 926 * some flags to the next transfer descriptor 927 */ 928 td = td->obj_next; 929 xfer->td_transfer_cache = td; 930 } 931 return (1); /* not complete */ 932 933done: |
934 sc = xfer->usb2_sc; | 934 sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
935 936 /* compute all actual lengths */ 937 938 musbotg_standard_done(xfer); 939 940 return (0); /* complete */ 941} 942 --- 182 unchanged lines hidden (view full) --- 1125 struct musbotg_std_temp temp; 1126 struct musbotg_softc *sc; 1127 struct musbotg_td *td; 1128 uint32_t x; 1129 uint8_t ep_no; 1130 1131 DPRINTFN(8, "addr=%d endpt=%d sumlen=%d speed=%d\n", 1132 xfer->address, UE_GET_ADDR(xfer->endpoint), | 935 936 /* compute all actual lengths */ 937 938 musbotg_standard_done(xfer); 939 940 return (0); /* complete */ 941} 942 --- 182 unchanged lines hidden (view full) --- 1125 struct musbotg_std_temp temp; 1126 struct musbotg_softc *sc; 1127 struct musbotg_td *td; 1128 uint32_t x; 1129 uint8_t ep_no; 1130 1131 DPRINTFN(8, "addr=%d endpt=%d sumlen=%d speed=%d\n", 1132 xfer->address, UE_GET_ADDR(xfer->endpoint), |
1133 xfer->sumlen, usb2_get_speed(xfer->udev)); | 1133 xfer->sumlen, usb2_get_speed(xfer->xroot->udev)); |
1134 1135 temp.max_frame_size = xfer->max_frame_size; 1136 1137 td = xfer->td_start[0]; 1138 xfer->td_transfer_first = td; 1139 xfer->td_transfer_cache = td; 1140 1141 /* setup temp */ 1142 1143 temp.td = NULL; 1144 temp.td_next = xfer->td_start[0]; 1145 temp.setup_alt_next = xfer->flags_int.short_frames_ok; 1146 temp.offset = 0; 1147 | 1134 1135 temp.max_frame_size = xfer->max_frame_size; 1136 1137 td = xfer->td_start[0]; 1138 xfer->td_transfer_first = td; 1139 xfer->td_transfer_cache = td; 1140 1141 /* setup temp */ 1142 1143 temp.td = NULL; 1144 temp.td_next = xfer->td_start[0]; 1145 temp.setup_alt_next = xfer->flags_int.short_frames_ok; 1146 temp.offset = 0; 1147 |
1148 sc = xfer->usb2_sc; | 1148 sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
1149 ep_no = (xfer->endpoint & UE_ADDR); 1150 1151 /* check if we should prepend a setup message */ 1152 1153 if (xfer->flags_int.control_xfr) { 1154 if (xfer->flags_int.control_hdr) { 1155 1156 temp.func = &musbotg_setup_rx; --- 83 unchanged lines hidden (view full) --- 1240 1241static void 1242musbotg_timeout(void *arg) 1243{ 1244 struct usb2_xfer *xfer = arg; 1245 1246 DPRINTFN(1, "xfer=%p\n", xfer); 1247 | 1149 ep_no = (xfer->endpoint & UE_ADDR); 1150 1151 /* check if we should prepend a setup message */ 1152 1153 if (xfer->flags_int.control_xfr) { 1154 if (xfer->flags_int.control_hdr) { 1155 1156 temp.func = &musbotg_setup_rx; --- 83 unchanged lines hidden (view full) --- 1240 1241static void 1242musbotg_timeout(void *arg) 1243{ 1244 struct usb2_xfer *xfer = arg; 1245 1246 DPRINTFN(1, "xfer=%p\n", xfer); 1247 |
1248 USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED); | 1248 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED); |
1249 1250 /* transfer is transferred */ 1251 musbotg_device_done(xfer, USB_ERR_TIMEOUT); 1252} 1253 1254static void 1255musbotg_ep_int_set(struct usb2_xfer *xfer, uint8_t on) 1256{ | 1249 1250 /* transfer is transferred */ 1251 musbotg_device_done(xfer, USB_ERR_TIMEOUT); 1252} 1253 1254static void 1255musbotg_ep_int_set(struct usb2_xfer *xfer, uint8_t on) 1256{ |
1257 struct musbotg_softc *sc = xfer->usb2_sc; | 1257 struct musbotg_softc *sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
1258 uint16_t temp; 1259 uint8_t ep_no = xfer->endpoint & UE_ADDR; 1260 1261 /* 1262 * Only enable the endpoint interrupt when we are 1263 * actually waiting for data, hence we are dealing 1264 * with level triggered interrupts ! 1265 */ --- 33 unchanged lines hidden (view full) --- 1299 /* poll one time */ 1300 if (musbotg_xfer_do_fifo(xfer)) { 1301 1302 musbotg_ep_int_set(xfer, 1); 1303 1304 DPRINTFN(14, "enabled interrupts on endpoint\n"); 1305 1306 /* put transfer on interrupt queue */ | 1258 uint16_t temp; 1259 uint8_t ep_no = xfer->endpoint & UE_ADDR; 1260 1261 /* 1262 * Only enable the endpoint interrupt when we are 1263 * actually waiting for data, hence we are dealing 1264 * with level triggered interrupts ! 1265 */ --- 33 unchanged lines hidden (view full) --- 1299 /* poll one time */ 1300 if (musbotg_xfer_do_fifo(xfer)) { 1301 1302 musbotg_ep_int_set(xfer, 1); 1303 1304 DPRINTFN(14, "enabled interrupts on endpoint\n"); 1305 1306 /* put transfer on interrupt queue */ |
1307 usb2_transfer_enqueue(&xfer->udev->bus->intr_q, xfer); | 1307 usb2_transfer_enqueue(&xfer->xroot->bus->intr_q, xfer); |
1308 1309 /* start timeout, if any */ 1310 if (xfer->timeout != 0) { 1311 usb2_transfer_timeout_ms(xfer, 1312 &musbotg_timeout, xfer->timeout); 1313 } 1314 } 1315} 1316 1317static void 1318musbotg_root_intr_done(struct usb2_xfer *xfer, 1319 struct usb2_sw_transfer *std) 1320{ | 1308 1309 /* start timeout, if any */ 1310 if (xfer->timeout != 0) { 1311 usb2_transfer_timeout_ms(xfer, 1312 &musbotg_timeout, xfer->timeout); 1313 } 1314 } 1315} 1316 1317static void 1318musbotg_root_intr_done(struct usb2_xfer *xfer, 1319 struct usb2_sw_transfer *std) 1320{ |
1321 struct musbotg_softc *sc = xfer->usb2_sc; | 1321 struct musbotg_softc *sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
1322 1323 DPRINTFN(8, "\n"); 1324 1325 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED); 1326 1327 if (std->state != USB_SW_TR_PRE_DATA) { 1328 if (std->state == USB_SW_TR_PRE_CALLBACK) { 1329 /* transfer transferred */ --- 123 unchanged lines hidden (view full) --- 1453 * musbotg_device_done 1454 * 1455 * NOTE: this function can be called more than one time on the 1456 * same USB transfer! 1457 *------------------------------------------------------------------------*/ 1458static void 1459musbotg_device_done(struct usb2_xfer *xfer, usb2_error_t error) 1460{ | 1322 1323 DPRINTFN(8, "\n"); 1324 1325 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED); 1326 1327 if (std->state != USB_SW_TR_PRE_DATA) { 1328 if (std->state == USB_SW_TR_PRE_CALLBACK) { 1329 /* transfer transferred */ --- 123 unchanged lines hidden (view full) --- 1453 * musbotg_device_done 1454 * 1455 * NOTE: this function can be called more than one time on the 1456 * same USB transfer! 1457 *------------------------------------------------------------------------*/ 1458static void 1459musbotg_device_done(struct usb2_xfer *xfer, usb2_error_t error) 1460{ |
1461 USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED); | 1461 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED); |
1462 1463 DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n", 1464 xfer, xfer->pipe, error); 1465 1466 if (xfer->flags_int.usb2_mode == USB_MODE_DEVICE) { 1467 1468 musbotg_ep_int_set(xfer, 0); 1469 --- 546 unchanged lines hidden (view full) --- 2016musbotg_device_isoc_close(struct usb2_xfer *xfer) 2017{ 2018 musbotg_device_done(xfer, USB_ERR_CANCELLED); 2019} 2020 2021static void 2022musbotg_device_isoc_enter(struct usb2_xfer *xfer) 2023{ | 1462 1463 DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n", 1464 xfer, xfer->pipe, error); 1465 1466 if (xfer->flags_int.usb2_mode == USB_MODE_DEVICE) { 1467 1468 musbotg_ep_int_set(xfer, 0); 1469 --- 546 unchanged lines hidden (view full) --- 2016musbotg_device_isoc_close(struct usb2_xfer *xfer) 2017{ 2018 musbotg_device_done(xfer, USB_ERR_CANCELLED); 2019} 2020 2021static void 2022musbotg_device_isoc_enter(struct usb2_xfer *xfer) 2023{ |
2024 struct musbotg_softc *sc = xfer->usb2_sc; | 2024 struct musbotg_softc *sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
2025 uint32_t temp; 2026 uint32_t nframes; 2027 uint32_t fs_frames; 2028 2029 DPRINTFN(5, "xfer=%p next=%d nframes=%d\n", 2030 xfer, xfer->pipe->isoc_next, xfer->nframes); 2031 2032 /* get the current frame index */ 2033 2034 nframes = MUSB2_READ_2(sc, MUSB2_REG_FRAME); 2035 2036 /* 2037 * check if the frame index is within the window where the frames 2038 * will be inserted 2039 */ 2040 temp = (nframes - xfer->pipe->isoc_next) & MUSB2_MASK_FRAME; 2041 | 2025 uint32_t temp; 2026 uint32_t nframes; 2027 uint32_t fs_frames; 2028 2029 DPRINTFN(5, "xfer=%p next=%d nframes=%d\n", 2030 xfer, xfer->pipe->isoc_next, xfer->nframes); 2031 2032 /* get the current frame index */ 2033 2034 nframes = MUSB2_READ_2(sc, MUSB2_REG_FRAME); 2035 2036 /* 2037 * check if the frame index is within the window where the frames 2038 * will be inserted 2039 */ 2040 temp = (nframes - xfer->pipe->isoc_next) & MUSB2_MASK_FRAME; 2041 |
2042 if (usb2_get_speed(xfer->udev) == USB_SPEED_HIGH) { | 2042 if (usb2_get_speed(xfer->xroot->udev) == USB_SPEED_HIGH) { |
2043 fs_frames = (xfer->nframes + 7) / 8; 2044 } else { 2045 fs_frames = xfer->nframes; 2046 } 2047 2048 if ((xfer->pipe->is_synced == 0) || 2049 (temp < fs_frames)) { 2050 /* --- 53 unchanged lines hidden (view full) --- 2104musbotg_root_ctrl_open(struct usb2_xfer *xfer) 2105{ 2106 return; 2107} 2108 2109static void 2110musbotg_root_ctrl_close(struct usb2_xfer *xfer) 2111{ | 2043 fs_frames = (xfer->nframes + 7) / 8; 2044 } else { 2045 fs_frames = xfer->nframes; 2046 } 2047 2048 if ((xfer->pipe->is_synced == 0) || 2049 (temp < fs_frames)) { 2050 /* --- 53 unchanged lines hidden (view full) --- 2104musbotg_root_ctrl_open(struct usb2_xfer *xfer) 2105{ 2106 return; 2107} 2108 2109static void 2110musbotg_root_ctrl_close(struct usb2_xfer *xfer) 2111{ |
2112 struct musbotg_softc *sc = xfer->usb2_sc; | 2112 struct musbotg_softc *sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
2113 2114 if (sc->sc_root_ctrl.xfer == xfer) { 2115 sc->sc_root_ctrl.xfer = NULL; 2116 } 2117 musbotg_device_done(xfer, USB_ERR_CANCELLED); 2118} 2119 2120/* --- 88 unchanged lines hidden (view full) --- 2209musbotg_root_ctrl_enter(struct usb2_xfer *xfer) 2210{ 2211 return; 2212} 2213 2214static void 2215musbotg_root_ctrl_start(struct usb2_xfer *xfer) 2216{ | 2113 2114 if (sc->sc_root_ctrl.xfer == xfer) { 2115 sc->sc_root_ctrl.xfer = NULL; 2116 } 2117 musbotg_device_done(xfer, USB_ERR_CANCELLED); 2118} 2119 2120/* --- 88 unchanged lines hidden (view full) --- 2209musbotg_root_ctrl_enter(struct usb2_xfer *xfer) 2210{ 2211 return; 2212} 2213 2214static void 2215musbotg_root_ctrl_start(struct usb2_xfer *xfer) 2216{ |
2217 struct musbotg_softc *sc = xfer->usb2_sc; | 2217 struct musbotg_softc *sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
2218 2219 sc->sc_root_ctrl.xfer = xfer; 2220 | 2218 2219 sc->sc_root_ctrl.xfer = xfer; 2220 |
2221 usb2_bus_roothub_exec(xfer->udev->bus); | 2221 usb2_bus_roothub_exec(xfer->xroot->bus); |
2222} 2223 2224static void 2225musbotg_root_ctrl_task(struct usb2_bus *bus) 2226{ 2227 musbotg_root_ctrl_poll(MUSBOTG_BUS2SC(bus)); 2228} 2229 2230static void 2231musbotg_root_ctrl_done(struct usb2_xfer *xfer, 2232 struct usb2_sw_transfer *std) 2233{ | 2222} 2223 2224static void 2225musbotg_root_ctrl_task(struct usb2_bus *bus) 2226{ 2227 musbotg_root_ctrl_poll(MUSBOTG_BUS2SC(bus)); 2228} 2229 2230static void 2231musbotg_root_ctrl_done(struct usb2_xfer *xfer, 2232 struct usb2_sw_transfer *std) 2233{ |
2234 struct musbotg_softc *sc = xfer->usb2_sc; | 2234 struct musbotg_softc *sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
2235 uint16_t value; 2236 uint16_t index; 2237 uint8_t use_polling; 2238 2239 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED); 2240 2241 if (std->state != USB_SW_TR_SETUP) { 2242 if (std->state == USB_SW_TR_PRE_CALLBACK) { --- 4 unchanged lines hidden (view full) --- 2247 } 2248 /* buffer reset */ 2249 std->ptr = USB_ADD_BYTES(&sc->sc_hub_temp, 0); 2250 std->len = 0; 2251 2252 value = UGETW(std->req.wValue); 2253 index = UGETW(std->req.wIndex); 2254 | 2235 uint16_t value; 2236 uint16_t index; 2237 uint8_t use_polling; 2238 2239 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED); 2240 2241 if (std->state != USB_SW_TR_SETUP) { 2242 if (std->state == USB_SW_TR_PRE_CALLBACK) { --- 4 unchanged lines hidden (view full) --- 2247 } 2248 /* buffer reset */ 2249 std->ptr = USB_ADD_BYTES(&sc->sc_hub_temp, 0); 2250 std->len = 0; 2251 2252 value = UGETW(std->req.wValue); 2253 index = UGETW(std->req.wIndex); 2254 |
2255 use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0; | 2255 use_polling = mtx_owned(xfer->xroot->xfer_mtx) ? 1 : 0; |
2256 2257 /* demultiplex the control request */ 2258 2259 switch (std->req.bmRequestType) { 2260 case UT_READ_DEVICE: 2261 switch (std->req.bRequest) { 2262 case UR_GET_DESCRIPTOR: 2263 goto tr_handle_get_descriptor; --- 391 unchanged lines hidden (view full) --- 2655musbotg_root_intr_open(struct usb2_xfer *xfer) 2656{ 2657 return; 2658} 2659 2660static void 2661musbotg_root_intr_close(struct usb2_xfer *xfer) 2662{ | 2256 2257 /* demultiplex the control request */ 2258 2259 switch (std->req.bmRequestType) { 2260 case UT_READ_DEVICE: 2261 switch (std->req.bRequest) { 2262 case UR_GET_DESCRIPTOR: 2263 goto tr_handle_get_descriptor; --- 391 unchanged lines hidden (view full) --- 2655musbotg_root_intr_open(struct usb2_xfer *xfer) 2656{ 2657 return; 2658} 2659 2660static void 2661musbotg_root_intr_close(struct usb2_xfer *xfer) 2662{ |
2663 struct musbotg_softc *sc = xfer->usb2_sc; | 2663 struct musbotg_softc *sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
2664 2665 if (sc->sc_root_intr.xfer == xfer) { 2666 sc->sc_root_intr.xfer = NULL; 2667 } 2668 musbotg_device_done(xfer, USB_ERR_CANCELLED); 2669} 2670 2671static void 2672musbotg_root_intr_enter(struct usb2_xfer *xfer) 2673{ 2674 return; 2675} 2676 2677static void 2678musbotg_root_intr_start(struct usb2_xfer *xfer) 2679{ | 2664 2665 if (sc->sc_root_intr.xfer == xfer) { 2666 sc->sc_root_intr.xfer = NULL; 2667 } 2668 musbotg_device_done(xfer, USB_ERR_CANCELLED); 2669} 2670 2671static void 2672musbotg_root_intr_enter(struct usb2_xfer *xfer) 2673{ 2674 return; 2675} 2676 2677static void 2678musbotg_root_intr_start(struct usb2_xfer *xfer) 2679{ |
2680 struct musbotg_softc *sc = xfer->usb2_sc; | 2680 struct musbotg_softc *sc = MUSBOTG_BUS2SC(xfer->xroot->bus); |
2681 2682 sc->sc_root_intr.xfer = xfer; 2683} 2684 2685struct usb2_pipe_methods musbotg_root_intr_methods = 2686{ 2687 .open = musbotg_root_intr_open, 2688 .close = musbotg_root_intr_close, --- 13 unchanged lines hidden (view full) --- 2702 uint32_t ntd; 2703 uint32_t n; 2704 uint8_t ep_no; 2705 2706 sc = MUSBOTG_BUS2SC(parm->udev->bus); 2707 xfer = parm->curr_xfer; 2708 2709 /* | 2681 2682 sc->sc_root_intr.xfer = xfer; 2683} 2684 2685struct usb2_pipe_methods musbotg_root_intr_methods = 2686{ 2687 .open = musbotg_root_intr_open, 2688 .close = musbotg_root_intr_close, --- 13 unchanged lines hidden (view full) --- 2702 uint32_t ntd; 2703 uint32_t n; 2704 uint8_t ep_no; 2705 2706 sc = MUSBOTG_BUS2SC(parm->udev->bus); 2707 xfer = parm->curr_xfer; 2708 2709 /* |
2710 * setup xfer 2711 */ 2712 xfer->usb2_sc = sc; 2713 2714 /* | |
2715 * NOTE: This driver does not use any of the parameters that 2716 * are computed from the following values. Just set some 2717 * reasonable dummies: 2718 */ 2719 parm->hc_max_packet_size = 0x400; 2720 parm->hc_max_frame_size = 0x400; 2721 2722 if ((parm->methods == &musbotg_device_isoc_methods) || --- 161 unchanged lines hidden --- | 2710 * NOTE: This driver does not use any of the parameters that 2711 * are computed from the following values. Just set some 2712 * reasonable dummies: 2713 */ 2714 parm->hc_max_packet_size = 0x400; 2715 parm->hc_max_frame_size = 0x400; 2716 2717 if ((parm->methods == &musbotg_device_isoc_methods) || --- 161 unchanged lines hidden --- |