/[scripts]/trunk/usbreset.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/usbreset.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 137 - (hide annotations)
Mon Sep 13 16:36:31 2010 UTC (12 years, 4 months ago) by dpavlin
File MIME type: text/plain
File size: 1547 byte(s)
mount usbfs
1 dpavlin 113 /* usbreset -- send a USB port reset to a USB device */
2    
3     /*
4    
5 dpavlin 137 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 dpavlin 113 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     }

  ViewVC Help
Powered by ViewVC 1.1.26