diff options
author | Jiri Kosina <jkosina@suse.cz> | 2010-08-11 03:36:51 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2010-08-11 03:36:51 -0400 |
commit | 6396fc3b3ff3f6b942992b653a62df11dcef9bea (patch) | |
tree | db3c7cbe833b43c653adc99f70941431c5ff7c4e /drivers/usb/gadget | |
parent | 4785879e4d340e24e54f6de2ccfc42728b912808 (diff) | |
parent | 3d30701b58970425e1d45994d6cb82f828924fdd (diff) |
Merge branch 'master' into for-next
Conflicts:
fs/exofs/inode.c
Diffstat (limited to 'drivers/usb/gadget')
29 files changed, 1178 insertions, 466 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 591ae9fde199..cd27f9bde2c8 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -714,6 +714,7 @@ config USB_GADGETFS | |||
714 | config USB_FUNCTIONFS | 714 | config USB_FUNCTIONFS |
715 | tristate "Function Filesystem (EXPERIMENTAL)" | 715 | tristate "Function Filesystem (EXPERIMENTAL)" |
716 | depends on EXPERIMENTAL | 716 | depends on EXPERIMENTAL |
717 | select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) | ||
717 | help | 718 | help |
718 | The Function Filesystem (FunctioFS) lets one create USB | 719 | The Function Filesystem (FunctioFS) lets one create USB |
719 | composite functions in user space in the same way as GadgetFS | 720 | composite functions in user space in the same way as GadgetFS |
@@ -722,31 +723,31 @@ config USB_FUNCTIONFS | |||
722 | implemented in kernel space (for instance Ethernet, serial or | 723 | implemented in kernel space (for instance Ethernet, serial or |
723 | mass storage) and other are implemented in user space. | 724 | mass storage) and other are implemented in user space. |
724 | 725 | ||
726 | If you say "y" or "m" here you will be able what kind of | ||
727 | configurations the gadget will provide. | ||
728 | |||
725 | Say "y" to link the driver statically, or "m" to build | 729 | Say "y" to link the driver statically, or "m" to build |
726 | a dynamically linked module called "g_ffs". | 730 | a dynamically linked module called "g_ffs". |
727 | 731 | ||
728 | config USB_FUNCTIONFS_ETH | 732 | config USB_FUNCTIONFS_ETH |
729 | bool "Include CDC ECM (Ethernet) function" | 733 | bool "Include configuration with CDC ECM (Ethernet)" |
730 | depends on USB_FUNCTIONFS && NET | 734 | depends on USB_FUNCTIONFS && NET |
731 | help | 735 | help |
732 | Include an CDC ECM (Ethernet) funcion in the CDC ECM (Funcion) | 736 | Include a configuration with CDC ECM funcion (Ethernet) and the |
733 | Filesystem. If you also say "y" to the RNDIS query below the | 737 | Funcion Filesystem. |
734 | gadget will have two configurations. | ||
735 | 738 | ||
736 | config USB_FUNCTIONFS_RNDIS | 739 | config USB_FUNCTIONFS_RNDIS |
737 | bool "Include RNDIS (Ethernet) function" | 740 | bool "Include configuration with RNDIS (Ethernet)" |
738 | depends on USB_FUNCTIONFS && NET | 741 | depends on USB_FUNCTIONFS && NET |
739 | help | 742 | help |
740 | Include an RNDIS (Ethernet) funcion in the Funcion Filesystem. | 743 | Include a configuration with RNDIS funcion (Ethernet) and the Filesystem. |
741 | If you also say "y" to the CDC ECM query above the gadget will | ||
742 | have two configurations. | ||
743 | 744 | ||
744 | config USB_FUNCTIONFS_GENERIC | 745 | config USB_FUNCTIONFS_GENERIC |
745 | bool "Include 'pure' configuration" | 746 | bool "Include 'pure' configuration" |
746 | depends on USB_FUNCTIONFS && (USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) | 747 | depends on USB_FUNCTIONFS |
747 | help | 748 | help |
748 | Include a configuration with FunctionFS and no Ethernet | 749 | Include a configuration with the Function Filesystem alone with |
749 | configuration. | 750 | no Ethernet interface. |
750 | 751 | ||
751 | config USB_FILE_STORAGE | 752 | config USB_FILE_STORAGE |
752 | tristate "File-backed Storage Gadget" | 753 | tristate "File-backed Storage Gadget" |
@@ -863,6 +864,7 @@ config USB_G_NOKIA | |||
863 | config USB_G_MULTI | 864 | config USB_G_MULTI |
864 | tristate "Multifunction Composite Gadget (EXPERIMENTAL)" | 865 | tristate "Multifunction Composite Gadget (EXPERIMENTAL)" |
865 | depends on BLOCK && NET | 866 | depends on BLOCK && NET |
867 | select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS | ||
866 | help | 868 | help |
867 | The Multifunction Composite Gadget provides Ethernet (RNDIS | 869 | The Multifunction Composite Gadget provides Ethernet (RNDIS |
868 | and/or CDC Ethernet), mass storage and ACM serial link | 870 | and/or CDC Ethernet), mass storage and ACM serial link |
@@ -913,6 +915,34 @@ config USB_G_HID | |||
913 | Say "y" to link the driver statically, or "m" to build a | 915 | Say "y" to link the driver statically, or "m" to build a |
914 | dynamically linked module called "g_hid". | 916 | dynamically linked module called "g_hid". |
915 | 917 | ||
918 | config USB_G_DBGP | ||
919 | tristate "EHCI Debug Device Gadget" | ||
920 | help | ||
921 | This gadget emulates an EHCI Debug device. This is useful when you want | ||
922 | to interact with an EHCI Debug Port. | ||
923 | |||
924 | Say "y" to link the driver statically, or "m" to build a | ||
925 | dynamically linked module called "g_dbgp". | ||
926 | |||
927 | if USB_G_DBGP | ||
928 | choice | ||
929 | prompt "EHCI Debug Device mode" | ||
930 | default USB_G_DBGP_SERIAL | ||
931 | |||
932 | config USB_G_DBGP_PRINTK | ||
933 | depends on USB_G_DBGP | ||
934 | bool "printk" | ||
935 | help | ||
936 | Directly printk() received data. No interaction. | ||
937 | |||
938 | config USB_G_DBGP_SERIAL | ||
939 | depends on USB_G_DBGP | ||
940 | bool "serial" | ||
941 | help | ||
942 | Userland can interact using /dev/ttyGSxxx. | ||
943 | endchoice | ||
944 | endif | ||
945 | |||
916 | # put drivers that need isochronous transfer support (for audio | 946 | # put drivers that need isochronous transfer support (for audio |
917 | # or video class gadget drivers), or specific hardware, here. | 947 | # or video class gadget drivers), or specific hardware, here. |
918 | config USB_G_WEBCAM | 948 | config USB_G_WEBCAM |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 9bcde110feb1..27283df37d09 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -44,6 +44,7 @@ g_printer-objs := printer.o | |||
44 | g_cdc-objs := cdc2.o | 44 | g_cdc-objs := cdc2.o |
45 | g_multi-objs := multi.o | 45 | g_multi-objs := multi.o |
46 | g_hid-objs := hid.o | 46 | g_hid-objs := hid.o |
47 | g_dbgp-objs := dbgp.o | ||
47 | g_nokia-objs := nokia.o | 48 | g_nokia-objs := nokia.o |
48 | g_webcam-objs := webcam.o | 49 | g_webcam-objs := webcam.o |
49 | 50 | ||
@@ -52,7 +53,6 @@ obj-$(CONFIG_USB_AUDIO) += g_audio.o | |||
52 | obj-$(CONFIG_USB_ETH) += g_ether.o | 53 | obj-$(CONFIG_USB_ETH) += g_ether.o |
53 | obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o | 54 | obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o |
54 | obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o | 55 | obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o |
55 | obj-$(CONFIG_USB_ETH_FUNCTIONFS) += g_eth_ffs.o | ||
56 | obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o | 56 | obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o |
57 | obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o | 57 | obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o |
58 | obj-$(CONFIG_USB_G_SERIAL) += g_serial.o | 58 | obj-$(CONFIG_USB_G_SERIAL) += g_serial.o |
@@ -60,6 +60,7 @@ obj-$(CONFIG_USB_G_PRINTER) += g_printer.o | |||
60 | obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o | 60 | obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o |
61 | obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o | 61 | obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o |
62 | obj-$(CONFIG_USB_G_HID) += g_hid.o | 62 | obj-$(CONFIG_USB_G_HID) += g_hid.o |
63 | obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o | ||
63 | obj-$(CONFIG_USB_G_MULTI) += g_multi.o | 64 | obj-$(CONFIG_USB_G_MULTI) += g_multi.o |
64 | obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o | 65 | obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o |
65 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o | 66 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o |
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c index a62af7b59094..b744ccd0f34d 100644 --- a/drivers/usb/gadget/audio.c +++ b/drivers/usb/gadget/audio.c | |||
@@ -89,7 +89,7 @@ static const struct usb_descriptor_header *otg_desc[] = { | |||
89 | 89 | ||
90 | /*-------------------------------------------------------------------------*/ | 90 | /*-------------------------------------------------------------------------*/ |
91 | 91 | ||
92 | static int __init audio_do_config(struct usb_configuration *c) | 92 | static int __ref audio_do_config(struct usb_configuration *c) |
93 | { | 93 | { |
94 | /* FIXME alloc iConfiguration string, set it in c->strings */ | 94 | /* FIXME alloc iConfiguration string, set it in c->strings */ |
95 | 95 | ||
@@ -113,7 +113,7 @@ static struct usb_configuration audio_config_driver = { | |||
113 | 113 | ||
114 | /*-------------------------------------------------------------------------*/ | 114 | /*-------------------------------------------------------------------------*/ |
115 | 115 | ||
116 | static int __init audio_bind(struct usb_composite_dev *cdev) | 116 | static int __ref audio_bind(struct usb_composite_dev *cdev) |
117 | { | 117 | { |
118 | int gcnum; | 118 | int gcnum; |
119 | int status; | 119 | int status; |
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index 928137d3dbdc..1f5ba2fd4c1f 100644 --- a/drivers/usb/gadget/cdc2.c +++ b/drivers/usb/gadget/cdc2.c | |||
@@ -129,7 +129,7 @@ static u8 hostaddr[ETH_ALEN]; | |||
129 | /* | 129 | /* |
130 | * We _always_ have both CDC ECM and CDC ACM functions. | 130 | * We _always_ have both CDC ECM and CDC ACM functions. |
131 | */ | 131 | */ |
132 | static int __init cdc_do_config(struct usb_configuration *c) | 132 | static int __ref cdc_do_config(struct usb_configuration *c) |
133 | { | 133 | { |
134 | int status; | 134 | int status; |
135 | 135 | ||
@@ -159,7 +159,7 @@ static struct usb_configuration cdc_config_driver = { | |||
159 | 159 | ||
160 | /*-------------------------------------------------------------------------*/ | 160 | /*-------------------------------------------------------------------------*/ |
161 | 161 | ||
162 | static int __init cdc_bind(struct usb_composite_dev *cdev) | 162 | static int __ref cdc_bind(struct usb_composite_dev *cdev) |
163 | { | 163 | { |
164 | int gcnum; | 164 | int gcnum; |
165 | struct usb_gadget *gadget = cdev->gadget; | 165 | struct usb_gadget *gadget = cdev->gadget; |
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 391d169f8d07..e483f80822d2 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -673,20 +673,83 @@ static int get_string(struct usb_composite_dev *cdev, | |||
673 | * string IDs. Drivers for functions, configurations, or gadgets will | 673 | * string IDs. Drivers for functions, configurations, or gadgets will |
674 | * then store that ID in the appropriate descriptors and string table. | 674 | * then store that ID in the appropriate descriptors and string table. |
675 | * | 675 | * |
676 | * All string identifier should be allocated using this routine, to | 676 | * All string identifier should be allocated using this, |
677 | * ensure that for example different functions don't wrongly assign | 677 | * @usb_string_ids_tab() or @usb_string_ids_n() routine, to ensure |
678 | * different meanings to the same identifier. | 678 | * that for example different functions don't wrongly assign different |
679 | * meanings to the same identifier. | ||
679 | */ | 680 | */ |
680 | int usb_string_id(struct usb_composite_dev *cdev) | 681 | int usb_string_id(struct usb_composite_dev *cdev) |
681 | { | 682 | { |
682 | if (cdev->next_string_id < 254) { | 683 | if (cdev->next_string_id < 254) { |
683 | /* string id 0 is reserved */ | 684 | /* string id 0 is reserved by USB spec for list of |
685 | * supported languages */ | ||
686 | /* 255 reserved as well? -- mina86 */ | ||
684 | cdev->next_string_id++; | 687 | cdev->next_string_id++; |
685 | return cdev->next_string_id; | 688 | return cdev->next_string_id; |
686 | } | 689 | } |
687 | return -ENODEV; | 690 | return -ENODEV; |
688 | } | 691 | } |
689 | 692 | ||
693 | /** | ||
694 | * usb_string_ids() - allocate unused string IDs in batch | ||
695 | * @cdev: the device whose string descriptor IDs are being allocated | ||
696 | * @str: an array of usb_string objects to assign numbers to | ||
697 | * Context: single threaded during gadget setup | ||
698 | * | ||
699 | * @usb_string_ids() is called from bind() callbacks to allocate | ||
700 | * string IDs. Drivers for functions, configurations, or gadgets will | ||
701 | * then copy IDs from the string table to the appropriate descriptors | ||
702 | * and string table for other languages. | ||
703 | * | ||
704 | * All string identifier should be allocated using this, | ||
705 | * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for | ||
706 | * example different functions don't wrongly assign different meanings | ||
707 | * to the same identifier. | ||
708 | */ | ||
709 | int usb_string_ids_tab(struct usb_composite_dev *cdev, struct usb_string *str) | ||
710 | { | ||
711 | int next = cdev->next_string_id; | ||
712 | |||
713 | for (; str->s; ++str) { | ||
714 | if (unlikely(next >= 254)) | ||
715 | return -ENODEV; | ||
716 | str->id = ++next; | ||
717 | } | ||
718 | |||
719 | cdev->next_string_id = next; | ||
720 | |||
721 | return 0; | ||
722 | } | ||
723 | |||
724 | /** | ||
725 | * usb_string_ids_n() - allocate unused string IDs in batch | ||
726 | * @cdev: the device whose string descriptor IDs are being allocated | ||
727 | * @n: number of string IDs to allocate | ||
728 | * Context: single threaded during gadget setup | ||
729 | * | ||
730 | * Returns the first requested ID. This ID and next @n-1 IDs are now | ||
731 | * valid IDs. At least providind that @n is non zore because if it | ||
732 | * is, returns last requested ID which is now very useful information. | ||
733 | * | ||
734 | * @usb_string_ids_n() is called from bind() callbacks to allocate | ||
735 | * string IDs. Drivers for functions, configurations, or gadgets will | ||
736 | * then store that ID in the appropriate descriptors and string table. | ||
737 | * | ||
738 | * All string identifier should be allocated using this, | ||
739 | * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for | ||
740 | * example different functions don't wrongly assign different meanings | ||
741 | * to the same identifier. | ||
742 | */ | ||
743 | int usb_string_ids_n(struct usb_composite_dev *c, unsigned n) | ||
744 | { | ||
745 | unsigned next = c->next_string_id; | ||
746 | if (unlikely(n > 254 || (unsigned)next + n > 254)) | ||
747 | return -ENODEV; | ||
748 | c->next_string_id += n; | ||
749 | return next + 1; | ||
750 | } | ||
751 | |||
752 | |||
690 | /*-------------------------------------------------------------------------*/ | 753 | /*-------------------------------------------------------------------------*/ |
691 | 754 | ||
692 | static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) | 755 | static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) |
@@ -893,6 +956,8 @@ static void composite_disconnect(struct usb_gadget *gadget) | |||
893 | spin_lock_irqsave(&cdev->lock, flags); | 956 | spin_lock_irqsave(&cdev->lock, flags); |
894 | if (cdev->config) | 957 | if (cdev->config) |
895 | reset_config(cdev); | 958 | reset_config(cdev); |
959 | if (composite->disconnect) | ||
960 | composite->disconnect(cdev); | ||
896 | spin_unlock_irqrestore(&cdev->lock, flags); | 961 | spin_unlock_irqrestore(&cdev->lock, flags); |
897 | } | 962 | } |
898 | 963 | ||
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c new file mode 100644 index 000000000000..0ed50a2c0a36 --- /dev/null +++ b/drivers/usb/gadget/dbgp.c | |||
@@ -0,0 +1,434 @@ | |||
1 | /* | ||
2 | * dbgp.c -- EHCI Debug Port device gadget | ||
3 | * | ||
4 | * Copyright (C) 2010 Stephane Duverger | ||
5 | * | ||
6 | * Released under the GPLv2. | ||
7 | * | ||
8 | */ | ||
9 | |||
10 | /* verbose messages */ | ||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/device.h> | ||
13 | #include <linux/usb/ch9.h> | ||
14 | #include <linux/usb/gadget.h> | ||
15 | |||
16 | /* See comments in "zero.c" */ | ||
17 | #include "epautoconf.c" | ||
18 | |||
19 | #ifdef CONFIG_USB_G_DBGP_SERIAL | ||
20 | #include "u_serial.c" | ||
21 | #endif | ||
22 | |||
23 | #define DRIVER_VENDOR_ID 0x0525 /* NetChip */ | ||
24 | #define DRIVER_PRODUCT_ID 0xc0de /* undefined */ | ||
25 | |||
26 | #define USB_DEBUG_MAX_PACKET_SIZE 8 | ||
27 | #define DBGP_REQ_EP0_LEN 128 | ||
28 | #define DBGP_REQ_LEN 512 | ||
29 | |||
30 | static struct dbgp { | ||
31 | struct usb_gadget *gadget; | ||
32 | struct usb_request *req; | ||
33 | struct usb_ep *i_ep; | ||
34 | struct usb_ep *o_ep; | ||
35 | #ifdef CONFIG_USB_G_DBGP_SERIAL | ||
36 | struct gserial *serial; | ||
37 | #endif | ||
38 | } dbgp; | ||
39 | |||
40 | static struct usb_device_descriptor device_desc = { | ||
41 | .bLength = sizeof device_desc, | ||
42 | .bDescriptorType = USB_DT_DEVICE, | ||
43 | .bcdUSB = __constant_cpu_to_le16(0x0200), | ||
44 | .bDeviceClass = USB_CLASS_VENDOR_SPEC, | ||
45 | .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_ID), | ||
46 | .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_ID), | ||
47 | .bNumConfigurations = 1, | ||
48 | }; | ||
49 | |||
50 | static struct usb_debug_descriptor dbg_desc = { | ||
51 | .bLength = sizeof dbg_desc, | ||
52 | .bDescriptorType = USB_DT_DEBUG, | ||
53 | }; | ||
54 | |||
55 | static struct usb_endpoint_descriptor i_desc = { | ||
56 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
57 | .bDescriptorType = USB_DT_ENDPOINT, | ||
58 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
59 | .bEndpointAddress = USB_DIR_IN, | ||
60 | }; | ||
61 | |||
62 | static struct usb_endpoint_descriptor o_desc = { | ||
63 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
64 | .bDescriptorType = USB_DT_ENDPOINT, | ||
65 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
66 | .bEndpointAddress = USB_DIR_OUT, | ||
67 | }; | ||
68 | |||
69 | #ifdef CONFIG_USB_G_DBGP_PRINTK | ||
70 | static int dbgp_consume(char *buf, unsigned len) | ||
71 | { | ||
72 | char c; | ||
73 | |||
74 | if (!len) | ||
75 | return 0; | ||
76 | |||
77 | c = buf[len-1]; | ||
78 | if (c != 0) | ||
79 | buf[len-1] = 0; | ||
80 | |||
81 | printk(KERN_NOTICE "%s%c", buf, c); | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | static void __disable_ep(struct usb_ep *ep) | ||
86 | { | ||
87 | if (ep && ep->driver_data == dbgp.gadget) { | ||
88 | usb_ep_disable(ep); | ||
89 | ep->driver_data = NULL; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | static void dbgp_disable_ep(void) | ||
94 | { | ||
95 | __disable_ep(dbgp.i_ep); | ||
96 | __disable_ep(dbgp.o_ep); | ||
97 | } | ||
98 | |||
99 | static void dbgp_complete(struct usb_ep *ep, struct usb_request *req) | ||
100 | { | ||
101 | int stp; | ||
102 | int err = 0; | ||
103 | int status = req->status; | ||
104 | |||
105 | if (ep == dbgp.i_ep) { | ||
106 | stp = 1; | ||
107 | goto fail; | ||
108 | } | ||
109 | |||
110 | if (status != 0) { | ||
111 | stp = 2; | ||
112 | goto release_req; | ||
113 | } | ||
114 | |||
115 | dbgp_consume(req->buf, req->actual); | ||
116 | |||
117 | req->length = DBGP_REQ_LEN; | ||
118 | err = usb_ep_queue(ep, req, GFP_ATOMIC); | ||
119 | if (err < 0) { | ||
120 | stp = 3; | ||
121 | goto release_req; | ||
122 | } | ||
123 | |||
124 | return; | ||
125 | |||
126 | release_req: | ||
127 | kfree(req->buf); | ||
128 | usb_ep_free_request(dbgp.o_ep, req); | ||
129 | dbgp_disable_ep(); | ||
130 | fail: | ||
131 | dev_dbg(&dbgp.gadget->dev, | ||
132 | "complete: failure (%d:%d) ==> %d\n", stp, err, status); | ||
133 | } | ||
134 | |||
135 | static int dbgp_enable_ep_req(struct usb_ep *ep) | ||
136 | { | ||
137 | int err, stp; | ||
138 | struct usb_request *req; | ||
139 | |||
140 | req = usb_ep_alloc_request(ep, GFP_KERNEL); | ||
141 | if (!req) { | ||
142 | err = -ENOMEM; | ||
143 | stp = 1; | ||
144 | goto fail_1; | ||
145 | } | ||
146 | |||
147 | req->buf = kmalloc(DBGP_REQ_LEN, GFP_KERNEL); | ||
148 | if (!req->buf) { | ||
149 | err = -ENOMEM; | ||
150 | stp = 2; | ||
151 | goto fail_2; | ||
152 | } | ||
153 | |||
154 | req->complete = dbgp_complete; | ||
155 | req->length = DBGP_REQ_LEN; | ||
156 | err = usb_ep_queue(ep, req, GFP_ATOMIC); | ||
157 | if (err < 0) { | ||
158 | stp = 3; | ||
159 | goto fail_3; | ||
160 | } | ||
161 | |||
162 | return 0; | ||
163 | |||
164 | fail_3: | ||
165 | kfree(req->buf); | ||
166 | fail_2: | ||
167 | usb_ep_free_request(dbgp.o_ep, req); | ||
168 | fail_1: | ||
169 | dev_dbg(&dbgp.gadget->dev, | ||
170 | "enable ep req: failure (%d:%d)\n", stp, err); | ||
171 | return err; | ||
172 | } | ||
173 | |||
174 | static int __enable_ep(struct usb_ep *ep, struct usb_endpoint_descriptor *desc) | ||
175 | { | ||
176 | int err = usb_ep_enable(ep, desc); | ||
177 | ep->driver_data = dbgp.gadget; | ||
178 | return err; | ||
179 | } | ||
180 | |||
181 | static int dbgp_enable_ep(void) | ||
182 | { | ||
183 | int err, stp; | ||
184 | |||
185 | err = __enable_ep(dbgp.i_ep, &i_desc); | ||
186 | if (err < 0) { | ||
187 | stp = 1; | ||
188 | goto fail_1; | ||
189 | } | ||
190 | |||
191 | err = __enable_ep(dbgp.o_ep, &o_desc); | ||
192 | if (err < 0) { | ||
193 | stp = 2; | ||
194 | goto fail_2; | ||
195 | } | ||
196 | |||
197 | err = dbgp_enable_ep_req(dbgp.o_ep); | ||
198 | if (err < 0) { | ||
199 | stp = 3; | ||
200 | goto fail_3; | ||
201 | } | ||
202 | |||
203 | return 0; | ||
204 | |||
205 | fail_3: | ||
206 | __disable_ep(dbgp.o_ep); | ||
207 | fail_2: | ||
208 | __disable_ep(dbgp.i_ep); | ||
209 | fail_1: | ||
210 | dev_dbg(&dbgp.gadget->dev, "enable ep: failure (%d:%d)\n", stp, err); | ||
211 | return err; | ||
212 | } | ||
213 | #endif | ||
214 | |||
215 | static void dbgp_disconnect(struct usb_gadget *gadget) | ||
216 | { | ||
217 | #ifdef CONFIG_USB_G_DBGP_PRINTK | ||
218 | dbgp_disable_ep(); | ||
219 | #else | ||
220 | gserial_disconnect(dbgp.serial); | ||
221 | #endif | ||
222 | } | ||
223 | |||
224 | static void dbgp_unbind(struct usb_gadget *gadget) | ||
225 | { | ||
226 | #ifdef CONFIG_USB_G_DBGP_SERIAL | ||
227 | kfree(dbgp.serial); | ||
228 | #endif | ||
229 | if (dbgp.req) { | ||
230 | kfree(dbgp.req->buf); | ||
231 | usb_ep_free_request(gadget->ep0, dbgp.req); | ||
232 | } | ||
233 | |||
234 | gadget->ep0->driver_data = NULL; | ||
235 | } | ||
236 | |||
237 | static int __init dbgp_configure_endpoints(struct usb_gadget *gadget) | ||
238 | { | ||
239 | int stp; | ||
240 | |||
241 | usb_ep_autoconfig_reset(gadget); | ||
242 | |||
243 | dbgp.i_ep = usb_ep_autoconfig(gadget, &i_desc); | ||
244 | if (!dbgp.i_ep) { | ||
245 | stp = 1; | ||
246 | goto fail_1; | ||
247 | } | ||
248 | |||
249 | dbgp.i_ep->driver_data = gadget; | ||
250 | i_desc.wMaxPacketSize = | ||
251 | __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE); | ||
252 | |||
253 | dbgp.o_ep = usb_ep_autoconfig(gadget, &o_desc); | ||
254 | if (!dbgp.o_ep) { | ||
255 | dbgp.i_ep->driver_data = NULL; | ||
256 | stp = 2; | ||
257 | goto fail_2; | ||
258 | } | ||
259 | |||
260 | dbgp.o_ep->driver_data = gadget; | ||
261 | o_desc.wMaxPacketSize = | ||
262 | __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE); | ||
263 | |||
264 | dbg_desc.bDebugInEndpoint = i_desc.bEndpointAddress & 0x7f; | ||
265 | dbg_desc.bDebugOutEndpoint = o_desc.bEndpointAddress & 0x7f; | ||
266 | |||
267 | #ifdef CONFIG_USB_G_DBGP_SERIAL | ||
268 | dbgp.serial->in = dbgp.i_ep; | ||
269 | dbgp.serial->out = dbgp.o_ep; | ||
270 | |||
271 | dbgp.serial->in_desc = &i_desc; | ||
272 | dbgp.serial->out_desc = &o_desc; | ||
273 | |||
274 | if (gserial_setup(gadget, 1) < 0) { | ||
275 | stp = 3; | ||
276 | goto fail_3; | ||
277 | } | ||
278 | |||
279 | return 0; | ||
280 | |||
281 | fail_3: | ||
282 | dbgp.o_ep->driver_data = NULL; | ||
283 | #else | ||
284 | return 0; | ||
285 | #endif | ||
286 | fail_2: | ||
287 | dbgp.i_ep->driver_data = NULL; | ||
288 | fail_1: | ||
289 | dev_dbg(&dbgp.gadget->dev, "ep config: failure (%d)\n", stp); | ||
290 | return -ENODEV; | ||
291 | } | ||
292 | |||
293 | static int __init dbgp_bind(struct usb_gadget *gadget) | ||
294 | { | ||
295 | int err, stp; | ||
296 | |||
297 | dbgp.gadget = gadget; | ||
298 | |||
299 | dbgp.req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); | ||
300 | if (!dbgp.req) { | ||
301 | err = -ENOMEM; | ||
302 | stp = 1; | ||
303 | goto fail; | ||
304 | } | ||
305 | |||
306 | dbgp.req->buf = kmalloc(DBGP_REQ_EP0_LEN, GFP_KERNEL); | ||
307 | if (!dbgp.req->buf) { | ||
308 | err = -ENOMEM; | ||
309 | stp = 2; | ||
310 | goto fail; | ||
311 | } | ||
312 | |||
313 | dbgp.req->length = DBGP_REQ_EP0_LEN; | ||
314 | gadget->ep0->driver_data = gadget; | ||
315 | |||
316 | #ifdef CONFIG_USB_G_DBGP_SERIAL | ||
317 | dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL); | ||
318 | if (!dbgp.serial) { | ||
319 | stp = 3; | ||
320 | err = -ENOMEM; | ||
321 | goto fail; | ||
322 | } | ||
323 | #endif | ||
324 | err = dbgp_configure_endpoints(gadget); | ||
325 | if (err < 0) { | ||
326 | stp = 4; | ||
327 | goto fail; | ||
328 | } | ||
329 | |||
330 | dev_dbg(&dbgp.gadget->dev, "bind: success\n"); | ||
331 | return 0; | ||
332 | |||
333 | fail: | ||
334 | dev_dbg(&gadget->dev, "bind: failure (%d:%d)\n", stp, err); | ||
335 | dbgp_unbind(gadget); | ||
336 | return err; | ||
337 | } | ||
338 | |||
339 | static void dbgp_setup_complete(struct usb_ep *ep, | ||
340 | struct usb_request *req) | ||
341 | { | ||
342 | dev_dbg(&dbgp.gadget->dev, "setup complete: %d, %d/%d\n", | ||
343 | req->status, req->actual, req->length); | ||
344 | } | ||
345 | |||
346 | static int dbgp_setup(struct usb_gadget *gadget, | ||
347 | const struct usb_ctrlrequest *ctrl) | ||
348 | { | ||
349 | struct usb_request *req = dbgp.req; | ||
350 | u8 request = ctrl->bRequest; | ||
351 | u16 value = le16_to_cpu(ctrl->wValue); | ||
352 | u16 length = le16_to_cpu(ctrl->wLength); | ||
353 | int err = 0; | ||
354 | void *data; | ||
355 | u16 len; | ||
356 | |||
357 | gadget->ep0->driver_data = gadget; | ||
358 | |||
359 | if (request == USB_REQ_GET_DESCRIPTOR) { | ||
360 | switch (value>>8) { | ||
361 | case USB_DT_DEVICE: | ||
362 | dev_dbg(&dbgp.gadget->dev, "setup: desc device\n"); | ||
363 | len = sizeof device_desc; | ||
364 | data = &device_desc; | ||
365 | break; | ||
366 | case USB_DT_DEBUG: | ||
367 | dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n"); | ||
368 | len = sizeof dbg_desc; | ||
369 | data = &dbg_desc; | ||
370 | break; | ||
371 | default: | ||
372 | goto fail; | ||
373 | } | ||
374 | } else if (request == USB_REQ_SET_FEATURE && | ||
375 | value == USB_DEVICE_DEBUG_MODE) { | ||
376 | len = 0; | ||
377 | data = NULL; | ||
378 | dev_dbg(&dbgp.gadget->dev, "setup: feat debug\n"); | ||
379 | #ifdef CONFIG_USB_G_DBGP_PRINTK | ||
380 | err = dbgp_enable_ep(); | ||
381 | #else | ||
382 | err = gserial_connect(dbgp.serial, 0); | ||
383 | #endif | ||
384 | if (err < 0) | ||
385 | goto fail; | ||
386 | } else | ||
387 | goto fail; | ||
388 | |||
389 | if (len >= 0) { | ||
390 | req->length = min(length, len); | ||
391 | req->zero = len < req->length; | ||
392 | if (data && req->length) | ||
393 | memcpy(req->buf, data, req->length); | ||
394 | |||
395 | req->complete = dbgp_setup_complete; | ||
396 | return usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); | ||
397 | } | ||
398 | |||
399 | fail: | ||
400 | dev_dbg(&dbgp.gadget->dev, | ||
401 | "setup: failure req %x v %x\n", request, value); | ||
402 | return err; | ||
403 | } | ||
404 | |||
405 | static struct usb_gadget_driver dbgp_driver = { | ||
406 | .function = "dbgp", | ||
407 | .speed = USB_SPEED_HIGH, | ||
408 | .bind = dbgp_bind, | ||
409 | .unbind = dbgp_unbind, | ||
410 | .setup = dbgp_setup, | ||
411 | .disconnect = dbgp_disconnect, | ||
412 | .driver = { | ||
413 | .owner = THIS_MODULE, | ||
414 | .name = "dbgp" | ||
415 | }, | ||
416 | }; | ||
417 | |||
418 | static int __init dbgp_init(void) | ||
419 | { | ||
420 | return usb_gadget_register_driver(&dbgp_driver); | ||
421 | } | ||
422 | |||
423 | static void __exit dbgp_exit(void) | ||
424 | { | ||
425 | usb_gadget_unregister_driver(&dbgp_driver); | ||
426 | #ifdef CONFIG_USB_G_DBGP_SERIAL | ||
427 | gserial_cleanup(); | ||
428 | #endif | ||
429 | } | ||
430 | |||
431 | MODULE_AUTHOR("Stephane Duverger"); | ||
432 | MODULE_LICENSE("GPL"); | ||
433 | module_init(dbgp_init); | ||
434 | module_exit(dbgp_exit); | ||
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 4f9e578cde9d..dc6546248ed9 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -1542,7 +1542,7 @@ static int dummy_hub_status (struct usb_hcd *hcd, char *buf) | |||
1542 | dum = hcd_to_dummy (hcd); | 1542 | dum = hcd_to_dummy (hcd); |
1543 | 1543 | ||
1544 | spin_lock_irqsave (&dum->lock, flags); | 1544 | spin_lock_irqsave (&dum->lock, flags); |
1545 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) | 1545 | if (!HCD_HW_ACCESSIBLE(hcd)) |
1546 | goto done; | 1546 | goto done; |
1547 | 1547 | ||
1548 | if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) { | 1548 | if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) { |
@@ -1588,7 +1588,7 @@ static int dummy_hub_control ( | |||
1588 | int retval = 0; | 1588 | int retval = 0; |
1589 | unsigned long flags; | 1589 | unsigned long flags; |
1590 | 1590 | ||
1591 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) | 1591 | if (!HCD_HW_ACCESSIBLE(hcd)) |
1592 | return -ETIMEDOUT; | 1592 | return -ETIMEDOUT; |
1593 | 1593 | ||
1594 | dum = hcd_to_dummy (hcd); | 1594 | dum = hcd_to_dummy (hcd); |
@@ -1739,7 +1739,7 @@ static int dummy_bus_resume (struct usb_hcd *hcd) | |||
1739 | dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); | 1739 | dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); |
1740 | 1740 | ||
1741 | spin_lock_irq (&dum->lock); | 1741 | spin_lock_irq (&dum->lock); |
1742 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { | 1742 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
1743 | rc = -ESHUTDOWN; | 1743 | rc = -ESHUTDOWN; |
1744 | } else { | 1744 | } else { |
1745 | dum->rh_state = DUMMY_RH_RUNNING; | 1745 | dum->rh_state = DUMMY_RH_RUNNING; |
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 400f80372d93..114fa024c22c 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -237,7 +237,7 @@ static u8 hostaddr[ETH_ALEN]; | |||
237 | * the first one present. That's to make Microsoft's drivers happy, | 237 | * the first one present. That's to make Microsoft's drivers happy, |
238 | * and to follow DOCSIS 1.0 (cable modem standard). | 238 | * and to follow DOCSIS 1.0 (cable modem standard). |
239 | */ | 239 | */ |
240 | static int __init rndis_do_config(struct usb_configuration *c) | 240 | static int __ref rndis_do_config(struct usb_configuration *c) |
241 | { | 241 | { |
242 | /* FIXME alloc iConfiguration string, set it in c->strings */ | 242 | /* FIXME alloc iConfiguration string, set it in c->strings */ |
243 | 243 | ||
@@ -270,7 +270,7 @@ MODULE_PARM_DESC(use_eem, "use CDC EEM mode"); | |||
270 | /* | 270 | /* |
271 | * We _always_ have an ECM, CDC Subset, or EEM configuration. | 271 | * We _always_ have an ECM, CDC Subset, or EEM configuration. |
272 | */ | 272 | */ |
273 | static int __init eth_do_config(struct usb_configuration *c) | 273 | static int __ref eth_do_config(struct usb_configuration *c) |
274 | { | 274 | { |
275 | /* FIXME alloc iConfiguration string, set it in c->strings */ | 275 | /* FIXME alloc iConfiguration string, set it in c->strings */ |
276 | 276 | ||
@@ -297,7 +297,7 @@ static struct usb_configuration eth_config_driver = { | |||
297 | 297 | ||
298 | /*-------------------------------------------------------------------------*/ | 298 | /*-------------------------------------------------------------------------*/ |
299 | 299 | ||
300 | static int __init eth_bind(struct usb_composite_dev *cdev) | 300 | static int __ref eth_bind(struct usb_composite_dev *cdev) |
301 | { | 301 | { |
302 | int gcnum; | 302 | int gcnum; |
303 | struct usb_gadget *gadget = cdev->gadget; | 303 | struct usb_gadget *gadget = cdev->gadget; |
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 2aaa0f75c6cf..e4f595055208 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -714,9 +714,7 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value) | |||
714 | struct ffs_function *func = ffs->func; | 714 | struct ffs_function *func = ffs->func; |
715 | ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV; | 715 | ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV; |
716 | } else if (gadget->ops->ioctl) { | 716 | } else if (gadget->ops->ioctl) { |
717 | lock_kernel(); | ||
718 | ret = gadget->ops->ioctl(gadget, code, value); | 717 | ret = gadget->ops->ioctl(gadget, code, value); |
719 | unlock_kernel(); | ||
720 | } else { | 718 | } else { |
721 | ret = -ENOTTY; | 719 | ret = -ENOTTY; |
722 | } | 720 | } |
@@ -1377,7 +1375,8 @@ static void ffs_data_reset(struct ffs_data *ffs) | |||
1377 | 1375 | ||
1378 | static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) | 1376 | static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) |
1379 | { | 1377 | { |
1380 | unsigned i, count; | 1378 | struct usb_gadget_strings **lang; |
1379 | int first_id; | ||
1381 | 1380 | ||
1382 | ENTER(); | 1381 | ENTER(); |
1383 | 1382 | ||
@@ -1385,7 +1384,9 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) | |||
1385 | || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) | 1384 | || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) |
1386 | return -EBADFD; | 1385 | return -EBADFD; |
1387 | 1386 | ||
1388 | ffs_data_get(ffs); | 1387 | first_id = usb_string_ids_n(cdev, ffs->strings_count); |
1388 | if (unlikely(first_id < 0)) | ||
1389 | return first_id; | ||
1389 | 1390 | ||
1390 | ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); | 1391 | ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); |
1391 | if (unlikely(!ffs->ep0req)) | 1392 | if (unlikely(!ffs->ep0req)) |
@@ -1393,25 +1394,16 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) | |||
1393 | ffs->ep0req->complete = ffs_ep0_complete; | 1394 | ffs->ep0req->complete = ffs_ep0_complete; |
1394 | ffs->ep0req->context = ffs; | 1395 | ffs->ep0req->context = ffs; |
1395 | 1396 | ||
1396 | /* Get strings identifiers */ | 1397 | lang = ffs->stringtabs; |
1397 | for (count = ffs->strings_count, i = 0; i < count; ++i) { | 1398 | for (lang = ffs->stringtabs; *lang; ++lang) { |
1398 | struct usb_gadget_strings **lang; | 1399 | struct usb_string *str = (*lang)->strings; |
1399 | 1400 | int id = first_id; | |
1400 | int id = usb_string_id(cdev); | 1401 | for (; str->s; ++id, ++str) |
1401 | if (unlikely(id < 0)) { | 1402 | str->id = id; |
1402 | usb_ep_free_request(cdev->gadget->ep0, ffs->ep0req); | ||
1403 | ffs->ep0req = NULL; | ||
1404 | return id; | ||
1405 | } | ||
1406 | |||
1407 | lang = ffs->stringtabs; | ||
1408 | do { | ||
1409 | (*lang)->strings[i].id = id; | ||
1410 | ++lang; | ||
1411 | } while (*lang); | ||
1412 | } | 1403 | } |
1413 | 1404 | ||
1414 | ffs->gadget = cdev->gadget; | 1405 | ffs->gadget = cdev->gadget; |
1406 | ffs_data_get(ffs); | ||
1415 | return 0; | 1407 | return 0; |
1416 | } | 1408 | } |
1417 | 1409 | ||
@@ -1480,9 +1472,9 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) | |||
1480 | } | 1472 | } |
1481 | 1473 | ||
1482 | 1474 | ||
1483 | static int functionfs_add(struct usb_composite_dev *cdev, | 1475 | static int functionfs_bind_config(struct usb_composite_dev *cdev, |
1484 | struct usb_configuration *c, | 1476 | struct usb_configuration *c, |
1485 | struct ffs_data *ffs) | 1477 | struct ffs_data *ffs) |
1486 | { | 1478 | { |
1487 | struct ffs_function *func; | 1479 | struct ffs_function *func; |
1488 | int ret; | 1480 | int ret; |
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c index 9447427fcbff..111b85ca7ac0 100644 --- a/drivers/usb/gadget/f_hid.c +++ b/drivers/usb/gadget/f_hid.c | |||
@@ -142,7 +142,7 @@ static struct usb_descriptor_header *hidg_fs_descriptors[] = { | |||
142 | static ssize_t f_hidg_read(struct file *file, char __user *buffer, | 142 | static ssize_t f_hidg_read(struct file *file, char __user *buffer, |
143 | size_t count, loff_t *ptr) | 143 | size_t count, loff_t *ptr) |
144 | { | 144 | { |
145 | struct f_hidg *hidg = (struct f_hidg *)file->private_data; | 145 | struct f_hidg *hidg = file->private_data; |
146 | char *tmp_buff = NULL; | 146 | char *tmp_buff = NULL; |
147 | unsigned long flags; | 147 | unsigned long flags; |
148 | 148 | ||
@@ -200,7 +200,7 @@ static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req) | |||
200 | static ssize_t f_hidg_write(struct file *file, const char __user *buffer, | 200 | static ssize_t f_hidg_write(struct file *file, const char __user *buffer, |
201 | size_t count, loff_t *offp) | 201 | size_t count, loff_t *offp) |
202 | { | 202 | { |
203 | struct f_hidg *hidg = (struct f_hidg *)file->private_data; | 203 | struct f_hidg *hidg = file->private_data; |
204 | ssize_t status = -ENOMEM; | 204 | ssize_t status = -ENOMEM; |
205 | 205 | ||
206 | if (!access_ok(VERIFY_READ, buffer, count)) | 206 | if (!access_ok(VERIFY_READ, buffer, count)) |
@@ -257,7 +257,7 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer, | |||
257 | 257 | ||
258 | static unsigned int f_hidg_poll(struct file *file, poll_table *wait) | 258 | static unsigned int f_hidg_poll(struct file *file, poll_table *wait) |
259 | { | 259 | { |
260 | struct f_hidg *hidg = (struct f_hidg *)file->private_data; | 260 | struct f_hidg *hidg = file->private_data; |
261 | unsigned int ret = 0; | 261 | unsigned int ret = 0; |
262 | 262 | ||
263 | poll_wait(file, &hidg->read_queue, wait); | 263 | poll_wait(file, &hidg->read_queue, wait); |
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index e91d1b16d9be..43225879c3cd 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -324,7 +324,7 @@ static void loopback_disable(struct usb_function *f) | |||
324 | 324 | ||
325 | /*-------------------------------------------------------------------------*/ | 325 | /*-------------------------------------------------------------------------*/ |
326 | 326 | ||
327 | static int __init loopback_bind_config(struct usb_configuration *c) | 327 | static int __ref loopback_bind_config(struct usb_configuration *c) |
328 | { | 328 | { |
329 | struct f_loopback *loop; | 329 | struct f_loopback *loop; |
330 | int status; | 330 | int status; |
@@ -346,7 +346,7 @@ static int __init loopback_bind_config(struct usb_configuration *c) | |||
346 | return status; | 346 | return status; |
347 | } | 347 | } |
348 | 348 | ||
349 | static struct usb_configuration loopback_driver = { | 349 | static struct usb_configuration loopback_driver = { |
350 | .label = "loopback", | 350 | .label = "loopback", |
351 | .strings = loopback_strings, | 351 | .strings = loopback_strings, |
352 | .bind = loopback_bind_config, | 352 | .bind = loopback_bind_config, |
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 4ce899c9b165..32cce029f65c 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c | |||
@@ -316,6 +316,27 @@ static const char fsg_string_interface[] = "Mass Storage"; | |||
316 | /*-------------------------------------------------------------------------*/ | 316 | /*-------------------------------------------------------------------------*/ |
317 | 317 | ||
318 | struct fsg_dev; | 318 | struct fsg_dev; |
319 | struct fsg_common; | ||
320 | |||
321 | /* FSF callback functions */ | ||
322 | struct fsg_operations { | ||
323 | /* Callback function to call when thread exits. If no | ||
324 | * callback is set or it returns value lower then zero MSF | ||
325 | * will force eject all LUNs it operates on (including those | ||
326 | * marked as non-removable or with prevent_medium_removal flag | ||
327 | * set). */ | ||
328 | int (*thread_exits)(struct fsg_common *common); | ||
329 | |||
330 | /* Called prior to ejection. Negative return means error, | ||
331 | * zero means to continue with ejection, positive means not to | ||
332 | * eject. */ | ||
333 | int (*pre_eject)(struct fsg_common *common, | ||
334 | struct fsg_lun *lun, int num); | ||
335 | /* Called after ejection. Negative return means error, zero | ||
336 | * or positive is just a success. */ | ||
337 | int (*post_eject)(struct fsg_common *common, | ||
338 | struct fsg_lun *lun, int num); | ||
339 | }; | ||
319 | 340 | ||
320 | 341 | ||
321 | /* Data shared by all the FSG instances. */ | 342 | /* Data shared by all the FSG instances. */ |
@@ -333,7 +354,6 @@ struct fsg_common { | |||
333 | struct usb_ep *ep0; /* Copy of gadget->ep0 */ | 354 | struct usb_ep *ep0; /* Copy of gadget->ep0 */ |
334 | struct usb_request *ep0req; /* Copy of cdev->req */ | 355 | struct usb_request *ep0req; /* Copy of cdev->req */ |
335 | unsigned int ep0_req_tag; | 356 | unsigned int ep0_req_tag; |
336 | const char *ep0req_name; | ||
337 | 357 | ||
338 | struct fsg_buffhd *next_buffhd_to_fill; | 358 | struct fsg_buffhd *next_buffhd_to_fill; |
339 | struct fsg_buffhd *next_buffhd_to_drain; | 359 | struct fsg_buffhd *next_buffhd_to_drain; |
@@ -369,8 +389,8 @@ struct fsg_common { | |||
369 | struct completion thread_notifier; | 389 | struct completion thread_notifier; |
370 | struct task_struct *thread_task; | 390 | struct task_struct *thread_task; |
371 | 391 | ||
372 | /* Callback function to call when thread exits. */ | 392 | /* Callback functions. */ |
373 | int (*thread_exits)(struct fsg_common *common); | 393 | const struct fsg_operations *ops; |
374 | /* Gadget's private data. */ | 394 | /* Gadget's private data. */ |
375 | void *private_data; | 395 | void *private_data; |
376 | 396 | ||
@@ -394,12 +414,8 @@ struct fsg_config { | |||
394 | const char *lun_name_format; | 414 | const char *lun_name_format; |
395 | const char *thread_name; | 415 | const char *thread_name; |
396 | 416 | ||
397 | /* Callback function to call when thread exits. If no | 417 | /* Callback functions. */ |
398 | * callback is set or it returns value lower then zero MSF | 418 | const struct fsg_operations *ops; |
399 | * will force eject all LUNs it operates on (including those | ||
400 | * marked as non-removable or with prevent_medium_removal flag | ||
401 | * set). */ | ||
402 | int (*thread_exits)(struct fsg_common *common); | ||
403 | /* Gadget's private data. */ | 419 | /* Gadget's private data. */ |
404 | void *private_data; | 420 | void *private_data; |
405 | 421 | ||
@@ -435,6 +451,7 @@ static inline int __fsg_is_set(struct fsg_common *common, | |||
435 | if (common->fsg) | 451 | if (common->fsg) |
436 | return 1; | 452 | return 1; |
437 | ERROR(common, "common->fsg is NULL in %s at %u\n", func, line); | 453 | ERROR(common, "common->fsg is NULL in %s at %u\n", func, line); |
454 | WARN_ON(1); | ||
438 | return 0; | 455 | return 0; |
439 | } | 456 | } |
440 | 457 | ||
@@ -623,8 +640,6 @@ static int fsg_setup(struct usb_function *f, | |||
623 | 640 | ||
624 | /* Respond with data/status */ | 641 | /* Respond with data/status */ |
625 | req->length = min((u16)1, w_length); | 642 | req->length = min((u16)1, w_length); |
626 | fsg->common->ep0req_name = | ||
627 | ctrl->bRequestType & USB_DIR_IN ? "ep0-in" : "ep0-out"; | ||
628 | return ep0_queue(fsg->common); | 643 | return ep0_queue(fsg->common); |
629 | } | 644 | } |
630 | 645 | ||
@@ -1395,43 +1410,55 @@ static int do_start_stop(struct fsg_common *common) | |||
1395 | } else if (!curlun->removable) { | 1410 | } else if (!curlun->removable) { |
1396 | curlun->sense_data = SS_INVALID_COMMAND; | 1411 | curlun->sense_data = SS_INVALID_COMMAND; |
1397 | return -EINVAL; | 1412 | return -EINVAL; |
1398 | } | 1413 | } else if ((common->cmnd[1] & ~0x01) != 0 || /* Mask away Immed */ |
1399 | 1414 | (common->cmnd[4] & ~0x03) != 0) { /* Mask LoEj, Start */ | |
1400 | loej = common->cmnd[4] & 0x02; | ||
1401 | start = common->cmnd[4] & 0x01; | ||
1402 | |||
1403 | /* eject code from file_storage.c:do_start_stop() */ | ||
1404 | |||
1405 | if ((common->cmnd[1] & ~0x01) != 0 || /* Mask away Immed */ | ||
1406 | (common->cmnd[4] & ~0x03) != 0) { /* Mask LoEj, Start */ | ||
1407 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | 1415 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; |
1408 | return -EINVAL; | 1416 | return -EINVAL; |
1409 | } | 1417 | } |
1410 | 1418 | ||
1411 | if (!start) { | 1419 | loej = common->cmnd[4] & 0x02; |
1412 | /* Are we allowed to unload the media? */ | 1420 | start = common->cmnd[4] & 0x01; |
1413 | if (curlun->prevent_medium_removal) { | ||
1414 | LDBG(curlun, "unload attempt prevented\n"); | ||
1415 | curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED; | ||
1416 | return -EINVAL; | ||
1417 | } | ||
1418 | if (loej) { /* Simulate an unload/eject */ | ||
1419 | up_read(&common->filesem); | ||
1420 | down_write(&common->filesem); | ||
1421 | fsg_lun_close(curlun); | ||
1422 | up_write(&common->filesem); | ||
1423 | down_read(&common->filesem); | ||
1424 | } | ||
1425 | } else { | ||
1426 | 1421 | ||
1427 | /* Our emulation doesn't support mounting; the medium is | 1422 | /* Our emulation doesn't support mounting; the medium is |
1428 | * available for use as soon as it is loaded. */ | 1423 | * available for use as soon as it is loaded. */ |
1424 | if (start) { | ||
1429 | if (!fsg_lun_is_open(curlun)) { | 1425 | if (!fsg_lun_is_open(curlun)) { |
1430 | curlun->sense_data = SS_MEDIUM_NOT_PRESENT; | 1426 | curlun->sense_data = SS_MEDIUM_NOT_PRESENT; |
1431 | return -EINVAL; | 1427 | return -EINVAL; |
1432 | } | 1428 | } |
1429 | return 0; | ||
1433 | } | 1430 | } |
1434 | return 0; | 1431 | |
1432 | /* Are we allowed to unload the media? */ | ||
1433 | if (curlun->prevent_medium_removal) { | ||
1434 | LDBG(curlun, "unload attempt prevented\n"); | ||
1435 | curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED; | ||
1436 | return -EINVAL; | ||
1437 | } | ||
1438 | |||
1439 | if (!loej) | ||
1440 | return 0; | ||
1441 | |||
1442 | /* Simulate an unload/eject */ | ||
1443 | if (common->ops && common->ops->pre_eject) { | ||
1444 | int r = common->ops->pre_eject(common, curlun, | ||
1445 | curlun - common->luns); | ||
1446 | if (unlikely(r < 0)) | ||
1447 | return r; | ||
1448 | else if (r) | ||
1449 | return 0; | ||
1450 | } | ||
1451 | |||
1452 | up_read(&common->filesem); | ||
1453 | down_write(&common->filesem); | ||
1454 | fsg_lun_close(curlun); | ||
1455 | up_write(&common->filesem); | ||
1456 | down_read(&common->filesem); | ||
1457 | |||
1458 | return common->ops && common->ops->post_eject | ||
1459 | ? min(0, common->ops->post_eject(common, curlun, | ||
1460 | curlun - common->luns)) | ||
1461 | : 0; | ||
1435 | } | 1462 | } |
1436 | 1463 | ||
1437 | 1464 | ||
@@ -2610,7 +2637,8 @@ static int fsg_main_thread(void *common_) | |||
2610 | common->thread_task = NULL; | 2637 | common->thread_task = NULL; |
2611 | spin_unlock_irq(&common->lock); | 2638 | spin_unlock_irq(&common->lock); |
2612 | 2639 | ||
2613 | if (!common->thread_exits || common->thread_exits(common) < 0) { | 2640 | if (!common->ops || !common->ops->thread_exits |
2641 | || common->ops->thread_exits(common) < 0) { | ||
2614 | struct fsg_lun *curlun = common->luns; | 2642 | struct fsg_lun *curlun = common->luns; |
2615 | unsigned i = common->nluns; | 2643 | unsigned i = common->nluns; |
2616 | 2644 | ||
@@ -2686,6 +2714,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, | |||
2686 | common->free_storage_on_release = 0; | 2714 | common->free_storage_on_release = 0; |
2687 | } | 2715 | } |
2688 | 2716 | ||
2717 | common->ops = cfg->ops; | ||
2689 | common->private_data = cfg->private_data; | 2718 | common->private_data = cfg->private_data; |
2690 | 2719 | ||
2691 | common->gadget = gadget; | 2720 | common->gadget = gadget; |
@@ -2807,7 +2836,6 @@ buffhds_first_it: | |||
2807 | 2836 | ||
2808 | 2837 | ||
2809 | /* Tell the thread to start working */ | 2838 | /* Tell the thread to start working */ |
2810 | common->thread_exits = cfg->thread_exits; | ||
2811 | common->thread_task = | 2839 | common->thread_task = |
2812 | kthread_create(fsg_main_thread, common, | 2840 | kthread_create(fsg_main_thread, common, |
2813 | OR(cfg->thread_name, "file-storage")); | 2841 | OR(cfg->thread_name, "file-storage")); |
@@ -2990,9 +3018,9 @@ static struct usb_gadget_strings *fsg_strings_array[] = { | |||
2990 | NULL, | 3018 | NULL, |
2991 | }; | 3019 | }; |
2992 | 3020 | ||
2993 | static int fsg_add(struct usb_composite_dev *cdev, | 3021 | static int fsg_bind_config(struct usb_composite_dev *cdev, |
2994 | struct usb_configuration *c, | 3022 | struct usb_configuration *c, |
2995 | struct fsg_common *common) | 3023 | struct fsg_common *common) |
2996 | { | 3024 | { |
2997 | struct fsg_dev *fsg; | 3025 | struct fsg_dev *fsg; |
2998 | int rc; | 3026 | int rc; |
@@ -3024,6 +3052,13 @@ static int fsg_add(struct usb_composite_dev *cdev, | |||
3024 | return rc; | 3052 | return rc; |
3025 | } | 3053 | } |
3026 | 3054 | ||
3055 | static inline int __deprecated __maybe_unused | ||
3056 | fsg_add(struct usb_composite_dev *cdev, | ||
3057 | struct usb_configuration *c, | ||
3058 | struct fsg_common *common) | ||
3059 | { | ||
3060 | return fsg_bind_config(cdev, c, common); | ||
3061 | } | ||
3027 | 3062 | ||
3028 | 3063 | ||
3029 | /************************* Module parameters *************************/ | 3064 | /************************* Module parameters *************************/ |
@@ -3096,8 +3131,8 @@ fsg_config_from_params(struct fsg_config *cfg, | |||
3096 | cfg->product_name = 0; | 3131 | cfg->product_name = 0; |
3097 | cfg->release = 0xffff; | 3132 | cfg->release = 0xffff; |
3098 | 3133 | ||
3099 | cfg->thread_exits = 0; | 3134 | cfg->ops = NULL; |
3100 | cfg->private_data = 0; | 3135 | cfg->private_data = NULL; |
3101 | 3136 | ||
3102 | /* Finalise */ | 3137 | /* Finalise */ |
3103 | cfg->can_stall = params->stall; | 3138 | cfg->can_stall = params->stall; |
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index 6d3cc443d914..685d768f336e 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c | |||
@@ -404,7 +404,7 @@ static void sourcesink_disable(struct usb_function *f) | |||
404 | 404 | ||
405 | /*-------------------------------------------------------------------------*/ | 405 | /*-------------------------------------------------------------------------*/ |
406 | 406 | ||
407 | static int __init sourcesink_bind_config(struct usb_configuration *c) | 407 | static int __ref sourcesink_bind_config(struct usb_configuration *c) |
408 | { | 408 | { |
409 | struct f_sourcesink *ss; | 409 | struct f_sourcesink *ss; |
410 | int status; | 410 | int status; |
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index b49d86e3e45b..a857b7ac238c 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -56,7 +56,7 @@ | |||
56 | * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03), | 56 | * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03), |
57 | * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by | 57 | * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by |
58 | * the optional "protocol" module parameter. In addition, the default | 58 | * the optional "protocol" module parameter. In addition, the default |
59 | * Vendor ID, Product ID, and release number can be overridden. | 59 | * Vendor ID, Product ID, release number and serial number can be overridden. |
60 | * | 60 | * |
61 | * There is support for multiple logical units (LUNs), each of which has | 61 | * There is support for multiple logical units (LUNs), each of which has |
62 | * its own backing file. The number of LUNs can be set using the optional | 62 | * its own backing file. The number of LUNs can be set using the optional |
@@ -93,6 +93,8 @@ | |||
93 | * removable Default false, boolean for removable media | 93 | * removable Default false, boolean for removable media |
94 | * luns=N Default N = number of filenames, number of | 94 | * luns=N Default N = number of filenames, number of |
95 | * LUNs to support | 95 | * LUNs to support |
96 | * nofua=b[,b...] Default false, booleans for ignore FUA flag | ||
97 | * in SCSI WRITE(10,12) commands | ||
96 | * stall Default determined according to the type of | 98 | * stall Default determined according to the type of |
97 | * USB device controller (usually true), | 99 | * USB device controller (usually true), |
98 | * boolean to permit the driver to halt | 100 | * boolean to permit the driver to halt |
@@ -106,17 +108,18 @@ | |||
106 | * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID | 108 | * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID |
107 | * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID | 109 | * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID |
108 | * release=0xRRRR Override the USB release number (bcdDevice) | 110 | * release=0xRRRR Override the USB release number (bcdDevice) |
111 | * serial=HHHH... Override serial number (string of hex chars) | ||
109 | * buflen=N Default N=16384, buffer size used (will be | 112 | * buflen=N Default N=16384, buffer size used (will be |
110 | * rounded down to a multiple of | 113 | * rounded down to a multiple of |
111 | * PAGE_CACHE_SIZE) | 114 | * PAGE_CACHE_SIZE) |
112 | * | 115 | * |
113 | * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", | 116 | * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", |
114 | * "removable", "luns", "stall", and "cdrom" options are available; default | 117 | * "removable", "luns", "nofua", "stall", and "cdrom" options are available; |
115 | * values are used for everything else. | 118 | * default values are used for everything else. |
116 | * | 119 | * |
117 | * The pathnames of the backing files and the ro settings are available in | 120 | * The pathnames of the backing files and the ro settings are available in |
118 | * the attribute files "file" and "ro" in the lun<n> subdirectory of the | 121 | * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of |
119 | * gadget's sysfs directory. If the "removable" option is set, writing to | 122 | * the gadget's sysfs directory. If the "removable" option is set, writing to |
120 | * these files will simulate ejecting/loading the medium (writing an empty | 123 | * these files will simulate ejecting/loading the medium (writing an empty |
121 | * line means eject) and adjusting a write-enable tab. Changes to the ro | 124 | * line means eject) and adjusting a write-enable tab. Changes to the ro |
122 | * setting are not allowed when the medium is loaded or if CD-ROM emulation | 125 | * setting are not allowed when the medium is loaded or if CD-ROM emulation |
@@ -270,6 +273,8 @@ | |||
270 | 273 | ||
271 | #define DRIVER_DESC "File-backed Storage Gadget" | 274 | #define DRIVER_DESC "File-backed Storage Gadget" |
272 | #define DRIVER_NAME "g_file_storage" | 275 | #define DRIVER_NAME "g_file_storage" |
276 | /* DRIVER_VERSION must be at least 6 characters long, as it is used | ||
277 | * to generate a fallback serial number. */ | ||
273 | #define DRIVER_VERSION "20 November 2008" | 278 | #define DRIVER_VERSION "20 November 2008" |
274 | 279 | ||
275 | static char fsg_string_manufacturer[64]; | 280 | static char fsg_string_manufacturer[64]; |
@@ -301,8 +306,10 @@ MODULE_LICENSE("Dual BSD/GPL"); | |||
301 | static struct { | 306 | static struct { |
302 | char *file[FSG_MAX_LUNS]; | 307 | char *file[FSG_MAX_LUNS]; |
303 | int ro[FSG_MAX_LUNS]; | 308 | int ro[FSG_MAX_LUNS]; |
309 | int nofua[FSG_MAX_LUNS]; | ||
304 | unsigned int num_filenames; | 310 | unsigned int num_filenames; |
305 | unsigned int num_ros; | 311 | unsigned int num_ros; |
312 | unsigned int num_nofuas; | ||
306 | unsigned int nluns; | 313 | unsigned int nluns; |
307 | 314 | ||
308 | int removable; | 315 | int removable; |
@@ -314,6 +321,7 @@ static struct { | |||
314 | unsigned short vendor; | 321 | unsigned short vendor; |
315 | unsigned short product; | 322 | unsigned short product; |
316 | unsigned short release; | 323 | unsigned short release; |
324 | char *serial; | ||
317 | unsigned int buflen; | 325 | unsigned int buflen; |
318 | 326 | ||
319 | int transport_type; | 327 | int transport_type; |
@@ -341,6 +349,10 @@ MODULE_PARM_DESC(file, "names of backing files or devices"); | |||
341 | module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO); | 349 | module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO); |
342 | MODULE_PARM_DESC(ro, "true to force read-only"); | 350 | MODULE_PARM_DESC(ro, "true to force read-only"); |
343 | 351 | ||
352 | module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas, | ||
353 | S_IRUGO); | ||
354 | MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit"); | ||
355 | |||
344 | module_param_named(luns, mod_data.nluns, uint, S_IRUGO); | 356 | module_param_named(luns, mod_data.nluns, uint, S_IRUGO); |
345 | MODULE_PARM_DESC(luns, "number of LUNs"); | 357 | MODULE_PARM_DESC(luns, "number of LUNs"); |
346 | 358 | ||
@@ -353,6 +365,8 @@ MODULE_PARM_DESC(stall, "false to prevent bulk stalls"); | |||
353 | module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); | 365 | module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); |
354 | MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); | 366 | MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); |
355 | 367 | ||
368 | module_param_named(serial, mod_data.serial, charp, S_IRUGO); | ||
369 | MODULE_PARM_DESC(serial, "USB serial number"); | ||
356 | 370 | ||
357 | /* In the non-TEST version, only the module parameters listed above | 371 | /* In the non-TEST version, only the module parameters listed above |
358 | * are available. */ | 372 | * are available. */ |
@@ -1272,7 +1286,8 @@ static int do_write(struct fsg_dev *fsg) | |||
1272 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; | 1286 | curlun->sense_data = SS_INVALID_FIELD_IN_CDB; |
1273 | return -EINVAL; | 1287 | return -EINVAL; |
1274 | } | 1288 | } |
1275 | if (fsg->cmnd[1] & 0x08) { // FUA | 1289 | /* FUA */ |
1290 | if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) { | ||
1276 | spin_lock(&curlun->filp->f_lock); | 1291 | spin_lock(&curlun->filp->f_lock); |
1277 | curlun->filp->f_flags |= O_DSYNC; | 1292 | curlun->filp->f_flags |= O_DSYNC; |
1278 | spin_unlock(&curlun->filp->f_lock); | 1293 | spin_unlock(&curlun->filp->f_lock); |
@@ -3126,6 +3141,7 @@ static int fsg_main_thread(void *fsg_) | |||
3126 | 3141 | ||
3127 | /* The write permissions and store_xxx pointers are set in fsg_bind() */ | 3142 | /* The write permissions and store_xxx pointers are set in fsg_bind() */ |
3128 | static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL); | 3143 | static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL); |
3144 | static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL); | ||
3129 | static DEVICE_ATTR(file, 0444, fsg_show_file, NULL); | 3145 | static DEVICE_ATTR(file, 0444, fsg_show_file, NULL); |
3130 | 3146 | ||
3131 | 3147 | ||
@@ -3197,6 +3213,7 @@ static int __init check_parameters(struct fsg_dev *fsg) | |||
3197 | { | 3213 | { |
3198 | int prot; | 3214 | int prot; |
3199 | int gcnum; | 3215 | int gcnum; |
3216 | int i; | ||
3200 | 3217 | ||
3201 | /* Store the default values */ | 3218 | /* Store the default values */ |
3202 | mod_data.transport_type = USB_PR_BULK; | 3219 | mod_data.transport_type = USB_PR_BULK; |
@@ -3272,13 +3289,65 @@ static int __init check_parameters(struct fsg_dev *fsg) | |||
3272 | ERROR(fsg, "invalid buflen\n"); | 3289 | ERROR(fsg, "invalid buflen\n"); |
3273 | return -ETOOSMALL; | 3290 | return -ETOOSMALL; |
3274 | } | 3291 | } |
3292 | |||
3275 | #endif /* CONFIG_USB_FILE_STORAGE_TEST */ | 3293 | #endif /* CONFIG_USB_FILE_STORAGE_TEST */ |
3276 | 3294 | ||
3295 | /* Serial string handling. | ||
3296 | * On a real device, the serial string would be loaded | ||
3297 | * from permanent storage. */ | ||
3298 | if (mod_data.serial) { | ||
3299 | const char *ch; | ||
3300 | unsigned len = 0; | ||
3301 | |||
3302 | /* Sanity check : | ||
3303 | * The CB[I] specification limits the serial string to | ||
3304 | * 12 uppercase hexadecimal characters. | ||
3305 | * BBB need at least 12 uppercase hexadecimal characters, | ||
3306 | * with a maximum of 126. */ | ||
3307 | for (ch = mod_data.serial; *ch; ++ch) { | ||
3308 | ++len; | ||
3309 | if ((*ch < '0' || *ch > '9') && | ||
3310 | (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */ | ||
3311 | WARNING(fsg, | ||
3312 | "Invalid serial string character: %c; " | ||
3313 | "Failing back to default\n", | ||
3314 | *ch); | ||
3315 | goto fill_serial; | ||
3316 | } | ||
3317 | } | ||
3318 | if (len > 126 || | ||
3319 | (mod_data.transport_type == USB_PR_BULK && len < 12) || | ||
3320 | (mod_data.transport_type != USB_PR_BULK && len > 12)) { | ||
3321 | WARNING(fsg, | ||
3322 | "Invalid serial string length; " | ||
3323 | "Failing back to default\n"); | ||
3324 | goto fill_serial; | ||
3325 | } | ||
3326 | fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial; | ||
3327 | } else { | ||
3328 | WARNING(fsg, | ||
3329 | "Userspace failed to provide serial number; " | ||
3330 | "Failing back to default\n"); | ||
3331 | fill_serial: | ||
3332 | /* Serial number not specified or invalid, make our own. | ||
3333 | * We just encode it from the driver version string, | ||
3334 | * 12 characters to comply with both CB[I] and BBB spec. | ||
3335 | * Warning : Two devices running the same kernel will have | ||
3336 | * the same fallback serial number. */ | ||
3337 | for (i = 0; i < 12; i += 2) { | ||
3338 | unsigned char c = DRIVER_VERSION[i / 2]; | ||
3339 | |||
3340 | if (!c) | ||
3341 | break; | ||
3342 | sprintf(&fsg_string_serial[i], "%02X", c); | ||
3343 | } | ||
3344 | } | ||
3345 | |||
3277 | return 0; | 3346 | return 0; |
3278 | } | 3347 | } |
3279 | 3348 | ||
3280 | 3349 | ||
3281 | static int __init fsg_bind(struct usb_gadget *gadget) | 3350 | static int __ref fsg_bind(struct usb_gadget *gadget) |
3282 | { | 3351 | { |
3283 | struct fsg_dev *fsg = the_fsg; | 3352 | struct fsg_dev *fsg = the_fsg; |
3284 | int rc; | 3353 | int rc; |
@@ -3305,6 +3374,10 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3305 | } | 3374 | } |
3306 | } | 3375 | } |
3307 | 3376 | ||
3377 | /* Only for removable media? */ | ||
3378 | dev_attr_nofua.attr.mode = 0644; | ||
3379 | dev_attr_nofua.store = fsg_store_nofua; | ||
3380 | |||
3308 | /* Find out how many LUNs there should be */ | 3381 | /* Find out how many LUNs there should be */ |
3309 | i = mod_data.nluns; | 3382 | i = mod_data.nluns; |
3310 | if (i == 0) | 3383 | if (i == 0) |
@@ -3330,6 +3403,7 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3330 | curlun->ro = mod_data.cdrom || mod_data.ro[i]; | 3403 | curlun->ro = mod_data.cdrom || mod_data.ro[i]; |
3331 | curlun->initially_ro = curlun->ro; | 3404 | curlun->initially_ro = curlun->ro; |
3332 | curlun->removable = mod_data.removable; | 3405 | curlun->removable = mod_data.removable; |
3406 | curlun->nofua = mod_data.nofua[i]; | ||
3333 | curlun->dev.release = lun_release; | 3407 | curlun->dev.release = lun_release; |
3334 | curlun->dev.parent = &gadget->dev; | 3408 | curlun->dev.parent = &gadget->dev; |
3335 | curlun->dev.driver = &fsg_driver.driver; | 3409 | curlun->dev.driver = &fsg_driver.driver; |
@@ -3344,6 +3418,8 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3344 | if ((rc = device_create_file(&curlun->dev, | 3418 | if ((rc = device_create_file(&curlun->dev, |
3345 | &dev_attr_ro)) != 0 || | 3419 | &dev_attr_ro)) != 0 || |
3346 | (rc = device_create_file(&curlun->dev, | 3420 | (rc = device_create_file(&curlun->dev, |
3421 | &dev_attr_nofua)) != 0 || | ||
3422 | (rc = device_create_file(&curlun->dev, | ||
3347 | &dev_attr_file)) != 0) { | 3423 | &dev_attr_file)) != 0) { |
3348 | device_unregister(&curlun->dev); | 3424 | device_unregister(&curlun->dev); |
3349 | goto out; | 3425 | goto out; |
@@ -3447,16 +3523,6 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3447 | init_utsname()->sysname, init_utsname()->release, | 3523 | init_utsname()->sysname, init_utsname()->release, |
3448 | gadget->name); | 3524 | gadget->name); |
3449 | 3525 | ||
3450 | /* On a real device, serial[] would be loaded from permanent | ||
3451 | * storage. We just encode it from the driver version string. */ | ||
3452 | for (i = 0; i < sizeof fsg_string_serial - 2; i += 2) { | ||
3453 | unsigned char c = DRIVER_VERSION[i / 2]; | ||
3454 | |||
3455 | if (!c) | ||
3456 | break; | ||
3457 | sprintf(&fsg_string_serial[i], "%02X", c); | ||
3458 | } | ||
3459 | |||
3460 | fsg->thread_task = kthread_create(fsg_main_thread, fsg, | 3526 | fsg->thread_task = kthread_create(fsg_main_thread, fsg, |
3461 | "file-storage-gadget"); | 3527 | "file-storage-gadget"); |
3462 | if (IS_ERR(fsg->thread_task)) { | 3528 | if (IS_ERR(fsg->thread_task)) { |
@@ -3478,8 +3544,8 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3478 | if (IS_ERR(p)) | 3544 | if (IS_ERR(p)) |
3479 | p = NULL; | 3545 | p = NULL; |
3480 | } | 3546 | } |
3481 | LINFO(curlun, "ro=%d, file: %s\n", | 3547 | LINFO(curlun, "ro=%d, nofua=%d, file: %s\n", |
3482 | curlun->ro, (p ? p : "(error)")); | 3548 | curlun->ro, curlun->nofua, (p ? p : "(error)")); |
3483 | } | 3549 | } |
3484 | } | 3550 | } |
3485 | kfree(pathbuf); | 3551 | kfree(pathbuf); |
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index d1af253a9105..a9474f8d5325 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -32,12 +32,13 @@ | |||
32 | # include "u_ether.c" | 32 | # include "u_ether.c" |
33 | 33 | ||
34 | static u8 gfs_hostaddr[ETH_ALEN]; | 34 | static u8 gfs_hostaddr[ETH_ALEN]; |
35 | #else | 35 | # ifdef CONFIG_USB_FUNCTIONFS_ETH |
36 | # if !defined CONFIG_USB_FUNCTIONFS_GENERIC | 36 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
37 | # define CONFIG_USB_FUNCTIONFS_GENERIC | ||
38 | # endif | 37 | # endif |
38 | #else | ||
39 | # define gether_cleanup() do { } while (0) | 39 | # define gether_cleanup() do { } while (0) |
40 | # define gether_setup(gadget, hostaddr) ((int)0) | 40 | # define gether_setup(gadget, hostaddr) ((int)0) |
41 | # define gfs_hostaddr NULL | ||
41 | #endif | 42 | #endif |
42 | 43 | ||
43 | #include "f_fs.c" | 44 | #include "f_fs.c" |
@@ -107,15 +108,7 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = { | |||
107 | enum { | 108 | enum { |
108 | GFS_STRING_MANUFACTURER_IDX, | 109 | GFS_STRING_MANUFACTURER_IDX, |
109 | GFS_STRING_PRODUCT_IDX, | 110 | GFS_STRING_PRODUCT_IDX, |
110 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | 111 | GFS_STRING_FIRST_CONFIG_IDX, |
111 | GFS_STRING_RNDIS_CONFIG_IDX, | ||
112 | #endif | ||
113 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | ||
114 | GFS_STRING_ECM_CONFIG_IDX, | ||
115 | #endif | ||
116 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | ||
117 | GFS_STRING_GENERIC_CONFIG_IDX, | ||
118 | #endif | ||
119 | }; | 112 | }; |
120 | 113 | ||
121 | static char gfs_manufacturer[50]; | 114 | static char gfs_manufacturer[50]; |
@@ -126,13 +119,13 @@ static struct usb_string gfs_strings[] = { | |||
126 | [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer, | 119 | [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer, |
127 | [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc, | 120 | [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc, |
128 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | 121 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
129 | [GFS_STRING_RNDIS_CONFIG_IDX].s = "FunctionFS + RNDIS", | 122 | { .s = "FunctionFS + RNDIS" }, |
130 | #endif | 123 | #endif |
131 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 124 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
132 | [GFS_STRING_ECM_CONFIG_IDX].s = "FunctionFS + ECM", | 125 | { .s = "FunctionFS + ECM" }, |
133 | #endif | 126 | #endif |
134 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | 127 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC |
135 | [GFS_STRING_GENERIC_CONFIG_IDX].s = "FunctionFS", | 128 | { .s = "FunctionFS" }, |
136 | #endif | 129 | #endif |
137 | { } /* end of list */ | 130 | { } /* end of list */ |
138 | }; | 131 | }; |
@@ -146,59 +139,33 @@ static struct usb_gadget_strings *gfs_dev_strings[] = { | |||
146 | }; | 139 | }; |
147 | 140 | ||
148 | 141 | ||
142 | |||
143 | struct gfs_configuration { | ||
144 | struct usb_configuration c; | ||
145 | int (*eth)(struct usb_configuration *c, u8 *ethaddr); | ||
146 | } gfs_configurations[] = { | ||
149 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | 147 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
150 | static int gfs_do_rndis_config(struct usb_configuration *c); | 148 | { |
151 | 149 | .eth = rndis_bind_config, | |
152 | static struct usb_configuration gfs_rndis_config_driver = { | 150 | }, |
153 | .label = "FunctionFS + RNDIS", | ||
154 | .bind = gfs_do_rndis_config, | ||
155 | .bConfigurationValue = 1, | ||
156 | /* .iConfiguration = DYNAMIC */ | ||
157 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | ||
158 | }; | ||
159 | # define gfs_add_rndis_config(cdev) \ | ||
160 | usb_add_config(cdev, &gfs_rndis_config_driver) | ||
161 | #else | ||
162 | # define gfs_add_rndis_config(cdev) 0 | ||
163 | #endif | 151 | #endif |
164 | 152 | ||
165 | |||
166 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 153 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
167 | static int gfs_do_ecm_config(struct usb_configuration *c); | 154 | { |
168 | 155 | .eth = eth_bind_config, | |
169 | static struct usb_configuration gfs_ecm_config_driver = { | 156 | }, |
170 | .label = "FunctionFS + ECM", | ||
171 | .bind = gfs_do_ecm_config, | ||
172 | .bConfigurationValue = 1, | ||
173 | /* .iConfiguration = DYNAMIC */ | ||
174 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | ||
175 | }; | ||
176 | # define gfs_add_ecm_config(cdev) \ | ||
177 | usb_add_config(cdev, &gfs_ecm_config_driver) | ||
178 | #else | ||
179 | # define gfs_add_ecm_config(cdev) 0 | ||
180 | #endif | 157 | #endif |
181 | 158 | ||
182 | |||
183 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | 159 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC |
184 | static int gfs_do_generic_config(struct usb_configuration *c); | 160 | { |
185 | 161 | }, | |
186 | static struct usb_configuration gfs_generic_config_driver = { | ||
187 | .label = "FunctionFS", | ||
188 | .bind = gfs_do_generic_config, | ||
189 | .bConfigurationValue = 2, | ||
190 | /* .iConfiguration = DYNAMIC */ | ||
191 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | ||
192 | }; | ||
193 | # define gfs_add_generic_config(cdev) \ | ||
194 | usb_add_config(cdev, &gfs_generic_config_driver) | ||
195 | #else | ||
196 | # define gfs_add_generic_config(cdev) 0 | ||
197 | #endif | 162 | #endif |
163 | }; | ||
198 | 164 | ||
199 | 165 | ||
200 | static int gfs_bind(struct usb_composite_dev *cdev); | 166 | static int gfs_bind(struct usb_composite_dev *cdev); |
201 | static int gfs_unbind(struct usb_composite_dev *cdev); | 167 | static int gfs_unbind(struct usb_composite_dev *cdev); |
168 | static int gfs_do_config(struct usb_configuration *c); | ||
202 | 169 | ||
203 | static struct usb_composite_driver gfs_driver = { | 170 | static struct usb_composite_driver gfs_driver = { |
204 | .name = gfs_short_name, | 171 | .name = gfs_short_name, |
@@ -267,7 +234,7 @@ static int functionfs_check_dev_callback(const char *dev_name) | |||
267 | 234 | ||
268 | static int gfs_bind(struct usb_composite_dev *cdev) | 235 | static int gfs_bind(struct usb_composite_dev *cdev) |
269 | { | 236 | { |
270 | int ret; | 237 | int ret, i; |
271 | 238 | ||
272 | ENTER(); | 239 | ENTER(); |
273 | 240 | ||
@@ -284,57 +251,32 @@ static int gfs_bind(struct usb_composite_dev *cdev) | |||
284 | snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s", | 251 | snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s", |
285 | init_utsname()->sysname, init_utsname()->release, | 252 | init_utsname()->sysname, init_utsname()->release, |
286 | cdev->gadget->name); | 253 | cdev->gadget->name); |
287 | ret = usb_string_id(cdev); | ||
288 | if (unlikely(ret < 0)) | ||
289 | goto error; | ||
290 | gfs_strings[GFS_STRING_MANUFACTURER_IDX].id = ret; | ||
291 | gfs_dev_desc.iManufacturer = ret; | ||
292 | |||
293 | ret = usb_string_id(cdev); | ||
294 | if (unlikely(ret < 0)) | ||
295 | goto error; | ||
296 | gfs_strings[GFS_STRING_PRODUCT_IDX].id = ret; | ||
297 | gfs_dev_desc.iProduct = ret; | ||
298 | |||
299 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
300 | ret = usb_string_id(cdev); | ||
301 | if (unlikely(ret < 0)) | ||
302 | goto error; | ||
303 | gfs_strings[GFS_STRING_RNDIS_CONFIG_IDX].id = ret; | ||
304 | gfs_rndis_config_driver.iConfiguration = ret; | ||
305 | #endif | ||
306 | 254 | ||
307 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 255 | ret = usb_string_ids_tab(cdev, gfs_strings); |
308 | ret = usb_string_id(cdev); | ||
309 | if (unlikely(ret < 0)) | 256 | if (unlikely(ret < 0)) |
310 | goto error; | 257 | goto error; |
311 | gfs_strings[GFS_STRING_ECM_CONFIG_IDX].id = ret; | ||
312 | gfs_ecm_config_driver.iConfiguration = ret; | ||
313 | #endif | ||
314 | 258 | ||
315 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | 259 | gfs_dev_desc.iManufacturer = gfs_strings[GFS_STRING_MANUFACTURER_IDX].id; |
316 | ret = usb_string_id(cdev); | 260 | gfs_dev_desc.iProduct = gfs_strings[GFS_STRING_PRODUCT_IDX].id; |
317 | if (unlikely(ret < 0)) | ||
318 | goto error; | ||
319 | gfs_strings[GFS_STRING_GENERIC_CONFIG_IDX].id = ret; | ||
320 | gfs_generic_config_driver.iConfiguration = ret; | ||
321 | #endif | ||
322 | 261 | ||
323 | ret = functionfs_bind(gfs_ffs_data, cdev); | 262 | ret = functionfs_bind(gfs_ffs_data, cdev); |
324 | if (unlikely(ret < 0)) | 263 | if (unlikely(ret < 0)) |
325 | goto error; | 264 | goto error; |
326 | 265 | ||
327 | ret = gfs_add_rndis_config(cdev); | 266 | for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { |
328 | if (unlikely(ret < 0)) | 267 | struct gfs_configuration *c = gfs_configurations + i; |
329 | goto error_unbind; | ||
330 | 268 | ||
331 | ret = gfs_add_ecm_config(cdev); | 269 | ret = GFS_STRING_FIRST_CONFIG_IDX + i; |
332 | if (unlikely(ret < 0)) | 270 | c->c.label = gfs_strings[ret].s; |
333 | goto error_unbind; | 271 | c->c.iConfiguration = gfs_strings[ret].id; |
272 | c->c.bind = gfs_do_config; | ||
273 | c->c.bConfigurationValue = 1 + i; | ||
274 | c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; | ||
334 | 275 | ||
335 | ret = gfs_add_generic_config(cdev); | 276 | ret = usb_add_config(cdev, &c->c); |
336 | if (unlikely(ret < 0)) | 277 | if (unlikely(ret < 0)) |
337 | goto error_unbind; | 278 | goto error_unbind; |
279 | } | ||
338 | 280 | ||
339 | return 0; | 281 | return 0; |
340 | 282 | ||
@@ -368,10 +310,10 @@ static int gfs_unbind(struct usb_composite_dev *cdev) | |||
368 | } | 310 | } |
369 | 311 | ||
370 | 312 | ||
371 | static int __gfs_do_config(struct usb_configuration *c, | 313 | static int gfs_do_config(struct usb_configuration *c) |
372 | int (*eth)(struct usb_configuration *c, u8 *ethaddr), | ||
373 | u8 *ethaddr) | ||
374 | { | 314 | { |
315 | struct gfs_configuration *gc = | ||
316 | container_of(c, struct gfs_configuration, c); | ||
375 | int ret; | 317 | int ret; |
376 | 318 | ||
377 | if (WARN_ON(!gfs_ffs_data)) | 319 | if (WARN_ON(!gfs_ffs_data)) |
@@ -382,13 +324,13 @@ static int __gfs_do_config(struct usb_configuration *c, | |||
382 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 324 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
383 | } | 325 | } |
384 | 326 | ||
385 | if (eth) { | 327 | if (gc->eth) { |
386 | ret = eth(c, ethaddr); | 328 | ret = gc->eth(c, gfs_hostaddr); |
387 | if (unlikely(ret < 0)) | 329 | if (unlikely(ret < 0)) |
388 | return ret; | 330 | return ret; |
389 | } | 331 | } |
390 | 332 | ||
391 | ret = functionfs_add(c->cdev, c, gfs_ffs_data); | 333 | ret = functionfs_bind_config(c->cdev, c, gfs_ffs_data); |
392 | if (unlikely(ret < 0)) | 334 | if (unlikely(ret < 0)) |
393 | return ret; | 335 | return ret; |
394 | 336 | ||
@@ -406,32 +348,12 @@ static int __gfs_do_config(struct usb_configuration *c, | |||
406 | return 0; | 348 | return 0; |
407 | } | 349 | } |
408 | 350 | ||
409 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
410 | static int gfs_do_rndis_config(struct usb_configuration *c) | ||
411 | { | ||
412 | ENTER(); | ||
413 | |||
414 | return __gfs_do_config(c, rndis_bind_config, gfs_hostaddr); | ||
415 | } | ||
416 | #endif | ||
417 | 351 | ||
418 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 352 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
419 | static int gfs_do_ecm_config(struct usb_configuration *c) | 353 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) |
420 | { | ||
421 | ENTER(); | ||
422 | |||
423 | return __gfs_do_config(c, | ||
424 | can_support_ecm(c->cdev->gadget) | ||
425 | ? ecm_bind_config : geth_bind_config, | ||
426 | gfs_hostaddr); | ||
427 | } | ||
428 | #endif | ||
429 | |||
430 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | ||
431 | static int gfs_do_generic_config(struct usb_configuration *c) | ||
432 | { | 354 | { |
433 | ENTER(); | 355 | return can_support_ecm(c->cdev->gadget) |
434 | 356 | ? ecm_bind_config(c, ethaddr) | |
435 | return __gfs_do_config(c, NULL, NULL); | 357 | : geth_bind_config(c, ethaddr); |
436 | } | 358 | } |
437 | #endif | 359 | #endif |
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index b7bf88019b06..1b413a5cc3f6 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c | |||
@@ -1157,7 +1157,7 @@ fail: | |||
1157 | /* | 1157 | /* |
1158 | * Creates an output endpoint, and initializes output ports. | 1158 | * Creates an output endpoint, and initializes output ports. |
1159 | */ | 1159 | */ |
1160 | static int __init gmidi_bind(struct usb_gadget *gadget) | 1160 | static int __ref gmidi_bind(struct usb_gadget *gadget) |
1161 | { | 1161 | { |
1162 | struct gmidi_device *dev; | 1162 | struct gmidi_device *dev; |
1163 | struct usb_ep *in_ep, *out_ep; | 1163 | struct usb_ep *in_ep, *out_ep; |
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c index 775722686ed8..735495bf8411 100644 --- a/drivers/usb/gadget/hid.c +++ b/drivers/usb/gadget/hid.c | |||
@@ -127,7 +127,7 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
127 | 127 | ||
128 | /****************************** Configurations ******************************/ | 128 | /****************************** Configurations ******************************/ |
129 | 129 | ||
130 | static int __init do_config(struct usb_configuration *c) | 130 | static int __ref do_config(struct usb_configuration *c) |
131 | { | 131 | { |
132 | struct hidg_func_node *e; | 132 | struct hidg_func_node *e; |
133 | int func = 0, status = 0; | 133 | int func = 0, status = 0; |
@@ -156,7 +156,7 @@ static struct usb_configuration config_driver = { | |||
156 | 156 | ||
157 | /****************************** Gadget Bind ******************************/ | 157 | /****************************** Gadget Bind ******************************/ |
158 | 158 | ||
159 | static int __init hid_bind(struct usb_composite_dev *cdev) | 159 | static int __ref hid_bind(struct usb_composite_dev *cdev) |
160 | { | 160 | { |
161 | struct usb_gadget *gadget = cdev->gadget; | 161 | struct usb_gadget *gadget = cdev->gadget; |
162 | struct list_head *tmp; | 162 | struct list_head *tmp; |
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index de8a83803505..fc35406fc80c 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -1299,11 +1299,9 @@ static long dev_ioctl (struct file *fd, unsigned code, unsigned long value) | |||
1299 | struct usb_gadget *gadget = dev->gadget; | 1299 | struct usb_gadget *gadget = dev->gadget; |
1300 | long ret = -ENOTTY; | 1300 | long ret = -ENOTTY; |
1301 | 1301 | ||
1302 | if (gadget->ops->ioctl) { | 1302 | if (gadget->ops->ioctl) |
1303 | lock_kernel(); | ||
1304 | ret = gadget->ops->ioctl (gadget, code, value); | 1303 | ret = gadget->ops->ioctl (gadget, code, value); |
1305 | unlock_kernel(); | 1304 | |
1306 | } | ||
1307 | return ret; | 1305 | return ret; |
1308 | } | 1306 | } |
1309 | 1307 | ||
@@ -1867,13 +1865,9 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | |||
1867 | buf += 4; | 1865 | buf += 4; |
1868 | length -= 4; | 1866 | length -= 4; |
1869 | 1867 | ||
1870 | kbuf = kmalloc (length, GFP_KERNEL); | 1868 | kbuf = memdup_user(buf, length); |
1871 | if (!kbuf) | 1869 | if (IS_ERR(kbuf)) |
1872 | return -ENOMEM; | 1870 | return PTR_ERR(kbuf); |
1873 | if (copy_from_user (kbuf, buf, length)) { | ||
1874 | kfree (kbuf); | ||
1875 | return -EFAULT; | ||
1876 | } | ||
1877 | 1871 | ||
1878 | spin_lock_irq (&dev->lock); | 1872 | spin_lock_irq (&dev->lock); |
1879 | value = -EINVAL; | 1873 | value = -EINVAL; |
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c index f1a070280c9c..d41b69cf508b 100644 --- a/drivers/usb/gadget/langwell_udc.c +++ b/drivers/usb/gadget/langwell_udc.c | |||
@@ -841,9 +841,9 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req, | |||
841 | VDBG(dev, "req->mapped = 0\n"); | 841 | VDBG(dev, "req->mapped = 0\n"); |
842 | } | 842 | } |
843 | 843 | ||
844 | DBG(dev, "%s queue req %p, len %u, buf %p, dma 0x%08x\n", | 844 | DBG(dev, "%s queue req %p, len %u, buf %p, dma 0x%08llx\n", |
845 | _ep->name, | 845 | _ep->name, |
846 | _req, _req->length, _req->buf, _req->dma); | 846 | _req, _req->length, _req->buf, (unsigned long long)_req->dma); |
847 | 847 | ||
848 | _req->status = -EINPROGRESS; | 848 | _req->status = -EINPROGRESS; |
849 | _req->actual = 0; | 849 | _req->actual = 0; |
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c index 705cc1f76327..585f2559484d 100644 --- a/drivers/usb/gadget/mass_storage.c +++ b/drivers/usb/gadget/mass_storage.c | |||
@@ -141,9 +141,14 @@ static int msg_thread_exits(struct fsg_common *common) | |||
141 | return 0; | 141 | return 0; |
142 | } | 142 | } |
143 | 143 | ||
144 | static int __init msg_do_config(struct usb_configuration *c) | 144 | static int __ref msg_do_config(struct usb_configuration *c) |
145 | { | 145 | { |
146 | struct fsg_common *common; | 146 | static const struct fsg_operations ops = { |
147 | .thread_exits = msg_thread_exits, | ||
148 | }; | ||
149 | static struct fsg_common common; | ||
150 | |||
151 | struct fsg_common *retp; | ||
147 | struct fsg_config config; | 152 | struct fsg_config config; |
148 | int ret; | 153 | int ret; |
149 | 154 | ||
@@ -153,13 +158,14 @@ static int __init msg_do_config(struct usb_configuration *c) | |||
153 | } | 158 | } |
154 | 159 | ||
155 | fsg_config_from_params(&config, &mod_data); | 160 | fsg_config_from_params(&config, &mod_data); |
156 | config.thread_exits = msg_thread_exits; | 161 | config.ops = &ops; |
157 | common = fsg_common_init(0, c->cdev, &config); | 162 | |
158 | if (IS_ERR(common)) | 163 | retp = fsg_common_init(&common, c->cdev, &config); |
159 | return PTR_ERR(common); | 164 | if (IS_ERR(retp)) |
165 | return PTR_ERR(retp); | ||
160 | 166 | ||
161 | ret = fsg_add(c->cdev, c, common); | 167 | ret = fsg_bind_config(c->cdev, c, &common); |
162 | fsg_common_put(common); | 168 | fsg_common_put(&common); |
163 | return ret; | 169 | return ret; |
164 | } | 170 | } |
165 | 171 | ||
@@ -176,7 +182,7 @@ static struct usb_configuration msg_config_driver = { | |||
176 | /****************************** Gadget Bind ******************************/ | 182 | /****************************** Gadget Bind ******************************/ |
177 | 183 | ||
178 | 184 | ||
179 | static int __init msg_bind(struct usb_composite_dev *cdev) | 185 | static int __ref msg_bind(struct usb_composite_dev *cdev) |
180 | { | 186 | { |
181 | struct usb_gadget *gadget = cdev->gadget; | 187 | struct usb_gadget *gadget = cdev->gadget; |
182 | int status; | 188 | int status; |
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index a930d7fd7e7a..795d76232167 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/utsname.h> | 26 | #include <linux/utsname.h> |
27 | #include <linux/module.h> | ||
27 | 28 | ||
28 | 29 | ||
29 | #if defined USB_ETH_RNDIS | 30 | #if defined USB_ETH_RNDIS |
@@ -35,14 +36,13 @@ | |||
35 | 36 | ||
36 | 37 | ||
37 | #define DRIVER_DESC "Multifunction Composite Gadget" | 38 | #define DRIVER_DESC "Multifunction Composite Gadget" |
38 | #define DRIVER_VERSION "2009/07/21" | ||
39 | 39 | ||
40 | /*-------------------------------------------------------------------------*/ | 40 | MODULE_DESCRIPTION(DRIVER_DESC); |
41 | MODULE_AUTHOR("Michal Nazarewicz"); | ||
42 | MODULE_LICENSE("GPL"); | ||
41 | 43 | ||
42 | #define MULTI_VENDOR_NUM 0x0525 /* XXX NetChip */ | ||
43 | #define MULTI_PRODUCT_NUM 0xa4ab /* XXX */ | ||
44 | 44 | ||
45 | /*-------------------------------------------------------------------------*/ | 45 | /***************************** All the files... *****************************/ |
46 | 46 | ||
47 | /* | 47 | /* |
48 | * kbuild is not very cooperative with respect to linking separately | 48 | * kbuild is not very cooperative with respect to linking separately |
@@ -57,6 +57,8 @@ | |||
57 | #include "config.c" | 57 | #include "config.c" |
58 | #include "epautoconf.c" | 58 | #include "epautoconf.c" |
59 | 59 | ||
60 | #include "f_mass_storage.c" | ||
61 | |||
60 | #include "u_serial.c" | 62 | #include "u_serial.c" |
61 | #include "f_acm.c" | 63 | #include "f_acm.c" |
62 | 64 | ||
@@ -68,13 +70,24 @@ | |||
68 | #endif | 70 | #endif |
69 | #include "u_ether.c" | 71 | #include "u_ether.c" |
70 | 72 | ||
71 | #undef DBG /* u_ether.c has broken idea about macros */ | ||
72 | #undef VDBG /* so clean up after it */ | ||
73 | #undef ERROR | ||
74 | #undef INFO | ||
75 | #include "f_mass_storage.c" | ||
76 | 73 | ||
77 | /*-------------------------------------------------------------------------*/ | 74 | |
75 | /***************************** Device Descriptor ****************************/ | ||
76 | |||
77 | #define MULTI_VENDOR_NUM 0x0525 /* XXX NetChip */ | ||
78 | #define MULTI_PRODUCT_NUM 0xa4ab /* XXX */ | ||
79 | |||
80 | |||
81 | enum { | ||
82 | __MULTI_NO_CONFIG, | ||
83 | #ifdef CONFIG_USB_G_MULTI_RNDIS | ||
84 | MULTI_RNDIS_CONFIG_NUM, | ||
85 | #endif | ||
86 | #ifdef CONFIG_USB_G_MULTI_CDC | ||
87 | MULTI_CDC_CONFIG_NUM, | ||
88 | #endif | ||
89 | }; | ||
90 | |||
78 | 91 | ||
79 | static struct usb_device_descriptor device_desc = { | 92 | static struct usb_device_descriptor device_desc = { |
80 | .bLength = sizeof device_desc, | 93 | .bLength = sizeof device_desc, |
@@ -82,80 +95,82 @@ static struct usb_device_descriptor device_desc = { | |||
82 | 95 | ||
83 | .bcdUSB = cpu_to_le16(0x0200), | 96 | .bcdUSB = cpu_to_le16(0x0200), |
84 | 97 | ||
85 | /* .bDeviceClass = USB_CLASS_COMM, */ | 98 | .bDeviceClass = USB_CLASS_MISC /* 0xEF */, |
86 | /* .bDeviceSubClass = 0, */ | ||
87 | /* .bDeviceProtocol = 0, */ | ||
88 | .bDeviceClass = 0xEF, | ||
89 | .bDeviceSubClass = 2, | 99 | .bDeviceSubClass = 2, |
90 | .bDeviceProtocol = 1, | 100 | .bDeviceProtocol = 1, |
91 | /* .bMaxPacketSize0 = f(hardware) */ | ||
92 | 101 | ||
93 | /* Vendor and product id can be overridden by module parameters. */ | 102 | /* Vendor and product id can be overridden by module parameters. */ |
94 | .idVendor = cpu_to_le16(MULTI_VENDOR_NUM), | 103 | .idVendor = cpu_to_le16(MULTI_VENDOR_NUM), |
95 | .idProduct = cpu_to_le16(MULTI_PRODUCT_NUM), | 104 | .idProduct = cpu_to_le16(MULTI_PRODUCT_NUM), |
96 | /* .bcdDevice = f(hardware) */ | ||
97 | /* .iManufacturer = DYNAMIC */ | ||
98 | /* .iProduct = DYNAMIC */ | ||
99 | /* NO SERIAL NUMBER */ | ||
100 | .bNumConfigurations = 1, | ||
101 | }; | 105 | }; |
102 | 106 | ||
103 | static struct usb_otg_descriptor otg_descriptor = { | ||
104 | .bLength = sizeof otg_descriptor, | ||
105 | .bDescriptorType = USB_DT_OTG, | ||
106 | |||
107 | /* REVISIT SRP-only hardware is possible, although | ||
108 | * it would not be called "OTG" ... | ||
109 | */ | ||
110 | .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, | ||
111 | }; | ||
112 | 107 | ||
113 | static const struct usb_descriptor_header *otg_desc[] = { | 108 | static const struct usb_descriptor_header *otg_desc[] = { |
114 | (struct usb_descriptor_header *) &otg_descriptor, | 109 | (struct usb_descriptor_header *) &(struct usb_otg_descriptor){ |
110 | .bLength = sizeof(struct usb_otg_descriptor), | ||
111 | .bDescriptorType = USB_DT_OTG, | ||
112 | |||
113 | /* | ||
114 | * REVISIT SRP-only hardware is possible, although | ||
115 | * it would not be called "OTG" ... | ||
116 | */ | ||
117 | .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, | ||
118 | }, | ||
115 | NULL, | 119 | NULL, |
116 | }; | 120 | }; |
117 | 121 | ||
118 | 122 | ||
119 | /* string IDs are assigned dynamically */ | 123 | enum { |
120 | 124 | MULTI_STRING_MANUFACTURER_IDX, | |
121 | #define STRING_MANUFACTURER_IDX 0 | 125 | MULTI_STRING_PRODUCT_IDX, |
122 | #define STRING_PRODUCT_IDX 1 | 126 | #ifdef CONFIG_USB_G_MULTI_RNDIS |
127 | MULTI_STRING_RNDIS_CONFIG_IDX, | ||
128 | #endif | ||
129 | #ifdef CONFIG_USB_G_MULTI_CDC | ||
130 | MULTI_STRING_CDC_CONFIG_IDX, | ||
131 | #endif | ||
132 | }; | ||
123 | 133 | ||
124 | static char manufacturer[50]; | 134 | static char manufacturer[50]; |
125 | 135 | ||
126 | static struct usb_string strings_dev[] = { | 136 | static struct usb_string strings_dev[] = { |
127 | [STRING_MANUFACTURER_IDX].s = manufacturer, | 137 | [MULTI_STRING_MANUFACTURER_IDX].s = manufacturer, |
128 | [STRING_PRODUCT_IDX].s = DRIVER_DESC, | 138 | [MULTI_STRING_PRODUCT_IDX].s = DRIVER_DESC, |
139 | #ifdef CONFIG_USB_G_MULTI_RNDIS | ||
140 | [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS", | ||
141 | #endif | ||
142 | #ifdef CONFIG_USB_G_MULTI_CDC | ||
143 | [MULTI_STRING_CDC_CONFIG_IDX].s = "Multifunction with CDC ECM", | ||
144 | #endif | ||
129 | { } /* end of list */ | 145 | { } /* end of list */ |
130 | }; | 146 | }; |
131 | 147 | ||
132 | static struct usb_gadget_strings stringtab_dev = { | ||
133 | .language = 0x0409, /* en-us */ | ||
134 | .strings = strings_dev, | ||
135 | }; | ||
136 | |||
137 | static struct usb_gadget_strings *dev_strings[] = { | 148 | static struct usb_gadget_strings *dev_strings[] = { |
138 | &stringtab_dev, | 149 | &(struct usb_gadget_strings){ |
150 | .language = 0x0409, /* en-us */ | ||
151 | .strings = strings_dev, | ||
152 | }, | ||
139 | NULL, | 153 | NULL, |
140 | }; | 154 | }; |
141 | 155 | ||
142 | static u8 hostaddr[ETH_ALEN]; | ||
143 | 156 | ||
144 | 157 | ||
145 | 158 | ||
146 | /****************************** Configurations ******************************/ | 159 | /****************************** Configurations ******************************/ |
147 | 160 | ||
148 | static struct fsg_module_parameters mod_data = { | 161 | static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; |
149 | .stall = 1 | 162 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); |
150 | }; | 163 | |
151 | FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); | 164 | static struct fsg_common fsg_common; |
165 | |||
166 | static u8 hostaddr[ETH_ALEN]; | ||
152 | 167 | ||
153 | static struct fsg_common *fsg_common; | ||
154 | 168 | ||
169 | /********** RNDIS **********/ | ||
155 | 170 | ||
156 | #ifdef USB_ETH_RNDIS | 171 | #ifdef USB_ETH_RNDIS |
157 | 172 | ||
158 | static int __init rndis_do_config(struct usb_configuration *c) | 173 | static __ref int rndis_do_config(struct usb_configuration *c) |
159 | { | 174 | { |
160 | int ret; | 175 | int ret; |
161 | 176 | ||
@@ -172,26 +187,42 @@ static int __init rndis_do_config(struct usb_configuration *c) | |||
172 | if (ret < 0) | 187 | if (ret < 0) |
173 | return ret; | 188 | return ret; |
174 | 189 | ||
175 | ret = fsg_add(c->cdev, c, fsg_common); | 190 | ret = fsg_bind_config(c->cdev, c, &fsg_common); |
176 | if (ret < 0) | 191 | if (ret < 0) |
177 | return ret; | 192 | return ret; |
178 | 193 | ||
179 | return 0; | 194 | return 0; |
180 | } | 195 | } |
181 | 196 | ||
182 | static struct usb_configuration rndis_config_driver = { | 197 | static int rndis_config_register(struct usb_composite_dev *cdev) |
183 | .label = "Multifunction Composite (RNDIS + MS + ACM)", | 198 | { |
184 | .bind = rndis_do_config, | 199 | static struct usb_configuration config = { |
185 | .bConfigurationValue = 2, | 200 | .bind = rndis_do_config, |
186 | /* .iConfiguration = DYNAMIC */ | 201 | .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM, |
187 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 202 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
188 | }; | 203 | }; |
204 | |||
205 | config.label = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].s; | ||
206 | config.iConfiguration = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].id; | ||
207 | |||
208 | return usb_add_config(cdev, &config); | ||
209 | } | ||
210 | |||
211 | #else | ||
212 | |||
213 | static int rndis_config_register(struct usb_composite_dev *cdev) | ||
214 | { | ||
215 | return 0; | ||
216 | } | ||
189 | 217 | ||
190 | #endif | 218 | #endif |
191 | 219 | ||
220 | |||
221 | /********** CDC ECM **********/ | ||
222 | |||
192 | #ifdef CONFIG_USB_G_MULTI_CDC | 223 | #ifdef CONFIG_USB_G_MULTI_CDC |
193 | 224 | ||
194 | static int __init cdc_do_config(struct usb_configuration *c) | 225 | static __ref int cdc_do_config(struct usb_configuration *c) |
195 | { | 226 | { |
196 | int ret; | 227 | int ret; |
197 | 228 | ||
@@ -208,20 +239,33 @@ static int __init cdc_do_config(struct usb_configuration *c) | |||
208 | if (ret < 0) | 239 | if (ret < 0) |
209 | return ret; | 240 | return ret; |
210 | 241 | ||
211 | ret = fsg_add(c->cdev, c, fsg_common); | 242 | ret = fsg_bind_config(c->cdev, c, &fsg_common); |
212 | if (ret < 0) | 243 | if (ret < 0) |
213 | return ret; | 244 | return ret; |
214 | 245 | ||
215 | return 0; | 246 | return 0; |
216 | } | 247 | } |
217 | 248 | ||
218 | static struct usb_configuration cdc_config_driver = { | 249 | static int cdc_config_register(struct usb_composite_dev *cdev) |
219 | .label = "Multifunction Composite (CDC + MS + ACM)", | 250 | { |
220 | .bind = cdc_do_config, | 251 | static struct usb_configuration config = { |
221 | .bConfigurationValue = 1, | 252 | .bind = cdc_do_config, |
222 | /* .iConfiguration = DYNAMIC */ | 253 | .bConfigurationValue = MULTI_CDC_CONFIG_NUM, |
223 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 254 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
224 | }; | 255 | }; |
256 | |||
257 | config.label = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].s; | ||
258 | config.iConfiguration = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].id; | ||
259 | |||
260 | return usb_add_config(cdev, &config); | ||
261 | } | ||
262 | |||
263 | #else | ||
264 | |||
265 | static int cdc_config_register(struct usb_composite_dev *cdev) | ||
266 | { | ||
267 | return 0; | ||
268 | } | ||
225 | 269 | ||
226 | #endif | 270 | #endif |
227 | 271 | ||
@@ -230,7 +274,7 @@ static struct usb_configuration cdc_config_driver = { | |||
230 | /****************************** Gadget Bind ******************************/ | 274 | /****************************** Gadget Bind ******************************/ |
231 | 275 | ||
232 | 276 | ||
233 | static int __init multi_bind(struct usb_composite_dev *cdev) | 277 | static int __ref multi_bind(struct usb_composite_dev *cdev) |
234 | { | 278 | { |
235 | struct usb_gadget *gadget = cdev->gadget; | 279 | struct usb_gadget *gadget = cdev->gadget; |
236 | int status, gcnum; | 280 | int status, gcnum; |
@@ -252,67 +296,56 @@ static int __init multi_bind(struct usb_composite_dev *cdev) | |||
252 | goto fail0; | 296 | goto fail0; |
253 | 297 | ||
254 | /* set up mass storage function */ | 298 | /* set up mass storage function */ |
255 | fsg_common = fsg_common_from_params(0, cdev, &mod_data); | 299 | { |
256 | if (IS_ERR(fsg_common)) { | 300 | void *retp; |
257 | status = PTR_ERR(fsg_common); | 301 | retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); |
258 | goto fail1; | 302 | if (IS_ERR(retp)) { |
303 | status = PTR_ERR(retp); | ||
304 | goto fail1; | ||
305 | } | ||
259 | } | 306 | } |
260 | 307 | ||
261 | 308 | /* set bcdDevice */ | |
262 | gcnum = usb_gadget_controller_number(gadget); | 309 | gcnum = usb_gadget_controller_number(gadget); |
263 | if (gcnum >= 0) | 310 | if (gcnum >= 0) { |
264 | device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum); | 311 | device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum); |
265 | else { | 312 | } else { |
266 | /* We assume that can_support_ecm() tells the truth; | 313 | WARNING(cdev, "controller '%s' not recognized\n", gadget->name); |
267 | * but if the controller isn't recognized at all then | ||
268 | * that assumption is a bit more likely to be wrong. | ||
269 | */ | ||
270 | WARNING(cdev, "controller '%s' not recognized\n", | ||
271 | gadget->name); | ||
272 | device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099); | 314 | device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099); |
273 | } | 315 | } |
274 | 316 | ||
275 | 317 | /* allocate string descriptor numbers */ | |
276 | /* Allocate string descriptor numbers ... note that string | ||
277 | * contents can be overridden by the composite_dev glue. | ||
278 | */ | ||
279 | |||
280 | /* device descriptor strings: manufacturer, product */ | ||
281 | snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", | 318 | snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", |
282 | init_utsname()->sysname, init_utsname()->release, | 319 | init_utsname()->sysname, init_utsname()->release, |
283 | gadget->name); | 320 | gadget->name); |
284 | status = usb_string_id(cdev); | ||
285 | if (status < 0) | ||
286 | goto fail2; | ||
287 | strings_dev[STRING_MANUFACTURER_IDX].id = status; | ||
288 | device_desc.iManufacturer = status; | ||
289 | 321 | ||
290 | status = usb_string_id(cdev); | 322 | status = usb_string_ids_tab(cdev, strings_dev); |
291 | if (status < 0) | 323 | if (unlikely(status < 0)) |
292 | goto fail2; | 324 | goto fail2; |
293 | strings_dev[STRING_PRODUCT_IDX].id = status; | ||
294 | device_desc.iProduct = status; | ||
295 | 325 | ||
296 | #ifdef USB_ETH_RNDIS | 326 | device_desc.iManufacturer = |
297 | /* register our first configuration */ | 327 | strings_dev[MULTI_STRING_MANUFACTURER_IDX].id; |
298 | status = usb_add_config(cdev, &rndis_config_driver); | 328 | device_desc.iProduct = |
299 | if (status < 0) | 329 | strings_dev[MULTI_STRING_PRODUCT_IDX].id; |
330 | |||
331 | /* register configurations */ | ||
332 | status = rndis_config_register(cdev); | ||
333 | if (unlikely(status < 0)) | ||
300 | goto fail2; | 334 | goto fail2; |
301 | #endif | ||
302 | 335 | ||
303 | #ifdef CONFIG_USB_G_MULTI_CDC | 336 | status = cdc_config_register(cdev); |
304 | /* register our second configuration */ | 337 | if (unlikely(status < 0)) |
305 | status = usb_add_config(cdev, &cdc_config_driver); | ||
306 | if (status < 0) | ||
307 | goto fail2; | 338 | goto fail2; |
308 | #endif | ||
309 | 339 | ||
310 | dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); | 340 | /* we're done */ |
311 | fsg_common_put(fsg_common); | 341 | dev_info(&gadget->dev, DRIVER_DESC "\n"); |
342 | fsg_common_put(&fsg_common); | ||
312 | return 0; | 343 | return 0; |
313 | 344 | ||
345 | |||
346 | /* error recovery */ | ||
314 | fail2: | 347 | fail2: |
315 | fsg_common_put(fsg_common); | 348 | fsg_common_put(&fsg_common); |
316 | fail1: | 349 | fail1: |
317 | gserial_cleanup(); | 350 | gserial_cleanup(); |
318 | fail0: | 351 | fail0: |
@@ -339,18 +372,15 @@ static struct usb_composite_driver multi_driver = { | |||
339 | .unbind = __exit_p(multi_unbind), | 372 | .unbind = __exit_p(multi_unbind), |
340 | }; | 373 | }; |
341 | 374 | ||
342 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
343 | MODULE_AUTHOR("Michal Nazarewicz"); | ||
344 | MODULE_LICENSE("GPL"); | ||
345 | 375 | ||
346 | static int __init g_multi_init(void) | 376 | static int __init multi_init(void) |
347 | { | 377 | { |
348 | return usb_composite_register(&multi_driver); | 378 | return usb_composite_register(&multi_driver); |
349 | } | 379 | } |
350 | module_init(g_multi_init); | 380 | module_init(multi_init); |
351 | 381 | ||
352 | static void __exit g_multi_cleanup(void) | 382 | static void __exit multi_exit(void) |
353 | { | 383 | { |
354 | usb_composite_unregister(&multi_driver); | 384 | usb_composite_unregister(&multi_driver); |
355 | } | 385 | } |
356 | module_exit(g_multi_cleanup); | 386 | module_exit(multi_exit); |
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index 4c3ac5c42237..cf241c371a71 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <linux/ioport.h> | 25 | #include <linux/ioport.h> |
26 | #include <linux/sched.h> | 26 | #include <linux/sched.h> |
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/smp_lock.h> | 28 | #include <linux/mutex.h> |
29 | #include <linux/errno.h> | 29 | #include <linux/errno.h> |
30 | #include <linux/init.h> | 30 | #include <linux/init.h> |
31 | #include <linux/timer.h> | 31 | #include <linux/timer.h> |
@@ -70,6 +70,7 @@ | |||
70 | #define DRIVER_DESC "Printer Gadget" | 70 | #define DRIVER_DESC "Printer Gadget" |
71 | #define DRIVER_VERSION "2007 OCT 06" | 71 | #define DRIVER_VERSION "2007 OCT 06" |
72 | 72 | ||
73 | static DEFINE_MUTEX(printer_mutex); | ||
73 | static const char shortname [] = "printer"; | 74 | static const char shortname [] = "printer"; |
74 | static const char driver_desc [] = DRIVER_DESC; | 75 | static const char driver_desc [] = DRIVER_DESC; |
75 | 76 | ||
@@ -476,7 +477,7 @@ printer_open(struct inode *inode, struct file *fd) | |||
476 | unsigned long flags; | 477 | unsigned long flags; |
477 | int ret = -EBUSY; | 478 | int ret = -EBUSY; |
478 | 479 | ||
479 | lock_kernel(); | 480 | mutex_lock(&printer_mutex); |
480 | dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); | 481 | dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); |
481 | 482 | ||
482 | spin_lock_irqsave(&dev->lock, flags); | 483 | spin_lock_irqsave(&dev->lock, flags); |
@@ -492,7 +493,7 @@ printer_open(struct inode *inode, struct file *fd) | |||
492 | spin_unlock_irqrestore(&dev->lock, flags); | 493 | spin_unlock_irqrestore(&dev->lock, flags); |
493 | 494 | ||
494 | DBG(dev, "printer_open returned %x\n", ret); | 495 | DBG(dev, "printer_open returned %x\n", ret); |
495 | unlock_kernel(); | 496 | mutex_unlock(&printer_mutex); |
496 | return ret; | 497 | return ret; |
497 | } | 498 | } |
498 | 499 | ||
@@ -1346,7 +1347,7 @@ printer_unbind(struct usb_gadget *gadget) | |||
1346 | set_gadget_data(gadget, NULL); | 1347 | set_gadget_data(gadget, NULL); |
1347 | } | 1348 | } |
1348 | 1349 | ||
1349 | static int __init | 1350 | static int __ref |
1350 | printer_bind(struct usb_gadget *gadget) | 1351 | printer_bind(struct usb_gadget *gadget) |
1351 | { | 1352 | { |
1352 | struct printer_dev *dev; | 1353 | struct printer_dev *dev; |
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index 26193eceb323..521ebed0118d 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -12,6 +12,8 @@ | |||
12 | * published by the Free Software Foundation. | 12 | * published by the Free Software Foundation. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #define DEBUG | ||
16 | |||
15 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
16 | #include <linux/module.h> | 18 | #include <linux/module.h> |
17 | #include <linux/spinlock.h> | 19 | #include <linux/spinlock.h> |
@@ -23,6 +25,7 @@ | |||
23 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
24 | #include <linux/io.h> | 26 | #include <linux/io.h> |
25 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/clk.h> | ||
26 | 29 | ||
27 | #include <linux/usb/ch9.h> | 30 | #include <linux/usb/ch9.h> |
28 | #include <linux/usb/gadget.h> | 31 | #include <linux/usb/gadget.h> |
@@ -33,6 +36,7 @@ | |||
33 | #include <plat/regs-usb-hsotg.h> | 36 | #include <plat/regs-usb-hsotg.h> |
34 | #include <mach/regs-sys.h> | 37 | #include <mach/regs-sys.h> |
35 | #include <plat/udc-hs.h> | 38 | #include <plat/udc-hs.h> |
39 | #include <plat/cpu.h> | ||
36 | 40 | ||
37 | #define DMA_ADDR_INVALID (~((dma_addr_t)0)) | 41 | #define DMA_ADDR_INVALID (~((dma_addr_t)0)) |
38 | 42 | ||
@@ -91,7 +95,9 @@ struct s3c_hsotg_req; | |||
91 | * For periodic IN endpoints, we have fifo_size and fifo_load to try | 95 | * For periodic IN endpoints, we have fifo_size and fifo_load to try |
92 | * and keep track of the amount of data in the periodic FIFO for each | 96 | * and keep track of the amount of data in the periodic FIFO for each |
93 | * of these as we don't have a status register that tells us how much | 97 | * of these as we don't have a status register that tells us how much |
94 | * is in each of them. | 98 | * is in each of them. (note, this may actually be useless information |
99 | * as in shared-fifo mode periodic in acts like a single-frame packet | ||
100 | * buffer than a fifo) | ||
95 | */ | 101 | */ |
96 | struct s3c_hsotg_ep { | 102 | struct s3c_hsotg_ep { |
97 | struct usb_ep ep; | 103 | struct usb_ep ep; |
@@ -128,6 +134,7 @@ struct s3c_hsotg_ep { | |||
128 | * @regs: The memory area mapped for accessing registers. | 134 | * @regs: The memory area mapped for accessing registers. |
129 | * @regs_res: The resource that was allocated when claiming register space. | 135 | * @regs_res: The resource that was allocated when claiming register space. |
130 | * @irq: The IRQ number we are using | 136 | * @irq: The IRQ number we are using |
137 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. | ||
131 | * @debug_root: root directrory for debugfs. | 138 | * @debug_root: root directrory for debugfs. |
132 | * @debug_file: main status file for debugfs. | 139 | * @debug_file: main status file for debugfs. |
133 | * @debug_fifo: FIFO status file for debugfs. | 140 | * @debug_fifo: FIFO status file for debugfs. |
@@ -145,6 +152,9 @@ struct s3c_hsotg { | |||
145 | void __iomem *regs; | 152 | void __iomem *regs; |
146 | struct resource *regs_res; | 153 | struct resource *regs_res; |
147 | int irq; | 154 | int irq; |
155 | struct clk *clk; | ||
156 | |||
157 | unsigned int dedicated_fifos:1; | ||
148 | 158 | ||
149 | struct dentry *debug_root; | 159 | struct dentry *debug_root; |
150 | struct dentry *debug_file; | 160 | struct dentry *debug_file; |
@@ -310,11 +320,11 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | |||
310 | hsotg->regs + S3C_GNPTXFSIZ); | 320 | hsotg->regs + S3C_GNPTXFSIZ); |
311 | */ | 321 | */ |
312 | 322 | ||
313 | /* set FIFO sizes to 2048/0x1C0 */ | 323 | /* set FIFO sizes to 2048/1024 */ |
314 | 324 | ||
315 | writel(2048, hsotg->regs + S3C_GRXFSIZ); | 325 | writel(2048, hsotg->regs + S3C_GRXFSIZ); |
316 | writel(S3C_GNPTXFSIZ_NPTxFStAddr(2048) | | 326 | writel(S3C_GNPTXFSIZ_NPTxFStAddr(2048) | |
317 | S3C_GNPTXFSIZ_NPTxFDep(0x1C0), | 327 | S3C_GNPTXFSIZ_NPTxFDep(1024), |
318 | hsotg->regs + S3C_GNPTXFSIZ); | 328 | hsotg->regs + S3C_GNPTXFSIZ); |
319 | 329 | ||
320 | /* arange all the rest of the TX FIFOs, as some versions of this | 330 | /* arange all the rest of the TX FIFOs, as some versions of this |
@@ -464,7 +474,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
464 | if (to_write == 0) | 474 | if (to_write == 0) |
465 | return 0; | 475 | return 0; |
466 | 476 | ||
467 | if (periodic) { | 477 | if (periodic && !hsotg->dedicated_fifos) { |
468 | u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index)); | 478 | u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index)); |
469 | int size_left; | 479 | int size_left; |
470 | int size_done; | 480 | int size_done; |
@@ -474,6 +484,14 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
474 | 484 | ||
475 | size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); | 485 | size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); |
476 | 486 | ||
487 | /* if shared fifo, we cannot write anything until the | ||
488 | * previous data has been completely sent. | ||
489 | */ | ||
490 | if (hs_ep->fifo_load != 0) { | ||
491 | s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp); | ||
492 | return -ENOSPC; | ||
493 | } | ||
494 | |||
477 | dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", | 495 | dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", |
478 | __func__, size_left, | 496 | __func__, size_left, |
479 | hs_ep->size_loaded, hs_ep->fifo_load, hs_ep->fifo_size); | 497 | hs_ep->size_loaded, hs_ep->fifo_load, hs_ep->fifo_size); |
@@ -494,6 +512,11 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
494 | s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp); | 512 | s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp); |
495 | return -ENOSPC; | 513 | return -ENOSPC; |
496 | } | 514 | } |
515 | } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { | ||
516 | can_write = readl(hsotg->regs + S3C_DTXFSTS(hs_ep->index)); | ||
517 | |||
518 | can_write &= 0xffff; | ||
519 | can_write *= 4; | ||
497 | } else { | 520 | } else { |
498 | if (S3C_GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) { | 521 | if (S3C_GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) { |
499 | dev_dbg(hsotg->dev, | 522 | dev_dbg(hsotg->dev, |
@@ -505,6 +528,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
505 | } | 528 | } |
506 | 529 | ||
507 | can_write = S3C_GNPTXSTS_NPTxFSpcAvail_GET(gnptxsts); | 530 | can_write = S3C_GNPTXSTS_NPTxFSpcAvail_GET(gnptxsts); |
531 | can_write *= 4; /* fifo size is in 32bit quantities. */ | ||
508 | } | 532 | } |
509 | 533 | ||
510 | dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", | 534 | dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", |
@@ -517,6 +541,17 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
517 | if (can_write > 512) | 541 | if (can_write > 512) |
518 | can_write = 512; | 542 | can_write = 512; |
519 | 543 | ||
544 | /* limit the write to one max-packet size worth of data, but allow | ||
545 | * the transfer to return that it did not run out of fifo space | ||
546 | * doing it. */ | ||
547 | if (to_write > hs_ep->ep.maxpacket) { | ||
548 | to_write = hs_ep->ep.maxpacket; | ||
549 | |||
550 | s3c_hsotg_en_gsint(hsotg, | ||
551 | periodic ? S3C_GINTSTS_PTxFEmp : | ||
552 | S3C_GINTSTS_NPTxFEmp); | ||
553 | } | ||
554 | |||
520 | /* see if we can write data */ | 555 | /* see if we can write data */ |
521 | 556 | ||
522 | if (to_write > can_write) { | 557 | if (to_write > can_write) { |
@@ -579,12 +614,10 @@ static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep) | |||
579 | maxsize = S3C_DxEPTSIZ_XferSize_LIMIT + 1; | 614 | maxsize = S3C_DxEPTSIZ_XferSize_LIMIT + 1; |
580 | maxpkt = S3C_DxEPTSIZ_PktCnt_LIMIT + 1; | 615 | maxpkt = S3C_DxEPTSIZ_PktCnt_LIMIT + 1; |
581 | } else { | 616 | } else { |
617 | maxsize = 64+64; | ||
582 | if (hs_ep->dir_in) { | 618 | if (hs_ep->dir_in) { |
583 | /* maxsize = S3C_DIEPTSIZ0_XferSize_LIMIT + 1; */ | ||
584 | maxsize = 64+64+1; | ||
585 | maxpkt = S3C_DIEPTSIZ0_PktCnt_LIMIT + 1; | 619 | maxpkt = S3C_DIEPTSIZ0_PktCnt_LIMIT + 1; |
586 | } else { | 620 | } else { |
587 | maxsize = 0x3f; | ||
588 | maxpkt = 2; | 621 | maxpkt = 2; |
589 | } | 622 | } |
590 | } | 623 | } |
@@ -1353,6 +1386,9 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | |||
1353 | read_ptr = hs_req->req.actual; | 1386 | read_ptr = hs_req->req.actual; |
1354 | max_req = hs_req->req.length - read_ptr; | 1387 | max_req = hs_req->req.length - read_ptr; |
1355 | 1388 | ||
1389 | dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", | ||
1390 | __func__, to_read, max_req, read_ptr, hs_req->req.length); | ||
1391 | |||
1356 | if (to_read > max_req) { | 1392 | if (to_read > max_req) { |
1357 | /* more data appeared than we where willing | 1393 | /* more data appeared than we where willing |
1358 | * to deal with in this request. | 1394 | * to deal with in this request. |
@@ -1362,9 +1398,6 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | |||
1362 | WARN_ON_ONCE(1); | 1398 | WARN_ON_ONCE(1); |
1363 | } | 1399 | } |
1364 | 1400 | ||
1365 | dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", | ||
1366 | __func__, to_read, max_req, read_ptr, hs_req->req.length); | ||
1367 | |||
1368 | hs_ep->total_data += to_read; | 1401 | hs_ep->total_data += to_read; |
1369 | hs_req->req.actual += to_read; | 1402 | hs_req->req.actual += to_read; |
1370 | to_read = DIV_ROUND_UP(to_read, 4); | 1403 | to_read = DIV_ROUND_UP(to_read, 4); |
@@ -1433,9 +1466,11 @@ static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, | |||
1433 | static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | 1466 | static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, |
1434 | int epnum, bool was_setup) | 1467 | int epnum, bool was_setup) |
1435 | { | 1468 | { |
1469 | u32 epsize = readl(hsotg->regs + S3C_DOEPTSIZ(epnum)); | ||
1436 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; | 1470 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; |
1437 | struct s3c_hsotg_req *hs_req = hs_ep->req; | 1471 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
1438 | struct usb_request *req = &hs_req->req; | 1472 | struct usb_request *req = &hs_req->req; |
1473 | unsigned size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); | ||
1439 | int result = 0; | 1474 | int result = 0; |
1440 | 1475 | ||
1441 | if (!hs_req) { | 1476 | if (!hs_req) { |
@@ -1444,9 +1479,7 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1444 | } | 1479 | } |
1445 | 1480 | ||
1446 | if (using_dma(hsotg)) { | 1481 | if (using_dma(hsotg)) { |
1447 | u32 epsize = readl(hsotg->regs + S3C_DOEPTSIZ(epnum)); | ||
1448 | unsigned size_done; | 1482 | unsigned size_done; |
1449 | unsigned size_left; | ||
1450 | 1483 | ||
1451 | /* Calculate the size of the transfer by checking how much | 1484 | /* Calculate the size of the transfer by checking how much |
1452 | * is left in the endpoint size register and then working it | 1485 | * is left in the endpoint size register and then working it |
@@ -1456,14 +1489,18 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1456 | * so may overshoot/undershoot the transfer. | 1489 | * so may overshoot/undershoot the transfer. |
1457 | */ | 1490 | */ |
1458 | 1491 | ||
1459 | size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); | ||
1460 | |||
1461 | size_done = hs_ep->size_loaded - size_left; | 1492 | size_done = hs_ep->size_loaded - size_left; |
1462 | size_done += hs_ep->last_load; | 1493 | size_done += hs_ep->last_load; |
1463 | 1494 | ||
1464 | req->actual = size_done; | 1495 | req->actual = size_done; |
1465 | } | 1496 | } |
1466 | 1497 | ||
1498 | /* if there is more request to do, schedule new transfer */ | ||
1499 | if (req->actual < req->length && size_left == 0) { | ||
1500 | s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); | ||
1501 | return; | ||
1502 | } | ||
1503 | |||
1467 | if (req->actual < req->length && req->short_not_ok) { | 1504 | if (req->actual < req->length && req->short_not_ok) { |
1468 | dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", | 1505 | dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", |
1469 | __func__, req->actual, req->length); | 1506 | __func__, req->actual, req->length); |
@@ -1758,7 +1795,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1758 | if (dir_in) { | 1795 | if (dir_in) { |
1759 | s3c_hsotg_complete_in(hsotg, hs_ep); | 1796 | s3c_hsotg_complete_in(hsotg, hs_ep); |
1760 | 1797 | ||
1761 | if (idx == 0) | 1798 | if (idx == 0 && !hs_ep->req) |
1762 | s3c_hsotg_enqueue_setup(hsotg); | 1799 | s3c_hsotg_enqueue_setup(hsotg); |
1763 | } else if (using_dma(hsotg)) { | 1800 | } else if (using_dma(hsotg)) { |
1764 | /* We're using DMA, we need to fire an OutDone here | 1801 | /* We're using DMA, we need to fire an OutDone here |
@@ -1818,6 +1855,15 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1818 | __func__, idx); | 1855 | __func__, idx); |
1819 | clear |= S3C_DIEPMSK_INTknEPMisMsk; | 1856 | clear |= S3C_DIEPMSK_INTknEPMisMsk; |
1820 | } | 1857 | } |
1858 | |||
1859 | /* FIFO has space or is empty (see GAHBCFG) */ | ||
1860 | if (hsotg->dedicated_fifos && | ||
1861 | ints & S3C_DIEPMSK_TxFIFOEmpty) { | ||
1862 | dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", | ||
1863 | __func__, idx); | ||
1864 | s3c_hsotg_trytx(hsotg, hs_ep); | ||
1865 | clear |= S3C_DIEPMSK_TxFIFOEmpty; | ||
1866 | } | ||
1821 | } | 1867 | } |
1822 | 1868 | ||
1823 | writel(clear, hsotg->regs + epint_reg); | 1869 | writel(clear, hsotg->regs + epint_reg); |
@@ -2071,17 +2117,12 @@ irq_retry: | |||
2071 | kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true); | 2117 | kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true); |
2072 | 2118 | ||
2073 | /* it seems after a reset we can end up with a situation | 2119 | /* it seems after a reset we can end up with a situation |
2074 | * where the TXFIFO still has data in it... try flushing | 2120 | * where the TXFIFO still has data in it... the docs |
2075 | * it to remove anything that may still be in it. | 2121 | * suggest resetting all the fifos, so use the init_fifo |
2122 | * code to relayout and flush the fifos. | ||
2076 | */ | 2123 | */ |
2077 | 2124 | ||
2078 | if (1) { | 2125 | s3c_hsotg_init_fifo(hsotg); |
2079 | writel(S3C_GRSTCTL_TxFNum(0) | S3C_GRSTCTL_TxFFlsh, | ||
2080 | hsotg->regs + S3C_GRSTCTL); | ||
2081 | |||
2082 | dev_info(hsotg->dev, "GNPTXSTS=%08x\n", | ||
2083 | readl(hsotg->regs + S3C_GNPTXSTS)); | ||
2084 | } | ||
2085 | 2126 | ||
2086 | s3c_hsotg_enqueue_setup(hsotg); | 2127 | s3c_hsotg_enqueue_setup(hsotg); |
2087 | 2128 | ||
@@ -2274,6 +2315,12 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2274 | break; | 2315 | break; |
2275 | } | 2316 | } |
2276 | 2317 | ||
2318 | /* if the hardware has dedicated fifos, we must give each IN EP | ||
2319 | * a unique tx-fifo even if it is non-periodic. | ||
2320 | */ | ||
2321 | if (dir_in && hsotg->dedicated_fifos) | ||
2322 | epctrl |= S3C_DxEPCTL_TxFNum(index); | ||
2323 | |||
2277 | /* for non control endpoints, set PID to D0 */ | 2324 | /* for non control endpoints, set PID to D0 */ |
2278 | if (index) | 2325 | if (index) |
2279 | epctrl |= S3C_DxEPCTL_SetD0PID; | 2326 | epctrl |= S3C_DxEPCTL_SetD0PID; |
@@ -2563,7 +2610,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
2563 | 2610 | ||
2564 | writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | | 2611 | writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | |
2565 | S3C_DIEPMSK_INTknEPMisMsk | | 2612 | S3C_DIEPMSK_INTknEPMisMsk | |
2566 | S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk, | 2613 | S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk | |
2614 | ((hsotg->dedicated_fifos) ? S3C_DIEPMSK_TxFIFOEmpty : 0), | ||
2567 | hsotg->regs + S3C_DIEPMSK); | 2615 | hsotg->regs + S3C_DIEPMSK); |
2568 | 2616 | ||
2569 | /* don't need XferCompl, we get that from RXFIFO in slave mode. In | 2617 | /* don't need XferCompl, we get that from RXFIFO in slave mode. In |
@@ -2732,7 +2780,7 @@ static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
2732 | */ | 2780 | */ |
2733 | 2781 | ||
2734 | ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum)); | 2782 | ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum)); |
2735 | hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo); | 2783 | hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo) * 4; |
2736 | 2784 | ||
2737 | /* if we're using dma, we need to set the next-endpoint pointer | 2785 | /* if we're using dma, we need to set the next-endpoint pointer |
2738 | * to be something valid. | 2786 | * to be something valid. |
@@ -2753,13 +2801,33 @@ static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
2753 | */ | 2801 | */ |
2754 | static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg) | 2802 | static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg) |
2755 | { | 2803 | { |
2756 | u32 osc; | 2804 | struct clk *xusbxti; |
2805 | u32 pwr, osc; | ||
2757 | 2806 | ||
2758 | writel(0, S3C_PHYPWR); | 2807 | pwr = readl(S3C_PHYPWR); |
2808 | pwr &= ~0x19; | ||
2809 | writel(pwr, S3C_PHYPWR); | ||
2759 | mdelay(1); | 2810 | mdelay(1); |
2760 | 2811 | ||
2761 | osc = hsotg->plat->is_osc ? S3C_PHYCLK_EXT_OSC : 0; | 2812 | osc = hsotg->plat->is_osc ? S3C_PHYCLK_EXT_OSC : 0; |
2762 | 2813 | ||
2814 | xusbxti = clk_get(hsotg->dev, "xusbxti"); | ||
2815 | if (xusbxti && !IS_ERR(xusbxti)) { | ||
2816 | switch (clk_get_rate(xusbxti)) { | ||
2817 | case 12*MHZ: | ||
2818 | osc |= S3C_PHYCLK_CLKSEL_12M; | ||
2819 | break; | ||
2820 | case 24*MHZ: | ||
2821 | osc |= S3C_PHYCLK_CLKSEL_24M; | ||
2822 | break; | ||
2823 | default: | ||
2824 | case 48*MHZ: | ||
2825 | /* default reference clock */ | ||
2826 | break; | ||
2827 | } | ||
2828 | clk_put(xusbxti); | ||
2829 | } | ||
2830 | |||
2763 | writel(osc | 0x10, S3C_PHYCLK); | 2831 | writel(osc | 0x10, S3C_PHYCLK); |
2764 | 2832 | ||
2765 | /* issue a full set of resets to the otg and core */ | 2833 | /* issue a full set of resets to the otg and core */ |
@@ -2772,6 +2840,8 @@ static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg) | |||
2772 | 2840 | ||
2773 | static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | 2841 | static void s3c_hsotg_init(struct s3c_hsotg *hsotg) |
2774 | { | 2842 | { |
2843 | u32 cfg4; | ||
2844 | |||
2775 | /* unmask subset of endpoint interrupts */ | 2845 | /* unmask subset of endpoint interrupts */ |
2776 | 2846 | ||
2777 | writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | | 2847 | writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | |
@@ -2807,6 +2877,14 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | |||
2807 | 2877 | ||
2808 | writel(using_dma(hsotg) ? S3C_GAHBCFG_DMAEn : 0x0, | 2878 | writel(using_dma(hsotg) ? S3C_GAHBCFG_DMAEn : 0x0, |
2809 | hsotg->regs + S3C_GAHBCFG); | 2879 | hsotg->regs + S3C_GAHBCFG); |
2880 | |||
2881 | /* check hardware configuration */ | ||
2882 | |||
2883 | cfg4 = readl(hsotg->regs + 0x50); | ||
2884 | hsotg->dedicated_fifos = (cfg4 >> 25) & 1; | ||
2885 | |||
2886 | dev_info(hsotg->dev, "%s fifos\n", | ||
2887 | hsotg->dedicated_fifos ? "dedicated" : "shared"); | ||
2810 | } | 2888 | } |
2811 | 2889 | ||
2812 | static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) | 2890 | static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) |
@@ -3181,13 +3259,20 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) | |||
3181 | hsotg->dev = dev; | 3259 | hsotg->dev = dev; |
3182 | hsotg->plat = plat; | 3260 | hsotg->plat = plat; |
3183 | 3261 | ||
3262 | hsotg->clk = clk_get(&pdev->dev, "otg"); | ||
3263 | if (IS_ERR(hsotg->clk)) { | ||
3264 | dev_err(dev, "cannot get otg clock\n"); | ||
3265 | ret = -EINVAL; | ||
3266 | goto err_mem; | ||
3267 | } | ||
3268 | |||
3184 | platform_set_drvdata(pdev, hsotg); | 3269 | platform_set_drvdata(pdev, hsotg); |
3185 | 3270 | ||
3186 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 3271 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
3187 | if (!res) { | 3272 | if (!res) { |
3188 | dev_err(dev, "cannot find register resource 0\n"); | 3273 | dev_err(dev, "cannot find register resource 0\n"); |
3189 | ret = -EINVAL; | 3274 | ret = -EINVAL; |
3190 | goto err_mem; | 3275 | goto err_clk; |
3191 | } | 3276 | } |
3192 | 3277 | ||
3193 | hsotg->regs_res = request_mem_region(res->start, resource_size(res), | 3278 | hsotg->regs_res = request_mem_region(res->start, resource_size(res), |
@@ -3195,7 +3280,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) | |||
3195 | if (!hsotg->regs_res) { | 3280 | if (!hsotg->regs_res) { |
3196 | dev_err(dev, "cannot reserve registers\n"); | 3281 | dev_err(dev, "cannot reserve registers\n"); |
3197 | ret = -ENOENT; | 3282 | ret = -ENOENT; |
3198 | goto err_mem; | 3283 | goto err_clk; |
3199 | } | 3284 | } |
3200 | 3285 | ||
3201 | hsotg->regs = ioremap(res->start, resource_size(res)); | 3286 | hsotg->regs = ioremap(res->start, resource_size(res)); |
@@ -3248,6 +3333,8 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) | |||
3248 | 3333 | ||
3249 | /* reset the system */ | 3334 | /* reset the system */ |
3250 | 3335 | ||
3336 | clk_enable(hsotg->clk); | ||
3337 | |||
3251 | s3c_hsotg_gate(pdev, true); | 3338 | s3c_hsotg_gate(pdev, true); |
3252 | 3339 | ||
3253 | s3c_hsotg_otgreset(hsotg); | 3340 | s3c_hsotg_otgreset(hsotg); |
@@ -3271,7 +3358,8 @@ err_regs: | |||
3271 | err_regs_res: | 3358 | err_regs_res: |
3272 | release_resource(hsotg->regs_res); | 3359 | release_resource(hsotg->regs_res); |
3273 | kfree(hsotg->regs_res); | 3360 | kfree(hsotg->regs_res); |
3274 | 3361 | err_clk: | |
3362 | clk_put(hsotg->clk); | ||
3275 | err_mem: | 3363 | err_mem: |
3276 | kfree(hsotg); | 3364 | kfree(hsotg); |
3277 | return ret; | 3365 | return ret; |
@@ -3293,6 +3381,9 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev) | |||
3293 | 3381 | ||
3294 | s3c_hsotg_gate(pdev, false); | 3382 | s3c_hsotg_gate(pdev, false); |
3295 | 3383 | ||
3384 | clk_disable(hsotg->clk); | ||
3385 | clk_put(hsotg->clk); | ||
3386 | |||
3296 | kfree(hsotg); | 3387 | kfree(hsotg); |
3297 | return 0; | 3388 | return 0; |
3298 | } | 3389 | } |
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index f46a60962dab..b22eedbc7dc5 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c | |||
@@ -137,7 +137,7 @@ MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); | |||
137 | 137 | ||
138 | /*-------------------------------------------------------------------------*/ | 138 | /*-------------------------------------------------------------------------*/ |
139 | 139 | ||
140 | static int __init serial_bind_config(struct usb_configuration *c) | 140 | static int __ref serial_bind_config(struct usb_configuration *c) |
141 | { | 141 | { |
142 | unsigned i; | 142 | unsigned i; |
143 | int status = 0; | 143 | int status = 0; |
@@ -161,7 +161,7 @@ static struct usb_configuration serial_config_driver = { | |||
161 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 161 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
162 | }; | 162 | }; |
163 | 163 | ||
164 | static int __init gs_bind(struct usb_composite_dev *cdev) | 164 | static int __ref gs_bind(struct usb_composite_dev *cdev) |
165 | { | 165 | { |
166 | int gcnum; | 166 | int gcnum; |
167 | struct usb_gadget *gadget = cdev->gadget; | 167 | struct usb_gadget *gadget = cdev->gadget; |
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 04c462ff0ea6..484acfb1a7c5 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
@@ -57,10 +57,12 @@ | |||
57 | #include <asm/unaligned.h> | 57 | #include <asm/unaligned.h> |
58 | 58 | ||
59 | 59 | ||
60 | /* Thanks to NetChip Technologies for donating this product ID. | 60 | /* |
61 | * Thanks to NetChip Technologies for donating this product ID. | ||
61 | * | 62 | * |
62 | * DO NOT REUSE THESE IDs with any other driver!! Ever!! | 63 | * DO NOT REUSE THESE IDs with any other driver!! Ever!! |
63 | * Instead: allocate your own, using normal USB-IF procedures. */ | 64 | * Instead: allocate your own, using normal USB-IF procedures. |
65 | */ | ||
64 | #define FSG_VENDOR_ID 0x0525 /* NetChip */ | 66 | #define FSG_VENDOR_ID 0x0525 /* NetChip */ |
65 | #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ | 67 | #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ |
66 | 68 | ||
@@ -84,14 +86,27 @@ | |||
84 | #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) | 86 | #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) |
85 | #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) | 87 | #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) |
86 | 88 | ||
87 | /* Keep those macros in sync with thos in | 89 | /* |
88 | * include/linux/ubs/composite.h or else GCC will complain. If they | 90 | * Keep those macros in sync with those in |
91 | * include/linux/usb/composite.h or else GCC will complain. If they | ||
89 | * are identical (the same names of arguments, white spaces in the | 92 | * are identical (the same names of arguments, white spaces in the |
90 | * same places) GCC will allow redefinition otherwise (even if some | 93 | * same places) GCC will allow redefinition otherwise (even if some |
91 | * white space is removed or added) warning will be issued. No | 94 | * white space is removed or added) warning will be issued. |
92 | * checking if those symbols is defined is performed because warning | 95 | * |
93 | * is desired when those macros were defined by someone else to mean | 96 | * Those macros are needed here because File Storage Gadget does not |
94 | * something else. */ | 97 | * include the composite.h header. For composite gadgets those macros |
98 | * are redundant since composite.h is included any way. | ||
99 | * | ||
100 | * One could check whether those macros are already defined (which | ||
101 | * would indicate composite.h had been included) or not (which would | ||
102 | * indicate we were in FSG) but this is not done because a warning is | ||
103 | * desired if definitions here differ from the ones in composite.h. | ||
104 | * | ||
105 | * We want the definitions to match and be the same in File Storage | ||
106 | * Gadget as well as Mass Storage Function (and so composite gadgets | ||
107 | * using MSF). If someone changes them in composite.h it will produce | ||
108 | * a warning in this file when building MSF. | ||
109 | */ | ||
95 | #define DBG(d, fmt, args...) dev_dbg(&(d)->gadget->dev , fmt , ## args) | 110 | #define DBG(d, fmt, args...) dev_dbg(&(d)->gadget->dev , fmt , ## args) |
96 | #define VDBG(d, fmt, args...) dev_vdbg(&(d)->gadget->dev , fmt , ## args) | 111 | #define VDBG(d, fmt, args...) dev_vdbg(&(d)->gadget->dev , fmt , ## args) |
97 | #define ERROR(d, fmt, args...) dev_err(&(d)->gadget->dev , fmt , ## args) | 112 | #define ERROR(d, fmt, args...) dev_err(&(d)->gadget->dev , fmt , ## args) |
@@ -269,6 +284,7 @@ struct fsg_lun { | |||
269 | unsigned int prevent_medium_removal:1; | 284 | unsigned int prevent_medium_removal:1; |
270 | unsigned int registered:1; | 285 | unsigned int registered:1; |
271 | unsigned int info_valid:1; | 286 | unsigned int info_valid:1; |
287 | unsigned int nofua:1; | ||
272 | 288 | ||
273 | u32 sense_data; | 289 | u32 sense_data; |
274 | u32 sense_data_info; | 290 | u32 sense_data_info; |
@@ -313,9 +329,11 @@ struct fsg_buffhd { | |||
313 | enum fsg_buffer_state state; | 329 | enum fsg_buffer_state state; |
314 | struct fsg_buffhd *next; | 330 | struct fsg_buffhd *next; |
315 | 331 | ||
316 | /* The NetChip 2280 is faster, and handles some protocol faults | 332 | /* |
333 | * The NetChip 2280 is faster, and handles some protocol faults | ||
317 | * better, if we don't submit any short bulk-out read requests. | 334 | * better, if we don't submit any short bulk-out read requests. |
318 | * So we will record the intended request length here. */ | 335 | * So we will record the intended request length here. |
336 | */ | ||
319 | unsigned int bulk_out_intended_length; | 337 | unsigned int bulk_out_intended_length; |
320 | 338 | ||
321 | struct usb_request *inreq; | 339 | struct usb_request *inreq; |
@@ -395,8 +413,10 @@ fsg_intf_desc = { | |||
395 | .iInterface = FSG_STRING_INTERFACE, | 413 | .iInterface = FSG_STRING_INTERFACE, |
396 | }; | 414 | }; |
397 | 415 | ||
398 | /* Three full-speed endpoint descriptors: bulk-in, bulk-out, | 416 | /* |
399 | * and interrupt-in. */ | 417 | * Three full-speed endpoint descriptors: bulk-in, bulk-out, and |
418 | * interrupt-in. | ||
419 | */ | ||
400 | 420 | ||
401 | static struct usb_endpoint_descriptor | 421 | static struct usb_endpoint_descriptor |
402 | fsg_fs_bulk_in_desc = { | 422 | fsg_fs_bulk_in_desc = { |
@@ -459,7 +479,7 @@ static struct usb_descriptor_header *fsg_fs_function[] = { | |||
459 | * | 479 | * |
460 | * That means alternate endpoint descriptors (bigger packets) | 480 | * That means alternate endpoint descriptors (bigger packets) |
461 | * and a "device qualifier" ... plus more construction options | 481 | * and a "device qualifier" ... plus more construction options |
462 | * for the config descriptor. | 482 | * for the configuration descriptor. |
463 | */ | 483 | */ |
464 | static struct usb_endpoint_descriptor | 484 | static struct usb_endpoint_descriptor |
465 | fsg_hs_bulk_in_desc = { | 485 | fsg_hs_bulk_in_desc = { |
@@ -547,8 +567,10 @@ static struct usb_gadget_strings fsg_stringtab = { | |||
547 | 567 | ||
548 | /*-------------------------------------------------------------------------*/ | 568 | /*-------------------------------------------------------------------------*/ |
549 | 569 | ||
550 | /* If the next two routines are called while the gadget is registered, | 570 | /* |
551 | * the caller must own fsg->filesem for writing. */ | 571 | * If the next two routines are called while the gadget is registered, |
572 | * the caller must own fsg->filesem for writing. | ||
573 | */ | ||
552 | 574 | ||
553 | static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | 575 | static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) |
554 | { | 576 | { |
@@ -587,8 +609,10 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | |||
587 | goto out; | 609 | goto out; |
588 | } | 610 | } |
589 | 611 | ||
590 | /* If we can't read the file, it's no good. | 612 | /* |
591 | * If we can't write the file, use it read-only. */ | 613 | * If we can't read the file, it's no good. |
614 | * If we can't write the file, use it read-only. | ||
615 | */ | ||
592 | if (!filp->f_op || !(filp->f_op->read || filp->f_op->aio_read)) { | 616 | if (!filp->f_op || !(filp->f_op->read || filp->f_op->aio_read)) { |
593 | LINFO(curlun, "file not readable: %s\n", filename); | 617 | LINFO(curlun, "file not readable: %s\n", filename); |
594 | goto out; | 618 | goto out; |
@@ -646,8 +670,10 @@ static void fsg_lun_close(struct fsg_lun *curlun) | |||
646 | 670 | ||
647 | /*-------------------------------------------------------------------------*/ | 671 | /*-------------------------------------------------------------------------*/ |
648 | 672 | ||
649 | /* Sync the file data, don't bother with the metadata. | 673 | /* |
650 | * This code was copied from fs/buffer.c:sys_fdatasync(). */ | 674 | * Sync the file data, don't bother with the metadata. |
675 | * This code was copied from fs/buffer.c:sys_fdatasync(). | ||
676 | */ | ||
651 | static int fsg_lun_fsync_sub(struct fsg_lun *curlun) | 677 | static int fsg_lun_fsync_sub(struct fsg_lun *curlun) |
652 | { | 678 | { |
653 | struct file *filp = curlun->filp; | 679 | struct file *filp = curlun->filp; |
@@ -689,6 +715,14 @@ static ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr, | |||
689 | : curlun->initially_ro); | 715 | : curlun->initially_ro); |
690 | } | 716 | } |
691 | 717 | ||
718 | static ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr, | ||
719 | char *buf) | ||
720 | { | ||
721 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
722 | |||
723 | return sprintf(buf, "%u\n", curlun->nofua); | ||
724 | } | ||
725 | |||
692 | static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr, | 726 | static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr, |
693 | char *buf) | 727 | char *buf) |
694 | { | 728 | { |
@@ -723,26 +757,47 @@ static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr, | |||
723 | ssize_t rc = count; | 757 | ssize_t rc = count; |
724 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | 758 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); |
725 | struct rw_semaphore *filesem = dev_get_drvdata(dev); | 759 | struct rw_semaphore *filesem = dev_get_drvdata(dev); |
726 | int i; | 760 | unsigned long ro; |
727 | 761 | ||
728 | if (sscanf(buf, "%d", &i) != 1) | 762 | if (strict_strtoul(buf, 2, &ro)) |
729 | return -EINVAL; | 763 | return -EINVAL; |
730 | 764 | ||
731 | /* Allow the write-enable status to change only while the backing file | 765 | /* |
732 | * is closed. */ | 766 | * Allow the write-enable status to change only while the |
767 | * backing file is closed. | ||
768 | */ | ||
733 | down_read(filesem); | 769 | down_read(filesem); |
734 | if (fsg_lun_is_open(curlun)) { | 770 | if (fsg_lun_is_open(curlun)) { |
735 | LDBG(curlun, "read-only status change prevented\n"); | 771 | LDBG(curlun, "read-only status change prevented\n"); |
736 | rc = -EBUSY; | 772 | rc = -EBUSY; |
737 | } else { | 773 | } else { |
738 | curlun->ro = !!i; | 774 | curlun->ro = ro; |
739 | curlun->initially_ro = !!i; | 775 | curlun->initially_ro = ro; |
740 | LDBG(curlun, "read-only status set to %d\n", curlun->ro); | 776 | LDBG(curlun, "read-only status set to %d\n", curlun->ro); |
741 | } | 777 | } |
742 | up_read(filesem); | 778 | up_read(filesem); |
743 | return rc; | 779 | return rc; |
744 | } | 780 | } |
745 | 781 | ||
782 | static ssize_t fsg_store_nofua(struct device *dev, | ||
783 | struct device_attribute *attr, | ||
784 | const char *buf, size_t count) | ||
785 | { | ||
786 | struct fsg_lun *curlun = fsg_lun_from_dev(dev); | ||
787 | unsigned long nofua; | ||
788 | |||
789 | if (strict_strtoul(buf, 2, &nofua)) | ||
790 | return -EINVAL; | ||
791 | |||
792 | /* Sync data when switching from async mode to sync */ | ||
793 | if (!nofua && curlun->nofua) | ||
794 | fsg_lun_fsync_sub(curlun); | ||
795 | |||
796 | curlun->nofua = nofua; | ||
797 | |||
798 | return count; | ||
799 | } | ||
800 | |||
746 | static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr, | 801 | static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr, |
747 | const char *buf, size_t count) | 802 | const char *buf, size_t count) |
748 | { | 803 | { |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index 1da755a1c855..6bb876d65252 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -704,17 +704,6 @@ static char *host_addr; | |||
704 | module_param(host_addr, charp, S_IRUGO); | 704 | module_param(host_addr, charp, S_IRUGO); |
705 | MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); | 705 | MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); |
706 | 706 | ||
707 | |||
708 | static u8 __init nibble(unsigned char c) | ||
709 | { | ||
710 | if (isdigit(c)) | ||
711 | return c - '0'; | ||
712 | c = toupper(c); | ||
713 | if (isxdigit(c)) | ||
714 | return 10 + c - 'A'; | ||
715 | return 0; | ||
716 | } | ||
717 | |||
718 | static int get_ether_addr(const char *str, u8 *dev_addr) | 707 | static int get_ether_addr(const char *str, u8 *dev_addr) |
719 | { | 708 | { |
720 | if (str) { | 709 | if (str) { |
@@ -725,8 +714,8 @@ static int get_ether_addr(const char *str, u8 *dev_addr) | |||
725 | 714 | ||
726 | if ((*str == '.') || (*str == ':')) | 715 | if ((*str == '.') || (*str == ':')) |
727 | str++; | 716 | str++; |
728 | num = nibble(*str++) << 4; | 717 | num = hex_to_bin(*str++) << 4; |
729 | num |= (nibble(*str++)); | 718 | num |= hex_to_bin(*str++); |
730 | dev_addr [i] = num; | 719 | dev_addr [i] = num; |
731 | } | 720 | } |
732 | if (is_valid_ether_addr(dev_addr)) | 721 | if (is_valid_ether_addr(dev_addr)) |
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index 3e8dcb5455e3..01e5354a4c20 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -18,6 +18,7 @@ | |||
18 | /* #define VERBOSE_DEBUG */ | 18 | /* #define VERBOSE_DEBUG */ |
19 | 19 | ||
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/sched.h> | ||
21 | #include <linux/interrupt.h> | 22 | #include <linux/interrupt.h> |
22 | #include <linux/device.h> | 23 | #include <linux/device.h> |
23 | #include <linux/delay.h> | 24 | #include <linux/delay.h> |
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c index 288d21155abe..de1deb7a3c63 100644 --- a/drivers/usb/gadget/webcam.c +++ b/drivers/usb/gadget/webcam.c | |||
@@ -308,7 +308,7 @@ static const struct uvc_descriptor_header * const uvc_hs_streaming_cls[] = { | |||
308 | * USB configuration | 308 | * USB configuration |
309 | */ | 309 | */ |
310 | 310 | ||
311 | static int __init | 311 | static int __ref |
312 | webcam_config_bind(struct usb_configuration *c) | 312 | webcam_config_bind(struct usb_configuration *c) |
313 | { | 313 | { |
314 | return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls, | 314 | return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls, |
@@ -330,7 +330,7 @@ webcam_unbind(struct usb_composite_dev *cdev) | |||
330 | return 0; | 330 | return 0; |
331 | } | 331 | } |
332 | 332 | ||
333 | static int __init | 333 | static int __ref |
334 | webcam_bind(struct usb_composite_dev *cdev) | 334 | webcam_bind(struct usb_composite_dev *cdev) |
335 | { | 335 | { |
336 | int ret; | 336 | int ret; |
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index 807280d069f9..cf353920bb1c 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c | |||
@@ -264,7 +264,7 @@ static void zero_resume(struct usb_composite_dev *cdev) | |||
264 | 264 | ||
265 | /*-------------------------------------------------------------------------*/ | 265 | /*-------------------------------------------------------------------------*/ |
266 | 266 | ||
267 | static int __init zero_bind(struct usb_composite_dev *cdev) | 267 | static int __ref zero_bind(struct usb_composite_dev *cdev) |
268 | { | 268 | { |
269 | int gcnum; | 269 | int gcnum; |
270 | struct usb_gadget *gadget = cdev->gadget; | 270 | struct usb_gadget *gadget = cdev->gadget; |