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

Merge tag 'usb-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB / Thunderbolt / PHY driver updates from Greg KH:
"Here is the big set of USB, Thunderbolt, and PHY driver updates for
6.6-rc1. Included in here are:

- PHY driver additions and cleanups

- Thunderbolt minor additions and fixes

- USB MIDI 2 gadget support added

- dwc3 driver updates and additions

- Removal of some old USB wireless code that was missed when that
codebase was originally removed a few years ago, cleaning up some
core USB code paths

- USB core potential use-after-free fixes that syzbot from different
people/groups keeps tripping over

- typec updates and additions

- gadget fixes and cleanups

- loads of smaller USB core and driver cleanups all over the place

Full details are in the shortlog. All of these have been in linux-next
for a while with no reported problems"

* tag 'usb-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (154 commits)
platform/chrome: cros_ec_typec: Configure Retimer cable type
tcpm: Avoid soft reset when partner does not support get_status
usb: typec: tcpm: reset counter when enter into unattached state after try role
usb: typec: tcpm: set initial svdm version based on pd revision
USB: serial: option: add FOXCONN T99W368/T99W373 product
USB: serial: option: add Quectel EM05G variant (0x030e)
usb: dwc2: add pci_device_id driver_data parse support
usb: gadget: remove max support speed info in bind operation
usb: gadget: composite: cleanup function config_ep_by_speed_and_alt()
usb: gadget: config: remove max speed check in usb_assign_descriptors()
usb: gadget: unconditionally allocate hs/ss descriptor in bind operation
usb: gadget: f_uvc: change endpoint allocation in uvc_function_bind()
usb: gadget: add a inline function gether_bitrate()
usb: gadget: use working speed to calcaulate network bitrate and qlen
dt-bindings: usb: samsung,exynos-dwc3: Add Exynos850 support
usb: dwc3: exynos: Add support for Exynos850 variant
usb: gadget: udc-xilinx: fix incorrect type in assignment warning
usb: gadget: udc-xilinx: fix cast from restricted __le16 warning
usb: gadget: udc-xilinx: fix restricted __le16 degrades to integer warning
USB: dwc2: hande irq on dead controller correctly
...

+7352 -1890
-11
CREDITS
··· 666 666 S: Taiwan 251 667 667 S: Republic of China 668 668 669 - N: Reinette Chatre 670 - E: reinette.chatre@intel.com 671 - D: WiMedia Link Protocol implementation 672 - D: UWB stack bits and pieces 673 - 674 669 N: Michael Elizabeth Chastain 675 670 E: mec@shout.net 676 671 D: Configure, Menuconfig, xconfig ··· 3017 3022 S: Demonstratsii 8-382 3018 3023 S: Tula 300000 3019 3024 S: Russia 3020 - 3021 - N: Inaky Perez-Gonzalez 3022 - E: inaky.perez-gonzalez@intel.com 3023 - D: UWB stack, HWA-RC driver and HWA-HC drivers 3024 - D: Wireless USB additions to the USB stack 3025 - D: WiMedia Link Protocol bits and pieces 3026 3025 3027 3026 N: Gordon Peters 3028 3027 E: GordPeters@smarttech.com
+54
Documentation/ABI/testing/configfs-usb-gadget-midi2
··· 1 + What: /config/usb-gadget/gadget/functions/midi2.name 2 + Date: Jul 2023 3 + KernelVersion: 6.6 4 + Description: 5 + The attributes: 6 + 7 + ============ =============================================== 8 + process_ump Flag to process UMP Stream messages (0 or 1) 9 + static_block Flag for static blocks (0 or 1) 10 + iface_name MIDI interface name string 11 + ============ =============================================== 12 + 13 + What: /config/usb-gadget/gadget/functions/midi2.name/ep.number 14 + Date: Jul 2023 15 + KernelVersion: 6.6 16 + Description: 17 + This group contains a UMP Endpoint configuration. 18 + A new Endpoint starts from 0, and can be up to 3. 19 + 20 + The attributes: 21 + 22 + ============= =============================================== 23 + protocol_caps MIDI protocol capabilities (1, 2 or 3 for both) 24 + protocol Default MIDI protocol (1 or 2) 25 + ep_name UMP Endpoint name string 26 + product_id Product ID string 27 + manufacturer Manufacture ID (24 bit) 28 + family Device family ID (16 bit) 29 + model Device model ID (16 bit) 30 + sw_revision Software Revision (32 bit) 31 + ============= =============================================== 32 + 33 + What: /config/usb-gadget/gadget/functions/midi2.name/ep.number/block.number 34 + Date: Jul 2023 35 + KernelVersion: 6.6 36 + Description: 37 + This group contains a UMP Function Block configuration. 38 + A new block starts from 0, and can be up to 31. 39 + 40 + The attributes: 41 + 42 + ================= ============================================== 43 + name Function Block name string 44 + direction 1: input, 2: output, 3: bidirectional 45 + first_group The first UMP Group number (0-15) 46 + num_groups The number of groups in this FB (1-16) 47 + midi1_first_group The first UMP Group number for MIDI 1.0 (0-15) 48 + midi1_num_groups The number of groups for MIDI 1.0 (0-16) 49 + ui_hint 0: unknown, 1: receiver, 2: sender, 3: both 50 + midi_ci_verison Supported MIDI-CI version number (8 bit) 51 + is_midi1 Legacy MIDI 1.0 device (0, 1 or 2) 52 + sysex8_streams Max number of SysEx8 streams (8 bit) 53 + active Active FB flag (0 or 1) 54 + ================= ==============================================
+19 -19
Documentation/ABI/testing/sysfs-bus-thunderbolt
··· 1 1 What: /sys/bus/thunderbolt/devices/.../domainX/boot_acl 2 2 Date: Jun 2018 3 3 KernelVersion: 4.17 4 - Contact: thunderbolt-software@lists.01.org 4 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 5 5 Description: Holds a comma separated list of device unique_ids that 6 6 are allowed to be connected automatically during system 7 7 startup (e.g boot devices). The list always contains ··· 33 33 What: /sys/bus/thunderbolt/devices/.../domainX/iommu_dma_protection 34 34 Date: Mar 2019 35 35 KernelVersion: 4.21 36 - Contact: thunderbolt-software@lists.01.org 36 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 37 37 Description: This attribute tells whether the system uses IOMMU 38 38 for DMA protection. Value of 1 means IOMMU is used 0 means 39 39 it is not (DMA protection is solely based on Thunderbolt ··· 42 42 What: /sys/bus/thunderbolt/devices/.../domainX/security 43 43 Date: Sep 2017 44 44 KernelVersion: 4.13 45 - Contact: thunderbolt-software@lists.01.org 45 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 46 46 Description: This attribute holds current Thunderbolt security level 47 47 set by the system BIOS. Possible values are: 48 48 ··· 64 64 What: /sys/bus/thunderbolt/devices/.../authorized 65 65 Date: Sep 2017 66 66 KernelVersion: 4.13 67 - Contact: thunderbolt-software@lists.01.org 67 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 68 68 Description: This attribute is used to authorize Thunderbolt devices 69 69 after they have been connected. If the device is not 70 70 authorized, no PCIe devices are available to the system. ··· 98 98 What: /sys/bus/thunderbolt/devices/.../boot 99 99 Date: Jun 2018 100 100 KernelVersion: 4.17 101 - Contact: thunderbolt-software@lists.01.org 101 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 102 102 Description: This attribute contains 1 if Thunderbolt device was already 103 103 authorized on boot and 0 otherwise. 104 104 ··· 113 113 What: /sys/bus/thunderbolt/devices/.../key 114 114 Date: Sep 2017 115 115 KernelVersion: 4.13 116 - Contact: thunderbolt-software@lists.01.org 116 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 117 117 Description: When a devices supports Thunderbolt secure connect it will 118 118 have this attribute. Writing 32 byte hex string changes 119 119 authorization to use the secure connection method instead. ··· 123 123 What: /sys/bus/thunderbolt/devices/.../device 124 124 Date: Sep 2017 125 125 KernelVersion: 4.13 126 - Contact: thunderbolt-software@lists.01.org 126 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 127 127 Description: This attribute contains id of this device extracted from 128 128 the device DROM. 129 129 130 130 What: /sys/bus/thunderbolt/devices/.../device_name 131 131 Date: Sep 2017 132 132 KernelVersion: 4.13 133 - Contact: thunderbolt-software@lists.01.org 133 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 134 134 Description: This attribute contains name of this device extracted from 135 135 the device DROM. 136 136 ··· 172 172 What: /sys/bus/thunderbolt/devices/.../vendor 173 173 Date: Sep 2017 174 174 KernelVersion: 4.13 175 - Contact: thunderbolt-software@lists.01.org 175 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 176 176 Description: This attribute contains vendor id of this device extracted 177 177 from the device DROM. 178 178 179 179 What: /sys/bus/thunderbolt/devices/.../vendor_name 180 180 Date: Sep 2017 181 181 KernelVersion: 4.13 182 - Contact: thunderbolt-software@lists.01.org 182 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 183 183 Description: This attribute contains vendor name of this device extracted 184 184 from the device DROM. 185 185 186 186 What: /sys/bus/thunderbolt/devices/.../unique_id 187 187 Date: Sep 2017 188 188 KernelVersion: 4.13 189 - Contact: thunderbolt-software@lists.01.org 189 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 190 190 Description: This attribute contains unique_id string of this device. 191 191 This is either read from hardware registers (UUID on 192 192 newer hardware) or based on UID from the device DROM. ··· 195 195 What: /sys/bus/thunderbolt/devices/.../nvm_version 196 196 Date: Sep 2017 197 197 KernelVersion: 4.13 198 - Contact: thunderbolt-software@lists.01.org 198 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 199 199 Description: If the device has upgradeable firmware the version 200 200 number is available here. Format: %x.%x, major.minor. 201 201 If the device is in safe mode reading the file returns ··· 204 204 What: /sys/bus/thunderbolt/devices/.../nvm_authenticate 205 205 Date: Sep 2017 206 206 KernelVersion: 4.13 207 - Contact: thunderbolt-software@lists.01.org 207 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 208 208 Description: When new NVM image is written to the non-active NVM 209 209 area (through non_activeX NVMem device), the 210 210 authentication procedure is started by writing to ··· 246 246 What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/key 247 247 Date: Jan 2018 248 248 KernelVersion: 4.15 249 - Contact: thunderbolt-software@lists.01.org 249 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 250 250 Description: This contains name of the property directory the XDomain 251 251 service exposes. This entry describes the protocol in 252 252 question. Following directories are already reserved by ··· 261 261 What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/modalias 262 262 Date: Jan 2018 263 263 KernelVersion: 4.15 264 - Contact: thunderbolt-software@lists.01.org 264 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 265 265 Description: Stores the same MODALIAS value emitted by uevent for 266 266 the XDomain service. Format: tbtsvc:kSpNvNrN 267 267 268 268 What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/prtcid 269 269 Date: Jan 2018 270 270 KernelVersion: 4.15 271 - Contact: thunderbolt-software@lists.01.org 271 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 272 272 Description: This contains XDomain protocol identifier the XDomain 273 273 service supports. 274 274 275 275 What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/prtcvers 276 276 Date: Jan 2018 277 277 KernelVersion: 4.15 278 - Contact: thunderbolt-software@lists.01.org 278 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 279 279 Description: This contains XDomain protocol version the XDomain 280 280 service supports. 281 281 282 282 What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/prtcrevs 283 283 Date: Jan 2018 284 284 KernelVersion: 4.15 285 - Contact: thunderbolt-software@lists.01.org 285 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 286 286 Description: This contains XDomain software version the XDomain 287 287 service supports. 288 288 289 289 What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/prtcstns 290 290 Date: Jan 2018 291 291 KernelVersion: 4.15 292 - Contact: thunderbolt-software@lists.01.org 292 + Contact: Mika Westerberg <mika.westerberg@linux.intel.com> 293 293 Description: This contains XDomain service specific settings as 294 294 bitmask. Format: %x 295 295
-28
Documentation/ABI/testing/sysfs-bus-umc
··· 1 - What: /sys/bus/umc/ 2 - Date: July 2008 3 - KernelVersion: 2.6.27 4 - Contact: David Vrabel <david.vrabel@csr.com> 5 - Description: 6 - The Wireless Host Controller Interface (WHCI) 7 - specification describes a PCI-based device with 8 - multiple capabilities; the UWB Multi-interface 9 - Controller (UMC). 10 - 11 - The umc bus presents each of the individual 12 - capabilities as a device. 13 - 14 - What: /sys/bus/umc/devices/.../capability_id 15 - Date: July 2008 16 - KernelVersion: 2.6.27 17 - Contact: David Vrabel <david.vrabel@csr.com> 18 - Description: 19 - The ID of this capability, with 0 being the radio 20 - controller capability. 21 - 22 - What: /sys/bus/umc/devices/.../version 23 - Date: July 2008 24 - KernelVersion: 2.6.27 25 - Contact: David Vrabel <david.vrabel@csr.com> 26 - Description: 27 - The specification version this capability's hardware 28 - interface complies with.
-34
Documentation/ABI/testing/sysfs-bus-usb
··· 28 28 drivers, non-authorized one are not. By default, wired 29 29 USB devices are authorized. 30 30 31 - Certified Wireless USB devices are not authorized 32 - initially and should be (by writing 1) after the 33 - device has been authenticated. 34 - 35 - What: /sys/bus/usb/device/.../wusb_cdid 36 - Date: July 2008 37 - KernelVersion: 2.6.27 38 - Contact: David Vrabel <david.vrabel@csr.com> 39 - Description: 40 - For Certified Wireless USB devices only. 41 - 42 - A devices's CDID, as 16 space-separated hex octets. 43 - 44 - What: /sys/bus/usb/device/.../wusb_ck 45 - Date: July 2008 46 - KernelVersion: 2.6.27 47 - Contact: David Vrabel <david.vrabel@csr.com> 48 - Description: 49 - For Certified Wireless USB devices only. 50 - 51 - Write the device's connection key (CK) to start the 52 - authentication of the device. The CK is 16 53 - space-separated hex octets. 54 - 55 - What: /sys/bus/usb/device/.../wusb_disconnect 56 - Date: July 2008 57 - KernelVersion: 2.6.27 58 - Contact: David Vrabel <david.vrabel@csr.com> 59 - Description: 60 - For Certified Wireless USB devices only. 61 - 62 - Write a 1 to force the device to disconnect 63 - (equivalent to unplugging a wired USB device). 64 - 65 31 What: /sys/bus/usb/drivers/.../new_id 66 32 Date: October 2011 67 33 Contact: linux-usb@vger.kernel.org
-156
Documentation/ABI/testing/sysfs-class-uwb_rc
··· 1 - What: /sys/class/uwb_rc 2 - Date: July 2008 3 - KernelVersion: 2.6.27 4 - Contact: linux-usb@vger.kernel.org 5 - Description: 6 - Interfaces for WiMedia Ultra Wideband Common Radio 7 - Platform (UWB) radio controllers. 8 - 9 - Familiarity with the ECMA-368 'High Rate Ultra 10 - Wideband MAC and PHY Specification' is assumed. 11 - 12 - What: /sys/class/uwb_rc/beacon_timeout_ms 13 - Date: July 2008 14 - KernelVersion: 2.6.27 15 - Description: 16 - If no beacons are received from a device for at least 17 - this time, the device will be considered to have gone 18 - and it will be removed. The default is 3 superframes 19 - (~197 ms) as required by the specification. 20 - 21 - What: /sys/class/uwb_rc/uwb<N>/ 22 - Date: July 2008 23 - KernelVersion: 2.6.27 24 - Contact: linux-usb@vger.kernel.org 25 - Description: 26 - An individual UWB radio controller. 27 - 28 - What: /sys/class/uwb_rc/uwb<N>/beacon 29 - Date: July 2008 30 - KernelVersion: 2.6.27 31 - Contact: linux-usb@vger.kernel.org 32 - Description: 33 - Write: 34 - 35 - <channel> 36 - 37 - to force a specific channel to be used when beaconing, 38 - or, if <channel> is -1, to prohibit beaconing. If 39 - <channel> is 0, then the default channel selection 40 - algorithm will be used. Valid channels depends on the 41 - radio controller's supported band groups. 42 - 43 - Reading returns the currently active channel, or -1 if 44 - the radio controller is not beaconing. 45 - 46 - What: /sys/class/uwb_rc/uwb<N>/ASIE 47 - Date: August 2014 48 - KernelVersion: 3.18 49 - Contact: linux-usb@vger.kernel.org 50 - Description: 51 - 52 - The application-specific information element (ASIE) 53 - included in this device's beacon, in space separated 54 - hex octets. 55 - 56 - Reading returns the current ASIE. Writing replaces 57 - the current ASIE with the one written. 58 - 59 - What: /sys/class/uwb_rc/uwb<N>/scan 60 - Date: July 2008 61 - KernelVersion: 2.6.27 62 - Contact: linux-usb@vger.kernel.org 63 - Description: 64 - Write: 65 - 66 - <channel> <type> [<bpst offset>] 67 - 68 - to start (or stop) scanning on a channel. <type> is one of: 69 - 70 - == ======================================= 71 - 0 scan 72 - 1 scan outside BP 73 - 2 scan while inactive 74 - 3 scanning disabled 75 - 4 scan (with start time of <bpst offset>) 76 - == ======================================= 77 - 78 - What: /sys/class/uwb_rc/uwb<N>/mac_address 79 - Date: July 2008 80 - KernelVersion: 2.6.27 81 - Contact: linux-usb@vger.kernel.org 82 - Description: 83 - The EUI-48, in colon-separated hex octets, for this 84 - radio controller. A write will change the radio 85 - controller's EUI-48 but only do so while the device is 86 - not beaconing or scanning. 87 - 88 - What: /sys/class/uwb_rc/uwb<N>/wusbhc 89 - Date: July 2008 90 - KernelVersion: 2.6.27 91 - Contact: linux-usb@vger.kernel.org 92 - Description: 93 - A symlink to the device (if any) of the WUSB Host 94 - Controller PAL using this radio controller. 95 - 96 - What: /sys/class/uwb_rc/uwb<N>/<EUI-48>/ 97 - Date: July 2008 98 - KernelVersion: 2.6.27 99 - Contact: linux-usb@vger.kernel.org 100 - Description: 101 - A neighbour UWB device that has either been detected 102 - as part of a scan or is a member of the radio 103 - controllers beacon group. 104 - 105 - What: /sys/class/uwb_rc/uwb<N>/<EUI-48>/BPST 106 - Date: July 2008 107 - KernelVersion: 2.6.27 108 - Contact: linux-usb@vger.kernel.org 109 - Description: 110 - The time (using the radio controllers internal 1 ms 111 - interval superframe timer) of the last beacon from 112 - this device was received. 113 - 114 - What: /sys/class/uwb_rc/uwb<N>/<EUI-48>/DevAddr 115 - Date: July 2008 116 - KernelVersion: 2.6.27 117 - Contact: linux-usb@vger.kernel.org 118 - Description: 119 - The current DevAddr of this device in colon separated 120 - hex octets. 121 - 122 - What: /sys/class/uwb_rc/uwb<N>/<EUI-48>/EUI_48 123 - Date: July 2008 124 - KernelVersion: 2.6.27 125 - Contact: linux-usb@vger.kernel.org 126 - Description: 127 - 128 - The EUI-48 of this device in colon separated hex 129 - octets. 130 - 131 - What: /sys/class/uwb_rc/uwb<N>/<EUI-48>/IEs 132 - Date: July 2008 133 - KernelVersion: 2.6.27 134 - Contact: linux-usb@vger.kernel.org 135 - Description: 136 - The latest IEs included in this device's beacon, in 137 - space separated hex octets with one IE per line. 138 - 139 - What: /sys/class/uwb_rc/uwb<N>/<EUI-48>/LQE 140 - Date: July 2008 141 - KernelVersion: 2.6.27 142 - Contact: linux-usb@vger.kernel.org 143 - Description: 144 - Link Quality Estimate - the Signal to Noise Ratio 145 - (SNR) of all packets received from this device in dB. 146 - This gives an estimate on a suitable PHY rate. Refer 147 - to [ECMA-368] section 13.3 for more details. 148 - 149 - What: /sys/class/uwb_rc/uwb<N>/<EUI-48>/RSSI 150 - Date: July 2008 151 - KernelVersion: 2.6.27 152 - Contact: linux-usb@vger.kernel.org 153 - Description: 154 - Received Signal Strength Indication - the strength of 155 - the received signal in dB. LQE is a more useful 156 - measure of the radio link quality.
-57
Documentation/ABI/testing/sysfs-class-uwb_rc-wusbhc
··· 1 - What: /sys/class/uwb_rc/uwb<N>/wusbhc/wusb_chid 2 - Date: July 2008 3 - KernelVersion: 2.6.27 4 - Contact: David Vrabel <david.vrabel@csr.com> 5 - Description: 6 - Write the CHID (16 space-separated hex octets) for this host controller. 7 - This starts the host controller, allowing it to accept connection from 8 - WUSB devices. 9 - 10 - Set an all zero CHID to stop the host controller. 11 - 12 - What: /sys/class/uwb_rc/uwb<N>/wusbhc/wusb_trust_timeout 13 - Date: July 2008 14 - KernelVersion: 2.6.27 15 - Contact: David Vrabel <david.vrabel@csr.com> 16 - Description: 17 - Devices that haven't sent a WUSB packet to the host 18 - within 'wusb_trust_timeout' ms are considered to have 19 - disconnected and are removed. The default value of 20 - 4000 ms is the value required by the WUSB 21 - specification. 22 - 23 - Since this relates to security (specifically, the 24 - lifetime of PTKs and GTKs) it should not be changed 25 - from the default. 26 - 27 - What: /sys/class/uwb_rc/uwb<N>/wusbhc/wusb_phy_rate 28 - Date: August 2009 29 - KernelVersion: 2.6.32 30 - Contact: David Vrabel <david.vrabel@csr.com> 31 - Description: 32 - The maximum PHY rate to use for all connected devices. 33 - This is only of limited use for testing and 34 - development as the hardware's automatic rate 35 - adaptation is better then this simple control. 36 - 37 - Refer to [ECMA-368] section 10.3.1.1 for the value to 38 - use. 39 - 40 - What: /sys/class/uwb_rc/uwb<N>/wusbhc/wusb_dnts 41 - Date: June 2013 42 - KernelVersion: 3.11 43 - Contact: Thomas Pugliese <thomas.pugliese@gmail.com> 44 - Description: 45 - The device notification time slot (DNTS) count and interval in 46 - milliseconds that the WUSB host should use. This controls how 47 - often the devices will have the opportunity to send 48 - notifications to the host. 49 - 50 - What: /sys/class/uwb_rc/uwb<N>/wusbhc/wusb_retry_count 51 - Date: June 2013 52 - KernelVersion: 3.11 53 - Contact: Thomas Pugliese <thomas.pugliese@gmail.com> 54 - Description: 55 - The number of retries that the WUSB host should attempt 56 - before reporting an error for a bus transaction. The range of 57 - valid values is [0..15], where 0 indicates infinite retries.
-101
Documentation/ABI/testing/sysfs-wusb_cbaf
··· 1 - What: /sys/bus/usb/drivers/wusb_cbaf/.../wusb_* 2 - Date: August 2008 3 - KernelVersion: 2.6.27 4 - Contact: David Vrabel <david.vrabel@csr.com> 5 - Description: 6 - Various files for managing Cable Based Association of 7 - (wireless) USB devices. 8 - 9 - The sequence of operations should be: 10 - 11 - 1. Device is plugged in. 12 - 13 - 2. The connection manager (CM) sees a device with CBA capability. 14 - (the wusb_chid etc. files in /sys/devices/blah/OURDEVICE). 15 - 16 - 3. The CM writes the host name, supported band groups, 17 - and the CHID (host ID) into the wusb_host_name, 18 - wusb_host_band_groups and wusb_chid files. These 19 - get sent to the device and the CDID (if any) for 20 - this host is requested. 21 - 22 - 4. The CM can verify that the device's supported band 23 - groups (wusb_device_band_groups) are compatible 24 - with the host. 25 - 26 - 5. The CM reads the wusb_cdid file. 27 - 28 - 6. The CM looks it up its database. 29 - 30 - - If it has a matching CHID,CDID entry, the device 31 - has been authorized before and nothing further 32 - needs to be done. 33 - 34 - - If the CDID is zero (or the CM doesn't find a 35 - matching CDID in its database), the device is 36 - assumed to be not known. The CM may associate 37 - the host with device by: writing a randomly 38 - generated CDID to wusb_cdid and then a random CK 39 - to wusb_ck (this uploads the new CC to the 40 - device). 41 - 42 - CMD may choose to prompt the user before 43 - associating with a new device. 44 - 45 - 7. Device is unplugged. 46 - 47 - References: 48 - [WUSB-AM] 49 - Association Models Supplement to the 50 - Certified Wireless Universal Serial Bus 51 - Specification, version 1.0. 52 - 53 - What: /sys/bus/usb/drivers/wusb_cbaf/.../wusb_chid 54 - Date: August 2008 55 - KernelVersion: 2.6.27 56 - Contact: David Vrabel <david.vrabel@csr.com> 57 - Description: 58 - The CHID of the host formatted as 16 space-separated 59 - hex octets. 60 - 61 - Writes fetches device's supported band groups and the 62 - the CDID for any existing association with this host. 63 - 64 - What: /sys/bus/usb/drivers/wusb_cbaf/.../wusb_host_name 65 - Date: August 2008 66 - KernelVersion: 2.6.27 67 - Contact: David Vrabel <david.vrabel@csr.com> 68 - Description: 69 - A friendly name for the host as a UTF-8 encoded string. 70 - 71 - What: /sys/bus/usb/drivers/wusb_cbaf/.../wusb_host_band_groups 72 - Date: August 2008 73 - KernelVersion: 2.6.27 74 - Contact: David Vrabel <david.vrabel@csr.com> 75 - Description: 76 - The band groups supported by the host, in the format 77 - defined in [WUSB-AM]. 78 - 79 - What: /sys/bus/usb/drivers/wusb_cbaf/.../wusb_device_band_groups 80 - Date: August 2008 81 - KernelVersion: 2.6.27 82 - Contact: David Vrabel <david.vrabel@csr.com> 83 - Description: 84 - The band groups supported by the device, in the format 85 - defined in [WUSB-AM]. 86 - 87 - What: /sys/bus/usb/drivers/wusb_cbaf/.../wusb_cdid 88 - Date: August 2008 89 - KernelVersion: 2.6.27 90 - Contact: David Vrabel <david.vrabel@csr.com> 91 - Description: 92 - The device's CDID formatted as 16 space-separated hex 93 - octets. 94 - 95 - What: /sys/bus/usb/drivers/wusb_cbaf/.../wusb_ck 96 - Date: August 2008 97 - KernelVersion: 2.6.27 98 - Contact: David Vrabel <david.vrabel@csr.com> 99 - Description: 100 - Write 16 space-separated random, hex octets to 101 - associate with the device.
+1 -1
Documentation/admin-guide/kernel-parameters.txt
··· 6719 6719 6720 6720 usbcore.authorized_default= 6721 6721 [USB] Default USB device authorization: 6722 - (default -1 = authorized except for wireless USB, 6722 + (default -1 = authorized (same as 1), 6723 6723 0 = not authorized, 1 = authorized, 2 = authorized 6724 6724 if device connected to internal port) 6725 6725
+175
Documentation/devicetree/bindings/phy/realtek,usb2phy.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + # Copyright 2023 Realtek Semiconductor Corporation 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/phy/realtek,usb2phy.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Realtek DHC SoCs USB 2.0 PHY 9 + 10 + maintainers: 11 + - Stanley Chang <stanley_chang@realtek.com> 12 + 13 + description: | 14 + Realtek USB 2.0 PHY support the digital home center (DHC) RTD series SoCs. 15 + The USB 2.0 PHY driver is designed to support the XHCI controller. The SoCs 16 + support multiple XHCI controllers. One PHY device node maps to one XHCI 17 + controller. 18 + 19 + RTD1295/RTD1619 SoCs USB 20 + The USB architecture includes three XHCI controllers. 21 + Each XHCI maps to one USB 2.0 PHY and map one USB 3.0 PHY on some 22 + controllers. 23 + XHCI controller#0 -- usb2phy -- phy#0 24 + |- usb3phy -- phy#0 25 + XHCI controller#1 -- usb2phy -- phy#0 26 + XHCI controller#2 -- usb2phy -- phy#0 27 + |- usb3phy -- phy#0 28 + 29 + RTD1395 SoCs USB 30 + The USB architecture includes two XHCI controllers. 31 + The controller#0 has one USB 2.0 PHY. The controller#1 includes two USB 2.0 32 + PHY. 33 + XHCI controller#0 -- usb2phy -- phy#0 34 + XHCI controller#1 -- usb2phy -- phy#0 35 + |- phy#1 36 + 37 + RTD1319/RTD1619b SoCs USB 38 + The USB architecture includes three XHCI controllers. 39 + Each XHCI maps to one USB 2.0 PHY and map one USB 3.0 PHY on controllers#2. 40 + XHCI controller#0 -- usb2phy -- phy#0 41 + XHCI controller#1 -- usb2phy -- phy#0 42 + XHCI controller#2 -- usb2phy -- phy#0 43 + |- usb3phy -- phy#0 44 + 45 + RTD1319d SoCs USB 46 + The USB architecture includes three XHCI controllers. 47 + Each xhci maps to one USB 2.0 PHY and map one USB 3.0 PHY on controllers#0. 48 + XHCI controller#0 -- usb2phy -- phy#0 49 + |- usb3phy -- phy#0 50 + XHCI controller#1 -- usb2phy -- phy#0 51 + XHCI controller#2 -- usb2phy -- phy#0 52 + 53 + RTD1312c/RTD1315e SoCs USB 54 + The USB architecture includes three XHCI controllers. 55 + Each XHCI maps to one USB 2.0 PHY. 56 + XHCI controller#0 -- usb2phy -- phy#0 57 + XHCI controller#1 -- usb2phy -- phy#0 58 + XHCI controller#2 -- usb2phy -- phy#0 59 + 60 + properties: 61 + compatible: 62 + enum: 63 + - realtek,rtd1295-usb2phy 64 + - realtek,rtd1312c-usb2phy 65 + - realtek,rtd1315e-usb2phy 66 + - realtek,rtd1319-usb2phy 67 + - realtek,rtd1319d-usb2phy 68 + - realtek,rtd1395-usb2phy 69 + - realtek,rtd1395-usb2phy-2port 70 + - realtek,rtd1619-usb2phy 71 + - realtek,rtd1619b-usb2phy 72 + 73 + reg: 74 + items: 75 + - description: PHY data registers 76 + - description: PHY control registers 77 + 78 + "#phy-cells": 79 + const: 0 80 + 81 + nvmem-cells: 82 + maxItems: 2 83 + description: 84 + Phandles to nvmem cell that contains the trimming data. 85 + If unspecified, default value is used. 86 + 87 + nvmem-cell-names: 88 + items: 89 + - const: usb-dc-cal 90 + - const: usb-dc-dis 91 + description: 92 + The following names, which correspond to each nvmem-cells. 93 + usb-dc-cal is the driving level for each phy specified via efuse. 94 + usb-dc-dis is the disconnection level for each phy specified via efuse. 95 + 96 + realtek,inverse-hstx-sync-clock: 97 + description: 98 + For one of the phys of RTD1619b SoC, the synchronous clock of the 99 + high-speed tx must be inverted. 100 + type: boolean 101 + 102 + realtek,driving-level: 103 + description: 104 + Control the magnitude of High speed Dp/Dm output swing (mV). 105 + For a different board or port, the original magnitude maybe not meet 106 + the specification. In this situation we can adjust the value to meet 107 + the specification. 108 + $ref: /schemas/types.yaml#/definitions/uint32 109 + default: 8 110 + minimum: 0 111 + maximum: 31 112 + 113 + realtek,driving-level-compensate: 114 + description: 115 + For RTD1315e SoC, the driving level can be adjusted by reading the 116 + efuse table. This property provides drive compensation. 117 + If the magnitude of High speed Dp/Dm output swing still not meet the 118 + specification, then we can set this value to meet the specification. 119 + $ref: /schemas/types.yaml#/definitions/int32 120 + default: 0 121 + minimum: -8 122 + maximum: 8 123 + 124 + realtek,disconnection-compensate: 125 + description: 126 + This adjusts the disconnection level compensation for the different 127 + boards with different disconnection level. 128 + $ref: /schemas/types.yaml#/definitions/int32 129 + default: 0 130 + minimum: -8 131 + maximum: 8 132 + 133 + required: 134 + - compatible 135 + - reg 136 + - "#phy-cells" 137 + 138 + allOf: 139 + - if: 140 + not: 141 + properties: 142 + compatible: 143 + contains: 144 + enum: 145 + - realtek,rtd1619b-usb2phy 146 + then: 147 + properties: 148 + realtek,inverse-hstx-sync-clock: false 149 + 150 + - if: 151 + not: 152 + properties: 153 + compatible: 154 + contains: 155 + enum: 156 + - realtek,rtd1315e-usb2phy 157 + then: 158 + properties: 159 + realtek,driving-level-compensate: false 160 + 161 + additionalProperties: false 162 + 163 + examples: 164 + - | 165 + usb-phy@13214 { 166 + compatible = "realtek,rtd1619b-usb2phy"; 167 + reg = <0x13214 0x4>, <0x28280 0x4>; 168 + #phy-cells = <0>; 169 + nvmem-cells = <&otp_usb_port0_dc_cal>, <&otp_usb_port0_dc_dis>; 170 + nvmem-cell-names = "usb-dc-cal", "usb-dc-dis"; 171 + 172 + realtek,inverse-hstx-sync-clock; 173 + realtek,driving-level = <0xa>; 174 + realtek,disconnection-compensate = <(-1)>; 175 + };
+107
Documentation/devicetree/bindings/phy/realtek,usb3phy.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + # Copyright 2023 Realtek Semiconductor Corporation 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/phy/realtek,usb3phy.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Realtek DHC SoCs USB 3.0 PHY 9 + 10 + maintainers: 11 + - Stanley Chang <stanley_chang@realtek.com> 12 + 13 + description: | 14 + Realtek USB 3.0 PHY support the digital home center (DHC) RTD series SoCs. 15 + The USB 3.0 PHY driver is designed to support the XHCI controller. The SoCs 16 + support multiple XHCI controllers. One PHY device node maps to one XHCI 17 + controller. 18 + 19 + RTD1295/RTD1619 SoCs USB 20 + The USB architecture includes three XHCI controllers. 21 + Each XHCI maps to one USB 2.0 PHY and map one USB 3.0 PHY on some 22 + controllers. 23 + XHCI controller#0 -- usb2phy -- phy#0 24 + |- usb3phy -- phy#0 25 + XHCI controller#1 -- usb2phy -- phy#0 26 + XHCI controller#2 -- usb2phy -- phy#0 27 + |- usb3phy -- phy#0 28 + 29 + RTD1319/RTD1619b SoCs USB 30 + The USB architecture includes three XHCI controllers. 31 + Each XHCI maps to one USB 2.0 PHY and map one USB 3.0 PHY on controllers#2. 32 + XHCI controller#0 -- usb2phy -- phy#0 33 + XHCI controller#1 -- usb2phy -- phy#0 34 + XHCI controller#2 -- usb2phy -- phy#0 35 + |- usb3phy -- phy#0 36 + 37 + RTD1319d SoCs USB 38 + The USB architecture includes three XHCI controllers. 39 + Each xhci maps to one USB 2.0 PHY and map one USB 3.0 PHY on controllers#0. 40 + XHCI controller#0 -- usb2phy -- phy#0 41 + |- usb3phy -- phy#0 42 + XHCI controller#1 -- usb2phy -- phy#0 43 + XHCI controller#2 -- usb2phy -- phy#0 44 + 45 + properties: 46 + compatible: 47 + enum: 48 + - realtek,rtd1295-usb3phy 49 + - realtek,rtd1319-usb3phy 50 + - realtek,rtd1319d-usb3phy 51 + - realtek,rtd1619-usb3phy 52 + - realtek,rtd1619b-usb3phy 53 + 54 + reg: 55 + maxItems: 1 56 + 57 + "#phy-cells": 58 + const: 0 59 + 60 + nvmem-cells: 61 + maxItems: 1 62 + description: A phandle to the tx lfps swing trim data provided by 63 + a nvmem device, if unspecified, default values shall be used. 64 + 65 + nvmem-cell-names: 66 + items: 67 + - const: usb_u3_tx_lfps_swing_trim 68 + 69 + realtek,amplitude-control-coarse-tuning: 70 + description: 71 + This adjusts the signal amplitude for normal operation and beacon LFPS. 72 + This value is a parameter for coarse tuning. 73 + For different boards, if the default value is inappropriate, this 74 + property can be assigned to adjust. 75 + $ref: /schemas/types.yaml#/definitions/uint32 76 + default: 255 77 + minimum: 0 78 + maximum: 255 79 + 80 + realtek,amplitude-control-fine-tuning: 81 + description: 82 + This adjusts the signal amplitude for normal operation and beacon LFPS. 83 + This value is used for fine-tuning parameters. 84 + $ref: /schemas/types.yaml#/definitions/uint32 85 + default: 65535 86 + minimum: 0 87 + maximum: 65535 88 + 89 + required: 90 + - compatible 91 + - reg 92 + - "#phy-cells" 93 + 94 + additionalProperties: false 95 + 96 + examples: 97 + - | 98 + usb-phy@13e10 { 99 + compatible = "realtek,rtd1319d-usb3phy"; 100 + reg = <0x13e10 0x4>; 101 + #phy-cells = <0>; 102 + 103 + nvmem-cells = <&otp_usb_u3_tx_lfps_swing_trim>; 104 + nvmem-cell-names = "usb_u3_tx_lfps_swing_trim"; 105 + 106 + realtek,amplitude-control-coarse-tuning = <0x77>; 107 + };
+15 -2
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.yaml
··· 34 34 - fsl,imx23-usb 35 35 - fsl,imx25-usb 36 36 - fsl,imx28-usb 37 + - fsl,imx35-usb 37 38 - fsl,imx50-usb 38 39 - fsl,imx51-usb 39 40 - fsl,imx53-usb ··· 77 76 78 77 clocks: 79 78 minItems: 1 80 - maxItems: 2 79 + maxItems: 3 81 80 82 81 clock-names: 83 82 minItems: 1 84 - maxItems: 2 83 + maxItems: 3 85 84 86 85 dr_mode: true 87 86 ··· 292 291 $ref: /schemas/types.yaml#/definitions/uint32 293 292 minimum: 0x0 294 293 maximum: 0xf 294 + 295 + fsl,picophy-rise-fall-time-adjust: 296 + description: 297 + HS Transmitter Rise/Fall Time Adjustment. Adjust the rise/fall times 298 + of the high-speed transmitter waveform. It has no unit. The rise/fall 299 + time will be increased or decreased by a certain percentage relative 300 + to design default time. (0:-10%; 1:design default; 2:+15%; 3:+20%) 301 + Details can refer to TXRISETUNE0 bit of USBNC_n_PHY_CFG1. 302 + $ref: /schemas/types.yaml#/definitions/uint32 303 + minimum: 0 304 + maximum: 3 305 + default: 1 295 306 296 307 usb-phy: 297 308 description: phandle for the PHY device. Use "phys" instead.
+77
Documentation/devicetree/bindings/usb/cypress,hx3.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/cypress,hx3.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Cypress HX3 USB 3.0 hub controller family 8 + 9 + maintainers: 10 + - Benjamin Bara <benjamin.bara@skidata.com> 11 + 12 + allOf: 13 + - $ref: usb-device.yaml# 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - usb4b4,6504 19 + - usb4b4,6506 20 + 21 + reg: true 22 + 23 + reset-gpios: 24 + items: 25 + - description: GPIO specifier for RESETN pin. 26 + 27 + vdd-supply: 28 + description: 29 + 1V2 power supply (VDD_EFUSE, AVDD12, DVDD12). 30 + 31 + vdd2-supply: 32 + description: 33 + 3V3 power supply (AVDD33, VDD_IO). 34 + 35 + peer-hub: 36 + $ref: /schemas/types.yaml#/definitions/phandle 37 + description: 38 + phandle to the peer hub on the controller. 39 + 40 + required: 41 + - compatible 42 + - reg 43 + - peer-hub 44 + - vdd-supply 45 + - vdd2-supply 46 + 47 + additionalProperties: false 48 + 49 + examples: 50 + - | 51 + #include <dt-bindings/gpio/gpio.h> 52 + 53 + usb { 54 + dr_mode = "host"; 55 + #address-cells = <1>; 56 + #size-cells = <0>; 57 + 58 + /* 2.0 hub on port 1 */ 59 + hub_2_0: hub@1 { 60 + compatible = "usb4b4,6504"; 61 + reg = <1>; 62 + peer-hub = <&hub_3_0>; 63 + reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 64 + vdd-supply = <&reg_1v2_usb>; 65 + vdd2-supply = <&reg_3v3_usb>; 66 + }; 67 + 68 + /* 3.0 hub on port 2 */ 69 + hub_3_0: hub@2 { 70 + compatible = "usb4b4,6506"; 71 + reg = <2>; 72 + peer-hub = <&hub_2_0>; 73 + reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 74 + vdd-supply = <&reg_1v2_usb>; 75 + vdd2-supply = <&reg_3v3_usb>; 76 + }; 77 + };
+1
Documentation/devicetree/bindings/usb/generic-ehci.yaml
··· 68 68 - const: generic-ehci 69 69 - items: 70 70 - enum: 71 + - atmel,at91sam9g45-ehci 71 72 - cavium,octeon-6335-ehci 72 73 - ibm,usb-ehci-440epx 73 74 - ibm,usb-ehci-460ex
+1
Documentation/devicetree/bindings/usb/genesys,gl850g.yaml
··· 17 17 enum: 18 18 - usb5e3,608 19 19 - usb5e3,610 20 + - usb5e3,620 20 21 21 22 reg: true 22 23
+19 -17
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml
··· 14 14 items: 15 15 - enum: 16 16 - qcom,ipq4019-dwc3 17 + - qcom,ipq5332-dwc3 17 18 - qcom,ipq6018-dwc3 18 19 - qcom,ipq8064-dwc3 19 20 - qcom,ipq8074-dwc3 ··· 83 82 minItems: 1 84 83 maxItems: 9 85 84 86 - assigned-clocks: 87 - items: 88 - - description: Phandle and clock specifier of MOCK_UTMI_CLK. 89 - - description: Phandle and clock specifoer of MASTER_CLK. 90 - 91 - assigned-clock-rates: 92 - items: 93 - - description: Must be 19.2MHz (19200000). 94 - - description: Must be >= 60 MHz in HS mode, >= 125 MHz in SS mode. 95 85 resets: 96 86 maxItems: 1 97 87 ··· 238 246 compatible: 239 247 contains: 240 248 enum: 249 + - qcom,ipq5332-dwc3 241 250 - qcom,msm8994-dwc3 242 251 - qcom,qcs404-dwc3 243 252 then: ··· 283 290 then: 284 291 properties: 285 292 clocks: 286 - minItems: 6 293 + minItems: 5 294 + maxItems: 6 287 295 clock-names: 288 - items: 289 - - const: cfg_noc 290 - - const: core 291 - - const: iface 292 - - const: sleep 293 - - const: mock_utmi 294 - - const: bus 296 + oneOf: 297 + - items: 298 + - const: cfg_noc 299 + - const: core 300 + - const: iface 301 + - const: sleep 302 + - const: mock_utmi 303 + - const: bus 304 + - items: 305 + - const: cfg_noc 306 + - const: core 307 + - const: sleep 308 + - const: mock_utmi 309 + - const: bus 295 310 296 311 - if: 297 312 properties: ··· 411 410 compatible: 412 411 contains: 413 412 enum: 413 + - qcom,ipq5332-dwc3 414 414 - qcom,sdm660-dwc3 415 415 then: 416 416 properties:
+18 -2
Documentation/devicetree/bindings/usb/samsung,exynos-dwc3.yaml
··· 15 15 - samsung,exynos5250-dwusb3 16 16 - samsung,exynos5433-dwusb3 17 17 - samsung,exynos7-dwusb3 18 + - samsung,exynos850-dwusb3 18 19 19 20 '#address-cells': 20 21 const: 1 ··· 73 72 properties: 74 73 compatible: 75 74 contains: 76 - const: samsung,exynos54333-dwusb3 75 + const: samsung,exynos5433-dwusb3 77 76 then: 78 77 properties: 79 78 clocks: ··· 83 82 items: 84 83 - const: aclk 85 84 - const: susp_clk 86 - - const: pipe_pclk 87 85 - const: phyclk 86 + - const: pipe_pclk 88 87 89 88 - if: 90 89 properties: ··· 101 100 - const: usbdrd30 102 101 - const: usbdrd30_susp_clk 103 102 - const: usbdrd30_axius_clk 103 + 104 + - if: 105 + properties: 106 + compatible: 107 + contains: 108 + const: samsung,exynos850-dwusb3 109 + then: 110 + properties: 111 + clocks: 112 + minItems: 2 113 + maxItems: 2 114 + clock-names: 115 + items: 116 + - const: bus_early 117 + - const: ref 104 118 105 119 additionalProperties: false 106 120
+7 -2
Documentation/driver-api/usb/usb.rst
··· 420 420 know the devnum value already, it's the DDD value of the device file 421 421 name. 422 422 423 + USBDEVFS_GET_SPEED 424 + Returns the speed of the device. The speed is returned as a 425 + nummerical value in accordance with enum usb_device_speed 426 + 427 + File modification time is not updated by this request. 428 + 423 429 USBDEVFS_GETDRIVER 424 430 Returns the name of the kernel driver bound to a given interface (a 425 431 string). Parameter is a pointer to this structure, which is ··· 777 771 ======= ====================================================== 778 772 1.5 Mbit/s for low speed USB 779 773 12 Mbit/s for full speed USB 780 - 480 Mbit/s for high speed USB (added for USB 2.0); 781 - also used for Wireless USB, which has no fixed speed 774 + 480 Mbit/s for high speed USB (added for USB 2.0) 782 775 5000 Mbit/s for SuperSpeed USB (added for USB 3.0) 783 776 ======= ====================================================== 784 777
+3 -6
Documentation/usb/authorization.rst
··· 33 33 34 34 $ echo 1 > /sys/bus/usb/devices/usbX/authorized_default 35 35 36 - By default, Wired USB devices are authorized by default to 37 - connect. Wireless USB hosts deauthorize by default all new connected 38 - devices (this is so because we need to do an authentication phase 39 - before authorizing). Writing "2" to the authorized_default attribute 40 - causes kernel to only authorize by default devices connected to internal 41 - USB ports. 36 + By default, all USB devices are authorized. Writing "2" to the 37 + authorized_default attribute causes the kernel to authorize by default 38 + only devices connected to internal USB ports. 42 39 43 40 44 41 Example system lockdown (lame)
+154
Documentation/usb/gadget-testing.rst
··· 27 27 18. UVC function 28 28 19. PRINTER function 29 29 20. UAC1 function (new API) 30 + 21. MIDI2 function 30 31 31 32 32 33 1. ACM function ··· 966 965 967 966 $ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \ 968 967 aplay -D default:CARD=OdroidU3 968 + 969 + 970 + 21. MIDI2 function 971 + ================== 972 + 973 + The function is provided by usb_f_midi2.ko module. 974 + It will create a virtual ALSA card containing a UMP rawmidi device 975 + where the UMP packet is looped back. In addition, a legacy rawmidi 976 + device is created. The UMP rawmidi is bound with ALSA sequencer 977 + clients, too. 978 + 979 + Function-specific configfs interface 980 + ------------------------------------ 981 + 982 + The function name to use when creating the function directory is "midi2". 983 + The midi2 function provides these attributes in its function directory 984 + as the card top-level information: 985 + 986 + ============= ================================================= 987 + process_ump Bool flag to process UMP Stream messages (0 or 1) 988 + static_block Bool flag for static blocks (0 or 1) 989 + iface_name Optional interface name string 990 + ============= ================================================= 991 + 992 + The directory contains a subdirectory "ep.0", and this provides the 993 + attributes for a UMP Endpoint (which is a pair of USB MIDI Endpoints): 994 + 995 + ============= ================================================= 996 + protocol_caps MIDI protocol capabilities; 997 + 1: MIDI 1.0, 2: MIDI 2.0, or 3: both protocols 998 + protocol Default MIDI protocol (either 1 or 2) 999 + ep_name UMP Endpoint name string 1000 + product_id Product ID string 1001 + manufacturer Manufacture ID number (24 bit) 1002 + family Device family ID number (16 bit) 1003 + model Device model ID number (16 bit) 1004 + sw_revision Software revision (32 bit) 1005 + ============= ================================================= 1006 + 1007 + Each Endpoint subdirectory contains a subdirectory "block.0", which 1008 + represents the Function Block for Block 0 information. 1009 + Its attributes are: 1010 + 1011 + ================= =============================================== 1012 + name Function Block name string 1013 + direction Direction of this FB 1014 + 1: input, 2: output, or 3: bidirectional 1015 + first_group The first UMP Group number (0-15) 1016 + num_groups The number of groups in this FB (1-16) 1017 + midi1_first_group The first UMP Group number for MIDI 1.0 (0-15) 1018 + midi1_num_groups The number of groups for MIDI 1.0 (0-16) 1019 + ui_hint UI-hint of this FB 1020 + 0: unknown, 1: receiver, 2: sender, 3: both 1021 + midi_ci_verison Supported MIDI-CI version number (8 bit) 1022 + is_midi1 Legacy MIDI 1.0 device (0-2) 1023 + 0: MIDI 2.0 device, 1024 + 1: MIDI 1.0 without restriction, or 1025 + 2: MIDI 1.0 with low speed 1026 + sysex8_streams Max number of SysEx8 streams (8 bit) 1027 + active Bool flag for FB activity (0 or 1) 1028 + ================= =============================================== 1029 + 1030 + If multiple Function Blocks are required, you can add more Function 1031 + Blocks by creating subdirectories "block.<num>" with the corresponding 1032 + Function Block number (1, 2, ....). The FB subdirectories can be 1033 + dynamically removed, too. Note that the Function Block numbers must be 1034 + continuous. 1035 + 1036 + Similarly, if you multiple UMP Endpoints are required, you can add 1037 + more Endpoints by creating subdirectories "ep.<num>". The number must 1038 + be continuous. 1039 + 1040 + For emulating the old MIDI 2.0 device without UMP v1.1 support, pass 0 1041 + to `process_ump` flag. Then the whole UMP v1.1 requests are ignored. 1042 + 1043 + Testing the MIDI2 function 1044 + -------------------------- 1045 + 1046 + On the device: run the gadget, and running:: 1047 + 1048 + $ cat /proc/asound/cards 1049 + 1050 + will show a new sound card containing a MIDI2 device. 1051 + 1052 + OTOH, on the host:: 1053 + 1054 + $ cat /proc/asound/cards 1055 + 1056 + will show a new sound card containing either MIDI1 or MIDI2 device, 1057 + depending on the USB audio driver configuration. 1058 + 1059 + On both, when ALSA sequencer is enabled on the host, you can find the 1060 + UMP MIDI client such as "MIDI 2.0 Gadget". 1061 + 1062 + As the driver simply loops back the data, there is no need for a real 1063 + device just for testing. 1064 + 1065 + For testing a MIDI input from the gadget to the host (e.g. emulating a 1066 + MIDI keyboard), you can send a MIDI stream like the following. 1067 + 1068 + On the gadget:: 1069 + 1070 + $ aconnect -o 1071 + .... 1072 + client 20: 'MIDI 2.0 Gadget' [type=kernel,card=1] 1073 + 0 'MIDI 2.0 ' 1074 + 1 'Group 1 (MIDI 2.0 Gadget I/O)' 1075 + $ aplaymidi -p 20:1 to_host.mid 1076 + 1077 + On the host:: 1078 + 1079 + $ aconnect -i 1080 + .... 1081 + client 24: 'MIDI 2.0 Gadget' [type=kernel,card=2] 1082 + 0 'MIDI 2.0 ' 1083 + 1 'Group 1 (MIDI 2.0 Gadget I/O)' 1084 + $ arecordmidi -p 24:1 from_gadget.mid 1085 + 1086 + If you have a UMP-capable application, you can use the UMP port to 1087 + send/receive the raw UMP packets, too. For example, aseqdump program 1088 + with UMP support can receive from UMP port. On the host:: 1089 + 1090 + $ aseqdump -u 2 -p 24:1 1091 + Waiting for data. Press Ctrl+C to end. 1092 + Source Group Event Ch Data 1093 + 24:1 Group 0, Program change 0, program 0, Bank select 0:0 1094 + 24:1 Group 0, Channel pressure 0, value 0x80000000 1095 + 1096 + For testing a MIDI output to the gadget to the host (e.g. emulating a 1097 + MIDI synth), it'll be just other way round. 1098 + 1099 + On the gadget:: 1100 + 1101 + $ arecordmidi -p 20:1 from_host.mid 1102 + 1103 + On the host:: 1104 + 1105 + $ aplaymidi -p 24:1 to_gadget.mid 1106 + 1107 + The access to MIDI 1.0 on altset 0 on the host is supported, and it's 1108 + translated from/to UMP packets on the gadget. It's bound to only 1109 + Function Block 0. 1110 + 1111 + The current operation mode can be observed in ALSA control element 1112 + "Operation Mode" for SND_CTL_IFACE_RAWMIDI. For example:: 1113 + 1114 + $ amixer -c1 contents 1115 + numid=1,iface=RAWMIDI,name='Operation Mode' 1116 + ; type=INTEGER,access=r--v----,values=1,min=0,max=2,step=0 1117 + : values=2 1118 + 1119 + where 0 = unused, 1 = MIDI 1.0 (altset 0), 2 = MIDI 2.0 (altset 1). 1120 + The example above shows it's running in 2, i.e. MIDI 2.0.
-1
arch/mips/cavium-octeon/Makefile
··· 18 18 obj-$(CONFIG_MTD) += flash_setup.o 19 19 obj-$(CONFIG_SMP) += smp.o 20 20 obj-$(CONFIG_OCTEON_ILM) += oct_ilm.o 21 - obj-$(CONFIG_USB) += octeon-usb.o
-1
arch/mips/cavium-octeon/octeon-platform.c
··· 450 450 { .compatible = "cavium,octeon-3860-bootbus", }, 451 451 { .compatible = "cavium,mdio-mux", }, 452 452 { .compatible = "gpio-leds", }, 453 - { .compatible = "cavium,octeon-7130-usb-uctl", }, 454 453 {}, 455 454 }; 456 455
+213 -221
arch/mips/cavium-octeon/octeon-usb.c drivers/usb/dwc3/dwc3-octeon.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 - * XHCI HCD glue for Cavium Octeon III SOCs. 3 + * DWC3 glue for Cavium Octeon III SOCs. 3 4 * 4 5 * Copyright (C) 2010-2017 Cavium Networks 5 - * 6 - * This file is subject to the terms and conditions of the GNU General Public 7 - * License. See the file "COPYING" in the main directory of this archive 8 - * for more details. 6 + * Copyright (C) 2023 RACOM s.r.o. 9 7 */ 10 8 11 9 #include <linux/bitfield.h> ··· 22 24 /* BIST fast-clear mode select. A BIST run with this bit set 23 25 * clears all entries in USBH RAMs to 0x0. 24 26 */ 25 - # define USBDRD_UCTL_CTL_CLEAR_BIST BIT(63) 27 + # define USBDRD_UCTL_CTL_CLEAR_BIST BIT_ULL(63) 26 28 /* 1 = Start BIST and cleared by hardware */ 27 - # define USBDRD_UCTL_CTL_START_BIST BIT(62) 29 + # define USBDRD_UCTL_CTL_START_BIST BIT_ULL(62) 28 30 /* Reference clock select for SuperSpeed and HighSpeed PLLs: 29 31 * 0x0 = Both PLLs use DLMC_REF_CLK0 for reference clock 30 32 * 0x1 = Both PLLs use DLMC_REF_CLK1 for reference clock ··· 33 35 * 0x3 = SuperSpeed PLL uses DLMC_REF_CLK1 for reference clock & 34 36 * HighSpeed PLL uses PLL_REF_CLK for reference clck 35 37 */ 36 - # define USBDRD_UCTL_CTL_REF_CLK_SEL GENMASK(61, 60) 38 + # define USBDRD_UCTL_CTL_REF_CLK_SEL GENMASK_ULL(61, 60) 37 39 /* 1 = Spread-spectrum clock enable, 0 = SS clock disable */ 38 - # define USBDRD_UCTL_CTL_SSC_EN BIT(59) 40 + # define USBDRD_UCTL_CTL_SSC_EN BIT_ULL(59) 39 41 /* Spread-spectrum clock modulation range: 40 42 * 0x0 = -4980 ppm downspread 41 43 * 0x1 = -4492 ppm downspread 42 44 * 0x2 = -4003 ppm downspread 43 45 * 0x3 - 0x7 = Reserved 44 46 */ 45 - # define USBDRD_UCTL_CTL_SSC_RANGE GENMASK(58, 56) 47 + # define USBDRD_UCTL_CTL_SSC_RANGE GENMASK_ULL(58, 56) 46 48 /* Enable non-standard oscillator frequencies: 47 49 * [55:53] = modules -1 48 50 * [52:47] = 2's complement push amount, 0 = Feature disabled 49 51 */ 50 - # define USBDRD_UCTL_CTL_SSC_REF_CLK_SEL GENMASK(55, 47) 52 + # define USBDRD_UCTL_CTL_SSC_REF_CLK_SEL GENMASK_ULL(55, 47) 51 53 /* Reference clock multiplier for non-standard frequencies: 52 54 * 0x19 = 100MHz on DLMC_REF_CLK* if REF_CLK_SEL = 0x0 or 0x1 53 55 * 0x28 = 125MHz on DLMC_REF_CLK* if REF_CLK_SEL = 0x0 or 0x1 54 56 * 0x32 = 50MHz on DLMC_REF_CLK* if REF_CLK_SEL = 0x0 or 0x1 55 57 * Other Values = Reserved 56 58 */ 57 - # define USBDRD_UCTL_CTL_MPLL_MULTIPLIER GENMASK(46, 40) 59 + # define USBDRD_UCTL_CTL_MPLL_MULTIPLIER GENMASK_ULL(46, 40) 58 60 /* Enable reference clock to prescaler for SuperSpeed functionality. 59 61 * Should always be set to "1" 60 62 */ 61 - # define USBDRD_UCTL_CTL_REF_SSP_EN BIT(39) 63 + # define USBDRD_UCTL_CTL_REF_SSP_EN BIT_ULL(39) 62 64 /* Divide the reference clock by 2 before entering the 63 65 * REF_CLK_FSEL divider: 64 66 * If REF_CLK_SEL = 0x0 or 0x1, then only 0x0 is legal ··· 66 68 * 0x1 = DLMC_REF_CLK* is 125MHz 67 69 * 0x0 = DLMC_REF_CLK* is another supported frequency 68 70 */ 69 - # define USBDRD_UCTL_CTL_REF_CLK_DIV2 BIT(38) 71 + # define USBDRD_UCTL_CTL_REF_CLK_DIV2 BIT_ULL(38) 70 72 /* Select reference clock freqnuency for both PLL blocks: 71 73 * 0x27 = REF_CLK_SEL is 0x0 or 0x1 72 74 * 0x07 = REF_CLK_SEL is 0x2 or 0x3 73 75 */ 74 - # define USBDRD_UCTL_CTL_REF_CLK_FSEL GENMASK(37, 32) 76 + # define USBDRD_UCTL_CTL_REF_CLK_FSEL GENMASK_ULL(37, 32) 75 77 /* Controller clock enable. */ 76 - # define USBDRD_UCTL_CTL_H_CLK_EN BIT(30) 78 + # define USBDRD_UCTL_CTL_H_CLK_EN BIT_ULL(30) 77 79 /* Select bypass input to controller clock divider: 78 80 * 0x0 = Use divided coprocessor clock from H_CLKDIV 79 81 * 0x1 = Use clock from GPIO pins 80 82 */ 81 - # define USBDRD_UCTL_CTL_H_CLK_BYP_SEL BIT(29) 83 + # define USBDRD_UCTL_CTL_H_CLK_BYP_SEL BIT_ULL(29) 82 84 /* Reset controller clock divider. */ 83 - # define USBDRD_UCTL_CTL_H_CLKDIV_RST BIT(28) 85 + # define USBDRD_UCTL_CTL_H_CLKDIV_RST BIT_ULL(28) 84 86 /* Clock divider select: 85 87 * 0x0 = divide by 1 86 88 * 0x1 = divide by 2 ··· 91 93 * 0x6 = divide by 24 92 94 * 0x7 = divide by 32 93 95 */ 94 - # define USBDRD_UCTL_CTL_H_CLKDIV_SEL GENMASK(26, 24) 96 + # define USBDRD_UCTL_CTL_H_CLKDIV_SEL GENMASK_ULL(26, 24) 95 97 /* USB3 port permanently attached: 0x0 = No, 0x1 = Yes */ 96 - # define USBDRD_UCTL_CTL_USB3_PORT_PERM_ATTACH BIT(21) 98 + # define USBDRD_UCTL_CTL_USB3_PORT_PERM_ATTACH BIT_ULL(21) 97 99 /* USB2 port permanently attached: 0x0 = No, 0x1 = Yes */ 98 - # define USBDRD_UCTL_CTL_USB2_PORT_PERM_ATTACH BIT(20) 100 + # define USBDRD_UCTL_CTL_USB2_PORT_PERM_ATTACH BIT_ULL(20) 99 101 /* Disable SuperSpeed PHY: 0x0 = No, 0x1 = Yes */ 100 - # define USBDRD_UCTL_CTL_USB3_PORT_DISABLE BIT(18) 102 + # define USBDRD_UCTL_CTL_USB3_PORT_DISABLE BIT_ULL(18) 101 103 /* Disable HighSpeed PHY: 0x0 = No, 0x1 = Yes */ 102 - # define USBDRD_UCTL_CTL_USB2_PORT_DISABLE BIT(16) 104 + # define USBDRD_UCTL_CTL_USB2_PORT_DISABLE BIT_ULL(16) 103 105 /* Enable PHY SuperSpeed block power: 0x0 = No, 0x1 = Yes */ 104 - # define USBDRD_UCTL_CTL_SS_POWER_EN BIT(14) 106 + # define USBDRD_UCTL_CTL_SS_POWER_EN BIT_ULL(14) 105 107 /* Enable PHY HighSpeed block power: 0x0 = No, 0x1 = Yes */ 106 - # define USBDRD_UCTL_CTL_HS_POWER_EN BIT(12) 108 + # define USBDRD_UCTL_CTL_HS_POWER_EN BIT_ULL(12) 107 109 /* Enable USB UCTL interface clock: 0xx = No, 0x1 = Yes */ 108 - # define USBDRD_UCTL_CTL_CSCLK_EN BIT(4) 110 + # define USBDRD_UCTL_CTL_CSCLK_EN BIT_ULL(4) 109 111 /* Controller mode: 0x0 = Host, 0x1 = Device */ 110 - # define USBDRD_UCTL_CTL_DRD_MODE BIT(3) 112 + # define USBDRD_UCTL_CTL_DRD_MODE BIT_ULL(3) 111 113 /* PHY reset */ 112 - # define USBDRD_UCTL_CTL_UPHY_RST BIT(2) 114 + # define USBDRD_UCTL_CTL_UPHY_RST BIT_ULL(2) 113 115 /* Software reset UAHC */ 114 - # define USBDRD_UCTL_CTL_UAHC_RST BIT(1) 116 + # define USBDRD_UCTL_CTL_UAHC_RST BIT_ULL(1) 115 117 /* Software resets UCTL */ 116 - # define USBDRD_UCTL_CTL_UCTL_RST BIT(0) 118 + # define USBDRD_UCTL_CTL_UCTL_RST BIT_ULL(0) 117 119 118 120 #define USBDRD_UCTL_BIST_STATUS 0x08 119 121 #define USBDRD_UCTL_SPARE0 0x10 ··· 128 130 */ 129 131 #define USBDRD_UCTL_HOST_CFG 0xe0 130 132 /* Indicates minimum value of all received BELT values */ 131 - # define USBDRD_UCTL_HOST_CFG_HOST_CURRENT_BELT GENMASK(59, 48) 133 + # define USBDRD_UCTL_HOST_CFG_HOST_CURRENT_BELT GENMASK_ULL(59, 48) 132 134 /* HS jitter adjustment */ 133 - # define USBDRD_UCTL_HOST_CFG_FLA GENMASK(37, 32) 135 + # define USBDRD_UCTL_HOST_CFG_FLA GENMASK_ULL(37, 32) 134 136 /* Bus-master enable: 0x0 = Disabled (stall DMAs), 0x1 = enabled */ 135 - # define USBDRD_UCTL_HOST_CFG_BME BIT(28) 137 + # define USBDRD_UCTL_HOST_CFG_BME BIT_ULL(28) 136 138 /* Overcurrent protection enable: 0x0 = unavailable, 0x1 = available */ 137 - # define USBDRD_UCTL_HOST_OCI_EN BIT(27) 139 + # define USBDRD_UCTL_HOST_OCI_EN BIT_ULL(27) 138 140 /* Overcurrent sene selection: 139 141 * 0x0 = Overcurrent indication from off-chip is active-low 140 142 * 0x1 = Overcurrent indication from off-chip is active-high 141 143 */ 142 - # define USBDRD_UCTL_HOST_OCI_ACTIVE_HIGH_EN BIT(26) 144 + # define USBDRD_UCTL_HOST_OCI_ACTIVE_HIGH_EN BIT_ULL(26) 143 145 /* Port power control enable: 0x0 = unavailable, 0x1 = available */ 144 - # define USBDRD_UCTL_HOST_PPC_EN BIT(25) 146 + # define USBDRD_UCTL_HOST_PPC_EN BIT_ULL(25) 145 147 /* Port power control sense selection: 146 148 * 0x0 = Port power to off-chip is active-low 147 149 * 0x1 = Port power to off-chip is active-high 148 150 */ 149 - # define USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN BIT(24) 151 + # define USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN BIT_ULL(24) 150 152 151 153 /* 152 154 * UCTL Shim Features Register 153 155 */ 154 156 #define USBDRD_UCTL_SHIM_CFG 0xe8 155 157 /* Out-of-bound UAHC register access: 0 = read, 1 = write */ 156 - # define USBDRD_UCTL_SHIM_CFG_XS_NCB_OOB_WRN BIT(63) 158 + # define USBDRD_UCTL_SHIM_CFG_XS_NCB_OOB_WRN BIT_ULL(63) 157 159 /* SRCID error log for out-of-bound UAHC register access: 158 160 * [59:58] = chipID 159 161 * [57] = Request source: 0 = core, 1 = NCB-device 160 162 * [56:51] = Core/NCB-device number, [56] always 0 for NCB devices 161 163 * [50:48] = SubID 162 164 */ 163 - # define USBDRD_UCTL_SHIM_CFG_XS_NCB_OOB_OSRC GENMASK(59, 48) 165 + # define USBDRD_UCTL_SHIM_CFG_XS_NCB_OOB_OSRC GENMASK_ULL(59, 48) 164 166 /* Error log for bad UAHC DMA access: 0 = Read log, 1 = Write log */ 165 - # define USBDRD_UCTL_SHIM_CFG_XM_BAD_DMA_WRN BIT(47) 167 + # define USBDRD_UCTL_SHIM_CFG_XM_BAD_DMA_WRN BIT_ULL(47) 166 168 /* Encoded error type for bad UAHC DMA */ 167 - # define USBDRD_UCTL_SHIM_CFG_XM_BAD_DMA_TYPE GENMASK(43, 40) 169 + # define USBDRD_UCTL_SHIM_CFG_XM_BAD_DMA_TYPE GENMASK_ULL(43, 40) 168 170 /* Select the IOI read command used by DMA accesses */ 169 - # define USBDRD_UCTL_SHIM_CFG_DMA_READ_CMD BIT(12) 171 + # define USBDRD_UCTL_SHIM_CFG_DMA_READ_CMD BIT_ULL(12) 170 172 /* Select endian format for DMA accesses to the L2C: 171 173 * 0x0 = Little endian 172 174 * 0x1 = Big endian 173 175 * 0x2 = Reserved 174 176 * 0x3 = Reserved 175 177 */ 176 - # define USBDRD_UCTL_SHIM_CFG_DMA_ENDIAN_MODE GENMASK(9, 8) 178 + # define USBDRD_UCTL_SHIM_CFG_DMA_ENDIAN_MODE GENMASK_ULL(9, 8) 177 179 /* Select endian format for IOI CSR access to UAHC: 178 180 * 0x0 = Little endian 179 181 * 0x1 = Big endian 180 182 * 0x2 = Reserved 181 183 * 0x3 = Reserved 182 184 */ 183 - # define USBDRD_UCTL_SHIM_CFG_CSR_ENDIAN_MODE GENMASK(1, 0) 185 + # define USBDRD_UCTL_SHIM_CFG_CSR_ENDIAN_MODE GENMASK_ULL(1, 0) 184 186 185 187 #define USBDRD_UCTL_ECC 0xf0 186 188 #define USBDRD_UCTL_SPARE1 0xf8 187 189 188 - static DEFINE_MUTEX(dwc3_octeon_clocks_mutex); 190 + struct dwc3_octeon { 191 + struct device *dev; 192 + void __iomem *base; 193 + }; 194 + 195 + #define DWC3_GPIO_POWER_NONE (-1) 189 196 190 197 #ifdef CONFIG_CAVIUM_OCTEON_SOC 191 198 #include <asm/octeon/octeon.h> ··· 236 233 static inline void dwc3_octeon_writeq(void __iomem *base, uint64_t val) { } 237 234 238 235 static inline void dwc3_octeon_config_gpio(int index, int gpio) { } 236 + 237 + static uint64_t octeon_get_io_clock_rate(void) 238 + { 239 + return 150000000; 240 + } 239 241 #endif 240 242 241 243 static int dwc3_octeon_get_divider(void) ··· 251 243 while (div < ARRAY_SIZE(clk_div)) { 252 244 uint64_t rate = octeon_get_io_clock_rate() / clk_div[div]; 253 245 if (rate <= 300000000 && rate >= 150000000) 254 - break; 246 + return div; 255 247 div++; 256 248 } 257 249 258 - return div; 250 + return -EINVAL; 259 251 } 260 252 261 - static int dwc3_octeon_config_power(struct device *dev, void __iomem *base) 253 + static int dwc3_octeon_setup(struct dwc3_octeon *octeon, 254 + int ref_clk_sel, int ref_clk_fsel, int mpll_mul, 255 + int power_gpio, int power_active_low) 262 256 { 263 - uint32_t gpio_pwr[3]; 264 - int gpio, len, power_active_low; 265 - struct device_node *node = dev->of_node; 266 257 u64 val; 267 - void __iomem *uctl_host_cfg_reg = base + USBDRD_UCTL_HOST_CFG; 268 - 269 - if (of_find_property(node, "power", &len) != NULL) { 270 - if (len == 12) { 271 - of_property_read_u32_array(node, "power", gpio_pwr, 3); 272 - power_active_low = gpio_pwr[2] & 0x01; 273 - gpio = gpio_pwr[1]; 274 - } else if (len == 8) { 275 - of_property_read_u32_array(node, "power", gpio_pwr, 2); 276 - power_active_low = 0; 277 - gpio = gpio_pwr[1]; 278 - } else { 279 - dev_err(dev, "invalid power configuration\n"); 280 - return -EINVAL; 281 - } 282 - dwc3_octeon_config_gpio(((u64)base >> 24) & 1, gpio); 283 - 284 - /* Enable XHCI power control and set if active high or low. */ 285 - val = dwc3_octeon_readq(uctl_host_cfg_reg); 286 - val |= USBDRD_UCTL_HOST_PPC_EN; 287 - if (power_active_low) 288 - val &= ~USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN; 289 - else 290 - val |= USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN; 291 - dwc3_octeon_writeq(uctl_host_cfg_reg, val); 292 - } else { 293 - /* Disable XHCI power control and set if active high. */ 294 - val = dwc3_octeon_readq(uctl_host_cfg_reg); 295 - val &= ~USBDRD_UCTL_HOST_PPC_EN; 296 - val &= ~USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN; 297 - dwc3_octeon_writeq(uctl_host_cfg_reg, val); 298 - dev_info(dev, "power control disabled\n"); 299 - } 300 - return 0; 301 - } 302 - 303 - static int dwc3_octeon_clocks_start(struct device *dev, void __iomem *base) 304 - { 305 - int i, div, mpll_mul, ref_clk_fsel, ref_clk_sel = 2; 306 - u32 clock_rate; 307 - u64 val; 308 - void __iomem *uctl_ctl_reg = base + USBDRD_UCTL_CTL; 309 - 310 - if (dev->of_node) { 311 - const char *ss_clock_type; 312 - const char *hs_clock_type; 313 - 314 - i = of_property_read_u32(dev->of_node, 315 - "refclk-frequency", &clock_rate); 316 - if (i) { 317 - dev_err(dev, "No UCTL \"refclk-frequency\"\n"); 318 - return -EINVAL; 319 - } 320 - i = of_property_read_string(dev->of_node, 321 - "refclk-type-ss", &ss_clock_type); 322 - if (i) { 323 - dev_err(dev, "No UCTL \"refclk-type-ss\"\n"); 324 - return -EINVAL; 325 - } 326 - i = of_property_read_string(dev->of_node, 327 - "refclk-type-hs", &hs_clock_type); 328 - if (i) { 329 - dev_err(dev, "No UCTL \"refclk-type-hs\"\n"); 330 - return -EINVAL; 331 - } 332 - if (strcmp("dlmc_ref_clk0", ss_clock_type) == 0) { 333 - if (strcmp(hs_clock_type, "dlmc_ref_clk0") == 0) 334 - ref_clk_sel = 0; 335 - else if (strcmp(hs_clock_type, "pll_ref_clk") == 0) 336 - ref_clk_sel = 2; 337 - else 338 - dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n", 339 - hs_clock_type); 340 - } else if (strcmp(ss_clock_type, "dlmc_ref_clk1") == 0) { 341 - if (strcmp(hs_clock_type, "dlmc_ref_clk1") == 0) 342 - ref_clk_sel = 1; 343 - else if (strcmp(hs_clock_type, "pll_ref_clk") == 0) 344 - ref_clk_sel = 3; 345 - else { 346 - dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n", 347 - hs_clock_type); 348 - ref_clk_sel = 3; 349 - } 350 - } else 351 - dev_warn(dev, "Invalid SS clock type %s, using dlmc_ref_clk0 instead\n", 352 - ss_clock_type); 353 - 354 - if ((ref_clk_sel == 0 || ref_clk_sel == 1) && 355 - (clock_rate != 100000000)) 356 - dev_warn(dev, "Invalid UCTL clock rate of %u, using 100000000 instead\n", 357 - clock_rate); 358 - 359 - } else { 360 - dev_err(dev, "No USB UCTL device node\n"); 361 - return -EINVAL; 362 - } 258 + int div; 259 + struct device *dev = octeon->dev; 260 + void __iomem *uctl_ctl_reg = octeon->base + USBDRD_UCTL_CTL; 261 + void __iomem *uctl_host_cfg_reg = octeon->base + USBDRD_UCTL_HOST_CFG; 363 262 364 263 /* 365 264 * Step 1: Wait for all voltages to be stable...that surely ··· 289 374 290 375 /* Step 4b: Select controller clock frequency. */ 291 376 div = dwc3_octeon_get_divider(); 377 + if (div < 0) { 378 + dev_err(dev, "clock divider invalid\n"); 379 + return div; 380 + } 292 381 val = dwc3_octeon_readq(uctl_ctl_reg); 293 382 val &= ~USBDRD_UCTL_CTL_H_CLKDIV_SEL; 294 383 val |= FIELD_PREP(USBDRD_UCTL_CTL_H_CLKDIV_SEL, div); ··· 301 382 val = dwc3_octeon_readq(uctl_ctl_reg); 302 383 if ((div != FIELD_GET(USBDRD_UCTL_CTL_H_CLKDIV_SEL, val)) || 303 384 (!(FIELD_GET(USBDRD_UCTL_CTL_H_CLK_EN, val)))) { 304 - dev_err(dev, "dwc3 controller clock init failure.\n"); 305 - return -EINVAL; 385 + dev_err(dev, "clock init failure (UCTL_CTL=%016llx)\n", val); 386 + return -EINVAL; 306 387 } 307 388 308 389 /* Step 4c: Deassert the controller clock divider reset. */ ··· 315 396 val &= ~USBDRD_UCTL_CTL_REF_CLK_SEL; 316 397 val |= FIELD_PREP(USBDRD_UCTL_CTL_REF_CLK_SEL, ref_clk_sel); 317 398 318 - ref_clk_fsel = 0x07; 319 - switch (clock_rate) { 320 - default: 321 - dev_warn(dev, "Invalid ref_clk %u, using 100000000 instead\n", 322 - clock_rate); 323 - fallthrough; 324 - case 100000000: 325 - mpll_mul = 0x19; 326 - if (ref_clk_sel < 2) 327 - ref_clk_fsel = 0x27; 328 - break; 329 - case 50000000: 330 - mpll_mul = 0x32; 331 - break; 332 - case 125000000: 333 - mpll_mul = 0x28; 334 - break; 335 - } 336 399 val &= ~USBDRD_UCTL_CTL_REF_CLK_FSEL; 337 400 val |= FIELD_PREP(USBDRD_UCTL_CTL_REF_CLK_FSEL, ref_clk_fsel); 338 401 ··· 345 444 /* Step 8b: Wait 10 controller-clock cycles. */ 346 445 udelay(10); 347 446 348 - /* Steo 8c: Setup power-power control. */ 349 - if (dwc3_octeon_config_power(dev, base)) 350 - return -EINVAL; 447 + /* Step 8c: Setup power control. */ 448 + val = dwc3_octeon_readq(uctl_host_cfg_reg); 449 + val |= USBDRD_UCTL_HOST_PPC_EN; 450 + if (power_gpio == DWC3_GPIO_POWER_NONE) { 451 + val &= ~USBDRD_UCTL_HOST_PPC_EN; 452 + } else { 453 + val |= USBDRD_UCTL_HOST_PPC_EN; 454 + dwc3_octeon_config_gpio(((__force uintptr_t)octeon->base >> 24) & 1, 455 + power_gpio); 456 + dev_dbg(dev, "power control is using gpio%d\n", power_gpio); 457 + } 458 + if (power_active_low) 459 + val &= ~USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN; 460 + else 461 + val |= USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN; 462 + dwc3_octeon_writeq(uctl_host_cfg_reg, val); 351 463 352 464 /* Step 8d: Deassert UAHC reset signal. */ 353 465 val = dwc3_octeon_readq(uctl_ctl_reg); ··· 383 469 return 0; 384 470 } 385 471 386 - static void __init dwc3_octeon_set_endian_mode(void __iomem *base) 472 + static void dwc3_octeon_set_endian_mode(struct dwc3_octeon *octeon) 387 473 { 388 474 u64 val; 389 - void __iomem *uctl_shim_cfg_reg = base + USBDRD_UCTL_SHIM_CFG; 475 + void __iomem *uctl_shim_cfg_reg = octeon->base + USBDRD_UCTL_SHIM_CFG; 390 476 391 477 val = dwc3_octeon_readq(uctl_shim_cfg_reg); 392 478 val &= ~USBDRD_UCTL_SHIM_CFG_DMA_ENDIAN_MODE; ··· 398 484 dwc3_octeon_writeq(uctl_shim_cfg_reg, val); 399 485 } 400 486 401 - static void __init dwc3_octeon_phy_reset(void __iomem *base) 487 + static void dwc3_octeon_phy_reset(struct dwc3_octeon *octeon) 402 488 { 403 489 u64 val; 404 - void __iomem *uctl_ctl_reg = base + USBDRD_UCTL_CTL; 490 + void __iomem *uctl_ctl_reg = octeon->base + USBDRD_UCTL_CTL; 405 491 406 492 val = dwc3_octeon_readq(uctl_ctl_reg); 407 493 val &= ~USBDRD_UCTL_CTL_UPHY_RST; 408 494 dwc3_octeon_writeq(uctl_ctl_reg, val); 409 495 } 410 496 411 - static int __init dwc3_octeon_device_init(void) 497 + static int dwc3_octeon_probe(struct platform_device *pdev) 412 498 { 413 - const char compat_node_name[] = "cavium,octeon-7130-usb-uctl"; 414 - struct platform_device *pdev; 415 - struct device_node *node; 416 - struct resource *res; 417 - void __iomem *base; 499 + struct device *dev = &pdev->dev; 500 + struct device_node *node = dev->of_node; 501 + struct dwc3_octeon *octeon; 502 + const char *hs_clock_type, *ss_clock_type; 503 + int ref_clk_sel, ref_clk_fsel, mpll_mul; 504 + int power_active_low, power_gpio; 505 + int err, len; 506 + u32 clock_rate; 418 507 419 - /* 420 - * There should only be three universal controllers, "uctl" 421 - * in the device tree. Two USB and a SATA, which we ignore. 422 - */ 423 - node = NULL; 424 - do { 425 - node = of_find_node_by_name(node, "uctl"); 426 - if (!node) 427 - return -ENODEV; 508 + if (of_property_read_u32(node, "refclk-frequency", &clock_rate)) { 509 + dev_err(dev, "No UCTL \"refclk-frequency\"\n"); 510 + return -EINVAL; 511 + } 512 + if (of_property_read_string(node, "refclk-type-ss", &ss_clock_type)) { 513 + dev_err(dev, "No UCTL \"refclk-type-ss\"\n"); 514 + return -EINVAL; 515 + } 516 + if (of_property_read_string(node, "refclk-type-hs", &hs_clock_type)) { 517 + dev_err(dev, "No UCTL \"refclk-type-hs\"\n"); 518 + return -EINVAL; 519 + } 428 520 429 - if (of_device_is_compatible(node, compat_node_name)) { 430 - pdev = of_find_device_by_node(node); 431 - if (!pdev) 432 - return -ENODEV; 433 - 434 - /* 435 - * The code below maps in the registers necessary for 436 - * setting up the clocks and reseting PHYs. We must 437 - * release the resources so the dwc3 subsystem doesn't 438 - * know the difference. 439 - */ 440 - base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 441 - if (IS_ERR(base)) { 442 - put_device(&pdev->dev); 443 - return PTR_ERR(base); 444 - } 445 - 446 - mutex_lock(&dwc3_octeon_clocks_mutex); 447 - if (dwc3_octeon_clocks_start(&pdev->dev, base) == 0) 448 - dev_info(&pdev->dev, "clocks initialized.\n"); 449 - dwc3_octeon_set_endian_mode(base); 450 - dwc3_octeon_phy_reset(base); 451 - mutex_unlock(&dwc3_octeon_clocks_mutex); 452 - devm_iounmap(&pdev->dev, base); 453 - devm_release_mem_region(&pdev->dev, res->start, 454 - resource_size(res)); 455 - put_device(&pdev->dev); 521 + ref_clk_sel = 2; 522 + if (strcmp("dlmc_ref_clk0", ss_clock_type) == 0) { 523 + if (strcmp(hs_clock_type, "dlmc_ref_clk0") == 0) 524 + ref_clk_sel = 0; 525 + else if (strcmp(hs_clock_type, "pll_ref_clk")) 526 + dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n", 527 + hs_clock_type); 528 + } else if (strcmp(ss_clock_type, "dlmc_ref_clk1") == 0) { 529 + if (strcmp(hs_clock_type, "dlmc_ref_clk1") == 0) { 530 + ref_clk_sel = 1; 531 + } else { 532 + ref_clk_sel = 3; 533 + if (strcmp(hs_clock_type, "pll_ref_clk")) 534 + dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n", 535 + hs_clock_type); 456 536 } 457 - } while (node != NULL); 537 + } else { 538 + dev_warn(dev, "Invalid SS clock type %s, using dlmc_ref_clk0 instead\n", 539 + ss_clock_type); 540 + } 458 541 459 - return 0; 542 + ref_clk_fsel = 0x07; 543 + switch (clock_rate) { 544 + default: 545 + dev_warn(dev, "Invalid ref_clk %u, using 100000000 instead\n", 546 + clock_rate); 547 + fallthrough; 548 + case 100000000: 549 + mpll_mul = 0x19; 550 + if (ref_clk_sel < 2) 551 + ref_clk_fsel = 0x27; 552 + break; 553 + case 50000000: 554 + mpll_mul = 0x32; 555 + break; 556 + case 125000000: 557 + mpll_mul = 0x28; 558 + break; 559 + } 560 + 561 + power_gpio = DWC3_GPIO_POWER_NONE; 562 + power_active_low = 0; 563 + if (of_find_property(node, "power", &len)) { 564 + u32 gpio_pwr[3]; 565 + 566 + switch (len) { 567 + case 8: 568 + of_property_read_u32_array(node, "power", gpio_pwr, 2); 569 + break; 570 + case 12: 571 + of_property_read_u32_array(node, "power", gpio_pwr, 3); 572 + power_active_low = gpio_pwr[2] & 0x01; 573 + break; 574 + default: 575 + dev_err(dev, "invalid power configuration\n"); 576 + return -EINVAL; 577 + } 578 + power_gpio = gpio_pwr[1]; 579 + } 580 + 581 + octeon = devm_kzalloc(dev, sizeof(*octeon), GFP_KERNEL); 582 + if (!octeon) 583 + return -ENOMEM; 584 + 585 + octeon->dev = dev; 586 + octeon->base = devm_platform_ioremap_resource(pdev, 0); 587 + if (IS_ERR(octeon->base)) 588 + return PTR_ERR(octeon->base); 589 + 590 + err = dwc3_octeon_setup(octeon, ref_clk_sel, ref_clk_fsel, mpll_mul, 591 + power_gpio, power_active_low); 592 + if (err) 593 + return err; 594 + 595 + dwc3_octeon_set_endian_mode(octeon); 596 + dwc3_octeon_phy_reset(octeon); 597 + 598 + platform_set_drvdata(pdev, octeon); 599 + 600 + return of_platform_populate(node, NULL, NULL, dev); 460 601 } 461 - device_initcall(dwc3_octeon_device_init); 462 602 463 - MODULE_AUTHOR("David Daney <david.daney@cavium.com>"); 603 + static void dwc3_octeon_remove(struct platform_device *pdev) 604 + { 605 + struct dwc3_octeon *octeon = platform_get_drvdata(pdev); 606 + 607 + of_platform_depopulate(octeon->dev); 608 + } 609 + 610 + static const struct of_device_id dwc3_octeon_of_match[] = { 611 + { .compatible = "cavium,octeon-7130-usb-uctl" }, 612 + { }, 613 + }; 614 + MODULE_DEVICE_TABLE(of, dwc3_octeon_of_match); 615 + 616 + static struct platform_driver dwc3_octeon_driver = { 617 + .probe = dwc3_octeon_probe, 618 + .remove_new = dwc3_octeon_remove, 619 + .driver = { 620 + .name = "dwc3-octeon", 621 + .of_match_table = dwc3_octeon_of_match, 622 + }, 623 + }; 624 + module_platform_driver(dwc3_octeon_driver); 625 + 626 + MODULE_ALIAS("platform:dwc3-octeon"); 627 + MODULE_AUTHOR("Ladislav Michl <ladis@linux-mips.org>"); 464 628 MODULE_LICENSE("GPL"); 465 - MODULE_DESCRIPTION("USB driver for OCTEON III SoC"); 629 + MODULE_DESCRIPTION("DesignWare USB3 OCTEON III Glue Layer");
+1 -2
drivers/net/wireless/mediatek/mt76/usb.c
··· 286 286 struct usb_device *udev = interface_to_usbdev(uintf); 287 287 288 288 return (!disable_usb_sg && udev->bus->sg_tablesize > 0 && 289 - (udev->bus->no_sg_constraint || 290 - udev->speed == USB_SPEED_WIRELESS)); 289 + udev->bus->no_sg_constraint); 291 290 } 292 291 293 292 static int
+1
drivers/phy/Kconfig
··· 87 87 source "drivers/phy/mscc/Kconfig" 88 88 source "drivers/phy/qualcomm/Kconfig" 89 89 source "drivers/phy/ralink/Kconfig" 90 + source "drivers/phy/realtek/Kconfig" 90 91 source "drivers/phy/renesas/Kconfig" 91 92 source "drivers/phy/rockchip/Kconfig" 92 93 source "drivers/phy/samsung/Kconfig"
+1
drivers/phy/Makefile
··· 26 26 mscc/ \ 27 27 qualcomm/ \ 28 28 ralink/ \ 29 + realtek/ \ 29 30 renesas/ \ 30 31 rockchip/ \ 31 32 samsung/ \
+27
drivers/phy/realtek/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # Phy drivers for Realtek platforms 4 + # 5 + config PHY_RTK_RTD_USB2PHY 6 + tristate "Realtek RTD USB2 PHY Transceiver Driver" 7 + depends on USB_SUPPORT 8 + select GENERIC_PHY 9 + select USB_PHY 10 + select USB_COMMON 11 + help 12 + Enable this to support Realtek SoC USB2 phy transceiver. 13 + The DHC (digital home center) RTD series SoCs used the Synopsys 14 + DWC3 USB IP. This driver will do the PHY initialization 15 + of the parameters. 16 + 17 + config PHY_RTK_RTD_USB3PHY 18 + tristate "Realtek RTD USB3 PHY Transceiver Driver" 19 + depends on USB_SUPPORT 20 + select GENERIC_PHY 21 + select USB_PHY 22 + select USB_COMMON 23 + help 24 + Enable this to support Realtek SoC USB3 phy transceiver. 25 + The DHC (digital home center) RTD series SoCs used the Synopsys 26 + DWC3 USB IP. This driver will do the PHY initialization 27 + of the parameters.
+3
drivers/phy/realtek/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + obj-$(CONFIG_PHY_RTK_RTD_USB2PHY) += phy-rtk-usb2.o 3 + obj-$(CONFIG_PHY_RTK_RTD_USB3PHY) += phy-rtk-usb3.o
+1331
drivers/phy/realtek/phy-rtk-usb2.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * phy-rtk-usb2.c RTK usb2.0 PHY driver 4 + * 5 + * Copyright (C) 2023 Realtek Semiconductor Corporation 6 + * 7 + */ 8 + 9 + #include <linux/module.h> 10 + #include <linux/of.h> 11 + #include <linux/of_device.h> 12 + #include <linux/of_address.h> 13 + #include <linux/uaccess.h> 14 + #include <linux/debugfs.h> 15 + #include <linux/nvmem-consumer.h> 16 + #include <linux/regmap.h> 17 + #include <linux/sys_soc.h> 18 + #include <linux/mfd/syscon.h> 19 + #include <linux/phy/phy.h> 20 + #include <linux/usb.h> 21 + #include <linux/usb/phy.h> 22 + #include <linux/usb/hcd.h> 23 + 24 + /* GUSB2PHYACCn register */ 25 + #define PHY_NEW_REG_REQ BIT(25) 26 + #define PHY_VSTS_BUSY BIT(23) 27 + #define PHY_VCTRL_SHIFT 8 28 + #define PHY_REG_DATA_MASK 0xff 29 + 30 + #define GET_LOW_NIBBLE(addr) ((addr) & 0x0f) 31 + #define GET_HIGH_NIBBLE(addr) (((addr) & 0xf0) >> 4) 32 + 33 + #define EFUS_USB_DC_CAL_RATE 2 34 + #define EFUS_USB_DC_CAL_MAX 7 35 + 36 + #define EFUS_USB_DC_DIS_RATE 1 37 + #define EFUS_USB_DC_DIS_MAX 7 38 + 39 + #define MAX_PHY_DATA_SIZE 20 40 + #define OFFEST_PHY_READ 0x20 41 + 42 + #define MAX_USB_PHY_NUM 4 43 + #define MAX_USB_PHY_PAGE0_DATA_SIZE 16 44 + #define MAX_USB_PHY_PAGE1_DATA_SIZE 16 45 + #define MAX_USB_PHY_PAGE2_DATA_SIZE 8 46 + 47 + #define SET_PAGE_OFFSET 0xf4 48 + #define SET_PAGE_0 0x9b 49 + #define SET_PAGE_1 0xbb 50 + #define SET_PAGE_2 0xdb 51 + 52 + #define PAGE_START 0xe0 53 + #define PAGE0_0XE4 0xe4 54 + #define PAGE0_0XE6 0xe6 55 + #define PAGE0_0XE7 0xe7 56 + #define PAGE1_0XE0 0xe0 57 + #define PAGE1_0XE2 0xe2 58 + 59 + #define SENSITIVITY_CTRL (BIT(4) | BIT(5) | BIT(6)) 60 + #define ENABLE_AUTO_SENSITIVITY_CALIBRATION BIT(2) 61 + #define DEFAULT_DC_DRIVING_VALUE (0x8) 62 + #define DEFAULT_DC_DISCONNECTION_VALUE (0x6) 63 + #define HS_CLK_SELECT BIT(6) 64 + 65 + struct phy_reg { 66 + void __iomem *reg_wrap_vstatus; 67 + void __iomem *reg_gusb2phyacc0; 68 + int vstatus_index; 69 + }; 70 + 71 + struct phy_data { 72 + u8 addr; 73 + u8 data; 74 + }; 75 + 76 + struct phy_cfg { 77 + int page0_size; 78 + struct phy_data page0[MAX_USB_PHY_PAGE0_DATA_SIZE]; 79 + int page1_size; 80 + struct phy_data page1[MAX_USB_PHY_PAGE1_DATA_SIZE]; 81 + int page2_size; 82 + struct phy_data page2[MAX_USB_PHY_PAGE2_DATA_SIZE]; 83 + 84 + int num_phy; 85 + 86 + bool check_efuse; 87 + int check_efuse_version; 88 + #define CHECK_EFUSE_V1 1 89 + #define CHECK_EFUSE_V2 2 90 + int efuse_dc_driving_rate; 91 + int efuse_dc_disconnect_rate; 92 + int dc_driving_mask; 93 + int dc_disconnect_mask; 94 + bool usb_dc_disconnect_at_page0; 95 + int driving_updated_for_dev_dis; 96 + 97 + bool do_toggle; 98 + bool do_toggle_driving; 99 + bool use_default_parameter; 100 + bool is_double_sensitivity_mode; 101 + }; 102 + 103 + struct phy_parameter { 104 + struct phy_reg phy_reg; 105 + 106 + /* Get from efuse */ 107 + s8 efuse_usb_dc_cal; 108 + s8 efuse_usb_dc_dis; 109 + 110 + /* Get from dts */ 111 + bool inverse_hstx_sync_clock; 112 + u32 driving_level; 113 + s32 driving_level_compensate; 114 + s32 disconnection_compensate; 115 + }; 116 + 117 + struct rtk_phy { 118 + struct usb_phy phy; 119 + struct device *dev; 120 + 121 + struct phy_cfg *phy_cfg; 122 + int num_phy; 123 + struct phy_parameter *phy_parameter; 124 + 125 + struct dentry *debug_dir; 126 + }; 127 + 128 + /* mapping 0xE0 to 0 ... 0xE7 to 7, 0xF0 to 8 ,,, 0xF7 to 15 */ 129 + static inline int page_addr_to_array_index(u8 addr) 130 + { 131 + return (int)((((addr) - PAGE_START) & 0x7) + 132 + ((((addr) - PAGE_START) & 0x10) >> 1)); 133 + } 134 + 135 + static inline u8 array_index_to_page_addr(int index) 136 + { 137 + return ((((index) + PAGE_START) & 0x7) + 138 + ((((index) & 0x8) << 1) + PAGE_START)); 139 + } 140 + 141 + #define PHY_IO_TIMEOUT_USEC (50000) 142 + #define PHY_IO_DELAY_US (100) 143 + 144 + static inline int utmi_wait_register(void __iomem *reg, u32 mask, u32 result) 145 + { 146 + int ret; 147 + unsigned int val; 148 + 149 + ret = read_poll_timeout(readl, val, ((val & mask) == result), 150 + PHY_IO_DELAY_US, PHY_IO_TIMEOUT_USEC, false, reg); 151 + if (ret) { 152 + pr_err("%s can't program USB phy\n", __func__); 153 + return -ETIMEDOUT; 154 + } 155 + 156 + return 0; 157 + } 158 + 159 + static char rtk_phy_read(struct phy_reg *phy_reg, char addr) 160 + { 161 + void __iomem *reg_gusb2phyacc0 = phy_reg->reg_gusb2phyacc0; 162 + unsigned int val; 163 + int ret = 0; 164 + 165 + addr -= OFFEST_PHY_READ; 166 + 167 + /* polling until VBusy == 0 */ 168 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 169 + if (ret) 170 + return (char)ret; 171 + 172 + /* VCtrl = low nibble of addr, and set PHY_NEW_REG_REQ */ 173 + val = PHY_NEW_REG_REQ | (GET_LOW_NIBBLE(addr) << PHY_VCTRL_SHIFT); 174 + writel(val, reg_gusb2phyacc0); 175 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 176 + if (ret) 177 + return (char)ret; 178 + 179 + /* VCtrl = high nibble of addr, and set PHY_NEW_REG_REQ */ 180 + val = PHY_NEW_REG_REQ | (GET_HIGH_NIBBLE(addr) << PHY_VCTRL_SHIFT); 181 + writel(val, reg_gusb2phyacc0); 182 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 183 + if (ret) 184 + return (char)ret; 185 + 186 + val = readl(reg_gusb2phyacc0); 187 + 188 + return (char)(val & PHY_REG_DATA_MASK); 189 + } 190 + 191 + static int rtk_phy_write(struct phy_reg *phy_reg, char addr, char data) 192 + { 193 + unsigned int val; 194 + void __iomem *reg_wrap_vstatus = phy_reg->reg_wrap_vstatus; 195 + void __iomem *reg_gusb2phyacc0 = phy_reg->reg_gusb2phyacc0; 196 + int shift_bits = phy_reg->vstatus_index * 8; 197 + int ret = 0; 198 + 199 + /* write data to VStatusOut2 (data output to phy) */ 200 + writel((u32)data << shift_bits, reg_wrap_vstatus); 201 + 202 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 203 + if (ret) 204 + return ret; 205 + 206 + /* VCtrl = low nibble of addr, set PHY_NEW_REG_REQ */ 207 + val = PHY_NEW_REG_REQ | (GET_LOW_NIBBLE(addr) << PHY_VCTRL_SHIFT); 208 + 209 + writel(val, reg_gusb2phyacc0); 210 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 211 + if (ret) 212 + return ret; 213 + 214 + /* VCtrl = high nibble of addr, set PHY_NEW_REG_REQ */ 215 + val = PHY_NEW_REG_REQ | (GET_HIGH_NIBBLE(addr) << PHY_VCTRL_SHIFT); 216 + 217 + writel(val, reg_gusb2phyacc0); 218 + ret = utmi_wait_register(reg_gusb2phyacc0, PHY_VSTS_BUSY, 0); 219 + if (ret) 220 + return ret; 221 + 222 + return 0; 223 + } 224 + 225 + static int rtk_phy_set_page(struct phy_reg *phy_reg, int page) 226 + { 227 + switch (page) { 228 + case 0: 229 + return rtk_phy_write(phy_reg, SET_PAGE_OFFSET, SET_PAGE_0); 230 + case 1: 231 + return rtk_phy_write(phy_reg, SET_PAGE_OFFSET, SET_PAGE_1); 232 + case 2: 233 + return rtk_phy_write(phy_reg, SET_PAGE_OFFSET, SET_PAGE_2); 234 + default: 235 + pr_err("%s error page=%d\n", __func__, page); 236 + } 237 + 238 + return -EINVAL; 239 + } 240 + 241 + static u8 __updated_dc_disconnect_level_page0_0xe4(struct phy_cfg *phy_cfg, 242 + struct phy_parameter *phy_parameter, u8 data) 243 + { 244 + u8 ret; 245 + s32 val; 246 + s32 dc_disconnect_mask = phy_cfg->dc_disconnect_mask; 247 + int offset = 4; 248 + 249 + val = (s32)((data >> offset) & dc_disconnect_mask) 250 + + phy_parameter->efuse_usb_dc_dis 251 + + phy_parameter->disconnection_compensate; 252 + 253 + if (val > dc_disconnect_mask) 254 + val = dc_disconnect_mask; 255 + else if (val < 0) 256 + val = 0; 257 + 258 + ret = (data & (~(dc_disconnect_mask << offset))) | 259 + (val & dc_disconnect_mask) << offset; 260 + 261 + return ret; 262 + } 263 + 264 + /* updated disconnect level at page0 */ 265 + static void update_dc_disconnect_level_at_page0(struct rtk_phy *rtk_phy, 266 + struct phy_parameter *phy_parameter, bool update) 267 + { 268 + struct phy_cfg *phy_cfg; 269 + struct phy_reg *phy_reg; 270 + struct phy_data *phy_data_page; 271 + struct phy_data *phy_data; 272 + u8 addr, data; 273 + int offset = 4; 274 + s32 dc_disconnect_mask; 275 + int i; 276 + 277 + phy_cfg = rtk_phy->phy_cfg; 278 + phy_reg = &phy_parameter->phy_reg; 279 + 280 + /* Set page 0 */ 281 + phy_data_page = phy_cfg->page0; 282 + rtk_phy_set_page(phy_reg, 0); 283 + 284 + i = page_addr_to_array_index(PAGE0_0XE4); 285 + phy_data = phy_data_page + i; 286 + if (!phy_data->addr) { 287 + phy_data->addr = PAGE0_0XE4; 288 + phy_data->data = rtk_phy_read(phy_reg, PAGE0_0XE4); 289 + } 290 + 291 + addr = phy_data->addr; 292 + data = phy_data->data; 293 + dc_disconnect_mask = phy_cfg->dc_disconnect_mask; 294 + 295 + if (update) 296 + data = __updated_dc_disconnect_level_page0_0xe4(phy_cfg, phy_parameter, data); 297 + else 298 + data = (data & ~(dc_disconnect_mask << offset)) | 299 + (DEFAULT_DC_DISCONNECTION_VALUE << offset); 300 + 301 + if (rtk_phy_write(phy_reg, addr, data)) 302 + dev_err(rtk_phy->dev, 303 + "%s: Error to set page1 parameter addr=0x%x value=0x%x\n", 304 + __func__, addr, data); 305 + } 306 + 307 + static u8 __updated_dc_disconnect_level_page1_0xe2(struct phy_cfg *phy_cfg, 308 + struct phy_parameter *phy_parameter, u8 data) 309 + { 310 + u8 ret; 311 + s32 val; 312 + s32 dc_disconnect_mask = phy_cfg->dc_disconnect_mask; 313 + 314 + if (phy_cfg->check_efuse_version == CHECK_EFUSE_V1) { 315 + val = (s32)(data & dc_disconnect_mask) 316 + + phy_parameter->efuse_usb_dc_dis 317 + + phy_parameter->disconnection_compensate; 318 + } else { /* for CHECK_EFUSE_V2 or no efuse */ 319 + if (phy_parameter->efuse_usb_dc_dis) 320 + val = (s32)(phy_parameter->efuse_usb_dc_dis + 321 + phy_parameter->disconnection_compensate); 322 + else 323 + val = (s32)((data & dc_disconnect_mask) + 324 + phy_parameter->disconnection_compensate); 325 + } 326 + 327 + if (val > dc_disconnect_mask) 328 + val = dc_disconnect_mask; 329 + else if (val < 0) 330 + val = 0; 331 + 332 + ret = (data & (~dc_disconnect_mask)) | (val & dc_disconnect_mask); 333 + 334 + return ret; 335 + } 336 + 337 + /* updated disconnect level at page1 */ 338 + static void update_dc_disconnect_level_at_page1(struct rtk_phy *rtk_phy, 339 + struct phy_parameter *phy_parameter, bool update) 340 + { 341 + struct phy_cfg *phy_cfg; 342 + struct phy_data *phy_data_page; 343 + struct phy_data *phy_data; 344 + struct phy_reg *phy_reg; 345 + u8 addr, data; 346 + s32 dc_disconnect_mask; 347 + int i; 348 + 349 + phy_cfg = rtk_phy->phy_cfg; 350 + phy_reg = &phy_parameter->phy_reg; 351 + 352 + /* Set page 1 */ 353 + phy_data_page = phy_cfg->page1; 354 + rtk_phy_set_page(phy_reg, 1); 355 + 356 + i = page_addr_to_array_index(PAGE1_0XE2); 357 + phy_data = phy_data_page + i; 358 + if (!phy_data->addr) { 359 + phy_data->addr = PAGE1_0XE2; 360 + phy_data->data = rtk_phy_read(phy_reg, PAGE1_0XE2); 361 + } 362 + 363 + addr = phy_data->addr; 364 + data = phy_data->data; 365 + dc_disconnect_mask = phy_cfg->dc_disconnect_mask; 366 + 367 + if (update) 368 + data = __updated_dc_disconnect_level_page1_0xe2(phy_cfg, phy_parameter, data); 369 + else 370 + data = (data & ~dc_disconnect_mask) | DEFAULT_DC_DISCONNECTION_VALUE; 371 + 372 + if (rtk_phy_write(phy_reg, addr, data)) 373 + dev_err(rtk_phy->dev, 374 + "%s: Error to set page1 parameter addr=0x%x value=0x%x\n", 375 + __func__, addr, data); 376 + } 377 + 378 + static void update_dc_disconnect_level(struct rtk_phy *rtk_phy, 379 + struct phy_parameter *phy_parameter, bool update) 380 + { 381 + struct phy_cfg *phy_cfg = rtk_phy->phy_cfg; 382 + 383 + if (phy_cfg->usb_dc_disconnect_at_page0) 384 + update_dc_disconnect_level_at_page0(rtk_phy, phy_parameter, update); 385 + else 386 + update_dc_disconnect_level_at_page1(rtk_phy, phy_parameter, update); 387 + } 388 + 389 + static u8 __update_dc_driving_page0_0xe4(struct phy_cfg *phy_cfg, 390 + struct phy_parameter *phy_parameter, u8 data) 391 + { 392 + s32 driving_level_compensate = phy_parameter->driving_level_compensate; 393 + s32 dc_driving_mask = phy_cfg->dc_driving_mask; 394 + s32 val; 395 + u8 ret; 396 + 397 + if (phy_cfg->check_efuse_version == CHECK_EFUSE_V1) { 398 + val = (s32)(data & dc_driving_mask) + driving_level_compensate 399 + + phy_parameter->efuse_usb_dc_cal; 400 + } else { /* for CHECK_EFUSE_V2 or no efuse */ 401 + if (phy_parameter->efuse_usb_dc_cal) 402 + val = (s32)((phy_parameter->efuse_usb_dc_cal & dc_driving_mask) 403 + + driving_level_compensate); 404 + else 405 + val = (s32)(data & dc_driving_mask); 406 + } 407 + 408 + if (val > dc_driving_mask) 409 + val = dc_driving_mask; 410 + else if (val < 0) 411 + val = 0; 412 + 413 + ret = (data & (~dc_driving_mask)) | (val & dc_driving_mask); 414 + 415 + return ret; 416 + } 417 + 418 + static void update_dc_driving_level(struct rtk_phy *rtk_phy, 419 + struct phy_parameter *phy_parameter) 420 + { 421 + struct phy_cfg *phy_cfg; 422 + struct phy_reg *phy_reg; 423 + 424 + phy_reg = &phy_parameter->phy_reg; 425 + phy_cfg = rtk_phy->phy_cfg; 426 + if (!phy_cfg->page0[4].addr) { 427 + rtk_phy_set_page(phy_reg, 0); 428 + phy_cfg->page0[4].addr = PAGE0_0XE4; 429 + phy_cfg->page0[4].data = rtk_phy_read(phy_reg, PAGE0_0XE4); 430 + } 431 + 432 + if (phy_parameter->driving_level != DEFAULT_DC_DRIVING_VALUE) { 433 + u32 dc_driving_mask; 434 + u8 driving_level; 435 + u8 data; 436 + 437 + data = phy_cfg->page0[4].data; 438 + dc_driving_mask = phy_cfg->dc_driving_mask; 439 + driving_level = data & dc_driving_mask; 440 + 441 + dev_dbg(rtk_phy->dev, "%s driving_level=%d => dts driving_level=%d\n", 442 + __func__, driving_level, phy_parameter->driving_level); 443 + 444 + phy_cfg->page0[4].data = (data & (~dc_driving_mask)) | 445 + (phy_parameter->driving_level & dc_driving_mask); 446 + } 447 + 448 + phy_cfg->page0[4].data = __update_dc_driving_page0_0xe4(phy_cfg, 449 + phy_parameter, 450 + phy_cfg->page0[4].data); 451 + } 452 + 453 + static void update_hs_clk_select(struct rtk_phy *rtk_phy, 454 + struct phy_parameter *phy_parameter) 455 + { 456 + struct phy_cfg *phy_cfg; 457 + struct phy_reg *phy_reg; 458 + 459 + phy_cfg = rtk_phy->phy_cfg; 460 + phy_reg = &phy_parameter->phy_reg; 461 + 462 + if (phy_parameter->inverse_hstx_sync_clock) { 463 + if (!phy_cfg->page0[6].addr) { 464 + rtk_phy_set_page(phy_reg, 0); 465 + phy_cfg->page0[6].addr = PAGE0_0XE6; 466 + phy_cfg->page0[6].data = rtk_phy_read(phy_reg, PAGE0_0XE6); 467 + } 468 + 469 + phy_cfg->page0[6].data = phy_cfg->page0[6].data | HS_CLK_SELECT; 470 + } 471 + } 472 + 473 + static void do_rtk_phy_toggle(struct rtk_phy *rtk_phy, 474 + int index, bool connect) 475 + { 476 + struct phy_parameter *phy_parameter; 477 + struct phy_cfg *phy_cfg; 478 + struct phy_reg *phy_reg; 479 + struct phy_data *phy_data_page; 480 + u8 addr, data; 481 + int i; 482 + 483 + phy_cfg = rtk_phy->phy_cfg; 484 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 485 + phy_reg = &phy_parameter->phy_reg; 486 + 487 + if (!phy_cfg->do_toggle) 488 + goto out; 489 + 490 + if (phy_cfg->is_double_sensitivity_mode) 491 + goto do_toggle_driving; 492 + 493 + /* Set page 0 */ 494 + rtk_phy_set_page(phy_reg, 0); 495 + 496 + addr = PAGE0_0XE7; 497 + data = rtk_phy_read(phy_reg, addr); 498 + 499 + if (connect) 500 + rtk_phy_write(phy_reg, addr, data & (~SENSITIVITY_CTRL)); 501 + else 502 + rtk_phy_write(phy_reg, addr, data | (SENSITIVITY_CTRL)); 503 + 504 + do_toggle_driving: 505 + 506 + if (!phy_cfg->do_toggle_driving) 507 + goto do_toggle; 508 + 509 + /* Page 0 addr 0xE4 driving capability */ 510 + 511 + /* Set page 0 */ 512 + phy_data_page = phy_cfg->page0; 513 + rtk_phy_set_page(phy_reg, 0); 514 + 515 + i = page_addr_to_array_index(PAGE0_0XE4); 516 + addr = phy_data_page[i].addr; 517 + data = phy_data_page[i].data; 518 + 519 + if (connect) { 520 + rtk_phy_write(phy_reg, addr, data); 521 + } else { 522 + u8 value; 523 + s32 tmp; 524 + s32 driving_updated = 525 + phy_cfg->driving_updated_for_dev_dis; 526 + s32 dc_driving_mask = phy_cfg->dc_driving_mask; 527 + 528 + tmp = (s32)(data & dc_driving_mask) + driving_updated; 529 + 530 + if (tmp > dc_driving_mask) 531 + tmp = dc_driving_mask; 532 + else if (tmp < 0) 533 + tmp = 0; 534 + 535 + value = (data & (~dc_driving_mask)) | (tmp & dc_driving_mask); 536 + 537 + rtk_phy_write(phy_reg, addr, value); 538 + } 539 + 540 + do_toggle: 541 + /* restore dc disconnect level before toggle */ 542 + update_dc_disconnect_level(rtk_phy, phy_parameter, false); 543 + 544 + /* Set page 1 */ 545 + rtk_phy_set_page(phy_reg, 1); 546 + 547 + addr = PAGE1_0XE0; 548 + data = rtk_phy_read(phy_reg, addr); 549 + 550 + rtk_phy_write(phy_reg, addr, data & 551 + (~ENABLE_AUTO_SENSITIVITY_CALIBRATION)); 552 + mdelay(1); 553 + rtk_phy_write(phy_reg, addr, data | 554 + (ENABLE_AUTO_SENSITIVITY_CALIBRATION)); 555 + 556 + /* update dc disconnect level after toggle */ 557 + update_dc_disconnect_level(rtk_phy, phy_parameter, true); 558 + 559 + out: 560 + return; 561 + } 562 + 563 + static int do_rtk_phy_init(struct rtk_phy *rtk_phy, int index) 564 + { 565 + struct phy_parameter *phy_parameter; 566 + struct phy_cfg *phy_cfg; 567 + struct phy_data *phy_data_page; 568 + struct phy_reg *phy_reg; 569 + int i; 570 + 571 + phy_cfg = rtk_phy->phy_cfg; 572 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 573 + phy_reg = &phy_parameter->phy_reg; 574 + 575 + if (phy_cfg->use_default_parameter) { 576 + dev_dbg(rtk_phy->dev, "%s phy#%d use default parameter\n", 577 + __func__, index); 578 + goto do_toggle; 579 + } 580 + 581 + /* Set page 0 */ 582 + phy_data_page = phy_cfg->page0; 583 + rtk_phy_set_page(phy_reg, 0); 584 + 585 + for (i = 0; i < phy_cfg->page0_size; i++) { 586 + struct phy_data *phy_data = phy_data_page + i; 587 + u8 addr = phy_data->addr; 588 + u8 data = phy_data->data; 589 + 590 + if (!addr) 591 + continue; 592 + 593 + if (rtk_phy_write(phy_reg, addr, data)) { 594 + dev_err(rtk_phy->dev, 595 + "%s: Error to set page0 parameter addr=0x%x value=0x%x\n", 596 + __func__, addr, data); 597 + return -EINVAL; 598 + } 599 + } 600 + 601 + /* Set page 1 */ 602 + phy_data_page = phy_cfg->page1; 603 + rtk_phy_set_page(phy_reg, 1); 604 + 605 + for (i = 0; i < phy_cfg->page1_size; i++) { 606 + struct phy_data *phy_data = phy_data_page + i; 607 + u8 addr = phy_data->addr; 608 + u8 data = phy_data->data; 609 + 610 + if (!addr) 611 + continue; 612 + 613 + if (rtk_phy_write(phy_reg, addr, data)) { 614 + dev_err(rtk_phy->dev, 615 + "%s: Error to set page1 parameter addr=0x%x value=0x%x\n", 616 + __func__, addr, data); 617 + return -EINVAL; 618 + } 619 + } 620 + 621 + if (phy_cfg->page2_size == 0) 622 + goto do_toggle; 623 + 624 + /* Set page 2 */ 625 + phy_data_page = phy_cfg->page2; 626 + rtk_phy_set_page(phy_reg, 2); 627 + 628 + for (i = 0; i < phy_cfg->page2_size; i++) { 629 + struct phy_data *phy_data = phy_data_page + i; 630 + u8 addr = phy_data->addr; 631 + u8 data = phy_data->data; 632 + 633 + if (!addr) 634 + continue; 635 + 636 + if (rtk_phy_write(phy_reg, addr, data)) { 637 + dev_err(rtk_phy->dev, 638 + "%s: Error to set page2 parameter addr=0x%x value=0x%x\n", 639 + __func__, addr, data); 640 + return -EINVAL; 641 + } 642 + } 643 + 644 + do_toggle: 645 + do_rtk_phy_toggle(rtk_phy, index, false); 646 + 647 + return 0; 648 + } 649 + 650 + static int rtk_phy_init(struct phy *phy) 651 + { 652 + struct rtk_phy *rtk_phy = phy_get_drvdata(phy); 653 + unsigned long phy_init_time = jiffies; 654 + int i, ret = 0; 655 + 656 + if (!rtk_phy) 657 + return -EINVAL; 658 + 659 + for (i = 0; i < rtk_phy->num_phy; i++) 660 + ret = do_rtk_phy_init(rtk_phy, i); 661 + 662 + dev_dbg(rtk_phy->dev, "Initialized RTK USB 2.0 PHY (take %dms)\n", 663 + jiffies_to_msecs(jiffies - phy_init_time)); 664 + return ret; 665 + } 666 + 667 + static int rtk_phy_exit(struct phy *phy) 668 + { 669 + return 0; 670 + } 671 + 672 + static const struct phy_ops ops = { 673 + .init = rtk_phy_init, 674 + .exit = rtk_phy_exit, 675 + .owner = THIS_MODULE, 676 + }; 677 + 678 + static void rtk_phy_toggle(struct usb_phy *usb2_phy, bool connect, int port) 679 + { 680 + int index = port; 681 + struct rtk_phy *rtk_phy = NULL; 682 + 683 + rtk_phy = dev_get_drvdata(usb2_phy->dev); 684 + 685 + if (index > rtk_phy->num_phy) { 686 + dev_err(rtk_phy->dev, "%s: The port=%d is not in usb phy (num_phy=%d)\n", 687 + __func__, index, rtk_phy->num_phy); 688 + return; 689 + } 690 + 691 + do_rtk_phy_toggle(rtk_phy, index, connect); 692 + } 693 + 694 + static int rtk_phy_notify_port_status(struct usb_phy *x, int port, 695 + u16 portstatus, u16 portchange) 696 + { 697 + bool connect = false; 698 + 699 + pr_debug("%s port=%d portstatus=0x%x portchange=0x%x\n", 700 + __func__, port, (int)portstatus, (int)portchange); 701 + if (portstatus & USB_PORT_STAT_CONNECTION) 702 + connect = true; 703 + 704 + if (portchange & USB_PORT_STAT_C_CONNECTION) 705 + rtk_phy_toggle(x, connect, port); 706 + 707 + return 0; 708 + } 709 + 710 + #ifdef CONFIG_DEBUG_FS 711 + static struct dentry *create_phy_debug_root(void) 712 + { 713 + struct dentry *phy_debug_root; 714 + 715 + phy_debug_root = debugfs_lookup("phy", usb_debug_root); 716 + if (!phy_debug_root) 717 + phy_debug_root = debugfs_create_dir("phy", usb_debug_root); 718 + 719 + return phy_debug_root; 720 + } 721 + 722 + static int rtk_usb2_parameter_show(struct seq_file *s, void *unused) 723 + { 724 + struct rtk_phy *rtk_phy = s->private; 725 + struct phy_cfg *phy_cfg; 726 + int i, index; 727 + 728 + phy_cfg = rtk_phy->phy_cfg; 729 + 730 + seq_puts(s, "Property:\n"); 731 + seq_printf(s, " check_efuse: %s\n", 732 + phy_cfg->check_efuse ? "Enable" : "Disable"); 733 + seq_printf(s, " check_efuse_version: %d\n", 734 + phy_cfg->check_efuse_version); 735 + seq_printf(s, " efuse_dc_driving_rate: %d\n", 736 + phy_cfg->efuse_dc_driving_rate); 737 + seq_printf(s, " dc_driving_mask: 0x%x\n", 738 + phy_cfg->dc_driving_mask); 739 + seq_printf(s, " efuse_dc_disconnect_rate: %d\n", 740 + phy_cfg->efuse_dc_disconnect_rate); 741 + seq_printf(s, " dc_disconnect_mask: 0x%x\n", 742 + phy_cfg->dc_disconnect_mask); 743 + seq_printf(s, " usb_dc_disconnect_at_page0: %s\n", 744 + phy_cfg->usb_dc_disconnect_at_page0 ? "true" : "false"); 745 + seq_printf(s, " do_toggle: %s\n", 746 + phy_cfg->do_toggle ? "Enable" : "Disable"); 747 + seq_printf(s, " do_toggle_driving: %s\n", 748 + phy_cfg->do_toggle_driving ? "Enable" : "Disable"); 749 + seq_printf(s, " driving_updated_for_dev_dis: 0x%x\n", 750 + phy_cfg->driving_updated_for_dev_dis); 751 + seq_printf(s, " use_default_parameter: %s\n", 752 + phy_cfg->use_default_parameter ? "Enable" : "Disable"); 753 + seq_printf(s, " is_double_sensitivity_mode: %s\n", 754 + phy_cfg->is_double_sensitivity_mode ? "Enable" : "Disable"); 755 + 756 + for (index = 0; index < rtk_phy->num_phy; index++) { 757 + struct phy_parameter *phy_parameter; 758 + struct phy_reg *phy_reg; 759 + struct phy_data *phy_data_page; 760 + 761 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 762 + phy_reg = &phy_parameter->phy_reg; 763 + 764 + seq_printf(s, "PHY %d:\n", index); 765 + 766 + seq_puts(s, "Page 0:\n"); 767 + /* Set page 0 */ 768 + phy_data_page = phy_cfg->page0; 769 + rtk_phy_set_page(phy_reg, 0); 770 + 771 + for (i = 0; i < phy_cfg->page0_size; i++) { 772 + struct phy_data *phy_data = phy_data_page + i; 773 + u8 addr = array_index_to_page_addr(i); 774 + u8 data = phy_data->data; 775 + u8 value = rtk_phy_read(phy_reg, addr); 776 + 777 + if (phy_data->addr) 778 + seq_printf(s, " Page 0: addr=0x%x data=0x%02x ==> read value=0x%02x\n", 779 + addr, data, value); 780 + else 781 + seq_printf(s, " Page 0: addr=0x%x data=none ==> read value=0x%02x\n", 782 + addr, value); 783 + } 784 + 785 + seq_puts(s, "Page 1:\n"); 786 + /* Set page 1 */ 787 + phy_data_page = phy_cfg->page1; 788 + rtk_phy_set_page(phy_reg, 1); 789 + 790 + for (i = 0; i < phy_cfg->page1_size; i++) { 791 + struct phy_data *phy_data = phy_data_page + i; 792 + u8 addr = array_index_to_page_addr(i); 793 + u8 data = phy_data->data; 794 + u8 value = rtk_phy_read(phy_reg, addr); 795 + 796 + if (phy_data->addr) 797 + seq_printf(s, " Page 1: addr=0x%x data=0x%02x ==> read value=0x%02x\n", 798 + addr, data, value); 799 + else 800 + seq_printf(s, " Page 1: addr=0x%x data=none ==> read value=0x%02x\n", 801 + addr, value); 802 + } 803 + 804 + if (phy_cfg->page2_size == 0) 805 + goto out; 806 + 807 + seq_puts(s, "Page 2:\n"); 808 + /* Set page 2 */ 809 + phy_data_page = phy_cfg->page2; 810 + rtk_phy_set_page(phy_reg, 2); 811 + 812 + for (i = 0; i < phy_cfg->page2_size; i++) { 813 + struct phy_data *phy_data = phy_data_page + i; 814 + u8 addr = array_index_to_page_addr(i); 815 + u8 data = phy_data->data; 816 + u8 value = rtk_phy_read(phy_reg, addr); 817 + 818 + if (phy_data->addr) 819 + seq_printf(s, " Page 2: addr=0x%x data=0x%02x ==> read value=0x%02x\n", 820 + addr, data, value); 821 + else 822 + seq_printf(s, " Page 2: addr=0x%x data=none ==> read value=0x%02x\n", 823 + addr, value); 824 + } 825 + 826 + out: 827 + seq_puts(s, "PHY Property:\n"); 828 + seq_printf(s, " efuse_usb_dc_cal: %d\n", 829 + (int)phy_parameter->efuse_usb_dc_cal); 830 + seq_printf(s, " efuse_usb_dc_dis: %d\n", 831 + (int)phy_parameter->efuse_usb_dc_dis); 832 + seq_printf(s, " inverse_hstx_sync_clock: %s\n", 833 + phy_parameter->inverse_hstx_sync_clock ? "Enable" : "Disable"); 834 + seq_printf(s, " driving_level: %d\n", 835 + phy_parameter->driving_level); 836 + seq_printf(s, " driving_level_compensate: %d\n", 837 + phy_parameter->driving_level_compensate); 838 + seq_printf(s, " disconnection_compensate: %d\n", 839 + phy_parameter->disconnection_compensate); 840 + } 841 + 842 + return 0; 843 + } 844 + DEFINE_SHOW_ATTRIBUTE(rtk_usb2_parameter); 845 + 846 + static inline void create_debug_files(struct rtk_phy *rtk_phy) 847 + { 848 + struct dentry *phy_debug_root = NULL; 849 + 850 + phy_debug_root = create_phy_debug_root(); 851 + if (!phy_debug_root) 852 + return; 853 + 854 + rtk_phy->debug_dir = debugfs_create_dir(dev_name(rtk_phy->dev), 855 + phy_debug_root); 856 + if (!rtk_phy->debug_dir) 857 + return; 858 + 859 + if (!debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy, 860 + &rtk_usb2_parameter_fops)) 861 + goto file_error; 862 + 863 + return; 864 + 865 + file_error: 866 + debugfs_remove_recursive(rtk_phy->debug_dir); 867 + } 868 + 869 + static inline void remove_debug_files(struct rtk_phy *rtk_phy) 870 + { 871 + debugfs_remove_recursive(rtk_phy->debug_dir); 872 + } 873 + #else 874 + static inline void create_debug_files(struct rtk_phy *rtk_phy) { } 875 + static inline void remove_debug_files(struct rtk_phy *rtk_phy) { } 876 + #endif /* CONFIG_DEBUG_FS */ 877 + 878 + static int get_phy_data_by_efuse(struct rtk_phy *rtk_phy, 879 + struct phy_parameter *phy_parameter, int index) 880 + { 881 + struct phy_cfg *phy_cfg = rtk_phy->phy_cfg; 882 + u8 value = 0; 883 + struct nvmem_cell *cell; 884 + struct soc_device_attribute rtk_soc_groot[] = { 885 + { .family = "Realtek Groot",}, 886 + { /* empty */ } }; 887 + 888 + if (!phy_cfg->check_efuse) 889 + goto out; 890 + 891 + /* Read efuse for usb dc cal */ 892 + cell = nvmem_cell_get(rtk_phy->dev, "usb-dc-cal"); 893 + if (IS_ERR(cell)) { 894 + dev_dbg(rtk_phy->dev, "%s no usb-dc-cal: %ld\n", 895 + __func__, PTR_ERR(cell)); 896 + } else { 897 + unsigned char *buf; 898 + size_t buf_size; 899 + 900 + buf = nvmem_cell_read(cell, &buf_size); 901 + if (!IS_ERR(buf)) { 902 + value = buf[0] & phy_cfg->dc_driving_mask; 903 + kfree(buf); 904 + } 905 + nvmem_cell_put(cell); 906 + } 907 + 908 + if (phy_cfg->check_efuse_version == CHECK_EFUSE_V1) { 909 + int rate = phy_cfg->efuse_dc_driving_rate; 910 + 911 + if (value <= EFUS_USB_DC_CAL_MAX) 912 + phy_parameter->efuse_usb_dc_cal = (int8_t)(value * rate); 913 + else 914 + phy_parameter->efuse_usb_dc_cal = -(int8_t) 915 + ((EFUS_USB_DC_CAL_MAX & value) * rate); 916 + 917 + if (soc_device_match(rtk_soc_groot)) { 918 + dev_dbg(rtk_phy->dev, "For groot IC we need a workaround to adjust efuse_usb_dc_cal\n"); 919 + 920 + /* We don't multiple dc_cal_rate=2 for positive dc cal compensate */ 921 + if (value <= EFUS_USB_DC_CAL_MAX) 922 + phy_parameter->efuse_usb_dc_cal = (int8_t)(value); 923 + 924 + /* We set max dc cal compensate is 0x8 if otp is 0x7 */ 925 + if (value == 0x7) 926 + phy_parameter->efuse_usb_dc_cal = (int8_t)(value + 1); 927 + } 928 + } else { /* for CHECK_EFUSE_V2 */ 929 + phy_parameter->efuse_usb_dc_cal = value & phy_cfg->dc_driving_mask; 930 + } 931 + 932 + /* Read efuse for usb dc disconnect level */ 933 + value = 0; 934 + cell = nvmem_cell_get(rtk_phy->dev, "usb-dc-dis"); 935 + if (IS_ERR(cell)) { 936 + dev_dbg(rtk_phy->dev, "%s no usb-dc-dis: %ld\n", 937 + __func__, PTR_ERR(cell)); 938 + } else { 939 + unsigned char *buf; 940 + size_t buf_size; 941 + 942 + buf = nvmem_cell_read(cell, &buf_size); 943 + if (!IS_ERR(buf)) { 944 + value = buf[0] & phy_cfg->dc_disconnect_mask; 945 + kfree(buf); 946 + } 947 + nvmem_cell_put(cell); 948 + } 949 + 950 + if (phy_cfg->check_efuse_version == CHECK_EFUSE_V1) { 951 + int rate = phy_cfg->efuse_dc_disconnect_rate; 952 + 953 + if (value <= EFUS_USB_DC_DIS_MAX) 954 + phy_parameter->efuse_usb_dc_dis = (int8_t)(value * rate); 955 + else 956 + phy_parameter->efuse_usb_dc_dis = -(int8_t) 957 + ((EFUS_USB_DC_DIS_MAX & value) * rate); 958 + } else { /* for CHECK_EFUSE_V2 */ 959 + phy_parameter->efuse_usb_dc_dis = value & phy_cfg->dc_disconnect_mask; 960 + } 961 + 962 + out: 963 + return 0; 964 + } 965 + 966 + static int parse_phy_data(struct rtk_phy *rtk_phy) 967 + { 968 + struct device *dev = rtk_phy->dev; 969 + struct device_node *np = dev->of_node; 970 + struct phy_parameter *phy_parameter; 971 + int ret = 0; 972 + int index; 973 + 974 + rtk_phy->phy_parameter = devm_kzalloc(dev, sizeof(struct phy_parameter) * 975 + rtk_phy->num_phy, GFP_KERNEL); 976 + if (!rtk_phy->phy_parameter) 977 + return -ENOMEM; 978 + 979 + for (index = 0; index < rtk_phy->num_phy; index++) { 980 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 981 + 982 + phy_parameter->phy_reg.reg_wrap_vstatus = of_iomap(np, 0); 983 + phy_parameter->phy_reg.reg_gusb2phyacc0 = of_iomap(np, 1) + index; 984 + phy_parameter->phy_reg.vstatus_index = index; 985 + 986 + if (of_property_read_bool(np, "realtek,inverse-hstx-sync-clock")) 987 + phy_parameter->inverse_hstx_sync_clock = true; 988 + else 989 + phy_parameter->inverse_hstx_sync_clock = false; 990 + 991 + if (of_property_read_u32_index(np, "realtek,driving-level", 992 + index, &phy_parameter->driving_level)) 993 + phy_parameter->driving_level = DEFAULT_DC_DRIVING_VALUE; 994 + 995 + if (of_property_read_u32_index(np, "realtek,driving-level-compensate", 996 + index, &phy_parameter->driving_level_compensate)) 997 + phy_parameter->driving_level_compensate = 0; 998 + 999 + if (of_property_read_u32_index(np, "realtek,disconnection-compensate", 1000 + index, &phy_parameter->disconnection_compensate)) 1001 + phy_parameter->disconnection_compensate = 0; 1002 + 1003 + get_phy_data_by_efuse(rtk_phy, phy_parameter, index); 1004 + 1005 + update_dc_driving_level(rtk_phy, phy_parameter); 1006 + 1007 + update_hs_clk_select(rtk_phy, phy_parameter); 1008 + } 1009 + 1010 + return ret; 1011 + } 1012 + 1013 + static int rtk_usb2phy_probe(struct platform_device *pdev) 1014 + { 1015 + struct rtk_phy *rtk_phy; 1016 + struct device *dev = &pdev->dev; 1017 + struct phy *generic_phy; 1018 + struct phy_provider *phy_provider; 1019 + const struct phy_cfg *phy_cfg; 1020 + int ret = 0; 1021 + 1022 + phy_cfg = of_device_get_match_data(dev); 1023 + if (!phy_cfg) { 1024 + dev_err(dev, "phy config are not assigned!\n"); 1025 + return -EINVAL; 1026 + } 1027 + 1028 + rtk_phy = devm_kzalloc(dev, sizeof(*rtk_phy), GFP_KERNEL); 1029 + if (!rtk_phy) 1030 + return -ENOMEM; 1031 + 1032 + rtk_phy->dev = &pdev->dev; 1033 + rtk_phy->phy.dev = rtk_phy->dev; 1034 + rtk_phy->phy.label = "rtk-usb2phy"; 1035 + rtk_phy->phy.notify_port_status = rtk_phy_notify_port_status; 1036 + 1037 + rtk_phy->phy_cfg = devm_kzalloc(dev, sizeof(*phy_cfg), GFP_KERNEL); 1038 + 1039 + memcpy(rtk_phy->phy_cfg, phy_cfg, sizeof(*phy_cfg)); 1040 + 1041 + rtk_phy->num_phy = phy_cfg->num_phy; 1042 + 1043 + ret = parse_phy_data(rtk_phy); 1044 + if (ret) 1045 + goto err; 1046 + 1047 + platform_set_drvdata(pdev, rtk_phy); 1048 + 1049 + generic_phy = devm_phy_create(rtk_phy->dev, NULL, &ops); 1050 + if (IS_ERR(generic_phy)) 1051 + return PTR_ERR(generic_phy); 1052 + 1053 + phy_set_drvdata(generic_phy, rtk_phy); 1054 + 1055 + phy_provider = devm_of_phy_provider_register(rtk_phy->dev, 1056 + of_phy_simple_xlate); 1057 + if (IS_ERR(phy_provider)) 1058 + return PTR_ERR(phy_provider); 1059 + 1060 + ret = usb_add_phy_dev(&rtk_phy->phy); 1061 + if (ret) 1062 + goto err; 1063 + 1064 + create_debug_files(rtk_phy); 1065 + 1066 + err: 1067 + return ret; 1068 + } 1069 + 1070 + static void rtk_usb2phy_remove(struct platform_device *pdev) 1071 + { 1072 + struct rtk_phy *rtk_phy = platform_get_drvdata(pdev); 1073 + 1074 + remove_debug_files(rtk_phy); 1075 + 1076 + usb_remove_phy(&rtk_phy->phy); 1077 + } 1078 + 1079 + static const struct phy_cfg rtd1295_phy_cfg = { 1080 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1081 + .page0 = { [0] = {0xe0, 0x90}, 1082 + [3] = {0xe3, 0x3a}, 1083 + [4] = {0xe4, 0x68}, 1084 + [6] = {0xe6, 0x91}, 1085 + [13] = {0xf5, 0x81}, 1086 + [15] = {0xf7, 0x02}, }, 1087 + .page1_size = 8, 1088 + .page1 = { /* default parameter */ }, 1089 + .page2_size = 0, 1090 + .page2 = { /* no parameter */ }, 1091 + .num_phy = 1, 1092 + .check_efuse = false, 1093 + .check_efuse_version = CHECK_EFUSE_V1, 1094 + .efuse_dc_driving_rate = 1, 1095 + .dc_driving_mask = 0xf, 1096 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1097 + .dc_disconnect_mask = 0xf, 1098 + .usb_dc_disconnect_at_page0 = true, 1099 + .do_toggle = true, 1100 + .do_toggle_driving = false, 1101 + .driving_updated_for_dev_dis = 0xf, 1102 + .use_default_parameter = false, 1103 + .is_double_sensitivity_mode = false, 1104 + }; 1105 + 1106 + static const struct phy_cfg rtd1395_phy_cfg = { 1107 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1108 + .page0 = { [4] = {0xe4, 0xac}, 1109 + [13] = {0xf5, 0x00}, 1110 + [15] = {0xf7, 0x02}, }, 1111 + .page1_size = 8, 1112 + .page1 = { /* default parameter */ }, 1113 + .page2_size = 0, 1114 + .page2 = { /* no parameter */ }, 1115 + .num_phy = 1, 1116 + .check_efuse = false, 1117 + .check_efuse_version = CHECK_EFUSE_V1, 1118 + .efuse_dc_driving_rate = 1, 1119 + .dc_driving_mask = 0xf, 1120 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1121 + .dc_disconnect_mask = 0xf, 1122 + .usb_dc_disconnect_at_page0 = true, 1123 + .do_toggle = true, 1124 + .do_toggle_driving = false, 1125 + .driving_updated_for_dev_dis = 0xf, 1126 + .use_default_parameter = false, 1127 + .is_double_sensitivity_mode = false, 1128 + }; 1129 + 1130 + static const struct phy_cfg rtd1395_phy_cfg_2port = { 1131 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1132 + .page0 = { [4] = {0xe4, 0xac}, 1133 + [13] = {0xf5, 0x00}, 1134 + [15] = {0xf7, 0x02}, }, 1135 + .page1_size = 8, 1136 + .page1 = { /* default parameter */ }, 1137 + .page2_size = 0, 1138 + .page2 = { /* no parameter */ }, 1139 + .num_phy = 2, 1140 + .check_efuse = false, 1141 + .check_efuse_version = CHECK_EFUSE_V1, 1142 + .efuse_dc_driving_rate = 1, 1143 + .dc_driving_mask = 0xf, 1144 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1145 + .dc_disconnect_mask = 0xf, 1146 + .usb_dc_disconnect_at_page0 = true, 1147 + .do_toggle = true, 1148 + .do_toggle_driving = false, 1149 + .driving_updated_for_dev_dis = 0xf, 1150 + .use_default_parameter = false, 1151 + .is_double_sensitivity_mode = false, 1152 + }; 1153 + 1154 + static const struct phy_cfg rtd1619_phy_cfg = { 1155 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1156 + .page0 = { [4] = {0xe4, 0x68}, }, 1157 + .page1_size = 8, 1158 + .page1 = { /* default parameter */ }, 1159 + .page2_size = 0, 1160 + .page2 = { /* no parameter */ }, 1161 + .num_phy = 1, 1162 + .check_efuse = true, 1163 + .check_efuse_version = CHECK_EFUSE_V1, 1164 + .efuse_dc_driving_rate = 1, 1165 + .dc_driving_mask = 0xf, 1166 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1167 + .dc_disconnect_mask = 0xf, 1168 + .usb_dc_disconnect_at_page0 = true, 1169 + .do_toggle = true, 1170 + .do_toggle_driving = false, 1171 + .driving_updated_for_dev_dis = 0xf, 1172 + .use_default_parameter = false, 1173 + .is_double_sensitivity_mode = false, 1174 + }; 1175 + 1176 + static const struct phy_cfg rtd1319_phy_cfg = { 1177 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1178 + .page0 = { [0] = {0xe0, 0x18}, 1179 + [4] = {0xe4, 0x6a}, 1180 + [7] = {0xe7, 0x71}, 1181 + [13] = {0xf5, 0x15}, 1182 + [15] = {0xf7, 0x32}, }, 1183 + .page1_size = 8, 1184 + .page1 = { [3] = {0xe3, 0x44}, }, 1185 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1186 + .page2 = { [0] = {0xe0, 0x01}, }, 1187 + .num_phy = 1, 1188 + .check_efuse = true, 1189 + .check_efuse_version = CHECK_EFUSE_V1, 1190 + .efuse_dc_driving_rate = 1, 1191 + .dc_driving_mask = 0xf, 1192 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1193 + .dc_disconnect_mask = 0xf, 1194 + .usb_dc_disconnect_at_page0 = true, 1195 + .do_toggle = true, 1196 + .do_toggle_driving = true, 1197 + .driving_updated_for_dev_dis = 0xf, 1198 + .use_default_parameter = false, 1199 + .is_double_sensitivity_mode = true, 1200 + }; 1201 + 1202 + static const struct phy_cfg rtd1312c_phy_cfg = { 1203 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1204 + .page0 = { [0] = {0xe0, 0x14}, 1205 + [4] = {0xe4, 0x67}, 1206 + [5] = {0xe5, 0x55}, }, 1207 + .page1_size = 8, 1208 + .page1 = { [3] = {0xe3, 0x23}, 1209 + [6] = {0xe6, 0x58}, }, 1210 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1211 + .page2 = { /* default parameter */ }, 1212 + .num_phy = 1, 1213 + .check_efuse = true, 1214 + .check_efuse_version = CHECK_EFUSE_V1, 1215 + .efuse_dc_driving_rate = 1, 1216 + .dc_driving_mask = 0xf, 1217 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1218 + .dc_disconnect_mask = 0xf, 1219 + .usb_dc_disconnect_at_page0 = true, 1220 + .do_toggle = true, 1221 + .do_toggle_driving = true, 1222 + .driving_updated_for_dev_dis = 0xf, 1223 + .use_default_parameter = false, 1224 + .is_double_sensitivity_mode = true, 1225 + }; 1226 + 1227 + static const struct phy_cfg rtd1619b_phy_cfg = { 1228 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1229 + .page0 = { [0] = {0xe0, 0xa3}, 1230 + [4] = {0xe4, 0x88}, 1231 + [5] = {0xe5, 0x4f}, 1232 + [6] = {0xe6, 0x02}, }, 1233 + .page1_size = 8, 1234 + .page1 = { [3] = {0xe3, 0x64}, }, 1235 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1236 + .page2 = { [7] = {0xe7, 0x45}, }, 1237 + .num_phy = 1, 1238 + .check_efuse = true, 1239 + .check_efuse_version = CHECK_EFUSE_V1, 1240 + .efuse_dc_driving_rate = EFUS_USB_DC_CAL_RATE, 1241 + .dc_driving_mask = 0x1f, 1242 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1243 + .dc_disconnect_mask = 0xf, 1244 + .usb_dc_disconnect_at_page0 = false, 1245 + .do_toggle = true, 1246 + .do_toggle_driving = true, 1247 + .driving_updated_for_dev_dis = 0x8, 1248 + .use_default_parameter = false, 1249 + .is_double_sensitivity_mode = true, 1250 + }; 1251 + 1252 + static const struct phy_cfg rtd1319d_phy_cfg = { 1253 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1254 + .page0 = { [0] = {0xe0, 0xa3}, 1255 + [4] = {0xe4, 0x8e}, 1256 + [5] = {0xe5, 0x4f}, 1257 + [6] = {0xe6, 0x02}, }, 1258 + .page1_size = MAX_USB_PHY_PAGE1_DATA_SIZE, 1259 + .page1 = { [14] = {0xf5, 0x1}, }, 1260 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1261 + .page2 = { [7] = {0xe7, 0x44}, }, 1262 + .check_efuse = true, 1263 + .num_phy = 1, 1264 + .check_efuse_version = CHECK_EFUSE_V1, 1265 + .efuse_dc_driving_rate = EFUS_USB_DC_CAL_RATE, 1266 + .dc_driving_mask = 0x1f, 1267 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1268 + .dc_disconnect_mask = 0xf, 1269 + .usb_dc_disconnect_at_page0 = false, 1270 + .do_toggle = true, 1271 + .do_toggle_driving = false, 1272 + .driving_updated_for_dev_dis = 0x8, 1273 + .use_default_parameter = false, 1274 + .is_double_sensitivity_mode = true, 1275 + }; 1276 + 1277 + static const struct phy_cfg rtd1315e_phy_cfg = { 1278 + .page0_size = MAX_USB_PHY_PAGE0_DATA_SIZE, 1279 + .page0 = { [0] = {0xe0, 0xa3}, 1280 + [4] = {0xe4, 0x8c}, 1281 + [5] = {0xe5, 0x4f}, 1282 + [6] = {0xe6, 0x02}, }, 1283 + .page1_size = MAX_USB_PHY_PAGE1_DATA_SIZE, 1284 + .page1 = { [3] = {0xe3, 0x7f}, 1285 + [14] = {0xf5, 0x01}, }, 1286 + .page2_size = MAX_USB_PHY_PAGE2_DATA_SIZE, 1287 + .page2 = { [7] = {0xe7, 0x44}, }, 1288 + .num_phy = 1, 1289 + .check_efuse = true, 1290 + .check_efuse_version = CHECK_EFUSE_V2, 1291 + .efuse_dc_driving_rate = EFUS_USB_DC_CAL_RATE, 1292 + .dc_driving_mask = 0x1f, 1293 + .efuse_dc_disconnect_rate = EFUS_USB_DC_DIS_RATE, 1294 + .dc_disconnect_mask = 0xf, 1295 + .usb_dc_disconnect_at_page0 = false, 1296 + .do_toggle = true, 1297 + .do_toggle_driving = false, 1298 + .driving_updated_for_dev_dis = 0x8, 1299 + .use_default_parameter = false, 1300 + .is_double_sensitivity_mode = true, 1301 + }; 1302 + 1303 + static const struct of_device_id usbphy_rtk_dt_match[] = { 1304 + { .compatible = "realtek,rtd1295-usb2phy", .data = &rtd1295_phy_cfg }, 1305 + { .compatible = "realtek,rtd1312c-usb2phy", .data = &rtd1312c_phy_cfg }, 1306 + { .compatible = "realtek,rtd1315e-usb2phy", .data = &rtd1315e_phy_cfg }, 1307 + { .compatible = "realtek,rtd1319-usb2phy", .data = &rtd1319_phy_cfg }, 1308 + { .compatible = "realtek,rtd1319d-usb2phy", .data = &rtd1319d_phy_cfg }, 1309 + { .compatible = "realtek,rtd1395-usb2phy", .data = &rtd1395_phy_cfg }, 1310 + { .compatible = "realtek,rtd1395-usb2phy-2port", .data = &rtd1395_phy_cfg_2port }, 1311 + { .compatible = "realtek,rtd1619-usb2phy", .data = &rtd1619_phy_cfg }, 1312 + { .compatible = "realtek,rtd1619b-usb2phy", .data = &rtd1619b_phy_cfg }, 1313 + {}, 1314 + }; 1315 + MODULE_DEVICE_TABLE(of, usbphy_rtk_dt_match); 1316 + 1317 + static struct platform_driver rtk_usb2phy_driver = { 1318 + .probe = rtk_usb2phy_probe, 1319 + .remove_new = rtk_usb2phy_remove, 1320 + .driver = { 1321 + .name = "rtk-usb2phy", 1322 + .of_match_table = usbphy_rtk_dt_match, 1323 + }, 1324 + }; 1325 + 1326 + module_platform_driver(rtk_usb2phy_driver); 1327 + 1328 + MODULE_LICENSE("GPL"); 1329 + MODULE_ALIAS("platform: rtk-usb2phy"); 1330 + MODULE_AUTHOR("Stanley Chang <stanley_chang@realtek.com>"); 1331 + MODULE_DESCRIPTION("Realtek usb 2.0 phy driver");
+767
drivers/phy/realtek/phy-rtk-usb3.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * phy-rtk-usb3.c RTK usb3.0 phy driver 4 + * 5 + * copyright (c) 2023 realtek semiconductor corporation 6 + * 7 + */ 8 + 9 + #include <linux/module.h> 10 + #include <linux/of.h> 11 + #include <linux/of_device.h> 12 + #include <linux/of_address.h> 13 + #include <linux/uaccess.h> 14 + #include <linux/debugfs.h> 15 + #include <linux/nvmem-consumer.h> 16 + #include <linux/regmap.h> 17 + #include <linux/sys_soc.h> 18 + #include <linux/mfd/syscon.h> 19 + #include <linux/phy/phy.h> 20 + #include <linux/usb.h> 21 + #include <linux/usb/hcd.h> 22 + #include <linux/usb/phy.h> 23 + 24 + #define USB_MDIO_CTRL_PHY_BUSY BIT(7) 25 + #define USB_MDIO_CTRL_PHY_WRITE BIT(0) 26 + #define USB_MDIO_CTRL_PHY_ADDR_SHIFT 8 27 + #define USB_MDIO_CTRL_PHY_DATA_SHIFT 16 28 + 29 + #define MAX_USB_PHY_DATA_SIZE 0x30 30 + #define PHY_ADDR_0X09 0x09 31 + #define PHY_ADDR_0X0B 0x0b 32 + #define PHY_ADDR_0X0D 0x0d 33 + #define PHY_ADDR_0X10 0x10 34 + #define PHY_ADDR_0X1F 0x1f 35 + #define PHY_ADDR_0X20 0x20 36 + #define PHY_ADDR_0X21 0x21 37 + #define PHY_ADDR_0X30 0x30 38 + 39 + #define REG_0X09_FORCE_CALIBRATION BIT(9) 40 + #define REG_0X0B_RX_OFFSET_RANGE_MASK 0xc 41 + #define REG_0X0D_RX_DEBUG_TEST_EN BIT(6) 42 + #define REG_0X10_DEBUG_MODE_SETTING 0x3c0 43 + #define REG_0X10_DEBUG_MODE_SETTING_MASK 0x3f8 44 + #define REG_0X1F_RX_OFFSET_CODE_MASK 0x1e 45 + 46 + #define USB_U3_TX_LFPS_SWING_TRIM_SHIFT 4 47 + #define USB_U3_TX_LFPS_SWING_TRIM_MASK 0xf 48 + #define AMPLITUDE_CONTROL_COARSE_MASK 0xff 49 + #define AMPLITUDE_CONTROL_FINE_MASK 0xffff 50 + #define AMPLITUDE_CONTROL_COARSE_DEFAULT 0xff 51 + #define AMPLITUDE_CONTROL_FINE_DEFAULT 0xffff 52 + 53 + #define PHY_ADDR_MAP_ARRAY_INDEX(addr) (addr) 54 + #define ARRAY_INDEX_MAP_PHY_ADDR(index) (index) 55 + 56 + struct phy_reg { 57 + void __iomem *reg_mdio_ctl; 58 + }; 59 + 60 + struct phy_data { 61 + u8 addr; 62 + u16 data; 63 + }; 64 + 65 + struct phy_cfg { 66 + int param_size; 67 + struct phy_data param[MAX_USB_PHY_DATA_SIZE]; 68 + 69 + bool check_efuse; 70 + bool do_toggle; 71 + bool do_toggle_once; 72 + bool use_default_parameter; 73 + bool check_rx_front_end_offset; 74 + }; 75 + 76 + struct phy_parameter { 77 + struct phy_reg phy_reg; 78 + 79 + /* Get from efuse */ 80 + u8 efuse_usb_u3_tx_lfps_swing_trim; 81 + 82 + /* Get from dts */ 83 + u32 amplitude_control_coarse; 84 + u32 amplitude_control_fine; 85 + }; 86 + 87 + struct rtk_phy { 88 + struct usb_phy phy; 89 + struct device *dev; 90 + 91 + struct phy_cfg *phy_cfg; 92 + int num_phy; 93 + struct phy_parameter *phy_parameter; 94 + 95 + struct dentry *debug_dir; 96 + }; 97 + 98 + #define PHY_IO_TIMEOUT_USEC (50000) 99 + #define PHY_IO_DELAY_US (100) 100 + 101 + static inline int utmi_wait_register(void __iomem *reg, u32 mask, u32 result) 102 + { 103 + int ret; 104 + unsigned int val; 105 + 106 + ret = read_poll_timeout(readl, val, ((val & mask) == result), 107 + PHY_IO_DELAY_US, PHY_IO_TIMEOUT_USEC, false, reg); 108 + if (ret) { 109 + pr_err("%s can't program USB phy\n", __func__); 110 + return -ETIMEDOUT; 111 + } 112 + 113 + return 0; 114 + } 115 + 116 + static int rtk_phy3_wait_vbusy(struct phy_reg *phy_reg) 117 + { 118 + return utmi_wait_register(phy_reg->reg_mdio_ctl, USB_MDIO_CTRL_PHY_BUSY, 0); 119 + } 120 + 121 + static u16 rtk_phy_read(struct phy_reg *phy_reg, char addr) 122 + { 123 + unsigned int tmp; 124 + u32 value; 125 + 126 + tmp = (addr << USB_MDIO_CTRL_PHY_ADDR_SHIFT); 127 + 128 + writel(tmp, phy_reg->reg_mdio_ctl); 129 + 130 + rtk_phy3_wait_vbusy(phy_reg); 131 + 132 + value = readl(phy_reg->reg_mdio_ctl); 133 + value = value >> USB_MDIO_CTRL_PHY_DATA_SHIFT; 134 + 135 + return (u16)value; 136 + } 137 + 138 + static int rtk_phy_write(struct phy_reg *phy_reg, char addr, u16 data) 139 + { 140 + unsigned int val; 141 + 142 + val = USB_MDIO_CTRL_PHY_WRITE | 143 + (addr << USB_MDIO_CTRL_PHY_ADDR_SHIFT) | 144 + (data << USB_MDIO_CTRL_PHY_DATA_SHIFT); 145 + 146 + writel(val, phy_reg->reg_mdio_ctl); 147 + 148 + rtk_phy3_wait_vbusy(phy_reg); 149 + 150 + return 0; 151 + } 152 + 153 + static void do_rtk_usb3_phy_toggle(struct rtk_phy *rtk_phy, int index, bool connect) 154 + { 155 + struct phy_cfg *phy_cfg = rtk_phy->phy_cfg; 156 + struct phy_reg *phy_reg; 157 + struct phy_parameter *phy_parameter; 158 + struct phy_data *phy_data; 159 + u8 addr; 160 + u16 data; 161 + int i; 162 + 163 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 164 + phy_reg = &phy_parameter->phy_reg; 165 + 166 + if (!phy_cfg->do_toggle) 167 + return; 168 + 169 + i = PHY_ADDR_MAP_ARRAY_INDEX(PHY_ADDR_0X09); 170 + phy_data = phy_cfg->param + i; 171 + addr = phy_data->addr; 172 + data = phy_data->data; 173 + 174 + if (!addr && !data) { 175 + addr = PHY_ADDR_0X09; 176 + data = rtk_phy_read(phy_reg, addr); 177 + phy_data->addr = addr; 178 + phy_data->data = data; 179 + } 180 + 181 + rtk_phy_write(phy_reg, addr, data & (~REG_0X09_FORCE_CALIBRATION)); 182 + mdelay(1); 183 + rtk_phy_write(phy_reg, addr, data | REG_0X09_FORCE_CALIBRATION); 184 + } 185 + 186 + static int do_rtk_phy_init(struct rtk_phy *rtk_phy, int index) 187 + { 188 + struct phy_cfg *phy_cfg; 189 + struct phy_reg *phy_reg; 190 + struct phy_parameter *phy_parameter; 191 + int i = 0; 192 + 193 + phy_cfg = rtk_phy->phy_cfg; 194 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 195 + phy_reg = &phy_parameter->phy_reg; 196 + 197 + if (phy_cfg->use_default_parameter) 198 + goto do_toggle; 199 + 200 + for (i = 0; i < phy_cfg->param_size; i++) { 201 + struct phy_data *phy_data = phy_cfg->param + i; 202 + u8 addr = phy_data->addr; 203 + u16 data = phy_data->data; 204 + 205 + if (!addr && !data) 206 + continue; 207 + 208 + rtk_phy_write(phy_reg, addr, data); 209 + } 210 + 211 + do_toggle: 212 + if (phy_cfg->do_toggle_once) 213 + phy_cfg->do_toggle = true; 214 + 215 + do_rtk_usb3_phy_toggle(rtk_phy, index, false); 216 + 217 + if (phy_cfg->do_toggle_once) { 218 + u16 check_value = 0; 219 + int count = 10; 220 + u16 value_0x0d, value_0x10; 221 + 222 + /* Enable Debug mode by set 0x0D and 0x10 */ 223 + value_0x0d = rtk_phy_read(phy_reg, PHY_ADDR_0X0D); 224 + value_0x10 = rtk_phy_read(phy_reg, PHY_ADDR_0X10); 225 + 226 + rtk_phy_write(phy_reg, PHY_ADDR_0X0D, 227 + value_0x0d | REG_0X0D_RX_DEBUG_TEST_EN); 228 + rtk_phy_write(phy_reg, PHY_ADDR_0X10, 229 + (value_0x10 & ~REG_0X10_DEBUG_MODE_SETTING_MASK) | 230 + REG_0X10_DEBUG_MODE_SETTING); 231 + 232 + check_value = rtk_phy_read(phy_reg, PHY_ADDR_0X30); 233 + 234 + while (!(check_value & BIT(15))) { 235 + check_value = rtk_phy_read(phy_reg, PHY_ADDR_0X30); 236 + mdelay(1); 237 + if (count-- < 0) 238 + break; 239 + } 240 + 241 + if (!(check_value & BIT(15))) 242 + dev_info(rtk_phy->dev, "toggle fail addr=0x%02x, data=0x%04x\n", 243 + PHY_ADDR_0X30, check_value); 244 + 245 + /* Disable Debug mode by set 0x0D and 0x10 to default*/ 246 + rtk_phy_write(phy_reg, PHY_ADDR_0X0D, value_0x0d); 247 + rtk_phy_write(phy_reg, PHY_ADDR_0X10, value_0x10); 248 + 249 + phy_cfg->do_toggle = false; 250 + } 251 + 252 + if (phy_cfg->check_rx_front_end_offset) { 253 + u16 rx_offset_code, rx_offset_range; 254 + u16 code_mask = REG_0X1F_RX_OFFSET_CODE_MASK; 255 + u16 range_mask = REG_0X0B_RX_OFFSET_RANGE_MASK; 256 + bool do_update = false; 257 + 258 + rx_offset_code = rtk_phy_read(phy_reg, PHY_ADDR_0X1F); 259 + if (((rx_offset_code & code_mask) == 0x0) || 260 + ((rx_offset_code & code_mask) == code_mask)) 261 + do_update = true; 262 + 263 + rx_offset_range = rtk_phy_read(phy_reg, PHY_ADDR_0X0B); 264 + if (((rx_offset_range & range_mask) == range_mask) && do_update) { 265 + dev_warn(rtk_phy->dev, "Don't update rx_offset_range (rx_offset_code=0x%x, rx_offset_range=0x%x)\n", 266 + rx_offset_code, rx_offset_range); 267 + do_update = false; 268 + } 269 + 270 + if (do_update) { 271 + u16 tmp1, tmp2; 272 + 273 + tmp1 = rx_offset_range & (~range_mask); 274 + tmp2 = rx_offset_range & range_mask; 275 + tmp2 += (1 << 2); 276 + rx_offset_range = tmp1 | (tmp2 & range_mask); 277 + rtk_phy_write(phy_reg, PHY_ADDR_0X0B, rx_offset_range); 278 + goto do_toggle; 279 + } 280 + } 281 + 282 + return 0; 283 + } 284 + 285 + static int rtk_phy_init(struct phy *phy) 286 + { 287 + struct rtk_phy *rtk_phy = phy_get_drvdata(phy); 288 + int ret = 0; 289 + int i; 290 + unsigned long phy_init_time = jiffies; 291 + 292 + for (i = 0; i < rtk_phy->num_phy; i++) 293 + ret = do_rtk_phy_init(rtk_phy, i); 294 + 295 + dev_dbg(rtk_phy->dev, "Initialized RTK USB 3.0 PHY (take %dms)\n", 296 + jiffies_to_msecs(jiffies - phy_init_time)); 297 + 298 + return ret; 299 + } 300 + 301 + static int rtk_phy_exit(struct phy *phy) 302 + { 303 + return 0; 304 + } 305 + 306 + static const struct phy_ops ops = { 307 + .init = rtk_phy_init, 308 + .exit = rtk_phy_exit, 309 + .owner = THIS_MODULE, 310 + }; 311 + 312 + static void rtk_phy_toggle(struct usb_phy *usb3_phy, bool connect, int port) 313 + { 314 + int index = port; 315 + struct rtk_phy *rtk_phy = NULL; 316 + 317 + rtk_phy = dev_get_drvdata(usb3_phy->dev); 318 + 319 + if (index > rtk_phy->num_phy) { 320 + dev_err(rtk_phy->dev, "%s: The port=%d is not in usb phy (num_phy=%d)\n", 321 + __func__, index, rtk_phy->num_phy); 322 + return; 323 + } 324 + 325 + do_rtk_usb3_phy_toggle(rtk_phy, index, connect); 326 + } 327 + 328 + static int rtk_phy_notify_port_status(struct usb_phy *x, int port, 329 + u16 portstatus, u16 portchange) 330 + { 331 + bool connect = false; 332 + 333 + pr_debug("%s port=%d portstatus=0x%x portchange=0x%x\n", 334 + __func__, port, (int)portstatus, (int)portchange); 335 + if (portstatus & USB_PORT_STAT_CONNECTION) 336 + connect = true; 337 + 338 + if (portchange & USB_PORT_STAT_C_CONNECTION) 339 + rtk_phy_toggle(x, connect, port); 340 + 341 + return 0; 342 + } 343 + 344 + #ifdef CONFIG_DEBUG_FS 345 + static struct dentry *create_phy_debug_root(void) 346 + { 347 + struct dentry *phy_debug_root; 348 + 349 + phy_debug_root = debugfs_lookup("phy", usb_debug_root); 350 + if (!phy_debug_root) 351 + phy_debug_root = debugfs_create_dir("phy", usb_debug_root); 352 + 353 + return phy_debug_root; 354 + } 355 + 356 + static int rtk_usb3_parameter_show(struct seq_file *s, void *unused) 357 + { 358 + struct rtk_phy *rtk_phy = s->private; 359 + struct phy_cfg *phy_cfg; 360 + int i, index; 361 + 362 + phy_cfg = rtk_phy->phy_cfg; 363 + 364 + seq_puts(s, "Property:\n"); 365 + seq_printf(s, " check_efuse: %s\n", 366 + phy_cfg->check_efuse ? "Enable" : "Disable"); 367 + seq_printf(s, " do_toggle: %s\n", 368 + phy_cfg->do_toggle ? "Enable" : "Disable"); 369 + seq_printf(s, " do_toggle_once: %s\n", 370 + phy_cfg->do_toggle_once ? "Enable" : "Disable"); 371 + seq_printf(s, " use_default_parameter: %s\n", 372 + phy_cfg->use_default_parameter ? "Enable" : "Disable"); 373 + 374 + for (index = 0; index < rtk_phy->num_phy; index++) { 375 + struct phy_reg *phy_reg; 376 + struct phy_parameter *phy_parameter; 377 + 378 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 379 + phy_reg = &phy_parameter->phy_reg; 380 + 381 + seq_printf(s, "PHY %d:\n", index); 382 + 383 + for (i = 0; i < phy_cfg->param_size; i++) { 384 + struct phy_data *phy_data = phy_cfg->param + i; 385 + u8 addr = ARRAY_INDEX_MAP_PHY_ADDR(i); 386 + u16 data = phy_data->data; 387 + 388 + if (!phy_data->addr && !data) 389 + seq_printf(s, " addr = 0x%02x, data = none ==> read value = 0x%04x\n", 390 + addr, rtk_phy_read(phy_reg, addr)); 391 + else 392 + seq_printf(s, " addr = 0x%02x, data = 0x%04x ==> read value = 0x%04x\n", 393 + addr, data, rtk_phy_read(phy_reg, addr)); 394 + } 395 + 396 + seq_puts(s, "PHY Property:\n"); 397 + seq_printf(s, " efuse_usb_u3_tx_lfps_swing_trim: 0x%x\n", 398 + (int)phy_parameter->efuse_usb_u3_tx_lfps_swing_trim); 399 + seq_printf(s, " amplitude_control_coarse: 0x%x\n", 400 + (int)phy_parameter->amplitude_control_coarse); 401 + seq_printf(s, " amplitude_control_fine: 0x%x\n", 402 + (int)phy_parameter->amplitude_control_fine); 403 + } 404 + 405 + return 0; 406 + } 407 + DEFINE_SHOW_ATTRIBUTE(rtk_usb3_parameter); 408 + 409 + static inline void create_debug_files(struct rtk_phy *rtk_phy) 410 + { 411 + struct dentry *phy_debug_root = NULL; 412 + 413 + phy_debug_root = create_phy_debug_root(); 414 + 415 + if (!phy_debug_root) 416 + return; 417 + 418 + rtk_phy->debug_dir = debugfs_create_dir(dev_name(rtk_phy->dev), phy_debug_root); 419 + if (!rtk_phy->debug_dir) 420 + return; 421 + 422 + if (!debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy, 423 + &rtk_usb3_parameter_fops)) 424 + goto file_error; 425 + 426 + return; 427 + 428 + file_error: 429 + debugfs_remove_recursive(rtk_phy->debug_dir); 430 + } 431 + 432 + static inline void remove_debug_files(struct rtk_phy *rtk_phy) 433 + { 434 + debugfs_remove_recursive(rtk_phy->debug_dir); 435 + } 436 + #else 437 + static inline void create_debug_files(struct rtk_phy *rtk_phy) { } 438 + static inline void remove_debug_files(struct rtk_phy *rtk_phy) { } 439 + #endif /* CONFIG_DEBUG_FS */ 440 + 441 + static int get_phy_data_by_efuse(struct rtk_phy *rtk_phy, 442 + struct phy_parameter *phy_parameter, int index) 443 + { 444 + struct phy_cfg *phy_cfg = rtk_phy->phy_cfg; 445 + u8 value = 0; 446 + struct nvmem_cell *cell; 447 + 448 + if (!phy_cfg->check_efuse) 449 + goto out; 450 + 451 + cell = nvmem_cell_get(rtk_phy->dev, "usb_u3_tx_lfps_swing_trim"); 452 + if (IS_ERR(cell)) { 453 + dev_dbg(rtk_phy->dev, "%s no usb_u3_tx_lfps_swing_trim: %ld\n", 454 + __func__, PTR_ERR(cell)); 455 + } else { 456 + unsigned char *buf; 457 + size_t buf_size; 458 + 459 + buf = nvmem_cell_read(cell, &buf_size); 460 + if (!IS_ERR(buf)) { 461 + value = buf[0] & USB_U3_TX_LFPS_SWING_TRIM_MASK; 462 + kfree(buf); 463 + } 464 + nvmem_cell_put(cell); 465 + } 466 + 467 + if (value > 0 && value < 0x8) 468 + phy_parameter->efuse_usb_u3_tx_lfps_swing_trim = 0x8; 469 + else 470 + phy_parameter->efuse_usb_u3_tx_lfps_swing_trim = (u8)value; 471 + 472 + out: 473 + return 0; 474 + } 475 + 476 + static void update_amplitude_control_value(struct rtk_phy *rtk_phy, 477 + struct phy_parameter *phy_parameter) 478 + { 479 + struct phy_cfg *phy_cfg; 480 + struct phy_reg *phy_reg; 481 + 482 + phy_reg = &phy_parameter->phy_reg; 483 + phy_cfg = rtk_phy->phy_cfg; 484 + 485 + if (phy_parameter->amplitude_control_coarse != AMPLITUDE_CONTROL_COARSE_DEFAULT) { 486 + u16 val_mask = AMPLITUDE_CONTROL_COARSE_MASK; 487 + u16 data; 488 + 489 + if (!phy_cfg->param[PHY_ADDR_0X20].addr && !phy_cfg->param[PHY_ADDR_0X20].data) { 490 + phy_cfg->param[PHY_ADDR_0X20].addr = PHY_ADDR_0X20; 491 + data = rtk_phy_read(phy_reg, PHY_ADDR_0X20); 492 + } else { 493 + data = phy_cfg->param[PHY_ADDR_0X20].data; 494 + } 495 + 496 + data &= (~val_mask); 497 + data |= (phy_parameter->amplitude_control_coarse & val_mask); 498 + 499 + phy_cfg->param[PHY_ADDR_0X20].data = data; 500 + } 501 + 502 + if (phy_parameter->efuse_usb_u3_tx_lfps_swing_trim) { 503 + u8 efuse_val = phy_parameter->efuse_usb_u3_tx_lfps_swing_trim; 504 + u16 val_mask = USB_U3_TX_LFPS_SWING_TRIM_MASK; 505 + int val_shift = USB_U3_TX_LFPS_SWING_TRIM_SHIFT; 506 + u16 data; 507 + 508 + if (!phy_cfg->param[PHY_ADDR_0X20].addr && !phy_cfg->param[PHY_ADDR_0X20].data) { 509 + phy_cfg->param[PHY_ADDR_0X20].addr = PHY_ADDR_0X20; 510 + data = rtk_phy_read(phy_reg, PHY_ADDR_0X20); 511 + } else { 512 + data = phy_cfg->param[PHY_ADDR_0X20].data; 513 + } 514 + 515 + data &= ~(val_mask << val_shift); 516 + data |= ((efuse_val & val_mask) << val_shift); 517 + 518 + phy_cfg->param[PHY_ADDR_0X20].data = data; 519 + } 520 + 521 + if (phy_parameter->amplitude_control_fine != AMPLITUDE_CONTROL_FINE_DEFAULT) { 522 + u16 val_mask = AMPLITUDE_CONTROL_FINE_MASK; 523 + 524 + if (!phy_cfg->param[PHY_ADDR_0X21].addr && !phy_cfg->param[PHY_ADDR_0X21].data) 525 + phy_cfg->param[PHY_ADDR_0X21].addr = PHY_ADDR_0X21; 526 + 527 + phy_cfg->param[PHY_ADDR_0X21].data = 528 + phy_parameter->amplitude_control_fine & val_mask; 529 + } 530 + } 531 + 532 + static int parse_phy_data(struct rtk_phy *rtk_phy) 533 + { 534 + struct device *dev = rtk_phy->dev; 535 + struct phy_parameter *phy_parameter; 536 + int ret = 0; 537 + int index; 538 + 539 + rtk_phy->phy_parameter = devm_kzalloc(dev, sizeof(struct phy_parameter) * 540 + rtk_phy->num_phy, GFP_KERNEL); 541 + if (!rtk_phy->phy_parameter) 542 + return -ENOMEM; 543 + 544 + for (index = 0; index < rtk_phy->num_phy; index++) { 545 + phy_parameter = &((struct phy_parameter *)rtk_phy->phy_parameter)[index]; 546 + 547 + phy_parameter->phy_reg.reg_mdio_ctl = of_iomap(dev->of_node, 0) + index; 548 + 549 + /* Amplitude control address 0x20 bit 0 to bit 7 */ 550 + if (of_property_read_u32(dev->of_node, "realtek,amplitude-control-coarse-tuning", 551 + &phy_parameter->amplitude_control_coarse)) 552 + phy_parameter->amplitude_control_coarse = AMPLITUDE_CONTROL_COARSE_DEFAULT; 553 + 554 + /* Amplitude control address 0x21 bit 0 to bit 16 */ 555 + if (of_property_read_u32(dev->of_node, "realtek,amplitude-control-fine-tuning", 556 + &phy_parameter->amplitude_control_fine)) 557 + phy_parameter->amplitude_control_fine = AMPLITUDE_CONTROL_FINE_DEFAULT; 558 + 559 + get_phy_data_by_efuse(rtk_phy, phy_parameter, index); 560 + 561 + update_amplitude_control_value(rtk_phy, phy_parameter); 562 + } 563 + 564 + return ret; 565 + } 566 + 567 + static int rtk_usb3phy_probe(struct platform_device *pdev) 568 + { 569 + struct rtk_phy *rtk_phy; 570 + struct device *dev = &pdev->dev; 571 + struct phy *generic_phy; 572 + struct phy_provider *phy_provider; 573 + const struct phy_cfg *phy_cfg; 574 + int ret; 575 + 576 + phy_cfg = of_device_get_match_data(dev); 577 + if (!phy_cfg) { 578 + dev_err(dev, "phy config are not assigned!\n"); 579 + return -EINVAL; 580 + } 581 + 582 + rtk_phy = devm_kzalloc(dev, sizeof(*rtk_phy), GFP_KERNEL); 583 + if (!rtk_phy) 584 + return -ENOMEM; 585 + 586 + rtk_phy->dev = &pdev->dev; 587 + rtk_phy->phy.dev = rtk_phy->dev; 588 + rtk_phy->phy.label = "rtk-usb3phy"; 589 + rtk_phy->phy.notify_port_status = rtk_phy_notify_port_status; 590 + 591 + rtk_phy->phy_cfg = devm_kzalloc(dev, sizeof(*phy_cfg), GFP_KERNEL); 592 + 593 + memcpy(rtk_phy->phy_cfg, phy_cfg, sizeof(*phy_cfg)); 594 + 595 + rtk_phy->num_phy = 1; 596 + 597 + ret = parse_phy_data(rtk_phy); 598 + if (ret) 599 + goto err; 600 + 601 + platform_set_drvdata(pdev, rtk_phy); 602 + 603 + generic_phy = devm_phy_create(rtk_phy->dev, NULL, &ops); 604 + if (IS_ERR(generic_phy)) 605 + return PTR_ERR(generic_phy); 606 + 607 + phy_set_drvdata(generic_phy, rtk_phy); 608 + 609 + phy_provider = devm_of_phy_provider_register(rtk_phy->dev, of_phy_simple_xlate); 610 + if (IS_ERR(phy_provider)) 611 + return PTR_ERR(phy_provider); 612 + 613 + ret = usb_add_phy_dev(&rtk_phy->phy); 614 + if (ret) 615 + goto err; 616 + 617 + create_debug_files(rtk_phy); 618 + 619 + err: 620 + return ret; 621 + } 622 + 623 + static void rtk_usb3phy_remove(struct platform_device *pdev) 624 + { 625 + struct rtk_phy *rtk_phy = platform_get_drvdata(pdev); 626 + 627 + remove_debug_files(rtk_phy); 628 + 629 + usb_remove_phy(&rtk_phy->phy); 630 + } 631 + 632 + static const struct phy_cfg rtd1295_phy_cfg = { 633 + .param_size = MAX_USB_PHY_DATA_SIZE, 634 + .param = { [0] = {0x01, 0x4008}, [1] = {0x01, 0xe046}, 635 + [2] = {0x02, 0x6046}, [3] = {0x03, 0x2779}, 636 + [4] = {0x04, 0x72f5}, [5] = {0x05, 0x2ad3}, 637 + [6] = {0x06, 0x000e}, [7] = {0x07, 0x2e00}, 638 + [8] = {0x08, 0x3591}, [9] = {0x09, 0x525c}, 639 + [10] = {0x0a, 0xa600}, [11] = {0x0b, 0xa904}, 640 + [12] = {0x0c, 0xc000}, [13] = {0x0d, 0xef1c}, 641 + [14] = {0x0e, 0x2000}, [15] = {0x0f, 0x0000}, 642 + [16] = {0x10, 0x000c}, [17] = {0x11, 0x4c00}, 643 + [18] = {0x12, 0xfc00}, [19] = {0x13, 0x0c81}, 644 + [20] = {0x14, 0xde01}, [21] = {0x15, 0x0000}, 645 + [22] = {0x16, 0x0000}, [23] = {0x17, 0x0000}, 646 + [24] = {0x18, 0x0000}, [25] = {0x19, 0x4004}, 647 + [26] = {0x1a, 0x1260}, [27] = {0x1b, 0xff00}, 648 + [28] = {0x1c, 0xcb00}, [29] = {0x1d, 0xa03f}, 649 + [30] = {0x1e, 0xc2e0}, [31] = {0x1f, 0x2807}, 650 + [32] = {0x20, 0x947a}, [33] = {0x21, 0x88aa}, 651 + [34] = {0x22, 0x0057}, [35] = {0x23, 0xab66}, 652 + [36] = {0x24, 0x0800}, [37] = {0x25, 0x0000}, 653 + [38] = {0x26, 0x040a}, [39] = {0x27, 0x01d6}, 654 + [40] = {0x28, 0xf8c2}, [41] = {0x29, 0x3080}, 655 + [42] = {0x2a, 0x3082}, [43] = {0x2b, 0x2078}, 656 + [44] = {0x2c, 0xffff}, [45] = {0x2d, 0xffff}, 657 + [46] = {0x2e, 0x0000}, [47] = {0x2f, 0x0040}, }, 658 + .check_efuse = false, 659 + .do_toggle = true, 660 + .do_toggle_once = false, 661 + .use_default_parameter = false, 662 + .check_rx_front_end_offset = false, 663 + }; 664 + 665 + static const struct phy_cfg rtd1619_phy_cfg = { 666 + .param_size = MAX_USB_PHY_DATA_SIZE, 667 + .param = { [8] = {0x08, 0x3591}, 668 + [38] = {0x26, 0x840b}, 669 + [40] = {0x28, 0xf842}, }, 670 + .check_efuse = false, 671 + .do_toggle = true, 672 + .do_toggle_once = false, 673 + .use_default_parameter = false, 674 + .check_rx_front_end_offset = false, 675 + }; 676 + 677 + static const struct phy_cfg rtd1319_phy_cfg = { 678 + .param_size = MAX_USB_PHY_DATA_SIZE, 679 + .param = { [1] = {0x01, 0xac86}, 680 + [6] = {0x06, 0x0003}, 681 + [9] = {0x09, 0x924c}, 682 + [10] = {0x0a, 0xa608}, 683 + [11] = {0x0b, 0xb905}, 684 + [14] = {0x0e, 0x2010}, 685 + [32] = {0x20, 0x705a}, 686 + [33] = {0x21, 0xf645}, 687 + [34] = {0x22, 0x0013}, 688 + [35] = {0x23, 0xcb66}, 689 + [41] = {0x29, 0xff00}, }, 690 + .check_efuse = true, 691 + .do_toggle = true, 692 + .do_toggle_once = false, 693 + .use_default_parameter = false, 694 + .check_rx_front_end_offset = false, 695 + }; 696 + 697 + static const struct phy_cfg rtd1619b_phy_cfg = { 698 + .param_size = MAX_USB_PHY_DATA_SIZE, 699 + .param = { [1] = {0x01, 0xac8c}, 700 + [6] = {0x06, 0x0017}, 701 + [9] = {0x09, 0x724c}, 702 + [10] = {0x0a, 0xb610}, 703 + [11] = {0x0b, 0xb90d}, 704 + [13] = {0x0d, 0xef2a}, 705 + [15] = {0x0f, 0x9050}, 706 + [16] = {0x10, 0x000c}, 707 + [32] = {0x20, 0x70ff}, 708 + [34] = {0x22, 0x0013}, 709 + [35] = {0x23, 0xdb66}, 710 + [38] = {0x26, 0x8609}, 711 + [41] = {0x29, 0xff13}, 712 + [42] = {0x2a, 0x3070}, }, 713 + .check_efuse = true, 714 + .do_toggle = false, 715 + .do_toggle_once = true, 716 + .use_default_parameter = false, 717 + .check_rx_front_end_offset = false, 718 + }; 719 + 720 + static const struct phy_cfg rtd1319d_phy_cfg = { 721 + .param_size = MAX_USB_PHY_DATA_SIZE, 722 + .param = { [1] = {0x01, 0xac89}, 723 + [4] = {0x04, 0xf2f5}, 724 + [6] = {0x06, 0x0017}, 725 + [9] = {0x09, 0x424c}, 726 + [10] = {0x0a, 0x9610}, 727 + [11] = {0x0b, 0x9901}, 728 + [12] = {0x0c, 0xf000}, 729 + [13] = {0x0d, 0xef2a}, 730 + [14] = {0x0e, 0x1000}, 731 + [15] = {0x0f, 0x9050}, 732 + [32] = {0x20, 0x7077}, 733 + [35] = {0x23, 0x0b62}, 734 + [37] = {0x25, 0x10ec}, 735 + [42] = {0x2a, 0x3070}, }, 736 + .check_efuse = true, 737 + .do_toggle = false, 738 + .do_toggle_once = true, 739 + .use_default_parameter = false, 740 + .check_rx_front_end_offset = true, 741 + }; 742 + 743 + static const struct of_device_id usbphy_rtk_dt_match[] = { 744 + { .compatible = "realtek,rtd1295-usb3phy", .data = &rtd1295_phy_cfg }, 745 + { .compatible = "realtek,rtd1319-usb3phy", .data = &rtd1319_phy_cfg }, 746 + { .compatible = "realtek,rtd1319d-usb3phy", .data = &rtd1319d_phy_cfg }, 747 + { .compatible = "realtek,rtd1619-usb3phy", .data = &rtd1619_phy_cfg }, 748 + { .compatible = "realtek,rtd1619b-usb3phy", .data = &rtd1619b_phy_cfg }, 749 + {}, 750 + }; 751 + MODULE_DEVICE_TABLE(of, usbphy_rtk_dt_match); 752 + 753 + static struct platform_driver rtk_usb3phy_driver = { 754 + .probe = rtk_usb3phy_probe, 755 + .remove_new = rtk_usb3phy_remove, 756 + .driver = { 757 + .name = "rtk-usb3phy", 758 + .of_match_table = usbphy_rtk_dt_match, 759 + }, 760 + }; 761 + 762 + module_platform_driver(rtk_usb3phy_driver); 763 + 764 + MODULE_LICENSE("GPL"); 765 + MODULE_ALIAS("platform: rtk-usb3phy"); 766 + MODULE_AUTHOR("Stanley Chang <stanley_chang@realtek.com>"); 767 + MODULE_DESCRIPTION("Realtek usb 3.0 phy driver");
+27 -1
drivers/platform/chrome/cros_ec_typec.c
··· 406 406 return ret; 407 407 } 408 408 409 + /** 410 + * cros_typec_get_cable_vdo() - Get Cable VDO of the connected cable 411 + * @port: Type-C port data 412 + * @svid: Standard or Vendor ID to match 413 + * 414 + * Returns the Cable VDO if match is found and returns 0 if match is not found. 415 + */ 416 + static int cros_typec_get_cable_vdo(struct cros_typec_port *port, u16 svid) 417 + { 418 + struct list_head *head = &port->plug_mode_list; 419 + struct cros_typec_altmode_node *node; 420 + u32 ret = 0; 421 + 422 + list_for_each_entry(node, head, list) { 423 + if (node->amode->svid == svid) 424 + return node->amode->vdo; 425 + } 426 + 427 + return ret; 428 + } 429 + 409 430 /* 410 431 * Spoof the VDOs that were likely communicated by the partner for TBT alt 411 432 * mode. ··· 453 432 454 433 /* Cable Discover Mode VDO */ 455 434 data.cable_mode = TBT_MODE; 435 + 436 + data.cable_mode |= cros_typec_get_cable_vdo(port, USB_TYPEC_TBT_SID); 437 + 456 438 data.cable_mode |= TBT_SET_CABLE_SPEED(pd_ctrl->cable_speed); 457 439 458 440 if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE) ··· 546 522 /* Cable Type */ 547 523 if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE) 548 524 data.eudo |= EUDO_CABLE_TYPE_OPTICAL << EUDO_CABLE_TYPE_SHIFT; 549 - else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE) 525 + else if (cros_typec_get_cable_vdo(port, USB_TYPEC_TBT_SID) & TBT_CABLE_RETIMER) 550 526 data.eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT; 527 + else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE) 528 + data.eudo |= EUDO_CABLE_TYPE_RE_DRIVER << EUDO_CABLE_TYPE_SHIFT; 551 529 552 530 data.active_link_training = !!(pd_ctrl->control_flags & 553 531 USB_PD_CTRL_ACTIVE_LINK_UNIDIR);
+13 -5
drivers/thunderbolt/acpi.c
··· 12 12 #include "tb.h" 13 13 14 14 static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data, 15 - void **return_value) 15 + void **ret) 16 16 { 17 17 struct acpi_device *adev = acpi_fetch_acpi_dev(handle); 18 18 struct fwnode_handle *fwnode; ··· 84 84 if (link) { 85 85 dev_dbg(&nhi->pdev->dev, "created link from %s\n", 86 86 dev_name(&pdev->dev)); 87 + *(bool *)ret = true; 87 88 } else { 88 89 dev_warn(&nhi->pdev->dev, "device link creation from %s failed\n", 89 90 dev_name(&pdev->dev)); ··· 105 104 * Goes over ACPI namespace finding tunneled ports that reference to 106 105 * @nhi ACPI node. For each reference a device link is added. The link 107 106 * is automatically removed by the driver core. 107 + * 108 + * Returns %true if at least one link was created. 108 109 */ 109 - void tb_acpi_add_links(struct tb_nhi *nhi) 110 + bool tb_acpi_add_links(struct tb_nhi *nhi) 110 111 { 111 112 acpi_status status; 113 + bool ret = false; 112 114 113 115 if (!has_acpi_companion(&nhi->pdev->dev)) 114 - return; 116 + return false; 115 117 116 118 /* 117 119 * Find all devices that have usb4-host-controller interface 118 120 * property that references to this NHI. 119 121 */ 120 122 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 32, 121 - tb_acpi_add_link, NULL, nhi, NULL); 122 - if (ACPI_FAILURE(status)) 123 + tb_acpi_add_link, NULL, nhi, (void **)&ret); 124 + if (ACPI_FAILURE(status)) { 123 125 dev_warn(&nhi->pdev->dev, "failed to enumerate tunneled ports\n"); 126 + return false; 127 + } 128 + 129 + return ret; 124 130 } 125 131 126 132 /**
+37 -36
drivers/thunderbolt/switch.c
··· 2188 2188 2189 2189 static int tb_switch_get_generation(struct tb_switch *sw) 2190 2190 { 2191 - switch (sw->config.device_id) { 2192 - case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE: 2193 - case PCI_DEVICE_ID_INTEL_EAGLE_RIDGE: 2194 - case PCI_DEVICE_ID_INTEL_LIGHT_PEAK: 2195 - case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_2C: 2196 - case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C: 2197 - case PCI_DEVICE_ID_INTEL_PORT_RIDGE: 2198 - case PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_2C_BRIDGE: 2199 - case PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_4C_BRIDGE: 2200 - return 1; 2191 + if (tb_switch_is_usb4(sw)) 2192 + return 4; 2201 2193 2202 - case PCI_DEVICE_ID_INTEL_WIN_RIDGE_2C_BRIDGE: 2203 - case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_BRIDGE: 2204 - case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_BRIDGE: 2205 - return 2; 2194 + if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { 2195 + switch (sw->config.device_id) { 2196 + case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE: 2197 + case PCI_DEVICE_ID_INTEL_EAGLE_RIDGE: 2198 + case PCI_DEVICE_ID_INTEL_LIGHT_PEAK: 2199 + case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_2C: 2200 + case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C: 2201 + case PCI_DEVICE_ID_INTEL_PORT_RIDGE: 2202 + case PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_2C_BRIDGE: 2203 + case PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_4C_BRIDGE: 2204 + return 1; 2206 2205 2207 - case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE: 2208 - case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE: 2209 - case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_BRIDGE: 2210 - case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE: 2211 - case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE: 2212 - case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_BRIDGE: 2213 - case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_BRIDGE: 2214 - case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE: 2215 - case PCI_DEVICE_ID_INTEL_ICL_NHI0: 2216 - case PCI_DEVICE_ID_INTEL_ICL_NHI1: 2217 - return 3; 2206 + case PCI_DEVICE_ID_INTEL_WIN_RIDGE_2C_BRIDGE: 2207 + case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_BRIDGE: 2208 + case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_BRIDGE: 2209 + return 2; 2218 2210 2219 - default: 2220 - if (tb_switch_is_usb4(sw)) 2221 - return 4; 2222 - 2223 - /* 2224 - * For unknown switches assume generation to be 1 to be 2225 - * on the safe side. 2226 - */ 2227 - tb_sw_warn(sw, "unsupported switch device id %#x\n", 2228 - sw->config.device_id); 2229 - return 1; 2211 + case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE: 2212 + case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE: 2213 + case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_BRIDGE: 2214 + case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE: 2215 + case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE: 2216 + case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_BRIDGE: 2217 + case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_BRIDGE: 2218 + case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE: 2219 + case PCI_DEVICE_ID_INTEL_ICL_NHI0: 2220 + case PCI_DEVICE_ID_INTEL_ICL_NHI1: 2221 + return 3; 2222 + } 2230 2223 } 2224 + 2225 + /* 2226 + * For unknown switches assume generation to be 1 to be on the 2227 + * safe side. 2228 + */ 2229 + tb_sw_warn(sw, "unsupported switch device id %#x\n", 2230 + sw->config.device_id); 2231 + return 1; 2231 2232 } 2232 2233 2233 2234 static bool tb_switch_exceeds_max_depth(const struct tb_switch *sw, int depth)
+17 -7
drivers/thunderbolt/tb.c
··· 2368 2368 * downstream ports and the NHI so that the device core will make sure 2369 2369 * NHI is resumed first before the rest. 2370 2370 */ 2371 - static void tb_apple_add_links(struct tb_nhi *nhi) 2371 + static bool tb_apple_add_links(struct tb_nhi *nhi) 2372 2372 { 2373 2373 struct pci_dev *upstream, *pdev; 2374 + bool ret; 2374 2375 2375 2376 if (!x86_apple_machine) 2376 - return; 2377 + return false; 2377 2378 2378 2379 switch (nhi->pdev->device) { 2379 2380 case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE: ··· 2383 2382 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI: 2384 2383 break; 2385 2384 default: 2386 - return; 2385 + return false; 2387 2386 } 2388 2387 2389 2388 upstream = pci_upstream_bridge(nhi->pdev); 2390 2389 while (upstream) { 2391 2390 if (!pci_is_pcie(upstream)) 2392 - return; 2391 + return false; 2393 2392 if (pci_pcie_type(upstream) == PCI_EXP_TYPE_UPSTREAM) 2394 2393 break; 2395 2394 upstream = pci_upstream_bridge(upstream); 2396 2395 } 2397 2396 2398 2397 if (!upstream) 2399 - return; 2398 + return false; 2400 2399 2401 2400 /* 2402 2401 * For each hotplug downstream port, create add device link 2403 2402 * back to NHI so that PCIe tunnels can be re-established after 2404 2403 * sleep. 2405 2404 */ 2405 + ret = false; 2406 2406 for_each_pci_bridge(pdev, upstream->subordinate) { 2407 2407 const struct device_link *link; 2408 2408 ··· 2419 2417 if (link) { 2420 2418 dev_dbg(&nhi->pdev->dev, "created link from %s\n", 2421 2419 dev_name(&pdev->dev)); 2420 + ret = true; 2422 2421 } else { 2423 2422 dev_warn(&nhi->pdev->dev, "device link creation from %s failed\n", 2424 2423 dev_name(&pdev->dev)); 2425 2424 } 2426 2425 } 2426 + 2427 + return ret; 2427 2428 } 2428 2429 2429 2430 struct tb *tb_probe(struct tb_nhi *nhi) ··· 2453 2448 2454 2449 tb_dbg(tb, "using software connection manager\n"); 2455 2450 2456 - tb_apple_add_links(nhi); 2457 - tb_acpi_add_links(nhi); 2451 + /* 2452 + * Device links are needed to make sure we establish tunnels 2453 + * before the PCIe/USB stack is resumed so complain here if we 2454 + * found them missing. 2455 + */ 2456 + if (!tb_apple_add_links(nhi) && !tb_acpi_add_links(nhi)) 2457 + tb_warn(tb, "device links to tunneled native ports are missing!\n"); 2458 2458 2459 2459 return tb; 2460 2460 }
+2 -2
drivers/thunderbolt/tb.h
··· 1333 1333 void tb_check_quirks(struct tb_switch *sw); 1334 1334 1335 1335 #ifdef CONFIG_ACPI 1336 - void tb_acpi_add_links(struct tb_nhi *nhi); 1336 + bool tb_acpi_add_links(struct tb_nhi *nhi); 1337 1337 1338 1338 bool tb_acpi_is_native(void); 1339 1339 bool tb_acpi_may_tunnel_usb3(void); ··· 1346 1346 int tb_acpi_power_on_retimers(struct tb_port *port); 1347 1347 int tb_acpi_power_off_retimers(struct tb_port *port); 1348 1348 #else 1349 - static inline void tb_acpi_add_links(struct tb_nhi *nhi) { } 1349 + static inline bool tb_acpi_add_links(struct tb_nhi *nhi) { return false; } 1350 1350 1351 1351 static inline bool tb_acpi_is_native(void) { return true; } 1352 1352 static inline bool tb_acpi_may_tunnel_usb3(void) { return true; }
+1 -1
drivers/thunderbolt/tmu.c
··· 19 19 [TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI] = 16, 20 20 }; 21 21 22 - const struct { 22 + static const struct { 23 23 unsigned int freq_meas_window; 24 24 unsigned int avg_const; 25 25 unsigned int delta_avg_const;
+1
drivers/usb/cdns3/cdns3-gadget.c
··· 61 61 #include <linux/module.h> 62 62 #include <linux/dmapool.h> 63 63 #include <linux/iopoll.h> 64 + #include <linux/property.h> 64 65 65 66 #include "core.h" 66 67 #include "gadget-export.h"
+3 -1
drivers/usb/cdns3/cdns3-plat.c
··· 15 15 #include <linux/module.h> 16 16 #include <linux/irq.h> 17 17 #include <linux/kernel.h> 18 + #include <linux/of.h> 18 19 #include <linux/platform_device.h> 19 20 #include <linux/pm_runtime.h> 20 21 ··· 256 255 cdns3_set_platform_suspend(cdns->dev, false, false); 257 256 258 257 spin_lock_irqsave(&cdns->lock, flags); 259 - cdns_resume(cdns, !PMSG_IS_AUTO(msg)); 258 + cdns_resume(cdns); 260 259 cdns->in_lpm = false; 261 260 spin_unlock_irqrestore(&cdns->lock, flags); 261 + cdns_set_active(cdns, !PMSG_IS_AUTO(msg)); 262 262 if (cdns->wakeup_pending) { 263 263 cdns->wakeup_pending = false; 264 264 enable_irq(cdns->wakeup_irq);
+2 -4
drivers/usb/cdns3/cdns3-starfive.c
··· 166 166 return 0; 167 167 } 168 168 169 - static int cdns_starfive_remove(struct platform_device *pdev) 169 + static void cdns_starfive_remove(struct platform_device *pdev) 170 170 { 171 171 struct device *dev = &pdev->dev; 172 172 struct cdns_starfive *data = dev_get_drvdata(dev); ··· 178 178 pm_runtime_put_noidle(dev); 179 179 cdns_clk_rst_deinit(data); 180 180 platform_set_drvdata(pdev, NULL); 181 - 182 - return 0; 183 181 } 184 182 185 183 #ifdef CONFIG_PM ··· 230 232 231 233 static struct platform_driver cdns_starfive_driver = { 232 234 .probe = cdns_starfive_probe, 233 - .remove = cdns_starfive_remove, 235 + .remove_new = cdns_starfive_remove, 234 236 .driver = { 235 237 .name = "cdns3-starfive", 236 238 .of_match_table = cdns_starfive_of_match,
+1
drivers/usb/cdns3/cdns3-ti.c
··· 15 15 #include <linux/io.h> 16 16 #include <linux/of_platform.h> 17 17 #include <linux/pm_runtime.h> 18 + #include <linux/property.h> 18 19 19 20 /* USB Wrapper register offsets */ 20 21 #define USBSS_PID 0x0
+2 -1
drivers/usb/cdns3/cdnsp-pci.c
··· 208 208 int ret; 209 209 210 210 spin_lock_irqsave(&cdns->lock, flags); 211 - ret = cdns_resume(cdns, 1); 211 + ret = cdns_resume(cdns); 212 212 spin_unlock_irqrestore(&cdns->lock, flags); 213 + cdns_set_active(cdns, 1); 213 214 214 215 return ret; 215 216 }
+12 -4
drivers/usb/cdns3/core.c
··· 14 14 #include <linux/dma-mapping.h> 15 15 #include <linux/module.h> 16 16 #include <linux/kernel.h> 17 + #include <linux/of.h> 17 18 #include <linux/platform_device.h> 18 19 #include <linux/interrupt.h> 19 20 #include <linux/io.h> ··· 523 522 } 524 523 EXPORT_SYMBOL_GPL(cdns_suspend); 525 524 526 - int cdns_resume(struct cdns *cdns, u8 set_active) 525 + int cdns_resume(struct cdns *cdns) 527 526 { 528 - struct device *dev = cdns->dev; 529 527 enum usb_role real_role; 530 528 bool role_changed = false; 531 529 int ret = 0; ··· 556 556 if (cdns->roles[cdns->role]->resume) 557 557 cdns->roles[cdns->role]->resume(cdns, cdns_power_is_lost(cdns)); 558 558 559 + return 0; 560 + } 561 + EXPORT_SYMBOL_GPL(cdns_resume); 562 + 563 + void cdns_set_active(struct cdns *cdns, u8 set_active) 564 + { 565 + struct device *dev = cdns->dev; 566 + 559 567 if (set_active) { 560 568 pm_runtime_disable(dev); 561 569 pm_runtime_set_active(dev); 562 570 pm_runtime_enable(dev); 563 571 } 564 572 565 - return 0; 573 + return; 566 574 } 567 - EXPORT_SYMBOL_GPL(cdns_resume); 575 + EXPORT_SYMBOL_GPL(cdns_set_active); 568 576 #endif /* CONFIG_PM_SLEEP */ 569 577 570 578 MODULE_AUTHOR("Peter Chen <peter.chen@nxp.com>");
+5 -2
drivers/usb/cdns3/core.h
··· 125 125 int cdns_remove(struct cdns *cdns); 126 126 127 127 #ifdef CONFIG_PM_SLEEP 128 - int cdns_resume(struct cdns *cdns, u8 set_active); 128 + int cdns_resume(struct cdns *cdns); 129 129 int cdns_suspend(struct cdns *cdns); 130 + void cdns_set_active(struct cdns *cdns, u8 set_active); 130 131 #else /* CONFIG_PM_SLEEP */ 131 - static inline int cdns_resume(struct cdns *cdns, u8 set_active) 132 + static inline int cdns_resume(struct cdns *cdns) 133 + { return 0; } 134 + static inline int cdns_set_active(struct cdns *cdns, u8 set_active) 132 135 { return 0; } 133 136 static inline int cdns_suspend(struct cdns *cdns) 134 137 { return 0; }
+4
drivers/usb/cdns3/drd.c
··· 196 196 if (ret) 197 197 dev_err(cdns->dev, "timeout waiting for xhci_ready\n"); 198 198 199 + phy_set_mode(cdns->usb2_phy, PHY_MODE_USB_HOST); 199 200 phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_HOST); 200 201 return ret; 201 202 } ··· 217 216 readl_poll_timeout_atomic(&cdns->otg_regs->state, val, 218 217 !(val & OTGSTATE_HOST_STATE_MASK), 219 218 1, 2000000); 219 + phy_set_mode(cdns->usb2_phy, PHY_MODE_INVALID); 220 220 phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID); 221 221 } 222 222 ··· 250 248 return ret; 251 249 } 252 250 251 + phy_set_mode(cdns->usb2_phy, PHY_MODE_USB_DEVICE); 253 252 phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_DEVICE); 254 253 return 0; 255 254 } ··· 276 273 readl_poll_timeout_atomic(&cdns->otg_regs->state, val, 277 274 !(val & OTGSTATE_DEV_STATE_MASK), 278 275 1, 2000000); 276 + phy_set_mode(cdns->usb2_phy, PHY_MODE_INVALID); 279 277 phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID); 280 278 } 281 279 EXPORT_SYMBOL_GPL(cdns_drd_gadget_off);
+17 -2
drivers/usb/chipidea/ci.h
··· 257 257 bool id_event; 258 258 bool b_sess_valid_event; 259 259 bool imx28_write_fix; 260 + bool has_portsc_pec_bug; 260 261 bool supports_runtime_pm; 261 262 bool in_lpm; 262 263 bool wakeup_int; ··· 282 281 return -ENXIO; 283 282 284 283 ret = ci->roles[role]->start(ci); 285 - if (!ret) 286 - ci->role = role; 284 + if (ret) 285 + return ret; 286 + 287 + ci->role = role; 288 + 289 + if (ci->usb_phy) { 290 + if (role == CI_ROLE_HOST) 291 + usb_phy_set_event(ci->usb_phy, USB_EVENT_ID); 292 + else 293 + /* in device mode but vbus is invalid*/ 294 + usb_phy_set_event(ci->usb_phy, USB_EVENT_NONE); 295 + } 296 + 287 297 return ret; 288 298 } 289 299 ··· 308 296 ci->role = CI_ROLE_END; 309 297 310 298 ci->roles[role]->stop(ci); 299 + 300 + if (ci->usb_phy) 301 + usb_phy_set_event(ci->usb_phy, USB_EVENT_NONE); 311 302 } 312 303 313 304 static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
+13 -5
drivers/usb/chipidea/ci_hdrc_imx.c
··· 6 6 */ 7 7 8 8 #include <linux/module.h> 9 + #include <linux/of.h> 9 10 #include <linux/of_platform.h> 10 11 #include <linux/platform_device.h> 11 12 #include <linux/pm_runtime.h> ··· 68 67 69 68 static const struct ci_hdrc_imx_platform_flag imx7ulp_usb_data = { 70 69 .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | 70 + CI_HDRC_HAS_PORTSC_PEC_MISSED | 71 71 CI_HDRC_PMQOS, 72 72 }; 73 73 74 74 static const struct ci_hdrc_imx_platform_flag imx8ulp_usb_data = { 75 - .flags = CI_HDRC_SUPPORTS_RUNTIME_PM, 75 + .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | 76 + CI_HDRC_HAS_PORTSC_PEC_MISSED, 76 77 }; 77 78 78 79 static const struct of_device_id ci_hdrc_imx_dt_ids[] = { ··· 178 175 if (of_usb_get_phy_mode(np) == USBPHY_INTERFACE_MODE_ULPI) 179 176 data->ulpi = 1; 180 177 181 - of_property_read_u32(np, "samsung,picophy-pre-emp-curr-control", 182 - &data->emp_curr_control); 183 - of_property_read_u32(np, "samsung,picophy-dc-vol-level-adjust", 184 - &data->dc_vol_level_adjust); 178 + if (of_property_read_u32(np, "samsung,picophy-pre-emp-curr-control", 179 + &data->emp_curr_control)) 180 + data->emp_curr_control = -1; 181 + if (of_property_read_u32(np, "samsung,picophy-dc-vol-level-adjust", 182 + &data->dc_vol_level_adjust)) 183 + data->dc_vol_level_adjust = -1; 184 + if (of_property_read_u32(np, "fsl,picophy-rise-fall-time-adjust", 185 + &data->rise_fall_time_adjust)) 186 + data->rise_fall_time_adjust = -1; 185 187 186 188 return data; 187 189 }
+1
drivers/usb/chipidea/ci_hdrc_imx.h
··· 28 28 enum usb_dr_mode available_role; /* runtime usb dr mode */ 29 29 int emp_curr_control; 30 30 int dc_vol_level_adjust; 31 + int rise_fall_time_adjust; 31 32 }; 32 33 33 34 int imx_usbmisc_init(struct imx_usbmisc_data *data);
+2 -1
drivers/usb/chipidea/ci_hdrc_tegra.c
··· 6 6 #include <linux/clk.h> 7 7 #include <linux/io.h> 8 8 #include <linux/module.h> 9 - #include <linux/of_device.h> 9 + #include <linux/of.h> 10 + #include <linux/platform_device.h> 10 11 #include <linux/pm_runtime.h> 11 12 #include <linux/reset.h> 12 13
+3 -2
drivers/usb/chipidea/core.c
··· 1028 1028 return -ENODEV; 1029 1029 } 1030 1030 1031 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1032 - base = devm_ioremap_resource(dev, res); 1031 + base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 1033 1032 if (IS_ERR(base)) 1034 1033 return PTR_ERR(base); 1035 1034 ··· 1044 1045 CI_HDRC_IMX28_WRITE_FIX); 1045 1046 ci->supports_runtime_pm = !!(ci->platdata->flags & 1046 1047 CI_HDRC_SUPPORTS_RUNTIME_PM); 1048 + ci->has_portsc_pec_bug = !!(ci->platdata->flags & 1049 + CI_HDRC_HAS_PORTSC_PEC_MISSED); 1047 1050 platform_set_drvdata(pdev, ci); 1048 1051 1049 1052 ret = hw_device_init(ci, base);
+1
drivers/usb/chipidea/host.c
··· 151 151 ehci->has_hostpc = ci->hw_bank.lpm; 152 152 ehci->has_tdi_phy_lpm = ci->hw_bank.lpm; 153 153 ehci->imx28_write_fix = ci->imx28_write_fix; 154 + ehci->has_ci_pec_bug = ci->has_portsc_pec_bug; 154 155 155 156 priv = (struct ehci_ci_priv *)ehci->priv; 156 157 priv->reg_vbus = NULL;
+11 -1
drivers/usb/chipidea/udc.c
··· 1463 1463 */ 1464 1464 static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) 1465 1465 { 1466 - struct ci_hw_req *hwreq = NULL; 1466 + struct ci_hw_req *hwreq; 1467 1467 1468 1468 if (ep == NULL) 1469 1469 return NULL; ··· 1717 1717 if (ci->platdata->notify_event) 1718 1718 ret = ci->platdata->notify_event(ci, 1719 1719 CI_HDRC_CONTROLLER_VBUS_EVENT); 1720 + 1721 + if (ci->usb_phy) { 1722 + if (is_active) 1723 + usb_phy_set_event(ci->usb_phy, USB_EVENT_VBUS); 1724 + else 1725 + usb_phy_set_event(ci->usb_phy, USB_EVENT_NONE); 1726 + } 1720 1727 1721 1728 if (ci->driver) 1722 1729 ci_hdrc_gadget_connect(_gadget, is_active); ··· 2041 2034 if (USBi_PCI & intr) { 2042 2035 ci->gadget.speed = hw_port_is_high_speed(ci) ? 2043 2036 USB_SPEED_HIGH : USB_SPEED_FULL; 2037 + if (ci->usb_phy) 2038 + usb_phy_set_event(ci->usb_phy, 2039 + USB_EVENT_ENUMERATED); 2044 2040 if (ci->suspended) { 2045 2041 if (ci->driver->resume) { 2046 2042 spin_unlock(&ci->lock);
+15 -3
drivers/usb/chipidea/usbmisc_imx.c
··· 4 4 */ 5 5 6 6 #include <linux/module.h> 7 - #include <linux/of_platform.h> 7 + #include <linux/of.h> 8 8 #include <linux/err.h> 9 9 #include <linux/io.h> 10 10 #include <linux/delay.h> 11 + #include <linux/platform_device.h> 11 12 #include <linux/usb/otg.h> 12 13 13 14 #include "ci_hdrc_imx.h" ··· 131 130 #define MX7D_USB_OTG_PHY_CFG1 0x30 132 131 #define TXPREEMPAMPTUNE0_BIT 28 133 132 #define TXPREEMPAMPTUNE0_MASK (3 << 28) 133 + #define TXRISETUNE0_BIT 24 134 + #define TXRISETUNE0_MASK (3 << 24) 134 135 #define TXVREFTUNE0_BIT 20 135 136 #define TXVREFTUNE0_MASK (0xf << 20) 136 137 ··· 662 659 usbmisc->base + MX7D_USBNC_USB_CTRL2); 663 660 /* PHY tuning for signal quality */ 664 661 reg = readl(usbmisc->base + MX7D_USB_OTG_PHY_CFG1); 665 - if (data->emp_curr_control && data->emp_curr_control <= 662 + if (data->emp_curr_control >= 0 && 663 + data->emp_curr_control <= 666 664 (TXPREEMPAMPTUNE0_MASK >> TXPREEMPAMPTUNE0_BIT)) { 667 665 reg &= ~TXPREEMPAMPTUNE0_MASK; 668 666 reg |= (data->emp_curr_control << TXPREEMPAMPTUNE0_BIT); 669 667 } 670 668 671 - if (data->dc_vol_level_adjust && data->dc_vol_level_adjust <= 669 + if (data->dc_vol_level_adjust >= 0 && 670 + data->dc_vol_level_adjust <= 672 671 (TXVREFTUNE0_MASK >> TXVREFTUNE0_BIT)) { 673 672 reg &= ~TXVREFTUNE0_MASK; 674 673 reg |= (data->dc_vol_level_adjust << TXVREFTUNE0_BIT); 674 + } 675 + 676 + if (data->rise_fall_time_adjust >= 0 && 677 + data->rise_fall_time_adjust <= 678 + (TXRISETUNE0_MASK >> TXRISETUNE0_BIT)) { 679 + reg &= ~TXRISETUNE0_MASK; 680 + reg |= (data->rise_fall_time_adjust << TXRISETUNE0_BIT); 675 681 } 676 682 677 683 writel(reg, usbmisc->base + MX7D_USB_OTG_PHY_CFG1);
+25
drivers/usb/class/cdc-acm.c
··· 28 28 #include <linux/serial.h> 29 29 #include <linux/tty_driver.h> 30 30 #include <linux/tty_flip.h> 31 + #include <linux/tty_ldisc.h> 31 32 #include <linux/module.h> 32 33 #include <linux/mutex.h> 33 34 #include <linux/uaccess.h> ··· 319 318 } 320 319 321 320 difference = acm->ctrlin ^ newctrl; 321 + 322 + if ((difference & USB_CDC_SERIAL_STATE_DCD) && acm->port.tty) { 323 + struct tty_ldisc *ld = tty_ldisc_ref(acm->port.tty); 324 + if (ld) { 325 + if (ld->ops->dcd_change) 326 + ld->ops->dcd_change(acm->port.tty, newctrl & USB_CDC_SERIAL_STATE_DCD); 327 + tty_ldisc_deref(ld); 328 + } 329 + } 330 + 322 331 spin_lock_irqsave(&acm->read_lock, flags); 323 332 acm->ctrlin = newctrl; 324 333 acm->oldcount = acm->iocount; ··· 862 851 * or it might get too enthusiastic. 863 852 */ 864 853 return acm_wb_is_avail(acm) ? acm->writesize : 0; 854 + } 855 + 856 + static void acm_tty_flush_buffer(struct tty_struct *tty) 857 + { 858 + struct acm *acm = tty->driver_data; 859 + unsigned long flags; 860 + int i; 861 + 862 + spin_lock_irqsave(&acm->write_lock, flags); 863 + for (i = 0; i < ACM_NW; i++) 864 + if (acm->wb[i].use) 865 + usb_unlink_urb(acm->wb[i].urb); 866 + spin_unlock_irqrestore(&acm->write_lock, flags); 865 867 } 866 868 867 869 static unsigned int acm_tty_chars_in_buffer(struct tty_struct *tty) ··· 2040 2016 .hangup = acm_tty_hangup, 2041 2017 .write = acm_tty_write, 2042 2018 .write_room = acm_tty_write_room, 2019 + .flush_buffer = acm_tty_flush_buffer, 2043 2020 .ioctl = acm_tty_ioctl, 2044 2021 .throttle = acm_tty_throttle, 2045 2022 .unthrottle = acm_tty_unthrottle,
+1
drivers/usb/common/common.c
··· 11 11 #include <linux/kernel.h> 12 12 #include <linux/module.h> 13 13 #include <linux/of.h> 14 + #include <linux/platform_device.h> 14 15 #include <linux/usb/ch9.h> 15 16 #include <linux/usb/of.h> 16 17 #include <linux/usb/otg.h>
-3
drivers/usb/core/config.c
··· 1051 1051 } 1052 1052 1053 1053 switch (cap_type) { 1054 - case USB_CAP_TYPE_WIRELESS_USB: 1055 - /* Wireless USB cap descriptor is handled by wusb */ 1056 - break; 1057 1054 case USB_CAP_TYPE_EXT: 1058 1055 dev->bos->ext_cap = 1059 1056 (struct usb_ext_cap_descriptor *)buffer;
-1
drivers/usb/core/devices.c
··· 424 424 case USB_SPEED_UNKNOWN: /* usb 1.1 root hub code */ 425 425 case USB_SPEED_FULL: 426 426 speed = "12"; break; 427 - case USB_SPEED_WIRELESS: /* Wireless has no real fixed speed */ 428 427 case USB_SPEED_HIGH: 429 428 speed = "480"; break; 430 429 case USB_SPEED_SUPER:
+7 -61
drivers/usb/core/file.c
··· 29 29 #define MAX_USB_MINORS 256 30 30 static const struct file_operations *usb_minors[MAX_USB_MINORS]; 31 31 static DECLARE_RWSEM(minor_rwsem); 32 - static DEFINE_MUTEX(init_usb_class_mutex); 33 32 34 33 static int usb_open(struct inode *inode, struct file *file) 35 34 { ··· 56 57 .llseek = noop_llseek, 57 58 }; 58 59 59 - static struct usb_class { 60 - struct kref kref; 61 - struct class *class; 62 - } *usb_class; 63 - 64 60 static char *usb_devnode(const struct device *dev, umode_t *mode) 65 61 { 66 62 struct usb_class_driver *drv; ··· 66 72 return drv->devnode(dev, mode); 67 73 } 68 74 69 - static int init_usb_class(void) 70 - { 71 - int result = 0; 72 - 73 - if (usb_class != NULL) { 74 - kref_get(&usb_class->kref); 75 - goto exit; 76 - } 77 - 78 - usb_class = kmalloc(sizeof(*usb_class), GFP_KERNEL); 79 - if (!usb_class) { 80 - result = -ENOMEM; 81 - goto exit; 82 - } 83 - 84 - kref_init(&usb_class->kref); 85 - usb_class->class = class_create("usbmisc"); 86 - if (IS_ERR(usb_class->class)) { 87 - result = PTR_ERR(usb_class->class); 88 - printk(KERN_ERR "class_create failed for usb devices\n"); 89 - kfree(usb_class); 90 - usb_class = NULL; 91 - goto exit; 92 - } 93 - usb_class->class->devnode = usb_devnode; 94 - 95 - exit: 96 - return result; 97 - } 98 - 99 - static void release_usb_class(struct kref *kref) 100 - { 101 - /* Ok, we cheat as we know we only have one usb_class */ 102 - class_destroy(usb_class->class); 103 - kfree(usb_class); 104 - usb_class = NULL; 105 - } 106 - 107 - static void destroy_usb_class(void) 108 - { 109 - mutex_lock(&init_usb_class_mutex); 110 - kref_put(&usb_class->kref, release_usb_class); 111 - mutex_unlock(&init_usb_class_mutex); 112 - } 75 + const struct class usbmisc_class = { 76 + .name = "usbmisc", 77 + .devnode = usb_devnode, 78 + }; 113 79 114 80 int usb_major_init(void) 115 81 { ··· 110 156 int usb_register_dev(struct usb_interface *intf, 111 157 struct usb_class_driver *class_driver) 112 158 { 113 - int retval; 159 + int retval = 0; 114 160 int minor_base = class_driver->minor_base; 115 161 int minor; 116 162 char name[20]; ··· 128 174 return -EINVAL; 129 175 if (intf->minor >= 0) 130 176 return -EADDRINUSE; 131 - 132 - mutex_lock(&init_usb_class_mutex); 133 - retval = init_usb_class(); 134 - mutex_unlock(&init_usb_class_mutex); 135 - 136 - if (retval) 137 - return retval; 138 177 139 178 dev_dbg(&intf->dev, "looking for a minor, starting at %d\n", minor_base); 140 179 ··· 147 200 148 201 /* create a usb class device for this usb interface */ 149 202 snprintf(name, sizeof(name), class_driver->name, minor - minor_base); 150 - intf->usb_dev = device_create(usb_class->class, &intf->dev, 203 + intf->usb_dev = device_create(&usbmisc_class, &intf->dev, 151 204 MKDEV(USB_MAJOR, minor), class_driver, 152 205 "%s", kbasename(name)); 153 206 if (IS_ERR(intf->usb_dev)) { ··· 181 234 return; 182 235 183 236 dev_dbg(&intf->dev, "removing %d minor\n", intf->minor); 184 - device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); 237 + device_destroy(&usbmisc_class, MKDEV(USB_MAJOR, intf->minor)); 185 238 186 239 down_write(&minor_rwsem); 187 240 usb_minors[intf->minor] = NULL; ··· 189 242 190 243 intf->usb_dev = NULL; 191 244 intf->minor = -1; 192 - destroy_usb_class(); 193 245 } 194 246 EXPORT_SYMBOL_GPL(usb_deregister_dev);
+11 -39
drivers/usb/core/hcd.c
··· 156 156 0x01 /* __u8 bNumConfigurations; */ 157 157 }; 158 158 159 - /* usb 2.5 (wireless USB 1.0) root hub device descriptor */ 160 - static const u8 usb25_rh_dev_descriptor[18] = { 161 - 0x12, /* __u8 bLength; */ 162 - USB_DT_DEVICE, /* __u8 bDescriptorType; Device */ 163 - 0x50, 0x02, /* __le16 bcdUSB; v2.5 */ 164 - 165 - 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */ 166 - 0x00, /* __u8 bDeviceSubClass; */ 167 - 0x00, /* __u8 bDeviceProtocol; [ usb 2.0 no TT ] */ 168 - 0xFF, /* __u8 bMaxPacketSize0; always 0xFF (WUSB Spec 7.4.1). */ 169 - 170 - 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation 0x1d6b */ 171 - 0x02, 0x00, /* __le16 idProduct; device 0x0002 */ 172 - KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */ 173 - 174 - 0x03, /* __u8 iManufacturer; */ 175 - 0x02, /* __u8 iProduct; */ 176 - 0x01, /* __u8 iSerialNumber; */ 177 - 0x01 /* __u8 bNumConfigurations; */ 178 - }; 179 - 180 159 /* usb 2.0 root hub device descriptor */ 181 160 static const u8 usb2_rh_dev_descriptor[18] = { 182 161 0x12, /* __u8 bLength; */ ··· 347 368 }; 348 369 349 370 /* authorized_default behaviour: 350 - * -1 is authorized for all devices except wireless (old behaviour) 371 + * -1 is authorized for all devices (leftover from wireless USB) 351 372 * 0 is unauthorized for all devices 352 373 * 1 is authorized for all devices 353 374 * 2 is authorized for internal devices ··· 362 383 MODULE_PARM_DESC(authorized_default, 363 384 "Default USB device authorization: 0 is not authorized, 1 is " 364 385 "authorized, 2 is authorized for internal devices, -1 is " 365 - "authorized except for wireless USB (default, old behaviour)"); 386 + "authorized (default, same as 1)"); 366 387 /*-------------------------------------------------------------------------*/ 367 388 368 389 /** ··· 557 578 case HCD_USB3: 558 579 bufp = usb3_rh_dev_descriptor; 559 580 break; 560 - case HCD_USB25: 561 - bufp = usb25_rh_dev_descriptor; 562 - break; 563 581 case HCD_USB2: 564 582 bufp = usb2_rh_dev_descriptor; 565 583 break; ··· 578 602 bufp = ss_rh_config_descriptor; 579 603 len = sizeof ss_rh_config_descriptor; 580 604 break; 581 - case HCD_USB25: 582 605 case HCD_USB2: 583 606 bufp = hs_rh_config_descriptor; 584 607 len = sizeof hs_rh_config_descriptor; ··· 958 983 { 959 984 struct device *parent_dev = hcd->self.controller; 960 985 struct usb_device *usb_dev = hcd->self.root_hub; 986 + struct usb_device_descriptor *descr; 961 987 const int devnum = 1; 962 988 int retval; 963 989 ··· 970 994 mutex_lock(&usb_bus_idr_lock); 971 995 972 996 usb_dev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); 973 - retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE); 974 - if (retval != sizeof usb_dev->descriptor) { 997 + descr = usb_get_device_descriptor(usb_dev); 998 + if (IS_ERR(descr)) { 999 + retval = PTR_ERR(descr); 975 1000 mutex_unlock(&usb_bus_idr_lock); 976 1001 dev_dbg (parent_dev, "can't read %s device descriptor %d\n", 977 1002 dev_name(&usb_dev->dev), retval); 978 - return (retval < 0) ? retval : -EMSGSIZE; 1003 + return retval; 979 1004 } 1005 + usb_dev->descriptor = *descr; 1006 + kfree(descr); 980 1007 981 1008 if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) { 982 1009 retval = usb_get_bos_descriptor(usb_dev); ··· 2823 2844 hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE; 2824 2845 break; 2825 2846 2826 - case USB_AUTHORIZE_ALL: 2827 - hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL; 2828 - break; 2829 - 2830 2847 case USB_AUTHORIZE_INTERNAL: 2831 2848 hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL; 2832 2849 break; 2833 2850 2851 + case USB_AUTHORIZE_ALL: 2834 2852 case USB_AUTHORIZE_WIRED: 2835 2853 default: 2836 - hcd->dev_policy = hcd->wireless ? 2837 - USB_DEVICE_AUTHORIZE_NONE : USB_DEVICE_AUTHORIZE_ALL; 2854 + hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL; 2838 2855 break; 2839 2856 } 2840 2857 ··· 2873 2898 break; 2874 2899 case HCD_USB2: 2875 2900 rhdev->speed = USB_SPEED_HIGH; 2876 - break; 2877 - case HCD_USB25: 2878 - rhdev->speed = USB_SPEED_WIRELESS; 2879 2901 break; 2880 2902 case HCD_USB3: 2881 2903 rhdev->speed = USB_SPEED_SUPER;
+263 -250
drivers/usb/core/hub.c
··· 614 614 ret = 0; 615 615 } 616 616 mutex_unlock(&hub->status_mutex); 617 + 618 + /* 619 + * There is no need to lock status_mutex here, because status_mutex 620 + * protects hub->status, and the phy driver only checks the port 621 + * status without changing the status. 622 + */ 623 + if (!ret) { 624 + struct usb_device *hdev = hub->hdev; 625 + 626 + /* 627 + * Only roothub will be notified of port state changes, 628 + * since the USB PHY only cares about changes at the next 629 + * level. 630 + */ 631 + if (is_root_hub(hdev)) { 632 + struct usb_hcd *hcd = bus_to_hcd(hdev->bus); 633 + 634 + if (hcd->usb_phy) 635 + usb_phy_notify_port_status(hcd->usb_phy, 636 + port1 - 1, *status, *change); 637 + } 638 + } 639 + 617 640 return ret; 618 641 } 619 642 ··· 2140 2117 * USB-3.0 buses the address is assigned by the controller hardware 2141 2118 * and it usually is not the same as the device number. 2142 2119 * 2143 - * WUSB devices are simple: they have no hubs behind, so the mapping 2144 - * device <-> virtual port number becomes 1:1. Why? to simplify the 2145 - * life of the device connection logic in 2146 - * drivers/usb/wusbcore/devconnect.c. When we do the initial secret 2147 - * handshake we need to assign a temporary address in the unauthorized 2148 - * space. For simplicity we use the first virtual port number found to 2149 - * be free [drivers/usb/wusbcore/devconnect.c:wusbhc_devconnect_ack()] 2150 - * and that becomes it's address [X < 128] or its unauthorized address 2151 - * [X | 0x80]. 2152 - * 2153 - * We add 1 as an offset to the one-based USB-stack port number 2154 - * (zero-based wusb virtual port index) for two reasons: (a) dev addr 2155 - * 0 is reserved by USB for default address; (b) Linux's USB stack 2156 - * uses always #1 for the root hub of the controller. So USB stack's 2157 - * port #1, which is wusb virtual-port #0 has address #2. 2158 - * 2159 2120 * Devices connected under xHCI are not as simple. The host controller 2160 2121 * supports virtualization, so the hardware assigns device addresses and 2161 2122 * the HCD must setup data structures before issuing a set address ··· 2152 2145 2153 2146 /* be safe when more hub events are proceed in parallel */ 2154 2147 mutex_lock(&bus->devnum_next_mutex); 2155 - if (udev->wusb) { 2156 - devnum = udev->portnum + 1; 2157 - BUG_ON(test_bit(devnum, bus->devmap.devicemap)); 2158 - } else { 2159 - /* Try to allocate the next devnum beginning at 2160 - * bus->devnum_next. */ 2161 - devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 2162 - bus->devnum_next); 2163 - if (devnum >= 128) 2164 - devnum = find_next_zero_bit(bus->devmap.devicemap, 2165 - 128, 1); 2166 - bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); 2167 - } 2148 + 2149 + /* Try to allocate the next devnum beginning at bus->devnum_next. */ 2150 + devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 2151 + bus->devnum_next); 2152 + if (devnum >= 128) 2153 + devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 1); 2154 + bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); 2168 2155 if (devnum < 128) { 2169 2156 set_bit(devnum, bus->devmap.devicemap); 2170 2157 udev->devnum = devnum; ··· 2176 2175 2177 2176 static void update_devnum(struct usb_device *udev, int devnum) 2178 2177 { 2179 - /* The address for a WUSB device is managed by wusbcore. */ 2180 - if (!udev->wusb) 2181 - udev->devnum = devnum; 2178 + udev->devnum = devnum; 2182 2179 if (!udev->devaddr) 2183 2180 udev->devaddr = (u8)devnum; 2184 2181 } ··· 2669 2670 goto error_autoresume; 2670 2671 } 2671 2672 2672 - if (usb_dev->wusb) { 2673 - result = usb_get_device_descriptor(usb_dev, sizeof(usb_dev->descriptor)); 2674 - if (result < 0) { 2675 - dev_err(&usb_dev->dev, "can't re-read device descriptor for " 2676 - "authorization: %d\n", result); 2677 - goto error_device_descriptor; 2678 - } 2679 - } 2680 - 2681 2673 usb_dev->authorized = 1; 2682 2674 /* Choose and set the configuration. This registers the interfaces 2683 2675 * with the driver core and lets interface drivers bind to them. ··· 2685 2695 } 2686 2696 dev_info(&usb_dev->dev, "authorized to connect\n"); 2687 2697 2688 - error_device_descriptor: 2689 2698 usb_autosuspend_device(usb_dev); 2690 2699 error_autoresume: 2691 2700 out_authorized: ··· 2766 2777 out: 2767 2778 return USB_SSP_GEN_UNKNOWN; 2768 2779 } 2769 - 2770 - /* Returns 1 if @hub is a WUSB root hub, 0 otherwise */ 2771 - static unsigned hub_is_wusb(struct usb_hub *hub) 2772 - { 2773 - struct usb_hcd *hcd; 2774 - if (hub->hdev->parent != NULL) /* not a root hub? */ 2775 - return 0; 2776 - hcd = bus_to_hcd(hub->hdev->bus); 2777 - return hcd->wireless; 2778 - } 2779 - 2780 2780 2781 2781 #ifdef CONFIG_USB_FEW_INIT_RETRIES 2782 2782 #define PORT_RESET_TRIES 2 ··· 2919 2941 udev->tx_lanes = 1; 2920 2942 udev->ssp_rate = USB_SSP_GEN_UNKNOWN; 2921 2943 } 2922 - if (hub_is_wusb(hub)) 2923 - udev->speed = USB_SPEED_WIRELESS; 2924 - else if (udev->ssp_rate != USB_SSP_GEN_UNKNOWN) 2944 + if (udev->ssp_rate != USB_SSP_GEN_UNKNOWN) 2925 2945 udev->speed = USB_SPEED_SUPER_PLUS; 2926 2946 else if (hub_is_superspeed(hub->hdev)) 2927 2947 udev->speed = USB_SPEED_SUPER; ··· 4694 4718 return hcd->driver->enable_device(hcd, udev); 4695 4719 } 4696 4720 4721 + /* 4722 + * Get the bMaxPacketSize0 value during initialization by reading the 4723 + * device's device descriptor. Since we don't already know this value, 4724 + * the transfer is unsafe and it ignores I/O errors, only testing for 4725 + * reasonable received values. 4726 + * 4727 + * For "old scheme" initialization, size will be 8 so we read just the 4728 + * start of the device descriptor, which should work okay regardless of 4729 + * the actual bMaxPacketSize0 value. For "new scheme" initialization, 4730 + * size will be 64 (and buf will point to a sufficiently large buffer), 4731 + * which might not be kosher according to the USB spec but it's what 4732 + * Windows does and what many devices expect. 4733 + * 4734 + * Returns: bMaxPacketSize0 or a negative error code. 4735 + */ 4736 + static int get_bMaxPacketSize0(struct usb_device *udev, 4737 + struct usb_device_descriptor *buf, int size, bool first_time) 4738 + { 4739 + int i, rc; 4740 + 4741 + /* 4742 + * Retry on all errors; some devices are flakey. 4743 + * 255 is for WUSB devices, we actually need to use 4744 + * 512 (WUSB1.0[4.8.1]). 4745 + */ 4746 + for (i = 0; i < GET_MAXPACKET0_TRIES; ++i) { 4747 + /* Start with invalid values in case the transfer fails */ 4748 + buf->bDescriptorType = buf->bMaxPacketSize0 = 0; 4749 + rc = usb_control_msg(udev, usb_rcvaddr0pipe(), 4750 + USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, 4751 + USB_DT_DEVICE << 8, 0, 4752 + buf, size, 4753 + initial_descriptor_timeout); 4754 + switch (buf->bMaxPacketSize0) { 4755 + case 8: case 16: case 32: case 64: case 9: 4756 + if (buf->bDescriptorType == USB_DT_DEVICE) { 4757 + rc = buf->bMaxPacketSize0; 4758 + break; 4759 + } 4760 + fallthrough; 4761 + default: 4762 + if (rc >= 0) 4763 + rc = -EPROTO; 4764 + break; 4765 + } 4766 + 4767 + /* 4768 + * Some devices time out if they are powered on 4769 + * when already connected. They need a second 4770 + * reset, so return early. But only on the first 4771 + * attempt, lest we get into a time-out/reset loop. 4772 + */ 4773 + if (rc > 0 || (rc == -ETIMEDOUT && first_time && 4774 + udev->speed > USB_SPEED_FULL)) 4775 + break; 4776 + } 4777 + return rc; 4778 + } 4779 + 4780 + #define GET_DESCRIPTOR_BUFSIZE 64 4781 + 4697 4782 /* Reset device, (re)assign address, get device descriptor. 4698 4783 * Device connection must be stable, no more debouncing needed. 4699 4784 * Returns device in USB_STATE_ADDRESS, except on error. ··· 4764 4727 * the port lock. For a newly detected device that is not accessible 4765 4728 * through any global pointers, it's not necessary to lock the device, 4766 4729 * but it is still necessary to lock the port. 4730 + * 4731 + * For a newly detected device, @dev_descr must be NULL. The device 4732 + * descriptor retrieved from the device will then be stored in 4733 + * @udev->descriptor. For an already existing device, @dev_descr 4734 + * must be non-NULL. The device descriptor will be stored there, 4735 + * not in @udev->descriptor, because descriptors for registered 4736 + * devices are meant to be immutable. 4767 4737 */ 4768 4738 static int 4769 4739 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, 4770 - int retry_counter) 4740 + int retry_counter, struct usb_device_descriptor *dev_descr) 4771 4741 { 4772 4742 struct usb_device *hdev = hub->hdev; 4773 4743 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); ··· 4786 4742 int devnum = udev->devnum; 4787 4743 const char *driver_name; 4788 4744 bool do_new_scheme; 4745 + const bool initial = !dev_descr; 4746 + int maxp0; 4747 + struct usb_device_descriptor *buf, *descr; 4748 + 4749 + buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO); 4750 + if (!buf) 4751 + return -ENOMEM; 4789 4752 4790 4753 /* root hub ports have a slightly longer reset period 4791 4754 * (from USB 2.0 spec, section 7.1.7.5) ··· 4825 4774 } 4826 4775 oldspeed = udev->speed; 4827 4776 4828 - /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ... 4829 - * it's fixed size except for full speed devices. 4830 - * For Wireless USB devices, ep0 max packet is always 512 (tho 4831 - * reported as 0xff in the device descriptor). WUSB1.0[4.8.1]. 4832 - */ 4833 - switch (udev->speed) { 4834 - case USB_SPEED_SUPER_PLUS: 4835 - case USB_SPEED_SUPER: 4836 - case USB_SPEED_WIRELESS: /* fixed at 512 */ 4837 - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); 4838 - break; 4839 - case USB_SPEED_HIGH: /* fixed at 64 */ 4840 - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); 4841 - break; 4842 - case USB_SPEED_FULL: /* 8, 16, 32, or 64 */ 4843 - /* to determine the ep0 maxpacket size, try to read 4844 - * the device descriptor to get bMaxPacketSize0 and 4845 - * then correct our initial guess. 4777 + if (initial) { 4778 + /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ... 4779 + * it's fixed size except for full speed devices. 4846 4780 */ 4847 - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); 4848 - break; 4849 - case USB_SPEED_LOW: /* fixed at 8 */ 4850 - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); 4851 - break; 4852 - default: 4853 - goto fail; 4781 + switch (udev->speed) { 4782 + case USB_SPEED_SUPER_PLUS: 4783 + case USB_SPEED_SUPER: 4784 + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); 4785 + break; 4786 + case USB_SPEED_HIGH: /* fixed at 64 */ 4787 + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); 4788 + break; 4789 + case USB_SPEED_FULL: /* 8, 16, 32, or 64 */ 4790 + /* to determine the ep0 maxpacket size, try to read 4791 + * the device descriptor to get bMaxPacketSize0 and 4792 + * then correct our initial guess. 4793 + */ 4794 + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); 4795 + break; 4796 + case USB_SPEED_LOW: /* fixed at 8 */ 4797 + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); 4798 + break; 4799 + default: 4800 + goto fail; 4801 + } 4854 4802 } 4855 4803 4856 - if (udev->speed == USB_SPEED_WIRELESS) 4857 - speed = "variable speed Wireless"; 4858 - else 4859 - speed = usb_speed_string(udev->speed); 4804 + speed = usb_speed_string(udev->speed); 4860 4805 4861 4806 /* 4862 4807 * The controller driver may be NULL if the controller device ··· 4869 4822 if (udev->speed < USB_SPEED_SUPER) 4870 4823 dev_info(&udev->dev, 4871 4824 "%s %s USB device number %d using %s\n", 4872 - (udev->config) ? "reset" : "new", speed, 4825 + (initial ? "new" : "reset"), speed, 4873 4826 devnum, driver_name); 4874 4827 4875 - /* Set up TT records, if needed */ 4876 - if (hdev->tt) { 4877 - udev->tt = hdev->tt; 4878 - udev->ttport = hdev->ttport; 4879 - } else if (udev->speed != USB_SPEED_HIGH 4880 - && hdev->speed == USB_SPEED_HIGH) { 4881 - if (!hub->tt.hub) { 4882 - dev_err(&udev->dev, "parent hub has no TT\n"); 4883 - retval = -EINVAL; 4884 - goto fail; 4828 + if (initial) { 4829 + /* Set up TT records, if needed */ 4830 + if (hdev->tt) { 4831 + udev->tt = hdev->tt; 4832 + udev->ttport = hdev->ttport; 4833 + } else if (udev->speed != USB_SPEED_HIGH 4834 + && hdev->speed == USB_SPEED_HIGH) { 4835 + if (!hub->tt.hub) { 4836 + dev_err(&udev->dev, "parent hub has no TT\n"); 4837 + retval = -EINVAL; 4838 + goto fail; 4839 + } 4840 + udev->tt = &hub->tt; 4841 + udev->ttport = port1; 4885 4842 } 4886 - udev->tt = &hub->tt; 4887 - udev->ttport = port1; 4888 4843 } 4889 4844 4890 4845 /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way? ··· 4910 4861 } 4911 4862 4912 4863 if (do_new_scheme) { 4913 - struct usb_device_descriptor *buf; 4914 - int r = 0; 4915 - 4916 4864 retval = hub_enable_device(udev); 4917 4865 if (retval < 0) { 4918 4866 dev_err(&udev->dev, ··· 4918 4872 goto fail; 4919 4873 } 4920 4874 4921 - #define GET_DESCRIPTOR_BUFSIZE 64 4922 - buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO); 4923 - if (!buf) { 4924 - retval = -ENOMEM; 4925 - continue; 4875 + maxp0 = get_bMaxPacketSize0(udev, buf, 4876 + GET_DESCRIPTOR_BUFSIZE, retries == 0); 4877 + if (maxp0 > 0 && !initial && 4878 + maxp0 != udev->descriptor.bMaxPacketSize0) { 4879 + dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); 4880 + retval = -ENODEV; 4881 + goto fail; 4926 4882 } 4927 - 4928 - /* Retry on all errors; some devices are flakey. 4929 - * 255 is for WUSB devices, we actually need to use 4930 - * 512 (WUSB1.0[4.8.1]). 4931 - */ 4932 - for (operations = 0; operations < GET_MAXPACKET0_TRIES; 4933 - ++operations) { 4934 - buf->bMaxPacketSize0 = 0; 4935 - r = usb_control_msg(udev, usb_rcvaddr0pipe(), 4936 - USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, 4937 - USB_DT_DEVICE << 8, 0, 4938 - buf, GET_DESCRIPTOR_BUFSIZE, 4939 - initial_descriptor_timeout); 4940 - switch (buf->bMaxPacketSize0) { 4941 - case 8: case 16: case 32: case 64: case 255: 4942 - if (buf->bDescriptorType == 4943 - USB_DT_DEVICE) { 4944 - r = 0; 4945 - break; 4946 - } 4947 - fallthrough; 4948 - default: 4949 - if (r == 0) 4950 - r = -EPROTO; 4951 - break; 4952 - } 4953 - /* 4954 - * Some devices time out if they are powered on 4955 - * when already connected. They need a second 4956 - * reset. But only on the first attempt, 4957 - * lest we get into a time out/reset loop 4958 - */ 4959 - if (r == 0 || (r == -ETIMEDOUT && 4960 - retries == 0 && 4961 - udev->speed > USB_SPEED_FULL)) 4962 - break; 4963 - } 4964 - udev->descriptor.bMaxPacketSize0 = 4965 - buf->bMaxPacketSize0; 4966 - kfree(buf); 4967 4883 4968 4884 retval = hub_port_reset(hub, port1, udev, delay, false); 4969 4885 if (retval < 0) /* error or disconnect */ ··· 4936 4928 retval = -ENODEV; 4937 4929 goto fail; 4938 4930 } 4939 - if (r) { 4940 - if (r != -ENODEV) 4931 + if (maxp0 < 0) { 4932 + if (maxp0 != -ENODEV) 4941 4933 dev_err(&udev->dev, "device descriptor read/64, error %d\n", 4942 - r); 4943 - retval = -EMSGSIZE; 4934 + maxp0); 4935 + retval = maxp0; 4944 4936 continue; 4945 4937 } 4946 - #undef GET_DESCRIPTOR_BUFSIZE 4938 + } 4939 + 4940 + for (operations = 0; operations < SET_ADDRESS_TRIES; ++operations) { 4941 + retval = hub_set_address(udev, devnum); 4942 + if (retval >= 0) 4943 + break; 4944 + msleep(200); 4945 + } 4946 + if (retval < 0) { 4947 + if (retval != -ENODEV) 4948 + dev_err(&udev->dev, "device not accepting address %d, error %d\n", 4949 + devnum, retval); 4950 + goto fail; 4951 + } 4952 + if (udev->speed >= USB_SPEED_SUPER) { 4953 + devnum = udev->devnum; 4954 + dev_info(&udev->dev, 4955 + "%s SuperSpeed%s%s USB device number %d using %s\n", 4956 + (udev->config) ? "reset" : "new", 4957 + (udev->speed == USB_SPEED_SUPER_PLUS) ? 4958 + " Plus" : "", 4959 + (udev->ssp_rate == USB_SSP_GEN_2x2) ? 4960 + " Gen 2x2" : 4961 + (udev->ssp_rate == USB_SSP_GEN_2x1) ? 4962 + " Gen 2x1" : 4963 + (udev->ssp_rate == USB_SSP_GEN_1x2) ? 4964 + " Gen 1x2" : "", 4965 + devnum, driver_name); 4947 4966 } 4948 4967 4949 4968 /* 4950 - * If device is WUSB, we already assigned an 4951 - * unauthorized address in the Connect Ack sequence; 4952 - * authorization will assign the final address. 4969 + * cope with hardware quirkiness: 4970 + * - let SET_ADDRESS settle, some device hardware wants it 4971 + * - read ep0 maxpacket even for high and low speed, 4953 4972 */ 4954 - if (udev->wusb == 0) { 4955 - for (operations = 0; operations < SET_ADDRESS_TRIES; ++operations) { 4956 - retval = hub_set_address(udev, devnum); 4957 - if (retval >= 0) 4958 - break; 4959 - msleep(200); 4960 - } 4961 - if (retval < 0) { 4962 - if (retval != -ENODEV) 4963 - dev_err(&udev->dev, "device not accepting address %d, error %d\n", 4964 - devnum, retval); 4965 - goto fail; 4966 - } 4967 - if (udev->speed >= USB_SPEED_SUPER) { 4968 - devnum = udev->devnum; 4969 - dev_info(&udev->dev, 4970 - "%s SuperSpeed%s%s USB device number %d using %s\n", 4971 - (udev->config) ? "reset" : "new", 4972 - (udev->speed == USB_SPEED_SUPER_PLUS) ? 4973 - " Plus" : "", 4974 - (udev->ssp_rate == USB_SSP_GEN_2x2) ? 4975 - " Gen 2x2" : 4976 - (udev->ssp_rate == USB_SSP_GEN_2x1) ? 4977 - " Gen 2x1" : 4978 - (udev->ssp_rate == USB_SSP_GEN_1x2) ? 4979 - " Gen 1x2" : "", 4980 - devnum, driver_name); 4981 - } 4973 + msleep(10); 4982 4974 4983 - /* cope with hardware quirkiness: 4984 - * - let SET_ADDRESS settle, some device hardware wants it 4985 - * - read ep0 maxpacket even for high and low speed, 4986 - */ 4987 - msleep(10); 4988 - if (do_new_scheme) 4989 - break; 4990 - } 4975 + if (do_new_scheme) 4976 + break; 4991 4977 4992 - retval = usb_get_device_descriptor(udev, 8); 4993 - if (retval < 8) { 4978 + maxp0 = get_bMaxPacketSize0(udev, buf, 8, retries == 0); 4979 + if (maxp0 < 0) { 4980 + retval = maxp0; 4994 4981 if (retval != -ENODEV) 4995 4982 dev_err(&udev->dev, 4996 4983 "device descriptor read/8, error %d\n", 4997 4984 retval); 4998 - if (retval >= 0) 4999 - retval = -EMSGSIZE; 5000 4985 } else { 5001 4986 u32 delay; 5002 4987 5003 - retval = 0; 4988 + if (!initial && maxp0 != udev->descriptor.bMaxPacketSize0) { 4989 + dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); 4990 + retval = -ENODEV; 4991 + goto fail; 4992 + } 5004 4993 5005 4994 delay = udev->parent->hub_delay; 5006 4995 udev->hub_delay = min_t(u32, delay, ··· 5016 5011 goto fail; 5017 5012 5018 5013 /* 5014 + * Check the ep0 maxpacket guess and correct it if necessary. 5015 + * maxp0 is the value stored in the device descriptor; 5016 + * i is the value it encodes (logarithmic for SuperSpeed or greater). 5017 + */ 5018 + i = maxp0; 5019 + if (udev->speed >= USB_SPEED_SUPER) { 5020 + if (maxp0 <= 16) 5021 + i = 1 << maxp0; 5022 + else 5023 + i = 0; /* Invalid */ 5024 + } 5025 + if (usb_endpoint_maxp(&udev->ep0.desc) == i) { 5026 + ; /* Initial ep0 maxpacket guess is right */ 5027 + } else if ((udev->speed == USB_SPEED_FULL || 5028 + udev->speed == USB_SPEED_HIGH) && 5029 + (i == 8 || i == 16 || i == 32 || i == 64)) { 5030 + /* Initial guess is wrong; use the descriptor's value */ 5031 + if (udev->speed == USB_SPEED_FULL) 5032 + dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); 5033 + else 5034 + dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); 5035 + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); 5036 + usb_ep0_reinit(udev); 5037 + } else { 5038 + /* Initial guess is wrong and descriptor's value is invalid */ 5039 + dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", maxp0); 5040 + retval = -EMSGSIZE; 5041 + goto fail; 5042 + } 5043 + 5044 + descr = usb_get_device_descriptor(udev); 5045 + if (IS_ERR(descr)) { 5046 + retval = PTR_ERR(descr); 5047 + if (retval != -ENODEV) 5048 + dev_err(&udev->dev, "device descriptor read/all, error %d\n", 5049 + retval); 5050 + goto fail; 5051 + } 5052 + if (initial) 5053 + udev->descriptor = *descr; 5054 + else 5055 + *dev_descr = *descr; 5056 + kfree(descr); 5057 + 5058 + /* 5019 5059 * Some superspeed devices have finished the link training process 5020 5060 * and attached to a superspeed hub port, but the device descriptor 5021 5061 * got from those devices show they aren't superspeed devices. Warm ··· 5068 5018 */ 5069 5019 if ((udev->speed >= USB_SPEED_SUPER) && 5070 5020 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { 5071 - dev_err(&udev->dev, "got a wrong device descriptor, " 5072 - "warm reset device\n"); 5073 - hub_port_reset(hub, port1, udev, 5074 - HUB_BH_RESET_TIME, true); 5021 + dev_err(&udev->dev, "got a wrong device descriptor, warm reset device\n"); 5022 + hub_port_reset(hub, port1, udev, HUB_BH_RESET_TIME, true); 5075 5023 retval = -EINVAL; 5076 - goto fail; 5077 - } 5078 - 5079 - if (udev->descriptor.bMaxPacketSize0 == 0xff || 5080 - udev->speed >= USB_SPEED_SUPER) 5081 - i = 512; 5082 - else 5083 - i = udev->descriptor.bMaxPacketSize0; 5084 - if (usb_endpoint_maxp(&udev->ep0.desc) != i) { 5085 - if (udev->speed == USB_SPEED_LOW || 5086 - !(i == 8 || i == 16 || i == 32 || i == 64)) { 5087 - dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i); 5088 - retval = -EMSGSIZE; 5089 - goto fail; 5090 - } 5091 - if (udev->speed == USB_SPEED_FULL) 5092 - dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); 5093 - else 5094 - dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); 5095 - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); 5096 - usb_ep0_reinit(udev); 5097 - } 5098 - 5099 - retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); 5100 - if (retval < (signed)sizeof(udev->descriptor)) { 5101 - if (retval != -ENODEV) 5102 - dev_err(&udev->dev, "device descriptor read/all, error %d\n", 5103 - retval); 5104 - if (retval >= 0) 5105 - retval = -ENOMSG; 5106 5024 goto fail; 5107 5025 } 5108 5026 5109 5027 usb_detect_quirks(udev); 5110 5028 5111 - if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { 5029 + if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { 5112 5030 retval = usb_get_bos_descriptor(udev); 5113 5031 if (!retval) { 5114 5032 udev->lpm_capable = usb_device_supports_lpm(udev); ··· 5096 5078 hub_port_disable(hub, port1, 0); 5097 5079 update_devnum(udev, devnum); /* for disconnect processing */ 5098 5080 } 5081 + kfree(buf); 5099 5082 return retval; 5100 5083 } 5101 5084 ··· 5177 5158 5178 5159 5179 5160 static int descriptors_changed(struct usb_device *udev, 5180 - struct usb_device_descriptor *old_device_descriptor, 5161 + struct usb_device_descriptor *new_device_descriptor, 5181 5162 struct usb_host_bos *old_bos) 5182 5163 { 5183 5164 int changed = 0; ··· 5188 5169 int length; 5189 5170 char *buf; 5190 5171 5191 - if (memcmp(&udev->descriptor, old_device_descriptor, 5192 - sizeof(*old_device_descriptor)) != 0) 5172 + if (memcmp(&udev->descriptor, new_device_descriptor, 5173 + sizeof(*new_device_descriptor)) != 0) 5193 5174 return 1; 5194 5175 5195 5176 if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) ··· 5352 5333 usb_set_device_state(udev, USB_STATE_POWERED); 5353 5334 udev->bus_mA = hub->mA_per_port; 5354 5335 udev->level = hdev->level + 1; 5355 - udev->wusb = hub_is_wusb(hub); 5356 5336 5357 5337 /* Devices connected to SuperSpeed hubs are USB 3.0 or later */ 5358 5338 if (hub_is_superspeed(hub->hdev)) ··· 5366 5348 } 5367 5349 5368 5350 /* reset (non-USB 3.0 devices) and get descriptor */ 5369 - status = hub_port_init(hub, udev, port1, i); 5351 + status = hub_port_init(hub, udev, port1, i, NULL); 5370 5352 if (status < 0) 5371 5353 goto loop; 5372 5354 ··· 5513 5495 { 5514 5496 struct usb_port *port_dev = hub->ports[port1 - 1]; 5515 5497 struct usb_device *udev = port_dev->child; 5516 - struct usb_device_descriptor descriptor; 5498 + struct usb_device_descriptor *descr; 5517 5499 int status = -ENODEV; 5518 - int retval; 5519 5500 5520 5501 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, 5521 5502 portchange, portspeed(hub, portstatus)); ··· 5541 5524 * changed device descriptors before resuscitating the 5542 5525 * device. 5543 5526 */ 5544 - descriptor = udev->descriptor; 5545 - retval = usb_get_device_descriptor(udev, 5546 - sizeof(udev->descriptor)); 5547 - if (retval < 0) { 5527 + descr = usb_get_device_descriptor(udev); 5528 + if (IS_ERR(descr)) { 5548 5529 dev_dbg(&udev->dev, 5549 - "can't read device descriptor %d\n", 5550 - retval); 5530 + "can't read device descriptor %ld\n", 5531 + PTR_ERR(descr)); 5551 5532 } else { 5552 - if (descriptors_changed(udev, &descriptor, 5533 + if (descriptors_changed(udev, descr, 5553 5534 udev->bos)) { 5554 5535 dev_dbg(&udev->dev, 5555 5536 "device descriptor has changed\n"); 5556 - /* for disconnect() calls */ 5557 - udev->descriptor = descriptor; 5558 5537 } else { 5559 5538 status = 0; /* Nothing to do */ 5560 5539 } 5540 + kfree(descr); 5561 5541 } 5562 5542 #ifdef CONFIG_PM 5563 5543 } else if (udev->state == USB_STATE_SUSPENDED && ··· 5996 5982 struct usb_device *parent_hdev = udev->parent; 5997 5983 struct usb_hub *parent_hub; 5998 5984 struct usb_hcd *hcd = bus_to_hcd(udev->bus); 5999 - struct usb_device_descriptor descriptor = udev->descriptor; 5985 + struct usb_device_descriptor descriptor; 6000 5986 struct usb_host_bos *bos; 6001 5987 int i, j, ret = 0; 6002 5988 int port1 = udev->portnum; ··· 6032 6018 /* ep0 maxpacket size may change; let the HCD know about it. 6033 6019 * Other endpoints will be handled by re-enumeration. */ 6034 6020 usb_ep0_reinit(udev); 6035 - ret = hub_port_init(parent_hub, udev, port1, i); 6021 + ret = hub_port_init(parent_hub, udev, port1, i, &descriptor); 6036 6022 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) 6037 6023 break; 6038 6024 } ··· 6044 6030 /* Device might have changed firmware (DFU or similar) */ 6045 6031 if (descriptors_changed(udev, &descriptor, bos)) { 6046 6032 dev_info(&udev->dev, "device firmware changed\n"); 6047 - udev->descriptor = descriptor; /* for disconnect() calls */ 6048 6033 goto re_enumerate; 6049 6034 } 6050 6035
+1 -12
drivers/usb/core/ledtrig-usbport.c
··· 350 350 .deactivate = usbport_trig_deactivate, 351 351 }; 352 352 353 - static int __init usbport_trig_init(void) 354 - { 355 - return led_trigger_register(&usbport_led_trigger); 356 - } 357 - 358 - static void __exit usbport_trig_exit(void) 359 - { 360 - led_trigger_unregister(&usbport_led_trigger); 361 - } 362 - 363 - module_init(usbport_trig_init); 364 - module_exit(usbport_trig_exit); 353 + module_led_trigger(usbport_led_trigger); 365 354 366 355 MODULE_AUTHOR("Rafał Miłecki <rafal@milecki.pl>"); 367 356 MODULE_DESCRIPTION("USB port trigger");
+13 -17
drivers/usb/core/message.c
··· 9 9 #include <linux/pci.h> /* for scatterlist macros */ 10 10 #include <linux/usb.h> 11 11 #include <linux/module.h> 12 + #include <linux/of.h> 12 13 #include <linux/slab.h> 13 14 #include <linux/mm.h> 14 15 #include <linux/timer.h> ··· 1041 1040 EXPORT_SYMBOL_GPL(usb_cache_string); 1042 1041 1043 1042 /* 1044 - * usb_get_device_descriptor - (re)reads the device descriptor (usbcore) 1045 - * @dev: the device whose device descriptor is being updated 1046 - * @size: how much of the descriptor to read 1043 + * usb_get_device_descriptor - read the device descriptor 1044 + * @udev: the device whose device descriptor should be read 1047 1045 * 1048 1046 * Context: task context, might sleep. 1049 - * 1050 - * Updates the copy of the device descriptor stored in the device structure, 1051 - * which dedicates space for this purpose. 1052 1047 * 1053 1048 * Not exported, only for use by the core. If drivers really want to read 1054 1049 * the device descriptor directly, they can call usb_get_descriptor() with 1055 1050 * type = USB_DT_DEVICE and index = 0. 1056 1051 * 1057 - * This call is synchronous, and may not be used in an interrupt context. 1058 - * 1059 - * Return: The number of bytes received on success, or else the status code 1060 - * returned by the underlying usb_control_msg() call. 1052 + * Returns: a pointer to a dynamically allocated usb_device_descriptor 1053 + * structure (which the caller must deallocate), or an ERR_PTR value. 1061 1054 */ 1062 - int usb_get_device_descriptor(struct usb_device *dev, unsigned int size) 1055 + struct usb_device_descriptor *usb_get_device_descriptor(struct usb_device *udev) 1063 1056 { 1064 1057 struct usb_device_descriptor *desc; 1065 1058 int ret; 1066 1059 1067 - if (size > sizeof(*desc)) 1068 - return -EINVAL; 1069 1060 desc = kmalloc(sizeof(*desc), GFP_NOIO); 1070 1061 if (!desc) 1071 - return -ENOMEM; 1062 + return ERR_PTR(-ENOMEM); 1072 1063 1073 - ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size); 1064 + ret = usb_get_descriptor(udev, USB_DT_DEVICE, 0, desc, sizeof(*desc)); 1065 + if (ret == sizeof(*desc)) 1066 + return desc; 1067 + 1074 1068 if (ret >= 0) 1075 - memcpy(&dev->descriptor, desc, size); 1069 + ret = -EMSGSIZE; 1076 1070 kfree(desc); 1077 - return ret; 1071 + return ERR_PTR(ret); 1078 1072 } 1079 1073 1080 1074 /*
-1
drivers/usb/core/of.c
··· 8 8 */ 9 9 10 10 #include <linux/of.h> 11 - #include <linux/of_platform.h> 12 11 #include <linux/usb/of.h> 13 12 14 13 /**
-3
drivers/usb/core/sysfs.c
··· 161 161 case USB_SPEED_HIGH: 162 162 speed = "480"; 163 163 break; 164 - case USB_SPEED_WIRELESS: 165 - speed = "480"; 166 - break; 167 164 case USB_SPEED_SUPER: 168 165 speed = "5000"; 169 166 break;
+6 -21
drivers/usb/core/urb.c
··· 480 480 urb->iso_frame_desc[n].status = -EXDEV; 481 481 urb->iso_frame_desc[n].actual_length = 0; 482 482 } 483 - } else if (urb->num_sgs && !urb->dev->bus->no_sg_constraint && 484 - dev->speed != USB_SPEED_WIRELESS) { 483 + } else if (urb->num_sgs && !urb->dev->bus->no_sg_constraint) { 485 484 struct scatterlist *sg; 486 485 int i; 487 486 ··· 539 540 case USB_ENDPOINT_XFER_ISOC: 540 541 case USB_ENDPOINT_XFER_INT: 541 542 /* too small? */ 542 - switch (dev->speed) { 543 - case USB_SPEED_WIRELESS: 544 - if ((urb->interval < 6) 545 - && (xfertype == USB_ENDPOINT_XFER_INT)) 546 - return -EINVAL; 547 - fallthrough; 548 - default: 549 - if (urb->interval <= 0) 550 - return -EINVAL; 551 - break; 552 - } 543 + if (urb->interval <= 0) 544 + return -EINVAL; 545 + 553 546 /* too big? */ 554 547 switch (dev->speed) { 555 548 case USB_SPEED_SUPER_PLUS: ··· 550 559 if (urb->interval > (1 << 15)) 551 560 return -EINVAL; 552 561 max = 1 << 15; 553 - break; 554 - case USB_SPEED_WIRELESS: 555 - if (urb->interval > 16) 556 - return -EINVAL; 557 562 break; 558 563 case USB_SPEED_HIGH: /* units are microframes */ 559 564 /* NOTE usb handles 2^15 */ ··· 574 587 default: 575 588 return -EINVAL; 576 589 } 577 - if (dev->speed != USB_SPEED_WIRELESS) { 578 - /* Round down to a power of 2, no more than max */ 579 - urb->interval = min(max, 1 << ilog2(urb->interval)); 580 - } 590 + /* Round down to a power of 2, no more than max */ 591 + urb->interval = min(max, 1 << ilog2(urb->interval)); 581 592 } 582 593 583 594 return usb_hcd_submit_urb(urb, mem_flags);
+7 -13
drivers/usb/core/usb.c
··· 25 25 26 26 #include <linux/module.h> 27 27 #include <linux/moduleparam.h> 28 + #include <linux/of.h> 28 29 #include <linux/string.h> 29 30 #include <linux/bitops.h> 30 31 #include <linux/slab.h> ··· 602 601 #endif 603 602 }; 604 603 605 - 606 - /* Returns 1 if @usb_bus is WUSB, 0 otherwise */ 607 - static unsigned usb_bus_is_wusb(struct usb_bus *bus) 608 - { 609 - struct usb_hcd *hcd = bus_to_hcd(bus); 610 - return hcd->wireless; 611 - } 612 - 613 604 static bool usb_dev_authorized(struct usb_device *dev, struct usb_hcd *hcd) 614 605 { 615 606 struct usb_hub *hub; ··· 645 652 { 646 653 struct usb_device *dev; 647 654 struct usb_hcd *usb_hcd = bus_to_hcd(bus); 648 - unsigned root_hub = 0; 649 655 unsigned raw_port = port1; 650 656 651 657 dev = kzalloc(sizeof(*dev), GFP_KERNEL); ··· 694 702 dev->dev.parent = bus->controller; 695 703 device_set_of_node_from_dev(&dev->dev, bus->sysdev); 696 704 dev_set_name(&dev->dev, "usb%d", bus->busnum); 697 - root_hub = 1; 698 705 } else { 699 706 /* match any labeling on the hubs; it's one-based */ 700 707 if (parent->devpath[0] == '0') { ··· 739 748 #endif 740 749 741 750 dev->authorized = usb_dev_authorized(dev, usb_hcd); 742 - if (!root_hub) 743 - dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0; 744 - 745 751 return dev; 746 752 } 747 753 EXPORT_SYMBOL_GPL(usb_alloc_dev); ··· 1089 1101 retval = usb_major_init(); 1090 1102 if (retval) 1091 1103 goto major_init_failed; 1104 + retval = class_register(&usbmisc_class); 1105 + if (retval) 1106 + goto class_register_failed; 1092 1107 retval = usb_register(&usbfs_driver); 1093 1108 if (retval) 1094 1109 goto driver_register_failed; ··· 1111 1120 usb_devio_init_failed: 1112 1121 usb_deregister(&usbfs_driver); 1113 1122 driver_register_failed: 1123 + class_unregister(&usbmisc_class); 1124 + class_register_failed: 1114 1125 usb_major_cleanup(); 1115 1126 major_init_failed: 1116 1127 bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); ··· 1140 1147 usb_deregister(&usbfs_driver); 1141 1148 usb_devio_cleanup(); 1142 1149 usb_hub_cleanup(); 1150 + class_unregister(&usbmisc_class); 1143 1151 bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); 1144 1152 bus_unregister(&usb_bus_type); 1145 1153 usb_acpi_unregister();
+3 -2
drivers/usb/core/usb.h
··· 43 43 struct usb_endpoint_descriptor *epd); 44 44 extern int usb_remove_device(struct usb_device *udev); 45 45 46 - extern int usb_get_device_descriptor(struct usb_device *dev, 47 - unsigned int size); 46 + extern struct usb_device_descriptor *usb_get_device_descriptor( 47 + struct usb_device *udev); 48 48 extern int usb_set_isoch_delay(struct usb_device *dev); 49 49 extern int usb_get_bos_descriptor(struct usb_device *dev); 50 50 extern void usb_release_bos_descriptor(struct usb_device *dev); ··· 141 141 142 142 #endif 143 143 144 + extern const struct class usbmisc_class; 144 145 extern const struct bus_type usb_bus_type; 145 146 extern struct mutex usb_port_peer_mutex; 146 147 extern struct device_type usb_device_type;
+1
drivers/usb/dwc2/core.h
··· 1330 1330 /* The device ID match table */ 1331 1331 extern const struct of_device_id dwc2_of_match_table[]; 1332 1332 extern const struct acpi_device_id dwc2_acpi_match[]; 1333 + extern const struct pci_device_id dwc2_pci_ids[]; 1333 1334 1334 1335 int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg); 1335 1336 int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
-1
drivers/usb/dwc2/gadget.c
··· 22 22 #include <linux/delay.h> 23 23 #include <linux/io.h> 24 24 #include <linux/slab.h> 25 - #include <linux/of_platform.h> 26 25 27 26 #include <linux/usb/ch9.h> 28 27 #include <linux/usb/gadget.h>
+3 -1
drivers/usb/dwc2/hcd_intr.c
··· 2203 2203 irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg) 2204 2204 { 2205 2205 u32 gintsts, dbg_gintsts; 2206 - irqreturn_t retval = IRQ_NONE; 2206 + irqreturn_t retval = IRQ_HANDLED; 2207 2207 2208 2208 if (!dwc2_is_controller_alive(hsotg)) { 2209 2209 dev_warn(hsotg->dev, "Controller is dead\n"); 2210 2210 return retval; 2211 + } else { 2212 + retval = IRQ_NONE; 2211 2213 } 2212 2214 2213 2215 spin_lock(&hsotg->lock);
+38 -1
drivers/usb/dwc2/params.c
··· 7 7 #include <linux/module.h> 8 8 #include <linux/of_device.h> 9 9 #include <linux/usb/of.h> 10 + #include <linux/pci_ids.h> 11 + #include <linux/pci.h> 10 12 11 13 #include "core.h" 14 + 15 + #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 16 + #define PCI_DEVICE_ID_LOONGSON_DWC2 0x7a04 12 17 13 18 static void dwc2_set_bcm_params(struct dwc2_hsotg *hsotg) 14 19 { ··· 58 53 p->phy_utmi_width = 16; 59 54 p->activate_ingenic_overcurrent_detection = 60 55 !device_property_read_bool(hsotg->dev, "disable-over-current"); 56 + } 57 + 58 + static void dwc2_set_loongson_params(struct dwc2_hsotg *hsotg) 59 + { 60 + struct dwc2_core_params *p = &hsotg->params; 61 + 62 + p->phy_utmi_width = 8; 63 + p->power_down = DWC2_POWER_DOWN_PARAM_PARTIAL; 61 64 } 62 65 63 66 static void dwc2_set_x1600_params(struct dwc2_hsotg *hsotg) ··· 314 301 { }, 315 302 }; 316 303 MODULE_DEVICE_TABLE(acpi, dwc2_acpi_match); 304 + 305 + const struct pci_device_id dwc2_pci_ids[] = { 306 + { 307 + PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), 308 + }, 309 + { 310 + PCI_DEVICE(PCI_VENDOR_ID_STMICRO, 311 + PCI_DEVICE_ID_STMICRO_USB_OTG), 312 + }, 313 + { 314 + PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_DWC2), 315 + .driver_data = (unsigned long)dwc2_set_loongson_params, 316 + }, 317 + { /* end: all zeroes */ } 318 + }; 319 + MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); 320 + EXPORT_SYMBOL_GPL(dwc2_pci_ids); 317 321 318 322 static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg) 319 323 { ··· 978 948 if (match && match->data) { 979 949 set_params = match->data; 980 950 set_params(hsotg); 981 - } else { 951 + } else if (!match) { 982 952 const struct acpi_device_id *amatch; 953 + const struct pci_device_id *pmatch = NULL; 983 954 984 955 amatch = acpi_match_device(dwc2_acpi_match, hsotg->dev); 985 956 if (amatch && amatch->driver_data) { 986 957 set_params = (set_params_cb)amatch->driver_data; 958 + set_params(hsotg); 959 + } else if (!amatch) 960 + pmatch = pci_match_id(dwc2_pci_ids, to_pci_dev(hsotg->dev->parent)); 961 + 962 + if (pmatch && pmatch->driver_data) { 963 + set_params = (set_params_cb)pmatch->driver_data; 987 964 set_params(hsotg); 988 965 } 989 966 }
+1 -13
drivers/usb/dwc2/pci.c
··· 24 24 #include <linux/platform_device.h> 25 25 #include <linux/usb/usb_phy_generic.h> 26 26 27 - #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 27 + #include "core.h" 28 28 29 29 static const char dwc2_driver_name[] = "dwc2-pci"; 30 30 ··· 121 121 platform_device_put(dwc2); 122 122 return ret; 123 123 } 124 - 125 - static const struct pci_device_id dwc2_pci_ids[] = { 126 - { 127 - PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), 128 - }, 129 - { 130 - PCI_DEVICE(PCI_VENDOR_ID_STMICRO, 131 - PCI_DEVICE_ID_STMICRO_USB_OTG), 132 - }, 133 - { /* end: all zeroes */ } 134 - }; 135 - MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); 136 124 137 125 static struct pci_driver dwc2_pci_driver = { 138 126 .name = dwc2_driver_name,
+1 -1
drivers/usb/dwc2/platform.c
··· 11 11 #include <linux/clk.h> 12 12 #include <linux/device.h> 13 13 #include <linux/dma-mapping.h> 14 - #include <linux/of_device.h> 14 + #include <linux/of.h> 15 15 #include <linux/mutex.h> 16 16 #include <linux/platform_device.h> 17 17 #include <linux/phy/phy.h>
+10
drivers/usb/dwc3/Kconfig
··· 168 168 The Designware Core USB3 IP is programmed to operate in 169 169 in USB 2.0 mode only. 170 170 Say 'Y' or 'M' here if you have one such device 171 + 172 + config USB_DWC3_OCTEON 173 + tristate "Cavium Octeon Platforms" 174 + depends on CAVIUM_OCTEON_SOC || COMPILE_TEST 175 + default USB_DWC3 176 + help 177 + Support Cavium Octeon platforms with DesignWare Core USB3 IP. 178 + Only the host mode is currently supported. 179 + Say 'Y' or 'M' here if you have one such device. 180 + 171 181 endif
+1
drivers/usb/dwc3/Makefile
··· 54 54 obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o 55 55 obj-$(CONFIG_USB_DWC3_IMX8MP) += dwc3-imx8mp.o 56 56 obj-$(CONFIG_USB_DWC3_XILINX) += dwc3-xilinx.o 57 + obj-$(CONFIG_USB_DWC3_OCTEON) += dwc3-octeon.o
+47 -49
drivers/usb/dwc3/dwc3-am62.c
··· 102 102 103 103 #define DWC3_AM62_AUTOSUSPEND_DELAY 100 104 104 105 - struct dwc3_data { 105 + struct dwc3_am62 { 106 106 struct device *dev; 107 107 void __iomem *usbss; 108 108 struct clk *usb2_refclk; ··· 129 129 52000, 130 130 }; 131 131 132 - static inline u32 dwc3_ti_readl(struct dwc3_data *data, u32 offset) 132 + static inline u32 dwc3_ti_readl(struct dwc3_am62 *am62, u32 offset) 133 133 { 134 - return readl((data->usbss) + offset); 134 + return readl((am62->usbss) + offset); 135 135 } 136 136 137 - static inline void dwc3_ti_writel(struct dwc3_data *data, u32 offset, u32 value) 137 + static inline void dwc3_ti_writel(struct dwc3_am62 *am62, u32 offset, u32 value) 138 138 { 139 - writel(value, (data->usbss) + offset); 139 + writel(value, (am62->usbss) + offset); 140 140 } 141 141 142 - static int phy_syscon_pll_refclk(struct dwc3_data *data) 142 + static int phy_syscon_pll_refclk(struct dwc3_am62 *am62) 143 143 { 144 - struct device *dev = data->dev; 144 + struct device *dev = am62->dev; 145 145 struct device_node *node = dev->of_node; 146 146 struct of_phandle_args args; 147 147 struct regmap *syscon; ··· 153 153 return PTR_ERR(syscon); 154 154 } 155 155 156 - data->syscon = syscon; 156 + am62->syscon = syscon; 157 157 158 158 ret = of_parse_phandle_with_fixed_args(node, "ti,syscon-phy-pll-refclk", 1, 159 159 0, &args); 160 160 if (ret) 161 161 return ret; 162 162 163 - data->offset = args.args[0]; 163 + am62->offset = args.args[0]; 164 164 165 - ret = regmap_update_bits(data->syscon, data->offset, PHY_PLL_REFCLK_MASK, data->rate_code); 165 + ret = regmap_update_bits(am62->syscon, am62->offset, PHY_PLL_REFCLK_MASK, am62->rate_code); 166 166 if (ret) { 167 167 dev_err(dev, "failed to set phy pll reference clock rate\n"); 168 168 return ret; ··· 175 175 { 176 176 struct device *dev = &pdev->dev; 177 177 struct device_node *node = pdev->dev.of_node; 178 - struct dwc3_data *data; 178 + struct dwc3_am62 *am62; 179 179 int i, ret; 180 180 unsigned long rate; 181 181 u32 reg; 182 182 183 - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 184 - if (!data) 183 + am62 = devm_kzalloc(dev, sizeof(*am62), GFP_KERNEL); 184 + if (!am62) 185 185 return -ENOMEM; 186 186 187 - data->dev = dev; 188 - platform_set_drvdata(pdev, data); 187 + am62->dev = dev; 188 + platform_set_drvdata(pdev, am62); 189 189 190 - data->usbss = devm_platform_ioremap_resource(pdev, 0); 191 - if (IS_ERR(data->usbss)) { 190 + am62->usbss = devm_platform_ioremap_resource(pdev, 0); 191 + if (IS_ERR(am62->usbss)) { 192 192 dev_err(dev, "can't map IOMEM resource\n"); 193 - return PTR_ERR(data->usbss); 193 + return PTR_ERR(am62->usbss); 194 194 } 195 195 196 - data->usb2_refclk = devm_clk_get(dev, "ref"); 197 - if (IS_ERR(data->usb2_refclk)) { 196 + am62->usb2_refclk = devm_clk_get(dev, "ref"); 197 + if (IS_ERR(am62->usb2_refclk)) { 198 198 dev_err(dev, "can't get usb2_refclk\n"); 199 - return PTR_ERR(data->usb2_refclk); 199 + return PTR_ERR(am62->usb2_refclk); 200 200 } 201 201 202 202 /* Calculate the rate code */ 203 - rate = clk_get_rate(data->usb2_refclk); 203 + rate = clk_get_rate(am62->usb2_refclk); 204 204 rate /= 1000; // To KHz 205 205 for (i = 0; i < ARRAY_SIZE(dwc3_ti_rate_table); i++) { 206 206 if (dwc3_ti_rate_table[i] == rate) ··· 212 212 return -EINVAL; 213 213 } 214 214 215 - data->rate_code = i; 215 + am62->rate_code = i; 216 216 217 217 /* Read the syscon property and set the rate code */ 218 - ret = phy_syscon_pll_refclk(data); 218 + ret = phy_syscon_pll_refclk(am62); 219 219 if (ret) 220 220 return ret; 221 221 222 222 /* VBUS divider select */ 223 - data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); 224 - reg = dwc3_ti_readl(data, USBSS_PHY_CONFIG); 225 - if (data->vbus_divider) 223 + am62->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); 224 + reg = dwc3_ti_readl(am62, USBSS_PHY_CONFIG); 225 + if (am62->vbus_divider) 226 226 reg |= 1 << USBSS_PHY_VBUS_SEL_SHIFT; 227 227 228 - dwc3_ti_writel(data, USBSS_PHY_CONFIG, reg); 228 + dwc3_ti_writel(am62, USBSS_PHY_CONFIG, reg); 229 229 230 230 pm_runtime_set_active(dev); 231 231 pm_runtime_enable(dev); ··· 233 233 * Don't ignore its dependencies with its children 234 234 */ 235 235 pm_suspend_ignore_children(dev, false); 236 - clk_prepare_enable(data->usb2_refclk); 236 + clk_prepare_enable(am62->usb2_refclk); 237 237 pm_runtime_get_noresume(dev); 238 238 239 239 ret = of_platform_populate(node, NULL, NULL, dev); ··· 243 243 } 244 244 245 245 /* Set mode valid bit to indicate role is valid */ 246 - reg = dwc3_ti_readl(data, USBSS_MODE_CONTROL); 246 + reg = dwc3_ti_readl(am62, USBSS_MODE_CONTROL); 247 247 reg |= USBSS_MODE_VALID; 248 - dwc3_ti_writel(data, USBSS_MODE_CONTROL, reg); 248 + dwc3_ti_writel(am62, USBSS_MODE_CONTROL, reg); 249 249 250 250 /* Device has capability to wakeup system from sleep */ 251 251 device_set_wakeup_capable(dev, true); ··· 261 261 return 0; 262 262 263 263 err_pm_disable: 264 - clk_disable_unprepare(data->usb2_refclk); 264 + clk_disable_unprepare(am62->usb2_refclk); 265 265 pm_runtime_disable(dev); 266 266 pm_runtime_set_suspended(dev); 267 267 return ret; ··· 278 278 static void dwc3_ti_remove(struct platform_device *pdev) 279 279 { 280 280 struct device *dev = &pdev->dev; 281 - struct dwc3_data *data = platform_get_drvdata(pdev); 281 + struct dwc3_am62 *am62 = platform_get_drvdata(pdev); 282 282 u32 reg; 283 283 284 284 device_for_each_child(dev, NULL, dwc3_ti_remove_core); 285 285 286 286 /* Clear mode valid bit */ 287 - reg = dwc3_ti_readl(data, USBSS_MODE_CONTROL); 287 + reg = dwc3_ti_readl(am62, USBSS_MODE_CONTROL); 288 288 reg &= ~USBSS_MODE_VALID; 289 - dwc3_ti_writel(data, USBSS_MODE_CONTROL, reg); 289 + dwc3_ti_writel(am62, USBSS_MODE_CONTROL, reg); 290 290 291 291 pm_runtime_put_sync(dev); 292 - clk_disable_unprepare(data->usb2_refclk); 292 + clk_disable_unprepare(am62->usb2_refclk); 293 293 pm_runtime_disable(dev); 294 294 pm_runtime_set_suspended(dev); 295 - 296 - platform_set_drvdata(pdev, NULL); 297 295 } 298 296 299 297 #ifdef CONFIG_PM 300 298 static int dwc3_ti_suspend_common(struct device *dev) 301 299 { 302 - struct dwc3_data *data = dev_get_drvdata(dev); 300 + struct dwc3_am62 *am62 = dev_get_drvdata(dev); 303 301 u32 reg, current_prtcap_dir; 304 302 305 303 if (device_may_wakeup(dev)) { 306 - reg = dwc3_ti_readl(data, USBSS_CORE_STAT); 304 + reg = dwc3_ti_readl(am62, USBSS_CORE_STAT); 307 305 current_prtcap_dir = (reg & USBSS_CORE_OPERATIONAL_MODE_MASK) 308 306 >> USBSS_CORE_OPERATIONAL_MODE_SHIFT; 309 307 /* Set wakeup config enable bits */ 310 - reg = dwc3_ti_readl(data, USBSS_WAKEUP_CONFIG); 308 + reg = dwc3_ti_readl(am62, USBSS_WAKEUP_CONFIG); 311 309 if (current_prtcap_dir == DWC3_GCTL_PRTCAP_HOST) { 312 310 reg = USBSS_WAKEUP_CFG_LINESTATE_EN | USBSS_WAKEUP_CFG_OVERCURRENT_EN; 313 311 } else { ··· 315 317 * and in U2/L3 state else it causes spurious wake-up. 316 318 */ 317 319 } 318 - dwc3_ti_writel(data, USBSS_WAKEUP_CONFIG, reg); 320 + dwc3_ti_writel(am62, USBSS_WAKEUP_CONFIG, reg); 319 321 /* clear wakeup status so we know what caused the wake up */ 320 - dwc3_ti_writel(data, USBSS_WAKEUP_STAT, USBSS_WAKEUP_STAT_CLR); 322 + dwc3_ti_writel(am62, USBSS_WAKEUP_STAT, USBSS_WAKEUP_STAT_CLR); 321 323 } 322 324 323 - clk_disable_unprepare(data->usb2_refclk); 325 + clk_disable_unprepare(am62->usb2_refclk); 324 326 325 327 return 0; 326 328 } 327 329 328 330 static int dwc3_ti_resume_common(struct device *dev) 329 331 { 330 - struct dwc3_data *data = dev_get_drvdata(dev); 332 + struct dwc3_am62 *am62 = dev_get_drvdata(dev); 331 333 u32 reg; 332 334 333 - clk_prepare_enable(data->usb2_refclk); 335 + clk_prepare_enable(am62->usb2_refclk); 334 336 335 337 if (device_may_wakeup(dev)) { 336 338 /* Clear wakeup config enable bits */ 337 - dwc3_ti_writel(data, USBSS_WAKEUP_CONFIG, USBSS_WAKEUP_CFG_NONE); 339 + dwc3_ti_writel(am62, USBSS_WAKEUP_CONFIG, USBSS_WAKEUP_CFG_NONE); 338 340 } 339 341 340 - reg = dwc3_ti_readl(data, USBSS_WAKEUP_STAT); 341 - data->wakeup_stat = reg; 342 + reg = dwc3_ti_readl(am62, USBSS_WAKEUP_STAT); 343 + am62->wakeup_stat = reg; 342 344 343 345 return 0; 344 346 }
+9
drivers/usb/dwc3/dwc3-exynos.c
··· 163 163 .suspend_clk_idx = 1, 164 164 }; 165 165 166 + static const struct dwc3_exynos_driverdata exynos850_drvdata = { 167 + .clk_names = { "bus_early", "ref" }, 168 + .num_clks = 2, 169 + .suspend_clk_idx = -1, 170 + }; 171 + 166 172 static const struct of_device_id exynos_dwc3_match[] = { 167 173 { 168 174 .compatible = "samsung,exynos5250-dwusb3", ··· 179 173 }, { 180 174 .compatible = "samsung,exynos7-dwusb3", 181 175 .data = &exynos7_drvdata, 176 + }, { 177 + .compatible = "samsung,exynos850-dwusb3", 178 + .data = &exynos850_drvdata, 182 179 }, { 183 180 } 184 181 };
+1 -1
drivers/usb/dwc3/dwc3-imx8mp.c
··· 10 10 #include <linux/io.h> 11 11 #include <linux/kernel.h> 12 12 #include <linux/module.h> 13 + #include <linux/of.h> 13 14 #include <linux/of_platform.h> 14 15 #include <linux/platform_device.h> 15 16 #include <linux/pm_runtime.h> ··· 280 279 281 280 pm_runtime_disable(dev); 282 281 pm_runtime_put_noidle(dev); 283 - platform_set_drvdata(pdev, NULL); 284 282 } 285 283 286 284 static int __maybe_unused dwc3_imx8mp_suspend(struct dwc3_imx8mp *dwc3_imx,
+1 -2
drivers/usb/dwc3/dwc3-keystone.c
··· 13 13 #include <linux/platform_device.h> 14 14 #include <linux/dma-mapping.h> 15 15 #include <linux/io.h> 16 + #include <linux/of.h> 16 17 #include <linux/of_platform.h> 17 18 #include <linux/phy/phy.h> 18 19 #include <linux/pm_runtime.h> ··· 197 196 phy_power_off(kdwc->usb3_phy); 198 197 phy_exit(kdwc->usb3_phy); 199 198 phy_pm_runtime_put_sync(kdwc->usb3_phy); 200 - 201 - platform_set_drvdata(pdev, NULL); 202 199 } 203 200 204 201 static const struct of_device_id kdwc3_of_match[] = {
+6
drivers/usb/dwc3/dwc3-meson-g12a.c
··· 926 926 return ret; 927 927 } 928 928 929 + if (priv->drvdata->usb_post_init) { 930 + ret = priv->drvdata->usb_post_init(priv); 931 + if (ret) 932 + return ret; 933 + } 934 + 929 935 return 0; 930 936 } 931 937
-1
drivers/usb/dwc3/dwc3-of-simple.c
··· 170 170 171 171 static const struct of_device_id of_dwc3_simple_match[] = { 172 172 { .compatible = "rockchip,rk3399-dwc3" }, 173 - { .compatible = "cavium,octeon-7130-usb-uctl" }, 174 173 { .compatible = "sprd,sc9860-dwc3" }, 175 174 { .compatible = "allwinner,sun50i-h6-dwc3" }, 176 175 { .compatible = "hisilicon,hi3670-dwc3" },
+18
drivers/usb/gadget/Kconfig
··· 208 208 config USB_F_MIDI 209 209 tristate 210 210 211 + config USB_F_MIDI2 212 + tristate 213 + 211 214 config USB_F_HID 212 215 tristate 213 216 ··· 438 435 a sound "card" in the ALSA sound system. Other MIDI 439 436 connections can then be made on the gadget system, using 440 437 ALSA's aconnect utility etc. 438 + 439 + config USB_CONFIGFS_F_MIDI2 440 + bool "MIDI 2.0 function" 441 + depends on USB_CONFIGFS 442 + depends on SND 443 + select USB_LIBCOMPOSITE 444 + select SND_UMP 445 + select SND_UMP_LEGACY_RAWMIDI 446 + select USB_F_MIDI2 447 + help 448 + The MIDI 2.0 function driver provides the generic emulated 449 + USB MIDI 2.0 interface, looped back to ALSA UMP rawmidi 450 + device on the gadget host. It supports UMP 1.1 spec and 451 + responds UMP Stream messages for UMP Endpoint and Function 452 + Block information / configuration. 441 453 442 454 config USB_CONFIGFS_F_HID 443 455 bool "HID function"
+14 -20
drivers/usb/gadget/composite.c
··· 170 170 /* select desired speed */ 171 171 switch (g->speed) { 172 172 case USB_SPEED_SUPER_PLUS: 173 - if (gadget_is_superspeed_plus(g)) { 174 - if (f->ssp_descriptors) { 175 - speed_desc = f->ssp_descriptors; 176 - want_comp_desc = 1; 177 - break; 178 - } 179 - incomplete_desc = true; 173 + if (f->ssp_descriptors) { 174 + speed_desc = f->ssp_descriptors; 175 + want_comp_desc = 1; 176 + break; 180 177 } 178 + incomplete_desc = true; 181 179 fallthrough; 182 180 case USB_SPEED_SUPER: 183 - if (gadget_is_superspeed(g)) { 184 - if (f->ss_descriptors) { 185 - speed_desc = f->ss_descriptors; 186 - want_comp_desc = 1; 187 - break; 188 - } 189 - incomplete_desc = true; 181 + if (f->ss_descriptors) { 182 + speed_desc = f->ss_descriptors; 183 + want_comp_desc = 1; 184 + break; 190 185 } 186 + incomplete_desc = true; 191 187 fallthrough; 192 188 case USB_SPEED_HIGH: 193 - if (gadget_is_dualspeed(g)) { 194 - if (f->hs_descriptors) { 195 - speed_desc = f->hs_descriptors; 196 - break; 197 - } 198 - incomplete_desc = true; 189 + if (f->hs_descriptors) { 190 + speed_desc = f->hs_descriptors; 191 + break; 199 192 } 193 + incomplete_desc = true; 200 194 fallthrough; 201 195 default: 202 196 speed_desc = f->fs_descriptors;
+3 -5
drivers/usb/gadget/config.c
··· 162 162 struct usb_descriptor_header **ss, 163 163 struct usb_descriptor_header **ssp) 164 164 { 165 - struct usb_gadget *g = f->config->cdev->gadget; 166 - 167 165 /* super-speed-plus descriptor falls back to super-speed one, 168 166 * if such a descriptor was provided, thus avoiding a NULL 169 167 * pointer dereference if a 5gbps capable gadget is used with ··· 175 177 if (!f->fs_descriptors) 176 178 goto err; 177 179 } 178 - if (hs && gadget_is_dualspeed(g)) { 180 + if (hs) { 179 181 f->hs_descriptors = usb_copy_descriptors(hs); 180 182 if (!f->hs_descriptors) 181 183 goto err; 182 184 } 183 - if (ss && gadget_is_superspeed(g)) { 185 + if (ss) { 184 186 f->ss_descriptors = usb_copy_descriptors(ss); 185 187 if (!f->ss_descriptors) 186 188 goto err; 187 189 } 188 - if (ssp && gadget_is_superspeed_plus(g)) { 190 + if (ssp) { 189 191 f->ssp_descriptors = usb_copy_descriptors(ssp); 190 192 if (!f->ssp_descriptors) 191 193 goto err;
+2
drivers/usb/gadget/function/Makefile
··· 44 44 obj-$(CONFIG_USB_F_UVC) += usb_f_uvc.o 45 45 usb_f_midi-y := f_midi.o 46 46 obj-$(CONFIG_USB_F_MIDI) += usb_f_midi.o 47 + usb_f_midi2-y := f_midi2.o 48 + obj-$(CONFIG_USB_F_MIDI2) += usb_f_midi2.o 47 49 usb_f_hid-y := f_hid.o 48 50 obj-$(CONFIG_USB_F_HID) += usb_f_hid.o 49 51 usb_f_printer-y := f_printer.o
+1 -3
drivers/usb/gadget/function/f_acm.c
··· 691 691 goto fail; 692 692 693 693 dev_dbg(&cdev->gadget->dev, 694 - "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n", 694 + "acm ttyGS%d: IN/%s OUT/%s NOTIFY/%s\n", 695 695 acm->port_num, 696 - gadget_is_superspeed(c->cdev->gadget) ? "super" : 697 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 698 696 acm->port.in->name, acm->port.out->name, 699 697 acm->notify->name); 700 698 return 0;
+3 -16
drivers/usb/gadget/function/f_ecm.c
··· 65 65 return container_of(f, struct f_ecm, port.func); 66 66 } 67 67 68 - /* peak (theoretical) bulk transfer rate in bits-per-second */ 69 - static inline unsigned ecm_bitrate(struct usb_gadget *g) 70 - { 71 - if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) 72 - return 13 * 1024 * 8 * 1000 * 8; 73 - else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 74 - return 13 * 512 * 8 * 1000 * 8; 75 - else 76 - return 19 * 64 * 1 * 1000 * 8; 77 - } 78 - 79 68 /*-------------------------------------------------------------------------*/ 80 69 81 70 /* ··· 400 411 401 412 /* SPEED_CHANGE data is up/down speeds in bits/sec */ 402 413 data = req->buf + sizeof *event; 403 - data[0] = cpu_to_le32(ecm_bitrate(cdev->gadget)); 414 + data[0] = cpu_to_le32(gether_bitrate(cdev->gadget)); 404 415 data[1] = data[0]; 405 416 406 - DBG(cdev, "notify speed %d\n", ecm_bitrate(cdev->gadget)); 417 + DBG(cdev, "notify speed %d\n", gether_bitrate(cdev->gadget)); 407 418 ecm->notify_state = ECM_NOTIFY_NONE; 408 419 break; 409 420 } ··· 788 799 ecm->port.open = ecm_open; 789 800 ecm->port.close = ecm_close; 790 801 791 - DBG(cdev, "CDC Ethernet: %s speed IN/%s OUT/%s NOTIFY/%s\n", 792 - gadget_is_superspeed(c->cdev->gadget) ? "super" : 793 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 802 + DBG(cdev, "CDC Ethernet: IN/%s OUT/%s NOTIFY/%s\n", 794 803 ecm->port.in_ep->name, ecm->port.out_ep->name, 795 804 ecm->notify->name); 796 805 return 0;
+1 -3
drivers/usb/gadget/function/f_eem.c
··· 311 311 if (status) 312 312 goto fail; 313 313 314 - DBG(cdev, "CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n", 315 - gadget_is_superspeed(c->cdev->gadget) ? "super" : 316 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 314 + DBG(cdev, "CDC Ethernet (EEM): IN/%s OUT/%s\n", 317 315 eem->port.in_ep->name, eem->port.out_ep->name); 318 316 return 0; 319 317
+1 -3
drivers/usb/gadget/function/f_loopback.c
··· 211 211 if (ret) 212 212 return ret; 213 213 214 - DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n", 215 - (gadget_is_superspeed(c->cdev->gadget) ? "super" : 216 - (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), 214 + DBG(cdev, "%s: IN/%s, OUT/%s\n", 217 215 f->name, loop->in_ep->name, loop->out_ep->name); 218 216 return 0; 219 217 }
+1 -1
drivers/usb/gadget/function/f_mass_storage.c
··· 927 927 { 928 928 struct file *filp = curlun->filp; 929 929 struct inode *inode = file_inode(filp); 930 - unsigned long rc; 930 + unsigned long __maybe_unused rc; 931 931 932 932 rc = invalidate_mapping_pages(inode->i_mapping, 0, -1); 933 933 VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
+23 -33
drivers/usb/gadget/function/f_midi.c
··· 1023 1023 if (!f->fs_descriptors) 1024 1024 goto fail_f_midi; 1025 1025 1026 - if (gadget_is_dualspeed(c->cdev->gadget)) { 1027 - bulk_in_desc.wMaxPacketSize = cpu_to_le16(512); 1028 - bulk_out_desc.wMaxPacketSize = cpu_to_le16(512); 1029 - f->hs_descriptors = usb_copy_descriptors(midi_function); 1030 - if (!f->hs_descriptors) 1031 - goto fail_f_midi; 1032 - } 1026 + bulk_in_desc.wMaxPacketSize = cpu_to_le16(512); 1027 + bulk_out_desc.wMaxPacketSize = cpu_to_le16(512); 1028 + f->hs_descriptors = usb_copy_descriptors(midi_function); 1029 + if (!f->hs_descriptors) 1030 + goto fail_f_midi; 1033 1031 1034 - if (gadget_is_superspeed(c->cdev->gadget)) { 1035 - bulk_in_desc.wMaxPacketSize = cpu_to_le16(1024); 1036 - bulk_out_desc.wMaxPacketSize = cpu_to_le16(1024); 1037 - i = endpoint_descriptor_index; 1038 - midi_function[i++] = (struct usb_descriptor_header *) 1039 - &bulk_out_desc; 1040 - midi_function[i++] = (struct usb_descriptor_header *) 1041 - &bulk_out_ss_comp_desc; 1042 - midi_function[i++] = (struct usb_descriptor_header *) 1043 - &ms_out_desc; 1044 - midi_function[i++] = (struct usb_descriptor_header *) 1045 - &bulk_in_desc; 1046 - midi_function[i++] = (struct usb_descriptor_header *) 1047 - &bulk_in_ss_comp_desc; 1048 - midi_function[i++] = (struct usb_descriptor_header *) 1049 - &ms_in_desc; 1050 - f->ss_descriptors = usb_copy_descriptors(midi_function); 1051 - if (!f->ss_descriptors) 1052 - goto fail_f_midi; 1053 - 1054 - if (gadget_is_superspeed_plus(c->cdev->gadget)) { 1055 - f->ssp_descriptors = usb_copy_descriptors(midi_function); 1056 - if (!f->ssp_descriptors) 1057 - goto fail_f_midi; 1058 - } 1059 - } 1032 + bulk_in_desc.wMaxPacketSize = cpu_to_le16(1024); 1033 + bulk_out_desc.wMaxPacketSize = cpu_to_le16(1024); 1034 + i = endpoint_descriptor_index; 1035 + midi_function[i++] = (struct usb_descriptor_header *) 1036 + &bulk_out_desc; 1037 + midi_function[i++] = (struct usb_descriptor_header *) 1038 + &bulk_out_ss_comp_desc; 1039 + midi_function[i++] = (struct usb_descriptor_header *) 1040 + &ms_out_desc; 1041 + midi_function[i++] = (struct usb_descriptor_header *) 1042 + &bulk_in_desc; 1043 + midi_function[i++] = (struct usb_descriptor_header *) 1044 + &bulk_in_ss_comp_desc; 1045 + midi_function[i++] = (struct usb_descriptor_header *) 1046 + &ms_in_desc; 1047 + f->ss_descriptors = usb_copy_descriptors(midi_function); 1048 + if (!f->ss_descriptors) 1049 + goto fail_f_midi; 1060 1050 1061 1051 kfree(midi_function); 1062 1052
+2871
drivers/usb/gadget/function/f_midi2.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * f_midi2.c -- USB MIDI 2.0 class function driver 4 + */ 5 + 6 + #include <linux/device.h> 7 + #include <linux/kernel.h> 8 + #include <linux/module.h> 9 + #include <linux/slab.h> 10 + 11 + #include <sound/core.h> 12 + #include <sound/control.h> 13 + #include <sound/ump.h> 14 + #include <sound/ump_msg.h> 15 + #include <sound/ump_convert.h> 16 + 17 + #include <linux/usb/ch9.h> 18 + #include <linux/usb/gadget.h> 19 + #include <linux/usb/audio.h> 20 + #include <linux/usb/midi-v2.h> 21 + 22 + #include "u_f.h" 23 + #include "u_midi2.h" 24 + 25 + struct f_midi2; 26 + struct f_midi2_ep; 27 + struct f_midi2_usb_ep; 28 + 29 + /* Context for each USB request */ 30 + struct f_midi2_req_ctx { 31 + struct f_midi2_usb_ep *usb_ep; /* belonging USB EP */ 32 + unsigned int index; /* array index: 0-31 */ 33 + struct usb_request *req; /* assigned request */ 34 + }; 35 + 36 + /* Resources for a USB Endpoint */ 37 + struct f_midi2_usb_ep { 38 + struct f_midi2 *card; /* belonging card */ 39 + struct f_midi2_ep *ep; /* belonging UMP EP (optional) */ 40 + struct usb_ep *usb_ep; /* assigned USB EP */ 41 + void (*complete)(struct usb_ep *usb_ep, struct usb_request *req); 42 + unsigned long free_reqs; /* bitmap for unused requests */ 43 + unsigned int num_reqs; /* number of allocated requests */ 44 + struct f_midi2_req_ctx *reqs; /* request context array */ 45 + }; 46 + 47 + /* Resources for UMP Function Block (and USB Group Terminal Block) */ 48 + struct f_midi2_block { 49 + struct f_midi2_block_info info; /* FB info, copied from configfs */ 50 + struct snd_ump_block *fb; /* assigned FB */ 51 + unsigned int gtb_id; /* assigned GTB id */ 52 + unsigned int string_id; /* assigned string id */ 53 + }; 54 + 55 + /* Temporary buffer for altset 0 MIDI 1.0 handling */ 56 + struct f_midi2_midi1_port { 57 + unsigned int pending; /* pending bytes on the input buffer */ 58 + u8 buf[32]; /* raw MIDI 1.0 byte input */ 59 + u8 state; /* running status */ 60 + u8 data[2]; /* rendered USB MIDI 1.0 packet data */ 61 + }; 62 + 63 + /* MIDI 1.0 message states */ 64 + enum { 65 + STATE_INITIAL = 0, /* pseudo state */ 66 + STATE_1PARAM, 67 + STATE_2PARAM_1, 68 + STATE_2PARAM_2, 69 + STATE_SYSEX_0, 70 + STATE_SYSEX_1, 71 + STATE_SYSEX_2, 72 + STATE_REAL_TIME, 73 + STATE_FINISHED, /* pseudo state */ 74 + }; 75 + 76 + /* Resources for UMP Endpoint */ 77 + struct f_midi2_ep { 78 + struct snd_ump_endpoint *ump; /* assigned UMP EP */ 79 + struct f_midi2 *card; /* belonging MIDI 2.0 device */ 80 + 81 + struct f_midi2_ep_info info; /* UMP EP info, copied from configfs */ 82 + unsigned int num_blks; /* number of FBs */ 83 + struct f_midi2_block blks[SNDRV_UMP_MAX_BLOCKS]; /* UMP FBs */ 84 + 85 + struct f_midi2_usb_ep ep_in; /* USB MIDI EP-in */ 86 + struct f_midi2_usb_ep ep_out; /* USB MIDI EP-out */ 87 + 88 + u8 in_group_to_cable[SNDRV_UMP_MAX_GROUPS]; /* map to cable; 1-based! */ 89 + }; 90 + 91 + /* indices for USB strings */ 92 + enum { 93 + STR_IFACE = 0, 94 + STR_GTB1 = 1, 95 + }; 96 + 97 + /* 1-based GTB id to string id */ 98 + #define gtb_to_str_id(id) (STR_GTB1 + (id) - 1) 99 + 100 + /* mapping from MIDI 1.0 cable to UMP group */ 101 + struct midi1_cable_mapping { 102 + struct f_midi2_ep *ep; 103 + unsigned char block; 104 + unsigned char group; 105 + }; 106 + 107 + /* operation mode */ 108 + enum { 109 + MIDI_OP_MODE_UNSET, /* no altset set yet */ 110 + MIDI_OP_MODE_MIDI1, /* MIDI 1.0 (altset 0) is used */ 111 + MIDI_OP_MODE_MIDI2, /* MIDI 2.0 (altset 1) is used */ 112 + }; 113 + 114 + /* Resources for MIDI 2.0 Device */ 115 + struct f_midi2 { 116 + struct usb_function func; 117 + struct usb_gadget *gadget; 118 + struct snd_card *card; 119 + 120 + /* MIDI 1.0 in/out USB EPs */ 121 + struct f_midi2_usb_ep midi1_ep_in; 122 + struct f_midi2_usb_ep midi1_ep_out; 123 + 124 + /* number of MIDI 1.0 I/O cables */ 125 + unsigned int num_midi1_in; 126 + unsigned int num_midi1_out; 127 + 128 + /* conversion for MIDI 1.0 EP-in */ 129 + struct f_midi2_midi1_port midi1_port[MAX_CABLES]; 130 + /* conversion for MIDI 1.0 EP-out */ 131 + struct ump_cvt_to_ump midi1_ump_cvt; 132 + /* mapping between cables and UMP groups */ 133 + struct midi1_cable_mapping in_cable_mapping[MAX_CABLES]; 134 + struct midi1_cable_mapping out_cable_mapping[MAX_CABLES]; 135 + 136 + int midi_if; /* USB MIDI interface number */ 137 + int operation_mode; /* current operation mode */ 138 + 139 + spinlock_t queue_lock; 140 + 141 + struct f_midi2_card_info info; /* card info, copied from configfs */ 142 + 143 + unsigned int num_eps; 144 + struct f_midi2_ep midi2_eps[MAX_UMP_EPS]; 145 + 146 + unsigned int total_blocks; /* total number of blocks of all EPs */ 147 + struct usb_string *string_defs; 148 + struct usb_string *strings; 149 + }; 150 + 151 + #define func_to_midi2(f) container_of(f, struct f_midi2, func) 152 + 153 + /* get EP name string */ 154 + static const char *ump_ep_name(const struct f_midi2_ep *ep) 155 + { 156 + return ep->info.ep_name ? ep->info.ep_name : "MIDI 2.0 Gadget"; 157 + } 158 + 159 + /* get EP product ID string */ 160 + static const char *ump_product_id(const struct f_midi2_ep *ep) 161 + { 162 + return ep->info.product_id ? ep->info.product_id : "Unique Product ID"; 163 + } 164 + 165 + /* get FB name string */ 166 + static const char *ump_fb_name(const struct f_midi2_block_info *info) 167 + { 168 + return info->name ? info->name : "MIDI 2.0 Gadget I/O"; 169 + } 170 + 171 + /* 172 + * USB Descriptor Definitions 173 + */ 174 + /* GTB header descriptor */ 175 + static struct usb_ms20_gr_trm_block_header_descriptor gtb_header_desc = { 176 + .bLength = sizeof(gtb_header_desc), 177 + .bDescriptorType = USB_DT_CS_GR_TRM_BLOCK, 178 + .bDescriptorSubtype = USB_MS_GR_TRM_BLOCK_HEADER, 179 + .wTotalLength = __cpu_to_le16(0x12), // to be filled 180 + }; 181 + 182 + /* GTB descriptor template: most items are replaced dynamically */ 183 + static struct usb_ms20_gr_trm_block_descriptor gtb_desc = { 184 + .bLength = sizeof(gtb_desc), 185 + .bDescriptorType = USB_DT_CS_GR_TRM_BLOCK, 186 + .bDescriptorSubtype = USB_MS_GR_TRM_BLOCK, 187 + .bGrpTrmBlkID = 0x01, 188 + .bGrpTrmBlkType = USB_MS_GR_TRM_BLOCK_TYPE_BIDIRECTIONAL, 189 + .nGroupTrm = 0x00, 190 + .nNumGroupTrm = 1, 191 + .iBlockItem = 0, 192 + .bMIDIProtocol = USB_MS_MIDI_PROTO_1_0_64, 193 + .wMaxInputBandwidth = 0, 194 + .wMaxOutputBandwidth = 0, 195 + }; 196 + 197 + DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); 198 + DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(16); 199 + DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); 200 + DECLARE_USB_MS20_ENDPOINT_DESCRIPTOR(32); 201 + 202 + #define EP_MAX_PACKET_INT 8 203 + 204 + /* Audio Control Interface */ 205 + static struct usb_interface_descriptor midi2_audio_if_desc = { 206 + .bLength = USB_DT_INTERFACE_SIZE, 207 + .bDescriptorType = USB_DT_INTERFACE, 208 + .bInterfaceNumber = 0, // to be filled 209 + .bNumEndpoints = 0, 210 + .bInterfaceClass = USB_CLASS_AUDIO, 211 + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, 212 + .bInterfaceProtocol = 0, 213 + .iInterface = 0, 214 + }; 215 + 216 + static struct uac1_ac_header_descriptor_1 midi2_audio_class_desc = { 217 + .bLength = 0x09, 218 + .bDescriptorType = USB_DT_CS_INTERFACE, 219 + .bDescriptorSubtype = 0x01, 220 + .bcdADC = __cpu_to_le16(0x0100), 221 + .wTotalLength = __cpu_to_le16(0x0009), 222 + .bInCollection = 0x01, 223 + .baInterfaceNr = { 0x01 }, // to be filled 224 + }; 225 + 226 + /* MIDI 1.0 Streaming Interface (altset 0) */ 227 + static struct usb_interface_descriptor midi2_midi1_if_desc = { 228 + .bLength = USB_DT_INTERFACE_SIZE, 229 + .bDescriptorType = USB_DT_INTERFACE, 230 + .bInterfaceNumber = 0, // to be filled 231 + .bAlternateSetting = 0, 232 + .bNumEndpoints = 2, // to be filled 233 + .bInterfaceClass = USB_CLASS_AUDIO, 234 + .bInterfaceSubClass = USB_SUBCLASS_MIDISTREAMING, 235 + .bInterfaceProtocol = 0, 236 + .iInterface = 0, // to be filled 237 + }; 238 + 239 + static struct usb_ms_header_descriptor midi2_midi1_class_desc = { 240 + .bLength = 0x07, 241 + .bDescriptorType = USB_DT_CS_INTERFACE, 242 + .bDescriptorSubtype = USB_MS_HEADER, 243 + .bcdMSC = __cpu_to_le16(0x0100), 244 + .wTotalLength = __cpu_to_le16(0x41), // to be calculated 245 + }; 246 + 247 + /* MIDI 1.0 EP OUT */ 248 + static struct usb_endpoint_descriptor midi2_midi1_ep_out_desc = { 249 + .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, 250 + .bDescriptorType = USB_DT_ENDPOINT, 251 + .bEndpointAddress = USB_DIR_OUT | 0, // set up dynamically 252 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 253 + }; 254 + 255 + static struct usb_ss_ep_comp_descriptor midi2_midi1_ep_out_ss_comp_desc = { 256 + .bLength = sizeof(midi2_midi1_ep_out_ss_comp_desc), 257 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 258 + }; 259 + 260 + static struct usb_ms_endpoint_descriptor_16 midi2_midi1_ep_out_class_desc = { 261 + .bLength = 0x05, // to be filled 262 + .bDescriptorType = USB_DT_CS_ENDPOINT, 263 + .bDescriptorSubtype = USB_MS_GENERAL, 264 + .bNumEmbMIDIJack = 1, 265 + .baAssocJackID = { 0x01 }, 266 + }; 267 + 268 + /* MIDI 1.0 EP IN */ 269 + static struct usb_endpoint_descriptor midi2_midi1_ep_in_desc = { 270 + .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, 271 + .bDescriptorType = USB_DT_ENDPOINT, 272 + .bEndpointAddress = USB_DIR_IN | 0, // set up dynamically 273 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 274 + }; 275 + 276 + static struct usb_ss_ep_comp_descriptor midi2_midi1_ep_in_ss_comp_desc = { 277 + .bLength = sizeof(midi2_midi1_ep_in_ss_comp_desc), 278 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 279 + }; 280 + 281 + static struct usb_ms_endpoint_descriptor_16 midi2_midi1_ep_in_class_desc = { 282 + .bLength = 0x05, // to be filled 283 + .bDescriptorType = USB_DT_CS_ENDPOINT, 284 + .bDescriptorSubtype = USB_MS_GENERAL, 285 + .bNumEmbMIDIJack = 1, 286 + .baAssocJackID = { 0x03 }, 287 + }; 288 + 289 + /* MIDI 2.0 Streaming Interface (altset 1) */ 290 + static struct usb_interface_descriptor midi2_midi2_if_desc = { 291 + .bLength = USB_DT_INTERFACE_SIZE, 292 + .bDescriptorType = USB_DT_INTERFACE, 293 + .bInterfaceNumber = 0, // to be filled 294 + .bAlternateSetting = 1, 295 + .bNumEndpoints = 2, // to be filled 296 + .bInterfaceClass = USB_CLASS_AUDIO, 297 + .bInterfaceSubClass = USB_SUBCLASS_MIDISTREAMING, 298 + .bInterfaceProtocol = 0, 299 + .iInterface = 0, // to be filled 300 + }; 301 + 302 + static struct usb_ms_header_descriptor midi2_midi2_class_desc = { 303 + .bLength = 0x07, 304 + .bDescriptorType = USB_DT_CS_INTERFACE, 305 + .bDescriptorSubtype = USB_MS_HEADER, 306 + .bcdMSC = __cpu_to_le16(0x0200), 307 + .wTotalLength = __cpu_to_le16(0x07), 308 + }; 309 + 310 + /* MIDI 2.0 EP OUT */ 311 + static struct usb_endpoint_descriptor midi2_midi2_ep_out_desc[MAX_UMP_EPS]; 312 + 313 + static struct usb_ss_ep_comp_descriptor midi2_midi2_ep_out_ss_comp_desc = { 314 + .bLength = sizeof(midi2_midi1_ep_out_ss_comp_desc), 315 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 316 + }; 317 + 318 + static struct usb_ms20_endpoint_descriptor_32 midi2_midi2_ep_out_class_desc[MAX_UMP_EPS]; 319 + 320 + /* MIDI 2.0 EP IN */ 321 + static struct usb_endpoint_descriptor midi2_midi2_ep_in_desc[MAX_UMP_EPS]; 322 + 323 + static struct usb_ss_ep_comp_descriptor midi2_midi2_ep_in_ss_comp_desc = { 324 + .bLength = sizeof(midi2_midi2_ep_in_ss_comp_desc), 325 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 326 + }; 327 + 328 + static struct usb_ms20_endpoint_descriptor_32 midi2_midi2_ep_in_class_desc[MAX_UMP_EPS]; 329 + 330 + /* Arrays of descriptors to be created */ 331 + static void *midi2_audio_descs[] = { 332 + &midi2_audio_if_desc, 333 + &midi2_audio_class_desc, 334 + NULL 335 + }; 336 + 337 + static void *midi2_midi1_descs[] = { 338 + &midi2_midi1_if_desc, 339 + &midi2_midi1_class_desc, 340 + NULL 341 + }; 342 + 343 + static void *midi2_midi1_ep_out_descs[] = { 344 + &midi2_midi1_ep_out_desc, 345 + &midi2_midi1_ep_out_class_desc, 346 + NULL 347 + }; 348 + 349 + static void *midi2_midi1_ep_in_descs[] = { 350 + &midi2_midi1_ep_in_desc, 351 + &midi2_midi1_ep_in_class_desc, 352 + NULL 353 + }; 354 + 355 + static void *midi2_midi1_ep_out_ss_descs[] = { 356 + &midi2_midi1_ep_out_desc, 357 + &midi2_midi1_ep_out_ss_comp_desc, 358 + &midi2_midi1_ep_out_class_desc, 359 + NULL 360 + }; 361 + 362 + static void *midi2_midi1_ep_in_ss_descs[] = { 363 + &midi2_midi1_ep_in_desc, 364 + &midi2_midi1_ep_in_ss_comp_desc, 365 + &midi2_midi1_ep_in_class_desc, 366 + NULL 367 + }; 368 + 369 + static void *midi2_midi2_descs[] = { 370 + &midi2_midi2_if_desc, 371 + &midi2_midi2_class_desc, 372 + NULL 373 + }; 374 + 375 + /* 376 + * USB request handling 377 + */ 378 + 379 + /* get an empty request for the given EP */ 380 + static struct usb_request *get_empty_request(struct f_midi2_usb_ep *usb_ep) 381 + { 382 + struct usb_request *req = NULL; 383 + unsigned long flags; 384 + int index; 385 + 386 + spin_lock_irqsave(&usb_ep->card->queue_lock, flags); 387 + if (!usb_ep->free_reqs) 388 + goto unlock; 389 + index = find_first_bit(&usb_ep->free_reqs, usb_ep->num_reqs); 390 + if (index >= usb_ep->num_reqs) 391 + goto unlock; 392 + req = usb_ep->reqs[index].req; 393 + if (!req) 394 + goto unlock; 395 + clear_bit(index, &usb_ep->free_reqs); 396 + req->length = 0; 397 + unlock: 398 + spin_unlock_irqrestore(&usb_ep->card->queue_lock, flags); 399 + return req; 400 + } 401 + 402 + /* put the empty request back */ 403 + static void put_empty_request(struct usb_request *req) 404 + { 405 + struct f_midi2_req_ctx *ctx = req->context; 406 + unsigned long flags; 407 + 408 + spin_lock_irqsave(&ctx->usb_ep->card->queue_lock, flags); 409 + set_bit(ctx->index, &ctx->usb_ep->free_reqs); 410 + spin_unlock_irqrestore(&ctx->usb_ep->card->queue_lock, flags); 411 + } 412 + 413 + /* 414 + * UMP v1.1 Stream message handling 415 + */ 416 + 417 + /* queue a request to UMP EP; request is either queued or freed after this */ 418 + static int queue_request_ep_raw(struct usb_request *req) 419 + { 420 + struct f_midi2_req_ctx *ctx = req->context; 421 + int err; 422 + 423 + req->complete = ctx->usb_ep->complete; 424 + err = usb_ep_queue(ctx->usb_ep->usb_ep, req, GFP_ATOMIC); 425 + if (err) { 426 + put_empty_request(req); 427 + return err; 428 + } 429 + return 0; 430 + } 431 + 432 + /* queue a request with endianness conversion */ 433 + static int queue_request_ep_in(struct usb_request *req) 434 + { 435 + /* UMP packets have to be converted to little-endian */ 436 + cpu_to_le32_array((u32 *)req->buf, req->length >> 2); 437 + return queue_request_ep_raw(req); 438 + } 439 + 440 + /* reply a UMP packet via EP-in */ 441 + static int reply_ep_in(struct f_midi2_ep *ep, const void *buf, int len) 442 + { 443 + struct f_midi2_usb_ep *usb_ep = &ep->ep_in; 444 + struct usb_request *req; 445 + 446 + req = get_empty_request(usb_ep); 447 + if (!req) 448 + return -ENOSPC; 449 + 450 + req->length = len; 451 + memcpy(req->buf, buf, len); 452 + return queue_request_ep_in(req); 453 + } 454 + 455 + /* reply a UMP stream EP info */ 456 + static void reply_ump_stream_ep_info(struct f_midi2_ep *ep) 457 + { 458 + struct snd_ump_stream_msg_ep_info rep = { 459 + .type = UMP_MSG_TYPE_STREAM, 460 + .status = UMP_STREAM_MSG_STATUS_EP_INFO, 461 + .ump_version_major = 0x01, 462 + .ump_version_minor = 0x01, 463 + .num_function_blocks = ep->num_blks, 464 + .static_function_block = !!ep->card->info.static_block, 465 + .protocol = (UMP_STREAM_MSG_EP_INFO_CAP_MIDI1 | 466 + UMP_STREAM_MSG_EP_INFO_CAP_MIDI2) >> 8, 467 + }; 468 + 469 + reply_ep_in(ep, &rep, sizeof(rep)); 470 + } 471 + 472 + /* reply a UMP EP device info */ 473 + static void reply_ump_stream_ep_device(struct f_midi2_ep *ep) 474 + { 475 + struct snd_ump_stream_msg_devince_info rep = { 476 + .type = UMP_MSG_TYPE_STREAM, 477 + .status = UMP_STREAM_MSG_STATUS_DEVICE_INFO, 478 + .manufacture_id = ep->info.manufacturer, 479 + .family_lsb = ep->info.family & 0xff, 480 + .family_msb = (ep->info.family >> 8) & 0xff, 481 + .model_lsb = ep->info.model & 0xff, 482 + .model_msb = (ep->info.model >> 8) & 0xff, 483 + .sw_revision = ep->info.sw_revision, 484 + }; 485 + 486 + reply_ep_in(ep, &rep, sizeof(rep)); 487 + } 488 + 489 + #define UMP_STREAM_PKT_BYTES 16 /* UMP stream packet size = 16 bytes*/ 490 + #define UMP_STREAM_EP_STR_OFF 2 /* offset of name string for EP info */ 491 + #define UMP_STREAM_FB_STR_OFF 3 /* offset of name string for FB info */ 492 + 493 + /* Helper to replay a string */ 494 + static void reply_ump_stream_string(struct f_midi2_ep *ep, const u8 *name, 495 + unsigned int type, unsigned int extra, 496 + unsigned int start_ofs) 497 + { 498 + struct f_midi2_usb_ep *usb_ep = &ep->ep_in; 499 + struct f_midi2 *midi2 = ep->card; 500 + struct usb_request *req; 501 + unsigned int pos; 502 + u32 *buf; 503 + 504 + if (!*name) 505 + return; 506 + req = get_empty_request(usb_ep); 507 + if (!req) 508 + return; 509 + 510 + buf = (u32 *)req->buf; 511 + pos = start_ofs; 512 + for (;;) { 513 + if (pos == start_ofs) { 514 + memset(buf, 0, UMP_STREAM_PKT_BYTES); 515 + buf[0] = ump_stream_compose(type, 0) | extra; 516 + } 517 + buf[pos / 4] |= *name++ << ((3 - (pos % 4)) * 8); 518 + if (!*name) { 519 + if (req->length) 520 + buf[0] |= UMP_STREAM_MSG_FORMAT_END << 26; 521 + req->length += UMP_STREAM_PKT_BYTES; 522 + break; 523 + } 524 + if (++pos == UMP_STREAM_PKT_BYTES) { 525 + if (!req->length) 526 + buf[0] |= UMP_STREAM_MSG_FORMAT_START << 26; 527 + else 528 + buf[0] |= UMP_STREAM_MSG_FORMAT_CONTINUE << 26; 529 + req->length += UMP_STREAM_PKT_BYTES; 530 + if (midi2->info.req_buf_size - req->length < UMP_STREAM_PKT_BYTES) 531 + break; 532 + buf += 4; 533 + pos = start_ofs; 534 + } 535 + } 536 + 537 + if (req->length) 538 + queue_request_ep_in(req); 539 + else 540 + put_empty_request(req); 541 + } 542 + 543 + /* Reply a UMP EP name string */ 544 + static void reply_ump_stream_ep_name(struct f_midi2_ep *ep) 545 + { 546 + reply_ump_stream_string(ep, ump_ep_name(ep), 547 + UMP_STREAM_MSG_STATUS_EP_NAME, 0, 548 + UMP_STREAM_EP_STR_OFF); 549 + } 550 + 551 + /* Reply a UMP EP product ID string */ 552 + static void reply_ump_stream_ep_pid(struct f_midi2_ep *ep) 553 + { 554 + reply_ump_stream_string(ep, ump_product_id(ep), 555 + UMP_STREAM_MSG_STATUS_PRODUCT_ID, 0, 556 + UMP_STREAM_EP_STR_OFF); 557 + } 558 + 559 + /* Reply a UMP EP stream config */ 560 + static void reply_ump_stream_ep_config(struct f_midi2_ep *ep) 561 + { 562 + struct snd_ump_stream_msg_stream_cfg rep = { 563 + .type = UMP_MSG_TYPE_STREAM, 564 + .status = UMP_STREAM_MSG_STATUS_STREAM_CFG, 565 + }; 566 + 567 + if ((ep->info.protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI_MASK) == 568 + SNDRV_UMP_EP_INFO_PROTO_MIDI2) 569 + rep.protocol = UMP_STREAM_MSG_EP_INFO_CAP_MIDI2 >> 8; 570 + else 571 + rep.protocol = UMP_STREAM_MSG_EP_INFO_CAP_MIDI1 >> 8; 572 + 573 + reply_ep_in(ep, &rep, sizeof(rep)); 574 + } 575 + 576 + /* Reply a UMP FB info */ 577 + static void reply_ump_stream_fb_info(struct f_midi2_ep *ep, int blk) 578 + { 579 + struct f_midi2_block_info *b = &ep->blks[blk].info; 580 + struct snd_ump_stream_msg_fb_info rep = { 581 + .type = UMP_MSG_TYPE_STREAM, 582 + .status = UMP_STREAM_MSG_STATUS_FB_INFO, 583 + .active = !!b->active, 584 + .function_block_id = blk, 585 + .ui_hint = b->ui_hint, 586 + .midi_10 = b->is_midi1, 587 + .direction = b->direction, 588 + .first_group = b->first_group, 589 + .num_groups = b->num_groups, 590 + .midi_ci_version = b->midi_ci_version, 591 + .sysex8_streams = b->sysex8_streams, 592 + }; 593 + 594 + reply_ep_in(ep, &rep, sizeof(rep)); 595 + } 596 + 597 + /* Reply a FB name string */ 598 + static void reply_ump_stream_fb_name(struct f_midi2_ep *ep, unsigned int blk) 599 + { 600 + reply_ump_stream_string(ep, ump_fb_name(&ep->blks[blk].info), 601 + UMP_STREAM_MSG_STATUS_FB_NAME, blk << 8, 602 + UMP_STREAM_FB_STR_OFF); 603 + } 604 + 605 + /* Process a UMP Stream message */ 606 + static void process_ump_stream_msg(struct f_midi2_ep *ep, const u32 *data) 607 + { 608 + struct f_midi2 *midi2 = ep->card; 609 + unsigned int format, status, blk; 610 + 611 + format = ump_stream_message_format(*data); 612 + status = ump_stream_message_status(*data); 613 + switch (status) { 614 + case UMP_STREAM_MSG_STATUS_EP_DISCOVERY: 615 + if (format) 616 + return; // invalid 617 + if (data[1] & UMP_STREAM_MSG_REQUEST_EP_INFO) 618 + reply_ump_stream_ep_info(ep); 619 + if (data[1] & UMP_STREAM_MSG_REQUEST_DEVICE_INFO) 620 + reply_ump_stream_ep_device(ep); 621 + if (data[1] & UMP_STREAM_MSG_REQUEST_EP_NAME) 622 + reply_ump_stream_ep_name(ep); 623 + if (data[1] & UMP_STREAM_MSG_REQUEST_PRODUCT_ID) 624 + reply_ump_stream_ep_pid(ep); 625 + if (data[1] & UMP_STREAM_MSG_REQUEST_STREAM_CFG) 626 + reply_ump_stream_ep_config(ep); 627 + return; 628 + case UMP_STREAM_MSG_STATUS_STREAM_CFG_REQUEST: 629 + if (*data & UMP_STREAM_MSG_EP_INFO_CAP_MIDI2) { 630 + ep->info.protocol = SNDRV_UMP_EP_INFO_PROTO_MIDI2; 631 + DBG(midi2, "Switching Protocol to MIDI2\n"); 632 + } else { 633 + ep->info.protocol = SNDRV_UMP_EP_INFO_PROTO_MIDI1; 634 + DBG(midi2, "Switching Protocol to MIDI1\n"); 635 + } 636 + snd_ump_switch_protocol(ep->ump, ep->info.protocol); 637 + reply_ump_stream_ep_config(ep); 638 + return; 639 + case UMP_STREAM_MSG_STATUS_FB_DISCOVERY: 640 + if (format) 641 + return; // invalid 642 + blk = (*data >> 8) & 0xff; 643 + if (blk >= ep->num_blks) 644 + return; 645 + if (*data & UMP_STREAM_MSG_REQUEST_FB_INFO) 646 + reply_ump_stream_fb_info(ep, blk); 647 + if (*data & UMP_STREAM_MSG_REQUEST_FB_NAME) 648 + reply_ump_stream_fb_name(ep, blk); 649 + return; 650 + } 651 + } 652 + 653 + /* Process UMP messages included in a USB request */ 654 + static void process_ump(struct f_midi2_ep *ep, const struct usb_request *req) 655 + { 656 + const u32 *data = (u32 *)req->buf; 657 + int len = req->actual >> 2; 658 + const u32 *in_buf = ep->ump->input_buf; 659 + 660 + for (; len > 0; len--, data++) { 661 + if (snd_ump_receive_ump_val(ep->ump, *data) <= 0) 662 + continue; 663 + if (ump_message_type(*in_buf) == UMP_MSG_TYPE_STREAM) 664 + process_ump_stream_msg(ep, in_buf); 665 + } 666 + } 667 + 668 + /* 669 + * MIDI 2.0 UMP USB request handling 670 + */ 671 + 672 + /* complete handler for UMP EP-out requests */ 673 + static void f_midi2_ep_out_complete(struct usb_ep *usb_ep, 674 + struct usb_request *req) 675 + { 676 + struct f_midi2_req_ctx *ctx = req->context; 677 + struct f_midi2_ep *ep = ctx->usb_ep->ep; 678 + struct f_midi2 *midi2 = ep->card; 679 + int status = req->status; 680 + 681 + if (status) { 682 + DBG(midi2, "%s complete error %d: %d/%d\n", 683 + usb_ep->name, status, req->actual, req->length); 684 + goto error; 685 + } 686 + 687 + /* convert to UMP packet in native endianness */ 688 + le32_to_cpu_array((u32 *)req->buf, req->actual >> 2); 689 + 690 + if (midi2->info.process_ump) 691 + process_ump(ep, req); 692 + 693 + snd_ump_receive(ep->ump, req->buf, req->actual & ~3); 694 + 695 + if (midi2->operation_mode != MIDI_OP_MODE_MIDI2) 696 + goto error; 697 + 698 + if (queue_request_ep_raw(req)) 699 + goto error; 700 + return; 701 + 702 + error: 703 + put_empty_request(req); 704 + } 705 + 706 + /* Transmit UMP packets received from user-space to the gadget */ 707 + static void process_ump_transmit(struct f_midi2_ep *ep) 708 + { 709 + struct f_midi2_usb_ep *usb_ep = &ep->ep_in; 710 + struct f_midi2 *midi2 = ep->card; 711 + struct usb_request *req; 712 + int len; 713 + 714 + if (!usb_ep->usb_ep->enabled) 715 + return; 716 + 717 + for (;;) { 718 + req = get_empty_request(usb_ep); 719 + if (!req) 720 + break; 721 + len = snd_ump_transmit(ep->ump, (u32 *)req->buf, 722 + midi2->info.req_buf_size); 723 + if (len <= 0) { 724 + put_empty_request(req); 725 + break; 726 + } 727 + 728 + req->length = len; 729 + if (queue_request_ep_in(req) < 0) 730 + break; 731 + } 732 + } 733 + 734 + /* Complete handler for UMP EP-in requests */ 735 + static void f_midi2_ep_in_complete(struct usb_ep *usb_ep, 736 + struct usb_request *req) 737 + { 738 + struct f_midi2_req_ctx *ctx = req->context; 739 + struct f_midi2_ep *ep = ctx->usb_ep->ep; 740 + struct f_midi2 *midi2 = ep->card; 741 + int status = req->status; 742 + 743 + put_empty_request(req); 744 + 745 + if (status) { 746 + DBG(midi2, "%s complete error %d: %d/%d\n", 747 + usb_ep->name, status, req->actual, req->length); 748 + return; 749 + } 750 + 751 + process_ump_transmit(ep); 752 + } 753 + 754 + /* 755 + * MIDI1 (altset 0) USB request handling 756 + */ 757 + 758 + /* process one MIDI byte -- copied from f_midi.c 759 + * 760 + * fill the packet or request if needed 761 + * returns true if the request became empty (queued) 762 + */ 763 + static bool process_midi1_byte(struct f_midi2 *midi2, u8 cable, u8 b, 764 + struct usb_request **req_p) 765 + { 766 + struct f_midi2_midi1_port *port = &midi2->midi1_port[cable]; 767 + u8 p[4] = { cable << 4, 0, 0, 0 }; 768 + int next_state = STATE_INITIAL; 769 + struct usb_request *req = *req_p; 770 + 771 + switch (b) { 772 + case 0xf8 ... 0xff: 773 + /* System Real-Time Messages */ 774 + p[0] |= 0x0f; 775 + p[1] = b; 776 + next_state = port->state; 777 + port->state = STATE_REAL_TIME; 778 + break; 779 + 780 + case 0xf7: 781 + /* End of SysEx */ 782 + switch (port->state) { 783 + case STATE_SYSEX_0: 784 + p[0] |= 0x05; 785 + p[1] = 0xf7; 786 + next_state = STATE_FINISHED; 787 + break; 788 + case STATE_SYSEX_1: 789 + p[0] |= 0x06; 790 + p[1] = port->data[0]; 791 + p[2] = 0xf7; 792 + next_state = STATE_FINISHED; 793 + break; 794 + case STATE_SYSEX_2: 795 + p[0] |= 0x07; 796 + p[1] = port->data[0]; 797 + p[2] = port->data[1]; 798 + p[3] = 0xf7; 799 + next_state = STATE_FINISHED; 800 + break; 801 + default: 802 + /* Ignore byte */ 803 + next_state = port->state; 804 + port->state = STATE_INITIAL; 805 + } 806 + break; 807 + 808 + case 0xf0 ... 0xf6: 809 + /* System Common Messages */ 810 + port->data[0] = port->data[1] = 0; 811 + port->state = STATE_INITIAL; 812 + switch (b) { 813 + case 0xf0: 814 + port->data[0] = b; 815 + port->data[1] = 0; 816 + next_state = STATE_SYSEX_1; 817 + break; 818 + case 0xf1: 819 + case 0xf3: 820 + port->data[0] = b; 821 + next_state = STATE_1PARAM; 822 + break; 823 + case 0xf2: 824 + port->data[0] = b; 825 + next_state = STATE_2PARAM_1; 826 + break; 827 + case 0xf4: 828 + case 0xf5: 829 + next_state = STATE_INITIAL; 830 + break; 831 + case 0xf6: 832 + p[0] |= 0x05; 833 + p[1] = 0xf6; 834 + next_state = STATE_FINISHED; 835 + break; 836 + } 837 + break; 838 + 839 + case 0x80 ... 0xef: 840 + /* 841 + * Channel Voice Messages, Channel Mode Messages 842 + * and Control Change Messages. 843 + */ 844 + port->data[0] = b; 845 + port->data[1] = 0; 846 + port->state = STATE_INITIAL; 847 + if (b >= 0xc0 && b <= 0xdf) 848 + next_state = STATE_1PARAM; 849 + else 850 + next_state = STATE_2PARAM_1; 851 + break; 852 + 853 + case 0x00 ... 0x7f: 854 + /* Message parameters */ 855 + switch (port->state) { 856 + case STATE_1PARAM: 857 + if (port->data[0] < 0xf0) 858 + p[0] |= port->data[0] >> 4; 859 + else 860 + p[0] |= 0x02; 861 + 862 + p[1] = port->data[0]; 863 + p[2] = b; 864 + /* This is to allow Running State Messages */ 865 + next_state = STATE_1PARAM; 866 + break; 867 + case STATE_2PARAM_1: 868 + port->data[1] = b; 869 + next_state = STATE_2PARAM_2; 870 + break; 871 + case STATE_2PARAM_2: 872 + if (port->data[0] < 0xf0) 873 + p[0] |= port->data[0] >> 4; 874 + else 875 + p[0] |= 0x03; 876 + 877 + p[1] = port->data[0]; 878 + p[2] = port->data[1]; 879 + p[3] = b; 880 + /* This is to allow Running State Messages */ 881 + next_state = STATE_2PARAM_1; 882 + break; 883 + case STATE_SYSEX_0: 884 + port->data[0] = b; 885 + next_state = STATE_SYSEX_1; 886 + break; 887 + case STATE_SYSEX_1: 888 + port->data[1] = b; 889 + next_state = STATE_SYSEX_2; 890 + break; 891 + case STATE_SYSEX_2: 892 + p[0] |= 0x04; 893 + p[1] = port->data[0]; 894 + p[2] = port->data[1]; 895 + p[3] = b; 896 + next_state = STATE_SYSEX_0; 897 + break; 898 + } 899 + break; 900 + } 901 + 902 + /* States where we have to write into the USB request */ 903 + if (next_state == STATE_FINISHED || 904 + port->state == STATE_SYSEX_2 || 905 + port->state == STATE_1PARAM || 906 + port->state == STATE_2PARAM_2 || 907 + port->state == STATE_REAL_TIME) { 908 + memcpy(req->buf + req->length, p, sizeof(p)); 909 + req->length += sizeof(p); 910 + 911 + if (next_state == STATE_FINISHED) { 912 + next_state = STATE_INITIAL; 913 + port->data[0] = port->data[1] = 0; 914 + } 915 + 916 + if (midi2->info.req_buf_size - req->length <= 4) { 917 + queue_request_ep_raw(req); 918 + *req_p = NULL; 919 + return true; 920 + } 921 + } 922 + 923 + port->state = next_state; 924 + return false; 925 + } 926 + 927 + /* process all pending MIDI bytes in the internal buffer; 928 + * returns true if the request gets empty 929 + * returns false if all have been processed 930 + */ 931 + static bool process_midi1_pending_buf(struct f_midi2 *midi2, 932 + struct usb_request **req_p) 933 + { 934 + unsigned int cable, c; 935 + 936 + for (cable = 0; cable < midi2->num_midi1_in; cable++) { 937 + struct f_midi2_midi1_port *port = &midi2->midi1_port[cable]; 938 + 939 + if (!port->pending) 940 + continue; 941 + for (c = 0; c < port->pending; c++) { 942 + if (process_midi1_byte(midi2, cable, port->buf[c], 943 + req_p)) { 944 + port->pending -= c; 945 + if (port->pending) 946 + memmove(port->buf, port->buf + c, 947 + port->pending); 948 + return true; 949 + } 950 + } 951 + port->pending = 0; 952 + } 953 + 954 + return false; 955 + } 956 + 957 + /* fill the MIDI bytes onto the temporary buffer 958 + */ 959 + static void fill_midi1_pending_buf(struct f_midi2 *midi2, u8 cable, u8 *buf, 960 + unsigned int size) 961 + { 962 + struct f_midi2_midi1_port *port = &midi2->midi1_port[cable]; 963 + 964 + if (port->pending + size > sizeof(port->buf)) 965 + return; 966 + memcpy(port->buf + port->pending, buf, size); 967 + port->pending += size; 968 + } 969 + 970 + /* try to process data given from the associated UMP stream */ 971 + static void process_midi1_transmit(struct f_midi2 *midi2) 972 + { 973 + struct f_midi2_usb_ep *usb_ep = &midi2->midi1_ep_in; 974 + struct f_midi2_ep *ep = &midi2->midi2_eps[0]; 975 + struct usb_request *req = NULL; 976 + /* 12 is the largest outcome (4 MIDI1 cmds) for a single UMP packet */ 977 + unsigned char outbuf[12]; 978 + unsigned char group, cable; 979 + int len, size; 980 + u32 ump; 981 + 982 + if (!usb_ep->usb_ep || !usb_ep->usb_ep->enabled) 983 + return; 984 + 985 + for (;;) { 986 + if (!req) { 987 + req = get_empty_request(usb_ep); 988 + if (!req) 989 + break; 990 + } 991 + 992 + if (process_midi1_pending_buf(midi2, &req)) 993 + continue; 994 + 995 + len = snd_ump_transmit(ep->ump, &ump, 4); 996 + if (len <= 0) 997 + break; 998 + if (snd_ump_receive_ump_val(ep->ump, ump) <= 0) 999 + continue; 1000 + size = snd_ump_convert_from_ump(ep->ump->input_buf, outbuf, 1001 + &group); 1002 + if (size <= 0) 1003 + continue; 1004 + cable = ep->in_group_to_cable[group]; 1005 + if (!cable) 1006 + continue; 1007 + cable--; /* to 0-base */ 1008 + fill_midi1_pending_buf(midi2, cable, outbuf, size); 1009 + } 1010 + 1011 + if (req) { 1012 + if (req->length) 1013 + queue_request_ep_raw(req); 1014 + else 1015 + put_empty_request(req); 1016 + } 1017 + } 1018 + 1019 + /* complete handler for MIDI1 EP-in requests */ 1020 + static void f_midi2_midi1_ep_in_complete(struct usb_ep *usb_ep, 1021 + struct usb_request *req) 1022 + { 1023 + struct f_midi2_req_ctx *ctx = req->context; 1024 + struct f_midi2 *midi2 = ctx->usb_ep->card; 1025 + int status = req->status; 1026 + 1027 + put_empty_request(req); 1028 + 1029 + if (status) { 1030 + DBG(midi2, "%s complete error %d: %d/%d\n", 1031 + usb_ep->name, status, req->actual, req->length); 1032 + return; 1033 + } 1034 + 1035 + process_midi1_transmit(midi2); 1036 + } 1037 + 1038 + /* complete handler for MIDI1 EP-out requests */ 1039 + static void f_midi2_midi1_ep_out_complete(struct usb_ep *usb_ep, 1040 + struct usb_request *req) 1041 + { 1042 + struct f_midi2_req_ctx *ctx = req->context; 1043 + struct f_midi2 *midi2 = ctx->usb_ep->card; 1044 + struct f_midi2_ep *ep; 1045 + struct ump_cvt_to_ump *cvt = &midi2->midi1_ump_cvt; 1046 + static const u8 midi1_packet_bytes[16] = { 1047 + 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1 1048 + }; 1049 + unsigned int group, cable, bytes, c, len; 1050 + int status = req->status; 1051 + const u8 *buf = req->buf; 1052 + 1053 + if (status) { 1054 + DBG(midi2, "%s complete error %d: %d/%d\n", 1055 + usb_ep->name, status, req->actual, req->length); 1056 + goto error; 1057 + } 1058 + 1059 + len = req->actual >> 2; 1060 + for (; len; len--, buf += 4) { 1061 + cable = *buf >> 4; 1062 + ep = midi2->out_cable_mapping[cable].ep; 1063 + if (!ep) 1064 + continue; 1065 + group = midi2->out_cable_mapping[cable].group; 1066 + bytes = midi1_packet_bytes[*buf & 0x0f]; 1067 + for (c = 0; c < bytes; c++) { 1068 + snd_ump_convert_to_ump(cvt, group, ep->info.protocol, 1069 + buf[c + 1]); 1070 + if (cvt->ump_bytes) { 1071 + snd_ump_receive(ep->ump, cvt->ump, 1072 + cvt->ump_bytes); 1073 + cvt->ump_bytes = 0; 1074 + } 1075 + } 1076 + } 1077 + 1078 + if (midi2->operation_mode != MIDI_OP_MODE_MIDI1) 1079 + goto error; 1080 + 1081 + if (queue_request_ep_raw(req)) 1082 + goto error; 1083 + return; 1084 + 1085 + error: 1086 + put_empty_request(req); 1087 + } 1088 + 1089 + /* 1090 + * Common EP handling helpers 1091 + */ 1092 + 1093 + /* Start MIDI EP */ 1094 + static int f_midi2_start_ep(struct f_midi2_usb_ep *usb_ep, 1095 + struct usb_function *fn) 1096 + { 1097 + int err; 1098 + 1099 + if (!usb_ep->usb_ep) 1100 + return 0; 1101 + 1102 + usb_ep_disable(usb_ep->usb_ep); 1103 + err = config_ep_by_speed(usb_ep->card->gadget, fn, usb_ep->usb_ep); 1104 + if (err) 1105 + return err; 1106 + return usb_ep_enable(usb_ep->usb_ep); 1107 + } 1108 + 1109 + /* Drop pending requests */ 1110 + static void f_midi2_drop_reqs(struct f_midi2_usb_ep *usb_ep) 1111 + { 1112 + int i; 1113 + 1114 + if (!usb_ep->usb_ep || !usb_ep->num_reqs) 1115 + return; 1116 + 1117 + for (i = 0; i < usb_ep->num_reqs; i++) { 1118 + if (!test_bit(i, &usb_ep->free_reqs) && usb_ep->reqs[i].req) { 1119 + usb_ep_dequeue(usb_ep->usb_ep, usb_ep->reqs[i].req); 1120 + set_bit(i, &usb_ep->free_reqs); 1121 + } 1122 + } 1123 + } 1124 + 1125 + /* Allocate requests for the given EP */ 1126 + static int f_midi2_alloc_ep_reqs(struct f_midi2_usb_ep *usb_ep) 1127 + { 1128 + struct f_midi2 *midi2 = usb_ep->card; 1129 + int i; 1130 + 1131 + if (!usb_ep->usb_ep) 1132 + return 0; 1133 + if (!usb_ep->reqs) 1134 + return -EINVAL; 1135 + 1136 + for (i = 0; i < midi2->info.num_reqs; i++) { 1137 + if (usb_ep->reqs[i].req) 1138 + continue; 1139 + usb_ep->reqs[i].req = alloc_ep_req(usb_ep->usb_ep, 1140 + midi2->info.req_buf_size); 1141 + if (!usb_ep->reqs[i].req) 1142 + return -ENOMEM; 1143 + usb_ep->reqs[i].req->context = &usb_ep->reqs[i]; 1144 + } 1145 + return 0; 1146 + } 1147 + 1148 + /* Free allocated requests */ 1149 + static void f_midi2_free_ep_reqs(struct f_midi2_usb_ep *usb_ep) 1150 + { 1151 + struct f_midi2 *midi2 = usb_ep->card; 1152 + int i; 1153 + 1154 + for (i = 0; i < midi2->info.num_reqs; i++) { 1155 + if (!usb_ep->reqs[i].req) 1156 + continue; 1157 + free_ep_req(usb_ep->usb_ep, usb_ep->reqs[i].req); 1158 + usb_ep->reqs[i].req = NULL; 1159 + } 1160 + } 1161 + 1162 + /* Initialize EP */ 1163 + static int f_midi2_init_ep(struct f_midi2 *midi2, struct f_midi2_ep *ep, 1164 + struct f_midi2_usb_ep *usb_ep, 1165 + void *desc, 1166 + void (*complete)(struct usb_ep *usb_ep, 1167 + struct usb_request *req)) 1168 + { 1169 + int i; 1170 + 1171 + usb_ep->card = midi2; 1172 + usb_ep->ep = ep; 1173 + usb_ep->usb_ep = usb_ep_autoconfig(midi2->gadget, desc); 1174 + if (!usb_ep->usb_ep) 1175 + return -ENODEV; 1176 + usb_ep->complete = complete; 1177 + 1178 + usb_ep->reqs = kcalloc(midi2->info.num_reqs, sizeof(*usb_ep->reqs), 1179 + GFP_KERNEL); 1180 + if (!usb_ep->reqs) 1181 + return -ENOMEM; 1182 + for (i = 0; i < midi2->info.num_reqs; i++) { 1183 + usb_ep->reqs[i].index = i; 1184 + usb_ep->reqs[i].usb_ep = usb_ep; 1185 + set_bit(i, &usb_ep->free_reqs); 1186 + usb_ep->num_reqs++; 1187 + } 1188 + 1189 + return 0; 1190 + } 1191 + 1192 + /* Free EP */ 1193 + static void f_midi2_free_ep(struct f_midi2_usb_ep *usb_ep) 1194 + { 1195 + f_midi2_drop_reqs(usb_ep); 1196 + 1197 + f_midi2_free_ep_reqs(usb_ep); 1198 + 1199 + kfree(usb_ep->reqs); 1200 + usb_ep->num_reqs = 0; 1201 + usb_ep->free_reqs = 0; 1202 + usb_ep->reqs = NULL; 1203 + } 1204 + 1205 + /* Queue requests for EP-out at start */ 1206 + static void f_midi2_queue_out_reqs(struct f_midi2_usb_ep *usb_ep) 1207 + { 1208 + int i, err; 1209 + 1210 + if (!usb_ep->usb_ep) 1211 + return; 1212 + 1213 + for (i = 0; i < usb_ep->num_reqs; i++) { 1214 + if (!test_bit(i, &usb_ep->free_reqs) || !usb_ep->reqs[i].req) 1215 + continue; 1216 + usb_ep->reqs[i].req->complete = usb_ep->complete; 1217 + err = usb_ep_queue(usb_ep->usb_ep, usb_ep->reqs[i].req, 1218 + GFP_ATOMIC); 1219 + if (!err) 1220 + clear_bit(i, &usb_ep->free_reqs); 1221 + } 1222 + } 1223 + 1224 + /* 1225 + * Gadget Function callbacks 1226 + */ 1227 + 1228 + /* stop both IN and OUT EPs */ 1229 + static void f_midi2_stop_eps(struct f_midi2_usb_ep *ep_in, 1230 + struct f_midi2_usb_ep *ep_out) 1231 + { 1232 + f_midi2_drop_reqs(ep_in); 1233 + f_midi2_drop_reqs(ep_out); 1234 + f_midi2_free_ep_reqs(ep_in); 1235 + f_midi2_free_ep_reqs(ep_out); 1236 + } 1237 + 1238 + /* start/queue both IN and OUT EPs */ 1239 + static int f_midi2_start_eps(struct f_midi2_usb_ep *ep_in, 1240 + struct f_midi2_usb_ep *ep_out, 1241 + struct usb_function *fn) 1242 + { 1243 + int err; 1244 + 1245 + err = f_midi2_start_ep(ep_in, fn); 1246 + if (err) 1247 + return err; 1248 + err = f_midi2_start_ep(ep_out, fn); 1249 + if (err) 1250 + return err; 1251 + 1252 + err = f_midi2_alloc_ep_reqs(ep_in); 1253 + if (err) 1254 + return err; 1255 + err = f_midi2_alloc_ep_reqs(ep_out); 1256 + if (err) 1257 + return err; 1258 + 1259 + f_midi2_queue_out_reqs(ep_out); 1260 + return 0; 1261 + } 1262 + 1263 + /* gadget function set_alt callback */ 1264 + static int f_midi2_set_alt(struct usb_function *fn, unsigned int intf, 1265 + unsigned int alt) 1266 + { 1267 + struct f_midi2 *midi2 = func_to_midi2(fn); 1268 + struct f_midi2_ep *ep; 1269 + int i, op_mode, err; 1270 + 1271 + if (intf != midi2->midi_if || alt > 1) 1272 + return 0; 1273 + 1274 + if (alt == 0) 1275 + op_mode = MIDI_OP_MODE_MIDI1; 1276 + else if (alt == 1) 1277 + op_mode = MIDI_OP_MODE_MIDI2; 1278 + else 1279 + op_mode = MIDI_OP_MODE_UNSET; 1280 + 1281 + if (midi2->operation_mode == op_mode) 1282 + return 0; 1283 + 1284 + midi2->operation_mode = op_mode; 1285 + 1286 + if (op_mode != MIDI_OP_MODE_MIDI1) 1287 + f_midi2_stop_eps(&midi2->midi1_ep_in, &midi2->midi1_ep_out); 1288 + 1289 + if (op_mode != MIDI_OP_MODE_MIDI2) { 1290 + for (i = 0; i < midi2->num_eps; i++) { 1291 + ep = &midi2->midi2_eps[i]; 1292 + f_midi2_stop_eps(&ep->ep_in, &ep->ep_out); 1293 + } 1294 + } 1295 + 1296 + if (op_mode == MIDI_OP_MODE_MIDI1) 1297 + return f_midi2_start_eps(&midi2->midi1_ep_in, 1298 + &midi2->midi1_ep_out, fn); 1299 + 1300 + if (op_mode == MIDI_OP_MODE_MIDI2) { 1301 + for (i = 0; i < midi2->num_eps; i++) { 1302 + ep = &midi2->midi2_eps[i]; 1303 + 1304 + err = f_midi2_start_eps(&ep->ep_in, &ep->ep_out, fn); 1305 + if (err) 1306 + return err; 1307 + } 1308 + } 1309 + 1310 + return 0; 1311 + } 1312 + 1313 + /* gadget function get_alt callback */ 1314 + static int f_midi2_get_alt(struct usb_function *fn, unsigned int intf) 1315 + { 1316 + struct f_midi2 *midi2 = func_to_midi2(fn); 1317 + 1318 + if (intf == midi2->midi_if && 1319 + midi2->operation_mode == MIDI_OP_MODE_MIDI2) 1320 + return 1; 1321 + return 0; 1322 + } 1323 + 1324 + /* convert UMP direction to USB MIDI 2.0 direction */ 1325 + static unsigned int ump_to_usb_dir(unsigned int ump_dir) 1326 + { 1327 + switch (ump_dir) { 1328 + case SNDRV_UMP_DIR_INPUT: 1329 + return USB_MS_GR_TRM_BLOCK_TYPE_INPUT_ONLY; 1330 + case SNDRV_UMP_DIR_OUTPUT: 1331 + return USB_MS_GR_TRM_BLOCK_TYPE_OUTPUT_ONLY; 1332 + default: 1333 + return USB_MS_GR_TRM_BLOCK_TYPE_BIDIRECTIONAL; 1334 + } 1335 + } 1336 + 1337 + /* assign GTB descriptors (for the given request) */ 1338 + static void assign_block_descriptors(struct f_midi2 *midi2, 1339 + struct usb_request *req, 1340 + int max_len) 1341 + { 1342 + struct usb_ms20_gr_trm_block_header_descriptor header; 1343 + struct usb_ms20_gr_trm_block_descriptor *desc; 1344 + struct f_midi2_block_info *b; 1345 + struct f_midi2_ep *ep; 1346 + int i, blk, len; 1347 + char *data; 1348 + 1349 + len = sizeof(gtb_header_desc) + sizeof(gtb_desc) * midi2->total_blocks; 1350 + if (WARN_ON(len > midi2->info.req_buf_size)) 1351 + return; 1352 + 1353 + header = gtb_header_desc; 1354 + header.wTotalLength = cpu_to_le16(len); 1355 + if (max_len < len) { 1356 + len = min_t(int, len, sizeof(header)); 1357 + memcpy(req->buf, &header, len); 1358 + req->length = len; 1359 + req->zero = len < max_len; 1360 + return; 1361 + } 1362 + 1363 + memcpy(req->buf, &header, sizeof(header)); 1364 + data = req->buf + sizeof(header); 1365 + for (i = 0; i < midi2->num_eps; i++) { 1366 + ep = &midi2->midi2_eps[i]; 1367 + for (blk = 0; blk < ep->num_blks; blk++) { 1368 + b = &ep->blks[blk].info; 1369 + desc = (struct usb_ms20_gr_trm_block_descriptor *)data; 1370 + 1371 + *desc = gtb_desc; 1372 + desc->bGrpTrmBlkID = ep->blks[blk].gtb_id; 1373 + desc->bGrpTrmBlkType = ump_to_usb_dir(b->direction); 1374 + desc->nGroupTrm = b->first_group; 1375 + desc->nNumGroupTrm = b->num_groups; 1376 + desc->iBlockItem = ep->blks[blk].string_id; 1377 + 1378 + if (ep->info.protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI2) 1379 + desc->bMIDIProtocol = USB_MS_MIDI_PROTO_2_0; 1380 + else 1381 + desc->bMIDIProtocol = USB_MS_MIDI_PROTO_1_0_128; 1382 + 1383 + if (b->is_midi1 == 2) { 1384 + desc->wMaxInputBandwidth = cpu_to_le16(1); 1385 + desc->wMaxOutputBandwidth = cpu_to_le16(1); 1386 + } 1387 + 1388 + data += sizeof(*desc); 1389 + } 1390 + } 1391 + 1392 + req->length = len; 1393 + req->zero = len < max_len; 1394 + } 1395 + 1396 + /* gadget function setup callback: handle GTB requests */ 1397 + static int f_midi2_setup(struct usb_function *fn, 1398 + const struct usb_ctrlrequest *ctrl) 1399 + { 1400 + struct f_midi2 *midi2 = func_to_midi2(fn); 1401 + struct usb_composite_dev *cdev = fn->config->cdev; 1402 + struct usb_request *req = cdev->req; 1403 + u16 value, length; 1404 + 1405 + if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD || 1406 + ctrl->bRequest != USB_REQ_GET_DESCRIPTOR) 1407 + return -EOPNOTSUPP; 1408 + 1409 + value = le16_to_cpu(ctrl->wValue); 1410 + length = le16_to_cpu(ctrl->wLength); 1411 + 1412 + if ((value >> 8) != USB_DT_CS_GR_TRM_BLOCK) 1413 + return -EOPNOTSUPP; 1414 + 1415 + /* handle only altset 1 */ 1416 + if ((value & 0xff) != 1) 1417 + return -EOPNOTSUPP; 1418 + 1419 + assign_block_descriptors(midi2, req, length); 1420 + return usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); 1421 + } 1422 + 1423 + /* gadget function disable callback */ 1424 + static void f_midi2_disable(struct usb_function *fn) 1425 + { 1426 + struct f_midi2 *midi2 = func_to_midi2(fn); 1427 + 1428 + midi2->operation_mode = MIDI_OP_MODE_UNSET; 1429 + } 1430 + 1431 + /* 1432 + * ALSA UMP ops: most of them are NOPs, only trigger for write is needed 1433 + */ 1434 + static int f_midi2_ump_open(struct snd_ump_endpoint *ump, int dir) 1435 + { 1436 + return 0; 1437 + } 1438 + 1439 + static void f_midi2_ump_close(struct snd_ump_endpoint *ump, int dir) 1440 + { 1441 + } 1442 + 1443 + static void f_midi2_ump_trigger(struct snd_ump_endpoint *ump, int dir, int up) 1444 + { 1445 + struct f_midi2_ep *ep = ump->private_data; 1446 + struct f_midi2 *midi2 = ep->card; 1447 + 1448 + if (up && dir == SNDRV_RAWMIDI_STREAM_OUTPUT) { 1449 + switch (midi2->operation_mode) { 1450 + case MIDI_OP_MODE_MIDI1: 1451 + process_midi1_transmit(midi2); 1452 + break; 1453 + case MIDI_OP_MODE_MIDI2: 1454 + process_ump_transmit(ep); 1455 + break; 1456 + } 1457 + } 1458 + } 1459 + 1460 + static void f_midi2_ump_drain(struct snd_ump_endpoint *ump, int dir) 1461 + { 1462 + } 1463 + 1464 + static const struct snd_ump_ops f_midi2_ump_ops = { 1465 + .open = f_midi2_ump_open, 1466 + .close = f_midi2_ump_close, 1467 + .trigger = f_midi2_ump_trigger, 1468 + .drain = f_midi2_ump_drain, 1469 + }; 1470 + 1471 + /* 1472 + * "Operation Mode" control element 1473 + */ 1474 + static int f_midi2_operation_mode_info(struct snd_kcontrol *kcontrol, 1475 + struct snd_ctl_elem_info *uinfo) 1476 + { 1477 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1478 + uinfo->count = 1; 1479 + uinfo->value.integer.min = MIDI_OP_MODE_UNSET; 1480 + uinfo->value.integer.max = MIDI_OP_MODE_MIDI2; 1481 + return 0; 1482 + } 1483 + 1484 + static int f_midi2_operation_mode_get(struct snd_kcontrol *kcontrol, 1485 + struct snd_ctl_elem_value *ucontrol) 1486 + { 1487 + struct f_midi2 *midi2 = snd_kcontrol_chip(kcontrol); 1488 + 1489 + ucontrol->value.integer.value[0] = midi2->operation_mode; 1490 + return 0; 1491 + } 1492 + 1493 + static const struct snd_kcontrol_new operation_mode_ctl = { 1494 + .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, 1495 + .name = "Operation Mode", 1496 + .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 1497 + .info = f_midi2_operation_mode_info, 1498 + .get = f_midi2_operation_mode_get, 1499 + }; 1500 + 1501 + /* 1502 + * ALSA UMP instance creation / deletion 1503 + */ 1504 + static void f_midi2_free_card(struct f_midi2 *midi2) 1505 + { 1506 + if (midi2->card) { 1507 + snd_card_free_when_closed(midi2->card); 1508 + midi2->card = NULL; 1509 + } 1510 + } 1511 + 1512 + /* use a reverse direction for the gadget host */ 1513 + static int reverse_dir(int dir) 1514 + { 1515 + if (!dir || dir == SNDRV_UMP_DIR_BIDIRECTION) 1516 + return dir; 1517 + return (dir == SNDRV_UMP_DIR_OUTPUT) ? 1518 + SNDRV_UMP_DIR_INPUT : SNDRV_UMP_DIR_OUTPUT; 1519 + } 1520 + 1521 + static int f_midi2_create_card(struct f_midi2 *midi2) 1522 + { 1523 + struct snd_card *card; 1524 + struct snd_ump_endpoint *ump; 1525 + struct f_midi2_ep *ep; 1526 + int i, id, blk, err; 1527 + __be32 sw; 1528 + 1529 + err = snd_card_new(&midi2->gadget->dev, -1, NULL, THIS_MODULE, 0, 1530 + &card); 1531 + if (err < 0) 1532 + return err; 1533 + midi2->card = card; 1534 + 1535 + strcpy(card->driver, "f_midi2"); 1536 + strcpy(card->shortname, "MIDI 2.0 Gadget"); 1537 + strcpy(card->longname, "MIDI 2.0 Gadget"); 1538 + 1539 + id = 0; 1540 + for (i = 0; i < midi2->num_eps; i++) { 1541 + ep = &midi2->midi2_eps[i]; 1542 + err = snd_ump_endpoint_new(card, "MIDI 2.0 Gadget", id, 1543 + 1, 1, &ump); 1544 + if (err < 0) 1545 + goto error; 1546 + id++; 1547 + 1548 + ep->ump = ump; 1549 + ump->no_process_stream = true; 1550 + ump->private_data = ep; 1551 + ump->ops = &f_midi2_ump_ops; 1552 + if (midi2->info.static_block) 1553 + ump->info.flags |= SNDRV_UMP_EP_INFO_STATIC_BLOCKS; 1554 + ump->info.protocol_caps = (ep->info.protocol_caps & 3) << 8; 1555 + ump->info.protocol = (ep->info.protocol & 3) << 8; 1556 + ump->info.version = 0x0101; 1557 + ump->info.family_id = ep->info.family; 1558 + ump->info.model_id = ep->info.model; 1559 + ump->info.manufacturer_id = ep->info.manufacturer & 0xffffff; 1560 + sw = cpu_to_be32(ep->info.sw_revision); 1561 + memcpy(ump->info.sw_revision, &sw, 4); 1562 + 1563 + strscpy(ump->info.name, ump_ep_name(ep), 1564 + sizeof(ump->info.name)); 1565 + strscpy(ump->info.product_id, ump_product_id(ep), 1566 + sizeof(ump->info.product_id)); 1567 + strscpy(ump->core.name, ump->info.name, sizeof(ump->core.name)); 1568 + 1569 + for (blk = 0; blk < ep->num_blks; blk++) { 1570 + const struct f_midi2_block_info *b = &ep->blks[blk].info; 1571 + struct snd_ump_block *fb; 1572 + 1573 + err = snd_ump_block_new(ump, blk, 1574 + reverse_dir(b->direction), 1575 + b->first_group, b->num_groups, 1576 + &ep->blks[blk].fb); 1577 + if (err < 0) 1578 + goto error; 1579 + fb = ep->blks[blk].fb; 1580 + fb->info.active = !!b->active; 1581 + fb->info.midi_ci_version = b->midi_ci_version; 1582 + fb->info.ui_hint = reverse_dir(b->ui_hint); 1583 + fb->info.sysex8_streams = b->sysex8_streams; 1584 + fb->info.flags |= b->is_midi1; 1585 + strscpy(fb->info.name, ump_fb_name(b), 1586 + sizeof(fb->info.name)); 1587 + } 1588 + } 1589 + 1590 + for (i = 0; i < midi2->num_eps; i++) { 1591 + err = snd_ump_attach_legacy_rawmidi(midi2->midi2_eps[i].ump, 1592 + "Legacy MIDI", id); 1593 + if (err < 0) 1594 + goto error; 1595 + id++; 1596 + } 1597 + 1598 + err = snd_ctl_add(card, snd_ctl_new1(&operation_mode_ctl, midi2)); 1599 + if (err < 0) 1600 + goto error; 1601 + 1602 + err = snd_card_register(card); 1603 + if (err < 0) 1604 + goto error; 1605 + 1606 + return 0; 1607 + 1608 + error: 1609 + f_midi2_free_card(midi2); 1610 + return err; 1611 + } 1612 + 1613 + /* 1614 + * Creation of USB descriptors 1615 + */ 1616 + struct f_midi2_usb_config { 1617 + struct usb_descriptor_header **list; 1618 + unsigned int size; 1619 + unsigned int alloc; 1620 + 1621 + /* MIDI 1.0 jacks */ 1622 + unsigned char jack_in, jack_out, jack_id; 1623 + struct usb_midi_in_jack_descriptor jack_ins[MAX_CABLES]; 1624 + struct usb_midi_out_jack_descriptor_1 jack_outs[MAX_CABLES]; 1625 + }; 1626 + 1627 + static int append_config(struct f_midi2_usb_config *config, void *d) 1628 + { 1629 + unsigned int size; 1630 + void *buf; 1631 + 1632 + if (config->size + 2 >= config->alloc) { 1633 + size = config->size + 16; 1634 + buf = krealloc(config->list, size * sizeof(void *), GFP_KERNEL); 1635 + if (!buf) 1636 + return -ENOMEM; 1637 + config->list = buf; 1638 + config->alloc = size; 1639 + } 1640 + 1641 + config->list[config->size] = d; 1642 + config->size++; 1643 + config->list[config->size] = NULL; 1644 + return 0; 1645 + } 1646 + 1647 + static int append_configs(struct f_midi2_usb_config *config, void **d) 1648 + { 1649 + int err; 1650 + 1651 + for (; *d; d++) { 1652 + err = append_config(config, *d); 1653 + if (err) 1654 + return err; 1655 + } 1656 + return 0; 1657 + } 1658 + 1659 + static int append_midi1_in_jack(struct f_midi2 *midi2, 1660 + struct f_midi2_usb_config *config, 1661 + struct midi1_cable_mapping *map, 1662 + unsigned int type) 1663 + { 1664 + struct usb_midi_in_jack_descriptor *jack = 1665 + &config->jack_ins[config->jack_in++]; 1666 + int id = ++config->jack_id; 1667 + int err; 1668 + 1669 + jack->bLength = 0x06; 1670 + jack->bDescriptorType = USB_DT_CS_INTERFACE; 1671 + jack->bDescriptorSubtype = USB_MS_MIDI_IN_JACK; 1672 + jack->bJackType = type; 1673 + jack->bJackID = id; 1674 + /* use the corresponding block name as jack name */ 1675 + if (map->ep) 1676 + jack->iJack = map->ep->blks[map->block].string_id; 1677 + 1678 + err = append_config(config, jack); 1679 + if (err < 0) 1680 + return err; 1681 + return id; 1682 + } 1683 + 1684 + static int append_midi1_out_jack(struct f_midi2 *midi2, 1685 + struct f_midi2_usb_config *config, 1686 + struct midi1_cable_mapping *map, 1687 + unsigned int type, unsigned int source) 1688 + { 1689 + struct usb_midi_out_jack_descriptor_1 *jack = 1690 + &config->jack_outs[config->jack_out++]; 1691 + int id = ++config->jack_id; 1692 + int err; 1693 + 1694 + jack->bLength = 0x09; 1695 + jack->bDescriptorType = USB_DT_CS_INTERFACE; 1696 + jack->bDescriptorSubtype = USB_MS_MIDI_OUT_JACK; 1697 + jack->bJackType = type; 1698 + jack->bJackID = id; 1699 + jack->bNrInputPins = 1; 1700 + jack->pins[0].baSourceID = source; 1701 + jack->pins[0].baSourcePin = 0x01; 1702 + /* use the corresponding block name as jack name */ 1703 + if (map->ep) 1704 + jack->iJack = map->ep->blks[map->block].string_id; 1705 + 1706 + err = append_config(config, jack); 1707 + if (err < 0) 1708 + return err; 1709 + return id; 1710 + } 1711 + 1712 + static int f_midi2_create_usb_configs(struct f_midi2 *midi2, 1713 + struct f_midi2_usb_config *config, 1714 + int speed) 1715 + { 1716 + void **midi1_in_eps, **midi1_out_eps; 1717 + int i, jack, total; 1718 + int err; 1719 + 1720 + switch (speed) { 1721 + default: 1722 + case USB_SPEED_HIGH: 1723 + midi2_midi1_ep_out_desc.wMaxPacketSize = cpu_to_le16(512); 1724 + midi2_midi1_ep_in_desc.wMaxPacketSize = cpu_to_le16(512); 1725 + for (i = 0; i < midi2->num_eps; i++) 1726 + midi2_midi2_ep_out_desc[i].wMaxPacketSize = 1727 + cpu_to_le16(512); 1728 + fallthrough; 1729 + case USB_SPEED_FULL: 1730 + midi1_in_eps = midi2_midi1_ep_in_descs; 1731 + midi1_out_eps = midi2_midi1_ep_out_descs; 1732 + break; 1733 + case USB_SPEED_SUPER: 1734 + midi2_midi1_ep_out_desc.wMaxPacketSize = cpu_to_le16(1024); 1735 + midi2_midi1_ep_in_desc.wMaxPacketSize = cpu_to_le16(1024); 1736 + for (i = 0; i < midi2->num_eps; i++) 1737 + midi2_midi2_ep_out_desc[i].wMaxPacketSize = 1738 + cpu_to_le16(1024); 1739 + midi1_in_eps = midi2_midi1_ep_in_ss_descs; 1740 + midi1_out_eps = midi2_midi1_ep_out_ss_descs; 1741 + break; 1742 + } 1743 + 1744 + err = append_configs(config, midi2_audio_descs); 1745 + if (err < 0) 1746 + return err; 1747 + 1748 + if (midi2->num_midi1_in && midi2->num_midi1_out) 1749 + midi2_midi1_if_desc.bNumEndpoints = 2; 1750 + else 1751 + midi2_midi1_if_desc.bNumEndpoints = 1; 1752 + 1753 + err = append_configs(config, midi2_midi1_descs); 1754 + if (err < 0) 1755 + return err; 1756 + 1757 + total = USB_DT_MS_HEADER_SIZE; 1758 + if (midi2->num_midi1_out) { 1759 + midi2_midi1_ep_out_class_desc.bLength = 1760 + USB_DT_MS_ENDPOINT_SIZE(midi2->num_midi1_out); 1761 + total += midi2_midi1_ep_out_class_desc.bLength; 1762 + midi2_midi1_ep_out_class_desc.bNumEmbMIDIJack = 1763 + midi2->num_midi1_out; 1764 + total += midi2->num_midi1_out * 1765 + (USB_DT_MIDI_IN_SIZE + USB_DT_MIDI_OUT_SIZE(1)); 1766 + for (i = 0; i < midi2->num_midi1_out; i++) { 1767 + jack = append_midi1_in_jack(midi2, config, 1768 + &midi2->in_cable_mapping[i], 1769 + USB_MS_EMBEDDED); 1770 + if (jack < 0) 1771 + return jack; 1772 + midi2_midi1_ep_out_class_desc.baAssocJackID[i] = jack; 1773 + jack = append_midi1_out_jack(midi2, config, 1774 + &midi2->in_cable_mapping[i], 1775 + USB_MS_EXTERNAL, jack); 1776 + if (jack < 0) 1777 + return jack; 1778 + } 1779 + } 1780 + 1781 + if (midi2->num_midi1_in) { 1782 + midi2_midi1_ep_in_class_desc.bLength = 1783 + USB_DT_MS_ENDPOINT_SIZE(midi2->num_midi1_in); 1784 + total += midi2_midi1_ep_in_class_desc.bLength; 1785 + midi2_midi1_ep_in_class_desc.bNumEmbMIDIJack = 1786 + midi2->num_midi1_in; 1787 + total += midi2->num_midi1_in * 1788 + (USB_DT_MIDI_IN_SIZE + USB_DT_MIDI_OUT_SIZE(1)); 1789 + for (i = 0; i < midi2->num_midi1_in; i++) { 1790 + jack = append_midi1_in_jack(midi2, config, 1791 + &midi2->out_cable_mapping[i], 1792 + USB_MS_EXTERNAL); 1793 + if (jack < 0) 1794 + return jack; 1795 + jack = append_midi1_out_jack(midi2, config, 1796 + &midi2->out_cable_mapping[i], 1797 + USB_MS_EMBEDDED, jack); 1798 + if (jack < 0) 1799 + return jack; 1800 + midi2_midi1_ep_in_class_desc.baAssocJackID[i] = jack; 1801 + } 1802 + } 1803 + 1804 + midi2_midi1_class_desc.wTotalLength = cpu_to_le16(total); 1805 + 1806 + if (midi2->num_midi1_out) { 1807 + err = append_configs(config, midi1_out_eps); 1808 + if (err < 0) 1809 + return err; 1810 + } 1811 + if (midi2->num_midi1_in) { 1812 + err = append_configs(config, midi1_in_eps); 1813 + if (err < 0) 1814 + return err; 1815 + } 1816 + 1817 + err = append_configs(config, midi2_midi2_descs); 1818 + if (err < 0) 1819 + return err; 1820 + 1821 + for (i = 0; i < midi2->num_eps; i++) { 1822 + err = append_config(config, &midi2_midi2_ep_out_desc[i]); 1823 + if (err < 0) 1824 + return err; 1825 + if (speed == USB_SPEED_SUPER || speed == USB_SPEED_SUPER_PLUS) { 1826 + err = append_config(config, &midi2_midi2_ep_out_ss_comp_desc); 1827 + if (err < 0) 1828 + return err; 1829 + } 1830 + err = append_config(config, &midi2_midi2_ep_out_class_desc[i]); 1831 + if (err < 0) 1832 + return err; 1833 + err = append_config(config, &midi2_midi2_ep_in_desc[i]); 1834 + if (err < 0) 1835 + return err; 1836 + if (speed == USB_SPEED_SUPER || speed == USB_SPEED_SUPER_PLUS) { 1837 + err = append_config(config, &midi2_midi2_ep_in_ss_comp_desc); 1838 + if (err < 0) 1839 + return err; 1840 + } 1841 + err = append_config(config, &midi2_midi2_ep_in_class_desc[i]); 1842 + if (err < 0) 1843 + return err; 1844 + } 1845 + 1846 + return 0; 1847 + } 1848 + 1849 + static void f_midi2_free_usb_configs(struct f_midi2_usb_config *config) 1850 + { 1851 + kfree(config->list); 1852 + memset(config, 0, sizeof(*config)); 1853 + } 1854 + 1855 + /* as we use the static descriptors for simplicity, serialize bind call */ 1856 + static DEFINE_MUTEX(f_midi2_desc_mutex); 1857 + 1858 + /* fill MIDI2 EP class-specific descriptor */ 1859 + static void fill_midi2_class_desc(struct f_midi2_ep *ep, 1860 + struct usb_ms20_endpoint_descriptor_32 *cdesc) 1861 + { 1862 + int blk; 1863 + 1864 + cdesc->bLength = USB_DT_MS20_ENDPOINT_SIZE(ep->num_blks); 1865 + cdesc->bDescriptorType = USB_DT_CS_ENDPOINT; 1866 + cdesc->bDescriptorSubtype = USB_MS_GENERAL_2_0; 1867 + cdesc->bNumGrpTrmBlock = ep->num_blks; 1868 + for (blk = 0; blk < ep->num_blks; blk++) 1869 + cdesc->baAssoGrpTrmBlkID[blk] = ep->blks[blk].gtb_id; 1870 + } 1871 + 1872 + /* initialize MIDI2 EP-in */ 1873 + static int f_midi2_init_midi2_ep_in(struct f_midi2 *midi2, int index) 1874 + { 1875 + struct f_midi2_ep *ep = &midi2->midi2_eps[index]; 1876 + struct usb_endpoint_descriptor *desc = &midi2_midi2_ep_in_desc[index]; 1877 + 1878 + desc->bLength = USB_DT_ENDPOINT_SIZE; 1879 + desc->bDescriptorType = USB_DT_ENDPOINT; 1880 + desc->bEndpointAddress = USB_DIR_IN; 1881 + desc->bmAttributes = USB_ENDPOINT_XFER_INT; 1882 + desc->wMaxPacketSize = cpu_to_le16(EP_MAX_PACKET_INT); 1883 + desc->bInterval = 1; 1884 + 1885 + fill_midi2_class_desc(ep, &midi2_midi2_ep_in_class_desc[index]); 1886 + 1887 + return f_midi2_init_ep(midi2, ep, &ep->ep_in, desc, 1888 + f_midi2_ep_in_complete); 1889 + } 1890 + 1891 + /* initialize MIDI2 EP-out */ 1892 + static int f_midi2_init_midi2_ep_out(struct f_midi2 *midi2, int index) 1893 + { 1894 + struct f_midi2_ep *ep = &midi2->midi2_eps[index]; 1895 + struct usb_endpoint_descriptor *desc = &midi2_midi2_ep_out_desc[index]; 1896 + 1897 + desc->bLength = USB_DT_ENDPOINT_SIZE; 1898 + desc->bDescriptorType = USB_DT_ENDPOINT; 1899 + desc->bEndpointAddress = USB_DIR_OUT; 1900 + desc->bmAttributes = USB_ENDPOINT_XFER_BULK; 1901 + 1902 + fill_midi2_class_desc(ep, &midi2_midi2_ep_out_class_desc[index]); 1903 + 1904 + return f_midi2_init_ep(midi2, ep, &ep->ep_out, desc, 1905 + f_midi2_ep_out_complete); 1906 + } 1907 + 1908 + /* gadget function bind callback */ 1909 + static int f_midi2_bind(struct usb_configuration *c, struct usb_function *f) 1910 + { 1911 + struct usb_composite_dev *cdev = c->cdev; 1912 + struct f_midi2 *midi2 = func_to_midi2(f); 1913 + struct f_midi2_ep *ep; 1914 + struct f_midi2_usb_config config = {}; 1915 + struct usb_gadget_strings string_fn = { 1916 + .language = 0x0409, /* en-us */ 1917 + .strings = midi2->string_defs, 1918 + }; 1919 + struct usb_gadget_strings *strings[] = { 1920 + &string_fn, 1921 + NULL, 1922 + }; 1923 + int i, blk, status; 1924 + 1925 + midi2->gadget = cdev->gadget; 1926 + midi2->operation_mode = MIDI_OP_MODE_UNSET; 1927 + 1928 + status = f_midi2_create_card(midi2); 1929 + if (status < 0) 1930 + goto fail_register; 1931 + 1932 + /* maybe allocate device-global string ID */ 1933 + midi2->strings = usb_gstrings_attach(c->cdev, strings, 1934 + midi2->total_blocks + 1); 1935 + if (IS_ERR(midi2->strings)) { 1936 + status = PTR_ERR(midi2->strings); 1937 + goto fail_string; 1938 + } 1939 + 1940 + mutex_lock(&f_midi2_desc_mutex); 1941 + midi2_midi1_if_desc.iInterface = midi2->strings[STR_IFACE].id; 1942 + midi2_midi2_if_desc.iInterface = midi2->strings[STR_IFACE].id; 1943 + for (i = 0; i < midi2->num_eps; i++) { 1944 + ep = &midi2->midi2_eps[i]; 1945 + for (blk = 0; blk < ep->num_blks; blk++) 1946 + ep->blks[blk].string_id = 1947 + midi2->strings[gtb_to_str_id(ep->blks[blk].gtb_id)].id; 1948 + } 1949 + 1950 + midi2_midi2_if_desc.bNumEndpoints = midi2->num_eps * 2; 1951 + 1952 + /* audio interface */ 1953 + status = usb_interface_id(c, f); 1954 + if (status < 0) 1955 + goto fail; 1956 + midi2_audio_if_desc.bInterfaceNumber = status; 1957 + 1958 + /* MIDI streaming */ 1959 + status = usb_interface_id(c, f); 1960 + if (status < 0) 1961 + goto fail; 1962 + midi2->midi_if = status; 1963 + midi2_midi1_if_desc.bInterfaceNumber = status; 1964 + midi2_midi2_if_desc.bInterfaceNumber = status; 1965 + midi2_audio_class_desc.baInterfaceNr[0] = status; 1966 + 1967 + /* allocate instance-specific endpoints */ 1968 + if (midi2->midi2_eps[0].blks[0].info.direction != SNDRV_UMP_DIR_OUTPUT) { 1969 + status = f_midi2_init_ep(midi2, NULL, &midi2->midi1_ep_in, 1970 + &midi2_midi1_ep_in_desc, 1971 + f_midi2_midi1_ep_in_complete); 1972 + if (status) 1973 + goto fail; 1974 + } 1975 + 1976 + if (midi2->midi2_eps[0].blks[0].info.direction != SNDRV_UMP_DIR_INPUT) { 1977 + status = f_midi2_init_ep(midi2, NULL, &midi2->midi1_ep_out, 1978 + &midi2_midi1_ep_out_desc, 1979 + f_midi2_midi1_ep_out_complete); 1980 + if (status) 1981 + goto fail; 1982 + } 1983 + 1984 + for (i = 0; i < midi2->num_eps; i++) { 1985 + status = f_midi2_init_midi2_ep_in(midi2, i); 1986 + if (status) 1987 + goto fail; 1988 + status = f_midi2_init_midi2_ep_out(midi2, i); 1989 + if (status) 1990 + goto fail; 1991 + } 1992 + 1993 + status = f_midi2_create_usb_configs(midi2, &config, USB_SPEED_FULL); 1994 + if (status < 0) 1995 + goto fail; 1996 + f->fs_descriptors = usb_copy_descriptors(config.list); 1997 + if (!f->fs_descriptors) { 1998 + status = -ENOMEM; 1999 + goto fail; 2000 + } 2001 + f_midi2_free_usb_configs(&config); 2002 + 2003 + status = f_midi2_create_usb_configs(midi2, &config, USB_SPEED_HIGH); 2004 + if (status < 0) 2005 + goto fail; 2006 + f->hs_descriptors = usb_copy_descriptors(config.list); 2007 + if (!f->hs_descriptors) { 2008 + status = -ENOMEM; 2009 + goto fail; 2010 + } 2011 + f_midi2_free_usb_configs(&config); 2012 + 2013 + status = f_midi2_create_usb_configs(midi2, &config, USB_SPEED_SUPER); 2014 + if (status < 0) 2015 + goto fail; 2016 + f->ss_descriptors = usb_copy_descriptors(config.list); 2017 + if (!f->ss_descriptors) { 2018 + status = -ENOMEM; 2019 + goto fail; 2020 + } 2021 + f_midi2_free_usb_configs(&config); 2022 + 2023 + mutex_unlock(&f_midi2_desc_mutex); 2024 + return 0; 2025 + 2026 + fail: 2027 + f_midi2_free_usb_configs(&config); 2028 + mutex_unlock(&f_midi2_desc_mutex); 2029 + usb_free_all_descriptors(f); 2030 + fail_string: 2031 + f_midi2_free_card(midi2); 2032 + fail_register: 2033 + ERROR(midi2, "%s: can't bind, err %d\n", f->name, status); 2034 + return status; 2035 + } 2036 + 2037 + /* gadget function unbind callback */ 2038 + static void f_midi2_unbind(struct usb_configuration *c, struct usb_function *f) 2039 + { 2040 + struct f_midi2 *midi2 = func_to_midi2(f); 2041 + int i; 2042 + 2043 + f_midi2_free_card(midi2); 2044 + 2045 + f_midi2_free_ep(&midi2->midi1_ep_in); 2046 + f_midi2_free_ep(&midi2->midi1_ep_out); 2047 + for (i = 0; i < midi2->num_eps; i++) { 2048 + f_midi2_free_ep(&midi2->midi2_eps[i].ep_in); 2049 + f_midi2_free_ep(&midi2->midi2_eps[i].ep_out); 2050 + } 2051 + 2052 + usb_free_all_descriptors(f); 2053 + } 2054 + 2055 + /* 2056 + * ConfigFS interface 2057 + */ 2058 + 2059 + /* type conversion helpers */ 2060 + static inline struct f_midi2_opts *to_f_midi2_opts(struct config_item *item) 2061 + { 2062 + return container_of(to_config_group(item), struct f_midi2_opts, 2063 + func_inst.group); 2064 + } 2065 + 2066 + static inline struct f_midi2_ep_opts * 2067 + to_f_midi2_ep_opts(struct config_item *item) 2068 + { 2069 + return container_of(to_config_group(item), struct f_midi2_ep_opts, 2070 + group); 2071 + } 2072 + 2073 + static inline struct f_midi2_block_opts * 2074 + to_f_midi2_block_opts(struct config_item *item) 2075 + { 2076 + return container_of(to_config_group(item), struct f_midi2_block_opts, 2077 + group); 2078 + } 2079 + 2080 + /* trim the string to be usable for EP and FB name strings */ 2081 + static void make_name_string(char *s) 2082 + { 2083 + char *p; 2084 + 2085 + p = strchr(s, '\n'); 2086 + if (p) 2087 + *p = 0; 2088 + 2089 + p = s + strlen(s); 2090 + for (; p > s && isspace(*p); p--) 2091 + *p = 0; 2092 + } 2093 + 2094 + /* configfs helpers: generic show/store for unisnged int */ 2095 + static ssize_t f_midi2_opts_uint_show(struct f_midi2_opts *opts, 2096 + u32 val, const char *format, char *page) 2097 + { 2098 + int result; 2099 + 2100 + mutex_lock(&opts->lock); 2101 + result = sprintf(page, format, val); 2102 + mutex_unlock(&opts->lock); 2103 + return result; 2104 + } 2105 + 2106 + static ssize_t f_midi2_opts_uint_store(struct f_midi2_opts *opts, 2107 + u32 *valp, u32 minval, u32 maxval, 2108 + const char *page, size_t len) 2109 + { 2110 + int ret; 2111 + u32 val; 2112 + 2113 + mutex_lock(&opts->lock); 2114 + if (opts->refcnt) { 2115 + ret = -EBUSY; 2116 + goto end; 2117 + } 2118 + 2119 + ret = kstrtou32(page, 0, &val); 2120 + if (ret) 2121 + goto end; 2122 + if (val < minval || val > maxval) { 2123 + ret = -EINVAL; 2124 + goto end; 2125 + } 2126 + 2127 + *valp = val; 2128 + ret = len; 2129 + 2130 + end: 2131 + mutex_unlock(&opts->lock); 2132 + return ret; 2133 + } 2134 + 2135 + /* generic store for bool */ 2136 + static ssize_t f_midi2_opts_bool_store(struct f_midi2_opts *opts, 2137 + bool *valp, const char *page, size_t len) 2138 + { 2139 + int ret; 2140 + bool val; 2141 + 2142 + mutex_lock(&opts->lock); 2143 + if (opts->refcnt) { 2144 + ret = -EBUSY; 2145 + goto end; 2146 + } 2147 + 2148 + ret = kstrtobool(page, &val); 2149 + if (ret) 2150 + goto end; 2151 + *valp = val; 2152 + ret = len; 2153 + 2154 + end: 2155 + mutex_unlock(&opts->lock); 2156 + return ret; 2157 + } 2158 + 2159 + /* generic show/store for string */ 2160 + static ssize_t f_midi2_opts_str_show(struct f_midi2_opts *opts, 2161 + const char *str, char *page) 2162 + { 2163 + int result = 0; 2164 + 2165 + mutex_lock(&opts->lock); 2166 + if (str) 2167 + result = scnprintf(page, PAGE_SIZE, "%s\n", str); 2168 + mutex_unlock(&opts->lock); 2169 + return result; 2170 + } 2171 + 2172 + static ssize_t f_midi2_opts_str_store(struct f_midi2_opts *opts, 2173 + const char **strp, size_t maxlen, 2174 + const char *page, size_t len) 2175 + { 2176 + char *c; 2177 + int ret; 2178 + 2179 + mutex_lock(&opts->lock); 2180 + if (opts->refcnt) { 2181 + ret = -EBUSY; 2182 + goto end; 2183 + } 2184 + 2185 + c = kstrndup(page, min(len, maxlen), GFP_KERNEL); 2186 + if (!c) { 2187 + ret = -ENOMEM; 2188 + goto end; 2189 + } 2190 + 2191 + kfree(*strp); 2192 + make_name_string(c); 2193 + *strp = c; 2194 + ret = len; 2195 + 2196 + end: 2197 + mutex_unlock(&opts->lock); 2198 + return ret; 2199 + } 2200 + 2201 + /* 2202 + * Definitions for UMP Block config 2203 + */ 2204 + 2205 + /* define an uint option for block */ 2206 + #define F_MIDI2_BLOCK_OPT(name, format, minval, maxval) \ 2207 + static ssize_t f_midi2_block_opts_##name##_show(struct config_item *item,\ 2208 + char *page) \ 2209 + { \ 2210 + struct f_midi2_block_opts *opts = to_f_midi2_block_opts(item); \ 2211 + return f_midi2_opts_uint_show(opts->ep->opts, opts->info.name, \ 2212 + format "\n", page); \ 2213 + } \ 2214 + \ 2215 + static ssize_t f_midi2_block_opts_##name##_store(struct config_item *item,\ 2216 + const char *page, size_t len) \ 2217 + { \ 2218 + struct f_midi2_block_opts *opts = to_f_midi2_block_opts(item); \ 2219 + return f_midi2_opts_uint_store(opts->ep->opts, &opts->info.name,\ 2220 + minval, maxval, page, len); \ 2221 + } \ 2222 + \ 2223 + CONFIGFS_ATTR(f_midi2_block_opts_, name) 2224 + 2225 + /* define a boolean option for block */ 2226 + #define F_MIDI2_BLOCK_BOOL_OPT(name) \ 2227 + static ssize_t f_midi2_block_opts_##name##_show(struct config_item *item,\ 2228 + char *page) \ 2229 + { \ 2230 + struct f_midi2_block_opts *opts = to_f_midi2_block_opts(item); \ 2231 + return f_midi2_opts_uint_show(opts->ep->opts, opts->info.name, \ 2232 + "%u\n", page); \ 2233 + } \ 2234 + \ 2235 + static ssize_t f_midi2_block_opts_##name##_store(struct config_item *item,\ 2236 + const char *page, size_t len) \ 2237 + { \ 2238 + struct f_midi2_block_opts *opts = to_f_midi2_block_opts(item); \ 2239 + return f_midi2_opts_bool_store(opts->ep->opts, &opts->info.name,\ 2240 + page, len); \ 2241 + } \ 2242 + \ 2243 + CONFIGFS_ATTR(f_midi2_block_opts_, name) 2244 + 2245 + F_MIDI2_BLOCK_OPT(direction, "0x%x", 1, 3); 2246 + F_MIDI2_BLOCK_OPT(first_group, "0x%x", 0, 15); 2247 + F_MIDI2_BLOCK_OPT(num_groups, "0x%x", 1, 16); 2248 + F_MIDI2_BLOCK_OPT(midi1_first_group, "0x%x", 0, 15); 2249 + F_MIDI2_BLOCK_OPT(midi1_num_groups, "0x%x", 0, 16); 2250 + F_MIDI2_BLOCK_OPT(ui_hint, "0x%x", 0, 3); 2251 + F_MIDI2_BLOCK_OPT(midi_ci_version, "%u", 0, 1); 2252 + F_MIDI2_BLOCK_OPT(sysex8_streams, "%u", 0, 255); 2253 + F_MIDI2_BLOCK_OPT(is_midi1, "%u", 0, 2); 2254 + F_MIDI2_BLOCK_BOOL_OPT(active); 2255 + 2256 + static ssize_t f_midi2_block_opts_name_show(struct config_item *item, 2257 + char *page) 2258 + { 2259 + struct f_midi2_block_opts *opts = to_f_midi2_block_opts(item); 2260 + 2261 + return f_midi2_opts_str_show(opts->ep->opts, opts->info.name, page); 2262 + } 2263 + 2264 + static ssize_t f_midi2_block_opts_name_store(struct config_item *item, 2265 + const char *page, size_t len) 2266 + { 2267 + struct f_midi2_block_opts *opts = to_f_midi2_block_opts(item); 2268 + 2269 + return f_midi2_opts_str_store(opts->ep->opts, &opts->info.name, 128, 2270 + page, len); 2271 + } 2272 + 2273 + CONFIGFS_ATTR(f_midi2_block_opts_, name); 2274 + 2275 + static struct configfs_attribute *f_midi2_block_attrs[] = { 2276 + &f_midi2_block_opts_attr_direction, 2277 + &f_midi2_block_opts_attr_first_group, 2278 + &f_midi2_block_opts_attr_num_groups, 2279 + &f_midi2_block_opts_attr_midi1_first_group, 2280 + &f_midi2_block_opts_attr_midi1_num_groups, 2281 + &f_midi2_block_opts_attr_ui_hint, 2282 + &f_midi2_block_opts_attr_midi_ci_version, 2283 + &f_midi2_block_opts_attr_sysex8_streams, 2284 + &f_midi2_block_opts_attr_is_midi1, 2285 + &f_midi2_block_opts_attr_active, 2286 + &f_midi2_block_opts_attr_name, 2287 + NULL, 2288 + }; 2289 + 2290 + static void f_midi2_block_opts_release(struct config_item *item) 2291 + { 2292 + struct f_midi2_block_opts *opts = to_f_midi2_block_opts(item); 2293 + 2294 + kfree(opts->info.name); 2295 + kfree(opts); 2296 + } 2297 + 2298 + static struct configfs_item_operations f_midi2_block_item_ops = { 2299 + .release = f_midi2_block_opts_release, 2300 + }; 2301 + 2302 + static const struct config_item_type f_midi2_block_type = { 2303 + .ct_item_ops = &f_midi2_block_item_ops, 2304 + .ct_attrs = f_midi2_block_attrs, 2305 + .ct_owner = THIS_MODULE, 2306 + }; 2307 + 2308 + /* create a f_midi2_block_opts instance for the given block number */ 2309 + static int f_midi2_block_opts_create(struct f_midi2_ep_opts *ep_opts, 2310 + unsigned int blk, 2311 + struct f_midi2_block_opts **block_p) 2312 + { 2313 + struct f_midi2_block_opts *block_opts; 2314 + int ret = 0; 2315 + 2316 + mutex_lock(&ep_opts->opts->lock); 2317 + if (ep_opts->opts->refcnt || ep_opts->blks[blk]) { 2318 + ret = -EBUSY; 2319 + goto out; 2320 + } 2321 + 2322 + block_opts = kzalloc(sizeof(*block_opts), GFP_KERNEL); 2323 + if (!block_opts) { 2324 + ret = -ENOMEM; 2325 + goto out; 2326 + } 2327 + 2328 + block_opts->ep = ep_opts; 2329 + block_opts->id = blk; 2330 + 2331 + /* set up the default values */ 2332 + block_opts->info.direction = SNDRV_UMP_DIR_BIDIRECTION; 2333 + block_opts->info.first_group = 0; 2334 + block_opts->info.num_groups = 1; 2335 + block_opts->info.ui_hint = SNDRV_UMP_BLOCK_UI_HINT_BOTH; 2336 + block_opts->info.active = 1; 2337 + 2338 + ep_opts->blks[blk] = block_opts; 2339 + *block_p = block_opts; 2340 + 2341 + out: 2342 + mutex_unlock(&ep_opts->opts->lock); 2343 + return ret; 2344 + } 2345 + 2346 + /* make_group callback for a block */ 2347 + static struct config_group * 2348 + f_midi2_opts_block_make(struct config_group *group, const char *name) 2349 + { 2350 + struct f_midi2_ep_opts *ep_opts; 2351 + struct f_midi2_block_opts *block_opts; 2352 + unsigned int blk; 2353 + int ret; 2354 + 2355 + if (strncmp(name, "block.", 6)) 2356 + return ERR_PTR(-EINVAL); 2357 + ret = kstrtouint(name + 6, 10, &blk); 2358 + if (ret) 2359 + return ERR_PTR(ret); 2360 + 2361 + ep_opts = to_f_midi2_ep_opts(&group->cg_item); 2362 + 2363 + if (blk >= SNDRV_UMP_MAX_BLOCKS) 2364 + return ERR_PTR(-EINVAL); 2365 + if (ep_opts->blks[blk]) 2366 + return ERR_PTR(-EBUSY); 2367 + ret = f_midi2_block_opts_create(ep_opts, blk, &block_opts); 2368 + if (ret) 2369 + return ERR_PTR(ret); 2370 + 2371 + config_group_init_type_name(&block_opts->group, name, 2372 + &f_midi2_block_type); 2373 + return &block_opts->group; 2374 + } 2375 + 2376 + /* drop_item callback for a block */ 2377 + static void 2378 + f_midi2_opts_block_drop(struct config_group *group, struct config_item *item) 2379 + { 2380 + struct f_midi2_block_opts *block_opts = to_f_midi2_block_opts(item); 2381 + 2382 + mutex_lock(&block_opts->ep->opts->lock); 2383 + block_opts->ep->blks[block_opts->id] = NULL; 2384 + mutex_unlock(&block_opts->ep->opts->lock); 2385 + config_item_put(item); 2386 + } 2387 + 2388 + /* 2389 + * Definitions for UMP Endpoint config 2390 + */ 2391 + 2392 + /* define an uint option for EP */ 2393 + #define F_MIDI2_EP_OPT(name, format, minval, maxval) \ 2394 + static ssize_t f_midi2_ep_opts_##name##_show(struct config_item *item, \ 2395 + char *page) \ 2396 + { \ 2397 + struct f_midi2_ep_opts *opts = to_f_midi2_ep_opts(item); \ 2398 + return f_midi2_opts_uint_show(opts->opts, opts->info.name, \ 2399 + format "\n", page); \ 2400 + } \ 2401 + \ 2402 + static ssize_t f_midi2_ep_opts_##name##_store(struct config_item *item, \ 2403 + const char *page, size_t len)\ 2404 + { \ 2405 + struct f_midi2_ep_opts *opts = to_f_midi2_ep_opts(item); \ 2406 + return f_midi2_opts_uint_store(opts->opts, &opts->info.name, \ 2407 + minval, maxval, page, len); \ 2408 + } \ 2409 + \ 2410 + CONFIGFS_ATTR(f_midi2_ep_opts_, name) 2411 + 2412 + /* define a string option for EP */ 2413 + #define F_MIDI2_EP_STR_OPT(name, maxlen) \ 2414 + static ssize_t f_midi2_ep_opts_##name##_show(struct config_item *item, \ 2415 + char *page) \ 2416 + { \ 2417 + struct f_midi2_ep_opts *opts = to_f_midi2_ep_opts(item); \ 2418 + return f_midi2_opts_str_show(opts->opts, opts->info.name, page);\ 2419 + } \ 2420 + \ 2421 + static ssize_t f_midi2_ep_opts_##name##_store(struct config_item *item, \ 2422 + const char *page, size_t len) \ 2423 + { \ 2424 + struct f_midi2_ep_opts *opts = to_f_midi2_ep_opts(item); \ 2425 + return f_midi2_opts_str_store(opts->opts, &opts->info.name, maxlen,\ 2426 + page, len); \ 2427 + } \ 2428 + \ 2429 + CONFIGFS_ATTR(f_midi2_ep_opts_, name) 2430 + 2431 + F_MIDI2_EP_OPT(protocol, "0x%x", 1, 2); 2432 + F_MIDI2_EP_OPT(protocol_caps, "0x%x", 1, 3); 2433 + F_MIDI2_EP_OPT(manufacturer, "0x%x", 0, 0xffffff); 2434 + F_MIDI2_EP_OPT(family, "0x%x", 0, 0xffff); 2435 + F_MIDI2_EP_OPT(model, "0x%x", 0, 0xffff); 2436 + F_MIDI2_EP_OPT(sw_revision, "0x%x", 0, 0xffffffff); 2437 + F_MIDI2_EP_STR_OPT(ep_name, 128); 2438 + F_MIDI2_EP_STR_OPT(product_id, 128); 2439 + 2440 + static struct configfs_attribute *f_midi2_ep_attrs[] = { 2441 + &f_midi2_ep_opts_attr_protocol, 2442 + &f_midi2_ep_opts_attr_protocol_caps, 2443 + &f_midi2_ep_opts_attr_ep_name, 2444 + &f_midi2_ep_opts_attr_product_id, 2445 + &f_midi2_ep_opts_attr_manufacturer, 2446 + &f_midi2_ep_opts_attr_family, 2447 + &f_midi2_ep_opts_attr_model, 2448 + &f_midi2_ep_opts_attr_sw_revision, 2449 + NULL, 2450 + }; 2451 + 2452 + static void f_midi2_ep_opts_release(struct config_item *item) 2453 + { 2454 + struct f_midi2_ep_opts *opts = to_f_midi2_ep_opts(item); 2455 + 2456 + kfree(opts->info.ep_name); 2457 + kfree(opts->info.product_id); 2458 + kfree(opts); 2459 + } 2460 + 2461 + static struct configfs_item_operations f_midi2_ep_item_ops = { 2462 + .release = f_midi2_ep_opts_release, 2463 + }; 2464 + 2465 + static struct configfs_group_operations f_midi2_ep_group_ops = { 2466 + .make_group = f_midi2_opts_block_make, 2467 + .drop_item = f_midi2_opts_block_drop, 2468 + }; 2469 + 2470 + static const struct config_item_type f_midi2_ep_type = { 2471 + .ct_item_ops = &f_midi2_ep_item_ops, 2472 + .ct_group_ops = &f_midi2_ep_group_ops, 2473 + .ct_attrs = f_midi2_ep_attrs, 2474 + .ct_owner = THIS_MODULE, 2475 + }; 2476 + 2477 + /* create a f_midi2_ep_opts instance */ 2478 + static int f_midi2_ep_opts_create(struct f_midi2_opts *opts, 2479 + unsigned int index, 2480 + struct f_midi2_ep_opts **ep_p) 2481 + { 2482 + struct f_midi2_ep_opts *ep_opts; 2483 + 2484 + ep_opts = kzalloc(sizeof(*ep_opts), GFP_KERNEL); 2485 + if (!ep_opts) 2486 + return -ENOMEM; 2487 + 2488 + ep_opts->opts = opts; 2489 + ep_opts->index = index; 2490 + 2491 + /* set up the default values */ 2492 + ep_opts->info.protocol = 2; 2493 + ep_opts->info.protocol_caps = 3; 2494 + 2495 + opts->eps[index] = ep_opts; 2496 + *ep_p = ep_opts; 2497 + return 0; 2498 + } 2499 + 2500 + /* make_group callback for an EP */ 2501 + static struct config_group * 2502 + f_midi2_opts_ep_make(struct config_group *group, const char *name) 2503 + { 2504 + struct f_midi2_opts *opts; 2505 + struct f_midi2_ep_opts *ep_opts; 2506 + unsigned int index; 2507 + int ret; 2508 + 2509 + if (strncmp(name, "ep.", 3)) 2510 + return ERR_PTR(-EINVAL); 2511 + ret = kstrtouint(name + 3, 10, &index); 2512 + if (ret) 2513 + return ERR_PTR(ret); 2514 + 2515 + opts = to_f_midi2_opts(&group->cg_item); 2516 + if (index >= MAX_UMP_EPS) 2517 + return ERR_PTR(-EINVAL); 2518 + if (opts->eps[index]) 2519 + return ERR_PTR(-EBUSY); 2520 + ret = f_midi2_ep_opts_create(opts, index, &ep_opts); 2521 + if (ret) 2522 + return ERR_PTR(ret); 2523 + 2524 + config_group_init_type_name(&ep_opts->group, name, &f_midi2_ep_type); 2525 + return &ep_opts->group; 2526 + } 2527 + 2528 + /* drop_item callback for an EP */ 2529 + static void 2530 + f_midi2_opts_ep_drop(struct config_group *group, struct config_item *item) 2531 + { 2532 + struct f_midi2_ep_opts *ep_opts = to_f_midi2_ep_opts(item); 2533 + 2534 + mutex_lock(&ep_opts->opts->lock); 2535 + ep_opts->opts->eps[ep_opts->index] = NULL; 2536 + mutex_unlock(&ep_opts->opts->lock); 2537 + config_item_put(item); 2538 + } 2539 + 2540 + /* 2541 + * Definitions for card config 2542 + */ 2543 + 2544 + /* define a bool option for card */ 2545 + #define F_MIDI2_BOOL_OPT(name) \ 2546 + static ssize_t f_midi2_opts_##name##_show(struct config_item *item, \ 2547 + char *page) \ 2548 + { \ 2549 + struct f_midi2_opts *opts = to_f_midi2_opts(item); \ 2550 + return f_midi2_opts_uint_show(opts, opts->info.name, \ 2551 + "%u\n", page); \ 2552 + } \ 2553 + \ 2554 + static ssize_t f_midi2_opts_##name##_store(struct config_item *item, \ 2555 + const char *page, size_t len) \ 2556 + { \ 2557 + struct f_midi2_opts *opts = to_f_midi2_opts(item); \ 2558 + return f_midi2_opts_bool_store(opts, &opts->info.name, \ 2559 + page, len); \ 2560 + } \ 2561 + \ 2562 + CONFIGFS_ATTR(f_midi2_opts_, name) 2563 + 2564 + F_MIDI2_BOOL_OPT(process_ump); 2565 + F_MIDI2_BOOL_OPT(static_block); 2566 + 2567 + static ssize_t f_midi2_opts_iface_name_show(struct config_item *item, 2568 + char *page) 2569 + { 2570 + struct f_midi2_opts *opts = to_f_midi2_opts(item); 2571 + 2572 + return f_midi2_opts_str_show(opts, opts->info.iface_name, page); 2573 + } 2574 + 2575 + static ssize_t f_midi2_opts_iface_name_store(struct config_item *item, 2576 + const char *page, size_t len) 2577 + { 2578 + struct f_midi2_opts *opts = to_f_midi2_opts(item); 2579 + 2580 + return f_midi2_opts_str_store(opts, &opts->info.iface_name, 128, 2581 + page, len); 2582 + } 2583 + 2584 + CONFIGFS_ATTR(f_midi2_opts_, iface_name); 2585 + 2586 + static struct configfs_attribute *f_midi2_attrs[] = { 2587 + &f_midi2_opts_attr_process_ump, 2588 + &f_midi2_opts_attr_static_block, 2589 + &f_midi2_opts_attr_iface_name, 2590 + NULL 2591 + }; 2592 + 2593 + static void f_midi2_opts_release(struct config_item *item) 2594 + { 2595 + struct f_midi2_opts *opts = to_f_midi2_opts(item); 2596 + 2597 + usb_put_function_instance(&opts->func_inst); 2598 + } 2599 + 2600 + static struct configfs_item_operations f_midi2_item_ops = { 2601 + .release = f_midi2_opts_release, 2602 + }; 2603 + 2604 + static struct configfs_group_operations f_midi2_group_ops = { 2605 + .make_group = f_midi2_opts_ep_make, 2606 + .drop_item = f_midi2_opts_ep_drop, 2607 + }; 2608 + 2609 + static const struct config_item_type f_midi2_func_type = { 2610 + .ct_item_ops = &f_midi2_item_ops, 2611 + .ct_group_ops = &f_midi2_group_ops, 2612 + .ct_attrs = f_midi2_attrs, 2613 + .ct_owner = THIS_MODULE, 2614 + }; 2615 + 2616 + static void f_midi2_free_inst(struct usb_function_instance *f) 2617 + { 2618 + struct f_midi2_opts *opts; 2619 + 2620 + opts = container_of(f, struct f_midi2_opts, func_inst); 2621 + 2622 + kfree(opts->info.iface_name); 2623 + kfree(opts); 2624 + } 2625 + 2626 + /* gadget alloc_inst */ 2627 + static struct usb_function_instance *f_midi2_alloc_inst(void) 2628 + { 2629 + struct f_midi2_opts *opts; 2630 + struct f_midi2_ep_opts *ep_opts; 2631 + struct f_midi2_block_opts *block_opts; 2632 + int ret; 2633 + 2634 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 2635 + if (!opts) 2636 + return ERR_PTR(-ENOMEM); 2637 + 2638 + mutex_init(&opts->lock); 2639 + opts->func_inst.free_func_inst = f_midi2_free_inst; 2640 + opts->info.process_ump = true; 2641 + opts->info.static_block = true; 2642 + opts->info.num_reqs = 32; 2643 + opts->info.req_buf_size = 512; 2644 + 2645 + /* create the default ep */ 2646 + ret = f_midi2_ep_opts_create(opts, 0, &ep_opts); 2647 + if (ret) { 2648 + kfree(opts); 2649 + return ERR_PTR(ret); 2650 + } 2651 + 2652 + /* create the default block */ 2653 + ret = f_midi2_block_opts_create(ep_opts, 0, &block_opts); 2654 + if (ret) { 2655 + kfree(ep_opts); 2656 + kfree(opts); 2657 + return ERR_PTR(ret); 2658 + } 2659 + 2660 + /* set up the default MIDI1 (that is mandatory) */ 2661 + block_opts->info.midi1_num_groups = 1; 2662 + 2663 + config_group_init_type_name(&opts->func_inst.group, "", 2664 + &f_midi2_func_type); 2665 + 2666 + config_group_init_type_name(&ep_opts->group, "ep.0", 2667 + &f_midi2_ep_type); 2668 + configfs_add_default_group(&ep_opts->group, &opts->func_inst.group); 2669 + 2670 + config_group_init_type_name(&block_opts->group, "block.0", 2671 + &f_midi2_block_type); 2672 + configfs_add_default_group(&block_opts->group, &ep_opts->group); 2673 + 2674 + return &opts->func_inst; 2675 + } 2676 + 2677 + static void do_f_midi2_free(struct f_midi2 *midi2, struct f_midi2_opts *opts) 2678 + { 2679 + mutex_lock(&opts->lock); 2680 + --opts->refcnt; 2681 + mutex_unlock(&opts->lock); 2682 + kfree(midi2->string_defs); 2683 + kfree(midi2); 2684 + } 2685 + 2686 + static void f_midi2_free(struct usb_function *f) 2687 + { 2688 + do_f_midi2_free(func_to_midi2(f), 2689 + container_of(f->fi, struct f_midi2_opts, func_inst)); 2690 + } 2691 + 2692 + /* verify the parameters set up via configfs; 2693 + * return the number of EPs or a negative error 2694 + */ 2695 + static int verify_parameters(struct f_midi2_opts *opts) 2696 + { 2697 + int i, j, num_eps, num_blks; 2698 + struct f_midi2_ep_info *ep; 2699 + struct f_midi2_block_info *bp; 2700 + 2701 + for (num_eps = 0; num_eps < MAX_UMP_EPS && opts->eps[num_eps]; 2702 + num_eps++) 2703 + ; 2704 + if (!num_eps) { 2705 + pr_err("f_midi2: No EP is defined\n"); 2706 + return -EINVAL; 2707 + } 2708 + 2709 + num_blks = 0; 2710 + for (i = 0; i < num_eps; i++) { 2711 + ep = &opts->eps[i]->info; 2712 + if (!(ep->protocol_caps & ep->protocol)) { 2713 + pr_err("f_midi2: Invalid protocol 0x%x (caps 0x%x) for EP %d\n", 2714 + ep->protocol, ep->protocol_caps, i); 2715 + return -EINVAL; 2716 + } 2717 + 2718 + for (j = 0; j < SNDRV_UMP_MAX_BLOCKS && opts->eps[i]->blks[j]; 2719 + j++, num_blks++) { 2720 + bp = &opts->eps[i]->blks[j]->info; 2721 + if (bp->first_group + bp->num_groups > SNDRV_UMP_MAX_GROUPS) { 2722 + pr_err("f_midi2: Invalid group definitions for block %d:%d\n", 2723 + i, j); 2724 + return -EINVAL; 2725 + } 2726 + 2727 + if (bp->midi1_num_groups) { 2728 + if (bp->midi1_first_group < bp->first_group || 2729 + bp->midi1_first_group + bp->midi1_num_groups > 2730 + bp->first_group + bp->num_groups) { 2731 + pr_err("f_midi2: Invalid MIDI1 group definitions for block %d:%d\n", 2732 + i, j); 2733 + return -EINVAL; 2734 + } 2735 + } 2736 + } 2737 + } 2738 + if (!num_blks) { 2739 + pr_err("f_midi2: No block is defined\n"); 2740 + return -EINVAL; 2741 + } 2742 + 2743 + return num_eps; 2744 + } 2745 + 2746 + /* fill mapping between MIDI 1.0 cable and UMP EP/group */ 2747 + static void fill_midi1_cable_mapping(struct f_midi2 *midi2, 2748 + struct f_midi2_ep *ep, 2749 + int blk) 2750 + { 2751 + const struct f_midi2_block_info *binfo = &ep->blks[blk].info; 2752 + struct midi1_cable_mapping *map; 2753 + int i, group; 2754 + 2755 + if (!binfo->midi1_num_groups) 2756 + return; 2757 + if (binfo->direction != SNDRV_UMP_DIR_OUTPUT) { 2758 + group = binfo->midi1_first_group; 2759 + map = midi2->in_cable_mapping + midi2->num_midi1_in; 2760 + for (i = 0; i < binfo->midi1_num_groups; i++, group++, map++) { 2761 + if (midi2->num_midi1_in >= MAX_CABLES) 2762 + break; 2763 + map->ep = ep; 2764 + map->block = blk; 2765 + map->group = group; 2766 + midi2->num_midi1_in++; 2767 + /* store 1-based cable number */ 2768 + ep->in_group_to_cable[group] = midi2->num_midi1_in; 2769 + } 2770 + } 2771 + 2772 + if (binfo->direction != SNDRV_UMP_DIR_INPUT) { 2773 + group = binfo->midi1_first_group; 2774 + map = midi2->out_cable_mapping + midi2->num_midi1_out; 2775 + for (i = 0; i < binfo->midi1_num_groups; i++, group++, map++) { 2776 + if (midi2->num_midi1_out >= MAX_CABLES) 2777 + break; 2778 + map->ep = ep; 2779 + map->block = blk; 2780 + map->group = group; 2781 + midi2->num_midi1_out++; 2782 + } 2783 + } 2784 + } 2785 + 2786 + /* gadget alloc callback */ 2787 + static struct usb_function *f_midi2_alloc(struct usb_function_instance *fi) 2788 + { 2789 + struct f_midi2 *midi2; 2790 + struct f_midi2_opts *opts; 2791 + struct f_midi2_ep *ep; 2792 + struct f_midi2_block *bp; 2793 + int i, num_eps, blk; 2794 + 2795 + midi2 = kzalloc(sizeof(*midi2), GFP_KERNEL); 2796 + if (!midi2) 2797 + return ERR_PTR(-ENOMEM); 2798 + 2799 + opts = container_of(fi, struct f_midi2_opts, func_inst); 2800 + mutex_lock(&opts->lock); 2801 + num_eps = verify_parameters(opts); 2802 + if (num_eps < 0) { 2803 + mutex_unlock(&opts->lock); 2804 + kfree(midi2); 2805 + return ERR_PTR(num_eps); 2806 + } 2807 + ++opts->refcnt; 2808 + mutex_unlock(&opts->lock); 2809 + 2810 + spin_lock_init(&midi2->queue_lock); 2811 + 2812 + midi2->func.name = "midi2_func"; 2813 + midi2->func.bind = f_midi2_bind; 2814 + midi2->func.unbind = f_midi2_unbind; 2815 + midi2->func.get_alt = f_midi2_get_alt; 2816 + midi2->func.set_alt = f_midi2_set_alt; 2817 + midi2->func.setup = f_midi2_setup; 2818 + midi2->func.disable = f_midi2_disable; 2819 + midi2->func.free_func = f_midi2_free; 2820 + 2821 + midi2->info = opts->info; 2822 + midi2->num_eps = num_eps; 2823 + 2824 + for (i = 0; i < num_eps; i++) { 2825 + ep = &midi2->midi2_eps[i]; 2826 + ep->info = opts->eps[i]->info; 2827 + ep->card = midi2; 2828 + for (blk = 0; blk < SNDRV_UMP_MAX_BLOCKS && 2829 + opts->eps[i]->blks[blk]; blk++) { 2830 + bp = &ep->blks[blk]; 2831 + ep->num_blks++; 2832 + bp->info = opts->eps[i]->blks[blk]->info; 2833 + bp->gtb_id = ++midi2->total_blocks; 2834 + } 2835 + } 2836 + 2837 + midi2->string_defs = kcalloc(midi2->total_blocks + 1, 2838 + sizeof(*midi2->string_defs), GFP_KERNEL); 2839 + if (!midi2->string_defs) { 2840 + do_f_midi2_free(midi2, opts); 2841 + return ERR_PTR(-ENOMEM); 2842 + } 2843 + 2844 + if (opts->info.iface_name && *opts->info.iface_name) 2845 + midi2->string_defs[STR_IFACE].s = opts->info.iface_name; 2846 + else 2847 + midi2->string_defs[STR_IFACE].s = ump_ep_name(&midi2->midi2_eps[0]); 2848 + 2849 + for (i = 0; i < midi2->num_eps; i++) { 2850 + ep = &midi2->midi2_eps[i]; 2851 + for (blk = 0; blk < ep->num_blks; blk++) { 2852 + bp = &ep->blks[blk]; 2853 + midi2->string_defs[gtb_to_str_id(bp->gtb_id)].s = 2854 + ump_fb_name(&bp->info); 2855 + 2856 + fill_midi1_cable_mapping(midi2, ep, blk); 2857 + } 2858 + } 2859 + 2860 + if (!midi2->num_midi1_in && !midi2->num_midi1_out) { 2861 + pr_err("f_midi2: MIDI1 definition is missing\n"); 2862 + do_f_midi2_free(midi2, opts); 2863 + return ERR_PTR(-EINVAL); 2864 + } 2865 + 2866 + return &midi2->func; 2867 + } 2868 + 2869 + DECLARE_USB_FUNCTION_INIT(midi2, f_midi2_alloc_inst, f_midi2_alloc); 2870 + 2871 + MODULE_LICENSE("GPL");
+3 -20
drivers/usb/gadget/function/f_ncm.c
··· 80 80 return container_of(f, struct f_ncm, port.func); 81 81 } 82 82 83 - /* peak (theoretical) bulk transfer rate in bits-per-second */ 84 - static inline unsigned ncm_bitrate(struct usb_gadget *g) 85 - { 86 - if (!g) 87 - return 0; 88 - else if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER_PLUS) 89 - return 4250000000U; 90 - else if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) 91 - return 3750000000U; 92 - else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 93 - return 13 * 512 * 8 * 1000 * 8; 94 - else 95 - return 19 * 64 * 1 * 1000 * 8; 96 - } 97 - 98 83 /*-------------------------------------------------------------------------*/ 99 84 100 85 /* ··· 561 576 562 577 /* SPEED_CHANGE data is up/down speeds in bits/sec */ 563 578 data = req->buf + sizeof *event; 564 - data[0] = cpu_to_le32(ncm_bitrate(cdev->gadget)); 579 + data[0] = cpu_to_le32(gether_bitrate(cdev->gadget)); 565 580 data[1] = data[0]; 566 581 567 - DBG(cdev, "notify speed %u\n", ncm_bitrate(cdev->gadget)); 582 + DBG(cdev, "notify speed %u\n", gether_bitrate(cdev->gadget)); 568 583 ncm->notify_state = NCM_NOTIFY_CONNECT; 569 584 break; 570 585 } ··· 1529 1544 hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); 1530 1545 ncm->task_timer.function = ncm_tx_timeout; 1531 1546 1532 - DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n", 1533 - gadget_is_superspeed(c->cdev->gadget) ? "super" : 1534 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 1547 + DBG(cdev, "CDC Network: IN/%s OUT/%s NOTIFY/%s\n", 1535 1548 ncm->port.in_ep->name, ncm->port.out_ep->name, 1536 1549 ncm->notify->name); 1537 1550 return 0;
+1 -2
drivers/usb/gadget/function/f_obex.c
··· 365 365 if (status) 366 366 goto fail; 367 367 368 - dev_dbg(&cdev->gadget->dev, "obex ttyGS%d: %s speed IN/%s OUT/%s\n", 368 + dev_dbg(&cdev->gadget->dev, "obex ttyGS%d: IN/%s OUT/%s\n", 369 369 obex->port_num, 370 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 371 370 obex->port.in->name, obex->port.out->name); 372 371 373 372 return 0;
+2 -17
drivers/usb/gadget/function/f_rndis.c
··· 84 84 return container_of(f, struct f_rndis, port.func); 85 85 } 86 86 87 - /* peak (theoretical) bulk transfer rate in bits-per-second */ 88 - static unsigned int bitrate(struct usb_gadget *g) 89 - { 90 - if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER_PLUS) 91 - return 4250000000U; 92 - if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) 93 - return 3750000000U; 94 - else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 95 - return 13 * 512 * 8 * 1000 * 8; 96 - else 97 - return 19 * 64 * 1 * 1000 * 8; 98 - } 99 - 100 87 /*-------------------------------------------------------------------------*/ 101 88 102 89 /* ··· 627 640 DBG(cdev, "%s\n", __func__); 628 641 629 642 rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 630 - bitrate(cdev->gadget) / 100); 643 + gether_bitrate(cdev->gadget) / 100); 631 644 rndis_signal_connect(rndis->params); 632 645 } 633 646 ··· 798 811 * until we're activated via set_alt(). 799 812 */ 800 813 801 - DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n", 802 - gadget_is_superspeed(c->cdev->gadget) ? "super" : 803 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 814 + DBG(cdev, "RNDIS: IN/%s OUT/%s NOTIFY/%s\n", 804 815 rndis->port.in_ep->name, rndis->port.out_ep->name, 805 816 rndis->notify->name); 806 817 return 0;
+1 -3
drivers/usb/gadget/function/f_serial.c
··· 236 236 gser_ss_function, gser_ss_function); 237 237 if (status) 238 238 goto fail; 239 - dev_dbg(&cdev->gadget->dev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", 239 + dev_dbg(&cdev->gadget->dev, "generic ttyGS%d: IN/%s OUT/%s\n", 240 240 gser->port_num, 241 - gadget_is_superspeed(c->cdev->gadget) ? "super" : 242 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 243 241 gser->port.in->name, gser->port.out->name); 244 242 return 0; 245 243
+1 -3
drivers/usb/gadget/function/f_sourcesink.c
··· 436 436 if (ret) 437 437 return ret; 438 438 439 - DBG(cdev, "%s speed %s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s\n", 440 - (gadget_is_superspeed(c->cdev->gadget) ? "super" : 441 - (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), 439 + DBG(cdev, "%s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s\n", 442 440 f->name, ss->in_ep->name, ss->out_ep->name, 443 441 ss->iso_in_ep ? ss->iso_in_ep->name : "<none>", 444 442 ss->iso_out_ep ? ss->iso_out_ep->name : "<none>");
+1 -3
drivers/usb/gadget/function/f_subset.c
··· 367 367 * until we're activated via set_alt(). 368 368 */ 369 369 370 - DBG(cdev, "CDC Subset: %s speed IN/%s OUT/%s\n", 371 - gadget_is_superspeed(c->cdev->gadget) ? "super" : 372 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 370 + DBG(cdev, "CDC Subset: IN/%s OUT/%s\n", 373 371 geth->port.in_ep->name, geth->port.out_ep->name); 374 372 return 0; 375 373
+13 -23
drivers/usb/gadget/function/f_uvc.c
··· 719 719 } 720 720 uvc->enable_interrupt_ep = opts->enable_interrupt_ep; 721 721 722 - if (gadget_is_superspeed(c->cdev->gadget)) 723 - ep = usb_ep_autoconfig_ss(cdev->gadget, &uvc_ss_streaming_ep, 724 - &uvc_ss_streaming_comp); 725 - else if (gadget_is_dualspeed(cdev->gadget)) 726 - ep = usb_ep_autoconfig(cdev->gadget, &uvc_hs_streaming_ep); 727 - else 728 - ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep); 729 - 722 + ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep); 730 723 if (!ep) { 731 724 uvcg_info(f, "Unable to allocate streaming EP\n"); 732 725 goto error; 733 726 } 734 727 uvc->video.ep = ep; 735 728 736 - uvc_fs_streaming_ep.bEndpointAddress = uvc->video.ep->address; 737 729 uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address; 738 730 uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address; 739 731 ··· 780 788 f->fs_descriptors = NULL; 781 789 goto error; 782 790 } 783 - if (gadget_is_dualspeed(cdev->gadget)) { 784 - f->hs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_HIGH); 785 - if (IS_ERR(f->hs_descriptors)) { 786 - ret = PTR_ERR(f->hs_descriptors); 787 - f->hs_descriptors = NULL; 788 - goto error; 789 - } 791 + 792 + f->hs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_HIGH); 793 + if (IS_ERR(f->hs_descriptors)) { 794 + ret = PTR_ERR(f->hs_descriptors); 795 + f->hs_descriptors = NULL; 796 + goto error; 790 797 } 791 - if (gadget_is_superspeed(c->cdev->gadget)) { 792 - f->ss_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_SUPER); 793 - if (IS_ERR(f->ss_descriptors)) { 794 - ret = PTR_ERR(f->ss_descriptors); 795 - f->ss_descriptors = NULL; 796 - goto error; 797 - } 798 + 799 + f->ss_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_SUPER); 800 + if (IS_ERR(f->ss_descriptors)) { 801 + ret = PTR_ERR(f->ss_descriptors); 802 + f->ss_descriptors = NULL; 803 + goto error; 798 804 } 799 805 800 806 /* Preallocate control endpoint request. */
+2 -3
drivers/usb/gadget/function/u_ether.c
··· 93 93 94 94 #define DEFAULT_QLEN 2 /* double buffering by default */ 95 95 96 - /* for dual-speed hardware, use deeper queues at high/super speed */ 96 + /* use deeper queues at high/super speed */ 97 97 static inline int qlen(struct usb_gadget *gadget, unsigned qmult) 98 98 { 99 - if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH || 100 - gadget->speed >= USB_SPEED_SUPER)) 99 + if (gadget->speed == USB_SPEED_HIGH || gadget->speed >= USB_SPEED_SUPER) 101 100 return qmult * DEFAULT_QLEN; 102 101 else 103 102 return DEFAULT_QLEN;
+13
drivers/usb/gadget/function/u_ether.h
··· 279 279 return true; 280 280 } 281 281 282 + /* peak (theoretical) bulk transfer rate in bits-per-second */ 283 + static inline unsigned int gether_bitrate(struct usb_gadget *g) 284 + { 285 + if (g->speed >= USB_SPEED_SUPER_PLUS) 286 + return 4250000000U; 287 + if (g->speed == USB_SPEED_SUPER) 288 + return 3750000000U; 289 + else if (g->speed == USB_SPEED_HIGH) 290 + return 13 * 512 * 8 * 1000 * 8; 291 + else 292 + return 19 * 64 * 1 * 1000 * 8; 293 + } 294 + 282 295 #endif /* __U_ETHER_H */
+81
drivers/usb/gadget/function/u_midi2.h
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Utility definitions for MIDI 2.0 function 4 + */ 5 + 6 + #ifndef U_MIDI2_H 7 + #define U_MIDI2_H 8 + 9 + #include <linux/usb/composite.h> 10 + #include <sound/asound.h> 11 + 12 + struct f_midi2_opts; 13 + struct f_midi2_ep_opts; 14 + struct f_midi2_block_opts; 15 + 16 + /* UMP Function Block info */ 17 + struct f_midi2_block_info { 18 + unsigned int direction; /* FB direction: 1-3 */ 19 + unsigned int first_group; /* first UMP group: 0-15 */ 20 + unsigned int num_groups; /* number of UMP groups: 1-16 */ 21 + unsigned int midi1_first_group; /* first UMP group for MIDI 1.0 */ 22 + unsigned int midi1_num_groups; /* number of UMP groups for MIDI 1.0 */ 23 + unsigned int ui_hint; /* UI-hint: 0-3 */ 24 + unsigned int midi_ci_version; /* MIDI-CI version: 0-255 */ 25 + unsigned int sysex8_streams; /* number of sysex8 streams: 0-255 */ 26 + unsigned int is_midi1; /* MIDI 1.0 port: 0-2 */ 27 + bool active; /* FB active flag: bool */ 28 + const char *name; /* FB name */ 29 + }; 30 + 31 + /* UMP Endpoint info */ 32 + struct f_midi2_ep_info { 33 + unsigned int protocol_caps; /* protocol capabilities: 1-3 */ 34 + unsigned int protocol; /* default protocol: 1-2 */ 35 + unsigned int manufacturer; /* manufacturer id: 0-0xffffff */ 36 + unsigned int family; /* device family id: 0-0xffff */ 37 + unsigned int model; /* device model id: 0x-0xffff */ 38 + unsigned int sw_revision; /* software revision: 32bit */ 39 + 40 + const char *ep_name; /* Endpoint name */ 41 + const char *product_id; /* Product ID */ 42 + }; 43 + 44 + struct f_midi2_card_info { 45 + bool process_ump; /* process UMP stream: bool */ 46 + bool static_block; /* static FBs: bool */ 47 + unsigned int req_buf_size; /* request buffer size */ 48 + unsigned int num_reqs; /* number of requests */ 49 + const char *iface_name; /* interface name */ 50 + }; 51 + 52 + struct f_midi2_block_opts { 53 + struct config_group group; 54 + unsigned int id; 55 + struct f_midi2_block_info info; 56 + struct f_midi2_ep_opts *ep; 57 + }; 58 + 59 + struct f_midi2_ep_opts { 60 + struct config_group group; 61 + unsigned int index; 62 + struct f_midi2_ep_info info; 63 + struct f_midi2_block_opts *blks[SNDRV_UMP_MAX_BLOCKS]; 64 + struct f_midi2_opts *opts; 65 + }; 66 + 67 + #define MAX_UMP_EPS 4 68 + #define MAX_CABLES 16 69 + 70 + struct f_midi2_opts { 71 + struct usb_function_instance func_inst; 72 + struct mutex lock; 73 + int refcnt; 74 + 75 + struct f_midi2_card_info info; 76 + 77 + unsigned int num_eps; 78 + struct f_midi2_ep_opts *eps[MAX_UMP_EPS]; 79 + }; 80 + 81 + #endif /* U_MIDI2_H */
-1
drivers/usb/gadget/function/u_phonet.h
··· 20 20 struct net_device *gphonet_setup_default(void); 21 21 void gphonet_set_gadget(struct net_device *net, struct usb_gadget *g); 22 22 int gphonet_register_netdev(struct net_device *net); 23 - int phonet_bind_config(struct usb_configuration *c, struct net_device *dev); 24 23 void gphonet_cleanup(struct net_device *dev); 25 24 26 25 #endif /* __U_PHONET_H */
-4
drivers/usb/gadget/function/u_serial.h
··· 71 71 void gserial_suspend(struct gserial *p); 72 72 void gserial_resume(struct gserial *p); 73 73 74 - /* functions are bound to configurations by a config or gadget driver */ 75 - int gser_bind_config(struct usb_configuration *c, u8 port_num); 76 - int obex_bind_config(struct usb_configuration *c, u8 port_num); 77 - 78 74 #endif /* __U_SERIAL_H */
-2
drivers/usb/gadget/function/uvc.h
··· 178 178 */ 179 179 180 180 extern void uvc_function_setup_continue(struct uvc_device *uvc); 181 - extern void uvc_endpoint_stream(struct uvc_device *dev); 182 - 183 181 extern void uvc_function_connect(struct uvc_device *uvc); 184 182 extern void uvc_function_disconnect(struct uvc_device *uvc); 185 183
+1 -2
drivers/usb/gadget/udc/aspeed-vhub/core.c
··· 328 328 vhub->port_irq_mask = GENMASK(VHUB_IRQ_DEV1_BIT + vhub->max_ports - 1, 329 329 VHUB_IRQ_DEV1_BIT); 330 330 331 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 332 - vhub->regs = devm_ioremap_resource(&pdev->dev, res); 331 + vhub->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 333 332 if (IS_ERR(vhub->regs)) { 334 333 dev_err(&pdev->dev, "Failed to map resources\n"); 335 334 return PTR_ERR(vhub->regs);
+1 -3
drivers/usb/gadget/udc/aspeed_udc.c
··· 1468 1468 enum usb_device_speed max_speed; 1469 1469 struct device *dev = &pdev->dev; 1470 1470 struct ast_udc_dev *udc; 1471 - struct resource *res; 1472 1471 int rc; 1473 1472 1474 1473 udc = devm_kzalloc(&pdev->dev, sizeof(struct ast_udc_dev), GFP_KERNEL); ··· 1483 1484 udc->gadget.name = "aspeed-udc"; 1484 1485 udc->gadget.dev.init_name = "gadget"; 1485 1486 1486 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1487 - udc->reg = devm_ioremap_resource(&pdev->dev, res); 1487 + udc->reg = devm_platform_ioremap_resource(pdev, 0); 1488 1488 if (IS_ERR(udc->reg)) { 1489 1489 dev_err(&pdev->dev, "Failed to map resources\n"); 1490 1490 return PTR_ERR(udc->reg);
+2 -4
drivers/usb/gadget/udc/atmel_usba_udc.c
··· 2285 2285 udc->gadget = usba_gadget_template; 2286 2286 INIT_LIST_HEAD(&udc->gadget.ep_list); 2287 2287 2288 - res = platform_get_resource(pdev, IORESOURCE_MEM, CTRL_IOMEM_ID); 2289 - udc->regs = devm_ioremap_resource(&pdev->dev, res); 2288 + udc->regs = devm_platform_get_and_ioremap_resource(pdev, CTRL_IOMEM_ID, &res); 2290 2289 if (IS_ERR(udc->regs)) 2291 2290 return PTR_ERR(udc->regs); 2292 2291 dev_info(&pdev->dev, "MMIO registers at %pR mapped at %p\n", 2293 2292 res, udc->regs); 2294 2293 2295 - res = platform_get_resource(pdev, IORESOURCE_MEM, FIFO_IOMEM_ID); 2296 - udc->fifo = devm_ioremap_resource(&pdev->dev, res); 2294 + udc->fifo = devm_platform_get_and_ioremap_resource(pdev, FIFO_IOMEM_ID, &res); 2297 2295 if (IS_ERR(udc->fifo)) 2298 2296 return PTR_ERR(udc->fifo); 2299 2297 dev_info(&pdev->dev, "FIFO at %pR mapped at %p\n", res, udc->fifo);
+1
drivers/usb/gadget/udc/core.c
··· 40 40 * @allow_connect: Indicates whether UDC is allowed to be pulled up. 41 41 * Set/cleared by gadget_(un)bind_driver() after gadget driver is bound or 42 42 * unbound. 43 + * @vbus_work: work routine to handle VBUS status change notifications. 43 44 * @connect_lock: protects udc->started, gadget->connect, 44 45 * gadget->allow_connect and gadget->deactivate. The routines 45 46 * usb_gadget_connect_locked(), usb_gadget_disconnect_locked(),
+2
drivers/usb/gadget/udc/fsl_qe_udc.c
··· 1959 1959 } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_ENDPOINT) { 1960 1960 /* Get endpoint status */ 1961 1961 int pipe = index & USB_ENDPOINT_NUMBER_MASK; 1962 + if (pipe >= USB_MAX_ENDPOINTS) 1963 + goto stall; 1962 1964 struct qe_ep *target_ep = &udc->eps[pipe]; 1963 1965 u16 usep; 1964 1966
+1 -2
drivers/usb/gadget/udc/fsl_udc_core.c
··· 36 36 #include <linux/platform_device.h> 37 37 #include <linux/fsl_devices.h> 38 38 #include <linux/dmapool.h> 39 - #include <linux/of_device.h> 40 39 41 40 #include <asm/byteorder.h> 42 41 #include <asm/io.h> ··· 671 672 static struct usb_request * 672 673 fsl_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) 673 674 { 674 - struct fsl_req *req = NULL; 675 + struct fsl_req *req; 675 676 676 677 req = kzalloc(sizeof *req, gfp_flags); 677 678 if (!req)
+6 -7
drivers/usb/gadget/udc/gr_udc.c
··· 23 23 24 24 #include <linux/kernel.h> 25 25 #include <linux/module.h> 26 + #include <linux/platform_device.h> 26 27 #include <linux/slab.h> 27 28 #include <linux/spinlock.h> 28 29 #include <linux/errno.h> ··· 37 36 #include <linux/dmapool.h> 38 37 #include <linux/debugfs.h> 39 38 #include <linux/seq_file.h> 40 - #include <linux/of_platform.h> 41 - #include <linux/of_irq.h> 42 - #include <linux/of_address.h> 39 + #include <linux/of.h> 43 40 44 41 #include <asm/byteorder.h> 45 42 ··· 2136 2137 return PTR_ERR(regs); 2137 2138 2138 2139 dev->irq = platform_get_irq(pdev, 0); 2139 - if (dev->irq <= 0) 2140 - return -ENODEV; 2140 + if (dev->irq < 0) 2141 + return dev->irq; 2141 2142 2142 2143 /* Some core configurations has separate irqs for IN and OUT events */ 2143 2144 dev->irqi = platform_get_irq(pdev, 1); 2144 2145 if (dev->irqi > 0) { 2145 2146 dev->irqo = platform_get_irq(pdev, 2); 2146 - if (dev->irqo <= 0) 2147 - return -ENODEV; 2147 + if (dev->irqo < 0) 2148 + return dev->irqo; 2148 2149 } else { 2149 2150 dev->irqi = 0; 2150 2151 }
+1 -3
drivers/usb/gadget/udc/max3420_udc.c
··· 19 19 #include <linux/io.h> 20 20 #include <linux/module.h> 21 21 #include <linux/bitfield.h> 22 - #include <linux/of_address.h> 23 - #include <linux/of_device.h> 24 - #include <linux/of_platform.h> 22 + #include <linux/of.h> 25 23 #include <linux/of_irq.h> 26 24 #include <linux/prefetch.h> 27 25 #include <linux/usb/ch9.h>
+2 -2
drivers/usb/gadget/udc/mv_u3d_core.c
··· 665 665 static struct usb_request * 666 666 mv_u3d_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) 667 667 { 668 - struct mv_u3d_req *req = NULL; 668 + struct mv_u3d_req *req; 669 669 670 670 req = kzalloc(sizeof *req, gfp_flags); 671 671 if (!req) ··· 1779 1779 1780 1780 static int mv_u3d_probe(struct platform_device *dev) 1781 1781 { 1782 - struct mv_u3d *u3d = NULL; 1782 + struct mv_u3d *u3d; 1783 1783 struct mv_usb_platform_data *pdata = dev_get_platdata(&dev->dev); 1784 1784 int retval = 0; 1785 1785 struct resource *r;
+1 -1
drivers/usb/gadget/udc/mv_udc_core.c
··· 595 595 static struct usb_request * 596 596 mv_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) 597 597 { 598 - struct mv_req *req = NULL; 598 + struct mv_req *req; 599 599 600 600 req = kzalloc(sizeof *req, gfp_flags); 601 601 if (!req)
+1 -1
drivers/usb/gadget/udc/pxa27x_udc.c
··· 23 23 #include <linux/prefetch.h> 24 24 #include <linux/byteorder/generic.h> 25 25 #include <linux/platform_data/pxa2xx_udc.h> 26 - #include <linux/of_device.h> 26 + #include <linux/of.h> 27 27 #include <linux/of_gpio.h> 28 28 29 29 #include <linux/usb.h>
+1 -1
drivers/usb/gadget/udc/renesas_usb3.c
··· 14 14 #include <linux/interrupt.h> 15 15 #include <linux/io.h> 16 16 #include <linux/module.h> 17 - #include <linux/of_device.h> 17 + #include <linux/of.h> 18 18 #include <linux/phy/phy.h> 19 19 #include <linux/platform_device.h> 20 20 #include <linux/pm_runtime.h>
+2 -4
drivers/usb/gadget/udc/renesas_usbf.c
··· 12 12 #include <linux/iopoll.h> 13 13 #include <linux/kernel.h> 14 14 #include <linux/kfifo.h> 15 + #include <linux/mod_devicetable.h> 15 16 #include <linux/module.h> 16 - #include <linux/of_address.h> 17 - #include <linux/of_irq.h> 18 - #include <linux/of_platform.h> 17 + #include <linux/platform_device.h> 19 18 #include <linux/pm_runtime.h> 20 19 #include <linux/types.h> 21 20 #include <linux/usb/composite.h> ··· 3378 3379 static struct platform_driver udc_driver = { 3379 3380 .driver = { 3380 3381 .name = "usbf_renesas", 3381 - .owner = THIS_MODULE, 3382 3382 .of_match_table = usbf_match, 3383 3383 }, 3384 3384 .probe = usbf_probe,
+2 -5
drivers/usb/gadget/udc/snps_udc_plat.c
··· 112 112 spin_lock_init(&udc->lock); 113 113 udc->dev = dev; 114 114 115 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 116 - udc->virt_addr = devm_ioremap_resource(dev, res); 115 + udc->virt_addr = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 117 116 if (IS_ERR(udc->virt_addr)) 118 117 return PTR_ERR(udc->virt_addr); 119 118 ··· 300 301 }; 301 302 #endif 302 303 303 - #if defined(CONFIG_OF) 304 304 static const struct of_device_id of_udc_match[] = { 305 305 { .compatible = "brcm,ns2-udc", }, 306 306 { .compatible = "brcm,cygnus-udc", }, ··· 307 309 { } 308 310 }; 309 311 MODULE_DEVICE_TABLE(of, of_udc_match); 310 - #endif 311 312 312 313 static struct platform_driver udc_plat_driver = { 313 314 .probe = udc_plat_probe, 314 315 .remove_new = udc_plat_remove, 315 316 .driver = { 316 317 .name = "snps-udc-plat", 317 - .of_match_table = of_match_ptr(of_udc_match), 318 + .of_match_table = of_udc_match, 318 319 #ifdef CONFIG_PM_SLEEP 319 320 .pm = &udc_plat_pm_ops, 320 321 #endif
-1
drivers/usb/gadget/udc/tegra-xudc.c
··· 16 16 #include <linux/kernel.h> 17 17 #include <linux/module.h> 18 18 #include <linux/of.h> 19 - #include <linux/of_device.h> 20 19 #include <linux/phy/phy.h> 21 20 #include <linux/phy/tegra/xusb.h> 22 21 #include <linux/pm_domain.h>
+17 -18
drivers/usb/gadget/udc/udc-xilinx.c
··· 18 18 #include <linux/interrupt.h> 19 19 #include <linux/io.h> 20 20 #include <linux/module.h> 21 - #include <linux/of_address.h> 22 - #include <linux/of_device.h> 23 - #include <linux/of_platform.h> 24 - #include <linux/of_irq.h> 21 + #include <linux/of.h> 22 + #include <linux/platform_device.h> 25 23 #include <linux/prefetch.h> 26 24 #include <linux/usb/ch9.h> 27 25 #include <linux/usb/gadget.h> ··· 1615 1617 case USB_RECIP_INTERFACE: 1616 1618 break; 1617 1619 case USB_RECIP_ENDPOINT: 1618 - epnum = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; 1620 + epnum = le16_to_cpu(udc->setup.wIndex) & USB_ENDPOINT_NUMBER_MASK; 1619 1621 if (epnum >= XUSB_MAX_ENDPOINTS) 1620 1622 goto stall; 1621 1623 target_ep = &udc->ep[epnum]; 1622 1624 epcfgreg = udc->read_fn(udc->addr + target_ep->offset); 1623 1625 halt = epcfgreg & XUSB_EP_CFG_STALL_MASK; 1624 - if (udc->setup.wIndex & USB_DIR_IN) { 1626 + if (le16_to_cpu(udc->setup.wIndex) & USB_DIR_IN) { 1625 1627 if (!target_ep->is_in) 1626 1628 goto stall; 1627 1629 } else { ··· 1636 1638 } 1637 1639 1638 1640 req->usb_req.length = 2; 1639 - *(u16 *)req->usb_req.buf = cpu_to_le16(status); 1641 + *(__le16 *)req->usb_req.buf = cpu_to_le16(status); 1640 1642 ret = __xudc_ep0_queue(ep0, req); 1641 1643 if (ret == 0) 1642 1644 return; ··· 1664 1666 1665 1667 switch (udc->setup.bRequestType) { 1666 1668 case USB_RECIP_DEVICE: 1667 - switch (udc->setup.wValue) { 1669 + switch (le16_to_cpu(udc->setup.wValue)) { 1668 1670 case USB_DEVICE_TEST_MODE: 1669 1671 /* 1670 1672 * The Test Mode will be executed ··· 1684 1686 break; 1685 1687 case USB_RECIP_ENDPOINT: 1686 1688 if (!udc->setup.wValue) { 1687 - endpoint = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; 1689 + endpoint = le16_to_cpu(udc->setup.wIndex) & 1690 + USB_ENDPOINT_NUMBER_MASK; 1688 1691 if (endpoint >= XUSB_MAX_ENDPOINTS) { 1689 1692 xudc_ep0_stall(udc); 1690 1693 return; 1691 1694 } 1692 1695 target_ep = &udc->ep[endpoint]; 1693 - outinbit = udc->setup.wIndex & USB_ENDPOINT_DIR_MASK; 1696 + outinbit = le16_to_cpu(udc->setup.wIndex) & 1697 + USB_ENDPOINT_DIR_MASK; 1694 1698 outinbit = outinbit >> 7; 1695 1699 1696 1700 /* Make sure direction matches.*/ ··· 1755 1755 memcpy(&setup, ep0rambase, 8); 1756 1756 1757 1757 udc->setup = setup; 1758 - udc->setup.wValue = cpu_to_le16(setup.wValue); 1759 - udc->setup.wIndex = cpu_to_le16(setup.wIndex); 1760 - udc->setup.wLength = cpu_to_le16(setup.wLength); 1758 + udc->setup.wValue = cpu_to_le16((u16 __force)setup.wValue); 1759 + udc->setup.wIndex = cpu_to_le16((u16 __force)setup.wIndex); 1760 + udc->setup.wLength = cpu_to_le16((u16 __force)setup.wLength); 1761 1761 1762 1762 /* Clear previous requests */ 1763 1763 xudc_nuke(ep0, -ECONNRESET); ··· 1869 1869 u16 count = 0; 1870 1870 u16 length; 1871 1871 u8 *ep0rambase; 1872 - u8 test_mode = udc->setup.wIndex >> 8; 1872 + u8 test_mode = le16_to_cpu(udc->setup.wIndex) >> 8; 1873 1873 1874 1874 req = list_first_entry(&ep0->queue, struct xusb_req, queue); 1875 1875 bytes_to_tx = req->usb_req.length - req->usb_req.actual; ··· 1880 1880 case USB_REQ_SET_ADDRESS: 1881 1881 /* Set the address of the device.*/ 1882 1882 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 1883 - udc->setup.wValue); 1883 + le16_to_cpu(udc->setup.wValue)); 1884 1884 break; 1885 1885 case USB_REQ_SET_FEATURE: 1886 1886 if (udc->setup.bRequestType == 1887 1887 USB_RECIP_DEVICE) { 1888 - if (udc->setup.wValue == 1888 + if (le16_to_cpu(udc->setup.wValue) == 1889 1889 USB_DEVICE_TEST_MODE) 1890 1890 udc->write_fn(udc->addr, 1891 1891 XUSB_TESTMODE_OFFSET, ··· 2080 2080 udc->req->usb_req.buf = buff; 2081 2081 2082 2082 /* Map the registers */ 2083 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2084 - udc->addr = devm_ioremap_resource(&pdev->dev, res); 2083 + udc->addr = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 2085 2084 if (IS_ERR(udc->addr)) 2086 2085 return PTR_ERR(udc->addr); 2087 2086
+3 -4
drivers/usb/host/ehci-atmel.c
··· 102 102 pr_debug("Initializing Atmel-SoC USB Host Controller\n"); 103 103 104 104 irq = platform_get_irq(pdev, 0); 105 - if (irq <= 0) { 106 - retval = -ENODEV; 105 + if (irq < 0) { 106 + retval = irq; 107 107 goto fail_create_hcd; 108 108 } 109 109 ··· 122 122 } 123 123 atmel_ehci = hcd_to_atmel_ehci_priv(hcd); 124 124 125 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 126 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 125 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 127 126 if (IS_ERR(hcd->regs)) { 128 127 retval = PTR_ERR(hcd->regs); 129 128 goto fail_request_resource;
+2 -2
drivers/usb/host/ehci-brcm.c
··· 140 140 return err; 141 141 142 142 irq = platform_get_irq(pdev, 0); 143 - if (irq <= 0) 144 - return irq ? irq : -EINVAL; 143 + if (irq < 0) 144 + return irq; 145 145 146 146 /* Hook the hub control routine to work around a bug */ 147 147 ehci_brcm_hc_driver.hub_control = ehci_brcm_hub_control;
+1 -2
drivers/usb/host/ehci-exynos.c
··· 173 173 if (err) 174 174 goto fail_clk; 175 175 176 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 177 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 176 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 178 177 if (IS_ERR(hcd->regs)) { 179 178 err = PTR_ERR(hcd->regs); 180 179 goto fail_io;
+2 -3
drivers/usb/host/ehci-fsl.c
··· 22 22 #include <linux/usb/otg.h> 23 23 #include <linux/platform_device.h> 24 24 #include <linux/fsl_devices.h> 25 - #include <linux/of_platform.h> 25 + #include <linux/of.h> 26 26 #include <linux/io.h> 27 27 28 28 #include "ehci.h" ··· 87 87 goto err1; 88 88 } 89 89 90 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 91 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 90 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 92 91 if (IS_ERR(hcd->regs)) { 93 92 retval = PTR_ERR(hcd->regs); 94 93 goto err2;
+6 -2
drivers/usb/host/ehci-hcd.c
··· 755 755 756 756 /* normal [4.15.1.2] or error [4.15.1.1] completion */ 757 757 if (likely ((status & (STS_INT|STS_ERR)) != 0)) { 758 - if (likely ((status & STS_ERR) == 0)) 758 + if (likely ((status & STS_ERR) == 0)) { 759 759 INCR(ehci->stats.normal); 760 - else 760 + } else { 761 + /* Force to check port status */ 762 + if (ehci->has_ci_pec_bug) 763 + status |= STS_PCD; 761 764 INCR(ehci->stats.error); 765 + } 762 766 bh = 1; 763 767 } 764 768
+9 -1
drivers/usb/host/ehci-hub.c
··· 674 674 675 675 if ((temp & mask) != 0 || test_bit(i, &ehci->port_c_suspend) 676 676 || (ehci->reset_done[i] && time_after_eq( 677 - jiffies, ehci->reset_done[i]))) { 677 + jiffies, ehci->reset_done[i])) 678 + || ehci_has_ci_pec_bug(ehci, temp)) { 678 679 if (i < 7) 679 680 buf [0] |= 1 << (i + 1); 680 681 else ··· 875 874 status |= USB_PORT_STAT_C_CONNECTION << 16; 876 875 if (temp & PORT_PEC) 877 876 status |= USB_PORT_STAT_C_ENABLE << 16; 877 + 878 + if (ehci_has_ci_pec_bug(ehci, temp)) { 879 + status |= USB_PORT_STAT_C_ENABLE << 16; 880 + ehci_info(ehci, 881 + "PE is cleared by HW port:%d PORTSC:%08x\n", 882 + wIndex + 1, temp); 883 + } 878 884 879 885 if ((temp & PORT_OCC) && (!ignore_oc && !ehci->spurious_oc)){ 880 886 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
+1 -2
drivers/usb/host/ehci-mv.c
··· 142 142 goto err_put_hcd; 143 143 } 144 144 145 - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 146 - ehci_mv->base = devm_ioremap_resource(&pdev->dev, r); 145 + ehci_mv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &r); 147 146 if (IS_ERR(ehci_mv->base)) { 148 147 retval = PTR_ERR(ehci_mv->base); 149 148 goto err_put_hcd;
+2 -3
drivers/usb/host/ehci-npcm7xx.c
··· 53 53 int irq; 54 54 int retval; 55 55 56 - dev_dbg(&pdev->dev, "initializing npcm7xx ehci USB Controller\n"); 56 + dev_dbg(&pdev->dev, "initializing npcm7xx ehci USB Controller\n"); 57 57 58 58 if (usb_disabled()) 59 59 return -ENODEV; ··· 79 79 goto fail; 80 80 } 81 81 82 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 83 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 82 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 84 83 if (IS_ERR(hcd->regs)) { 85 84 retval = PTR_ERR(hcd->regs); 86 85 goto err_put_hcd;
+1 -2
drivers/usb/host/ehci-omap.c
··· 113 113 if (irq < 0) 114 114 return irq; 115 115 116 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 117 - regs = devm_ioremap_resource(dev, res); 116 + regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 118 117 if (IS_ERR(regs)) 119 118 return PTR_ERR(regs); 120 119
+3 -6
drivers/usb/host/ehci-orion.c
··· 13 13 #include <linux/platform_data/usb-ehci-orion.h> 14 14 #include <linux/of.h> 15 15 #include <linux/phy/phy.h> 16 - #include <linux/of_device.h> 17 - #include <linux/of_irq.h> 18 16 #include <linux/usb.h> 19 17 #include <linux/usb/hcd.h> 20 18 #include <linux/io.h> ··· 218 220 pr_debug("Initializing Orion-SoC USB Host Controller\n"); 219 221 220 222 irq = platform_get_irq(pdev, 0); 221 - if (irq <= 0) { 222 - err = -ENODEV; 223 + if (irq < 0) { 224 + err = irq; 223 225 goto err; 224 226 } 225 227 ··· 232 234 if (err) 233 235 goto err; 234 236 235 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 236 - regs = devm_ioremap_resource(&pdev->dev, res); 237 + regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 237 238 if (IS_ERR(regs)) { 238 239 err = PTR_ERR(regs); 239 240 goto err;
+1 -2
drivers/usb/host/ehci-platform.c
··· 359 359 goto err_reset; 360 360 } 361 361 362 - res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); 363 - hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); 362 + hcd->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res_mem); 364 363 if (IS_ERR(hcd->regs)) { 365 364 err = PTR_ERR(hcd->regs); 366 365 goto err_power;
+2 -1
drivers/usb/host/ehci-sched.c
··· 490 490 static void enable_periodic(struct ehci_hcd *ehci) 491 491 { 492 492 if (ehci->periodic_count++) 493 - return; 493 + goto out; 494 494 495 495 /* Stop waiting to turn off the periodic schedule */ 496 496 ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_DISABLE_PERIODIC); 497 497 498 498 /* Don't start the schedule until PSS is 0 */ 499 499 ehci_poll_PSS(ehci); 500 + out: 500 501 turn_on_io_watchdog(ehci); 501 502 } 502 503
+3 -4
drivers/usb/host/ehci-sh.c
··· 82 82 return -ENODEV; 83 83 84 84 irq = platform_get_irq(pdev, 0); 85 - if (irq <= 0) { 86 - ret = -ENODEV; 85 + if (irq < 0) { 86 + ret = irq; 87 87 goto fail_create_hcd; 88 88 } 89 89 ··· 95 95 goto fail_create_hcd; 96 96 } 97 97 98 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 99 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 98 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 100 99 if (IS_ERR(hcd->regs)) { 101 100 ret = PTR_ERR(hcd->regs); 102 101 goto fail_request_resource;
+1 -2
drivers/usb/host/ehci-spear.c
··· 91 91 goto fail; 92 92 } 93 93 94 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 95 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 94 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 96 95 if (IS_ERR(hcd->regs)) { 97 96 retval = PTR_ERR(hcd->regs); 98 97 goto err_put_hcd;
+3 -9
drivers/usb/host/ehci-st.c
··· 158 158 irq = platform_get_irq(dev, 0); 159 159 if (irq < 0) 160 160 return irq; 161 - res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); 162 - if (!res_mem) { 163 - dev_err(&dev->dev, "no memory resource provided"); 164 - return -ENXIO; 165 - } 166 161 167 162 hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev, 168 163 dev_name(&dev->dev)); ··· 217 222 goto err_put_clks; 218 223 } 219 224 220 - hcd->rsrc_start = res_mem->start; 221 - hcd->rsrc_len = resource_size(res_mem); 222 - 223 - hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); 225 + hcd->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res_mem); 224 226 if (IS_ERR(hcd->regs)) { 225 227 err = PTR_ERR(hcd->regs); 226 228 goto err_put_clks; 227 229 } 230 + hcd->rsrc_start = res_mem->start; 231 + hcd->rsrc_len = resource_size(res_mem); 228 232 229 233 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 230 234 if (err)
+10
drivers/usb/host/ehci.h
··· 207 207 unsigned has_fsl_port_bug:1; /* FreeScale */ 208 208 unsigned has_fsl_hs_errata:1; /* Freescale HS quirk */ 209 209 unsigned has_fsl_susp_errata:1; /* NXP SUSP quirk */ 210 + unsigned has_ci_pec_bug:1; /* ChipIdea PEC bug */ 210 211 unsigned big_endian_mmio:1; 211 212 unsigned big_endian_desc:1; 212 213 unsigned big_endian_capbase:1; ··· 707 706 * after setting SUSP bit. 708 707 */ 709 708 #define ehci_has_fsl_susp_errata(e) ((e)->has_fsl_susp_errata) 709 + 710 + /* 711 + * Some Freescale/NXP processors using ChipIdea IP have a bug in which 712 + * disabling the port (PE is cleared) does not cause PEC to be asserted 713 + * when frame babble is detected. 714 + */ 715 + #define ehci_has_ci_pec_bug(e, portsc) \ 716 + ((e)->has_ci_pec_bug && ((e)->command & CMD_PSE) \ 717 + && !(portsc & PORT_PEC) && !(portsc & PORT_PE)) 710 718 711 719 /* 712 720 * While most USB host controllers implement their registers in
+2 -1
drivers/usb/host/fhci-hcd.c
··· 22 22 #include <linux/io.h> 23 23 #include <linux/usb.h> 24 24 #include <linux/usb/hcd.h> 25 + #include <linux/of.h> 25 26 #include <linux/of_address.h> 26 27 #include <linux/of_irq.h> 27 - #include <linux/of_platform.h> 28 + #include <linux/platform_device.h> 28 29 #include <linux/slab.h> 29 30 #include <linux/gpio/consumer.h> 30 31 #include <soc/fsl/qe/qe.h>
+2 -1
drivers/usb/host/fsl-mph-dr-of.c
··· 10 10 #include <linux/fsl_devices.h> 11 11 #include <linux/err.h> 12 12 #include <linux/io.h> 13 - #include <linux/of_platform.h> 13 + #include <linux/of.h> 14 + #include <linux/of_device.h> 14 15 #include <linux/clk.h> 15 16 #include <linux/module.h> 16 17 #include <linux/dma-mapping.h>
+1 -2
drivers/usb/host/isp1362-hcd.c
··· 2651 2651 if (IS_ERR(addr_reg)) 2652 2652 return PTR_ERR(addr_reg); 2653 2653 2654 - data = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2655 - data_reg = devm_ioremap_resource(&pdev->dev, data); 2654 + data_reg = devm_platform_get_and_ioremap_resource(pdev, 0, &data); 2656 2655 if (IS_ERR(data_reg)) 2657 2656 return PTR_ERR(data_reg); 2658 2657
+3 -6
drivers/usb/host/ohci-at91.c
··· 17 17 #include <linux/clk.h> 18 18 #include <linux/dma-mapping.h> 19 19 #include <linux/gpio/consumer.h> 20 - #include <linux/of_platform.h> 21 20 #include <linux/platform_device.h> 22 21 #include <linux/platform_data/atmel.h> 23 22 #include <linux/io.h> 24 23 #include <linux/kernel.h> 25 24 #include <linux/module.h> 26 25 #include <linux/mfd/syscon.h> 26 + #include <linux/of.h> 27 27 #include <linux/regmap.h> 28 28 #include <linux/usb.h> 29 29 #include <linux/usb/hcd.h> ··· 190 190 int irq; 191 191 192 192 irq = platform_get_irq(pdev, 0); 193 - if (irq < 0) { 194 - dev_dbg(dev, "hcd probe: missing irq resource\n"); 193 + if (irq < 0) 195 194 return irq; 196 - } 197 195 198 196 hcd = usb_create_hcd(driver, dev, "at91"); 199 197 if (!hcd) 200 198 return -ENOMEM; 201 199 ohci_at91 = hcd_to_ohci_at91_priv(hcd); 202 200 203 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 204 - hcd->regs = devm_ioremap_resource(dev, res); 201 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 205 202 if (IS_ERR(hcd->regs)) { 206 203 retval = PTR_ERR(hcd->regs); 207 204 goto err;
+2 -2
drivers/usb/host/ohci-da8xx.c
··· 15 15 #include <linux/jiffies.h> 16 16 #include <linux/kernel.h> 17 17 #include <linux/module.h> 18 + #include <linux/of.h> 18 19 #include <linux/platform_device.h> 19 20 #include <linux/phy/phy.h> 20 21 #include <linux/platform_data/usb-davinci.h> ··· 436 435 goto err; 437 436 } 438 437 439 - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 440 - hcd->regs = devm_ioremap_resource(dev, mem); 438 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem); 441 439 if (IS_ERR(hcd->regs)) { 442 440 error = PTR_ERR(hcd->regs); 443 441 goto err;
+1 -2
drivers/usb/host/ohci-exynos.c
··· 149 149 if (err) 150 150 goto fail_clk; 151 151 152 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 153 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 152 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 154 153 if (IS_ERR(hcd->regs)) { 155 154 err = PTR_ERR(hcd->regs); 156 155 goto fail_io;
+1 -2
drivers/usb/host/ohci-nxp.c
··· 202 202 goto fail_hcd; 203 203 } 204 204 205 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 206 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 205 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 207 206 if (IS_ERR(hcd->regs)) { 208 207 ret = PTR_ERR(hcd->regs); 209 208 goto fail_resource;
+1 -2
drivers/usb/host/ohci-platform.c
··· 200 200 goto err_reset; 201 201 } 202 202 203 - res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); 204 - hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); 203 + hcd->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res_mem); 205 204 if (IS_ERR(hcd->regs)) { 206 205 err = PTR_ERR(hcd->regs); 207 206 goto err_power;
+2 -1
drivers/usb/host/ohci-ppc-of.c
··· 15 15 */ 16 16 17 17 #include <linux/signal.h> 18 + #include <linux/of.h> 18 19 #include <linux/of_address.h> 19 20 #include <linux/of_irq.h> 20 - #include <linux/of_platform.h> 21 + #include <linux/platform_device.h> 21 22 22 23 static int 23 24 ohci_ppc_of_start(struct usb_hcd *hcd)
+1 -2
drivers/usb/host/ohci-pxa27x.c
··· 435 435 if (!hcd) 436 436 return -ENOMEM; 437 437 438 - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 439 - hcd->regs = devm_ioremap_resource(&pdev->dev, r); 438 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &r); 440 439 if (IS_ERR(hcd->regs)) { 441 440 retval = PTR_ERR(hcd->regs); 442 441 goto err;
+1 -2
drivers/usb/host/ohci-sm501.c
··· 195 195 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 196 196 usb_put_hcd(hcd); 197 197 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); 198 - if (mem) 199 - release_mem_region(mem->start, resource_size(mem)); 198 + release_mem_region(mem->start, resource_size(mem)); 200 199 201 200 /* mask interrupts and disable power */ 202 201
+1 -2
drivers/usb/host/ohci-spear.c
··· 68 68 goto fail; 69 69 } 70 70 71 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 72 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 71 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 73 72 if (IS_ERR(hcd->regs)) { 74 73 retval = PTR_ERR(hcd->regs); 75 74 goto err_put_hcd;
+4 -10
drivers/usb/host/ohci-st.c
··· 139 139 if (irq < 0) 140 140 return irq; 141 141 142 - res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); 143 - if (!res_mem) { 144 - dev_err(&dev->dev, "no memory resource provided"); 145 - return -ENXIO; 146 - } 147 - 148 142 hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev, 149 143 dev_name(&dev->dev)); 150 144 if (!hcd) ··· 193 199 goto err_power; 194 200 } 195 201 196 - hcd->rsrc_start = res_mem->start; 197 - hcd->rsrc_len = resource_size(res_mem); 198 - 199 - hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); 202 + hcd->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res_mem); 200 203 if (IS_ERR(hcd->regs)) { 201 204 err = PTR_ERR(hcd->regs); 202 205 goto err_power; 203 206 } 207 + hcd->rsrc_start = res_mem->start; 208 + hcd->rsrc_len = resource_size(res_mem); 209 + 204 210 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 205 211 if (err) 206 212 goto err_power;
+1 -2
drivers/usb/host/oxu210hp-hcd.c
··· 4230 4230 return irq; 4231 4231 dev_dbg(&pdev->dev, "IRQ resource %d\n", irq); 4232 4232 4233 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 4234 - base = devm_ioremap_resource(&pdev->dev, res); 4233 + base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 4235 4234 if (IS_ERR(base)) { 4236 4235 ret = PTR_ERR(base); 4237 4236 goto error;
+1 -2
drivers/usb/host/uhci-platform.c
··· 91 91 92 92 uhci = hcd_to_uhci(hcd); 93 93 94 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 95 - hcd->regs = devm_ioremap_resource(&pdev->dev, res); 94 + hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 96 95 if (IS_ERR(hcd->regs)) { 97 96 ret = PTR_ERR(hcd->regs); 98 97 goto err_rmr;
-3
drivers/usb/host/xhci-mem.c
··· 1108 1108 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS); 1109 1109 max_packets = MAX_PACKET(8); 1110 1110 break; 1111 - case USB_SPEED_WIRELESS: 1112 - xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); 1113 - return -EINVAL; 1114 1111 default: 1115 1112 /* Speed was set earlier, this shouldn't happen. */ 1116 1113 return -EINVAL;
-1
drivers/usb/host/xhci-plat.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/pci.h> 15 15 #include <linux/of.h> 16 - #include <linux/of_device.h> 17 16 #include <linux/platform_device.h> 18 17 #include <linux/usb/phy.h> 19 18 #include <linux/slab.h>
-1
drivers/usb/host/xhci-rcar.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/platform_device.h> 12 12 #include <linux/of.h> 13 - #include <linux/of_device.h> 14 13 #include <linux/usb/phy.h> 15 14 16 15 #include "xhci.h"
+22 -8
drivers/usb/host/xhci-tegra.c
··· 14 14 #include <linux/iopoll.h> 15 15 #include <linux/kernel.h> 16 16 #include <linux/module.h> 17 - #include <linux/of_device.h> 17 + #include <linux/of.h> 18 18 #include <linux/of_irq.h> 19 19 #include <linux/phy/phy.h> 20 20 #include <linux/phy/tegra/xusb.h> ··· 1912 1912 return err; 1913 1913 } 1914 1914 1915 + static void tegra_xusb_disable(struct tegra_xusb *tegra) 1916 + { 1917 + tegra_xusb_powergate_partitions(tegra); 1918 + tegra_xusb_powerdomain_remove(tegra->dev, tegra); 1919 + tegra_xusb_phy_disable(tegra); 1920 + tegra_xusb_clk_disable(tegra); 1921 + regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); 1922 + } 1923 + 1915 1924 static void tegra_xusb_remove(struct platform_device *pdev) 1916 1925 { 1917 1926 struct tegra_xusb *tegra = platform_get_drvdata(pdev); ··· 1943 1934 1944 1935 pm_runtime_put(&pdev->dev); 1945 1936 1946 - tegra_xusb_powergate_partitions(tegra); 1947 - 1948 - tegra_xusb_powerdomain_remove(&pdev->dev, tegra); 1949 - 1950 - tegra_xusb_phy_disable(tegra); 1951 - tegra_xusb_clk_disable(tegra); 1952 - regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); 1937 + tegra_xusb_disable(tegra); 1953 1938 tegra_xusb_padctl_put(tegra->padctl); 1939 + } 1940 + 1941 + static void tegra_xusb_shutdown(struct platform_device *pdev) 1942 + { 1943 + struct tegra_xusb *tegra = platform_get_drvdata(pdev); 1944 + 1945 + pm_runtime_get_sync(&pdev->dev); 1946 + disable_irq(tegra->xhci_irq); 1947 + xhci_shutdown(tegra->hcd); 1948 + tegra_xusb_disable(tegra); 1954 1949 } 1955 1950 1956 1951 static bool xhci_hub_ports_suspended(struct xhci_hub *hub) ··· 2665 2652 static struct platform_driver tegra_xusb_driver = { 2666 2653 .probe = tegra_xusb_probe, 2667 2654 .remove_new = tegra_xusb_remove, 2655 + .shutdown = tegra_xusb_shutdown, 2668 2656 .driver = { 2669 2657 .name = "tegra-xusb", 2670 2658 .pm = &tegra_xusb_pm_ops,
+2 -9
drivers/usb/host/xhci.c
··· 2194 2194 case USB_SPEED_SUPER_PLUS: 2195 2195 return SS_BLOCK; 2196 2196 case USB_SPEED_UNKNOWN: 2197 - case USB_SPEED_WIRELESS: 2198 2197 default: 2199 2198 /* Should never happen */ 2200 2199 return 1; ··· 2554 2555 case USB_SPEED_HIGH: 2555 2556 interval_bw->overhead[HS_OVERHEAD_TYPE] -= 1; 2556 2557 break; 2557 - case USB_SPEED_SUPER: 2558 - case USB_SPEED_SUPER_PLUS: 2559 - case USB_SPEED_UNKNOWN: 2560 - case USB_SPEED_WIRELESS: 2558 + default: 2561 2559 /* Should never happen because only LS/FS/HS endpoints will get 2562 2560 * added to the endpoint list. 2563 2561 */ ··· 2611 2615 case USB_SPEED_HIGH: 2612 2616 interval_bw->overhead[HS_OVERHEAD_TYPE] += 1; 2613 2617 break; 2614 - case USB_SPEED_SUPER: 2615 - case USB_SPEED_SUPER_PLUS: 2616 - case USB_SPEED_UNKNOWN: 2617 - case USB_SPEED_WIRELESS: 2618 + default: 2618 2619 /* Should never happen because only LS/FS/HS endpoints will get 2619 2620 * added to the endpoint list. 2620 2621 */
+1 -1
drivers/usb/misc/cypress_cy7c63.c
··· 203 203 static int cypress_probe(struct usb_interface *interface, 204 204 const struct usb_device_id *id) 205 205 { 206 - struct cypress *dev = NULL; 206 + struct cypress *dev; 207 207 int retval = -ENOMEM; 208 208 209 209 /* allocate memory for our device state and initialize it */
+6 -6
drivers/usb/misc/cytherm.c
··· 304 304 const struct usb_device_id *id) 305 305 { 306 306 struct usb_device *udev = interface_to_usbdev(interface); 307 - struct usb_cytherm *dev = NULL; 307 + struct usb_cytherm *dev; 308 308 int retval = -ENOMEM; 309 309 310 - dev = kzalloc (sizeof(struct usb_cytherm), GFP_KERNEL); 310 + dev = kzalloc(sizeof(struct usb_cytherm), GFP_KERNEL); 311 311 if (!dev) 312 312 goto error_mem; 313 313 314 314 dev->udev = usb_get_dev(udev); 315 315 316 - usb_set_intfdata (interface, dev); 316 + usb_set_intfdata(interface, dev); 317 317 318 318 dev->brightness = 0xFF; 319 319 320 - dev_info (&interface->dev, 320 + dev_info(&interface->dev, 321 321 "Cypress thermometer device now attached\n"); 322 322 return 0; 323 323 ··· 329 329 { 330 330 struct usb_cytherm *dev; 331 331 332 - dev = usb_get_intfdata (interface); 332 + dev = usb_get_intfdata(interface); 333 333 334 334 /* first remove the files, then NULL the pointer */ 335 - usb_set_intfdata (interface, NULL); 335 + usb_set_intfdata(interface, NULL); 336 336 337 337 usb_put_dev(dev->udev); 338 338
+33 -8
drivers/usb/misc/onboard_usb_hub.c
··· 27 27 28 28 #include "onboard_usb_hub.h" 29 29 30 + /* 31 + * Use generic names, as the actual names might differ between hubs. If a new 32 + * hub requires more than the currently supported supplies, add a new one here. 33 + */ 34 + static const char * const supply_names[] = { 35 + "vdd", 36 + "vdd2", 37 + }; 38 + 39 + #define MAX_SUPPLIES ARRAY_SIZE(supply_names) 40 + 30 41 static void onboard_hub_attach_usb_driver(struct work_struct *work); 31 42 32 43 static struct usb_device_driver onboard_hub_usbdev_driver; ··· 51 40 }; 52 41 53 42 struct onboard_hub { 54 - struct regulator *vdd; 43 + struct regulator_bulk_data supplies[MAX_SUPPLIES]; 55 44 struct device *dev; 56 45 const struct onboard_hub_pdata *pdata; 57 46 struct gpio_desc *reset_gpio; ··· 66 55 { 67 56 int err; 68 57 69 - err = regulator_enable(hub->vdd); 58 + err = regulator_bulk_enable(hub->pdata->num_supplies, hub->supplies); 70 59 if (err) { 71 - dev_err(hub->dev, "failed to enable regulator: %d\n", err); 60 + dev_err(hub->dev, "failed to enable supplies: %d\n", err); 72 61 return err; 73 62 } 74 63 ··· 86 75 87 76 gpiod_set_value_cansleep(hub->reset_gpio, 1); 88 77 89 - err = regulator_disable(hub->vdd); 78 + err = regulator_bulk_disable(hub->pdata->num_supplies, hub->supplies); 90 79 if (err) { 91 - dev_err(hub->dev, "failed to disable regulator: %d\n", err); 80 + dev_err(hub->dev, "failed to disable supplies: %d\n", err); 92 81 return err; 93 82 } 94 83 ··· 243 232 const struct of_device_id *of_id; 244 233 struct device *dev = &pdev->dev; 245 234 struct onboard_hub *hub; 235 + unsigned int i; 246 236 int err; 247 237 248 238 hub = devm_kzalloc(dev, sizeof(*hub), GFP_KERNEL); ··· 258 246 if (!hub->pdata) 259 247 return -EINVAL; 260 248 261 - hub->vdd = devm_regulator_get(dev, "vdd"); 262 - if (IS_ERR(hub->vdd)) 263 - return PTR_ERR(hub->vdd); 249 + if (hub->pdata->num_supplies > MAX_SUPPLIES) 250 + return dev_err_probe(dev, -EINVAL, "max %zu supplies supported!\n", 251 + MAX_SUPPLIES); 252 + 253 + for (i = 0; i < hub->pdata->num_supplies; i++) 254 + hub->supplies[i].supply = supply_names[i]; 255 + 256 + err = devm_regulator_bulk_get(dev, hub->pdata->num_supplies, hub->supplies); 257 + if (err) { 258 + dev_err(dev, "Failed to get regulator supplies: %d\n", err); 259 + return err; 260 + } 264 261 265 262 hub->reset_gpio = devm_gpiod_get_optional(dev, "reset", 266 263 GPIOD_OUT_HIGH); ··· 350 329 351 330 /************************** USB driver **************************/ 352 331 332 + #define VENDOR_ID_CYPRESS 0x04b4 353 333 #define VENDOR_ID_GENESYS 0x05e3 354 334 #define VENDOR_ID_MICROCHIP 0x0424 355 335 #define VENDOR_ID_REALTEK 0x0bda ··· 429 407 } 430 408 431 409 static const struct usb_device_id onboard_hub_id_table[] = { 410 + { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6504) }, /* CYUSB33{0,1,2}x/CYUSB230x 3.0 */ 411 + { USB_DEVICE(VENDOR_ID_CYPRESS, 0x6506) }, /* CYUSB33{0,1,2}x/CYUSB230x 2.0 */ 432 412 { USB_DEVICE(VENDOR_ID_GENESYS, 0x0608) }, /* Genesys Logic GL850G USB 2.0 */ 433 413 { USB_DEVICE(VENDOR_ID_GENESYS, 0x0610) }, /* Genesys Logic GL852G USB 2.0 */ 414 + { USB_DEVICE(VENDOR_ID_GENESYS, 0x0620) }, /* Genesys Logic GL3523 USB 3.1 */ 434 415 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2514) }, /* USB2514B USB 2.0 */ 435 416 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2517) }, /* USB2517 USB 2.0 */ 436 417 { USB_DEVICE(VENDOR_ID_REALTEK, 0x0411) }, /* RTS5411 USB 3.1 */
+15
drivers/usb/misc/onboard_usb_hub.h
··· 8 8 9 9 struct onboard_hub_pdata { 10 10 unsigned long reset_us; /* reset pulse width in us */ 11 + unsigned int num_supplies; /* number of supplies */ 11 12 }; 12 13 13 14 static const struct onboard_hub_pdata microchip_usb424_data = { 14 15 .reset_us = 1, 16 + .num_supplies = 1, 15 17 }; 16 18 17 19 static const struct onboard_hub_pdata realtek_rts5411_data = { 18 20 .reset_us = 0, 21 + .num_supplies = 1, 19 22 }; 20 23 21 24 static const struct onboard_hub_pdata ti_tusb8041_data = { 22 25 .reset_us = 3000, 26 + .num_supplies = 1, 27 + }; 28 + 29 + static const struct onboard_hub_pdata cypress_hx3_data = { 30 + .reset_us = 10000, 31 + .num_supplies = 2, 23 32 }; 24 33 25 34 static const struct onboard_hub_pdata genesys_gl850g_data = { 26 35 .reset_us = 3, 36 + .num_supplies = 1, 27 37 }; 28 38 29 39 static const struct onboard_hub_pdata genesys_gl852g_data = { 30 40 .reset_us = 50, 41 + .num_supplies = 1, 31 42 }; 32 43 33 44 static const struct onboard_hub_pdata vialab_vl817_data = { 34 45 .reset_us = 10, 46 + .num_supplies = 1, 35 47 }; 36 48 37 49 static const struct of_device_id onboard_hub_match[] = { ··· 51 39 { .compatible = "usb424,2517", .data = &microchip_usb424_data, }, 52 40 { .compatible = "usb451,8140", .data = &ti_tusb8041_data, }, 53 41 { .compatible = "usb451,8142", .data = &ti_tusb8041_data, }, 42 + { .compatible = "usb4b4,6504", .data = &cypress_hx3_data, }, 43 + { .compatible = "usb4b4,6506", .data = &cypress_hx3_data, }, 54 44 { .compatible = "usb5e3,608", .data = &genesys_gl850g_data, }, 55 45 { .compatible = "usb5e3,610", .data = &genesys_gl852g_data, }, 46 + { .compatible = "usb5e3,620", .data = &genesys_gl852g_data, }, 56 47 { .compatible = "usbbda,411", .data = &realtek_rts5411_data, }, 57 48 { .compatible = "usbbda,5411", .data = &realtek_rts5411_data, }, 58 49 { .compatible = "usbbda,414", .data = &realtek_rts5411_data, },
+1 -1
drivers/usb/misc/usb251xb.c
··· 16 16 #include <linux/i2c.h> 17 17 #include <linux/module.h> 18 18 #include <linux/nls.h> 19 - #include <linux/of_device.h> 19 + #include <linux/of.h> 20 20 #include <linux/regulator/consumer.h> 21 21 #include <linux/slab.h> 22 22
-97
drivers/usb/misc/usb_u132.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * Common Header File for the Elan Digital Systems U132 adapter 4 - * this file should be included by both the "ftdi-u132" and 5 - * the "u132-hcd" modules. 6 - * 7 - * Copyright(C) 2006 Elan Digital Systems Limited 8 - *(http://www.elandigitalsystems.com) 9 - * 10 - * Author and Maintainer - Tony Olech - Elan Digital Systems 11 - *(tony.olech@elandigitalsystems.com) 12 - * 13 - * The driver was written by Tony Olech(tony.olech@elandigitalsystems.com) 14 - * based on various USB client drivers in the 2.6.15 linux kernel 15 - * with constant reference to the 3rd Edition of Linux Device Drivers 16 - * published by O'Reilly 17 - * 18 - * The U132 adapter is a USB to CardBus adapter specifically designed 19 - * for PC cards that contain an OHCI host controller. Typical PC cards 20 - * are the Orange Mobile 3G Option GlobeTrotter Fusion card. 21 - * 22 - * The U132 adapter will *NOT *work with PC cards that do not contain 23 - * an OHCI controller. A simple way to test whether a PC card has an 24 - * OHCI controller as an interface is to insert the PC card directly 25 - * into a laptop(or desktop) with a CardBus slot and if "lspci" shows 26 - * a new USB controller and "lsusb -v" shows a new OHCI Host Controller 27 - * then there is a good chance that the U132 adapter will support the 28 - * PC card.(you also need the specific client driver for the PC card) 29 - * 30 - * Please inform the Author and Maintainer about any PC cards that 31 - * contain OHCI Host Controller and work when directly connected to 32 - * an embedded CardBus slot but do not work when they are connected 33 - * via an ELAN U132 adapter. 34 - * 35 - * The driver consists of two modules, the "ftdi-u132" module is 36 - * a USB client driver that interfaces to the FTDI chip within 37 - * the U132 adapter manufactured by Elan Digital Systems, and the 38 - * "u132-hcd" module is a USB host controller driver that talks 39 - * to the OHCI controller within CardBus card that are inserted 40 - * in the U132 adapter. 41 - * 42 - * The "ftdi-u132" module should be loaded automatically by the 43 - * hot plug system when the U132 adapter is plugged in. The module 44 - * initialises the adapter which mostly consists of synchronising 45 - * the FTDI chip, before continuously polling the adapter to detect 46 - * PC card insertions. As soon as a PC card containing a recognised 47 - * OHCI controller is seen the "ftdi-u132" module explicitly requests 48 - * the kernel to load the "u132-hcd" module. 49 - * 50 - * The "ftdi-u132" module provides the interface to the inserted 51 - * PC card and the "u132-hcd" module uses the API to send and receive 52 - * data. The API features call-backs, so that part of the "u132-hcd" 53 - * module code will run in the context of one of the kernel threads 54 - * of the "ftdi-u132" module. 55 - * 56 - */ 57 - int ftdi_elan_switch_on_diagnostics(int number); 58 - void ftdi_elan_gone_away(struct platform_device *pdev); 59 - void start_usb_lock_device_tracing(void); 60 - struct u132_platform_data { 61 - u16 vendor; 62 - u16 device; 63 - u8 potpg; 64 - void (*port_power) (struct device *dev, int is_on); 65 - void (*reset) (struct device *dev); 66 - }; 67 - int usb_ftdi_elan_edset_single(struct platform_device *pdev, u8 ed_number, 68 - void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, 69 - void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 70 - int toggle_bits, int error_count, int condition_code, int repeat_number, 71 - int halted, int skipped, int actual, int non_null)); 72 - int usb_ftdi_elan_edset_output(struct platform_device *pdev, u8 ed_number, 73 - void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, 74 - void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 75 - int toggle_bits, int error_count, int condition_code, int repeat_number, 76 - int halted, int skipped, int actual, int non_null)); 77 - int usb_ftdi_elan_edset_empty(struct platform_device *pdev, u8 ed_number, 78 - void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, 79 - void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 80 - int toggle_bits, int error_count, int condition_code, int repeat_number, 81 - int halted, int skipped, int actual, int non_null)); 82 - int usb_ftdi_elan_edset_input(struct platform_device *pdev, u8 ed_number, 83 - void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, 84 - void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 85 - int toggle_bits, int error_count, int condition_code, int repeat_number, 86 - int halted, int skipped, int actual, int non_null)); 87 - int usb_ftdi_elan_edset_setup(struct platform_device *pdev, u8 ed_number, 88 - void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, 89 - void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 90 - int toggle_bits, int error_count, int condition_code, int repeat_number, 91 - int halted, int skipped, int actual, int non_null)); 92 - int usb_ftdi_elan_edset_flush(struct platform_device *pdev, u8 ed_number, 93 - void *endp); 94 - int usb_ftdi_elan_read_pcimem(struct platform_device *pdev, int mem_offset, 95 - u8 width, u32 *data); 96 - int usb_ftdi_elan_write_pcimem(struct platform_device *pdev, int mem_offset, 97 - u8 width, u32 data);
+1 -1
drivers/usb/misc/usbsevseg.c
··· 305 305 const struct usb_device_id *id) 306 306 { 307 307 struct usb_device *udev = interface_to_usbdev(interface); 308 - struct usb_sevsegdev *mydev = NULL; 308 + struct usb_sevsegdev *mydev; 309 309 int rc = -ENOMEM; 310 310 311 311 mydev = kzalloc(sizeof(struct usb_sevsegdev), GFP_KERNEL);
+1
drivers/usb/mtu3/mtu3.h
··· 16 16 #include <linux/extcon.h> 17 17 #include <linux/interrupt.h> 18 18 #include <linux/list.h> 19 + #include <linux/of.h> 19 20 #include <linux/phy/phy.h> 20 21 #include <linux/regulator/consumer.h> 21 22 #include <linux/usb.h>
+1
drivers/usb/mtu3/mtu3_host.c
··· 11 11 #include <linux/irq.h> 12 12 #include <linux/kernel.h> 13 13 #include <linux/mfd/syscon.h> 14 + #include <linux/of.h> 14 15 #include <linux/of_platform.h> 15 16 #include <linux/regmap.h> 16 17
-3
drivers/usb/musb/cppi_dma.h
··· 121 121 struct list_head tx_complete; 122 122 }; 123 123 124 - /* CPPI IRQ handler */ 125 - extern irqreturn_t cppi_interrupt(int, void *); 126 - 127 124 struct cppi41_dma_channel { 128 125 struct dma_channel channel; 129 126 struct cppi41_dma_controller *controller;
+1 -1
drivers/usb/musb/jz4740.c
··· 10 10 #include <linux/errno.h> 11 11 #include <linux/kernel.h> 12 12 #include <linux/module.h> 13 - #include <linux/of_device.h> 13 + #include <linux/of.h> 14 14 #include <linux/phy/phy.h> 15 15 #include <linux/platform_device.h> 16 16 #include <linux/usb/role.h>
+1
drivers/usb/musb/mediatek.c
··· 10 10 #include <linux/clk.h> 11 11 #include <linux/dma-mapping.h> 12 12 #include <linux/module.h> 13 + #include <linux/of.h> 13 14 #include <linux/of_platform.h> 14 15 #include <linux/platform_device.h> 15 16 #include <linux/usb/role.h>
+1
drivers/usb/musb/mpfs.c
··· 13 13 #include <linux/io.h> 14 14 #include <linux/kernel.h> 15 15 #include <linux/module.h> 16 + #include <linux/of.h> 16 17 #include <linux/platform_device.h> 17 18 #include <linux/usb/usb_phy_generic.h> 18 19 #include "musb_core.h"
+2 -2
drivers/usb/musb/musb_core.c
··· 2610 2610 int irq = platform_get_irq_byname(pdev, "mc"); 2611 2611 void __iomem *base; 2612 2612 2613 - if (irq <= 0) 2614 - return -ENODEV; 2613 + if (irq < 0) 2614 + return irq; 2615 2615 2616 2616 base = devm_platform_ioremap_resource(pdev, 0); 2617 2617 if (IS_ERR(base))
-4
drivers/usb/musb/musb_dma.h
··· 199 199 extern void tusb_dma_controller_destroy(struct dma_controller *c); 200 200 201 201 extern struct dma_controller * 202 - cppi_dma_controller_create(struct musb *musb, void __iomem *base); 203 - extern void cppi_dma_controller_destroy(struct dma_controller *c); 204 - 205 - extern struct dma_controller * 206 202 cppi41_dma_controller_create(struct musb *musb, void __iomem *base); 207 203 extern void cppi41_dma_controller_destroy(struct dma_controller *c); 208 204
-2
drivers/usb/musb/musb_dsps.c
··· 26 26 #include <linux/sizes.h> 27 27 28 28 #include <linux/of.h> 29 - #include <linux/of_device.h> 30 29 #include <linux/of_address.h> 31 - #include <linux/of_irq.h> 32 30 #include <linux/usb/of.h> 33 31 34 32 #include <linux/debugfs.h>
+1 -1
drivers/usb/musb/musb_gadget.c
··· 1130 1130 struct usb_request *musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) 1131 1131 { 1132 1132 struct musb_ep *musb_ep = to_musb_ep(ep); 1133 - struct musb_request *request = NULL; 1133 + struct musb_request *request; 1134 1134 1135 1135 request = kzalloc(sizeof *request, gfp_flags); 1136 1136 if (!request)
-1
drivers/usb/musb/sunxi.c
··· 15 15 #include <linux/kernel.h> 16 16 #include <linux/module.h> 17 17 #include <linux/of.h> 18 - #include <linux/of_device.h> 19 18 #include <linux/phy/phy-sun4i-usb.h> 20 19 #include <linux/platform_device.h> 21 20 #include <linux/reset.h>
+7 -10
drivers/usb/musb/tusb6010.c
··· 21 21 #include <linux/usb.h> 22 22 #include <linux/irq.h> 23 23 #include <linux/io.h> 24 + #include <linux/iopoll.h> 24 25 #include <linux/device.h> 25 26 #include <linux/platform_device.h> 26 27 #include <linux/dma-mapping.h> ··· 1030 1029 void __iomem *tbase = musb->ctrl_base; 1031 1030 unsigned long flags; 1032 1031 u32 reg; 1033 - int i; 1032 + int ret; 1034 1033 1035 1034 /* 1036 1035 * Enable or disable power to TUSB6010. When enabling, turn on 3.3 V and ··· 1038 1037 * provide then PGOOD signal to TUSB6010 which will release it from reset. 1039 1038 */ 1040 1039 gpiod_set_value(glue->enable, 1); 1041 - msleep(1); 1042 1040 1043 1041 /* Wait for 100ms until TUSB6010 pulls INT pin down */ 1044 - i = 100; 1045 - while (i && gpiod_get_value(glue->intpin)) { 1046 - msleep(1); 1047 - i--; 1048 - } 1049 - if (!i) { 1050 - pr_err("tusb: Powerup respones failed\n"); 1051 - return -ENODEV; 1042 + ret = read_poll_timeout(gpiod_get_value, reg, !reg, 5000, 100000, true, 1043 + glue->intpin); 1044 + if (ret) { 1045 + pr_err("tusb: Powerup response failed\n"); 1046 + return ret; 1052 1047 } 1053 1048 1054 1049 spin_lock_irqsave(&musb->lock, flags);
+6 -10
drivers/usb/phy/phy-mxs-usb.c
··· 14 14 #include <linux/delay.h> 15 15 #include <linux/err.h> 16 16 #include <linux/io.h> 17 - #include <linux/of_device.h> 17 + #include <linux/of.h> 18 18 #include <linux/regmap.h> 19 19 #include <linux/mfd/syscon.h> 20 20 #include <linux/iopoll.h> ··· 388 388 389 389 static bool mxs_phy_is_otg_host(struct mxs_phy *mxs_phy) 390 390 { 391 - void __iomem *base = mxs_phy->phy.io_priv; 392 - u32 phyctrl = readl(base + HW_USBPHY_CTRL); 393 - 394 - if (IS_ENABLED(CONFIG_USB_OTG) && 395 - !(phyctrl & BM_USBPHY_CTRL_OTG_ID_VALUE)) 396 - return true; 397 - 398 - return false; 391 + return IS_ENABLED(CONFIG_USB_OTG) && 392 + mxs_phy->phy.last_event == USB_EVENT_ID; 399 393 } 400 394 401 395 static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on) 402 396 { 403 397 bool vbus_is_on = false; 398 + enum usb_phy_events last_event = mxs_phy->phy.last_event; 404 399 405 400 /* If the SoCs don't need to disconnect line without vbus, quit */ 406 401 if (!(mxs_phy->data->flags & MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS)) ··· 407 412 408 413 vbus_is_on = mxs_phy_get_vbus_status(mxs_phy); 409 414 410 - if (on && !vbus_is_on && !mxs_phy_is_otg_host(mxs_phy)) 415 + if (on && ((!vbus_is_on && !mxs_phy_is_otg_host(mxs_phy)) 416 + || (last_event == USB_EVENT_VBUS))) 411 417 __mxs_phy_disconnect_line(mxs_phy, true); 412 418 else 413 419 __mxs_phy_disconnect_line(mxs_phy, false);
+1 -1
drivers/usb/phy/phy-tegra-usb.c
··· 16 16 #include <linux/iopoll.h> 17 17 #include <linux/module.h> 18 18 #include <linux/of.h> 19 - #include <linux/of_device.h> 19 + #include <linux/of_platform.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/resource.h> 22 22 #include <linux/slab.h>
+1 -1
drivers/usb/renesas_usbhs/common.c
··· 11 11 #include <linux/gpio/consumer.h> 12 12 #include <linux/io.h> 13 13 #include <linux/module.h> 14 - #include <linux/of_device.h> 14 + #include <linux/of.h> 15 15 #include <linux/pm_runtime.h> 16 16 #include <linux/reset.h> 17 17 #include <linux/slab.h>
+1 -1
drivers/usb/renesas_usbhs/rza.c
··· 8 8 9 9 #include <linux/delay.h> 10 10 #include <linux/io.h> 11 - #include <linux/of_device.h> 11 + #include <linux/of.h> 12 12 #include "common.h" 13 13 #include "rza.h" 14 14
-1
drivers/usb/renesas_usbhs/rza2.c
··· 8 8 9 9 #include <linux/delay.h> 10 10 #include <linux/io.h> 11 - #include <linux/of_device.h> 12 11 #include <linux/phy/phy.h> 13 12 #include "common.h" 14 13 #include "rza.h"
+7
drivers/usb/serial/option.c
··· 259 259 #define QUECTEL_PRODUCT_EM05G 0x030a 260 260 #define QUECTEL_PRODUCT_EM060K 0x030b 261 261 #define QUECTEL_PRODUCT_EM05G_CS 0x030c 262 + #define QUECTEL_PRODUCT_EM05GV2 0x030e 262 263 #define QUECTEL_PRODUCT_EM05CN_SG 0x0310 263 264 #define QUECTEL_PRODUCT_EM05G_SG 0x0311 264 265 #define QUECTEL_PRODUCT_EM05CN 0x0312 ··· 1189 1188 .driver_info = RSVD(6) | ZLP }, 1190 1189 { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G, 0xff), 1191 1190 .driver_info = RSVD(6) | ZLP }, 1191 + { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05GV2, 0xff), 1192 + .driver_info = RSVD(4) | ZLP }, 1192 1193 { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G_CS, 0xff), 1193 1194 .driver_info = RSVD(6) | ZLP }, 1194 1195 { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G_GR, 0xff), ··· 2234 2231 { USB_DEVICE(0x0489, 0xe0b5), /* Foxconn T77W968 ESIM */ 2235 2232 .driver_info = RSVD(0) | RSVD(1) | RSVD(6) }, 2236 2233 { USB_DEVICE_INTERFACE_CLASS(0x0489, 0xe0db, 0xff), /* Foxconn T99W265 MBIM */ 2234 + .driver_info = RSVD(3) }, 2235 + { USB_DEVICE_INTERFACE_CLASS(0x0489, 0xe0ee, 0xff), /* Foxconn T99W368 MBIM */ 2236 + .driver_info = RSVD(3) }, 2237 + { USB_DEVICE_INTERFACE_CLASS(0x0489, 0xe0f0, 0xff), /* Foxconn T99W373 MBIM */ 2237 2238 .driver_info = RSVD(3) }, 2238 2239 { USB_DEVICE(0x1508, 0x1001), /* Fibocom NL668 (IOT version) */ 2239 2240 .driver_info = RSVD(4) | RSVD(5) | RSVD(6) },
+88 -1
drivers/usb/serial/xr_serial.c
··· 93 93 #define XR_GPIO_MODE_SEL_DTR_DSR 0x2 94 94 #define XR_GPIO_MODE_SEL_RS485 0x3 95 95 #define XR_GPIO_MODE_SEL_RS485_ADDR 0x4 96 + #define XR_GPIO_MODE_RS485_TX_H 0x8 96 97 #define XR_GPIO_MODE_TX_TOGGLE 0x100 97 98 #define XR_GPIO_MODE_RX_TOGGLE 0x200 98 99 ··· 238 237 struct xr_data { 239 238 const struct xr_type *type; 240 239 u8 channel; /* zero-based index or interface number */ 240 + struct serial_rs485 rs485; 241 241 }; 242 242 243 243 static int xr_set_reg(struct usb_serial_port *port, u8 channel, u16 reg, u16 val) ··· 631 629 struct xr_data *data = usb_get_serial_port_data(port); 632 630 const struct xr_type *type = data->type; 633 631 u16 flow, gpio_mode; 632 + bool rs485_enabled; 634 633 int ret; 635 634 636 635 ret = xr_get_reg_uart(port, type->gpio_mode, &gpio_mode); ··· 648 645 /* Set GPIO mode for controlling the pins manually by default. */ 649 646 gpio_mode &= ~XR_GPIO_MODE_SEL_MASK; 650 647 651 - if (C_CRTSCTS(tty) && C_BAUD(tty) != B0) { 648 + rs485_enabled = !!(data->rs485.flags & SER_RS485_ENABLED); 649 + if (rs485_enabled) { 650 + dev_dbg(&port->dev, "Enabling RS-485\n"); 651 + gpio_mode |= XR_GPIO_MODE_SEL_RS485; 652 + if (data->rs485.flags & SER_RS485_RTS_ON_SEND) 653 + gpio_mode &= ~XR_GPIO_MODE_RS485_TX_H; 654 + else 655 + gpio_mode |= XR_GPIO_MODE_RS485_TX_H; 656 + } 657 + 658 + if (C_CRTSCTS(tty) && C_BAUD(tty) != B0 && !rs485_enabled) { 652 659 dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); 653 660 gpio_mode |= XR_GPIO_MODE_SEL_RTS_CTS; 654 661 flow = XR_UART_FLOW_MODE_HW; ··· 820 807 dev_err(&port->dev, "Failed to set line coding: %d\n", ret); 821 808 822 809 kfree(lc); 810 + } 811 + 812 + static void xr_sanitize_serial_rs485(struct serial_rs485 *rs485) 813 + { 814 + if (!(rs485->flags & SER_RS485_ENABLED)) { 815 + memset(rs485, 0, sizeof(*rs485)); 816 + return; 817 + } 818 + 819 + /* RTS always toggles after TX */ 820 + if (rs485->flags & SER_RS485_RTS_ON_SEND) 821 + rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; 822 + else 823 + rs485->flags |= SER_RS485_RTS_AFTER_SEND; 824 + 825 + /* Only the flags are implemented at the moment */ 826 + rs485->flags &= SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | 827 + SER_RS485_RTS_AFTER_SEND; 828 + rs485->delay_rts_before_send = 0; 829 + rs485->delay_rts_after_send = 0; 830 + memset(rs485->padding, 0, sizeof(rs485->padding)); 831 + } 832 + 833 + static int xr_get_rs485_config(struct tty_struct *tty, 834 + struct serial_rs485 __user *argp) 835 + { 836 + struct usb_serial_port *port = tty->driver_data; 837 + struct xr_data *data = usb_get_serial_port_data(port); 838 + 839 + down_read(&tty->termios_rwsem); 840 + if (copy_to_user(argp, &data->rs485, sizeof(data->rs485))) { 841 + up_read(&tty->termios_rwsem); 842 + return -EFAULT; 843 + } 844 + up_read(&tty->termios_rwsem); 845 + 846 + return 0; 847 + } 848 + 849 + static int xr_set_rs485_config(struct tty_struct *tty, 850 + struct serial_rs485 __user *argp) 851 + { 852 + struct usb_serial_port *port = tty->driver_data; 853 + struct xr_data *data = usb_get_serial_port_data(port); 854 + struct serial_rs485 rs485; 855 + 856 + if (copy_from_user(&rs485, argp, sizeof(rs485))) 857 + return -EFAULT; 858 + xr_sanitize_serial_rs485(&rs485); 859 + 860 + down_write(&tty->termios_rwsem); 861 + data->rs485 = rs485; 862 + xr_set_flow_mode(tty, port, NULL); 863 + up_write(&tty->termios_rwsem); 864 + 865 + if (copy_to_user(argp, &rs485, sizeof(rs485))) 866 + return -EFAULT; 867 + 868 + return 0; 869 + } 870 + 871 + static int xr_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) 872 + { 873 + void __user *argp = (void __user *)arg; 874 + 875 + switch (cmd) { 876 + case TIOCGRS485: 877 + return xr_get_rs485_config(tty, argp); 878 + case TIOCSRS485: 879 + return xr_set_rs485_config(tty, argp); 880 + } 881 + 882 + return -ENOIOCTLCMD; 823 883 } 824 884 825 885 static void xr_set_termios(struct tty_struct *tty, ··· 1096 1010 .set_termios = xr_set_termios, 1097 1011 .tiocmget = xr_tiocmget, 1098 1012 .tiocmset = xr_tiocmset, 1013 + .ioctl = xr_ioctl, 1099 1014 .dtr_rts = xr_dtr_rts 1100 1015 }; 1101 1016
+4 -1
drivers/usb/typec/altmodes/displayport.c
··· 594 594 alt->ops = &dp_altmode_ops; 595 595 596 596 fwnode = dev_fwnode(alt->dev.parent->parent); /* typec_port fwnode */ 597 - dp->connector_fwnode = fwnode_find_reference(fwnode, "displayport", 0); 597 + if (fwnode_property_present(fwnode, "displayport")) 598 + dp->connector_fwnode = fwnode_find_reference(fwnode, "displayport", 0); 599 + else 600 + dp->connector_fwnode = fwnode_handle_get(fwnode); /* embedded DP */ 598 601 if (IS_ERR(dp->connector_fwnode)) 599 602 dp->connector_fwnode = NULL; 600 603
+10 -2
drivers/usb/typec/bus.c
··· 183 183 * 184 184 * Notifies the partner of @adev about Attention command. 185 185 */ 186 - void typec_altmode_attention(struct typec_altmode *adev, u32 vdo) 186 + int typec_altmode_attention(struct typec_altmode *adev, u32 vdo) 187 187 { 188 - struct typec_altmode *pdev = &to_altmode(adev)->partner->adev; 188 + struct altmode *partner = to_altmode(adev)->partner; 189 + struct typec_altmode *pdev; 190 + 191 + if (!partner) 192 + return -ENODEV; 193 + 194 + pdev = &partner->adev; 189 195 190 196 if (pdev->ops && pdev->ops->attention) 191 197 pdev->ops->attention(pdev, vdo); 198 + 199 + return 0; 192 200 } 193 201 EXPORT_SYMBOL_GPL(typec_altmode_attention); 194 202
+44 -9
drivers/usb/typec/mux/intel_pmc_mux.c
··· 59 59 }; 60 60 61 61 /* Common Mode Data bits */ 62 - #define PMC_USB_ALTMODE_ACTIVE_CABLE BIT(2) 62 + #define PMC_USB_ALTMODE_RETIMER_CABLE BIT(2) 63 63 64 64 #define PMC_USB_ALTMODE_ORI_SHIFT 1 65 65 #define PMC_USB_ALTMODE_UFP_SHIFT 3 ··· 71 71 #define PMC_USB_ALTMODE_TBT_TYPE BIT(17) 72 72 #define PMC_USB_ALTMODE_CABLE_TYPE BIT(18) 73 73 #define PMC_USB_ALTMODE_ACTIVE_LINK BIT(20) 74 + #define PMC_USB_ALTMODE_ACTIVE_CABLE BIT(22) 74 75 #define PMC_USB_ALTMODE_FORCE_LSR BIT(23) 75 76 #define PMC_USB_ALTMODE_CABLE_SPD(_s_) (((_s_) & GENMASK(2, 0)) << 25) 76 77 #define PMC_USB_ALTMODE_CABLE_USB31 1 ··· 118 117 IOM_PORT_STATUS_DHPD_HPD_STATUS_SHIFT) & \ 119 118 IOM_PORT_STATUS_DHPD_HPD_STATUS_ASSERT) 120 119 120 + /* IOM port status register */ 121 + #define IOM_PORT_STATUS_REGS(_offset_, _size_) ((_offset_) | (_size_)) 122 + #define IOM_PORT_STATUS_REGS_SZ_MASK BIT(0) 123 + #define IOM_PORT_STATUS_REGS_SZ_4 0 124 + #define IOM_PORT_STATUS_REGS_SZ_8 1 125 + #define IOM_PORT_STATUS_REGS_OFFSET(_d_) \ 126 + ((_d_) & ~IOM_PORT_STATUS_REGS_SZ_MASK) 127 + #define IOM_PORT_STATUS_REGS_SIZE(_d_) \ 128 + (4 << ((_d_) & IOM_PORT_STATUS_REGS_SZ_MASK)) 129 + 121 130 struct pmc_usb; 122 131 123 132 struct pmc_usb_port { ··· 156 145 struct acpi_device *iom_adev; 157 146 void __iomem *iom_base; 158 147 u32 iom_port_status_offset; 148 + u8 iom_port_status_size; 159 149 160 150 struct dentry *dentry; 161 151 }; ··· 172 160 173 161 port->iom_status = readl(port->pmc->iom_base + 174 162 port->pmc->iom_port_status_offset + 175 - port_num * sizeof(u32)); 163 + port_num * port->pmc->iom_port_status_size); 176 164 } 177 165 178 166 static int sbu_orientation(struct pmc_usb_port *port) ··· 331 319 if (data->cable_mode & TBT_CABLE_LINK_TRAINING) 332 320 req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK; 333 321 334 - if (data->enter_vdo & TBT_ENTER_MODE_ACTIVE_CABLE) 335 - req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE; 322 + if (acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1072", NULL) || 323 + acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1079", NULL)) { 324 + if ((data->enter_vdo & TBT_ENTER_MODE_ACTIVE_CABLE) || 325 + (data->cable_mode & TBT_CABLE_RETIMER)) 326 + req.mode_data |= PMC_USB_ALTMODE_RETIMER_CABLE; 327 + } else { 328 + if (data->enter_vdo & TBT_ENTER_MODE_ACTIVE_CABLE) 329 + req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE; 330 + 331 + if (data->cable_mode & TBT_CABLE_RETIMER) 332 + req.mode_data |= PMC_USB_ALTMODE_RETIMER_CABLE; 333 + } 336 334 337 335 req.mode_data |= PMC_USB_ALTMODE_CABLE_SPD(cable_speed); 338 336 ··· 381 359 case EUDO_CABLE_TYPE_OPTICAL: 382 360 req.mode_data |= PMC_USB_ALTMODE_CABLE_TYPE; 383 361 fallthrough; 362 + case EUDO_CABLE_TYPE_RE_TIMER: 363 + if (!acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1072", NULL) || 364 + !acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1079", NULL)) 365 + req.mode_data |= PMC_USB_ALTMODE_RETIMER_CABLE; 366 + fallthrough; 384 367 default: 385 - req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE; 368 + if (acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1072", NULL) || 369 + acpi_dev_hid_uid_match(port->pmc->iom_adev, "INTC1079", NULL)) 370 + req.mode_data |= PMC_USB_ALTMODE_RETIMER_CABLE; 371 + else 372 + req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE; 386 373 387 374 /* Configure data rate to rounded in the case of Active TBT3 388 375 * and USB4 cables. ··· 620 589 /* IOM ACPI IDs and IOM_PORT_STATUS_OFFSET */ 621 590 static const struct acpi_device_id iom_acpi_ids[] = { 622 591 /* TigerLake */ 623 - { "INTC1072", 0x560, }, 592 + { "INTC1072", IOM_PORT_STATUS_REGS(0x560, IOM_PORT_STATUS_REGS_SZ_4) }, 624 593 625 594 /* AlderLake */ 626 - { "INTC1079", 0x160, }, 595 + { "INTC1079", IOM_PORT_STATUS_REGS(0x160, IOM_PORT_STATUS_REGS_SZ_4) }, 627 596 628 597 /* Meteor Lake */ 629 - { "INTC107A", 0x160, }, 598 + { "INTC107A", IOM_PORT_STATUS_REGS(0x160, IOM_PORT_STATUS_REGS_SZ_4) }, 599 + 600 + /* Lunar Lake */ 601 + { "INTC10EA", IOM_PORT_STATUS_REGS(0x150, IOM_PORT_STATUS_REGS_SZ_8) }, 630 602 {} 631 603 }; 632 604 ··· 649 615 if (!adev) 650 616 return -ENODEV; 651 617 652 - pmc->iom_port_status_offset = (u32)dev_id->driver_data; 618 + pmc->iom_port_status_offset = IOM_PORT_STATUS_REGS_OFFSET(dev_id->driver_data); 619 + pmc->iom_port_status_size = IOM_PORT_STATUS_REGS_SIZE(dev_id->driver_data); 653 620 654 621 INIT_LIST_HEAD(&resource_list); 655 622 ret = acpi_dev_get_memory_resources(adev, &resource_list);
+1 -1
drivers/usb/typec/mux/nb7vpq904m.c
··· 528 528 .name = "nb7vpq904m", 529 529 .of_match_table = nb7vpq904m_of_table, 530 530 }, 531 - .probe_new = nb7vpq904m_probe, 531 + .probe = nb7vpq904m_probe, 532 532 .remove = nb7vpq904m_remove, 533 533 .id_table = nb7vpq904m_table, 534 534 };
+1
drivers/usb/typec/tcpm/Kconfig
··· 79 79 config TYPEC_QCOM_PMIC 80 80 tristate "Qualcomm PMIC USB Type-C Port Controller Manager driver" 81 81 depends on ARCH_QCOM || COMPILE_TEST 82 + depends on DRM || DRM=n 82 83 help 83 84 A Type-C port and Power Delivery driver which aggregates two 84 85 discrete pieces of silicon in the PM8150b PMIC block: the
+1 -1
drivers/usb/typec/tcpm/fusb302.c
··· 15 15 #include <linux/kernel.h> 16 16 #include <linux/module.h> 17 17 #include <linux/mutex.h> 18 - #include <linux/of_device.h> 18 + #include <linux/of.h> 19 19 #include <linux/pinctrl/consumer.h> 20 20 #include <linux/proc_fs.h> 21 21 #include <linux/regulator/consumer.h>
+38 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
··· 8 8 #include <linux/kernel.h> 9 9 #include <linux/mod_devicetable.h> 10 10 #include <linux/module.h> 11 - #include <linux/of_device.h> 11 + #include <linux/of.h> 12 12 #include <linux/of_graph.h> 13 13 #include <linux/platform_device.h> 14 14 #include <linux/regmap.h> ··· 17 17 #include <linux/usb/role.h> 18 18 #include <linux/usb/tcpm.h> 19 19 #include <linux/usb/typec_mux.h> 20 + 21 + #include <drm/drm_bridge.h> 22 + 20 23 #include "qcom_pmic_typec_pdphy.h" 21 24 #include "qcom_pmic_typec_port.h" 22 25 ··· 36 33 struct pmic_typec_port *pmic_typec_port; 37 34 bool vbus_enabled; 38 35 struct mutex lock; /* VBUS state serialization */ 36 + struct drm_bridge bridge; 39 37 }; 40 38 41 39 #define tcpc_to_tcpm(_tcpc_) container_of(_tcpc_, struct pmic_typec, tcpc) ··· 150 146 return 0; 151 147 } 152 148 149 + #if IS_ENABLED(CONFIG_DRM) 150 + static int qcom_pmic_typec_attach(struct drm_bridge *bridge, 151 + enum drm_bridge_attach_flags flags) 152 + { 153 + return flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ? 0 : -EINVAL; 154 + } 155 + 156 + static const struct drm_bridge_funcs qcom_pmic_typec_bridge_funcs = { 157 + .attach = qcom_pmic_typec_attach, 158 + }; 159 + 160 + static int qcom_pmic_typec_init_drm(struct pmic_typec *tcpm) 161 + { 162 + tcpm->bridge.funcs = &qcom_pmic_typec_bridge_funcs; 163 + #ifdef CONFIG_OF 164 + tcpm->bridge.of_node = of_get_child_by_name(tcpm->dev->of_node, "connector"); 165 + #endif 166 + tcpm->bridge.ops = DRM_BRIDGE_OP_HPD; 167 + tcpm->bridge.type = DRM_MODE_CONNECTOR_DisplayPort; 168 + 169 + return devm_drm_bridge_add(tcpm->dev, &tcpm->bridge); 170 + } 171 + #else 172 + static int qcom_pmic_typec_init_drm(struct pmic_typec *tcpm) 173 + { 174 + return 0; 175 + } 176 + #endif 177 + 153 178 static int qcom_pmic_typec_probe(struct platform_device *pdev) 154 179 { 155 180 struct pmic_typec *tcpm; ··· 240 207 241 208 mutex_init(&tcpm->lock); 242 209 platform_set_drvdata(pdev, tcpm); 210 + 211 + ret = qcom_pmic_typec_init_drm(tcpm); 212 + if (ret) 213 + return ret; 243 214 244 215 tcpm->tcpc.fwnode = device_get_named_child_node(tcpm->dev, "connector"); 245 216 if (!tcpm->tcpc.fwnode)
-2
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
··· 8 8 #include <linux/kernel.h> 9 9 #include <linux/mod_devicetable.h> 10 10 #include <linux/module.h> 11 - #include <linux/of_device.h> 12 - #include <linux/of_irq.h> 13 11 #include <linux/platform_device.h> 14 12 #include <linux/regmap.h> 15 13 #include <linux/regulator/consumer.h>
+5 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
··· 9 9 #include <linux/kernel.h> 10 10 #include <linux/mod_devicetable.h> 11 11 #include <linux/module.h> 12 - #include <linux/of_device.h> 13 12 #include <linux/platform_device.h> 14 13 #include <linux/regmap.h> 15 14 #include <linux/regulator/consumer.h> ··· 213 214 if (ret) 214 215 goto done; 215 216 switch (val & DETECTED_SRC_TYPE_MASK) { 217 + case AUDIO_ACCESS_RA_RA: 218 + val = TYPEC_CC_RA; 219 + *cc1 = TYPEC_CC_RA; 220 + *cc2 = TYPEC_CC_RA; 221 + break; 216 222 case SRC_RD_OPEN: 217 223 val = TYPEC_CC_RD; 218 224 break;
+4
drivers/usb/typec/tcpm/tcpci.c
··· 602 602 if (time_after(jiffies, timeout)) 603 603 return -ETIMEDOUT; 604 604 605 + ret = tcpci_write16(tcpci, TCPC_FAULT_STATUS, TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT); 606 + if (ret < 0) 607 + return ret; 608 + 605 609 /* Handle vendor init */ 606 610 if (tcpci->data->init) { 607 611 ret = tcpci->data->init(tcpci, tcpci->data);
+1 -1
drivers/usb/typec/tcpm/tcpci_mt6370.c
··· 147 147 148 148 irq = platform_get_irq(pdev, 0); 149 149 if (irq < 0) 150 - return dev_err_probe(dev, irq, "Failed to get irq\n"); 150 + return irq; 151 151 152 152 /* Assign TCPCI feature and ops */ 153 153 priv->tcpci_data.auto_discharge_disconnect = 1;
+68 -107
drivers/usb/typec/tcpm/tcpm.c
··· 1877 1877 } 1878 1878 break; 1879 1879 case ADEV_ATTENTION: 1880 - typec_altmode_attention(adev, p[1]); 1880 + if (typec_altmode_attention(adev, p[1])) 1881 + tcpm_log(port, "typec_altmode_attention no port partner altmode"); 1881 1882 break; 1882 1883 } 1883 1884 } ··· 2754 2753 port->sink_cap_done = true; 2755 2754 tcpm_set_state(port, ready_state(port), 0); 2756 2755 break; 2756 + /* 2757 + * Some port partners do not support GET_STATUS, avoid soft reset the link to 2758 + * prevent redundant power re-negotiation 2759 + */ 2760 + case GET_STATUS_SEND: 2761 + tcpm_set_state(port, ready_state(port), 0); 2762 + break; 2757 2763 case SRC_READY: 2758 2764 case SNK_READY: 2759 2765 if (port->vdm_state > VDM_STATE_READY) { ··· 3261 3253 return ret; 3262 3254 } 3263 3255 3264 - #define min_pps_apdo_current(x, y) \ 3265 - min(pdo_pps_apdo_max_current(x), pdo_pps_apdo_max_current(y)) 3266 - 3267 3256 static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port) 3268 3257 { 3269 - unsigned int i, j, max_mw = 0, max_mv = 0; 3270 - unsigned int min_src_mv, max_src_mv, src_ma, src_mw; 3271 - unsigned int min_snk_mv, max_snk_mv; 3272 - unsigned int max_op_mv; 3273 - u32 pdo, src, snk; 3274 - unsigned int src_pdo = 0, snk_pdo = 0; 3258 + unsigned int i, src_ma, max_temp_mw = 0, max_op_ma, op_mw; 3259 + unsigned int src_pdo = 0; 3260 + u32 pdo, src; 3275 3261 3276 - /* 3277 - * Select the source PPS APDO providing the most power while staying 3278 - * within the board's limits. We skip the first PDO as this is always 3279 - * 5V 3A. 3280 - */ 3281 3262 for (i = 1; i < port->nr_source_caps; ++i) { 3282 3263 pdo = port->source_caps[i]; 3283 3264 ··· 3277 3280 continue; 3278 3281 } 3279 3282 3280 - min_src_mv = pdo_pps_apdo_min_voltage(pdo); 3281 - max_src_mv = pdo_pps_apdo_max_voltage(pdo); 3283 + if (port->pps_data.req_out_volt > pdo_pps_apdo_max_voltage(pdo) || 3284 + port->pps_data.req_out_volt < pdo_pps_apdo_min_voltage(pdo)) 3285 + continue; 3286 + 3282 3287 src_ma = pdo_pps_apdo_max_current(pdo); 3283 - src_mw = (src_ma * max_src_mv) / 1000; 3284 - 3285 - /* 3286 - * Now search through the sink PDOs to find a matching 3287 - * PPS APDO. Again skip the first sink PDO as this will 3288 - * always be 5V 3A. 3289 - */ 3290 - for (j = 1; j < port->nr_snk_pdo; j++) { 3291 - pdo = port->snk_pdo[j]; 3292 - 3293 - switch (pdo_type(pdo)) { 3294 - case PDO_TYPE_APDO: 3295 - if (pdo_apdo_type(pdo) != APDO_TYPE_PPS) { 3296 - tcpm_log(port, 3297 - "Not PPS APDO (sink), ignoring"); 3298 - continue; 3299 - } 3300 - 3301 - min_snk_mv = 3302 - pdo_pps_apdo_min_voltage(pdo); 3303 - max_snk_mv = 3304 - pdo_pps_apdo_max_voltage(pdo); 3305 - break; 3306 - default: 3307 - tcpm_log(port, 3308 - "Not APDO type (sink), ignoring"); 3309 - continue; 3310 - } 3311 - 3312 - if (min_src_mv <= max_snk_mv && 3313 - max_src_mv >= min_snk_mv) { 3314 - max_op_mv = min(max_src_mv, max_snk_mv); 3315 - src_mw = (max_op_mv * src_ma) / 1000; 3316 - /* Prefer higher voltages if available */ 3317 - if ((src_mw == max_mw && 3318 - max_op_mv > max_mv) || 3319 - src_mw > max_mw) { 3320 - src_pdo = i; 3321 - snk_pdo = j; 3322 - max_mw = src_mw; 3323 - max_mv = max_op_mv; 3324 - } 3325 - } 3288 + max_op_ma = min(src_ma, port->pps_data.req_op_curr); 3289 + op_mw = max_op_ma * port->pps_data.req_out_volt / 1000; 3290 + if (op_mw > max_temp_mw) { 3291 + src_pdo = i; 3292 + max_temp_mw = op_mw; 3326 3293 } 3327 - 3328 3294 break; 3329 3295 default: 3330 3296 tcpm_log(port, "Not APDO type (source), ignoring"); ··· 3297 3337 3298 3338 if (src_pdo) { 3299 3339 src = port->source_caps[src_pdo]; 3300 - snk = port->snk_pdo[snk_pdo]; 3301 3340 3302 - port->pps_data.req_min_volt = max(pdo_pps_apdo_min_voltage(src), 3303 - pdo_pps_apdo_min_voltage(snk)); 3304 - port->pps_data.req_max_volt = min(pdo_pps_apdo_max_voltage(src), 3305 - pdo_pps_apdo_max_voltage(snk)); 3306 - port->pps_data.req_max_curr = min_pps_apdo_current(src, snk); 3307 - port->pps_data.req_out_volt = min(port->pps_data.req_max_volt, 3308 - max(port->pps_data.req_min_volt, 3309 - port->pps_data.req_out_volt)); 3341 + port->pps_data.req_min_volt = pdo_pps_apdo_min_voltage(src); 3342 + port->pps_data.req_max_volt = pdo_pps_apdo_max_voltage(src); 3343 + port->pps_data.req_max_curr = pdo_pps_apdo_max_current(src); 3310 3344 port->pps_data.req_op_curr = min(port->pps_data.req_max_curr, 3311 3345 port->pps_data.req_op_curr); 3312 3346 } ··· 3418 3464 static int tcpm_pd_build_pps_request(struct tcpm_port *port, u32 *rdo) 3419 3465 { 3420 3466 unsigned int out_mv, op_ma, op_mw, max_mv, max_ma, flags; 3421 - enum pd_pdo_type type; 3422 3467 unsigned int src_pdo_index; 3423 - u32 pdo; 3424 3468 3425 3469 src_pdo_index = tcpm_pd_select_pps_apdo(port); 3426 3470 if (!src_pdo_index) 3427 3471 return -EOPNOTSUPP; 3428 3472 3429 - pdo = port->source_caps[src_pdo_index]; 3430 - type = pdo_type(pdo); 3431 - 3432 - switch (type) { 3433 - case PDO_TYPE_APDO: 3434 - if (pdo_apdo_type(pdo) != APDO_TYPE_PPS) { 3435 - tcpm_log(port, "Invalid APDO selected!"); 3436 - return -EINVAL; 3437 - } 3438 - max_mv = port->pps_data.req_max_volt; 3439 - max_ma = port->pps_data.req_max_curr; 3440 - out_mv = port->pps_data.req_out_volt; 3441 - op_ma = port->pps_data.req_op_curr; 3442 - break; 3443 - default: 3444 - tcpm_log(port, "Invalid PDO selected!"); 3445 - return -EINVAL; 3446 - } 3473 + max_mv = port->pps_data.req_max_volt; 3474 + max_ma = port->pps_data.req_max_curr; 3475 + out_mv = port->pps_data.req_out_volt; 3476 + op_ma = port->pps_data.req_op_curr; 3447 3477 3448 3478 flags = RDO_USB_COMM | RDO_NO_SUSPEND; 3449 3479 ··· 3727 3789 if (tcpm_port_is_disconnected(port)) 3728 3790 port->hard_reset_count = 0; 3729 3791 3792 + port->try_src_count = 0; 3793 + port->try_snk_count = 0; 3794 + 3730 3795 if (!port->attached) 3731 3796 return; 3732 3797 ··· 3866 3925 case TYPEC_PWR_MODE_PD: 3867 3926 default: 3868 3927 return TYPEC_CC_RP_3_0; 3928 + } 3929 + } 3930 + 3931 + static void tcpm_set_initial_svdm_version(struct tcpm_port *port) 3932 + { 3933 + switch (port->negotiated_rev) { 3934 + case PD_REV30: 3935 + break; 3936 + /* 3937 + * 6.4.4.2.3 Structured VDM Version 3938 + * 2.0 states "At this time, there is only one version (1.0) defined. 3939 + * This field Shall be set to zero to indicate Version 1.0." 3940 + * 3.0 states "This field Shall be set to 01b to indicate Version 2.0." 3941 + * To ensure that we follow the Power Delivery revision we are currently 3942 + * operating on, downgrade the SVDM version to the highest one supported 3943 + * by the Power Delivery revision. 3944 + */ 3945 + case PD_REV20: 3946 + typec_partner_set_svdm_version(port->partner, SVDM_VER_1_0); 3947 + break; 3948 + default: 3949 + typec_partner_set_svdm_version(port->partner, SVDM_VER_1_0); 3950 + break; 3869 3951 } 3870 3952 } 3871 3953 ··· 4129 4165 * For now, this driver only supports SOP for DISCOVER_IDENTITY, thus using 4130 4166 * port->explicit_contract to decide whether to send the command. 4131 4167 */ 4132 - if (port->explicit_contract) 4168 + if (port->explicit_contract) { 4169 + tcpm_set_initial_svdm_version(port); 4133 4170 mod_send_discover_delayed_work(port, 0); 4134 - else 4171 + } else { 4135 4172 port->send_discover = false; 4173 + } 4136 4174 4137 4175 /* 4138 4176 * 6.3.5 ··· 4267 4301 if (port->slow_charger_loop && (current_lim > PD_P_SNK_STDBY_MW / 5)) 4268 4302 current_lim = PD_P_SNK_STDBY_MW / 5; 4269 4303 tcpm_set_current_limit(port, current_lim, 5000); 4270 - tcpm_set_charge(port, true); 4304 + /* Not sink vbus if operational current is 0mA */ 4305 + tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0])); 4306 + 4271 4307 if (!port->pd_supported) 4272 4308 tcpm_set_state(port, SNK_READY, 0); 4273 4309 else ··· 4423 4455 * For now, this driver only supports SOP for DISCOVER_IDENTITY, thus using 4424 4456 * port->explicit_contract. 4425 4457 */ 4426 - if (port->explicit_contract) 4458 + if (port->explicit_contract) { 4459 + tcpm_set_initial_svdm_version(port); 4427 4460 mod_send_discover_delayed_work(port, 0); 4428 - else 4461 + } else { 4429 4462 port->send_discover = false; 4463 + } 4430 4464 4431 4465 power_supply_changed(port->psy); 4432 4466 break; ··· 4552 4582 tcpm_set_current_limit(port, 4553 4583 tcpm_get_current_limit(port), 4554 4584 5000); 4555 - tcpm_set_charge(port, true); 4585 + /* Not sink vbus if operational current is 0mA */ 4586 + tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0])); 4556 4587 } 4557 4588 if (port->ams == HARD_RESET) 4558 4589 tcpm_ams_finish(port); ··· 5860 5889 goto port_unlock; 5861 5890 } 5862 5891 5863 - if (req_out_volt < port->pps_data.min_volt || 5864 - req_out_volt > port->pps_data.max_volt) { 5865 - ret = -EINVAL; 5866 - goto port_unlock; 5867 - } 5868 - 5869 5892 target_mw = (port->current_limit * req_out_volt) / 1000; 5870 5893 if (target_mw < port->operating_snk_mw) { 5871 5894 ret = -EINVAL; ··· 6412 6447 ret = tcpm_psy_set_online(port, val); 6413 6448 break; 6414 6449 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 6415 - if (val->intval < port->pps_data.min_volt * 1000 || 6416 - val->intval > port->pps_data.max_volt * 1000) 6417 - ret = -EINVAL; 6418 - else 6419 - ret = tcpm_pps_set_out_volt(port, val->intval / 1000); 6450 + ret = tcpm_pps_set_out_volt(port, val->intval / 1000); 6420 6451 break; 6421 6452 case POWER_SUPPLY_PROP_CURRENT_NOW: 6422 6453 if (val->intval > port->pps_data.max_curr * 1000)
+1
drivers/usb/typec/ucsi/Kconfig
··· 4 4 tristate "USB Type-C Connector System Software Interface driver" 5 5 depends on !CPU_BIG_ENDIAN 6 6 depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH 7 + select USB_COMMON if DEBUG_FS 7 8 help 8 9 USB Type-C Connector System Software Interface (UCSI) is a 9 10 specification for an interface that allows the operating system to
+2
drivers/usb/typec/ucsi/Makefile
··· 5 5 6 6 typec_ucsi-y := ucsi.o 7 7 8 + typec_ucsi-$(CONFIG_DEBUG_FS) += debugfs.o 9 + 8 10 typec_ucsi-$(CONFIG_TRACING) += trace.o 9 11 10 12 ifneq ($(CONFIG_POWER_SUPPLY),)
+99
drivers/usb/typec/ucsi/debugfs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * UCSI debugfs interface 4 + * 5 + * Copyright (C) 2023 Intel Corporation 6 + * 7 + * Authors: Rajaram Regupathy <rajaram.regupathy@intel.com> 8 + * Gopal Saranya <saranya.gopal@intel.com> 9 + */ 10 + #include <linux/debugfs.h> 11 + #include <linux/slab.h> 12 + #include <linux/string.h> 13 + #include <linux/types.h> 14 + #include <linux/usb.h> 15 + 16 + #include <asm/errno.h> 17 + 18 + #include "ucsi.h" 19 + 20 + static struct dentry *ucsi_debugfs_root; 21 + 22 + static int ucsi_cmd(void *data, u64 val) 23 + { 24 + struct ucsi *ucsi = data; 25 + int ret; 26 + 27 + memset(&ucsi->debugfs->response, 0, sizeof(ucsi->debugfs->response)); 28 + ucsi->debugfs->status = 0; 29 + 30 + switch (UCSI_COMMAND(val)) { 31 + case UCSI_SET_UOM: 32 + case UCSI_SET_UOR: 33 + case UCSI_SET_PDR: 34 + case UCSI_CONNECTOR_RESET: 35 + ret = ucsi_send_command(ucsi, val, NULL, 0); 36 + break; 37 + case UCSI_GET_CAPABILITY: 38 + case UCSI_GET_CONNECTOR_CAPABILITY: 39 + case UCSI_GET_ALTERNATE_MODES: 40 + case UCSI_GET_CURRENT_CAM: 41 + case UCSI_GET_PDOS: 42 + case UCSI_GET_CABLE_PROPERTY: 43 + case UCSI_GET_CONNECTOR_STATUS: 44 + ret = ucsi_send_command(ucsi, val, 45 + &ucsi->debugfs->response, 46 + sizeof(ucsi->debugfs->response)); 47 + break; 48 + default: 49 + ret = -EOPNOTSUPP; 50 + } 51 + 52 + if (ret < 0) { 53 + ucsi->debugfs->status = ret; 54 + return ret; 55 + } 56 + 57 + return 0; 58 + } 59 + DEFINE_DEBUGFS_ATTRIBUTE(ucsi_cmd_fops, NULL, ucsi_cmd, "0x%llx\n"); 60 + 61 + static int ucsi_resp_show(struct seq_file *s, void *not_used) 62 + { 63 + struct ucsi *ucsi = s->private; 64 + 65 + if (ucsi->debugfs->status) 66 + return ucsi->debugfs->status; 67 + 68 + seq_printf(s, "0x%016llx%016llx\n", ucsi->debugfs->response.high, 69 + ucsi->debugfs->response.low); 70 + return 0; 71 + } 72 + DEFINE_SHOW_ATTRIBUTE(ucsi_resp); 73 + 74 + void ucsi_debugfs_register(struct ucsi *ucsi) 75 + { 76 + ucsi->debugfs = kzalloc(sizeof(*ucsi->debugfs), GFP_KERNEL); 77 + if (!ucsi->debugfs) 78 + return; 79 + 80 + ucsi->debugfs->dentry = debugfs_create_dir(dev_name(ucsi->dev), ucsi_debugfs_root); 81 + debugfs_create_file("command", 0200, ucsi->debugfs->dentry, ucsi, &ucsi_cmd_fops); 82 + debugfs_create_file("response", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_resp_fops); 83 + } 84 + 85 + void ucsi_debugfs_unregister(struct ucsi *ucsi) 86 + { 87 + debugfs_remove_recursive(ucsi->debugfs->dentry); 88 + kfree(ucsi->debugfs); 89 + } 90 + 91 + void ucsi_debugfs_init(void) 92 + { 93 + ucsi_debugfs_root = debugfs_create_dir("ucsi", usb_debug_root); 94 + } 95 + 96 + void ucsi_debugfs_exit(void) 97 + { 98 + debugfs_remove(ucsi_debugfs_root); 99 + }
+15
drivers/usb/typec/ucsi/ucsi.c
··· 1530 1530 */ 1531 1531 void ucsi_destroy(struct ucsi *ucsi) 1532 1532 { 1533 + ucsi_debugfs_unregister(ucsi); 1533 1534 kfree(ucsi); 1534 1535 } 1535 1536 EXPORT_SYMBOL_GPL(ucsi_destroy); ··· 1553 1552 1554 1553 queue_delayed_work(system_long_wq, &ucsi->work, 0); 1555 1554 1555 + ucsi_debugfs_register(ucsi); 1556 1556 return 0; 1557 1557 } 1558 1558 EXPORT_SYMBOL_GPL(ucsi_register); ··· 1612 1610 kfree(ucsi->connector); 1613 1611 } 1614 1612 EXPORT_SYMBOL_GPL(ucsi_unregister); 1613 + 1614 + static int __init ucsi_module_init(void) 1615 + { 1616 + ucsi_debugfs_init(); 1617 + return 0; 1618 + } 1619 + module_init(ucsi_module_init); 1620 + 1621 + static void __exit ucsi_module_exit(void) 1622 + { 1623 + ucsi_debugfs_exit(); 1624 + } 1625 + module_exit(ucsi_module_exit); 1615 1626 1616 1627 MODULE_AUTHOR("Heikki Krogerus <heikki.krogerus@linux.intel.com>"); 1617 1628 MODULE_LICENSE("GPL v2");
+24
drivers/usb/typec/ucsi/ucsi.h
··· 15 15 16 16 struct ucsi; 17 17 struct ucsi_altmode; 18 + struct dentry; 18 19 19 20 /* UCSI offsets (Bytes) */ 20 21 #define UCSI_VERSION 0 ··· 278 277 279 278 /* -------------------------------------------------------------------------- */ 280 279 280 + struct ucsi_debugfs_entry { 281 + u64 command; 282 + struct ucsi_data { 283 + u64 low; 284 + u64 high; 285 + } response; 286 + u32 status; 287 + struct dentry *dentry; 288 + }; 289 + 281 290 struct ucsi { 282 291 u16 version; 283 292 struct device *dev; ··· 297 286 298 287 struct ucsi_capability cap; 299 288 struct ucsi_connector *connector; 289 + struct ucsi_debugfs_entry *debugfs; 300 290 301 291 struct work_struct resume_work; 302 292 struct delayed_work work; ··· 399 387 static inline void 400 388 ucsi_displayport_remove_partner(struct typec_altmode *adev) { } 401 389 #endif /* CONFIG_TYPEC_DP_ALTMODE */ 390 + 391 + #ifdef CONFIG_DEBUG_FS 392 + void ucsi_debugfs_init(void); 393 + void ucsi_debugfs_exit(void); 394 + void ucsi_debugfs_register(struct ucsi *ucsi); 395 + void ucsi_debugfs_unregister(struct ucsi *ucsi); 396 + #else 397 + static inline void ucsi_debugfs_init(void) { } 398 + static inline void ucsi_debugfs_exit(void) { } 399 + static inline void ucsi_debugfs_register(struct ucsi *ucsi) { } 400 + static inline void ucsi_debugfs_unregister(struct ucsi *ucsi) { } 401 + #endif /* CONFIG_DEBUG_FS */ 402 402 403 403 /* 404 404 * NVIDIA VirtualLink (svid 0x955) has two altmode. VirtualLink
-1
drivers/usb/typec/ucsi/ucsi_glink.c
··· 5 5 */ 6 6 #include <linux/auxiliary_bus.h> 7 7 #include <linux/module.h> 8 - #include <linux/of_device.h> 9 8 #include <linux/mutex.h> 10 9 #include <linux/property.h> 11 10 #include <linux/soc/qcom/pdr.h>
+2 -3
drivers/usb/usbip/vudc_dev.c
··· 489 489 490 490 struct vudc_device *alloc_vudc_device(int devid) 491 491 { 492 - struct vudc_device *udc_dev = NULL; 492 + struct vudc_device *udc_dev; 493 493 494 494 udc_dev = kzalloc(sizeof(*udc_dev), GFP_KERNEL); 495 495 if (!udc_dev) 496 - goto out; 496 + return NULL; 497 497 498 498 INIT_LIST_HEAD(&udc_dev->dev_entry); 499 499 ··· 503 503 udc_dev = NULL; 504 504 } 505 505 506 - out: 507 506 return udc_dev; 508 507 } 509 508
-12
include/linux/usb.h
··· 25 25 26 26 struct usb_device; 27 27 struct usb_driver; 28 - struct wusb_dev; 29 28 30 29 /*-------------------------------------------------------------------------*/ 31 30 ··· 424 425 struct usb_host_bos { 425 426 struct usb_bos_descriptor *desc; 426 427 427 - /* wireless cap descriptor is handled by wusb */ 428 428 struct usb_ext_cap_descriptor *ext_cap; 429 429 struct usb_ss_cap_descriptor *ss_cap; 430 430 struct usb_ssp_cap_descriptor *ssp_cap; ··· 610 612 * WUSB devices are not, until we authorize them from user space. 611 613 * FIXME -- complete doc 612 614 * @authenticated: Crypto authentication passed 613 - * @wusb: device is Wireless USB 614 615 * @lpm_capable: device supports LPM 615 616 * @lpm_devinit_allow: Allow USB3 device initiated LPM, exit latency is in range 616 617 * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM ··· 631 634 * @do_remote_wakeup: remote wakeup should be enabled 632 635 * @reset_resume: needs reset instead of resume 633 636 * @port_is_suspended: the upstream port is suspended (L2 or U3) 634 - * @wusb_dev: if this is a Wireless USB device, link to the WUSB 635 - * specific data for the device. 636 637 * @slot_id: Slot ID assigned by xHCI 637 638 * @removable: Device can be physically removed from this port 638 639 * @l1_params: best effor service latency for USB2 L1 LPM state, and L1 timeout. ··· 691 696 unsigned have_langid:1; 692 697 unsigned authorized:1; 693 698 unsigned authenticated:1; 694 - unsigned wusb:1; 695 699 unsigned lpm_capable:1; 696 700 unsigned lpm_devinit_allow:1; 697 701 unsigned usb2_hw_lpm_capable:1; ··· 721 727 unsigned reset_resume:1; 722 728 unsigned port_is_suspended:1; 723 729 724 - struct wusb_dev *wusb_dev; 725 730 int slot_id; 726 731 struct usb2_lpm_parameters l1_params; 727 732 struct usb3_lpm_parameters u1_params; ··· 1735 1742 * encoding of the endpoint interval, and express polling intervals in 1736 1743 * microframes (eight per millisecond) rather than in frames (one per 1737 1744 * millisecond). 1738 - * 1739 - * Wireless USB also uses the logarithmic encoding, but specifies it in units of 1740 - * 128us instead of 125us. For Wireless USB devices, the interval is passed 1741 - * through to the host controller, rather than being translated into microframe 1742 - * units. 1743 1745 */ 1744 1746 static inline void usb_fill_int_urb(struct urb *urb, 1745 1747 struct usb_device *dev,
+1 -4
include/linux/usb/ch9.h
··· 3 3 * This file holds USB constants and structures that are needed for 4 4 * USB device APIs. These are used by the USB device model, which is 5 5 * defined in chapter 9 of the USB 2.0 specification and in the 6 - * Wireless USB 1.0 (spread around). Linux has several APIs in C that 6 + * Wireless USB 1.0 spec (now defunct). Linux has several APIs in C that 7 7 * need these: 8 8 * 9 9 * - the host side Linux-USB kernel driver API; ··· 13 13 * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems 14 14 * act either as a USB host or as a USB device. That means the host and 15 15 * device side APIs benefit from working well together. 16 - * 17 - * There's also "Wireless USB", using low power short range radios for 18 - * peripheral interconnection but otherwise building on the USB framework. 19 16 * 20 17 * Note all descriptors are declared '__attribute__((packed))' so that: 21 18 *
+1
include/linux/usb/chipidea.h
··· 63 63 #define CI_HDRC_IMX_IS_HSIC BIT(14) 64 64 #define CI_HDRC_PMQOS BIT(15) 65 65 #define CI_HDRC_PHY_VBUS_CONTROL BIT(16) 66 + #define CI_HDRC_HAS_PORTSC_PEC_MISSED BIT(17) 66 67 enum usb_dr_mode dr_mode; 67 68 #define CI_HDRC_CONTROLLER_RESET_EVENT 0 68 69 #define CI_HDRC_CONTROLLER_STOPPED_EVENT 1
-23
include/linux/usb/composite.h
··· 450 450 * 451 451 * One of these devices is allocated and initialized before the 452 452 * associated device driver's bind() is called. 453 - * 454 - * OPEN ISSUE: it appears that some WUSB devices will need to be 455 - * built by combining a normal (wired) gadget with a wireless one. 456 - * This revision of the gadget framework should probably try to make 457 - * sure doing that won't hurt too much. 458 - * 459 - * One notion for how to handle Wireless USB devices involves: 460 - * 461 - * (a) a second gadget here, discovery mechanism TBD, but likely 462 - * needing separate "register/unregister WUSB gadget" calls; 463 - * (b) updates to usb_gadget to include flags "is it wireless", 464 - * "is it wired", plus (presumably in a wrapper structure) 465 - * bandgroup and PHY info; 466 - * (c) presumably a wireless_ep wrapping a usb_ep, and reporting 467 - * wireless-specific parameters like maxburst and maxsequence; 468 - * (d) configurations that are specific to wireless links; 469 - * (e) function drivers that understand wireless configs and will 470 - * support wireless for (additional) function instances; 471 - * (f) a function to support association setup (like CBAF), not 472 - * necessarily requiring a wireless adapter; 473 - * (g) composite device setup that can create one or more wireless 474 - * configs, including appropriate association setup support; 475 - * (h) more, TBD. 476 453 */ 477 454 struct usb_composite_dev { 478 455 struct usb_gadget *gadget;
-2
include/linux/usb/hcd.h
··· 154 154 /* The next flag is a stopgap, to be removed when all the HCDs 155 155 * support the new root-hub polling mechanism. */ 156 156 unsigned uses_new_polling:1; 157 - unsigned wireless:1; /* Wireless USB HCD */ 158 157 unsigned has_tt:1; /* Integrated TT in root hub */ 159 158 unsigned amd_resume_bug:1; /* AMD remote wakeup quirk */ 160 159 unsigned can_do_streams:1; /* HC supports streams */ ··· 248 249 #define HCD_SHARED 0x0004 /* Two (or more) usb_hcds share HW */ 249 250 #define HCD_USB11 0x0010 /* USB 1.1 */ 250 251 #define HCD_USB2 0x0020 /* USB 2.0 */ 251 - #define HCD_USB25 0x0030 /* Wireless USB 1.0 (USB 2.5)*/ 252 252 #define HCD_USB3 0x0040 /* USB 3.0 */ 253 253 #define HCD_USB31 0x0050 /* USB 3.1 */ 254 254 #define HCD_USB32 0x0060 /* USB 3.2 */
+13
include/linux/usb/phy.h
··· 144 144 */ 145 145 int (*set_wakeup)(struct usb_phy *x, bool enabled); 146 146 147 + /* notify phy port status change */ 148 + int (*notify_port_status)(struct usb_phy *x, int port, 149 + u16 portstatus, u16 portchange); 150 + 147 151 /* notify phy connect status change */ 148 152 int (*notify_connect)(struct usb_phy *x, 149 153 enum usb_device_speed speed); ··· 316 312 { 317 313 if (x && x->set_wakeup) 318 314 return x->set_wakeup(x, enabled); 315 + else 316 + return 0; 317 + } 318 + 319 + static inline int 320 + usb_phy_notify_port_status(struct usb_phy *x, int port, u16 portstatus, u16 portchange) 321 + { 322 + if (x && x->notify_port_status) 323 + return x->notify_port_status(x, port, portstatus, portchange); 319 324 else 320 325 return 0; 321 326 }
+1
include/linux/usb/tcpci.h
··· 103 103 #define TCPC_POWER_STATUS_SINKING_VBUS BIT(0) 104 104 105 105 #define TCPC_FAULT_STATUS 0x1f 106 + #define TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT BIT(7) 106 107 107 108 #define TCPC_ALERT_EXTENDED 0x21 108 109
+1 -1
include/linux/usb/typec_altmode.h
··· 67 67 68 68 int typec_altmode_enter(struct typec_altmode *altmode, u32 *vdo); 69 69 int typec_altmode_exit(struct typec_altmode *altmode); 70 - void typec_altmode_attention(struct typec_altmode *altmode, u32 vdo); 70 + int typec_altmode_attention(struct typec_altmode *altmode, u32 vdo); 71 71 int typec_altmode_vdm(struct typec_altmode *altmode, 72 72 const u32 header, const u32 *vdo, int count); 73 73 int typec_altmode_notify(struct typec_altmode *altmode, unsigned long conf,
+2 -4
include/uapi/linux/usb/ch11.h
··· 15 15 /* This is arbitrary. 16 16 * From USB 2.0 spec Table 11-13, offset 7, a hub can 17 17 * have up to 255 ports. The most yet reported is 10. 18 - * 19 - * Current Wireless USB host hardware (Intel i1480 for example) allows 20 - * up to 22 devices to connect. Upcoming hardware might raise that 21 - * limit. Because the arrays need to add a bit for hub status data, we 18 + * Upcoming hardware might raise that limit. 19 + * Because the arrays need to add a bit for hub status data, we 22 20 * use 31, so plus one evens out to four bytes. 23 21 */ 24 22 #define USB_MAXCHILDREN 31
+1 -4
include/uapi/linux/usb/ch9.h
··· 3 3 * This file holds USB constants and structures that are needed for 4 4 * USB device APIs. These are used by the USB device model, which is 5 5 * defined in chapter 9 of the USB 2.0 specification and in the 6 - * Wireless USB 1.0 (spread around). Linux has several APIs in C that 6 + * Wireless USB 1.0 spec (now defunct). Linux has several APIs in C that 7 7 * need these: 8 8 * 9 9 * - the master/host side Linux-USB kernel driver API; ··· 13 13 * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems 14 14 * act either as a USB master/host or as a USB slave/device. That means 15 15 * the master and slave side APIs benefit from working well together. 16 - * 17 - * There's also "Wireless USB", using low power short range radios for 18 - * peripheral interconnection but otherwise building on the USB framework. 19 16 * 20 17 * Note all descriptors are declared '__attribute__((packed))' so that: 21 18 *