Deleted Added
full compact
usb_hub.c (228758) usb_hub.c (230032)
1/* $FreeBSD: head/sys/dev/usb/usb_hub.c 228758 2011-12-21 08:46:08Z hselasky $ */
1/* $FreeBSD: head/sys/dev/usb/usb_hub.c 230032 2012-01-12 21:21:20Z hselasky $ */
2/*-
3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
5 * Copyright (c) 2008-2010 Hans Petter Selasky. 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:

--- 354 unchanged lines hidden (view full) ---

364 }
365 /* check if nothing is connected to the port */
366
367 if (!(sc->sc_st.port_status & UPS_CURRENT_CONNECT_STATUS)) {
368 goto error;
369 }
370 /* check if there is no power on the port and print a warning */
371
2/*-
3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
5 * Copyright (c) 2008-2010 Hans Petter Selasky. 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:

--- 354 unchanged lines hidden (view full) ---

364 }
365 /* check if nothing is connected to the port */
366
367 if (!(sc->sc_st.port_status & UPS_CURRENT_CONNECT_STATUS)) {
368 goto error;
369 }
370 /* check if there is no power on the port and print a warning */
371
372 if (!(sc->sc_st.port_status & UPS_PORT_POWER)) {
373 DPRINTF("WARNING: strange, connected port %d "
374 "has no power\n", portno);
372 switch (udev->speed) {
373 case USB_SPEED_HIGH:
374 case USB_SPEED_FULL:
375 case USB_SPEED_LOW:
376 if (!(sc->sc_st.port_status & UPS_PORT_POWER)) {
377 DPRINTF("WARNING: strange, connected port %d "
378 "has no power\n", portno);
379 }
380 break;
381 case USB_SPEED_SUPER:
382 if (!(sc->sc_st.port_status & UPS_PORT_POWER_SS)) {
383 DPRINTF("WARNING: strange, connected port %d "
384 "has no power\n", portno);
385 }
386 break;
387 default:
388 break;
375 }
389 }
390
376 /* check if the device is in Host Mode */
377
378 if (!(sc->sc_st.port_status & UPS_PORT_MODE_DEVICE)) {
379
380 DPRINTF("Port %d is in Host Mode\n", portno);
381
382 if (sc->sc_st.port_status & UPS_SUSPEND) {
383 /*

--- 222 unchanged lines hidden (view full) ---

606 is_suspend = 1;
607 } else {
608 is_suspend = 0;
609 }
610 } else {
611 switch (UPS_PORT_LINK_STATE_GET(sc->sc_st.port_status)) {
612 case UPS_PORT_LS_U0:
613 case UPS_PORT_LS_U1:
391 /* check if the device is in Host Mode */
392
393 if (!(sc->sc_st.port_status & UPS_PORT_MODE_DEVICE)) {
394
395 DPRINTF("Port %d is in Host Mode\n", portno);
396
397 if (sc->sc_st.port_status & UPS_SUSPEND) {
398 /*

--- 222 unchanged lines hidden (view full) ---

621 is_suspend = 1;
622 } else {
623 is_suspend = 0;
624 }
625 } else {
626 switch (UPS_PORT_LINK_STATE_GET(sc->sc_st.port_status)) {
627 case UPS_PORT_LS_U0:
628 case UPS_PORT_LS_U1:
629 case UPS_PORT_LS_U2:
614 case UPS_PORT_LS_RESUME:
615 is_suspend = 0;
616 break;
617 default:
618 is_suspend = 1;
619 break;
620 }
621 }

--- 5 unchanged lines hidden (view full) ---

627 if (child) {
628 /*
629 * This code handle two cases: 1) Host Mode - we can only
630 * receive resume here 2) Device Mode - we can receive
631 * suspend and resume here
632 */
633 if (is_suspend == 0)
634 usb_dev_resume_peer(child);
630 case UPS_PORT_LS_RESUME:
631 is_suspend = 0;
632 break;
633 default:
634 is_suspend = 1;
635 break;
636 }
637 }

--- 5 unchanged lines hidden (view full) ---

643 if (child) {
644 /*
645 * This code handle two cases: 1) Host Mode - we can only
646 * receive resume here 2) Device Mode - we can receive
647 * suspend and resume here
648 */
649 if (is_suspend == 0)
650 usb_dev_resume_peer(child);
635 else if ((child->flags.usb_mode == USB_MODE_DEVICE) ||
636 (usb_device_20_compatible(child) == 0))
651 else if (child->flags.usb_mode == USB_MODE_DEVICE)
637 usb_dev_suspend_peer(child);
638 }
639done:
640 return (err);
641}
642
643/*------------------------------------------------------------------------*
644 * uhub_root_interrupt

--- 1414 unchanged lines hidden (view full) ---

2059{
2060 return ((udev->power_mode == USB_POWER_MODE_ON) ||
2061 (udev->driver_added_refcount != udev->bus->driver_added_refcount) ||
2062 (udev->re_enumerate_wait != 0) ||
2063 (udev->pwr_save.type_refs[UE_ISOCHRONOUS] != 0) ||
2064 (udev->pwr_save.write_refs != 0) ||
2065 ((udev->pwr_save.read_refs != 0) &&
2066 (udev->flags.usb_mode == USB_MODE_HOST) &&
652 usb_dev_suspend_peer(child);
653 }
654done:
655 return (err);
656}
657
658/*------------------------------------------------------------------------*
659 * uhub_root_interrupt

--- 1414 unchanged lines hidden (view full) ---

2074{
2075 return ((udev->power_mode == USB_POWER_MODE_ON) ||
2076 (udev->driver_added_refcount != udev->bus->driver_added_refcount) ||
2077 (udev->re_enumerate_wait != 0) ||
2078 (udev->pwr_save.type_refs[UE_ISOCHRONOUS] != 0) ||
2079 (udev->pwr_save.write_refs != 0) ||
2080 ((udev->pwr_save.read_refs != 0) &&
2081 (udev->flags.usb_mode == USB_MODE_HOST) &&
2067 (usb_device_20_compatible(udev) != 0) &&
2068 (usb_peer_can_wakeup(udev) == 0)));
2069}
2070
2071/*------------------------------------------------------------------------*
2072 * usb_bus_powerd
2073 *
2074 * This function implements the USB power daemon and is called
2075 * regularly from the USB explore thread.

--- 163 unchanged lines hidden (view full) ---

2239 if (usb_device_20_compatible(udev)) {
2240 /* resume current port (Valid in Host and Device Mode) */
2241 err = usbd_req_clear_port_feature(udev->parent_hub,
2242 NULL, udev->port_no, UHF_PORT_SUSPEND);
2243 if (err) {
2244 DPRINTFN(0, "Resuming port failed\n");
2245 return;
2246 }
2082 (usb_peer_can_wakeup(udev) == 0)));
2083}
2084
2085/*------------------------------------------------------------------------*
2086 * usb_bus_powerd
2087 *
2088 * This function implements the USB power daemon and is called
2089 * regularly from the USB explore thread.

--- 163 unchanged lines hidden (view full) ---

2253 if (usb_device_20_compatible(udev)) {
2254 /* resume current port (Valid in Host and Device Mode) */
2255 err = usbd_req_clear_port_feature(udev->parent_hub,
2256 NULL, udev->port_no, UHF_PORT_SUSPEND);
2257 if (err) {
2258 DPRINTFN(0, "Resuming port failed\n");
2259 return;
2260 }
2261 } else {
2262 /* resume current port (Valid in Host and Device Mode) */
2263 err = usbd_req_set_port_link_state(udev->parent_hub,
2264 NULL, udev->port_no, UPS_PORT_LS_U0);
2265 if (err) {
2266 DPRINTFN(0, "Resuming port failed\n");
2267 return;
2268 }
2247 }
2248
2249 /* resume settle time */
2250 usb_pause_mtx(NULL, USB_MS_TO_TICKS(USB_PORT_RESUME_DELAY));
2251
2252 if (bus->methods->device_resume != NULL) {
2253 /* resume USB device on the USB controller */
2254 (bus->methods->device_resume) (udev);

--- 25 unchanged lines hidden (view full) ---

2280 usbd_sr_lock(udev);
2281
2282 /* notify all sub-devices about resume */
2283 err = usb_suspend_resume(udev, 0);
2284
2285 usbd_sr_unlock(udev);
2286
2287 /* check if peer has wakeup capability */
2269 }
2270
2271 /* resume settle time */
2272 usb_pause_mtx(NULL, USB_MS_TO_TICKS(USB_PORT_RESUME_DELAY));
2273
2274 if (bus->methods->device_resume != NULL) {
2275 /* resume USB device on the USB controller */
2276 (bus->methods->device_resume) (udev);

--- 25 unchanged lines hidden (view full) ---

2302 usbd_sr_lock(udev);
2303
2304 /* notify all sub-devices about resume */
2305 err = usb_suspend_resume(udev, 0);
2306
2307 usbd_sr_unlock(udev);
2308
2309 /* check if peer has wakeup capability */
2288 if (usb_peer_can_wakeup(udev) &&
2289 usb_device_20_compatible(udev)) {
2310 if (usb_peer_can_wakeup(udev)) {
2290 /* clear remote wakeup */
2291 err = usbd_req_clear_device_feature(udev,
2292 NULL, UF_DEVICE_REMOTE_WAKEUP);
2293 if (err) {
2294 DPRINTFN(0, "Clearing device "
2295 "remote wakeup failed: %s\n",
2296 usbd_errstr(err));
2297 }

--- 44 unchanged lines hidden (view full) ---

2342 if (child->flags.self_suspended)
2343 continue;
2344
2345 DPRINTFN(1, "Port %u is busy on the HUB!\n", x + 1);
2346 return;
2347 }
2348 }
2349
2311 /* clear remote wakeup */
2312 err = usbd_req_clear_device_feature(udev,
2313 NULL, UF_DEVICE_REMOTE_WAKEUP);
2314 if (err) {
2315 DPRINTFN(0, "Clearing device "
2316 "remote wakeup failed: %s\n",
2317 usbd_errstr(err));
2318 }

--- 44 unchanged lines hidden (view full) ---

2363 if (child->flags.self_suspended)
2364 continue;
2365
2366 DPRINTFN(1, "Port %u is busy on the HUB!\n", x + 1);
2367 return;
2368 }
2369 }
2370
2350 if (usb_peer_can_wakeup(udev) &&
2351 usb_device_20_compatible(udev)) {
2371 if (usb_peer_can_wakeup(udev)) {
2352 /*
2353 * This request needs to be done before we set
2354 * "udev->flags.self_suspended":
2355 */
2356
2357 /* allow device to do remote wakeup */
2358 err = usbd_req_set_device_feature(udev,
2359 NULL, UF_DEVICE_REMOTE_WAKEUP);

--- 15 unchanged lines hidden (view full) ---

2375 * must be set before calling USB controller suspend
2376 * callbacks.
2377 */
2378 udev->flags.self_suspended = 1;
2379 }
2380 USB_BUS_UNLOCK(udev->bus);
2381
2382 if (err != 0) {
2372 /*
2373 * This request needs to be done before we set
2374 * "udev->flags.self_suspended":
2375 */
2376
2377 /* allow device to do remote wakeup */
2378 err = usbd_req_set_device_feature(udev,
2379 NULL, UF_DEVICE_REMOTE_WAKEUP);

--- 15 unchanged lines hidden (view full) ---

2395 * must be set before calling USB controller suspend
2396 * callbacks.
2397 */
2398 udev->flags.self_suspended = 1;
2399 }
2400 USB_BUS_UNLOCK(udev->bus);
2401
2402 if (err != 0) {
2383 if (usb_peer_can_wakeup(udev) &&
2384 usb_device_20_compatible(udev)) {
2403 if (usb_peer_can_wakeup(udev)) {
2385 /* allow device to do remote wakeup */
2386 err = usbd_req_clear_device_feature(udev,
2387 NULL, UF_DEVICE_REMOTE_WAKEUP);
2388 if (err) {
2389 DPRINTFN(0, "Setting device "
2390 "remote wakeup failed\n");
2391 }
2392 }

--- 39 unchanged lines hidden (view full) ---

2432 if (usb_device_20_compatible(udev)) {
2433 /* suspend current port */
2434 err = usbd_req_set_port_feature(udev->parent_hub,
2435 NULL, udev->port_no, UHF_PORT_SUSPEND);
2436 if (err) {
2437 DPRINTFN(0, "Suspending port failed\n");
2438 return;
2439 }
2404 /* allow device to do remote wakeup */
2405 err = usbd_req_clear_device_feature(udev,
2406 NULL, UF_DEVICE_REMOTE_WAKEUP);
2407 if (err) {
2408 DPRINTFN(0, "Setting device "
2409 "remote wakeup failed\n");
2410 }
2411 }

--- 39 unchanged lines hidden (view full) ---

2451 if (usb_device_20_compatible(udev)) {
2452 /* suspend current port */
2453 err = usbd_req_set_port_feature(udev->parent_hub,
2454 NULL, udev->port_no, UHF_PORT_SUSPEND);
2455 if (err) {
2456 DPRINTFN(0, "Suspending port failed\n");
2457 return;
2458 }
2459 } else {
2460 /* suspend current port */
2461 err = usbd_req_set_port_link_state(udev->parent_hub,
2462 NULL, udev->port_no, UPS_PORT_LS_U3);
2463 if (err) {
2464 DPRINTFN(0, "Suspending port failed\n");
2465 return;
2466 }
2440 }
2441
2442 udev = udev->parent_hub;
2443 goto repeat;
2444}
2445
2446/*------------------------------------------------------------------------*
2447 * usbd_set_power_mode

--- 61 unchanged lines hidden ---
2467 }
2468
2469 udev = udev->parent_hub;
2470 goto repeat;
2471}
2472
2473/*------------------------------------------------------------------------*
2474 * usbd_set_power_mode

--- 61 unchanged lines hidden ---