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

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

Felipe writes:

usb: patches for v3.16 merge window

Not a lot here during this merge window. Mostly we just have
the usual miscellaneous patches (removal of unnecessary prints,
proper dependencies being added to Kconfig, build warning fixes,
new device ID, etc.

Other than those, the only important new features are the
new support for OS Strings which should help Linux Gadget
Drivers behave better under MS Windows. Also Babble Recovery
implementation for MUSB on AM335x. Lastly, we also have
ARCH_QCOM PHY support though phy-msm.

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

Conflicts:
drivers/usb/phy/phy-mv-u3d-usb.c

+4126 -791
+45
Documentation/ABI/testing/configfs-usb-gadget
··· 62 62 Description: 63 63 This group contains functions available to this USB gadget. 64 64 65 + What: /config/usb-gadget/gadget/functions/<func>.<inst>/interface.<n> 66 + Date: May 2014 67 + KernelVersion: 3.16 68 + Description: 69 + This group contains "Feature Descriptors" specific for one 70 + gadget's USB interface or one interface group described 71 + by an IAD. 72 + 73 + The attributes: 74 + 75 + compatible_id - 8-byte string for "Compatible ID" 76 + sub_compatible_id - 8-byte string for "Sub Compatible ID" 77 + 78 + What: /config/usb-gadget/gadget/functions/<func>.<inst>/interface.<n>/<property> 79 + Date: May 2014 80 + KernelVersion: 3.16 81 + Description: 82 + This group contains "Extended Property Descriptors" specific for one 83 + gadget's USB interface or one interface group described 84 + by an IAD. 85 + 86 + The attributes: 87 + 88 + type - value 1..7 for interpreting the data 89 + 1: unicode string 90 + 2: unicode string with environment variable 91 + 3: binary 92 + 4: little-endian 32-bit 93 + 5: big-endian 32-bit 94 + 6: unicode string with a symbolic link 95 + 7: multiple unicode strings 96 + data - blob of data to be interpreted depending on 97 + type 98 + 65 99 What: /config/usb-gadget/gadget/strings 66 100 Date: Jun 2013 67 101 KernelVersion: 3.11 ··· 113 79 product - gadget's product description 114 80 manufacturer - gadget's manufacturer description 115 81 82 + What: /config/usb-gadget/gadget/os_desc 83 + Date: May 2014 84 + KernelVersion: 3.16 85 + Description: 86 + This group contains "OS String" extension handling attributes. 87 + 88 + use - flag turning "OS Desctiptors" support on/off 89 + b_vendor_code - one-byte value used for custom per-device and 90 + per-interface requests 91 + qw_sign - an identifier to be reported as "OS String" 92 + proper
+2 -1
Documentation/DocBook/Makefile
··· 14 14 genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \ 15 15 80211.xml debugobjects.xml sh.xml regulator.xml \ 16 16 alsa-driver-api.xml writing-an-alsa-driver.xml \ 17 - tracepoint.xml drm.xml media_api.xml w1.xml 17 + tracepoint.xml drm.xml media_api.xml w1.xml \ 18 + writing_musb_glue_layer.xml 18 19 19 20 include Documentation/DocBook/media/Makefile 20 21
+873
Documentation/DocBook/writing_musb_glue_layer.tmpl
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 3 + "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []> 4 + 5 + <book id="Writing-MUSB-Glue-Layer"> 6 + <bookinfo> 7 + <title>Writing an MUSB Glue Layer</title> 8 + 9 + <authorgroup> 10 + <author> 11 + <firstname>Apelete</firstname> 12 + <surname>Seketeli</surname> 13 + <affiliation> 14 + <address> 15 + <email>apelete at seketeli.net</email> 16 + </address> 17 + </affiliation> 18 + </author> 19 + </authorgroup> 20 + 21 + <copyright> 22 + <year>2014</year> 23 + <holder>Apelete Seketeli</holder> 24 + </copyright> 25 + 26 + <legalnotice> 27 + <para> 28 + This documentation is free software; you can redistribute it 29 + and/or modify it under the terms of the GNU General Public 30 + License as published by the Free Software Foundation; either 31 + version 2 of the License, or (at your option) any later version. 32 + </para> 33 + 34 + <para> 35 + This documentation is distributed in the hope that it will be 36 + useful, but WITHOUT ANY WARRANTY; without even the implied 37 + warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 38 + See the GNU General Public License for more details. 39 + </para> 40 + 41 + <para> 42 + You should have received a copy of the GNU General Public License 43 + along with this documentation; if not, write to the Free Software 44 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 45 + 02111-1307 USA 46 + </para> 47 + 48 + <para> 49 + For more details see the file COPYING in the Linux kernel source 50 + tree. 51 + </para> 52 + </legalnotice> 53 + </bookinfo> 54 + 55 + <toc></toc> 56 + 57 + <chapter id="introduction"> 58 + <title>Introduction</title> 59 + <para> 60 + The Linux MUSB subsystem is part of the larger Linux USB 61 + subsystem. It provides support for embedded USB Device Controllers 62 + (UDC) that do not use Universal Host Controller Interface (UHCI) 63 + or Open Host Controller Interface (OHCI). 64 + </para> 65 + <para> 66 + Instead, these embedded UDC rely on the USB On-the-Go (OTG) 67 + specification which they implement at least partially. The silicon 68 + reference design used in most cases is the Multipoint USB 69 + Highspeed Dual-Role Controller (MUSB HDRC) found in the Mentor 70 + Graphics Inventra™ design. 71 + </para> 72 + <para> 73 + As a self-taught exercise I have written an MUSB glue layer for 74 + the Ingenic JZ4740 SoC, modelled after the many MUSB glue layers 75 + in the kernel source tree. This layer can be found at 76 + drivers/usb/musb/jz4740.c. In this documentation I will walk 77 + through the basics of the jz4740.c glue layer, explaining the 78 + different pieces and what needs to be done in order to write your 79 + own device glue layer. 80 + </para> 81 + </chapter> 82 + 83 + <chapter id="linux-musb-basics"> 84 + <title>Linux MUSB Basics</title> 85 + <para> 86 + To get started on the topic, please read USB On-the-Go Basics (see 87 + Resources) which provides an introduction of USB OTG operation at 88 + the hardware level. A couple of wiki pages by Texas Instruments 89 + and Analog Devices also provide an overview of the Linux kernel 90 + MUSB configuration, albeit focused on some specific devices 91 + provided by these companies. Finally, getting acquainted with the 92 + USB specification at USB home page may come in handy, with 93 + practical instance provided through the Writing USB Device Drivers 94 + documentation (again, see Resources). 95 + </para> 96 + <para> 97 + Linux USB stack is a layered architecture in which the MUSB 98 + controller hardware sits at the lowest. The MUSB controller driver 99 + abstract the MUSB controller hardware to the Linux USB stack. 100 + </para> 101 + <programlisting> 102 + ------------------------ 103 + | | &lt;------- drivers/usb/gadget 104 + | Linux USB Core Stack | &lt;------- drivers/usb/host 105 + | | &lt;------- drivers/usb/core 106 + ------------------------ 107 + 108 + -------------------------- 109 + | | &lt;------ drivers/usb/musb/musb_gadget.c 110 + | MUSB Controller driver | &lt;------ drivers/usb/musb/musb_host.c 111 + | | &lt;------ drivers/usb/musb/musb_core.c 112 + -------------------------- 113 + 114 + --------------------------------- 115 + | MUSB Platform Specific Driver | 116 + | | &lt;-- drivers/usb/musb/jz4740.c 117 + | aka &quot;Glue Layer&quot; | 118 + --------------------------------- 119 + 120 + --------------------------------- 121 + | MUSB Controller Hardware | 122 + --------------------------------- 123 + </programlisting> 124 + <para> 125 + As outlined above, the glue layer is actually the platform 126 + specific code sitting in between the controller driver and the 127 + controller hardware. 128 + </para> 129 + <para> 130 + Just like a Linux USB driver needs to register itself with the 131 + Linux USB subsystem, the MUSB glue layer needs first to register 132 + itself with the MUSB controller driver. This will allow the 133 + controller driver to know about which device the glue layer 134 + supports and which functions to call when a supported device is 135 + detected or released; remember we are talking about an embedded 136 + controller chip here, so no insertion or removal at run-time. 137 + </para> 138 + <para> 139 + All of this information is passed to the MUSB controller driver 140 + through a platform_driver structure defined in the glue layer as: 141 + </para> 142 + <programlisting linenumbering="numbered"> 143 + static struct platform_driver jz4740_driver = { 144 + .probe = jz4740_probe, 145 + .remove = jz4740_remove, 146 + .driver = { 147 + .name = "musb-jz4740", 148 + }, 149 + }; 150 + </programlisting> 151 + <para> 152 + The probe and remove function pointers are called when a matching 153 + device is detected and, respectively, released. The name string 154 + describes the device supported by this glue layer. In the current 155 + case it matches a platform_device structure declared in 156 + arch/mips/jz4740/platform.c. Note that we are not using device 157 + tree bindings here. 158 + </para> 159 + <para> 160 + In order to register itself to the controller driver, the glue 161 + layer goes through a few steps, basically allocating the 162 + controller hardware resources and initialising a couple of 163 + circuits. To do so, it needs to keep track of the information used 164 + throughout these steps. This is done by defining a private 165 + jz4740_glue structure: 166 + </para> 167 + <programlisting linenumbering="numbered"> 168 + struct jz4740_glue { 169 + struct device *dev; 170 + struct platform_device *musb; 171 + struct clk *clk; 172 + }; 173 + </programlisting> 174 + <para> 175 + The dev and musb members are both device structure variables. The 176 + first one holds generic information about the device, since it's 177 + the basic device structure, and the latter holds information more 178 + closely related to the subsystem the device is registered to. The 179 + clk variable keeps information related to the device clock 180 + operation. 181 + </para> 182 + <para> 183 + Let's go through the steps of the probe function that leads the 184 + glue layer to register itself to the controller driver. 185 + </para> 186 + <para> 187 + N.B.: For the sake of readability each function will be split in 188 + logical parts, each part being shown as if it was independent from 189 + the others. 190 + </para> 191 + <programlisting linenumbering="numbered"> 192 + static int jz4740_probe(struct platform_device *pdev) 193 + { 194 + struct platform_device *musb; 195 + struct jz4740_glue *glue; 196 + struct clk *clk; 197 + int ret; 198 + 199 + glue = devm_kzalloc(&amp;pdev->dev, sizeof(*glue), GFP_KERNEL); 200 + if (!glue) 201 + return -ENOMEM; 202 + 203 + musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 204 + if (!musb) { 205 + dev_err(&amp;pdev->dev, "failed to allocate musb device\n"); 206 + return -ENOMEM; 207 + } 208 + 209 + clk = devm_clk_get(&amp;pdev->dev, "udc"); 210 + if (IS_ERR(clk)) { 211 + dev_err(&amp;pdev->dev, "failed to get clock\n"); 212 + ret = PTR_ERR(clk); 213 + goto err_platform_device_put; 214 + } 215 + 216 + ret = clk_prepare_enable(clk); 217 + if (ret) { 218 + dev_err(&amp;pdev->dev, "failed to enable clock\n"); 219 + goto err_platform_device_put; 220 + } 221 + 222 + musb->dev.parent = &amp;pdev->dev; 223 + 224 + glue->dev = &amp;pdev->dev; 225 + glue->musb = musb; 226 + glue->clk = clk; 227 + 228 + return 0; 229 + 230 + err_platform_device_put: 231 + platform_device_put(musb); 232 + return ret; 233 + } 234 + </programlisting> 235 + <para> 236 + The first few lines of the probe function allocate and assign the 237 + glue, musb and clk variables. The GFP_KERNEL flag (line 8) allows 238 + the allocation process to sleep and wait for memory, thus being 239 + usable in a blocking situation. The PLATFORM_DEVID_AUTO flag (line 240 + 12) allows automatic allocation and management of device IDs in 241 + order to avoid device namespace collisions with explicit IDs. With 242 + devm_clk_get() (line 18) the glue layer allocates the clock -- the 243 + <literal>devm_</literal> prefix indicates that clk_get() is 244 + managed: it automatically frees the allocated clock resource data 245 + when the device is released -- and enable it. 246 + </para> 247 + <para> 248 + Then comes the registration steps: 249 + </para> 250 + <programlisting linenumbering="numbered"> 251 + static int jz4740_probe(struct platform_device *pdev) 252 + { 253 + struct musb_hdrc_platform_data *pdata = &amp;jz4740_musb_platform_data; 254 + 255 + pdata->platform_ops = &amp;jz4740_musb_ops; 256 + 257 + platform_set_drvdata(pdev, glue); 258 + 259 + ret = platform_device_add_resources(musb, pdev->resource, 260 + pdev->num_resources); 261 + if (ret) { 262 + dev_err(&amp;pdev->dev, "failed to add resources\n"); 263 + goto err_clk_disable; 264 + } 265 + 266 + ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 267 + if (ret) { 268 + dev_err(&amp;pdev->dev, "failed to add platform_data\n"); 269 + goto err_clk_disable; 270 + } 271 + 272 + return 0; 273 + 274 + err_clk_disable: 275 + clk_disable_unprepare(clk); 276 + err_platform_device_put: 277 + platform_device_put(musb); 278 + return ret; 279 + } 280 + </programlisting> 281 + <para> 282 + The first step is to pass the device data privately held by the 283 + glue layer on to the controller driver through 284 + platform_set_drvdata() (line 7). Next is passing on the device 285 + resources information, also privately held at that point, through 286 + platform_device_add_resources() (line 9). 287 + </para> 288 + <para> 289 + Finally comes passing on the platform specific data to the 290 + controller driver (line 16). Platform data will be discussed in 291 + <link linkend="device-platform-data">Chapter 4</link>, but here 292 + we are looking at the platform_ops function pointer (line 5) in 293 + musb_hdrc_platform_data structure (line 3). This function 294 + pointer allows the MUSB controller driver to know which function 295 + to call for device operation: 296 + </para> 297 + <programlisting linenumbering="numbered"> 298 + static const struct musb_platform_ops jz4740_musb_ops = { 299 + .init = jz4740_musb_init, 300 + .exit = jz4740_musb_exit, 301 + }; 302 + </programlisting> 303 + <para> 304 + Here we have the minimal case where only init and exit functions 305 + are called by the controller driver when needed. Fact is the 306 + JZ4740 MUSB controller is a basic controller, lacking some 307 + features found in other controllers, otherwise we may also have 308 + pointers to a few other functions like a power management function 309 + or a function to switch between OTG and non-OTG modes, for 310 + instance. 311 + </para> 312 + <para> 313 + At that point of the registration process, the controller driver 314 + actually calls the init function: 315 + </para> 316 + <programlisting linenumbering="numbered"> 317 + static int jz4740_musb_init(struct musb *musb) 318 + { 319 + musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 320 + if (!musb->xceiv) { 321 + pr_err("HS UDC: no transceiver configured\n"); 322 + return -ENODEV; 323 + } 324 + 325 + /* Silicon does not implement ConfigData register. 326 + * Set dyn_fifo to avoid reading EP config from hardware. 327 + */ 328 + musb->dyn_fifo = true; 329 + 330 + musb->isr = jz4740_musb_interrupt; 331 + 332 + return 0; 333 + } 334 + </programlisting> 335 + <para> 336 + The goal of jz4740_musb_init() is to get hold of the transceiver 337 + driver data of the MUSB controller hardware and pass it on to the 338 + MUSB controller driver, as usual. The transceiver is the circuitry 339 + inside the controller hardware responsible for sending/receiving 340 + the USB data. Since it is an implementation of the physical layer 341 + of the OSI model, the transceiver is also referred to as PHY. 342 + </para> 343 + <para> 344 + Getting hold of the MUSB PHY driver data is done with 345 + usb_get_phy() which returns a pointer to the structure 346 + containing the driver instance data. The next couple of 347 + instructions (line 12 and 14) are used as a quirk and to setup 348 + IRQ handling respectively. Quirks and IRQ handling will be 349 + discussed later in <link linkend="device-quirks">Chapter 350 + 5</link> and <link linkend="handling-irqs">Chapter 3</link>. 351 + </para> 352 + <programlisting linenumbering="numbered"> 353 + static int jz4740_musb_exit(struct musb *musb) 354 + { 355 + usb_put_phy(musb->xceiv); 356 + 357 + return 0; 358 + } 359 + </programlisting> 360 + <para> 361 + Acting as the counterpart of init, the exit function releases the 362 + MUSB PHY driver when the controller hardware itself is about to be 363 + released. 364 + </para> 365 + <para> 366 + Again, note that init and exit are fairly simple in this case due 367 + to the basic set of features of the JZ4740 controller hardware. 368 + When writing an musb glue layer for a more complex controller 369 + hardware, you might need to take care of more processing in those 370 + two functions. 371 + </para> 372 + <para> 373 + Returning from the init function, the MUSB controller driver jumps 374 + back into the probe function: 375 + </para> 376 + <programlisting linenumbering="numbered"> 377 + static int jz4740_probe(struct platform_device *pdev) 378 + { 379 + ret = platform_device_add(musb); 380 + if (ret) { 381 + dev_err(&amp;pdev->dev, "failed to register musb device\n"); 382 + goto err_clk_disable; 383 + } 384 + 385 + return 0; 386 + 387 + err_clk_disable: 388 + clk_disable_unprepare(clk); 389 + err_platform_device_put: 390 + platform_device_put(musb); 391 + return ret; 392 + } 393 + </programlisting> 394 + <para> 395 + This is the last part of the device registration process where the 396 + glue layer adds the controller hardware device to Linux kernel 397 + device hierarchy: at this stage, all known information about the 398 + device is passed on to the Linux USB core stack. 399 + </para> 400 + <programlisting linenumbering="numbered"> 401 + static int jz4740_remove(struct platform_device *pdev) 402 + { 403 + struct jz4740_glue *glue = platform_get_drvdata(pdev); 404 + 405 + platform_device_unregister(glue->musb); 406 + clk_disable_unprepare(glue->clk); 407 + 408 + return 0; 409 + } 410 + </programlisting> 411 + <para> 412 + Acting as the counterpart of probe, the remove function unregister 413 + the MUSB controller hardware (line 5) and disable the clock (line 414 + 6), allowing it to be gated. 415 + </para> 416 + </chapter> 417 + 418 + <chapter id="handling-irqs"> 419 + <title>Handling IRQs</title> 420 + <para> 421 + Additionally to the MUSB controller hardware basic setup and 422 + registration, the glue layer is also responsible for handling the 423 + IRQs: 424 + </para> 425 + <programlisting linenumbering="numbered"> 426 + static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) 427 + { 428 + unsigned long flags; 429 + irqreturn_t retval = IRQ_NONE; 430 + struct musb *musb = __hci; 431 + 432 + spin_lock_irqsave(&amp;musb->lock, flags); 433 + 434 + musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 435 + musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 436 + musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 437 + 438 + /* 439 + * The controller is gadget only, the state of the host mode IRQ bits is 440 + * undefined. Mask them to make sure that the musb driver core will 441 + * never see them set 442 + */ 443 + musb->int_usb &amp;= MUSB_INTR_SUSPEND | MUSB_INTR_RESUME | 444 + MUSB_INTR_RESET | MUSB_INTR_SOF; 445 + 446 + if (musb->int_usb || musb->int_tx || musb->int_rx) 447 + retval = musb_interrupt(musb); 448 + 449 + spin_unlock_irqrestore(&amp;musb->lock, flags); 450 + 451 + return retval; 452 + } 453 + </programlisting> 454 + <para> 455 + Here the glue layer mostly has to read the relevant hardware 456 + registers and pass their values on to the controller driver which 457 + will handle the actual event that triggered the IRQ. 458 + </para> 459 + <para> 460 + The interrupt handler critical section is protected by the 461 + spin_lock_irqsave() and counterpart spin_unlock_irqrestore() 462 + functions (line 7 and 24 respectively), which prevent the 463 + interrupt handler code to be run by two different threads at the 464 + same time. 465 + </para> 466 + <para> 467 + Then the relevant interrupt registers are read (line 9 to 11): 468 + </para> 469 + <itemizedlist> 470 + <listitem> 471 + <para> 472 + MUSB_INTRUSB: indicates which USB interrupts are currently 473 + active, 474 + </para> 475 + </listitem> 476 + <listitem> 477 + <para> 478 + MUSB_INTRTX: indicates which of the interrupts for TX 479 + endpoints are currently active, 480 + </para> 481 + </listitem> 482 + <listitem> 483 + <para> 484 + MUSB_INTRRX: indicates which of the interrupts for TX 485 + endpoints are currently active. 486 + </para> 487 + </listitem> 488 + </itemizedlist> 489 + <para> 490 + Note that musb_readb() is used to read 8-bit registers at most, 491 + while musb_readw() allows us to read at most 16-bit registers. 492 + There are other functions that can be used depending on the size 493 + of your device registers. See musb_io.h for more information. 494 + </para> 495 + <para> 496 + Instruction on line 18 is another quirk specific to the JZ4740 497 + USB device controller, which will be discussed later in <link 498 + linkend="device-quirks">Chapter 5</link>. 499 + </para> 500 + <para> 501 + The glue layer still needs to register the IRQ handler though. 502 + Remember the instruction on line 14 of the init function: 503 + </para> 504 + <programlisting linenumbering="numbered"> 505 + static int jz4740_musb_init(struct musb *musb) 506 + { 507 + musb->isr = jz4740_musb_interrupt; 508 + 509 + return 0; 510 + } 511 + </programlisting> 512 + <para> 513 + This instruction sets a pointer to the glue layer IRQ handler 514 + function, in order for the controller hardware to call the handler 515 + back when an IRQ comes from the controller hardware. The interrupt 516 + handler is now implemented and registered. 517 + </para> 518 + </chapter> 519 + 520 + <chapter id="device-platform-data"> 521 + <title>Device Platform Data</title> 522 + <para> 523 + In order to write an MUSB glue layer, you need to have some data 524 + describing the hardware capabilities of your controller hardware, 525 + which is called the platform data. 526 + </para> 527 + <para> 528 + Platform data is specific to your hardware, though it may cover a 529 + broad range of devices, and is generally found somewhere in the 530 + arch/ directory, depending on your device architecture. 531 + </para> 532 + <para> 533 + For instance, platform data for the JZ4740 SoC is found in 534 + arch/mips/jz4740/platform.c. In the platform.c file each device of 535 + the JZ4740 SoC is described through a set of structures. 536 + </para> 537 + <para> 538 + Here is the part of arch/mips/jz4740/platform.c that covers the 539 + USB Device Controller (UDC): 540 + </para> 541 + <programlisting linenumbering="numbered"> 542 + /* USB Device Controller */ 543 + struct platform_device jz4740_udc_xceiv_device = { 544 + .name = "usb_phy_gen_xceiv", 545 + .id = 0, 546 + }; 547 + 548 + static struct resource jz4740_udc_resources[] = { 549 + [0] = { 550 + .start = JZ4740_UDC_BASE_ADDR, 551 + .end = JZ4740_UDC_BASE_ADDR + 0x10000 - 1, 552 + .flags = IORESOURCE_MEM, 553 + }, 554 + [1] = { 555 + .start = JZ4740_IRQ_UDC, 556 + .end = JZ4740_IRQ_UDC, 557 + .flags = IORESOURCE_IRQ, 558 + .name = "mc", 559 + }, 560 + }; 561 + 562 + struct platform_device jz4740_udc_device = { 563 + .name = "musb-jz4740", 564 + .id = -1, 565 + .dev = { 566 + .dma_mask = &amp;jz4740_udc_device.dev.coherent_dma_mask, 567 + .coherent_dma_mask = DMA_BIT_MASK(32), 568 + }, 569 + .num_resources = ARRAY_SIZE(jz4740_udc_resources), 570 + .resource = jz4740_udc_resources, 571 + }; 572 + </programlisting> 573 + <para> 574 + The jz4740_udc_xceiv_device platform device structure (line 2) 575 + describes the UDC transceiver with a name and id number. 576 + </para> 577 + <para> 578 + At the time of this writing, note that 579 + &quot;usb_phy_gen_xceiv&quot; is the specific name to be used for 580 + all transceivers that are either built-in with reference USB IP or 581 + autonomous and doesn't require any PHY programming. You will need 582 + to set CONFIG_NOP_USB_XCEIV=y in the kernel configuration to make 583 + use of the corresponding transceiver driver. The id field could be 584 + set to -1 (equivalent to PLATFORM_DEVID_NONE), -2 (equivalent to 585 + PLATFORM_DEVID_AUTO) or start with 0 for the first device of this 586 + kind if we want a specific id number. 587 + </para> 588 + <para> 589 + The jz4740_udc_resources resource structure (line 7) defines the 590 + UDC registers base addresses. 591 + </para> 592 + <para> 593 + The first array (line 9 to 11) defines the UDC registers base 594 + memory addresses: start points to the first register memory 595 + address, end points to the last register memory address and the 596 + flags member defines the type of resource we are dealing with. So 597 + IORESOURCE_MEM is used to define the registers memory addresses. 598 + The second array (line 14 to 17) defines the UDC IRQ registers 599 + addresses. Since there is only one IRQ register available for the 600 + JZ4740 UDC, start and end point at the same address. The 601 + IORESOURCE_IRQ flag tells that we are dealing with IRQ resources, 602 + and the name &quot;mc&quot; is in fact hard-coded in the MUSB core 603 + in order for the controller driver to retrieve this IRQ resource 604 + by querying it by its name. 605 + </para> 606 + <para> 607 + Finally, the jz4740_udc_device platform device structure (line 21) 608 + describes the UDC itself. 609 + </para> 610 + <para> 611 + The &quot;musb-jz4740&quot; name (line 22) defines the MUSB 612 + driver that is used for this device; remember this is in fact 613 + the name that we used in the jz4740_driver platform driver 614 + structure in <link linkend="linux-musb-basics">Chapter 615 + 2</link>. The id field (line 23) is set to -1 (equivalent to 616 + PLATFORM_DEVID_NONE) since we do not need an id for the device: 617 + the MUSB controller driver was already set to allocate an 618 + automatic id in <link linkend="linux-musb-basics">Chapter 619 + 2</link>. In the dev field we care for DMA related information 620 + here. The dma_mask field (line 25) defines the width of the DMA 621 + mask that is going to be used, and coherent_dma_mask (line 26) 622 + has the same purpose but for the alloc_coherent DMA mappings: in 623 + both cases we are using a 32 bits mask. Then the resource field 624 + (line 29) is simply a pointer to the resource structure defined 625 + before, while the num_resources field (line 28) keeps track of 626 + the number of arrays defined in the resource structure (in this 627 + case there were two resource arrays defined before). 628 + </para> 629 + <para> 630 + With this quick overview of the UDC platform data at the arch/ 631 + level now done, let's get back to the MUSB glue layer specific 632 + platform data in drivers/usb/musb/jz4740.c: 633 + </para> 634 + <programlisting linenumbering="numbered"> 635 + static struct musb_hdrc_config jz4740_musb_config = { 636 + /* Silicon does not implement USB OTG. */ 637 + .multipoint = 0, 638 + /* Max EPs scanned, driver will decide which EP can be used. */ 639 + .num_eps = 4, 640 + /* RAMbits needed to configure EPs from table */ 641 + .ram_bits = 9, 642 + .fifo_cfg = jz4740_musb_fifo_cfg, 643 + .fifo_cfg_size = ARRAY_SIZE(jz4740_musb_fifo_cfg), 644 + }; 645 + 646 + static struct musb_hdrc_platform_data jz4740_musb_platform_data = { 647 + .mode = MUSB_PERIPHERAL, 648 + .config = &amp;jz4740_musb_config, 649 + }; 650 + </programlisting> 651 + <para> 652 + First the glue layer configures some aspects of the controller 653 + driver operation related to the controller hardware specifics. 654 + This is done through the jz4740_musb_config musb_hdrc_config 655 + structure. 656 + </para> 657 + <para> 658 + Defining the OTG capability of the controller hardware, the 659 + multipoint member (line 3) is set to 0 (equivalent to false) 660 + since the JZ4740 UDC is not OTG compatible. Then num_eps (line 661 + 5) defines the number of USB endpoints of the controller 662 + hardware, including endpoint 0: here we have 3 endpoints + 663 + endpoint 0. Next is ram_bits (line 7) which is the width of the 664 + RAM address bus for the MUSB controller hardware. This 665 + information is needed when the controller driver cannot 666 + automatically configure endpoints by reading the relevant 667 + controller hardware registers. This issue will be discussed when 668 + we get to device quirks in <link linkend="device-quirks">Chapter 669 + 5</link>. Last two fields (line 8 and 9) are also about device 670 + quirks: fifo_cfg points to the USB endpoints configuration table 671 + and fifo_cfg_size keeps track of the size of the number of 672 + entries in that configuration table. More on that later in <link 673 + linkend="device-quirks">Chapter 5</link>. 674 + </para> 675 + <para> 676 + Then this configuration is embedded inside 677 + jz4740_musb_platform_data musb_hdrc_platform_data structure (line 678 + 11): config is a pointer to the configuration structure itself, 679 + and mode tells the controller driver if the controller hardware 680 + may be used as MUSB_HOST only, MUSB_PERIPHERAL only or MUSB_OTG 681 + which is a dual mode. 682 + </para> 683 + <para> 684 + Remember that jz4740_musb_platform_data is then used to convey 685 + platform data information as we have seen in the probe function 686 + in <link linkend="linux-musb-basics">Chapter 2</link> 687 + </para> 688 + </chapter> 689 + 690 + <chapter id="device-quirks"> 691 + <title>Device Quirks</title> 692 + <para> 693 + Completing the platform data specific to your device, you may also 694 + need to write some code in the glue layer to work around some 695 + device specific limitations. These quirks may be due to some 696 + hardware bugs, or simply be the result of an incomplete 697 + implementation of the USB On-the-Go specification. 698 + </para> 699 + <para> 700 + The JZ4740 UDC exhibits such quirks, some of which we will discuss 701 + here for the sake of insight even though these might not be found 702 + in the controller hardware you are working on. 703 + </para> 704 + <para> 705 + Let's get back to the init function first: 706 + </para> 707 + <programlisting linenumbering="numbered"> 708 + static int jz4740_musb_init(struct musb *musb) 709 + { 710 + musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 711 + if (!musb->xceiv) { 712 + pr_err("HS UDC: no transceiver configured\n"); 713 + return -ENODEV; 714 + } 715 + 716 + /* Silicon does not implement ConfigData register. 717 + * Set dyn_fifo to avoid reading EP config from hardware. 718 + */ 719 + musb->dyn_fifo = true; 720 + 721 + musb->isr = jz4740_musb_interrupt; 722 + 723 + return 0; 724 + } 725 + </programlisting> 726 + <para> 727 + Instruction on line 12 helps the MUSB controller driver to work 728 + around the fact that the controller hardware is missing registers 729 + that are used for USB endpoints configuration. 730 + </para> 731 + <para> 732 + Without these registers, the controller driver is unable to read 733 + the endpoints configuration from the hardware, so we use line 12 734 + instruction to bypass reading the configuration from silicon, and 735 + rely on a hard-coded table that describes the endpoints 736 + configuration instead: 737 + </para> 738 + <programlisting linenumbering="numbered"> 739 + static struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { 740 + { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 741 + { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 742 + { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 64, }, 743 + }; 744 + </programlisting> 745 + <para> 746 + Looking at the configuration table above, we see that each 747 + endpoints is described by three fields: hw_ep_num is the endpoint 748 + number, style is its direction (either FIFO_TX for the controller 749 + driver to send packets in the controller hardware, or FIFO_RX to 750 + receive packets from hardware), and maxpacket defines the maximum 751 + size of each data packet that can be transmitted over that 752 + endpoint. Reading from the table, the controller driver knows that 753 + endpoint 1 can be used to send and receive USB data packets of 512 754 + bytes at once (this is in fact a bulk in/out endpoint), and 755 + endpoint 2 can be used to send data packets of 64 bytes at once 756 + (this is in fact an interrupt endpoint). 757 + </para> 758 + <para> 759 + Note that there is no information about endpoint 0 here: that one 760 + is implemented by default in every silicon design, with a 761 + predefined configuration according to the USB specification. For 762 + more examples of endpoint configuration tables, see musb_core.c. 763 + </para> 764 + <para> 765 + Let's now get back to the interrupt handler function: 766 + </para> 767 + <programlisting linenumbering="numbered"> 768 + static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) 769 + { 770 + unsigned long flags; 771 + irqreturn_t retval = IRQ_NONE; 772 + struct musb *musb = __hci; 773 + 774 + spin_lock_irqsave(&amp;musb->lock, flags); 775 + 776 + musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 777 + musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 778 + musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 779 + 780 + /* 781 + * The controller is gadget only, the state of the host mode IRQ bits is 782 + * undefined. Mask them to make sure that the musb driver core will 783 + * never see them set 784 + */ 785 + musb->int_usb &amp;= MUSB_INTR_SUSPEND | MUSB_INTR_RESUME | 786 + MUSB_INTR_RESET | MUSB_INTR_SOF; 787 + 788 + if (musb->int_usb || musb->int_tx || musb->int_rx) 789 + retval = musb_interrupt(musb); 790 + 791 + spin_unlock_irqrestore(&amp;musb->lock, flags); 792 + 793 + return retval; 794 + } 795 + </programlisting> 796 + <para> 797 + Instruction on line 18 above is a way for the controller driver to 798 + work around the fact that some interrupt bits used for USB host 799 + mode operation are missing in the MUSB_INTRUSB register, thus left 800 + in an undefined hardware state, since this MUSB controller 801 + hardware is used in peripheral mode only. As a consequence, the 802 + glue layer masks these missing bits out to avoid parasite 803 + interrupts by doing a logical AND operation between the value read 804 + from MUSB_INTRUSB and the bits that are actually implemented in 805 + the register. 806 + </para> 807 + <para> 808 + These are only a couple of the quirks found in the JZ4740 USB 809 + device controller. Some others were directly addressed in the MUSB 810 + core since the fixes were generic enough to provide a better 811 + handling of the issues for others controller hardware eventually. 812 + </para> 813 + </chapter> 814 + 815 + <chapter id="conclusion"> 816 + <title>Conclusion</title> 817 + <para> 818 + Writing a Linux MUSB glue layer should be a more accessible task, 819 + as this documentation tries to show the ins and outs of this 820 + exercise. 821 + </para> 822 + <para> 823 + The JZ4740 USB device controller being fairly simple, I hope its 824 + glue layer serves as a good example for the curious mind. Used 825 + with the current MUSB glue layers, this documentation should 826 + provide enough guidance to get started; should anything gets out 827 + of hand, the linux-usb mailing list archive is another helpful 828 + resource to browse through. 829 + </para> 830 + </chapter> 831 + 832 + <chapter id="acknowledgements"> 833 + <title>Acknowledgements</title> 834 + <para> 835 + Many thanks to Lars-Peter Clausen and Maarten ter Huurne for 836 + answering my questions while I was writing the JZ4740 glue layer 837 + and for helping me out getting the code in good shape. 838 + </para> 839 + <para> 840 + I would also like to thank the Qi-Hardware community at large for 841 + its cheerful guidance and support. 842 + </para> 843 + </chapter> 844 + 845 + <chapter id="resources"> 846 + <title>Resources</title> 847 + <para> 848 + USB Home Page: 849 + <ulink url="http://www.usb.org">http://www.usb.org</ulink> 850 + </para> 851 + <para> 852 + linux-usb Mailing List Archives: 853 + <ulink url="http://marc.info/?l=linux-usb">http://marc.info/?l=linux-usb</ulink> 854 + </para> 855 + <para> 856 + USB On-the-Go Basics: 857 + <ulink url="http://www.maximintegrated.com/app-notes/index.mvp/id/1822">http://www.maximintegrated.com/app-notes/index.mvp/id/1822</ulink> 858 + </para> 859 + <para> 860 + Writing USB Device Drivers: 861 + <ulink url="https://www.kernel.org/doc/htmldocs/writing_usb_driver/index.html">https://www.kernel.org/doc/htmldocs/writing_usb_driver/index.html</ulink> 862 + </para> 863 + <para> 864 + Texas Instruments USB Configuration Wiki Page: 865 + <ulink url="http://processors.wiki.ti.com/index.php/Usbgeneralpage">http://processors.wiki.ti.com/index.php/Usbgeneralpage</ulink> 866 + </para> 867 + <para> 868 + Analog Devices Blackfin MUSB Configuration: 869 + <ulink url="http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:musb">http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:musb</ulink> 870 + </para> 871 + </chapter> 872 + 873 + </book>
+13 -7
Documentation/devicetree/bindings/usb/gr-udc.txt
··· 12 12 13 13 - reg : Address and length of the register set for the device 14 14 15 - - interrupts : Interrupt numbers for this device 15 + - interrupts : Interrupt numbers for this device. Either one interrupt number 16 + for all interrupts, or one for status related interrupts, one for IN 17 + endpoint related interrupts and one for OUT endpoint related interrupts. 16 18 17 19 Optional properties: 18 20 19 - - epobufsizes : An array of buffer sizes for OUT endpoints. If the property is 20 - not present, or for endpoints outside of the array, 1024 is assumed by 21 - the driver. 21 + - epobufsizes : Array of buffer sizes for OUT endpoints when they differ 22 + from the default size of 1024. The array is indexed by the OUT endpoint 23 + number. If the property is present it typically contains one entry for 24 + each OUT endpoint of the core. Fewer entries overrides the default sizes 25 + only for as many endpoints as the array contains. 22 26 23 - - epibufsizes : An array of buffer sizes for IN endpoints. If the property is 24 - not present, or for endpoints outside of the array, 1024 is assumed by 25 - the driver. 27 + - epibufsizes : Array of buffer sizes for IN endpoints when they differ 28 + from the default size of 1024. The array is indexed by the IN endpoint 29 + number. If the property is present it typically contains one entry for 30 + each IN endpoint of the core. Fewer entries overrides the default sizes 31 + only for as many endpoints as the array contains. 26 32 27 33 For further information look in the documentation for the GLIB IP core library: 28 34 http://www.gaisler.com/products/grlib/grip.pdf
+78
Documentation/devicetree/bindings/usb/msm-hsusb.txt
··· 15 15 usb-phy = <&usb_otg>; 16 16 }; 17 17 18 + USB PHY with optional OTG: 19 + 20 + Required properties: 21 + - compatible: Should contain: 22 + "qcom,usb-otg-ci" for chipsets with ChipIdea 45nm PHY 23 + "qcom,usb-otg-snps" for chipsets with Synopsys 28nm PHY 24 + 25 + - regs: Offset and length of the register set in the memory map 26 + - interrupts: interrupt-specifier for the OTG interrupt. 27 + 28 + - clocks: A list of phandle + clock-specifier pairs for the 29 + clocks listed in clock-names 30 + - clock-names: Should contain the following: 31 + "phy" USB PHY reference clock 32 + "core" Protocol engine clock 33 + "iface" Interface bus clock 34 + "alt_core" Protocol engine clock for targets with asynchronous 35 + reset methodology. (optional) 36 + 37 + - vdccx-supply: phandle to the regulator for the vdd supply for 38 + digital circuit operation. 39 + - v1p8-supply: phandle to the regulator for the 1.8V supply 40 + - v3p3-supply: phandle to the regulator for the 3.3V supply 41 + 42 + - resets: A list of phandle + reset-specifier pairs for the 43 + resets listed in reset-names 44 + - reset-names: Should contain the following: 45 + "phy" USB PHY controller reset 46 + "link" USB LINK controller reset 47 + 48 + - qcom,otg-control: OTG control (VBUS and ID notifications) can be one of 49 + 1 - PHY control 50 + 2 - PMIC control 51 + 52 + Optional properties: 53 + - dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg" 54 + 55 + - qcom,phy-init-sequence: PHY configuration sequence values. This is related to Device 56 + Mode Eye Diagram test. Start address at which these values will be 57 + written is ULPI_EXT_VENDOR_SPECIFIC. Value of -1 is reserved as 58 + "do not overwrite default value at this address". 59 + For example: qcom,phy-init-sequence = < -1 0x63 >; 60 + Will update only value at address ULPI_EXT_VENDOR_SPECIFIC + 1. 61 + 62 + - qcom,phy-num: Select number of pyco-phy to use, can be one of 63 + 0 - PHY one, default 64 + 1 - Second PHY 65 + Some platforms may have configuration to allow USB 66 + controller work with any of the two HSPHYs present. 67 + 68 + - qcom,vdd-levels: This property must be a list of three integer values 69 + (no, min, max) where each value represents either a voltage 70 + in microvolts or a value corresponding to voltage corner. 71 + 72 + Example HSUSB OTG controller device node: 73 + 74 + usb@f9a55000 { 75 + compatible = "qcom,usb-otg-snps"; 76 + reg = <0xf9a55000 0x400>; 77 + interrupts = <0 134 0>; 78 + dr_mode = "peripheral"; 79 + 80 + clocks = <&gcc GCC_XO_CLK>, <&gcc GCC_USB_HS_SYSTEM_CLK>, 81 + <&gcc GCC_USB_HS_AHB_CLK>; 82 + 83 + clock-names = "phy", "core", "iface"; 84 + 85 + vddcx-supply = <&pm8841_s2_corner>; 86 + v1p8-supply = <&pm8941_l6>; 87 + v3p3-supply = <&pm8941_l24>; 88 + 89 + resets = <&gcc GCC_USB2A_PHY_BCR>, <&gcc GCC_USB_HS_BCR>; 90 + reset-names = "phy", "link"; 91 + 92 + qcom,otg-control = <1>; 93 + qcom,phy-init-sequence = < -1 0x63 >; 94 + qcom,vdd-levels = <1 5 7>; 95 + };
+1 -1
arch/arm/mach-msm/board-msm7x30.c
··· 95 95 96 96 static struct msm_otg_platform_data msm_otg_pdata = { 97 97 .phy_init_seq = hsusb_phy_init_seq, 98 - .mode = USB_PERIPHERAL, 98 + .mode = USB_DR_MODE_PERIPHERAL, 99 99 .otg_control = OTG_PHY_CONTROL, 100 100 .link_clk_reset = hsusb_link_clk_reset, 101 101 .phy_clk_reset = hsusb_phy_clk_reset,
+1 -1
arch/arm/mach-msm/board-qsd8x50.c
··· 116 116 117 117 static struct msm_otg_platform_data msm_otg_pdata = { 118 118 .phy_init_seq = hsusb_phy_init_seq, 119 - .mode = USB_PERIPHERAL, 119 + .mode = USB_DR_MODE_PERIPHERAL, 120 120 .otg_control = OTG_PHY_CONTROL, 121 121 .link_clk_reset = hsusb_link_clk_reset, 122 122 .phy_clk_reset = hsusb_phy_clk_reset,
-1
arch/arm/mach-omap2/board-omap3beagle.c
··· 33 33 #include <linux/mtd/nand.h> 34 34 #include <linux/mmc/host.h> 35 35 #include <linux/usb/phy.h> 36 - #include <linux/usb/usb_phy_gen_xceiv.h> 37 36 38 37 #include <linux/regulator/machine.h> 39 38 #include <linux/i2c/twl.h>
+5 -5
arch/arm/mach-omap2/usb-host.c
··· 28 28 #include <linux/io.h> 29 29 #include <linux/gpio.h> 30 30 #include <linux/usb/phy.h> 31 - #include <linux/usb/usb_phy_gen_xceiv.h> 31 + #include <linux/usb/usb_phy_generic.h> 32 32 33 33 #include "soc.h" 34 34 #include "omap_device.h" ··· 349 349 /* .init_data filled later */ 350 350 }; 351 351 352 - static const char *nop_name = "usb_phy_gen_xceiv"; /* NOP PHY driver */ 352 + static const char *nop_name = "usb_phy_generic"; /* NOP PHY driver */ 353 353 static const char *reg_name = "reg-fixed-voltage"; /* Regulator driver */ 354 354 355 355 /** ··· 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 + struct usb_phy_generic_platform_data nop_pdata; 439 439 440 440 for (i = 0; i < num_phys; i++) { 441 441 ··· 469 469 pdevinfo.id = phy->port; 470 470 pdevinfo.data = &nop_pdata; 471 471 pdevinfo.size_data = 472 - sizeof(struct usb_phy_gen_xceiv_platform_data); 473 - scnprintf(phy_id, MAX_STR, "usb_phy_gen_xceiv.%d", 472 + sizeof(struct usb_phy_generic_platform_data); 473 + scnprintf(phy_id, MAX_STR, "usb_phy_generic.%d", 474 474 phy->port); 475 475 pdev = platform_device_register_full(&pdevinfo); 476 476 if (IS_ERR(pdev)) {
+3 -1
drivers/usb/dwc3/Kconfig
··· 44 44 45 45 config USB_DWC3_OMAP 46 46 tristate "Texas Instruments OMAP5 and similar Platforms" 47 - depends on EXTCON 47 + depends on EXTCON && (ARCH_OMAP2PLUS || COMPILE_TEST) 48 48 default USB_DWC3 49 49 help 50 50 Some platforms from Texas Instruments like OMAP5, DRA7xxx and ··· 54 54 55 55 config USB_DWC3_EXYNOS 56 56 tristate "Samsung Exynos Platform" 57 + depends on ARCH_EXYNOS || COMPILE_TEST 57 58 default USB_DWC3 58 59 help 59 60 Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside, ··· 73 72 74 73 config USB_DWC3_KEYSTONE 75 74 tristate "Texas Instruments Keystone2 Platforms" 75 + depends on ARCH_KEYSTONE || COMPILE_TEST 76 76 default USB_DWC3 77 77 help 78 78 Support of USB2/3 functionality in TI Keystone2 platforms.
+133 -120
drivers/usb/dwc3/core.c
··· 486 486 phy_exit(dwc->usb3_generic_phy); 487 487 } 488 488 489 - #define DWC3_ALIGN_MASK (16 - 1) 490 - 491 - static int dwc3_probe(struct platform_device *pdev) 489 + static int dwc3_core_get_phy(struct dwc3 *dwc) 492 490 { 493 - struct device *dev = &pdev->dev; 494 - struct dwc3_platform_data *pdata = dev_get_platdata(dev); 491 + struct device *dev = dwc->dev; 495 492 struct device_node *node = dev->of_node; 496 - struct resource *res; 497 - struct dwc3 *dwc; 498 - 499 - int ret = -ENOMEM; 500 - 501 - void __iomem *regs; 502 - void *mem; 503 - 504 - mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); 505 - if (!mem) { 506 - dev_err(dev, "not enough memory\n"); 507 - return -ENOMEM; 508 - } 509 - dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); 510 - dwc->mem = mem; 511 - 512 - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 513 - if (!res) { 514 - dev_err(dev, "missing IRQ\n"); 515 - return -ENODEV; 516 - } 517 - dwc->xhci_resources[1].start = res->start; 518 - dwc->xhci_resources[1].end = res->end; 519 - dwc->xhci_resources[1].flags = res->flags; 520 - dwc->xhci_resources[1].name = res->name; 521 - 522 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 523 - if (!res) { 524 - dev_err(dev, "missing memory resource\n"); 525 - return -ENODEV; 526 - } 493 + int ret; 527 494 528 495 if (node) { 529 - dwc->maximum_speed = of_usb_get_maximum_speed(node); 530 - 531 496 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); 532 497 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); 533 - 534 - dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize"); 535 - dwc->dr_mode = of_usb_get_dr_mode(node); 536 - } else if (pdata) { 537 - dwc->maximum_speed = pdata->maximum_speed; 538 - 539 - dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 540 - dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); 541 - 542 - dwc->needs_fifo_resize = pdata->tx_fifo_resize; 543 - dwc->dr_mode = pdata->dr_mode; 544 498 } else { 545 499 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 546 500 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); 547 501 } 548 - 549 - /* default to superspeed if no maximum_speed passed */ 550 - if (dwc->maximum_speed == USB_SPEED_UNKNOWN) 551 - dwc->maximum_speed = USB_SPEED_SUPER; 552 502 553 503 if (IS_ERR(dwc->usb2_phy)) { 554 504 ret = PTR_ERR(dwc->usb2_phy); ··· 550 600 } 551 601 } 552 602 603 + return 0; 604 + } 605 + 606 + static int dwc3_core_init_mode(struct dwc3 *dwc) 607 + { 608 + struct device *dev = dwc->dev; 609 + int ret; 610 + 611 + switch (dwc->dr_mode) { 612 + case USB_DR_MODE_PERIPHERAL: 613 + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); 614 + ret = dwc3_gadget_init(dwc); 615 + if (ret) { 616 + dev_err(dev, "failed to initialize gadget\n"); 617 + return ret; 618 + } 619 + break; 620 + case USB_DR_MODE_HOST: 621 + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); 622 + ret = dwc3_host_init(dwc); 623 + if (ret) { 624 + dev_err(dev, "failed to initialize host\n"); 625 + return ret; 626 + } 627 + break; 628 + case USB_DR_MODE_OTG: 629 + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); 630 + ret = dwc3_host_init(dwc); 631 + if (ret) { 632 + dev_err(dev, "failed to initialize host\n"); 633 + return ret; 634 + } 635 + 636 + ret = dwc3_gadget_init(dwc); 637 + if (ret) { 638 + dev_err(dev, "failed to initialize gadget\n"); 639 + return ret; 640 + } 641 + break; 642 + default: 643 + dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); 644 + return -EINVAL; 645 + } 646 + 647 + return 0; 648 + } 649 + 650 + static void dwc3_core_exit_mode(struct dwc3 *dwc) 651 + { 652 + switch (dwc->dr_mode) { 653 + case USB_DR_MODE_PERIPHERAL: 654 + dwc3_gadget_exit(dwc); 655 + break; 656 + case USB_DR_MODE_HOST: 657 + dwc3_host_exit(dwc); 658 + break; 659 + case USB_DR_MODE_OTG: 660 + dwc3_host_exit(dwc); 661 + dwc3_gadget_exit(dwc); 662 + break; 663 + default: 664 + /* do nothing */ 665 + break; 666 + } 667 + } 668 + 669 + #define DWC3_ALIGN_MASK (16 - 1) 670 + 671 + static int dwc3_probe(struct platform_device *pdev) 672 + { 673 + struct device *dev = &pdev->dev; 674 + struct dwc3_platform_data *pdata = dev_get_platdata(dev); 675 + struct device_node *node = dev->of_node; 676 + struct resource *res; 677 + struct dwc3 *dwc; 678 + 679 + int ret; 680 + 681 + void __iomem *regs; 682 + void *mem; 683 + 684 + mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); 685 + if (!mem) { 686 + dev_err(dev, "not enough memory\n"); 687 + return -ENOMEM; 688 + } 689 + dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); 690 + dwc->mem = mem; 691 + dwc->dev = dev; 692 + 693 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 694 + if (!res) { 695 + dev_err(dev, "missing IRQ\n"); 696 + return -ENODEV; 697 + } 698 + dwc->xhci_resources[1].start = res->start; 699 + dwc->xhci_resources[1].end = res->end; 700 + dwc->xhci_resources[1].flags = res->flags; 701 + dwc->xhci_resources[1].name = res->name; 702 + 703 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 704 + if (!res) { 705 + dev_err(dev, "missing memory resource\n"); 706 + return -ENODEV; 707 + } 708 + 709 + if (node) { 710 + dwc->maximum_speed = of_usb_get_maximum_speed(node); 711 + 712 + dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize"); 713 + dwc->dr_mode = of_usb_get_dr_mode(node); 714 + } else if (pdata) { 715 + dwc->maximum_speed = pdata->maximum_speed; 716 + 717 + dwc->needs_fifo_resize = pdata->tx_fifo_resize; 718 + dwc->dr_mode = pdata->dr_mode; 719 + } 720 + 721 + /* default to superspeed if no maximum_speed passed */ 722 + if (dwc->maximum_speed == USB_SPEED_UNKNOWN) 723 + dwc->maximum_speed = USB_SPEED_SUPER; 724 + 725 + ret = dwc3_core_get_phy(dwc); 726 + if (ret) 727 + return ret; 728 + 553 729 dwc->xhci_resources[0].start = res->start; 554 730 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + 555 731 DWC3_XHCI_REGS_END; ··· 697 621 698 622 dwc->regs = regs; 699 623 dwc->regs_size = resource_size(res); 700 - dwc->dev = dev; 701 624 702 625 dev->dma_mask = dev->parent->dma_mask; 703 626 dev->dma_parms = dev->parent->dma_parms; ··· 745 670 goto err_usb3phy_power; 746 671 } 747 672 748 - switch (dwc->dr_mode) { 749 - case USB_DR_MODE_PERIPHERAL: 750 - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); 751 - ret = dwc3_gadget_init(dwc); 752 - if (ret) { 753 - dev_err(dev, "failed to initialize gadget\n"); 754 - goto err2; 755 - } 756 - break; 757 - case USB_DR_MODE_HOST: 758 - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); 759 - ret = dwc3_host_init(dwc); 760 - if (ret) { 761 - dev_err(dev, "failed to initialize host\n"); 762 - goto err2; 763 - } 764 - break; 765 - case USB_DR_MODE_OTG: 766 - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); 767 - ret = dwc3_host_init(dwc); 768 - if (ret) { 769 - dev_err(dev, "failed to initialize host\n"); 770 - goto err2; 771 - } 772 - 773 - ret = dwc3_gadget_init(dwc); 774 - if (ret) { 775 - dev_err(dev, "failed to initialize gadget\n"); 776 - goto err2; 777 - } 778 - break; 779 - default: 780 - dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); 673 + ret = dwc3_core_init_mode(dwc); 674 + if (ret) 781 675 goto err2; 782 - } 783 676 784 677 ret = dwc3_debugfs_init(dwc); 785 678 if (ret) { ··· 760 717 return 0; 761 718 762 719 err3: 763 - switch (dwc->dr_mode) { 764 - case USB_DR_MODE_PERIPHERAL: 765 - dwc3_gadget_exit(dwc); 766 - break; 767 - case USB_DR_MODE_HOST: 768 - dwc3_host_exit(dwc); 769 - break; 770 - case USB_DR_MODE_OTG: 771 - dwc3_host_exit(dwc); 772 - dwc3_gadget_exit(dwc); 773 - break; 774 - default: 775 - /* do nothing */ 776 - break; 777 - } 720 + dwc3_core_exit_mode(dwc); 778 721 779 722 err2: 780 723 dwc3_event_buffers_cleanup(dwc); ··· 795 766 pm_runtime_disable(&pdev->dev); 796 767 797 768 dwc3_debugfs_exit(dwc); 798 - 799 - switch (dwc->dr_mode) { 800 - case USB_DR_MODE_PERIPHERAL: 801 - dwc3_gadget_exit(dwc); 802 - break; 803 - case USB_DR_MODE_HOST: 804 - dwc3_host_exit(dwc); 805 - break; 806 - case USB_DR_MODE_OTG: 807 - dwc3_host_exit(dwc); 808 - dwc3_gadget_exit(dwc); 809 - break; 810 - default: 811 - /* do nothing */ 812 - break; 813 - } 814 - 769 + dwc3_core_exit_mode(dwc); 815 770 dwc3_event_buffers_cleanup(dwc); 816 771 dwc3_free_event_buffers(dwc); 817 772 dwc3_core_exit(dwc);
+58 -13
drivers/usb/dwc3/dwc3-exynos.c
··· 24 24 #include <linux/dma-mapping.h> 25 25 #include <linux/clk.h> 26 26 #include <linux/usb/otg.h> 27 - #include <linux/usb/usb_phy_gen_xceiv.h> 27 + #include <linux/usb/usb_phy_generic.h> 28 28 #include <linux/of.h> 29 29 #include <linux/of_platform.h> 30 + #include <linux/regulator/consumer.h> 30 31 31 32 struct dwc3_exynos { 32 33 struct platform_device *usb2_phy; ··· 35 34 struct device *dev; 36 35 37 36 struct clk *clk; 37 + struct regulator *vdd33; 38 + struct regulator *vdd10; 38 39 }; 39 40 40 41 static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos) 41 42 { 42 - struct usb_phy_gen_xceiv_platform_data pdata; 43 + struct usb_phy_generic_platform_data pdata; 43 44 struct platform_device *pdev; 44 45 int ret; 45 46 46 47 memset(&pdata, 0x00, sizeof(pdata)); 47 48 48 - pdev = platform_device_alloc("usb_phy_gen_xceiv", PLATFORM_DEVID_AUTO); 49 + pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO); 49 50 if (!pdev) 50 51 return -ENOMEM; 51 52 ··· 59 56 if (ret) 60 57 goto err1; 61 58 62 - pdev = platform_device_alloc("usb_phy_gen_xceiv", PLATFORM_DEVID_AUTO); 59 + pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO); 63 60 if (!pdev) { 64 61 ret = -ENOMEM; 65 62 goto err1; ··· 110 107 struct device *dev = &pdev->dev; 111 108 struct device_node *node = dev->of_node; 112 109 113 - int ret = -ENOMEM; 110 + int ret; 114 111 115 112 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); 116 113 if (!exynos) { 117 114 dev_err(dev, "not enough memory\n"); 118 - goto err1; 115 + return -ENOMEM; 119 116 } 120 117 121 118 /* ··· 125 122 */ 126 123 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); 127 124 if (ret) 128 - goto err1; 125 + return ret; 129 126 130 127 platform_set_drvdata(pdev, exynos); 131 128 132 129 ret = dwc3_exynos_register_phys(exynos); 133 130 if (ret) { 134 131 dev_err(dev, "couldn't register PHYs\n"); 135 - goto err1; 132 + return ret; 136 133 } 137 134 138 135 clk = devm_clk_get(dev, "usbdrd30"); 139 136 if (IS_ERR(clk)) { 140 137 dev_err(dev, "couldn't get clock\n"); 141 - ret = -EINVAL; 142 - goto err1; 138 + return -EINVAL; 143 139 } 144 140 145 141 exynos->dev = dev; ··· 146 144 147 145 clk_prepare_enable(exynos->clk); 148 146 147 + exynos->vdd33 = devm_regulator_get(dev, "vdd33"); 148 + if (IS_ERR(exynos->vdd33)) { 149 + ret = PTR_ERR(exynos->vdd33); 150 + goto err2; 151 + } 152 + ret = regulator_enable(exynos->vdd33); 153 + if (ret) { 154 + dev_err(dev, "Failed to enable VDD33 supply\n"); 155 + goto err2; 156 + } 157 + 158 + exynos->vdd10 = devm_regulator_get(dev, "vdd10"); 159 + if (IS_ERR(exynos->vdd10)) { 160 + ret = PTR_ERR(exynos->vdd10); 161 + goto err3; 162 + } 163 + ret = regulator_enable(exynos->vdd10); 164 + if (ret) { 165 + dev_err(dev, "Failed to enable VDD10 supply\n"); 166 + goto err3; 167 + } 168 + 149 169 if (node) { 150 170 ret = of_platform_populate(node, NULL, NULL, dev); 151 171 if (ret) { 152 172 dev_err(dev, "failed to add dwc3 core\n"); 153 - goto err2; 173 + goto err4; 154 174 } 155 175 } else { 156 176 dev_err(dev, "no device node, failed to add dwc3 core\n"); 157 177 ret = -ENODEV; 158 - goto err2; 178 + goto err4; 159 179 } 160 180 161 181 return 0; 162 182 183 + err4: 184 + regulator_disable(exynos->vdd10); 185 + err3: 186 + regulator_disable(exynos->vdd33); 163 187 err2: 164 188 clk_disable_unprepare(clk); 165 - err1: 166 189 return ret; 167 190 } 168 191 ··· 200 173 platform_device_unregister(exynos->usb3_phy); 201 174 202 175 clk_disable_unprepare(exynos->clk); 176 + 177 + regulator_disable(exynos->vdd33); 178 + regulator_disable(exynos->vdd10); 203 179 204 180 return 0; 205 181 } ··· 222 192 223 193 clk_disable(exynos->clk); 224 194 195 + regulator_disable(exynos->vdd33); 196 + regulator_disable(exynos->vdd10); 197 + 225 198 return 0; 226 199 } 227 200 228 201 static int dwc3_exynos_resume(struct device *dev) 229 202 { 230 203 struct dwc3_exynos *exynos = dev_get_drvdata(dev); 204 + int ret; 205 + 206 + ret = regulator_enable(exynos->vdd33); 207 + if (ret) { 208 + dev_err(dev, "Failed to enable VDD33 supply\n"); 209 + return ret; 210 + } 211 + ret = regulator_enable(exynos->vdd10); 212 + if (ret) { 213 + dev_err(dev, "Failed to enable VDD10 supply\n"); 214 + return ret; 215 + } 231 216 232 217 clk_enable(exynos->clk); 233 218
+1 -1
drivers/usb/dwc3/dwc3-omap.c
··· 393 393 struct extcon_dev *edev; 394 394 struct regulator *vbus_reg = NULL; 395 395 396 - int ret = -ENOMEM; 396 + int ret; 397 397 int irq; 398 398 399 399 int utmi_mode = 0;
+8 -13
drivers/usb/dwc3/dwc3-pci.c
··· 23 23 #include <linux/platform_device.h> 24 24 25 25 #include <linux/usb/otg.h> 26 - #include <linux/usb/usb_phy_gen_xceiv.h> 26 + #include <linux/usb/usb_phy_generic.h> 27 27 28 28 /* FIXME define these in <linux/pci_ids.h> */ 29 29 #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 ··· 40 40 41 41 static int dwc3_pci_register_phys(struct dwc3_pci *glue) 42 42 { 43 - struct usb_phy_gen_xceiv_platform_data pdata; 43 + struct usb_phy_generic_platform_data pdata; 44 44 struct platform_device *pdev; 45 45 int ret; 46 46 47 47 memset(&pdata, 0x00, sizeof(pdata)); 48 48 49 - pdev = platform_device_alloc("usb_phy_gen_xceiv", 0); 49 + pdev = platform_device_alloc("usb_phy_generic", 0); 50 50 if (!pdev) 51 51 return -ENOMEM; 52 52 ··· 58 58 if (ret) 59 59 goto err1; 60 60 61 - pdev = platform_device_alloc("usb_phy_gen_xceiv", 1); 61 + pdev = platform_device_alloc("usb_phy_generic", 1); 62 62 if (!pdev) { 63 63 ret = -ENOMEM; 64 64 goto err1; ··· 99 99 struct resource res[2]; 100 100 struct platform_device *dwc3; 101 101 struct dwc3_pci *glue; 102 - int ret = -ENOMEM; 102 + int ret; 103 103 struct device *dev = &pci->dev; 104 104 105 105 glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); ··· 110 110 111 111 glue->dev = dev; 112 112 113 - ret = pci_enable_device(pci); 113 + ret = pcim_enable_device(pci); 114 114 if (ret) { 115 115 dev_err(dev, "failed to enable pci device\n"); 116 116 return -ENODEV; ··· 127 127 dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); 128 128 if (!dwc3) { 129 129 dev_err(dev, "couldn't allocate dwc3 device\n"); 130 - ret = -ENOMEM; 131 - goto err1; 130 + return -ENOMEM; 132 131 } 133 132 134 133 memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); ··· 144 145 ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res)); 145 146 if (ret) { 146 147 dev_err(dev, "couldn't add resources to dwc3 device\n"); 147 - goto err1; 148 + return ret; 148 149 } 149 150 150 151 pci_set_drvdata(pci, glue); ··· 166 167 167 168 err3: 168 169 platform_device_put(dwc3); 169 - err1: 170 - pci_disable_device(pci); 171 - 172 170 return ret; 173 171 } 174 172 ··· 176 180 platform_device_unregister(glue->dwc3); 177 181 platform_device_unregister(glue->usb2_phy); 178 182 platform_device_unregister(glue->usb3_phy); 179 - pci_disable_device(pci); 180 183 } 181 184 182 185 static const struct pci_device_id dwc3_pci_id_table[] = {
+77 -6
drivers/usb/dwc3/gadget.c
··· 298 298 } 299 299 } 300 300 301 + static const char *dwc3_gadget_generic_cmd_string(u8 cmd) 302 + { 303 + switch (cmd) { 304 + case DWC3_DGCMD_SET_LMP: 305 + return "Set LMP"; 306 + case DWC3_DGCMD_SET_PERIODIC_PAR: 307 + return "Set Periodic Parameters"; 308 + case DWC3_DGCMD_XMIT_FUNCTION: 309 + return "Transmit Function Wake Device Notification"; 310 + case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO: 311 + return "Set Scratchpad Buffer Array Address Lo"; 312 + case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI: 313 + return "Set Scratchpad Buffer Array Address Hi"; 314 + case DWC3_DGCMD_SELECTED_FIFO_FLUSH: 315 + return "Selected FIFO Flush"; 316 + case DWC3_DGCMD_ALL_FIFO_FLUSH: 317 + return "All FIFO Flush"; 318 + case DWC3_DGCMD_SET_ENDPOINT_NRDY: 319 + return "Set Endpoint NRDY"; 320 + case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK: 321 + return "Run SoC Bus Loopback Test"; 322 + default: 323 + return "UNKNOWN"; 324 + } 325 + } 326 + 327 + static const char *dwc3_gadget_link_string(enum dwc3_link_state link_state) 328 + { 329 + switch (link_state) { 330 + case DWC3_LINK_STATE_U0: 331 + return "U0"; 332 + case DWC3_LINK_STATE_U1: 333 + return "U1"; 334 + case DWC3_LINK_STATE_U2: 335 + return "U2"; 336 + case DWC3_LINK_STATE_U3: 337 + return "U3"; 338 + case DWC3_LINK_STATE_SS_DIS: 339 + return "SS.Disabled"; 340 + case DWC3_LINK_STATE_RX_DET: 341 + return "RX.Detect"; 342 + case DWC3_LINK_STATE_SS_INACT: 343 + return "SS.Inactive"; 344 + case DWC3_LINK_STATE_POLL: 345 + return "Polling"; 346 + case DWC3_LINK_STATE_RECOV: 347 + return "Recovery"; 348 + case DWC3_LINK_STATE_HRESET: 349 + return "Hot Reset"; 350 + case DWC3_LINK_STATE_CMPLY: 351 + return "Compliance"; 352 + case DWC3_LINK_STATE_LPBK: 353 + return "Loopback"; 354 + case DWC3_LINK_STATE_RESET: 355 + return "Reset"; 356 + case DWC3_LINK_STATE_RESUME: 357 + return "Resume"; 358 + default: 359 + return "UNKNOWN link state\n"; 360 + } 361 + } 362 + 301 363 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param) 302 364 { 303 365 u32 timeout = 500; 304 366 u32 reg; 367 + 368 + dev_vdbg(dwc->dev, "generic cmd '%s' [%d] param %08x\n", 369 + dwc3_gadget_generic_cmd_string(cmd), cmd, param); 305 370 306 371 dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); 307 372 dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); ··· 397 332 u32 timeout = 500; 398 333 u32 reg; 399 334 400 - dev_vdbg(dwc->dev, "%s: cmd '%s' params %08x %08x %08x\n", 335 + dev_vdbg(dwc->dev, "%s: cmd '%s' [%d] params %08x %08x %08x\n", 401 336 dep->name, 402 - dwc3_gadget_ep_cmd_string(cmd), params->param0, 337 + dwc3_gadget_ep_cmd_string(cmd), cmd, params->param0, 403 338 params->param1, params->param2); 404 339 405 340 dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0); ··· 580 515 { 581 516 struct dwc3 *dwc = dep->dwc; 582 517 u32 reg; 583 - int ret = -ENOMEM; 518 + int ret; 584 519 585 520 dev_vdbg(dwc->dev, "Enabling %s\n", dep->name); 586 521 ··· 668 603 u32 reg; 669 604 670 605 dwc3_remove_requests(dwc, dep); 606 + 607 + /* make sure HW endpoint isn't stalled */ 608 + if (dep->flags & DWC3_EP_STALL) 609 + __dwc3_gadget_ep_set_halt(dep, 0); 671 610 672 611 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); 673 612 reg &= ~DWC3_DALEPENA_EP(dep->number); ··· 2510 2441 } 2511 2442 } 2512 2443 2513 - dwc->link_state = next; 2514 - 2515 2444 switch (next) { 2516 2445 case DWC3_LINK_STATE_U1: 2517 2446 if (dwc->speed == USB_SPEED_SUPER) ··· 2527 2460 break; 2528 2461 } 2529 2462 2530 - dev_vdbg(dwc->dev, "%s link %d\n", __func__, dwc->link_state); 2463 + dev_vdbg(dwc->dev, "link change: %s [%d] -> %s [%d]\n", 2464 + dwc3_gadget_link_string(dwc->link_state), 2465 + dwc->link_state, dwc3_gadget_link_string(next), next); 2466 + 2467 + dwc->link_state = next; 2531 2468 } 2532 2469 2533 2470 static void dwc3_gadget_hibernation_interrupt(struct dwc3 *dwc,
+1 -1
drivers/usb/gadget/atmel_usba_udc.c
··· 1686 1686 reset_all_endpoints(udc); 1687 1687 1688 1688 if (udc->gadget.speed != USB_SPEED_UNKNOWN 1689 - && udc->driver->disconnect) { 1689 + && udc->driver && udc->driver->disconnect) { 1690 1690 udc->gadget.speed = USB_SPEED_UNKNOWN; 1691 1691 spin_unlock(&udc->lock); 1692 1692 udc->driver->disconnect(&udc->gadget);
+317 -1
drivers/usb/gadget/composite.c
··· 21 21 #include <linux/usb/composite.h> 22 22 #include <asm/unaligned.h> 23 23 24 + #include "u_os_desc.h" 25 + 26 + /** 27 + * struct usb_os_string - represents OS String to be reported by a gadget 28 + * @bLength: total length of the entire descritor, always 0x12 29 + * @bDescriptorType: USB_DT_STRING 30 + * @qwSignature: the OS String proper 31 + * @bMS_VendorCode: code used by the host for subsequent requests 32 + * @bPad: not used, must be zero 33 + */ 34 + struct usb_os_string { 35 + __u8 bLength; 36 + __u8 bDescriptorType; 37 + __u8 qwSignature[OS_STRING_QW_SIGN_LEN]; 38 + __u8 bMS_VendorCode; 39 + __u8 bPad; 40 + } __packed; 41 + 24 42 /* 25 43 * The code in this file is utility code, used to build a gadget driver 26 44 * from one or more "function" drivers, one or more "configuration" ··· 440 422 { 441 423 struct usb_gadget *gadget = cdev->gadget; 442 424 struct usb_configuration *c; 425 + struct list_head *pos; 443 426 u8 type = w_value >> 8; 444 427 enum usb_device_speed speed = USB_SPEED_UNKNOWN; 445 428 ··· 459 440 460 441 /* This is a lookup by config *INDEX* */ 461 442 w_value &= 0xff; 462 - list_for_each_entry(c, &cdev->configs, list) { 443 + 444 + pos = &cdev->configs; 445 + c = cdev->os_desc_config; 446 + if (c) 447 + goto check_config; 448 + 449 + while ((pos = pos->next) != &cdev->configs) { 450 + c = list_entry(pos, typeof(*c), list); 451 + 452 + /* skip OS Descriptors config which is handled separately */ 453 + if (c == cdev->os_desc_config) 454 + continue; 455 + 456 + check_config: 463 457 /* ignore configs that won't work at this speed */ 464 458 switch (speed) { 465 459 case USB_SPEED_SUPER: ··· 666 634 if (!c) 667 635 goto done; 668 636 637 + usb_gadget_set_state(gadget, USB_STATE_CONFIGURED); 669 638 cdev->config = c; 670 639 671 640 /* Initialize all interfaces by setting them to altsetting zero. */ ··· 993 960 return s->bLength; 994 961 } 995 962 963 + if (cdev->use_os_string && language == 0 && id == OS_STRING_IDX) { 964 + struct usb_os_string *b = buf; 965 + b->bLength = sizeof(*b); 966 + b->bDescriptorType = USB_DT_STRING; 967 + compiletime_assert( 968 + sizeof(b->qwSignature) == sizeof(cdev->qw_sign), 969 + "qwSignature size must be equal to qw_sign"); 970 + memcpy(&b->qwSignature, cdev->qw_sign, sizeof(b->qwSignature)); 971 + b->bMS_VendorCode = cdev->b_vendor_code; 972 + b->bPad = 0; 973 + return sizeof(*b); 974 + } 975 + 996 976 list_for_each_entry(uc, &cdev->gstrings, list) { 997 977 struct usb_gadget_strings **sp; 998 978 ··· 1252 1206 req->status, req->actual, req->length); 1253 1207 } 1254 1208 1209 + static int count_ext_compat(struct usb_configuration *c) 1210 + { 1211 + int i, res; 1212 + 1213 + res = 0; 1214 + for (i = 0; i < c->next_interface_id; ++i) { 1215 + struct usb_function *f; 1216 + int j; 1217 + 1218 + f = c->interface[i]; 1219 + for (j = 0; j < f->os_desc_n; ++j) { 1220 + struct usb_os_desc *d; 1221 + 1222 + if (i != f->os_desc_table[j].if_id) 1223 + continue; 1224 + d = f->os_desc_table[j].os_desc; 1225 + if (d && d->ext_compat_id) 1226 + ++res; 1227 + } 1228 + } 1229 + BUG_ON(res > 255); 1230 + return res; 1231 + } 1232 + 1233 + static void fill_ext_compat(struct usb_configuration *c, u8 *buf) 1234 + { 1235 + int i, count; 1236 + 1237 + count = 16; 1238 + for (i = 0; i < c->next_interface_id; ++i) { 1239 + struct usb_function *f; 1240 + int j; 1241 + 1242 + f = c->interface[i]; 1243 + for (j = 0; j < f->os_desc_n; ++j) { 1244 + struct usb_os_desc *d; 1245 + 1246 + if (i != f->os_desc_table[j].if_id) 1247 + continue; 1248 + d = f->os_desc_table[j].os_desc; 1249 + if (d && d->ext_compat_id) { 1250 + *buf++ = i; 1251 + *buf++ = 0x01; 1252 + memcpy(buf, d->ext_compat_id, 16); 1253 + buf += 22; 1254 + } else { 1255 + ++buf; 1256 + *buf = 0x01; 1257 + buf += 23; 1258 + } 1259 + count += 24; 1260 + if (count >= 4096) 1261 + return; 1262 + } 1263 + } 1264 + } 1265 + 1266 + static int count_ext_prop(struct usb_configuration *c, int interface) 1267 + { 1268 + struct usb_function *f; 1269 + int j, res; 1270 + 1271 + res = 0; 1272 + 1273 + f = c->interface[interface]; 1274 + for (j = 0; j < f->os_desc_n; ++j) { 1275 + struct usb_os_desc *d; 1276 + 1277 + if (interface != f->os_desc_table[j].if_id) 1278 + continue; 1279 + d = f->os_desc_table[j].os_desc; 1280 + if (d && d->ext_compat_id) 1281 + return d->ext_prop_count; 1282 + } 1283 + return res; 1284 + } 1285 + 1286 + static int len_ext_prop(struct usb_configuration *c, int interface) 1287 + { 1288 + struct usb_function *f; 1289 + struct usb_os_desc *d; 1290 + int j, res; 1291 + 1292 + res = 10; /* header length */ 1293 + f = c->interface[interface]; 1294 + for (j = 0; j < f->os_desc_n; ++j) { 1295 + if (interface != f->os_desc_table[j].if_id) 1296 + continue; 1297 + d = f->os_desc_table[j].os_desc; 1298 + if (d) 1299 + return min(res + d->ext_prop_len, 4096); 1300 + } 1301 + return res; 1302 + } 1303 + 1304 + static int fill_ext_prop(struct usb_configuration *c, int interface, u8 *buf) 1305 + { 1306 + struct usb_function *f; 1307 + struct usb_os_desc *d; 1308 + struct usb_os_desc_ext_prop *ext_prop; 1309 + int j, count, n, ret; 1310 + u8 *start = buf; 1311 + 1312 + f = c->interface[interface]; 1313 + for (j = 0; j < f->os_desc_n; ++j) { 1314 + if (interface != f->os_desc_table[j].if_id) 1315 + continue; 1316 + d = f->os_desc_table[j].os_desc; 1317 + if (d) 1318 + list_for_each_entry(ext_prop, &d->ext_prop, entry) { 1319 + /* 4kB minus header length */ 1320 + n = buf - start; 1321 + if (n >= 4086) 1322 + return 0; 1323 + 1324 + count = ext_prop->data_len + 1325 + ext_prop->name_len + 14; 1326 + if (count > 4086 - n) 1327 + return -EINVAL; 1328 + usb_ext_prop_put_size(buf, count); 1329 + usb_ext_prop_put_type(buf, ext_prop->type); 1330 + ret = usb_ext_prop_put_name(buf, ext_prop->name, 1331 + ext_prop->name_len); 1332 + if (ret < 0) 1333 + return ret; 1334 + switch (ext_prop->type) { 1335 + case USB_EXT_PROP_UNICODE: 1336 + case USB_EXT_PROP_UNICODE_ENV: 1337 + case USB_EXT_PROP_UNICODE_LINK: 1338 + usb_ext_prop_put_unicode(buf, ret, 1339 + ext_prop->data, 1340 + ext_prop->data_len); 1341 + break; 1342 + case USB_EXT_PROP_BINARY: 1343 + usb_ext_prop_put_binary(buf, ret, 1344 + ext_prop->data, 1345 + ext_prop->data_len); 1346 + break; 1347 + case USB_EXT_PROP_LE32: 1348 + /* not implemented */ 1349 + case USB_EXT_PROP_BE32: 1350 + /* not implemented */ 1351 + default: 1352 + return -EINVAL; 1353 + } 1354 + buf += count; 1355 + } 1356 + } 1357 + 1358 + return 0; 1359 + } 1360 + 1255 1361 /* 1256 1362 * The setup() callback implements all the ep0 functionality that's 1257 1363 * not handled lower down, in hardware or the hardware driver(like ··· 1613 1415 break; 1614 1416 default: 1615 1417 unknown: 1418 + /* 1419 + * OS descriptors handling 1420 + */ 1421 + if (cdev->use_os_string && cdev->os_desc_config && 1422 + (ctrl->bRequest & USB_TYPE_VENDOR) && 1423 + ctrl->bRequest == cdev->b_vendor_code) { 1424 + struct usb_request *req; 1425 + struct usb_configuration *os_desc_cfg; 1426 + u8 *buf; 1427 + int interface; 1428 + int count = 0; 1429 + 1430 + req = cdev->os_desc_req; 1431 + req->complete = composite_setup_complete; 1432 + buf = req->buf; 1433 + os_desc_cfg = cdev->os_desc_config; 1434 + memset(buf, 0, w_length); 1435 + buf[5] = 0x01; 1436 + switch (ctrl->bRequestType & USB_RECIP_MASK) { 1437 + case USB_RECIP_DEVICE: 1438 + if (w_index != 0x4 || (w_value >> 8)) 1439 + break; 1440 + buf[6] = w_index; 1441 + if (w_length == 0x10) { 1442 + /* Number of ext compat interfaces */ 1443 + count = count_ext_compat(os_desc_cfg); 1444 + buf[8] = count; 1445 + count *= 24; /* 24 B/ext compat desc */ 1446 + count += 16; /* header */ 1447 + put_unaligned_le32(count, buf); 1448 + value = w_length; 1449 + } else { 1450 + /* "extended compatibility ID"s */ 1451 + count = count_ext_compat(os_desc_cfg); 1452 + buf[8] = count; 1453 + count *= 24; /* 24 B/ext compat desc */ 1454 + count += 16; /* header */ 1455 + put_unaligned_le32(count, buf); 1456 + buf += 16; 1457 + fill_ext_compat(os_desc_cfg, buf); 1458 + value = w_length; 1459 + } 1460 + break; 1461 + case USB_RECIP_INTERFACE: 1462 + if (w_index != 0x5 || (w_value >> 8)) 1463 + break; 1464 + interface = w_value & 0xFF; 1465 + buf[6] = w_index; 1466 + if (w_length == 0x0A) { 1467 + count = count_ext_prop(os_desc_cfg, 1468 + interface); 1469 + put_unaligned_le16(count, buf + 8); 1470 + count = len_ext_prop(os_desc_cfg, 1471 + interface); 1472 + put_unaligned_le32(count, buf); 1473 + 1474 + value = w_length; 1475 + } else { 1476 + count = count_ext_prop(os_desc_cfg, 1477 + interface); 1478 + put_unaligned_le16(count, buf + 8); 1479 + count = len_ext_prop(os_desc_cfg, 1480 + interface); 1481 + put_unaligned_le32(count, buf); 1482 + buf += 10; 1483 + value = fill_ext_prop(os_desc_cfg, 1484 + interface, buf); 1485 + if (value < 0) 1486 + return value; 1487 + 1488 + value = w_length; 1489 + } 1490 + break; 1491 + } 1492 + req->length = value; 1493 + req->zero = value < w_length; 1494 + value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); 1495 + if (value < 0) { 1496 + DBG(cdev, "ep_queue --> %d\n", value); 1497 + req->status = 0; 1498 + composite_setup_complete(gadget->ep0, req); 1499 + } 1500 + return value; 1501 + } 1502 + 1616 1503 VDBG(cdev, 1617 1504 "non-core control req%02x.%02x v%04x i%04x l%d\n", 1618 1505 ctrl->bRequestType, ctrl->bRequest, ··· 1921 1638 return ret; 1922 1639 } 1923 1640 1641 + int composite_os_desc_req_prepare(struct usb_composite_dev *cdev, 1642 + struct usb_ep *ep0) 1643 + { 1644 + int ret = 0; 1645 + 1646 + cdev->os_desc_req = usb_ep_alloc_request(ep0, GFP_KERNEL); 1647 + if (!cdev->os_desc_req) { 1648 + ret = PTR_ERR(cdev->os_desc_req); 1649 + goto end; 1650 + } 1651 + 1652 + /* OS feature descriptor length <= 4kB */ 1653 + cdev->os_desc_req->buf = kmalloc(4096, GFP_KERNEL); 1654 + if (!cdev->os_desc_req->buf) { 1655 + ret = PTR_ERR(cdev->os_desc_req->buf); 1656 + kfree(cdev->os_desc_req); 1657 + goto end; 1658 + } 1659 + cdev->os_desc_req->complete = composite_setup_complete; 1660 + end: 1661 + return ret; 1662 + } 1663 + 1924 1664 void composite_dev_cleanup(struct usb_composite_dev *cdev) 1925 1665 { 1926 1666 struct usb_gadget_string_container *uc, *tmp; ··· 1951 1645 list_for_each_entry_safe(uc, tmp, &cdev->gstrings, list) { 1952 1646 list_del(&uc->list); 1953 1647 kfree(uc); 1648 + } 1649 + if (cdev->os_desc_req) { 1650 + kfree(cdev->os_desc_req->buf); 1651 + usb_ep_free_request(cdev->gadget->ep0, cdev->os_desc_req); 1954 1652 } 1955 1653 if (cdev->req) { 1956 1654 kfree(cdev->req->buf); ··· 1992 1682 status = composite->bind(cdev); 1993 1683 if (status < 0) 1994 1684 goto fail; 1685 + 1686 + if (cdev->use_os_string) { 1687 + status = composite_os_desc_req_prepare(cdev, gadget->ep0); 1688 + if (status) 1689 + goto fail; 1690 + } 1995 1691 1996 1692 update_unchanged_dev_desc(&cdev->desc, composite->dev); 1997 1693
+552 -4
drivers/usb/gadget/configfs.c
··· 2 2 #include <linux/module.h> 3 3 #include <linux/slab.h> 4 4 #include <linux/device.h> 5 + #include <linux/nls.h> 5 6 #include <linux/usb/composite.h> 6 7 #include <linux/usb/gadget_configfs.h> 7 8 #include "configfs.h" 9 + #include "u_f.h" 10 + #include "u_os_desc.h" 8 11 9 12 int check_user_usb_string(const char *name, 10 13 struct usb_gadget_strings *stringtab_dev) ··· 46 43 struct config_group functions_group; 47 44 struct config_group configs_group; 48 45 struct config_group strings_group; 49 - struct config_group *default_groups[4]; 46 + struct config_group os_desc_group; 47 + struct config_group *default_groups[5]; 50 48 51 49 struct mutex lock; 52 50 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1]; ··· 60 56 #endif 61 57 struct usb_composite_driver composite; 62 58 struct usb_composite_dev cdev; 59 + bool use_os_desc; 60 + char b_vendor_code; 61 + char qw_sign[OS_STRING_QW_SIGN_LEN]; 63 62 }; 64 63 65 64 struct config_usb_cfg { ··· 84 77 85 78 struct config_group group; 86 79 struct list_head list; 80 + }; 81 + 82 + struct os_desc { 83 + struct config_group group; 87 84 }; 88 85 89 86 struct gadget_config_name { ··· 747 736 USB_CONFIG_STRING_RW_OPS(gadget_strings); 748 737 USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info); 749 738 739 + static inline struct os_desc *to_os_desc(struct config_item *item) 740 + { 741 + return container_of(to_config_group(item), struct os_desc, group); 742 + } 743 + 744 + CONFIGFS_ATTR_STRUCT(os_desc); 745 + CONFIGFS_ATTR_OPS(os_desc); 746 + 747 + static ssize_t os_desc_use_show(struct os_desc *os_desc, char *page) 748 + { 749 + struct gadget_info *gi; 750 + 751 + gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 752 + 753 + return sprintf(page, "%d", gi->use_os_desc); 754 + } 755 + 756 + static ssize_t os_desc_use_store(struct os_desc *os_desc, const char *page, 757 + size_t len) 758 + { 759 + struct gadget_info *gi; 760 + int ret; 761 + bool use; 762 + 763 + gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 764 + 765 + mutex_lock(&gi->lock); 766 + ret = strtobool(page, &use); 767 + if (!ret) { 768 + gi->use_os_desc = use; 769 + ret = len; 770 + } 771 + mutex_unlock(&gi->lock); 772 + 773 + return ret; 774 + } 775 + 776 + static struct os_desc_attribute os_desc_use = 777 + __CONFIGFS_ATTR(use, S_IRUGO | S_IWUSR, 778 + os_desc_use_show, 779 + os_desc_use_store); 780 + 781 + static ssize_t os_desc_b_vendor_code_show(struct os_desc *os_desc, char *page) 782 + { 783 + struct gadget_info *gi; 784 + 785 + gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 786 + 787 + return sprintf(page, "%d", gi->b_vendor_code); 788 + } 789 + 790 + static ssize_t os_desc_b_vendor_code_store(struct os_desc *os_desc, 791 + const char *page, size_t len) 792 + { 793 + struct gadget_info *gi; 794 + int ret; 795 + u8 b_vendor_code; 796 + 797 + gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 798 + 799 + mutex_lock(&gi->lock); 800 + ret = kstrtou8(page, 0, &b_vendor_code); 801 + if (!ret) { 802 + gi->b_vendor_code = b_vendor_code; 803 + ret = len; 804 + } 805 + mutex_unlock(&gi->lock); 806 + 807 + return ret; 808 + } 809 + 810 + static struct os_desc_attribute os_desc_b_vendor_code = 811 + __CONFIGFS_ATTR(b_vendor_code, S_IRUGO | S_IWUSR, 812 + os_desc_b_vendor_code_show, 813 + os_desc_b_vendor_code_store); 814 + 815 + static ssize_t os_desc_qw_sign_show(struct os_desc *os_desc, char *page) 816 + { 817 + struct gadget_info *gi; 818 + 819 + gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 820 + 821 + memcpy(page, gi->qw_sign, OS_STRING_QW_SIGN_LEN); 822 + 823 + return OS_STRING_QW_SIGN_LEN; 824 + } 825 + 826 + static ssize_t os_desc_qw_sign_store(struct os_desc *os_desc, const char *page, 827 + size_t len) 828 + { 829 + struct gadget_info *gi; 830 + int res, l; 831 + 832 + gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 833 + l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1); 834 + if (page[l - 1] == '\n') 835 + --l; 836 + 837 + mutex_lock(&gi->lock); 838 + res = utf8s_to_utf16s(page, l, 839 + UTF16_LITTLE_ENDIAN, (wchar_t *) gi->qw_sign, 840 + OS_STRING_QW_SIGN_LEN); 841 + if (res > 0) 842 + res = len; 843 + mutex_unlock(&gi->lock); 844 + 845 + return res; 846 + } 847 + 848 + static struct os_desc_attribute os_desc_qw_sign = 849 + __CONFIGFS_ATTR(qw_sign, S_IRUGO | S_IWUSR, 850 + os_desc_qw_sign_show, 851 + os_desc_qw_sign_store); 852 + 853 + static struct configfs_attribute *os_desc_attrs[] = { 854 + &os_desc_use.attr, 855 + &os_desc_b_vendor_code.attr, 856 + &os_desc_qw_sign.attr, 857 + NULL, 858 + }; 859 + 860 + static void os_desc_attr_release(struct config_item *item) 861 + { 862 + struct os_desc *os_desc = to_os_desc(item); 863 + kfree(os_desc); 864 + } 865 + 866 + static int os_desc_link(struct config_item *os_desc_ci, 867 + struct config_item *usb_cfg_ci) 868 + { 869 + struct gadget_info *gi = container_of(to_config_group(os_desc_ci), 870 + struct gadget_info, os_desc_group); 871 + struct usb_composite_dev *cdev = &gi->cdev; 872 + struct config_usb_cfg *c_target = 873 + container_of(to_config_group(usb_cfg_ci), 874 + struct config_usb_cfg, group); 875 + struct usb_configuration *c; 876 + int ret; 877 + 878 + mutex_lock(&gi->lock); 879 + list_for_each_entry(c, &cdev->configs, list) { 880 + if (c == &c_target->c) 881 + break; 882 + } 883 + if (c != &c_target->c) { 884 + ret = -EINVAL; 885 + goto out; 886 + } 887 + 888 + if (cdev->os_desc_config) { 889 + ret = -EBUSY; 890 + goto out; 891 + } 892 + 893 + cdev->os_desc_config = &c_target->c; 894 + ret = 0; 895 + 896 + out: 897 + mutex_unlock(&gi->lock); 898 + return ret; 899 + } 900 + 901 + static int os_desc_unlink(struct config_item *os_desc_ci, 902 + struct config_item *usb_cfg_ci) 903 + { 904 + struct gadget_info *gi = container_of(to_config_group(os_desc_ci), 905 + struct gadget_info, os_desc_group); 906 + struct usb_composite_dev *cdev = &gi->cdev; 907 + 908 + mutex_lock(&gi->lock); 909 + if (gi->udc_name) 910 + unregister_gadget(gi); 911 + cdev->os_desc_config = NULL; 912 + WARN_ON(gi->udc_name); 913 + mutex_unlock(&gi->lock); 914 + return 0; 915 + } 916 + 917 + static struct configfs_item_operations os_desc_ops = { 918 + .release = os_desc_attr_release, 919 + .show_attribute = os_desc_attr_show, 920 + .store_attribute = os_desc_attr_store, 921 + .allow_link = os_desc_link, 922 + .drop_link = os_desc_unlink, 923 + }; 924 + 925 + static struct config_item_type os_desc_type = { 926 + .ct_item_ops = &os_desc_ops, 927 + .ct_attrs = os_desc_attrs, 928 + .ct_owner = THIS_MODULE, 929 + }; 930 + 931 + CONFIGFS_ATTR_STRUCT(usb_os_desc); 932 + CONFIGFS_ATTR_OPS(usb_os_desc); 933 + 934 + 935 + static inline struct usb_os_desc_ext_prop 936 + *to_usb_os_desc_ext_prop(struct config_item *item) 937 + { 938 + return container_of(item, struct usb_os_desc_ext_prop, item); 939 + } 940 + 941 + CONFIGFS_ATTR_STRUCT(usb_os_desc_ext_prop); 942 + CONFIGFS_ATTR_OPS(usb_os_desc_ext_prop); 943 + 944 + static ssize_t ext_prop_type_show(struct usb_os_desc_ext_prop *ext_prop, 945 + char *page) 946 + { 947 + return sprintf(page, "%d", ext_prop->type); 948 + } 949 + 950 + static ssize_t ext_prop_type_store(struct usb_os_desc_ext_prop *ext_prop, 951 + const char *page, size_t len) 952 + { 953 + struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); 954 + u8 type; 955 + int ret; 956 + 957 + if (desc->opts_mutex) 958 + mutex_lock(desc->opts_mutex); 959 + ret = kstrtou8(page, 0, &type); 960 + if (ret) 961 + goto end; 962 + if (type < USB_EXT_PROP_UNICODE || type > USB_EXT_PROP_UNICODE_MULTI) { 963 + ret = -EINVAL; 964 + goto end; 965 + } 966 + 967 + if ((ext_prop->type == USB_EXT_PROP_BINARY || 968 + ext_prop->type == USB_EXT_PROP_LE32 || 969 + ext_prop->type == USB_EXT_PROP_BE32) && 970 + (type == USB_EXT_PROP_UNICODE || 971 + type == USB_EXT_PROP_UNICODE_ENV || 972 + type == USB_EXT_PROP_UNICODE_LINK)) 973 + ext_prop->data_len <<= 1; 974 + else if ((ext_prop->type == USB_EXT_PROP_UNICODE || 975 + ext_prop->type == USB_EXT_PROP_UNICODE_ENV || 976 + ext_prop->type == USB_EXT_PROP_UNICODE_LINK) && 977 + (type == USB_EXT_PROP_BINARY || 978 + type == USB_EXT_PROP_LE32 || 979 + type == USB_EXT_PROP_BE32)) 980 + ext_prop->data_len >>= 1; 981 + ext_prop->type = type; 982 + ret = len; 983 + 984 + end: 985 + if (desc->opts_mutex) 986 + mutex_unlock(desc->opts_mutex); 987 + return ret; 988 + } 989 + 990 + static ssize_t ext_prop_data_show(struct usb_os_desc_ext_prop *ext_prop, 991 + char *page) 992 + { 993 + int len = ext_prop->data_len; 994 + 995 + if (ext_prop->type == USB_EXT_PROP_UNICODE || 996 + ext_prop->type == USB_EXT_PROP_UNICODE_ENV || 997 + ext_prop->type == USB_EXT_PROP_UNICODE_LINK) 998 + len >>= 1; 999 + memcpy(page, ext_prop->data, len); 1000 + 1001 + return len; 1002 + } 1003 + 1004 + static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop, 1005 + const char *page, size_t len) 1006 + { 1007 + struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); 1008 + char *new_data; 1009 + size_t ret_len = len; 1010 + 1011 + if (page[len - 1] == '\n' || page[len - 1] == '\0') 1012 + --len; 1013 + new_data = kzalloc(len, GFP_KERNEL); 1014 + if (!new_data) 1015 + return -ENOMEM; 1016 + 1017 + memcpy(new_data, page, len); 1018 + 1019 + if (desc->opts_mutex) 1020 + mutex_lock(desc->opts_mutex); 1021 + kfree(ext_prop->data); 1022 + ext_prop->data = new_data; 1023 + desc->ext_prop_len -= ext_prop->data_len; 1024 + ext_prop->data_len = len; 1025 + desc->ext_prop_len += ext_prop->data_len; 1026 + if (ext_prop->type == USB_EXT_PROP_UNICODE || 1027 + ext_prop->type == USB_EXT_PROP_UNICODE_ENV || 1028 + ext_prop->type == USB_EXT_PROP_UNICODE_LINK) { 1029 + desc->ext_prop_len -= ext_prop->data_len; 1030 + ext_prop->data_len <<= 1; 1031 + ext_prop->data_len += 2; 1032 + desc->ext_prop_len += ext_prop->data_len; 1033 + } 1034 + if (desc->opts_mutex) 1035 + mutex_unlock(desc->opts_mutex); 1036 + return ret_len; 1037 + } 1038 + 1039 + static struct usb_os_desc_ext_prop_attribute ext_prop_type = 1040 + __CONFIGFS_ATTR(type, S_IRUGO | S_IWUSR, 1041 + ext_prop_type_show, ext_prop_type_store); 1042 + 1043 + static struct usb_os_desc_ext_prop_attribute ext_prop_data = 1044 + __CONFIGFS_ATTR(data, S_IRUGO | S_IWUSR, 1045 + ext_prop_data_show, ext_prop_data_store); 1046 + 1047 + static struct configfs_attribute *ext_prop_attrs[] = { 1048 + &ext_prop_type.attr, 1049 + &ext_prop_data.attr, 1050 + NULL, 1051 + }; 1052 + 1053 + static void usb_os_desc_ext_prop_release(struct config_item *item) 1054 + { 1055 + struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); 1056 + 1057 + kfree(ext_prop); /* frees a whole chunk */ 1058 + } 1059 + 1060 + static struct configfs_item_operations ext_prop_ops = { 1061 + .release = usb_os_desc_ext_prop_release, 1062 + .show_attribute = usb_os_desc_ext_prop_attr_show, 1063 + .store_attribute = usb_os_desc_ext_prop_attr_store, 1064 + }; 1065 + 1066 + static struct config_item *ext_prop_make( 1067 + struct config_group *group, 1068 + const char *name) 1069 + { 1070 + struct usb_os_desc_ext_prop *ext_prop; 1071 + struct config_item_type *ext_prop_type; 1072 + struct usb_os_desc *desc; 1073 + char *vlabuf; 1074 + 1075 + vla_group(data_chunk); 1076 + vla_item(data_chunk, struct usb_os_desc_ext_prop, ext_prop, 1); 1077 + vla_item(data_chunk, struct config_item_type, ext_prop_type, 1); 1078 + 1079 + vlabuf = kzalloc(vla_group_size(data_chunk), GFP_KERNEL); 1080 + if (!vlabuf) 1081 + return ERR_PTR(-ENOMEM); 1082 + 1083 + ext_prop = vla_ptr(vlabuf, data_chunk, ext_prop); 1084 + ext_prop_type = vla_ptr(vlabuf, data_chunk, ext_prop_type); 1085 + 1086 + desc = container_of(group, struct usb_os_desc, group); 1087 + ext_prop_type->ct_item_ops = &ext_prop_ops; 1088 + ext_prop_type->ct_attrs = ext_prop_attrs; 1089 + ext_prop_type->ct_owner = desc->owner; 1090 + 1091 + config_item_init_type_name(&ext_prop->item, name, ext_prop_type); 1092 + 1093 + ext_prop->name = kstrdup(name, GFP_KERNEL); 1094 + if (!ext_prop->name) { 1095 + kfree(vlabuf); 1096 + return ERR_PTR(-ENOMEM); 1097 + } 1098 + desc->ext_prop_len += 14; 1099 + ext_prop->name_len = 2 * strlen(ext_prop->name) + 2; 1100 + if (desc->opts_mutex) 1101 + mutex_lock(desc->opts_mutex); 1102 + desc->ext_prop_len += ext_prop->name_len; 1103 + list_add_tail(&ext_prop->entry, &desc->ext_prop); 1104 + ++desc->ext_prop_count; 1105 + if (desc->opts_mutex) 1106 + mutex_unlock(desc->opts_mutex); 1107 + 1108 + return &ext_prop->item; 1109 + } 1110 + 1111 + static void ext_prop_drop(struct config_group *group, struct config_item *item) 1112 + { 1113 + struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); 1114 + struct usb_os_desc *desc = to_usb_os_desc(&group->cg_item); 1115 + 1116 + if (desc->opts_mutex) 1117 + mutex_lock(desc->opts_mutex); 1118 + list_del(&ext_prop->entry); 1119 + --desc->ext_prop_count; 1120 + kfree(ext_prop->name); 1121 + desc->ext_prop_len -= (ext_prop->name_len + ext_prop->data_len + 14); 1122 + if (desc->opts_mutex) 1123 + mutex_unlock(desc->opts_mutex); 1124 + config_item_put(item); 1125 + } 1126 + 1127 + static struct configfs_group_operations interf_grp_ops = { 1128 + .make_item = &ext_prop_make, 1129 + .drop_item = &ext_prop_drop, 1130 + }; 1131 + 1132 + static struct configfs_item_operations interf_item_ops = { 1133 + .show_attribute = usb_os_desc_attr_show, 1134 + .store_attribute = usb_os_desc_attr_store, 1135 + }; 1136 + 1137 + static ssize_t rndis_grp_compatible_id_show(struct usb_os_desc *desc, 1138 + char *page) 1139 + { 1140 + memcpy(page, desc->ext_compat_id, 8); 1141 + return 8; 1142 + } 1143 + 1144 + static ssize_t rndis_grp_compatible_id_store(struct usb_os_desc *desc, 1145 + const char *page, size_t len) 1146 + { 1147 + int l; 1148 + 1149 + l = min_t(int, 8, len); 1150 + if (page[l - 1] == '\n') 1151 + --l; 1152 + if (desc->opts_mutex) 1153 + mutex_lock(desc->opts_mutex); 1154 + memcpy(desc->ext_compat_id, page, l); 1155 + desc->ext_compat_id[l] = '\0'; 1156 + 1157 + if (desc->opts_mutex) 1158 + mutex_unlock(desc->opts_mutex); 1159 + 1160 + return len; 1161 + } 1162 + 1163 + static struct usb_os_desc_attribute rndis_grp_attr_compatible_id = 1164 + __CONFIGFS_ATTR(compatible_id, S_IRUGO | S_IWUSR, 1165 + rndis_grp_compatible_id_show, 1166 + rndis_grp_compatible_id_store); 1167 + 1168 + static ssize_t rndis_grp_sub_compatible_id_show(struct usb_os_desc *desc, 1169 + char *page) 1170 + { 1171 + memcpy(page, desc->ext_compat_id + 8, 8); 1172 + return 8; 1173 + } 1174 + 1175 + static ssize_t rndis_grp_sub_compatible_id_store(struct usb_os_desc *desc, 1176 + const char *page, size_t len) 1177 + { 1178 + int l; 1179 + 1180 + l = min_t(int, 8, len); 1181 + if (page[l - 1] == '\n') 1182 + --l; 1183 + if (desc->opts_mutex) 1184 + mutex_lock(desc->opts_mutex); 1185 + memcpy(desc->ext_compat_id + 8, page, l); 1186 + desc->ext_compat_id[l + 8] = '\0'; 1187 + 1188 + if (desc->opts_mutex) 1189 + mutex_unlock(desc->opts_mutex); 1190 + 1191 + return len; 1192 + } 1193 + 1194 + static struct usb_os_desc_attribute rndis_grp_attr_sub_compatible_id = 1195 + __CONFIGFS_ATTR(sub_compatible_id, S_IRUGO | S_IWUSR, 1196 + rndis_grp_sub_compatible_id_show, 1197 + rndis_grp_sub_compatible_id_store); 1198 + 1199 + static struct configfs_attribute *interf_grp_attrs[] = { 1200 + &rndis_grp_attr_compatible_id.attr, 1201 + &rndis_grp_attr_sub_compatible_id.attr, 1202 + NULL 1203 + }; 1204 + 1205 + int usb_os_desc_prepare_interf_dir(struct config_group *parent, 1206 + int n_interf, 1207 + struct usb_os_desc **desc, 1208 + struct module *owner) 1209 + { 1210 + struct config_group **f_default_groups, *os_desc_group, 1211 + **interface_groups; 1212 + struct config_item_type *os_desc_type, *interface_type; 1213 + 1214 + vla_group(data_chunk); 1215 + vla_item(data_chunk, struct config_group *, f_default_groups, 2); 1216 + vla_item(data_chunk, struct config_group, os_desc_group, 1); 1217 + vla_item(data_chunk, struct config_group *, interface_groups, 1218 + n_interf + 1); 1219 + vla_item(data_chunk, struct config_item_type, os_desc_type, 1); 1220 + vla_item(data_chunk, struct config_item_type, interface_type, 1); 1221 + 1222 + char *vlabuf = kzalloc(vla_group_size(data_chunk), GFP_KERNEL); 1223 + if (!vlabuf) 1224 + return -ENOMEM; 1225 + 1226 + f_default_groups = vla_ptr(vlabuf, data_chunk, f_default_groups); 1227 + os_desc_group = vla_ptr(vlabuf, data_chunk, os_desc_group); 1228 + os_desc_type = vla_ptr(vlabuf, data_chunk, os_desc_type); 1229 + interface_groups = vla_ptr(vlabuf, data_chunk, interface_groups); 1230 + interface_type = vla_ptr(vlabuf, data_chunk, interface_type); 1231 + 1232 + parent->default_groups = f_default_groups; 1233 + os_desc_type->ct_owner = owner; 1234 + config_group_init_type_name(os_desc_group, "os_desc", os_desc_type); 1235 + f_default_groups[0] = os_desc_group; 1236 + 1237 + os_desc_group->default_groups = interface_groups; 1238 + interface_type->ct_item_ops = &interf_item_ops; 1239 + interface_type->ct_group_ops = &interf_grp_ops; 1240 + interface_type->ct_attrs = interf_grp_attrs; 1241 + interface_type->ct_owner = owner; 1242 + 1243 + while (n_interf--) { 1244 + struct usb_os_desc *d; 1245 + 1246 + d = desc[n_interf]; 1247 + d->owner = owner; 1248 + config_group_init_type_name(&d->group, "", interface_type); 1249 + config_item_set_name(&d->group.cg_item, "interface.%d", 1250 + n_interf); 1251 + interface_groups[n_interf] = &d->group; 1252 + } 1253 + 1254 + return 0; 1255 + } 1256 + EXPORT_SYMBOL(usb_os_desc_prepare_interf_dir); 1257 + 750 1258 static int configfs_do_nothing(struct usb_composite_dev *cdev) 751 1259 { 752 1260 WARN_ON(1); ··· 1274 744 1275 745 int composite_dev_prepare(struct usb_composite_driver *composite, 1276 746 struct usb_composite_dev *dev); 747 + 748 + int composite_os_desc_req_prepare(struct usb_composite_dev *cdev, 749 + struct usb_ep *ep0); 1277 750 1278 751 static void purge_configs_funcs(struct gadget_info *gi) 1279 752 { ··· 1326 793 ret = -EINVAL; 1327 794 1328 795 if (list_empty(&gi->cdev.configs)) { 1329 - pr_err("Need atleast one configuration in %s.\n", 796 + pr_err("Need at least one configuration in %s.\n", 1330 797 gi->composite.name); 1331 798 goto err_comp_cleanup; 1332 799 } ··· 1337 804 1338 805 cfg = container_of(c, struct config_usb_cfg, c); 1339 806 if (list_empty(&cfg->func_list)) { 1340 - pr_err("Config %s/%d of %s needs atleast one function.\n", 807 + pr_err("Config %s/%d of %s needs at least one function.\n", 1341 808 c->label, c->bConfigurationValue, 1342 809 gi->composite.name); 1343 810 goto err_comp_cleanup; ··· 1370 837 gi->cdev.desc.iManufacturer = s[USB_GADGET_MANUFACTURER_IDX].id; 1371 838 gi->cdev.desc.iProduct = s[USB_GADGET_PRODUCT_IDX].id; 1372 839 gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id; 840 + } 841 + 842 + if (gi->use_os_desc) { 843 + cdev->use_os_string = true; 844 + cdev->b_vendor_code = gi->b_vendor_code; 845 + memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN); 1373 846 } 1374 847 1375 848 /* Go through all configs, attach all functions */ ··· 1413 874 } 1414 875 usb_ep_autoconfig_reset(cdev->gadget); 1415 876 } 877 + if (cdev->use_os_string) { 878 + ret = composite_os_desc_req_prepare(cdev, gadget->ep0); 879 + if (ret) 880 + goto err_purge_funcs; 881 + } 882 + 1416 883 usb_ep_autoconfig_reset(cdev->gadget); 1417 884 return 0; 1418 885 ··· 1474 929 gi->group.default_groups[0] = &gi->functions_group; 1475 930 gi->group.default_groups[1] = &gi->configs_group; 1476 931 gi->group.default_groups[2] = &gi->strings_group; 932 + gi->group.default_groups[3] = &gi->os_desc_group; 1477 933 1478 934 config_group_init_type_name(&gi->functions_group, "functions", 1479 935 &functions_type); ··· 1482 936 &config_desc_type); 1483 937 config_group_init_type_name(&gi->strings_group, "strings", 1484 938 &gadget_strings_strings_type); 939 + config_group_init_type_name(&gi->os_desc_group, "os_desc", 940 + &os_desc_type); 1485 941 1486 942 gi->composite.bind = configfs_do_nothing; 1487 943 gi->composite.unbind = configfs_do_nothing; ··· 1553 1005 1554 1006 unregister_gadget(gi); 1555 1007 } 1556 - EXPORT_SYMBOL(unregister_gadget_item); 1008 + EXPORT_SYMBOL_GPL(unregister_gadget_item); 1557 1009 1558 1010 static int __init gadget_cfs_init(void) 1559 1011 {
+12
drivers/usb/gadget/configfs.h
··· 1 1 #ifndef USB__GADGET__CONFIGFS__H 2 2 #define USB__GADGET__CONFIGFS__H 3 3 4 + #include <linux/configfs.h> 5 + 4 6 void unregister_gadget_item(struct config_item *item); 7 + 8 + int usb_os_desc_prepare_interf_dir(struct config_group *parent, 9 + int n_interf, 10 + struct usb_os_desc **desc, 11 + struct module *owner); 12 + 13 + static inline struct usb_os_desc *to_usb_os_desc(struct config_item *item) 14 + { 15 + return container_of(to_config_group(item), struct usb_os_desc, group); 16 + } 5 17 6 18 #endif /* USB__GADGET__CONFIGFS__H */
+4 -29
drivers/usb/gadget/f_fs.c
··· 33 33 #include <linux/poll.h> 34 34 35 35 #include "u_fs.h" 36 + #include "u_f.h" 36 37 #include "configfs.h" 37 38 38 39 #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ 39 - 40 - /* Variable Length Array Macros **********************************************/ 41 - #define vla_group(groupname) size_t groupname##__next = 0 42 - #define vla_group_size(groupname) groupname##__next 43 - 44 - #define vla_item(groupname, type, name, n) \ 45 - size_t groupname##_##name##__offset = ({ \ 46 - size_t align_mask = __alignof__(type) - 1; \ 47 - size_t offset = (groupname##__next + align_mask) & ~align_mask;\ 48 - size_t size = (n) * sizeof(type); \ 49 - groupname##__next = offset + size; \ 50 - offset; \ 51 - }) 52 - 53 - #define vla_item_with_sz(groupname, type, name, n) \ 54 - size_t groupname##_##name##__sz = (n) * sizeof(type); \ 55 - size_t groupname##_##name##__offset = ({ \ 56 - size_t align_mask = __alignof__(type) - 1; \ 57 - size_t offset = (groupname##__next + align_mask) & ~align_mask;\ 58 - size_t size = groupname##_##name##__sz; \ 59 - groupname##__next = offset + size; \ 60 - offset; \ 61 - }) 62 - 63 - #define vla_ptr(ptr, groupname, name) \ 64 - ((void *) ((char *)ptr + groupname##_##name##__offset)) 65 40 66 41 /* Reference counter handling */ 67 42 static void ffs_data_get(struct ffs_data *ffs); ··· 165 190 /* Devices management *******************************************************/ 166 191 167 192 DEFINE_MUTEX(ffs_lock); 168 - EXPORT_SYMBOL(ffs_lock); 193 + EXPORT_SYMBOL_GPL(ffs_lock); 169 194 170 195 static struct ffs_dev *_ffs_find_dev(const char *name); 171 196 static struct ffs_dev *_ffs_alloc_dev(void); ··· 2858 2883 2859 2884 return ret; 2860 2885 } 2861 - EXPORT_SYMBOL(ffs_name_dev); 2886 + EXPORT_SYMBOL_GPL(ffs_name_dev); 2862 2887 2863 2888 int ffs_single_dev(struct ffs_dev *dev) 2864 2889 { ··· 2875 2900 ffs_dev_unlock(); 2876 2901 return ret; 2877 2902 } 2878 - EXPORT_SYMBOL(ffs_single_dev); 2903 + EXPORT_SYMBOL_GPL(ffs_single_dev); 2879 2904 2880 2905 /* 2881 2906 * ffs_lock must be taken by the caller of this function
+29 -4
drivers/usb/gadget/f_rndis.c
··· 27 27 #include "u_ether_configfs.h" 28 28 #include "u_rndis.h" 29 29 #include "rndis.h" 30 + #include "configfs.h" 30 31 31 32 /* 32 33 * This function is an RNDIS Ethernet port -- a Microsoft protocol that's ··· 683 682 684 683 rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst); 685 684 685 + if (cdev->use_os_string) { 686 + f->os_desc_table = kzalloc(sizeof(*f->os_desc_table), 687 + GFP_KERNEL); 688 + if (!f->os_desc_table) 689 + return PTR_ERR(f->os_desc_table); 690 + f->os_desc_n = 1; 691 + f->os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc; 692 + } 693 + 686 694 /* 687 695 * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 688 696 * configurations are bound in sequence with list_for_each_entry, ··· 703 693 gether_set_gadget(rndis_opts->net, cdev->gadget); 704 694 status = gether_register_netdev(rndis_opts->net); 705 695 if (status) 706 - return status; 696 + goto fail; 707 697 rndis_opts->bound = true; 708 698 } 709 699 710 700 us = usb_gstrings_attach(cdev, rndis_strings, 711 701 ARRAY_SIZE(rndis_string_defs)); 712 - if (IS_ERR(us)) 713 - return PTR_ERR(us); 702 + if (IS_ERR(us)) { 703 + status = PTR_ERR(us); 704 + goto fail; 705 + } 714 706 rndis_control_intf.iInterface = us[0].id; 715 707 rndis_data_intf.iInterface = us[1].id; 716 708 rndis_iad_descriptor.iFunction = us[2].id; ··· 814 802 return 0; 815 803 816 804 fail: 805 + kfree(f->os_desc_table); 806 + f->os_desc_n = 0; 817 807 usb_free_all_descriptors(f); 818 808 819 809 if (rndis->notify_req) { ··· 848 834 opts->borrowed_net = opts->bound = true; 849 835 opts->net = net; 850 836 } 851 - EXPORT_SYMBOL(rndis_borrow_net); 837 + EXPORT_SYMBOL_GPL(rndis_borrow_net); 852 838 853 839 static inline struct f_rndis_opts *to_f_rndis_opts(struct config_item *item) 854 840 { ··· 896 882 else 897 883 free_netdev(opts->net); 898 884 } 885 + 886 + kfree(opts->rndis_os_desc.group.default_groups); /* single VLA chunk */ 899 887 kfree(opts); 900 888 } 901 889 902 890 static struct usb_function_instance *rndis_alloc_inst(void) 903 891 { 904 892 struct f_rndis_opts *opts; 893 + struct usb_os_desc *descs[1]; 905 894 906 895 opts = kzalloc(sizeof(*opts), GFP_KERNEL); 907 896 if (!opts) 908 897 return ERR_PTR(-ENOMEM); 898 + opts->rndis_os_desc.ext_compat_id = opts->rndis_ext_compat_id; 899 + 909 900 mutex_init(&opts->lock); 910 901 opts->func_inst.free_func_inst = rndis_free_inst; 911 902 opts->net = gether_setup_default(); ··· 919 900 kfree(opts); 920 901 return ERR_CAST(net); 921 902 } 903 + INIT_LIST_HEAD(&opts->rndis_os_desc.ext_prop); 922 904 905 + descs[0] = &opts->rndis_os_desc; 906 + usb_os_desc_prepare_interf_dir(&opts->func_inst.group, 1, descs, 907 + THIS_MODULE); 923 908 config_group_init_type_name(&opts->func_inst.group, "", 924 909 &rndis_func_type); 925 910 ··· 948 925 { 949 926 struct f_rndis *rndis = func_to_rndis(f); 950 927 928 + kfree(f->os_desc_table); 929 + f->os_desc_n = 0; 951 930 usb_free_all_descriptors(f); 952 931 953 932 kfree(rndis->notify_req->buf);
+1 -1
drivers/usb/gadget/f_subset.c
··· 276 276 } 277 277 278 278 net = gether_connect(&geth->port); 279 - return PTR_RET(net); 279 + return PTR_ERR_OR_ZERO(net); 280 280 } 281 281 282 282 static void geth_disable(struct usb_function *f)
+2 -8
drivers/usb/gadget/f_uac2.c
··· 196 196 struct snd_uac2_chip *uac2 = prm->uac2; 197 197 198 198 /* i/f shutting down */ 199 - if (!prm->ep_enabled) 199 + if (!prm->ep_enabled || req->status == -ESHUTDOWN) 200 200 return; 201 201 202 202 /* ··· 974 974 prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL); 975 975 if (!prm->rbuf) { 976 976 prm->max_psize = 0; 977 - dev_err(&uac2->pdev.dev, 978 - "%s:%d Error!\n", __func__, __LINE__); 979 977 goto err; 980 978 } 981 979 ··· 982 984 prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL); 983 985 if (!prm->rbuf) { 984 986 prm->max_psize = 0; 985 - dev_err(&uac2->pdev.dev, 986 - "%s:%d Error!\n", __func__, __LINE__); 987 987 goto err; 988 988 } 989 989 ··· 1294 1298 int res; 1295 1299 1296 1300 agdev_g = kzalloc(sizeof *agdev_g, GFP_KERNEL); 1297 - if (agdev_g == NULL) { 1298 - printk(KERN_ERR "Unable to allocate audio gadget\n"); 1301 + if (agdev_g == NULL) 1299 1302 return -ENOMEM; 1300 - } 1301 1303 1302 1304 res = usb_string_ids_tab(cfg->cdev, strings_fn); 1303 1305 if (res)
+2 -6
drivers/usb/gadget/fotg210-udc.c
··· 1112 1112 1113 1113 /* initialize udc */ 1114 1114 fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL); 1115 - if (fotg210 == NULL) { 1116 - pr_err("kzalloc error\n"); 1115 + if (fotg210 == NULL) 1117 1116 goto err_alloc; 1118 - } 1119 1117 1120 1118 for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { 1121 1119 _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL); 1122 - if (_ep[i] == NULL) { 1123 - pr_err("_ep kzalloc error\n"); 1120 + if (_ep[i] == NULL) 1124 1121 goto err_alloc; 1125 - } 1126 1122 fotg210->ep[i] = _ep[i]; 1127 1123 } 1128 1124
+2 -6
drivers/usb/gadget/fsl_udc_core.c
··· 2256 2256 udc->phy_mode = pdata->phy_mode; 2257 2257 2258 2258 udc->eps = kzalloc(sizeof(struct fsl_ep) * udc->max_ep, GFP_KERNEL); 2259 - if (!udc->eps) { 2260 - ERR("malloc fsl_ep failed\n"); 2259 + if (!udc->eps) 2261 2260 return -1; 2262 - } 2263 2261 2264 2262 /* initialized QHs, take care of alignment */ 2265 2263 size = udc->max_ep * sizeof(struct ep_queue_head); ··· 2340 2342 u32 dccparams; 2341 2343 2342 2344 udc_controller = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL); 2343 - if (udc_controller == NULL) { 2344 - ERR("malloc udc failed\n"); 2345 + if (udc_controller == NULL) 2345 2346 return -ENOMEM; 2346 - } 2347 2347 2348 2348 pdata = dev_get_platdata(&pdev->dev); 2349 2349 udc_controller->pdata = pdata;
+2 -6
drivers/usb/gadget/fusb300_udc.c
··· 1400 1400 1401 1401 /* initialize udc */ 1402 1402 fusb300 = kzalloc(sizeof(struct fusb300), GFP_KERNEL); 1403 - if (fusb300 == NULL) { 1404 - pr_err("kzalloc error\n"); 1403 + if (fusb300 == NULL) 1405 1404 goto clean_up; 1406 - } 1407 1405 1408 1406 for (i = 0; i < FUSB300_MAX_NUM_EP; i++) { 1409 1407 _ep[i] = kzalloc(sizeof(struct fusb300_ep), GFP_KERNEL); 1410 - if (_ep[i] == NULL) { 1411 - pr_err("_ep kzalloc error\n"); 1408 + if (_ep[i] == NULL) 1412 1409 goto clean_up; 1413 - } 1414 1410 fusb300->ep[i] = _ep[i]; 1415 1411 } 1416 1412
+29 -26
drivers/usb/gadget/gr_udc.c
··· 143 143 seq_printf(seq, " wedged = %d\n", ep->wedged); 144 144 seq_printf(seq, " callback = %d\n", ep->callback); 145 145 seq_printf(seq, " maxpacket = %d\n", ep->ep.maxpacket); 146 + seq_printf(seq, " maxpacket_limit = %d\n", ep->ep.maxpacket_limit); 146 147 seq_printf(seq, " bytes_per_buffer = %d\n", ep->bytes_per_buffer); 147 148 if (mode == 1 || mode == 3) 148 149 seq_printf(seq, " nt = %d\n", ··· 1542 1541 } else if (max == 0) { 1543 1542 dev_err(dev->dev, "Max payload cannot be set to 0\n"); 1544 1543 return -EINVAL; 1544 + } else if (max > ep->ep.maxpacket_limit) { 1545 + dev_err(dev->dev, "Requested max payload %d > limit %d\n", 1546 + max, ep->ep.maxpacket_limit); 1547 + return -EINVAL; 1545 1548 } 1546 1549 1547 1550 spin_lock(&ep->dev->lock); ··· 1684 1679 if (ep->is_in) 1685 1680 gr_dbgprint_request("EXTERN", ep, req); 1686 1681 1687 - ret = gr_queue(ep, req, gfp_flags); 1682 + ret = gr_queue(ep, req, GFP_ATOMIC); 1688 1683 1689 1684 spin_unlock(&ep->dev->lock); 1690 1685 ··· 1990 1985 INIT_LIST_HEAD(&ep->queue); 1991 1986 1992 1987 if (num == 0) { 1993 - _req = gr_alloc_request(&ep->ep, GFP_KERNEL); 1994 - buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_KERNEL); 1988 + _req = gr_alloc_request(&ep->ep, GFP_ATOMIC); 1989 + buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_ATOMIC); 1995 1990 if (!_req || !buf) { 1996 1991 /* possible _req freed by gr_probe via gr_remove */ 1997 1992 return -ENOMEM; ··· 2025 2020 u32 dmactrl_val; 2026 2021 int i; 2027 2022 int ret = 0; 2028 - u32 *bufsizes; 2029 2023 u32 bufsize; 2030 - int len; 2031 2024 2032 2025 gr_set_address(dev, 0); 2033 2026 ··· 2036 2033 INIT_LIST_HEAD(&dev->ep_list); 2037 2034 gr_set_ep0state(dev, GR_EP0_DISCONNECT); 2038 2035 2039 - bufsizes = (u32 *)of_get_property(np, "epobufsizes", &len); 2040 - len /= sizeof(u32); 2041 2036 for (i = 0; i < dev->nepo; i++) { 2042 - bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; 2037 + if (of_property_read_u32_index(np, "epobufsizes", i, &bufsize)) 2038 + bufsize = 1024; 2043 2039 ret = gr_ep_init(dev, i, 0, bufsize); 2044 2040 if (ret) 2045 2041 return ret; 2046 2042 } 2047 2043 2048 - bufsizes = (u32 *)of_get_property(np, "epibufsizes", &len); 2049 - len /= sizeof(u32); 2050 2044 for (i = 0; i < dev->nepi; i++) { 2051 - bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; 2045 + if (of_property_read_u32_index(np, "epibufsizes", i, &bufsize)) 2046 + bufsize = 1024; 2052 2047 ret = gr_ep_init(dev, i, 1, bufsize); 2053 2048 if (ret) 2054 2049 return ret; ··· 2066 2065 return 0; 2067 2066 } 2068 2067 2069 - static int gr_remove(struct platform_device *ofdev) 2068 + static int gr_remove(struct platform_device *pdev) 2070 2069 { 2071 - struct gr_udc *dev = dev_get_drvdata(&ofdev->dev); 2070 + struct gr_udc *dev = platform_get_drvdata(pdev); 2072 2071 2073 2072 if (dev->added) 2074 2073 usb_del_gadget_udc(&dev->gadget); /* Shuts everything down */ ··· 2078 2077 gr_dfs_delete(dev); 2079 2078 if (dev->desc_pool) 2080 2079 dma_pool_destroy(dev->desc_pool); 2081 - dev_set_drvdata(&ofdev->dev, NULL); 2080 + platform_set_drvdata(pdev, NULL); 2082 2081 2083 2082 gr_free_request(&dev->epi[0].ep, &dev->ep0reqi->req); 2084 2083 gr_free_request(&dev->epo[0].ep, &dev->ep0reqo->req); ··· 2091 2090 IRQF_SHARED, driver_name, dev); 2092 2091 } 2093 2092 2094 - static int gr_probe(struct platform_device *ofdev) 2093 + static int gr_probe(struct platform_device *pdev) 2095 2094 { 2096 2095 struct gr_udc *dev; 2097 2096 struct resource *res; ··· 2099 2098 int retval; 2100 2099 u32 status; 2101 2100 2102 - dev = devm_kzalloc(&ofdev->dev, sizeof(*dev), GFP_KERNEL); 2101 + dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 2103 2102 if (!dev) 2104 2103 return -ENOMEM; 2105 - dev->dev = &ofdev->dev; 2104 + dev->dev = &pdev->dev; 2106 2105 2107 - res = platform_get_resource(ofdev, IORESOURCE_MEM, 0); 2106 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2108 2107 regs = devm_ioremap_resource(dev->dev, res); 2109 2108 if (IS_ERR(regs)) 2110 2109 return PTR_ERR(regs); 2111 2110 2112 - dev->irq = irq_of_parse_and_map(dev->dev->of_node, 0); 2113 - if (!dev->irq) { 2111 + dev->irq = platform_get_irq(pdev, 0); 2112 + if (dev->irq <= 0) { 2114 2113 dev_err(dev->dev, "No irq found\n"); 2115 2114 return -ENODEV; 2116 2115 } 2117 2116 2118 2117 /* Some core configurations has separate irqs for IN and OUT events */ 2119 - dev->irqi = irq_of_parse_and_map(dev->dev->of_node, 1); 2120 - if (dev->irqi) { 2121 - dev->irqo = irq_of_parse_and_map(dev->dev->of_node, 2); 2122 - if (!dev->irqo) { 2118 + dev->irqi = platform_get_irq(pdev, 1); 2119 + if (dev->irqi > 0) { 2120 + dev->irqo = platform_get_irq(pdev, 2); 2121 + if (dev->irqo <= 0) { 2123 2122 dev_err(dev->dev, "Found irqi but not irqo\n"); 2124 2123 return -ENODEV; 2125 2124 } 2125 + } else { 2126 + dev->irqi = 0; 2126 2127 } 2127 2128 2128 2129 dev->gadget.name = driver_name; ··· 2135 2132 spin_lock_init(&dev->lock); 2136 2133 dev->regs = regs; 2137 2134 2138 - dev_set_drvdata(&ofdev->dev, dev); 2135 + platform_set_drvdata(pdev, dev); 2139 2136 2140 2137 /* Determine number of endpoints and data interface mode */ 2141 2138 status = gr_read32(&dev->regs->status); ··· 2207 2204 spin_unlock(&dev->lock); 2208 2205 2209 2206 if (retval) 2210 - gr_remove(ofdev); 2207 + gr_remove(pdev); 2211 2208 2212 2209 return retval; 2213 2210 }
+1
drivers/usb/gadget/inode.c
··· 1494 1494 */ 1495 1495 if (value == 0) { 1496 1496 INFO (dev, "configuration #%d\n", dev->current_config); 1497 + usb_gadget_set_state(gadget, USB_STATE_CONFIGURED); 1497 1498 if (dev->usermode_setup) { 1498 1499 dev->setup_can_stall = 0; 1499 1500 goto delegate;
-1
drivers/usb/gadget/m66592-udc.c
··· 1594 1594 m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL); 1595 1595 if (m66592 == NULL) { 1596 1596 ret = -ENOMEM; 1597 - pr_err("kzalloc error\n"); 1598 1597 goto clean_up; 1599 1598 } 1600 1599
+2 -12
drivers/usb/gadget/mv_u3d_core.c
··· 297 297 u3d = req->ep->u3d; 298 298 299 299 trb = kzalloc(sizeof(*trb), GFP_ATOMIC); 300 - if (!trb) { 301 - dev_err(u3d->dev, "%s, trb alloc fail\n", __func__); 300 + if (!trb) 302 301 return NULL; 303 - } 304 302 305 303 /* 306 304 * Be careful that no _GFP_HIGHMEM is set, ··· 444 446 trb_num++; 445 447 446 448 trb = kcalloc(trb_num, sizeof(*trb), GFP_ATOMIC); 447 - if (!trb) { 448 - dev_err(u3d->dev, 449 - "%s, trb alloc fail\n", __func__); 449 + if (!trb) 450 450 return -ENOMEM; 451 - } 452 451 453 452 trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC); 454 453 if (!trb_hw) { 455 454 kfree(trb); 456 - dev_err(u3d->dev, 457 - "%s, trb_hw alloc fail\n", __func__); 458 455 return -ENOMEM; 459 456 } 460 457 ··· 1804 1811 1805 1812 u3d = kzalloc(sizeof(*u3d), GFP_KERNEL); 1806 1813 if (!u3d) { 1807 - dev_err(&dev->dev, "failed to allocate memory for u3d\n"); 1808 1814 retval = -ENOMEM; 1809 1815 goto err_alloc_private; 1810 1816 } ··· 1897 1905 size = u3d->max_eps * sizeof(struct mv_u3d_ep) * 2; 1898 1906 u3d->eps = kzalloc(size, GFP_KERNEL); 1899 1907 if (!u3d->eps) { 1900 - dev_err(&dev->dev, "allocate ep memory failed\n"); 1901 1908 retval = -ENOMEM; 1902 1909 goto err_alloc_eps; 1903 1910 } ··· 1904 1913 /* initialize ep0 status request structure */ 1905 1914 u3d->status_req = kzalloc(sizeof(struct mv_u3d_req) + 8, GFP_KERNEL); 1906 1915 if (!u3d->status_req) { 1907 - dev_err(&dev->dev, "allocate status_req memory failed\n"); 1908 1916 retval = -ENOMEM; 1909 1917 goto err_alloc_status_req; 1910 1918 }
+3 -1
drivers/usb/gadget/net2280.c
··· 1972 1972 device_remove_file (&dev->pdev->dev, &dev_attr_function); 1973 1973 device_remove_file (&dev->pdev->dev, &dev_attr_queues); 1974 1974 1975 - DEBUG (dev, "unregistered driver '%s'\n", driver->driver.name); 1975 + DEBUG(dev, "unregistered driver '%s'\n", 1976 + driver ? driver->driver.name : ""); 1977 + 1976 1978 return 0; 1977 1979 } 1978 1980
-1
drivers/usb/gadget/r8a66597-udc.c
··· 1904 1904 r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL); 1905 1905 if (r8a66597 == NULL) { 1906 1906 ret = -ENOMEM; 1907 - dev_err(&pdev->dev, "kzalloc error\n"); 1908 1907 goto clean_up; 1909 1908 } 1910 1909
+14 -14
drivers/usb/gadget/rndis.c
··· 761 761 return rndis_indicate_status_msg(configNr, 762 762 RNDIS_STATUS_MEDIA_CONNECT); 763 763 } 764 - EXPORT_SYMBOL(rndis_signal_connect); 764 + EXPORT_SYMBOL_GPL(rndis_signal_connect); 765 765 766 766 int rndis_signal_disconnect(int configNr) 767 767 { ··· 770 770 return rndis_indicate_status_msg(configNr, 771 771 RNDIS_STATUS_MEDIA_DISCONNECT); 772 772 } 773 - EXPORT_SYMBOL(rndis_signal_disconnect); 773 + EXPORT_SYMBOL_GPL(rndis_signal_disconnect); 774 774 775 775 void rndis_uninit(int configNr) 776 776 { ··· 785 785 while ((buf = rndis_get_next_response(configNr, &length))) 786 786 rndis_free_response(configNr, buf); 787 787 } 788 - EXPORT_SYMBOL(rndis_uninit); 788 + EXPORT_SYMBOL_GPL(rndis_uninit); 789 789 790 790 void rndis_set_host_mac(int configNr, const u8 *addr) 791 791 { 792 792 rndis_per_dev_params[configNr].host_mac = addr; 793 793 } 794 - EXPORT_SYMBOL(rndis_set_host_mac); 794 + EXPORT_SYMBOL_GPL(rndis_set_host_mac); 795 795 796 796 /* 797 797 * Message Parser ··· 874 874 875 875 return -ENOTSUPP; 876 876 } 877 - EXPORT_SYMBOL(rndis_msg_parser); 877 + EXPORT_SYMBOL_GPL(rndis_msg_parser); 878 878 879 879 int rndis_register(void (*resp_avail)(void *v), void *v) 880 880 { ··· 896 896 897 897 return -ENODEV; 898 898 } 899 - EXPORT_SYMBOL(rndis_register); 899 + EXPORT_SYMBOL_GPL(rndis_register); 900 900 901 901 void rndis_deregister(int configNr) 902 902 { ··· 905 905 if (configNr >= RNDIS_MAX_CONFIGS) return; 906 906 rndis_per_dev_params[configNr].used = 0; 907 907 } 908 - EXPORT_SYMBOL(rndis_deregister); 908 + EXPORT_SYMBOL_GPL(rndis_deregister); 909 909 910 910 int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) 911 911 { ··· 919 919 920 920 return 0; 921 921 } 922 - EXPORT_SYMBOL(rndis_set_param_dev); 922 + EXPORT_SYMBOL_GPL(rndis_set_param_dev); 923 923 924 924 int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr) 925 925 { ··· 932 932 933 933 return 0; 934 934 } 935 - EXPORT_SYMBOL(rndis_set_param_vendor); 935 + EXPORT_SYMBOL_GPL(rndis_set_param_vendor); 936 936 937 937 int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed) 938 938 { ··· 944 944 945 945 return 0; 946 946 } 947 - EXPORT_SYMBOL(rndis_set_param_medium); 947 + EXPORT_SYMBOL_GPL(rndis_set_param_medium); 948 948 949 949 void rndis_add_hdr(struct sk_buff *skb) 950 950 { ··· 959 959 header->DataOffset = cpu_to_le32(36); 960 960 header->DataLength = cpu_to_le32(skb->len - sizeof(*header)); 961 961 } 962 - EXPORT_SYMBOL(rndis_add_hdr); 962 + EXPORT_SYMBOL_GPL(rndis_add_hdr); 963 963 964 964 void rndis_free_response(int configNr, u8 *buf) 965 965 { ··· 976 976 } 977 977 } 978 978 } 979 - EXPORT_SYMBOL(rndis_free_response); 979 + EXPORT_SYMBOL_GPL(rndis_free_response); 980 980 981 981 u8 *rndis_get_next_response(int configNr, u32 *length) 982 982 { ··· 998 998 999 999 return NULL; 1000 1000 } 1001 - EXPORT_SYMBOL(rndis_get_next_response); 1001 + EXPORT_SYMBOL_GPL(rndis_get_next_response); 1002 1002 1003 1003 static rndis_resp_t *rndis_add_response(int configNr, u32 length) 1004 1004 { ··· 1042 1042 skb_queue_tail(list, skb); 1043 1043 return 0; 1044 1044 } 1045 - EXPORT_SYMBOL(rndis_rm_hdr); 1045 + EXPORT_SYMBOL_GPL(rndis_rm_hdr); 1046 1046 1047 1047 #ifdef CONFIG_USB_GADGET_DEBUG_FILES 1048 1048
+2 -1
drivers/usb/gadget/s3c2410_udc.c
··· 117 117 sizeof(printk_buf)-len, fmt, args); 118 118 va_end(args); 119 119 120 - return pr_debug("%s", printk_buf); 120 + pr_debug("%s", printk_buf); 121 + return len; 121 122 } 122 123 #else 123 124 static int dprintk(int level, const char *fmt, ...)
+26 -26
drivers/usb/gadget/storage_common.c
··· 43 43 .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ 44 44 .iInterface = FSG_STRING_INTERFACE, 45 45 }; 46 - EXPORT_SYMBOL(fsg_intf_desc); 46 + EXPORT_SYMBOL_GPL(fsg_intf_desc); 47 47 48 48 /* 49 49 * Three full-speed endpoint descriptors: bulk-in, bulk-out, and ··· 58 58 .bmAttributes = USB_ENDPOINT_XFER_BULK, 59 59 /* wMaxPacketSize set by autoconfiguration */ 60 60 }; 61 - EXPORT_SYMBOL(fsg_fs_bulk_in_desc); 61 + EXPORT_SYMBOL_GPL(fsg_fs_bulk_in_desc); 62 62 63 63 struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = { 64 64 .bLength = USB_DT_ENDPOINT_SIZE, ··· 68 68 .bmAttributes = USB_ENDPOINT_XFER_BULK, 69 69 /* wMaxPacketSize set by autoconfiguration */ 70 70 }; 71 - EXPORT_SYMBOL(fsg_fs_bulk_out_desc); 71 + EXPORT_SYMBOL_GPL(fsg_fs_bulk_out_desc); 72 72 73 73 struct usb_descriptor_header *fsg_fs_function[] = { 74 74 (struct usb_descriptor_header *) &fsg_intf_desc, ··· 76 76 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, 77 77 NULL, 78 78 }; 79 - EXPORT_SYMBOL(fsg_fs_function); 79 + EXPORT_SYMBOL_GPL(fsg_fs_function); 80 80 81 81 82 82 /* ··· 95 95 .bmAttributes = USB_ENDPOINT_XFER_BULK, 96 96 .wMaxPacketSize = cpu_to_le16(512), 97 97 }; 98 - EXPORT_SYMBOL(fsg_hs_bulk_in_desc); 98 + EXPORT_SYMBOL_GPL(fsg_hs_bulk_in_desc); 99 99 100 100 struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = { 101 101 .bLength = USB_DT_ENDPOINT_SIZE, ··· 106 106 .wMaxPacketSize = cpu_to_le16(512), 107 107 .bInterval = 1, /* NAK every 1 uframe */ 108 108 }; 109 - EXPORT_SYMBOL(fsg_hs_bulk_out_desc); 109 + EXPORT_SYMBOL_GPL(fsg_hs_bulk_out_desc); 110 110 111 111 112 112 struct usb_descriptor_header *fsg_hs_function[] = { ··· 115 115 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, 116 116 NULL, 117 117 }; 118 - EXPORT_SYMBOL(fsg_hs_function); 118 + EXPORT_SYMBOL_GPL(fsg_hs_function); 119 119 120 120 struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = { 121 121 .bLength = USB_DT_ENDPOINT_SIZE, ··· 125 125 .bmAttributes = USB_ENDPOINT_XFER_BULK, 126 126 .wMaxPacketSize = cpu_to_le16(1024), 127 127 }; 128 - EXPORT_SYMBOL(fsg_ss_bulk_in_desc); 128 + EXPORT_SYMBOL_GPL(fsg_ss_bulk_in_desc); 129 129 130 130 struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { 131 131 .bLength = sizeof(fsg_ss_bulk_in_comp_desc), ··· 133 133 134 134 /*.bMaxBurst = DYNAMIC, */ 135 135 }; 136 - EXPORT_SYMBOL(fsg_ss_bulk_in_comp_desc); 136 + EXPORT_SYMBOL_GPL(fsg_ss_bulk_in_comp_desc); 137 137 138 138 struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = { 139 139 .bLength = USB_DT_ENDPOINT_SIZE, ··· 143 143 .bmAttributes = USB_ENDPOINT_XFER_BULK, 144 144 .wMaxPacketSize = cpu_to_le16(1024), 145 145 }; 146 - EXPORT_SYMBOL(fsg_ss_bulk_out_desc); 146 + EXPORT_SYMBOL_GPL(fsg_ss_bulk_out_desc); 147 147 148 148 struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { 149 149 .bLength = sizeof(fsg_ss_bulk_in_comp_desc), ··· 151 151 152 152 /*.bMaxBurst = DYNAMIC, */ 153 153 }; 154 - EXPORT_SYMBOL(fsg_ss_bulk_out_comp_desc); 154 + EXPORT_SYMBOL_GPL(fsg_ss_bulk_out_comp_desc); 155 155 156 156 struct usb_descriptor_header *fsg_ss_function[] = { 157 157 (struct usb_descriptor_header *) &fsg_intf_desc, ··· 161 161 (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, 162 162 NULL, 163 163 }; 164 - EXPORT_SYMBOL(fsg_ss_function); 164 + EXPORT_SYMBOL_GPL(fsg_ss_function); 165 165 166 166 167 167 /*-------------------------------------------------------------------------*/ ··· 179 179 curlun->filp = NULL; 180 180 } 181 181 } 182 - EXPORT_SYMBOL(fsg_lun_close); 182 + EXPORT_SYMBOL_GPL(fsg_lun_close); 183 183 184 184 int fsg_lun_open(struct fsg_lun *curlun, const char *filename) 185 185 { ··· 278 278 fput(filp); 279 279 return rc; 280 280 } 281 - EXPORT_SYMBOL(fsg_lun_open); 281 + EXPORT_SYMBOL_GPL(fsg_lun_open); 282 282 283 283 284 284 /*-------------------------------------------------------------------------*/ ··· 295 295 return 0; 296 296 return vfs_fsync(filp, 1); 297 297 } 298 - EXPORT_SYMBOL(fsg_lun_fsync_sub); 298 + EXPORT_SYMBOL_GPL(fsg_lun_fsync_sub); 299 299 300 300 void store_cdrom_address(u8 *dest, int msf, u32 addr) 301 301 { ··· 314 314 put_unaligned_be32(addr, dest); 315 315 } 316 316 } 317 - EXPORT_SYMBOL(store_cdrom_address); 317 + EXPORT_SYMBOL_GPL(store_cdrom_address); 318 318 319 319 /*-------------------------------------------------------------------------*/ 320 320 ··· 325 325 ? curlun->ro 326 326 : curlun->initially_ro); 327 327 } 328 - EXPORT_SYMBOL(fsg_show_ro); 328 + EXPORT_SYMBOL_GPL(fsg_show_ro); 329 329 330 330 ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf) 331 331 { 332 332 return sprintf(buf, "%u\n", curlun->nofua); 333 333 } 334 - EXPORT_SYMBOL(fsg_show_nofua); 334 + EXPORT_SYMBOL_GPL(fsg_show_nofua); 335 335 336 336 ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, 337 337 char *buf) ··· 357 357 up_read(filesem); 358 358 return rc; 359 359 } 360 - EXPORT_SYMBOL(fsg_show_file); 360 + EXPORT_SYMBOL_GPL(fsg_show_file); 361 361 362 362 ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf) 363 363 { 364 364 return sprintf(buf, "%u\n", curlun->cdrom); 365 365 } 366 - EXPORT_SYMBOL(fsg_show_cdrom); 366 + EXPORT_SYMBOL_GPL(fsg_show_cdrom); 367 367 368 368 ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf) 369 369 { 370 370 return sprintf(buf, "%u\n", curlun->removable); 371 371 } 372 - EXPORT_SYMBOL(fsg_show_removable); 372 + EXPORT_SYMBOL_GPL(fsg_show_removable); 373 373 374 374 /* 375 375 * The caller must hold fsg->filesem for reading when calling this function. ··· 410 410 411 411 return rc; 412 412 } 413 - EXPORT_SYMBOL(fsg_store_ro); 413 + EXPORT_SYMBOL_GPL(fsg_store_ro); 414 414 415 415 ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) 416 416 { ··· 429 429 430 430 return count; 431 431 } 432 - EXPORT_SYMBOL(fsg_store_nofua); 432 + EXPORT_SYMBOL_GPL(fsg_store_nofua); 433 433 434 434 ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, 435 435 const char *buf, size_t count) ··· 460 460 up_write(filesem); 461 461 return (rc < 0 ? rc : count); 462 462 } 463 - EXPORT_SYMBOL(fsg_store_file); 463 + EXPORT_SYMBOL_GPL(fsg_store_file); 464 464 465 465 ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, 466 466 const char *buf, size_t count) ··· 483 483 484 484 return ret; 485 485 } 486 - EXPORT_SYMBOL(fsg_store_cdrom); 486 + EXPORT_SYMBOL_GPL(fsg_store_cdrom); 487 487 488 488 ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, 489 489 size_t count) ··· 499 499 500 500 return count; 501 501 } 502 - EXPORT_SYMBOL(fsg_store_removable); 502 + EXPORT_SYMBOL_GPL(fsg_store_removable); 503 503 504 504 MODULE_LICENSE("GPL");
+4 -12
drivers/usb/gadget/tcm_usb_gadget.c
··· 1383 1383 struct usbg_nacl *nacl; 1384 1384 1385 1385 nacl = kzalloc(sizeof(struct usbg_nacl), GFP_KERNEL); 1386 - if (!nacl) { 1387 - printk(KERN_ERR "Unable to allocate struct usbg_nacl\n"); 1386 + if (!nacl) 1388 1387 return NULL; 1389 - } 1390 1388 1391 1389 return &nacl->se_node_acl; 1392 1390 } ··· 1559 1561 } 1560 1562 1561 1563 tpg = kzalloc(sizeof(struct usbg_tpg), GFP_KERNEL); 1562 - if (!tpg) { 1563 - printk(KERN_ERR "Unable to allocate struct usbg_tpg"); 1564 + if (!tpg) 1564 1565 return ERR_PTR(-ENOMEM); 1565 - } 1566 1566 mutex_init(&tpg->tpg_mutex); 1567 1567 atomic_set(&tpg->tpg_port_count, 0); 1568 1568 tpg->workqueue = alloc_workqueue("tcm_usb_gadget", 0, 1); ··· 1609 1613 return ERR_PTR(-EINVAL); 1610 1614 1611 1615 tport = kzalloc(sizeof(struct usbg_tport), GFP_KERNEL); 1612 - if (!(tport)) { 1613 - printk(KERN_ERR "Unable to allocate struct usbg_tport"); 1616 + if (!(tport)) 1614 1617 return ERR_PTR(-ENOMEM); 1615 - } 1616 1618 tport->tport_wwpn = wwpn; 1617 1619 snprintf(tport->tport_name, sizeof(tport->tport_name), "%s", wnn_name); 1618 1620 return &tport->tport_wwn; ··· 1721 1727 1722 1728 ret = -ENOMEM; 1723 1729 tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL); 1724 - if (!tv_nexus) { 1725 - pr_err("Unable to allocate struct tcm_vhost_nexus\n"); 1730 + if (!tv_nexus) 1726 1731 goto err_unlock; 1727 - } 1728 1732 tv_nexus->tvn_se_sess = transport_init_session(TARGET_PROT_NORMAL); 1729 1733 if (IS_ERR(tv_nexus->tvn_se_sess)) 1730 1734 goto err_free;
+16 -16
drivers/usb/gadget/u_ether.c
··· 818 818 819 819 return dev; 820 820 } 821 - EXPORT_SYMBOL(gether_setup_name); 821 + EXPORT_SYMBOL_GPL(gether_setup_name); 822 822 823 823 struct net_device *gether_setup_name_default(const char *netname) 824 824 { ··· 855 855 856 856 return net; 857 857 } 858 - EXPORT_SYMBOL(gether_setup_name_default); 858 + EXPORT_SYMBOL_GPL(gether_setup_name_default); 859 859 860 860 int gether_register_netdev(struct net_device *net) 861 861 { ··· 893 893 894 894 return status; 895 895 } 896 - EXPORT_SYMBOL(gether_register_netdev); 896 + EXPORT_SYMBOL_GPL(gether_register_netdev); 897 897 898 898 void gether_set_gadget(struct net_device *net, struct usb_gadget *g) 899 899 { ··· 903 903 dev->gadget = g; 904 904 SET_NETDEV_DEV(net, &g->dev); 905 905 } 906 - EXPORT_SYMBOL(gether_set_gadget); 906 + EXPORT_SYMBOL_GPL(gether_set_gadget); 907 907 908 908 int gether_set_dev_addr(struct net_device *net, const char *dev_addr) 909 909 { ··· 916 916 memcpy(dev->dev_mac, new_addr, ETH_ALEN); 917 917 return 0; 918 918 } 919 - EXPORT_SYMBOL(gether_set_dev_addr); 919 + EXPORT_SYMBOL_GPL(gether_set_dev_addr); 920 920 921 921 int gether_get_dev_addr(struct net_device *net, char *dev_addr, int len) 922 922 { ··· 925 925 dev = netdev_priv(net); 926 926 return get_ether_addr_str(dev->dev_mac, dev_addr, len); 927 927 } 928 - EXPORT_SYMBOL(gether_get_dev_addr); 928 + EXPORT_SYMBOL_GPL(gether_get_dev_addr); 929 929 930 930 int gether_set_host_addr(struct net_device *net, const char *host_addr) 931 931 { ··· 938 938 memcpy(dev->host_mac, new_addr, ETH_ALEN); 939 939 return 0; 940 940 } 941 - EXPORT_SYMBOL(gether_set_host_addr); 941 + EXPORT_SYMBOL_GPL(gether_set_host_addr); 942 942 943 943 int gether_get_host_addr(struct net_device *net, char *host_addr, int len) 944 944 { ··· 947 947 dev = netdev_priv(net); 948 948 return get_ether_addr_str(dev->host_mac, host_addr, len); 949 949 } 950 - EXPORT_SYMBOL(gether_get_host_addr); 950 + EXPORT_SYMBOL_GPL(gether_get_host_addr); 951 951 952 952 int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len) 953 953 { ··· 961 961 962 962 return strlen(host_addr); 963 963 } 964 - EXPORT_SYMBOL(gether_get_host_addr_cdc); 964 + EXPORT_SYMBOL_GPL(gether_get_host_addr_cdc); 965 965 966 966 void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN]) 967 967 { ··· 970 970 dev = netdev_priv(net); 971 971 memcpy(host_mac, dev->host_mac, ETH_ALEN); 972 972 } 973 - EXPORT_SYMBOL(gether_get_host_addr_u8); 973 + EXPORT_SYMBOL_GPL(gether_get_host_addr_u8); 974 974 975 975 void gether_set_qmult(struct net_device *net, unsigned qmult) 976 976 { ··· 979 979 dev = netdev_priv(net); 980 980 dev->qmult = qmult; 981 981 } 982 - EXPORT_SYMBOL(gether_set_qmult); 982 + EXPORT_SYMBOL_GPL(gether_set_qmult); 983 983 984 984 unsigned gether_get_qmult(struct net_device *net) 985 985 { ··· 988 988 dev = netdev_priv(net); 989 989 return dev->qmult; 990 990 } 991 - EXPORT_SYMBOL(gether_get_qmult); 991 + EXPORT_SYMBOL_GPL(gether_get_qmult); 992 992 993 993 int gether_get_ifname(struct net_device *net, char *name, int len) 994 994 { ··· 997 997 rtnl_unlock(); 998 998 return strlen(name); 999 999 } 1000 - EXPORT_SYMBOL(gether_get_ifname); 1000 + EXPORT_SYMBOL_GPL(gether_get_ifname); 1001 1001 1002 1002 /** 1003 1003 * gether_cleanup - remove Ethernet-over-USB device ··· 1014 1014 flush_work(&dev->work); 1015 1015 free_netdev(dev->net); 1016 1016 } 1017 - EXPORT_SYMBOL(gether_cleanup); 1017 + EXPORT_SYMBOL_GPL(gether_cleanup); 1018 1018 1019 1019 /** 1020 1020 * gether_connect - notify network layer that USB link is active ··· 1095 1095 return ERR_PTR(result); 1096 1096 return dev->net; 1097 1097 } 1098 - EXPORT_SYMBOL(gether_connect); 1098 + EXPORT_SYMBOL_GPL(gether_connect); 1099 1099 1100 1100 /** 1101 1101 * gether_disconnect - notify network layer that USB link is inactive ··· 1166 1166 dev->port_usb = NULL; 1167 1167 spin_unlock(&dev->lock); 1168 1168 } 1169 - EXPORT_SYMBOL(gether_disconnect); 1169 + EXPORT_SYMBOL_GPL(gether_disconnect); 1170 1170 1171 1171 MODULE_LICENSE("GPL"); 1172 1172 MODULE_AUTHOR("David Brownell");
+1 -1
drivers/usb/gadget/u_f.c
··· 29 29 } 30 30 return req; 31 31 } 32 - EXPORT_SYMBOL(alloc_ep_req); 32 + EXPORT_SYMBOL_GPL(alloc_ep_req);
+26
drivers/usb/gadget/u_f.h
··· 16 16 #ifndef __U_F_H__ 17 17 #define __U_F_H__ 18 18 19 + /* Variable Length Array Macros **********************************************/ 20 + #define vla_group(groupname) size_t groupname##__next = 0 21 + #define vla_group_size(groupname) groupname##__next 22 + 23 + #define vla_item(groupname, type, name, n) \ 24 + size_t groupname##_##name##__offset = ({ \ 25 + size_t align_mask = __alignof__(type) - 1; \ 26 + size_t offset = (groupname##__next + align_mask) & ~align_mask;\ 27 + size_t size = (n) * sizeof(type); \ 28 + groupname##__next = offset + size; \ 29 + offset; \ 30 + }) 31 + 32 + #define vla_item_with_sz(groupname, type, name, n) \ 33 + size_t groupname##_##name##__sz = (n) * sizeof(type); \ 34 + size_t groupname##_##name##__offset = ({ \ 35 + size_t align_mask = __alignof__(type) - 1; \ 36 + size_t offset = (groupname##__next + align_mask) & ~align_mask;\ 37 + size_t size = groupname##_##name##__sz; \ 38 + groupname##__next = offset + size; \ 39 + offset; \ 40 + }) 41 + 42 + #define vla_ptr(ptr, groupname, name) \ 43 + ((void *) ((char *)ptr + groupname##_##name##__offset)) 44 + 19 45 struct usb_ep; 20 46 struct usb_request; 21 47
+90
drivers/usb/gadget/u_os_desc.h
··· 1 + /* 2 + * u_os_desc.h 3 + * 4 + * Utility definitions for "OS Descriptors" support 5 + * 6 + * Copyright (c) 2014 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef __U_OS_DESC_H__ 17 + #define __U_OS_DESC_H__ 18 + 19 + #include <asm/unaligned.h> 20 + #include <linux/nls.h> 21 + 22 + #define USB_EXT_PROP_DW_SIZE 0 23 + #define USB_EXT_PROP_DW_PROPERTY_DATA_TYPE 4 24 + #define USB_EXT_PROP_W_PROPERTY_NAME_LENGTH 8 25 + #define USB_EXT_PROP_B_PROPERTY_NAME 10 26 + #define USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH 10 27 + #define USB_EXT_PROP_B_PROPERTY_DATA 14 28 + 29 + #define USB_EXT_PROP_RESERVED 0 30 + #define USB_EXT_PROP_UNICODE 1 31 + #define USB_EXT_PROP_UNICODE_ENV 2 32 + #define USB_EXT_PROP_BINARY 3 33 + #define USB_EXT_PROP_LE32 4 34 + #define USB_EXT_PROP_BE32 5 35 + #define USB_EXT_PROP_UNICODE_LINK 6 36 + #define USB_EXT_PROP_UNICODE_MULTI 7 37 + 38 + static inline void usb_ext_prop_put_size(u8 *buf, int dw_size) 39 + { 40 + put_unaligned_le32(dw_size, &buf[USB_EXT_PROP_DW_SIZE]); 41 + } 42 + 43 + static inline void usb_ext_prop_put_type(u8 *buf, int type) 44 + { 45 + put_unaligned_le32(type, &buf[USB_EXT_PROP_DW_PROPERTY_DATA_TYPE]); 46 + } 47 + 48 + static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl) 49 + { 50 + int result; 51 + 52 + put_unaligned_le16(pnl, &buf[USB_EXT_PROP_W_PROPERTY_NAME_LENGTH]); 53 + result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN, 54 + (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_NAME], pnl - 2); 55 + if (result < 0) 56 + return result; 57 + 58 + put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl]); 59 + 60 + return pnl; 61 + } 62 + 63 + static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data, 64 + int data_len) 65 + { 66 + put_unaligned_le32(data_len, 67 + &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]); 68 + memcpy(&buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl], data, data_len); 69 + } 70 + 71 + static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string, 72 + int data_len) 73 + { 74 + int result; 75 + put_unaligned_le32(data_len, 76 + &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]); 77 + 78 + result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN, 79 + (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl], 80 + data_len - 2); 81 + if (result < 0) 82 + return result; 83 + 84 + put_unaligned_le16(0, 85 + &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len]); 86 + 87 + return data_len; 88 + } 89 + 90 + #endif /* __U_OS_DESC_H__ */
+3
drivers/usb/gadget/u_rndis.h
··· 26 26 bool bound; 27 27 bool borrowed_net; 28 28 29 + struct usb_os_desc rndis_os_desc; 30 + char rndis_ext_compat_id[16]; 31 + 29 32 /* 30 33 * Read/write access to configfs attributes is handled by configfs. 31 34 *
+2
drivers/usb/gadget/udc-core.c
··· 428 428 list_for_each_entry(udc, &udc_list, list) 429 429 if (udc->driver == driver) { 430 430 usb_gadget_remove_driver(udc); 431 + usb_gadget_set_state(udc->gadget, 432 + USB_STATE_NOTATTACHED); 431 433 ret = 0; 432 434 break; 433 435 }
+5 -7
drivers/usb/gadget/uvc_queue.c
··· 20 20 #include <linux/vmalloc.h> 21 21 #include <linux/wait.h> 22 22 23 + #include <media/v4l2-common.h> 23 24 #include <media/videobuf2-vmalloc.h> 24 25 25 26 #include "uvc.h" ··· 137 136 queue->queue.buf_struct_size = sizeof(struct uvc_buffer); 138 137 queue->queue.ops = &uvc_queue_qops; 139 138 queue->queue.mem_ops = &vb2_vmalloc_memops; 139 + queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC 140 + | V4L2_BUF_FLAG_TSTAMP_SRC_EOF; 140 141 ret = vb2_queue_init(&queue->queue); 141 142 if (ret) 142 143 return ret; ··· 382 379 else 383 380 nextbuf = NULL; 384 381 385 - /* 386 - * FIXME: with videobuf2, the sequence number or timestamp fields 387 - * are valid only for video capture devices and the UVC gadget usually 388 - * is a video output device. Keeping these until the specs are clear on 389 - * this aspect. 390 - */ 382 + buf->buf.v4l2_buf.field = V4L2_FIELD_NONE; 391 383 buf->buf.v4l2_buf.sequence = queue->sequence++; 392 - do_gettimeofday(&buf->buf.v4l2_buf.timestamp); 384 + v4l2_get_timestamp(&buf->buf.v4l2_buf.timestamp); 393 385 394 386 vb2_set_plane_payload(&buf->buf, 0, buf->bytesused); 395 387 vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE);
-1
drivers/usb/host/Kconfig
··· 170 170 tristate "Support for Qualcomm QSD/MSM on-chip EHCI USB controller" 171 171 depends on ARCH_MSM 172 172 select USB_EHCI_ROOT_HUB_TT 173 - select USB_MSM_OTG 174 173 ---help--- 175 174 Enables support for the USB Host controller present on the 176 175 Qualcomm chipsets. Root Hub has inbuilt TT.
+3 -2
drivers/usb/musb/Kconfig
··· 76 76 77 77 config USB_MUSB_OMAP2PLUS 78 78 tristate "OMAP2430 and onwards" 79 - depends on ARCH_OMAP2PLUS 79 + depends on ARCH_OMAP2PLUS && USB 80 80 select GENERIC_PHY 81 81 82 82 config USB_MUSB_AM35X ··· 141 141 config USB_TI_CPPI41_DMA 142 142 bool 'TI CPPI 4.1 (AM335x)' 143 143 depends on ARCH_OMAP 144 + select TI_CPPI41 144 145 145 146 config USB_TUSB_OMAP_DMA 146 147 bool 'TUSB 6010' 147 - depends on USB_MUSB_TUSB6010 148 + depends on USB_MUSB_TUSB6010 = USB_MUSB_HDRC # both built-in or both modules 148 149 depends on ARCH_OMAP 149 150 help 150 151 Enable DMA transfers on TUSB 6010 when OMAP DMA is available.
+10 -4
drivers/usb/musb/am35x.c
··· 32 32 #include <linux/io.h> 33 33 #include <linux/platform_device.h> 34 34 #include <linux/dma-mapping.h> 35 - #include <linux/usb/usb_phy_gen_xceiv.h> 35 + #include <linux/usb/usb_phy_generic.h> 36 36 #include <linux/platform_data/usb-omap.h> 37 37 38 38 #include "musb_core.h" ··· 85 85 struct am35x_glue { 86 86 struct device *dev; 87 87 struct platform_device *musb; 88 + struct platform_device *phy; 88 89 struct clk *phy_clk; 89 90 struct clk *clk; 90 91 }; ··· 361 360 if (!rev) 362 361 return -ENODEV; 363 362 364 - usb_nop_xceiv_register(); 365 363 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 366 364 if (IS_ERR_OR_NULL(musb->xceiv)) 367 365 return -EPROBE_DEFER; ··· 402 402 data->set_phy_power(0); 403 403 404 404 usb_put_phy(musb->xceiv); 405 - usb_nop_xceiv_unregister(); 406 405 407 406 return 0; 408 407 } ··· 504 505 505 506 pdata->platform_ops = &am35x_ops; 506 507 508 + glue->phy = usb_phy_generic_register(); 509 + if (IS_ERR(glue->phy)) 510 + goto err7; 507 511 platform_set_drvdata(pdev, glue); 508 512 509 513 pinfo = am35x_dev_info; ··· 520 518 if (IS_ERR(musb)) { 521 519 ret = PTR_ERR(musb); 522 520 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); 523 - goto err7; 521 + goto err8; 524 522 } 525 523 526 524 return 0; 525 + 526 + err8: 527 + usb_phy_generic_unregister(glue->phy); 527 528 528 529 err7: 529 530 clk_disable(clk); ··· 552 547 struct am35x_glue *glue = platform_get_drvdata(pdev); 553 548 554 549 platform_device_unregister(glue->musb); 550 + usb_phy_generic_unregister(glue->phy); 555 551 clk_disable(glue->clk); 556 552 clk_disable(glue->phy_clk); 557 553 clk_put(glue->clk);
+10 -4
drivers/usb/musb/blackfin.c
··· 18 18 #include <linux/platform_device.h> 19 19 #include <linux/dma-mapping.h> 20 20 #include <linux/prefetch.h> 21 - #include <linux/usb/usb_phy_gen_xceiv.h> 21 + #include <linux/usb/usb_phy_generic.h> 22 22 23 23 #include <asm/cacheflush.h> 24 24 ··· 29 29 struct bfin_glue { 30 30 struct device *dev; 31 31 struct platform_device *musb; 32 + struct platform_device *phy; 32 33 }; 33 34 #define glue_to_musb(g) platform_get_drvdata(g->musb) 34 35 ··· 402 401 } 403 402 gpio_direction_output(musb->config->gpio_vrsel, 0); 404 403 405 - usb_nop_xceiv_register(); 406 404 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 407 405 if (IS_ERR_OR_NULL(musb->xceiv)) { 408 406 gpio_free(musb->config->gpio_vrsel); ··· 424 424 static int bfin_musb_exit(struct musb *musb) 425 425 { 426 426 gpio_free(musb->config->gpio_vrsel); 427 - 428 427 usb_put_phy(musb->xceiv); 429 - usb_nop_xceiv_unregister(); 428 + 430 429 return 0; 431 430 } 432 431 ··· 476 477 477 478 pdata->platform_ops = &bfin_ops; 478 479 480 + glue->phy = usb_phy_generic_register(); 481 + if (IS_ERR(glue->phy)) 482 + goto err2; 479 483 platform_set_drvdata(pdev, glue); 480 484 481 485 memset(musb_resources, 0x00, sizeof(*musb_resources) * ··· 516 514 return 0; 517 515 518 516 err3: 517 + usb_phy_generic_unregister(glue->phy); 518 + 519 + err2: 519 520 platform_device_put(musb); 520 521 521 522 err1: ··· 533 528 struct bfin_glue *glue = platform_get_drvdata(pdev); 534 529 535 530 platform_device_unregister(glue->musb); 531 + usb_phy_generic_unregister(glue->phy); 536 532 kfree(glue); 537 533 538 534 return 0;
+12 -4
drivers/usb/musb/da8xx.c
··· 32 32 #include <linux/io.h> 33 33 #include <linux/platform_device.h> 34 34 #include <linux/dma-mapping.h> 35 - #include <linux/usb/usb_phy_gen_xceiv.h> 35 + #include <linux/usb/usb_phy_generic.h> 36 36 37 37 #include <mach/da8xx.h> 38 38 #include <linux/platform_data/usb-davinci.h> ··· 85 85 struct da8xx_glue { 86 86 struct device *dev; 87 87 struct platform_device *musb; 88 + struct platform_device *phy; 88 89 struct clk *clk; 89 90 }; 90 91 ··· 419 418 if (!rev) 420 419 goto fail; 421 420 422 - usb_nop_xceiv_register(); 423 421 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 424 422 if (IS_ERR_OR_NULL(musb->xceiv)) { 425 423 ret = -EPROBE_DEFER; ··· 453 453 phy_off(); 454 454 455 455 usb_put_phy(musb->xceiv); 456 - usb_nop_xceiv_unregister(); 457 456 458 457 return 0; 459 458 } ··· 511 512 512 513 pdata->platform_ops = &da8xx_ops; 513 514 515 + glue->phy = usb_phy_generic_register(); 516 + if (IS_ERR(glue->phy)) { 517 + ret = PTR_ERR(glue->phy); 518 + goto err5; 519 + } 514 520 platform_set_drvdata(pdev, glue); 515 521 516 522 memset(musb_resources, 0x00, sizeof(*musb_resources) * ··· 542 538 if (IS_ERR(musb)) { 543 539 ret = PTR_ERR(musb); 544 540 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); 545 - goto err5; 541 + goto err6; 546 542 } 547 543 548 544 return 0; 545 + 546 + err6: 547 + usb_phy_generic_unregister(glue->phy); 549 548 550 549 err5: 551 550 clk_disable(clk); ··· 568 561 struct da8xx_glue *glue = platform_get_drvdata(pdev); 569 562 570 563 platform_device_unregister(glue->musb); 564 + usb_phy_generic_unregister(glue->phy); 571 565 clk_disable(glue->clk); 572 566 clk_put(glue->clk); 573 567 kfree(glue);
+4 -4
drivers/usb/musb/davinci.c
··· 32 32 #include <linux/gpio.h> 33 33 #include <linux/platform_device.h> 34 34 #include <linux/dma-mapping.h> 35 - #include <linux/usb/usb_phy_gen_xceiv.h> 35 + #include <linux/usb/usb_phy_generic.h> 36 36 37 37 #include <mach/cputype.h> 38 38 #include <mach/hardware.h> ··· 381 381 u32 revision; 382 382 int ret = -ENODEV; 383 383 384 - usb_nop_xceiv_register(); 385 384 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 386 385 if (IS_ERR_OR_NULL(musb->xceiv)) { 387 386 ret = -EPROBE_DEFER; ··· 438 439 fail: 439 440 usb_put_phy(musb->xceiv); 440 441 unregister: 441 - usb_nop_xceiv_unregister(); 442 + usb_phy_generic_unregister(); 442 443 return ret; 443 444 } 444 445 ··· 486 487 phy_off(); 487 488 488 489 usb_put_phy(musb->xceiv); 489 - usb_nop_xceiv_unregister(); 490 490 491 491 return 0; 492 492 } ··· 543 545 544 546 pdata->platform_ops = &davinci_ops; 545 547 548 + usb_phy_generic_register(); 546 549 platform_set_drvdata(pdev, glue); 547 550 548 551 memset(musb_resources, 0x00, sizeof(*musb_resources) * ··· 602 603 struct davinci_glue *glue = platform_get_drvdata(pdev); 603 604 604 605 platform_device_unregister(glue->musb); 606 + usb_phy_generic_unregister(); 605 607 clk_disable(glue->clk); 606 608 clk_put(glue->clk); 607 609 kfree(glue);
+35
drivers/usb/musb/musb_core.c
··· 848 848 } 849 849 } 850 850 851 + /* handle babble condition */ 852 + if (int_usb & MUSB_INTR_BABBLE) 853 + schedule_work(&musb->recover_work); 854 + 851 855 #if 0 852 856 /* REVISIT ... this would be for multiplexing periodic endpoints, or 853 857 * supporting transfer phasing to prevent exceeding ISO bandwidth ··· 1750 1746 } 1751 1747 } 1752 1748 1749 + /* Recover from babble interrupt conditions */ 1750 + static void musb_recover_work(struct work_struct *data) 1751 + { 1752 + struct musb *musb = container_of(data, struct musb, recover_work); 1753 + int status; 1754 + 1755 + musb_platform_reset(musb); 1756 + 1757 + usb_phy_vbus_off(musb->xceiv); 1758 + udelay(100); 1759 + 1760 + usb_phy_vbus_on(musb->xceiv); 1761 + udelay(100); 1762 + 1763 + /* 1764 + * When a babble condition occurs, the musb controller removes the 1765 + * session bit and the endpoint config is lost. 1766 + */ 1767 + if (musb->dyn_fifo) 1768 + status = ep_config_from_table(musb); 1769 + else 1770 + status = ep_config_from_hw(musb); 1771 + 1772 + /* start the session again */ 1773 + if (status == 0) 1774 + musb_start(musb); 1775 + } 1776 + 1753 1777 /* -------------------------------------------------------------------------- 1754 1778 * Init support 1755 1779 */ ··· 1945 1913 1946 1914 /* Init IRQ workqueue before request_irq */ 1947 1915 INIT_WORK(&musb->irq_work, musb_irq_work); 1916 + INIT_WORK(&musb->recover_work, musb_recover_work); 1948 1917 INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); 1949 1918 INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); 1950 1919 ··· 2041 2008 2042 2009 fail3: 2043 2010 cancel_work_sync(&musb->irq_work); 2011 + cancel_work_sync(&musb->recover_work); 2044 2012 cancel_delayed_work_sync(&musb->finish_resume_work); 2045 2013 cancel_delayed_work_sync(&musb->deassert_reset_work); 2046 2014 if (musb->dma_controller) ··· 2107 2073 dma_controller_destroy(musb->dma_controller); 2108 2074 2109 2075 cancel_work_sync(&musb->irq_work); 2076 + cancel_work_sync(&musb->recover_work); 2110 2077 cancel_delayed_work_sync(&musb->finish_resume_work); 2111 2078 cancel_delayed_work_sync(&musb->deassert_reset_work); 2112 2079 musb_free(musb);
+9
drivers/usb/musb/musb_core.h
··· 192 192 193 193 int (*set_mode)(struct musb *musb, u8 mode); 194 194 void (*try_idle)(struct musb *musb, unsigned long timeout); 195 + void (*reset)(struct musb *musb); 195 196 196 197 int (*vbus_status)(struct musb *musb); 197 198 void (*set_vbus)(struct musb *musb, int on); ··· 297 296 298 297 irqreturn_t (*isr)(int, void *); 299 298 struct work_struct irq_work; 299 + struct work_struct recover_work; 300 300 struct delayed_work deassert_reset_work; 301 301 struct delayed_work finish_resume_work; 302 302 u16 hwvers; ··· 339 337 dma_addr_t async; 340 338 dma_addr_t sync; 341 339 void __iomem *sync_va; 340 + u8 tusb_revision; 342 341 #endif 343 342 344 343 /* passed down from chip/board specific irq handlers */ ··· 553 550 { 554 551 if (musb->ops->try_idle) 555 552 musb->ops->try_idle(musb, timeout); 553 + } 554 + 555 + static inline void musb_platform_reset(struct musb *musb) 556 + { 557 + if (musb->ops->reset) 558 + musb->ops->reset(musb); 556 559 } 557 560 558 561 static inline int musb_platform_get_vbus_status(struct musb *musb)
+26 -3
drivers/usb/musb/musb_dsps.c
··· 35 35 #include <linux/dma-mapping.h> 36 36 #include <linux/pm_runtime.h> 37 37 #include <linux/module.h> 38 - #include <linux/usb/usb_phy_gen_xceiv.h> 38 + #include <linux/usb/usb_phy_generic.h> 39 39 #include <linux/platform_data/usb-omap.h> 40 40 #include <linux/sizes.h> 41 41 ··· 329 329 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. 330 330 * Also, DRVVBUS pulses for SRP (but not at 5V) ... 331 331 */ 332 - if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE) 332 + if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE) { 333 333 pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); 334 + 335 + /* 336 + * When a babble condition occurs, the musb controller removes 337 + * the session and is no longer in host mode. Hence, all 338 + * devices connected to its root hub get disconnected. 339 + * 340 + * Hand this error down to the musb core isr, so it can 341 + * recover. 342 + */ 343 + musb->int_usb = MUSB_INTR_BABBLE | MUSB_INTR_DISCONNECT; 344 + musb->int_tx = musb->int_rx = 0; 345 + } 334 346 335 347 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { 336 348 int drvvbus = dsps_readl(reg_base, wrp->status); ··· 536 524 return 0; 537 525 } 538 526 527 + static void dsps_musb_reset(struct musb *musb) 528 + { 529 + struct device *dev = musb->controller; 530 + struct dsps_glue *glue = dev_get_drvdata(dev->parent); 531 + const struct dsps_musb_wrapper *wrp = glue->wrp; 532 + 533 + dsps_writel(musb->ctrl_base, wrp->control, (1 << wrp->reset)); 534 + udelay(100); 535 + } 536 + 539 537 static struct musb_platform_ops dsps_ops = { 540 538 .init = dsps_musb_init, 541 539 .exit = dsps_musb_exit, ··· 555 533 556 534 .try_idle = dsps_musb_try_idle, 557 535 .set_mode = dsps_musb_set_mode, 536 + .reset = dsps_musb_reset, 558 537 }; 559 538 560 539 static u64 musb_dmamask = DMA_BIT_MASK(32); ··· 773 750 }; 774 751 MODULE_DEVICE_TABLE(of, musb_dsps_of_match); 775 752 776 - #ifdef CONFIG_PM 753 + #ifdef CONFIG_PM_SLEEP 777 754 static int dsps_suspend(struct device *dev) 778 755 { 779 756 struct dsps_glue *glue = dev_get_drvdata(dev);
+13 -15
drivers/usb/musb/tusb6010.c
··· 24 24 #include <linux/io.h> 25 25 #include <linux/platform_device.h> 26 26 #include <linux/dma-mapping.h> 27 - #include <linux/usb/usb_phy_gen_xceiv.h> 27 + #include <linux/usb/usb_phy_generic.h> 28 28 29 29 #include "musb_core.h" 30 30 31 31 struct tusb6010_glue { 32 32 struct device *dev; 33 33 struct platform_device *musb; 34 + struct platform_device *phy; 34 35 }; 35 36 36 37 static void tusb_musb_set_vbus(struct musb *musb, int is_on); ··· 43 42 * Checks the revision. We need to use the DMA register as 3.0 does not 44 43 * have correct versions for TUSB_PRCM_REV or TUSB_INT_CTRL_REV. 45 44 */ 46 - u8 tusb_get_revision(struct musb *musb) 45 + static u8 tusb_get_revision(struct musb *musb) 47 46 { 48 47 void __iomem *tbase = musb->ctrl_base; 49 48 u32 die_id; ··· 59 58 60 59 return rev; 61 60 } 62 - EXPORT_SYMBOL_GPL(tusb_get_revision); 63 61 64 - static int tusb_print_revision(struct musb *musb) 62 + static void tusb_print_revision(struct musb *musb) 65 63 { 66 64 void __iomem *tbase = musb->ctrl_base; 67 65 u8 rev; 68 66 69 - rev = tusb_get_revision(musb); 67 + rev = musb->tusb_revision; 70 68 71 69 pr_info("tusb: %s%i.%i %s%i.%i %s%i.%i %s%i.%i %s%i %s%i.%i\n", 72 70 "prcm", ··· 84 84 TUSB_DIDR1_HI_CHIP_REV(musb_readl(tbase, TUSB_DIDR1_HI)), 85 85 "rev", 86 86 TUSB_REV_MAJOR(rev), TUSB_REV_MINOR(rev)); 87 - 88 - return tusb_get_revision(musb); 89 87 } 90 88 91 89 #define WBUS_QUIRK_MASK (TUSB_PHY_OTG_CTRL_TESTM2 | TUSB_PHY_OTG_CTRL_TESTM1 \ ··· 347 349 u32 reg; 348 350 349 351 if ((wakeup_enables & TUSB_PRCM_WBUS) 350 - && (tusb_get_revision(musb) == TUSB_REV_30)) 352 + && (musb->tusb_revision == TUSB_REV_30)) 351 353 tusb_wbus_quirk(musb, 1); 352 354 353 355 tusb_set_clock_source(musb, 0); ··· 795 797 u32 reg; 796 798 u32 i; 797 799 798 - if (tusb_get_revision(musb) == TUSB_REV_30) 800 + if (musb->tusb_revision == TUSB_REV_30) 799 801 tusb_wbus_quirk(musb, 0); 800 802 801 803 /* there are issues re-locking the PLL on wakeup ... */ ··· 1009 1011 goto err; 1010 1012 } 1011 1013 1012 - ret = tusb_print_revision(musb); 1013 - if (ret < 2) { 1014 + musb->tusb_revision = tusb_get_revision(musb); 1015 + tusb_print_revision(musb); 1016 + if (musb->tusb_revision < 2) { 1014 1017 printk(KERN_ERR "tusb: Unsupported TUSB6010 revision %i\n", 1015 - ret); 1018 + musb->tusb_revision); 1016 1019 goto err; 1017 1020 } 1018 1021 ··· 1064 1065 void __iomem *sync = NULL; 1065 1066 int ret; 1066 1067 1067 - usb_nop_xceiv_register(); 1068 1068 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 1069 1069 if (IS_ERR_OR_NULL(musb->xceiv)) 1070 1070 return -EPROBE_DEFER; ··· 1115 1117 iounmap(sync); 1116 1118 1117 1119 usb_put_phy(musb->xceiv); 1118 - usb_nop_xceiv_unregister(); 1119 1120 } 1120 1121 return ret; 1121 1122 } ··· 1130 1133 iounmap(musb->sync_va); 1131 1134 1132 1135 usb_put_phy(musb->xceiv); 1133 - usb_nop_xceiv_unregister(); 1134 1136 return 0; 1135 1137 } 1136 1138 ··· 1172 1176 1173 1177 pdata->platform_ops = &tusb_ops; 1174 1178 1179 + usb_phy_generic_register(); 1175 1180 platform_set_drvdata(pdev, glue); 1176 1181 1177 1182 memset(musb_resources, 0x00, sizeof(*musb_resources) * ··· 1221 1224 struct tusb6010_glue *glue = platform_get_drvdata(pdev); 1222 1225 1223 1226 platform_device_unregister(glue->musb); 1227 + usb_phy_generic_unregister(glue->phy); 1224 1228 kfree(glue); 1225 1229 1226 1230 return 0;
-8
drivers/usb/musb/tusb6010.h
··· 12 12 #ifndef __TUSB6010_H__ 13 13 #define __TUSB6010_H__ 14 14 15 - extern u8 tusb_get_revision(struct musb *musb); 16 - 17 - #ifdef CONFIG_USB_TUSB6010 18 - #define musb_in_tusb() 1 19 - #else 20 - #define musb_in_tusb() 0 21 - #endif 22 - 23 15 #ifdef CONFIG_USB_TUSB_OMAP_DMA 24 16 #define tusb_dma_omap() 1 25 17 #else
+1 -1
drivers/usb/musb/tusb6010_omap.c
··· 677 677 tusb_dma->controller.channel_program = tusb_omap_dma_program; 678 678 tusb_dma->controller.channel_abort = tusb_omap_dma_abort; 679 679 680 - if (tusb_get_revision(musb) >= TUSB_REV_30) 680 + if (musb->tusb_revision >= TUSB_REV_30) 681 681 tusb_dma->multichannel = 1; 682 682 683 683 for (i = 0; i < MAX_DMAREQ; i++) {
+4 -3
drivers/usb/phy/Kconfig
··· 163 163 module will be called phy-isp1301. 164 164 165 165 config USB_MSM_OTG 166 - tristate "OTG support for Qualcomm on-chip USB controller" 167 - depends on (USB || USB_GADGET) && ARCH_MSM 166 + tristate "Qualcomm on-chip USB OTG controller support" 167 + depends on (USB || USB_GADGET) && (ARCH_MSM || ARCH_QCOM || COMPILE_TEST) 168 + depends on RESET_CONTROLLER 168 169 select USB_PHY 169 170 help 170 - Enable this to support the USB OTG transceiver on MSM chips. It 171 + Enable this to support the USB OTG transceiver on Qualcomm chips. It 171 172 handles PHY initialization, clock management, and workarounds 172 173 required after resetting the hardware and power management. 173 174 This driver is required even for peripheral only or host only
+2 -2
drivers/usb/phy/phy-am335x.c
··· 2 2 #include <linux/platform_device.h> 3 3 #include <linux/dma-mapping.h> 4 4 #include <linux/usb/otg.h> 5 - #include <linux/usb/usb_phy_gen_xceiv.h> 5 + #include <linux/usb/usb_phy_generic.h> 6 6 #include <linux/slab.h> 7 7 #include <linux/clk.h> 8 8 #include <linux/regulator/consumer.h> ··· 13 13 #include "phy-generic.h" 14 14 15 15 struct am335x_phy { 16 - struct usb_phy_gen_xceiv usb_phy_gen; 16 + struct usb_phy_generic usb_phy_gen; 17 17 struct phy_control *phy_ctrl; 18 18 int id; 19 19 };
+28 -37
drivers/usb/phy/phy-generic.c
··· 30 30 #include <linux/platform_device.h> 31 31 #include <linux/dma-mapping.h> 32 32 #include <linux/usb/otg.h> 33 - #include <linux/usb/usb_phy_gen_xceiv.h> 33 + #include <linux/usb/usb_phy_generic.h> 34 34 #include <linux/slab.h> 35 35 #include <linux/clk.h> 36 36 #include <linux/regulator/consumer.h> ··· 41 41 42 42 #include "phy-generic.h" 43 43 44 - static struct platform_device *pd; 45 - 46 - void usb_nop_xceiv_register(void) 44 + struct platform_device *usb_phy_generic_register(void) 47 45 { 48 - if (pd) 49 - return; 50 - pd = platform_device_register_simple("usb_phy_gen_xceiv", -1, NULL, 0); 51 - if (IS_ERR(pd)) { 52 - pr_err("Unable to register generic usb transceiver\n"); 53 - pd = NULL; 54 - return; 55 - } 46 + return platform_device_register_simple("usb_phy_generic", 47 + PLATFORM_DEVID_AUTO, NULL, 0); 56 48 } 57 - EXPORT_SYMBOL(usb_nop_xceiv_register); 49 + EXPORT_SYMBOL_GPL(usb_phy_generic_register); 58 50 59 - void usb_nop_xceiv_unregister(void) 51 + void usb_phy_generic_unregister(struct platform_device *pdev) 60 52 { 61 - platform_device_unregister(pd); 62 - pd = NULL; 53 + platform_device_unregister(pdev); 63 54 } 64 - EXPORT_SYMBOL(usb_nop_xceiv_unregister); 55 + EXPORT_SYMBOL_GPL(usb_phy_generic_unregister); 65 56 66 57 static int nop_set_suspend(struct usb_phy *x, int suspend) 67 58 { 68 59 return 0; 69 60 } 70 61 71 - static void nop_reset_set(struct usb_phy_gen_xceiv *nop, int asserted) 62 + static void nop_reset_set(struct usb_phy_generic *nop, int asserted) 72 63 { 73 64 int value; 74 65 ··· 78 87 79 88 int usb_gen_phy_init(struct usb_phy *phy) 80 89 { 81 - struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); 90 + struct usb_phy_generic *nop = dev_get_drvdata(phy->dev); 82 91 83 92 if (!IS_ERR(nop->vcc)) { 84 93 if (regulator_enable(nop->vcc)) ··· 97 106 98 107 void usb_gen_phy_shutdown(struct usb_phy *phy) 99 108 { 100 - struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); 109 + struct usb_phy_generic *nop = dev_get_drvdata(phy->dev); 101 110 102 111 /* Assert RESET */ 103 112 nop_reset_set(nop, 1); ··· 141 150 return 0; 142 151 } 143 152 144 - int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, 145 - struct usb_phy_gen_xceiv_platform_data *pdata) 153 + int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop, 154 + struct usb_phy_generic_platform_data *pdata) 146 155 { 147 156 enum usb_phy_type type = USB_PHY_TYPE_USB2; 148 157 int err; ··· 236 245 } 237 246 EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); 238 247 239 - static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) 248 + static int usb_phy_generic_probe(struct platform_device *pdev) 240 249 { 241 250 struct device *dev = &pdev->dev; 242 - struct usb_phy_gen_xceiv *nop; 251 + struct usb_phy_generic *nop; 243 252 int err; 244 253 245 254 nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); ··· 265 274 return 0; 266 275 } 267 276 268 - static int usb_phy_gen_xceiv_remove(struct platform_device *pdev) 277 + static int usb_phy_generic_remove(struct platform_device *pdev) 269 278 { 270 - struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev); 279 + struct usb_phy_generic *nop = platform_get_drvdata(pdev); 271 280 272 281 usb_remove_phy(&nop->phy); 273 282 ··· 281 290 282 291 MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids); 283 292 284 - static struct platform_driver usb_phy_gen_xceiv_driver = { 285 - .probe = usb_phy_gen_xceiv_probe, 286 - .remove = usb_phy_gen_xceiv_remove, 293 + static struct platform_driver usb_phy_generic_driver = { 294 + .probe = usb_phy_generic_probe, 295 + .remove = usb_phy_generic_remove, 287 296 .driver = { 288 - .name = "usb_phy_gen_xceiv", 297 + .name = "usb_phy_generic", 289 298 .owner = THIS_MODULE, 290 299 .of_match_table = nop_xceiv_dt_ids, 291 300 }, 292 301 }; 293 302 294 - static int __init usb_phy_gen_xceiv_init(void) 303 + static int __init usb_phy_generic_init(void) 295 304 { 296 - return platform_driver_register(&usb_phy_gen_xceiv_driver); 305 + return platform_driver_register(&usb_phy_generic_driver); 297 306 } 298 - subsys_initcall(usb_phy_gen_xceiv_init); 307 + subsys_initcall(usb_phy_generic_init); 299 308 300 - static void __exit usb_phy_gen_xceiv_exit(void) 309 + static void __exit usb_phy_generic_exit(void) 301 310 { 302 - platform_driver_unregister(&usb_phy_gen_xceiv_driver); 311 + platform_driver_unregister(&usb_phy_generic_driver); 303 312 } 304 - module_exit(usb_phy_gen_xceiv_exit); 313 + module_exit(usb_phy_generic_exit); 305 314 306 - MODULE_ALIAS("platform:usb_phy_gen_xceiv"); 315 + MODULE_ALIAS("platform:usb_phy_generic"); 307 316 MODULE_AUTHOR("Texas Instruments Inc"); 308 317 MODULE_DESCRIPTION("NOP USB Transceiver driver"); 309 318 MODULE_LICENSE("GPL");
+4 -4
drivers/usb/phy/phy-generic.h
··· 1 1 #ifndef _PHY_GENERIC_H_ 2 2 #define _PHY_GENERIC_H_ 3 3 4 - #include <linux/usb/usb_phy_gen_xceiv.h> 4 + #include <linux/usb/usb_phy_generic.h> 5 5 6 - struct usb_phy_gen_xceiv { 6 + struct usb_phy_generic { 7 7 struct usb_phy phy; 8 8 struct device *dev; 9 9 struct clk *clk; ··· 15 15 int usb_gen_phy_init(struct usb_phy *phy); 16 16 void usb_gen_phy_shutdown(struct usb_phy *phy); 17 17 18 - int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, 19 - struct usb_phy_gen_xceiv_platform_data *pdata); 18 + int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop, 19 + struct usb_phy_generic_platform_data *pdata); 20 20 21 21 #endif
+2 -2
drivers/usb/phy/phy-keystone.c
··· 18 18 19 19 #include <linux/module.h> 20 20 #include <linux/platform_device.h> 21 - #include <linux/usb/usb_phy_gen_xceiv.h> 21 + #include <linux/usb/usb_phy_generic.h> 22 22 #include <linux/io.h> 23 23 #include <linux/of.h> 24 24 ··· 35 35 #define PHY_REF_SSP_EN BIT(29) 36 36 37 37 struct keystone_usbphy { 38 - struct usb_phy_gen_xceiv usb_phy_gen; 38 + struct usb_phy_generic usb_phy_gen; 39 39 void __iomem *phy_ctrl; 40 40 }; 41 41
+401 -309
drivers/usb/phy/phy-msm-usb.c
··· 30 30 #include <linux/debugfs.h> 31 31 #include <linux/seq_file.h> 32 32 #include <linux/pm_runtime.h> 33 + #include <linux/of.h> 34 + #include <linux/of_device.h> 35 + #include <linux/reset.h> 33 36 34 37 #include <linux/usb.h> 35 38 #include <linux/usb/otg.h> 39 + #include <linux/usb/of.h> 36 40 #include <linux/usb/ulpi.h> 37 41 #include <linux/usb/gadget.h> 38 42 #include <linux/usb/hcd.h> ··· 48 44 #define DRIVER_NAME "msm_otg" 49 45 50 46 #define ULPI_IO_TIMEOUT_USEC (10 * 1000) 47 + #define LINK_RESET_TIMEOUT_USEC (250 * 1000) 51 48 52 49 #define USB_PHY_3P3_VOL_MIN 3050000 /* uV */ 53 50 #define USB_PHY_3P3_VOL_MAX 3300000 /* uV */ ··· 62 57 63 58 #define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */ 64 59 #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ 60 + #define USB_PHY_SUSP_DIG_VOL 500000 /* uV */ 65 61 66 - static struct regulator *hsusb_3p3; 67 - static struct regulator *hsusb_1p8; 68 - static struct regulator *hsusb_vddcx; 62 + enum vdd_levels { 63 + VDD_LEVEL_NONE = 0, 64 + VDD_LEVEL_MIN, 65 + VDD_LEVEL_MAX, 66 + }; 69 67 70 68 static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) 71 69 { 72 70 int ret = 0; 73 71 74 72 if (init) { 75 - hsusb_vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX"); 76 - if (IS_ERR(hsusb_vddcx)) { 77 - dev_err(motg->phy.dev, "unable to get hsusb vddcx\n"); 78 - return PTR_ERR(hsusb_vddcx); 79 - } 80 - 81 - ret = regulator_set_voltage(hsusb_vddcx, 82 - USB_PHY_VDD_DIG_VOL_MIN, 83 - USB_PHY_VDD_DIG_VOL_MAX); 73 + ret = regulator_set_voltage(motg->vddcx, 74 + motg->vdd_levels[VDD_LEVEL_MIN], 75 + motg->vdd_levels[VDD_LEVEL_MAX]); 84 76 if (ret) { 85 - dev_err(motg->phy.dev, "unable to set the voltage " 86 - "for hsusb vddcx\n"); 87 - regulator_put(hsusb_vddcx); 77 + dev_err(motg->phy.dev, "Cannot set vddcx voltage\n"); 88 78 return ret; 89 79 } 90 80 91 - ret = regulator_enable(hsusb_vddcx); 92 - if (ret) { 93 - dev_err(motg->phy.dev, "unable to enable hsusb vddcx\n"); 94 - regulator_put(hsusb_vddcx); 95 - } 96 - } else { 97 - ret = regulator_set_voltage(hsusb_vddcx, 0, 98 - USB_PHY_VDD_DIG_VOL_MAX); 81 + ret = regulator_enable(motg->vddcx); 99 82 if (ret) 100 - dev_err(motg->phy.dev, "unable to set the voltage " 101 - "for hsusb vddcx\n"); 102 - ret = regulator_disable(hsusb_vddcx); 83 + dev_err(motg->phy.dev, "unable to enable hsusb vddcx\n"); 84 + } else { 85 + ret = regulator_set_voltage(motg->vddcx, 0, 86 + motg->vdd_levels[VDD_LEVEL_MAX]); 87 + if (ret) 88 + dev_err(motg->phy.dev, "Cannot set vddcx voltage\n"); 89 + ret = regulator_disable(motg->vddcx); 103 90 if (ret) 104 91 dev_err(motg->phy.dev, "unable to disable hsusb vddcx\n"); 105 - 106 - regulator_put(hsusb_vddcx); 107 92 } 108 93 109 94 return ret; ··· 104 109 int rc = 0; 105 110 106 111 if (init) { 107 - hsusb_3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3"); 108 - if (IS_ERR(hsusb_3p3)) { 109 - dev_err(motg->phy.dev, "unable to get hsusb 3p3\n"); 110 - return PTR_ERR(hsusb_3p3); 111 - } 112 - 113 - rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN, 112 + rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN, 114 113 USB_PHY_3P3_VOL_MAX); 115 114 if (rc) { 116 - dev_err(motg->phy.dev, "unable to set voltage level " 117 - "for hsusb 3p3\n"); 118 - goto put_3p3; 115 + dev_err(motg->phy.dev, "Cannot set v3p3 voltage\n"); 116 + goto exit; 119 117 } 120 - rc = regulator_enable(hsusb_3p3); 118 + rc = regulator_enable(motg->v3p3); 121 119 if (rc) { 122 120 dev_err(motg->phy.dev, "unable to enable the hsusb 3p3\n"); 123 - goto put_3p3; 121 + goto exit; 124 122 } 125 - hsusb_1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8"); 126 - if (IS_ERR(hsusb_1p8)) { 127 - dev_err(motg->phy.dev, "unable to get hsusb 1p8\n"); 128 - rc = PTR_ERR(hsusb_1p8); 129 - goto disable_3p3; 130 - } 131 - rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN, 123 + rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN, 132 124 USB_PHY_1P8_VOL_MAX); 133 125 if (rc) { 134 - dev_err(motg->phy.dev, "unable to set voltage level " 135 - "for hsusb 1p8\n"); 136 - goto put_1p8; 126 + dev_err(motg->phy.dev, "Cannot set v1p8 voltage\n"); 127 + goto disable_3p3; 137 128 } 138 - rc = regulator_enable(hsusb_1p8); 129 + rc = regulator_enable(motg->v1p8); 139 130 if (rc) { 140 131 dev_err(motg->phy.dev, "unable to enable the hsusb 1p8\n"); 141 - goto put_1p8; 132 + goto disable_3p3; 142 133 } 143 134 144 135 return 0; 145 136 } 146 137 147 - regulator_disable(hsusb_1p8); 148 - put_1p8: 149 - regulator_put(hsusb_1p8); 138 + regulator_disable(motg->v1p8); 150 139 disable_3p3: 151 - regulator_disable(hsusb_3p3); 152 - put_3p3: 153 - regulator_put(hsusb_3p3); 140 + regulator_disable(motg->v3p3); 141 + exit: 154 142 return rc; 155 143 } 156 144 157 - static int msm_hsusb_ldo_set_mode(int on) 145 + static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, int on) 158 146 { 159 147 int ret = 0; 160 148 161 - if (!hsusb_1p8 || IS_ERR(hsusb_1p8)) { 162 - pr_err("%s: HSUSB_1p8 is not initialized\n", __func__); 163 - return -ENODEV; 164 - } 165 - 166 - if (!hsusb_3p3 || IS_ERR(hsusb_3p3)) { 167 - pr_err("%s: HSUSB_3p3 is not initialized\n", __func__); 168 - return -ENODEV; 169 - } 170 - 171 149 if (on) { 172 - ret = regulator_set_optimum_mode(hsusb_1p8, 150 + ret = regulator_set_optimum_mode(motg->v1p8, 173 151 USB_PHY_1P8_HPM_LOAD); 174 152 if (ret < 0) { 175 - pr_err("%s: Unable to set HPM of the regulator " 176 - "HSUSB_1p8\n", __func__); 153 + pr_err("Could not set HPM for v1p8\n"); 177 154 return ret; 178 155 } 179 - ret = regulator_set_optimum_mode(hsusb_3p3, 156 + ret = regulator_set_optimum_mode(motg->v3p3, 180 157 USB_PHY_3P3_HPM_LOAD); 181 158 if (ret < 0) { 182 - pr_err("%s: Unable to set HPM of the regulator " 183 - "HSUSB_3p3\n", __func__); 184 - regulator_set_optimum_mode(hsusb_1p8, 159 + pr_err("Could not set HPM for v3p3\n"); 160 + regulator_set_optimum_mode(motg->v1p8, 185 161 USB_PHY_1P8_LPM_LOAD); 186 162 return ret; 187 163 } 188 164 } else { 189 - ret = regulator_set_optimum_mode(hsusb_1p8, 165 + ret = regulator_set_optimum_mode(motg->v1p8, 190 166 USB_PHY_1P8_LPM_LOAD); 191 167 if (ret < 0) 192 - pr_err("%s: Unable to set LPM of the regulator " 193 - "HSUSB_1p8\n", __func__); 194 - ret = regulator_set_optimum_mode(hsusb_3p3, 168 + pr_err("Could not set LPM for v1p8\n"); 169 + ret = regulator_set_optimum_mode(motg->v3p3, 195 170 USB_PHY_3P3_LPM_LOAD); 196 171 if (ret < 0) 197 - pr_err("%s: Unable to set LPM of the regulator " 198 - "HSUSB_3p3\n", __func__); 172 + pr_err("Could not set LPM for v3p3\n"); 199 173 } 200 174 201 175 pr_debug("reg (%s)\n", on ? "HPM" : "LPM"); ··· 229 265 static void ulpi_init(struct msm_otg *motg) 230 266 { 231 267 struct msm_otg_platform_data *pdata = motg->pdata; 232 - int *seq = pdata->phy_init_seq; 268 + int *seq = pdata->phy_init_seq, idx; 269 + u32 addr = ULPI_EXT_VENDOR_SPECIFIC; 233 270 234 - if (!seq) 235 - return; 271 + for (idx = 0; idx < pdata->phy_init_sz; idx++) { 272 + if (seq[idx] == -1) 273 + continue; 236 274 237 - while (seq[0] >= 0) { 238 275 dev_vdbg(motg->phy.dev, "ulpi: write 0x%02x to 0x%02x\n", 239 - seq[0], seq[1]); 240 - ulpi_write(&motg->phy, seq[0], seq[1]); 241 - seq += 2; 276 + seq[idx], addr + idx); 277 + ulpi_write(&motg->phy, seq[idx], addr + idx); 242 278 } 279 + } 280 + 281 + static int msm_phy_notify_disconnect(struct usb_phy *phy, 282 + enum usb_device_speed speed) 283 + { 284 + int val; 285 + 286 + /* 287 + * Put the transceiver in non-driving mode. Otherwise host 288 + * may not detect soft-disconnection. 289 + */ 290 + val = ulpi_read(phy, ULPI_FUNC_CTRL); 291 + val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; 292 + val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; 293 + ulpi_write(phy, val, ULPI_FUNC_CTRL); 294 + 295 + return 0; 243 296 } 244 297 245 298 static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) 246 299 { 247 - int ret = 0; 300 + int ret; 248 301 249 - if (!motg->pdata->link_clk_reset) 250 - return ret; 302 + if (motg->pdata->link_clk_reset) 303 + ret = motg->pdata->link_clk_reset(motg->clk, assert); 304 + else if (assert) 305 + ret = reset_control_assert(motg->link_rst); 306 + else 307 + ret = reset_control_deassert(motg->link_rst); 251 308 252 - ret = motg->pdata->link_clk_reset(motg->clk, assert); 253 309 if (ret) 254 310 dev_err(motg->phy.dev, "usb link clk reset %s failed\n", 255 311 assert ? "assert" : "deassert"); ··· 279 295 280 296 static int msm_otg_phy_clk_reset(struct msm_otg *motg) 281 297 { 282 - int ret = 0; 298 + int ret; 283 299 284 - if (!motg->pdata->phy_clk_reset) 285 - return ret; 300 + if (motg->pdata->phy_clk_reset) 301 + ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); 302 + else 303 + ret = reset_control_reset(motg->phy_rst); 286 304 287 - ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); 288 305 if (ret) 289 306 dev_err(motg->phy.dev, "usb phy clk reset failed\n"); 290 307 291 308 return ret; 292 309 } 293 310 294 - static int msm_otg_phy_reset(struct msm_otg *motg) 311 + static int msm_link_reset(struct msm_otg *motg) 295 312 { 296 313 u32 val; 297 314 int ret; 298 - int retries; 299 315 300 316 ret = msm_otg_link_clk_reset(motg, 1); 301 317 if (ret) 302 318 return ret; 303 - ret = msm_otg_phy_clk_reset(motg); 304 - if (ret) 305 - return ret; 319 + 320 + /* wait for 1ms delay as suggested in HPG. */ 321 + usleep_range(1000, 1200); 322 + 306 323 ret = msm_otg_link_clk_reset(motg, 0); 307 324 if (ret) 308 325 return ret; 309 326 327 + if (motg->phy_number) 328 + writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2); 329 + 330 + /* put transceiver in serial mode as part of reset */ 310 331 val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK; 311 - writel(val | PORTSC_PTS_ULPI, USB_PORTSC); 332 + writel(val | PORTSC_PTS_SERIAL, USB_PORTSC); 312 333 313 - for (retries = 3; retries > 0; retries--) { 314 - ret = ulpi_write(&motg->phy, ULPI_FUNC_CTRL_SUSPENDM, 315 - ULPI_CLR(ULPI_FUNC_CTRL)); 316 - if (!ret) 317 - break; 318 - ret = msm_otg_phy_clk_reset(motg); 319 - if (ret) 320 - return ret; 321 - } 322 - if (!retries) 323 - return -ETIMEDOUT; 324 - 325 - /* This reset calibrates the phy, if the above write succeeded */ 326 - ret = msm_otg_phy_clk_reset(motg); 327 - if (ret) 328 - return ret; 329 - 330 - for (retries = 3; retries > 0; retries--) { 331 - ret = ulpi_read(&motg->phy, ULPI_DEBUG); 332 - if (ret != -ETIMEDOUT) 333 - break; 334 - ret = msm_otg_phy_clk_reset(motg); 335 - if (ret) 336 - return ret; 337 - } 338 - if (!retries) 339 - return -ETIMEDOUT; 340 - 341 - dev_info(motg->phy.dev, "phy_reset: success\n"); 342 334 return 0; 343 335 } 344 336 345 - #define LINK_RESET_TIMEOUT_USEC (250 * 1000) 346 337 static int msm_otg_reset(struct usb_phy *phy) 347 338 { 348 339 struct msm_otg *motg = container_of(phy, struct msm_otg, phy); 349 - struct msm_otg_platform_data *pdata = motg->pdata; 350 340 int cnt = 0; 351 - int ret; 352 - u32 val = 0; 353 - u32 ulpi_val = 0; 354 - 355 - ret = msm_otg_phy_reset(motg); 356 - if (ret) { 357 - dev_err(phy->dev, "phy_reset failed\n"); 358 - return ret; 359 - } 360 - 361 - ulpi_init(motg); 362 341 363 342 writel(USBCMD_RESET, USB_USBCMD); 364 343 while (cnt < LINK_RESET_TIMEOUT_USEC) { ··· 333 386 if (cnt >= LINK_RESET_TIMEOUT_USEC) 334 387 return -ETIMEDOUT; 335 388 336 - /* select ULPI phy */ 337 - writel(0x80000000, USB_PORTSC); 389 + /* select ULPI phy and clear other status/control bits in PORTSC */ 390 + writel(PORTSC_PTS_ULPI, USB_PORTSC); 391 + 392 + writel(0x0, USB_AHBBURST); 393 + writel(0x08, USB_AHBMODE); 394 + 395 + if (motg->phy_number) 396 + writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2); 397 + return 0; 398 + } 399 + 400 + static void msm_phy_reset(struct msm_otg *motg) 401 + { 402 + void __iomem *addr; 403 + 404 + if (motg->pdata->phy_type != SNPS_28NM_INTEGRATED_PHY) { 405 + msm_otg_phy_clk_reset(motg); 406 + return; 407 + } 408 + 409 + addr = USB_PHY_CTRL; 410 + if (motg->phy_number) 411 + addr = USB_PHY_CTRL2; 412 + 413 + /* Assert USB PHY_POR */ 414 + writel(readl(addr) | PHY_POR_ASSERT, addr); 415 + 416 + /* 417 + * wait for minimum 10 microseconds as suggested in HPG. 418 + * Use a slightly larger value since the exact value didn't 419 + * work 100% of the time. 420 + */ 421 + udelay(12); 422 + 423 + /* Deassert USB PHY_POR */ 424 + writel(readl(addr) & ~PHY_POR_ASSERT, addr); 425 + } 426 + 427 + static int msm_usb_reset(struct usb_phy *phy) 428 + { 429 + struct msm_otg *motg = container_of(phy, struct msm_otg, phy); 430 + int ret; 431 + 432 + if (!IS_ERR(motg->core_clk)) 433 + clk_prepare_enable(motg->core_clk); 434 + 435 + ret = msm_link_reset(motg); 436 + if (ret) { 437 + dev_err(phy->dev, "phy_reset failed\n"); 438 + return ret; 439 + } 440 + 441 + ret = msm_otg_reset(&motg->phy); 442 + if (ret) { 443 + dev_err(phy->dev, "link reset failed\n"); 444 + return ret; 445 + } 338 446 339 447 msleep(100); 340 448 341 - writel(0x0, USB_AHBBURST); 342 - writel(0x00, USB_AHBMODE); 449 + /* Reset USB PHY after performing USB Link RESET */ 450 + msm_phy_reset(motg); 451 + 452 + if (!IS_ERR(motg->core_clk)) 453 + clk_disable_unprepare(motg->core_clk); 454 + 455 + return 0; 456 + } 457 + 458 + static int msm_phy_init(struct usb_phy *phy) 459 + { 460 + struct msm_otg *motg = container_of(phy, struct msm_otg, phy); 461 + struct msm_otg_platform_data *pdata = motg->pdata; 462 + u32 val, ulpi_val = 0; 463 + 464 + /* Program USB PHY Override registers. */ 465 + ulpi_init(motg); 466 + 467 + /* 468 + * It is recommended in HPG to reset USB PHY after programming 469 + * USB PHY Override registers. 470 + */ 471 + msm_phy_reset(motg); 343 472 344 473 if (pdata->otg_control == OTG_PHY_CONTROL) { 345 474 val = readl(USB_OTGSC); 346 - if (pdata->mode == USB_OTG) { 475 + if (pdata->mode == USB_DR_MODE_OTG) { 347 476 ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID; 348 477 val |= OTGSC_IDIE | OTGSC_BSVIE; 349 - } else if (pdata->mode == USB_PERIPHERAL) { 478 + } else if (pdata->mode == USB_DR_MODE_PERIPHERAL) { 350 479 ulpi_val = ULPI_INT_SESS_VALID; 351 480 val |= OTGSC_BSVIE; 352 481 } ··· 430 407 ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_RISE); 431 408 ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_FALL); 432 409 } 410 + 411 + if (motg->phy_number) 412 + writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2); 433 413 434 414 return 0; 435 415 } ··· 442 416 443 417 #ifdef CONFIG_PM 444 418 445 - #define USB_PHY_SUSP_DIG_VOL 500000 446 - static int msm_hsusb_config_vddcx(int high) 419 + static int msm_hsusb_config_vddcx(struct msm_otg *motg, int high) 447 420 { 448 - int max_vol = USB_PHY_VDD_DIG_VOL_MAX; 421 + int max_vol = motg->vdd_levels[VDD_LEVEL_MAX]; 449 422 int min_vol; 450 423 int ret; 451 424 452 425 if (high) 453 - min_vol = USB_PHY_VDD_DIG_VOL_MIN; 426 + min_vol = motg->vdd_levels[VDD_LEVEL_MIN]; 454 427 else 455 - min_vol = USB_PHY_SUSP_DIG_VOL; 428 + min_vol = motg->vdd_levels[VDD_LEVEL_NONE]; 456 429 457 - ret = regulator_set_voltage(hsusb_vddcx, min_vol, max_vol); 430 + ret = regulator_set_voltage(motg->vddcx, min_vol, max_vol); 458 431 if (ret) { 459 - pr_err("%s: unable to set the voltage for regulator " 460 - "HSUSB_VDDCX\n", __func__); 432 + pr_err("Cannot set vddcx voltage\n"); 461 433 return ret; 462 434 } 463 435 ··· 469 445 struct usb_phy *phy = &motg->phy; 470 446 struct usb_bus *bus = phy->otg->host; 471 447 struct msm_otg_platform_data *pdata = motg->pdata; 448 + void __iomem *addr; 472 449 int cnt = 0; 473 450 474 451 if (atomic_read(&motg->in_lpm)) ··· 529 504 */ 530 505 writel(readl(USB_USBCMD) | ASYNC_INTR_CTRL | ULPI_STP_CTRL, USB_USBCMD); 531 506 507 + addr = USB_PHY_CTRL; 508 + if (motg->phy_number) 509 + addr = USB_PHY_CTRL2; 510 + 532 511 if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && 533 512 motg->pdata->otg_control == OTG_PMIC_CONTROL) 534 - writel(readl(USB_PHY_CTRL) | PHY_RETEN, USB_PHY_CTRL); 513 + writel(readl(addr) | PHY_RETEN, addr); 535 514 536 515 clk_disable_unprepare(motg->pclk); 537 516 clk_disable_unprepare(motg->clk); 538 - if (motg->core_clk) 517 + if (!IS_ERR(motg->core_clk)) 539 518 clk_disable_unprepare(motg->core_clk); 540 - 541 - if (!IS_ERR(motg->pclk_src)) 542 - clk_disable_unprepare(motg->pclk_src); 543 519 544 520 if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && 545 521 motg->pdata->otg_control == OTG_PMIC_CONTROL) { 546 - msm_hsusb_ldo_set_mode(0); 547 - msm_hsusb_config_vddcx(0); 522 + msm_hsusb_ldo_set_mode(motg, 0); 523 + msm_hsusb_config_vddcx(motg, 0); 548 524 } 549 525 550 526 if (device_may_wakeup(phy->dev)) ··· 565 539 { 566 540 struct usb_phy *phy = &motg->phy; 567 541 struct usb_bus *bus = phy->otg->host; 542 + void __iomem *addr; 568 543 int cnt = 0; 569 544 unsigned temp; 570 545 571 546 if (!atomic_read(&motg->in_lpm)) 572 547 return 0; 573 548 574 - if (!IS_ERR(motg->pclk_src)) 575 - clk_prepare_enable(motg->pclk_src); 576 - 577 549 clk_prepare_enable(motg->pclk); 578 550 clk_prepare_enable(motg->clk); 579 - if (motg->core_clk) 551 + if (!IS_ERR(motg->core_clk)) 580 552 clk_prepare_enable(motg->core_clk); 581 553 582 554 if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && 583 555 motg->pdata->otg_control == OTG_PMIC_CONTROL) { 584 - msm_hsusb_ldo_set_mode(1); 585 - msm_hsusb_config_vddcx(1); 586 - writel(readl(USB_PHY_CTRL) & ~PHY_RETEN, USB_PHY_CTRL); 556 + 557 + addr = USB_PHY_CTRL; 558 + if (motg->phy_number) 559 + addr = USB_PHY_CTRL2; 560 + 561 + msm_hsusb_ldo_set_mode(motg, 1); 562 + msm_hsusb_config_vddcx(motg, 1); 563 + writel(readl(addr) & ~PHY_RETEN, addr); 587 564 } 588 565 589 566 temp = readl(USB_USBCMD); ··· 615 586 * PHY. USB state can not be restored. Re-insertion 616 587 * of USB cable is the only way to get USB working. 617 588 */ 618 - dev_err(phy->dev, "Unable to resume USB." 619 - "Re-plugin the cable\n"); 589 + dev_err(phy->dev, "Unable to resume USB. Re-plugin the cable\n"); 620 590 msm_otg_reset(phy); 621 591 } 622 592 ··· 715 687 * Fail host registration if this board can support 716 688 * only peripheral configuration. 717 689 */ 718 - if (motg->pdata->mode == USB_PERIPHERAL) { 690 + if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL) { 719 691 dev_info(otg->phy->dev, "Host mode is not supported\n"); 720 692 return -ENODEV; 721 693 } ··· 744 716 * Kick the state machine work, if peripheral is not supported 745 717 * or peripheral is already registered with us. 746 718 */ 747 - if (motg->pdata->mode == USB_HOST || otg->gadget) { 719 + if (motg->pdata->mode == USB_DR_MODE_HOST || otg->gadget) { 748 720 pm_runtime_get_sync(otg->phy->dev); 749 721 schedule_work(&motg->sm_work); 750 722 } ··· 788 760 * Fail peripheral registration if this board can support 789 761 * only host configuration. 790 762 */ 791 - if (motg->pdata->mode == USB_HOST) { 763 + if (motg->pdata->mode == USB_DR_MODE_HOST) { 792 764 dev_info(otg->phy->dev, "Peripheral mode is not supported\n"); 793 765 return -ENODEV; 794 766 } ··· 813 785 * Kick the state machine work, if host is not supported 814 786 * or host is already registered with us. 815 787 */ 816 - if (motg->pdata->mode == USB_PERIPHERAL || otg->host) { 788 + if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL || otg->host) { 817 789 pm_runtime_get_sync(otg->phy->dev); 818 790 schedule_work(&motg->sm_work); 819 791 } ··· 1134 1106 u32 otgsc = readl(USB_OTGSC); 1135 1107 1136 1108 switch (pdata->mode) { 1137 - case USB_OTG: 1109 + case USB_DR_MODE_OTG: 1138 1110 if (pdata->otg_control == OTG_PHY_CONTROL) { 1139 1111 if (otgsc & OTGSC_ID) 1140 1112 set_bit(ID, &motg->inputs); ··· 1146 1118 else 1147 1119 clear_bit(B_SESS_VLD, &motg->inputs); 1148 1120 } else if (pdata->otg_control == OTG_USER_CONTROL) { 1149 - if (pdata->default_mode == USB_HOST) { 1150 - clear_bit(ID, &motg->inputs); 1151 - } else if (pdata->default_mode == USB_PERIPHERAL) { 1152 - set_bit(ID, &motg->inputs); 1153 - set_bit(B_SESS_VLD, &motg->inputs); 1154 - } else { 1155 1121 set_bit(ID, &motg->inputs); 1156 1122 clear_bit(B_SESS_VLD, &motg->inputs); 1157 - } 1158 1123 } 1159 1124 break; 1160 - case USB_HOST: 1125 + case USB_DR_MODE_HOST: 1161 1126 clear_bit(ID, &motg->inputs); 1162 1127 break; 1163 - case USB_PERIPHERAL: 1128 + case USB_DR_MODE_PERIPHERAL: 1164 1129 set_bit(ID, &motg->inputs); 1165 1130 if (otgsc & OTGSC_BSV) 1166 1131 set_bit(B_SESS_VLD, &motg->inputs); ··· 1303 1282 1304 1283 switch (otg->phy->state) { 1305 1284 case OTG_STATE_A_HOST: 1306 - seq_printf(s, "host\n"); 1285 + seq_puts(s, "host\n"); 1307 1286 break; 1308 1287 case OTG_STATE_B_PERIPHERAL: 1309 - seq_printf(s, "peripheral\n"); 1288 + seq_puts(s, "peripheral\n"); 1310 1289 break; 1311 1290 default: 1312 - seq_printf(s, "none\n"); 1291 + seq_puts(s, "none\n"); 1313 1292 break; 1314 1293 } 1315 1294 ··· 1329 1308 char buf[16]; 1330 1309 struct usb_otg *otg = motg->phy.otg; 1331 1310 int status = count; 1332 - enum usb_mode_type req_mode; 1311 + enum usb_dr_mode req_mode; 1333 1312 1334 1313 memset(buf, 0x00, sizeof(buf)); 1335 1314 ··· 1339 1318 } 1340 1319 1341 1320 if (!strncmp(buf, "host", 4)) { 1342 - req_mode = USB_HOST; 1321 + req_mode = USB_DR_MODE_HOST; 1343 1322 } else if (!strncmp(buf, "peripheral", 10)) { 1344 - req_mode = USB_PERIPHERAL; 1323 + req_mode = USB_DR_MODE_PERIPHERAL; 1345 1324 } else if (!strncmp(buf, "none", 4)) { 1346 - req_mode = USB_NONE; 1325 + req_mode = USB_DR_MODE_UNKNOWN; 1347 1326 } else { 1348 1327 status = -EINVAL; 1349 1328 goto out; 1350 1329 } 1351 1330 1352 1331 switch (req_mode) { 1353 - case USB_NONE: 1332 + case USB_DR_MODE_UNKNOWN: 1354 1333 switch (otg->phy->state) { 1355 1334 case OTG_STATE_A_HOST: 1356 1335 case OTG_STATE_B_PERIPHERAL: ··· 1361 1340 goto out; 1362 1341 } 1363 1342 break; 1364 - case USB_PERIPHERAL: 1343 + case USB_DR_MODE_PERIPHERAL: 1365 1344 switch (otg->phy->state) { 1366 1345 case OTG_STATE_B_IDLE: 1367 1346 case OTG_STATE_A_HOST: ··· 1372 1351 goto out; 1373 1352 } 1374 1353 break; 1375 - case USB_HOST: 1354 + case USB_DR_MODE_HOST: 1376 1355 switch (otg->phy->state) { 1377 1356 case OTG_STATE_B_IDLE: 1378 1357 case OTG_STATE_B_PERIPHERAL: ··· 1427 1406 debugfs_remove(msm_otg_dbg_root); 1428 1407 } 1429 1408 1430 - static int __init msm_otg_probe(struct platform_device *pdev) 1409 + static struct of_device_id msm_otg_dt_match[] = { 1410 + { 1411 + .compatible = "qcom,usb-otg-ci", 1412 + .data = (void *) CI_45NM_INTEGRATED_PHY 1413 + }, 1414 + { 1415 + .compatible = "qcom,usb-otg-snps", 1416 + .data = (void *) SNPS_28NM_INTEGRATED_PHY 1417 + }, 1418 + { } 1419 + }; 1420 + MODULE_DEVICE_TABLE(of, msm_otg_dt_match); 1421 + 1422 + static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) 1431 1423 { 1424 + struct msm_otg_platform_data *pdata; 1425 + const struct of_device_id *id; 1426 + struct device_node *node = pdev->dev.of_node; 1427 + struct property *prop; 1428 + int len, ret, words; 1429 + u32 val, tmp[3]; 1430 + 1431 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 1432 + if (!pdata) 1433 + return -ENOMEM; 1434 + 1435 + motg->pdata = pdata; 1436 + 1437 + id = of_match_device(msm_otg_dt_match, &pdev->dev); 1438 + pdata->phy_type = (enum msm_usb_phy_type) id->data; 1439 + 1440 + motg->link_rst = devm_reset_control_get(&pdev->dev, "link"); 1441 + if (IS_ERR(motg->link_rst)) 1442 + return PTR_ERR(motg->link_rst); 1443 + 1444 + motg->phy_rst = devm_reset_control_get(&pdev->dev, "phy"); 1445 + if (IS_ERR(motg->phy_rst)) 1446 + return PTR_ERR(motg->phy_rst); 1447 + 1448 + pdata->mode = of_usb_get_dr_mode(node); 1449 + if (pdata->mode == USB_DR_MODE_UNKNOWN) 1450 + pdata->mode = USB_DR_MODE_OTG; 1451 + 1452 + pdata->otg_control = OTG_PHY_CONTROL; 1453 + if (!of_property_read_u32(node, "qcom,otg-control", &val)) 1454 + if (val == OTG_PMIC_CONTROL) 1455 + pdata->otg_control = val; 1456 + 1457 + if (!of_property_read_u32(node, "qcom,phy-num", &val) && val < 2) 1458 + motg->phy_number = val; 1459 + 1460 + motg->vdd_levels[VDD_LEVEL_NONE] = USB_PHY_SUSP_DIG_VOL; 1461 + motg->vdd_levels[VDD_LEVEL_MIN] = USB_PHY_VDD_DIG_VOL_MIN; 1462 + motg->vdd_levels[VDD_LEVEL_MAX] = USB_PHY_VDD_DIG_VOL_MAX; 1463 + 1464 + if (of_get_property(node, "qcom,vdd-levels", &len) && 1465 + len == sizeof(tmp)) { 1466 + of_property_read_u32_array(node, "qcom,vdd-levels", 1467 + tmp, len / sizeof(*tmp)); 1468 + motg->vdd_levels[VDD_LEVEL_NONE] = tmp[VDD_LEVEL_NONE]; 1469 + motg->vdd_levels[VDD_LEVEL_MIN] = tmp[VDD_LEVEL_MIN]; 1470 + motg->vdd_levels[VDD_LEVEL_MAX] = tmp[VDD_LEVEL_MAX]; 1471 + } 1472 + 1473 + prop = of_find_property(node, "qcom,phy-init-sequence", &len); 1474 + if (!prop || !len) 1475 + return 0; 1476 + 1477 + words = len / sizeof(u32); 1478 + 1479 + if (words >= ULPI_EXT_VENDOR_SPECIFIC) { 1480 + dev_warn(&pdev->dev, "Too big PHY init sequence %d\n", words); 1481 + return 0; 1482 + } 1483 + 1484 + pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); 1485 + if (!pdata->phy_init_seq) { 1486 + dev_warn(&pdev->dev, "No space for PHY init sequence\n"); 1487 + return 0; 1488 + } 1489 + 1490 + ret = of_property_read_u32_array(node, "qcom,phy-init-sequence", 1491 + pdata->phy_init_seq, words); 1492 + if (!ret) 1493 + pdata->phy_init_sz = words; 1494 + 1495 + return 0; 1496 + } 1497 + 1498 + static int msm_otg_probe(struct platform_device *pdev) 1499 + { 1500 + struct regulator_bulk_data regs[3]; 1432 1501 int ret = 0; 1502 + struct device_node *np = pdev->dev.of_node; 1503 + struct msm_otg_platform_data *pdata; 1433 1504 struct resource *res; 1434 1505 struct msm_otg *motg; 1435 1506 struct usb_phy *phy; 1507 + void __iomem *phy_select; 1436 1508 1437 - dev_info(&pdev->dev, "msm_otg probe\n"); 1438 - if (!dev_get_platdata(&pdev->dev)) { 1439 - dev_err(&pdev->dev, "No platform data given. Bailing out\n"); 1440 - return -ENODEV; 1441 - } 1442 - 1443 - motg = kzalloc(sizeof(struct msm_otg), GFP_KERNEL); 1509 + motg = devm_kzalloc(&pdev->dev, sizeof(struct msm_otg), GFP_KERNEL); 1444 1510 if (!motg) { 1445 1511 dev_err(&pdev->dev, "unable to allocate msm_otg\n"); 1446 1512 return -ENOMEM; 1447 1513 } 1448 1514 1449 - motg->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); 1450 - if (!motg->phy.otg) { 1451 - dev_err(&pdev->dev, "unable to allocate msm_otg\n"); 1452 - ret = -ENOMEM; 1453 - goto free_motg; 1515 + pdata = dev_get_platdata(&pdev->dev); 1516 + if (!pdata) { 1517 + if (!np) 1518 + return -ENXIO; 1519 + ret = msm_otg_read_dt(pdev, motg); 1520 + if (ret) 1521 + return ret; 1454 1522 } 1455 1523 1456 - motg->pdata = dev_get_platdata(&pdev->dev); 1524 + motg->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), 1525 + GFP_KERNEL); 1526 + if (!motg->phy.otg) { 1527 + dev_err(&pdev->dev, "unable to allocate msm_otg\n"); 1528 + return -ENOMEM; 1529 + } 1530 + 1457 1531 phy = &motg->phy; 1458 1532 phy->dev = &pdev->dev; 1459 1533 1460 - motg->phy_reset_clk = clk_get(&pdev->dev, "usb_phy_clk"); 1534 + motg->phy_reset_clk = devm_clk_get(&pdev->dev, 1535 + np ? "phy" : "usb_phy_clk"); 1461 1536 if (IS_ERR(motg->phy_reset_clk)) { 1462 1537 dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); 1463 - ret = PTR_ERR(motg->phy_reset_clk); 1464 - goto free_motg; 1538 + return PTR_ERR(motg->phy_reset_clk); 1465 1539 } 1466 1540 1467 - motg->clk = clk_get(&pdev->dev, "usb_hs_clk"); 1541 + motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); 1468 1542 if (IS_ERR(motg->clk)) { 1469 1543 dev_err(&pdev->dev, "failed to get usb_hs_clk\n"); 1470 - ret = PTR_ERR(motg->clk); 1471 - goto put_phy_reset_clk; 1544 + return PTR_ERR(motg->clk); 1472 1545 } 1473 - clk_set_rate(motg->clk, 60000000); 1474 1546 1475 1547 /* 1476 1548 * If USB Core is running its protocol engine based on CORE CLK, 1477 1549 * CORE CLK must be running at >55Mhz for correct HSUSB 1478 1550 * operation and USB core cannot tolerate frequency changes on 1479 - * CORE CLK. For such USB cores, vote for maximum clk frequency 1480 - * on pclk source 1551 + * CORE CLK. 1481 1552 */ 1482 - if (motg->pdata->pclk_src_name) { 1483 - motg->pclk_src = clk_get(&pdev->dev, 1484 - motg->pdata->pclk_src_name); 1485 - if (IS_ERR(motg->pclk_src)) 1486 - goto put_clk; 1487 - clk_set_rate(motg->pclk_src, INT_MAX); 1488 - clk_prepare_enable(motg->pclk_src); 1489 - } else 1490 - motg->pclk_src = ERR_PTR(-ENOENT); 1491 - 1492 - 1493 - motg->pclk = clk_get(&pdev->dev, "usb_hs_pclk"); 1553 + motg->pclk = devm_clk_get(&pdev->dev, np ? "iface" : "usb_hs_pclk"); 1494 1554 if (IS_ERR(motg->pclk)) { 1495 1555 dev_err(&pdev->dev, "failed to get usb_hs_pclk\n"); 1496 - ret = PTR_ERR(motg->pclk); 1497 - goto put_pclk_src; 1556 + return PTR_ERR(motg->pclk); 1498 1557 } 1499 1558 1500 1559 /* ··· 1582 1481 * clock is introduced to remove the dependency on AXI 1583 1482 * bus frequency. 1584 1483 */ 1585 - motg->core_clk = clk_get(&pdev->dev, "usb_hs_core_clk"); 1586 - if (IS_ERR(motg->core_clk)) 1587 - motg->core_clk = NULL; 1484 + motg->core_clk = devm_clk_get(&pdev->dev, 1485 + np ? "alt_core" : "usb_hs_core_clk"); 1588 1486 1589 1487 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1590 - if (!res) { 1591 - dev_err(&pdev->dev, "failed to get platform resource mem\n"); 1592 - ret = -ENODEV; 1593 - goto put_core_clk; 1488 + motg->regs = devm_ioremap_resource(&pdev->dev, res); 1489 + if (IS_ERR(motg->regs)) 1490 + return PTR_ERR(motg->regs); 1491 + 1492 + /* 1493 + * NOTE: The PHYs can be multiplexed between the chipidea controller 1494 + * and the dwc3 controller, using a single bit. It is important that 1495 + * the dwc3 driver does not set this bit in an incompatible way. 1496 + */ 1497 + if (motg->phy_number) { 1498 + phy_select = devm_ioremap_nocache(&pdev->dev, USB2_PHY_SEL, 4); 1499 + if (IS_ERR(phy_select)) 1500 + return PTR_ERR(phy_select); 1501 + /* Enable second PHY with the OTG port */ 1502 + writel(0x1, phy_select); 1594 1503 } 1595 1504 1596 - motg->regs = ioremap(res->start, resource_size(res)); 1597 - if (!motg->regs) { 1598 - dev_err(&pdev->dev, "ioremap failed\n"); 1599 - ret = -ENOMEM; 1600 - goto put_core_clk; 1601 - } 1602 1505 dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs); 1603 1506 1604 1507 motg->irq = platform_get_irq(pdev, 0); 1605 - if (!motg->irq) { 1508 + if (motg->irq < 0) { 1606 1509 dev_err(&pdev->dev, "platform_get_irq failed\n"); 1607 - ret = -ENODEV; 1608 - goto free_regs; 1510 + return motg->irq; 1609 1511 } 1512 + 1513 + regs[0].supply = "vddcx"; 1514 + regs[1].supply = "v3p3"; 1515 + regs[2].supply = "v1p8"; 1516 + 1517 + ret = devm_regulator_bulk_get(motg->phy.dev, ARRAY_SIZE(regs), regs); 1518 + if (ret) 1519 + return ret; 1520 + 1521 + motg->vddcx = regs[0].consumer; 1522 + motg->v3p3 = regs[1].consumer; 1523 + motg->v1p8 = regs[2].consumer; 1524 + 1525 + clk_set_rate(motg->clk, 60000000); 1610 1526 1611 1527 clk_prepare_enable(motg->clk); 1612 1528 clk_prepare_enable(motg->pclk); 1613 1529 1530 + if (!IS_ERR(motg->core_clk)) 1531 + clk_prepare_enable(motg->core_clk); 1532 + 1614 1533 ret = msm_hsusb_init_vddcx(motg, 1); 1615 1534 if (ret) { 1616 1535 dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); 1617 - goto free_regs; 1536 + goto disable_clks; 1618 1537 } 1619 1538 1620 1539 ret = msm_hsusb_ldo_init(motg, 1); 1621 1540 if (ret) { 1622 1541 dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); 1623 - goto vddcx_exit; 1542 + goto disable_vddcx; 1624 1543 } 1625 - ret = msm_hsusb_ldo_set_mode(1); 1544 + ret = msm_hsusb_ldo_set_mode(motg, 1); 1626 1545 if (ret) { 1627 1546 dev_err(&pdev->dev, "hsusb vreg enable failed\n"); 1628 - goto ldo_exit; 1547 + goto disable_ldo; 1629 1548 } 1630 - 1631 - if (motg->core_clk) 1632 - clk_prepare_enable(motg->core_clk); 1633 1549 1634 1550 writel(0, USB_USBINTR); 1635 1551 writel(0, USB_OTGSC); 1636 1552 1637 1553 INIT_WORK(&motg->sm_work, msm_otg_sm_work); 1638 1554 INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work); 1639 - ret = request_irq(motg->irq, msm_otg_irq, IRQF_SHARED, 1555 + ret = devm_request_irq(&pdev->dev, motg->irq, msm_otg_irq, IRQF_SHARED, 1640 1556 "msm_otg", motg); 1641 1557 if (ret) { 1642 1558 dev_err(&pdev->dev, "request irq failed\n"); 1643 - goto disable_clks; 1559 + goto disable_ldo; 1644 1560 } 1645 1561 1646 - phy->init = msm_otg_reset; 1562 + phy->init = msm_phy_init; 1647 1563 phy->set_power = msm_otg_set_power; 1564 + phy->notify_disconnect = msm_phy_notify_disconnect; 1565 + phy->type = USB_PHY_TYPE_USB2; 1648 1566 1649 1567 phy->io_ops = &msm_otg_io_ops; 1650 1568 ··· 1671 1551 phy->otg->set_host = msm_otg_set_host; 1672 1552 phy->otg->set_peripheral = msm_otg_set_peripheral; 1673 1553 1674 - ret = usb_add_phy(&motg->phy, USB_PHY_TYPE_USB2); 1554 + msm_usb_reset(phy); 1555 + 1556 + ret = usb_add_phy_dev(&motg->phy); 1675 1557 if (ret) { 1676 1558 dev_err(&pdev->dev, "usb_add_phy failed\n"); 1677 - goto free_irq; 1559 + goto disable_ldo; 1678 1560 } 1679 1561 1680 1562 platform_set_drvdata(pdev, motg); 1681 1563 device_init_wakeup(&pdev->dev, 1); 1682 1564 1683 - if (motg->pdata->mode == USB_OTG && 1684 - motg->pdata->otg_control == OTG_USER_CONTROL) { 1565 + if (motg->pdata->mode == USB_DR_MODE_OTG && 1566 + motg->pdata->otg_control == OTG_USER_CONTROL) { 1685 1567 ret = msm_otg_debugfs_init(motg); 1686 1568 if (ret) 1687 - dev_dbg(&pdev->dev, "mode debugfs file is" 1688 - "not available\n"); 1569 + dev_dbg(&pdev->dev, "Can not create mode change file\n"); 1689 1570 } 1690 1571 1691 1572 pm_runtime_set_active(&pdev->dev); 1692 1573 pm_runtime_enable(&pdev->dev); 1693 1574 1694 1575 return 0; 1695 - free_irq: 1696 - free_irq(motg->irq, motg); 1576 + 1577 + disable_ldo: 1578 + msm_hsusb_ldo_init(motg, 0); 1579 + disable_vddcx: 1580 + msm_hsusb_init_vddcx(motg, 0); 1697 1581 disable_clks: 1698 1582 clk_disable_unprepare(motg->pclk); 1699 1583 clk_disable_unprepare(motg->clk); 1700 - ldo_exit: 1701 - msm_hsusb_ldo_init(motg, 0); 1702 - vddcx_exit: 1703 - msm_hsusb_init_vddcx(motg, 0); 1704 - free_regs: 1705 - iounmap(motg->regs); 1706 - put_core_clk: 1707 - if (motg->core_clk) 1708 - clk_put(motg->core_clk); 1709 - clk_put(motg->pclk); 1710 - put_pclk_src: 1711 - if (!IS_ERR(motg->pclk_src)) { 1712 - clk_disable_unprepare(motg->pclk_src); 1713 - clk_put(motg->pclk_src); 1714 - } 1715 - put_clk: 1716 - clk_put(motg->clk); 1717 - put_phy_reset_clk: 1718 - clk_put(motg->phy_reset_clk); 1719 - free_motg: 1720 - kfree(motg->phy.otg); 1721 - kfree(motg); 1584 + if (!IS_ERR(motg->core_clk)) 1585 + clk_disable_unprepare(motg->core_clk); 1722 1586 return ret; 1723 1587 } 1724 1588 ··· 1725 1621 pm_runtime_disable(&pdev->dev); 1726 1622 1727 1623 usb_remove_phy(phy); 1728 - free_irq(motg->irq, motg); 1624 + disable_irq(motg->irq); 1729 1625 1730 1626 /* 1731 1627 * Put PHY in low power mode. ··· 1745 1641 1746 1642 clk_disable_unprepare(motg->pclk); 1747 1643 clk_disable_unprepare(motg->clk); 1748 - if (motg->core_clk) 1644 + if (!IS_ERR(motg->core_clk)) 1749 1645 clk_disable_unprepare(motg->core_clk); 1750 - if (!IS_ERR(motg->pclk_src)) { 1751 - clk_disable_unprepare(motg->pclk_src); 1752 - clk_put(motg->pclk_src); 1753 - } 1754 1646 msm_hsusb_ldo_init(motg, 0); 1755 1647 1756 - iounmap(motg->regs); 1757 1648 pm_runtime_set_suspended(&pdev->dev); 1758 - 1759 - clk_put(motg->phy_reset_clk); 1760 - clk_put(motg->pclk); 1761 - clk_put(motg->clk); 1762 - if (motg->core_clk) 1763 - clk_put(motg->core_clk); 1764 - 1765 - kfree(motg->phy.otg); 1766 - kfree(motg); 1767 1649 1768 1650 return 0; 1769 1651 } ··· 1830 1740 }; 1831 1741 1832 1742 static struct platform_driver msm_otg_driver = { 1743 + .probe = msm_otg_probe, 1833 1744 .remove = msm_otg_remove, 1834 1745 .driver = { 1835 1746 .name = DRIVER_NAME, 1836 1747 .owner = THIS_MODULE, 1837 1748 .pm = &msm_otg_dev_pm_ops, 1749 + .of_match_table = msm_otg_dt_match, 1838 1750 }, 1839 1751 }; 1840 1752 1841 - module_platform_driver_probe(msm_otg_driver, msm_otg_probe); 1753 + module_platform_driver(msm_otg_driver); 1842 1754 1843 1755 MODULE_LICENSE("GPL v2"); 1844 1756 MODULE_DESCRIPTION("MSM USB transceiver driver");
+1
drivers/usb/phy/phy-ulpi.c
··· 48 48 ULPI_INFO(ULPI_ID(0x04cc, 0x1504), "NXP ISP1504"), 49 49 ULPI_INFO(ULPI_ID(0x0424, 0x0006), "SMSC USB331x"), 50 50 ULPI_INFO(ULPI_ID(0x0424, 0x0007), "SMSC USB3320"), 51 + ULPI_INFO(ULPI_ID(0x0424, 0x0009), "SMSC USB334x"), 51 52 ULPI_INFO(ULPI_ID(0x0451, 0x1507), "TI TUSB1210"), 52 53 }; 53 54
+79
include/linux/usb/composite.h
··· 57 57 struct usb_configuration; 58 58 59 59 /** 60 + * struct usb_os_desc_ext_prop - describes one "Extended Property" 61 + * @entry: used to keep a list of extended properties 62 + * @type: Extended Property type 63 + * @name_len: Extended Property unicode name length, including terminating '\0' 64 + * @name: Extended Property name 65 + * @data_len: Length of Extended Property blob (for unicode store double len) 66 + * @data: Extended Property blob 67 + * @item: Represents this Extended Property in configfs 68 + */ 69 + struct usb_os_desc_ext_prop { 70 + struct list_head entry; 71 + u8 type; 72 + int name_len; 73 + char *name; 74 + int data_len; 75 + char *data; 76 + struct config_item item; 77 + }; 78 + 79 + /** 80 + * struct usb_os_desc - describes OS descriptors associated with one interface 81 + * @ext_compat_id: 16 bytes of "Compatible ID" and "Subcompatible ID" 82 + * @ext_prop: Extended Properties list 83 + * @ext_prop_len: Total length of Extended Properties blobs 84 + * @ext_prop_count: Number of Extended Properties 85 + * @opts_mutex: Optional mutex protecting config data of a usb_function_instance 86 + * @group: Represents OS descriptors associated with an interface in configfs 87 + * @owner: Module associated with this OS descriptor 88 + */ 89 + struct usb_os_desc { 90 + char *ext_compat_id; 91 + struct list_head ext_prop; 92 + int ext_prop_len; 93 + int ext_prop_count; 94 + struct mutex *opts_mutex; 95 + struct config_group group; 96 + struct module *owner; 97 + }; 98 + 99 + /** 100 + * struct usb_os_desc_table - describes OS descriptors associated with one 101 + * interface of a usb_function 102 + * @if_id: Interface id 103 + * @os_desc: "Extended Compatibility ID" and "Extended Properties" of the 104 + * interface 105 + * 106 + * Each interface can have at most one "Extended Compatibility ID" and a 107 + * number of "Extended Properties". 108 + */ 109 + struct usb_os_desc_table { 110 + int if_id; 111 + struct usb_os_desc *os_desc; 112 + }; 113 + 114 + /** 60 115 * struct usb_function - describes one function of a configuration 61 116 * @name: For diagnostics, identifies the function. 62 117 * @strings: tables of strings, keyed by identifiers assigned during bind() ··· 128 73 * be available at super speed. 129 74 * @config: assigned when @usb_add_function() is called; this is the 130 75 * configuration with which this function is associated. 76 + * @os_desc_table: Table of (interface id, os descriptors) pairs. The function 77 + * can expose more than one interface. If an interface is a member of 78 + * an IAD, only the first interface of IAD has its entry in the table. 79 + * @os_desc_n: Number of entries in os_desc_table 131 80 * @bind: Before the gadget can register, all of its functions bind() to the 132 81 * available resources including string and interface identifiers used 133 82 * in interface or class descriptors; endpoints; I/O buffers; and so on. ··· 187 128 struct usb_descriptor_header **ss_descriptors; 188 129 189 130 struct usb_configuration *config; 131 + 132 + struct usb_os_desc_table *os_desc_table; 133 + unsigned os_desc_n; 190 134 191 135 /* REVISIT: bind() functions can be marked __init, which 192 136 * makes trouble for section mismatch analysis. See if ··· 389 327 extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); 390 328 extern int composite_dev_prepare(struct usb_composite_driver *composite, 391 329 struct usb_composite_dev *cdev); 330 + extern int composite_os_desc_req_prepare(struct usb_composite_dev *cdev, 331 + struct usb_ep *ep0); 392 332 void composite_dev_cleanup(struct usb_composite_dev *cdev); 393 333 394 334 static inline struct usb_composite_driver *to_cdriver( ··· 399 335 return container_of(gdrv, struct usb_composite_driver, gadget_driver); 400 336 } 401 337 338 + #define OS_STRING_QW_SIGN_LEN 14 339 + #define OS_STRING_IDX 0xEE 340 + 402 341 /** 403 342 * struct usb_composite_device - represents one composite usb gadget 404 343 * @gadget: read-only, abstracts the gadget's usb peripheral controller 405 344 * @req: used for control responses; buffer is pre-allocated 345 + * @os_desc_req: used for OS descriptors responses; buffer is pre-allocated 406 346 * @config: the currently active configuration 347 + * @qw_sign: qwSignature part of the OS string 348 + * @b_vendor_code: bMS_VendorCode part of the OS string 349 + * @use_os_string: false by default, interested gadgets set it 350 + * @os_desc_config: the configuration to be used with OS descriptors 407 351 * 408 352 * One of these devices is allocated and initialized before the 409 353 * associated device driver's bind() is called. ··· 441 369 struct usb_composite_dev { 442 370 struct usb_gadget *gadget; 443 371 struct usb_request *req; 372 + struct usb_request *os_desc_req; 444 373 445 374 struct usb_configuration *config; 375 + 376 + /* OS String is a custom (yet popular) extension to the USB standard. */ 377 + u8 qw_sign[OS_STRING_QW_SIGN_LEN]; 378 + u8 b_vendor_code; 379 + struct usb_configuration *os_desc_config; 380 + unsigned int use_os_string:1; 446 381 447 382 /* private: */ 448 383 /* internals */
+13 -26
include/linux/usb/msm_hsusb.h
··· 23 23 #include <linux/clk.h> 24 24 25 25 /** 26 - * Supported USB modes 27 - * 28 - * USB_PERIPHERAL Only peripheral mode is supported. 29 - * USB_HOST Only host mode is supported. 30 - * USB_OTG OTG mode is supported. 31 - * 32 - */ 33 - enum usb_mode_type { 34 - USB_NONE = 0, 35 - USB_PERIPHERAL, 36 - USB_HOST, 37 - USB_OTG, 38 - }; 39 - 40 - /** 41 26 * OTG control 42 27 * 43 28 * OTG_NO_CONTROL Id/VBUS notifications not required. Useful in host ··· 100 115 /** 101 116 * struct msm_otg_platform_data - platform device data 102 117 * for msm_otg driver. 103 - * @phy_init_seq: PHY configuration sequence. val, reg pairs 104 - * terminated by -1. 118 + * @phy_init_seq: PHY configuration sequence values. Value of -1 is reserved as 119 + * "do not overwrite default vaule at this address". 120 + * @phy_init_sz: PHY configuration sequence size. 105 121 * @vbus_power: VBUS power on/off routine. 106 122 * @power_budget: VBUS power budget in mA (0 will be treated as 500mA). 107 123 * @mode: Supported mode (OTG/peripheral/host). 108 124 * @otg_control: OTG switch controlled by user/Id pin 109 - * @default_mode: Default operational mode. Applicable only if 110 - * OTG switch is controller by user. 111 - * @pclk_src_name: pclk is derived from ebi1_usb_clk in case of 7x27 and 8k 112 - * dfab_usb_hs_clk in case of 8660 and 8960. 113 125 */ 114 126 struct msm_otg_platform_data { 115 127 int *phy_init_seq; 128 + int phy_init_sz; 116 129 void (*vbus_power)(bool on); 117 130 unsigned power_budget; 118 - enum usb_mode_type mode; 131 + enum usb_dr_mode mode; 119 132 enum otg_control_type otg_control; 120 - enum usb_mode_type default_mode; 121 133 enum msm_usb_phy_type phy_type; 122 134 void (*setup_gpio)(enum usb_otg_state state); 123 - char *pclk_src_name; 124 135 int (*link_clk_reset)(struct clk *link_clk, bool assert); 125 136 int (*phy_clk_reset)(struct clk *phy_clk); 126 137 }; ··· 128 147 * @irq: IRQ number assigned for HSUSB controller. 129 148 * @clk: clock struct of usb_hs_clk. 130 149 * @pclk: clock struct of usb_hs_pclk. 131 - * @pclk_src: pclk source for voting. 132 150 * @phy_reset_clk: clock struct of usb_phy_clk. 133 151 * @core_clk: clock struct of usb_hs_core_clk. 134 152 * @regs: ioremapped register base address. ··· 148 168 int irq; 149 169 struct clk *clk; 150 170 struct clk *pclk; 151 - struct clk *pclk_src; 152 171 struct clk *phy_reset_clk; 153 172 struct clk *core_clk; 154 173 void __iomem *regs; ··· 158 179 atomic_t in_lpm; 159 180 int async_int; 160 181 unsigned cur_power; 182 + int phy_number; 161 183 struct delayed_work chg_work; 162 184 enum usb_chg_state chg_state; 163 185 enum usb_chg_type chg_type; 164 186 u8 dcd_retries; 187 + struct regulator *v3p3; 188 + struct regulator *v1p8; 189 + struct regulator *vddcx; 190 + 191 + struct reset_control *phy_rst; 192 + struct reset_control *link_rst; 193 + int vdd_levels[3]; 165 194 }; 166 195 167 196 #endif
+12 -2
include/linux/usb/msm_hsusb_hw.h
··· 16 16 #ifndef __LINUX_USB_GADGET_MSM72K_UDC_H__ 17 17 #define __LINUX_USB_GADGET_MSM72K_UDC_H__ 18 18 19 + /* USB phy selector - in TCSR address range */ 20 + #define USB2_PHY_SEL 0xfd4ab000 21 + 19 22 #define USB_AHBBURST (MSM_USB_BASE + 0x0090) 20 23 #define USB_AHBMODE (MSM_USB_BASE + 0x0098) 21 24 #define USB_CAPLENGTH (MSM_USB_BASE + 0x0100) /* 8 bit */ ··· 28 25 #define USB_OTGSC (MSM_USB_BASE + 0x01A4) 29 26 #define USB_USBMODE (MSM_USB_BASE + 0x01A8) 30 27 #define USB_PHY_CTRL (MSM_USB_BASE + 0x0240) 28 + #define USB_PHY_CTRL2 (MSM_USB_BASE + 0x0278) 31 29 32 30 #define USBCMD_RESET 2 33 31 #define USB_USBINTR (MSM_USB_BASE + 0x0148) 34 32 35 33 #define PORTSC_PHCD (1 << 23) /* phy suspend mode */ 36 - #define PORTSC_PTS_MASK (3 << 30) 37 - #define PORTSC_PTS_ULPI (3 << 30) 34 + #define PORTSC_PTS_MASK (3 << 30) 35 + #define PORTSC_PTS_ULPI (2 << 30) 36 + #define PORTSC_PTS_SERIAL (3 << 30) 38 37 39 38 #define USB_ULPI_VIEWPORT (MSM_USB_BASE + 0x0170) 40 39 #define ULPI_RUN (1 << 30) ··· 46 41 #define ULPI_DATA(n) ((n) & 255) 47 42 #define ULPI_DATA_READ(n) (((n) >> 8) & 255) 48 43 44 + /* synopsys 28nm phy registers */ 45 + #define ULPI_PWR_CLK_MNG_REG 0x88 46 + #define OTG_COMP_DISABLE BIT(0) 47 + 49 48 #define ASYNC_INTR_CTRL (1 << 29) /* Enable async interrupt */ 50 49 #define ULPI_STP_CTRL (1 << 30) /* Block communication with PHY */ 51 50 #define PHY_RETEN (1 << 1) /* PHY retention enable/disable */ 51 + #define PHY_POR_ASSERT (1 << 0) /* USB2 28nm PHY POR ASSERT */ 52 52 53 53 /* OTG definitions */ 54 54 #define OTGSC_INTSTS_MASK (0x7f << 16)
+7 -6
include/linux/usb/usb_phy_gen_xceiv.h include/linux/usb/usb_phy_generic.h
··· 3 3 4 4 #include <linux/usb/otg.h> 5 5 6 - struct usb_phy_gen_xceiv_platform_data { 6 + struct usb_phy_generic_platform_data { 7 7 enum usb_phy_type type; 8 8 unsigned long clk_rate; 9 9 ··· 13 13 int gpio_reset; 14 14 }; 15 15 16 - #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) 16 + #if IS_ENABLED(CONFIG_NOP_USB_XCEIV) 17 17 /* sometimes transceivers are accessed only through e.g. ULPI */ 18 - extern void usb_nop_xceiv_register(void); 19 - extern void usb_nop_xceiv_unregister(void); 18 + extern struct platform_device *usb_phy_generic_register(void); 19 + extern void usb_phy_generic_unregister(struct platform_device *); 20 20 #else 21 - static inline void usb_nop_xceiv_register(void) 21 + static inline struct platform_device *usb_phy_generic_register(void) 22 22 { 23 + return NULL; 23 24 } 24 25 25 - static inline void usb_nop_xceiv_unregister(void) 26 + static inline void usb_phy_generic_unregister(struct platform_device *pdev) 26 27 { 27 28 } 28 29 #endif
+349
tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c
··· 1 + #define _BSD_SOURCE /* for endian.h */ 2 + 3 + #include <endian.h> 4 + #include <errno.h> 5 + #include <fcntl.h> 6 + #include <stdarg.h> 7 + #include <stdio.h> 8 + #include <stdlib.h> 9 + #include <string.h> 10 + #include <sys/ioctl.h> 11 + #include <sys/stat.h> 12 + #include <sys/types.h> 13 + #include <sys/poll.h> 14 + #include <unistd.h> 15 + #include <stdbool.h> 16 + #include <sys/eventfd.h> 17 + 18 + #include "libaio.h" 19 + #define IOCB_FLAG_RESFD (1 << 0) 20 + 21 + #include <linux/usb/functionfs.h> 22 + 23 + #define BUF_LEN 8192 24 + #define BUFS_MAX 128 25 + #define AIO_MAX (BUFS_MAX*2) 26 + 27 + /******************** Descriptors and Strings *******************************/ 28 + 29 + static const struct { 30 + struct usb_functionfs_descs_head header; 31 + struct { 32 + struct usb_interface_descriptor intf; 33 + struct usb_endpoint_descriptor_no_audio bulk_sink; 34 + struct usb_endpoint_descriptor_no_audio bulk_source; 35 + } __attribute__ ((__packed__)) fs_descs, hs_descs; 36 + } __attribute__ ((__packed__)) descriptors = { 37 + .header = { 38 + .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC), 39 + .length = htole32(sizeof(descriptors)), 40 + .fs_count = 3, 41 + .hs_count = 3, 42 + }, 43 + .fs_descs = { 44 + .intf = { 45 + .bLength = sizeof(descriptors.fs_descs.intf), 46 + .bDescriptorType = USB_DT_INTERFACE, 47 + .bNumEndpoints = 2, 48 + .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 49 + .iInterface = 1, 50 + }, 51 + .bulk_sink = { 52 + .bLength = sizeof(descriptors.fs_descs.bulk_sink), 53 + .bDescriptorType = USB_DT_ENDPOINT, 54 + .bEndpointAddress = 1 | USB_DIR_IN, 55 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 56 + }, 57 + .bulk_source = { 58 + .bLength = sizeof(descriptors.fs_descs.bulk_source), 59 + .bDescriptorType = USB_DT_ENDPOINT, 60 + .bEndpointAddress = 2 | USB_DIR_OUT, 61 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 62 + }, 63 + }, 64 + .hs_descs = { 65 + .intf = { 66 + .bLength = sizeof(descriptors.hs_descs.intf), 67 + .bDescriptorType = USB_DT_INTERFACE, 68 + .bNumEndpoints = 2, 69 + .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 70 + .iInterface = 1, 71 + }, 72 + .bulk_sink = { 73 + .bLength = sizeof(descriptors.hs_descs.bulk_sink), 74 + .bDescriptorType = USB_DT_ENDPOINT, 75 + .bEndpointAddress = 1 | USB_DIR_IN, 76 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 77 + .wMaxPacketSize = htole16(512), 78 + }, 79 + .bulk_source = { 80 + .bLength = sizeof(descriptors.hs_descs.bulk_source), 81 + .bDescriptorType = USB_DT_ENDPOINT, 82 + .bEndpointAddress = 2 | USB_DIR_OUT, 83 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 84 + .wMaxPacketSize = htole16(512), 85 + }, 86 + }, 87 + }; 88 + 89 + #define STR_INTERFACE "AIO Test" 90 + 91 + static const struct { 92 + struct usb_functionfs_strings_head header; 93 + struct { 94 + __le16 code; 95 + const char str1[sizeof(STR_INTERFACE)]; 96 + } __attribute__ ((__packed__)) lang0; 97 + } __attribute__ ((__packed__)) strings = { 98 + .header = { 99 + .magic = htole32(FUNCTIONFS_STRINGS_MAGIC), 100 + .length = htole32(sizeof(strings)), 101 + .str_count = htole32(1), 102 + .lang_count = htole32(1), 103 + }, 104 + .lang0 = { 105 + htole16(0x0409), /* en-us */ 106 + STR_INTERFACE, 107 + }, 108 + }; 109 + 110 + /********************** Buffer structure *******************************/ 111 + 112 + struct io_buffer { 113 + struct iocb **iocb; 114 + unsigned char **buf; 115 + unsigned cnt; 116 + unsigned len; 117 + unsigned requested; 118 + }; 119 + 120 + /******************** Endpoints handling *******************************/ 121 + 122 + static void display_event(struct usb_functionfs_event *event) 123 + { 124 + static const char *const names[] = { 125 + [FUNCTIONFS_BIND] = "BIND", 126 + [FUNCTIONFS_UNBIND] = "UNBIND", 127 + [FUNCTIONFS_ENABLE] = "ENABLE", 128 + [FUNCTIONFS_DISABLE] = "DISABLE", 129 + [FUNCTIONFS_SETUP] = "SETUP", 130 + [FUNCTIONFS_SUSPEND] = "SUSPEND", 131 + [FUNCTIONFS_RESUME] = "RESUME", 132 + }; 133 + switch (event->type) { 134 + case FUNCTIONFS_BIND: 135 + case FUNCTIONFS_UNBIND: 136 + case FUNCTIONFS_ENABLE: 137 + case FUNCTIONFS_DISABLE: 138 + case FUNCTIONFS_SETUP: 139 + case FUNCTIONFS_SUSPEND: 140 + case FUNCTIONFS_RESUME: 141 + printf("Event %s\n", names[event->type]); 142 + } 143 + } 144 + 145 + static void handle_ep0(int ep0, bool *ready) 146 + { 147 + int ret; 148 + struct usb_functionfs_event event; 149 + 150 + ret = read(ep0, &event, sizeof(event)); 151 + if (!ret) { 152 + perror("unable to read event from ep0"); 153 + return; 154 + } 155 + display_event(&event); 156 + switch (event.type) { 157 + case FUNCTIONFS_SETUP: 158 + if (event.u.setup.bRequestType & USB_DIR_IN) 159 + write(ep0, NULL, 0); 160 + else 161 + read(ep0, NULL, 0); 162 + break; 163 + 164 + case FUNCTIONFS_ENABLE: 165 + *ready = true; 166 + break; 167 + 168 + case FUNCTIONFS_DISABLE: 169 + *ready = false; 170 + break; 171 + 172 + default: 173 + break; 174 + } 175 + } 176 + 177 + void init_bufs(struct io_buffer *iobuf, unsigned n, unsigned len) 178 + { 179 + unsigned i; 180 + iobuf->buf = malloc(n*sizeof(*iobuf->buf)); 181 + iobuf->iocb = malloc(n*sizeof(*iobuf->iocb)); 182 + iobuf->cnt = n; 183 + iobuf->len = len; 184 + iobuf->requested = 0; 185 + for (i = 0; i < n; ++i) { 186 + iobuf->buf[i] = malloc(len*sizeof(**iobuf->buf)); 187 + iobuf->iocb[i] = malloc(sizeof(**iobuf->iocb)); 188 + } 189 + iobuf->cnt = n; 190 + } 191 + 192 + void delete_bufs(struct io_buffer *iobuf) 193 + { 194 + unsigned i; 195 + for (i = 0; i < iobuf->cnt; ++i) { 196 + free(iobuf->buf[i]); 197 + free(iobuf->iocb[i]); 198 + } 199 + free(iobuf->buf); 200 + free(iobuf->iocb); 201 + } 202 + 203 + int main(int argc, char *argv[]) 204 + { 205 + int ret; 206 + unsigned i, j; 207 + char *ep_path; 208 + 209 + int ep0, ep1; 210 + 211 + io_context_t ctx; 212 + 213 + int evfd; 214 + fd_set rfds; 215 + 216 + struct io_buffer iobuf[2]; 217 + int actual = 0; 218 + bool ready; 219 + 220 + if (argc != 2) { 221 + printf("ffs directory not specified!\n"); 222 + return 1; 223 + } 224 + 225 + ep_path = malloc(strlen(argv[1]) + 4 /* "/ep#" */ + 1 /* '\0' */); 226 + if (!ep_path) { 227 + perror("malloc"); 228 + return 1; 229 + } 230 + 231 + /* open endpoint files */ 232 + sprintf(ep_path, "%s/ep0", argv[1]); 233 + ep0 = open(ep_path, O_RDWR); 234 + if (ep0 < 0) { 235 + perror("unable to open ep0"); 236 + return 1; 237 + } 238 + if (write(ep0, &descriptors, sizeof(descriptors)) < 0) { 239 + perror("unable do write descriptors"); 240 + return 1; 241 + } 242 + if (write(ep0, &strings, sizeof(strings)) < 0) { 243 + perror("unable to write strings"); 244 + return 1; 245 + } 246 + sprintf(ep_path, "%s/ep1", argv[1]); 247 + ep1 = open(ep_path, O_RDWR); 248 + if (ep1 < 0) { 249 + perror("unable to open ep1"); 250 + return 1; 251 + } 252 + 253 + free(ep_path); 254 + 255 + memset(&ctx, 0, sizeof(ctx)); 256 + /* setup aio context to handle up to AIO_MAX requests */ 257 + if (io_setup(AIO_MAX, &ctx) < 0) { 258 + perror("unable to setup aio"); 259 + return 1; 260 + } 261 + 262 + evfd = eventfd(0, 0); 263 + if (evfd < 0) { 264 + perror("unable to open eventfd"); 265 + return 1; 266 + } 267 + 268 + for (i = 0; i < sizeof(iobuf)/sizeof(*iobuf); ++i) 269 + init_bufs(&iobuf[i], BUFS_MAX, BUF_LEN); 270 + 271 + while (1) { 272 + FD_ZERO(&rfds); 273 + FD_SET(ep0, &rfds); 274 + FD_SET(evfd, &rfds); 275 + 276 + ret = select(((ep0 > evfd) ? ep0 : evfd)+1, 277 + &rfds, NULL, NULL, NULL); 278 + if (ret < 0) { 279 + if (errno == EINTR) 280 + continue; 281 + perror("select"); 282 + break; 283 + } 284 + 285 + if (FD_ISSET(ep0, &rfds)) 286 + handle_ep0(ep0, &ready); 287 + 288 + /* we are waiting for function ENABLE */ 289 + if (!ready) 290 + continue; 291 + 292 + /* 293 + * when we're preparing new data to submit, 294 + * second buffer being transmitted 295 + */ 296 + for (i = 0; i < sizeof(iobuf)/sizeof(*iobuf); ++i) { 297 + if (iobuf[i].requested) 298 + continue; 299 + /* prepare requests */ 300 + for (j = 0; j < iobuf[i].cnt; ++j) { 301 + io_prep_pwrite(iobuf[i].iocb[j], ep1, 302 + iobuf[i].buf[j], 303 + iobuf[i].len, 0); 304 + /* enable eventfd notification */ 305 + iobuf[i].iocb[j]->u.c.flags |= IOCB_FLAG_RESFD; 306 + iobuf[i].iocb[j]->u.c.resfd = evfd; 307 + } 308 + /* submit table of requests */ 309 + ret = io_submit(ctx, iobuf[i].cnt, iobuf[i].iocb); 310 + if (ret >= 0) { 311 + iobuf[i].requested = ret; 312 + printf("submit: %d requests buf: %d\n", ret, i); 313 + } else 314 + perror("unable to submit reqests"); 315 + } 316 + 317 + /* if event is ready to read */ 318 + if (!FD_ISSET(evfd, &rfds)) 319 + continue; 320 + 321 + uint64_t ev_cnt; 322 + ret = read(evfd, &ev_cnt, sizeof(ev_cnt)); 323 + if (ret < 0) { 324 + perror("unable to read eventfd"); 325 + break; 326 + } 327 + 328 + struct io_event e[BUFS_MAX]; 329 + /* we read aio events */ 330 + ret = io_getevents(ctx, 1, BUFS_MAX, e, NULL); 331 + if (ret > 0) /* if we got events */ 332 + iobuf[actual].requested -= ret; 333 + 334 + /* if all req's from iocb completed */ 335 + if (!iobuf[actual].requested) 336 + actual = (actual + 1)%(sizeof(iobuf)/sizeof(*iobuf)); 337 + } 338 + 339 + /* free resources */ 340 + 341 + for (i = 0; i < sizeof(iobuf)/sizeof(*iobuf); ++i) 342 + delete_bufs(&iobuf[i]); 343 + io_destroy(ctx); 344 + 345 + close(ep1); 346 + close(ep0); 347 + 348 + return 0; 349 + }
+13
tools/usb/ffs-aio-example/multibuff/host_app/Makefile
··· 1 + CC = gcc 2 + LIBUSB_CFLAGS = $(shell pkg-config --cflags libusb-1.0) 3 + LIBUSB_LIBS = $(shell pkg-config --libs libusb-1.0) 4 + WARNINGS = -Wall -Wextra 5 + CFLAGS = $(LIBUSB_CFLAGS) $(WARNINGS) 6 + LDFLAGS = $(LIBUSB_LIBS) 7 + 8 + all: test 9 + %: %.c 10 + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) 11 + 12 + clean: 13 + $(RM) test
+146
tools/usb/ffs-aio-example/multibuff/host_app/test.c
··· 1 + #include <libusb.h> 2 + #include <stdio.h> 3 + #include <string.h> 4 + #include <unistd.h> 5 + 6 + #define VENDOR 0x1d6b 7 + #define PRODUCT 0x0105 8 + 9 + /* endpoints indexes */ 10 + 11 + #define EP_BULK_IN (1 | LIBUSB_ENDPOINT_IN) 12 + #define EP_BULK_OUT (2 | LIBUSB_ENDPOINT_OUT) 13 + 14 + #define BUF_LEN 8192 15 + 16 + /* 17 + * struct test_state - describes test program state 18 + * @list: list of devices returned by libusb_get_device_list function 19 + * @found: pointer to struct describing tested device 20 + * @ctx: context, set to NULL 21 + * @handle: handle of tested device 22 + * @attached: indicates that device was attached to kernel, and has to be 23 + * reattached at the end of test program 24 + */ 25 + 26 + struct test_state { 27 + libusb_device *found; 28 + libusb_context *ctx; 29 + libusb_device_handle *handle; 30 + int attached; 31 + }; 32 + 33 + /* 34 + * test_init - initialize test program 35 + */ 36 + 37 + int test_init(struct test_state *state) 38 + { 39 + int i, ret; 40 + ssize_t cnt; 41 + libusb_device **list; 42 + 43 + state->found = NULL; 44 + state->ctx = NULL; 45 + state->handle = NULL; 46 + state->attached = 0; 47 + 48 + ret = libusb_init(&state->ctx); 49 + if (ret) { 50 + printf("cannot init libusb: %s\n", libusb_error_name(ret)); 51 + return 1; 52 + } 53 + 54 + cnt = libusb_get_device_list(state->ctx, &list); 55 + if (cnt <= 0) { 56 + printf("no devices found\n"); 57 + goto error1; 58 + } 59 + 60 + for (i = 0; i < cnt; ++i) { 61 + libusb_device *dev = list[i]; 62 + struct libusb_device_descriptor desc; 63 + ret = libusb_get_device_descriptor(dev, &desc); 64 + if (ret) { 65 + printf("unable to get device descriptor: %s\n", 66 + libusb_error_name(ret)); 67 + goto error2; 68 + } 69 + if (desc.idVendor == VENDOR && desc.idProduct == PRODUCT) { 70 + state->found = dev; 71 + break; 72 + } 73 + } 74 + 75 + if (!state->found) { 76 + printf("no devices found\n"); 77 + goto error2; 78 + } 79 + 80 + ret = libusb_open(state->found, &state->handle); 81 + if (ret) { 82 + printf("cannot open device: %s\n", libusb_error_name(ret)); 83 + goto error2; 84 + } 85 + 86 + if (libusb_claim_interface(state->handle, 0)) { 87 + ret = libusb_detach_kernel_driver(state->handle, 0); 88 + if (ret) { 89 + printf("unable to detach kernel driver: %s\n", 90 + libusb_error_name(ret)); 91 + goto error3; 92 + } 93 + state->attached = 1; 94 + ret = libusb_claim_interface(state->handle, 0); 95 + if (ret) { 96 + printf("cannot claim interface: %s\n", 97 + libusb_error_name(ret)); 98 + goto error4; 99 + } 100 + } 101 + 102 + return 0; 103 + 104 + error4: 105 + if (state->attached == 1) 106 + libusb_attach_kernel_driver(state->handle, 0); 107 + 108 + error3: 109 + libusb_close(state->handle); 110 + 111 + error2: 112 + libusb_free_device_list(list, 1); 113 + 114 + error1: 115 + libusb_exit(state->ctx); 116 + return 1; 117 + } 118 + 119 + /* 120 + * test_exit - cleanup test program 121 + */ 122 + 123 + void test_exit(struct test_state *state) 124 + { 125 + libusb_release_interface(state->handle, 0); 126 + if (state->attached == 1) 127 + libusb_attach_kernel_driver(state->handle, 0); 128 + libusb_close(state->handle); 129 + libusb_exit(state->ctx); 130 + } 131 + 132 + int main(void) 133 + { 134 + struct test_state state; 135 + 136 + if (test_init(&state)) 137 + return 1; 138 + 139 + while (1) { 140 + static unsigned char buffer[BUF_LEN]; 141 + int bytes; 142 + libusb_bulk_transfer(state.handle, EP_BULK_IN, buffer, BUF_LEN, 143 + &bytes, 500); 144 + } 145 + test_exit(&state); 146 + }
+335
tools/usb/ffs-aio-example/simple/device_app/aio_simple.c
··· 1 + #define _BSD_SOURCE /* for endian.h */ 2 + 3 + #include <endian.h> 4 + #include <errno.h> 5 + #include <fcntl.h> 6 + #include <stdarg.h> 7 + #include <stdio.h> 8 + #include <stdlib.h> 9 + #include <string.h> 10 + #include <sys/ioctl.h> 11 + #include <sys/stat.h> 12 + #include <sys/types.h> 13 + #include <sys/poll.h> 14 + #include <unistd.h> 15 + #include <stdbool.h> 16 + #include <sys/eventfd.h> 17 + 18 + #include "libaio.h" 19 + #define IOCB_FLAG_RESFD (1 << 0) 20 + 21 + #include <linux/usb/functionfs.h> 22 + 23 + #define BUF_LEN 8192 24 + 25 + /******************** Descriptors and Strings *******************************/ 26 + 27 + static const struct { 28 + struct usb_functionfs_descs_head header; 29 + struct { 30 + struct usb_interface_descriptor intf; 31 + struct usb_endpoint_descriptor_no_audio bulk_sink; 32 + struct usb_endpoint_descriptor_no_audio bulk_source; 33 + } __attribute__ ((__packed__)) fs_descs, hs_descs; 34 + } __attribute__ ((__packed__)) descriptors = { 35 + .header = { 36 + .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC), 37 + .length = htole32(sizeof(descriptors)), 38 + .fs_count = 3, 39 + .hs_count = 3, 40 + }, 41 + .fs_descs = { 42 + .intf = { 43 + .bLength = sizeof(descriptors.fs_descs.intf), 44 + .bDescriptorType = USB_DT_INTERFACE, 45 + .bNumEndpoints = 2, 46 + .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 47 + .iInterface = 1, 48 + }, 49 + .bulk_sink = { 50 + .bLength = sizeof(descriptors.fs_descs.bulk_sink), 51 + .bDescriptorType = USB_DT_ENDPOINT, 52 + .bEndpointAddress = 1 | USB_DIR_IN, 53 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 54 + }, 55 + .bulk_source = { 56 + .bLength = sizeof(descriptors.fs_descs.bulk_source), 57 + .bDescriptorType = USB_DT_ENDPOINT, 58 + .bEndpointAddress = 2 | USB_DIR_OUT, 59 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 60 + }, 61 + }, 62 + .hs_descs = { 63 + .intf = { 64 + .bLength = sizeof(descriptors.hs_descs.intf), 65 + .bDescriptorType = USB_DT_INTERFACE, 66 + .bNumEndpoints = 2, 67 + .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 68 + .iInterface = 1, 69 + }, 70 + .bulk_sink = { 71 + .bLength = sizeof(descriptors.hs_descs.bulk_sink), 72 + .bDescriptorType = USB_DT_ENDPOINT, 73 + .bEndpointAddress = 1 | USB_DIR_IN, 74 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 75 + }, 76 + .bulk_source = { 77 + .bLength = sizeof(descriptors.hs_descs.bulk_source), 78 + .bDescriptorType = USB_DT_ENDPOINT, 79 + .bEndpointAddress = 2 | USB_DIR_OUT, 80 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 81 + }, 82 + }, 83 + }; 84 + 85 + #define STR_INTERFACE "AIO Test" 86 + 87 + static const struct { 88 + struct usb_functionfs_strings_head header; 89 + struct { 90 + __le16 code; 91 + const char str1[sizeof(STR_INTERFACE)]; 92 + } __attribute__ ((__packed__)) lang0; 93 + } __attribute__ ((__packed__)) strings = { 94 + .header = { 95 + .magic = htole32(FUNCTIONFS_STRINGS_MAGIC), 96 + .length = htole32(sizeof(strings)), 97 + .str_count = htole32(1), 98 + .lang_count = htole32(1), 99 + }, 100 + .lang0 = { 101 + htole16(0x0409), /* en-us */ 102 + STR_INTERFACE, 103 + }, 104 + }; 105 + 106 + /******************** Endpoints handling *******************************/ 107 + 108 + static void display_event(struct usb_functionfs_event *event) 109 + { 110 + static const char *const names[] = { 111 + [FUNCTIONFS_BIND] = "BIND", 112 + [FUNCTIONFS_UNBIND] = "UNBIND", 113 + [FUNCTIONFS_ENABLE] = "ENABLE", 114 + [FUNCTIONFS_DISABLE] = "DISABLE", 115 + [FUNCTIONFS_SETUP] = "SETUP", 116 + [FUNCTIONFS_SUSPEND] = "SUSPEND", 117 + [FUNCTIONFS_RESUME] = "RESUME", 118 + }; 119 + switch (event->type) { 120 + case FUNCTIONFS_BIND: 121 + case FUNCTIONFS_UNBIND: 122 + case FUNCTIONFS_ENABLE: 123 + case FUNCTIONFS_DISABLE: 124 + case FUNCTIONFS_SETUP: 125 + case FUNCTIONFS_SUSPEND: 126 + case FUNCTIONFS_RESUME: 127 + printf("Event %s\n", names[event->type]); 128 + } 129 + } 130 + 131 + static void handle_ep0(int ep0, bool *ready) 132 + { 133 + struct usb_functionfs_event event; 134 + int ret; 135 + 136 + struct pollfd pfds[1]; 137 + pfds[0].fd = ep0; 138 + pfds[0].events = POLLIN; 139 + 140 + ret = poll(pfds, 1, 0); 141 + 142 + if (ret && (pfds[0].revents & POLLIN)) { 143 + ret = read(ep0, &event, sizeof(event)); 144 + if (!ret) { 145 + perror("unable to read event from ep0"); 146 + return; 147 + } 148 + display_event(&event); 149 + switch (event.type) { 150 + case FUNCTIONFS_SETUP: 151 + if (event.u.setup.bRequestType & USB_DIR_IN) 152 + write(ep0, NULL, 0); 153 + else 154 + read(ep0, NULL, 0); 155 + break; 156 + 157 + case FUNCTIONFS_ENABLE: 158 + *ready = true; 159 + break; 160 + 161 + case FUNCTIONFS_DISABLE: 162 + *ready = false; 163 + break; 164 + 165 + default: 166 + break; 167 + } 168 + } 169 + } 170 + 171 + int main(int argc, char *argv[]) 172 + { 173 + int i, ret; 174 + char *ep_path; 175 + 176 + int ep0; 177 + int ep[2]; 178 + 179 + io_context_t ctx; 180 + 181 + int evfd; 182 + fd_set rfds; 183 + 184 + char *buf_in, *buf_out; 185 + struct iocb *iocb_in, *iocb_out; 186 + int req_in = 0, req_out = 0; 187 + bool ready; 188 + 189 + if (argc != 2) { 190 + printf("ffs directory not specified!\n"); 191 + return 1; 192 + } 193 + 194 + ep_path = malloc(strlen(argv[1]) + 4 /* "/ep#" */ + 1 /* '\0' */); 195 + if (!ep_path) { 196 + perror("malloc"); 197 + return 1; 198 + } 199 + 200 + /* open endpoint files */ 201 + sprintf(ep_path, "%s/ep0", argv[1]); 202 + ep0 = open(ep_path, O_RDWR); 203 + if (ep0 < 0) { 204 + perror("unable to open ep0"); 205 + return 1; 206 + } 207 + if (write(ep0, &descriptors, sizeof(descriptors)) < 0) { 208 + perror("unable do write descriptors"); 209 + return 1; 210 + } 211 + if (write(ep0, &strings, sizeof(strings)) < 0) { 212 + perror("unable to write strings"); 213 + return 1; 214 + } 215 + for (i = 0; i < 2; ++i) { 216 + sprintf(ep_path, "%s/ep%d", argv[1], i+1); 217 + ep[i] = open(ep_path, O_RDWR); 218 + if (ep[i] < 0) { 219 + printf("unable to open ep%d: %s\n", i+1, 220 + strerror(errno)); 221 + return 1; 222 + } 223 + } 224 + 225 + free(ep_path); 226 + 227 + memset(&ctx, 0, sizeof(ctx)); 228 + /* setup aio context to handle up to 2 requests */ 229 + if (io_setup(2, &ctx) < 0) { 230 + perror("unable to setup aio"); 231 + return 1; 232 + } 233 + 234 + evfd = eventfd(0, 0); 235 + if (evfd < 0) { 236 + perror("unable to open eventfd"); 237 + return 1; 238 + } 239 + 240 + /* alloc buffers and requests */ 241 + buf_in = malloc(BUF_LEN); 242 + buf_out = malloc(BUF_LEN); 243 + iocb_in = malloc(sizeof(*iocb_in)); 244 + iocb_out = malloc(sizeof(*iocb_out)); 245 + 246 + while (1) { 247 + FD_ZERO(&rfds); 248 + FD_SET(ep0, &rfds); 249 + FD_SET(evfd, &rfds); 250 + 251 + ret = select(((ep0 > evfd) ? ep0 : evfd)+1, 252 + &rfds, NULL, NULL, NULL); 253 + if (ret < 0) { 254 + if (errno == EINTR) 255 + continue; 256 + perror("select"); 257 + break; 258 + } 259 + 260 + if (FD_ISSET(ep0, &rfds)) 261 + handle_ep0(ep0, &ready); 262 + 263 + /* we are waiting for function ENABLE */ 264 + if (!ready) 265 + continue; 266 + 267 + /* if something was submitted we wait for event */ 268 + if (FD_ISSET(evfd, &rfds)) { 269 + uint64_t ev_cnt; 270 + ret = read(evfd, &ev_cnt, sizeof(ev_cnt)); 271 + if (ret < 0) { 272 + perror("unable to read eventfd"); 273 + break; 274 + } 275 + 276 + struct io_event e[2]; 277 + /* we wait for one event */ 278 + ret = io_getevents(ctx, 1, 2, e, NULL); 279 + /* if we got event */ 280 + for (i = 0; i < ret; ++i) { 281 + if (e[i].obj->aio_fildes == ep[0]) { 282 + printf("ev=in; ret=%lu\n", e[i].res); 283 + req_in = 0; 284 + } else if (e[i].obj->aio_fildes == ep[1]) { 285 + printf("ev=out; ret=%lu\n", e[i].res); 286 + req_out = 0; 287 + } 288 + } 289 + } 290 + 291 + if (!req_in) { /* if IN transfer not requested*/ 292 + /* prepare write request */ 293 + io_prep_pwrite(iocb_in, ep[0], buf_in, BUF_LEN, 0); 294 + /* enable eventfd notification */ 295 + iocb_in->u.c.flags |= IOCB_FLAG_RESFD; 296 + iocb_in->u.c.resfd = evfd; 297 + /* submit table of requests */ 298 + ret = io_submit(ctx, 1, &iocb_in); 299 + if (ret >= 0) { /* if ret > 0 request is queued */ 300 + req_in = 1; 301 + printf("submit: in\n"); 302 + } else 303 + perror("unable to submit request"); 304 + } 305 + if (!req_out) { /* if OUT transfer not requested */ 306 + /* prepare read request */ 307 + io_prep_pread(iocb_out, ep[1], buf_out, BUF_LEN, 0); 308 + /* enable eventfs notification */ 309 + iocb_out->u.c.flags |= IOCB_FLAG_RESFD; 310 + iocb_out->u.c.resfd = evfd; 311 + /* submit table of requests */ 312 + ret = io_submit(ctx, 1, &iocb_out); 313 + if (ret >= 0) { /* if ret > 0 request is queued */ 314 + req_out = 1; 315 + printf("submit: out\n"); 316 + } else 317 + perror("unable to submit request"); 318 + } 319 + } 320 + 321 + /* free resources */ 322 + 323 + io_destroy(ctx); 324 + 325 + free(buf_in); 326 + free(buf_out); 327 + free(iocb_in); 328 + free(iocb_out); 329 + 330 + for (i = 0; i < 2; ++i) 331 + close(ep[i]); 332 + close(ep0); 333 + 334 + return 0; 335 + }
+13
tools/usb/ffs-aio-example/simple/host_app/Makefile
··· 1 + CC = gcc 2 + LIBUSB_CFLAGS = $(shell pkg-config --cflags libusb-1.0) 3 + LIBUSB_LIBS = $(shell pkg-config --libs libusb-1.0) 4 + WARNINGS = -Wall -Wextra 5 + CFLAGS = $(LIBUSB_CFLAGS) $(WARNINGS) 6 + LDFLAGS = $(LIBUSB_LIBS) 7 + 8 + all: test 9 + %: %.c 10 + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) 11 + 12 + clean: 13 + $(RM) test
+148
tools/usb/ffs-aio-example/simple/host_app/test.c
··· 1 + #include <libusb.h> 2 + #include <stdio.h> 3 + #include <string.h> 4 + #include <unistd.h> 5 + 6 + #define VENDOR 0x1d6b 7 + #define PRODUCT 0x0105 8 + 9 + /* endpoints indexes */ 10 + 11 + #define EP_BULK_IN (1 | LIBUSB_ENDPOINT_IN) 12 + #define EP_BULK_OUT (2 | LIBUSB_ENDPOINT_OUT) 13 + 14 + #define BUF_LEN 8192 15 + 16 + /* 17 + * struct test_state - describes test program state 18 + * @list: list of devices returned by libusb_get_device_list function 19 + * @found: pointer to struct describing tested device 20 + * @ctx: context, set to NULL 21 + * @handle: handle of tested device 22 + * @attached: indicates that device was attached to kernel, and has to be 23 + * reattached at the end of test program 24 + */ 25 + 26 + struct test_state { 27 + libusb_device *found; 28 + libusb_context *ctx; 29 + libusb_device_handle *handle; 30 + int attached; 31 + }; 32 + 33 + /* 34 + * test_init - initialize test program 35 + */ 36 + 37 + int test_init(struct test_state *state) 38 + { 39 + int i, ret; 40 + ssize_t cnt; 41 + libusb_device **list; 42 + 43 + state->found = NULL; 44 + state->ctx = NULL; 45 + state->handle = NULL; 46 + state->attached = 0; 47 + 48 + ret = libusb_init(&state->ctx); 49 + if (ret) { 50 + printf("cannot init libusb: %s\n", libusb_error_name(ret)); 51 + return 1; 52 + } 53 + 54 + cnt = libusb_get_device_list(state->ctx, &list); 55 + if (cnt <= 0) { 56 + printf("no devices found\n"); 57 + goto error1; 58 + } 59 + 60 + for (i = 0; i < cnt; ++i) { 61 + libusb_device *dev = list[i]; 62 + struct libusb_device_descriptor desc; 63 + ret = libusb_get_device_descriptor(dev, &desc); 64 + if (ret) { 65 + printf("unable to get device descriptor: %s\n", 66 + libusb_error_name(ret)); 67 + goto error2; 68 + } 69 + if (desc.idVendor == VENDOR && desc.idProduct == PRODUCT) { 70 + state->found = dev; 71 + break; 72 + } 73 + } 74 + 75 + if (!state->found) { 76 + printf("no devices found\n"); 77 + goto error2; 78 + } 79 + 80 + ret = libusb_open(state->found, &state->handle); 81 + if (ret) { 82 + printf("cannot open device: %s\n", libusb_error_name(ret)); 83 + goto error2; 84 + } 85 + 86 + if (libusb_claim_interface(state->handle, 0)) { 87 + ret = libusb_detach_kernel_driver(state->handle, 0); 88 + if (ret) { 89 + printf("unable to detach kernel driver: %s\n", 90 + libusb_error_name(ret)); 91 + goto error3; 92 + } 93 + state->attached = 1; 94 + ret = libusb_claim_interface(state->handle, 0); 95 + if (ret) { 96 + printf("cannot claim interface: %s\n", 97 + libusb_error_name(ret)); 98 + goto error4; 99 + } 100 + } 101 + 102 + return 0; 103 + 104 + error4: 105 + if (state->attached == 1) 106 + libusb_attach_kernel_driver(state->handle, 0); 107 + 108 + error3: 109 + libusb_close(state->handle); 110 + 111 + error2: 112 + libusb_free_device_list(list, 1); 113 + 114 + error1: 115 + libusb_exit(state->ctx); 116 + return 1; 117 + } 118 + 119 + /* 120 + * test_exit - cleanup test program 121 + */ 122 + 123 + void test_exit(struct test_state *state) 124 + { 125 + libusb_release_interface(state->handle, 0); 126 + if (state->attached == 1) 127 + libusb_attach_kernel_driver(state->handle, 0); 128 + libusb_close(state->handle); 129 + libusb_exit(state->ctx); 130 + } 131 + 132 + int main(void) 133 + { 134 + struct test_state state; 135 + 136 + if (test_init(&state)) 137 + return 1; 138 + 139 + while (1) { 140 + static unsigned char buffer[BUF_LEN]; 141 + int bytes; 142 + libusb_bulk_transfer(state.handle, EP_BULK_IN, buffer, BUF_LEN, 143 + &bytes, 500); 144 + libusb_bulk_transfer(state.handle, EP_BULK_OUT, buffer, BUF_LEN, 145 + &bytes, 500); 146 + } 147 + test_exit(&state); 148 + }