Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'usb-for-v3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

Felipe writes:

usb: patches for v3.13

Final conversions to configfs for mass storage, acm_ms, and
multi gadgets.

MUSB should now work out of the box on AM335x-based boards
(beagle bone white and black) with DMA thanks to Sebastian's
work.

We can now enable VERBOSE_DEBUG on builds of drivers/usb/gadget/
by selecting CONFIG_USB_GADGET_VERBOSE.

s3c-hsotg got quite a few non-critical fixes but also learned
a few new tricks (isochronous transfers, multi count support).

The Marvel USB3 Controller driver got a memory leak fix.

devm_usb_get_phy() learned not to return NULL, ever.

Other than these patches, we have the usual set of cleanups
ranging from removal of unnecessary *_set_drvdata() to using
SIMPLE_DEV_PM_OPS.

Signed-of-by: Felipe Balbi <balbi@ti.com>

+2965 -1196
+31
Documentation/ABI/testing/configfs-usb-gadget-mass-storage
··· 1 + What: /config/usb-gadget/gadget/functions/mass_storage.name 2 + Date: Oct 2013 3 + KenelVersion: 3.13 4 + Description: 5 + The attributes: 6 + 7 + stall - Set to permit function to halt bulk endpoints. 8 + Disabled on some USB devices known not to work 9 + correctly. You should set it to true. 10 + num_buffers - Number of pipeline buffers. Valid numbers 11 + are 2..4. Available only if 12 + CONFIG_USB_GADGET_DEBUG_FILES is set. 13 + 14 + What: /config/usb-gadget/gadget/functions/mass_storage.name/lun.name 15 + Date: Oct 2013 16 + KenelVersion: 3.13 17 + Description: 18 + The attributes: 19 + 20 + file - The path to the backing file for the LUN. 21 + Required if LUN is not marked as removable. 22 + ro - Flag specifying access to the LUN shall be 23 + read-only. This is implied if CD-ROM emulation 24 + is enabled as well as when it was impossible 25 + to open "filename" in R/W mode. 26 + removable - Flag specifying that LUN shall be indicated as 27 + being removable. 28 + cdrom - Flag specifying that LUN shall be reported as 29 + being a CD-ROM. 30 + nofua - Flag specifying that FUA flag 31 + in SCSI WRITE(10,12)
+3 -4
Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt
··· 15 15 16 16 - vcc-supply: phandle to the regulator that provides RESET to the PHY. 17 17 18 - - reset-supply: phandle to the regulator that provides power to the PHY. 18 + - reset-gpios: Should specify the GPIO for reset. 19 19 20 20 Example: 21 21 ··· 25 25 clocks = <&osc 0>; 26 26 clock-names = "main_clk"; 27 27 vcc-supply = <&hsusb1_vcc_regulator>; 28 - reset-supply = <&hsusb1_reset_regulator>; 28 + reset-gpios = <&gpio1 7 GPIO_ACTIVE_LOW>; 29 29 }; 30 30 31 31 hsusb1_phy is a NOP USB PHY device that gets its clock from an oscillator 32 32 and expects that clock to be configured to 19.2MHz by the NOP PHY driver. 33 - hsusb1_vcc_regulator provides power to the PHY and hsusb1_reset_regulator 34 - controls RESET. 33 + hsusb1_vcc_regulator provides power to the PHY and GPIO 7 controls RESET.
-6
arch/arm/mach-omap2/board-omap3beagle.c
··· 289 289 290 290 static struct gpio_led gpio_leds[]; 291 291 292 - /* PHY's VCC regulator might be added later, so flag that we need it */ 293 - static struct usb_phy_gen_xceiv_platform_data hsusb2_phy_data = { 294 - .needs_vcc = true, 295 - }; 296 - 297 292 static struct usbhs_phy_data phy_data[] = { 298 293 { 299 294 .port = 2, 300 295 .reset_gpio = 147, 301 296 .vcc_gpio = -1, /* updated in beagle_twl_gpio_setup */ 302 297 .vcc_polarity = 1, /* updated in beagle_twl_gpio_setup */ 303 - .platform_data = &hsusb2_phy_data, 304 298 }, 305 299 }; 306 300
+9 -9
arch/arm/mach-omap2/usb-host.c
··· 435 435 struct platform_device *pdev; 436 436 char *phy_id; 437 437 struct platform_device_info pdevinfo; 438 + struct usb_phy_gen_xceiv_platform_data nop_pdata; 438 439 439 440 for (i = 0; i < num_phys; i++) { 440 441 ··· 456 455 return -ENOMEM; 457 456 } 458 457 458 + /* set platform data */ 459 + memset(&nop_pdata, 0, sizeof(nop_pdata)); 460 + if (gpio_is_valid(phy->vcc_gpio)) 461 + nop_pdata.needs_vcc = true; 462 + nop_pdata.gpio_reset = phy->reset_gpio; 463 + nop_pdata.type = USB_PHY_TYPE_USB2; 464 + 459 465 /* create a NOP PHY device */ 460 466 memset(&pdevinfo, 0, sizeof(pdevinfo)); 461 467 pdevinfo.name = nop_name; 462 468 pdevinfo.id = phy->port; 463 - pdevinfo.data = phy->platform_data; 469 + pdevinfo.data = &nop_pdata; 464 470 pdevinfo.size_data = 465 471 sizeof(struct usb_phy_gen_xceiv_platform_data); 466 472 scnprintf(phy_id, MAX_STR, "usb_phy_gen_xceiv.%d", ··· 481 473 } 482 474 483 475 usb_bind_phy("ehci-omap.0", phy->port - 1, phy_id); 484 - 485 - /* Do we need RESET regulator ? */ 486 - if (gpio_is_valid(phy->reset_gpio)) { 487 - scnprintf(rail_name, MAX_STR, 488 - "hsusb%d_reset", phy->port); 489 - usbhs_add_regulator(rail_name, phy_id, "reset", 490 - phy->reset_gpio, 1); 491 - } 492 476 493 477 /* Do we need VCC regulator ? */ 494 478 if (gpio_is_valid(phy->vcc_gpio)) {
-1
arch/arm/mach-omap2/usb.h
··· 58 58 int reset_gpio; 59 59 int vcc_gpio; 60 60 bool vcc_polarity; /* 1 active high, 0 active low */ 61 - void *platform_data; 62 61 }; 63 62 64 63 extern void usb_musb_init(struct omap_musb_board_data *board_data);
+2
drivers/phy/phy-twl4030-usb.c
··· 724 724 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 725 725 dev_warn(&pdev->dev, "could not create sysfs file\n"); 726 726 727 + ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier); 728 + 727 729 /* Our job is to use irqs and status from the power module 728 730 * to keep the transceiver disabled when nothing's connected. 729 731 *
+1 -2
drivers/usb/dwc3/core.c
··· 584 584 usb_phy_set_suspend(dwc->usb2_phy, 1); 585 585 usb_phy_set_suspend(dwc->usb3_phy, 1); 586 586 587 - pm_runtime_put(&pdev->dev); 587 + pm_runtime_put_sync(&pdev->dev); 588 588 pm_runtime_disable(&pdev->dev); 589 589 590 590 dwc3_debugfs_exit(dwc); ··· 691 691 692 692 usb_phy_init(dwc->usb3_phy); 693 693 usb_phy_init(dwc->usb2_phy); 694 - msleep(100); 695 694 696 695 spin_lock_irqsave(&dwc->lock, flags); 697 696
+33 -1
drivers/usb/gadget/Kconfig
··· 58 58 trying to track down. Never enable these messages for a 59 59 production build. 60 60 61 + config USB_GADGET_VERBOSE 62 + bool "Verbose debugging Messages (DEVELOPMENT)" 63 + depends on USB_GADGET_DEBUG 64 + help 65 + Many controller and gadget drivers will print verbose debugging 66 + messages if you use this option to ask for those messages. 67 + 68 + Avoid enabling these messages, even if you're actively 69 + debugging such a driver. Many drivers will emit so many 70 + messages that the driver timings are affected, which will 71 + either create new failure modes or remove the one you're 72 + trying to track down. Never enable these messages for a 73 + production build. 74 + 61 75 config USB_GADGET_DEBUG_FILES 62 76 boolean "Debugging information files (DEVELOPMENT)" 63 77 depends on PROC_FS ··· 539 525 config USB_F_RNDIS 540 526 tristate 541 527 528 + config USB_F_MASS_STORAGE 529 + tristate 530 + 542 531 choice 543 532 tristate "USB Gadget Drivers" 544 533 default USB_ETH ··· 678 661 select USB_F_PHONET 679 662 help 680 663 The Phonet protocol implementation for USB device. 664 + 665 + config USB_CONFIGFS_MASS_STORAGE 666 + boolean "Mass storage" 667 + depends on USB_CONFIGFS 668 + select USB_F_MASS_STORAGE 669 + help 670 + The Mass Storage Gadget acts as a USB Mass Storage disk drive. 671 + As its storage repository it can use a regular file or a block 672 + device (in much the same way as the "loop" device driver), 673 + specified as a module parameter or sysfs option. 681 674 682 675 config USB_ZERO 683 676 tristate "Gadget Zero (DEVELOPMENT)" ··· 905 878 tristate "Mass Storage Gadget" 906 879 depends on BLOCK 907 880 select USB_LIBCOMPOSITE 881 + select USB_F_MASS_STORAGE 908 882 help 909 883 The Mass Storage Gadget acts as a USB Mass Storage disk drive. 910 884 As its storage repository it can use a regular file or a block ··· 1029 1001 select USB_LIBCOMPOSITE 1030 1002 select USB_U_SERIAL 1031 1003 select USB_F_ACM 1004 + select USB_F_MASS_STORAGE 1032 1005 help 1033 1006 This driver provides two functions in one configuration: 1034 1007 a mass storage, and a CDC ACM (serial port) link. ··· 1044 1015 select USB_LIBCOMPOSITE 1045 1016 select USB_U_SERIAL 1046 1017 select USB_U_ETHER 1047 - select USB_U_RNDIS 1048 1018 select USB_F_ACM 1019 + select USB_F_MASS_STORAGE 1049 1020 help 1050 1021 The Multifunction Composite Gadget provides Ethernet (RNDIS 1051 1022 and/or CDC Ethernet), mass storage and ACM serial link ··· 1064 1035 config USB_G_MULTI_RNDIS 1065 1036 bool "RNDIS + CDC Serial + Storage configuration" 1066 1037 depends on USB_G_MULTI 1038 + select USB_U_RNDIS 1039 + select USB_F_RNDIS 1067 1040 default y 1068 1041 help 1069 1042 This option enables a configuration with RNDIS, CDC Serial and ··· 1079 1048 bool "CDC Ethernet + CDC Serial + Storage configuration" 1080 1049 depends on USB_G_MULTI 1081 1050 default n 1051 + select USB_F_ECM 1082 1052 help 1083 1053 This option enables a configuration with CDC Ethernet (ECM), CDC 1084 1054 Serial and Mass Storage functions available in the Multifunction
+4 -1
drivers/usb/gadget/Makefile
··· 1 1 # 2 2 # USB peripheral controller drivers 3 3 # 4 - ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG 4 + ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG 5 + ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG 5 6 6 7 obj-$(CONFIG_USB_GADGET) += udc-core.o 7 8 obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o ··· 61 60 obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o 62 61 usb_f_rndis-y := f_rndis.o 63 62 obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o 63 + usb_f_mass_storage-y := f_mass_storage.o storage_common.o 64 + obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o 64 65 65 66 # 66 67 # USB gadget drivers
+88 -37
drivers/usb/gadget/acm_ms.c
··· 31 31 #define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */ 32 32 #define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/ 33 33 34 - /*-------------------------------------------------------------------------*/ 35 - 36 - /* 37 - * Kbuild is not very cooperative with respect to linking separately 38 - * compiled library objects into one module. So for now we won't use 39 - * separate compilation ... ensuring init/exit sections work to shrink 40 - * the runtime footprint, and giving us at least some parts of what 41 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 42 - */ 43 - #include "f_mass_storage.c" 34 + #include "f_mass_storage.h" 44 35 45 36 /*-------------------------------------------------------------------------*/ 46 37 USB_GADGET_COMPOSITE_OPTIONS(); ··· 95 104 /****************************** Configurations ******************************/ 96 105 97 106 static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; 98 - FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); 107 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 99 108 100 - static struct fsg_common fsg_common; 109 + static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; 110 + 111 + #else 112 + 113 + /* 114 + * Number of buffers we will use. 115 + * 2 is usually enough for good buffering pipeline 116 + */ 117 + #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS 118 + 119 + #endif /* CONFIG_USB_DEBUG */ 120 + 121 + FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); 101 122 102 123 /*-------------------------------------------------------------------------*/ 103 124 static struct usb_function *f_acm; 104 125 static struct usb_function_instance *f_acm_inst; 126 + 127 + static struct usb_function_instance *fi_msg; 128 + static struct usb_function *f_msg; 129 + 105 130 /* 106 131 * We _always_ have both ACM and mass storage functions. 107 132 */ 108 133 static int __init acm_ms_do_config(struct usb_configuration *c) 109 134 { 135 + struct fsg_opts *opts; 110 136 int status; 111 137 112 138 if (gadget_is_otg(c->cdev->gadget)) { ··· 131 123 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 132 124 } 133 125 134 - f_acm_inst = usb_get_function_instance("acm"); 135 - if (IS_ERR(f_acm_inst)) 136 - return PTR_ERR(f_acm_inst); 126 + opts = fsg_opts_from_func_inst(fi_msg); 137 127 138 128 f_acm = usb_get_function(f_acm_inst); 139 - if (IS_ERR(f_acm)) { 140 - status = PTR_ERR(f_acm); 141 - goto err_func; 129 + if (IS_ERR(f_acm)) 130 + return PTR_ERR(f_acm); 131 + 132 + f_msg = usb_get_function(fi_msg); 133 + if (IS_ERR(f_msg)) { 134 + status = PTR_ERR(f_msg); 135 + goto put_acm; 142 136 } 143 137 144 138 status = usb_add_function(c, f_acm); 145 139 if (status < 0) 146 - goto err_conf; 140 + goto put_msg; 147 141 148 - status = fsg_bind_config(c->cdev, c, &fsg_common); 149 - if (status < 0) 150 - goto err_fsg; 142 + status = fsg_common_run_thread(opts->common); 143 + if (status) 144 + goto remove_acm; 145 + 146 + status = usb_add_function(c, f_msg); 147 + if (status) 148 + goto remove_acm; 151 149 152 150 return 0; 153 - err_fsg: 151 + remove_acm: 154 152 usb_remove_function(c, f_acm); 155 - err_conf: 153 + put_msg: 154 + usb_put_function(f_msg); 155 + put_acm: 156 156 usb_put_function(f_acm); 157 - err_func: 158 - usb_put_function_instance(f_acm_inst); 159 157 return status; 160 158 } 161 159 ··· 177 163 static int __init acm_ms_bind(struct usb_composite_dev *cdev) 178 164 { 179 165 struct usb_gadget *gadget = cdev->gadget; 166 + struct fsg_opts *opts; 167 + struct fsg_config config; 180 168 int status; 181 - void *retp; 182 169 183 - /* set up mass storage function */ 184 - retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 185 - if (IS_ERR(retp)) { 186 - status = PTR_ERR(retp); 187 - return PTR_ERR(retp); 170 + f_acm_inst = usb_get_function_instance("acm"); 171 + if (IS_ERR(f_acm_inst)) 172 + return PTR_ERR(f_acm_inst); 173 + 174 + fi_msg = usb_get_function_instance("mass_storage"); 175 + if (IS_ERR(fi_msg)) { 176 + status = PTR_ERR(fi_msg); 177 + goto fail_get_msg; 188 178 } 189 179 180 + /* set up mass storage function */ 181 + fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers); 182 + opts = fsg_opts_from_func_inst(fi_msg); 183 + 184 + opts->no_configfs = true; 185 + status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers); 186 + if (status) 187 + goto fail; 188 + 189 + status = fsg_common_set_nluns(opts->common, config.nluns); 190 + if (status) 191 + goto fail_set_nluns; 192 + 193 + status = fsg_common_set_cdev(opts->common, cdev, config.can_stall); 194 + if (status) 195 + goto fail_set_cdev; 196 + 197 + fsg_common_set_sysfs(opts->common, true); 198 + status = fsg_common_create_luns(opts->common, &config); 199 + if (status) 200 + goto fail_set_cdev; 201 + 202 + fsg_common_set_inquiry_string(opts->common, config.vendor_name, 203 + config.product_name); 190 204 /* 191 205 * Allocate string descriptor numbers ... note that string 192 206 * contents can be overridden by the composite_dev glue. 193 207 */ 194 208 status = usb_string_ids_tab(cdev, strings_dev); 195 209 if (status < 0) 196 - goto fail1; 210 + goto fail_string_ids; 197 211 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; 198 212 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 199 213 200 214 /* register our configuration */ 201 215 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); 202 216 if (status < 0) 203 - goto fail1; 217 + goto fail_string_ids; 204 218 205 219 usb_composite_overwrite_options(cdev, &coverwrite); 206 220 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 207 221 DRIVER_DESC); 208 - fsg_common_put(&fsg_common); 209 222 return 0; 210 223 211 224 /* error recovery */ 212 - fail1: 213 - fsg_common_put(&fsg_common); 225 + fail_string_ids: 226 + fsg_common_remove_luns(opts->common); 227 + fail_set_cdev: 228 + fsg_common_free_luns(opts->common); 229 + fail_set_nluns: 230 + fsg_common_free_buffers(opts->common); 231 + fail: 232 + usb_put_function_instance(fi_msg); 233 + fail_get_msg: 234 + usb_put_function_instance(f_acm_inst); 214 235 return status; 215 236 } 216 237 217 238 static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) 218 239 { 240 + usb_put_function(f_msg); 241 + usb_put_function_instance(fi_msg); 219 242 usb_put_function(f_acm); 220 243 usb_put_function_instance(f_acm_inst); 221 244 return 0;
+9 -1
drivers/usb/gadget/configfs.c
··· 557 557 558 558 fi = usb_get_function_instance(func_name); 559 559 if (IS_ERR(fi)) 560 - return ERR_PTR(PTR_ERR(fi)); 560 + return ERR_CAST(fi); 561 561 562 562 ret = config_item_set_name(&fi->group.cg_item, name); 563 563 if (ret) { ··· 990 990 }, 991 991 .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex), 992 992 }; 993 + 994 + void unregister_gadget_item(struct config_item *item) 995 + { 996 + struct gadget_info *gi = to_gadget_info(item); 997 + 998 + unregister_gadget(gi); 999 + } 1000 + EXPORT_SYMBOL(unregister_gadget_item); 993 1001 994 1002 static int __init gadget_cfs_init(void) 995 1003 {
+6
drivers/usb/gadget/configfs.h
··· 1 + #ifndef USB__GADGET__CONFIGFS__H 2 + #define USB__GADGET__CONFIGFS__H 3 + 4 + void unregister_gadget_item(struct config_item *item); 5 + 6 + #endif /* USB__GADGET__CONFIGFS__H */
+932 -338
drivers/usb/gadget/f_mass_storage.c
··· 213 213 #include <linux/spinlock.h> 214 214 #include <linux/string.h> 215 215 #include <linux/freezer.h> 216 + #include <linux/module.h> 216 217 217 218 #include <linux/usb/ch9.h> 218 219 #include <linux/usb/gadget.h> 219 220 #include <linux/usb/composite.h> 220 221 221 222 #include "gadget_chips.h" 223 + #include "configfs.h" 222 224 223 225 224 226 /*------------------------------------------------------------------------*/ ··· 230 228 231 229 static const char fsg_string_interface[] = "Mass Storage"; 232 230 233 - #include "storage_common.c" 231 + #include "storage_common.h" 232 + #include "f_mass_storage.h" 234 233 234 + /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ 235 + static struct usb_string fsg_strings[] = { 236 + {FSG_STRING_INTERFACE, fsg_string_interface}, 237 + {} 238 + }; 239 + 240 + static struct usb_gadget_strings fsg_stringtab = { 241 + .language = 0x0409, /* en-us */ 242 + .strings = fsg_strings, 243 + }; 244 + 245 + static struct usb_gadget_strings *fsg_strings_array[] = { 246 + &fsg_stringtab, 247 + NULL, 248 + }; 235 249 236 250 /*-------------------------------------------------------------------------*/ 237 251 238 252 struct fsg_dev; 239 253 struct fsg_common; 240 - 241 - /* FSF callback functions */ 242 - struct fsg_operations { 243 - /* 244 - * Callback function to call when thread exits. If no 245 - * callback is set or it returns value lower then zero MSF 246 - * will force eject all LUNs it operates on (including those 247 - * marked as non-removable or with prevent_medium_removal flag 248 - * set). 249 - */ 250 - int (*thread_exits)(struct fsg_common *common); 251 - }; 252 254 253 255 /* Data shared by all the FSG instances. */ 254 256 struct fsg_common { ··· 274 268 struct fsg_buffhd *next_buffhd_to_fill; 275 269 struct fsg_buffhd *next_buffhd_to_drain; 276 270 struct fsg_buffhd *buffhds; 271 + unsigned int fsg_num_buffers; 277 272 278 273 int cmnd_size; 279 274 u8 cmnd[MAX_COMMAND_SIZE]; 280 275 281 276 unsigned int nluns; 282 277 unsigned int lun; 283 - struct fsg_lun *luns; 278 + struct fsg_lun **luns; 284 279 struct fsg_lun *curlun; 285 280 286 281 unsigned int bulk_out_maxpacket; ··· 301 294 unsigned int short_packet_received:1; 302 295 unsigned int bad_lun_okay:1; 303 296 unsigned int running:1; 297 + unsigned int sysfs:1; 304 298 305 299 int thread_wakeup_needed; 306 300 struct completion thread_notifier; ··· 319 311 char inquiry_string[8 + 16 + 4 + 1]; 320 312 321 313 struct kref ref; 322 - }; 323 - 324 - struct fsg_config { 325 - unsigned nluns; 326 - struct fsg_lun_config { 327 - const char *filename; 328 - char ro; 329 - char removable; 330 - char cdrom; 331 - char nofua; 332 - } luns[FSG_MAX_LUNS]; 333 - 334 - /* Callback functions. */ 335 - const struct fsg_operations *ops; 336 - /* Gadget's private data. */ 337 - void *private_data; 338 - 339 - const char *vendor_name; /* 8 characters or less */ 340 - const char *product_name; /* 16 characters or less */ 341 - 342 - char can_stall; 343 314 }; 344 315 345 316 struct fsg_dev { ··· 2159 2172 common->data_dir = DATA_DIR_NONE; 2160 2173 common->lun = cbw->Lun; 2161 2174 if (common->lun < common->nluns) 2162 - common->curlun = &common->luns[common->lun]; 2175 + common->curlun = common->luns[common->lun]; 2163 2176 else 2164 2177 common->curlun = NULL; 2165 2178 common->tag = cbw->Tag; ··· 2231 2244 if (common->fsg) { 2232 2245 fsg = common->fsg; 2233 2246 2234 - for (i = 0; i < fsg_num_buffers; ++i) { 2247 + for (i = 0; i < common->fsg_num_buffers; ++i) { 2235 2248 struct fsg_buffhd *bh = &common->buffhds[i]; 2236 2249 2237 2250 if (bh->inreq) { ··· 2290 2303 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2291 2304 2292 2305 /* Allocate the requests */ 2293 - for (i = 0; i < fsg_num_buffers; ++i) { 2306 + for (i = 0; i < common->fsg_num_buffers; ++i) { 2294 2307 struct fsg_buffhd *bh = &common->buffhds[i]; 2295 2308 2296 2309 rc = alloc_request(common, fsg->bulk_in, &bh->inreq); ··· 2307 2320 2308 2321 common->running = 1; 2309 2322 for (i = 0; i < common->nluns; ++i) 2310 - common->luns[i].unit_attention_data = SS_RESET_OCCURRED; 2323 + if (common->luns[i]) 2324 + common->luns[i]->unit_attention_data = 2325 + SS_RESET_OCCURRED; 2311 2326 return rc; 2312 2327 } 2313 2328 ··· 2361 2372 2362 2373 /* Cancel all the pending transfers */ 2363 2374 if (likely(common->fsg)) { 2364 - for (i = 0; i < fsg_num_buffers; ++i) { 2375 + for (i = 0; i < common->fsg_num_buffers; ++i) { 2365 2376 bh = &common->buffhds[i]; 2366 2377 if (bh->inreq_busy) 2367 2378 usb_ep_dequeue(common->fsg->bulk_in, bh->inreq); ··· 2373 2384 /* Wait until everything is idle */ 2374 2385 for (;;) { 2375 2386 int num_active = 0; 2376 - for (i = 0; i < fsg_num_buffers; ++i) { 2387 + for (i = 0; i < common->fsg_num_buffers; ++i) { 2377 2388 bh = &common->buffhds[i]; 2378 2389 num_active += bh->inreq_busy + bh->outreq_busy; 2379 2390 } ··· 2396 2407 */ 2397 2408 spin_lock_irq(&common->lock); 2398 2409 2399 - for (i = 0; i < fsg_num_buffers; ++i) { 2410 + for (i = 0; i < common->fsg_num_buffers; ++i) { 2400 2411 bh = &common->buffhds[i]; 2401 2412 bh->state = BUF_STATE_EMPTY; 2402 2413 } ··· 2409 2420 common->state = FSG_STATE_STATUS_PHASE; 2410 2421 else { 2411 2422 for (i = 0; i < common->nluns; ++i) { 2412 - curlun = &common->luns[i]; 2423 + curlun = common->luns[i]; 2424 + if (!curlun) 2425 + continue; 2413 2426 curlun->prevent_medium_removal = 0; 2414 2427 curlun->sense_data = SS_NO_SENSE; 2415 2428 curlun->unit_attention_data = SS_NO_SENSE; ··· 2453 2462 * CONFIG_CHANGE cases. 2454 2463 */ 2455 2464 /* for (i = 0; i < common->nluns; ++i) */ 2456 - /* common->luns[i].unit_attention_data = */ 2457 - /* SS_RESET_OCCURRED; */ 2465 + /* if (common->luns[i]) */ 2466 + /* common->luns[i]->unit_attention_data = */ 2467 + /* SS_RESET_OCCURRED; */ 2458 2468 break; 2459 2469 2460 2470 case FSG_STATE_CONFIG_CHANGE: ··· 2551 2559 2552 2560 if (!common->ops || !common->ops->thread_exits 2553 2561 || common->ops->thread_exits(common) < 0) { 2554 - struct fsg_lun *curlun = common->luns; 2562 + struct fsg_lun **curlun_it = common->luns; 2555 2563 unsigned i = common->nluns; 2556 2564 2557 2565 down_write(&common->filesem); 2558 - for (; i--; ++curlun) { 2559 - if (!fsg_lun_is_open(curlun)) 2566 + for (; i--; ++curlun_it) { 2567 + struct fsg_lun *curlun = *curlun_it; 2568 + if (!curlun || !fsg_lun_is_open(curlun)) 2560 2569 continue; 2561 2570 2562 2571 fsg_lun_close(curlun); ··· 2572 2579 2573 2580 2574 2581 /*************************** DEVICE ATTRIBUTES ***************************/ 2582 + 2583 + static ssize_t ro_show(struct device *dev, struct device_attribute *attr, char *buf) 2584 + { 2585 + struct fsg_lun *curlun = fsg_lun_from_dev(dev); 2586 + 2587 + return fsg_show_ro(curlun, buf); 2588 + } 2589 + 2590 + static ssize_t nofua_show(struct device *dev, struct device_attribute *attr, 2591 + char *buf) 2592 + { 2593 + struct fsg_lun *curlun = fsg_lun_from_dev(dev); 2594 + 2595 + return fsg_show_nofua(curlun, buf); 2596 + } 2597 + 2598 + static ssize_t file_show(struct device *dev, struct device_attribute *attr, 2599 + char *buf) 2600 + { 2601 + struct fsg_lun *curlun = fsg_lun_from_dev(dev); 2602 + struct rw_semaphore *filesem = dev_get_drvdata(dev); 2603 + 2604 + return fsg_show_file(curlun, filesem, buf); 2605 + } 2606 + 2607 + static ssize_t ro_store(struct device *dev, struct device_attribute *attr, 2608 + const char *buf, size_t count) 2609 + { 2610 + struct fsg_lun *curlun = fsg_lun_from_dev(dev); 2611 + struct rw_semaphore *filesem = dev_get_drvdata(dev); 2612 + 2613 + return fsg_store_ro(curlun, filesem, buf, count); 2614 + } 2615 + 2616 + static ssize_t nofua_store(struct device *dev, struct device_attribute *attr, 2617 + const char *buf, size_t count) 2618 + { 2619 + struct fsg_lun *curlun = fsg_lun_from_dev(dev); 2620 + 2621 + return fsg_store_nofua(curlun, buf, count); 2622 + } 2623 + 2624 + static ssize_t file_store(struct device *dev, struct device_attribute *attr, 2625 + const char *buf, size_t count) 2626 + { 2627 + struct fsg_lun *curlun = fsg_lun_from_dev(dev); 2628 + struct rw_semaphore *filesem = dev_get_drvdata(dev); 2629 + 2630 + return fsg_store_file(curlun, filesem, buf, count); 2631 + } 2575 2632 2576 2633 static DEVICE_ATTR_RW(ro); 2577 2634 static DEVICE_ATTR_RW(nofua); ··· 2640 2597 /* Nothing needs to be done */ 2641 2598 } 2642 2599 2643 - static inline void fsg_common_get(struct fsg_common *common) 2600 + void fsg_common_get(struct fsg_common *common) 2644 2601 { 2645 2602 kref_get(&common->ref); 2646 2603 } 2604 + EXPORT_SYMBOL_GPL(fsg_common_get); 2647 2605 2648 - static inline void fsg_common_put(struct fsg_common *common) 2606 + void fsg_common_put(struct fsg_common *common) 2649 2607 { 2650 2608 kref_put(&common->ref, fsg_common_release); 2651 2609 } 2610 + EXPORT_SYMBOL_GPL(fsg_common_put); 2652 2611 2653 - static struct fsg_common *fsg_common_init(struct fsg_common *common, 2654 - struct usb_composite_dev *cdev, 2655 - struct fsg_config *cfg) 2612 + /* check if fsg_num_buffers is within a valid range */ 2613 + static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers) 2656 2614 { 2657 - struct usb_gadget *gadget = cdev->gadget; 2658 - struct fsg_buffhd *bh; 2659 - struct fsg_lun *curlun; 2660 - struct fsg_lun_config *lcfg; 2661 - int nluns, i, rc; 2662 - char *pathbuf; 2615 + if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4) 2616 + return 0; 2617 + pr_err("fsg_num_buffers %u is out of range (%d to %d)\n", 2618 + fsg_num_buffers, 2, 4); 2619 + return -EINVAL; 2620 + } 2663 2621 2664 - rc = fsg_num_buffers_validate(); 2665 - if (rc != 0) 2666 - return ERR_PTR(rc); 2667 - 2668 - /* Find out how many LUNs there should be */ 2669 - nluns = cfg->nluns; 2670 - if (nluns < 1 || nluns > FSG_MAX_LUNS) { 2671 - dev_err(&gadget->dev, "invalid number of LUNs: %u\n", nluns); 2672 - return ERR_PTR(-EINVAL); 2673 - } 2674 - 2675 - /* Allocate? */ 2622 + static struct fsg_common *fsg_common_setup(struct fsg_common *common) 2623 + { 2676 2624 if (!common) { 2677 - common = kzalloc(sizeof *common, GFP_KERNEL); 2625 + common = kzalloc(sizeof(*common), GFP_KERNEL); 2678 2626 if (!common) 2679 2627 return ERR_PTR(-ENOMEM); 2680 2628 common->free_storage_on_release = 1; 2681 2629 } else { 2682 - memset(common, 0, sizeof *common); 2683 2630 common->free_storage_on_release = 0; 2684 2631 } 2685 - 2686 - common->buffhds = kcalloc(fsg_num_buffers, 2687 - sizeof *(common->buffhds), GFP_KERNEL); 2688 - if (!common->buffhds) { 2689 - if (common->free_storage_on_release) 2690 - kfree(common); 2691 - return ERR_PTR(-ENOMEM); 2692 - } 2693 - 2694 - common->ops = cfg->ops; 2695 - common->private_data = cfg->private_data; 2696 - 2697 - common->gadget = gadget; 2698 - common->ep0 = gadget->ep0; 2699 - common->ep0req = cdev->req; 2700 - common->cdev = cdev; 2701 - 2702 - /* Maybe allocate device-global string IDs, and patch descriptors */ 2703 - if (fsg_strings[FSG_STRING_INTERFACE].id == 0) { 2704 - rc = usb_string_id(cdev); 2705 - if (unlikely(rc < 0)) 2706 - goto error_release; 2707 - fsg_strings[FSG_STRING_INTERFACE].id = rc; 2708 - fsg_intf_desc.iInterface = rc; 2709 - } 2710 - 2711 - /* 2712 - * Create the LUNs, open their backing files, and register the 2713 - * LUN devices in sysfs. 2714 - */ 2715 - curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL); 2716 - if (unlikely(!curlun)) { 2717 - rc = -ENOMEM; 2718 - goto error_release; 2719 - } 2720 - common->luns = curlun; 2721 - 2722 2632 init_rwsem(&common->filesem); 2633 + spin_lock_init(&common->lock); 2634 + kref_init(&common->ref); 2635 + init_completion(&common->thread_notifier); 2636 + init_waitqueue_head(&common->fsg_wait); 2637 + common->state = FSG_STATE_TERMINATED; 2723 2638 2724 - for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun, ++lcfg) { 2725 - curlun->cdrom = !!lcfg->cdrom; 2726 - curlun->ro = lcfg->cdrom || lcfg->ro; 2727 - curlun->initially_ro = curlun->ro; 2728 - curlun->removable = lcfg->removable; 2729 - curlun->dev.release = fsg_lun_release; 2730 - curlun->dev.parent = &gadget->dev; 2731 - /* curlun->dev.driver = &fsg_driver.driver; XXX */ 2732 - dev_set_drvdata(&curlun->dev, &common->filesem); 2733 - dev_set_name(&curlun->dev, "lun%d", i); 2639 + return common; 2640 + } 2734 2641 2735 - rc = device_register(&curlun->dev); 2736 - if (rc) { 2737 - INFO(common, "failed to register LUN%d: %d\n", i, rc); 2738 - common->nluns = i; 2739 - put_device(&curlun->dev); 2740 - goto error_release; 2642 + void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs) 2643 + { 2644 + common->sysfs = sysfs; 2645 + } 2646 + EXPORT_SYMBOL_GPL(fsg_common_set_sysfs); 2647 + 2648 + static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n) 2649 + { 2650 + if (buffhds) { 2651 + struct fsg_buffhd *bh = buffhds; 2652 + while (n--) { 2653 + kfree(bh->buf); 2654 + ++bh; 2741 2655 } 2742 - 2743 - rc = device_create_file(&curlun->dev, 2744 - curlun->cdrom 2745 - ? &dev_attr_ro_cdrom 2746 - : &dev_attr_ro); 2747 - if (rc) 2748 - goto error_luns; 2749 - rc = device_create_file(&curlun->dev, 2750 - curlun->removable 2751 - ? &dev_attr_file 2752 - : &dev_attr_file_nonremovable); 2753 - if (rc) 2754 - goto error_luns; 2755 - rc = device_create_file(&curlun->dev, &dev_attr_nofua); 2756 - if (rc) 2757 - goto error_luns; 2758 - 2759 - if (lcfg->filename) { 2760 - rc = fsg_lun_open(curlun, lcfg->filename); 2761 - if (rc) 2762 - goto error_luns; 2763 - } else if (!curlun->removable) { 2764 - ERROR(common, "no file given for LUN%d\n", i); 2765 - rc = -EINVAL; 2766 - goto error_luns; 2767 - } 2656 + kfree(buffhds); 2768 2657 } 2769 - common->nluns = nluns; 2658 + } 2659 + 2660 + int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n) 2661 + { 2662 + struct fsg_buffhd *bh, *buffhds; 2663 + int i, rc; 2664 + 2665 + rc = fsg_num_buffers_validate(n); 2666 + if (rc != 0) 2667 + return rc; 2668 + 2669 + buffhds = kcalloc(n, sizeof(*buffhds), GFP_KERNEL); 2670 + if (!buffhds) 2671 + return -ENOMEM; 2770 2672 2771 2673 /* Data buffers cyclic list */ 2772 - bh = common->buffhds; 2773 - i = fsg_num_buffers; 2674 + bh = buffhds; 2675 + i = n; 2774 2676 goto buffhds_first_it; 2775 2677 do { 2776 2678 bh->next = bh + 1; 2777 2679 ++bh; 2778 2680 buffhds_first_it: 2779 2681 bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL); 2780 - if (unlikely(!bh->buf)) { 2781 - rc = -ENOMEM; 2682 + if (unlikely(!bh->buf)) 2782 2683 goto error_release; 2783 - } 2784 2684 } while (--i); 2785 - bh->next = common->buffhds; 2685 + bh->next = buffhds; 2786 2686 2787 - /* Prepare inquiryString */ 2788 - i = get_default_bcdDevice(); 2789 - snprintf(common->inquiry_string, sizeof common->inquiry_string, 2790 - "%-8s%-16s%04x", cfg->vendor_name ?: "Linux", 2791 - /* Assume product name dependent on the first LUN */ 2792 - cfg->product_name ?: (common->luns->cdrom 2793 - ? "File-CD Gadget" 2794 - : "File-Stor Gadget"), 2795 - i); 2687 + _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers); 2688 + common->fsg_num_buffers = n; 2689 + common->buffhds = buffhds; 2690 + 2691 + return 0; 2692 + 2693 + error_release: 2694 + /* 2695 + * "buf"s pointed to by heads after n - i are NULL 2696 + * so releasing them won't hurt 2697 + */ 2698 + _fsg_common_free_buffers(buffhds, n); 2699 + 2700 + return -ENOMEM; 2701 + } 2702 + EXPORT_SYMBOL_GPL(fsg_common_set_num_buffers); 2703 + 2704 + static inline void fsg_common_remove_sysfs(struct fsg_lun *lun) 2705 + { 2706 + device_remove_file(&lun->dev, &dev_attr_nofua); 2707 + /* 2708 + * device_remove_file() => 2709 + * 2710 + * here the attr (e.g. dev_attr_ro) is only used to be passed to: 2711 + * 2712 + * sysfs_remove_file() => 2713 + * 2714 + * here e.g. both dev_attr_ro_cdrom and dev_attr_ro are in 2715 + * the same namespace and 2716 + * from here only attr->name is passed to: 2717 + * 2718 + * sysfs_hash_and_remove() 2719 + * 2720 + * attr->name is the same for dev_attr_ro_cdrom and 2721 + * dev_attr_ro 2722 + * attr->name is the same for dev_attr_file and 2723 + * dev_attr_file_nonremovable 2724 + * 2725 + * so we don't differentiate between removing e.g. dev_attr_ro_cdrom 2726 + * and dev_attr_ro 2727 + */ 2728 + device_remove_file(&lun->dev, &dev_attr_ro); 2729 + device_remove_file(&lun->dev, &dev_attr_file); 2730 + } 2731 + 2732 + void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs) 2733 + { 2734 + if (sysfs) { 2735 + fsg_common_remove_sysfs(lun); 2736 + device_unregister(&lun->dev); 2737 + } 2738 + fsg_lun_close(lun); 2739 + kfree(lun); 2740 + } 2741 + EXPORT_SYMBOL_GPL(fsg_common_remove_lun); 2742 + 2743 + static void _fsg_common_remove_luns(struct fsg_common *common, int n) 2744 + { 2745 + int i; 2746 + 2747 + for (i = 0; i < n; ++i) 2748 + if (common->luns[i]) { 2749 + fsg_common_remove_lun(common->luns[i], common->sysfs); 2750 + common->luns[i] = NULL; 2751 + } 2752 + } 2753 + EXPORT_SYMBOL_GPL(fsg_common_remove_luns); 2754 + 2755 + void fsg_common_remove_luns(struct fsg_common *common) 2756 + { 2757 + _fsg_common_remove_luns(common, common->nluns); 2758 + } 2759 + 2760 + void fsg_common_free_luns(struct fsg_common *common) 2761 + { 2762 + fsg_common_remove_luns(common); 2763 + kfree(common->luns); 2764 + common->luns = NULL; 2765 + } 2766 + EXPORT_SYMBOL_GPL(fsg_common_free_luns); 2767 + 2768 + int fsg_common_set_nluns(struct fsg_common *common, int nluns) 2769 + { 2770 + struct fsg_lun **curlun; 2771 + 2772 + /* Find out how many LUNs there should be */ 2773 + if (nluns < 1 || nluns > FSG_MAX_LUNS) { 2774 + pr_err("invalid number of LUNs: %u\n", nluns); 2775 + return -EINVAL; 2776 + } 2777 + 2778 + curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL); 2779 + if (unlikely(!curlun)) 2780 + return -ENOMEM; 2781 + 2782 + if (common->luns) 2783 + fsg_common_free_luns(common); 2784 + 2785 + common->luns = curlun; 2786 + common->nluns = nluns; 2787 + 2788 + pr_info("Number of LUNs=%d\n", common->nluns); 2789 + 2790 + return 0; 2791 + } 2792 + EXPORT_SYMBOL_GPL(fsg_common_set_nluns); 2793 + 2794 + void fsg_common_set_ops(struct fsg_common *common, 2795 + const struct fsg_operations *ops) 2796 + { 2797 + common->ops = ops; 2798 + } 2799 + EXPORT_SYMBOL_GPL(fsg_common_set_ops); 2800 + 2801 + void fsg_common_free_buffers(struct fsg_common *common) 2802 + { 2803 + _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers); 2804 + common->buffhds = NULL; 2805 + } 2806 + EXPORT_SYMBOL_GPL(fsg_common_free_buffers); 2807 + 2808 + int fsg_common_set_cdev(struct fsg_common *common, 2809 + struct usb_composite_dev *cdev, bool can_stall) 2810 + { 2811 + struct usb_string *us; 2812 + 2813 + common->gadget = cdev->gadget; 2814 + common->ep0 = cdev->gadget->ep0; 2815 + common->ep0req = cdev->req; 2816 + common->cdev = cdev; 2817 + 2818 + us = usb_gstrings_attach(cdev, fsg_strings_array, 2819 + ARRAY_SIZE(fsg_strings)); 2820 + if (IS_ERR(us)) 2821 + return PTR_ERR(us); 2822 + 2823 + fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id; 2796 2824 2797 2825 /* 2798 2826 * Some peripheral controllers are known not to be able to 2799 2827 * halt bulk endpoints correctly. If one of them is present, 2800 2828 * disable stalls. 2801 2829 */ 2802 - common->can_stall = cfg->can_stall && 2803 - !(gadget_is_at91(common->gadget)); 2830 + common->can_stall = can_stall && !(gadget_is_at91(common->gadget)); 2804 2831 2805 - spin_lock_init(&common->lock); 2806 - kref_init(&common->ref); 2832 + return 0; 2833 + } 2834 + EXPORT_SYMBOL_GPL(fsg_common_set_cdev); 2807 2835 2836 + static inline int fsg_common_add_sysfs(struct fsg_common *common, 2837 + struct fsg_lun *lun) 2838 + { 2839 + int rc; 2840 + 2841 + rc = device_register(&lun->dev); 2842 + if (rc) { 2843 + put_device(&lun->dev); 2844 + return rc; 2845 + } 2846 + 2847 + rc = device_create_file(&lun->dev, 2848 + lun->cdrom 2849 + ? &dev_attr_ro_cdrom 2850 + : &dev_attr_ro); 2851 + if (rc) 2852 + goto error; 2853 + rc = device_create_file(&lun->dev, 2854 + lun->removable 2855 + ? &dev_attr_file 2856 + : &dev_attr_file_nonremovable); 2857 + if (rc) 2858 + goto error; 2859 + rc = device_create_file(&lun->dev, &dev_attr_nofua); 2860 + if (rc) 2861 + goto error; 2862 + 2863 + return 0; 2864 + 2865 + error: 2866 + /* removing nonexistent files is a no-op */ 2867 + fsg_common_remove_sysfs(lun); 2868 + device_unregister(&lun->dev); 2869 + return rc; 2870 + } 2871 + 2872 + int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, 2873 + unsigned int id, const char *name, 2874 + const char **name_pfx) 2875 + { 2876 + struct fsg_lun *lun; 2877 + char *pathbuf, *p; 2878 + int rc = -ENOMEM; 2879 + 2880 + if (!common->nluns || !common->luns) 2881 + return -ENODEV; 2882 + 2883 + if (common->luns[id]) 2884 + return -EBUSY; 2885 + 2886 + if (!cfg->filename && !cfg->removable) { 2887 + pr_err("no file given for LUN%d\n", id); 2888 + return -EINVAL; 2889 + } 2890 + 2891 + lun = kzalloc(sizeof(*lun), GFP_KERNEL); 2892 + if (!lun) 2893 + return -ENOMEM; 2894 + 2895 + lun->name_pfx = name_pfx; 2896 + 2897 + lun->cdrom = !!cfg->cdrom; 2898 + lun->ro = cfg->cdrom || cfg->ro; 2899 + lun->initially_ro = lun->ro; 2900 + lun->removable = !!cfg->removable; 2901 + 2902 + if (!common->sysfs) { 2903 + /* we DON'T own the name!*/ 2904 + lun->name = name; 2905 + } else { 2906 + lun->dev.release = fsg_lun_release; 2907 + lun->dev.parent = &common->gadget->dev; 2908 + dev_set_drvdata(&lun->dev, &common->filesem); 2909 + dev_set_name(&lun->dev, name); 2910 + lun->name = dev_name(&lun->dev); 2911 + 2912 + rc = fsg_common_add_sysfs(common, lun); 2913 + if (rc) { 2914 + pr_info("failed to register LUN%d: %d\n", id, rc); 2915 + goto error_sysfs; 2916 + } 2917 + } 2918 + 2919 + common->luns[id] = lun; 2920 + 2921 + if (cfg->filename) { 2922 + rc = fsg_lun_open(lun, cfg->filename); 2923 + if (rc) 2924 + goto error_lun; 2925 + } 2926 + 2927 + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); 2928 + p = "(no medium)"; 2929 + if (fsg_lun_is_open(lun)) { 2930 + p = "(error)"; 2931 + if (pathbuf) { 2932 + p = d_path(&lun->filp->f_path, pathbuf, PATH_MAX); 2933 + if (IS_ERR(p)) 2934 + p = "(error)"; 2935 + } 2936 + } 2937 + pr_info("LUN: %s%s%sfile: %s\n", 2938 + lun->removable ? "removable " : "", 2939 + lun->ro ? "read only " : "", 2940 + lun->cdrom ? "CD-ROM " : "", 2941 + p); 2942 + kfree(pathbuf); 2943 + 2944 + return 0; 2945 + 2946 + error_lun: 2947 + if (common->sysfs) { 2948 + fsg_common_remove_sysfs(lun); 2949 + device_unregister(&lun->dev); 2950 + } 2951 + fsg_lun_close(lun); 2952 + common->luns[id] = NULL; 2953 + error_sysfs: 2954 + kfree(lun); 2955 + return rc; 2956 + } 2957 + EXPORT_SYMBOL_GPL(fsg_common_create_lun); 2958 + 2959 + int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg) 2960 + { 2961 + char buf[8]; /* enough for 100000000 different numbers, decimal */ 2962 + int i, rc; 2963 + 2964 + for (i = 0; i < common->nluns; ++i) { 2965 + snprintf(buf, sizeof(buf), "lun%d", i); 2966 + rc = fsg_common_create_lun(common, &cfg->luns[i], i, buf, NULL); 2967 + if (rc) 2968 + goto fail; 2969 + } 2970 + 2971 + pr_info("Number of LUNs=%d\n", common->nluns); 2972 + 2973 + return 0; 2974 + 2975 + fail: 2976 + _fsg_common_remove_luns(common, i); 2977 + return rc; 2978 + } 2979 + EXPORT_SYMBOL_GPL(fsg_common_create_luns); 2980 + 2981 + void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn, 2982 + const char *pn) 2983 + { 2984 + int i; 2985 + 2986 + /* Prepare inquiryString */ 2987 + i = get_default_bcdDevice(); 2988 + snprintf(common->inquiry_string, sizeof(common->inquiry_string), 2989 + "%-8s%-16s%04x", vn ?: "Linux", 2990 + /* Assume product name dependent on the first LUN */ 2991 + pn ?: ((*common->luns)->cdrom 2992 + ? "File-CD Gadget" 2993 + : "File-Stor Gadget"), 2994 + i); 2995 + } 2996 + EXPORT_SYMBOL_GPL(fsg_common_set_inquiry_string); 2997 + 2998 + int fsg_common_run_thread(struct fsg_common *common) 2999 + { 3000 + common->state = FSG_STATE_IDLE; 2808 3001 /* Tell the thread to start working */ 2809 3002 common->thread_task = 2810 3003 kthread_create(fsg_main_thread, common, "file-storage"); 2811 3004 if (IS_ERR(common->thread_task)) { 2812 - rc = PTR_ERR(common->thread_task); 2813 - goto error_release; 3005 + common->state = FSG_STATE_TERMINATED; 3006 + return PTR_ERR(common->thread_task); 2814 3007 } 2815 - init_completion(&common->thread_notifier); 2816 - init_waitqueue_head(&common->fsg_wait); 2817 - 2818 - /* Information */ 2819 - INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); 2820 - INFO(common, "Number of LUNs=%d\n", common->nluns); 2821 - 2822 - pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); 2823 - for (i = 0, nluns = common->nluns, curlun = common->luns; 2824 - i < nluns; 2825 - ++curlun, ++i) { 2826 - char *p = "(no medium)"; 2827 - if (fsg_lun_is_open(curlun)) { 2828 - p = "(error)"; 2829 - if (pathbuf) { 2830 - p = d_path(&curlun->filp->f_path, 2831 - pathbuf, PATH_MAX); 2832 - if (IS_ERR(p)) 2833 - p = "(error)"; 2834 - } 2835 - } 2836 - LINFO(curlun, "LUN: %s%s%sfile: %s\n", 2837 - curlun->removable ? "removable " : "", 2838 - curlun->ro ? "read only " : "", 2839 - curlun->cdrom ? "CD-ROM " : "", 2840 - p); 2841 - } 2842 - kfree(pathbuf); 2843 3008 2844 3009 DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task)); 2845 3010 2846 3011 wake_up_process(common->thread_task); 2847 3012 2848 - return common; 2849 - 2850 - error_luns: 2851 - common->nluns = i + 1; 2852 - error_release: 2853 - common->state = FSG_STATE_TERMINATED; /* The thread is dead */ 2854 - /* Call fsg_common_release() directly, ref might be not initialised. */ 2855 - fsg_common_release(&common->ref); 2856 - return ERR_PTR(rc); 3013 + return 0; 2857 3014 } 3015 + EXPORT_SYMBOL_GPL(fsg_common_run_thread); 2858 3016 2859 3017 static void fsg_common_release(struct kref *ref) 2860 3018 { ··· 3068 2824 } 3069 2825 3070 2826 if (likely(common->luns)) { 3071 - struct fsg_lun *lun = common->luns; 2827 + struct fsg_lun **lun_it = common->luns; 3072 2828 unsigned i = common->nluns; 3073 2829 3074 2830 /* In error recovery common->nluns may be zero. */ 3075 - for (; i; --i, ++lun) { 3076 - device_remove_file(&lun->dev, &dev_attr_nofua); 3077 - device_remove_file(&lun->dev, 3078 - lun->cdrom 3079 - ? &dev_attr_ro_cdrom 3080 - : &dev_attr_ro); 3081 - device_remove_file(&lun->dev, 3082 - lun->removable 3083 - ? &dev_attr_file 3084 - : &dev_attr_file_nonremovable); 2831 + for (; i; --i, ++lun_it) { 2832 + struct fsg_lun *lun = *lun_it; 2833 + if (!lun) 2834 + continue; 2835 + if (common->sysfs) 2836 + fsg_common_remove_sysfs(lun); 3085 2837 fsg_lun_close(lun); 3086 - device_unregister(&lun->dev); 2838 + if (common->sysfs) 2839 + device_unregister(&lun->dev); 2840 + kfree(lun); 3087 2841 } 3088 2842 3089 2843 kfree(common->luns); 3090 2844 } 3091 2845 3092 - { 3093 - struct fsg_buffhd *bh = common->buffhds; 3094 - unsigned i = fsg_num_buffers; 3095 - do { 3096 - kfree(bh->buf); 3097 - } while (++bh, --i); 3098 - } 3099 - 3100 - kfree(common->buffhds); 2846 + _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers); 3101 2847 if (common->free_storage_on_release) 3102 2848 kfree(common); 3103 2849 } 3104 2850 3105 2851 3106 2852 /*-------------------------------------------------------------------------*/ 3107 - 3108 - static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) 3109 - { 3110 - struct fsg_dev *fsg = fsg_from_func(f); 3111 - struct fsg_common *common = fsg->common; 3112 - 3113 - DBG(fsg, "unbind\n"); 3114 - if (fsg->common->fsg == fsg) { 3115 - fsg->common->new_fsg = NULL; 3116 - raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); 3117 - /* FIXME: make interruptible or killable somehow? */ 3118 - wait_event(common->fsg_wait, common->fsg != fsg); 3119 - } 3120 - 3121 - fsg_common_put(common); 3122 - usb_free_all_descriptors(&fsg->function); 3123 - kfree(fsg); 3124 - } 3125 2853 3126 2854 static int fsg_bind(struct usb_configuration *c, struct usb_function *f) 3127 2855 { ··· 3103 2887 struct usb_ep *ep; 3104 2888 unsigned max_burst; 3105 2889 int ret; 2890 + struct fsg_opts *opts; 2891 + 2892 + opts = fsg_opts_from_func_inst(f->fi); 2893 + if (!opts->no_configfs) { 2894 + ret = fsg_common_set_cdev(fsg->common, c->cdev, 2895 + fsg->common->can_stall); 2896 + if (ret) 2897 + return ret; 2898 + fsg_common_set_inquiry_string(fsg->common, 0, 0); 2899 + ret = fsg_common_run_thread(fsg->common); 2900 + if (ret) 2901 + return ret; 2902 + } 3106 2903 3107 2904 fsg->gadget = gadget; 3108 2905 ··· 3168 2939 return -ENOTSUPP; 3169 2940 } 3170 2941 3171 - /****************************** ADD FUNCTION ******************************/ 2942 + /****************************** ALLOCATE FUNCTION *************************/ 3172 2943 3173 - static struct usb_gadget_strings *fsg_strings_array[] = { 3174 - &fsg_stringtab, 2944 + static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) 2945 + { 2946 + struct fsg_dev *fsg = fsg_from_func(f); 2947 + struct fsg_common *common = fsg->common; 2948 + 2949 + DBG(fsg, "unbind\n"); 2950 + if (fsg->common->fsg == fsg) { 2951 + fsg->common->new_fsg = NULL; 2952 + raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); 2953 + /* FIXME: make interruptible or killable somehow? */ 2954 + wait_event(common->fsg_wait, common->fsg != fsg); 2955 + } 2956 + 2957 + usb_free_all_descriptors(&fsg->function); 2958 + } 2959 + 2960 + static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item) 2961 + { 2962 + return container_of(to_config_group(item), struct fsg_lun_opts, group); 2963 + } 2964 + 2965 + static inline struct fsg_opts *to_fsg_opts(struct config_item *item) 2966 + { 2967 + return container_of(to_config_group(item), struct fsg_opts, 2968 + func_inst.group); 2969 + } 2970 + 2971 + CONFIGFS_ATTR_STRUCT(fsg_lun_opts); 2972 + CONFIGFS_ATTR_OPS(fsg_lun_opts); 2973 + 2974 + static void fsg_lun_attr_release(struct config_item *item) 2975 + { 2976 + struct fsg_lun_opts *lun_opts; 2977 + 2978 + lun_opts = to_fsg_lun_opts(item); 2979 + kfree(lun_opts); 2980 + } 2981 + 2982 + static struct configfs_item_operations fsg_lun_item_ops = { 2983 + .release = fsg_lun_attr_release, 2984 + .show_attribute = fsg_lun_opts_attr_show, 2985 + .store_attribute = fsg_lun_opts_attr_store, 2986 + }; 2987 + 2988 + static ssize_t fsg_lun_opts_file_show(struct fsg_lun_opts *opts, char *page) 2989 + { 2990 + struct fsg_opts *fsg_opts; 2991 + 2992 + fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); 2993 + 2994 + return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page); 2995 + } 2996 + 2997 + static ssize_t fsg_lun_opts_file_store(struct fsg_lun_opts *opts, 2998 + const char *page, size_t len) 2999 + { 3000 + struct fsg_opts *fsg_opts; 3001 + 3002 + fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); 3003 + 3004 + return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len); 3005 + } 3006 + 3007 + static struct fsg_lun_opts_attribute fsg_lun_opts_file = 3008 + __CONFIGFS_ATTR(file, S_IRUGO | S_IWUSR, fsg_lun_opts_file_show, 3009 + fsg_lun_opts_file_store); 3010 + 3011 + static ssize_t fsg_lun_opts_ro_show(struct fsg_lun_opts *opts, char *page) 3012 + { 3013 + return fsg_show_ro(opts->lun, page); 3014 + } 3015 + 3016 + static ssize_t fsg_lun_opts_ro_store(struct fsg_lun_opts *opts, 3017 + const char *page, size_t len) 3018 + { 3019 + struct fsg_opts *fsg_opts; 3020 + 3021 + fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); 3022 + 3023 + return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len); 3024 + } 3025 + 3026 + static struct fsg_lun_opts_attribute fsg_lun_opts_ro = 3027 + __CONFIGFS_ATTR(ro, S_IRUGO | S_IWUSR, fsg_lun_opts_ro_show, 3028 + fsg_lun_opts_ro_store); 3029 + 3030 + static ssize_t fsg_lun_opts_removable_show(struct fsg_lun_opts *opts, 3031 + char *page) 3032 + { 3033 + return fsg_show_removable(opts->lun, page); 3034 + } 3035 + 3036 + static ssize_t fsg_lun_opts_removable_store(struct fsg_lun_opts *opts, 3037 + const char *page, size_t len) 3038 + { 3039 + return fsg_store_removable(opts->lun, page, len); 3040 + } 3041 + 3042 + static struct fsg_lun_opts_attribute fsg_lun_opts_removable = 3043 + __CONFIGFS_ATTR(removable, S_IRUGO | S_IWUSR, 3044 + fsg_lun_opts_removable_show, 3045 + fsg_lun_opts_removable_store); 3046 + 3047 + static ssize_t fsg_lun_opts_cdrom_show(struct fsg_lun_opts *opts, char *page) 3048 + { 3049 + return fsg_show_cdrom(opts->lun, page); 3050 + } 3051 + 3052 + static ssize_t fsg_lun_opts_cdrom_store(struct fsg_lun_opts *opts, 3053 + const char *page, size_t len) 3054 + { 3055 + struct fsg_opts *fsg_opts; 3056 + 3057 + fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); 3058 + 3059 + return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page, 3060 + len); 3061 + } 3062 + 3063 + static struct fsg_lun_opts_attribute fsg_lun_opts_cdrom = 3064 + __CONFIGFS_ATTR(cdrom, S_IRUGO | S_IWUSR, fsg_lun_opts_cdrom_show, 3065 + fsg_lun_opts_cdrom_store); 3066 + 3067 + static ssize_t fsg_lun_opts_nofua_show(struct fsg_lun_opts *opts, char *page) 3068 + { 3069 + return fsg_show_nofua(opts->lun, page); 3070 + } 3071 + 3072 + static ssize_t fsg_lun_opts_nofua_store(struct fsg_lun_opts *opts, 3073 + const char *page, size_t len) 3074 + { 3075 + return fsg_store_nofua(opts->lun, page, len); 3076 + } 3077 + 3078 + static struct fsg_lun_opts_attribute fsg_lun_opts_nofua = 3079 + __CONFIGFS_ATTR(nofua, S_IRUGO | S_IWUSR, fsg_lun_opts_nofua_show, 3080 + fsg_lun_opts_nofua_store); 3081 + 3082 + static struct configfs_attribute *fsg_lun_attrs[] = { 3083 + &fsg_lun_opts_file.attr, 3084 + &fsg_lun_opts_ro.attr, 3085 + &fsg_lun_opts_removable.attr, 3086 + &fsg_lun_opts_cdrom.attr, 3087 + &fsg_lun_opts_nofua.attr, 3175 3088 NULL, 3176 3089 }; 3177 3090 3178 - static int fsg_bind_config(struct usb_composite_dev *cdev, 3179 - struct usb_configuration *c, 3180 - struct fsg_common *common) 3091 + static struct config_item_type fsg_lun_type = { 3092 + .ct_item_ops = &fsg_lun_item_ops, 3093 + .ct_attrs = fsg_lun_attrs, 3094 + .ct_owner = THIS_MODULE, 3095 + }; 3096 + 3097 + static struct config_group *fsg_lun_make(struct config_group *group, 3098 + const char *name) 3181 3099 { 3182 - struct fsg_dev *fsg; 3183 - int rc; 3100 + struct fsg_lun_opts *opts; 3101 + struct fsg_opts *fsg_opts; 3102 + struct fsg_lun_config config; 3103 + char *num_str; 3104 + u8 num; 3105 + int ret; 3184 3106 3185 - fsg = kzalloc(sizeof *fsg, GFP_KERNEL); 3186 - if (unlikely(!fsg)) 3187 - return -ENOMEM; 3107 + num_str = strchr(name, '.'); 3108 + if (!num_str) { 3109 + pr_err("Unable to locate . in LUN.NUMBER\n"); 3110 + return ERR_PTR(-EINVAL); 3111 + } 3112 + num_str++; 3188 3113 3189 - fsg->function.name = FSG_DRIVER_DESC; 3190 - fsg->function.strings = fsg_strings_array; 3191 - fsg->function.bind = fsg_bind; 3192 - fsg->function.unbind = fsg_unbind; 3193 - fsg->function.setup = fsg_setup; 3194 - fsg->function.set_alt = fsg_set_alt; 3195 - fsg->function.disable = fsg_disable; 3114 + ret = kstrtou8(num_str, 0, &num); 3115 + if (ret) 3116 + return ERR_PTR(ret); 3196 3117 3197 - fsg->common = common; 3198 - /* 3199 - * Our caller holds a reference to common structure so we 3200 - * don't have to be worry about it being freed until we return 3201 - * from this function. So instead of incrementing counter now 3202 - * and decrement in error recovery we increment it only when 3203 - * call to usb_add_function() was successful. 3204 - */ 3118 + fsg_opts = to_fsg_opts(&group->cg_item); 3119 + if (num >= FSG_MAX_LUNS) 3120 + return ERR_PTR(-ERANGE); 3205 3121 3206 - rc = usb_add_function(c, &fsg->function); 3207 - if (unlikely(rc)) 3208 - kfree(fsg); 3209 - else 3210 - fsg_common_get(fsg->common); 3211 - return rc; 3122 + mutex_lock(&fsg_opts->lock); 3123 + if (fsg_opts->refcnt || fsg_opts->common->luns[num]) { 3124 + ret = -EBUSY; 3125 + goto out; 3126 + } 3127 + 3128 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 3129 + if (!opts) { 3130 + ret = -ENOMEM; 3131 + goto out; 3132 + } 3133 + 3134 + memset(&config, 0, sizeof(config)); 3135 + config.removable = true; 3136 + 3137 + ret = fsg_common_create_lun(fsg_opts->common, &config, num, name, 3138 + (const char **)&group->cg_item.ci_name); 3139 + if (ret) { 3140 + kfree(opts); 3141 + goto out; 3142 + } 3143 + opts->lun = fsg_opts->common->luns[num]; 3144 + opts->lun_id = num; 3145 + mutex_unlock(&fsg_opts->lock); 3146 + 3147 + config_group_init_type_name(&opts->group, name, &fsg_lun_type); 3148 + 3149 + return &opts->group; 3150 + out: 3151 + mutex_unlock(&fsg_opts->lock); 3152 + return ERR_PTR(ret); 3212 3153 } 3213 3154 3155 + static void fsg_lun_drop(struct config_group *group, struct config_item *item) 3156 + { 3157 + struct fsg_lun_opts *lun_opts; 3158 + struct fsg_opts *fsg_opts; 3159 + 3160 + lun_opts = to_fsg_lun_opts(item); 3161 + fsg_opts = to_fsg_opts(&group->cg_item); 3162 + 3163 + mutex_lock(&fsg_opts->lock); 3164 + if (fsg_opts->refcnt) { 3165 + struct config_item *gadget; 3166 + 3167 + gadget = group->cg_item.ci_parent->ci_parent; 3168 + unregister_gadget_item(gadget); 3169 + } 3170 + 3171 + fsg_common_remove_lun(lun_opts->lun, fsg_opts->common->sysfs); 3172 + fsg_opts->common->luns[lun_opts->lun_id] = NULL; 3173 + lun_opts->lun_id = 0; 3174 + mutex_unlock(&fsg_opts->lock); 3175 + 3176 + config_item_put(item); 3177 + } 3178 + 3179 + CONFIGFS_ATTR_STRUCT(fsg_opts); 3180 + CONFIGFS_ATTR_OPS(fsg_opts); 3181 + 3182 + static void fsg_attr_release(struct config_item *item) 3183 + { 3184 + struct fsg_opts *opts = to_fsg_opts(item); 3185 + 3186 + usb_put_function_instance(&opts->func_inst); 3187 + } 3188 + 3189 + static struct configfs_item_operations fsg_item_ops = { 3190 + .release = fsg_attr_release, 3191 + .show_attribute = fsg_opts_attr_show, 3192 + .store_attribute = fsg_opts_attr_store, 3193 + }; 3194 + 3195 + static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page) 3196 + { 3197 + int result; 3198 + 3199 + mutex_lock(&opts->lock); 3200 + result = sprintf(page, "%d", opts->common->can_stall); 3201 + mutex_unlock(&opts->lock); 3202 + 3203 + return result; 3204 + } 3205 + 3206 + static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page, 3207 + size_t len) 3208 + { 3209 + int ret; 3210 + bool stall; 3211 + 3212 + mutex_lock(&opts->lock); 3213 + 3214 + if (opts->refcnt) { 3215 + mutex_unlock(&opts->lock); 3216 + return -EBUSY; 3217 + } 3218 + 3219 + ret = strtobool(page, &stall); 3220 + if (!ret) { 3221 + opts->common->can_stall = stall; 3222 + ret = len; 3223 + } 3224 + 3225 + mutex_unlock(&opts->lock); 3226 + 3227 + return ret; 3228 + } 3229 + 3230 + static struct fsg_opts_attribute fsg_opts_stall = 3231 + __CONFIGFS_ATTR(stall, S_IRUGO | S_IWUSR, fsg_opts_stall_show, 3232 + fsg_opts_stall_store); 3233 + 3234 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 3235 + static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page) 3236 + { 3237 + int result; 3238 + 3239 + mutex_lock(&opts->lock); 3240 + result = sprintf(page, "%d", opts->common->fsg_num_buffers); 3241 + mutex_unlock(&opts->lock); 3242 + 3243 + return result; 3244 + } 3245 + 3246 + static ssize_t fsg_opts_num_buffers_store(struct fsg_opts *opts, 3247 + const char *page, size_t len) 3248 + { 3249 + int ret; 3250 + u8 num; 3251 + 3252 + mutex_lock(&opts->lock); 3253 + if (opts->refcnt) { 3254 + ret = -EBUSY; 3255 + goto end; 3256 + } 3257 + ret = kstrtou8(page, 0, &num); 3258 + if (ret) 3259 + goto end; 3260 + 3261 + ret = fsg_num_buffers_validate(num); 3262 + if (ret) 3263 + goto end; 3264 + 3265 + fsg_common_set_num_buffers(opts->common, num); 3266 + ret = len; 3267 + 3268 + end: 3269 + mutex_unlock(&opts->lock); 3270 + return ret; 3271 + } 3272 + 3273 + static struct fsg_opts_attribute fsg_opts_num_buffers = 3274 + __CONFIGFS_ATTR(num_buffers, S_IRUGO | S_IWUSR, 3275 + fsg_opts_num_buffers_show, 3276 + fsg_opts_num_buffers_store); 3277 + 3278 + #endif 3279 + 3280 + static struct configfs_attribute *fsg_attrs[] = { 3281 + &fsg_opts_stall.attr, 3282 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 3283 + &fsg_opts_num_buffers.attr, 3284 + #endif 3285 + NULL, 3286 + }; 3287 + 3288 + static struct configfs_group_operations fsg_group_ops = { 3289 + .make_group = fsg_lun_make, 3290 + .drop_item = fsg_lun_drop, 3291 + }; 3292 + 3293 + static struct config_item_type fsg_func_type = { 3294 + .ct_item_ops = &fsg_item_ops, 3295 + .ct_group_ops = &fsg_group_ops, 3296 + .ct_attrs = fsg_attrs, 3297 + .ct_owner = THIS_MODULE, 3298 + }; 3299 + 3300 + static void fsg_free_inst(struct usb_function_instance *fi) 3301 + { 3302 + struct fsg_opts *opts; 3303 + 3304 + opts = fsg_opts_from_func_inst(fi); 3305 + fsg_common_put(opts->common); 3306 + kfree(opts); 3307 + } 3308 + 3309 + static struct usb_function_instance *fsg_alloc_inst(void) 3310 + { 3311 + struct fsg_opts *opts; 3312 + struct fsg_lun_config config; 3313 + int rc; 3314 + 3315 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 3316 + if (!opts) 3317 + return ERR_PTR(-ENOMEM); 3318 + mutex_init(&opts->lock); 3319 + opts->func_inst.free_func_inst = fsg_free_inst; 3320 + opts->common = fsg_common_setup(opts->common); 3321 + if (IS_ERR(opts->common)) { 3322 + rc = PTR_ERR(opts->common); 3323 + goto release_opts; 3324 + } 3325 + rc = fsg_common_set_nluns(opts->common, FSG_MAX_LUNS); 3326 + if (rc) 3327 + goto release_opts; 3328 + 3329 + rc = fsg_common_set_num_buffers(opts->common, 3330 + CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS); 3331 + if (rc) 3332 + goto release_luns; 3333 + 3334 + pr_info(FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); 3335 + 3336 + memset(&config, 0, sizeof(config)); 3337 + config.removable = true; 3338 + rc = fsg_common_create_lun(opts->common, &config, 0, "lun.0", 3339 + (const char **)&opts->func_inst.group.cg_item.ci_name); 3340 + opts->lun0.lun = opts->common->luns[0]; 3341 + opts->lun0.lun_id = 0; 3342 + config_group_init_type_name(&opts->lun0.group, "lun.0", &fsg_lun_type); 3343 + opts->default_groups[0] = &opts->lun0.group; 3344 + opts->func_inst.group.default_groups = opts->default_groups; 3345 + 3346 + config_group_init_type_name(&opts->func_inst.group, "", &fsg_func_type); 3347 + 3348 + return &opts->func_inst; 3349 + 3350 + release_luns: 3351 + kfree(opts->common->luns); 3352 + release_opts: 3353 + kfree(opts); 3354 + return ERR_PTR(rc); 3355 + } 3356 + 3357 + static void fsg_free(struct usb_function *f) 3358 + { 3359 + struct fsg_dev *fsg; 3360 + struct fsg_opts *opts; 3361 + 3362 + fsg = container_of(f, struct fsg_dev, function); 3363 + opts = container_of(f->fi, struct fsg_opts, func_inst); 3364 + 3365 + mutex_lock(&opts->lock); 3366 + opts->refcnt--; 3367 + mutex_unlock(&opts->lock); 3368 + 3369 + kfree(fsg); 3370 + } 3371 + 3372 + static struct usb_function *fsg_alloc(struct usb_function_instance *fi) 3373 + { 3374 + struct fsg_opts *opts = fsg_opts_from_func_inst(fi); 3375 + struct fsg_common *common = opts->common; 3376 + struct fsg_dev *fsg; 3377 + 3378 + fsg = kzalloc(sizeof(*fsg), GFP_KERNEL); 3379 + if (unlikely(!fsg)) 3380 + return ERR_PTR(-ENOMEM); 3381 + 3382 + mutex_lock(&opts->lock); 3383 + opts->refcnt++; 3384 + mutex_unlock(&opts->lock); 3385 + fsg->function.name = FSG_DRIVER_DESC; 3386 + fsg->function.bind = fsg_bind; 3387 + fsg->function.unbind = fsg_unbind; 3388 + fsg->function.setup = fsg_setup; 3389 + fsg->function.set_alt = fsg_set_alt; 3390 + fsg->function.disable = fsg_disable; 3391 + fsg->function.free_func = fsg_free; 3392 + 3393 + fsg->common = common; 3394 + 3395 + return &fsg->function; 3396 + } 3397 + 3398 + DECLARE_USB_FUNCTION_INIT(mass_storage, fsg_alloc_inst, fsg_alloc); 3399 + MODULE_LICENSE("GPL"); 3400 + MODULE_AUTHOR("Michal Nazarewicz"); 3214 3401 3215 3402 /************************* Module parameters *************************/ 3216 3403 3217 - struct fsg_module_parameters { 3218 - char *file[FSG_MAX_LUNS]; 3219 - bool ro[FSG_MAX_LUNS]; 3220 - bool removable[FSG_MAX_LUNS]; 3221 - bool cdrom[FSG_MAX_LUNS]; 3222 - bool nofua[FSG_MAX_LUNS]; 3223 3404 3224 - unsigned int file_count, ro_count, removable_count, cdrom_count; 3225 - unsigned int nofua_count; 3226 - unsigned int luns; /* nluns */ 3227 - bool stall; /* can_stall */ 3228 - }; 3229 - 3230 - #define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \ 3231 - module_param_array_named(prefix ## name, params.name, type, \ 3232 - &prefix ## params.name ## _count, \ 3233 - S_IRUGO); \ 3234 - MODULE_PARM_DESC(prefix ## name, desc) 3235 - 3236 - #define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \ 3237 - module_param_named(prefix ## name, params.name, type, \ 3238 - S_IRUGO); \ 3239 - MODULE_PARM_DESC(prefix ## name, desc) 3240 - 3241 - #define FSG_MODULE_PARAMETERS(prefix, params) \ 3242 - _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \ 3243 - "names of backing files or devices"); \ 3244 - _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \ 3245 - "true to force read-only"); \ 3246 - _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \ 3247 - "true to simulate removable media"); \ 3248 - _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \ 3249 - "true to simulate CD-ROM instead of disk"); \ 3250 - _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \ 3251 - "true to ignore SCSI WRITE(10,12) FUA bit"); \ 3252 - _FSG_MODULE_PARAM(prefix, params, luns, uint, \ 3253 - "number of LUNs"); \ 3254 - _FSG_MODULE_PARAM(prefix, params, stall, bool, \ 3255 - "false to prevent bulk stalls") 3256 - 3257 - static void 3258 - fsg_config_from_params(struct fsg_config *cfg, 3259 - const struct fsg_module_parameters *params) 3405 + void fsg_config_from_params(struct fsg_config *cfg, 3406 + const struct fsg_module_parameters *params, 3407 + unsigned int fsg_num_buffers) 3260 3408 { 3261 3409 struct fsg_lun_config *lun; 3262 3410 unsigned i; ··· 3661 3055 3662 3056 /* Finalise */ 3663 3057 cfg->can_stall = params->stall; 3058 + cfg->fsg_num_buffers = fsg_num_buffers; 3664 3059 } 3060 + EXPORT_SYMBOL_GPL(fsg_config_from_params); 3665 3061 3666 - static inline struct fsg_common * 3667 - fsg_common_from_params(struct fsg_common *common, 3668 - struct usb_composite_dev *cdev, 3669 - const struct fsg_module_parameters *params) 3670 - __attribute__((unused)); 3671 - static inline struct fsg_common * 3672 - fsg_common_from_params(struct fsg_common *common, 3673 - struct usb_composite_dev *cdev, 3674 - const struct fsg_module_parameters *params) 3675 - { 3676 - struct fsg_config cfg; 3677 - fsg_config_from_params(&cfg, params); 3678 - return fsg_common_init(common, cdev, &cfg); 3679 - }
+166
drivers/usb/gadget/f_mass_storage.h
··· 1 + #ifndef USB_F_MASS_STORAGE_H 2 + #define USB_F_MASS_STORAGE_H 3 + 4 + #include <linux/usb/composite.h> 5 + #include "storage_common.h" 6 + 7 + struct fsg_module_parameters { 8 + char *file[FSG_MAX_LUNS]; 9 + bool ro[FSG_MAX_LUNS]; 10 + bool removable[FSG_MAX_LUNS]; 11 + bool cdrom[FSG_MAX_LUNS]; 12 + bool nofua[FSG_MAX_LUNS]; 13 + 14 + unsigned int file_count, ro_count, removable_count, cdrom_count; 15 + unsigned int nofua_count; 16 + unsigned int luns; /* nluns */ 17 + bool stall; /* can_stall */ 18 + }; 19 + 20 + #define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \ 21 + module_param_array_named(prefix ## name, params.name, type, \ 22 + &prefix ## params.name ## _count, \ 23 + S_IRUGO); \ 24 + MODULE_PARM_DESC(prefix ## name, desc) 25 + 26 + #define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \ 27 + module_param_named(prefix ## name, params.name, type, \ 28 + S_IRUGO); \ 29 + MODULE_PARM_DESC(prefix ## name, desc) 30 + 31 + #define __FSG_MODULE_PARAMETERS(prefix, params) \ 32 + _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \ 33 + "names of backing files or devices"); \ 34 + _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \ 35 + "true to force read-only"); \ 36 + _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \ 37 + "true to simulate removable media"); \ 38 + _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \ 39 + "true to simulate CD-ROM instead of disk"); \ 40 + _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \ 41 + "true to ignore SCSI WRITE(10,12) FUA bit"); \ 42 + _FSG_MODULE_PARAM(prefix, params, luns, uint, \ 43 + "number of LUNs"); \ 44 + _FSG_MODULE_PARAM(prefix, params, stall, bool, \ 45 + "false to prevent bulk stalls") 46 + 47 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 48 + 49 + #define FSG_MODULE_PARAMETERS(prefix, params) \ 50 + __FSG_MODULE_PARAMETERS(prefix, params); \ 51 + module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\ 52 + MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers") 53 + #else 54 + 55 + #define FSG_MODULE_PARAMETERS(prefix, params) \ 56 + __FSG_MODULE_PARAMETERS(prefix, params) 57 + 58 + #endif 59 + 60 + struct fsg_common; 61 + 62 + /* FSF callback functions */ 63 + struct fsg_operations { 64 + /* 65 + * Callback function to call when thread exits. If no 66 + * callback is set or it returns value lower then zero MSF 67 + * will force eject all LUNs it operates on (including those 68 + * marked as non-removable or with prevent_medium_removal flag 69 + * set). 70 + */ 71 + int (*thread_exits)(struct fsg_common *common); 72 + }; 73 + 74 + struct fsg_lun_opts { 75 + struct config_group group; 76 + struct fsg_lun *lun; 77 + int lun_id; 78 + }; 79 + 80 + struct fsg_opts { 81 + struct fsg_common *common; 82 + struct usb_function_instance func_inst; 83 + struct fsg_lun_opts lun0; 84 + struct config_group *default_groups[2]; 85 + bool no_configfs; /* for legacy gadgets */ 86 + 87 + /* 88 + * Read/write access to configfs attributes is handled by configfs. 89 + * 90 + * This is to protect the data from concurrent access by read/write 91 + * and create symlink/remove symlink. 92 + */ 93 + struct mutex lock; 94 + int refcnt; 95 + }; 96 + 97 + struct fsg_lun_config { 98 + const char *filename; 99 + char ro; 100 + char removable; 101 + char cdrom; 102 + char nofua; 103 + }; 104 + 105 + struct fsg_config { 106 + unsigned nluns; 107 + struct fsg_lun_config luns[FSG_MAX_LUNS]; 108 + 109 + /* Callback functions. */ 110 + const struct fsg_operations *ops; 111 + /* Gadget's private data. */ 112 + void *private_data; 113 + 114 + const char *vendor_name; /* 8 characters or less */ 115 + const char *product_name; /* 16 characters or less */ 116 + 117 + char can_stall; 118 + unsigned int fsg_num_buffers; 119 + }; 120 + 121 + static inline struct fsg_opts * 122 + fsg_opts_from_func_inst(const struct usb_function_instance *fi) 123 + { 124 + return container_of(fi, struct fsg_opts, func_inst); 125 + } 126 + 127 + void fsg_common_get(struct fsg_common *common); 128 + 129 + void fsg_common_put(struct fsg_common *common); 130 + 131 + void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs); 132 + 133 + int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n); 134 + 135 + void fsg_common_free_buffers(struct fsg_common *common); 136 + 137 + int fsg_common_set_cdev(struct fsg_common *common, 138 + struct usb_composite_dev *cdev, bool can_stall); 139 + 140 + void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs); 141 + 142 + void fsg_common_remove_luns(struct fsg_common *common); 143 + 144 + void fsg_common_free_luns(struct fsg_common *common); 145 + 146 + int fsg_common_set_nluns(struct fsg_common *common, int nluns); 147 + 148 + void fsg_common_set_ops(struct fsg_common *common, 149 + const struct fsg_operations *ops); 150 + 151 + int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, 152 + unsigned int id, const char *name, 153 + const char **name_pfx); 154 + 155 + int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg); 156 + 157 + void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn, 158 + const char *pn); 159 + 160 + int fsg_common_run_thread(struct fsg_common *common); 161 + 162 + void fsg_config_from_params(struct fsg_config *cfg, 163 + const struct fsg_module_parameters *params, 164 + unsigned int fsg_num_buffers); 165 + 166 + #endif /* USB_F_MASS_STORAGE_H */
+101 -24
drivers/usb/gadget/mass_storage.c
··· 37 37 #define DRIVER_DESC "Mass Storage Gadget" 38 38 #define DRIVER_VERSION "2009/09/11" 39 39 40 - /*-------------------------------------------------------------------------*/ 41 - 42 40 /* 43 - * kbuild is not very cooperative with respect to linking separately 44 - * compiled library objects into one module. So for now we won't use 45 - * separate compilation ... ensuring init/exit sections work to shrink 46 - * the runtime footprint, and giving us at least some parts of what 47 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 41 + * Thanks to NetChip Technologies for donating this product ID. 42 + * 43 + * DO NOT REUSE THESE IDs with any other driver!! Ever!! 44 + * Instead: allocate your own, using normal USB-IF procedures. 48 45 */ 49 - #include "f_mass_storage.c" 46 + #define FSG_VENDOR_ID 0x0525 /* NetChip */ 47 + #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ 48 + 49 + #include "f_mass_storage.h" 50 50 51 51 /*-------------------------------------------------------------------------*/ 52 52 USB_GADGET_COMPOSITE_OPTIONS(); ··· 97 97 NULL, 98 98 }; 99 99 100 + static struct usb_function_instance *fi_msg; 101 + static struct usb_function *f_msg; 102 + 100 103 /****************************** Configurations ******************************/ 101 104 102 105 static struct fsg_module_parameters mod_data = { 103 106 .stall = 1 104 107 }; 108 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 109 + 110 + static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; 111 + 112 + #else 113 + 114 + /* 115 + * Number of buffers we will use. 116 + * 2 is usually enough for good buffering pipeline 117 + */ 118 + #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS 119 + 120 + #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 121 + 105 122 FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); 106 123 107 124 static unsigned long msg_registered; ··· 132 115 133 116 static int __init msg_do_config(struct usb_configuration *c) 134 117 { 135 - static const struct fsg_operations ops = { 136 - .thread_exits = msg_thread_exits, 137 - }; 138 - static struct fsg_common common; 139 - 140 - struct fsg_common *retp; 141 - struct fsg_config config; 118 + struct fsg_opts *opts; 142 119 int ret; 143 120 144 121 if (gadget_is_otg(c->cdev->gadget)) { ··· 140 129 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 141 130 } 142 131 143 - fsg_config_from_params(&config, &mod_data); 144 - config.ops = &ops; 132 + opts = fsg_opts_from_func_inst(fi_msg); 145 133 146 - retp = fsg_common_init(&common, c->cdev, &config); 147 - if (IS_ERR(retp)) 148 - return PTR_ERR(retp); 134 + f_msg = usb_get_function(fi_msg); 135 + if (IS_ERR(f_msg)) 136 + return PTR_ERR(f_msg); 149 137 150 - ret = fsg_bind_config(c->cdev, c, &common); 151 - fsg_common_put(&common); 138 + ret = fsg_common_run_thread(opts->common); 139 + if (ret) 140 + goto put_func; 141 + 142 + ret = usb_add_function(c, f_msg); 143 + if (ret) 144 + goto put_func; 145 + 146 + return 0; 147 + 148 + put_func: 149 + usb_put_function(f_msg); 152 150 return ret; 153 151 } 154 152 ··· 172 152 173 153 static int __init msg_bind(struct usb_composite_dev *cdev) 174 154 { 155 + static const struct fsg_operations ops = { 156 + .thread_exits = msg_thread_exits, 157 + }; 158 + struct fsg_opts *opts; 159 + struct fsg_config config; 175 160 int status; 161 + 162 + fi_msg = usb_get_function_instance("mass_storage"); 163 + if (IS_ERR(fi_msg)) 164 + return PTR_ERR(fi_msg); 165 + 166 + fsg_config_from_params(&config, &mod_data, fsg_num_buffers); 167 + opts = fsg_opts_from_func_inst(fi_msg); 168 + 169 + opts->no_configfs = true; 170 + status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers); 171 + if (status) 172 + goto fail; 173 + 174 + status = fsg_common_set_nluns(opts->common, config.nluns); 175 + if (status) 176 + goto fail_set_nluns; 177 + 178 + fsg_common_set_ops(opts->common, &ops); 179 + 180 + status = fsg_common_set_cdev(opts->common, cdev, config.can_stall); 181 + if (status) 182 + goto fail_set_cdev; 183 + 184 + fsg_common_set_sysfs(opts->common, true); 185 + status = fsg_common_create_luns(opts->common, &config); 186 + if (status) 187 + goto fail_set_cdev; 188 + 189 + fsg_common_set_inquiry_string(opts->common, config.vendor_name, 190 + config.product_name); 176 191 177 192 status = usb_string_ids_tab(cdev, strings_dev); 178 193 if (status < 0) 179 - return status; 194 + goto fail_string_ids; 180 195 msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 181 196 182 197 status = usb_add_config(cdev, &msg_config_driver, msg_do_config); 183 198 if (status < 0) 184 - return status; 199 + goto fail_string_ids; 200 + 185 201 usb_composite_overwrite_options(cdev, &coverwrite); 186 202 dev_info(&cdev->gadget->dev, 187 203 DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 188 204 set_bit(0, &msg_registered); 189 205 return 0; 206 + 207 + fail_string_ids: 208 + fsg_common_remove_luns(opts->common); 209 + fail_set_cdev: 210 + fsg_common_free_luns(opts->common); 211 + fail_set_nluns: 212 + fsg_common_free_buffers(opts->common); 213 + fail: 214 + usb_put_function_instance(fi_msg); 215 + return status; 190 216 } 191 217 218 + static int msg_unbind(struct usb_composite_dev *cdev) 219 + { 220 + if (!IS_ERR(f_msg)) 221 + usb_put_function(f_msg); 222 + 223 + if (!IS_ERR(fi_msg)) 224 + usb_put_function_instance(fi_msg); 225 + 226 + return 0; 227 + } 192 228 193 229 /****************************** Some noise ******************************/ 194 230 ··· 255 179 .needs_serial = 1, 256 180 .strings = dev_strings, 257 181 .bind = msg_bind, 182 + .unbind = msg_unbind, 258 183 }; 259 184 260 185 MODULE_DESCRIPTION(DRIVER_DESC);
+198 -51
drivers/usb/gadget/multi.c
··· 15 15 16 16 #include <linux/kernel.h> 17 17 #include <linux/module.h> 18 + #include <linux/netdevice.h> 18 19 19 20 #include "u_serial.h" 20 21 #if defined USB_ETH_RNDIS ··· 33 32 MODULE_LICENSE("GPL"); 34 33 35 34 36 - /***************************** All the files... *****************************/ 35 + #include "f_mass_storage.h" 37 36 38 - /* 39 - * kbuild is not very cooperative with respect to linking separately 40 - * compiled library objects into one module. So for now we won't use 41 - * separate compilation ... ensuring init/exit sections work to shrink 42 - * the runtime footprint, and giving us at least some parts of what 43 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 44 - */ 45 - #include "f_mass_storage.c" 46 - 47 - #define USBF_ECM_INCLUDED 48 - #include "f_ecm.c" 37 + #include "u_ecm.h" 49 38 #ifdef USB_ETH_RNDIS 50 - # define USB_FRNDIS_INCLUDED 51 - # include "f_rndis.c" 39 + # include "u_rndis.h" 52 40 # include "rndis.h" 53 41 #endif 54 42 #include "u_ether.h" ··· 122 132 /****************************** Configurations ******************************/ 123 133 124 134 static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; 135 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 136 + 137 + static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; 138 + 139 + #else 140 + 141 + /* 142 + * Number of buffers we will use. 143 + * 2 is usually enough for good buffering pipeline 144 + */ 145 + #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS 146 + 147 + #endif /* CONFIG_USB_DEBUG */ 148 + 125 149 FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); 126 150 127 - static struct fsg_common fsg_common; 128 - 129 - static u8 host_mac[ETH_ALEN]; 130 - 131 151 static struct usb_function_instance *fi_acm; 132 - static struct eth_dev *the_dev; 152 + static struct usb_function_instance *fi_msg; 133 153 134 154 /********** RNDIS **********/ 135 155 136 156 #ifdef USB_ETH_RNDIS 157 + static struct usb_function_instance *fi_rndis; 137 158 static struct usb_function *f_acm_rndis; 159 + static struct usb_function *f_rndis; 160 + static struct usb_function *f_msg_rndis; 138 161 139 162 static __init int rndis_do_config(struct usb_configuration *c) 140 163 { 164 + struct fsg_opts *fsg_opts; 141 165 int ret; 142 166 143 167 if (gadget_is_otg(c->cdev->gadget)) { ··· 159 155 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 160 156 } 161 157 162 - ret = rndis_bind_config(c, host_mac, the_dev); 158 + f_rndis = usb_get_function(fi_rndis); 159 + if (IS_ERR(f_rndis)) 160 + return PTR_ERR(f_rndis); 161 + 162 + ret = usb_add_function(c, f_rndis); 163 163 if (ret < 0) 164 - return ret; 164 + goto err_func_rndis; 165 165 166 166 f_acm_rndis = usb_get_function(fi_acm); 167 - if (IS_ERR(f_acm_rndis)) 168 - return PTR_ERR(f_acm_rndis); 167 + if (IS_ERR(f_acm_rndis)) { 168 + ret = PTR_ERR(f_acm_rndis); 169 + goto err_func_acm; 170 + } 169 171 170 172 ret = usb_add_function(c, f_acm_rndis); 171 173 if (ret) 172 174 goto err_conf; 173 175 174 - ret = fsg_bind_config(c->cdev, c, &fsg_common); 175 - if (ret < 0) 176 + f_msg_rndis = usb_get_function(fi_msg); 177 + if (IS_ERR(f_msg_rndis)) { 178 + ret = PTR_ERR(f_msg_rndis); 176 179 goto err_fsg; 180 + } 181 + 182 + fsg_opts = fsg_opts_from_func_inst(fi_msg); 183 + ret = fsg_common_run_thread(fsg_opts->common); 184 + if (ret) 185 + goto err_run; 186 + 187 + ret = usb_add_function(c, f_msg_rndis); 188 + if (ret) 189 + goto err_run; 177 190 178 191 return 0; 192 + err_run: 193 + usb_put_function(f_msg_rndis); 179 194 err_fsg: 180 195 usb_remove_function(c, f_acm_rndis); 181 196 err_conf: 182 197 usb_put_function(f_acm_rndis); 198 + err_func_acm: 199 + usb_remove_function(c, f_rndis); 200 + err_func_rndis: 201 + usb_put_function(f_rndis); 183 202 return ret; 184 203 } 185 204 ··· 232 205 /********** CDC ECM **********/ 233 206 234 207 #ifdef CONFIG_USB_G_MULTI_CDC 208 + static struct usb_function_instance *fi_ecm; 235 209 static struct usb_function *f_acm_multi; 210 + static struct usb_function *f_ecm; 211 + static struct usb_function *f_msg_multi; 236 212 237 213 static __init int cdc_do_config(struct usb_configuration *c) 238 214 { 215 + struct fsg_opts *fsg_opts; 239 216 int ret; 240 217 241 218 if (gadget_is_otg(c->cdev->gadget)) { ··· 247 216 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 248 217 } 249 218 250 - ret = ecm_bind_config(c, host_mac, the_dev); 219 + f_ecm = usb_get_function(fi_ecm); 220 + if (IS_ERR(f_ecm)) 221 + return PTR_ERR(f_ecm); 222 + 223 + ret = usb_add_function(c, f_ecm); 251 224 if (ret < 0) 252 - return ret; 225 + goto err_func_ecm; 253 226 254 227 /* implicit port_num is zero */ 255 228 f_acm_multi = usb_get_function(fi_acm); 256 - if (IS_ERR(f_acm_multi)) 257 - return PTR_ERR(f_acm_multi); 229 + if (IS_ERR(f_acm_multi)) { 230 + ret = PTR_ERR(f_acm_multi); 231 + goto err_func_acm; 232 + } 258 233 259 234 ret = usb_add_function(c, f_acm_multi); 260 235 if (ret) 261 236 goto err_conf; 262 237 263 - ret = fsg_bind_config(c->cdev, c, &fsg_common); 264 - if (ret < 0) 238 + f_msg_multi = usb_get_function(fi_msg); 239 + if (IS_ERR(f_msg_multi)) { 240 + ret = PTR_ERR(f_msg_multi); 265 241 goto err_fsg; 242 + } 243 + 244 + fsg_opts = fsg_opts_from_func_inst(fi_msg); 245 + ret = fsg_common_run_thread(fsg_opts->common); 246 + if (ret) 247 + goto err_run; 248 + 249 + ret = usb_add_function(c, f_msg_multi); 250 + if (ret) 251 + goto err_run; 266 252 267 253 return 0; 254 + err_run: 255 + usb_put_function(f_msg_multi); 268 256 err_fsg: 269 257 usb_remove_function(c, f_acm_multi); 270 258 err_conf: 271 259 usb_put_function(f_acm_multi); 260 + err_func_acm: 261 + usb_remove_function(c, f_ecm); 262 + err_func_ecm: 263 + usb_put_function(f_ecm); 272 264 return ret; 273 265 } 274 266 ··· 324 270 static int __ref multi_bind(struct usb_composite_dev *cdev) 325 271 { 326 272 struct usb_gadget *gadget = cdev->gadget; 273 + #ifdef CONFIG_USB_G_MULTI_CDC 274 + struct f_ecm_opts *ecm_opts; 275 + #endif 276 + #ifdef USB_ETH_RNDIS 277 + struct f_rndis_opts *rndis_opts; 278 + #endif 279 + struct fsg_opts *fsg_opts; 280 + struct fsg_config config; 327 281 int status; 328 282 329 283 if (!can_support_ecm(cdev->gadget)) { 330 284 dev_err(&gadget->dev, "controller '%s' not usable\n", 331 - gadget->name); 285 + gadget->name); 332 286 return -EINVAL; 333 287 } 334 288 335 - /* set up network link layer */ 336 - the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac, 337 - qmult); 338 - if (IS_ERR(the_dev)) 339 - return PTR_ERR(the_dev); 289 + #ifdef CONFIG_USB_G_MULTI_CDC 290 + fi_ecm = usb_get_function_instance("ecm"); 291 + if (IS_ERR(fi_ecm)) 292 + return PTR_ERR(fi_ecm); 293 + 294 + ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); 295 + 296 + gether_set_qmult(ecm_opts->net, qmult); 297 + if (!gether_set_host_addr(ecm_opts->net, host_addr)) 298 + pr_info("using host ethernet address: %s", host_addr); 299 + if (!gether_set_dev_addr(ecm_opts->net, dev_addr)) 300 + pr_info("using self ethernet address: %s", dev_addr); 301 + #endif 302 + 303 + #ifdef USB_ETH_RNDIS 304 + fi_rndis = usb_get_function_instance("rndis"); 305 + if (IS_ERR(fi_rndis)) { 306 + status = PTR_ERR(fi_rndis); 307 + goto fail; 308 + } 309 + 310 + rndis_opts = container_of(fi_rndis, struct f_rndis_opts, func_inst); 311 + 312 + gether_set_qmult(rndis_opts->net, qmult); 313 + if (!gether_set_host_addr(rndis_opts->net, host_addr)) 314 + pr_info("using host ethernet address: %s", host_addr); 315 + if (!gether_set_dev_addr(rndis_opts->net, dev_addr)) 316 + pr_info("using self ethernet address: %s", dev_addr); 317 + #endif 318 + 319 + #if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS) 320 + /* 321 + * If both ecm and rndis are selected then: 322 + * 1) rndis borrows the net interface from ecm 323 + * 2) since the interface is shared it must not be bound 324 + * twice - in ecm's _and_ rndis' binds, so do it here. 325 + */ 326 + gether_set_gadget(ecm_opts->net, cdev->gadget); 327 + status = gether_register_netdev(ecm_opts->net); 328 + if (status) 329 + goto fail0; 330 + 331 + rndis_borrow_net(fi_rndis, ecm_opts->net); 332 + ecm_opts->bound = true; 333 + #endif 340 334 341 335 /* set up serial link layer */ 342 336 fi_acm = usb_get_function_instance("acm"); ··· 394 292 } 395 293 396 294 /* set up mass storage function */ 397 - { 398 - void *retp; 399 - retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 400 - if (IS_ERR(retp)) { 401 - status = PTR_ERR(retp); 402 - goto fail1; 403 - } 295 + fi_msg = usb_get_function_instance("mass_storage"); 296 + if (IS_ERR(fi_msg)) { 297 + status = PTR_ERR(fi_msg); 298 + goto fail1; 404 299 } 300 + fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers); 301 + fsg_opts = fsg_opts_from_func_inst(fi_msg); 302 + 303 + fsg_opts->no_configfs = true; 304 + status = fsg_common_set_num_buffers(fsg_opts->common, fsg_num_buffers); 305 + if (status) 306 + goto fail2; 307 + 308 + status = fsg_common_set_nluns(fsg_opts->common, config.nluns); 309 + if (status) 310 + goto fail_set_nluns; 311 + 312 + status = fsg_common_set_cdev(fsg_opts->common, cdev, config.can_stall); 313 + if (status) 314 + goto fail_set_cdev; 315 + 316 + fsg_common_set_sysfs(fsg_opts->common, true); 317 + status = fsg_common_create_luns(fsg_opts->common, &config); 318 + if (status) 319 + goto fail_set_cdev; 320 + 321 + fsg_common_set_inquiry_string(fsg_opts->common, config.vendor_name, 322 + config.product_name); 405 323 406 324 /* allocate string IDs */ 407 325 status = usb_string_ids_tab(cdev, strings_dev); 408 326 if (unlikely(status < 0)) 409 - goto fail2; 327 + goto fail_string_ids; 410 328 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 411 329 412 330 /* register configurations */ 413 331 status = rndis_config_register(cdev); 414 332 if (unlikely(status < 0)) 415 - goto fail2; 333 + goto fail_string_ids; 416 334 417 335 status = cdc_config_register(cdev); 418 336 if (unlikely(status < 0)) 419 - goto fail2; 337 + goto fail_string_ids; 420 338 usb_composite_overwrite_options(cdev, &coverwrite); 421 339 422 340 /* we're done */ 423 341 dev_info(&gadget->dev, DRIVER_DESC "\n"); 424 - fsg_common_put(&fsg_common); 425 342 return 0; 426 343 427 344 428 345 /* error recovery */ 346 + fail_string_ids: 347 + fsg_common_remove_luns(fsg_opts->common); 348 + fail_set_cdev: 349 + fsg_common_free_luns(fsg_opts->common); 350 + fail_set_nluns: 351 + fsg_common_free_buffers(fsg_opts->common); 429 352 fail2: 430 - fsg_common_put(&fsg_common); 353 + usb_put_function_instance(fi_msg); 431 354 fail1: 432 355 usb_put_function_instance(fi_acm); 433 356 fail0: 434 - gether_cleanup(the_dev); 357 + #ifdef USB_ETH_RNDIS 358 + usb_put_function_instance(fi_rndis); 359 + fail: 360 + #endif 361 + #ifdef CONFIG_USB_G_MULTI_CDC 362 + usb_put_function_instance(fi_ecm); 363 + #endif 435 364 return status; 436 365 } 437 366 438 367 static int __exit multi_unbind(struct usb_composite_dev *cdev) 439 368 { 369 + #ifdef CONFIG_USB_G_MULTI_CDC 370 + usb_put_function(f_msg_multi); 371 + #endif 372 + #ifdef USB_ETH_RNDIS 373 + usb_put_function(f_msg_rndis); 374 + #endif 375 + usb_put_function_instance(fi_msg); 440 376 #ifdef CONFIG_USB_G_MULTI_CDC 441 377 usb_put_function(f_acm_multi); 442 378 #endif ··· 482 342 usb_put_function(f_acm_rndis); 483 343 #endif 484 344 usb_put_function_instance(fi_acm); 485 - gether_cleanup(the_dev); 345 + #ifdef USB_ETH_RNDIS 346 + usb_put_function(f_rndis); 347 + usb_put_function_instance(fi_rndis); 348 + #endif 349 + #ifdef CONFIG_USB_G_MULTI_CDC 350 + usb_put_function(f_ecm); 351 + usb_put_function_instance(fi_ecm); 352 + #endif 486 353 return 0; 487 354 } 488 355
+2
drivers/usb/gadget/mv_u3d_core.c
··· 310 310 */ 311 311 trb_hw = dma_pool_alloc(u3d->trb_pool, GFP_ATOMIC, dma); 312 312 if (!trb_hw) { 313 + kfree(trb); 313 314 dev_err(u3d->dev, 314 315 "%s, dma_pool_alloc fail\n", __func__); 315 316 return NULL; ··· 455 454 456 455 trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC); 457 456 if (!trb_hw) { 457 + kfree(trb); 458 458 dev_err(u3d->dev, 459 459 "%s, trb_hw alloc fail\n", __func__); 460 460 return -ENOMEM;
+124 -43
drivers/usb/gadget/s3c-hsotg.c
··· 83 83 * @dir_in: Set to true if this endpoint is of the IN direction, which 84 84 * means that it is sending data to the Host. 85 85 * @index: The index for the endpoint registers. 86 + * @mc: Multi Count - number of transactions per microframe 87 + * @interval - Interval for periodic endpoints 86 88 * @name: The name array passed to the USB core. 87 89 * @halted: Set if the endpoint has been halted. 88 90 * @periodic: Set if this is a periodic ep, such as Interrupt 91 + * @isochronous: Set if this is a isochronous ep 89 92 * @sent_zlp: Set if we've sent a zero-length packet. 90 93 * @total_data: The total number of data bytes done. 91 94 * @fifo_size: The size of the FIFO (for periodic IN endpoints) ··· 124 121 125 122 unsigned char dir_in; 126 123 unsigned char index; 124 + unsigned char mc; 125 + unsigned char interval; 127 126 128 127 unsigned int halted:1; 129 128 unsigned int periodic:1; 129 + unsigned int isochronous:1; 130 130 unsigned int sent_zlp:1; 131 131 132 132 char name[10]; ··· 474 468 void *data; 475 469 int can_write; 476 470 int pkt_round; 471 + int max_transfer; 477 472 478 473 to_write -= (buf_pos - hs_ep->last_load); 479 474 ··· 542 535 can_write *= 4; /* fifo size is in 32bit quantities. */ 543 536 } 544 537 545 - dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", 546 - __func__, gnptxsts, can_write, to_write, hs_ep->ep.maxpacket); 538 + max_transfer = hs_ep->ep.maxpacket * hs_ep->mc; 539 + 540 + dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n", 541 + __func__, gnptxsts, can_write, to_write, max_transfer); 547 542 548 543 /* 549 544 * limit to 512 bytes of data, it seems at least on the non-periodic ··· 560 551 * the transfer to return that it did not run out of fifo space 561 552 * doing it. 562 553 */ 563 - if (to_write > hs_ep->ep.maxpacket) { 564 - to_write = hs_ep->ep.maxpacket; 554 + if (to_write > max_transfer) { 555 + to_write = max_transfer; 565 556 566 - s3c_hsotg_en_gsint(hsotg, 567 - periodic ? GINTSTS_PTxFEmp : 568 - GINTSTS_NPTxFEmp); 557 + /* it's needed only when we do not use dedicated fifos */ 558 + if (!hsotg->dedicated_fifos) 559 + s3c_hsotg_en_gsint(hsotg, 560 + periodic ? GINTSTS_PTxFEmp : 561 + GINTSTS_NPTxFEmp); 569 562 } 570 563 571 564 /* see if we can write data */ 572 565 573 566 if (to_write > can_write) { 574 567 to_write = can_write; 575 - pkt_round = to_write % hs_ep->ep.maxpacket; 568 + pkt_round = to_write % max_transfer; 576 569 577 570 /* 578 571 * Round the write down to an ··· 592 581 * is more room left. 593 582 */ 594 583 595 - s3c_hsotg_en_gsint(hsotg, 596 - periodic ? GINTSTS_PTxFEmp : 597 - GINTSTS_NPTxFEmp); 584 + /* it's needed only when we do not use dedicated fifos */ 585 + if (!hsotg->dedicated_fifos) 586 + s3c_hsotg_en_gsint(hsotg, 587 + periodic ? GINTSTS_PTxFEmp : 588 + GINTSTS_NPTxFEmp); 598 589 } 599 590 600 591 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", ··· 740 727 else 741 728 packets = 1; /* send one packet if length is zero. */ 742 729 730 + if (hs_ep->isochronous && length > (hs_ep->mc * hs_ep->ep.maxpacket)) { 731 + dev_err(hsotg->dev, "req length > maxpacket*mc\n"); 732 + return; 733 + } 734 + 743 735 if (dir_in && index != 0) 744 - epsize = DxEPTSIZ_MC(1); 736 + if (hs_ep->isochronous) 737 + epsize = DxEPTSIZ_MC(packets); 738 + else 739 + epsize = DxEPTSIZ_MC(1); 745 740 else 746 741 epsize = 0; 747 742 ··· 841 820 842 821 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", 843 822 __func__, readl(hsotg->regs + epctrl_reg)); 823 + 824 + /* enable ep interrupts */ 825 + s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1); 844 826 } 845 827 846 828 /** ··· 1115 1091 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); 1116 1092 struct s3c_hsotg_ep *ep; 1117 1093 int ret; 1094 + bool halted; 1118 1095 1119 1096 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", 1120 1097 __func__, set ? "SET" : "CLEAR"); ··· 1130 1105 1131 1106 switch (le16_to_cpu(ctrl->wValue)) { 1132 1107 case USB_ENDPOINT_HALT: 1108 + halted = ep->halted; 1109 + 1133 1110 s3c_hsotg_ep_sethalt(&ep->ep, set); 1134 1111 1135 1112 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); ··· 1141 1114 return ret; 1142 1115 } 1143 1116 1144 - if (!set) { 1117 + /* 1118 + * we have to complete all requests for ep if it was 1119 + * halted, and the halt was cleared by CLEAR_FEATURE 1120 + */ 1121 + 1122 + if (!set && halted) { 1145 1123 /* 1146 1124 * If we have request in progress, 1147 1125 * then complete it ··· 1178 1146 1179 1147 return 1; 1180 1148 } 1149 + 1150 + static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg); 1181 1151 1182 1152 /** 1183 1153 * s3c_hsotg_process_control - process a control request ··· 1280 1246 * don't believe we need to anything more to get the EP 1281 1247 * to reply with a STALL packet 1282 1248 */ 1249 + 1250 + /* 1251 + * complete won't be called, so we enqueue 1252 + * setup request here 1253 + */ 1254 + s3c_hsotg_enqueue_setup(hsotg); 1283 1255 } 1284 1256 } 1285 - 1286 - static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg); 1287 1257 1288 1258 /** 1289 1259 * s3c_hsotg_complete_setup - completion of a setup transfer ··· 1736 1698 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; 1737 1699 void __iomem *regs = hsotg->regs; 1738 1700 u32 mpsval; 1701 + u32 mcval; 1739 1702 u32 reg; 1740 1703 1741 1704 if (ep == 0) { ··· 1744 1705 mpsval = s3c_hsotg_ep0_mps(mps); 1745 1706 if (mpsval > 3) 1746 1707 goto bad_mps; 1708 + hs_ep->ep.maxpacket = mps; 1709 + hs_ep->mc = 1; 1747 1710 } else { 1748 - if (mps >= DxEPCTL_MPS_LIMIT+1) 1711 + mpsval = mps & DxEPCTL_MPS_MASK; 1712 + if (mpsval > 1024) 1749 1713 goto bad_mps; 1750 - 1751 - mpsval = mps; 1714 + mcval = ((mps >> 11) & 0x3) + 1; 1715 + hs_ep->mc = mcval; 1716 + if (mcval > 3) 1717 + goto bad_mps; 1718 + hs_ep->ep.maxpacket = mpsval; 1752 1719 } 1753 - 1754 - hs_ep->ep.maxpacket = mps; 1755 1720 1756 1721 /* 1757 1722 * update both the in and out endpoint controldir_ registers, even ··· 1825 1782 { 1826 1783 struct s3c_hsotg_req *hs_req = hs_ep->req; 1827 1784 1828 - if (!hs_ep->dir_in || !hs_req) 1785 + if (!hs_ep->dir_in || !hs_req) { 1786 + /** 1787 + * if request is not enqueued, we disable interrupts 1788 + * for endpoints, excepting ep0 1789 + */ 1790 + if (hs_ep->index != 0) 1791 + s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, 1792 + hs_ep->dir_in, 0); 1829 1793 return 0; 1794 + } 1830 1795 1831 1796 if (hs_req->req.actual < hs_req->req.length) { 1832 1797 dev_dbg(hsotg->dev, "trying to write more for ep%d\n", ··· 1938 1887 u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); 1939 1888 u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx); 1940 1889 u32 ints; 1890 + u32 ctrl; 1941 1891 1942 1892 ints = readl(hsotg->regs + epint_reg); 1893 + ctrl = readl(hsotg->regs + epctl_reg); 1943 1894 1944 1895 /* Clear endpoint interrupts */ 1945 1896 writel(ints, hsotg->regs + epint_reg); ··· 1950 1897 __func__, idx, dir_in ? "in" : "out", ints); 1951 1898 1952 1899 if (ints & DxEPINT_XferCompl) { 1900 + if (hs_ep->isochronous && hs_ep->interval == 1) { 1901 + if (ctrl & DxEPCTL_EOFrNum) 1902 + ctrl |= DxEPCTL_SetEvenFr; 1903 + else 1904 + ctrl |= DxEPCTL_SetOddFr; 1905 + writel(ctrl, hsotg->regs + epctl_reg); 1906 + } 1907 + 1953 1908 dev_dbg(hsotg->dev, 1954 1909 "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n", 1955 1910 __func__, readl(hsotg->regs + epctl_reg), ··· 2024 1963 if (ints & DxEPINT_Back2BackSetup) 2025 1964 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); 2026 1965 2027 - if (dir_in) { 1966 + if (dir_in && !hs_ep->isochronous) { 2028 1967 /* not sure if this is important, but we'll clear it anyway */ 2029 1968 if (ints & DIEPMSK_INTknTXFEmpMsk) { 2030 1969 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", ··· 2153 2092 } 2154 2093 2155 2094 #define call_gadget(_hs, _entry) \ 2095 + do { \ 2156 2096 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ 2157 2097 (_hs)->driver && (_hs)->driver->_entry) { \ 2158 2098 spin_unlock(&_hs->lock); \ 2159 2099 (_hs)->driver->_entry(&(_hs)->gadget); \ 2160 2100 spin_lock(&_hs->lock); \ 2161 - } 2101 + } \ 2102 + } while (0) 2162 2103 2163 2104 /** 2164 2105 * s3c_hsotg_disconnect - disconnect service ··· 2304 2241 GAHBCFG_HBstLen_Incr4, 2305 2242 hsotg->regs + GAHBCFG); 2306 2243 else 2307 - writel(GAHBCFG_GlblIntrEn, hsotg->regs + GAHBCFG); 2244 + writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NPTxFEmpLvl | 2245 + GAHBCFG_PTxFEmpLvl) : 0) | 2246 + GAHBCFG_GlblIntrEn, 2247 + hsotg->regs + GAHBCFG); 2308 2248 2309 2249 /* 2310 - * Enabling INTknTXFEmpMsk here seems to be a big mistake, we end 2311 - * up being flooded with interrupts if the host is polling the 2312 - * endpoint to try and read data. 2250 + * If INTknTXFEmpMsk is enabled, it's important to disable ep interrupts 2251 + * when we have no data to transfer. Otherwise we get being flooded by 2252 + * interrupts. 2313 2253 */ 2314 2254 2315 - writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty : 0) | 2255 + writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty | 2256 + DIEPMSK_INTknTXFEmpMsk : 0) | 2316 2257 DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk | 2317 2258 DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk | 2318 2259 DIEPMSK_INTknEPMisMsk, ··· 2445 2378 2446 2379 if (gintsts & (GINTSTS_OEPInt | GINTSTS_IEPInt)) { 2447 2380 u32 daint = readl(hsotg->regs + DAINT); 2448 - u32 daint_out = daint >> DAINT_OutEP_SHIFT; 2449 - u32 daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT); 2381 + u32 daintmsk = readl(hsotg->regs + DAINTMSK); 2382 + u32 daint_out, daint_in; 2450 2383 int ep; 2384 + 2385 + daint &= daintmsk; 2386 + daint_out = daint >> DAINT_OutEP_SHIFT; 2387 + daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT); 2451 2388 2452 2389 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); 2453 2390 ··· 2648 2577 epctrl |= DxEPCTL_SNAK; 2649 2578 2650 2579 /* update the endpoint state */ 2651 - hs_ep->ep.maxpacket = mps; 2580 + s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps); 2652 2581 2653 2582 /* default, set to non-periodic */ 2583 + hs_ep->isochronous = 0; 2654 2584 hs_ep->periodic = 0; 2585 + hs_ep->halted = 0; 2586 + hs_ep->interval = desc->bInterval; 2587 + 2588 + if (hs_ep->interval > 1 && hs_ep->mc > 1) 2589 + dev_err(hsotg->dev, "MC > 1 when interval is not 1\n"); 2655 2590 2656 2591 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 2657 2592 case USB_ENDPOINT_XFER_ISOC: 2658 - dev_err(hsotg->dev, "no current ISOC support\n"); 2659 - ret = -EINVAL; 2660 - goto out; 2593 + epctrl |= DxEPCTL_EPType_Iso; 2594 + epctrl |= DxEPCTL_SetEvenFr; 2595 + hs_ep->isochronous = 1; 2596 + if (dir_in) 2597 + hs_ep->periodic = 1; 2598 + break; 2661 2599 2662 2600 case USB_ENDPOINT_XFER_BULK: 2663 2601 epctrl |= DxEPCTL_EPType_Bulk; ··· 2714 2634 /* enable the endpoint interrupt */ 2715 2635 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); 2716 2636 2717 - out: 2718 2637 spin_unlock_irqrestore(&hsotg->lock, flags); 2719 2638 return ret; 2720 2639 } ··· 2855 2776 2856 2777 writel(epctl, hs->regs + epreg); 2857 2778 2779 + hs_ep->halted = value; 2780 + 2858 2781 return 0; 2859 2782 } 2860 2783 ··· 2984 2903 int ret; 2985 2904 2986 2905 if (!hsotg) { 2987 - printk(KERN_ERR "%s: called with no device\n", __func__); 2906 + pr_err("%s: called with no device\n", __func__); 2988 2907 return -ENODEV; 2989 2908 } 2990 2909 ··· 3147 3066 3148 3067 hs_ep->parent = hsotg; 3149 3068 hs_ep->ep.name = hs_ep->name; 3150 - hs_ep->ep.maxpacket = epnum ? 512 : EP0_MPS_LIMIT; 3069 + hs_ep->ep.maxpacket = epnum ? 1024 : EP0_MPS_LIMIT; 3151 3070 hs_ep->ep.ops = &s3c_hsotg_ep_ops; 3152 3071 3153 3072 /* ··· 3281 3200 readl(regs + GNPTXSTS), 3282 3201 readl(regs + GRXSTSR)); 3283 3202 3284 - seq_printf(seq, "\nEndpoint status:\n"); 3203 + seq_puts(seq, "\nEndpoint status:\n"); 3285 3204 3286 3205 for (idx = 0; idx < 15; idx++) { 3287 3206 u32 in, out; ··· 3298 3217 seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", 3299 3218 in, out); 3300 3219 3301 - seq_printf(seq, "\n"); 3220 + seq_puts(seq, "\n"); 3302 3221 } 3303 3222 3304 3223 return 0; ··· 3332 3251 u32 val; 3333 3252 int idx; 3334 3253 3335 - seq_printf(seq, "Non-periodic FIFOs:\n"); 3254 + seq_puts(seq, "Non-periodic FIFOs:\n"); 3336 3255 seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); 3337 3256 3338 3257 val = readl(regs + GNPTXFSIZ); ··· 3340 3259 val >> GNPTXFSIZ_NPTxFDep_SHIFT, 3341 3260 val & GNPTXFSIZ_NPTxFStAddr_MASK); 3342 3261 3343 - seq_printf(seq, "\nPeriodic TXFIFOs:\n"); 3262 + seq_puts(seq, "\nPeriodic TXFIFOs:\n"); 3344 3263 3345 3264 for (idx = 1; idx <= 15; idx++) { 3346 3265 val = readl(regs + DPTXFSIZn(idx)); ··· 3411 3330 readl(regs + DIEPTSIZ(index)), 3412 3331 readl(regs + DOEPTSIZ(index))); 3413 3332 3414 - seq_printf(seq, "\n"); 3333 + seq_puts(seq, "\n"); 3415 3334 seq_printf(seq, "mps %d\n", ep->ep.maxpacket); 3416 3335 seq_printf(seq, "total_data=%ld\n", ep->total_data); 3417 3336 ··· 3422 3341 3423 3342 list_for_each_entry(req, &ep->queue, queue) { 3424 3343 if (--show_limit < 0) { 3425 - seq_printf(seq, "not showing more requests...\n"); 3344 + seq_puts(seq, "not showing more requests...\n"); 3426 3345 break; 3427 3346 } 3428 3347
+129 -301
drivers/usb/gadget/storage_common.c
··· 23 23 * The valid range of num_buffers is: num >= 2 && num <= 4. 24 24 */ 25 25 26 + #include <linux/module.h> 27 + #include <linux/blkdev.h> 28 + #include <linux/file.h> 29 + #include <linux/fs.h> 30 + #include <linux/usb/composite.h> 26 31 27 - #include <linux/usb/storage.h> 28 - #include <scsi/scsi.h> 29 - #include <asm/unaligned.h> 30 - 31 - 32 - /* 33 - * Thanks to NetChip Technologies for donating this product ID. 34 - * 35 - * DO NOT REUSE THESE IDs with any other driver!! Ever!! 36 - * Instead: allocate your own, using normal USB-IF procedures. 37 - */ 38 - #define FSG_VENDOR_ID 0x0525 /* NetChip */ 39 - #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ 40 - 41 - 42 - /*-------------------------------------------------------------------------*/ 43 - 44 - 45 - #ifndef DEBUG 46 - #undef VERBOSE_DEBUG 47 - #undef DUMP_MSGS 48 - #endif /* !DEBUG */ 49 - 50 - #ifdef VERBOSE_DEBUG 51 - #define VLDBG LDBG 52 - #else 53 - #define VLDBG(lun, fmt, args...) do { } while (0) 54 - #endif /* VERBOSE_DEBUG */ 55 - 56 - #define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args) 57 - #define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args) 58 - #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) 59 - #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) 60 - 61 - 62 - #ifdef DUMP_MSGS 63 - 64 - # define dump_msg(fsg, /* const char * */ label, \ 65 - /* const u8 * */ buf, /* unsigned */ length) do { \ 66 - if (length < 512) { \ 67 - DBG(fsg, "%s, length %u:\n", label, length); \ 68 - print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \ 69 - 16, 1, buf, length, 0); \ 70 - } \ 71 - } while (0) 72 - 73 - # define dump_cdb(fsg) do { } while (0) 74 - 75 - #else 76 - 77 - # define dump_msg(fsg, /* const char * */ label, \ 78 - /* const u8 * */ buf, /* unsigned */ length) do { } while (0) 79 - 80 - # ifdef VERBOSE_DEBUG 81 - 82 - # define dump_cdb(fsg) \ 83 - print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \ 84 - 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \ 85 - 86 - # else 87 - 88 - # define dump_cdb(fsg) do { } while (0) 89 - 90 - # endif /* VERBOSE_DEBUG */ 91 - 92 - #endif /* DUMP_MSGS */ 93 - 94 - /*-------------------------------------------------------------------------*/ 95 - 96 - /* Length of a SCSI Command Data Block */ 97 - #define MAX_COMMAND_SIZE 16 98 - 99 - /* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ 100 - #define SS_NO_SENSE 0 101 - #define SS_COMMUNICATION_FAILURE 0x040800 102 - #define SS_INVALID_COMMAND 0x052000 103 - #define SS_INVALID_FIELD_IN_CDB 0x052400 104 - #define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100 105 - #define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500 106 - #define SS_MEDIUM_NOT_PRESENT 0x023a00 107 - #define SS_MEDIUM_REMOVAL_PREVENTED 0x055302 108 - #define SS_NOT_READY_TO_READY_TRANSITION 0x062800 109 - #define SS_RESET_OCCURRED 0x062900 110 - #define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900 111 - #define SS_UNRECOVERED_READ_ERROR 0x031100 112 - #define SS_WRITE_ERROR 0x030c02 113 - #define SS_WRITE_PROTECTED 0x072700 114 - 115 - #define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */ 116 - #define ASC(x) ((u8) ((x) >> 8)) 117 - #define ASCQ(x) ((u8) (x)) 118 - 119 - 120 - /*-------------------------------------------------------------------------*/ 121 - 122 - 123 - struct fsg_lun { 124 - struct file *filp; 125 - loff_t file_length; 126 - loff_t num_sectors; 127 - 128 - unsigned int initially_ro:1; 129 - unsigned int ro:1; 130 - unsigned int removable:1; 131 - unsigned int cdrom:1; 132 - unsigned int prevent_medium_removal:1; 133 - unsigned int registered:1; 134 - unsigned int info_valid:1; 135 - unsigned int nofua:1; 136 - 137 - u32 sense_data; 138 - u32 sense_data_info; 139 - u32 unit_attention_data; 140 - 141 - unsigned int blkbits; /* Bits of logical block size of bound block device */ 142 - unsigned int blksize; /* logical block size of bound block device */ 143 - struct device dev; 144 - }; 145 - 146 - static inline bool fsg_lun_is_open(struct fsg_lun *curlun) 147 - { 148 - return curlun->filp != NULL; 149 - } 150 - 151 - static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev) 152 - { 153 - return container_of(dev, struct fsg_lun, dev); 154 - } 155 - 156 - 157 - /* Big enough to hold our biggest descriptor */ 158 - #define EP0_BUFSIZE 256 159 - #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ 160 - 161 - #ifdef CONFIG_USB_GADGET_DEBUG_FILES 162 - 163 - static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; 164 - module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO); 165 - MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers"); 166 - 167 - #else 168 - 169 - /* 170 - * Number of buffers we will use. 171 - * 2 is usually enough for good buffering pipeline 172 - */ 173 - #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS 174 - 175 - #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 176 - 177 - /* check if fsg_num_buffers is within a valid range */ 178 - static inline int fsg_num_buffers_validate(void) 179 - { 180 - if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4) 181 - return 0; 182 - pr_err("fsg_num_buffers %u is out of range (%d to %d)\n", 183 - fsg_num_buffers, 2 ,4); 184 - return -EINVAL; 185 - } 186 - 187 - /* Default size of buffer length. */ 188 - #define FSG_BUFLEN ((u32)16384) 189 - 190 - /* Maximal number of LUNs supported in mass storage function */ 191 - #define FSG_MAX_LUNS 8 192 - 193 - enum fsg_buffer_state { 194 - BUF_STATE_EMPTY = 0, 195 - BUF_STATE_FULL, 196 - BUF_STATE_BUSY 197 - }; 198 - 199 - struct fsg_buffhd { 200 - void *buf; 201 - enum fsg_buffer_state state; 202 - struct fsg_buffhd *next; 203 - 204 - /* 205 - * The NetChip 2280 is faster, and handles some protocol faults 206 - * better, if we don't submit any short bulk-out read requests. 207 - * So we will record the intended request length here. 208 - */ 209 - unsigned int bulk_out_intended_length; 210 - 211 - struct usb_request *inreq; 212 - int inreq_busy; 213 - struct usb_request *outreq; 214 - int outreq_busy; 215 - }; 216 - 217 - enum fsg_state { 218 - /* This one isn't used anywhere */ 219 - FSG_STATE_COMMAND_PHASE = -10, 220 - FSG_STATE_DATA_PHASE, 221 - FSG_STATE_STATUS_PHASE, 222 - 223 - FSG_STATE_IDLE = 0, 224 - FSG_STATE_ABORT_BULK_OUT, 225 - FSG_STATE_RESET, 226 - FSG_STATE_INTERFACE_CHANGE, 227 - FSG_STATE_CONFIG_CHANGE, 228 - FSG_STATE_DISCONNECT, 229 - FSG_STATE_EXIT, 230 - FSG_STATE_TERMINATED 231 - }; 232 - 233 - enum data_direction { 234 - DATA_DIR_UNKNOWN = 0, 235 - DATA_DIR_FROM_HOST, 236 - DATA_DIR_TO_HOST, 237 - DATA_DIR_NONE 238 - }; 239 - 240 - 241 - /*-------------------------------------------------------------------------*/ 242 - 243 - 244 - static inline u32 get_unaligned_be24(u8 *buf) 245 - { 246 - return 0xffffff & (u32) get_unaligned_be32(buf - 1); 247 - } 248 - 249 - 250 - /*-------------------------------------------------------------------------*/ 251 - 252 - 253 - enum { 254 - FSG_STRING_INTERFACE 255 - }; 256 - 32 + #include "storage_common.h" 257 33 258 34 /* There is only one interface. */ 259 35 260 - static struct usb_interface_descriptor 261 - fsg_intf_desc = { 36 + struct usb_interface_descriptor fsg_intf_desc = { 262 37 .bLength = sizeof fsg_intf_desc, 263 38 .bDescriptorType = USB_DT_INTERFACE, 264 39 ··· 43 268 .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ 44 269 .iInterface = FSG_STRING_INTERFACE, 45 270 }; 271 + EXPORT_SYMBOL(fsg_intf_desc); 46 272 47 273 /* 48 274 * Three full-speed endpoint descriptors: bulk-in, bulk-out, and 49 275 * interrupt-in. 50 276 */ 51 277 52 - static struct usb_endpoint_descriptor 53 - fsg_fs_bulk_in_desc = { 278 + struct usb_endpoint_descriptor fsg_fs_bulk_in_desc = { 54 279 .bLength = USB_DT_ENDPOINT_SIZE, 55 280 .bDescriptorType = USB_DT_ENDPOINT, 56 281 ··· 58 283 .bmAttributes = USB_ENDPOINT_XFER_BULK, 59 284 /* wMaxPacketSize set by autoconfiguration */ 60 285 }; 286 + EXPORT_SYMBOL(fsg_fs_bulk_in_desc); 61 287 62 - static struct usb_endpoint_descriptor 63 - fsg_fs_bulk_out_desc = { 288 + struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = { 64 289 .bLength = USB_DT_ENDPOINT_SIZE, 65 290 .bDescriptorType = USB_DT_ENDPOINT, 66 291 ··· 68 293 .bmAttributes = USB_ENDPOINT_XFER_BULK, 69 294 /* wMaxPacketSize set by autoconfiguration */ 70 295 }; 296 + EXPORT_SYMBOL(fsg_fs_bulk_out_desc); 71 297 72 - static struct usb_descriptor_header *fsg_fs_function[] = { 298 + struct usb_descriptor_header *fsg_fs_function[] = { 73 299 (struct usb_descriptor_header *) &fsg_intf_desc, 74 300 (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc, 75 301 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, 76 302 NULL, 77 303 }; 304 + EXPORT_SYMBOL(fsg_fs_function); 78 305 79 306 80 307 /* ··· 87 310 * and a "device qualifier" ... plus more construction options 88 311 * for the configuration descriptor. 89 312 */ 90 - static struct usb_endpoint_descriptor 91 - fsg_hs_bulk_in_desc = { 313 + struct usb_endpoint_descriptor fsg_hs_bulk_in_desc = { 92 314 .bLength = USB_DT_ENDPOINT_SIZE, 93 315 .bDescriptorType = USB_DT_ENDPOINT, 94 316 ··· 95 319 .bmAttributes = USB_ENDPOINT_XFER_BULK, 96 320 .wMaxPacketSize = cpu_to_le16(512), 97 321 }; 322 + EXPORT_SYMBOL(fsg_hs_bulk_in_desc); 98 323 99 - static struct usb_endpoint_descriptor 100 - fsg_hs_bulk_out_desc = { 324 + struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = { 101 325 .bLength = USB_DT_ENDPOINT_SIZE, 102 326 .bDescriptorType = USB_DT_ENDPOINT, 103 327 ··· 106 330 .wMaxPacketSize = cpu_to_le16(512), 107 331 .bInterval = 1, /* NAK every 1 uframe */ 108 332 }; 333 + EXPORT_SYMBOL(fsg_hs_bulk_out_desc); 109 334 110 335 111 - static struct usb_descriptor_header *fsg_hs_function[] = { 336 + struct usb_descriptor_header *fsg_hs_function[] = { 112 337 (struct usb_descriptor_header *) &fsg_intf_desc, 113 338 (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc, 114 339 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, 115 340 NULL, 116 341 }; 342 + EXPORT_SYMBOL(fsg_hs_function); 117 343 118 - static struct usb_endpoint_descriptor 119 - fsg_ss_bulk_in_desc = { 344 + struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = { 120 345 .bLength = USB_DT_ENDPOINT_SIZE, 121 346 .bDescriptorType = USB_DT_ENDPOINT, 122 347 ··· 125 348 .bmAttributes = USB_ENDPOINT_XFER_BULK, 126 349 .wMaxPacketSize = cpu_to_le16(1024), 127 350 }; 351 + EXPORT_SYMBOL(fsg_ss_bulk_in_desc); 128 352 129 - static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { 353 + struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { 130 354 .bLength = sizeof(fsg_ss_bulk_in_comp_desc), 131 355 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 132 356 133 357 /*.bMaxBurst = DYNAMIC, */ 134 358 }; 359 + EXPORT_SYMBOL(fsg_ss_bulk_in_comp_desc); 135 360 136 - static struct usb_endpoint_descriptor 137 - fsg_ss_bulk_out_desc = { 361 + struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = { 138 362 .bLength = USB_DT_ENDPOINT_SIZE, 139 363 .bDescriptorType = USB_DT_ENDPOINT, 140 364 ··· 143 365 .bmAttributes = USB_ENDPOINT_XFER_BULK, 144 366 .wMaxPacketSize = cpu_to_le16(1024), 145 367 }; 368 + EXPORT_SYMBOL(fsg_ss_bulk_out_desc); 146 369 147 - static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { 370 + struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { 148 371 .bLength = sizeof(fsg_ss_bulk_in_comp_desc), 149 372 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 150 373 151 374 /*.bMaxBurst = DYNAMIC, */ 152 375 }; 376 + EXPORT_SYMBOL(fsg_ss_bulk_out_comp_desc); 153 377 154 - static struct usb_descriptor_header *fsg_ss_function[] = { 378 + struct usb_descriptor_header *fsg_ss_function[] = { 155 379 (struct usb_descriptor_header *) &fsg_intf_desc, 156 380 (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, 157 381 (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc, ··· 161 381 (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, 162 382 NULL, 163 383 }; 164 - 165 - /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ 166 - static struct usb_string fsg_strings[] = { 167 - {FSG_STRING_INTERFACE, fsg_string_interface}, 168 - {} 169 - }; 170 - 171 - static struct usb_gadget_strings fsg_stringtab = { 172 - .language = 0x0409, /* en-us */ 173 - .strings = fsg_strings, 174 - }; 384 + EXPORT_SYMBOL(fsg_ss_function); 175 385 176 386 177 387 /*-------------------------------------------------------------------------*/ ··· 171 401 * the caller must own fsg->filesem for writing. 172 402 */ 173 403 174 - static void fsg_lun_close(struct fsg_lun *curlun) 404 + void fsg_lun_close(struct fsg_lun *curlun) 175 405 { 176 406 if (curlun->filp) { 177 407 LDBG(curlun, "close backing file\n"); ··· 179 409 curlun->filp = NULL; 180 410 } 181 411 } 412 + EXPORT_SYMBOL(fsg_lun_close); 182 413 183 - 184 - static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) 414 + int fsg_lun_open(struct fsg_lun *curlun, const char *filename) 185 415 { 186 416 int ro; 187 417 struct file *filp = NULL; ··· 278 508 fput(filp); 279 509 return rc; 280 510 } 511 + EXPORT_SYMBOL(fsg_lun_open); 281 512 282 513 283 514 /*-------------------------------------------------------------------------*/ ··· 287 516 * Sync the file data, don't bother with the metadata. 288 517 * This code was copied from fs/buffer.c:sys_fdatasync(). 289 518 */ 290 - static int fsg_lun_fsync_sub(struct fsg_lun *curlun) 519 + int fsg_lun_fsync_sub(struct fsg_lun *curlun) 291 520 { 292 521 struct file *filp = curlun->filp; 293 522 ··· 295 524 return 0; 296 525 return vfs_fsync(filp, 1); 297 526 } 527 + EXPORT_SYMBOL(fsg_lun_fsync_sub); 298 528 299 - static void store_cdrom_address(u8 *dest, int msf, u32 addr) 529 + void store_cdrom_address(u8 *dest, int msf, u32 addr) 300 530 { 301 531 if (msf) { 302 532 /* Convert to Minutes-Seconds-Frames */ ··· 314 542 put_unaligned_be32(addr, dest); 315 543 } 316 544 } 317 - 545 + EXPORT_SYMBOL(store_cdrom_address); 318 546 319 547 /*-------------------------------------------------------------------------*/ 320 548 321 549 322 - static ssize_t ro_show(struct device *dev, struct device_attribute *attr, 323 - char *buf) 550 + ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf) 324 551 { 325 - struct fsg_lun *curlun = fsg_lun_from_dev(dev); 326 - 327 552 return sprintf(buf, "%d\n", fsg_lun_is_open(curlun) 328 553 ? curlun->ro 329 554 : curlun->initially_ro); 330 555 } 556 + EXPORT_SYMBOL(fsg_show_ro); 331 557 332 - static ssize_t nofua_show(struct device *dev, struct device_attribute *attr, 333 - char *buf) 558 + ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf) 334 559 { 335 - struct fsg_lun *curlun = fsg_lun_from_dev(dev); 336 - 337 560 return sprintf(buf, "%u\n", curlun->nofua); 338 561 } 562 + EXPORT_SYMBOL(fsg_show_nofua); 339 563 340 - static ssize_t file_show(struct device *dev, struct device_attribute *attr, 341 - char *buf) 564 + ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, 565 + char *buf) 342 566 { 343 - struct fsg_lun *curlun = fsg_lun_from_dev(dev); 344 - struct rw_semaphore *filesem = dev_get_drvdata(dev); 345 567 char *p; 346 568 ssize_t rc; 347 569 ··· 357 591 up_read(filesem); 358 592 return rc; 359 593 } 594 + EXPORT_SYMBOL(fsg_show_file); 360 595 596 + ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf) 597 + { 598 + return sprintf(buf, "%u\n", curlun->cdrom); 599 + } 600 + EXPORT_SYMBOL(fsg_show_cdrom); 361 601 362 - static ssize_t ro_store(struct device *dev, struct device_attribute *attr, 363 - const char *buf, size_t count) 602 + ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf) 603 + { 604 + return sprintf(buf, "%u\n", curlun->removable); 605 + } 606 + EXPORT_SYMBOL(fsg_show_removable); 607 + 608 + /* 609 + * The caller must hold fsg->filesem for reading when calling this function. 610 + */ 611 + static ssize_t _fsg_store_ro(struct fsg_lun *curlun, bool ro) 612 + { 613 + if (fsg_lun_is_open(curlun)) { 614 + LDBG(curlun, "read-only status change prevented\n"); 615 + return -EBUSY; 616 + } 617 + 618 + curlun->ro = ro; 619 + curlun->initially_ro = ro; 620 + LDBG(curlun, "read-only status set to %d\n", curlun->ro); 621 + 622 + return 0; 623 + } 624 + 625 + ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, 626 + const char *buf, size_t count) 364 627 { 365 628 ssize_t rc; 366 - struct fsg_lun *curlun = fsg_lun_from_dev(dev); 367 - struct rw_semaphore *filesem = dev_get_drvdata(dev); 368 - unsigned ro; 629 + bool ro; 369 630 370 - rc = kstrtouint(buf, 2, &ro); 631 + rc = strtobool(buf, &ro); 371 632 if (rc) 372 633 return rc; 373 634 ··· 403 610 * backing file is closed. 404 611 */ 405 612 down_read(filesem); 406 - if (fsg_lun_is_open(curlun)) { 407 - LDBG(curlun, "read-only status change prevented\n"); 408 - rc = -EBUSY; 409 - } else { 410 - curlun->ro = ro; 411 - curlun->initially_ro = ro; 412 - LDBG(curlun, "read-only status set to %d\n", curlun->ro); 613 + rc = _fsg_store_ro(curlun, ro); 614 + if (!rc) 413 615 rc = count; 414 - } 415 616 up_read(filesem); 617 + 416 618 return rc; 417 619 } 620 + EXPORT_SYMBOL(fsg_store_ro); 418 621 419 - static ssize_t nofua_store(struct device *dev, struct device_attribute *attr, 420 - const char *buf, size_t count) 622 + ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) 421 623 { 422 - struct fsg_lun *curlun = fsg_lun_from_dev(dev); 423 - unsigned nofua; 624 + bool nofua; 424 625 int ret; 425 626 426 - ret = kstrtouint(buf, 2, &nofua); 627 + ret = strtobool(buf, &nofua); 427 628 if (ret) 428 629 return ret; 429 630 ··· 429 642 430 643 return count; 431 644 } 645 + EXPORT_SYMBOL(fsg_store_nofua); 432 646 433 - static ssize_t file_store(struct device *dev, struct device_attribute *attr, 434 - const char *buf, size_t count) 647 + ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, 648 + const char *buf, size_t count) 435 649 { 436 - struct fsg_lun *curlun = fsg_lun_from_dev(dev); 437 - struct rw_semaphore *filesem = dev_get_drvdata(dev); 438 650 int rc = 0; 439 651 440 652 if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) { ··· 460 674 up_write(filesem); 461 675 return (rc < 0 ? rc : count); 462 676 } 677 + EXPORT_SYMBOL(fsg_store_file); 678 + 679 + ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, 680 + const char *buf, size_t count) 681 + { 682 + bool cdrom; 683 + int ret; 684 + 685 + ret = strtobool(buf, &cdrom); 686 + if (ret) 687 + return ret; 688 + 689 + down_read(filesem); 690 + ret = cdrom ? _fsg_store_ro(curlun, true) : 0; 691 + 692 + if (!ret) { 693 + curlun->cdrom = cdrom; 694 + ret = count; 695 + } 696 + up_read(filesem); 697 + 698 + return ret; 699 + } 700 + EXPORT_SYMBOL(fsg_store_cdrom); 701 + 702 + ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, 703 + size_t count) 704 + { 705 + bool removable; 706 + int ret; 707 + 708 + ret = strtobool(buf, &removable); 709 + if (ret) 710 + return ret; 711 + 712 + curlun->removable = removable; 713 + 714 + return count; 715 + } 716 + EXPORT_SYMBOL(fsg_store_removable); 717 + 718 + MODULE_LICENSE("GPL");
+229
drivers/usb/gadget/storage_common.h
··· 1 + #ifndef USB_STORAGE_COMMON_H 2 + #define USB_STORAGE_COMMON_H 3 + 4 + #include <linux/device.h> 5 + #include <linux/usb/storage.h> 6 + #include <scsi/scsi.h> 7 + #include <asm/unaligned.h> 8 + 9 + #ifndef DEBUG 10 + #undef VERBOSE_DEBUG 11 + #undef DUMP_MSGS 12 + #endif /* !DEBUG */ 13 + 14 + #ifdef VERBOSE_DEBUG 15 + #define VLDBG LDBG 16 + #else 17 + #define VLDBG(lun, fmt, args...) do { } while (0) 18 + #endif /* VERBOSE_DEBUG */ 19 + 20 + #define _LMSG(func, lun, fmt, args...) \ 21 + do { \ 22 + if ((lun)->name_pfx && *(lun)->name_pfx) \ 23 + func("%s/%s: " fmt, *(lun)->name_pfx, \ 24 + (lun)->name, ## args); \ 25 + else \ 26 + func("%s: " fmt, (lun)->name, ## args); \ 27 + } while (0) 28 + 29 + #define LDBG(lun, fmt, args...) _LMSG(pr_debug, lun, fmt, ## args) 30 + #define LERROR(lun, fmt, args...) _LMSG(pr_err, lun, fmt, ## args) 31 + #define LWARN(lun, fmt, args...) _LMSG(pr_warn, lun, fmt, ## args) 32 + #define LINFO(lun, fmt, args...) _LMSG(pr_info, lun, fmt, ## args) 33 + 34 + 35 + #ifdef DUMP_MSGS 36 + 37 + # define dump_msg(fsg, /* const char * */ label, \ 38 + /* const u8 * */ buf, /* unsigned */ length) \ 39 + do { \ 40 + if (length < 512) { \ 41 + DBG(fsg, "%s, length %u:\n", label, length); \ 42 + print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \ 43 + 16, 1, buf, length, 0); \ 44 + } \ 45 + } while (0) 46 + 47 + # define dump_cdb(fsg) do { } while (0) 48 + 49 + #else 50 + 51 + # define dump_msg(fsg, /* const char * */ label, \ 52 + /* const u8 * */ buf, /* unsigned */ length) do { } while (0) 53 + 54 + # ifdef VERBOSE_DEBUG 55 + 56 + # define dump_cdb(fsg) \ 57 + print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \ 58 + 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \ 59 + 60 + # else 61 + 62 + # define dump_cdb(fsg) do { } while (0) 63 + 64 + # endif /* VERBOSE_DEBUG */ 65 + 66 + #endif /* DUMP_MSGS */ 67 + 68 + /* Length of a SCSI Command Data Block */ 69 + #define MAX_COMMAND_SIZE 16 70 + 71 + /* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ 72 + #define SS_NO_SENSE 0 73 + #define SS_COMMUNICATION_FAILURE 0x040800 74 + #define SS_INVALID_COMMAND 0x052000 75 + #define SS_INVALID_FIELD_IN_CDB 0x052400 76 + #define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100 77 + #define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500 78 + #define SS_MEDIUM_NOT_PRESENT 0x023a00 79 + #define SS_MEDIUM_REMOVAL_PREVENTED 0x055302 80 + #define SS_NOT_READY_TO_READY_TRANSITION 0x062800 81 + #define SS_RESET_OCCURRED 0x062900 82 + #define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900 83 + #define SS_UNRECOVERED_READ_ERROR 0x031100 84 + #define SS_WRITE_ERROR 0x030c02 85 + #define SS_WRITE_PROTECTED 0x072700 86 + 87 + #define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */ 88 + #define ASC(x) ((u8) ((x) >> 8)) 89 + #define ASCQ(x) ((u8) (x)) 90 + 91 + struct fsg_lun { 92 + struct file *filp; 93 + loff_t file_length; 94 + loff_t num_sectors; 95 + 96 + unsigned int initially_ro:1; 97 + unsigned int ro:1; 98 + unsigned int removable:1; 99 + unsigned int cdrom:1; 100 + unsigned int prevent_medium_removal:1; 101 + unsigned int registered:1; 102 + unsigned int info_valid:1; 103 + unsigned int nofua:1; 104 + 105 + u32 sense_data; 106 + u32 sense_data_info; 107 + u32 unit_attention_data; 108 + 109 + unsigned int blkbits; /* Bits of logical block size 110 + of bound block device */ 111 + unsigned int blksize; /* logical block size of bound block device */ 112 + struct device dev; 113 + const char *name; /* "lun.name" */ 114 + const char **name_pfx; /* "function.name" */ 115 + }; 116 + 117 + static inline bool fsg_lun_is_open(struct fsg_lun *curlun) 118 + { 119 + return curlun->filp != NULL; 120 + } 121 + 122 + /* Big enough to hold our biggest descriptor */ 123 + #define EP0_BUFSIZE 256 124 + #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ 125 + 126 + /* Default size of buffer length. */ 127 + #define FSG_BUFLEN ((u32)16384) 128 + 129 + /* Maximal number of LUNs supported in mass storage function */ 130 + #define FSG_MAX_LUNS 8 131 + 132 + enum fsg_buffer_state { 133 + BUF_STATE_EMPTY = 0, 134 + BUF_STATE_FULL, 135 + BUF_STATE_BUSY 136 + }; 137 + 138 + struct fsg_buffhd { 139 + void *buf; 140 + enum fsg_buffer_state state; 141 + struct fsg_buffhd *next; 142 + 143 + /* 144 + * The NetChip 2280 is faster, and handles some protocol faults 145 + * better, if we don't submit any short bulk-out read requests. 146 + * So we will record the intended request length here. 147 + */ 148 + unsigned int bulk_out_intended_length; 149 + 150 + struct usb_request *inreq; 151 + int inreq_busy; 152 + struct usb_request *outreq; 153 + int outreq_busy; 154 + }; 155 + 156 + enum fsg_state { 157 + /* This one isn't used anywhere */ 158 + FSG_STATE_COMMAND_PHASE = -10, 159 + FSG_STATE_DATA_PHASE, 160 + FSG_STATE_STATUS_PHASE, 161 + 162 + FSG_STATE_IDLE = 0, 163 + FSG_STATE_ABORT_BULK_OUT, 164 + FSG_STATE_RESET, 165 + FSG_STATE_INTERFACE_CHANGE, 166 + FSG_STATE_CONFIG_CHANGE, 167 + FSG_STATE_DISCONNECT, 168 + FSG_STATE_EXIT, 169 + FSG_STATE_TERMINATED 170 + }; 171 + 172 + enum data_direction { 173 + DATA_DIR_UNKNOWN = 0, 174 + DATA_DIR_FROM_HOST, 175 + DATA_DIR_TO_HOST, 176 + DATA_DIR_NONE 177 + }; 178 + 179 + static inline u32 get_unaligned_be24(u8 *buf) 180 + { 181 + return 0xffffff & (u32) get_unaligned_be32(buf - 1); 182 + } 183 + 184 + static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev) 185 + { 186 + return container_of(dev, struct fsg_lun, dev); 187 + } 188 + 189 + enum { 190 + FSG_STRING_INTERFACE 191 + }; 192 + 193 + extern struct usb_interface_descriptor fsg_intf_desc; 194 + 195 + extern struct usb_endpoint_descriptor fsg_fs_bulk_in_desc; 196 + extern struct usb_endpoint_descriptor fsg_fs_bulk_out_desc; 197 + extern struct usb_descriptor_header *fsg_fs_function[]; 198 + 199 + extern struct usb_endpoint_descriptor fsg_hs_bulk_in_desc; 200 + extern struct usb_endpoint_descriptor fsg_hs_bulk_out_desc; 201 + extern struct usb_descriptor_header *fsg_hs_function[]; 202 + 203 + extern struct usb_endpoint_descriptor fsg_ss_bulk_in_desc; 204 + extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc; 205 + extern struct usb_endpoint_descriptor fsg_ss_bulk_out_desc; 206 + extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc; 207 + extern struct usb_descriptor_header *fsg_ss_function[]; 208 + 209 + void fsg_lun_close(struct fsg_lun *curlun); 210 + int fsg_lun_open(struct fsg_lun *curlun, const char *filename); 211 + int fsg_lun_fsync_sub(struct fsg_lun *curlun); 212 + void store_cdrom_address(u8 *dest, int msf, u32 addr); 213 + ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf); 214 + ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf); 215 + ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, 216 + char *buf); 217 + ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf); 218 + ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf); 219 + ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, 220 + const char *buf, size_t count); 221 + ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count); 222 + ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, 223 + const char *buf, size_t count); 224 + ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, 225 + const char *buf, size_t count); 226 + ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, 227 + size_t count); 228 + 229 + #endif /* USB_STORAGE_COMMON_H */
+2 -1
drivers/usb/gadget/udc-core.c
··· 356 356 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 357 357 return 0; 358 358 err1: 359 - dev_err(&udc->dev, "failed to start %s: %d\n", 359 + if (ret != -EISNAM) 360 + dev_err(&udc->dev, "failed to start %s: %d\n", 360 361 udc->driver->function, ret); 361 362 udc->driver = NULL; 362 363 udc->dev.driver = NULL;
+23 -2
drivers/usb/gadget/zero.c
··· 95 95 module_param(autoresume, uint, S_IRUGO); 96 96 MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup"); 97 97 98 + /* Maximum Autoresume time */ 99 + unsigned max_autoresume; 100 + module_param(max_autoresume, uint, S_IRUGO); 101 + MODULE_PARM_DESC(max_autoresume, "maximum seconds before remote wakeup"); 102 + 103 + /* Interval between two remote wakeups */ 104 + unsigned autoresume_interval_ms; 105 + module_param(autoresume_interval_ms, uint, S_IRUGO); 106 + MODULE_PARM_DESC(autoresume_interval_ms, 107 + "milliseconds to increase successive wakeup delays"); 108 + 109 + static unsigned autoresume_step_ms; 98 110 /*-------------------------------------------------------------------------*/ 99 111 100 112 static struct usb_device_descriptor device_desc = { ··· 195 183 return; 196 184 197 185 if (autoresume) { 198 - mod_timer(&autoresume_timer, jiffies + (HZ * autoresume)); 199 - DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume); 186 + if (max_autoresume && 187 + (autoresume_step_ms > max_autoresume * 1000)) 188 + autoresume_step_ms = autoresume * 1000; 189 + 190 + mod_timer(&autoresume_timer, jiffies + 191 + msecs_to_jiffies(autoresume_step_ms)); 192 + DBG(cdev, "suspend, wakeup in %d milliseconds\n", 193 + autoresume_step_ms); 194 + 195 + autoresume_step_ms += autoresume_interval_ms; 200 196 } else 201 197 DBG(cdev, "%s\n", __func__); 202 198 } ··· 336 316 if (autoresume) { 337 317 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 338 318 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 319 + autoresume_step_ms = autoresume * 1000; 339 320 } 340 321 341 322 /* support OTG systems */
+2 -2
drivers/usb/musb/Kconfig
··· 91 91 depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523) 92 92 93 93 config USB_MUSB_UX500 94 - tristate "U8500 and U5500" 94 + tristate "Ux500 platforms" 95 95 96 96 endchoice 97 97 ··· 113 113 allow using DMA on multiplatform kernels. 114 114 115 115 config USB_UX500_DMA 116 - bool 'ST Ericsson U8500 and U5500' 116 + bool 'ST Ericsson Ux500' 117 117 depends on USB_MUSB_UX500 118 118 help 119 119 Enable DMA transfers on UX500 platforms.
+19 -42
drivers/usb/musb/am35x.c
··· 89 89 struct clk *phy_clk; 90 90 struct clk *clk; 91 91 }; 92 - #define glue_to_musb(g) platform_get_drvdata(g->musb) 93 92 94 93 /* 95 94 * am35x_musb_enable - enable interrupts ··· 451 452 .set_vbus = am35x_musb_set_vbus, 452 453 }; 453 454 454 - static u64 am35x_dmamask = DMA_BIT_MASK(32); 455 + static const struct platform_device_info am35x_dev_info = { 456 + .name = "musb-hdrc", 457 + .id = PLATFORM_DEVID_AUTO, 458 + .dma_mask = DMA_BIT_MASK(32), 459 + }; 455 460 456 461 static int am35x_probe(struct platform_device *pdev) 457 462 { 458 463 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 459 464 struct platform_device *musb; 460 465 struct am35x_glue *glue; 461 - 466 + struct platform_device_info pinfo; 462 467 struct clk *phy_clk; 463 468 struct clk *clk; 464 469 ··· 472 469 if (!glue) { 473 470 dev_err(&pdev->dev, "failed to allocate glue context\n"); 474 471 goto err0; 475 - } 476 - 477 - musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 478 - if (!musb) { 479 - dev_err(&pdev->dev, "failed to allocate musb device\n"); 480 - goto err1; 481 472 } 482 473 483 474 phy_clk = clk_get(&pdev->dev, "fck"); ··· 500 503 goto err6; 501 504 } 502 505 503 - musb->dev.parent = &pdev->dev; 504 - musb->dev.dma_mask = &am35x_dmamask; 505 - musb->dev.coherent_dma_mask = am35x_dmamask; 506 - 507 506 glue->dev = &pdev->dev; 508 - glue->musb = musb; 509 507 glue->phy_clk = phy_clk; 510 508 glue->clk = clk; 511 509 ··· 508 516 509 517 platform_set_drvdata(pdev, glue); 510 518 511 - ret = platform_device_add_resources(musb, pdev->resource, 512 - pdev->num_resources); 513 - if (ret) { 514 - dev_err(&pdev->dev, "failed to add resources\n"); 515 - goto err7; 516 - } 519 + pinfo = am35x_dev_info; 520 + pinfo.parent = &pdev->dev; 521 + pinfo.res = pdev->resource; 522 + pinfo.num_res = pdev->num_resources; 523 + pinfo.data = pdata; 524 + pinfo.size_data = sizeof(*pdata); 517 525 518 - ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 519 - if (ret) { 520 - dev_err(&pdev->dev, "failed to add platform_data\n"); 521 - goto err7; 522 - } 523 - 524 - ret = platform_device_add(musb); 525 - if (ret) { 526 - dev_err(&pdev->dev, "failed to register musb device\n"); 526 + glue->musb = musb = platform_device_register_full(&pinfo); 527 + if (IS_ERR(musb)) { 528 + ret = PTR_ERR(musb); 529 + dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); 527 530 goto err7; 528 531 } 529 532 ··· 537 550 clk_put(phy_clk); 538 551 539 552 err3: 540 - platform_device_put(musb); 541 - 542 - err1: 543 553 kfree(glue); 544 554 545 555 err0: ··· 599 615 600 616 return 0; 601 617 } 602 - 603 - static struct dev_pm_ops am35x_pm_ops = { 604 - .suspend = am35x_suspend, 605 - .resume = am35x_resume, 606 - }; 607 - 608 - #define DEV_PM_OPS &am35x_pm_ops 609 - #else 610 - #define DEV_PM_OPS NULL 611 618 #endif 619 + 620 + static SIMPLE_DEV_PM_OPS(am35x_pm_ops, am35x_suspend, am35x_resume); 612 621 613 622 static struct platform_driver am35x_driver = { 614 623 .probe = am35x_probe, 615 624 .remove = am35x_remove, 616 625 .driver = { 617 626 .name = "musb-am35x", 618 - .pm = DEV_PM_OPS, 627 + .pm = &am35x_pm_ops, 619 628 }, 620 629 }; 621 630
+3 -10
drivers/usb/musb/blackfin.c
··· 561 561 562 562 return 0; 563 563 } 564 - 565 - static struct dev_pm_ops bfin_pm_ops = { 566 - .suspend = bfin_suspend, 567 - .resume = bfin_resume, 568 - }; 569 - 570 - #define DEV_PM_OPS &bfin_pm_ops 571 - #else 572 - #define DEV_PM_OPS NULL 573 564 #endif 565 + 566 + static SIMPLE_DEV_PM_OPS(bfin_pm_ops, bfin_suspend, bfin_resume); 574 567 575 568 static struct platform_driver bfin_driver = { 576 569 .probe = bfin_probe, 577 570 .remove = __exit_p(bfin_remove), 578 571 .driver = { 579 572 .name = "musb-blackfin", 580 - .pm = DEV_PM_OPS, 573 + .pm = &bfin_pm_ops, 581 574 }, 582 575 }; 583 576
+16 -31
drivers/usb/musb/da8xx.c
··· 472 472 .set_vbus = da8xx_musb_set_vbus, 473 473 }; 474 474 475 - static u64 da8xx_dmamask = DMA_BIT_MASK(32); 475 + static const struct platform_device_info da8xx_dev_info = { 476 + .name = "musb-hdrc", 477 + .id = PLATFORM_DEVID_AUTO, 478 + .dma_mask = DMA_BIT_MASK(32), 479 + }; 476 480 477 481 static int da8xx_probe(struct platform_device *pdev) 478 482 { ··· 484 480 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 485 481 struct platform_device *musb; 486 482 struct da8xx_glue *glue; 487 - 483 + struct platform_device_info pinfo; 488 484 struct clk *clk; 489 485 490 486 int ret = -ENOMEM; ··· 493 489 if (!glue) { 494 490 dev_err(&pdev->dev, "failed to allocate glue context\n"); 495 491 goto err0; 496 - } 497 - 498 - musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 499 - if (!musb) { 500 - dev_err(&pdev->dev, "failed to allocate musb device\n"); 501 - goto err1; 502 492 } 503 493 504 494 clk = clk_get(&pdev->dev, "usb20"); ··· 508 510 goto err4; 509 511 } 510 512 511 - musb->dev.parent = &pdev->dev; 512 - musb->dev.dma_mask = &da8xx_dmamask; 513 - musb->dev.coherent_dma_mask = da8xx_dmamask; 514 - 515 513 glue->dev = &pdev->dev; 516 - glue->musb = musb; 517 514 glue->clk = clk; 518 515 519 516 pdata->platform_ops = &da8xx_ops; ··· 528 535 musb_resources[1].end = pdev->resource[1].end; 529 536 musb_resources[1].flags = pdev->resource[1].flags; 530 537 531 - ret = platform_device_add_resources(musb, musb_resources, 532 - ARRAY_SIZE(musb_resources)); 533 - if (ret) { 534 - dev_err(&pdev->dev, "failed to add resources\n"); 535 - goto err5; 536 - } 538 + pinfo = da8xx_dev_info; 539 + pinfo.parent = &pdev->dev; 540 + pinfo.res = musb_resources; 541 + pinfo.num_res = ARRAY_SIZE(musb_resources); 542 + pinfo.data = pdata; 543 + pinfo.size_data = sizeof(*pdata); 537 544 538 - ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 539 - if (ret) { 540 - dev_err(&pdev->dev, "failed to add platform_data\n"); 541 - goto err5; 542 - } 543 - 544 - ret = platform_device_add(musb); 545 - if (ret) { 546 - dev_err(&pdev->dev, "failed to register musb device\n"); 545 + glue->musb = musb = platform_device_register_full(&pinfo); 546 + if (IS_ERR(musb)) { 547 + ret = PTR_ERR(musb); 548 + dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); 547 549 goto err5; 548 550 } 549 551 ··· 551 563 clk_put(clk); 552 564 553 565 err3: 554 - platform_device_put(musb); 555 - 556 - err1: 557 566 kfree(glue); 558 567 559 568 err0:
+25 -30
drivers/usb/musb/davinci.c
··· 505 505 .set_vbus = davinci_musb_set_vbus, 506 506 }; 507 507 508 - static u64 davinci_dmamask = DMA_BIT_MASK(32); 508 + static const struct platform_device_info davinci_dev_info = { 509 + .name = "musb-hdrc", 510 + .id = PLATFORM_DEVID_AUTO, 511 + .dma_mask = DMA_BIT_MASK(32), 512 + }; 509 513 510 514 static int davinci_probe(struct platform_device *pdev) 511 515 { 512 - struct resource musb_resources[2]; 516 + struct resource musb_resources[3]; 513 517 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 514 518 struct platform_device *musb; 515 519 struct davinci_glue *glue; 520 + struct platform_device_info pinfo; 516 521 struct clk *clk; 517 522 518 523 int ret = -ENOMEM; ··· 526 521 if (!glue) { 527 522 dev_err(&pdev->dev, "failed to allocate glue context\n"); 528 523 goto err0; 529 - } 530 - 531 - musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 532 - if (!musb) { 533 - dev_err(&pdev->dev, "failed to allocate musb device\n"); 534 - goto err1; 535 524 } 536 525 537 526 clk = clk_get(&pdev->dev, "usb"); ··· 541 542 goto err4; 542 543 } 543 544 544 - musb->dev.parent = &pdev->dev; 545 - musb->dev.dma_mask = &davinci_dmamask; 546 - musb->dev.coherent_dma_mask = davinci_dmamask; 547 - 548 545 glue->dev = &pdev->dev; 549 - glue->musb = musb; 550 546 glue->clk = clk; 551 547 552 548 pdata->platform_ops = &davinci_ops; ··· 561 567 musb_resources[1].end = pdev->resource[1].end; 562 568 musb_resources[1].flags = pdev->resource[1].flags; 563 569 564 - ret = platform_device_add_resources(musb, musb_resources, 565 - ARRAY_SIZE(musb_resources)); 566 - if (ret) { 567 - dev_err(&pdev->dev, "failed to add resources\n"); 568 - goto err5; 569 - } 570 + /* 571 + * For DM6467 3 resources are passed. A placeholder for the 3rd 572 + * resource is always there, so it's safe to always copy it... 573 + */ 574 + musb_resources[2].name = pdev->resource[2].name; 575 + musb_resources[2].start = pdev->resource[2].start; 576 + musb_resources[2].end = pdev->resource[2].end; 577 + musb_resources[2].flags = pdev->resource[2].flags; 570 578 571 - ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 572 - if (ret) { 573 - dev_err(&pdev->dev, "failed to add platform_data\n"); 574 - goto err5; 575 - } 579 + pinfo = davinci_dev_info; 580 + pinfo.parent = &pdev->dev; 581 + pinfo.res = musb_resources; 582 + pinfo.num_res = ARRAY_SIZE(musb_resources); 583 + pinfo.data = pdata; 584 + pinfo.size_data = sizeof(*pdata); 576 585 577 - ret = platform_device_add(musb); 578 - if (ret) { 579 - dev_err(&pdev->dev, "failed to register musb device\n"); 586 + glue->musb = musb = platform_device_register_full(&pinfo); 587 + if (IS_ERR(musb)) { 588 + ret = PTR_ERR(musb); 589 + dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); 580 590 goto err5; 581 591 } 582 592 ··· 593 595 clk_put(clk); 594 596 595 597 err3: 596 - platform_device_put(musb); 597 - 598 - err1: 599 598 kfree(glue); 600 599 601 600 err0:
+1 -1
drivers/usb/musb/musb_am335x.c
··· 46 46 .remove = am335x_child_remove, 47 47 .driver = { 48 48 .name = "am335x-usb-childs", 49 - .of_match_table = of_match_ptr(am335x_child_of_match), 49 + .of_match_table = am335x_child_of_match, 50 50 }, 51 51 }; 52 52
+14 -3
drivers/usb/musb/musb_core.c
··· 1809 1809 disable_irq_wake(musb->nIrq); 1810 1810 free_irq(musb->nIrq, musb); 1811 1811 } 1812 - if (musb->dma_controller) 1813 - dma_controller_destroy(musb->dma_controller); 1812 + cancel_work_sync(&musb->irq_work); 1814 1813 1815 1814 musb_host_free(musb); 1816 1815 } ··· 1884 1885 1885 1886 pm_runtime_get_sync(musb->controller); 1886 1887 1887 - if (use_dma && dev->dma_mask) 1888 + if (use_dma && dev->dma_mask) { 1888 1889 musb->dma_controller = dma_controller_create(musb, musb->mregs); 1890 + if (IS_ERR(musb->dma_controller)) { 1891 + status = PTR_ERR(musb->dma_controller); 1892 + goto fail2_5; 1893 + } 1894 + } 1889 1895 1890 1896 /* be sure interrupts are disabled before connecting ISR */ 1891 1897 musb_platform_disable(musb); ··· 1950 1946 if (status < 0) 1951 1947 goto fail3; 1952 1948 status = musb_gadget_setup(musb); 1949 + if (status) 1950 + musb_host_cleanup(musb); 1953 1951 break; 1954 1952 default: 1955 1953 dev_err(dev, "unsupported port mode %d\n", musb->port_mode); ··· 1978 1972 1979 1973 fail4: 1980 1974 musb_gadget_cleanup(musb); 1975 + musb_host_cleanup(musb); 1981 1976 1982 1977 fail3: 1983 1978 if (musb->dma_controller) 1984 1979 dma_controller_destroy(musb->dma_controller); 1980 + fail2_5: 1985 1981 pm_runtime_put_sync(musb->controller); 1986 1982 1987 1983 fail2: ··· 2039 2031 */ 2040 2032 musb_exit_debugfs(musb); 2041 2033 musb_shutdown(pdev); 2034 + 2035 + if (musb->dma_controller) 2036 + dma_controller_destroy(musb->dma_controller); 2042 2037 2043 2038 musb_free(musb); 2044 2039 device_init_wakeup(dev, 0);
+6 -2
drivers/usb/musb/musb_cppi41.c
··· 484 484 if (ret) 485 485 goto err; 486 486 487 + ret = -EINVAL; 487 488 if (port > MUSB_DMA_NUM_CHANNELS || !port) 488 489 goto err; 489 490 if (is_tx) ··· 504 503 dc = dma_request_slave_channel(dev, str); 505 504 if (!dc) { 506 505 dev_err(dev, "Falied to request %s.\n", str); 506 + ret = -EPROBE_DEFER; 507 507 goto err; 508 508 } 509 509 cppi41_channel->dc = dc; ··· 512 510 return 0; 513 511 err: 514 512 cppi41_release_all_dma_chans(controller); 515 - return -EINVAL; 513 + return ret; 516 514 } 517 515 518 516 void dma_controller_destroy(struct dma_controller *c) ··· 528 526 void __iomem *base) 529 527 { 530 528 struct cppi41_dma_controller *controller; 531 - int ret; 529 + int ret = 0; 532 530 533 531 if (!musb->controller->of_node) { 534 532 dev_err(musb->controller, "Need DT for the DMA engine.\n"); ··· 555 553 plat_get_fail: 556 554 kfree(controller); 557 555 kzalloc_fail: 556 + if (ret == -EPROBE_DEFER) 557 + return ERR_PTR(ret); 558 558 return NULL; 559 559 }
+48 -46
drivers/usb/musb/musb_dsps.c
··· 121 121 unsigned long last_timer; /* last timer data for each instance */ 122 122 }; 123 123 124 + static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) 125 + { 126 + struct device *dev = musb->controller; 127 + struct dsps_glue *glue = dev_get_drvdata(dev->parent); 128 + 129 + if (timeout == 0) 130 + timeout = jiffies + msecs_to_jiffies(3); 131 + 132 + /* Never idle if active, or when VBUS timeout is not set as host */ 133 + if (musb->is_active || (musb->a_wait_bcon == 0 && 134 + musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 135 + dev_dbg(musb->controller, "%s active, deleting timer\n", 136 + usb_otg_state_string(musb->xceiv->state)); 137 + del_timer(&glue->timer); 138 + glue->last_timer = jiffies; 139 + return; 140 + } 141 + if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE) 142 + return; 143 + 144 + if (!musb->g.dev.driver) 145 + return; 146 + 147 + if (time_after(glue->last_timer, timeout) && 148 + timer_pending(&glue->timer)) { 149 + dev_dbg(musb->controller, 150 + "Longer idle timer already pending, ignoring...\n"); 151 + return; 152 + } 153 + glue->last_timer = timeout; 154 + 155 + dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 156 + usb_otg_state_string(musb->xceiv->state), 157 + jiffies_to_msecs(timeout - jiffies)); 158 + mod_timer(&glue->timer, timeout); 159 + } 160 + 124 161 /** 125 162 * dsps_musb_enable - enable interrupts 126 163 */ ··· 180 143 /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 181 144 dsps_writel(reg_base, wrp->coreintr_set, 182 145 (1 << wrp->drvvbus) << wrp->usb_shift); 146 + dsps_musb_try_idle(musb, 0); 183 147 } 184 148 185 149 /** ··· 209 171 const struct dsps_musb_wrapper *wrp = glue->wrp; 210 172 u8 devctl; 211 173 unsigned long flags; 174 + int skip_session = 0; 212 175 213 176 /* 214 177 * We poll because DSPS IP's won't expose several OTG-critical ··· 222 183 spin_lock_irqsave(&musb->lock, flags); 223 184 switch (musb->xceiv->state) { 224 185 case OTG_STATE_A_WAIT_BCON: 225 - devctl &= ~MUSB_DEVCTL_SESSION; 226 - dsps_writeb(musb->mregs, MUSB_DEVCTL, devctl); 186 + dsps_writeb(musb->mregs, MUSB_DEVCTL, 0); 187 + skip_session = 1; 188 + /* fall */ 227 189 228 - devctl = dsps_readb(musb->mregs, MUSB_DEVCTL); 190 + case OTG_STATE_A_IDLE: 191 + case OTG_STATE_B_IDLE: 229 192 if (devctl & MUSB_DEVCTL_BDEVICE) { 230 193 musb->xceiv->state = OTG_STATE_B_IDLE; 231 194 MUSB_DEV_MODE(musb); ··· 235 194 musb->xceiv->state = OTG_STATE_A_IDLE; 236 195 MUSB_HST_MODE(musb); 237 196 } 197 + if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session) 198 + dsps_writeb(mregs, MUSB_DEVCTL, MUSB_DEVCTL_SESSION); 199 + mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); 238 200 break; 239 201 case OTG_STATE_A_WAIT_VFALL: 240 202 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 241 203 dsps_writel(musb->ctrl_base, wrp->coreintr_set, 242 204 MUSB_INTR_VBUSERROR << wrp->usb_shift); 243 205 break; 244 - case OTG_STATE_B_IDLE: 245 - devctl = dsps_readb(mregs, MUSB_DEVCTL); 246 - if (devctl & MUSB_DEVCTL_BDEVICE) 247 - mod_timer(&glue->timer, 248 - jiffies + wrp->poll_seconds * HZ); 249 - else 250 - musb->xceiv->state = OTG_STATE_A_IDLE; 251 - break; 252 206 default: 253 207 break; 254 208 } 255 209 spin_unlock_irqrestore(&musb->lock, flags); 256 - } 257 - 258 - static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) 259 - { 260 - struct device *dev = musb->controller; 261 - struct dsps_glue *glue = dev_get_drvdata(dev->parent); 262 - 263 - if (timeout == 0) 264 - timeout = jiffies + msecs_to_jiffies(3); 265 - 266 - /* Never idle if active, or when VBUS timeout is not set as host */ 267 - if (musb->is_active || (musb->a_wait_bcon == 0 && 268 - musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 269 - dev_dbg(musb->controller, "%s active, deleting timer\n", 270 - usb_otg_state_string(musb->xceiv->state)); 271 - del_timer(&glue->timer); 272 - glue->last_timer = jiffies; 273 - return; 274 - } 275 - if (musb->port_mode == MUSB_PORT_MODE_HOST) 276 - return; 277 - 278 - if (time_after(glue->last_timer, timeout) && 279 - timer_pending(&glue->timer)) { 280 - dev_dbg(musb->controller, 281 - "Longer idle timer already pending, ignoring...\n"); 282 - return; 283 - } 284 - glue->last_timer = timeout; 285 - 286 - dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 287 - usb_otg_state_string(musb->xceiv->state), 288 - jiffies_to_msecs(timeout - jiffies)); 289 - mod_timer(&glue->timer, timeout); 290 210 } 291 211 292 212 static irqreturn_t dsps_interrupt(int irq, void *hci) ··· 633 631 .remove = dsps_remove, 634 632 .driver = { 635 633 .name = "musb-dsps", 636 - .of_match_table = of_match_ptr(musb_dsps_of_match), 634 + .of_match_table = musb_dsps_of_match, 637 635 }, 638 636 }; 639 637
+18 -1
drivers/usb/musb/musb_virthub.c
··· 220 220 return retval; 221 221 } 222 222 223 + static int musb_has_gadget(struct musb *musb) 224 + { 225 + /* 226 + * In host-only mode we start a connection right away. In OTG mode 227 + * we have to wait until we loaded a gadget. We don't really need a 228 + * gadget if we operate as a host but we should not start a session 229 + * as a device without a gadget or else we explode. 230 + */ 231 + #ifdef CONFIG_USB_MUSB_HOST 232 + return 1; 233 + #else 234 + if (musb->port_mode == MUSB_PORT_MODE_HOST) 235 + return 1; 236 + return musb->g.dev.driver != NULL; 237 + #endif 238 + } 239 + 223 240 int musb_hub_control( 224 241 struct usb_hcd *hcd, 225 242 u16 typeReq, ··· 379 362 * initialization logic, e.g. for OTG, or change any 380 363 * logic relating to VBUS power-up. 381 364 */ 382 - if (!hcd->self.is_b_host) 365 + if (!hcd->self.is_b_host && musb_has_gadget(musb)) 383 366 musb_start(musb); 384 367 break; 385 368 case USB_PORT_FEAT_RESET:
+3
drivers/usb/musb/omap2430.c
··· 306 306 default: 307 307 dev_dbg(dev, "ID float\n"); 308 308 } 309 + 310 + atomic_notifier_call_chain(&musb->xceiv->notifier, 311 + musb->xceiv->last_event, NULL); 309 312 } 310 313 311 314
+16 -31
drivers/usb/musb/tusb6010.c
··· 1152 1152 .set_vbus = tusb_musb_set_vbus, 1153 1153 }; 1154 1154 1155 - static u64 tusb_dmamask = DMA_BIT_MASK(32); 1155 + static const struct platform_device_info tusb_dev_info = { 1156 + .name = "musb-hdrc", 1157 + .id = PLATFORM_DEVID_AUTO, 1158 + .dma_mask = DMA_BIT_MASK(32), 1159 + }; 1156 1160 1157 1161 static int tusb_probe(struct platform_device *pdev) 1158 1162 { ··· 1164 1160 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 1165 1161 struct platform_device *musb; 1166 1162 struct tusb6010_glue *glue; 1167 - 1163 + struct platform_device_info pinfo; 1168 1164 int ret = -ENOMEM; 1169 1165 1170 1166 glue = kzalloc(sizeof(*glue), GFP_KERNEL); ··· 1173 1169 goto err0; 1174 1170 } 1175 1171 1176 - musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 1177 - if (!musb) { 1178 - dev_err(&pdev->dev, "failed to allocate musb device\n"); 1179 - goto err1; 1180 - } 1181 - 1182 - musb->dev.parent = &pdev->dev; 1183 - musb->dev.dma_mask = &tusb_dmamask; 1184 - musb->dev.coherent_dma_mask = tusb_dmamask; 1185 - 1186 1172 glue->dev = &pdev->dev; 1187 - glue->musb = musb; 1188 1173 1189 1174 pdata->platform_ops = &tusb_ops; 1190 1175 ··· 1197 1204 musb_resources[2].end = pdev->resource[2].end; 1198 1205 musb_resources[2].flags = pdev->resource[2].flags; 1199 1206 1200 - ret = platform_device_add_resources(musb, musb_resources, 1201 - ARRAY_SIZE(musb_resources)); 1202 - if (ret) { 1203 - dev_err(&pdev->dev, "failed to add resources\n"); 1204 - goto err3; 1205 - } 1207 + pinfo = tusb_dev_info; 1208 + pinfo.parent = &pdev->dev; 1209 + pinfo.res = musb_resources; 1210 + pinfo.num_res = ARRAY_SIZE(musb_resources); 1211 + pinfo.data = pdata; 1212 + pinfo.size_data = sizeof(*pdata); 1206 1213 1207 - ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 1208 - if (ret) { 1209 - dev_err(&pdev->dev, "failed to add platform_data\n"); 1210 - goto err3; 1211 - } 1212 - 1213 - ret = platform_device_add(musb); 1214 - if (ret) { 1215 - dev_err(&pdev->dev, "failed to register musb device\n"); 1214 + glue->musb = musb = platform_device_register_full(&pinfo); 1215 + if (IS_ERR(musb)) { 1216 + ret = PTR_ERR(musb); 1217 + dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); 1216 1218 goto err3; 1217 1219 } 1218 1220 1219 1221 return 0; 1220 1222 1221 1223 err3: 1222 - platform_device_put(musb); 1223 - 1224 - err1: 1225 1224 kfree(glue); 1226 1225 1227 1226 err0:
+3 -10
drivers/usb/musb/ux500.c
··· 376 376 377 377 return 0; 378 378 } 379 - 380 - static const struct dev_pm_ops ux500_pm_ops = { 381 - .suspend = ux500_suspend, 382 - .resume = ux500_resume, 383 - }; 384 - 385 - #define DEV_PM_OPS (&ux500_pm_ops) 386 - #else 387 - #define DEV_PM_OPS NULL 388 379 #endif 380 + 381 + static SIMPLE_DEV_PM_OPS(ux500_pm_ops, ux500_suspend, ux500_resume); 389 382 390 383 static const struct of_device_id ux500_match[] = { 391 384 { .compatible = "stericsson,db8500-musb", }, ··· 390 397 .remove = ux500_remove, 391 398 .driver = { 392 399 .name = "musb-ux500", 393 - .pm = DEV_PM_OPS, 400 + .pm = &ux500_pm_ops, 394 401 .of_match_table = ux500_match, 395 402 }, 396 403 };
+13
drivers/usb/phy/Kconfig
··· 194 194 To compile this driver as a module, choose M here: the 195 195 module will be called phy-rcar-usb. 196 196 197 + config USB_RCAR_GEN2_PHY 198 + tristate "Renesas R-Car Gen2 USB PHY support" 199 + depends on ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST 200 + select USB_PHY 201 + help 202 + Say Y here to add support for the Renesas R-Car Gen2 USB PHY driver. 203 + It is typically used to control internal USB PHY for USBHS, 204 + and to configure shared USB channels 0 and 2. 205 + This driver supports R8A7790 and R8A7791. 206 + 207 + To compile this driver as a module, choose M here: the 208 + module will be called phy-rcar-gen2-usb. 209 + 197 210 config USB_ULPI 198 211 bool "Generic ULPI Transceiver Driver" 199 212 depends on ARM
+1
drivers/usb/phy/Makefile
··· 27 27 obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o 28 28 obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o 29 29 obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o 30 + obj-$(CONFIG_USB_RCAR_GEN2_PHY) += phy-rcar-gen2-usb.o 30 31 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o 31 32 obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o
+43 -1
drivers/usb/phy/phy-am335x-control.c
··· 26 26 #define USBPHY_OTGVDET_EN (1 << 19) 27 27 #define USBPHY_OTGSESSEND_EN (1 << 20) 28 28 29 + #define AM335X_PHY0_WK_EN (1 << 0) 30 + #define AM335X_PHY1_WK_EN (1 << 8) 31 + 32 + static void am335x_phy_wkup(struct phy_control *phy_ctrl, u32 id, bool on) 33 + { 34 + struct am335x_control_usb *usb_ctrl; 35 + u32 val; 36 + u32 reg; 37 + 38 + usb_ctrl = container_of(phy_ctrl, struct am335x_control_usb, phy_ctrl); 39 + 40 + switch (id) { 41 + case 0: 42 + reg = AM335X_PHY0_WK_EN; 43 + break; 44 + case 1: 45 + reg = AM335X_PHY1_WK_EN; 46 + break; 47 + default: 48 + WARN_ON(1); 49 + return; 50 + } 51 + 52 + spin_lock(&usb_ctrl->lock); 53 + val = readl(usb_ctrl->wkup); 54 + 55 + if (on) 56 + val |= reg; 57 + else 58 + val &= ~reg; 59 + 60 + writel(val, usb_ctrl->wkup); 61 + spin_unlock(&usb_ctrl->lock); 62 + } 63 + 29 64 static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on) 30 65 { 31 66 struct am335x_control_usb *usb_ctrl; ··· 94 59 95 60 static const struct phy_control ctrl_am335x = { 96 61 .phy_power = am335x_phy_power, 62 + .phy_wkup = am335x_phy_wkup, 97 63 }; 98 64 99 65 static const struct of_device_id omap_control_usb_id_table[] = { ··· 153 117 ctrl_usb->phy_reg = devm_ioremap_resource(&pdev->dev, res); 154 118 if (IS_ERR(ctrl_usb->phy_reg)) 155 119 return PTR_ERR(ctrl_usb->phy_reg); 120 + 121 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wakeup"); 122 + ctrl_usb->wkup = devm_ioremap_resource(&pdev->dev, res); 123 + if (IS_ERR(ctrl_usb->wkup)) 124 + return PTR_ERR(ctrl_usb->wkup); 125 + 156 126 spin_lock_init(&ctrl_usb->lock); 157 127 ctrl_usb->phy_ctrl = *phy_ctrl; 158 128 ··· 171 129 .driver = { 172 130 .name = "am335x-control-usb", 173 131 .owner = THIS_MODULE, 174 - .of_match_table = of_match_ptr(omap_control_usb_id_table), 132 + .of_match_table = omap_control_usb_id_table, 175 133 }, 176 134 }; 177 135
+39 -5
drivers/usb/phy/phy-am335x.c
··· 53 53 } 54 54 55 55 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, 56 - USB_PHY_TYPE_USB2, 0, false, false); 56 + USB_PHY_TYPE_USB2, 0, false); 57 57 if (ret) 58 58 return ret; 59 59 60 60 ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy); 61 61 if (ret) 62 - goto err_add; 62 + return ret; 63 63 am_phy->usb_phy_gen.phy.init = am335x_init; 64 64 am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; 65 65 66 66 platform_set_drvdata(pdev, am_phy); 67 + 67 68 return 0; 68 69 69 - err_add: 70 - usb_phy_gen_cleanup_phy(&am_phy->usb_phy_gen); 71 70 return ret; 72 71 } 73 72 ··· 77 78 usb_remove_phy(&am_phy->usb_phy_gen.phy); 78 79 return 0; 79 80 } 81 + 82 + #ifdef CONFIG_PM_RUNTIME 83 + 84 + static int am335x_phy_runtime_suspend(struct device *dev) 85 + { 86 + struct platform_device *pdev = to_platform_device(dev); 87 + struct am335x_phy *am_phy = platform_get_drvdata(pdev); 88 + 89 + if (device_may_wakeup(dev)) 90 + phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true); 91 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 92 + return 0; 93 + } 94 + 95 + static int am335x_phy_runtime_resume(struct device *dev) 96 + { 97 + struct platform_device *pdev = to_platform_device(dev); 98 + struct am335x_phy *am_phy = platform_get_drvdata(pdev); 99 + 100 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); 101 + if (device_may_wakeup(dev)) 102 + phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false); 103 + return 0; 104 + } 105 + 106 + static const struct dev_pm_ops am335x_pm_ops = { 107 + SET_RUNTIME_PM_OPS(am335x_phy_runtime_suspend, 108 + am335x_phy_runtime_resume, NULL) 109 + }; 110 + 111 + #define DEV_PM_OPS (&am335x_pm_ops) 112 + #else 113 + #define DEV_PM_OPS NULL 114 + #endif 80 115 81 116 static const struct of_device_id am335x_phy_ids[] = { 82 117 { .compatible = "ti,am335x-usb-phy" }, ··· 124 91 .driver = { 125 92 .name = "am335x-phy-driver", 126 93 .owner = THIS_MODULE, 127 - .of_match_table = of_match_ptr(am335x_phy_ids), 94 + .pm = DEV_PM_OPS, 95 + .of_match_table = am335x_phy_ids, 128 96 }, 129 97 }; 130 98
+76 -20
drivers/usb/phy/phy-fsl-usb.c
··· 134 134 /* Operations that will be called from OTG Finite State Machine */ 135 135 136 136 /* Charge vbus for vbus pulsing in SRP */ 137 - void fsl_otg_chrg_vbus(int on) 137 + void fsl_otg_chrg_vbus(struct otg_fsm *fsm, int on) 138 138 { 139 139 u32 tmp; 140 140 ··· 170 170 } 171 171 172 172 /* A-device driver vbus, controlled through PP bit in PORTSC */ 173 - void fsl_otg_drv_vbus(int on) 173 + void fsl_otg_drv_vbus(struct otg_fsm *fsm, int on) 174 174 { 175 175 u32 tmp; 176 176 ··· 188 188 * Pull-up D+, signalling connect by periperal. Also used in 189 189 * data-line pulsing in SRP 190 190 */ 191 - void fsl_otg_loc_conn(int on) 191 + void fsl_otg_loc_conn(struct otg_fsm *fsm, int on) 192 192 { 193 193 u32 tmp; 194 194 ··· 207 207 * port. In host mode, controller will automatically send SOF. 208 208 * Suspend will block the data on the port. 209 209 */ 210 - void fsl_otg_loc_sof(int on) 210 + void fsl_otg_loc_sof(struct otg_fsm *fsm, int on) 211 211 { 212 212 u32 tmp; 213 213 ··· 222 222 } 223 223 224 224 /* Start SRP pulsing by data-line pulsing, followed with v-bus pulsing. */ 225 - void fsl_otg_start_pulse(void) 225 + void fsl_otg_start_pulse(struct otg_fsm *fsm) 226 226 { 227 227 u32 tmp; 228 228 ··· 235 235 fsl_otg_loc_conn(1); 236 236 #endif 237 237 238 - fsl_otg_add_timer(b_data_pulse_tmr); 238 + fsl_otg_add_timer(fsm, b_data_pulse_tmr); 239 239 } 240 240 241 241 void b_data_pulse_end(unsigned long foo) ··· 252 252 void fsl_otg_pulse_vbus(void) 253 253 { 254 254 srp_wait_done = 0; 255 - fsl_otg_chrg_vbus(1); 255 + fsl_otg_chrg_vbus(&fsl_otg_dev->fsm, 1); 256 256 /* start the timer to end vbus charge */ 257 - fsl_otg_add_timer(b_vbus_pulse_tmr); 257 + fsl_otg_add_timer(&fsl_otg_dev->fsm, b_vbus_pulse_tmr); 258 258 } 259 259 260 260 void b_vbus_pulse_end(unsigned long foo) 261 261 { 262 - fsl_otg_chrg_vbus(0); 262 + fsl_otg_chrg_vbus(&fsl_otg_dev->fsm, 0); 263 263 264 264 /* 265 265 * As USB3300 using the same a_sess_vld and b_sess_vld voltage ··· 267 267 * residual voltage of vbus pulsing and A device pull up 268 268 */ 269 269 fsl_otg_dischrg_vbus(1); 270 - fsl_otg_add_timer(b_srp_wait_tmr); 270 + fsl_otg_add_timer(&fsl_otg_dev->fsm, b_srp_wait_tmr); 271 271 } 272 272 273 273 void b_srp_end(unsigned long foo) ··· 289 289 { 290 290 VDBG("a_wait_enum timeout\n"); 291 291 if (!fsl_otg_dev->phy.otg->host->b_hnp_enable) 292 - fsl_otg_add_timer(a_wait_enum_tmr); 292 + fsl_otg_add_timer(&fsl_otg_dev->fsm, a_wait_enum_tmr); 293 293 else 294 294 otg_statemachine(&fsl_otg_dev->fsm); 295 295 } ··· 375 375 kfree(b_vbus_pulse_tmr); 376 376 } 377 377 378 + static struct fsl_otg_timer *fsl_otg_get_timer(enum otg_fsm_timer t) 379 + { 380 + struct fsl_otg_timer *timer; 381 + 382 + /* REVISIT: use array of pointers to timers instead */ 383 + switch (t) { 384 + case A_WAIT_VRISE: 385 + timer = a_wait_vrise_tmr; 386 + break; 387 + case A_WAIT_BCON: 388 + timer = a_wait_vrise_tmr; 389 + break; 390 + case A_AIDL_BDIS: 391 + timer = a_wait_vrise_tmr; 392 + break; 393 + case B_ASE0_BRST: 394 + timer = a_wait_vrise_tmr; 395 + break; 396 + case B_SE0_SRP: 397 + timer = a_wait_vrise_tmr; 398 + break; 399 + case B_SRP_FAIL: 400 + timer = a_wait_vrise_tmr; 401 + break; 402 + case A_WAIT_ENUM: 403 + timer = a_wait_vrise_tmr; 404 + break; 405 + default: 406 + timer = NULL; 407 + } 408 + 409 + return timer; 410 + } 411 + 378 412 /* Add timer to timer list */ 379 - void fsl_otg_add_timer(void *gtimer) 413 + void fsl_otg_add_timer(struct otg_fsm *fsm, void *gtimer) 380 414 { 381 415 struct fsl_otg_timer *timer = gtimer; 382 416 struct fsl_otg_timer *tmp_timer; ··· 428 394 list_add_tail(&timer->list, &active_timers); 429 395 } 430 396 397 + static void fsl_otg_fsm_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer t) 398 + { 399 + struct fsl_otg_timer *timer; 400 + 401 + timer = fsl_otg_get_timer(t); 402 + if (!timer) 403 + return; 404 + 405 + fsl_otg_add_timer(fsm, timer); 406 + } 407 + 431 408 /* Remove timer from the timer list; clear timeout status */ 432 - void fsl_otg_del_timer(void *gtimer) 409 + void fsl_otg_del_timer(struct otg_fsm *fsm, void *gtimer) 433 410 { 434 411 struct fsl_otg_timer *timer = gtimer; 435 412 struct fsl_otg_timer *tmp_timer, *del_tmp; ··· 448 403 list_for_each_entry_safe(tmp_timer, del_tmp, &active_timers, list) 449 404 if (tmp_timer == timer) 450 405 list_del(&timer->list); 406 + } 407 + 408 + static void fsl_otg_fsm_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer t) 409 + { 410 + struct fsl_otg_timer *timer; 411 + 412 + timer = fsl_otg_get_timer(t); 413 + if (!timer) 414 + return; 415 + 416 + fsl_otg_del_timer(fsm, timer); 451 417 } 452 418 453 419 /* ··· 524 468 retval = dev->driver->pm->resume(dev); 525 469 if (fsm->id) { 526 470 /* default-b */ 527 - fsl_otg_drv_vbus(1); 471 + fsl_otg_drv_vbus(fsm, 1); 528 472 /* 529 473 * Workaround: b_host can't driver 530 474 * vbus, but PP in PORTSC needs to ··· 549 493 retval = dev->driver->pm->suspend(dev); 550 494 if (fsm->id) 551 495 /* default-b */ 552 - fsl_otg_drv_vbus(0); 496 + fsl_otg_drv_vbus(fsm, 0); 553 497 } 554 498 otg_dev->host_working = 0; 555 499 } ··· 813 757 .loc_sof = fsl_otg_loc_sof, 814 758 .start_pulse = fsl_otg_start_pulse, 815 759 816 - .add_timer = fsl_otg_add_timer, 817 - .del_timer = fsl_otg_del_timer, 760 + .add_timer = fsl_otg_fsm_add_timer, 761 + .del_timer = fsl_otg_fsm_del_timer, 818 762 819 763 .start_host = fsl_otg_start_host, 820 764 .start_gadget = fsl_otg_start_gadget, ··· 1067 1011 "b_bus_suspend: %d\n" 1068 1012 "b_conn: %d\n" 1069 1013 "b_se0_srp: %d\n" 1070 - "b_sess_end: %d\n" 1014 + "b_ssend_srp: %d\n" 1071 1015 "b_sess_vld: %d\n" 1072 1016 "id: %d\n", 1073 1017 fsm->a_bus_req, ··· 1082 1026 fsm->b_bus_suspend, 1083 1027 fsm->b_conn, 1084 1028 fsm->b_se0_srp, 1085 - fsm->b_sess_end, 1029 + fsm->b_ssend_srp, 1086 1030 fsm->b_sess_vld, 1087 1031 fsm->id); 1088 1032 size -= t; ··· 1113 1057 break; 1114 1058 1115 1059 case SET_A_SUSPEND_REQ: 1116 - fsl_otg_dev->fsm.a_suspend_req = arg; 1060 + fsl_otg_dev->fsm.a_suspend_req_inf = arg; 1117 1061 break; 1118 1062 1119 1063 case SET_A_BUS_DROP:
+2 -2
drivers/usb/phy/phy-fsl-usb.h
··· 401 401 #define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int) 402 402 #define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int) 403 403 404 - void fsl_otg_add_timer(void *timer); 405 - void fsl_otg_del_timer(void *timer); 404 + void fsl_otg_add_timer(struct otg_fsm *fsm, void *timer); 405 + void fsl_otg_del_timer(struct otg_fsm *fsm, void *timer); 406 406 void fsl_otg_pulse_vbus(void);
+45 -27
drivers/usb/phy/phy-fsm-usb.c
··· 41 41 fsm->protocol, protocol); 42 42 /* stop old protocol */ 43 43 if (fsm->protocol == PROTO_HOST) 44 - ret = fsm->ops->start_host(fsm, 0); 44 + ret = otg_start_host(fsm, 0); 45 45 else if (fsm->protocol == PROTO_GADGET) 46 - ret = fsm->ops->start_gadget(fsm, 0); 46 + ret = otg_start_gadget(fsm, 0); 47 47 if (ret) 48 48 return ret; 49 49 50 50 /* start new protocol */ 51 51 if (protocol == PROTO_HOST) 52 - ret = fsm->ops->start_host(fsm, 1); 52 + ret = otg_start_host(fsm, 1); 53 53 else if (protocol == PROTO_GADGET) 54 - ret = fsm->ops->start_gadget(fsm, 1); 54 + ret = otg_start_gadget(fsm, 1); 55 55 if (ret) 56 56 return ret; 57 57 ··· 69 69 { 70 70 switch (old_state) { 71 71 case OTG_STATE_B_IDLE: 72 - otg_del_timer(fsm, b_se0_srp_tmr); 72 + otg_del_timer(fsm, B_SE0_SRP); 73 73 fsm->b_se0_srp = 0; 74 + fsm->adp_sns = 0; 75 + fsm->adp_prb = 0; 74 76 break; 75 77 case OTG_STATE_B_SRP_INIT: 78 + fsm->data_pulse = 0; 76 79 fsm->b_srp_done = 0; 77 80 break; 78 81 case OTG_STATE_B_PERIPHERAL: 79 82 break; 80 83 case OTG_STATE_B_WAIT_ACON: 81 - otg_del_timer(fsm, b_ase0_brst_tmr); 84 + otg_del_timer(fsm, B_ASE0_BRST); 82 85 fsm->b_ase0_brst_tmout = 0; 83 86 break; 84 87 case OTG_STATE_B_HOST: 85 88 break; 86 89 case OTG_STATE_A_IDLE: 90 + fsm->adp_prb = 0; 87 91 break; 88 92 case OTG_STATE_A_WAIT_VRISE: 89 - otg_del_timer(fsm, a_wait_vrise_tmr); 93 + otg_del_timer(fsm, A_WAIT_VRISE); 90 94 fsm->a_wait_vrise_tmout = 0; 91 95 break; 92 96 case OTG_STATE_A_WAIT_BCON: 93 - otg_del_timer(fsm, a_wait_bcon_tmr); 97 + otg_del_timer(fsm, A_WAIT_BCON); 94 98 fsm->a_wait_bcon_tmout = 0; 95 99 break; 96 100 case OTG_STATE_A_HOST: 97 - otg_del_timer(fsm, a_wait_enum_tmr); 101 + otg_del_timer(fsm, A_WAIT_ENUM); 98 102 break; 99 103 case OTG_STATE_A_SUSPEND: 100 - otg_del_timer(fsm, a_aidl_bdis_tmr); 104 + otg_del_timer(fsm, A_AIDL_BDIS); 101 105 fsm->a_aidl_bdis_tmout = 0; 102 - fsm->a_suspend_req = 0; 106 + fsm->a_suspend_req_inf = 0; 103 107 break; 104 108 case OTG_STATE_A_PERIPHERAL: 109 + otg_del_timer(fsm, A_BIDL_ADIS); 110 + fsm->a_bidl_adis_tmout = 0; 105 111 break; 106 112 case OTG_STATE_A_WAIT_VFALL: 107 - otg_del_timer(fsm, a_wait_vrise_tmr); 113 + otg_del_timer(fsm, A_WAIT_VFALL); 114 + fsm->a_wait_vfall_tmout = 0; 115 + otg_del_timer(fsm, A_WAIT_VRISE); 108 116 break; 109 117 case OTG_STATE_A_VBUS_ERR: 110 118 break; ··· 135 127 otg_chrg_vbus(fsm, 0); 136 128 otg_loc_conn(fsm, 0); 137 129 otg_loc_sof(fsm, 0); 130 + /* 131 + * Driver is responsible for starting ADP probing 132 + * if ADP sensing times out. 133 + */ 134 + otg_start_adp_sns(fsm); 138 135 otg_set_protocol(fsm, PROTO_UNDEF); 139 - otg_add_timer(fsm, b_se0_srp_tmr); 136 + otg_add_timer(fsm, B_SE0_SRP); 140 137 break; 141 138 case OTG_STATE_B_SRP_INIT: 142 139 otg_start_pulse(fsm); 143 140 otg_loc_sof(fsm, 0); 144 141 otg_set_protocol(fsm, PROTO_UNDEF); 145 - otg_add_timer(fsm, b_srp_fail_tmr); 142 + otg_add_timer(fsm, B_SRP_FAIL); 146 143 break; 147 144 case OTG_STATE_B_PERIPHERAL: 148 145 otg_chrg_vbus(fsm, 0); ··· 160 147 otg_loc_conn(fsm, 0); 161 148 otg_loc_sof(fsm, 0); 162 149 otg_set_protocol(fsm, PROTO_HOST); 163 - otg_add_timer(fsm, b_ase0_brst_tmr); 150 + otg_add_timer(fsm, B_ASE0_BRST); 164 151 fsm->a_bus_suspend = 0; 165 152 break; 166 153 case OTG_STATE_B_HOST: ··· 176 163 otg_chrg_vbus(fsm, 0); 177 164 otg_loc_conn(fsm, 0); 178 165 otg_loc_sof(fsm, 0); 166 + otg_start_adp_prb(fsm); 179 167 otg_set_protocol(fsm, PROTO_HOST); 180 168 break; 181 169 case OTG_STATE_A_WAIT_VRISE: ··· 184 170 otg_loc_conn(fsm, 0); 185 171 otg_loc_sof(fsm, 0); 186 172 otg_set_protocol(fsm, PROTO_HOST); 187 - otg_add_timer(fsm, a_wait_vrise_tmr); 173 + otg_add_timer(fsm, A_WAIT_VRISE); 188 174 break; 189 175 case OTG_STATE_A_WAIT_BCON: 190 176 otg_drv_vbus(fsm, 1); 191 177 otg_loc_conn(fsm, 0); 192 178 otg_loc_sof(fsm, 0); 193 179 otg_set_protocol(fsm, PROTO_HOST); 194 - otg_add_timer(fsm, a_wait_bcon_tmr); 180 + otg_add_timer(fsm, A_WAIT_BCON); 195 181 break; 196 182 case OTG_STATE_A_HOST: 197 183 otg_drv_vbus(fsm, 1); ··· 202 188 * When HNP is triggered while a_bus_req = 0, a_host will 203 189 * suspend too fast to complete a_set_b_hnp_en 204 190 */ 205 - if (!fsm->a_bus_req || fsm->a_suspend_req) 206 - otg_add_timer(fsm, a_wait_enum_tmr); 191 + if (!fsm->a_bus_req || fsm->a_suspend_req_inf) 192 + otg_add_timer(fsm, A_WAIT_ENUM); 207 193 break; 208 194 case OTG_STATE_A_SUSPEND: 209 195 otg_drv_vbus(fsm, 1); 210 196 otg_loc_conn(fsm, 0); 211 197 otg_loc_sof(fsm, 0); 212 198 otg_set_protocol(fsm, PROTO_HOST); 213 - otg_add_timer(fsm, a_aidl_bdis_tmr); 199 + otg_add_timer(fsm, A_AIDL_BDIS); 214 200 215 201 break; 216 202 case OTG_STATE_A_PERIPHERAL: ··· 218 204 otg_loc_sof(fsm, 0); 219 205 otg_set_protocol(fsm, PROTO_GADGET); 220 206 otg_drv_vbus(fsm, 1); 207 + otg_add_timer(fsm, A_BIDL_ADIS); 221 208 break; 222 209 case OTG_STATE_A_WAIT_VFALL: 223 210 otg_drv_vbus(fsm, 0); 224 211 otg_loc_conn(fsm, 0); 225 212 otg_loc_sof(fsm, 0); 226 213 otg_set_protocol(fsm, PROTO_HOST); 214 + otg_add_timer(fsm, A_WAIT_VFALL); 227 215 break; 228 216 case OTG_STATE_A_VBUS_ERR: 229 217 otg_drv_vbus(fsm, 0); ··· 266 250 otg_set_state(fsm, OTG_STATE_A_IDLE); 267 251 else if (fsm->b_sess_vld && fsm->otg->gadget) 268 252 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); 269 - else if (fsm->b_bus_req && fsm->b_sess_end && fsm->b_se0_srp) 253 + else if ((fsm->b_bus_req || fsm->adp_change || fsm->power_up) && 254 + fsm->b_ssend_srp && fsm->b_se0_srp) 270 255 otg_set_state(fsm, OTG_STATE_B_SRP_INIT); 271 256 break; 272 257 case OTG_STATE_B_SRP_INIT: ··· 294 277 case OTG_STATE_B_HOST: 295 278 if (!fsm->id || !fsm->b_sess_vld) 296 279 otg_set_state(fsm, OTG_STATE_B_IDLE); 297 - else if (!fsm->b_bus_req || !fsm->a_conn) 280 + else if (!fsm->b_bus_req || !fsm->a_conn || fsm->test_device) 298 281 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); 299 282 break; 300 283 case OTG_STATE_A_IDLE: 301 284 if (fsm->id) 302 285 otg_set_state(fsm, OTG_STATE_B_IDLE); 303 - else if (!fsm->a_bus_drop && (fsm->a_bus_req || fsm->a_srp_det)) 286 + else if (!fsm->a_bus_drop && (fsm->a_bus_req || 287 + fsm->a_srp_det || fsm->adp_change || fsm->power_up)) 304 288 otg_set_state(fsm, OTG_STATE_A_WAIT_VRISE); 305 289 break; 306 290 case OTG_STATE_A_WAIT_VRISE: ··· 319 301 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); 320 302 break; 321 303 case OTG_STATE_A_HOST: 322 - if ((!fsm->a_bus_req || fsm->a_suspend_req) && 304 + if ((!fsm->a_bus_req || fsm->a_suspend_req_inf) && 323 305 fsm->otg->host->b_hnp_enable) 324 306 otg_set_state(fsm, OTG_STATE_A_SUSPEND); 325 307 else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop) ··· 342 324 case OTG_STATE_A_PERIPHERAL: 343 325 if (fsm->id || fsm->a_bus_drop) 344 326 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); 345 - else if (fsm->b_bus_suspend) 327 + else if (fsm->a_bidl_adis_tmout || fsm->b_bus_suspend) 346 328 otg_set_state(fsm, OTG_STATE_A_WAIT_BCON); 347 329 else if (!fsm->a_vbus_vld) 348 330 otg_set_state(fsm, OTG_STATE_A_VBUS_ERR); 349 331 break; 350 332 case OTG_STATE_A_WAIT_VFALL: 351 - if (fsm->id || fsm->a_bus_req || (!fsm->a_sess_vld && 352 - !fsm->b_conn)) 333 + if (fsm->a_wait_vfall_tmout || fsm->id || fsm->a_bus_req || 334 + (!fsm->a_sess_vld && !fsm->b_conn)) 353 335 otg_set_state(fsm, OTG_STATE_A_IDLE); 354 336 break; 355 337 case OTG_STATE_A_VBUS_ERR:
+134 -45
drivers/usb/phy/phy-fsm-usb.h
··· 34 34 #define PROTO_HOST (1) 35 35 #define PROTO_GADGET (2) 36 36 37 + enum otg_fsm_timer { 38 + /* Standard OTG timers */ 39 + A_WAIT_VRISE, 40 + A_WAIT_VFALL, 41 + A_WAIT_BCON, 42 + A_AIDL_BDIS, 43 + B_ASE0_BRST, 44 + A_BIDL_ADIS, 45 + 46 + /* Auxiliary timers */ 47 + B_SE0_SRP, 48 + B_SRP_FAIL, 49 + A_WAIT_ENUM, 50 + 51 + NUM_OTG_FSM_TIMERS, 52 + }; 53 + 37 54 /* OTG state machine according to the OTG spec */ 38 55 struct otg_fsm { 39 56 /* Input */ 57 + int id; 58 + int adp_change; 59 + int power_up; 60 + int test_device; 61 + int a_bus_drop; 62 + int a_bus_req; 63 + int a_srp_det; 64 + int a_vbus_vld; 65 + int b_conn; 40 66 int a_bus_resume; 41 67 int a_bus_suspend; 42 68 int a_conn; 69 + int b_bus_req; 70 + int b_se0_srp; 71 + int b_ssend_srp; 72 + int b_sess_vld; 73 + /* Auxilary inputs */ 43 74 int a_sess_vld; 44 - int a_srp_det; 45 - int a_vbus_vld; 46 75 int b_bus_resume; 47 76 int b_bus_suspend; 48 - int b_conn; 49 - int b_se0_srp; 50 - int b_sess_end; 51 - int b_sess_vld; 52 - int id; 77 + 78 + /* Output */ 79 + int data_pulse; 80 + int drv_vbus; 81 + int loc_conn; 82 + int loc_sof; 83 + int adp_prb; 84 + int adp_sns; 53 85 54 86 /* Internal variables */ 55 87 int a_set_b_hnp_en; 56 88 int b_srp_done; 57 89 int b_hnp_enable; 90 + int a_clr_err; 91 + 92 + /* Informative variables */ 93 + int a_bus_drop_inf; 94 + int a_bus_req_inf; 95 + int a_clr_err_inf; 96 + int b_bus_req_inf; 97 + /* Auxilary informative variables */ 98 + int a_suspend_req_inf; 58 99 59 100 /* Timeout indicator for timers */ 60 101 int a_wait_vrise_tmout; 102 + int a_wait_vfall_tmout; 61 103 int a_wait_bcon_tmout; 62 104 int a_aidl_bdis_tmout; 63 105 int b_ase0_brst_tmout; 64 - 65 - /* Informative variables */ 66 - int a_bus_drop; 67 - int a_bus_req; 68 - int a_clr_err; 69 - int a_suspend_req; 70 - int b_bus_req; 71 - 72 - /* Output */ 73 - int drv_vbus; 74 - int loc_conn; 75 - int loc_sof; 106 + int a_bidl_adis_tmout; 76 107 77 108 struct otg_fsm_ops *ops; 78 109 struct usb_otg *otg; ··· 114 83 }; 115 84 116 85 struct otg_fsm_ops { 117 - void (*chrg_vbus)(int on); 118 - void (*drv_vbus)(int on); 119 - void (*loc_conn)(int on); 120 - void (*loc_sof)(int on); 121 - void (*start_pulse)(void); 122 - void (*add_timer)(void *timer); 123 - void (*del_timer)(void *timer); 86 + void (*chrg_vbus)(struct otg_fsm *fsm, int on); 87 + void (*drv_vbus)(struct otg_fsm *fsm, int on); 88 + void (*loc_conn)(struct otg_fsm *fsm, int on); 89 + void (*loc_sof)(struct otg_fsm *fsm, int on); 90 + void (*start_pulse)(struct otg_fsm *fsm); 91 + void (*start_adp_prb)(struct otg_fsm *fsm); 92 + void (*start_adp_sns)(struct otg_fsm *fsm); 93 + void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer); 94 + void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer); 124 95 int (*start_host)(struct otg_fsm *fsm, int on); 125 96 int (*start_gadget)(struct otg_fsm *fsm, int on); 126 97 }; 127 98 128 99 129 - static inline void otg_chrg_vbus(struct otg_fsm *fsm, int on) 100 + static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on) 130 101 { 131 - fsm->ops->chrg_vbus(on); 102 + if (!fsm->ops->chrg_vbus) 103 + return -EOPNOTSUPP; 104 + fsm->ops->chrg_vbus(fsm, on); 105 + return 0; 132 106 } 133 107 134 - static inline void otg_drv_vbus(struct otg_fsm *fsm, int on) 108 + static inline int otg_drv_vbus(struct otg_fsm *fsm, int on) 135 109 { 110 + if (!fsm->ops->drv_vbus) 111 + return -EOPNOTSUPP; 136 112 if (fsm->drv_vbus != on) { 137 113 fsm->drv_vbus = on; 138 - fsm->ops->drv_vbus(on); 114 + fsm->ops->drv_vbus(fsm, on); 139 115 } 116 + return 0; 140 117 } 141 118 142 - static inline void otg_loc_conn(struct otg_fsm *fsm, int on) 119 + static inline int otg_loc_conn(struct otg_fsm *fsm, int on) 143 120 { 121 + if (!fsm->ops->loc_conn) 122 + return -EOPNOTSUPP; 144 123 if (fsm->loc_conn != on) { 145 124 fsm->loc_conn = on; 146 - fsm->ops->loc_conn(on); 125 + fsm->ops->loc_conn(fsm, on); 147 126 } 127 + return 0; 148 128 } 149 129 150 - static inline void otg_loc_sof(struct otg_fsm *fsm, int on) 130 + static inline int otg_loc_sof(struct otg_fsm *fsm, int on) 151 131 { 132 + if (!fsm->ops->loc_sof) 133 + return -EOPNOTSUPP; 152 134 if (fsm->loc_sof != on) { 153 135 fsm->loc_sof = on; 154 - fsm->ops->loc_sof(on); 136 + fsm->ops->loc_sof(fsm, on); 155 137 } 138 + return 0; 156 139 } 157 140 158 - static inline void otg_start_pulse(struct otg_fsm *fsm) 141 + static inline int otg_start_pulse(struct otg_fsm *fsm) 159 142 { 160 - fsm->ops->start_pulse(); 143 + if (!fsm->ops->start_pulse) 144 + return -EOPNOTSUPP; 145 + if (!fsm->data_pulse) { 146 + fsm->data_pulse = 1; 147 + fsm->ops->start_pulse(fsm); 148 + } 149 + return 0; 161 150 } 162 151 163 - static inline void otg_add_timer(struct otg_fsm *fsm, void *timer) 152 + static inline int otg_start_adp_prb(struct otg_fsm *fsm) 164 153 { 165 - fsm->ops->add_timer(timer); 154 + if (!fsm->ops->start_adp_prb) 155 + return -EOPNOTSUPP; 156 + if (!fsm->adp_prb) { 157 + fsm->adp_sns = 0; 158 + fsm->adp_prb = 1; 159 + fsm->ops->start_adp_prb(fsm); 160 + } 161 + return 0; 166 162 } 167 163 168 - static inline void otg_del_timer(struct otg_fsm *fsm, void *timer) 164 + static inline int otg_start_adp_sns(struct otg_fsm *fsm) 169 165 { 170 - fsm->ops->del_timer(timer); 166 + if (!fsm->ops->start_adp_sns) 167 + return -EOPNOTSUPP; 168 + if (!fsm->adp_sns) { 169 + fsm->adp_sns = 1; 170 + fsm->ops->start_adp_sns(fsm); 171 + } 172 + return 0; 173 + } 174 + 175 + static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer) 176 + { 177 + if (!fsm->ops->add_timer) 178 + return -EOPNOTSUPP; 179 + fsm->ops->add_timer(fsm, timer); 180 + return 0; 181 + } 182 + 183 + static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer) 184 + { 185 + if (!fsm->ops->del_timer) 186 + return -EOPNOTSUPP; 187 + fsm->ops->del_timer(fsm, timer); 188 + return 0; 189 + } 190 + 191 + static inline int otg_start_host(struct otg_fsm *fsm, int on) 192 + { 193 + if (!fsm->ops->start_host) 194 + return -EOPNOTSUPP; 195 + return fsm->ops->start_host(fsm, on); 196 + } 197 + 198 + static inline int otg_start_gadget(struct otg_fsm *fsm, int on) 199 + { 200 + if (!fsm->ops->start_gadget) 201 + return -EOPNOTSUPP; 202 + return fsm->ops->start_gadget(fsm, on); 171 203 } 172 204 173 205 int otg_statemachine(struct otg_fsm *fsm); 174 - 175 - /* Defined by device specific driver, for different timer implementation */ 176 - extern struct fsl_otg_timer *a_wait_vrise_tmr, *a_wait_bcon_tmr, 177 - *a_aidl_bdis_tmr, *b_ase0_brst_tmr, *b_se0_srp_tmr, *b_srp_fail_tmr, 178 - *a_wait_enum_tmr;
+68 -58
drivers/usb/phy/phy-generic.c
··· 35 35 #include <linux/clk.h> 36 36 #include <linux/regulator/consumer.h> 37 37 #include <linux/of.h> 38 + #include <linux/of_gpio.h> 39 + #include <linux/gpio.h> 40 + #include <linux/delay.h> 38 41 39 42 #include "phy-generic.h" 40 43 ··· 67 64 return 0; 68 65 } 69 66 67 + static void nop_reset_set(struct usb_phy_gen_xceiv *nop, int asserted) 68 + { 69 + int value; 70 + 71 + if (!gpio_is_valid(nop->gpio_reset)) 72 + return; 73 + 74 + value = asserted; 75 + if (nop->reset_active_low) 76 + value = !value; 77 + 78 + gpio_set_value_cansleep(nop->gpio_reset, value); 79 + 80 + if (!asserted) 81 + usleep_range(10000, 20000); 82 + } 83 + 70 84 int usb_gen_phy_init(struct usb_phy *phy) 71 85 { 72 86 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); ··· 94 74 } 95 75 96 76 if (!IS_ERR(nop->clk)) 97 - clk_enable(nop->clk); 77 + clk_prepare_enable(nop->clk); 98 78 99 - if (!IS_ERR(nop->reset)) { 100 - /* De-assert RESET */ 101 - if (regulator_enable(nop->reset)) 102 - dev_err(phy->dev, "Failed to de-assert reset\n"); 103 - } 79 + /* De-assert RESET */ 80 + nop_reset_set(nop, 0); 104 81 105 82 return 0; 106 83 } ··· 107 90 { 108 91 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); 109 92 110 - if (!IS_ERR(nop->reset)) { 111 - /* Assert RESET */ 112 - if (regulator_disable(nop->reset)) 113 - dev_err(phy->dev, "Failed to assert reset\n"); 114 - } 93 + /* Assert RESET */ 94 + nop_reset_set(nop, 1); 115 95 116 96 if (!IS_ERR(nop->clk)) 117 - clk_disable(nop->clk); 97 + clk_disable_unprepare(nop->clk); 118 98 119 99 if (!IS_ERR(nop->vcc)) { 120 100 if (regulator_disable(nop->vcc)) ··· 150 136 } 151 137 152 138 int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, 153 - enum usb_phy_type type, u32 clk_rate, bool needs_vcc, 154 - bool needs_reset) 139 + enum usb_phy_type type, u32 clk_rate, bool needs_vcc) 155 140 { 156 141 int err; 157 142 ··· 173 160 } 174 161 } 175 162 176 - if (!IS_ERR(nop->clk)) { 177 - err = clk_prepare(nop->clk); 178 - if (err) { 179 - dev_err(dev, "Error preparing clock\n"); 180 - return err; 181 - } 182 - } 183 - 184 163 nop->vcc = devm_regulator_get(dev, "vcc"); 185 164 if (IS_ERR(nop->vcc)) { 186 165 dev_dbg(dev, "Error getting vcc regulator: %ld\n", ··· 181 176 return -EPROBE_DEFER; 182 177 } 183 178 184 - nop->reset = devm_regulator_get(dev, "reset"); 185 - if (IS_ERR(nop->reset)) { 186 - dev_dbg(dev, "Error getting reset regulator: %ld\n", 187 - PTR_ERR(nop->reset)); 188 - if (needs_reset) 189 - return -EPROBE_DEFER; 179 + if (gpio_is_valid(nop->gpio_reset)) { 180 + unsigned long gpio_flags; 181 + 182 + /* Assert RESET */ 183 + if (nop->reset_active_low) 184 + gpio_flags = GPIOF_OUT_INIT_LOW; 185 + else 186 + gpio_flags = GPIOF_OUT_INIT_HIGH; 187 + 188 + err = devm_gpio_request_one(dev, nop->gpio_reset, 189 + gpio_flags, dev_name(dev)); 190 + if (err) { 191 + dev_err(dev, "Error requesting RESET GPIO %d\n", 192 + nop->gpio_reset); 193 + return err; 194 + } 190 195 } 191 196 192 197 nop->dev = dev; ··· 215 200 } 216 201 EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); 217 202 218 - void usb_phy_gen_cleanup_phy(struct usb_phy_gen_xceiv *nop) 219 - { 220 - if (!IS_ERR(nop->clk)) 221 - clk_unprepare(nop->clk); 222 - } 223 - EXPORT_SYMBOL_GPL(usb_phy_gen_cleanup_phy); 224 - 225 203 static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) 226 204 { 227 205 struct device *dev = &pdev->dev; ··· 225 217 int err; 226 218 u32 clk_rate = 0; 227 219 bool needs_vcc = false; 228 - bool needs_reset = false; 229 - 230 - if (dev->of_node) { 231 - struct device_node *node = dev->of_node; 232 - 233 - if (of_property_read_u32(node, "clock-frequency", &clk_rate)) 234 - clk_rate = 0; 235 - 236 - needs_vcc = of_property_read_bool(node, "vcc-supply"); 237 - needs_reset = of_property_read_bool(node, "reset-supply"); 238 - 239 - } else if (pdata) { 240 - type = pdata->type; 241 - clk_rate = pdata->clk_rate; 242 - needs_vcc = pdata->needs_vcc; 243 - needs_reset = pdata->needs_reset; 244 - } 245 220 246 221 nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); 247 222 if (!nop) 248 223 return -ENOMEM; 249 224 225 + nop->reset_active_low = true; /* default behaviour */ 250 226 251 - err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc, 252 - needs_reset); 227 + if (dev->of_node) { 228 + struct device_node *node = dev->of_node; 229 + enum of_gpio_flags flags; 230 + 231 + if (of_property_read_u32(node, "clock-frequency", &clk_rate)) 232 + clk_rate = 0; 233 + 234 + needs_vcc = of_property_read_bool(node, "vcc-supply"); 235 + nop->gpio_reset = of_get_named_gpio_flags(node, "reset-gpios", 236 + 0, &flags); 237 + if (nop->gpio_reset == -EPROBE_DEFER) 238 + return -EPROBE_DEFER; 239 + 240 + nop->reset_active_low = flags & OF_GPIO_ACTIVE_LOW; 241 + 242 + } else if (pdata) { 243 + type = pdata->type; 244 + clk_rate = pdata->clk_rate; 245 + needs_vcc = pdata->needs_vcc; 246 + nop->gpio_reset = pdata->gpio_reset; 247 + } 248 + 249 + err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc); 253 250 if (err) 254 251 return err; 255 252 ··· 265 252 if (err) { 266 253 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 267 254 err); 268 - goto err_add; 255 + return err; 269 256 } 270 257 271 258 platform_set_drvdata(pdev, nop); 272 259 273 260 return 0; 274 261 275 - err_add: 276 - usb_phy_gen_cleanup_phy(nop); 277 262 return err; 278 263 } 279 264 ··· 279 268 { 280 269 struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev); 281 270 282 - usb_phy_gen_cleanup_phy(nop); 283 271 usb_remove_phy(&nop->phy); 284 272 285 273 return 0;
+3 -4
drivers/usb/phy/phy-generic.h
··· 6 6 struct device *dev; 7 7 struct clk *clk; 8 8 struct regulator *vcc; 9 - struct regulator *reset; 9 + int gpio_reset; 10 + bool reset_active_low; 10 11 }; 11 12 12 13 int usb_gen_phy_init(struct usb_phy *phy); 13 14 void usb_gen_phy_shutdown(struct usb_phy *phy); 14 15 15 16 int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, 16 - enum usb_phy_type type, u32 clk_rate, bool needs_vcc, 17 - bool needs_reset); 18 - void usb_phy_gen_cleanup_phy(struct usb_phy_gen_xceiv *nop); 17 + enum usb_phy_type type, u32 clk_rate, bool needs_vcc); 19 18 20 19 #endif
+248
drivers/usb/phy/phy-rcar-gen2-usb.c
··· 1 + /* 2 + * Renesas R-Car Gen2 USB phy driver 3 + * 4 + * Copyright (C) 2013 Renesas Solutions Corp. 5 + * Copyright (C) 2013 Cogent Embedded, Inc. 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/clk.h> 13 + #include <linux/delay.h> 14 + #include <linux/io.h> 15 + #include <linux/module.h> 16 + #include <linux/platform_data/usb-rcar-gen2-phy.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/spinlock.h> 19 + #include <linux/usb/otg.h> 20 + 21 + struct rcar_gen2_usb_phy_priv { 22 + struct usb_phy phy; 23 + void __iomem *base; 24 + struct clk *clk; 25 + spinlock_t lock; 26 + int usecount; 27 + u32 ugctrl2; 28 + }; 29 + 30 + #define usb_phy_to_priv(p) container_of(p, struct rcar_gen2_usb_phy_priv, phy) 31 + 32 + /* Low Power Status register */ 33 + #define USBHS_LPSTS_REG 0x02 34 + #define USBHS_LPSTS_SUSPM (1 << 14) 35 + 36 + /* USB General control register */ 37 + #define USBHS_UGCTRL_REG 0x80 38 + #define USBHS_UGCTRL_CONNECT (1 << 2) 39 + #define USBHS_UGCTRL_PLLRESET (1 << 0) 40 + 41 + /* USB General control register 2 */ 42 + #define USBHS_UGCTRL2_REG 0x84 43 + #define USBHS_UGCTRL2_USB0_PCI (1 << 4) 44 + #define USBHS_UGCTRL2_USB0_HS (3 << 4) 45 + #define USBHS_UGCTRL2_USB2_PCI (0 << 31) 46 + #define USBHS_UGCTRL2_USB2_SS (1 << 31) 47 + 48 + /* USB General status register */ 49 + #define USBHS_UGSTS_REG 0x88 50 + #define USBHS_UGSTS_LOCK (3 << 8) 51 + 52 + /* Enable USBHS internal phy */ 53 + static int __rcar_gen2_usbhs_phy_enable(void __iomem *base) 54 + { 55 + u32 val; 56 + int i; 57 + 58 + /* USBHS PHY power on */ 59 + val = ioread32(base + USBHS_UGCTRL_REG); 60 + val &= ~USBHS_UGCTRL_PLLRESET; 61 + iowrite32(val, base + USBHS_UGCTRL_REG); 62 + 63 + val = ioread16(base + USBHS_LPSTS_REG); 64 + val |= USBHS_LPSTS_SUSPM; 65 + iowrite16(val, base + USBHS_LPSTS_REG); 66 + 67 + for (i = 0; i < 20; i++) { 68 + val = ioread32(base + USBHS_UGSTS_REG); 69 + if ((val & USBHS_UGSTS_LOCK) == USBHS_UGSTS_LOCK) { 70 + val = ioread32(base + USBHS_UGCTRL_REG); 71 + val |= USBHS_UGCTRL_CONNECT; 72 + iowrite32(val, base + USBHS_UGCTRL_REG); 73 + return 0; 74 + } 75 + udelay(1); 76 + } 77 + 78 + /* Timed out waiting for the PLL lock */ 79 + return -ETIMEDOUT; 80 + } 81 + 82 + /* Disable USBHS internal phy */ 83 + static int __rcar_gen2_usbhs_phy_disable(void __iomem *base) 84 + { 85 + u32 val; 86 + 87 + /* USBHS PHY power off */ 88 + val = ioread32(base + USBHS_UGCTRL_REG); 89 + val &= ~USBHS_UGCTRL_CONNECT; 90 + iowrite32(val, base + USBHS_UGCTRL_REG); 91 + 92 + val = ioread16(base + USBHS_LPSTS_REG); 93 + val &= ~USBHS_LPSTS_SUSPM; 94 + iowrite16(val, base + USBHS_LPSTS_REG); 95 + 96 + val = ioread32(base + USBHS_UGCTRL_REG); 97 + val |= USBHS_UGCTRL_PLLRESET; 98 + iowrite32(val, base + USBHS_UGCTRL_REG); 99 + return 0; 100 + } 101 + 102 + /* Setup USB channels */ 103 + static void __rcar_gen2_usb_phy_init(struct rcar_gen2_usb_phy_priv *priv) 104 + { 105 + u32 val; 106 + 107 + clk_prepare_enable(priv->clk); 108 + 109 + /* Set USB channels in the USBHS UGCTRL2 register */ 110 + val = ioread32(priv->base); 111 + val &= ~(USBHS_UGCTRL2_USB0_HS | USBHS_UGCTRL2_USB2_SS); 112 + val |= priv->ugctrl2; 113 + iowrite32(val, priv->base); 114 + } 115 + 116 + /* Shutdown USB channels */ 117 + static void __rcar_gen2_usb_phy_shutdown(struct rcar_gen2_usb_phy_priv *priv) 118 + { 119 + __rcar_gen2_usbhs_phy_disable(priv->base); 120 + clk_disable_unprepare(priv->clk); 121 + } 122 + 123 + static int rcar_gen2_usb_phy_set_suspend(struct usb_phy *phy, int suspend) 124 + { 125 + struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy); 126 + unsigned long flags; 127 + int retval; 128 + 129 + spin_lock_irqsave(&priv->lock, flags); 130 + retval = suspend ? __rcar_gen2_usbhs_phy_disable(priv->base) : 131 + __rcar_gen2_usbhs_phy_enable(priv->base); 132 + spin_unlock_irqrestore(&priv->lock, flags); 133 + return retval; 134 + } 135 + 136 + static int rcar_gen2_usb_phy_init(struct usb_phy *phy) 137 + { 138 + struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy); 139 + unsigned long flags; 140 + 141 + spin_lock_irqsave(&priv->lock, flags); 142 + /* 143 + * Enable the clock and setup USB channels 144 + * if it's the first user 145 + */ 146 + if (!priv->usecount++) 147 + __rcar_gen2_usb_phy_init(priv); 148 + spin_unlock_irqrestore(&priv->lock, flags); 149 + return 0; 150 + } 151 + 152 + static void rcar_gen2_usb_phy_shutdown(struct usb_phy *phy) 153 + { 154 + struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy); 155 + unsigned long flags; 156 + 157 + spin_lock_irqsave(&priv->lock, flags); 158 + if (!priv->usecount) { 159 + dev_warn(phy->dev, "Trying to disable phy with 0 usecount\n"); 160 + goto out; 161 + } 162 + 163 + /* Disable everything if it's the last user */ 164 + if (!--priv->usecount) 165 + __rcar_gen2_usb_phy_shutdown(priv); 166 + out: 167 + spin_unlock_irqrestore(&priv->lock, flags); 168 + } 169 + 170 + static int rcar_gen2_usb_phy_probe(struct platform_device *pdev) 171 + { 172 + struct device *dev = &pdev->dev; 173 + struct rcar_gen2_phy_platform_data *pdata; 174 + struct rcar_gen2_usb_phy_priv *priv; 175 + struct resource *res; 176 + void __iomem *base; 177 + struct clk *clk; 178 + int retval; 179 + 180 + pdata = dev_get_platdata(&pdev->dev); 181 + if (!pdata) { 182 + dev_err(dev, "No platform data\n"); 183 + return -EINVAL; 184 + } 185 + 186 + clk = devm_clk_get(&pdev->dev, "usbhs"); 187 + if (IS_ERR(clk)) { 188 + dev_err(&pdev->dev, "Can't get the clock\n"); 189 + return PTR_ERR(clk); 190 + } 191 + 192 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 193 + base = devm_ioremap_resource(dev, res); 194 + if (IS_ERR(base)) 195 + return PTR_ERR(base); 196 + 197 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 198 + if (!priv) { 199 + dev_err(dev, "Memory allocation failed\n"); 200 + return -ENOMEM; 201 + } 202 + 203 + spin_lock_init(&priv->lock); 204 + priv->clk = clk; 205 + priv->base = base; 206 + priv->ugctrl2 = pdata->chan0_pci ? 207 + USBHS_UGCTRL2_USB0_PCI : USBHS_UGCTRL2_USB0_HS; 208 + priv->ugctrl2 |= pdata->chan2_pci ? 209 + USBHS_UGCTRL2_USB2_PCI : USBHS_UGCTRL2_USB2_SS; 210 + priv->phy.dev = dev; 211 + priv->phy.label = dev_name(dev); 212 + priv->phy.init = rcar_gen2_usb_phy_init; 213 + priv->phy.shutdown = rcar_gen2_usb_phy_shutdown; 214 + priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend; 215 + 216 + retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2); 217 + if (retval < 0) { 218 + dev_err(dev, "Failed to add USB phy\n"); 219 + return retval; 220 + } 221 + 222 + platform_set_drvdata(pdev, priv); 223 + 224 + return retval; 225 + } 226 + 227 + static int rcar_gen2_usb_phy_remove(struct platform_device *pdev) 228 + { 229 + struct rcar_gen2_usb_phy_priv *priv = platform_get_drvdata(pdev); 230 + 231 + usb_remove_phy(&priv->phy); 232 + 233 + return 0; 234 + } 235 + 236 + static struct platform_driver rcar_gen2_usb_phy_driver = { 237 + .driver = { 238 + .name = "usb_phy_rcar_gen2", 239 + }, 240 + .probe = rcar_gen2_usb_phy_probe, 241 + .remove = rcar_gen2_usb_phy_remove, 242 + }; 243 + 244 + module_platform_driver(rcar_gen2_usb_phy_driver); 245 + 246 + MODULE_LICENSE("GPL v2"); 247 + MODULE_DESCRIPTION("Renesas R-Car Gen2 USB phy"); 248 + MODULE_AUTHOR("Valentine Barshak <valentine.barshak@cogentembedded.com>");
+1 -1
drivers/usb/phy/phy-tegra-usb.c
··· 1090 1090 .driver = { 1091 1091 .name = "tegra-phy", 1092 1092 .owner = THIS_MODULE, 1093 - .of_match_table = of_match_ptr(tegra_usb_phy_id_table), 1093 + .of_match_table = tegra_usb_phy_id_table, 1094 1094 }, 1095 1095 }; 1096 1096 module_platform_driver(tegra_usb_phy_driver);
+1
drivers/usb/phy/phy-twl6030-usb.c
··· 33 33 #include <linux/err.h> 34 34 #include <linux/slab.h> 35 35 #include <linux/delay.h> 36 + #include <linux/of.h> 36 37 37 38 /* usb register definitions */ 38 39 #define USB_VENDOR_ID_LSB 0x00
+1 -1
drivers/usb/phy/phy.c
··· 98 98 99 99 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL); 100 100 if (!ptr) 101 - return NULL; 101 + return ERR_PTR(-ENOMEM); 102 102 103 103 phy = usb_get_phy(type); 104 104 if (!IS_ERR(phy)) {
+22
include/linux/platform_data/usb-rcar-gen2-phy.h
··· 1 + /* 2 + * Copyright (C) 2013 Renesas Solutions Corp. 3 + * Copyright (C) 2013 Cogent Embedded, Inc. 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + */ 9 + 10 + #ifndef __USB_RCAR_GEN2_PHY_H 11 + #define __USB_RCAR_GEN2_PHY_H 12 + 13 + #include <linux/types.h> 14 + 15 + struct rcar_gen2_phy_platform_data { 16 + /* USB channel 0 configuration */ 17 + bool chan0_pci:1; /* true: PCI USB host 0, false: USBHS */ 18 + /* USB channel 2 configuration */ 19 + bool chan2_pci:1; /* true: PCI USB host 2, false: USBSS */ 20 + }; 21 + 22 + #endif
+2 -1
include/linux/usb/usb_phy_gen_xceiv.h
··· 9 9 10 10 /* if set fails with -EPROBE_DEFER if can't get regulator */ 11 11 unsigned int needs_vcc:1; 12 - unsigned int needs_reset:1; 12 + unsigned int needs_reset:1; /* deprecated */ 13 + int gpio_reset; 13 14 }; 14 15 15 16 #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))