| 1 | /* usbreset -- send a USB port reset to a USB device */ |
| 2 | |
| 3 | /* |
| 4 | |
| 5 | http://marc.info/?l=linux-usb-users&m=116827193506484&w=2 |
| 6 | |
| 7 | and needs mounted usbfs filesystem |
| 8 | |
| 9 | sudo mount -t usbfs none /proc/bus/usb |
| 10 | |
| 11 | There is a way to suspend a USB device. In order to use it, |
| 12 | you must have a kernel with CONFIG_PM_SYSFS_DEPRECATED turned on. To |
| 13 | suspend a device, do (as root): |
| 14 | |
| 15 | echo -n 2 >/sys/bus/usb/devices/.../power/state |
| 16 | |
| 17 | where the "..." is the ID for your device. To unsuspend, do the same |
| 18 | thing but with a "0" instead of the "2" above. |
| 19 | |
| 20 | Note that this mechanism is slated to be removed from the kernel within |
| 21 | the next year. Hopefully some other mechanism will take its place. |
| 22 | |
| 23 | > To reset a |
| 24 | > device? |
| 25 | |
| 26 | Here's a program to do it. You invoke it as either |
| 27 | |
| 28 | usbreset /proc/bus/usb/BBB/DDD |
| 29 | or |
| 30 | usbreset /dev/usbB.D |
| 31 | |
| 32 | depending on how your system is set up, where BBB and DDD are the bus and |
| 33 | device address numbers. |
| 34 | |
| 35 | Alan Stern |
| 36 | |
| 37 | */ |
| 38 | |
| 39 | #include <stdio.h> |
| 40 | #include <unistd.h> |
| 41 | #include <fcntl.h> |
| 42 | #include <errno.h> |
| 43 | #include <sys/ioctl.h> |
| 44 | |
| 45 | #include <linux/usbdevice_fs.h> |
| 46 | |
| 47 | |
| 48 | int main(int argc, char **argv) |
| 49 | { |
| 50 | const char *filename; |
| 51 | int fd; |
| 52 | int rc; |
| 53 | |
| 54 | if (argc != 2) { |
| 55 | fprintf(stderr, "Usage: usbreset device-filename\n"); |
| 56 | return 1; |
| 57 | } |
| 58 | filename = argv[1]; |
| 59 | |
| 60 | fd = open(filename, O_WRONLY); |
| 61 | if (fd < 0) { |
| 62 | perror("Error opening output file"); |
| 63 | return 1; |
| 64 | } |
| 65 | |
| 66 | printf("Resetting USB device %s\n", filename); |
| 67 | rc = ioctl(fd, USBDEVFS_RESET, 0); |
| 68 | if (rc < 0) { |
| 69 | perror("Error in ioctl"); |
| 70 | return 1; |
| 71 | } |
| 72 | printf("Reset successful\n"); |
| 73 | |
| 74 | close(fd); |
| 75 | return 0; |
| 76 | } |
| 77 | |