This patch adds some ifdefs to make the file-storage gadget work as a usb_function module.
Signed-off-by: Felipe Balbi <[EMAIL PROTECTED]> Signed-off-by: Ragner Magalhes <[EMAIL PROTECTED]> --- Index: linux-2.6/drivers/usb/gadget/file_storage.c =================================================================== --- linux-2.6.orig/drivers/usb/gadget/file_storage.c +++ linux-2.6/drivers/usb/gadget/file_storage.c @@ -257,2 +257,3 @@ #include <linux/usb_gadget.h> +#include <linux/usb/composite.h> @@ -586,2 +587,3 @@ static inline struct lun *dev_to_lun(str +#ifndef USB_COMPOSITE_DEVICE /* Big enough to hold our biggest descriptor */ @@ -589,2 +591,5 @@ static inline struct lun *dev_to_lun(str #define DELAYED_STATUS (EP0_BUFSIZE + 999) // An impossibly large value +#else +#define DELAYED_STATUS (COMPOSITE_BUFSIZ + 999) +#endif /* !USB_COMPOSITE_DEVICE */ @@ -734,3 +739,7 @@ static void inline set_bulk_out_req_leng static struct fsg_dev *the_fsg; +#ifdef USB_COMPOSITE_DEVICE +static struct usb_function fsg_usb_function; +#else static struct usb_gadget_driver fsg_driver; +#endif @@ -846,2 +855,5 @@ static void inline put_be32(u8 *buf, u32 */ +#ifdef USB_COMPOSITE_DEVICE +#define STRING_INTERFACE 1 +#else #define STRING_MANUFACTURER 1 @@ -851,2 +863,3 @@ static void inline put_be32(u8 *buf, u32 #define STRING_INTERFACE 5 +#endif /* USB_COMPOSITE_DEVICE */ @@ -855,2 +868,3 @@ static void inline put_be32(u8 *buf, u32 +#ifndef USB_COMPOSITE_DEVICE static struct usb_device_descriptor @@ -886,2 +900,3 @@ config_desc = { }; +#endif /* !USB_COMPOSITE_DEVICE */ @@ -943,3 +958,3 @@ fs_intr_in_desc = { -static const struct usb_descriptor_header *fs_function[] = { +static struct usb_descriptor_header *fs_function[] = { (struct usb_descriptor_header *) &otg_desc, @@ -964,2 +979,3 @@ static const struct usb_descriptor_heade */ +#ifndef USB_COMPOSITE_DEVICE static struct usb_qualifier_descriptor @@ -974,2 +990,3 @@ dev_qualifier = { }; +#endif /* !USB_COMPOSITE_DEVICE */ @@ -1035,2 +1052,5 @@ static char serial[13]; static struct usb_string strings[] = { +#ifdef USB_COMPOSITE_DEVICE + {STRING_INTERFACE, "Mass Storage"}, +#else {STRING_MANUFACTURER, manufacturer}, @@ -1040,2 +1060,3 @@ static struct usb_string strings[] = { {STRING_INTERFACE, "Mass Storage"}, +#endif /* USB_COMPOSITE_DEVICE */ {} @@ -1049,2 +1070,3 @@ static struct usb_gadget_strings stringt +#ifndef USB_COMPOSITE_DEVICE /* @@ -1061,3 +1083,3 @@ static int populate_config_buf(struct us int len; - const struct usb_descriptor_header **function; + struct usb_descriptor_header **function; @@ -1084,2 +1106,3 @@ static int populate_config_buf(struct us +#endif /* !USB_COMPOSITE_DEVICE */ @@ -1127,3 +1150,8 @@ static void fsg_disconnect(struct usb_ga { +#ifdef USB_COMPOSITE_DEVICE + struct usb_composite_dev *cdev = get_gadget_data(gadget); + struct fsg_dev *fsg = get_composite_data(cdev); +#else struct fsg_dev *fsg = get_gadget_data(gadget); +#endif @@ -1148,2 +1176,3 @@ static int ep0_queue(struct fsg_dev *fsg +#ifndef USB_COMPOSITE_DEVICE static void ep0_complete(struct usb_ep *ep, struct usb_request *req) @@ -1163,2 +1192,3 @@ static void ep0_complete(struct usb_ep * } +#endif /* !USB_COMPOSITE_DEVICE */ @@ -1292,5 +1322,11 @@ static void received_cbi_adsc(struct fsg -static int class_setup_req(struct fsg_dev *fsg, +static int class_setup_req(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) { +#ifdef USB_COMPOSITE_DEVICE + struct usb_composite_dev *cdev = get_gadget_data(gadget); + struct fsg_dev *fsg = get_composite_data(cdev); +#else + struct fsg_dev *fsg = get_gadget_data(gadget); +#endif struct usb_request *req = fsg->ep0req; @@ -1303,2 +1339,6 @@ static int class_setup_req(struct fsg_de +#ifdef USB_COMPOSITE_DEVICE + w_index -= cdev->current_func->interface_shift; +#endif /* USB_COMPOSITE_DEVICE */ + /* Handle Bulk-only class-specific requests */ @@ -1374,5 +1414,11 @@ static int class_setup_req(struct fsg_de -static int standard_setup_req(struct fsg_dev *fsg, +static int standard_setup_req(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) { +#ifdef USB_COMPOSITE_DEVICE + struct usb_composite_dev *cdev = get_gadget_data(gadget); + struct fsg_dev *fsg = get_composite_data(cdev); +#else + struct fsg_dev *fsg = get_gadget_data(gadget); +#endif struct usb_request *req = fsg->ep0req; @@ -1386,2 +1432,3 @@ static int standard_setup_req(struct fsg +#ifndef USB_COMPOSITE_DEVICE case USB_REQ_GET_DESCRIPTOR: @@ -1432,2 +1479,3 @@ static int standard_setup_req(struct fsg break; +#endif /* !USB_COMPOSITE_DEVICE */ @@ -1439,2 +1487,6 @@ static int standard_setup_req(struct fsg VDBG(fsg, "set configuration\n"); +#ifdef USB_COMPOSITE_DEVICE + if (w_value == COMPOSITE_CONFIG_VALUE) + w_value = CONFIG_VALUE; +#endif /* USB_COMPOSITE_DEVICE */ if (w_value == CONFIG_VALUE || w_value == 0) { @@ -1448,2 +1500,3 @@ static int standard_setup_req(struct fsg break; +#ifndef USB_COMPOSITE_DEVICE case USB_REQ_GET_CONFIGURATION: @@ -1456,4 +1509,8 @@ static int standard_setup_req(struct fsg break; +#endif /* !USB_COMPOSITE_DEVICE */ case USB_REQ_SET_INTERFACE: +#ifdef USB_COMPOSITE_DEVICE + w_index -= cdev->current_func->interface_shift; +#endif /* USB_COMPOSITE_DEVICE */ if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD | @@ -1471,2 +1528,5 @@ static int standard_setup_req(struct fsg case USB_REQ_GET_INTERFACE: +#ifdef USB_COMPOSITE_DEVICE + w_index -= cdev->current_func->interface_shift; +#endif /* USB_COMPOSITE_DEVICE */ if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD | @@ -1499,5 +1559,10 @@ static int fsg_setup(struct usb_gadget * { +#ifdef USB_COMPOSITE_DEVICE + struct usb_composite_dev *cdev = get_gadget_data(gadget); + struct fsg_dev *fsg = get_composite_data(cdev); +#else struct fsg_dev *fsg = get_gadget_data(gadget); - int rc; int w_length = le16_to_cpu(ctrl->wLength); +#endif + int rc; @@ -1509,6 +1574,7 @@ static int fsg_setup(struct usb_gadget * if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS) - rc = class_setup_req(fsg, ctrl); + rc = class_setup_req(gadget, ctrl); else - rc = standard_setup_req(fsg, ctrl); + rc = standard_setup_req(gadget, ctrl); +#ifndef USB_COMPOSITE_DEVICE /* Respond with data/status or defer until later? */ @@ -1522,2 +1588,3 @@ static int fsg_setup(struct usb_gadget * } +#endif @@ -3401,2 +3468,3 @@ static void handle_exception(struct fsg_ rc = do_set_config(fsg, new_config); +#ifndef USB_COMPOSITE_DEVICE if (fsg->ep0_req_tag != exception_req_tag) @@ -3407,2 +3475,3 @@ static void handle_exception(struct fsg_ ep0_queue(fsg); +#endif /* !USB_COMPOSITE_DEVICE */ break; @@ -3487,3 +3556,8 @@ static int fsg_main_thread(void *fsg_) if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags)) { + /* Wait for the thread to finish up */ +#ifdef USB_COMPOSITE_DEVICE + usb_function_unregister(&fsg_usb_function); +#else usb_gadget_unregister_driver(&fsg_driver); +#endif close_all_backing_files(fsg); @@ -3706,5 +3780,11 @@ static void lun_release(struct device *d + static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget) { +#ifdef USB_COMPOSITE_DEVICE + struct usb_composite_dev *cdev = get_gadget_data(gadget); + struct fsg_dev *fsg = get_composite_data(cdev); +#else struct fsg_dev *fsg = get_gadget_data(gadget); +#endif int i; @@ -3745,2 +3825,12 @@ static void /* __init_or_exit */ fsg_unb +#ifdef USB_COMPOSITE_DEVICE + raise_exception(fsg, FSG_STATE_RESET); + req = NULL; + set_composite_data(cdev, NULL); + + usb_composite_ep_reset(fsg->bulk_in); + usb_composite_ep_reset(fsg->bulk_out); + usb_composite_ep_reset(fsg->intr_in); + +#else /* Free the request and buffer for endpoint 0 */ @@ -3754,2 +3844,3 @@ static void /* __init_or_exit */ fsg_unb set_gadget_data(gadget, NULL); +#endif } @@ -3842,4 +3933,7 @@ static int __init check_parameters(struc -static int __init fsg_bind(struct usb_gadget *gadget) +static int __devinit fsg_bind(struct usb_gadget *gadget) { +#ifdef USB_COMPOSITE_DEVICE + struct usb_composite_dev *cdev = get_gadget_data(gadget); +#endif struct fsg_dev *fsg = the_fsg; @@ -3853,5 +3947,11 @@ static int __init fsg_bind(struct usb_ga fsg->gadget = gadget; +#ifdef USB_COMPOSITE_DEVICE + set_composite_data(cdev, fsg); +#else set_gadget_data(gadget, fsg); +#endif fsg->ep0 = gadget->ep0; +#ifndef USB_COMPOSITE_DEVICE fsg->ep0->driver_data = fsg; +#endif @@ -3890,3 +3990,7 @@ static int __init fsg_bind(struct usb_ga curlun->dev.parent = &gadget->dev; +#ifdef USB_COMPOSITE_DEVICE + curlun->dev.driver = cdev->gadget->dev.driver; +#else curlun->dev.driver = &fsg_driver.driver; +#endif dev_set_drvdata(&curlun->dev, fsg); @@ -3921,3 +4025,5 @@ static int __init fsg_bind(struct usb_ga /* Find all the endpoints we will use */ +#ifndef USB_COMPOSITE_DEVICE usb_ep_autoconfig_reset(gadget); +#endif ep = usb_ep_autoconfig(gadget, &fs_bulk_in_desc); @@ -3943,2 +4049,3 @@ static int __init fsg_bind(struct usb_ga /* Fix up the descriptors */ +#ifndef USB_COMPOSITE_DEVICE device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket; @@ -3947,2 +4054,3 @@ static int __init fsg_bind(struct usb_ga device_desc.bcdDevice = cpu_to_le16(mod_data.release); +#endif @@ -3958,3 +4066,5 @@ static int __init fsg_bind(struct usb_ga /* Assume ep0 uses the same maxpacket value for both speeds */ +#ifndef USB_COMPOSITE_DEVICE dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket; +#endif @@ -3967,4 +4077,8 @@ static int __init fsg_bind(struct usb_ga if (gadget->is_otg) { +#ifdef USB_COMPOSITE_DEVICE + otg_desc.bmAttributes |= USB_OTG_HNP; +#else otg_desc.bmAttributes |= USB_OTG_HNP, config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP; +#endif } @@ -3973,2 +4087,6 @@ static int __init fsg_bind(struct usb_ga +#ifdef USB_COMPOSITE_DEVICE + fsg->ep0req = req = cdev->req; + req->buf = cdev->req->buf; +#else /* Allocate the request and buffer for endpoint 0 */ @@ -3983,2 +4101,3 @@ static int __init fsg_bind(struct usb_ga +#endif /* Allocate the data buffers */ @@ -4076,3 +4195,8 @@ static void fsg_suspend(struct usb_gadge { +#ifdef USB_COMPOSITE_DEVICE + struct usb_composite_dev *cdev = get_gadget_data(gadget); + struct fsg_dev *fsg = get_composite_data(cdev); +#else struct fsg_dev *fsg = get_gadget_data(gadget); +#endif @@ -4084,3 +4208,8 @@ static void fsg_resume(struct usb_gadget { +#ifdef USB_COMPOSITE_DEVICE + struct usb_composite_dev *cdev = get_gadget_data(gadget); + struct fsg_dev *fsg = get_composite_data(cdev); +#else struct fsg_dev *fsg = get_gadget_data(gadget); +#endif @@ -4093,2 +4222,18 @@ static void fsg_resume(struct usb_gadget +#ifdef USB_COMPOSITE_DEVICE +static struct usb_function fsg_usb_function = { + .name = DRIVER_DESC, + .strings = &stringtab, + .descriptors = fs_function, +#ifdef CONFIG_USB_GADGET_DUALSPEED + .hs_descriptors = fs_function, +#endif + .bind = fsg_bind, + .unbind = fsg_unbind, + .setup = fsg_setup, + .disconnect = fsg_disconnect, + .suspend = fsg_suspend, + .resume = fsg_resume, +}; +#else /* not def composite */ static struct usb_gadget_driver fsg_driver = { @@ -4116,2 +4261,3 @@ static struct usb_gadget_driver fsg_dri +#endif /* USB_COMPOSITE_DEVICE */ @@ -4142,3 +4288,8 @@ static int __init fsg_init(void) fsg = the_fsg; + +#ifdef USB_COMPOSITE_DEVICE + if ((rc = usb_function_register(&fsg_usb_function)) != 0) +#else if ((rc = usb_gadget_register_driver(&fsg_driver)) != 0) +#endif kref_put(&fsg->ref, fsg_release); @@ -4155,4 +4306,8 @@ static void __exit fsg_cleanup(void) if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags)) +#ifdef USB_COMPOSITE_DEVICE + usb_function_unregister(&fsg_usb_function); +#else usb_gadget_unregister_driver(&fsg_driver); +#endif /* Wait for the thread to finish up */ -- Best Regards, Felipe Balbi [EMAIL PROTECTED] Nokia Institute of Technology - INdT Kernel Developers Team +55 92 2126 1003 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel