FreeCalypso > hg > fc-usbser-tools
annotate libuwrap/claim_if.c @ 102:4f72e09fb698
doc/CP2102-EEPROM-tools: complete for now
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Sep 2023 21:13:33 +0000 |
parents | 5cbde3c80c24 |
children |
rev | line source |
---|---|
12
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
44
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
2 * The operation of programming an FTDI EEPROM *can* be done without ever |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
3 * claiming any of the chip's interfaces and without unbinding ttyUSB from |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
4 * any channel, even if we are doing the special magic sequence for FT232R. |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
5 * However, given the identity-altering nature of EEPROM programming it is |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
6 * generally a good idea to claim all interfaces and unbind all ttyUSB |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
7 * devices, and in the case of FT232R the magic sequence breaks normal |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
8 * UART operation. |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
9 * |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
10 * This library module provides building block functions: a function for |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
11 * claiming one interface and a higher-level function claiming all interfaces |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
12 * of a multichannel device. |
12
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 */ |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <stdio.h> |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <stdlib.h> |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include <usb.h> |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "open_close.h" |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
40
f5847be43d35
fc-duart28-conf: bump off both ttyUSB devices on set operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
20 void usbwrap_claim_interface(usb_dev_handle *usbh, int ifnum, int detach) |
12
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (detach) |
40
f5847be43d35
fc-duart28-conf: bump off both ttyUSB devices on set operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
23 usb_detach_kernel_driver_np(usbh, ifnum); |
f5847be43d35
fc-duart28-conf: bump off both ttyUSB devices on set operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
24 if (usb_claim_interface(usbh, ifnum) != 0) { |
12
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 fprintf(stderr, "error: usb_claim_interface() failed\n"); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 exit(1); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
44
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
29 |
68
5cbde3c80c24
fteeprom-{erase,prog}: detach logic: change to detach by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
30 void usbwrap_claim_all_ifs(usb_dev_handle *usbh) |
44
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
31 { |
68
5cbde3c80c24
fteeprom-{erase,prog}: detach logic: change to detach by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
32 struct usb_device *dev = usb_device(usbh); |
5cbde3c80c24
fteeprom-{erase,prog}: detach logic: change to detach by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
33 unsigned numint = dev->config->bNumInterfaces; |
44
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
34 unsigned n; |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
35 |
68
5cbde3c80c24
fteeprom-{erase,prog}: detach logic: change to detach by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
36 for (n = 0; n < numint; n++) |
44
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
37 usbwrap_claim_interface(usbh, n, 1); |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
38 } |