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

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

Pull USB and Thunderbolt driver updates from Greg KH:
"Here is the large set of USB and Thunderbolt driver changes for
6.2-rc1. Overall, thanks to the removal of a driver, more lines were
removed than added, a nice change. Highlights include:

- removal of the sisusbvga driver that was not used by anyone anymore

- minor thunderbolt driver changes and tweaks

- chipidea driver updates

- usual set of typec driver features and hardware support added

- musb minor driver fixes

- fotg210 driver fixes, bringing that hardware back from the "dead"

- minor dwc3 driver updates

- addition, and then removal, of a list.h helper function for many
USB and other subsystem drivers, that ended up breaking the build.
That will come back for 6.3-rc1, it missed this merge window.

- usual xhci updates and enhancements

- usb-serial driver updates and support for new devices

- other minor USB driver updates

All of these have been in linux-next for a while with no reported
problems"

* tag 'usb-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (153 commits)
usb: gadget: uvc: Rename bmInterfaceFlags -> bmInterlaceFlags
usb: dwc2: power on/off phy for peripheral mode in dual-role mode
usb: dwc2: disable lpm feature on Rockchip SoCs
dt-bindings: usb: mtk-xhci: add support for mt7986
usb: dwc3: core: defer probe on ulpi_read_id timeout
usb: ulpi: defer ulpi_register on ulpi_read_id timeout
usb: misc: onboard_usb_hub: add Genesys Logic GL850G hub support
dt-bindings: usb: Add binding for Genesys Logic GL850G hub controller
dt-bindings: vendor-prefixes: add Genesys Logic
usb: fotg210-udc: fix potential memory leak in fotg210_udc_probe()
usb: typec: tipd: Set mode of operation for USB Type-C connector
usb: gadget: udc: drop obsolete dependencies on COMPILE_TEST
usb: musb: remove extra check in musb_gadget_vbus_draw
usb: gadget: uvc: Prevent buffer overflow in setup handler
usb: dwc3: qcom: Fix memory leak in dwc3_qcom_interconnect_init
usb: typec: wusb3801: fix fwnode refcount leak in wusb3801_probe()
usb: storage: Add check for kcalloc
USB: sisusbvga: use module_usb_driver()
USB: sisusbvga: rename sisusb.c to sisusbvga.c
USB: sisusbvga: remove console support
...

+2084 -7054
+2 -2
Documentation/ABI/testing/configfs-usb-gadget-uvc
··· 197 197 read-only 198 198 bmaControls this format's data for bmaControls in 199 199 the streaming header 200 - bmInterfaceFlags specifies interlace information, 200 + bmInterlaceFlags specifies interlace information, 201 201 read-only 202 202 bAspectRatioY the X dimension of the picture aspect 203 203 ratio, read-only ··· 253 253 read-only 254 254 bmaControls this format's data for bmaControls in 255 255 the streaming header 256 - bmInterfaceFlags specifies interlace information, 256 + bmInterlaceFlags specifies interlace information, 257 257 read-only 258 258 bAspectRatioY the X dimension of the picture aspect 259 259 ratio, read-only
+11
Documentation/ABI/testing/sysfs-bus-usb
··· 264 264 attached to the port will not be detected, initialized, 265 265 or enumerated. 266 266 267 + What: /sys/bus/usb/devices/.../<hub_interface>/port<X>/early_stop 268 + Date: Sep 2022 269 + Contact: Ray Chi <raychi@google.com> 270 + Description: 271 + Some USB hosts have some watchdog mechanisms so that the device 272 + may enter ramdump if it takes a long time during port initialization. 273 + This attribute allows each port just has two attempts so that the 274 + port initialization will be failed quickly. In addition, if a port 275 + which is marked with early_stop has failed to initialize, it will ignore 276 + all future connections until this attribute is clear. 277 + 267 278 What: /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout 268 279 Date: May 2013 269 280 Contact: Mathias Nyman <mathias.nyman@linux.intel.com>
+3
Documentation/devicetree/bindings/phy/fsl,imx8mq-usb-phy.yaml
··· 28 28 items: 29 29 - const: phy 30 30 31 + power-domains: 32 + maxItems: 1 33 + 31 34 vbus-supply: 32 35 description: 33 36 A phandle to the regulator for USB VBUS.
+3
Documentation/devicetree/bindings/usb/dwc2.yaml
··· 43 43 - const: rockchip,rk3066-usb 44 44 - const: snps,dwc2 45 45 - const: lantiq,arx100-usb 46 + - const: lantiq,ase-usb 47 + - const: lantiq,danube-usb 46 48 - const: lantiq,xrx200-usb 49 + - const: lantiq,xrx300-usb 47 50 - items: 48 51 - enum: 49 52 - amlogic,meson8-usb
+48
Documentation/devicetree/bindings/usb/genesys,gl850g.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/genesys,gl850g.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Genesys Logic GL850G USB 2.0 hub controller 8 + 9 + maintainers: 10 + - Icenowy Zheng <uwu@icenowy.me> 11 + 12 + allOf: 13 + - $ref: usb-device.yaml# 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - usb5e3,608 19 + 20 + reg: true 21 + 22 + reset-gpios: 23 + description: GPIO controlling the RESET# pin. 24 + 25 + vdd-supply: 26 + description: 27 + the regulator that provides 3.3V core power to the hub. 28 + 29 + required: 30 + - compatible 31 + - reg 32 + 33 + additionalProperties: false 34 + 35 + examples: 36 + - | 37 + #include <dt-bindings/gpio/gpio.h> 38 + usb { 39 + dr_mode = "host"; 40 + #address-cells = <1>; 41 + #size-cells = <0>; 42 + 43 + hub: hub@1 { 44 + compatible = "usb5e3,608"; 45 + reg = <1>; 46 + reset-gpios = <&pio 7 2 GPIO_ACTIVE_LOW>; 47 + }; 48 + };
+1
Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
··· 28 28 - mediatek,mt7622-xhci 29 29 - mediatek,mt7623-xhci 30 30 - mediatek,mt7629-xhci 31 + - mediatek,mt7986-xhci 31 32 - mediatek,mt8173-xhci 32 33 - mediatek,mt8183-xhci 33 34 - mediatek,mt8186-xhci
+1
Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml
··· 24 24 - mediatek,mt2712-mtu3 25 25 - mediatek,mt8173-mtu3 26 26 - mediatek,mt8183-mtu3 27 + - mediatek,mt8186-mtu3 27 28 - mediatek,mt8188-mtu3 28 29 - mediatek,mt8192-mtu3 29 30 - mediatek,mt8195-mtu3
+3
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml
··· 39 39 - qcom,sm8250-dwc3 40 40 - qcom,sm8350-dwc3 41 41 - qcom,sm8450-dwc3 42 + - qcom,sm8550-dwc3 42 43 - const: qcom,dwc3 43 44 44 45 reg: ··· 302 301 - qcom,sm8150-dwc3 303 302 - qcom,sm8250-dwc3 304 303 - qcom,sm8450-dwc3 304 + - qcom,sm8550-dwc3 305 305 then: 306 306 properties: 307 307 clocks: ··· 360 358 - qcom,sm8250-dwc3 361 359 - qcom,sm8350-dwc3 362 360 - qcom,sm8450-dwc3 361 + - qcom,sm8550-dwc3 363 362 then: 364 363 properties: 365 364 interrupts:
+1
Documentation/devicetree/bindings/usb/usb-drd.yaml
··· 27 27 should default to OTG. 28 28 $ref: /schemas/types.yaml#/definitions/string 29 29 enum: [host, peripheral, otg] 30 + default: otg 30 31 31 32 hnp-disable: 32 33 description:
+5
Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml
··· 39 39 the VBus line. 40 40 $ref: /schemas/types.yaml#/definitions/phandle 41 41 42 + wakeup-source: 43 + description: 44 + Specify if the USB phy can detect the remote wakeup signal 45 + while the system sleep. 46 + 42 47 required: 43 48 - compatible 44 49 - '#phy-cells'
-89
Documentation/devicetree/bindings/usb/usb251xb.txt
··· 1 - Microchip USB 2.0 Hi-Speed Hub Controller 2 - 3 - The device node for the configuration of a Microchip USB251x/xBi USB 2.0 4 - Hi-Speed Controller. 5 - 6 - Required properties : 7 - - compatible : Should be "microchip,usb251xb" or one of the specific types: 8 - "microchip,usb2512b", "microchip,usb2512bi", "microchip,usb2513b", 9 - "microchip,usb2513bi", "microchip,usb2514b", "microchip,usb2514bi", 10 - "microchip,usb2517", "microchip,usb2517i", "microchip,usb2422" 11 - - reg : I2C address on the selected bus (default is <0x2C>) 12 - 13 - Optional properties : 14 - - reset-gpios : Should specify the gpio for hub reset 15 - - vdd-supply : Should specify the phandle to the regulator supplying vdd 16 - - skip-config : Skip Hub configuration, but only send the USB-Attach command 17 - - vendor-id : Set USB Vendor ID of the hub (16 bit, default is 0x0424) 18 - - product-id : Set USB Product ID of the hub (16 bit, default depends on type) 19 - - device-id : Set USB Device ID of the hub (16 bit, default is 0x0bb3) 20 - - language-id : Set USB Language ID (16 bit, default is 0x0000) 21 - - manufacturer : Set USB Manufacturer string (max 31 characters long) 22 - - product : Set USB Product string (max 31 characters long) 23 - - serial : Set USB Serial string (max 31 characters long) 24 - - {bus,self}-powered : selects between self- and bus-powered operation 25 - (boolean, default is self-powered) 26 - - disable-hi-speed : disable USB Hi-Speed support (boolean) 27 - - {multi,single}-tt : selects between multi- and single-transaction-translator 28 - (boolean, default is multi-tt) 29 - - disable-eop : disable End of Packet generation in full-speed mode (boolean) 30 - - {ganged,individual}-sensing : select over-current sense type in self-powered 31 - mode (boolean, default is individual) 32 - - {ganged,individual}-port-switching : select port power switching mode 33 - (boolean, default is individual) 34 - - dynamic-power-switching : enable auto-switching from self- to bus-powered 35 - operation if the local power source is removed or unavailable (boolean) 36 - - oc-delay-us : Delay time (in microseconds) for filtering the over-current 37 - sense inputs. Valid values are 100, 4000, 8000 (default) and 16000. If 38 - an invalid value is given, the default is used instead. 39 - - compound-device : indicate the hub is part of a compound device (boolean) 40 - - port-mapping-mode : enable port mapping mode (boolean) 41 - - led-{usb,speed}-mode : led usb/speed indication mode selection 42 - (boolean, default is speed mode) 43 - - string-support : enable string descriptor support (required for manufacturer, 44 - product and serial string configuration) 45 - - non-removable-ports : Should specify the ports which have a non-removable 46 - device connected. 47 - - sp-disabled-ports : Specifies the ports which will be self-power disabled 48 - - bp-disabled-ports : Specifies the ports which will be bus-power disabled 49 - - sp-max-total-current-microamp: Specifies max current consumed by the hub 50 - from VBUS when operating in self-powered hub. It includes the hub 51 - silicon along with all associated circuitry including a permanently 52 - attached peripheral (range: 0 - 100000 uA, default 1000 uA) 53 - - bp-max-total-current-microamp: Specifies max current consumed by the hub 54 - from VBUS when operating in self-powered hub. It includes the hub 55 - silicon along with all associated circuitry including a permanently 56 - attached peripheral (range: 0 - 510000 uA, default 100000 uA) 57 - - sp-max-removable-current-microamp: Specifies max current consumed by the hub 58 - from VBUS when operating in self-powered hub. It includes the hub 59 - silicon along with all associated circuitry excluding a permanently 60 - attached peripheral (range: 0 - 100000 uA, default 1000 uA) 61 - - bp-max-removable-current-microamp: Specifies max current consumed by the hub 62 - from VBUS when operating in self-powered hub. It includes the hub 63 - silicon along with all associated circuitry excluding a permanently 64 - attached peripheral (range: 0 - 510000 uA, default 100000 uA) 65 - - power-on-time-ms : Specifies the time it takes from the time the host 66 - initiates the power-on sequence to a port until the port has adequate 67 - power. The value is given in ms in a 0 - 510 range (default is 100ms). 68 - - swap-dx-lanes : Specifies the ports which will swap the differential-pair 69 - (D+/D-), default is not-swapped. 70 - 71 - Examples: 72 - usb2512b@2c { 73 - compatible = "microchip,usb2512b"; 74 - reg = <0x2c>; 75 - reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>; 76 - }; 77 - 78 - usb2514b@2c { 79 - compatible = "microchip,usb2514b"; 80 - reg = <0x2c>; 81 - vendor-id = /bits/ 16 <0x0000>; 82 - product-id = /bits/ 16 <0x0000>; 83 - string-support; 84 - manufacturer = "Foo"; 85 - product = "Foo-Bar"; 86 - serial = "1234567890A"; 87 - /* correct misplaced usb connectors on port 1,2 */ 88 - swap-dx-lanes = <1 2>; 89 - };
+271
Documentation/devicetree/bindings/usb/usb251xb.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/usb251xb.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Microchip USB 2.0 Hi-Speed Hub Controller 8 + 9 + maintainers: 10 + - Richard Leitner <richard.leitner@skidata.com> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - microchip,usb2422 16 + - microchip,usb2512b 17 + - microchip,usb2512bi 18 + - microchip,usb2513b 19 + - microchip,usb2513bi 20 + - microchip,usb2514b 21 + - microchip,usb2514bi 22 + - microchip,usb2517 23 + - microchip,usb2517i 24 + - microchip,usb251xb 25 + 26 + reg: 27 + maxItems: 1 28 + 29 + reset-gpios: 30 + description: | 31 + Should specify the gpio for hub reset 32 + 33 + vdd-supply: 34 + description: | 35 + Should specify the phandle to the regulator supplying vdd 36 + 37 + skip-config: 38 + $ref: /schemas/types.yaml#/definitions/flag 39 + description: | 40 + Skip Hub configuration, but only send the USB-Attach command 41 + 42 + vendor-id: 43 + $ref: /schemas/types.yaml#/definitions/uint16 44 + default: 0x0424 45 + description: | 46 + Set USB Vendor ID of the hub 47 + 48 + product-id: 49 + $ref: /schemas/types.yaml#/definitions/uint16 50 + description: | 51 + Set USB Product ID of the hub 52 + 53 + device-id: 54 + $ref: /schemas/types.yaml#/definitions/uint16 55 + default: 0x0bb3 56 + description: | 57 + Set USB Device ID of the hub 58 + 59 + language-id: 60 + $ref: /schemas/types.yaml#/definitions/uint16 61 + default: 0x0000 62 + description: | 63 + Set USB Language ID 64 + 65 + manufacturer: 66 + $ref: /schemas/types.yaml#/definitions/string 67 + description: | 68 + Set USB Manufacturer string (max 31 characters long) 69 + 70 + product: 71 + $ref: /schemas/types.yaml#/definitions/string 72 + description: | 73 + Set USB Product string (max 31 characters long) 74 + 75 + serial: 76 + $ref: /schemas/types.yaml#/definitions/string 77 + description: | 78 + Set USB Serial string (max 31 characters long) 79 + 80 + bus-powered: 81 + $ref: /schemas/types.yaml#/definitions/flag 82 + description: | 83 + selects between self- and bus-powered operation 84 + (boolean, default is self-powered) 85 + 86 + self-powered: 87 + $ref: /schemas/types.yaml#/definitions/flag 88 + description: | 89 + selects between self- and bus-powered operation 90 + (boolean, default is self-powered) 91 + 92 + disable-hi-speed: 93 + $ref: /schemas/types.yaml#/definitions/flag 94 + description: | 95 + disable USB Hi-Speed support (boolean) 96 + 97 + multi-tt: 98 + $ref: /schemas/types.yaml#/definitions/flag 99 + description: | 100 + selects between multi- and single-transaction-translator 101 + (boolean, default is multi-tt) 102 + 103 + single-tt: 104 + $ref: /schemas/types.yaml#/definitions/flag 105 + description: | 106 + selects between multi- and single-transaction-translator 107 + (boolean, default is multi-tt) 108 + 109 + disable-eop: 110 + $ref: /schemas/types.yaml#/definitions/flag 111 + description: | 112 + disable End of Packet generation in full-speed mode (boolean) 113 + 114 + ganged-sensing: 115 + $ref: /schemas/types.yaml#/definitions/flag 116 + description: | 117 + select over-current sense type in self-powered mode 118 + (boolean, default is individual) 119 + 120 + individual-sensing: 121 + $ref: /schemas/types.yaml#/definitions/flag 122 + description: | 123 + select over-current sense type in self-powered mode 124 + (boolean, default is individual) 125 + 126 + ganged-port-switching: 127 + $ref: /schemas/types.yaml#/definitions/flag 128 + description: | 129 + select port power switching mode (boolean, default is individual) 130 + 131 + individual-port-switching: 132 + $ref: /schemas/types.yaml#/definitions/flag 133 + description: | 134 + select port power switching mode (boolean, default is individual) 135 + 136 + dynamic-power-switching: 137 + $ref: /schemas/types.yaml#/definitions/flag 138 + description: | 139 + enable auto-switching from self- to bus-powered operation if the 140 + local power source is removed or unavailable (boolean) 141 + 142 + oc-delay-us: 143 + enum: [100, 4000, 8000, 16000] 144 + default: 8000 145 + description: | 146 + Delay time (in microseconds) for filtering the over-current sense 147 + inputs. If an invalid value is given, the default is used instead. 148 + 149 + compound-device: 150 + $ref: /schemas/types.yaml#/definitions/flag 151 + description: | 152 + indicate the hub is part of a compound device (boolean) 153 + 154 + port-mapping-mode: 155 + $ref: /schemas/types.yaml#/definitions/flag 156 + description: | 157 + enable port mapping mode (boolean) 158 + 159 + led-usb-mode: 160 + $ref: /schemas/types.yaml#/definitions/flag 161 + description: | 162 + led usb/speed indication mode selection (boolean, default is speed mode) 163 + 164 + led-speed-mode: 165 + $ref: /schemas/types.yaml#/definitions/flag 166 + description: | 167 + led usb/speed indication mode selection (boolean, default is speed mode) 168 + 169 + string-support: 170 + $ref: /schemas/types.yaml#/definitions/flag 171 + description: | 172 + enable string descriptor support (required for manufacturer, product 173 + and serial string configuration) 174 + 175 + non-removable-ports: 176 + $ref: /schemas/types.yaml#/definitions/uint8-array 177 + description: | 178 + Should specify the ports which have a non-removable device connected. 179 + 180 + sp-disabled-ports: 181 + $ref: /schemas/types.yaml#/definitions/uint8-array 182 + description: | 183 + Specifies the ports which will be self-power disabled 184 + 185 + bp-disabled-ports: 186 + $ref: /schemas/types.yaml#/definitions/uint8-array 187 + description: | 188 + Specifies the ports which will be bus-power disabled 189 + 190 + sp-max-total-current-microamp: 191 + maximum: 100000 192 + default: 1000 193 + description: | 194 + Specifies max current consumed by the hub from VBUS when 195 + operating in self-powered hub. It includes the hub silicon 196 + along with all associated circuitry including a permanently 197 + attached peripheral. 198 + 199 + bp-max-total-current-microamp: 200 + maximum: 510000 201 + default: 100000 202 + description: | 203 + Specifies max current consumed by the hub from VBUS when 204 + operating in self-powered hub. It includes the hub silicon 205 + along with all associated circuitry including a permanently 206 + attached peripheral. 207 + 208 + sp-max-removable-current-microamp: 209 + maximum: 100000 210 + default: 1000 211 + description: | 212 + Specifies max current consumed by the hub from VBUS when 213 + operating in self-powered hub. It includes the hub silicon 214 + along with all associated circuitry excluding a permanently 215 + attached peripheral. 216 + 217 + bp-max-removable-current-microamp: 218 + maximum: 510000 219 + default: 100000 220 + description: | 221 + Specifies max current consumed by the hub from VBUS when 222 + operating in self-powered hub. It includes the hub silicon 223 + along with all associated circuitry excluding a permanently 224 + attached peripheral. 225 + 226 + power-on-time-ms: 227 + maximum: 510 228 + default: 100 229 + description: | 230 + Specifies the time it takes from the time the host initiates the 231 + power-on sequence to a port until the port has adequate power. 232 + 233 + swap-dx-lanes: 234 + $ref: /schemas/types.yaml#/definitions/uint8-array 235 + description: | 236 + Specifies the ports which will swap the differential-pair (D+/D-), 237 + default is not-swapped. 238 + 239 + additionalProperties: false 240 + 241 + required: 242 + - compatible 243 + - reg 244 + 245 + examples: 246 + - | 247 + #include <dt-bindings/gpio/gpio.h> 248 + 249 + i2c { 250 + #address-cells = <1>; 251 + #size-cells = <0>; 252 + 253 + usb-hub@2c { 254 + compatible = "microchip,usb2512b"; 255 + reg = <0x2c>; 256 + reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>; 257 + }; 258 + 259 + usb-hub@2d { 260 + compatible = "microchip,usb2514b"; 261 + reg = <0x2d>; 262 + vendor-id = /bits/ 16 <0x0000>; 263 + product-id = /bits/ 16 <0x0000>; 264 + string-support; 265 + manufacturer = "Foo"; 266 + product = "Foo-Bar"; 267 + serial = "1234567890A"; 268 + /* correct misplaced usb connectors on port 1,2 */ 269 + swap-dx-lanes = <1 2>; 270 + }; 271 + };
+2
Documentation/devicetree/bindings/vendor-prefixes.yaml
··· 494 494 description: GE Fanuc Intelligent Platforms Embedded Systems, Inc. 495 495 "^gemei,.*": 496 496 description: Gemei Digital Technology Co., Ltd. 497 + "^genesys,.*": 498 + description: Genesys Logic, Inc. 497 499 "^geniatech,.*": 498 500 description: Geniatech, Inc. 499 501 "^giantec,.*":
+2
Documentation/driver-api/driver-model/devres.rst
··· 395 395 396 396 PHY 397 397 devm_usb_get_phy() 398 + devm_usb_get_phy_by_node() 399 + devm_usb_get_phy_by_phandle() 398 400 devm_usb_put_phy() 399 401 400 402 PINCTRL
+7 -1
MAINTAINERS
··· 7935 7935 F: include/linux/fanotify.h 7936 7936 F: include/uapi/linux/fanotify.h 7937 7937 7938 + FARADAY FOTG210 USB2 DUAL-ROLE CONTROLLER 7939 + M: Linus Walleij <linus.walleij@linaro.org> 7940 + L: linux-usb@vger.kernel.org 7941 + S: Maintained 7942 + F: drivers/usb/fotg210/ 7943 + 7938 7944 FARSYNC SYNCHRONOUS DRIVER 7939 7945 M: Kevin Curtis <kevin.curtis@farsite.co.uk> 7940 7946 S: Supported ··· 13801 13795 M: Richard Leitner <richard.leitner@skidata.com> 13802 13796 L: linux-usb@vger.kernel.org 13803 13797 S: Maintained 13804 - F: Documentation/devicetree/bindings/usb/usb251xb.txt 13798 + F: Documentation/devicetree/bindings/usb/usb251xb.yaml 13805 13799 F: drivers/usb/misc/usb251xb.c 13806 13800 13807 13801 MICROCHIP USBA UDC DRIVER
-1
arch/powerpc/configs/ppc6xx_defconfig
··· 911 911 CONFIG_USB_FTDI_ELAN=m 912 912 CONFIG_USB_APPLEDISPLAY=m 913 913 CONFIG_USB_SISUSBVGA=m 914 - CONFIG_USB_SISUSBVGA_CON=y 915 914 CONFIG_USB_LD=m 916 915 CONFIG_USB_TRANCEVIBRATOR=m 917 916 CONFIG_USB_IOWARRIOR=m
-1
arch/sh/configs/landisk_defconfig
··· 92 92 CONFIG_USB_EMI62=m 93 93 CONFIG_USB_EMI26=m 94 94 CONFIG_USB_SISUSBVGA=m 95 - CONFIG_USB_SISUSBVGA_CON=y 96 95 CONFIG_EXT2_FS=y 97 96 CONFIG_EXT3_FS=y 98 97 # CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
+12 -5
drivers/extcon/extcon-usbc-tusb320.c
··· 313 313 typec_set_pwr_opmode(port, TYPEC_PWR_MODE_USB); 314 314 } 315 315 316 - static irqreturn_t tusb320_irq_handler(int irq, void *dev_id) 316 + static irqreturn_t tusb320_state_update_handler(struct tusb320_priv *priv, 317 + bool force_update) 317 318 { 318 - struct tusb320_priv *priv = dev_id; 319 319 unsigned int reg; 320 320 321 321 if (regmap_read(priv->regmap, TUSB320_REG9, &reg)) { ··· 323 323 return IRQ_NONE; 324 324 } 325 325 326 - if (!(reg & TUSB320_REG9_INTERRUPT_STATUS)) 326 + if (!force_update && !(reg & TUSB320_REG9_INTERRUPT_STATUS)) 327 327 return IRQ_NONE; 328 328 329 329 tusb320_extcon_irq_handler(priv, reg); ··· 338 338 regmap_write(priv->regmap, TUSB320_REG9, reg); 339 339 340 340 return IRQ_HANDLED; 341 + } 342 + 343 + static irqreturn_t tusb320_irq_handler(int irq, void *dev_id) 344 + { 345 + struct tusb320_priv *priv = dev_id; 346 + 347 + return tusb320_state_update_handler(priv, false); 341 348 } 342 349 343 350 static const struct regmap_config tusb320_regmap_config = { ··· 473 466 return ret; 474 467 475 468 /* update initial state */ 476 - tusb320_irq_handler(client->irq, priv); 469 + tusb320_state_update_handler(priv, true); 477 470 478 471 /* Reset chip to its default state */ 479 472 ret = tusb320_reset(priv); ··· 484 477 * State and polarity might change after a reset, so update 485 478 * them again and make sure the interrupt status bit is cleared. 486 479 */ 487 - tusb320_irq_handler(client->irq, priv); 480 + tusb320_state_update_handler(priv, true); 488 481 489 482 ret = devm_request_threaded_irq(priv->dev, client->irq, NULL, 490 483 tusb320_irq_handler,
+1 -1
drivers/platform/chrome/cros_ec_typec.c
··· 971 971 if (!resp->source_cap_count && !resp->sink_cap_count) 972 972 return; 973 973 974 - port->partner_pd = usb_power_delivery_register(NULL, &desc); 974 + port->partner_pd = typec_partner_usb_power_delivery_register(port->partner, &desc); 975 975 if (IS_ERR(port->partner_pd)) { 976 976 dev_warn(typec->dev, "Failed to register partner PD device, port: %d\n", port_num); 977 977 return;
+4 -8
drivers/thunderbolt/acpi.c
··· 15 15 void **return_value) 16 16 { 17 17 struct acpi_device *adev = acpi_fetch_acpi_dev(handle); 18 - struct fwnode_reference_args args; 19 18 struct fwnode_handle *fwnode; 20 19 struct tb_nhi *nhi = data; 21 20 struct pci_dev *pdev; 22 21 struct device *dev; 23 - int ret; 24 22 25 23 if (!adev) 26 24 return AE_OK; 27 25 28 - fwnode = acpi_fwnode_handle(adev); 29 - ret = fwnode_property_get_reference_args(fwnode, "usb4-host-interface", 30 - NULL, 0, 0, &args); 31 - if (ret) 26 + fwnode = fwnode_find_reference(acpi_fwnode_handle(adev), "usb4-host-interface", 0); 27 + if (IS_ERR(fwnode)) 32 28 return AE_OK; 33 29 34 30 /* It needs to reference this NHI */ 35 - if (dev_fwnode(&nhi->pdev->dev) != args.fwnode) 31 + if (dev_fwnode(&nhi->pdev->dev) != fwnode) 36 32 goto out_put; 37 33 38 34 /* ··· 96 100 } 97 101 98 102 out_put: 99 - fwnode_handle_put(args.fwnode); 103 + fwnode_handle_put(fwnode); 100 104 return AE_OK; 101 105 } 102 106
+3 -2
drivers/thunderbolt/switch.c
··· 8 8 9 9 #include <linux/delay.h> 10 10 #include <linux/idr.h> 11 + #include <linux/module.h> 11 12 #include <linux/nvmem-provider.h> 12 13 #include <linux/pm_runtime.h> 13 14 #include <linux/sched/signal.h> 14 15 #include <linux/sizes.h> 15 16 #include <linux/slab.h> 16 - #include <linux/module.h> 17 + #include <linux/string_helpers.h> 17 18 18 19 #include "tb.h" 19 20 ··· 645 644 if (ret) 646 645 return ret; 647 646 648 - tb_port_dbg(port, "lane %sabled\n", enable ? "en" : "dis"); 647 + tb_port_dbg(port, "lane %s\n", str_enabled_disabled(enable)); 649 648 return 0; 650 649 } 651 650
+2
drivers/thunderbolt/tb_regs.h
··· 361 361 #define PORT_CS_18_BE BIT(8) 362 362 #define PORT_CS_18_TCM BIT(9) 363 363 #define PORT_CS_18_CPS BIT(10) 364 + #define PORT_CS_18_WOCS BIT(16) 365 + #define PORT_CS_18_WODS BIT(17) 364 366 #define PORT_CS_18_WOU4S BIT(18) 365 367 #define PORT_CS_19 0x13 366 368 #define PORT_CS_19_PC BIT(3)
+25 -8
drivers/thunderbolt/usb4.c
··· 155 155 156 156 static void usb4_switch_check_wakes(struct tb_switch *sw) 157 157 { 158 + bool wakeup_usb4 = false; 159 + struct usb4_port *usb4; 158 160 struct tb_port *port; 159 161 bool wakeup = false; 160 162 u32 val; ··· 175 173 wakeup = val & (ROUTER_CS_6_WOPS | ROUTER_CS_6_WOUS); 176 174 } 177 175 178 - /* Check for any connected downstream ports for USB4 wake */ 176 + /* 177 + * Check for any downstream ports for USB4 wake, 178 + * connection wake and disconnection wake. 179 + */ 179 180 tb_switch_for_each_port(sw, port) { 180 - if (!tb_port_has_remote(port)) 181 + if (!port->cap_usb4) 181 182 continue; 182 183 183 184 if (tb_port_read(port, &val, TB_CFG_PORT, 184 185 port->cap_usb4 + PORT_CS_18, 1)) 185 186 break; 186 187 187 - tb_port_dbg(port, "USB4 wake: %s\n", 188 - (val & PORT_CS_18_WOU4S) ? "yes" : "no"); 188 + tb_port_dbg(port, "USB4 wake: %s, connection wake: %s, disconnection wake: %s\n", 189 + (val & PORT_CS_18_WOU4S) ? "yes" : "no", 190 + (val & PORT_CS_18_WOCS) ? "yes" : "no", 191 + (val & PORT_CS_18_WODS) ? "yes" : "no"); 189 192 190 - if (val & PORT_CS_18_WOU4S) 191 - wakeup = true; 193 + wakeup_usb4 = val & (PORT_CS_18_WOU4S | PORT_CS_18_WOCS | 194 + PORT_CS_18_WODS); 195 + 196 + usb4 = port->usb4; 197 + if (device_may_wakeup(&usb4->dev) && wakeup_usb4) 198 + pm_wakeup_event(&usb4->dev, 0); 199 + 200 + wakeup |= wakeup_usb4; 192 201 } 193 202 194 203 if (wakeup) ··· 379 366 */ 380 367 int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags) 381 368 { 369 + struct usb4_port *usb4; 382 370 struct tb_port *port; 383 371 u64 route = tb_route(sw); 384 372 u32 val; ··· 409 395 val |= PORT_CS_19_WOU4; 410 396 } else { 411 397 bool configured = val & PORT_CS_19_PC; 398 + usb4 = port->usb4; 412 399 413 - if ((flags & TB_WAKE_ON_CONNECT) && !configured) 400 + if (((flags & TB_WAKE_ON_CONNECT) | 401 + device_may_wakeup(&usb4->dev)) && !configured) 414 402 val |= PORT_CS_19_WOC; 415 - if ((flags & TB_WAKE_ON_DISCONNECT) && configured) 403 + if (((flags & TB_WAKE_ON_DISCONNECT) | 404 + device_may_wakeup(&usb4->dev)) && configured) 416 405 val |= PORT_CS_19_WOD; 417 406 if ((flags & TB_WAKE_ON_USB4) && configured) 418 407 val |= PORT_CS_19_WOU4;
+3
drivers/thunderbolt/usb4_port.c
··· 284 284 } 285 285 } 286 286 287 + if (!tb_is_upstream_port(port)) 288 + device_set_wakeup_capable(&usb4->dev, true); 289 + 287 290 pm_runtime_no_callbacks(&usb4->dev); 288 291 pm_runtime_set_active(&usb4->dev); 289 292 pm_runtime_enable(&usb4->dev);
+2 -2
drivers/thunderbolt/xdomain.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/pm_runtime.h> 15 15 #include <linux/prandom.h> 16 + #include <linux/string_helpers.h> 16 17 #include <linux/utsname.h> 17 18 #include <linux/uuid.h> 18 19 #include <linux/workqueue.h> ··· 342 341 memcpy(&req.src_uuid, src_uuid, sizeof(*src_uuid)); 343 342 memcpy(&req.dst_uuid, dst_uuid, sizeof(*dst_uuid)); 344 343 345 - len = 0; 346 344 data_len = 0; 347 345 348 346 do { ··· 1344 1344 tb_port_update_credits(port); 1345 1345 tb_xdomain_update_link_attributes(xd); 1346 1346 1347 - dev_dbg(&xd->dev, "lane bonding %sabled\n", width == 2 ? "en" : "dis"); 1347 + dev_dbg(&xd->dev, "lane bonding %s\n", str_enabled_disabled(width == 2)); 1348 1348 return 0; 1349 1349 } 1350 1350
+4
drivers/usb/Kconfig
··· 111 111 112 112 endif 113 113 114 + comment "USB dual-mode controller drivers" 115 + 114 116 source "drivers/usb/cdns3/Kconfig" 117 + 118 + source "drivers/usb/fotg210/Kconfig" 115 119 116 120 source "drivers/usb/mtu3/Kconfig" 117 121
+2
drivers/usb/Makefile
··· 17 17 obj-$(CONFIG_USB_CDNS3) += cdns3/ 18 18 obj-$(CONFIG_USB_CDNSP_PCI) += cdns3/ 19 19 20 + obj-$(CONFIG_USB_FOTG210) += fotg210/ 21 + 20 22 obj-$(CONFIG_USB_MON) += mon/ 21 23 obj-$(CONFIG_USB_MTU3) += mtu3/ 22 24
+3 -5
drivers/usb/cdns3/cdnsp-pci.c
··· 192 192 if (pci_dev_run_wake(pdev)) 193 193 pm_runtime_get_noresume(&pdev->dev); 194 194 195 - if (!pci_is_enabled(func)) { 195 + if (pci_is_enabled(func)) { 196 + cdns_remove(cdnsp); 197 + } else { 196 198 kfree(cdnsp); 197 - goto pci_put; 198 199 } 199 200 200 - cdns_remove(cdnsp); 201 - 202 - pci_put: 203 201 pci_dev_put(func); 204 202 } 205 203
+32 -10
drivers/usb/cdns3/cdnsp-ring.c
··· 2006 2006 2007 2007 int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq) 2008 2008 { 2009 - u32 field, length_field, remainder; 2009 + u32 field, length_field, zlp = 0; 2010 2010 struct cdnsp_ep *pep = preq->pep; 2011 2011 struct cdnsp_ring *ep_ring; 2012 2012 int num_trbs; 2013 + u32 maxp; 2013 2014 int ret; 2014 2015 2015 2016 ep_ring = cdnsp_request_to_transfer_ring(pdev, preq); ··· 2020 2019 /* 1 TRB for data, 1 for status */ 2021 2020 num_trbs = (pdev->three_stage_setup) ? 2 : 1; 2022 2021 2022 + maxp = usb_endpoint_maxp(pep->endpoint.desc); 2023 + 2024 + if (preq->request.zero && preq->request.length && 2025 + (preq->request.length % maxp == 0)) { 2026 + num_trbs++; 2027 + zlp = 1; 2028 + } 2029 + 2023 2030 ret = cdnsp_prepare_transfer(pdev, preq, num_trbs); 2024 2031 if (ret) 2025 2032 return ret; 2026 2033 2027 2034 /* If there's data, queue data TRBs */ 2028 - if (pdev->ep0_expect_in) 2029 - field = TRB_TYPE(TRB_DATA) | TRB_IOC; 2030 - else 2031 - field = TRB_ISP | TRB_TYPE(TRB_DATA) | TRB_IOC; 2032 - 2033 2035 if (preq->request.length > 0) { 2034 - remainder = cdnsp_td_remainder(pdev, 0, preq->request.length, 2035 - preq->request.length, preq, 1, 0); 2036 + field = TRB_TYPE(TRB_DATA); 2036 2037 2037 - length_field = TRB_LEN(preq->request.length) | 2038 - TRB_TD_SIZE(remainder) | TRB_INTR_TARGET(0); 2038 + if (zlp) 2039 + field |= TRB_CHAIN; 2040 + else 2041 + field |= TRB_IOC | (pdev->ep0_expect_in ? 0 : TRB_ISP); 2039 2042 2040 2043 if (pdev->ep0_expect_in) 2041 2044 field |= TRB_DIR_IN; 2045 + 2046 + length_field = TRB_LEN(preq->request.length) | 2047 + TRB_TD_SIZE(zlp) | TRB_INTR_TARGET(0); 2042 2048 2043 2049 cdnsp_queue_trb(pdev, ep_ring, true, 2044 2050 lower_32_bits(preq->request.dma), ··· 2053 2045 field | ep_ring->cycle_state | 2054 2046 TRB_SETUPID(pdev->setup_id) | 2055 2047 pdev->setup_speed); 2048 + 2049 + if (zlp) { 2050 + field = TRB_TYPE(TRB_NORMAL) | TRB_IOC; 2051 + 2052 + if (!pdev->ep0_expect_in) 2053 + field = TRB_ISP; 2054 + 2055 + cdnsp_queue_trb(pdev, ep_ring, true, 2056 + lower_32_bits(preq->request.dma), 2057 + upper_32_bits(preq->request.dma), 0, 2058 + field | ep_ring->cycle_state | 2059 + TRB_SETUPID(pdev->setup_id) | 2060 + pdev->setup_speed); 2061 + } 2056 2062 2057 2063 pdev->ep0_stage = CDNSP_DATA_STAGE; 2058 2064 }
+4
drivers/usb/chipidea/ci.h
··· 127 127 * struct ci_role_driver - host/gadget role driver 128 128 * @start: start this role 129 129 * @stop: stop this role 130 + * @suspend: system suspend handler for this role 131 + * @resume: system resume handler for this role 130 132 * @irq: irq handler for this role 131 133 * @name: role name string (host/gadget) 132 134 */ 133 135 struct ci_role_driver { 134 136 int (*start)(struct ci_hdrc *); 135 137 void (*stop)(struct ci_hdrc *); 138 + void (*suspend)(struct ci_hdrc *ci); 139 + void (*resume)(struct ci_hdrc *ci, bool power_lost); 136 140 irqreturn_t (*irq)(struct ci_hdrc *); 137 141 const char *name; 138 142 };
+16 -35
drivers/usb/chipidea/ci_hdrc_imx.c
··· 355 355 data->hsic_pad_regulator = 356 356 devm_regulator_get_optional(dev, "hsic"); 357 357 if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) { 358 - /* no pad regualator is needed */ 358 + /* no pad regulator is needed */ 359 359 data->hsic_pad_regulator = NULL; 360 360 } else if (IS_ERR(data->hsic_pad_regulator)) 361 361 return dev_err_probe(dev, PTR_ERR(data->hsic_pad_regulator), ··· 527 527 ci_hdrc_imx_remove(pdev); 528 528 } 529 529 530 - static int __maybe_unused imx_controller_suspend(struct device *dev) 530 + static int __maybe_unused imx_controller_suspend(struct device *dev, 531 + pm_message_t msg) 531 532 { 532 533 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); 533 534 int ret = 0; 534 535 535 536 dev_dbg(dev, "at %s\n", __func__); 536 537 537 - ret = imx_usbmisc_hsic_set_clk(data->usbmisc_data, false); 538 + ret = imx_usbmisc_suspend(data->usbmisc_data, 539 + PMSG_IS_AUTO(msg) || device_may_wakeup(dev)); 538 540 if (ret) { 539 - dev_err(dev, "usbmisc hsic_set_clk failed, ret=%d\n", ret); 541 + dev_err(dev, 542 + "usbmisc suspend failed, ret=%d\n", ret); 540 543 return ret; 541 544 } 542 545 ··· 552 549 return 0; 553 550 } 554 551 555 - static int __maybe_unused imx_controller_resume(struct device *dev) 552 + static int __maybe_unused imx_controller_resume(struct device *dev, 553 + pm_message_t msg) 556 554 { 557 555 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); 558 556 int ret = 0; ··· 574 570 575 571 data->in_lpm = false; 576 572 577 - ret = imx_usbmisc_set_wakeup(data->usbmisc_data, false); 573 + ret = imx_usbmisc_resume(data->usbmisc_data, 574 + PMSG_IS_AUTO(msg) || device_may_wakeup(dev)); 578 575 if (ret) { 579 - dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret); 576 + dev_err(dev, "usbmisc resume failed, ret=%d\n", ret); 580 577 goto clk_disable; 581 - } 582 - 583 - ret = imx_usbmisc_hsic_set_clk(data->usbmisc_data, true); 584 - if (ret) { 585 - dev_err(dev, "usbmisc hsic_set_clk failed, ret=%d\n", ret); 586 - goto hsic_set_clk_fail; 587 578 } 588 579 589 580 return 0; 590 581 591 - hsic_set_clk_fail: 592 - imx_usbmisc_set_wakeup(data->usbmisc_data, true); 593 582 clk_disable: 594 583 imx_disable_unprepare_clks(dev); 595 584 return ret; ··· 598 601 /* The core's suspend doesn't run */ 599 602 return 0; 600 603 601 - if (device_may_wakeup(dev)) { 602 - ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true); 603 - if (ret) { 604 - dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", 605 - ret); 606 - return ret; 607 - } 608 - } 609 - 610 - ret = imx_controller_suspend(dev); 604 + ret = imx_controller_suspend(dev, PMSG_SUSPEND); 611 605 if (ret) 612 606 return ret; 613 607 ··· 612 624 int ret; 613 625 614 626 pinctrl_pm_select_default_state(dev); 615 - ret = imx_controller_resume(dev); 627 + ret = imx_controller_resume(dev, PMSG_RESUME); 616 628 if (!ret && data->supports_runtime_pm) { 617 629 pm_runtime_disable(dev); 618 630 pm_runtime_set_active(dev); ··· 625 637 static int __maybe_unused ci_hdrc_imx_runtime_suspend(struct device *dev) 626 638 { 627 639 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); 628 - int ret; 629 640 630 641 if (data->in_lpm) { 631 642 WARN_ON(1); 632 643 return 0; 633 644 } 634 645 635 - ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true); 636 - if (ret) { 637 - dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret); 638 - return ret; 639 - } 640 - 641 - return imx_controller_suspend(dev); 646 + return imx_controller_suspend(dev, PMSG_AUTO_SUSPEND); 642 647 } 643 648 644 649 static int __maybe_unused ci_hdrc_imx_runtime_resume(struct device *dev) 645 650 { 646 - return imx_controller_resume(dev); 651 + return imx_controller_resume(dev, PMSG_AUTO_RESUME); 647 652 } 648 653 649 654 static const struct dev_pm_ops ci_hdrc_imx_pm_ops = {
+2 -2
drivers/usb/chipidea/ci_hdrc_imx.h
··· 32 32 33 33 int imx_usbmisc_init(struct imx_usbmisc_data *data); 34 34 int imx_usbmisc_init_post(struct imx_usbmisc_data *data); 35 - int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled); 36 35 int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data); 37 - int imx_usbmisc_hsic_set_clk(struct imx_usbmisc_data *data, bool on); 38 36 int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect); 37 + int imx_usbmisc_suspend(struct imx_usbmisc_data *data, bool wakeup); 38 + int imx_usbmisc_resume(struct imx_usbmisc_data *data, bool wakeup); 39 39 40 40 #endif /* __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H */
+93 -58
drivers/usb/chipidea/core.c
··· 608 608 enum usb_role role) 609 609 { 610 610 struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw); 611 - struct ci_hdrc_cable *cable = NULL; 612 - enum usb_role current_role = ci_role_to_usb_role(ci); 613 - enum ci_role ci_role = usb_role_to_ci_role(role); 614 - unsigned long flags; 611 + struct ci_hdrc_cable *cable; 615 612 616 - if ((ci_role != CI_ROLE_END && !ci->roles[ci_role]) || 617 - (current_role == role)) 618 - return 0; 619 - 620 - pm_runtime_get_sync(ci->dev); 621 - /* Stop current role */ 622 - spin_lock_irqsave(&ci->lock, flags); 623 - if (current_role == USB_ROLE_DEVICE) 624 - cable = &ci->platdata->vbus_extcon; 625 - else if (current_role == USB_ROLE_HOST) 613 + if (role == USB_ROLE_HOST) { 626 614 cable = &ci->platdata->id_extcon; 627 - 628 - if (cable) { 629 - cable->changed = true; 630 - cable->connected = false; 631 - ci_irq(ci); 632 - spin_unlock_irqrestore(&ci->lock, flags); 633 - if (ci->wq && role != USB_ROLE_NONE) 634 - flush_workqueue(ci->wq); 635 - spin_lock_irqsave(&ci->lock, flags); 636 - } 637 - 638 - cable = NULL; 639 - 640 - /* Start target role */ 641 - if (role == USB_ROLE_DEVICE) 642 - cable = &ci->platdata->vbus_extcon; 643 - else if (role == USB_ROLE_HOST) 644 - cable = &ci->platdata->id_extcon; 645 - 646 - if (cable) { 647 615 cable->changed = true; 648 616 cable->connected = true; 649 - ci_irq(ci); 617 + cable = &ci->platdata->vbus_extcon; 618 + cable->changed = true; 619 + cable->connected = false; 620 + } else if (role == USB_ROLE_DEVICE) { 621 + cable = &ci->platdata->id_extcon; 622 + cable->changed = true; 623 + cable->connected = false; 624 + cable = &ci->platdata->vbus_extcon; 625 + cable->changed = true; 626 + cable->connected = true; 627 + } else { 628 + cable = &ci->platdata->id_extcon; 629 + cable->changed = true; 630 + cable->connected = false; 631 + cable = &ci->platdata->vbus_extcon; 632 + cable->changed = true; 633 + cable->connected = false; 650 634 } 651 - spin_unlock_irqrestore(&ci->lock, flags); 652 - pm_runtime_put_sync(ci->dev); 653 635 636 + ci_irq(ci); 654 637 return 0; 638 + } 639 + 640 + static enum ci_role ci_get_role(struct ci_hdrc *ci) 641 + { 642 + enum ci_role role; 643 + 644 + if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { 645 + if (ci->is_otg) { 646 + role = ci_otg_role(ci); 647 + hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE); 648 + } else { 649 + /* 650 + * If the controller is not OTG capable, but support 651 + * role switch, the defalt role is gadget, and the 652 + * user can switch it through debugfs. 653 + */ 654 + role = CI_ROLE_GADGET; 655 + } 656 + } else { 657 + role = ci->roles[CI_ROLE_HOST] ? CI_ROLE_HOST 658 + : CI_ROLE_GADGET; 659 + } 660 + 661 + return role; 655 662 } 656 663 657 664 static struct usb_role_switch_desc ci_role_switch = { ··· 1158 1151 } 1159 1152 } 1160 1153 1161 - if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { 1162 - if (ci->is_otg) { 1163 - ci->role = ci_otg_role(ci); 1164 - /* Enable ID change irq */ 1165 - hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE); 1166 - } else { 1167 - /* 1168 - * If the controller is not OTG capable, but support 1169 - * role switch, the defalt role is gadget, and the 1170 - * user can switch it through debugfs. 1171 - */ 1172 - ci->role = CI_ROLE_GADGET; 1173 - } 1174 - } else { 1175 - ci->role = ci->roles[CI_ROLE_HOST] 1176 - ? CI_ROLE_HOST 1177 - : CI_ROLE_GADGET; 1178 - } 1179 - 1154 + ci->role = ci_get_role(ci); 1180 1155 if (!ci_otg_is_fsm_mode(ci)) { 1181 1156 /* only update vbus status for peripheral */ 1182 1157 if (ci->role == CI_ROLE_GADGET) { ··· 1294 1305 cable_id = &ci->platdata->id_extcon; 1295 1306 cable_vbus = &ci->platdata->vbus_extcon; 1296 1307 1297 - if (!IS_ERR(cable_id->edev) && ci->is_otg && 1308 + if ((!IS_ERR(cable_id->edev) || !IS_ERR(ci->role_switch)) 1309 + && ci->is_otg && 1298 1310 (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) 1299 1311 ci_irq(ci); 1300 1312 1301 - if (!IS_ERR(cable_vbus->edev) && ci->is_otg && 1313 + if ((!IS_ERR(cable_vbus->edev) || !IS_ERR(ci->role_switch)) 1314 + && ci->is_otg && 1302 1315 (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) 1303 1316 ci_irq(ci); 1304 1317 } ··· 1364 1373 return 0; 1365 1374 } 1366 1375 1376 + /* Extra routine per role before system suspend */ 1377 + if (ci->role != CI_ROLE_END && ci_role(ci)->suspend) 1378 + ci_role(ci)->suspend(ci); 1379 + 1367 1380 if (device_may_wakeup(dev)) { 1368 1381 if (ci_otg_is_fsm_mode(ci)) 1369 1382 ci_otg_fsm_suspend_for_srp(ci); ··· 1381 1386 return 0; 1382 1387 } 1383 1388 1389 + static void ci_handle_power_lost(struct ci_hdrc *ci) 1390 + { 1391 + enum ci_role role; 1392 + 1393 + disable_irq_nosync(ci->irq); 1394 + if (!ci_otg_is_fsm_mode(ci)) { 1395 + role = ci_get_role(ci); 1396 + 1397 + if (ci->role != role) { 1398 + ci_handle_id_switch(ci); 1399 + } else if (role == CI_ROLE_GADGET) { 1400 + if (ci->is_otg && hw_read_otgsc(ci, OTGSC_BSV)) 1401 + usb_gadget_vbus_connect(&ci->gadget); 1402 + } 1403 + } 1404 + 1405 + enable_irq(ci->irq); 1406 + } 1407 + 1384 1408 static int ci_resume(struct device *dev) 1385 1409 { 1386 1410 struct ci_hdrc *ci = dev_get_drvdata(dev); 1411 + bool power_lost; 1387 1412 int ret; 1413 + 1414 + /* Since ASYNCLISTADDR (host mode) and ENDPTLISTADDR (device 1415 + * mode) share the same register address. We can check if 1416 + * controller resume from power lost based on this address 1417 + * due to this register will be reset after power lost. 1418 + */ 1419 + power_lost = !hw_read(ci, OP_ENDPTLISTADDR, ~0); 1388 1420 1389 1421 if (device_may_wakeup(dev)) 1390 1422 disable_irq_wake(ci->irq); ··· 1419 1397 ret = ci_controller_resume(dev); 1420 1398 if (ret) 1421 1399 return ret; 1400 + 1401 + if (power_lost) { 1402 + /* shutdown and re-init for phy */ 1403 + ci_usb_phy_exit(ci); 1404 + ci_usb_phy_init(ci); 1405 + } 1406 + 1407 + /* Extra routine per role after system resume */ 1408 + if (ci->role != CI_ROLE_END && ci_role(ci)->resume) 1409 + ci_role(ci)->resume(ci, power_lost); 1410 + 1411 + if (power_lost) 1412 + ci_handle_power_lost(ci); 1422 1413 1423 1414 if (ci->supports_runtime_pm) { 1424 1415 pm_runtime_disable(dev);
+16
drivers/usb/chipidea/host.c
··· 459 459 ci_hdrc_free_dma_aligned_buffer(urb); 460 460 } 461 461 462 + #ifdef CONFIG_PM_SLEEP 463 + static void ci_hdrc_host_suspend(struct ci_hdrc *ci) 464 + { 465 + ehci_suspend(ci->hcd, device_may_wakeup(ci->dev)); 466 + } 467 + 468 + static void ci_hdrc_host_resume(struct ci_hdrc *ci, bool power_lost) 469 + { 470 + ehci_resume(ci->hcd, power_lost); 471 + } 472 + #endif 473 + 462 474 int ci_hdrc_host_init(struct ci_hdrc *ci) 463 475 { 464 476 struct ci_role_driver *rdrv; ··· 484 472 485 473 rdrv->start = host_start; 486 474 rdrv->stop = host_stop; 475 + #ifdef CONFIG_PM_SLEEP 476 + rdrv->suspend = ci_hdrc_host_suspend; 477 + rdrv->resume = ci_hdrc_host_resume; 478 + #endif 487 479 rdrv->irq = host_irq; 488 480 rdrv->name = "host"; 489 481 ci->roles[CI_ROLE_HOST] = rdrv;
+1 -1
drivers/usb/chipidea/otg.c
··· 165 165 return 0; 166 166 } 167 167 168 - static void ci_handle_id_switch(struct ci_hdrc *ci) 168 + void ci_handle_id_switch(struct ci_hdrc *ci) 169 169 { 170 170 enum ci_role role = ci_otg_role(ci); 171 171
+1
drivers/usb/chipidea/otg.h
··· 14 14 void ci_hdrc_otg_destroy(struct ci_hdrc *ci); 15 15 enum ci_role ci_otg_role(struct ci_hdrc *ci); 16 16 void ci_handle_vbus_change(struct ci_hdrc *ci); 17 + void ci_handle_id_switch(struct ci_hdrc *ci); 17 18 static inline void ci_otg_queue_work(struct ci_hdrc *ci) 18 19 { 19 20 disable_irq_nosync(ci->irq);
+32
drivers/usb/chipidea/udc.c
··· 2181 2181 ci->platdata->pins_default); 2182 2182 } 2183 2183 2184 + #ifdef CONFIG_PM_SLEEP 2185 + static void udc_suspend(struct ci_hdrc *ci) 2186 + { 2187 + /* 2188 + * Set OP_ENDPTLISTADDR to be non-zero for 2189 + * checking if controller resume from power lost 2190 + * in non-host mode. 2191 + */ 2192 + if (hw_read(ci, OP_ENDPTLISTADDR, ~0) == 0) 2193 + hw_write(ci, OP_ENDPTLISTADDR, ~0, ~0); 2194 + } 2195 + 2196 + static void udc_resume(struct ci_hdrc *ci, bool power_lost) 2197 + { 2198 + if (power_lost) { 2199 + if (ci->is_otg) 2200 + hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, 2201 + OTGSC_BSVIS | OTGSC_BSVIE); 2202 + if (ci->vbus_active) 2203 + usb_gadget_vbus_disconnect(&ci->gadget); 2204 + } 2205 + 2206 + /* Restore value 0 if it was set for power lost check */ 2207 + if (hw_read(ci, OP_ENDPTLISTADDR, ~0) == 0xFFFFFFFF) 2208 + hw_write(ci, OP_ENDPTLISTADDR, ~0, 0); 2209 + } 2210 + #endif 2211 + 2184 2212 /** 2185 2213 * ci_hdrc_gadget_init - initialize device related bits 2186 2214 * @ci: the controller ··· 2229 2201 2230 2202 rdrv->start = udc_id_switch_for_device; 2231 2203 rdrv->stop = udc_id_switch_for_host; 2204 + #ifdef CONFIG_PM_SLEEP 2205 + rdrv->suspend = udc_suspend; 2206 + rdrv->resume = udc_resume; 2207 + #endif 2232 2208 rdrv->irq = udc_irq; 2233 2209 rdrv->name = "gadget"; 2234 2210
+131 -31
drivers/usb/chipidea/usbmisc_imx.c
··· 150 150 int (*hsic_set_clk)(struct imx_usbmisc_data *data, bool enabled); 151 151 /* usb charger detection */ 152 152 int (*charger_detection)(struct imx_usbmisc_data *data); 153 + /* It's called when system resume from usb power lost */ 154 + int (*power_lost_check)(struct imx_usbmisc_data *data); 153 155 }; 154 156 155 157 struct imx_usbmisc { ··· 939 937 return 0; 940 938 } 941 939 940 + static int usbmisc_imx7d_power_lost_check(struct imx_usbmisc_data *data) 941 + { 942 + struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 943 + unsigned long flags; 944 + u32 val; 945 + 946 + spin_lock_irqsave(&usbmisc->lock, flags); 947 + val = readl(usbmisc->base); 948 + spin_unlock_irqrestore(&usbmisc->lock, flags); 949 + /* 950 + * Here use a power on reset value to judge 951 + * if the controller experienced a power lost 952 + */ 953 + if (val == 0x30001000) 954 + return 1; 955 + else 956 + return 0; 957 + } 958 + 959 + static int usbmisc_imx6sx_power_lost_check(struct imx_usbmisc_data *data) 960 + { 961 + struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); 962 + unsigned long flags; 963 + u32 val; 964 + 965 + spin_lock_irqsave(&usbmisc->lock, flags); 966 + val = readl(usbmisc->base + data->index * 4); 967 + spin_unlock_irqrestore(&usbmisc->lock, flags); 968 + /* 969 + * Here use a power on reset value to judge 970 + * if the controller experienced a power lost 971 + */ 972 + if (val == 0x30001000) 973 + return 1; 974 + else 975 + return 0; 976 + } 977 + 942 978 static const struct usbmisc_ops imx25_usbmisc_ops = { 943 979 .init = usbmisc_imx25_init, 944 980 .post = usbmisc_imx25_post, ··· 1010 970 .init = usbmisc_imx6sx_init, 1011 971 .hsic_set_connect = usbmisc_imx6_hsic_set_connect, 1012 972 .hsic_set_clk = usbmisc_imx6_hsic_set_clk, 973 + .power_lost_check = usbmisc_imx6sx_power_lost_check, 1013 974 }; 1014 975 1015 976 static const struct usbmisc_ops imx7d_usbmisc_ops = { 1016 977 .init = usbmisc_imx7d_init, 1017 978 .set_wakeup = usbmisc_imx7d_set_wakeup, 1018 979 .charger_detection = imx7d_charger_detection, 980 + .power_lost_check = usbmisc_imx7d_power_lost_check, 1019 981 }; 1020 982 1021 983 static const struct usbmisc_ops imx7ulp_usbmisc_ops = { ··· 1025 983 .set_wakeup = usbmisc_imx7d_set_wakeup, 1026 984 .hsic_set_connect = usbmisc_imx6_hsic_set_connect, 1027 985 .hsic_set_clk = usbmisc_imx6_hsic_set_clk, 986 + .power_lost_check = usbmisc_imx7d_power_lost_check, 1028 987 }; 1029 988 1030 989 static inline bool is_imx53_usbmisc(struct imx_usbmisc_data *data) ··· 1052 1009 int imx_usbmisc_init_post(struct imx_usbmisc_data *data) 1053 1010 { 1054 1011 struct imx_usbmisc *usbmisc; 1012 + int ret = 0; 1055 1013 1056 1014 if (!data) 1057 1015 return 0; 1058 1016 1059 1017 usbmisc = dev_get_drvdata(data->dev); 1060 - if (!usbmisc->ops->post) 1061 - return 0; 1062 - return usbmisc->ops->post(data); 1018 + if (usbmisc->ops->post) 1019 + ret = usbmisc->ops->post(data); 1020 + if (ret) { 1021 + dev_err(data->dev, "post init failed, ret=%d\n", ret); 1022 + return ret; 1023 + } 1024 + 1025 + if (usbmisc->ops->set_wakeup) 1026 + ret = usbmisc->ops->set_wakeup(data, false); 1027 + if (ret) { 1028 + dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret); 1029 + return ret; 1030 + } 1031 + 1032 + return 0; 1063 1033 } 1064 1034 EXPORT_SYMBOL_GPL(imx_usbmisc_init_post); 1065 - 1066 - int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled) 1067 - { 1068 - struct imx_usbmisc *usbmisc; 1069 - 1070 - if (!data) 1071 - return 0; 1072 - 1073 - usbmisc = dev_get_drvdata(data->dev); 1074 - if (!usbmisc->ops->set_wakeup) 1075 - return 0; 1076 - return usbmisc->ops->set_wakeup(data, enabled); 1077 - } 1078 - EXPORT_SYMBOL_GPL(imx_usbmisc_set_wakeup); 1079 1035 1080 1036 int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data) 1081 1037 { ··· 1089 1047 return usbmisc->ops->hsic_set_connect(data); 1090 1048 } 1091 1049 EXPORT_SYMBOL_GPL(imx_usbmisc_hsic_set_connect); 1092 - 1093 - int imx_usbmisc_hsic_set_clk(struct imx_usbmisc_data *data, bool on) 1094 - { 1095 - struct imx_usbmisc *usbmisc; 1096 - 1097 - if (!data) 1098 - return 0; 1099 - 1100 - usbmisc = dev_get_drvdata(data->dev); 1101 - if (!usbmisc->ops->hsic_set_clk || !data->hsic) 1102 - return 0; 1103 - return usbmisc->ops->hsic_set_clk(data, on); 1104 - } 1105 - EXPORT_SYMBOL_GPL(imx_usbmisc_hsic_set_clk); 1106 1050 1107 1051 int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect) 1108 1052 { ··· 1121 1093 return ret; 1122 1094 } 1123 1095 EXPORT_SYMBOL_GPL(imx_usbmisc_charger_detection); 1096 + 1097 + int imx_usbmisc_suspend(struct imx_usbmisc_data *data, bool wakeup) 1098 + { 1099 + struct imx_usbmisc *usbmisc; 1100 + int ret = 0; 1101 + 1102 + if (!data) 1103 + return 0; 1104 + 1105 + usbmisc = dev_get_drvdata(data->dev); 1106 + 1107 + if (wakeup && usbmisc->ops->set_wakeup) 1108 + ret = usbmisc->ops->set_wakeup(data, true); 1109 + if (ret) { 1110 + dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret); 1111 + return ret; 1112 + } 1113 + 1114 + if (usbmisc->ops->hsic_set_clk && data->hsic) 1115 + ret = usbmisc->ops->hsic_set_clk(data, false); 1116 + if (ret) { 1117 + dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret); 1118 + return ret; 1119 + } 1120 + 1121 + return ret; 1122 + } 1123 + EXPORT_SYMBOL_GPL(imx_usbmisc_suspend); 1124 + 1125 + int imx_usbmisc_resume(struct imx_usbmisc_data *data, bool wakeup) 1126 + { 1127 + struct imx_usbmisc *usbmisc; 1128 + int ret = 0; 1129 + 1130 + if (!data) 1131 + return 0; 1132 + 1133 + usbmisc = dev_get_drvdata(data->dev); 1134 + 1135 + if (usbmisc->ops->power_lost_check) 1136 + ret = usbmisc->ops->power_lost_check(data); 1137 + if (ret > 0) { 1138 + /* re-init if resume from power lost */ 1139 + ret = imx_usbmisc_init(data); 1140 + if (ret) { 1141 + dev_err(data->dev, "re-init failed, ret=%d\n", ret); 1142 + return ret; 1143 + } 1144 + } 1145 + 1146 + if (wakeup && usbmisc->ops->set_wakeup) 1147 + ret = usbmisc->ops->set_wakeup(data, false); 1148 + if (ret) { 1149 + dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret); 1150 + return ret; 1151 + } 1152 + 1153 + if (usbmisc->ops->hsic_set_clk && data->hsic) 1154 + ret = usbmisc->ops->hsic_set_clk(data, true); 1155 + if (ret) { 1156 + dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret); 1157 + goto hsic_set_clk_fail; 1158 + } 1159 + 1160 + return 0; 1161 + 1162 + hsic_set_clk_fail: 1163 + if (wakeup && usbmisc->ops->set_wakeup) 1164 + usbmisc->ops->set_wakeup(data, true); 1165 + return ret; 1166 + } 1167 + EXPORT_SYMBOL_GPL(imx_usbmisc_resume); 1124 1168 1125 1169 static const struct of_device_id usbmisc_imx_dt_ids[] = { 1126 1170 {
+1 -1
drivers/usb/common/ulpi.c
··· 207 207 /* Test the interface */ 208 208 ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa); 209 209 if (ret < 0) 210 - goto err; 210 + return ret; 211 211 212 212 ret = ulpi_read(ulpi, ULPI_SCRATCH); 213 213 if (ret < 0)
+41 -41
drivers/usb/core/config.c
··· 61 61 desc = (struct usb_ssp_isoc_ep_comp_descriptor *) buffer; 62 62 if (desc->bDescriptorType != USB_DT_SSP_ISOC_ENDPOINT_COMP || 63 63 size < USB_DT_SSP_ISOC_EP_COMP_SIZE) { 64 - dev_warn(ddev, "Invalid SuperSpeedPlus isoc endpoint companion" 64 + dev_notice(ddev, "Invalid SuperSpeedPlus isoc endpoint companion" 65 65 "for config %d interface %d altsetting %d ep %d.\n", 66 66 cfgno, inum, asnum, ep->desc.bEndpointAddress); 67 67 return; ··· 83 83 84 84 if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP || 85 85 size < USB_DT_SS_EP_COMP_SIZE) { 86 - dev_warn(ddev, "No SuperSpeed endpoint companion for config %d " 86 + dev_notice(ddev, "No SuperSpeed endpoint companion for config %d " 87 87 " interface %d altsetting %d ep %d: " 88 88 "using minimum values\n", 89 89 cfgno, inum, asnum, ep->desc.bEndpointAddress); ··· 109 109 110 110 /* Check the various values */ 111 111 if (usb_endpoint_xfer_control(&ep->desc) && desc->bMaxBurst != 0) { 112 - dev_warn(ddev, "Control endpoint with bMaxBurst = %d in " 112 + dev_notice(ddev, "Control endpoint with bMaxBurst = %d in " 113 113 "config %d interface %d altsetting %d ep %d: " 114 114 "setting to zero\n", desc->bMaxBurst, 115 115 cfgno, inum, asnum, ep->desc.bEndpointAddress); 116 116 ep->ss_ep_comp.bMaxBurst = 0; 117 117 } else if (desc->bMaxBurst > 15) { 118 - dev_warn(ddev, "Endpoint with bMaxBurst = %d in " 118 + dev_notice(ddev, "Endpoint with bMaxBurst = %d in " 119 119 "config %d interface %d altsetting %d ep %d: " 120 120 "setting to 15\n", desc->bMaxBurst, 121 121 cfgno, inum, asnum, ep->desc.bEndpointAddress); ··· 125 125 if ((usb_endpoint_xfer_control(&ep->desc) || 126 126 usb_endpoint_xfer_int(&ep->desc)) && 127 127 desc->bmAttributes != 0) { 128 - dev_warn(ddev, "%s endpoint with bmAttributes = %d in " 128 + dev_notice(ddev, "%s endpoint with bmAttributes = %d in " 129 129 "config %d interface %d altsetting %d ep %d: " 130 130 "setting to zero\n", 131 131 usb_endpoint_xfer_control(&ep->desc) ? "Control" : "Bulk", ··· 134 134 ep->ss_ep_comp.bmAttributes = 0; 135 135 } else if (usb_endpoint_xfer_bulk(&ep->desc) && 136 136 desc->bmAttributes > 16) { 137 - dev_warn(ddev, "Bulk endpoint with more than 65536 streams in " 137 + dev_notice(ddev, "Bulk endpoint with more than 65536 streams in " 138 138 "config %d interface %d altsetting %d ep %d: " 139 139 "setting to max\n", 140 140 cfgno, inum, asnum, ep->desc.bEndpointAddress); ··· 142 142 } else if (usb_endpoint_xfer_isoc(&ep->desc) && 143 143 !USB_SS_SSP_ISOC_COMP(desc->bmAttributes) && 144 144 USB_SS_MULT(desc->bmAttributes) > 3) { 145 - dev_warn(ddev, "Isoc endpoint has Mult of %d in " 145 + dev_notice(ddev, "Isoc endpoint has Mult of %d in " 146 146 "config %d interface %d altsetting %d ep %d: " 147 147 "setting to 3\n", 148 148 USB_SS_MULT(desc->bmAttributes), ··· 160 160 else 161 161 max_tx = 999999; 162 162 if (le16_to_cpu(desc->wBytesPerInterval) > max_tx) { 163 - dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in " 163 + dev_notice(ddev, "%s endpoint with wBytesPerInterval of %d in " 164 164 "config %d interface %d altsetting %d ep %d: " 165 165 "setting to %d\n", 166 166 usb_endpoint_xfer_isoc(&ep->desc) ? "Isoc" : "Int", ··· 273 273 else if (d->bLength >= USB_DT_ENDPOINT_SIZE) 274 274 n = USB_DT_ENDPOINT_SIZE; 275 275 else { 276 - dev_warn(ddev, "config %d interface %d altsetting %d has an " 276 + dev_notice(ddev, "config %d interface %d altsetting %d has an " 277 277 "invalid endpoint descriptor of length %d, skipping\n", 278 278 cfgno, inum, asnum, d->bLength); 279 279 goto skip_to_next_endpoint_or_interface_descriptor; ··· 281 281 282 282 i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK; 283 283 if (i >= 16 || i == 0) { 284 - dev_warn(ddev, "config %d interface %d altsetting %d has an " 284 + dev_notice(ddev, "config %d interface %d altsetting %d has an " 285 285 "invalid endpoint with address 0x%X, skipping\n", 286 286 cfgno, inum, asnum, d->bEndpointAddress); 287 287 goto skip_to_next_endpoint_or_interface_descriptor; ··· 293 293 294 294 /* Check for duplicate endpoint addresses */ 295 295 if (config_endpoint_is_duplicate(config, inum, asnum, d)) { 296 - dev_warn(ddev, "config %d interface %d altsetting %d has a duplicate endpoint with address 0x%X, skipping\n", 296 + dev_notice(ddev, "config %d interface %d altsetting %d has a duplicate endpoint with address 0x%X, skipping\n", 297 297 cfgno, inum, asnum, d->bEndpointAddress); 298 298 goto skip_to_next_endpoint_or_interface_descriptor; 299 299 } ··· 301 301 /* Ignore some endpoints */ 302 302 if (udev->quirks & USB_QUIRK_ENDPOINT_IGNORE) { 303 303 if (usb_endpoint_is_ignored(udev, ifp, d)) { 304 - dev_warn(ddev, "config %d interface %d altsetting %d has an ignored endpoint with address 0x%X, skipping\n", 304 + dev_notice(ddev, "config %d interface %d altsetting %d has an ignored endpoint with address 0x%X, skipping\n", 305 305 cfgno, inum, asnum, 306 306 d->bEndpointAddress); 307 307 goto skip_to_next_endpoint_or_interface_descriptor; ··· 378 378 } 379 379 } 380 380 if (d->bInterval < i || d->bInterval > j) { 381 - dev_warn(ddev, "config %d interface %d altsetting %d " 381 + dev_notice(ddev, "config %d interface %d altsetting %d " 382 382 "endpoint 0x%X has an invalid bInterval %d, " 383 383 "changing to %d\n", 384 384 cfgno, inum, asnum, ··· 391 391 * them usable, we will try treating them as Interrupt endpoints. 392 392 */ 393 393 if (udev->speed == USB_SPEED_LOW && usb_endpoint_xfer_bulk(d)) { 394 - dev_warn(ddev, "config %d interface %d altsetting %d " 394 + dev_notice(ddev, "config %d interface %d altsetting %d " 395 395 "endpoint 0x%X is Bulk; changing to Interrupt\n", 396 396 cfgno, inum, asnum, d->bEndpointAddress); 397 397 endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT; ··· 408 408 */ 409 409 maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize); 410 410 if (maxp == 0 && !(usb_endpoint_xfer_isoc(d) && asnum == 0)) { 411 - dev_warn(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid wMaxPacketSize 0\n", 411 + dev_notice(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid wMaxPacketSize 0\n", 412 412 cfgno, inum, asnum, d->bEndpointAddress); 413 413 } 414 414 ··· 439 439 j = maxpacket_maxes[usb_endpoint_type(&endpoint->desc)]; 440 440 441 441 if (maxp > j) { 442 - dev_warn(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid maxpacket %d, setting to %d\n", 442 + dev_notice(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid maxpacket %d, setting to %d\n", 443 443 cfgno, inum, asnum, d->bEndpointAddress, maxp, j); 444 444 maxp = j; 445 445 endpoint->desc.wMaxPacketSize = cpu_to_le16(i | maxp); ··· 452 452 */ 453 453 if (udev->speed == USB_SPEED_HIGH && usb_endpoint_xfer_bulk(d)) { 454 454 if (maxp != 512) 455 - dev_warn(ddev, "config %d interface %d altsetting %d " 455 + dev_notice(ddev, "config %d interface %d altsetting %d " 456 456 "bulk endpoint 0x%X has invalid maxpacket %d\n", 457 457 cfgno, inum, asnum, d->bEndpointAddress, 458 458 maxp); ··· 533 533 i < intfc->num_altsetting; 534 534 (++i, ++alt)) { 535 535 if (alt->desc.bAlternateSetting == asnum) { 536 - dev_warn(ddev, "Duplicate descriptor for config %d " 536 + dev_notice(ddev, "Duplicate descriptor for config %d " 537 537 "interface %d altsetting %d, skipping\n", 538 538 cfgno, inum, asnum); 539 539 goto skip_to_next_interface_descriptor; ··· 559 559 num_ep = num_ep_orig = alt->desc.bNumEndpoints; 560 560 alt->desc.bNumEndpoints = 0; /* Use as a counter */ 561 561 if (num_ep > USB_MAXENDPOINTS) { 562 - dev_warn(ddev, "too many endpoints for config %d interface %d " 562 + dev_notice(ddev, "too many endpoints for config %d interface %d " 563 563 "altsetting %d: %d, using maximum allowed: %d\n", 564 564 cfgno, inum, asnum, num_ep, USB_MAXENDPOINTS); 565 565 num_ep = USB_MAXENDPOINTS; ··· 590 590 } 591 591 592 592 if (n != num_ep_orig) 593 - dev_warn(ddev, "config %d interface %d altsetting %d has %d " 593 + dev_notice(ddev, "config %d interface %d altsetting %d has %d " 594 594 "endpoint descriptor%s, different from the interface " 595 595 "descriptor's value: %d\n", 596 596 cfgno, inum, asnum, n, plural(n), num_ep_orig); ··· 625 625 if (config->desc.bDescriptorType != USB_DT_CONFIG || 626 626 config->desc.bLength < USB_DT_CONFIG_SIZE || 627 627 config->desc.bLength > size) { 628 - dev_err(ddev, "invalid descriptor for config index %d: " 628 + dev_notice(ddev, "invalid descriptor for config index %d: " 629 629 "type = 0x%X, length = %d\n", cfgidx, 630 630 config->desc.bDescriptorType, config->desc.bLength); 631 631 return -EINVAL; ··· 636 636 size -= config->desc.bLength; 637 637 638 638 if (nintf > USB_MAXINTERFACES) { 639 - dev_warn(ddev, "config %d has too many interfaces: %d, " 639 + dev_notice(ddev, "config %d has too many interfaces: %d, " 640 640 "using maximum allowed: %d\n", 641 641 cfgno, nintf, USB_MAXINTERFACES); 642 642 nintf = USB_MAXINTERFACES; ··· 650 650 (buffer2 += header->bLength, size2 -= header->bLength)) { 651 651 652 652 if (size2 < sizeof(struct usb_descriptor_header)) { 653 - dev_warn(ddev, "config %d descriptor has %d excess " 653 + dev_notice(ddev, "config %d descriptor has %d excess " 654 654 "byte%s, ignoring\n", 655 655 cfgno, size2, plural(size2)); 656 656 break; ··· 658 658 659 659 header = (struct usb_descriptor_header *) buffer2; 660 660 if ((header->bLength > size2) || (header->bLength < 2)) { 661 - dev_warn(ddev, "config %d has an invalid descriptor " 661 + dev_notice(ddev, "config %d has an invalid descriptor " 662 662 "of length %d, skipping remainder of the config\n", 663 663 cfgno, header->bLength); 664 664 break; ··· 670 670 671 671 d = (struct usb_interface_descriptor *) header; 672 672 if (d->bLength < USB_DT_INTERFACE_SIZE) { 673 - dev_warn(ddev, "config %d has an invalid " 673 + dev_notice(ddev, "config %d has an invalid " 674 674 "interface descriptor of length %d, " 675 675 "skipping\n", cfgno, d->bLength); 676 676 continue; ··· 680 680 681 681 if ((dev->quirks & USB_QUIRK_HONOR_BNUMINTERFACES) && 682 682 n >= nintf_orig) { 683 - dev_warn(ddev, "config %d has more interface " 683 + dev_notice(ddev, "config %d has more interface " 684 684 "descriptors, than it declares in " 685 685 "bNumInterfaces, ignoring interface " 686 686 "number: %d\n", cfgno, inum); ··· 688 688 } 689 689 690 690 if (inum >= nintf_orig) 691 - dev_warn(ddev, "config %d has an invalid " 691 + dev_notice(ddev, "config %d has an invalid " 692 692 "interface number: %d but max is %d\n", 693 693 cfgno, inum, nintf_orig - 1); 694 694 ··· 713 713 714 714 d = (struct usb_interface_assoc_descriptor *)header; 715 715 if (d->bLength < USB_DT_INTERFACE_ASSOCIATION_SIZE) { 716 - dev_warn(ddev, 716 + dev_notice(ddev, 717 717 "config %d has an invalid interface association descriptor of length %d, skipping\n", 718 718 cfgno, d->bLength); 719 719 continue; 720 720 } 721 721 722 722 if (iad_num == USB_MAXIADS) { 723 - dev_warn(ddev, "found more Interface " 723 + dev_notice(ddev, "found more Interface " 724 724 "Association Descriptors " 725 725 "than allocated for in " 726 726 "configuration %d\n", cfgno); ··· 731 731 732 732 } else if (header->bDescriptorType == USB_DT_DEVICE || 733 733 header->bDescriptorType == USB_DT_CONFIG) 734 - dev_warn(ddev, "config %d contains an unexpected " 734 + dev_notice(ddev, "config %d contains an unexpected " 735 735 "descriptor of type 0x%X, skipping\n", 736 736 cfgno, header->bDescriptorType); 737 737 ··· 740 740 config->desc.wTotalLength = cpu_to_le16(buffer2 - buffer0); 741 741 742 742 if (n != nintf) 743 - dev_warn(ddev, "config %d has %d interface%s, different from " 743 + dev_notice(ddev, "config %d has %d interface%s, different from " 744 744 "the descriptor's value: %d\n", 745 745 cfgno, n, plural(n), nintf_orig); 746 746 else if (n == 0) 747 - dev_warn(ddev, "config %d has no interfaces?\n", cfgno); 747 + dev_notice(ddev, "config %d has no interfaces?\n", cfgno); 748 748 config->desc.bNumInterfaces = nintf = n; 749 749 750 750 /* Check for missing interface numbers */ ··· 754 754 break; 755 755 } 756 756 if (j >= nintf) 757 - dev_warn(ddev, "config %d has no interface number " 757 + dev_notice(ddev, "config %d has no interface number " 758 758 "%d\n", cfgno, i); 759 759 } 760 760 ··· 762 762 for (i = 0; i < nintf; ++i) { 763 763 j = nalts[i]; 764 764 if (j > USB_MAXALTSETTING) { 765 - dev_warn(ddev, "too many alternate settings for " 765 + dev_notice(ddev, "too many alternate settings for " 766 766 "config %d interface %d: %d, " 767 767 "using maximum allowed: %d\n", 768 768 cfgno, inums[i], j, USB_MAXALTSETTING); ··· 811 811 break; 812 812 } 813 813 if (n >= intfc->num_altsetting) 814 - dev_warn(ddev, "config %d interface %d has no " 814 + dev_notice(ddev, "config %d interface %d has no " 815 815 "altsetting %d\n", cfgno, inums[i], j); 816 816 } 817 817 } ··· 868 868 int result; 869 869 870 870 if (ncfg > USB_MAXCONFIG) { 871 - dev_warn(ddev, "too many configurations: %d, " 871 + dev_notice(ddev, "too many configurations: %d, " 872 872 "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG); 873 873 dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG; 874 874 } ··· 902 902 "descriptor/%s: %d\n", cfgno, "start", result); 903 903 if (result != -EPIPE) 904 904 goto err; 905 - dev_err(ddev, "chopping to %d config(s)\n", cfgno); 905 + dev_notice(ddev, "chopping to %d config(s)\n", cfgno); 906 906 dev->descriptor.bNumConfigurations = cfgno; 907 907 break; 908 908 } else if (result < 4) { ··· 934 934 goto err; 935 935 } 936 936 if (result < length) { 937 - dev_warn(ddev, "config index %d descriptor too short " 937 + dev_notice(ddev, "config index %d descriptor too short " 938 938 "(expected %i, got %i)\n", cfgno, length, result); 939 939 length = result; 940 940 } ··· 993 993 /* Get BOS descriptor */ 994 994 ret = usb_get_descriptor(dev, USB_DT_BOS, 0, bos, USB_DT_BOS_SIZE); 995 995 if (ret < USB_DT_BOS_SIZE || bos->bLength < USB_DT_BOS_SIZE) { 996 - dev_err(ddev, "unable to get BOS descriptor or descriptor too short\n"); 996 + dev_notice(ddev, "unable to get BOS descriptor or descriptor too short\n"); 997 997 if (ret >= 0) 998 998 ret = -ENOMSG; 999 999 kfree(bos); ··· 1021 1021 1022 1022 ret = usb_get_descriptor(dev, USB_DT_BOS, 0, buffer, total_len); 1023 1023 if (ret < total_len) { 1024 - dev_err(ddev, "unable to get BOS descriptor set\n"); 1024 + dev_notice(ddev, "unable to get BOS descriptor set\n"); 1025 1025 if (ret >= 0) 1026 1026 ret = -ENOMSG; 1027 1027 goto err; ··· 1046 1046 } 1047 1047 1048 1048 if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) { 1049 - dev_warn(ddev, "descriptor type invalid, skip\n"); 1049 + dev_notice(ddev, "descriptor type invalid, skip\n"); 1050 1050 continue; 1051 1051 } 1052 1052
+13
drivers/usb/core/hcd-pci.c
··· 558 558 return retval; 559 559 } 560 560 561 + static int hcd_pci_poweroff_late(struct device *dev) 562 + { 563 + struct pci_dev *pci_dev = to_pci_dev(dev); 564 + struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 565 + 566 + if (hcd->driver->pci_poweroff_late && !HCD_DEAD(hcd)) 567 + return hcd->driver->pci_poweroff_late(hcd, device_may_wakeup(dev)); 568 + 569 + return 0; 570 + } 571 + 561 572 static int hcd_pci_resume_noirq(struct device *dev) 562 573 { 563 574 powermac_set_asic(to_pci_dev(dev), 1); ··· 589 578 590 579 #define hcd_pci_suspend NULL 591 580 #define hcd_pci_suspend_noirq NULL 581 + #define hcd_pci_poweroff_late NULL 592 582 #define hcd_pci_resume_noirq NULL 593 583 #define hcd_pci_resume NULL 594 584 #define hcd_pci_restore NULL ··· 627 615 .thaw_noirq = NULL, 628 616 .thaw = hcd_pci_resume, 629 617 .poweroff = hcd_pci_suspend, 618 + .poweroff_late = hcd_pci_poweroff_late, 630 619 .poweroff_noirq = hcd_pci_suspend_noirq, 631 620 .restore_noirq = hcd_pci_resume_noirq, 632 621 .restore = hcd_pci_restore,
+5 -1
drivers/usb/core/hcd.c
··· 3133 3133 GFP_KERNEL, 3134 3134 DMA_ATTR_WRITE_COMBINE); 3135 3135 3136 - if (IS_ERR(local_mem)) 3136 + if (IS_ERR_OR_NULL(local_mem)) { 3137 + if (!local_mem) 3138 + return -ENOMEM; 3139 + 3137 3140 return PTR_ERR(local_mem); 3141 + } 3138 3142 3139 3143 /* 3140 3144 * Here we pass a dma_addr_t but the arg type is a phys_addr_t.
+60
drivers/usb/core/hub.c
··· 3081 3081 return status; 3082 3082 } 3083 3083 3084 + /* 3085 + * hub_port_stop_enumerate - stop USB enumeration or ignore port events 3086 + * @hub: target hub 3087 + * @port1: port num of the port 3088 + * @retries: port retries number of hub_port_init() 3089 + * 3090 + * Return: 3091 + * true: ignore port actions/events or give up connection attempts. 3092 + * false: keep original behavior. 3093 + * 3094 + * This function will be based on retries to check whether the port which is 3095 + * marked with early_stop attribute would stop enumeration or ignore events. 3096 + * 3097 + * Note: 3098 + * This function didn't change anything if early_stop is not set, and it will 3099 + * prevent all connection attempts when early_stop is set and the attempts of 3100 + * the port are more than 1. 3101 + */ 3102 + static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries) 3103 + { 3104 + struct usb_port *port_dev = hub->ports[port1 - 1]; 3105 + 3106 + if (port_dev->early_stop) { 3107 + if (port_dev->ignore_event) 3108 + return true; 3109 + 3110 + /* 3111 + * We want unsuccessful attempts to fail quickly. 3112 + * Since some devices may need one failure during 3113 + * port initialization, we allow two tries but no 3114 + * more. 3115 + */ 3116 + if (retries < 2) 3117 + return false; 3118 + 3119 + port_dev->ignore_event = 1; 3120 + } else 3121 + port_dev->ignore_event = 0; 3122 + 3123 + return port_dev->ignore_event; 3124 + } 3125 + 3084 3126 /* Check if a port is power on */ 3085 3127 int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) 3086 3128 { ··· 4838 4796 do_new_scheme = use_new_scheme(udev, retry_counter, port_dev); 4839 4797 4840 4798 for (retries = 0; retries < GET_DESCRIPTOR_TRIES; (++retries, msleep(100))) { 4799 + if (hub_port_stop_enumerate(hub, port1, retries)) { 4800 + retval = -ENODEV; 4801 + break; 4802 + } 4803 + 4841 4804 if (do_new_scheme) { 4842 4805 struct usb_device_descriptor *buf; 4843 4806 int r = 0; ··· 5293 5246 status = 0; 5294 5247 5295 5248 for (i = 0; i < PORT_INIT_TRIES; i++) { 5249 + if (hub_port_stop_enumerate(hub, port1, i)) { 5250 + status = -ENODEV; 5251 + break; 5252 + } 5253 + 5296 5254 usb_lock_port(port_dev); 5297 5255 mutex_lock(hcd->address0_mutex); 5298 5256 retry_locked = true; ··· 5666 5614 if (!pm_runtime_active(&port_dev->dev)) 5667 5615 return; 5668 5616 5617 + /* skip port actions if ignore_event and early_stop are true */ 5618 + if (port_dev->ignore_event && port_dev->early_stop) 5619 + return; 5620 + 5669 5621 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange)) 5670 5622 connect_change = 1; 5671 5623 ··· 5983 5927 mutex_lock(hcd->address0_mutex); 5984 5928 5985 5929 for (i = 0; i < PORT_INIT_TRIES; ++i) { 5930 + if (hub_port_stop_enumerate(parent_hub, port1, i)) { 5931 + ret = -ENODEV; 5932 + break; 5933 + } 5986 5934 5987 5935 /* ep0 maxpacket size may change; let the HCD know about it. 5988 5936 * Other endpoints will be handled by re-enumeration. */
+4
drivers/usb/core/hub.h
··· 90 90 * @is_superspeed cache super-speed status 91 91 * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted. 92 92 * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted. 93 + * @early_stop: whether port initialization will be stopped earlier. 94 + * @ignore_event: whether events of the port are ignored. 93 95 */ 94 96 struct usb_port { 95 97 struct usb_device *child; ··· 105 103 u32 over_current_count; 106 104 u8 portnum; 107 105 u32 quirks; 106 + unsigned int early_stop:1; 107 + unsigned int ignore_event:1; 108 108 unsigned int is_superspeed:1; 109 109 unsigned int usb3_lpm_u1_permit:1; 110 110 unsigned int usb3_lpm_u2_permit:1;
+29 -1
drivers/usb/core/port.c
··· 7 7 * Author: Lan Tianyu <tianyu.lan@intel.com> 8 8 */ 9 9 10 + #include <linux/kstrtox.h> 10 11 #include <linux/slab.h> 11 12 #include <linux/pm_qos.h> 12 13 #include <linux/component.h> ··· 17 16 static int usb_port_block_power_off; 18 17 19 18 static const struct attribute_group *port_dev_group[]; 19 + 20 + static ssize_t early_stop_show(struct device *dev, 21 + struct device_attribute *attr, char *buf) 22 + { 23 + struct usb_port *port_dev = to_usb_port(dev); 24 + 25 + return sysfs_emit(buf, "%s\n", port_dev->early_stop ? "yes" : "no"); 26 + } 27 + 28 + static ssize_t early_stop_store(struct device *dev, struct device_attribute *attr, 29 + const char *buf, size_t count) 30 + { 31 + struct usb_port *port_dev = to_usb_port(dev); 32 + bool value; 33 + 34 + if (kstrtobool(buf, &value)) 35 + return -EINVAL; 36 + 37 + if (value) 38 + port_dev->early_stop = 1; 39 + else 40 + port_dev->early_stop = 0; 41 + 42 + return count; 43 + } 44 + static DEVICE_ATTR_RW(early_stop); 20 45 21 46 static ssize_t disable_show(struct device *dev, 22 47 struct device_attribute *attr, char *buf) ··· 90 63 bool disabled; 91 64 int rc; 92 65 93 - rc = strtobool(buf, &disabled); 66 + rc = kstrtobool(buf, &disabled); 94 67 if (rc) 95 68 return rc; 96 69 ··· 263 236 &dev_attr_quirks.attr, 264 237 &dev_attr_over_current_count.attr, 265 238 &dev_attr_disable.attr, 239 + &dev_attr_early_stop.attr, 266 240 NULL, 267 241 }; 268 242
+4 -3
drivers/usb/core/sysfs.c
··· 13 13 14 14 15 15 #include <linux/kernel.h> 16 + #include <linux/kstrtox.h> 16 17 #include <linux/string.h> 17 18 #include <linux/usb.h> 18 19 #include <linux/usb/hcd.h> ··· 506 505 if (ret < 0) 507 506 return -EINTR; 508 507 509 - ret = strtobool(buf, &value); 508 + ret = kstrtobool(buf, &value); 510 509 511 510 if (!ret) { 512 511 udev->usb2_hw_lpm_allowed = value; ··· 976 975 int rc = count; 977 976 bool val; 978 977 979 - if (strtobool(buf, &val) != 0) 978 + if (kstrtobool(buf, &val) != 0) 980 979 return -EINVAL; 981 980 982 981 if (val) ··· 1177 1176 struct usb_interface *intf = to_usb_interface(dev); 1178 1177 bool val; 1179 1178 1180 - if (strtobool(buf, &val) != 0) 1179 + if (kstrtobool(buf, &val) != 0) 1181 1180 return -EINVAL; 1182 1181 1183 1182 if (val)
+4 -2
drivers/usb/dwc2/gadget.c
··· 4549 4549 hsotg->gadget.dev.of_node = hsotg->dev->of_node; 4550 4550 hsotg->gadget.speed = USB_SPEED_UNKNOWN; 4551 4551 4552 - if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) { 4552 + if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL || 4553 + (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg))) { 4553 4554 ret = dwc2_lowlevel_hw_enable(hsotg); 4554 4555 if (ret) 4555 4556 goto err; ··· 4612 4611 if (!IS_ERR_OR_NULL(hsotg->uphy)) 4613 4612 otg_set_peripheral(hsotg->uphy->otg, NULL); 4614 4613 4615 - if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) 4614 + if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL || 4615 + (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg))) 4616 4616 dwc2_lowlevel_hw_disable(hsotg); 4617 4617 4618 4618 return 0;
+4
drivers/usb/dwc2/params.c
··· 113 113 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 114 114 GAHBCFG_HBSTLEN_SHIFT; 115 115 p->power_down = DWC2_POWER_DOWN_PARAM_NONE; 116 + p->lpm = false; 117 + p->lpm_clock_gating = false; 118 + p->besl = false; 119 + p->hird_threshold_en = false; 116 120 } 117 121 118 122 static void dwc2_set_ltq_params(struct dwc2_hsotg *hsotg)
+3 -2
drivers/usb/dwc2/platform.c
··· 321 321 reset_control_assert(hsotg->reset); 322 322 reset_control_assert(hsotg->reset_ecc); 323 323 324 - return ret; 324 + return 0; 325 325 } 326 326 327 327 /** ··· 576 576 dwc2_debugfs_init(hsotg); 577 577 578 578 /* Gadget code manages lowlevel hw on its own */ 579 - if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) 579 + if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL || 580 + (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg))) 580 581 dwc2_lowlevel_hw_disable(hsotg); 581 582 582 583 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
+2 -2
drivers/usb/dwc3/Kconfig
··· 152 152 153 153 config USB_DWC3_XILINX 154 154 tristate "Xilinx Platforms" 155 - depends on (ARCH_ZYNQMP || ARCH_VERSAL) && OF 155 + depends on (ARCH_ZYNQMP || COMPILE_TEST) && OF 156 156 default USB_DWC3 157 157 help 158 158 Support Xilinx SoCs with DesignWare Core USB3 IP. 159 - This driver handles both ZynqMP and Versal SoC operations. 159 + This driver handles ZynqMP SoC operations. 160 160 Say 'Y' or 'M' if you have one such device. 161 161 162 162 config USB_DWC3_AM62
+16 -7
drivers/usb/dwc3/core.c
··· 122 122 unsigned long flags; 123 123 int ret; 124 124 u32 reg; 125 + u32 desired_dr_role; 125 126 126 127 mutex_lock(&dwc->mutex); 128 + spin_lock_irqsave(&dwc->lock, flags); 129 + desired_dr_role = dwc->desired_dr_role; 130 + spin_unlock_irqrestore(&dwc->lock, flags); 127 131 128 132 pm_runtime_get_sync(dwc->dev); 129 133 130 134 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG) 131 135 dwc3_otg_update(dwc, 0); 132 136 133 - if (!dwc->desired_dr_role) 137 + if (!desired_dr_role) 134 138 goto out; 135 139 136 - if (dwc->desired_dr_role == dwc->current_dr_role) 140 + if (desired_dr_role == dwc->current_dr_role) 137 141 goto out; 138 142 139 - if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) 143 + if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev) 140 144 goto out; 141 145 142 146 switch (dwc->current_dr_role) { ··· 168 164 */ 169 165 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) || 170 166 DWC3_VER_IS_PRIOR(DWC31, 190A)) && 171 - dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) { 167 + desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) { 172 168 reg = dwc3_readl(dwc->regs, DWC3_GCTL); 173 169 reg |= DWC3_GCTL_CORESOFTRESET; 174 170 dwc3_writel(dwc->regs, DWC3_GCTL, reg); ··· 188 184 189 185 spin_lock_irqsave(&dwc->lock, flags); 190 186 191 - dwc3_set_prtcap(dwc, dwc->desired_dr_role); 187 + dwc3_set_prtcap(dwc, desired_dr_role); 192 188 193 189 spin_unlock_irqrestore(&dwc->lock, flags); 194 190 195 - switch (dwc->desired_dr_role) { 191 + switch (desired_dr_role) { 196 192 case DWC3_GCTL_PRTCAP_HOST: 197 193 ret = dwc3_host_init(dwc); 198 194 if (ret) { ··· 1100 1096 1101 1097 if (!dwc->ulpi_ready) { 1102 1098 ret = dwc3_core_ulpi_init(dwc); 1103 - if (ret) 1099 + if (ret) { 1100 + if (ret == -ETIMEDOUT) { 1101 + dwc3_core_soft_reset(dwc); 1102 + ret = -EPROBE_DEFER; 1103 + } 1104 1104 goto err0; 1105 + } 1105 1106 dwc->ulpi_ready = true; 1106 1107 } 1107 1108
+1 -1
drivers/usb/dwc3/dwc3-pci.c
··· 45 45 #define PCI_DEVICE_ID_INTEL_ADLN 0x465e 46 46 #define PCI_DEVICE_ID_INTEL_ADLN_PCH 0x54ee 47 47 #define PCI_DEVICE_ID_INTEL_ADLS 0x7ae1 48 - #define PCI_DEVICE_ID_INTEL_RPL 0x460e 48 + #define PCI_DEVICE_ID_INTEL_RPL 0xa70e 49 49 #define PCI_DEVICE_ID_INTEL_RPLS 0x7a61 50 50 #define PCI_DEVICE_ID_INTEL_MTLP 0x7ec1 51 51 #define PCI_DEVICE_ID_INTEL_MTL 0x7e7e
+10 -3
drivers/usb/dwc3/dwc3-qcom.c
··· 261 261 if (IS_ERR(qcom->icc_path_apps)) { 262 262 dev_err(dev, "failed to get apps-usb path: %ld\n", 263 263 PTR_ERR(qcom->icc_path_apps)); 264 - return PTR_ERR(qcom->icc_path_apps); 264 + ret = PTR_ERR(qcom->icc_path_apps); 265 + goto put_path_ddr; 265 266 } 266 267 267 268 max_speed = usb_get_maximum_speed(&qcom->dwc3->dev); ··· 275 274 } 276 275 if (ret) { 277 276 dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret); 278 - return ret; 277 + goto put_path_apps; 279 278 } 280 279 281 280 ret = icc_set_bw(qcom->icc_path_apps, APPS_USB_AVG_BW, APPS_USB_PEAK_BW); 282 281 if (ret) { 283 282 dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret); 284 - return ret; 283 + goto put_path_apps; 285 284 } 286 285 287 286 return 0; 287 + 288 + put_path_apps: 289 + icc_put(qcom->icc_path_apps); 290 + put_path_ddr: 291 + icc_put(qcom->icc_path_ddr); 292 + return ret; 288 293 } 289 294 290 295 /**
+12 -2
drivers/usb/dwc3/gadget.c
··· 1464 1464 */ 1465 1465 if (num_trbs_left == 1 || (needs_extra_trb && 1466 1466 num_trbs_left <= 2 && 1467 - sg_dma_len(sg_next(s)) >= length)) 1468 - must_interrupt = true; 1467 + sg_dma_len(sg_next(s)) >= length)) { 1468 + struct dwc3_request *r; 1469 + 1470 + /* Check if previous requests already set IOC */ 1471 + list_for_each_entry(r, &dep->started_list, list) { 1472 + if (r != req && !r->request.no_interrupt) 1473 + break; 1474 + 1475 + if (r == req) 1476 + must_interrupt = true; 1477 + } 1478 + } 1469 1479 1470 1480 dwc3_prepare_one_trb(dep, req, trb_length, 1, i, false, 1471 1481 must_interrupt);
+38
drivers/usb/fotg210/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + config USB_FOTG210 4 + tristate "Faraday FOTG210 USB2 Dual Role controller" 5 + depends on USB || USB_GADGET 6 + depends on HAS_DMA && HAS_IOMEM 7 + depends on ARCH_GEMINI || COMPILE_TEST 8 + default ARCH_GEMINI 9 + select MFD_SYSCON 10 + help 11 + Faraday FOTG210 is a dual-mode USB controller that can act 12 + in both host controller and peripheral controller mode. 13 + 14 + if USB_FOTG210 15 + 16 + config USB_FOTG210_HCD 17 + bool "Faraday FOTG210 USB Host Controller support" 18 + depends on USB=y || USB=USB_FOTG210 19 + help 20 + Faraday FOTG210 is an OTG controller which can be configured as 21 + an USB2.0 host. It is designed to meet USB2.0 EHCI specification 22 + with minor modification. 23 + 24 + To compile this driver as a module, choose M here: the 25 + module will be called fotg210-hcd. 26 + 27 + config USB_FOTG210_UDC 28 + depends on USB_GADGET=y || USB_GADGET=USB_FOTG210 29 + bool "Faraday FOTG210 USB Peripheral Controller support" 30 + help 31 + Faraday USB2.0 OTG controller which can be configured as 32 + high speed or full speed USB device. This driver suppports 33 + Bulk Transfer so far. 34 + 35 + Say "y" to link the driver statically, or "m" to build a 36 + dynamically linked module called "fotg210-udc". 37 + 38 + endif
+10
drivers/usb/fotg210/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + # This setup links the different object files into one single 4 + # module so we don't have to EXPORT() a lot of internal symbols 5 + # or create unnecessary submodules. 6 + fotg210-objs-y += fotg210-core.o 7 + fotg210-objs-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o 8 + fotg210-objs-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o 9 + fotg210-objs := $(fotg210-objs-y) 10 + obj-$(CONFIG_USB_FOTG210) += fotg210.o
+166
drivers/usb/fotg210/fotg210-core.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Central probing code for the FOTG210 dual role driver 4 + * We register one driver for the hardware and then we decide 5 + * whether to proceed with probing the host or the peripheral 6 + * driver. 7 + */ 8 + #include <linux/bitops.h> 9 + #include <linux/device.h> 10 + #include <linux/mfd/syscon.h> 11 + #include <linux/module.h> 12 + #include <linux/of.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/regmap.h> 15 + #include <linux/usb.h> 16 + #include <linux/usb/otg.h> 17 + 18 + #include "fotg210.h" 19 + 20 + /* 21 + * Gemini-specific initialization function, only executed on the 22 + * Gemini SoC using the global misc control register. 23 + * 24 + * The gemini USB blocks are connected to either Mini-A (host mode) or 25 + * Mini-B (peripheral mode) plugs. There is no role switch support on the 26 + * Gemini SoC, just either-or. 27 + */ 28 + #define GEMINI_GLOBAL_MISC_CTRL 0x30 29 + #define GEMINI_MISC_USB0_WAKEUP BIT(14) 30 + #define GEMINI_MISC_USB1_WAKEUP BIT(15) 31 + #define GEMINI_MISC_USB0_VBUS_ON BIT(22) 32 + #define GEMINI_MISC_USB1_VBUS_ON BIT(23) 33 + #define GEMINI_MISC_USB0_MINI_B BIT(29) 34 + #define GEMINI_MISC_USB1_MINI_B BIT(30) 35 + 36 + static int fotg210_gemini_init(struct device *dev, struct resource *res, 37 + enum usb_dr_mode mode) 38 + { 39 + struct device_node *np = dev->of_node; 40 + struct regmap *map; 41 + bool wakeup; 42 + u32 mask, val; 43 + int ret; 44 + 45 + map = syscon_regmap_lookup_by_phandle(np, "syscon"); 46 + if (IS_ERR(map)) { 47 + dev_err(dev, "no syscon\n"); 48 + return PTR_ERR(map); 49 + } 50 + wakeup = of_property_read_bool(np, "wakeup-source"); 51 + 52 + /* 53 + * Figure out if this is USB0 or USB1 by simply checking the 54 + * physical base address. 55 + */ 56 + mask = 0; 57 + if (res->start == 0x69000000) { 58 + mask = GEMINI_MISC_USB1_VBUS_ON | GEMINI_MISC_USB1_MINI_B | 59 + GEMINI_MISC_USB1_WAKEUP; 60 + if (mode == USB_DR_MODE_HOST) 61 + val = GEMINI_MISC_USB1_VBUS_ON; 62 + else 63 + val = GEMINI_MISC_USB1_MINI_B; 64 + if (wakeup) 65 + val |= GEMINI_MISC_USB1_WAKEUP; 66 + } else { 67 + mask = GEMINI_MISC_USB0_VBUS_ON | GEMINI_MISC_USB0_MINI_B | 68 + GEMINI_MISC_USB0_WAKEUP; 69 + if (mode == USB_DR_MODE_HOST) 70 + val = GEMINI_MISC_USB0_VBUS_ON; 71 + else 72 + val = GEMINI_MISC_USB0_MINI_B; 73 + if (wakeup) 74 + val |= GEMINI_MISC_USB0_WAKEUP; 75 + } 76 + 77 + ret = regmap_update_bits(map, GEMINI_GLOBAL_MISC_CTRL, mask, val); 78 + if (ret) { 79 + dev_err(dev, "failed to initialize Gemini PHY\n"); 80 + return ret; 81 + } 82 + 83 + dev_info(dev, "initialized Gemini PHY in %s mode\n", 84 + (mode == USB_DR_MODE_HOST) ? "host" : "gadget"); 85 + return 0; 86 + } 87 + 88 + static int fotg210_probe(struct platform_device *pdev) 89 + { 90 + struct device *dev = &pdev->dev; 91 + enum usb_dr_mode mode; 92 + int ret; 93 + 94 + mode = usb_get_dr_mode(dev); 95 + 96 + if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) { 97 + struct resource *res; 98 + 99 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 100 + ret = fotg210_gemini_init(dev, res, mode); 101 + if (ret) 102 + return ret; 103 + } 104 + 105 + if (mode == USB_DR_MODE_PERIPHERAL) 106 + ret = fotg210_udc_probe(pdev); 107 + else 108 + ret = fotg210_hcd_probe(pdev); 109 + 110 + return ret; 111 + } 112 + 113 + static int fotg210_remove(struct platform_device *pdev) 114 + { 115 + struct device *dev = &pdev->dev; 116 + enum usb_dr_mode mode; 117 + 118 + mode = usb_get_dr_mode(dev); 119 + 120 + if (mode == USB_DR_MODE_PERIPHERAL) 121 + fotg210_udc_remove(pdev); 122 + else 123 + fotg210_hcd_remove(pdev); 124 + 125 + return 0; 126 + } 127 + 128 + #ifdef CONFIG_OF 129 + static const struct of_device_id fotg210_of_match[] = { 130 + { .compatible = "faraday,fotg210" }, 131 + {}, 132 + }; 133 + MODULE_DEVICE_TABLE(of, fotg210_of_match); 134 + #endif 135 + 136 + static struct platform_driver fotg210_driver = { 137 + .driver = { 138 + .name = "fotg210", 139 + .of_match_table = of_match_ptr(fotg210_of_match), 140 + }, 141 + .probe = fotg210_probe, 142 + .remove = fotg210_remove, 143 + }; 144 + 145 + static int __init fotg210_init(void) 146 + { 147 + if (usb_disabled()) 148 + return -ENODEV; 149 + 150 + if (IS_ENABLED(CONFIG_USB_FOTG210_HCD)) 151 + fotg210_hcd_init(); 152 + return platform_driver_register(&fotg210_driver); 153 + } 154 + module_init(fotg210_init); 155 + 156 + static void __exit fotg210_cleanup(void) 157 + { 158 + platform_driver_unregister(&fotg210_driver); 159 + if (IS_ENABLED(CONFIG_USB_FOTG210_HCD)) 160 + fotg210_hcd_cleanup(); 161 + } 162 + module_exit(fotg210_cleanup); 163 + 164 + MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang"); 165 + MODULE_LICENSE("GPL"); 166 + MODULE_DESCRIPTION("FOTG210 Dual Role Controller Driver");
+42
drivers/usb/fotg210/fotg210.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __FOTG210_H 3 + #define __FOTG210_H 4 + 5 + #ifdef CONFIG_USB_FOTG210_HCD 6 + int fotg210_hcd_probe(struct platform_device *pdev); 7 + int fotg210_hcd_remove(struct platform_device *pdev); 8 + int fotg210_hcd_init(void); 9 + void fotg210_hcd_cleanup(void); 10 + #else 11 + static inline int fotg210_hcd_probe(struct platform_device *pdev) 12 + { 13 + return 0; 14 + } 15 + static inline int fotg210_hcd_remove(struct platform_device *pdev) 16 + { 17 + return 0; 18 + } 19 + static inline int fotg210_hcd_init(void) 20 + { 21 + return 0; 22 + } 23 + static inline void fotg210_hcd_cleanup(void) 24 + { 25 + } 26 + #endif 27 + 28 + #ifdef CONFIG_USB_FOTG210_UDC 29 + int fotg210_udc_probe(struct platform_device *pdev); 30 + int fotg210_udc_remove(struct platform_device *pdev); 31 + #else 32 + static inline int fotg210_udc_probe(struct platform_device *pdev) 33 + { 34 + return 0; 35 + } 36 + static inline int fotg210_udc_remove(struct platform_device *pdev) 37 + { 38 + return 0; 39 + } 40 + #endif 41 + 42 + #endif /* __FOTG210_H */
+2 -1
drivers/usb/gadget/configfs.c
··· 3 3 #include <linux/module.h> 4 4 #include <linux/slab.h> 5 5 #include <linux/device.h> 6 + #include <linux/kstrtox.h> 6 7 #include <linux/nls.h> 7 8 #include <linux/usb/composite.h> 8 9 #include <linux/usb/gadget_configfs.h> ··· 801 800 bool use; 802 801 803 802 mutex_lock(&gi->lock); 804 - ret = strtobool(page, &use); 803 + ret = kstrtobool(page, &use); 805 804 if (!ret) { 806 805 gi->use_os_desc = use; 807 806 ret = len;
+9 -13
drivers/usb/gadget/function/f_ecm.c
··· 685 685 struct usb_composite_dev *cdev = c->cdev; 686 686 struct f_ecm *ecm = func_to_ecm(f); 687 687 struct usb_string *us; 688 - int status; 688 + int status = 0; 689 689 struct usb_ep *ep; 690 690 691 691 struct f_ecm_opts *ecm_opts; ··· 695 695 696 696 ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst); 697 697 698 - /* 699 - * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 700 - * configurations are bound in sequence with list_for_each_entry, 701 - * in each configuration its functions are bound in sequence 702 - * with list_for_each_entry, so we assume no race condition 703 - * with regard to ecm_opts->bound access 704 - */ 698 + mutex_lock(&ecm_opts->lock); 699 + 700 + gether_set_gadget(ecm_opts->net, cdev->gadget); 701 + 705 702 if (!ecm_opts->bound) { 706 - mutex_lock(&ecm_opts->lock); 707 - gether_set_gadget(ecm_opts->net, cdev->gadget); 708 703 status = gether_register_netdev(ecm_opts->net); 709 - mutex_unlock(&ecm_opts->lock); 710 - if (status) 711 - return status; 712 704 ecm_opts->bound = true; 713 705 } 706 + 707 + mutex_unlock(&ecm_opts->lock); 708 + if (status) 709 + return status; 714 710 715 711 ecm_string_defs[1].s = ecm->ethaddr; 716 712
+33 -27
drivers/usb/gadget/function/f_hid.c
··· 71 71 wait_queue_head_t write_queue; 72 72 struct usb_request *req; 73 73 74 - int minor; 74 + struct device dev; 75 75 struct cdev cdev; 76 76 struct usb_function func; 77 77 ··· 82 82 static inline struct f_hidg *func_to_hidg(struct usb_function *f) 83 83 { 84 84 return container_of(f, struct f_hidg, func); 85 + } 86 + 87 + static void hidg_release(struct device *dev) 88 + { 89 + struct f_hidg *hidg = container_of(dev, struct f_hidg, dev); 90 + 91 + kfree(hidg->set_report_buf); 92 + kfree(hidg); 85 93 } 86 94 87 95 /*-------------------------------------------------------------------------*/ ··· 912 904 struct usb_ep *ep; 913 905 struct f_hidg *hidg = func_to_hidg(f); 914 906 struct usb_string *us; 915 - struct device *device; 916 907 int status; 917 - dev_t dev; 918 908 919 909 /* maybe allocate device-global string IDs, and patch descriptors */ 920 910 us = usb_gstrings_attach(c->cdev, ct_func_strings, ··· 1005 999 1006 1000 /* create char device */ 1007 1001 cdev_init(&hidg->cdev, &f_hidg_fops); 1008 - dev = MKDEV(major, hidg->minor); 1009 - status = cdev_add(&hidg->cdev, dev, 1); 1002 + status = cdev_device_add(&hidg->cdev, &hidg->dev); 1010 1003 if (status) 1011 1004 goto fail_free_descs; 1012 1005 1013 - device = device_create(hidg_class, NULL, dev, NULL, 1014 - "%s%d", "hidg", hidg->minor); 1015 - if (IS_ERR(device)) { 1016 - status = PTR_ERR(device); 1017 - goto del; 1018 - } 1019 - 1020 1006 return 0; 1021 - del: 1022 - cdev_del(&hidg->cdev); 1023 1007 fail_free_descs: 1024 1008 usb_free_all_descriptors(f); 1025 1009 fail: ··· 1240 1244 1241 1245 hidg = func_to_hidg(f); 1242 1246 opts = container_of(f->fi, struct f_hid_opts, func_inst); 1243 - kfree(hidg->report_desc); 1244 - kfree(hidg->set_report_buf); 1245 - kfree(hidg); 1247 + put_device(&hidg->dev); 1246 1248 mutex_lock(&opts->lock); 1247 1249 --opts->refcnt; 1248 1250 mutex_unlock(&opts->lock); ··· 1250 1256 { 1251 1257 struct f_hidg *hidg = func_to_hidg(f); 1252 1258 1253 - device_destroy(hidg_class, MKDEV(major, hidg->minor)); 1254 - cdev_del(&hidg->cdev); 1259 + cdev_device_del(&hidg->cdev, &hidg->dev); 1255 1260 1256 1261 usb_free_all_descriptors(f); 1257 1262 } ··· 1259 1266 { 1260 1267 struct f_hidg *hidg; 1261 1268 struct f_hid_opts *opts; 1269 + int ret; 1262 1270 1263 1271 /* allocate and initialize one new instance */ 1264 1272 hidg = kzalloc(sizeof(*hidg), GFP_KERNEL); ··· 1269 1275 opts = container_of(fi, struct f_hid_opts, func_inst); 1270 1276 1271 1277 mutex_lock(&opts->lock); 1272 - ++opts->refcnt; 1273 1278 1274 - hidg->minor = opts->minor; 1279 + device_initialize(&hidg->dev); 1280 + hidg->dev.release = hidg_release; 1281 + hidg->dev.class = hidg_class; 1282 + hidg->dev.devt = MKDEV(major, opts->minor); 1283 + ret = dev_set_name(&hidg->dev, "hidg%d", opts->minor); 1284 + if (ret) 1285 + goto err_unlock; 1286 + 1275 1287 hidg->bInterfaceSubClass = opts->subclass; 1276 1288 hidg->bInterfaceProtocol = opts->protocol; 1277 1289 hidg->report_length = opts->report_length; 1278 1290 hidg->report_desc_length = opts->report_desc_length; 1279 1291 if (opts->report_desc) { 1280 - hidg->report_desc = kmemdup(opts->report_desc, 1281 - opts->report_desc_length, 1282 - GFP_KERNEL); 1292 + hidg->report_desc = devm_kmemdup(&hidg->dev, opts->report_desc, 1293 + opts->report_desc_length, 1294 + GFP_KERNEL); 1283 1295 if (!hidg->report_desc) { 1284 - kfree(hidg); 1285 - mutex_unlock(&opts->lock); 1286 - return ERR_PTR(-ENOMEM); 1296 + ret = -ENOMEM; 1297 + goto err_put_device; 1287 1298 } 1288 1299 } 1289 1300 hidg->use_out_ep = !opts->no_out_endpoint; 1290 1301 1302 + ++opts->refcnt; 1291 1303 mutex_unlock(&opts->lock); 1292 1304 1293 1305 hidg->func.name = "hid"; ··· 1308 1308 hidg->qlen = 4; 1309 1309 1310 1310 return &hidg->func; 1311 + 1312 + err_put_device: 1313 + put_device(&hidg->dev); 1314 + err_unlock: 1315 + mutex_unlock(&opts->lock); 1316 + return ERR_PTR(ret); 1311 1317 } 1312 1318 1313 1319 DECLARE_USB_FUNCTION_INIT(hid, hidg_alloc_inst, hidg_alloc);
+2 -1
drivers/usb/gadget/function/f_mass_storage.c
··· 176 176 #include <linux/fcntl.h> 177 177 #include <linux/file.h> 178 178 #include <linux/fs.h> 179 + #include <linux/kstrtox.h> 179 180 #include <linux/kthread.h> 180 181 #include <linux/sched/signal.h> 181 182 #include <linux/limits.h> ··· 3388 3387 return -EBUSY; 3389 3388 } 3390 3389 3391 - ret = strtobool(page, &stall); 3390 + ret = kstrtobool(page, &stall); 3392 3391 if (!ret) { 3393 3392 opts->common->can_stall = stall; 3394 3393 ret = len;
+1 -8
drivers/usb/gadget/function/f_printer.c
··· 364 364 spin_unlock_irqrestore(&dev->lock, flags); 365 365 366 366 kref_get(&dev->kref); 367 - DBG(dev, "printer_open returned %x\n", ret); 367 + 368 368 return ret; 369 369 } 370 370 ··· 382 382 spin_unlock_irqrestore(&dev->lock, flags); 383 383 384 384 kref_put(&dev->kref, printer_dev_free); 385 - DBG(dev, "printer_close\n"); 386 385 387 386 return 0; 388 387 } ··· 847 848 if (dev->interface < 0) 848 849 return; 849 850 850 - DBG(dev, "%s\n", __func__); 851 - 852 851 if (dev->in_ep->desc) 853 852 usb_ep_disable(dev->in_ep); 854 853 ··· 883 886 static void printer_soft_reset(struct printer_dev *dev) 884 887 { 885 888 struct usb_request *req; 886 - 887 - INFO(dev, "Received Printer Reset Request\n"); 888 889 889 890 if (usb_ep_disable(dev->in_ep)) 890 891 DBG(dev, "Failed to disable USB in_ep\n"); ··· 1179 1184 static void printer_func_disable(struct usb_function *f) 1180 1185 { 1181 1186 struct printer_dev *dev = func_to_printer(f); 1182 - 1183 - DBG(dev, "%s\n", __func__); 1184 1187 1185 1188 printer_reset_interface(dev); 1186 1189 }
+15 -5
drivers/usb/gadget/function/f_uvc.c
··· 39 39 40 40 /* string IDs are assigned dynamically */ 41 41 42 - #define UVC_STRING_CONTROL_IDX 0 43 - #define UVC_STRING_STREAMING_IDX 1 44 - 45 42 static struct usb_string uvc_en_us_strings[] = { 46 43 /* [UVC_STRING_CONTROL_IDX].s = DYNAMIC, */ 47 44 [UVC_STRING_STREAMING_IDX].s = "Video Streaming", ··· 213 216 214 217 memset(&v4l2_event, 0, sizeof(v4l2_event)); 215 218 v4l2_event.type = UVC_EVENT_DATA; 216 - uvc_event->data.length = req->actual; 217 - memcpy(&uvc_event->data.data, req->buf, req->actual); 219 + uvc_event->data.length = min_t(unsigned int, req->actual, 220 + sizeof(uvc_event->data.data)); 221 + memcpy(&uvc_event->data.data, req->buf, uvc_event->data.length); 218 222 v4l2_event_queue(&uvc->vdev, &v4l2_event); 219 223 } 220 224 } ··· 226 228 struct uvc_device *uvc = to_uvc(f); 227 229 struct v4l2_event v4l2_event; 228 230 struct uvc_event *uvc_event = (void *)&v4l2_event.u.data; 231 + unsigned int interface = le16_to_cpu(ctrl->wIndex) & 0xff; 232 + struct usb_ctrlrequest *mctrl; 229 233 230 234 if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) { 231 235 uvcg_info(f, "invalid request type\n"); ··· 248 248 memset(&v4l2_event, 0, sizeof(v4l2_event)); 249 249 v4l2_event.type = UVC_EVENT_SETUP; 250 250 memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req)); 251 + 252 + /* check for the interface number, fixup the interface number in 253 + * the ctrl request so the userspace doesn't have to bother with 254 + * offset and configfs parsing 255 + */ 256 + mctrl = &uvc_event->req; 257 + mctrl->wIndex &= ~cpu_to_le16(0xff); 258 + if (interface == uvc->streaming_intf) 259 + mctrl->wIndex = cpu_to_le16(UVC_STRING_STREAMING_IDX); 260 + 251 261 v4l2_event_queue(&uvc->vdev, &v4l2_event); 252 262 253 263 return 0;
+5 -4
drivers/usb/gadget/function/storage_common.c
··· 23 23 #include <linux/blkdev.h> 24 24 #include <linux/file.h> 25 25 #include <linux/fs.h> 26 + #include <linux/kstrtox.h> 26 27 #include <linux/usb/composite.h> 27 28 28 29 #include "storage_common.h" ··· 397 396 ssize_t rc; 398 397 bool ro; 399 398 400 - rc = strtobool(buf, &ro); 399 + rc = kstrtobool(buf, &ro); 401 400 if (rc) 402 401 return rc; 403 402 ··· 420 419 bool nofua; 421 420 int ret; 422 421 423 - ret = strtobool(buf, &nofua); 422 + ret = kstrtobool(buf, &nofua); 424 423 if (ret) 425 424 return ret; 426 425 ··· 471 470 bool cdrom; 472 471 int ret; 473 472 474 - ret = strtobool(buf, &cdrom); 473 + ret = kstrtobool(buf, &cdrom); 475 474 if (ret) 476 475 return ret; 477 476 ··· 494 493 bool removable; 495 494 int ret; 496 495 497 - ret = strtobool(buf, &removable); 496 + ret = kstrtobool(buf, &removable); 498 497 if (ret) 499 498 return ret; 500 499
-4
drivers/usb/gadget/function/u_ether.c
··· 798 798 net->max_mtu = GETHER_MAX_MTU_SIZE; 799 799 800 800 dev->gadget = g; 801 - SET_NETDEV_DEV(net, &g->dev); 802 801 SET_NETDEV_DEVTYPE(net, &gadget_type); 803 802 804 803 status = register_netdev(net); ··· 872 873 struct usb_gadget *g; 873 874 int status; 874 875 875 - if (!net->dev.parent) 876 - return -EINVAL; 877 876 dev = netdev_priv(net); 878 877 g = dev->gadget; 879 878 ··· 902 905 903 906 dev = netdev_priv(net); 904 907 dev->gadget = g; 905 - SET_NETDEV_DEV(net, &g->dev); 906 908 } 907 909 EXPORT_SYMBOL_GPL(gether_set_gadget); 908 910
+2 -1
drivers/usb/gadget/function/u_serial.c
··· 24 24 #include <linux/export.h> 25 25 #include <linux/module.h> 26 26 #include <linux/console.h> 27 + #include <linux/kstrtox.h> 27 28 #include <linux/kthread.h> 28 29 #include <linux/workqueue.h> 29 30 #include <linux/kfifo.h> ··· 1071 1070 bool enable; 1072 1071 int ret; 1073 1072 1074 - ret = strtobool(page, &enable); 1073 + ret = kstrtobool(page, &enable); 1075 1074 if (ret) 1076 1075 return ret; 1077 1076
+6 -6
drivers/usb/gadget/function/uvc_configfs.c
··· 1512 1512 UVCG_UNCOMPRESSED_ATTR(b_default_frame_index, bDefaultFrameIndex, 8); 1513 1513 UVCG_UNCOMPRESSED_ATTR_RO(b_aspect_ratio_x, bAspectRatioX, 8); 1514 1514 UVCG_UNCOMPRESSED_ATTR_RO(b_aspect_ratio_y, bAspectRatioY, 8); 1515 - UVCG_UNCOMPRESSED_ATTR_RO(bm_interface_flags, bmInterfaceFlags, 8); 1515 + UVCG_UNCOMPRESSED_ATTR_RO(bm_interlace_flags, bmInterlaceFlags, 8); 1516 1516 1517 1517 #undef UVCG_UNCOMPRESSED_ATTR 1518 1518 #undef UVCG_UNCOMPRESSED_ATTR_RO ··· 1541 1541 &uvcg_uncompressed_attr_b_default_frame_index, 1542 1542 &uvcg_uncompressed_attr_b_aspect_ratio_x, 1543 1543 &uvcg_uncompressed_attr_b_aspect_ratio_y, 1544 - &uvcg_uncompressed_attr_bm_interface_flags, 1544 + &uvcg_uncompressed_attr_bm_interlace_flags, 1545 1545 &uvcg_uncompressed_attr_bma_controls, 1546 1546 NULL, 1547 1547 }; ··· 1574 1574 h->desc.bDefaultFrameIndex = 1; 1575 1575 h->desc.bAspectRatioX = 0; 1576 1576 h->desc.bAspectRatioY = 0; 1577 - h->desc.bmInterfaceFlags = 0; 1577 + h->desc.bmInterlaceFlags = 0; 1578 1578 h->desc.bCopyProtect = 0; 1579 1579 1580 1580 INIT_LIST_HEAD(&h->fmt.frames); ··· 1700 1700 UVCG_MJPEG_ATTR_RO(bm_flags, bmFlags, 8); 1701 1701 UVCG_MJPEG_ATTR_RO(b_aspect_ratio_x, bAspectRatioX, 8); 1702 1702 UVCG_MJPEG_ATTR_RO(b_aspect_ratio_y, bAspectRatioY, 8); 1703 - UVCG_MJPEG_ATTR_RO(bm_interface_flags, bmInterfaceFlags, 8); 1703 + UVCG_MJPEG_ATTR_RO(bm_interlace_flags, bmInterlaceFlags, 8); 1704 1704 1705 1705 #undef UVCG_MJPEG_ATTR 1706 1706 #undef UVCG_MJPEG_ATTR_RO ··· 1728 1728 &uvcg_mjpeg_attr_bm_flags, 1729 1729 &uvcg_mjpeg_attr_b_aspect_ratio_x, 1730 1730 &uvcg_mjpeg_attr_b_aspect_ratio_y, 1731 - &uvcg_mjpeg_attr_bm_interface_flags, 1731 + &uvcg_mjpeg_attr_bm_interlace_flags, 1732 1732 &uvcg_mjpeg_attr_bma_controls, 1733 1733 NULL, 1734 1734 }; ··· 1755 1755 h->desc.bDefaultFrameIndex = 1; 1756 1756 h->desc.bAspectRatioX = 0; 1757 1757 h->desc.bAspectRatioY = 0; 1758 - h->desc.bmInterfaceFlags = 0; 1758 + h->desc.bmInterlaceFlags = 0; 1759 1759 h->desc.bCopyProtect = 0; 1760 1760 1761 1761 INIT_LIST_HEAD(&h->fmt.frames);
+2 -1
drivers/usb/gadget/legacy/serial.c
··· 9 9 10 10 #include <linux/kernel.h> 11 11 #include <linux/device.h> 12 + #include <linux/kstrtox.h> 12 13 #include <linux/module.h> 13 14 #include <linux/tty.h> 14 15 #include <linux/tty_flip.h> ··· 110 109 if (!s) /* called for no-arg enable == default */ 111 110 return 0; 112 111 113 - ret = strtobool(s, &do_enable); 112 + ret = kstrtobool(s, &do_enable); 114 113 if (ret || enable == do_enable) 115 114 return ret; 116 115
+2 -2
drivers/usb/gadget/legacy/webcam.c
··· 171 171 .bDefaultFrameIndex = 1, 172 172 .bAspectRatioX = 0, 173 173 .bAspectRatioY = 0, 174 - .bmInterfaceFlags = 0, 174 + .bmInterlaceFlags = 0, 175 175 .bCopyProtect = 0, 176 176 }; 177 177 ··· 222 222 .bDefaultFrameIndex = 1, 223 223 .bAspectRatioX = 0, 224 224 .bAspectRatioY = 0, 225 - .bmInterfaceFlags = 0, 225 + .bmInterlaceFlags = 0, 226 226 .bCopyProtect = 0, 227 227 }; 228 228
+2 -13
drivers/usb/gadget/udc/Kconfig
··· 33 33 config USB_AT91 34 34 tristate "Atmel AT91 USB Device Port" 35 35 depends on ARCH_AT91 36 - depends on OF || COMPILE_TEST 36 + depends on OF 37 37 help 38 38 Many Atmel AT91 processors (such as the AT91RM2000) have a 39 39 full speed USB Device Port with support for five configurable ··· 107 107 depends on !PHYS_ADDR_T_64BIT && HAS_DMA 108 108 help 109 109 Faraday usb device controller FUSB300 driver 110 - 111 - config USB_FOTG210_UDC 112 - depends on HAS_DMA 113 - tristate "Faraday FOTG210 USB Peripheral Controller" 114 - help 115 - Faraday USB2.0 OTG controller which can be configured as 116 - high speed or full speed USB device. This driver supppors 117 - Bulk Transfer so far. 118 - 119 - Say "y" to link the driver statically, or "m" to build a 120 - dynamically linked module called "fotg210_udc". 121 110 122 111 config USB_GR_UDC 123 112 tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver" ··· 419 430 config USB_GADGET_XILINX 420 431 tristate "Xilinx USB Driver" 421 432 depends on HAS_DMA 422 - depends on OF || COMPILE_TEST 433 + depends on OF 423 434 help 424 435 USB peripheral controller driver for Xilinx USB2 device. 425 436 Xilinx USB2 device is a soft IP which supports both full
-1
drivers/usb/gadget/udc/Makefile
··· 34 34 obj-$(CONFIG_USB_MV_UDC) += mv_udc.o 35 35 mv_udc-y := mv_udc_core.o 36 36 obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o 37 - obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o 38 37 obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o 39 38 obj-$(CONFIG_USB_GR_UDC) += gr_udc.o 40 39 obj-$(CONFIG_USB_GADGET_XILINX) += udc-xilinx.o
+1 -1
drivers/usb/gadget/udc/aspeed-vhub/core.c
··· 37 37 38 38 list_del_init(&req->queue); 39 39 40 - if (req->req.status == -EINPROGRESS) 40 + if ((req->req.status == -EINPROGRESS) || (status == -EOVERFLOW)) 41 41 req->req.status = status; 42 42 43 43 if (req->req.dma) {
+12 -4
drivers/usb/gadget/udc/aspeed-vhub/epn.c
··· 84 84 { 85 85 struct ast_vhub_req *req; 86 86 unsigned int len; 87 + int status = 0; 87 88 u32 stat; 88 89 89 90 /* Read EP status */ ··· 120 119 len = VHUB_EP_DMA_TX_SIZE(stat); 121 120 122 121 /* If not using DMA, copy data out if needed */ 123 - if (!req->req.dma && !ep->epn.is_in && len) 124 - memcpy(req->req.buf + req->req.actual, ep->buf, len); 125 - 122 + if (!req->req.dma && !ep->epn.is_in && len) { 123 + if (req->req.actual + len > req->req.length) { 124 + req->last_desc = 1; 125 + status = -EOVERFLOW; 126 + goto done; 127 + } else { 128 + memcpy(req->req.buf + req->req.actual, ep->buf, len); 129 + } 130 + } 126 131 /* Adjust size */ 127 132 req->req.actual += len; 128 133 ··· 136 129 if (len < ep->ep.maxpacket) 137 130 req->last_desc = 1; 138 131 132 + done: 139 133 /* That's it ? complete the request and pick a new one */ 140 134 if (req->last_desc >= 0) { 141 - ast_vhub_done(ep, req, 0); 135 + ast_vhub_done(ep, req, status); 142 136 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, 143 137 queue); 144 138
+1 -4
drivers/usb/gadget/udc/at91_udc.c
··· 1628 1628 1629 1629 static void at91rm9200_udc_pullup(struct at91_udc *udc, int is_on) 1630 1630 { 1631 - if (is_on) 1632 - gpiod_set_value(udc->board.pullup_pin, 1); 1633 - else 1634 - gpiod_set_value(udc->board.pullup_pin, 0); 1631 + gpiod_set_value(udc->board.pullup_pin, is_on); 1635 1632 } 1636 1633 1637 1634 static const struct at91_udc_caps at91rm9200_udc_caps = {
+6 -6
drivers/usb/gadget/udc/core.c
··· 734 734 } 735 735 736 736 ret = gadget->ops->pullup(gadget, 0); 737 - if (!ret) { 737 + if (!ret) 738 738 gadget->connected = 0; 739 - mutex_lock(&udc_lock); 740 - if (gadget->udc->driver) 741 - gadget->udc->driver->disconnect(gadget); 742 - mutex_unlock(&udc_lock); 743 - } 739 + 740 + mutex_lock(&udc_lock); 741 + if (gadget->udc->driver) 742 + gadget->udc->driver->disconnect(gadget); 743 + mutex_unlock(&udc_lock); 744 744 745 745 out: 746 746 trace_usb_gadget_disconnect(gadget, ret);
+123 -41
drivers/usb/gadget/udc/fotg210-udc.c drivers/usb/fotg210/fotg210-udc.c
··· 15 15 #include <linux/platform_device.h> 16 16 #include <linux/usb/ch9.h> 17 17 #include <linux/usb/gadget.h> 18 + #include <linux/clk.h> 19 + #include <linux/usb/otg.h> 20 + #include <linux/usb/phy.h> 18 21 19 22 #include "fotg210.h" 23 + #include "fotg210-udc.h" 20 24 21 25 #define DRIVER_DESC "FOTG210 USB Device Controller Driver" 22 26 #define DRIVER_VERSION "30-April-2013" ··· 633 629 static void fotg210_set_address(struct fotg210_udc *fotg210, 634 630 struct usb_ctrlrequest *ctrl) 635 631 { 636 - if (ctrl->wValue >= 0x0100) { 632 + if (le16_to_cpu(ctrl->wValue) >= 0x0100) { 637 633 fotg210_request_error(fotg210); 638 634 } else { 639 - fotg210_set_dev_addr(fotg210, ctrl->wValue); 635 + fotg210_set_dev_addr(fotg210, le16_to_cpu(ctrl->wValue)); 640 636 fotg210_set_cxdone(fotg210); 641 637 } 642 638 } ··· 717 713 718 714 switch (ctrl->bRequestType & USB_RECIP_MASK) { 719 715 case USB_RECIP_DEVICE: 720 - fotg210->ep0_data = 1 << USB_DEVICE_SELF_POWERED; 716 + fotg210->ep0_data = cpu_to_le16(1 << USB_DEVICE_SELF_POWERED); 721 717 break; 722 718 case USB_RECIP_INTERFACE: 723 - fotg210->ep0_data = 0; 719 + fotg210->ep0_data = cpu_to_le16(0); 724 720 break; 725 721 case USB_RECIP_ENDPOINT: 726 722 epnum = ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK; 727 723 if (epnum) 728 724 fotg210->ep0_data = 729 - fotg210_is_epnstall(fotg210->ep[epnum]) 730 - << USB_ENDPOINT_HALT; 725 + cpu_to_le16(fotg210_is_epnstall(fotg210->ep[epnum]) 726 + << USB_ENDPOINT_HALT); 731 727 else 732 728 fotg210_request_error(fotg210); 733 729 break; ··· 1011 1007 { 1012 1008 struct fotg210_udc *fotg210 = gadget_to_fotg210(g); 1013 1009 u32 value; 1010 + int ret; 1014 1011 1015 1012 /* hook up the driver */ 1016 1013 driver->driver.bus = NULL; 1017 1014 fotg210->driver = driver; 1015 + 1016 + if (!IS_ERR_OR_NULL(fotg210->phy)) { 1017 + ret = otg_set_peripheral(fotg210->phy->otg, 1018 + &fotg210->gadget); 1019 + if (ret) 1020 + dev_err(fotg210->dev, "can't bind to phy\n"); 1021 + } 1018 1022 1019 1023 /* enable device global interrupt */ 1020 1024 value = ioread32(fotg210->reg + FOTG210_DMCR); ··· 1065 1053 struct fotg210_udc *fotg210 = gadget_to_fotg210(g); 1066 1054 unsigned long flags; 1067 1055 1056 + if (!IS_ERR_OR_NULL(fotg210->phy)) 1057 + return otg_set_peripheral(fotg210->phy->otg, NULL); 1058 + 1068 1059 spin_lock_irqsave(&fotg210->lock, flags); 1069 1060 1070 1061 fotg210_init(fotg210); ··· 1083 1068 .udc_stop = fotg210_udc_stop, 1084 1069 }; 1085 1070 1086 - static int fotg210_udc_remove(struct platform_device *pdev) 1071 + /** 1072 + * fotg210_phy_event - Called by phy upon VBus event 1073 + * @nb: notifier block 1074 + * @action: phy action, is vbus connect or disconnect 1075 + * @data: the usb_gadget structure in fotg210 1076 + * 1077 + * Called by the USB Phy when a cable connect or disconnect is sensed. 1078 + * 1079 + * Returns NOTIFY_OK or NOTIFY_DONE 1080 + */ 1081 + static int fotg210_phy_event(struct notifier_block *nb, unsigned long action, 1082 + void *data) 1083 + { 1084 + struct usb_gadget *gadget = data; 1085 + 1086 + if (!gadget) 1087 + return NOTIFY_DONE; 1088 + 1089 + switch (action) { 1090 + case USB_EVENT_VBUS: 1091 + usb_gadget_vbus_connect(gadget); 1092 + return NOTIFY_OK; 1093 + case USB_EVENT_NONE: 1094 + usb_gadget_vbus_disconnect(gadget); 1095 + return NOTIFY_OK; 1096 + default: 1097 + return NOTIFY_DONE; 1098 + } 1099 + } 1100 + 1101 + static struct notifier_block fotg210_phy_notifier = { 1102 + .notifier_call = fotg210_phy_event, 1103 + }; 1104 + 1105 + int fotg210_udc_remove(struct platform_device *pdev) 1087 1106 { 1088 1107 struct fotg210_udc *fotg210 = platform_get_drvdata(pdev); 1089 1108 int i; 1090 1109 1091 1110 usb_del_gadget_udc(&fotg210->gadget); 1111 + if (!IS_ERR_OR_NULL(fotg210->phy)) { 1112 + usb_unregister_notifier(fotg210->phy, &fotg210_phy_notifier); 1113 + usb_put_phy(fotg210->phy); 1114 + } 1092 1115 iounmap(fotg210->reg); 1093 1116 free_irq(platform_get_irq(pdev, 0), fotg210); 1094 1117 1095 1118 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req); 1096 1119 for (i = 0; i < FOTG210_MAX_NUM_EP; i++) 1097 1120 kfree(fotg210->ep[i]); 1121 + 1122 + if (!IS_ERR(fotg210->pclk)) 1123 + clk_disable_unprepare(fotg210->pclk); 1124 + 1098 1125 kfree(fotg210); 1099 1126 1100 1127 return 0; 1101 1128 } 1102 1129 1103 - static int fotg210_udc_probe(struct platform_device *pdev) 1130 + int fotg210_udc_probe(struct platform_device *pdev) 1104 1131 { 1105 - struct resource *res, *ires; 1132 + struct resource *res; 1106 1133 struct fotg210_udc *fotg210 = NULL; 1107 - struct fotg210_ep *_ep[FOTG210_MAX_NUM_EP]; 1134 + struct device *dev = &pdev->dev; 1135 + int irq; 1108 1136 int ret = 0; 1109 1137 int i; 1110 1138 ··· 1157 1099 return -ENODEV; 1158 1100 } 1159 1101 1160 - ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1161 - if (!ires) { 1162 - pr_err("platform_get_resource IORESOURCE_IRQ error.\n"); 1102 + irq = platform_get_irq(pdev, 0); 1103 + if (irq < 0) { 1104 + pr_err("could not get irq\n"); 1163 1105 return -ENODEV; 1164 1106 } 1165 - 1166 - ret = -ENOMEM; 1167 1107 1168 1108 /* initialize udc */ 1169 1109 fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL); 1170 1110 if (fotg210 == NULL) 1111 + return -ENOMEM; 1112 + 1113 + fotg210->dev = dev; 1114 + 1115 + /* It's OK not to supply this clock */ 1116 + fotg210->pclk = devm_clk_get(dev, "PCLK"); 1117 + if (!IS_ERR(fotg210->pclk)) { 1118 + ret = clk_prepare_enable(fotg210->pclk); 1119 + if (ret) { 1120 + dev_err(dev, "failed to enable PCLK\n"); 1121 + goto err; 1122 + } 1123 + } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) { 1124 + /* 1125 + * Percolate deferrals, for anything else, 1126 + * just live without the clocking. 1127 + */ 1128 + ret = -EPROBE_DEFER; 1171 1129 goto err; 1130 + } 1131 + 1132 + fotg210->phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); 1133 + if (IS_ERR(fotg210->phy)) { 1134 + ret = PTR_ERR(fotg210->phy); 1135 + if (ret == -EPROBE_DEFER) 1136 + goto err_pclk; 1137 + dev_info(dev, "no PHY found\n"); 1138 + fotg210->phy = NULL; 1139 + } else { 1140 + ret = usb_phy_init(fotg210->phy); 1141 + if (ret) 1142 + goto err_pclk; 1143 + dev_info(dev, "found and initialized PHY\n"); 1144 + } 1172 1145 1173 1146 for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { 1174 - _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL); 1175 - if (_ep[i] == NULL) 1147 + fotg210->ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL); 1148 + if (!fotg210->ep[i]) 1176 1149 goto err_alloc; 1177 - fotg210->ep[i] = _ep[i]; 1178 1150 } 1179 1151 1180 1152 fotg210->reg = ioremap(res->start, resource_size(res)); 1181 1153 if (fotg210->reg == NULL) { 1182 - pr_err("ioremap error.\n"); 1154 + dev_err(dev, "ioremap error\n"); 1183 1155 goto err_alloc; 1184 1156 } 1185 1157 ··· 1220 1132 fotg210->gadget.ops = &fotg210_gadget_ops; 1221 1133 1222 1134 fotg210->gadget.max_speed = USB_SPEED_HIGH; 1223 - fotg210->gadget.dev.parent = &pdev->dev; 1224 - fotg210->gadget.dev.dma_mask = pdev->dev.dma_mask; 1135 + fotg210->gadget.dev.parent = dev; 1136 + fotg210->gadget.dev.dma_mask = dev->dma_mask; 1225 1137 fotg210->gadget.name = udc_name; 1226 1138 1227 1139 INIT_LIST_HEAD(&fotg210->gadget.ep_list); ··· 1264 1176 1265 1177 fotg210_disable_unplug(fotg210); 1266 1178 1267 - ret = request_irq(ires->start, fotg210_irq, IRQF_SHARED, 1179 + ret = request_irq(irq, fotg210_irq, IRQF_SHARED, 1268 1180 udc_name, fotg210); 1269 1181 if (ret < 0) { 1270 - pr_err("request_irq error (%d)\n", ret); 1182 + dev_err(dev, "request_irq error (%d)\n", ret); 1271 1183 goto err_req; 1272 1184 } 1273 1185 1274 - ret = usb_add_gadget_udc(&pdev->dev, &fotg210->gadget); 1186 + if (!IS_ERR_OR_NULL(fotg210->phy)) 1187 + usb_register_notifier(fotg210->phy, &fotg210_phy_notifier); 1188 + 1189 + ret = usb_add_gadget_udc(dev, &fotg210->gadget); 1275 1190 if (ret) 1276 1191 goto err_add_udc; 1277 1192 1278 - dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1193 + dev_info(dev, "version %s\n", DRIVER_VERSION); 1279 1194 1280 1195 return 0; 1281 1196 1282 1197 err_add_udc: 1283 - free_irq(ires->start, fotg210); 1198 + if (!IS_ERR_OR_NULL(fotg210->phy)) 1199 + usb_unregister_notifier(fotg210->phy, &fotg210_phy_notifier); 1200 + free_irq(irq, fotg210); 1284 1201 1285 1202 err_req: 1286 1203 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req); ··· 1296 1203 err_alloc: 1297 1204 for (i = 0; i < FOTG210_MAX_NUM_EP; i++) 1298 1205 kfree(fotg210->ep[i]); 1299 - kfree(fotg210); 1206 + err_pclk: 1207 + if (!IS_ERR(fotg210->pclk)) 1208 + clk_disable_unprepare(fotg210->pclk); 1300 1209 1301 1210 err: 1211 + kfree(fotg210); 1302 1212 return ret; 1303 1213 } 1304 - 1305 - static struct platform_driver fotg210_driver = { 1306 - .driver = { 1307 - .name = udc_name, 1308 - }, 1309 - .probe = fotg210_udc_probe, 1310 - .remove = fotg210_udc_remove, 1311 - }; 1312 - 1313 - module_platform_driver(fotg210_driver); 1314 - 1315 - MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang <john453@faraday-tech.com>"); 1316 - MODULE_LICENSE("GPL"); 1317 - MODULE_DESCRIPTION(DRIVER_DESC);
+3
drivers/usb/gadget/udc/fotg210.h drivers/usb/fotg210/fotg210-udc.h
··· 231 231 struct fotg210_udc { 232 232 spinlock_t lock; /* protect the struct */ 233 233 void __iomem *reg; 234 + struct clk *pclk; 234 235 235 236 unsigned long irq_trigger; 236 237 238 + struct device *dev; 239 + struct usb_phy *phy; 237 240 struct usb_gadget gadget; 238 241 struct usb_gadget_driver *driver; 239 242
+1 -12
drivers/usb/host/Kconfig
··· 47 47 tristate "Support for additional Renesas xHCI controller with firmware" 48 48 help 49 49 Say 'Y' to enable the support for the Renesas xHCI controller with 50 - firmware. Make sure you have the firwmare for the device and 50 + firmware. Make sure you have the firmware for the device and 51 51 installed on your system for this device to work. 52 52 If unsure, say 'N'. 53 53 ··· 388 388 389 389 To compile this driver as a module, choose M here: the 390 390 module will be called isp1362-hcd. 391 - 392 - config USB_FOTG210_HCD 393 - tristate "FOTG210 HCD support" 394 - depends on USB && HAS_DMA && HAS_IOMEM 395 - help 396 - Faraday FOTG210 is an OTG controller which can be configured as 397 - an USB2.0 host. It is designed to meet USB2.0 EHCI specification 398 - with minor modification. 399 - 400 - To compile this driver as a module, choose M here: the 401 - module will be called fotg210-hcd. 402 391 403 392 config USB_MAX3421_HCD 404 393 tristate "MAX3421 HCD (USB-over-SPI) support"
-1
drivers/usb/host/Makefile
··· 84 84 obj-$(CONFIG_USB_EHCI_MV) += ehci-mv.o 85 85 obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o 86 86 obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o 87 - obj-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o 88 87 obj-$(CONFIG_USB_MAX3421_HCD) += max3421-hcd.o 89 88 obj-$(CONFIG_USB_XEN_HCD) += xen-hcd.o
+1 -1
drivers/usb/host/ehci-grlib.c
··· 99 99 hcd->rsrc_len = resource_size(&res); 100 100 101 101 irq = irq_of_parse_and_map(dn, 0); 102 - if (irq == NO_IRQ) { 102 + if (!irq) { 103 103 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n", 104 104 __FILE__); 105 105 rv = -EBUSY;
+4 -3
drivers/usb/host/ehci-pci.c
··· 411 411 .remove = ehci_pci_remove, 412 412 .shutdown = usb_hcd_pci_shutdown, 413 413 414 - #ifdef CONFIG_PM 415 414 .driver = { 416 - .pm = &usb_hcd_pci_pm_ops 417 - }, 415 + #ifdef CONFIG_PM 416 + .pm = &usb_hcd_pci_pm_ops, 418 417 #endif 418 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 419 + }, 419 420 }; 420 421 421 422 static int __init ehci_pci_init(void)
+1 -1
drivers/usb/host/ehci-ppc-of.c
··· 119 119 hcd->rsrc_len = resource_size(&res); 120 120 121 121 irq = irq_of_parse_and_map(dn, 0); 122 - if (irq == NO_IRQ) { 122 + if (!irq) { 123 123 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n", 124 124 __FILE__); 125 125 rv = -EBUSY;
+1 -1
drivers/usb/host/ehci.h
··· 471 471 * acts like a qh would, if EHCI had them for ISO. 472 472 */ 473 473 struct ehci_iso_stream { 474 - /* first field matches ehci_hq, but is NULL */ 474 + /* first field matches ehci_qh, but is NULL */ 475 475 struct ehci_qh_hw *hw; 476 476 477 477 u8 bEndpointAddress;
+1 -1
drivers/usb/host/fhci-hcd.c
··· 676 676 677 677 /* USB Host interrupt. */ 678 678 usb_irq = irq_of_parse_and_map(node, 0); 679 - if (usb_irq == NO_IRQ) { 679 + if (!usb_irq) { 680 680 dev_err(dev, "could not get usb irq\n"); 681 681 ret = -EINVAL; 682 682 goto err_usb_irq;
+8 -43
drivers/usb/host/fotg210-hcd.c drivers/usb/fotg210/fotg210-hcd.c
··· 39 39 #include <asm/irq.h> 40 40 #include <asm/unaligned.h> 41 41 42 - #define DRIVER_AUTHOR "Yuan-Hsin Chen" 43 - #define DRIVER_DESC "FOTG210 Host Controller (EHCI) Driver" 42 + #include "fotg210.h" 43 + 44 44 static const char hcd_name[] = "fotg210_hcd"; 45 45 46 46 #undef FOTG210_URB_TRACE ··· 77 77 78 78 #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) 79 79 80 - #include "fotg210.h" 80 + #include "fotg210-hcd.h" 81 81 82 82 #define fotg210_dbg(fotg210, fmt, args...) \ 83 83 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args) ··· 5490 5490 * functions and in order to facilitate role switching we cannot 5491 5491 * give the fotg210 driver exclusive access to those. 5492 5492 */ 5493 - MODULE_DESCRIPTION(DRIVER_DESC); 5494 - MODULE_AUTHOR(DRIVER_AUTHOR); 5495 - MODULE_LICENSE("GPL"); 5496 5493 5497 5494 static const struct hc_driver fotg210_fotg210_hc_driver = { 5498 5495 .description = hcd_name, ··· 5557 5560 * then invokes the start() method for the HCD associated with it 5558 5561 * through the hotplug entry's driver_data. 5559 5562 */ 5560 - static int fotg210_hcd_probe(struct platform_device *pdev) 5563 + int fotg210_hcd_probe(struct platform_device *pdev) 5561 5564 { 5562 5565 struct device *dev = &pdev->dev; 5563 5566 struct usb_hcd *hcd; ··· 5649 5652 * @dev: USB Host Controller being removed 5650 5653 * 5651 5654 */ 5652 - static int fotg210_hcd_remove(struct platform_device *pdev) 5655 + int fotg210_hcd_remove(struct platform_device *pdev) 5653 5656 { 5654 5657 struct usb_hcd *hcd = platform_get_drvdata(pdev); 5655 5658 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); ··· 5665 5668 return 0; 5666 5669 } 5667 5670 5668 - #ifdef CONFIG_OF 5669 - static const struct of_device_id fotg210_of_match[] = { 5670 - { .compatible = "faraday,fotg210" }, 5671 - {}, 5672 - }; 5673 - MODULE_DEVICE_TABLE(of, fotg210_of_match); 5674 - #endif 5675 - 5676 - static struct platform_driver fotg210_hcd_driver = { 5677 - .driver = { 5678 - .name = "fotg210-hcd", 5679 - .of_match_table = of_match_ptr(fotg210_of_match), 5680 - }, 5681 - .probe = fotg210_hcd_probe, 5682 - .remove = fotg210_hcd_remove, 5683 - }; 5684 - 5685 - static int __init fotg210_hcd_init(void) 5671 + int __init fotg210_hcd_init(void) 5686 5672 { 5687 - int retval = 0; 5688 - 5689 5673 if (usb_disabled()) 5690 5674 return -ENODEV; 5691 5675 ··· 5682 5704 5683 5705 fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root); 5684 5706 5685 - retval = platform_driver_register(&fotg210_hcd_driver); 5686 - if (retval < 0) 5687 - goto clean; 5688 - return retval; 5689 - 5690 - clean: 5691 - debugfs_remove(fotg210_debug_root); 5692 - fotg210_debug_root = NULL; 5693 - 5694 - clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); 5695 - return retval; 5707 + return 0; 5696 5708 } 5697 - module_init(fotg210_hcd_init); 5698 5709 5699 - static void __exit fotg210_hcd_cleanup(void) 5710 + void __exit fotg210_hcd_cleanup(void) 5700 5711 { 5701 - platform_driver_unregister(&fotg210_hcd_driver); 5702 5712 debugfs_remove(fotg210_debug_root); 5703 5713 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded); 5704 5714 } 5705 - module_exit(fotg210_hcd_cleanup);
drivers/usb/host/fotg210.h drivers/usb/fotg210/fotg210-hcd.h
+1 -1
drivers/usb/host/ohci-ppc-of.c
··· 120 120 } 121 121 122 122 irq = irq_of_parse_and_map(dn, 0); 123 - if (irq == NO_IRQ) { 123 + if (!irq) { 124 124 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n", 125 125 __FILE__); 126 126 rv = -EBUSY;
+1 -1
drivers/usb/host/uhci-grlib.c
··· 116 116 hcd->rsrc_len = resource_size(&res); 117 117 118 118 irq = irq_of_parse_and_map(dn, 0); 119 - if (irq == NO_IRQ) { 119 + if (!irq) { 120 120 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); 121 121 rv = -EBUSY; 122 122 goto err_usb;
+18 -4
drivers/usb/host/xhci-hub.c
··· 426 426 */ 427 427 #define XHCI_PORT_RZ ((1<<2) | (1<<24) | (0xf<<28)) 428 428 429 - /* 429 + /** 430 + * xhci_port_state_to_neutral() - Clean up read portsc value back into writeable 431 + * @state: u32 port value read from portsc register to be cleanup up 432 + * 430 433 * Given a port state, this function returns a value that would result in the 431 434 * port being in the same state, if the value was written to the port status 432 435 * control register. 433 436 * Save Read Only (RO) bits and save read/write bits where 434 437 * writing a 0 clears the bit and writing a 1 sets the bit (RWS). 435 438 * For all other types (RW1S, RW1CS, RW, and RZ), writing a '0' has no effect. 439 + * 440 + * Return: u32 value that can be written back to portsc register without 441 + * changing port state. 436 442 */ 443 + 437 444 u32 xhci_port_state_to_neutral(u32 state) 438 445 { 439 446 /* Save read-only status and port state */ 440 447 return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS); 441 448 } 449 + EXPORT_SYMBOL_GPL(xhci_port_state_to_neutral); 442 450 443 - /* 444 - * find slot id based on port number. 445 - * @port: The one-based port number from one of the two split roothubs. 451 + /** 452 + * xhci_find_slot_id_by_port() - Find slot id of a usb device on a roothub port 453 + * @hcd: pointer to hcd of the roothub 454 + * @xhci: pointer to xhci structure 455 + * @port: one-based port number of the port in this roothub. 456 + * 457 + * Return: Slot id of the usb device connected to the root port, 0 if not found 446 458 */ 459 + 447 460 int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, 448 461 u16 port) 449 462 { ··· 478 465 479 466 return slot_id; 480 467 } 468 + EXPORT_SYMBOL_GPL(xhci_find_slot_id_by_port); 481 469 482 470 /* 483 471 * Stop device
+46 -27
drivers/usb/host/xhci-mtk.c
··· 485 485 const struct hc_driver *driver; 486 486 struct xhci_hcd *xhci; 487 487 struct resource *res; 488 + struct usb_hcd *usb3_hcd; 488 489 struct usb_hcd *hcd; 489 490 int ret = -ENODEV; 490 491 int wakeup_irq; ··· 594 593 595 594 xhci = hcd_to_xhci(hcd); 596 595 xhci->main_hcd = hcd; 596 + xhci->allow_single_roothub = 1; 597 597 598 598 /* 599 599 * imod_interval is the interrupt moderation value in nanoseconds. ··· 604 602 xhci->imod_interval = 5000; 605 603 device_property_read_u32(dev, "imod-interval-ns", &xhci->imod_interval); 606 604 607 - xhci->shared_hcd = usb_create_shared_hcd(driver, dev, 608 - dev_name(dev), hcd); 609 - if (!xhci->shared_hcd) { 610 - ret = -ENOMEM; 611 - goto disable_device_wakeup; 612 - } 613 - 614 605 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 615 606 if (ret) 616 - goto put_usb3_hcd; 607 + goto disable_device_wakeup; 617 608 618 - if (HCC_MAX_PSA(xhci->hcc_params) >= 4 && 609 + if (!xhci_has_one_roothub(xhci)) { 610 + xhci->shared_hcd = usb_create_shared_hcd(driver, dev, 611 + dev_name(dev), hcd); 612 + if (!xhci->shared_hcd) { 613 + ret = -ENOMEM; 614 + goto dealloc_usb2_hcd; 615 + } 616 + } 617 + 618 + usb3_hcd = xhci_get_usb3_hcd(xhci); 619 + if (usb3_hcd && HCC_MAX_PSA(xhci->hcc_params) >= 4 && 619 620 !(xhci->quirks & XHCI_BROKEN_STREAMS)) 620 - xhci->shared_hcd->can_do_streams = 1; 621 + usb3_hcd->can_do_streams = 1; 621 622 622 - ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); 623 - if (ret) 624 - goto dealloc_usb2_hcd; 623 + if (xhci->shared_hcd) { 624 + ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); 625 + if (ret) 626 + goto put_usb3_hcd; 627 + } 625 628 626 629 if (wakeup_irq > 0) { 627 630 ret = dev_pm_set_dedicated_wake_irq_reverse(dev, wakeup_irq); ··· 646 639 647 640 dealloc_usb3_hcd: 648 641 usb_remove_hcd(xhci->shared_hcd); 649 - xhci->shared_hcd = NULL; 650 - 651 - dealloc_usb2_hcd: 652 - usb_remove_hcd(hcd); 653 642 654 643 put_usb3_hcd: 655 - xhci_mtk_sch_exit(mtk); 656 644 usb_put_hcd(xhci->shared_hcd); 645 + 646 + dealloc_usb2_hcd: 647 + xhci_mtk_sch_exit(mtk); 648 + usb_remove_hcd(hcd); 657 649 658 650 disable_device_wakeup: 659 651 device_init_wakeup(dev, false); ··· 685 679 dev_pm_clear_wake_irq(dev); 686 680 device_init_wakeup(dev, false); 687 681 688 - usb_remove_hcd(shared_hcd); 689 - xhci->shared_hcd = NULL; 682 + if (shared_hcd) { 683 + usb_remove_hcd(shared_hcd); 684 + xhci->shared_hcd = NULL; 685 + } 690 686 usb_remove_hcd(hcd); 691 - usb_put_hcd(shared_hcd); 687 + 688 + if (shared_hcd) 689 + usb_put_hcd(shared_hcd); 690 + 692 691 usb_put_hcd(hcd); 693 692 xhci_mtk_sch_exit(mtk); 694 693 clk_bulk_disable_unprepare(BULK_CLKS_NUM, mtk->clks); ··· 711 700 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev); 712 701 struct usb_hcd *hcd = mtk->hcd; 713 702 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 703 + struct usb_hcd *shared_hcd = xhci->shared_hcd; 714 704 int ret; 715 705 716 706 xhci_dbg(xhci, "%s: stop port polling\n", __func__); 717 707 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 718 708 del_timer_sync(&hcd->rh_timer); 719 - clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); 720 - del_timer_sync(&xhci->shared_hcd->rh_timer); 709 + if (shared_hcd) { 710 + clear_bit(HCD_FLAG_POLL_RH, &shared_hcd->flags); 711 + del_timer_sync(&shared_hcd->rh_timer); 712 + } 721 713 722 714 ret = xhci_mtk_host_disable(mtk); 723 715 if (ret) ··· 732 718 733 719 restart_poll_rh: 734 720 xhci_dbg(xhci, "%s: restart port polling\n", __func__); 735 - set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); 736 - usb_hcd_poll_rh_status(xhci->shared_hcd); 721 + if (shared_hcd) { 722 + set_bit(HCD_FLAG_POLL_RH, &shared_hcd->flags); 723 + usb_hcd_poll_rh_status(shared_hcd); 724 + } 737 725 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); 738 726 usb_hcd_poll_rh_status(hcd); 739 727 return ret; ··· 746 730 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev); 747 731 struct usb_hcd *hcd = mtk->hcd; 748 732 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 733 + struct usb_hcd *shared_hcd = xhci->shared_hcd; 749 734 int ret; 750 735 751 736 usb_wakeup_set(mtk, false); ··· 759 742 goto disable_clks; 760 743 761 744 xhci_dbg(xhci, "%s: restart port polling\n", __func__); 762 - set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); 763 - usb_hcd_poll_rh_status(xhci->shared_hcd); 745 + if (shared_hcd) { 746 + set_bit(HCD_FLAG_POLL_RH, &shared_hcd->flags); 747 + usb_hcd_poll_rh_status(shared_hcd); 748 + } 764 749 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); 765 750 usb_hcd_poll_rh_status(hcd); 766 751 return 0;
+59 -4
drivers/usb/host/xhci-pci.c
··· 59 59 #define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI 0x9a13 60 60 #define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI 0x1138 61 61 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI 0x51ed 62 + #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI 0x54ed 62 63 63 64 #define PCI_DEVICE_ID_AMD_RENOIR_XHCI 0x1639 64 65 #define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9 ··· 247 246 xhci->quirks |= XHCI_MISSING_CAS; 248 247 249 248 if (pdev->vendor == PCI_VENDOR_ID_INTEL && 250 - pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI) 249 + (pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI || 250 + pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI)) 251 251 xhci->quirks |= XHCI_RESET_TO_DEFAULT; 252 252 253 253 if (pdev->vendor == PCI_VENDOR_ID_INTEL && ··· 622 620 return retval; 623 621 } 624 622 623 + static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup) 624 + { 625 + struct xhci_hcd *xhci = hcd_to_xhci(hcd); 626 + struct xhci_port *port; 627 + struct usb_device *udev; 628 + unsigned int slot_id; 629 + u32 portsc; 630 + int i; 631 + 632 + /* 633 + * Systems with XHCI_RESET_TO_DEFAULT quirk have boot firmware that 634 + * cause significant boot delay if usb ports are in suspended U3 state 635 + * during boot. Some USB devices survive in U3 state over S4 hibernate 636 + * 637 + * Disable ports that are in U3 if remote wake is not enabled for either 638 + * host controller or connected device 639 + */ 640 + 641 + if (!(xhci->quirks & XHCI_RESET_TO_DEFAULT)) 642 + return 0; 643 + 644 + for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { 645 + port = &xhci->hw_ports[i]; 646 + portsc = readl(port->addr); 647 + 648 + if ((portsc & PORT_PLS_MASK) != XDEV_U3) 649 + continue; 650 + 651 + slot_id = xhci_find_slot_id_by_port(port->rhub->hcd, xhci, 652 + port->hcd_portnum + 1); 653 + if (!slot_id || !xhci->devs[slot_id]) { 654 + xhci_err(xhci, "No dev for slot_id %d for port %d-%d in U3\n", 655 + slot_id, port->rhub->hcd->self.busnum, port->hcd_portnum + 1); 656 + continue; 657 + } 658 + 659 + udev = xhci->devs[slot_id]->udev; 660 + 661 + /* if wakeup is enabled then don't disable the port */ 662 + if (udev->do_remote_wakeup && do_wakeup) 663 + continue; 664 + 665 + xhci_dbg(xhci, "port %d-%d in U3 without wakeup, disable it\n", 666 + port->rhub->hcd->self.busnum, port->hcd_portnum + 1); 667 + portsc = xhci_port_state_to_neutral(portsc); 668 + writel(portsc | PORT_PE, port->addr); 669 + } 670 + 671 + return 0; 672 + } 673 + 625 674 static void xhci_pci_shutdown(struct usb_hcd *hcd) 626 675 { 627 676 struct xhci_hcd *xhci = hcd_to_xhci(hcd); ··· 726 673 /* suspend and resume implemented later */ 727 674 728 675 .shutdown = usb_hcd_pci_shutdown, 729 - #ifdef CONFIG_PM 730 676 .driver = { 731 - .pm = &usb_hcd_pci_pm_ops 732 - }, 677 + #ifdef CONFIG_PM 678 + .pm = &usb_hcd_pci_pm_ops, 733 679 #endif 680 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 681 + }, 734 682 }; 735 683 736 684 static int __init xhci_pci_init(void) ··· 740 686 #ifdef CONFIG_PM 741 687 xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend; 742 688 xhci_pci_hc_driver.pci_resume = xhci_pci_resume; 689 + xhci_pci_hc_driver.pci_poweroff_late = xhci_pci_poweroff_late; 743 690 xhci_pci_hc_driver.shutdown = xhci_pci_shutdown; 744 691 #endif 745 692 return pci_register_driver(&xhci_pci_driver);
+23 -19
drivers/usb/host/xhci-ring.c
··· 896 896 } 897 897 898 898 static int xhci_handle_halted_endpoint(struct xhci_hcd *xhci, 899 - struct xhci_virt_ep *ep, unsigned int stream_id, 899 + struct xhci_virt_ep *ep, 900 900 struct xhci_td *td, 901 901 enum xhci_ep_reset_type reset_type) 902 902 { ··· 1110 1110 td->status = -EPROTO; 1111 1111 } 1112 1112 /* reset ep, reset handler cleans up cancelled tds */ 1113 - err = xhci_handle_halted_endpoint(xhci, ep, 0, td, 1114 - reset_type); 1113 + err = xhci_handle_halted_endpoint(xhci, ep, td, reset_type); 1115 1114 if (err) 1116 1115 break; 1117 1116 ep->ep_state &= ~EP_STOP_CMD_PENDING; ··· 2182 2183 } 2183 2184 /* Almost same procedure as for STALL_ERROR below */ 2184 2185 xhci_clear_hub_tt_buffer(xhci, td, ep); 2185 - xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td, 2186 - EP_HARD_RESET); 2186 + xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); 2187 2187 return 0; 2188 2188 case COMP_STALL_ERROR: 2189 2189 /* ··· 2198 2200 if (ep->ep_index != 0) 2199 2201 xhci_clear_hub_tt_buffer(xhci, td, ep); 2200 2202 2201 - xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td, 2202 - EP_HARD_RESET); 2203 + xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); 2203 2204 2204 2205 return 0; /* xhci_handle_halted_endpoint marked td cancelled */ 2205 2206 default: ··· 2455 2458 2456 2459 switch (trb_comp_code) { 2457 2460 case COMP_SUCCESS: 2458 - ep_ring->err_count = 0; 2461 + ep->err_count = 0; 2459 2462 /* handle success with untransferred data as short packet */ 2460 2463 if (ep_trb != td->last_trb || remaining) { 2461 2464 xhci_warn(xhci, "WARN Successful completion on short TX\n"); ··· 2481 2484 break; 2482 2485 case COMP_USB_TRANSACTION_ERROR: 2483 2486 if (xhci->quirks & XHCI_NO_SOFT_RETRY || 2484 - (ep_ring->err_count++ > MAX_SOFT_RETRY) || 2487 + (ep->err_count++ > MAX_SOFT_RETRY) || 2485 2488 le32_to_cpu(slot_ctx->tt_info) & TT_SLOT) 2486 2489 break; 2487 2490 2488 2491 td->status = 0; 2489 2492 2490 - xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td, 2491 - EP_SOFT_RESET); 2493 + xhci_handle_halted_endpoint(xhci, ep, td, EP_SOFT_RESET); 2492 2494 return 0; 2493 2495 default: 2494 2496 /* do nothing */ ··· 2561 2565 case COMP_USB_TRANSACTION_ERROR: 2562 2566 case COMP_INVALID_STREAM_TYPE_ERROR: 2563 2567 case COMP_INVALID_STREAM_ID_ERROR: 2564 - xhci_handle_halted_endpoint(xhci, ep, 0, NULL, 2565 - EP_SOFT_RESET); 2568 + xhci_dbg(xhci, "Stream transaction error ep %u no id\n", 2569 + ep_index); 2570 + if (ep->err_count++ > MAX_SOFT_RETRY) 2571 + xhci_handle_halted_endpoint(xhci, ep, NULL, 2572 + EP_HARD_RESET); 2573 + else 2574 + xhci_handle_halted_endpoint(xhci, ep, NULL, 2575 + EP_SOFT_RESET); 2566 2576 goto cleanup; 2567 2577 case COMP_RING_UNDERRUN: 2568 2578 case COMP_RING_OVERRUN: ··· 2751 2749 if (trb_comp_code == COMP_STALL_ERROR || 2752 2750 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, 2753 2751 trb_comp_code)) { 2754 - xhci_handle_halted_endpoint(xhci, ep, 2755 - ep_ring->stream_id, 2756 - NULL, 2752 + xhci_handle_halted_endpoint(xhci, ep, NULL, 2757 2753 EP_HARD_RESET); 2758 2754 } 2759 2755 goto cleanup; ··· 2844 2844 if (trb_comp_code == COMP_STALL_ERROR || 2845 2845 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, 2846 2846 trb_comp_code)) 2847 - xhci_handle_halted_endpoint(xhci, ep, 2848 - ep_ring->stream_id, 2849 - td, EP_HARD_RESET); 2847 + xhci_handle_halted_endpoint(xhci, ep, td, 2848 + EP_HARD_RESET); 2850 2849 goto cleanup; 2851 2850 } 2852 2851 ··· 3029 3030 3030 3031 if (!(status & STS_EINT)) 3031 3032 goto out; 3033 + 3034 + if (status & STS_HCE) { 3035 + xhci_warn(xhci, "WARNING: Host Controller Error\n"); 3036 + goto out; 3037 + } 3032 3038 3033 3039 if (status & STS_FATAL) { 3034 3040 xhci_warn(xhci, "WARNING: Host System Error\n");
+1 -1
drivers/usb/host/xhci.h
··· 933 933 * have to restore the device state to the previous state 934 934 */ 935 935 struct xhci_ring *new_ring; 936 + unsigned int err_count; 936 937 unsigned int ep_state; 937 938 #define SET_DEQ_PENDING (1 << 0) 938 939 #define EP_HALTED (1 << 1) /* For stall handling */ ··· 1628 1627 * if we own the TRB (if we are the consumer). See section 4.9.1. 1629 1628 */ 1630 1629 u32 cycle_state; 1631 - unsigned int err_count; 1632 1630 unsigned int stream_id; 1633 1631 unsigned int num_segs; 1634 1632 unsigned int num_trbs_free;
+1 -1
drivers/usb/misc/Kconfig
··· 298 298 299 299 config USB_ONBOARD_HUB 300 300 tristate "Onboard USB hub support" 301 - depends on OF || COMPILE_TEST 301 + depends on OF 302 302 help 303 303 Say Y here if you want to support discrete onboard USB hubs that 304 304 don't require an additional control bus for initialization, but
-4
drivers/usb/misc/ftdi-elan.c
··· 1624 1624 char data[30 *3 + 4]; 1625 1625 char *d = data; 1626 1626 int m = (sizeof(data) - 1) / 3 - 1; 1627 - int l = 0; 1628 1627 struct u132_target *target = &ftdi->target[ed]; 1629 1628 struct u132_command *command = &ftdi->command[ 1630 1629 COMMAND_MASK & ftdi->command_next]; ··· 1646 1647 } else if (i++ < m) { 1647 1648 int w = sprintf(d, " %02X", *b++); 1648 1649 d += w; 1649 - l += w; 1650 1650 } else 1651 1651 d += sprintf(d, " .."); 1652 1652 } ··· 1954 1956 int long_stop = 10; 1955 1957 int retry_on_timeout = 5; 1956 1958 int retry_on_empty = 10; 1957 - int err_count = 0; 1958 1959 retval = ftdi_elan_flush_input_fifo(ftdi); 1959 1960 if (retval) 1960 1961 return retval; ··· 2048 2051 continue; 2049 2052 } 2050 2053 } else { 2051 - err_count += 1; 2052 2054 dev_err(&ftdi->udev->dev, "error = %d\n", 2053 2055 retval); 2054 2056 if (read_stop-- > 0) {
+2
drivers/usb/misc/onboard_usb_hub.c
··· 331 331 332 332 /************************** USB driver **************************/ 333 333 334 + #define VENDOR_ID_GENESYS 0x05e3 334 335 #define VENDOR_ID_MICROCHIP 0x0424 335 336 #define VENDOR_ID_REALTEK 0x0bda 336 337 #define VENDOR_ID_TI 0x0451 ··· 408 407 } 409 408 410 409 static const struct usb_device_id onboard_hub_id_table[] = { 410 + { USB_DEVICE(VENDOR_ID_GENESYS, 0x0608) }, /* Genesys Logic GL850G USB 2.0 */ 411 411 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2514) }, /* USB2514B USB 2.0 */ 412 412 { USB_DEVICE(VENDOR_ID_REALTEK, 0x0411) }, /* RTS5411 USB 3.1 */ 413 413 { USB_DEVICE(VENDOR_ID_REALTEK, 0x5411) }, /* RTS5411 USB 2.1 */
+5
drivers/usb/misc/onboard_usb_hub.h
··· 22 22 .reset_us = 3000, 23 23 }; 24 24 25 + static const struct onboard_hub_pdata genesys_gl850g_data = { 26 + .reset_us = 3, 27 + }; 28 + 25 29 static const struct of_device_id onboard_hub_match[] = { 26 30 { .compatible = "usb424,2514", .data = &microchip_usb424_data, }, 27 31 { .compatible = "usb451,8140", .data = &ti_tusb8041_data, }, 28 32 { .compatible = "usb451,8142", .data = &ti_tusb8041_data, }, 33 + { .compatible = "usb5e3,608", .data = &genesys_gl850g_data, }, 29 34 { .compatible = "usbbda,411", .data = &realtek_rts5411_data, }, 30 35 { .compatible = "usbbda,5411", .data = &realtek_rts5411_data, }, 31 36 { .compatible = "usbbda,414", .data = &realtek_rts5411_data, },
-34
drivers/usb/misc/sisusbvga/Kconfig
··· 3 3 config USB_SISUSBVGA 4 4 tristate "USB 2.0 SVGA dongle support (Net2280/SiS315)" 5 5 depends on (USB_MUSB_HDRC || USB_EHCI_HCD) 6 - select FONT_SUPPORT if USB_SISUSBVGA_CON 7 6 help 8 7 Say Y here if you intend to attach a USB2VGA dongle based on a 9 8 Net2280 and a SiS315 chip. ··· 12 13 13 14 To compile this driver as a module, choose M here; the module will be 14 15 called sisusbvga. If unsure, say N. 15 - 16 - config USB_SISUSBVGA_CON 17 - bool "Text console and mode switching support" if USB_SISUSBVGA 18 - depends on VT && BROKEN 19 - select FONT_8x16 20 - help 21 - Say Y here if you want a VGA text console via the USB dongle or 22 - want to support userland applications that utilize the driver's 23 - display mode switching capabilities. 24 - 25 - Note that this console supports VGA/EGA text mode only. 26 - 27 - By default, the console part of the driver will not kick in when 28 - the driver is initialized. If you want the driver to take over 29 - one or more of the consoles, you need to specify the number of 30 - the first and last consoles (starting at 1) as driver parameters. 31 - 32 - For example, if the driver is compiled as a module: 33 - 34 - modprobe sisusbvga first=1 last=5 35 - 36 - If you use hotplug, add this to your modutils config files with 37 - the "options" keyword, such as eg. 38 - 39 - options sisusbvga first=1 last=5 40 - 41 - If the driver is compiled into the kernel image, the parameters 42 - must be given in the kernel command like, such as 43 - 44 - sisusbvga.first=1 sisusbvga.last=5 45 - 46 - 47 -
-3
drivers/usb/misc/sisusbvga/Makefile
··· 4 4 # 5 5 6 6 obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga.o 7 - 8 - sisusbvga-y := sisusb.o 9 - sisusbvga-$(CONFIG_USB_SISUSBVGA_CON) += sisusb_con.o sisusb_init.o
+7 -282
drivers/usb/misc/sisusbvga/sisusb.c drivers/usb/misc/sisusbvga/sisusbvga.c
··· 51 51 #include <linux/vmalloc.h> 52 52 53 53 #include "sisusb.h" 54 - #include "sisusb_init.h" 55 - 56 - #ifdef CONFIG_USB_SISUSBVGA_CON 57 - #include <linux/font.h> 58 - #endif 59 54 60 55 #define SISUSB_DONTSYNC 61 56 62 57 /* Forward declarations / clean-up routines */ 63 - 64 - #ifdef CONFIG_USB_SISUSBVGA_CON 65 - static int sisusb_first_vc; 66 - static int sisusb_last_vc; 67 - module_param_named(first, sisusb_first_vc, int, 0); 68 - module_param_named(last, sisusb_last_vc, int, 0); 69 - MODULE_PARM_DESC(first, "Number of first console to take over (1 - MAX_NR_CONSOLES)"); 70 - MODULE_PARM_DESC(last, "Number of last console to take over (1 - MAX_NR_CONSOLES)"); 71 - #endif 72 58 73 59 static struct usb_driver sisusb_driver; 74 60 ··· 1184 1198 1185 1199 /* High level: Gfx (indexed) register access */ 1186 1200 1187 - #ifdef CONFIG_USB_SISUSBVGA_CON 1188 - int sisusb_setreg(struct sisusb_usb_data *sisusb, u32 port, u8 data) 1189 - { 1190 - return sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, port, data); 1191 - } 1192 - 1193 - int sisusb_getreg(struct sisusb_usb_data *sisusb, u32 port, u8 *data) 1194 - { 1195 - return sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO, port, data); 1196 - } 1197 - #endif 1198 - 1199 - int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port, 1201 + static int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port, 1200 1202 u8 index, u8 data) 1201 1203 { 1202 1204 int ret; ··· 1194 1220 return ret; 1195 1221 } 1196 1222 1197 - int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port, 1223 + static int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port, 1198 1224 u8 index, u8 *data) 1199 1225 { 1200 1226 int ret; ··· 1204 1230 return ret; 1205 1231 } 1206 1232 1207 - int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port, u8 idx, 1233 + static int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port, u8 idx, 1208 1234 u8 myand, u8 myor) 1209 1235 { 1210 1236 int ret; ··· 1232 1258 return ret; 1233 1259 } 1234 1260 1235 - int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port, 1261 + static int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port, 1236 1262 u8 index, u8 myor) 1237 1263 { 1238 1264 return sisusb_setidxregandor(sisusb, port, index, 0xff, myor); 1239 1265 } 1240 1266 1241 - int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port, 1267 + static int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port, 1242 1268 u8 idx, u8 myand) 1243 1269 { 1244 1270 return sisusb_setidxregandor(sisusb, port, idx, myand, 0x00); 1245 1271 } 1246 1272 1247 1273 /* Write/read video ram */ 1248 - 1249 - #ifdef CONFIG_USB_SISUSBVGA_CON 1250 - int sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data) 1251 - { 1252 - return sisusb_write_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data); 1253 - } 1254 - 1255 - int sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 *data) 1256 - { 1257 - return sisusb_read_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data); 1258 - } 1259 - 1260 - int sisusb_copy_memory(struct sisusb_usb_data *sisusb, u8 *src, 1261 - u32 dest, int length) 1262 - { 1263 - size_t dummy; 1264 - 1265 - return sisusb_write_mem_bulk(sisusb, dest, src, length, 1266 - NULL, 0, &dummy); 1267 - } 1268 - 1269 - #ifdef SISUSBENDIANTEST 1270 - static int sisusb_read_memory(struct sisusb_usb_data *sisusb, char *dest, 1271 - u32 src, int length) 1272 - { 1273 - size_t dummy; 1274 - 1275 - return sisusb_read_mem_bulk(sisusb, src, dest, length, 1276 - NULL, &dummy); 1277 - } 1278 - #endif 1279 - #endif 1280 1274 1281 1275 #ifdef SISUSBENDIANTEST 1282 1276 static void sisusb_testreadwrite(struct sisusb_usb_data *sisusb) ··· 2194 2252 return ret; 2195 2253 } 2196 2254 2197 - 2198 - #ifdef CONFIG_USB_SISUSBVGA_CON 2199 - 2200 - /* Set up default text mode: 2201 - * - Set text mode (0x03) 2202 - * - Upload default font 2203 - * - Upload user font (if available) 2204 - */ 2205 - 2206 - int sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init) 2207 - { 2208 - int ret = 0, slot = sisusb->font_slot, i; 2209 - const struct font_desc *myfont; 2210 - u8 *tempbuf; 2211 - u16 *tempbufb; 2212 - static const char bootstring[] = 2213 - "SiSUSB VGA text console, (C) 2005 Thomas Winischhofer."; 2214 - static const char bootlogo[] = "(o_ //\\ V_/_"; 2215 - 2216 - /* sisusb->lock is down */ 2217 - 2218 - if (!sisusb->SiS_Pr) 2219 - return 1; 2220 - 2221 - sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30; 2222 - sisusb->SiS_Pr->sisusb = (void *)sisusb; 2223 - 2224 - /* Set mode 0x03 */ 2225 - SiSUSBSetMode(sisusb->SiS_Pr, 0x03); 2226 - 2227 - myfont = find_font("VGA8x16"); 2228 - if (!myfont) 2229 - return 1; 2230 - 2231 - tempbuf = vmalloc(8192); 2232 - if (!tempbuf) 2233 - return 1; 2234 - 2235 - for (i = 0; i < 256; i++) 2236 - memcpy(tempbuf + (i * 32), myfont->data + (i * 16), 16); 2237 - 2238 - /* Upload default font */ 2239 - ret = sisusbcon_do_font_op(sisusb, 1, 0, tempbuf, 8192, 2240 - 0, 1, NULL, 16, 0); 2241 - 2242 - vfree(tempbuf); 2243 - 2244 - /* Upload user font (and reset current slot) */ 2245 - if (sisusb->font_backup) { 2246 - ret |= sisusbcon_do_font_op(sisusb, 1, 2, sisusb->font_backup, 2247 - 8192, sisusb->font_backup_512, 1, NULL, 2248 - sisusb->font_backup_height, 0); 2249 - if (slot != 2) 2250 - sisusbcon_do_font_op(sisusb, 1, 0, NULL, 0, 0, 1, 2251 - NULL, 16, 0); 2252 - } 2253 - 2254 - if (init && !sisusb->scrbuf) { 2255 - 2256 - tempbuf = vmalloc(8192); 2257 - if (tempbuf) { 2258 - 2259 - i = 4096; 2260 - tempbufb = (u16 *)tempbuf; 2261 - while (i--) 2262 - *(tempbufb++) = 0x0720; 2263 - 2264 - i = 0; 2265 - tempbufb = (u16 *)tempbuf; 2266 - while (bootlogo[i]) { 2267 - *(tempbufb++) = 0x0700 | bootlogo[i++]; 2268 - if (!(i % 4)) 2269 - tempbufb += 76; 2270 - } 2271 - 2272 - i = 0; 2273 - tempbufb = (u16 *)tempbuf + 6; 2274 - while (bootstring[i]) 2275 - *(tempbufb++) = 0x0700 | bootstring[i++]; 2276 - 2277 - ret |= sisusb_copy_memory(sisusb, tempbuf, 2278 - sisusb->vrambase, 8192); 2279 - 2280 - vfree(tempbuf); 2281 - 2282 - } 2283 - 2284 - } else if (sisusb->scrbuf) { 2285 - ret |= sisusb_copy_memory(sisusb, (u8 *)sisusb->scrbuf, 2286 - sisusb->vrambase, sisusb->scrbuf_size); 2287 - } 2288 - 2289 - if (sisusb->sisusb_cursor_size_from >= 0 && 2290 - sisusb->sisusb_cursor_size_to >= 0) { 2291 - sisusb_setidxreg(sisusb, SISCR, 0x0a, 2292 - sisusb->sisusb_cursor_size_from); 2293 - sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0, 2294 - sisusb->sisusb_cursor_size_to); 2295 - } else { 2296 - sisusb_setidxreg(sisusb, SISCR, 0x0a, 0x2d); 2297 - sisusb_setidxreg(sisusb, SISCR, 0x0b, 0x0e); 2298 - sisusb->sisusb_cursor_size_to = -1; 2299 - } 2300 - 2301 - slot = sisusb->sisusb_cursor_loc; 2302 - if (slot < 0) 2303 - slot = 0; 2304 - 2305 - sisusb->sisusb_cursor_loc = -1; 2306 - sisusb->bad_cursor_pos = 1; 2307 - 2308 - sisusb_set_cursor(sisusb, slot); 2309 - 2310 - sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8)); 2311 - sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff)); 2312 - 2313 - sisusb->textmodedestroyed = 0; 2314 - 2315 - /* sisusb->lock is down */ 2316 - 2317 - return ret; 2318 - } 2319 - 2320 - #endif 2321 - 2322 2255 /* fops */ 2323 2256 2324 2257 static int sisusb_open(struct inode *inode, struct file *file) ··· 2251 2434 return 0; 2252 2435 } 2253 2436 2254 - void sisusb_delete(struct kref *kref) 2437 + static void sisusb_delete(struct kref *kref) 2255 2438 { 2256 2439 struct sisusb_usb_data *sisusb = to_sisusb_dev(kref); 2257 2440 ··· 2263 2446 sisusb->sisusb_dev = NULL; 2264 2447 sisusb_free_buffers(sisusb); 2265 2448 sisusb_free_urbs(sisusb); 2266 - #ifdef CONFIG_USB_SISUSBVGA_CON 2267 - kfree(sisusb->SiS_Pr); 2268 - #endif 2269 2449 kfree(sisusb); 2270 2450 } 2271 2451 ··· 2656 2842 2657 2843 case SUCMD_HANDLETEXTMODE: 2658 2844 retval = 0; 2659 - #ifdef CONFIG_USB_SISUSBVGA_CON 2660 - /* Gfx core must be initialized, SiS_Pr must exist */ 2661 - if (!sisusb->gfxinit || !sisusb->SiS_Pr) 2662 - return -ENODEV; 2663 - 2664 - switch (y->data0) { 2665 - case 0: 2666 - retval = sisusb_reset_text_mode(sisusb, 0); 2667 - break; 2668 - case 1: 2669 - sisusb->textmodedestroyed = 1; 2670 - break; 2671 - } 2672 - #endif 2673 2845 break; 2674 - 2675 - #ifdef CONFIG_USB_SISUSBVGA_CON 2676 - case SUCMD_SETMODE: 2677 - /* Gfx core must be initialized, SiS_Pr must exist */ 2678 - if (!sisusb->gfxinit || !sisusb->SiS_Pr) 2679 - return -ENODEV; 2680 - 2681 - retval = 0; 2682 - 2683 - sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30; 2684 - sisusb->SiS_Pr->sisusb = (void *)sisusb; 2685 - 2686 - if (SiSUSBSetMode(sisusb->SiS_Pr, y->data3)) 2687 - retval = -EINVAL; 2688 - 2689 - break; 2690 - 2691 - case SUCMD_SETVESAMODE: 2692 - /* Gfx core must be initialized, SiS_Pr must exist */ 2693 - if (!sisusb->gfxinit || !sisusb->SiS_Pr) 2694 - return -ENODEV; 2695 - 2696 - retval = 0; 2697 - 2698 - sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30; 2699 - sisusb->SiS_Pr->sisusb = (void *)sisusb; 2700 - 2701 - if (SiSUSBSetVESAMode(sisusb->SiS_Pr, y->data3)) 2702 - retval = -EINVAL; 2703 - 2704 - break; 2705 - #endif 2706 2846 2707 2847 default: 2708 2848 retval = -EINVAL; ··· 2710 2942 x.sisusb_vramsize = sisusb->vramsize; 2711 2943 x.sisusb_minor = sisusb->minor; 2712 2944 x.sisusb_fbdevactive = 0; 2713 - #ifdef CONFIG_USB_SISUSBVGA_CON 2714 - x.sisusb_conactive = sisusb->haveconsole ? 1 : 0; 2715 - #else 2716 2945 x.sisusb_conactive = 0; 2717 - #endif 2718 2946 memset(x.sisusb_reserved, 0, sizeof(x.sisusb_reserved)); 2719 2947 2720 2948 if (copy_to_user((void __user *)arg, &x, sizeof(x))) ··· 2854 3090 dev_info(&sisusb->sisusb_dev->dev, "Allocated %d output buffers\n", 2855 3091 sisusb->numobufs); 2856 3092 2857 - #ifdef CONFIG_USB_SISUSBVGA_CON 2858 - /* Allocate our SiS_Pr */ 2859 - sisusb->SiS_Pr = kmalloc(sizeof(struct SiS_Private), GFP_KERNEL); 2860 - if (!sisusb->SiS_Pr) { 2861 - retval = -ENOMEM; 2862 - goto error_4; 2863 - } 2864 - #endif 2865 - 2866 3093 /* Do remaining init stuff */ 2867 3094 2868 3095 init_waitqueue_head(&sisusb->wait_q); ··· 2866 3111 2867 3112 if (dev->speed == USB_SPEED_HIGH || dev->speed >= USB_SPEED_SUPER) { 2868 3113 int initscreen = 1; 2869 - #ifdef CONFIG_USB_SISUSBVGA_CON 2870 - if (sisusb_first_vc > 0 && sisusb_last_vc > 0 && 2871 - sisusb_first_vc <= sisusb_last_vc && 2872 - sisusb_last_vc <= MAX_NR_CONSOLES) 2873 - initscreen = 0; 2874 - #endif 2875 3114 if (sisusb_init_gfxdevice(sisusb, initscreen)) 2876 3115 dev_err(&sisusb->sisusb_dev->dev, 2877 3116 "Failed to early initialize device\n"); ··· 2880 3131 dev_dbg(&sisusb->sisusb_dev->dev, "*** RWTEST ***\n"); 2881 3132 sisusb_testreadwrite(sisusb); 2882 3133 dev_dbg(&sisusb->sisusb_dev->dev, "*** RWTEST END ***\n"); 2883 - #endif 2884 - 2885 - #ifdef CONFIG_USB_SISUSBVGA_CON 2886 - sisusb_console_init(sisusb, sisusb_first_vc, sisusb_last_vc); 2887 3134 #endif 2888 3135 2889 3136 return 0; ··· 2903 3158 sisusb = usb_get_intfdata(intf); 2904 3159 if (!sisusb) 2905 3160 return; 2906 - 2907 - #ifdef CONFIG_USB_SISUSBVGA_CON 2908 - sisusb_console_exit(sisusb); 2909 - #endif 2910 3161 2911 3162 usb_deregister_dev(intf, &usb_sisusb_class); 2912 3163 ··· 2947 3206 .id_table = sisusb_table, 2948 3207 }; 2949 3208 2950 - static int __init usb_sisusb_init(void) 2951 - { 2952 - 2953 - #ifdef CONFIG_USB_SISUSBVGA_CON 2954 - sisusb_init_concode(); 2955 - #endif 2956 - 2957 - return usb_register(&sisusb_driver); 2958 - } 2959 - 2960 - static void __exit usb_sisusb_exit(void) 2961 - { 2962 - usb_deregister(&sisusb_driver); 2963 - } 2964 - 2965 - module_init(usb_sisusb_init); 2966 - module_exit(usb_sisusb_exit); 3209 + module_usb_driver(sisusb_driver); 2967 3210 2968 3211 MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>"); 2969 3212 MODULE_DESCRIPTION("sisusbvga - Driver for Net2280/SiS315-based USB2VGA dongles");
-21
drivers/usb/misc/sisusbvga/sisusb.h
··· 48 48 49 49 /* Include console and mode switching code? */ 50 50 51 - #include <linux/console.h> 52 51 #include <linux/vt_kern.h> 53 52 #include "sisusb_struct.h" 54 53 ··· 125 126 unsigned char gfxinit; /* graphics core initialized? */ 126 127 unsigned short chipid, chipvendor; 127 128 unsigned short chiprevision; 128 - #ifdef CONFIG_USB_SISUSBVGA_CON 129 - struct SiS_Private *SiS_Pr; 130 - unsigned long scrbuf; 131 - unsigned int scrbuf_size; 132 - int haveconsole, con_first, con_last; 133 - int havethisconsole[MAX_NR_CONSOLES]; 134 - int textmodedestroyed; 135 - unsigned int sisusb_num_columns; /* real number, not vt's idea */ 136 - int cur_start_addr, con_rolled_over; 137 - int sisusb_cursor_loc, bad_cursor_pos; 138 - int sisusb_cursor_size_from; 139 - int sisusb_cursor_size_to; 140 - int current_font_height, current_font_512; 141 - int font_backup_size, font_backup_height, font_backup_512; 142 - char *font_backup; 143 - int font_slot; 144 - struct vc_data *sisusb_display_fg; 145 - int is_gfx; 146 - int con_blanked; 147 - #endif 148 129 }; 149 130 150 131 #define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref)
-1496
drivers/usb/misc/sisusbvga/sisusb_con.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 2 - /* 3 - * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles 4 - * 5 - * VGA text mode console part 6 - * 7 - * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria 8 - * 9 - * If distributed as part of the Linux kernel, this code is licensed under the 10 - * terms of the GPL v2. 11 - * 12 - * Otherwise, the following license terms apply: 13 - * 14 - * * Redistribution and use in source and binary forms, with or without 15 - * * modification, are permitted provided that the following conditions 16 - * * are met: 17 - * * 1) Redistributions of source code must retain the above copyright 18 - * * notice, this list of conditions and the following disclaimer. 19 - * * 2) Redistributions in binary form must reproduce the above copyright 20 - * * notice, this list of conditions and the following disclaimer in the 21 - * * documentation and/or other materials provided with the distribution. 22 - * * 3) The name of the author may not be used to endorse or promote products 23 - * * derived from this software without specific psisusbr written permission. 24 - * * 25 - * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR 26 - * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 - * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 - * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 29 - * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 - * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 - * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 - * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 - * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 - * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 - * 36 - * Author: Thomas Winischhofer <thomas@winischhofer.net> 37 - * 38 - * Portions based on vgacon.c which are 39 - * Created 28 Sep 1997 by Geert Uytterhoeven 40 - * Rewritten by Martin Mares <mj@ucw.cz>, July 1998 41 - * based on code Copyright (C) 1991, 1992 Linus Torvalds 42 - * 1995 Jay Estabrook 43 - * 44 - * A note on using in_atomic() in here: We can't handle console 45 - * calls from non-schedulable context due to our USB-dependend 46 - * nature. For now, this driver just ignores any calls if it 47 - * detects this state. 48 - * 49 - */ 50 - 51 - #include <linux/mutex.h> 52 - #include <linux/module.h> 53 - #include <linux/kernel.h> 54 - #include <linux/signal.h> 55 - #include <linux/fs.h> 56 - #include <linux/usb.h> 57 - #include <linux/tty.h> 58 - #include <linux/console.h> 59 - #include <linux/string.h> 60 - #include <linux/kd.h> 61 - #include <linux/init.h> 62 - #include <linux/vt_kern.h> 63 - #include <linux/selection.h> 64 - #include <linux/spinlock.h> 65 - #include <linux/kref.h> 66 - #include <linux/ioport.h> 67 - #include <linux/interrupt.h> 68 - #include <linux/vmalloc.h> 69 - 70 - #include "sisusb.h" 71 - #include "sisusb_init.h" 72 - 73 - /* vc_data -> sisusb conversion table */ 74 - static struct sisusb_usb_data *mysisusbs[MAX_NR_CONSOLES]; 75 - 76 - /* Forward declaration */ 77 - static const struct consw sisusb_con; 78 - 79 - static inline void 80 - sisusbcon_memsetw(u16 *s, u16 c, unsigned int count) 81 - { 82 - memset16(s, c, count / 2); 83 - } 84 - 85 - static inline void 86 - sisusb_initialize(struct sisusb_usb_data *sisusb) 87 - { 88 - /* Reset cursor and start address */ 89 - if (sisusb_setidxreg(sisusb, SISCR, 0x0c, 0x00)) 90 - return; 91 - if (sisusb_setidxreg(sisusb, SISCR, 0x0d, 0x00)) 92 - return; 93 - if (sisusb_setidxreg(sisusb, SISCR, 0x0e, 0x00)) 94 - return; 95 - sisusb_setidxreg(sisusb, SISCR, 0x0f, 0x00); 96 - } 97 - 98 - static inline void 99 - sisusbcon_set_start_address(struct sisusb_usb_data *sisusb, struct vc_data *c) 100 - { 101 - sisusb->cur_start_addr = (c->vc_visible_origin - sisusb->scrbuf) / 2; 102 - 103 - sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8)); 104 - sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff)); 105 - } 106 - 107 - void 108 - sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location) 109 - { 110 - if (sisusb->sisusb_cursor_loc == location) 111 - return; 112 - 113 - sisusb->sisusb_cursor_loc = location; 114 - 115 - /* Hardware bug: Text cursor appears twice or not at all 116 - * at some positions. Work around it with the cursor skew 117 - * bits. 118 - */ 119 - 120 - if ((location & 0x0007) == 0x0007) { 121 - sisusb->bad_cursor_pos = 1; 122 - location--; 123 - if (sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0x1f, 0x20)) 124 - return; 125 - } else if (sisusb->bad_cursor_pos) { 126 - if (sisusb_setidxregand(sisusb, SISCR, 0x0b, 0x1f)) 127 - return; 128 - sisusb->bad_cursor_pos = 0; 129 - } 130 - 131 - if (sisusb_setidxreg(sisusb, SISCR, 0x0e, (location >> 8))) 132 - return; 133 - sisusb_setidxreg(sisusb, SISCR, 0x0f, (location & 0xff)); 134 - } 135 - 136 - static inline struct sisusb_usb_data * 137 - sisusb_get_sisusb(unsigned short console) 138 - { 139 - return mysisusbs[console]; 140 - } 141 - 142 - static inline int 143 - sisusb_sisusb_valid(struct sisusb_usb_data *sisusb) 144 - { 145 - if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev) 146 - return 0; 147 - 148 - return 1; 149 - } 150 - 151 - static struct sisusb_usb_data * 152 - sisusb_get_sisusb_lock_and_check(unsigned short console) 153 - { 154 - struct sisusb_usb_data *sisusb; 155 - 156 - /* We can't handle console calls in non-schedulable 157 - * context due to our locks and the USB transport. 158 - * So we simply ignore them. This should only affect 159 - * some calls to printk. 160 - */ 161 - if (in_atomic()) 162 - return NULL; 163 - 164 - sisusb = sisusb_get_sisusb(console); 165 - if (!sisusb) 166 - return NULL; 167 - 168 - mutex_lock(&sisusb->lock); 169 - 170 - if (!sisusb_sisusb_valid(sisusb) || 171 - !sisusb->havethisconsole[console]) { 172 - mutex_unlock(&sisusb->lock); 173 - return NULL; 174 - } 175 - 176 - return sisusb; 177 - } 178 - 179 - static int 180 - sisusb_is_inactive(struct vc_data *c, struct sisusb_usb_data *sisusb) 181 - { 182 - if (sisusb->is_gfx || 183 - sisusb->textmodedestroyed || 184 - c->vc_mode != KD_TEXT) 185 - return 1; 186 - 187 - return 0; 188 - } 189 - 190 - /* con_startup console interface routine */ 191 - static const char * 192 - sisusbcon_startup(void) 193 - { 194 - return "SISUSBCON"; 195 - } 196 - 197 - /* con_init console interface routine */ 198 - static void 199 - sisusbcon_init(struct vc_data *c, int init) 200 - { 201 - struct sisusb_usb_data *sisusb; 202 - int cols, rows; 203 - 204 - /* This is called by do_take_over_console(), 205 - * ie by us/under our control. It is 206 - * only called after text mode and fonts 207 - * are set up/restored. 208 - */ 209 - 210 - sisusb = sisusb_get_sisusb(c->vc_num); 211 - if (!sisusb) 212 - return; 213 - 214 - mutex_lock(&sisusb->lock); 215 - 216 - if (!sisusb_sisusb_valid(sisusb)) { 217 - mutex_unlock(&sisusb->lock); 218 - return; 219 - } 220 - 221 - c->vc_can_do_color = 1; 222 - 223 - c->vc_complement_mask = 0x7700; 224 - 225 - c->vc_hi_font_mask = sisusb->current_font_512 ? 0x0800 : 0; 226 - 227 - sisusb->haveconsole = 1; 228 - 229 - sisusb->havethisconsole[c->vc_num] = 1; 230 - 231 - /* We only support 640x400 */ 232 - c->vc_scan_lines = 400; 233 - 234 - c->vc_font.height = sisusb->current_font_height; 235 - 236 - /* We only support width = 8 */ 237 - cols = 80; 238 - rows = c->vc_scan_lines / c->vc_font.height; 239 - 240 - /* Increment usage count for our sisusb. 241 - * Doing so saves us from upping/downing 242 - * the disconnect semaphore; we can't 243 - * lose our sisusb until this is undone 244 - * in con_deinit. For all other console 245 - * interface functions, it suffices to 246 - * use sisusb->lock and do a quick check 247 - * of sisusb for device disconnection. 248 - */ 249 - kref_get(&sisusb->kref); 250 - 251 - if (!*c->uni_pagedict_loc) 252 - con_set_default_unimap(c); 253 - 254 - mutex_unlock(&sisusb->lock); 255 - 256 - if (init) { 257 - c->vc_cols = cols; 258 - c->vc_rows = rows; 259 - } else 260 - vc_resize(c, cols, rows); 261 - } 262 - 263 - /* con_deinit console interface routine */ 264 - static void 265 - sisusbcon_deinit(struct vc_data *c) 266 - { 267 - struct sisusb_usb_data *sisusb; 268 - int i; 269 - 270 - /* This is called by do_take_over_console() 271 - * and others, ie not under our control. 272 - */ 273 - 274 - sisusb = sisusb_get_sisusb(c->vc_num); 275 - if (!sisusb) 276 - return; 277 - 278 - mutex_lock(&sisusb->lock); 279 - 280 - /* Clear ourselves in mysisusbs */ 281 - mysisusbs[c->vc_num] = NULL; 282 - 283 - sisusb->havethisconsole[c->vc_num] = 0; 284 - 285 - /* Free our font buffer if all consoles are gone */ 286 - if (sisusb->font_backup) { 287 - for(i = 0; i < MAX_NR_CONSOLES; i++) { 288 - if (sisusb->havethisconsole[c->vc_num]) 289 - break; 290 - } 291 - if (i == MAX_NR_CONSOLES) { 292 - vfree(sisusb->font_backup); 293 - sisusb->font_backup = NULL; 294 - } 295 - } 296 - 297 - mutex_unlock(&sisusb->lock); 298 - 299 - /* decrement the usage count on our sisusb */ 300 - kref_put(&sisusb->kref, sisusb_delete); 301 - } 302 - 303 - /* interface routine */ 304 - static u8 305 - sisusbcon_build_attr(struct vc_data *c, u8 color, enum vc_intensity intensity, 306 - bool blink, bool underline, bool reverse, 307 - bool unused) 308 - { 309 - u8 attr = color; 310 - 311 - if (underline) 312 - attr = (attr & 0xf0) | c->vc_ulcolor; 313 - else if (intensity == VCI_HALF_BRIGHT) 314 - attr = (attr & 0xf0) | c->vc_halfcolor; 315 - 316 - if (reverse) 317 - attr = ((attr) & 0x88) | 318 - ((((attr) >> 4) | 319 - ((attr) << 4)) & 0x77); 320 - 321 - if (blink) 322 - attr ^= 0x80; 323 - 324 - if (intensity == VCI_BOLD) 325 - attr ^= 0x08; 326 - 327 - return attr; 328 - } 329 - 330 - /* Interface routine */ 331 - static void 332 - sisusbcon_invert_region(struct vc_data *vc, u16 *p, int count) 333 - { 334 - /* Invert a region. This is called with a pointer 335 - * to the console's internal screen buffer. So we 336 - * simply do the inversion there and rely on 337 - * a call to putc(s) to update the real screen. 338 - */ 339 - 340 - while (count--) { 341 - u16 a = *p; 342 - 343 - *p++ = ((a) & 0x88ff) | 344 - (((a) & 0x7000) >> 4) | 345 - (((a) & 0x0700) << 4); 346 - } 347 - } 348 - 349 - static inline void *sisusb_vaddr(const struct sisusb_usb_data *sisusb, 350 - const struct vc_data *c, unsigned int x, unsigned int y) 351 - { 352 - return (u16 *)c->vc_origin + y * sisusb->sisusb_num_columns + x; 353 - } 354 - 355 - static inline unsigned long sisusb_haddr(const struct sisusb_usb_data *sisusb, 356 - const struct vc_data *c, unsigned int x, unsigned int y) 357 - { 358 - unsigned long offset = c->vc_origin - sisusb->scrbuf; 359 - 360 - /* 2 bytes per each character */ 361 - offset += 2 * (y * sisusb->sisusb_num_columns + x); 362 - 363 - return sisusb->vrambase + offset; 364 - } 365 - 366 - /* Interface routine */ 367 - static void 368 - sisusbcon_putc(struct vc_data *c, int ch, int y, int x) 369 - { 370 - struct sisusb_usb_data *sisusb; 371 - 372 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 373 - if (!sisusb) 374 - return; 375 - 376 - /* sisusb->lock is down */ 377 - if (sisusb_is_inactive(c, sisusb)) { 378 - mutex_unlock(&sisusb->lock); 379 - return; 380 - } 381 - 382 - sisusb_copy_memory(sisusb, sisusb_vaddr(sisusb, c, x, y), 383 - sisusb_haddr(sisusb, c, x, y), 2); 384 - 385 - mutex_unlock(&sisusb->lock); 386 - } 387 - 388 - /* Interface routine */ 389 - static void 390 - sisusbcon_putcs(struct vc_data *c, const unsigned short *s, 391 - int count, int y, int x) 392 - { 393 - struct sisusb_usb_data *sisusb; 394 - 395 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 396 - if (!sisusb) 397 - return; 398 - 399 - /* sisusb->lock is down */ 400 - 401 - /* Need to put the characters into the buffer ourselves, 402 - * because the vt does this AFTER calling us. 403 - */ 404 - 405 - memcpy(sisusb_vaddr(sisusb, c, x, y), s, count * 2); 406 - 407 - if (sisusb_is_inactive(c, sisusb)) { 408 - mutex_unlock(&sisusb->lock); 409 - return; 410 - } 411 - 412 - sisusb_copy_memory(sisusb, sisusb_vaddr(sisusb, c, x, y), 413 - sisusb_haddr(sisusb, c, x, y), count * 2); 414 - 415 - mutex_unlock(&sisusb->lock); 416 - } 417 - 418 - /* Interface routine */ 419 - static void 420 - sisusbcon_clear(struct vc_data *c, int y, int x, int height, int width) 421 - { 422 - struct sisusb_usb_data *sisusb; 423 - u16 eattr = c->vc_video_erase_char; 424 - int i, length, cols; 425 - u16 *dest; 426 - 427 - if (width <= 0 || height <= 0) 428 - return; 429 - 430 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 431 - if (!sisusb) 432 - return; 433 - 434 - /* sisusb->lock is down */ 435 - 436 - /* Need to clear buffer ourselves, because the vt does 437 - * this AFTER calling us. 438 - */ 439 - 440 - dest = sisusb_vaddr(sisusb, c, x, y); 441 - 442 - cols = sisusb->sisusb_num_columns; 443 - 444 - if (width > cols) 445 - width = cols; 446 - 447 - if (x == 0 && width >= c->vc_cols) { 448 - 449 - sisusbcon_memsetw(dest, eattr, height * cols * 2); 450 - 451 - } else { 452 - 453 - for (i = height; i > 0; i--, dest += cols) 454 - sisusbcon_memsetw(dest, eattr, width * 2); 455 - 456 - } 457 - 458 - if (sisusb_is_inactive(c, sisusb)) { 459 - mutex_unlock(&sisusb->lock); 460 - return; 461 - } 462 - 463 - length = ((height * cols) - x - (cols - width - x)) * 2; 464 - 465 - 466 - sisusb_copy_memory(sisusb, sisusb_vaddr(sisusb, c, x, y), 467 - sisusb_haddr(sisusb, c, x, y), length); 468 - 469 - mutex_unlock(&sisusb->lock); 470 - } 471 - 472 - /* interface routine */ 473 - static int 474 - sisusbcon_switch(struct vc_data *c) 475 - { 476 - struct sisusb_usb_data *sisusb; 477 - int length; 478 - 479 - /* Returnvalue 0 means we have fully restored screen, 480 - * and vt doesn't need to call do_update_region(). 481 - * Returnvalue != 0 naturally means the opposite. 482 - */ 483 - 484 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 485 - if (!sisusb) 486 - return 0; 487 - 488 - /* sisusb->lock is down */ 489 - 490 - /* Don't write to screen if in gfx mode */ 491 - if (sisusb_is_inactive(c, sisusb)) { 492 - mutex_unlock(&sisusb->lock); 493 - return 0; 494 - } 495 - 496 - /* That really should not happen. It would mean we are 497 - * being called while the vc is using its private buffer 498 - * as origin. 499 - */ 500 - if (c->vc_origin == (unsigned long)c->vc_screenbuf) { 501 - mutex_unlock(&sisusb->lock); 502 - dev_dbg(&sisusb->sisusb_dev->dev, "ASSERT ORIGIN != SCREENBUF!\n"); 503 - return 0; 504 - } 505 - 506 - /* Check that we don't copy too much */ 507 - length = min((int)c->vc_screenbuf_size, 508 - (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin)); 509 - 510 - /* Restore the screen contents */ 511 - memcpy((u16 *)c->vc_origin, (u16 *)c->vc_screenbuf, length); 512 - 513 - sisusb_copy_memory(sisusb, (u8 *)c->vc_origin, 514 - sisusb_haddr(sisusb, c, 0, 0), length); 515 - 516 - mutex_unlock(&sisusb->lock); 517 - 518 - return 0; 519 - } 520 - 521 - /* interface routine */ 522 - static void 523 - sisusbcon_save_screen(struct vc_data *c) 524 - { 525 - struct sisusb_usb_data *sisusb; 526 - int length; 527 - 528 - /* Save the current screen contents to vc's private 529 - * buffer. 530 - */ 531 - 532 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 533 - if (!sisusb) 534 - return; 535 - 536 - /* sisusb->lock is down */ 537 - 538 - if (sisusb_is_inactive(c, sisusb)) { 539 - mutex_unlock(&sisusb->lock); 540 - return; 541 - } 542 - 543 - /* Check that we don't copy too much */ 544 - length = min((int)c->vc_screenbuf_size, 545 - (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin)); 546 - 547 - /* Save the screen contents to vc's private buffer */ 548 - memcpy((u16 *)c->vc_screenbuf, (u16 *)c->vc_origin, length); 549 - 550 - mutex_unlock(&sisusb->lock); 551 - } 552 - 553 - /* interface routine */ 554 - static void 555 - sisusbcon_set_palette(struct vc_data *c, const unsigned char *table) 556 - { 557 - struct sisusb_usb_data *sisusb; 558 - int i, j; 559 - 560 - /* Return value not used by vt */ 561 - 562 - if (!con_is_visible(c)) 563 - return; 564 - 565 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 566 - if (!sisusb) 567 - return; 568 - 569 - /* sisusb->lock is down */ 570 - 571 - if (sisusb_is_inactive(c, sisusb)) { 572 - mutex_unlock(&sisusb->lock); 573 - return; 574 - } 575 - 576 - for (i = j = 0; i < 16; i++) { 577 - if (sisusb_setreg(sisusb, SISCOLIDX, table[i])) 578 - break; 579 - if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2)) 580 - break; 581 - if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2)) 582 - break; 583 - if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2)) 584 - break; 585 - } 586 - 587 - mutex_unlock(&sisusb->lock); 588 - } 589 - 590 - /* interface routine */ 591 - static int 592 - sisusbcon_blank(struct vc_data *c, int blank, int mode_switch) 593 - { 594 - struct sisusb_usb_data *sisusb; 595 - u8 sr1, cr17, pmreg, cr63; 596 - int ret = 0; 597 - 598 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 599 - if (!sisusb) 600 - return 0; 601 - 602 - /* sisusb->lock is down */ 603 - 604 - if (mode_switch) 605 - sisusb->is_gfx = blank ? 1 : 0; 606 - 607 - if (sisusb_is_inactive(c, sisusb)) { 608 - mutex_unlock(&sisusb->lock); 609 - return 0; 610 - } 611 - 612 - switch (blank) { 613 - 614 - case 1: /* Normal blanking: Clear screen */ 615 - case -1: 616 - sisusbcon_memsetw((u16 *)c->vc_origin, 617 - c->vc_video_erase_char, 618 - c->vc_screenbuf_size); 619 - sisusb_copy_memory(sisusb, (u8 *)c->vc_origin, 620 - sisusb_haddr(sisusb, c, 0, 0), 621 - c->vc_screenbuf_size); 622 - sisusb->con_blanked = 1; 623 - ret = 1; 624 - break; 625 - 626 - default: /* VESA blanking */ 627 - switch (blank) { 628 - case 0: /* Unblank */ 629 - sr1 = 0x00; 630 - cr17 = 0x80; 631 - pmreg = 0x00; 632 - cr63 = 0x00; 633 - ret = 1; 634 - sisusb->con_blanked = 0; 635 - break; 636 - case VESA_VSYNC_SUSPEND + 1: 637 - sr1 = 0x20; 638 - cr17 = 0x80; 639 - pmreg = 0x80; 640 - cr63 = 0x40; 641 - break; 642 - case VESA_HSYNC_SUSPEND + 1: 643 - sr1 = 0x20; 644 - cr17 = 0x80; 645 - pmreg = 0x40; 646 - cr63 = 0x40; 647 - break; 648 - case VESA_POWERDOWN + 1: 649 - sr1 = 0x20; 650 - cr17 = 0x00; 651 - pmreg = 0xc0; 652 - cr63 = 0x40; 653 - break; 654 - default: 655 - mutex_unlock(&sisusb->lock); 656 - return -EINVAL; 657 - } 658 - 659 - sisusb_setidxregandor(sisusb, SISSR, 0x01, ~0x20, sr1); 660 - sisusb_setidxregandor(sisusb, SISCR, 0x17, 0x7f, cr17); 661 - sisusb_setidxregandor(sisusb, SISSR, 0x1f, 0x3f, pmreg); 662 - sisusb_setidxregandor(sisusb, SISCR, 0x63, 0xbf, cr63); 663 - 664 - } 665 - 666 - mutex_unlock(&sisusb->lock); 667 - 668 - return ret; 669 - } 670 - 671 - /* interface routine */ 672 - static void 673 - sisusbcon_scrolldelta(struct vc_data *c, int lines) 674 - { 675 - struct sisusb_usb_data *sisusb; 676 - 677 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 678 - if (!sisusb) 679 - return; 680 - 681 - /* sisusb->lock is down */ 682 - 683 - if (sisusb_is_inactive(c, sisusb)) { 684 - mutex_unlock(&sisusb->lock); 685 - return; 686 - } 687 - 688 - vc_scrolldelta_helper(c, lines, sisusb->con_rolled_over, 689 - (void *)sisusb->scrbuf, sisusb->scrbuf_size); 690 - 691 - sisusbcon_set_start_address(sisusb, c); 692 - 693 - mutex_unlock(&sisusb->lock); 694 - } 695 - 696 - /* Interface routine */ 697 - static void 698 - sisusbcon_cursor(struct vc_data *c, int mode) 699 - { 700 - struct sisusb_usb_data *sisusb; 701 - int from, to, baseline; 702 - 703 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 704 - if (!sisusb) 705 - return; 706 - 707 - /* sisusb->lock is down */ 708 - 709 - if (sisusb_is_inactive(c, sisusb)) { 710 - mutex_unlock(&sisusb->lock); 711 - return; 712 - } 713 - 714 - if (c->vc_origin != c->vc_visible_origin) { 715 - c->vc_visible_origin = c->vc_origin; 716 - sisusbcon_set_start_address(sisusb, c); 717 - } 718 - 719 - if (mode == CM_ERASE) { 720 - sisusb_setidxregor(sisusb, SISCR, 0x0a, 0x20); 721 - sisusb->sisusb_cursor_size_to = -1; 722 - mutex_unlock(&sisusb->lock); 723 - return; 724 - } 725 - 726 - sisusb_set_cursor(sisusb, (c->vc_pos - sisusb->scrbuf) / 2); 727 - 728 - baseline = c->vc_font.height - (c->vc_font.height < 10 ? 1 : 2); 729 - 730 - switch (CUR_SIZE(c->vc_cursor_type)) { 731 - case CUR_BLOCK: from = 1; 732 - to = c->vc_font.height; 733 - break; 734 - case CUR_TWO_THIRDS: from = c->vc_font.height / 3; 735 - to = baseline; 736 - break; 737 - case CUR_LOWER_HALF: from = c->vc_font.height / 2; 738 - to = baseline; 739 - break; 740 - case CUR_LOWER_THIRD: from = (c->vc_font.height * 2) / 3; 741 - to = baseline; 742 - break; 743 - case CUR_NONE: from = 31; 744 - to = 30; 745 - break; 746 - default: 747 - case CUR_UNDERLINE: from = baseline - 1; 748 - to = baseline; 749 - break; 750 - } 751 - 752 - if (sisusb->sisusb_cursor_size_from != from || 753 - sisusb->sisusb_cursor_size_to != to) { 754 - 755 - sisusb_setidxreg(sisusb, SISCR, 0x0a, from); 756 - sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0, to); 757 - 758 - sisusb->sisusb_cursor_size_from = from; 759 - sisusb->sisusb_cursor_size_to = to; 760 - } 761 - 762 - mutex_unlock(&sisusb->lock); 763 - } 764 - 765 - static bool 766 - sisusbcon_scroll_area(struct vc_data *c, struct sisusb_usb_data *sisusb, 767 - unsigned int t, unsigned int b, enum con_scroll dir, 768 - unsigned int lines) 769 - { 770 - int cols = sisusb->sisusb_num_columns; 771 - int length = ((b - t) * cols) * 2; 772 - u16 eattr = c->vc_video_erase_char; 773 - 774 - /* sisusb->lock is down */ 775 - 776 - /* Scroll an area which does not match the 777 - * visible screen's dimensions. This needs 778 - * to be done separately, as it does not 779 - * use hardware panning. 780 - */ 781 - 782 - switch (dir) { 783 - 784 - case SM_UP: 785 - memmove(sisusb_vaddr(sisusb, c, 0, t), 786 - sisusb_vaddr(sisusb, c, 0, t + lines), 787 - (b - t - lines) * cols * 2); 788 - sisusbcon_memsetw(sisusb_vaddr(sisusb, c, 0, b - lines), 789 - eattr, lines * cols * 2); 790 - break; 791 - 792 - case SM_DOWN: 793 - memmove(sisusb_vaddr(sisusb, c, 0, t + lines), 794 - sisusb_vaddr(sisusb, c, 0, t), 795 - (b - t - lines) * cols * 2); 796 - sisusbcon_memsetw(sisusb_vaddr(sisusb, c, 0, t), eattr, 797 - lines * cols * 2); 798 - break; 799 - } 800 - 801 - sisusb_copy_memory(sisusb, sisusb_vaddr(sisusb, c, 0, t), 802 - sisusb_haddr(sisusb, c, 0, t), length); 803 - 804 - mutex_unlock(&sisusb->lock); 805 - 806 - return true; 807 - } 808 - 809 - /* Interface routine */ 810 - static bool 811 - sisusbcon_scroll(struct vc_data *c, unsigned int t, unsigned int b, 812 - enum con_scroll dir, unsigned int lines) 813 - { 814 - struct sisusb_usb_data *sisusb; 815 - u16 eattr = c->vc_video_erase_char; 816 - int copyall = 0; 817 - unsigned long oldorigin; 818 - unsigned int delta = lines * c->vc_size_row; 819 - 820 - /* Returning != 0 means we have done the scrolling successfully. 821 - * Returning 0 makes vt do the scrolling on its own. 822 - * Note that con_scroll is only called if the console is 823 - * visible. In that case, the origin should be our buffer, 824 - * not the vt's private one. 825 - */ 826 - 827 - if (!lines) 828 - return true; 829 - 830 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 831 - if (!sisusb) 832 - return false; 833 - 834 - /* sisusb->lock is down */ 835 - 836 - if (sisusb_is_inactive(c, sisusb)) { 837 - mutex_unlock(&sisusb->lock); 838 - return false; 839 - } 840 - 841 - /* Special case */ 842 - if (t || b != c->vc_rows) 843 - return sisusbcon_scroll_area(c, sisusb, t, b, dir, lines); 844 - 845 - if (c->vc_origin != c->vc_visible_origin) { 846 - c->vc_visible_origin = c->vc_origin; 847 - sisusbcon_set_start_address(sisusb, c); 848 - } 849 - 850 - /* limit amount to maximum realistic size */ 851 - if (lines > c->vc_rows) 852 - lines = c->vc_rows; 853 - 854 - oldorigin = c->vc_origin; 855 - 856 - switch (dir) { 857 - 858 - case SM_UP: 859 - 860 - if (c->vc_scr_end + delta >= 861 - sisusb->scrbuf + sisusb->scrbuf_size) { 862 - memcpy((u16 *)sisusb->scrbuf, 863 - (u16 *)(oldorigin + delta), 864 - c->vc_screenbuf_size - delta); 865 - c->vc_origin = sisusb->scrbuf; 866 - sisusb->con_rolled_over = oldorigin - sisusb->scrbuf; 867 - copyall = 1; 868 - } else 869 - c->vc_origin += delta; 870 - 871 - sisusbcon_memsetw( 872 - (u16 *)(c->vc_origin + c->vc_screenbuf_size - delta), 873 - eattr, delta); 874 - 875 - break; 876 - 877 - case SM_DOWN: 878 - 879 - if (oldorigin - delta < sisusb->scrbuf) { 880 - memmove((void *)sisusb->scrbuf + sisusb->scrbuf_size - 881 - c->vc_screenbuf_size + delta, 882 - (u16 *)oldorigin, 883 - c->vc_screenbuf_size - delta); 884 - c->vc_origin = sisusb->scrbuf + 885 - sisusb->scrbuf_size - 886 - c->vc_screenbuf_size; 887 - sisusb->con_rolled_over = 0; 888 - copyall = 1; 889 - } else 890 - c->vc_origin -= delta; 891 - 892 - c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; 893 - 894 - scr_memsetw((u16 *)(c->vc_origin), eattr, delta); 895 - 896 - break; 897 - } 898 - 899 - if (copyall) 900 - sisusb_copy_memory(sisusb, 901 - (u8 *)c->vc_origin, 902 - sisusb_haddr(sisusb, c, 0, 0), 903 - c->vc_screenbuf_size); 904 - else if (dir == SM_UP) 905 - sisusb_copy_memory(sisusb, 906 - (u8 *)c->vc_origin + c->vc_screenbuf_size - delta, 907 - sisusb_haddr(sisusb, c, 0, 0) + 908 - c->vc_screenbuf_size - delta, 909 - delta); 910 - else 911 - sisusb_copy_memory(sisusb, 912 - (u8 *)c->vc_origin, 913 - sisusb_haddr(sisusb, c, 0, 0), 914 - delta); 915 - 916 - c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; 917 - c->vc_visible_origin = c->vc_origin; 918 - 919 - sisusbcon_set_start_address(sisusb, c); 920 - 921 - c->vc_pos = c->vc_pos - oldorigin + c->vc_origin; 922 - 923 - mutex_unlock(&sisusb->lock); 924 - 925 - return true; 926 - } 927 - 928 - /* Interface routine */ 929 - static int 930 - sisusbcon_set_origin(struct vc_data *c) 931 - { 932 - struct sisusb_usb_data *sisusb; 933 - 934 - /* Returning != 0 means we were successful. 935 - * Returning 0 will vt make to use its own 936 - * screenbuffer as the origin. 937 - */ 938 - 939 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 940 - if (!sisusb) 941 - return 0; 942 - 943 - /* sisusb->lock is down */ 944 - 945 - if (sisusb_is_inactive(c, sisusb) || sisusb->con_blanked) { 946 - mutex_unlock(&sisusb->lock); 947 - return 0; 948 - } 949 - 950 - c->vc_origin = c->vc_visible_origin = sisusb->scrbuf; 951 - 952 - sisusbcon_set_start_address(sisusb, c); 953 - 954 - sisusb->con_rolled_over = 0; 955 - 956 - mutex_unlock(&sisusb->lock); 957 - 958 - return true; 959 - } 960 - 961 - /* Interface routine */ 962 - static int 963 - sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows, 964 - unsigned int user) 965 - { 966 - struct sisusb_usb_data *sisusb; 967 - int fh; 968 - 969 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 970 - if (!sisusb) 971 - return -ENODEV; 972 - 973 - fh = sisusb->current_font_height; 974 - 975 - mutex_unlock(&sisusb->lock); 976 - 977 - /* We are quite unflexible as regards resizing. The vt code 978 - * handles sizes where the line length isn't equal the pitch 979 - * quite badly. As regards the rows, our panning tricks only 980 - * work well if the number of rows equals the visible number 981 - * of rows. 982 - */ 983 - 984 - if (newcols != 80 || c->vc_scan_lines / fh != newrows) 985 - return -EINVAL; 986 - 987 - return 0; 988 - } 989 - 990 - int 991 - sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot, 992 - u8 *arg, int cmapsz, int ch512, int dorecalc, 993 - struct vc_data *c, int fh, int uplock) 994 - { 995 - int font_select = 0x00, i, err = 0; 996 - u32 offset = 0; 997 - u8 dummy; 998 - 999 - /* sisusb->lock is down */ 1000 - 1001 - /* 1002 - * The default font is kept in slot 0. 1003 - * A user font is loaded in slot 2 (256 ch) 1004 - * or 2+3 (512 ch). 1005 - */ 1006 - 1007 - if ((slot != 0 && slot != 2) || !fh) { 1008 - if (uplock) 1009 - mutex_unlock(&sisusb->lock); 1010 - return -EINVAL; 1011 - } 1012 - 1013 - if (set) 1014 - sisusb->font_slot = slot; 1015 - 1016 - /* Default font is always 256 */ 1017 - if (slot == 0) 1018 - ch512 = 0; 1019 - else 1020 - offset = 4 * cmapsz; 1021 - 1022 - font_select = (slot == 0) ? 0x00 : (ch512 ? 0x0e : 0x0a); 1023 - 1024 - err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */ 1025 - err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x04); /* Write to plane 2 */ 1026 - err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x07); /* Memory mode a0-bf */ 1027 - err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset */ 1028 - 1029 - if (err) 1030 - goto font_op_error; 1031 - 1032 - err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x03); /* Select plane read 2 */ 1033 - err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x00); /* Disable odd/even */ 1034 - err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x00); /* Address range a0-bf */ 1035 - 1036 - if (err) 1037 - goto font_op_error; 1038 - 1039 - if (arg) { 1040 - if (set) 1041 - for (i = 0; i < cmapsz; i++) { 1042 - err |= sisusb_writeb(sisusb, 1043 - sisusb->vrambase + offset + i, 1044 - arg[i]); 1045 - if (err) 1046 - break; 1047 - } 1048 - else 1049 - for (i = 0; i < cmapsz; i++) { 1050 - err |= sisusb_readb(sisusb, 1051 - sisusb->vrambase + offset + i, 1052 - &arg[i]); 1053 - if (err) 1054 - break; 1055 - } 1056 - 1057 - /* 1058 - * In 512-character mode, the character map is not contiguous if 1059 - * we want to remain EGA compatible -- which we do 1060 - */ 1061 - 1062 - if (ch512) { 1063 - if (set) 1064 - for (i = 0; i < cmapsz; i++) { 1065 - err |= sisusb_writeb(sisusb, 1066 - sisusb->vrambase + offset + 1067 - (2 * cmapsz) + i, 1068 - arg[cmapsz + i]); 1069 - if (err) 1070 - break; 1071 - } 1072 - else 1073 - for (i = 0; i < cmapsz; i++) { 1074 - err |= sisusb_readb(sisusb, 1075 - sisusb->vrambase + offset + 1076 - (2 * cmapsz) + i, 1077 - &arg[cmapsz + i]); 1078 - if (err) 1079 - break; 1080 - } 1081 - } 1082 - } 1083 - 1084 - if (err) 1085 - goto font_op_error; 1086 - 1087 - err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */ 1088 - err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x03); /* Write to planes 0+1 */ 1089 - err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x03); /* Memory mode a0-bf */ 1090 - if (set) 1091 - sisusb_setidxreg(sisusb, SISSR, 0x03, font_select); 1092 - err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset end */ 1093 - 1094 - if (err) 1095 - goto font_op_error; 1096 - 1097 - err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x00); /* Select plane read 0 */ 1098 - err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x10); /* Enable odd/even */ 1099 - err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x06); /* Address range b8-bf */ 1100 - 1101 - if (err) 1102 - goto font_op_error; 1103 - 1104 - if ((set) && (ch512 != sisusb->current_font_512)) { 1105 - 1106 - /* Font is shared among all our consoles. 1107 - * And so is the hi_font_mask. 1108 - */ 1109 - for (i = 0; i < MAX_NR_CONSOLES; i++) { 1110 - struct vc_data *d = vc_cons[i].d; 1111 - if (d && d->vc_sw == &sisusb_con) 1112 - d->vc_hi_font_mask = ch512 ? 0x0800 : 0; 1113 - } 1114 - 1115 - sisusb->current_font_512 = ch512; 1116 - 1117 - /* color plane enable register: 1118 - 256-char: enable intensity bit 1119 - 512-char: disable intensity bit */ 1120 - sisusb_getreg(sisusb, SISINPSTAT, &dummy); 1121 - sisusb_setreg(sisusb, SISAR, 0x12); 1122 - sisusb_setreg(sisusb, SISAR, ch512 ? 0x07 : 0x0f); 1123 - 1124 - sisusb_getreg(sisusb, SISINPSTAT, &dummy); 1125 - sisusb_setreg(sisusb, SISAR, 0x20); 1126 - sisusb_getreg(sisusb, SISINPSTAT, &dummy); 1127 - } 1128 - 1129 - if (dorecalc) { 1130 - 1131 - /* 1132 - * Adjust the screen to fit a font of a certain height 1133 - */ 1134 - 1135 - unsigned char ovr, vde, fsr; 1136 - int rows = 0, maxscan = 0; 1137 - 1138 - if (c) { 1139 - 1140 - /* Number of video rows */ 1141 - rows = c->vc_scan_lines / fh; 1142 - /* Scan lines to actually display-1 */ 1143 - maxscan = rows * fh - 1; 1144 - 1145 - /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n", 1146 - rows, maxscan, fh, c->vc_scan_lines);*/ 1147 - 1148 - sisusb_getidxreg(sisusb, SISCR, 0x07, &ovr); 1149 - vde = maxscan & 0xff; 1150 - ovr = (ovr & 0xbd) | 1151 - ((maxscan & 0x100) >> 7) | 1152 - ((maxscan & 0x200) >> 3); 1153 - sisusb_setidxreg(sisusb, SISCR, 0x07, ovr); 1154 - sisusb_setidxreg(sisusb, SISCR, 0x12, vde); 1155 - 1156 - } 1157 - 1158 - sisusb_getidxreg(sisusb, SISCR, 0x09, &fsr); 1159 - fsr = (fsr & 0xe0) | (fh - 1); 1160 - sisusb_setidxreg(sisusb, SISCR, 0x09, fsr); 1161 - sisusb->current_font_height = fh; 1162 - 1163 - sisusb->sisusb_cursor_size_from = -1; 1164 - sisusb->sisusb_cursor_size_to = -1; 1165 - 1166 - } 1167 - 1168 - if (uplock) 1169 - mutex_unlock(&sisusb->lock); 1170 - 1171 - if (dorecalc && c) { 1172 - int rows = c->vc_scan_lines / fh; 1173 - 1174 - /* Now adjust our consoles' size */ 1175 - 1176 - for (i = 0; i < MAX_NR_CONSOLES; i++) { 1177 - struct vc_data *vc = vc_cons[i].d; 1178 - 1179 - if (vc && vc->vc_sw == &sisusb_con) { 1180 - if (con_is_visible(vc)) { 1181 - vc->vc_sw->con_cursor(vc, CM_DRAW); 1182 - } 1183 - vc->vc_font.height = fh; 1184 - vc_resize(vc, 0, rows); 1185 - } 1186 - } 1187 - } 1188 - 1189 - return 0; 1190 - 1191 - font_op_error: 1192 - if (uplock) 1193 - mutex_unlock(&sisusb->lock); 1194 - 1195 - return -EIO; 1196 - } 1197 - 1198 - /* Interface routine */ 1199 - static int 1200 - sisusbcon_font_set(struct vc_data *c, struct console_font *font, 1201 - unsigned int flags) 1202 - { 1203 - struct sisusb_usb_data *sisusb; 1204 - unsigned charcount = font->charcount; 1205 - 1206 - if (font->width != 8 || (charcount != 256 && charcount != 512)) 1207 - return -EINVAL; 1208 - 1209 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 1210 - if (!sisusb) 1211 - return -ENODEV; 1212 - 1213 - /* sisusb->lock is down */ 1214 - 1215 - /* Save the user-provided font into a buffer. This 1216 - * is used for restoring text mode after quitting 1217 - * from X and for the con_getfont routine. 1218 - */ 1219 - if (sisusb->font_backup) { 1220 - if (sisusb->font_backup_size < charcount) { 1221 - vfree(sisusb->font_backup); 1222 - sisusb->font_backup = NULL; 1223 - } 1224 - } 1225 - 1226 - if (!sisusb->font_backup) 1227 - sisusb->font_backup = vmalloc(array_size(charcount, 32)); 1228 - 1229 - if (sisusb->font_backup) { 1230 - memcpy(sisusb->font_backup, font->data, array_size(charcount, 32)); 1231 - sisusb->font_backup_size = charcount; 1232 - sisusb->font_backup_height = font->height; 1233 - sisusb->font_backup_512 = (charcount == 512) ? 1 : 0; 1234 - } 1235 - 1236 - /* do_font_op ups sisusb->lock */ 1237 - 1238 - return sisusbcon_do_font_op(sisusb, 1, 2, font->data, 1239 - 8192, (charcount == 512), 1240 - (!(flags & KD_FONT_FLAG_DONT_RECALC)) ? 1 : 0, 1241 - c, font->height, 1); 1242 - } 1243 - 1244 - /* Interface routine */ 1245 - static int 1246 - sisusbcon_font_get(struct vc_data *c, struct console_font *font) 1247 - { 1248 - struct sisusb_usb_data *sisusb; 1249 - 1250 - sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num); 1251 - if (!sisusb) 1252 - return -ENODEV; 1253 - 1254 - /* sisusb->lock is down */ 1255 - 1256 - font->width = 8; 1257 - font->height = c->vc_font.height; 1258 - font->charcount = 256; 1259 - 1260 - if (!font->data) { 1261 - mutex_unlock(&sisusb->lock); 1262 - return 0; 1263 - } 1264 - 1265 - if (!sisusb->font_backup) { 1266 - mutex_unlock(&sisusb->lock); 1267 - return -ENODEV; 1268 - } 1269 - 1270 - /* Copy 256 chars only, like vgacon */ 1271 - memcpy(font->data, sisusb->font_backup, 256 * 32); 1272 - 1273 - mutex_unlock(&sisusb->lock); 1274 - 1275 - return 0; 1276 - } 1277 - 1278 - /* 1279 - * The console `switch' structure for the sisusb console 1280 - */ 1281 - 1282 - static const struct consw sisusb_con = { 1283 - .owner = THIS_MODULE, 1284 - .con_startup = sisusbcon_startup, 1285 - .con_init = sisusbcon_init, 1286 - .con_deinit = sisusbcon_deinit, 1287 - .con_clear = sisusbcon_clear, 1288 - .con_putc = sisusbcon_putc, 1289 - .con_putcs = sisusbcon_putcs, 1290 - .con_cursor = sisusbcon_cursor, 1291 - .con_scroll = sisusbcon_scroll, 1292 - .con_switch = sisusbcon_switch, 1293 - .con_blank = sisusbcon_blank, 1294 - .con_font_set = sisusbcon_font_set, 1295 - .con_font_get = sisusbcon_font_get, 1296 - .con_set_palette = sisusbcon_set_palette, 1297 - .con_scrolldelta = sisusbcon_scrolldelta, 1298 - .con_build_attr = sisusbcon_build_attr, 1299 - .con_invert_region = sisusbcon_invert_region, 1300 - .con_set_origin = sisusbcon_set_origin, 1301 - .con_save_screen = sisusbcon_save_screen, 1302 - .con_resize = sisusbcon_resize, 1303 - }; 1304 - 1305 - /* Our very own dummy console driver */ 1306 - 1307 - static const char *sisusbdummycon_startup(void) 1308 - { 1309 - return "SISUSBVGADUMMY"; 1310 - } 1311 - 1312 - static void sisusbdummycon_init(struct vc_data *vc, int init) 1313 - { 1314 - vc->vc_can_do_color = 1; 1315 - if (init) { 1316 - vc->vc_cols = 80; 1317 - vc->vc_rows = 25; 1318 - } else 1319 - vc_resize(vc, 80, 25); 1320 - } 1321 - 1322 - static void sisusbdummycon_deinit(struct vc_data *vc) { } 1323 - static void sisusbdummycon_clear(struct vc_data *vc, int sy, int sx, 1324 - int height, int width) { } 1325 - static void sisusbdummycon_putc(struct vc_data *vc, int c, int ypos, 1326 - int xpos) { } 1327 - static void sisusbdummycon_putcs(struct vc_data *vc, const unsigned short *s, 1328 - int count, int ypos, int xpos) { } 1329 - static void sisusbdummycon_cursor(struct vc_data *vc, int mode) { } 1330 - 1331 - static bool sisusbdummycon_scroll(struct vc_data *vc, unsigned int top, 1332 - unsigned int bottom, enum con_scroll dir, 1333 - unsigned int lines) 1334 - { 1335 - return false; 1336 - } 1337 - 1338 - static int sisusbdummycon_switch(struct vc_data *vc) 1339 - { 1340 - return 0; 1341 - } 1342 - 1343 - static int sisusbdummycon_blank(struct vc_data *vc, int blank, int mode_switch) 1344 - { 1345 - return 0; 1346 - } 1347 - 1348 - static const struct consw sisusb_dummy_con = { 1349 - .owner = THIS_MODULE, 1350 - .con_startup = sisusbdummycon_startup, 1351 - .con_init = sisusbdummycon_init, 1352 - .con_deinit = sisusbdummycon_deinit, 1353 - .con_clear = sisusbdummycon_clear, 1354 - .con_putc = sisusbdummycon_putc, 1355 - .con_putcs = sisusbdummycon_putcs, 1356 - .con_cursor = sisusbdummycon_cursor, 1357 - .con_scroll = sisusbdummycon_scroll, 1358 - .con_switch = sisusbdummycon_switch, 1359 - .con_blank = sisusbdummycon_blank, 1360 - }; 1361 - 1362 - int 1363 - sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last) 1364 - { 1365 - int i, ret; 1366 - 1367 - mutex_lock(&sisusb->lock); 1368 - 1369 - /* Erm.. that should not happen */ 1370 - if (sisusb->haveconsole || !sisusb->SiS_Pr) { 1371 - mutex_unlock(&sisusb->lock); 1372 - return 1; 1373 - } 1374 - 1375 - sisusb->con_first = first; 1376 - sisusb->con_last = last; 1377 - 1378 - if (first > last || 1379 - first > MAX_NR_CONSOLES || 1380 - last > MAX_NR_CONSOLES) { 1381 - mutex_unlock(&sisusb->lock); 1382 - return 1; 1383 - } 1384 - 1385 - /* If gfxcore not initialized or no consoles given, quit graciously */ 1386 - if (!sisusb->gfxinit || first < 1 || last < 1) { 1387 - mutex_unlock(&sisusb->lock); 1388 - return 0; 1389 - } 1390 - 1391 - sisusb->sisusb_cursor_loc = -1; 1392 - sisusb->sisusb_cursor_size_from = -1; 1393 - sisusb->sisusb_cursor_size_to = -1; 1394 - 1395 - /* Set up text mode (and upload default font) */ 1396 - if (sisusb_reset_text_mode(sisusb, 1)) { 1397 - mutex_unlock(&sisusb->lock); 1398 - dev_err(&sisusb->sisusb_dev->dev, "Failed to set up text mode\n"); 1399 - return 1; 1400 - } 1401 - 1402 - /* Initialize some gfx registers */ 1403 - sisusb_initialize(sisusb); 1404 - 1405 - for (i = first - 1; i <= last - 1; i++) { 1406 - /* Save sisusb for our interface routines */ 1407 - mysisusbs[i] = sisusb; 1408 - } 1409 - 1410 - /* Initial console setup */ 1411 - sisusb->sisusb_num_columns = 80; 1412 - 1413 - /* Use a 32K buffer (matches b8000-bffff area) */ 1414 - sisusb->scrbuf_size = 32 * 1024; 1415 - 1416 - /* Allocate screen buffer */ 1417 - if (!(sisusb->scrbuf = (unsigned long)vmalloc(sisusb->scrbuf_size))) { 1418 - mutex_unlock(&sisusb->lock); 1419 - dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate screen buffer\n"); 1420 - return 1; 1421 - } 1422 - 1423 - mutex_unlock(&sisusb->lock); 1424 - 1425 - /* Now grab the desired console(s) */ 1426 - console_lock(); 1427 - ret = do_take_over_console(&sisusb_con, first - 1, last - 1, 0); 1428 - console_unlock(); 1429 - if (!ret) 1430 - sisusb->haveconsole = 1; 1431 - else { 1432 - for (i = first - 1; i <= last - 1; i++) 1433 - mysisusbs[i] = NULL; 1434 - } 1435 - 1436 - return ret; 1437 - } 1438 - 1439 - void 1440 - sisusb_console_exit(struct sisusb_usb_data *sisusb) 1441 - { 1442 - int i; 1443 - 1444 - /* This is called if the device is disconnected 1445 - * and while disconnect and lock semaphores 1446 - * are up. This should be save because we 1447 - * can't lose our sisusb any other way but by 1448 - * disconnection (and hence, the disconnect 1449 - * sema is for protecting all other access 1450 - * functions from disconnection, not the 1451 - * other way round). 1452 - */ 1453 - 1454 - /* Now what do we do in case of disconnection: 1455 - * One alternative would be to simply call 1456 - * give_up_console(). Nah, not a good idea. 1457 - * give_up_console() is obviously buggy as it 1458 - * only discards the consw pointer from the 1459 - * driver_map, but doesn't adapt vc->vc_sw 1460 - * of the affected consoles. Hence, the next 1461 - * call to any of the console functions will 1462 - * eventually take a trip to oops county. 1463 - * Also, give_up_console for some reason 1464 - * doesn't decrement our module refcount. 1465 - * Instead, we switch our consoles to a private 1466 - * dummy console. This, of course, keeps our 1467 - * refcount up as well, but it works perfectly. 1468 - */ 1469 - 1470 - if (sisusb->haveconsole) { 1471 - for (i = 0; i < MAX_NR_CONSOLES; i++) 1472 - if (sisusb->havethisconsole[i]) { 1473 - console_lock(); 1474 - do_take_over_console(&sisusb_dummy_con, i, i, 0); 1475 - console_unlock(); 1476 - /* At this point, con_deinit for all our 1477 - * consoles is executed by do_take_over_console(). 1478 - */ 1479 - } 1480 - sisusb->haveconsole = 0; 1481 - } 1482 - 1483 - vfree((void *)sisusb->scrbuf); 1484 - sisusb->scrbuf = 0; 1485 - 1486 - vfree(sisusb->font_backup); 1487 - sisusb->font_backup = NULL; 1488 - } 1489 - 1490 - void __init sisusb_init_concode(void) 1491 - { 1492 - int i; 1493 - 1494 - for (i = 0; i < MAX_NR_CONSOLES; i++) 1495 - mysisusbs[i] = NULL; 1496 - }
-955
drivers/usb/misc/sisusbvga/sisusb_init.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 2 - /* 3 - * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles 4 - * 5 - * Display mode initializing code 6 - * 7 - * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria 8 - * 9 - * If distributed as part of the Linux kernel, this code is licensed under the 10 - * terms of the GPL v2. 11 - * 12 - * Otherwise, the following license terms apply: 13 - * 14 - * * Redistribution and use in source and binary forms, with or without 15 - * * modification, are permitted provided that the following conditions 16 - * * are met: 17 - * * 1) Redistributions of source code must retain the above copyright 18 - * * notice, this list of conditions and the following disclaimer. 19 - * * 2) Redistributions in binary form must reproduce the above copyright 20 - * * notice, this list of conditions and the following disclaimer in the 21 - * * documentation and/or other materials provided with the distribution. 22 - * * 3) The name of the author may not be used to endorse or promote products 23 - * * derived from this software without specific prior written permission. 24 - * * 25 - * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 26 - * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 - * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 - * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 29 - * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 - * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 - * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 - * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 - * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 - * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 - * 36 - * Author: Thomas Winischhofer <thomas@winischhofer.net> 37 - * 38 - */ 39 - 40 - #include <linux/module.h> 41 - #include <linux/kernel.h> 42 - #include <linux/errno.h> 43 - #include <linux/poll.h> 44 - #include <linux/spinlock.h> 45 - 46 - #include "sisusb.h" 47 - #include "sisusb_init.h" 48 - #include "sisusb_tables.h" 49 - 50 - /*********************************************/ 51 - /* POINTER INITIALIZATION */ 52 - /*********************************************/ 53 - 54 - static void SiSUSB_InitPtr(struct SiS_Private *SiS_Pr) 55 - { 56 - SiS_Pr->SiS_ModeResInfo = SiSUSB_ModeResInfo; 57 - SiS_Pr->SiS_StandTable = SiSUSB_StandTable; 58 - 59 - SiS_Pr->SiS_SModeIDTable = SiSUSB_SModeIDTable; 60 - SiS_Pr->SiS_EModeIDTable = SiSUSB_EModeIDTable; 61 - SiS_Pr->SiS_RefIndex = SiSUSB_RefIndex; 62 - SiS_Pr->SiS_CRT1Table = SiSUSB_CRT1Table; 63 - 64 - SiS_Pr->SiS_VCLKData = SiSUSB_VCLKData; 65 - } 66 - 67 - /*********************************************/ 68 - /* HELPER: SetReg, GetReg */ 69 - /*********************************************/ 70 - 71 - static void 72 - SiS_SetReg(struct SiS_Private *SiS_Pr, unsigned long port, 73 - unsigned short index, unsigned short data) 74 - { 75 - sisusb_setidxreg(SiS_Pr->sisusb, port, index, data); 76 - } 77 - 78 - static void 79 - SiS_SetRegByte(struct SiS_Private *SiS_Pr, unsigned long port, 80 - unsigned short data) 81 - { 82 - sisusb_setreg(SiS_Pr->sisusb, port, data); 83 - } 84 - 85 - static unsigned char 86 - SiS_GetReg(struct SiS_Private *SiS_Pr, unsigned long port, unsigned short index) 87 - { 88 - u8 data; 89 - 90 - sisusb_getidxreg(SiS_Pr->sisusb, port, index, &data); 91 - 92 - return data; 93 - } 94 - 95 - static unsigned char 96 - SiS_GetRegByte(struct SiS_Private *SiS_Pr, unsigned long port) 97 - { 98 - u8 data; 99 - 100 - sisusb_getreg(SiS_Pr->sisusb, port, &data); 101 - 102 - return data; 103 - } 104 - 105 - static void 106 - SiS_SetRegANDOR(struct SiS_Private *SiS_Pr, unsigned long port, 107 - unsigned short index, unsigned short DataAND, 108 - unsigned short DataOR) 109 - { 110 - sisusb_setidxregandor(SiS_Pr->sisusb, port, index, DataAND, DataOR); 111 - } 112 - 113 - static void 114 - SiS_SetRegAND(struct SiS_Private *SiS_Pr, unsigned long port, 115 - unsigned short index, unsigned short DataAND) 116 - { 117 - sisusb_setidxregand(SiS_Pr->sisusb, port, index, DataAND); 118 - } 119 - 120 - static void 121 - SiS_SetRegOR(struct SiS_Private *SiS_Pr, unsigned long port, 122 - unsigned short index, unsigned short DataOR) 123 - { 124 - sisusb_setidxregor(SiS_Pr->sisusb, port, index, DataOR); 125 - } 126 - 127 - /*********************************************/ 128 - /* HELPER: DisplayOn, DisplayOff */ 129 - /*********************************************/ 130 - 131 - static void SiS_DisplayOn(struct SiS_Private *SiS_Pr) 132 - { 133 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x01, 0xDF); 134 - } 135 - 136 - /*********************************************/ 137 - /* HELPER: Init Port Addresses */ 138 - /*********************************************/ 139 - 140 - static void SiSUSBRegInit(struct SiS_Private *SiS_Pr, unsigned long BaseAddr) 141 - { 142 - SiS_Pr->SiS_P3c4 = BaseAddr + 0x14; 143 - SiS_Pr->SiS_P3d4 = BaseAddr + 0x24; 144 - SiS_Pr->SiS_P3c0 = BaseAddr + 0x10; 145 - SiS_Pr->SiS_P3ce = BaseAddr + 0x1e; 146 - SiS_Pr->SiS_P3c2 = BaseAddr + 0x12; 147 - SiS_Pr->SiS_P3ca = BaseAddr + 0x1a; 148 - SiS_Pr->SiS_P3c6 = BaseAddr + 0x16; 149 - SiS_Pr->SiS_P3c7 = BaseAddr + 0x17; 150 - SiS_Pr->SiS_P3c8 = BaseAddr + 0x18; 151 - SiS_Pr->SiS_P3c9 = BaseAddr + 0x19; 152 - SiS_Pr->SiS_P3cb = BaseAddr + 0x1b; 153 - SiS_Pr->SiS_P3cc = BaseAddr + 0x1c; 154 - SiS_Pr->SiS_P3cd = BaseAddr + 0x1d; 155 - SiS_Pr->SiS_P3da = BaseAddr + 0x2a; 156 - SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04; 157 - } 158 - 159 - /*********************************************/ 160 - /* HELPER: GetSysFlags */ 161 - /*********************************************/ 162 - 163 - static void SiS_GetSysFlags(struct SiS_Private *SiS_Pr) 164 - { 165 - SiS_Pr->SiS_MyCR63 = 0x63; 166 - } 167 - 168 - /*********************************************/ 169 - /* HELPER: Init PCI & Engines */ 170 - /*********************************************/ 171 - 172 - static void SiSInitPCIetc(struct SiS_Private *SiS_Pr) 173 - { 174 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x20, 0xa1); 175 - /* - Enable 2D (0x40) 176 - * - Enable 3D (0x02) 177 - * - Enable 3D vertex command fetch (0x10) 178 - * - Enable 3D command parser (0x08) 179 - * - Enable 3D G/L transformation engine (0x80) 180 - */ 181 - SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1E, 0xDA); 182 - } 183 - 184 - /*********************************************/ 185 - /* HELPER: SET SEGMENT REGISTERS */ 186 - /*********************************************/ 187 - 188 - static void SiS_SetSegRegLower(struct SiS_Private *SiS_Pr, unsigned short value) 189 - { 190 - unsigned short temp; 191 - 192 - value &= 0x00ff; 193 - temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb) & 0xf0; 194 - temp |= (value >> 4); 195 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb, temp); 196 - temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd) & 0xf0; 197 - temp |= (value & 0x0f); 198 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd, temp); 199 - } 200 - 201 - static void SiS_SetSegRegUpper(struct SiS_Private *SiS_Pr, unsigned short value) 202 - { 203 - unsigned short temp; 204 - 205 - value &= 0x00ff; 206 - temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb) & 0x0f; 207 - temp |= (value & 0xf0); 208 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb, temp); 209 - temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd) & 0x0f; 210 - temp |= (value << 4); 211 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd, temp); 212 - } 213 - 214 - static void SiS_SetSegmentReg(struct SiS_Private *SiS_Pr, unsigned short value) 215 - { 216 - SiS_SetSegRegLower(SiS_Pr, value); 217 - SiS_SetSegRegUpper(SiS_Pr, value); 218 - } 219 - 220 - static void SiS_ResetSegmentReg(struct SiS_Private *SiS_Pr) 221 - { 222 - SiS_SetSegmentReg(SiS_Pr, 0); 223 - } 224 - 225 - static void 226 - SiS_SetSegmentRegOver(struct SiS_Private *SiS_Pr, unsigned short value) 227 - { 228 - unsigned short temp = value >> 8; 229 - 230 - temp &= 0x07; 231 - temp |= (temp << 4); 232 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1d, temp); 233 - SiS_SetSegmentReg(SiS_Pr, value); 234 - } 235 - 236 - static void SiS_ResetSegmentRegOver(struct SiS_Private *SiS_Pr) 237 - { 238 - SiS_SetSegmentRegOver(SiS_Pr, 0); 239 - } 240 - 241 - static void SiS_ResetSegmentRegisters(struct SiS_Private *SiS_Pr) 242 - { 243 - SiS_ResetSegmentReg(SiS_Pr); 244 - SiS_ResetSegmentRegOver(SiS_Pr); 245 - } 246 - 247 - /*********************************************/ 248 - /* HELPER: SearchModeID */ 249 - /*********************************************/ 250 - 251 - static int 252 - SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo, 253 - unsigned short *ModeIdIndex) 254 - { 255 - if ((*ModeNo) <= 0x13) { 256 - 257 - if ((*ModeNo) != 0x03) 258 - return 0; 259 - 260 - (*ModeIdIndex) = 0; 261 - 262 - } else { 263 - 264 - for (*ModeIdIndex = 0;; (*ModeIdIndex)++) { 265 - 266 - if (SiS_Pr->SiS_EModeIDTable[*ModeIdIndex].Ext_ModeID == 267 - (*ModeNo)) 268 - break; 269 - 270 - if (SiS_Pr->SiS_EModeIDTable[*ModeIdIndex].Ext_ModeID == 271 - 0xFF) 272 - return 0; 273 - } 274 - 275 - } 276 - 277 - return 1; 278 - } 279 - 280 - /*********************************************/ 281 - /* HELPER: ENABLE CRT1 */ 282 - /*********************************************/ 283 - 284 - static void SiS_HandleCRT1(struct SiS_Private *SiS_Pr) 285 - { 286 - /* Enable CRT1 gating */ 287 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3d4, SiS_Pr->SiS_MyCR63, 0xbf); 288 - } 289 - 290 - /*********************************************/ 291 - /* HELPER: GetColorDepth */ 292 - /*********************************************/ 293 - 294 - static unsigned short 295 - SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 296 - unsigned short ModeIdIndex) 297 - { 298 - static const unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 }; 299 - unsigned short modeflag; 300 - short index; 301 - 302 - if (ModeNo <= 0x13) { 303 - modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 304 - } else { 305 - modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 306 - } 307 - 308 - index = (modeflag & ModeTypeMask) - ModeEGA; 309 - if (index < 0) 310 - index = 0; 311 - return ColorDepth[index]; 312 - } 313 - 314 - /*********************************************/ 315 - /* HELPER: GetOffset */ 316 - /*********************************************/ 317 - 318 - static unsigned short 319 - SiS_GetOffset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 320 - unsigned short ModeIdIndex, unsigned short rrti) 321 - { 322 - unsigned short xres, temp, colordepth, infoflag; 323 - 324 - infoflag = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag; 325 - xres = SiS_Pr->SiS_RefIndex[rrti].XRes; 326 - 327 - colordepth = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex); 328 - 329 - temp = xres / 16; 330 - 331 - if (infoflag & InterlaceMode) 332 - temp <<= 1; 333 - 334 - temp *= colordepth; 335 - 336 - if (xres % 16) 337 - temp += (colordepth >> 1); 338 - 339 - return temp; 340 - } 341 - 342 - /*********************************************/ 343 - /* SEQ */ 344 - /*********************************************/ 345 - 346 - static void 347 - SiS_SetSeqRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex) 348 - { 349 - unsigned char SRdata; 350 - int i; 351 - 352 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x00, 0x03); 353 - 354 - SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[0] | 0x20; 355 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x01, SRdata); 356 - 357 - for (i = 2; i <= 4; i++) { 358 - SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[i - 1]; 359 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, i, SRdata); 360 - } 361 - } 362 - 363 - /*********************************************/ 364 - /* MISC */ 365 - /*********************************************/ 366 - 367 - static void 368 - SiS_SetMiscRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex) 369 - { 370 - unsigned char Miscdata = SiS_Pr->SiS_StandTable[StandTableIndex].MISC; 371 - 372 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c2, Miscdata); 373 - } 374 - 375 - /*********************************************/ 376 - /* CRTC */ 377 - /*********************************************/ 378 - 379 - static void 380 - SiS_SetCRTCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex) 381 - { 382 - unsigned char CRTCdata; 383 - unsigned short i; 384 - 385 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3d4, 0x11, 0x7f); 386 - 387 - for (i = 0; i <= 0x18; i++) { 388 - CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i]; 389 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, i, CRTCdata); 390 - } 391 - } 392 - 393 - /*********************************************/ 394 - /* ATT */ 395 - /*********************************************/ 396 - 397 - static void 398 - SiS_SetATTRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex) 399 - { 400 - unsigned char ARdata; 401 - unsigned short i; 402 - 403 - for (i = 0; i <= 0x13; i++) { 404 - ARdata = SiS_Pr->SiS_StandTable[StandTableIndex].ATTR[i]; 405 - SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da); 406 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, i); 407 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, ARdata); 408 - } 409 - SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da); 410 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, 0x14); 411 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, 0x00); 412 - 413 - SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da); 414 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, 0x20); 415 - SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da); 416 - } 417 - 418 - /*********************************************/ 419 - /* GRC */ 420 - /*********************************************/ 421 - 422 - static void 423 - SiS_SetGRCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex) 424 - { 425 - unsigned char GRdata; 426 - unsigned short i; 427 - 428 - for (i = 0; i <= 0x08; i++) { 429 - GRdata = SiS_Pr->SiS_StandTable[StandTableIndex].GRC[i]; 430 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3ce, i, GRdata); 431 - } 432 - 433 - if (SiS_Pr->SiS_ModeType > ModeVGA) { 434 - /* 256 color disable */ 435 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3ce, 0x05, 0xBF); 436 - } 437 - } 438 - 439 - /*********************************************/ 440 - /* CLEAR EXTENDED REGISTERS */ 441 - /*********************************************/ 442 - 443 - static void SiS_ClearExt1Regs(struct SiS_Private *SiS_Pr, unsigned short ModeNo) 444 - { 445 - int i; 446 - 447 - for (i = 0x0A; i <= 0x0E; i++) { 448 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, i, 0x00); 449 - } 450 - 451 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x37, 0xFE); 452 - } 453 - 454 - /*********************************************/ 455 - /* Get rate index */ 456 - /*********************************************/ 457 - 458 - static unsigned short 459 - SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 460 - unsigned short ModeIdIndex) 461 - { 462 - unsigned short rrti, i, index, temp; 463 - 464 - if (ModeNo <= 0x13) 465 - return 0xFFFF; 466 - 467 - index = SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x33) & 0x0F; 468 - if (index > 0) 469 - index--; 470 - 471 - rrti = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; 472 - ModeNo = SiS_Pr->SiS_RefIndex[rrti].ModeID; 473 - 474 - i = 0; 475 - do { 476 - if (SiS_Pr->SiS_RefIndex[rrti + i].ModeID != ModeNo) 477 - break; 478 - 479 - temp = 480 - SiS_Pr->SiS_RefIndex[rrti + i].Ext_InfoFlag & ModeTypeMask; 481 - if (temp < SiS_Pr->SiS_ModeType) 482 - break; 483 - 484 - i++; 485 - index--; 486 - } while (index != 0xFFFF); 487 - 488 - i--; 489 - 490 - return (rrti + i); 491 - } 492 - 493 - /*********************************************/ 494 - /* SYNC */ 495 - /*********************************************/ 496 - 497 - static void SiS_SetCRT1Sync(struct SiS_Private *SiS_Pr, unsigned short rrti) 498 - { 499 - unsigned short sync = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag >> 8; 500 - sync &= 0xC0; 501 - sync |= 0x2f; 502 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c2, sync); 503 - } 504 - 505 - /*********************************************/ 506 - /* CRTC/2 */ 507 - /*********************************************/ 508 - 509 - static void 510 - SiS_SetCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 511 - unsigned short ModeIdIndex, unsigned short rrti) 512 - { 513 - unsigned char index; 514 - unsigned short temp, i, j, modeflag; 515 - 516 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3d4, 0x11, 0x7f); 517 - 518 - modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 519 - 520 - index = SiS_Pr->SiS_RefIndex[rrti].Ext_CRT1CRTC; 521 - 522 - for (i = 0, j = 0; i <= 7; i++, j++) { 523 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, j, 524 - SiS_Pr->SiS_CRT1Table[index].CR[i]); 525 - } 526 - for (j = 0x10; i <= 10; i++, j++) { 527 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, j, 528 - SiS_Pr->SiS_CRT1Table[index].CR[i]); 529 - } 530 - for (j = 0x15; i <= 12; i++, j++) { 531 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, j, 532 - SiS_Pr->SiS_CRT1Table[index].CR[i]); 533 - } 534 - for (j = 0x0A; i <= 15; i++, j++) { 535 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, j, 536 - SiS_Pr->SiS_CRT1Table[index].CR[i]); 537 - } 538 - 539 - temp = SiS_Pr->SiS_CRT1Table[index].CR[16] & 0xE0; 540 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0E, temp); 541 - 542 - temp = ((SiS_Pr->SiS_CRT1Table[index].CR[16]) & 0x01) << 5; 543 - if (modeflag & DoubleScanMode) 544 - temp |= 0x80; 545 - SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3d4, 0x09, 0x5F, temp); 546 - 547 - if (SiS_Pr->SiS_ModeType > ModeVGA) 548 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x14, 0x4F); 549 - } 550 - 551 - /*********************************************/ 552 - /* OFFSET & PITCH */ 553 - /*********************************************/ 554 - /* (partly overruled by SetPitch() in XF86) */ 555 - /*********************************************/ 556 - 557 - static void 558 - SiS_SetCRT1Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 559 - unsigned short ModeIdIndex, unsigned short rrti) 560 - { 561 - unsigned short du = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, rrti); 562 - unsigned short infoflag = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag; 563 - unsigned short temp; 564 - 565 - temp = (du >> 8) & 0x0f; 566 - SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0E, 0xF0, temp); 567 - 568 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x13, (du & 0xFF)); 569 - 570 - if (infoflag & InterlaceMode) 571 - du >>= 1; 572 - 573 - du <<= 5; 574 - temp = (du >> 8) & 0xff; 575 - if (du & 0xff) 576 - temp++; 577 - temp++; 578 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x10, temp); 579 - } 580 - 581 - /*********************************************/ 582 - /* VCLK */ 583 - /*********************************************/ 584 - 585 - static void 586 - SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 587 - unsigned short rrti) 588 - { 589 - unsigned short index = SiS_Pr->SiS_RefIndex[rrti].Ext_CRTVCLK; 590 - unsigned short clka = SiS_Pr->SiS_VCLKData[index].SR2B; 591 - unsigned short clkb = SiS_Pr->SiS_VCLKData[index].SR2C; 592 - 593 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x31, 0xCF); 594 - 595 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x2B, clka); 596 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x2C, clkb); 597 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x2D, 0x01); 598 - } 599 - 600 - /*********************************************/ 601 - /* FIFO */ 602 - /*********************************************/ 603 - 604 - static void 605 - SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 606 - unsigned short mi) 607 - { 608 - unsigned short modeflag = SiS_Pr->SiS_EModeIDTable[mi].Ext_ModeFlag; 609 - 610 - /* disable auto-threshold */ 611 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x3D, 0xFE); 612 - 613 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x08, 0xAE); 614 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x09, 0xF0); 615 - 616 - if (ModeNo <= 0x13) 617 - return; 618 - 619 - if ((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) { 620 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x08, 0x34); 621 - SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x3D, 0x01); 622 - } 623 - } 624 - 625 - /*********************************************/ 626 - /* MODE REGISTERS */ 627 - /*********************************************/ 628 - 629 - static void 630 - SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 631 - unsigned short rrti) 632 - { 633 - unsigned short data = 0, VCLK = 0, index = 0; 634 - 635 - if (ModeNo > 0x13) { 636 - index = SiS_Pr->SiS_RefIndex[rrti].Ext_CRTVCLK; 637 - VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; 638 - } 639 - 640 - if (VCLK >= 166) 641 - data |= 0x0c; 642 - SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x32, 0xf3, data); 643 - 644 - if (VCLK >= 166) 645 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1f, 0xe7); 646 - 647 - /* DAC speed */ 648 - data = 0x03; 649 - if (VCLK >= 260) 650 - data = 0x00; 651 - else if (VCLK >= 160) 652 - data = 0x01; 653 - else if (VCLK >= 135) 654 - data = 0x02; 655 - 656 - SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x07, 0xF8, data); 657 - } 658 - 659 - static void 660 - SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 661 - unsigned short ModeIdIndex, unsigned short rrti) 662 - { 663 - unsigned short data, infoflag = 0, modeflag; 664 - 665 - if (ModeNo <= 0x13) 666 - modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; 667 - else { 668 - modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 669 - infoflag = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag; 670 - } 671 - 672 - /* Disable DPMS */ 673 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1F, 0x3F); 674 - 675 - data = 0; 676 - if (ModeNo > 0x13) { 677 - if (SiS_Pr->SiS_ModeType > ModeEGA) { 678 - data |= 0x02; 679 - data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2); 680 - } 681 - if (infoflag & InterlaceMode) 682 - data |= 0x20; 683 - } 684 - SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x06, 0xC0, data); 685 - 686 - data = 0; 687 - if (infoflag & InterlaceMode) { 688 - /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */ 689 - unsigned short hrs = 690 - (SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x04) | 691 - ((SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0b) & 0xc0) << 2)) 692 - - 3; 693 - unsigned short hto = 694 - (SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x00) | 695 - ((SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0b) & 0x03) << 8)) 696 - + 5; 697 - data = hrs - (hto >> 1) + 3; 698 - } 699 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x19, (data & 0xFF)); 700 - SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3d4, 0x1a, 0xFC, (data >> 8)); 701 - 702 - if (modeflag & HalfDCLK) 703 - SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x01, 0x08); 704 - 705 - data = 0; 706 - if (modeflag & LineCompareOff) 707 - data = 0x08; 708 - SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0F, 0xB7, data); 709 - 710 - if ((SiS_Pr->SiS_ModeType == ModeEGA) && (ModeNo > 0x13)) 711 - SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0F, 0x40); 712 - 713 - SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x31, 0xfb); 714 - 715 - data = 0x60; 716 - if (SiS_Pr->SiS_ModeType != ModeText) { 717 - data ^= 0x60; 718 - if (SiS_Pr->SiS_ModeType != ModeEGA) 719 - data ^= 0xA0; 720 - } 721 - SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x21, 0x1F, data); 722 - 723 - SiS_SetVCLKState(SiS_Pr, ModeNo, rrti); 724 - 725 - if (SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x31) & 0x40) 726 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x52, 0x2c); 727 - else 728 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x52, 0x6c); 729 - } 730 - 731 - /*********************************************/ 732 - /* LOAD DAC */ 733 - /*********************************************/ 734 - 735 - static void 736 - SiS_WriteDAC(struct SiS_Private *SiS_Pr, unsigned long DACData, 737 - unsigned short shiftflag, unsigned short dl, unsigned short ah, 738 - unsigned short al, unsigned short dh) 739 - { 740 - unsigned short d1, d2, d3; 741 - 742 - switch (dl) { 743 - case 0: 744 - d1 = dh; 745 - d2 = ah; 746 - d3 = al; 747 - break; 748 - case 1: 749 - d1 = ah; 750 - d2 = al; 751 - d3 = dh; 752 - break; 753 - default: 754 - d1 = al; 755 - d2 = dh; 756 - d3 = ah; 757 - } 758 - SiS_SetRegByte(SiS_Pr, DACData, (d1 << shiftflag)); 759 - SiS_SetRegByte(SiS_Pr, DACData, (d2 << shiftflag)); 760 - SiS_SetRegByte(SiS_Pr, DACData, (d3 << shiftflag)); 761 - } 762 - 763 - static void 764 - SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 765 - unsigned short mi) 766 - { 767 - unsigned short data, data2, time, i, j, k, m, n, o; 768 - unsigned short si, di, bx, sf; 769 - unsigned long DACAddr, DACData; 770 - const unsigned char *table = NULL; 771 - 772 - if (ModeNo < 0x13) 773 - data = SiS_Pr->SiS_SModeIDTable[mi].St_ModeFlag; 774 - else 775 - data = SiS_Pr->SiS_EModeIDTable[mi].Ext_ModeFlag; 776 - 777 - data &= DACInfoFlag; 778 - 779 - j = time = 64; 780 - if (data == 0x00) 781 - table = SiS_MDA_DAC; 782 - else if (data == 0x08) 783 - table = SiS_CGA_DAC; 784 - else if (data == 0x10) 785 - table = SiS_EGA_DAC; 786 - else { 787 - j = 16; 788 - time = 256; 789 - table = SiS_VGA_DAC; 790 - } 791 - 792 - DACAddr = SiS_Pr->SiS_P3c8; 793 - DACData = SiS_Pr->SiS_P3c9; 794 - sf = 0; 795 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c6, 0xFF); 796 - 797 - SiS_SetRegByte(SiS_Pr, DACAddr, 0x00); 798 - 799 - for (i = 0; i < j; i++) { 800 - data = table[i]; 801 - for (k = 0; k < 3; k++) { 802 - data2 = 0; 803 - if (data & 0x01) 804 - data2 += 0x2A; 805 - if (data & 0x02) 806 - data2 += 0x15; 807 - SiS_SetRegByte(SiS_Pr, DACData, (data2 << sf)); 808 - data >>= 2; 809 - } 810 - } 811 - 812 - if (time == 256) { 813 - for (i = 16; i < 32; i++) { 814 - data = table[i] << sf; 815 - for (k = 0; k < 3; k++) 816 - SiS_SetRegByte(SiS_Pr, DACData, data); 817 - } 818 - si = 32; 819 - for (m = 0; m < 9; m++) { 820 - di = si; 821 - bx = si + 4; 822 - for (n = 0; n < 3; n++) { 823 - for (o = 0; o < 5; o++) { 824 - SiS_WriteDAC(SiS_Pr, DACData, sf, n, 825 - table[di], table[bx], 826 - table[si]); 827 - si++; 828 - } 829 - si -= 2; 830 - for (o = 0; o < 3; o++) { 831 - SiS_WriteDAC(SiS_Pr, DACData, sf, n, 832 - table[di], table[si], 833 - table[bx]); 834 - si--; 835 - } 836 - } 837 - si += 5; 838 - } 839 - } 840 - } 841 - 842 - /*********************************************/ 843 - /* SET CRT1 REGISTER GROUP */ 844 - /*********************************************/ 845 - 846 - static void 847 - SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 848 - unsigned short ModeIdIndex) 849 - { 850 - unsigned short StandTableIndex, rrti; 851 - 852 - SiS_Pr->SiS_CRT1Mode = ModeNo; 853 - 854 - if (ModeNo <= 0x13) 855 - StandTableIndex = 0; 856 - else 857 - StandTableIndex = 1; 858 - 859 - SiS_ResetSegmentRegisters(SiS_Pr); 860 - SiS_SetSeqRegs(SiS_Pr, StandTableIndex); 861 - SiS_SetMiscRegs(SiS_Pr, StandTableIndex); 862 - SiS_SetCRTCRegs(SiS_Pr, StandTableIndex); 863 - SiS_SetATTRegs(SiS_Pr, StandTableIndex); 864 - SiS_SetGRCRegs(SiS_Pr, StandTableIndex); 865 - SiS_ClearExt1Regs(SiS_Pr, ModeNo); 866 - 867 - rrti = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex); 868 - 869 - if (rrti != 0xFFFF) { 870 - SiS_SetCRT1Sync(SiS_Pr, rrti); 871 - SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, rrti); 872 - SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, rrti); 873 - SiS_SetCRT1VCLK(SiS_Pr, ModeNo, rrti); 874 - } 875 - 876 - SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex); 877 - 878 - SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, rrti); 879 - 880 - SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex); 881 - 882 - SiS_DisplayOn(SiS_Pr); 883 - } 884 - 885 - /*********************************************/ 886 - /* SiSSetMode() */ 887 - /*********************************************/ 888 - 889 - int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo) 890 - { 891 - unsigned short ModeIdIndex; 892 - unsigned long BaseAddr = SiS_Pr->IOAddress; 893 - 894 - SiSUSB_InitPtr(SiS_Pr); 895 - SiSUSBRegInit(SiS_Pr, BaseAddr); 896 - SiS_GetSysFlags(SiS_Pr); 897 - 898 - if (!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) 899 - return 0; 900 - 901 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x05, 0x86); 902 - 903 - SiSInitPCIetc(SiS_Pr); 904 - 905 - ModeNo &= 0x7f; 906 - 907 - SiS_Pr->SiS_ModeType = 908 - SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag & ModeTypeMask; 909 - 910 - SiS_Pr->SiS_SetFlag = LowModeTests; 911 - 912 - /* Set mode on CRT1 */ 913 - SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex); 914 - 915 - SiS_HandleCRT1(SiS_Pr); 916 - 917 - SiS_DisplayOn(SiS_Pr); 918 - SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c6, 0xFF); 919 - 920 - /* Store mode number */ 921 - SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x34, ModeNo); 922 - 923 - return 1; 924 - } 925 - 926 - int SiSUSBSetVESAMode(struct SiS_Private *SiS_Pr, unsigned short VModeNo) 927 - { 928 - unsigned short ModeNo = 0; 929 - int i; 930 - 931 - SiSUSB_InitPtr(SiS_Pr); 932 - 933 - if (VModeNo == 0x03) { 934 - 935 - ModeNo = 0x03; 936 - 937 - } else { 938 - 939 - i = 0; 940 - do { 941 - 942 - if (SiS_Pr->SiS_EModeIDTable[i].Ext_VESAID == VModeNo) { 943 - ModeNo = SiS_Pr->SiS_EModeIDTable[i].Ext_ModeID; 944 - break; 945 - } 946 - 947 - } while (SiS_Pr->SiS_EModeIDTable[i++].Ext_ModeID != 0xff); 948 - 949 - } 950 - 951 - if (!ModeNo) 952 - return 0; 953 - 954 - return SiSUSBSetMode(SiS_Pr, ModeNo); 955 - }
-180
drivers/usb/misc/sisusbvga/sisusb_init.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ 2 - /* $XFree86$ */ 3 - /* $XdotOrg$ */ 4 - /* 5 - * Data and prototypes for init.c 6 - * 7 - * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria 8 - * 9 - * If distributed as part of the Linux kernel, the following license terms 10 - * apply: 11 - * 12 - * * This program is free software; you can redistribute it and/or modify 13 - * * it under the terms of the GNU General Public License as published by 14 - * * the Free Software Foundation; either version 2 of the named License, 15 - * * or any later version. 16 - * * 17 - * * This program is distributed in the hope that it will be useful, 18 - * * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 - * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 - * * GNU General Public License for more details. 21 - * * 22 - * * You should have received a copy of the GNU General Public License 23 - * * along with this program; if not, write to the Free Software 24 - * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA 25 - * 26 - * Otherwise, the following license terms apply: 27 - * 28 - * * Redistribution and use in source and binary forms, with or without 29 - * * modification, are permitted provided that the following conditions 30 - * * are met: 31 - * * 1) Redistributions of source code must retain the above copyright 32 - * * notice, this list of conditions and the following disclaimer. 33 - * * 2) Redistributions in binary form must reproduce the above copyright 34 - * * notice, this list of conditions and the following disclaimer in the 35 - * * documentation and/or other materials provided with the distribution. 36 - * * 3) The name of the author may not be used to endorse or promote products 37 - * * derived from this software without specific prior written permission. 38 - * * 39 - * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 40 - * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 41 - * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 42 - * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 43 - * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44 - * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 45 - * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 46 - * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 47 - * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 48 - * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 - * 50 - * Author: Thomas Winischhofer <thomas@winischhofer.net> 51 - * 52 - */ 53 - 54 - #ifndef _SISUSB_INIT_H_ 55 - #define _SISUSB_INIT_H_ 56 - 57 - /* SiS_ModeType */ 58 - #define ModeText 0x00 59 - #define ModeCGA 0x01 60 - #define ModeEGA 0x02 61 - #define ModeVGA 0x03 62 - #define Mode15Bpp 0x04 63 - #define Mode16Bpp 0x05 64 - #define Mode24Bpp 0x06 65 - #define Mode32Bpp 0x07 66 - 67 - #define ModeTypeMask 0x07 68 - #define IsTextMode 0x07 69 - 70 - #define DACInfoFlag 0x0018 71 - #define MemoryInfoFlag 0x01E0 72 - #define MemorySizeShift 5 73 - 74 - /* modeflag */ 75 - #define Charx8Dot 0x0200 76 - #define LineCompareOff 0x0400 77 - #define CRT2Mode 0x0800 78 - #define HalfDCLK 0x1000 79 - #define NoSupportSimuTV 0x2000 80 - #define NoSupportLCDScale 0x4000 /* SiS bridge: No scaling possible (no matter what panel) */ 81 - #define DoubleScanMode 0x8000 82 - 83 - /* Infoflag */ 84 - #define SupportTV 0x0008 85 - #define SupportTV1024 0x0800 86 - #define SupportCHTV 0x0800 87 - #define Support64048060Hz 0x0800 /* Special for 640x480 LCD */ 88 - #define SupportHiVision 0x0010 89 - #define SupportYPbPr750p 0x1000 90 - #define SupportLCD 0x0020 91 - #define SupportRAMDAC2 0x0040 /* All (<= 100Mhz) */ 92 - #define SupportRAMDAC2_135 0x0100 /* All except DH (<= 135Mhz) */ 93 - #define SupportRAMDAC2_162 0x0200 /* B, C (<= 162Mhz) */ 94 - #define SupportRAMDAC2_202 0x0400 /* C (<= 202Mhz) */ 95 - #define InterlaceMode 0x0080 96 - #define SyncPP 0x0000 97 - #define SyncPN 0x4000 98 - #define SyncNP 0x8000 99 - #define SyncNN 0xc000 100 - 101 - /* SetFlag */ 102 - #define ProgrammingCRT2 0x0001 103 - #define LowModeTests 0x0002 104 - #define LCDVESATiming 0x0008 105 - #define EnableLVDSDDA 0x0010 106 - #define SetDispDevSwitchFlag 0x0020 107 - #define CheckWinDos 0x0040 108 - #define SetDOSMode 0x0080 109 - 110 - /* Index in ModeResInfo table */ 111 - #define SIS_RI_320x200 0 112 - #define SIS_RI_320x240 1 113 - #define SIS_RI_320x400 2 114 - #define SIS_RI_400x300 3 115 - #define SIS_RI_512x384 4 116 - #define SIS_RI_640x400 5 117 - #define SIS_RI_640x480 6 118 - #define SIS_RI_800x600 7 119 - #define SIS_RI_1024x768 8 120 - #define SIS_RI_1280x1024 9 121 - #define SIS_RI_1600x1200 10 122 - #define SIS_RI_1920x1440 11 123 - #define SIS_RI_2048x1536 12 124 - #define SIS_RI_720x480 13 125 - #define SIS_RI_720x576 14 126 - #define SIS_RI_1280x960 15 127 - #define SIS_RI_800x480 16 128 - #define SIS_RI_1024x576 17 129 - #define SIS_RI_1280x720 18 130 - #define SIS_RI_856x480 19 131 - #define SIS_RI_1280x768 20 132 - #define SIS_RI_1400x1050 21 133 - #define SIS_RI_1152x864 22 /* Up to here SiS conforming */ 134 - #define SIS_RI_848x480 23 135 - #define SIS_RI_1360x768 24 136 - #define SIS_RI_1024x600 25 137 - #define SIS_RI_1152x768 26 138 - #define SIS_RI_768x576 27 139 - #define SIS_RI_1360x1024 28 140 - #define SIS_RI_1680x1050 29 141 - #define SIS_RI_1280x800 30 142 - #define SIS_RI_1920x1080 31 143 - #define SIS_RI_960x540 32 144 - #define SIS_RI_960x600 33 145 - 146 - #define SIS_VIDEO_CAPTURE 0x00 - 0x30 147 - #define SIS_VIDEO_PLAYBACK 0x02 - 0x30 148 - #define SIS_CRT2_PORT_04 0x04 - 0x30 149 - 150 - int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo); 151 - int SiSUSBSetVESAMode(struct SiS_Private *SiS_Pr, unsigned short VModeNo); 152 - 153 - extern int sisusb_setreg(struct sisusb_usb_data *sisusb, u32 port, u8 data); 154 - extern int sisusb_getreg(struct sisusb_usb_data *sisusb, u32 port, u8 * data); 155 - extern int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port, 156 - u8 index, u8 data); 157 - extern int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port, 158 - u8 index, u8 * data); 159 - extern int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port, 160 - u8 idx, u8 myand, u8 myor); 161 - extern int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port, 162 - u8 index, u8 myor); 163 - extern int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port, 164 - u8 idx, u8 myand); 165 - 166 - void sisusb_delete(struct kref *kref); 167 - int sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data); 168 - int sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 * data); 169 - int sisusb_copy_memory(struct sisusb_usb_data *sisusb, u8 *src, 170 - u32 dest, int length); 171 - int sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init); 172 - int sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot, 173 - u8 * arg, int cmapsz, int ch512, int dorecalc, 174 - struct vc_data *c, int fh, int uplock); 175 - void sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location); 176 - int sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last); 177 - void sisusb_console_exit(struct sisusb_usb_data *sisusb); 178 - void sisusb_init_concode(void); 179 - 180 - #endif
+2 -3
drivers/usb/misc/usb251xb.c
··· 699 699 return 0; 700 700 } 701 701 702 - static int usb251xb_i2c_probe(struct i2c_client *i2c, 703 - const struct i2c_device_id *id) 702 + static int usb251xb_i2c_probe(struct i2c_client *i2c) 704 703 { 705 704 struct usb251xb *hub; 706 705 ··· 757 758 .of_match_table = of_match_ptr(usb251xb_of_match), 758 759 .pm = &usb251xb_pm_ops, 759 760 }, 760 - .probe = usb251xb_i2c_probe, 761 + .probe_new = usb251xb_i2c_probe, 761 762 .id_table = usb251xb_id, 762 763 }; 763 764
+2 -3
drivers/usb/misc/usb3503.c
··· 280 280 return err; 281 281 } 282 282 283 - static int usb3503_i2c_probe(struct i2c_client *i2c, 284 - const struct i2c_device_id *id) 283 + static int usb3503_i2c_probe(struct i2c_client *i2c) 285 284 { 286 285 struct usb3503 *hub; 287 286 int err; ··· 399 400 .pm = pm_ptr(&usb3503_i2c_pm_ops), 400 401 .of_match_table = of_match_ptr(usb3503_of_match), 401 402 }, 402 - .probe = usb3503_i2c_probe, 403 + .probe_new = usb3503_i2c_probe, 403 404 .remove = usb3503_i2c_remove, 404 405 .id_table = usb3503_id, 405 406 };
+2 -3
drivers/usb/misc/usb4604.c
··· 97 97 return usb4604_switch_mode(hub, hub->mode); 98 98 } 99 99 100 - static int usb4604_i2c_probe(struct i2c_client *i2c, 101 - const struct i2c_device_id *id) 100 + static int usb4604_i2c_probe(struct i2c_client *i2c) 102 101 { 103 102 struct usb4604 *hub; 104 103 ··· 154 155 .pm = pm_ptr(&usb4604_i2c_pm_ops), 155 156 .of_match_table = of_match_ptr(usb4604_of_match), 156 157 }, 157 - .probe = usb4604_i2c_probe, 158 + .probe_new = usb4604_i2c_probe, 158 159 .id_table = usb4604_id, 159 160 }; 160 161 module_i2c_driver(usb4604_i2c_driver);
-18
drivers/usb/musb/Kconfig
··· 70 70 select GENERIC_PHY 71 71 select SUNXI_SRAM 72 72 73 - config USB_MUSB_DAVINCI 74 - tristate "DaVinci" 75 - depends on ARCH_DAVINCI_DMx 76 - depends on NOP_USB_XCEIV 77 - depends on BROKEN 78 - 79 73 config USB_MUSB_DA8XX 80 74 tristate "DA8xx/OMAP-L1x" 81 75 depends on ARCH_DAVINCI_DA8XX ··· 88 94 depends on OMAP_CONTROL_PHY || !OMAP_CONTROL_PHY 89 95 select GENERIC_PHY 90 96 91 - config USB_MUSB_AM35X 92 - tristate "AM35x" 93 - depends on ARCH_OMAP 94 - depends on NOP_USB_XCEIV 95 - 96 97 config USB_MUSB_DSPS 97 98 tristate "TI DSPS platforms" 98 99 depends on ARCH_OMAP2PLUS || COMPILE_TEST ··· 102 113 depends on OF 103 114 depends on MIPS || COMPILE_TEST 104 115 depends on USB_MUSB_GADGET 105 - depends on USB=n || USB_OTG_DISABLE_EXTERNAL_HUB 106 116 select USB_ROLE_SWITCH 107 117 108 118 config USB_MUSB_MEDIATEK ··· 148 160 depends on USB_MUSB_OMAP2PLUS || USB_MUSB_MEDIATEK || USB_MUSB_JZ4740 || USB_MUSB_POLARFIRE_SOC 149 161 help 150 162 Enable DMA transfers using Mentor's engine. 151 - 152 - config USB_TI_CPPI_DMA 153 - bool 'TI CPPI (Davinci)' 154 - depends on USB_MUSB_DAVINCI 155 - help 156 - Enable DMA transfers when TI CPPI DMA is available. 157 163 158 164 config USB_TI_CPPI41_DMA 159 165 bool 'TI CPPI 4.1'
-3
drivers/usb/musb/Makefile
··· 16 16 17 17 # Hardware Glue Layer 18 18 obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o 19 - obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o 20 19 obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o 21 20 obj-$(CONFIG_USB_MUSB_TUSB6010) += tusb6010.o 22 - obj-$(CONFIG_USB_MUSB_DAVINCI) += davinci.o 23 21 obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o 24 22 obj-$(CONFIG_USB_MUSB_UX500) += ux500.o 25 23 obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o ··· 31 33 # though PIO is always there to back up DMA, and for ep0 32 34 33 35 musb_hdrc-$(CONFIG_USB_INVENTRA_DMA) += musbhsdma.o 34 - musb_hdrc-$(CONFIG_USB_TI_CPPI_DMA) += cppi_dma.o 35 36 musb_hdrc-$(CONFIG_USB_TUSB_OMAP_DMA) += tusb6010_omap.o 36 37 musb_hdrc-$(CONFIG_USB_UX500_DMA) += ux500_dma.o 37 38 musb_hdrc-$(CONFIG_USB_TI_CPPI41_DMA) += musb_cppi41.o
-610
drivers/usb/musb/am35x.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - 3 - /* 4 - * Texas Instruments AM35x "glue layer" 5 - * 6 - * Copyright (c) 2010, by Texas Instruments 7 - * 8 - * Based on the DA8xx "glue layer" code. 9 - * Copyright (c) 2008-2009, MontaVista Software, Inc. <source@mvista.com> 10 - * 11 - * This file is part of the Inventra Controller Driver for Linux. 12 - */ 13 - 14 - #include <linux/module.h> 15 - #include <linux/clk.h> 16 - #include <linux/err.h> 17 - #include <linux/io.h> 18 - #include <linux/platform_device.h> 19 - #include <linux/dma-mapping.h> 20 - #include <linux/usb/usb_phy_generic.h> 21 - #include <linux/platform_data/usb-omap.h> 22 - 23 - #include "musb_core.h" 24 - 25 - /* 26 - * AM35x specific definitions 27 - */ 28 - /* USB 2.0 OTG module registers */ 29 - #define USB_REVISION_REG 0x00 30 - #define USB_CTRL_REG 0x04 31 - #define USB_STAT_REG 0x08 32 - #define USB_EMULATION_REG 0x0c 33 - /* 0x10 Reserved */ 34 - #define USB_AUTOREQ_REG 0x14 35 - #define USB_SRP_FIX_TIME_REG 0x18 36 - #define USB_TEARDOWN_REG 0x1c 37 - #define EP_INTR_SRC_REG 0x20 38 - #define EP_INTR_SRC_SET_REG 0x24 39 - #define EP_INTR_SRC_CLEAR_REG 0x28 40 - #define EP_INTR_MASK_REG 0x2c 41 - #define EP_INTR_MASK_SET_REG 0x30 42 - #define EP_INTR_MASK_CLEAR_REG 0x34 43 - #define EP_INTR_SRC_MASKED_REG 0x38 44 - #define CORE_INTR_SRC_REG 0x40 45 - #define CORE_INTR_SRC_SET_REG 0x44 46 - #define CORE_INTR_SRC_CLEAR_REG 0x48 47 - #define CORE_INTR_MASK_REG 0x4c 48 - #define CORE_INTR_MASK_SET_REG 0x50 49 - #define CORE_INTR_MASK_CLEAR_REG 0x54 50 - #define CORE_INTR_SRC_MASKED_REG 0x58 51 - /* 0x5c Reserved */ 52 - #define USB_END_OF_INTR_REG 0x60 53 - 54 - /* Control register bits */ 55 - #define AM35X_SOFT_RESET_MASK 1 56 - 57 - /* USB interrupt register bits */ 58 - #define AM35X_INTR_USB_SHIFT 16 59 - #define AM35X_INTR_USB_MASK (0x1ff << AM35X_INTR_USB_SHIFT) 60 - #define AM35X_INTR_DRVVBUS 0x100 61 - #define AM35X_INTR_RX_SHIFT 16 62 - #define AM35X_INTR_TX_SHIFT 0 63 - #define AM35X_TX_EP_MASK 0xffff /* EP0 + 15 Tx EPs */ 64 - #define AM35X_RX_EP_MASK 0xfffe /* 15 Rx EPs */ 65 - #define AM35X_TX_INTR_MASK (AM35X_TX_EP_MASK << AM35X_INTR_TX_SHIFT) 66 - #define AM35X_RX_INTR_MASK (AM35X_RX_EP_MASK << AM35X_INTR_RX_SHIFT) 67 - 68 - #define USB_MENTOR_CORE_OFFSET 0x400 69 - 70 - struct am35x_glue { 71 - struct device *dev; 72 - struct platform_device *musb; 73 - struct platform_device *phy; 74 - struct clk *phy_clk; 75 - struct clk *clk; 76 - }; 77 - 78 - /* 79 - * am35x_musb_enable - enable interrupts 80 - */ 81 - static void am35x_musb_enable(struct musb *musb) 82 - { 83 - void __iomem *reg_base = musb->ctrl_base; 84 - u32 epmask; 85 - 86 - /* Workaround: setup IRQs through both register sets. */ 87 - epmask = ((musb->epmask & AM35X_TX_EP_MASK) << AM35X_INTR_TX_SHIFT) | 88 - ((musb->epmask & AM35X_RX_EP_MASK) << AM35X_INTR_RX_SHIFT); 89 - 90 - musb_writel(reg_base, EP_INTR_MASK_SET_REG, epmask); 91 - musb_writel(reg_base, CORE_INTR_MASK_SET_REG, AM35X_INTR_USB_MASK); 92 - 93 - /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 94 - musb_writel(reg_base, CORE_INTR_SRC_SET_REG, 95 - AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT); 96 - } 97 - 98 - /* 99 - * am35x_musb_disable - disable HDRC and flush interrupts 100 - */ 101 - static void am35x_musb_disable(struct musb *musb) 102 - { 103 - void __iomem *reg_base = musb->ctrl_base; 104 - 105 - musb_writel(reg_base, CORE_INTR_MASK_CLEAR_REG, AM35X_INTR_USB_MASK); 106 - musb_writel(reg_base, EP_INTR_MASK_CLEAR_REG, 107 - AM35X_TX_INTR_MASK | AM35X_RX_INTR_MASK); 108 - musb_writel(reg_base, USB_END_OF_INTR_REG, 0); 109 - } 110 - 111 - #define portstate(stmt) stmt 112 - 113 - static void am35x_musb_set_vbus(struct musb *musb, int is_on) 114 - { 115 - WARN_ON(is_on && is_peripheral_active(musb)); 116 - } 117 - 118 - #define POLL_SECONDS 2 119 - 120 - static void otg_timer(struct timer_list *t) 121 - { 122 - struct musb *musb = from_timer(musb, t, dev_timer); 123 - void __iomem *mregs = musb->mregs; 124 - u8 devctl; 125 - unsigned long flags; 126 - 127 - /* 128 - * We poll because AM35x's won't expose several OTG-critical 129 - * status change events (from the transceiver) otherwise. 130 - */ 131 - devctl = musb_readb(mregs, MUSB_DEVCTL); 132 - dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 133 - usb_otg_state_string(musb->xceiv->otg->state)); 134 - 135 - spin_lock_irqsave(&musb->lock, flags); 136 - switch (musb->xceiv->otg->state) { 137 - case OTG_STATE_A_WAIT_BCON: 138 - devctl &= ~MUSB_DEVCTL_SESSION; 139 - musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); 140 - 141 - devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 142 - if (devctl & MUSB_DEVCTL_BDEVICE) { 143 - musb->xceiv->otg->state = OTG_STATE_B_IDLE; 144 - MUSB_DEV_MODE(musb); 145 - } else { 146 - musb->xceiv->otg->state = OTG_STATE_A_IDLE; 147 - MUSB_HST_MODE(musb); 148 - } 149 - break; 150 - case OTG_STATE_A_WAIT_VFALL: 151 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; 152 - musb_writel(musb->ctrl_base, CORE_INTR_SRC_SET_REG, 153 - MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT); 154 - break; 155 - case OTG_STATE_B_IDLE: 156 - devctl = musb_readb(mregs, MUSB_DEVCTL); 157 - if (devctl & MUSB_DEVCTL_BDEVICE) 158 - mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 159 - else 160 - musb->xceiv->otg->state = OTG_STATE_A_IDLE; 161 - break; 162 - default: 163 - break; 164 - } 165 - spin_unlock_irqrestore(&musb->lock, flags); 166 - } 167 - 168 - static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout) 169 - { 170 - static unsigned long last_timer; 171 - 172 - if (timeout == 0) 173 - timeout = jiffies + msecs_to_jiffies(3); 174 - 175 - /* Never idle if active, or when VBUS timeout is not set as host */ 176 - if (musb->is_active || (musb->a_wait_bcon == 0 && 177 - musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) { 178 - dev_dbg(musb->controller, "%s active, deleting timer\n", 179 - usb_otg_state_string(musb->xceiv->otg->state)); 180 - del_timer(&musb->dev_timer); 181 - last_timer = jiffies; 182 - return; 183 - } 184 - 185 - if (time_after(last_timer, timeout) && timer_pending(&musb->dev_timer)) { 186 - dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n"); 187 - return; 188 - } 189 - last_timer = timeout; 190 - 191 - dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 192 - usb_otg_state_string(musb->xceiv->otg->state), 193 - jiffies_to_msecs(timeout - jiffies)); 194 - mod_timer(&musb->dev_timer, timeout); 195 - } 196 - 197 - static irqreturn_t am35x_musb_interrupt(int irq, void *hci) 198 - { 199 - struct musb *musb = hci; 200 - void __iomem *reg_base = musb->ctrl_base; 201 - struct device *dev = musb->controller; 202 - struct musb_hdrc_platform_data *plat = dev_get_platdata(dev); 203 - struct omap_musb_board_data *data = plat->board_data; 204 - unsigned long flags; 205 - irqreturn_t ret = IRQ_NONE; 206 - u32 epintr, usbintr; 207 - 208 - spin_lock_irqsave(&musb->lock, flags); 209 - 210 - /* Get endpoint interrupts */ 211 - epintr = musb_readl(reg_base, EP_INTR_SRC_MASKED_REG); 212 - 213 - if (epintr) { 214 - musb_writel(reg_base, EP_INTR_SRC_CLEAR_REG, epintr); 215 - 216 - musb->int_rx = 217 - (epintr & AM35X_RX_INTR_MASK) >> AM35X_INTR_RX_SHIFT; 218 - musb->int_tx = 219 - (epintr & AM35X_TX_INTR_MASK) >> AM35X_INTR_TX_SHIFT; 220 - } 221 - 222 - /* Get usb core interrupts */ 223 - usbintr = musb_readl(reg_base, CORE_INTR_SRC_MASKED_REG); 224 - if (!usbintr && !epintr) 225 - goto eoi; 226 - 227 - if (usbintr) { 228 - musb_writel(reg_base, CORE_INTR_SRC_CLEAR_REG, usbintr); 229 - 230 - musb->int_usb = 231 - (usbintr & AM35X_INTR_USB_MASK) >> AM35X_INTR_USB_SHIFT; 232 - } 233 - /* 234 - * DRVVBUS IRQs are the only proxy we have (a very poor one!) for 235 - * AM35x's missing ID change IRQ. We need an ID change IRQ to 236 - * switch appropriately between halves of the OTG state machine. 237 - * Managing DEVCTL.SESSION per Mentor docs requires that we know its 238 - * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. 239 - * Also, DRVVBUS pulses for SRP (but not at 5V) ... 240 - */ 241 - if (usbintr & (AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT)) { 242 - int drvvbus = musb_readl(reg_base, USB_STAT_REG); 243 - void __iomem *mregs = musb->mregs; 244 - u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 245 - int err; 246 - 247 - err = musb->int_usb & MUSB_INTR_VBUSERROR; 248 - if (err) { 249 - /* 250 - * The Mentor core doesn't debounce VBUS as needed 251 - * to cope with device connect current spikes. This 252 - * means it's not uncommon for bus-powered devices 253 - * to get VBUS errors during enumeration. 254 - * 255 - * This is a workaround, but newer RTL from Mentor 256 - * seems to allow a better one: "re"-starting sessions 257 - * without waiting for VBUS to stop registering in 258 - * devctl. 259 - */ 260 - musb->int_usb &= ~MUSB_INTR_VBUSERROR; 261 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; 262 - mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 263 - WARNING("VBUS error workaround (delay coming)\n"); 264 - } else if (drvvbus) { 265 - MUSB_HST_MODE(musb); 266 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; 267 - portstate(musb->port1_status |= USB_PORT_STAT_POWER); 268 - del_timer(&musb->dev_timer); 269 - } else { 270 - musb->is_active = 0; 271 - MUSB_DEV_MODE(musb); 272 - musb->xceiv->otg->state = OTG_STATE_B_IDLE; 273 - portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); 274 - } 275 - 276 - /* NOTE: this must complete power-on within 100 ms. */ 277 - dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 278 - drvvbus ? "on" : "off", 279 - usb_otg_state_string(musb->xceiv->otg->state), 280 - err ? " ERROR" : "", 281 - devctl); 282 - ret = IRQ_HANDLED; 283 - } 284 - 285 - /* Drop spurious RX and TX if device is disconnected */ 286 - if (musb->int_usb & MUSB_INTR_DISCONNECT) { 287 - musb->int_tx = 0; 288 - musb->int_rx = 0; 289 - } 290 - 291 - if (musb->int_tx || musb->int_rx || musb->int_usb) 292 - ret |= musb_interrupt(musb); 293 - 294 - eoi: 295 - /* EOI needs to be written for the IRQ to be re-asserted. */ 296 - if (ret == IRQ_HANDLED || epintr || usbintr) { 297 - /* clear level interrupt */ 298 - if (data->clear_irq) 299 - data->clear_irq(); 300 - /* write EOI */ 301 - musb_writel(reg_base, USB_END_OF_INTR_REG, 0); 302 - } 303 - 304 - /* Poll for ID change */ 305 - if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) 306 - mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 307 - 308 - spin_unlock_irqrestore(&musb->lock, flags); 309 - 310 - return ret; 311 - } 312 - 313 - static int am35x_musb_set_mode(struct musb *musb, u8 musb_mode) 314 - { 315 - struct device *dev = musb->controller; 316 - struct musb_hdrc_platform_data *plat = dev_get_platdata(dev); 317 - struct omap_musb_board_data *data = plat->board_data; 318 - int retval = 0; 319 - 320 - if (data->set_mode) 321 - data->set_mode(musb_mode); 322 - else 323 - retval = -EIO; 324 - 325 - return retval; 326 - } 327 - 328 - static int am35x_musb_init(struct musb *musb) 329 - { 330 - struct device *dev = musb->controller; 331 - struct musb_hdrc_platform_data *plat = dev_get_platdata(dev); 332 - struct omap_musb_board_data *data = plat->board_data; 333 - void __iomem *reg_base = musb->ctrl_base; 334 - u32 rev; 335 - 336 - musb->mregs += USB_MENTOR_CORE_OFFSET; 337 - 338 - /* Returns zero if e.g. not clocked */ 339 - rev = musb_readl(reg_base, USB_REVISION_REG); 340 - if (!rev) 341 - return -ENODEV; 342 - 343 - musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 344 - if (IS_ERR_OR_NULL(musb->xceiv)) 345 - return -EPROBE_DEFER; 346 - 347 - timer_setup(&musb->dev_timer, otg_timer, 0); 348 - 349 - /* Reset the musb */ 350 - if (data->reset) 351 - data->reset(); 352 - 353 - /* Reset the controller */ 354 - musb_writel(reg_base, USB_CTRL_REG, AM35X_SOFT_RESET_MASK); 355 - 356 - /* Start the on-chip PHY and its PLL. */ 357 - if (data->set_phy_power) 358 - data->set_phy_power(1); 359 - 360 - msleep(5); 361 - 362 - musb->isr = am35x_musb_interrupt; 363 - 364 - /* clear level interrupt */ 365 - if (data->clear_irq) 366 - data->clear_irq(); 367 - 368 - return 0; 369 - } 370 - 371 - static int am35x_musb_exit(struct musb *musb) 372 - { 373 - struct device *dev = musb->controller; 374 - struct musb_hdrc_platform_data *plat = dev_get_platdata(dev); 375 - struct omap_musb_board_data *data = plat->board_data; 376 - 377 - del_timer_sync(&musb->dev_timer); 378 - 379 - /* Shutdown the on-chip PHY and its PLL. */ 380 - if (data->set_phy_power) 381 - data->set_phy_power(0); 382 - 383 - usb_put_phy(musb->xceiv); 384 - 385 - return 0; 386 - } 387 - 388 - /* AM35x supports only 32bit read operation */ 389 - static void am35x_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) 390 - { 391 - void __iomem *fifo = hw_ep->fifo; 392 - u32 val; 393 - int i; 394 - 395 - /* Read for 32bit-aligned destination address */ 396 - if (likely((0x03 & (unsigned long) dst) == 0) && len >= 4) { 397 - readsl(fifo, dst, len >> 2); 398 - dst += len & ~0x03; 399 - len &= 0x03; 400 - } 401 - /* 402 - * Now read the remaining 1 to 3 byte or complete length if 403 - * unaligned address. 404 - */ 405 - if (len > 4) { 406 - for (i = 0; i < (len >> 2); i++) { 407 - *(u32 *) dst = musb_readl(fifo, 0); 408 - dst += 4; 409 - } 410 - len &= 0x03; 411 - } 412 - if (len > 0) { 413 - val = musb_readl(fifo, 0); 414 - memcpy(dst, &val, len); 415 - } 416 - } 417 - 418 - static const struct musb_platform_ops am35x_ops = { 419 - .quirks = MUSB_DMA_INVENTRA | MUSB_INDEXED_EP, 420 - .init = am35x_musb_init, 421 - .exit = am35x_musb_exit, 422 - 423 - .read_fifo = am35x_read_fifo, 424 - #ifdef CONFIG_USB_INVENTRA_DMA 425 - .dma_init = musbhs_dma_controller_create, 426 - .dma_exit = musbhs_dma_controller_destroy, 427 - #endif 428 - .enable = am35x_musb_enable, 429 - .disable = am35x_musb_disable, 430 - 431 - .set_mode = am35x_musb_set_mode, 432 - .try_idle = am35x_musb_try_idle, 433 - 434 - .set_vbus = am35x_musb_set_vbus, 435 - }; 436 - 437 - static const struct platform_device_info am35x_dev_info = { 438 - .name = "musb-hdrc", 439 - .id = PLATFORM_DEVID_AUTO, 440 - .dma_mask = DMA_BIT_MASK(32), 441 - }; 442 - 443 - static int am35x_probe(struct platform_device *pdev) 444 - { 445 - struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 446 - struct platform_device *musb; 447 - struct am35x_glue *glue; 448 - struct platform_device_info pinfo; 449 - struct clk *phy_clk; 450 - struct clk *clk; 451 - 452 - int ret = -ENOMEM; 453 - 454 - glue = kzalloc(sizeof(*glue), GFP_KERNEL); 455 - if (!glue) 456 - goto err0; 457 - 458 - phy_clk = clk_get(&pdev->dev, "fck"); 459 - if (IS_ERR(phy_clk)) { 460 - dev_err(&pdev->dev, "failed to get PHY clock\n"); 461 - ret = PTR_ERR(phy_clk); 462 - goto err3; 463 - } 464 - 465 - clk = clk_get(&pdev->dev, "ick"); 466 - if (IS_ERR(clk)) { 467 - dev_err(&pdev->dev, "failed to get clock\n"); 468 - ret = PTR_ERR(clk); 469 - goto err4; 470 - } 471 - 472 - ret = clk_enable(phy_clk); 473 - if (ret) { 474 - dev_err(&pdev->dev, "failed to enable PHY clock\n"); 475 - goto err5; 476 - } 477 - 478 - ret = clk_enable(clk); 479 - if (ret) { 480 - dev_err(&pdev->dev, "failed to enable clock\n"); 481 - goto err6; 482 - } 483 - 484 - glue->dev = &pdev->dev; 485 - glue->phy_clk = phy_clk; 486 - glue->clk = clk; 487 - 488 - pdata->platform_ops = &am35x_ops; 489 - 490 - glue->phy = usb_phy_generic_register(); 491 - if (IS_ERR(glue->phy)) { 492 - ret = PTR_ERR(glue->phy); 493 - goto err7; 494 - } 495 - platform_set_drvdata(pdev, glue); 496 - 497 - pinfo = am35x_dev_info; 498 - pinfo.parent = &pdev->dev; 499 - pinfo.res = pdev->resource; 500 - pinfo.num_res = pdev->num_resources; 501 - pinfo.data = pdata; 502 - pinfo.size_data = sizeof(*pdata); 503 - pinfo.fwnode = of_fwnode_handle(pdev->dev.of_node); 504 - pinfo.of_node_reused = true; 505 - 506 - glue->musb = musb = platform_device_register_full(&pinfo); 507 - if (IS_ERR(musb)) { 508 - ret = PTR_ERR(musb); 509 - dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); 510 - goto err8; 511 - } 512 - 513 - return 0; 514 - 515 - err8: 516 - usb_phy_generic_unregister(glue->phy); 517 - 518 - err7: 519 - clk_disable(clk); 520 - 521 - err6: 522 - clk_disable(phy_clk); 523 - 524 - err5: 525 - clk_put(clk); 526 - 527 - err4: 528 - clk_put(phy_clk); 529 - 530 - err3: 531 - kfree(glue); 532 - 533 - err0: 534 - return ret; 535 - } 536 - 537 - static int am35x_remove(struct platform_device *pdev) 538 - { 539 - struct am35x_glue *glue = platform_get_drvdata(pdev); 540 - 541 - platform_device_unregister(glue->musb); 542 - usb_phy_generic_unregister(glue->phy); 543 - clk_disable(glue->clk); 544 - clk_disable(glue->phy_clk); 545 - clk_put(glue->clk); 546 - clk_put(glue->phy_clk); 547 - kfree(glue); 548 - 549 - return 0; 550 - } 551 - 552 - #ifdef CONFIG_PM_SLEEP 553 - static int am35x_suspend(struct device *dev) 554 - { 555 - struct am35x_glue *glue = dev_get_drvdata(dev); 556 - struct musb_hdrc_platform_data *plat = dev_get_platdata(dev); 557 - struct omap_musb_board_data *data = plat->board_data; 558 - 559 - /* Shutdown the on-chip PHY and its PLL. */ 560 - if (data->set_phy_power) 561 - data->set_phy_power(0); 562 - 563 - clk_disable(glue->phy_clk); 564 - clk_disable(glue->clk); 565 - 566 - return 0; 567 - } 568 - 569 - static int am35x_resume(struct device *dev) 570 - { 571 - struct am35x_glue *glue = dev_get_drvdata(dev); 572 - struct musb_hdrc_platform_data *plat = dev_get_platdata(dev); 573 - struct omap_musb_board_data *data = plat->board_data; 574 - int ret; 575 - 576 - /* Start the on-chip PHY and its PLL. */ 577 - if (data->set_phy_power) 578 - data->set_phy_power(1); 579 - 580 - ret = clk_enable(glue->phy_clk); 581 - if (ret) { 582 - dev_err(dev, "failed to enable PHY clock\n"); 583 - return ret; 584 - } 585 - 586 - ret = clk_enable(glue->clk); 587 - if (ret) { 588 - dev_err(dev, "failed to enable clock\n"); 589 - return ret; 590 - } 591 - 592 - return 0; 593 - } 594 - #endif 595 - 596 - static SIMPLE_DEV_PM_OPS(am35x_pm_ops, am35x_suspend, am35x_resume); 597 - 598 - static struct platform_driver am35x_driver = { 599 - .probe = am35x_probe, 600 - .remove = am35x_remove, 601 - .driver = { 602 - .name = "musb-am35x", 603 - .pm = &am35x_pm_ops, 604 - }, 605 - }; 606 - 607 - MODULE_DESCRIPTION("AM35x MUSB Glue Layer"); 608 - MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>"); 609 - MODULE_LICENSE("GPL v2"); 610 - module_platform_driver(am35x_driver);
-1547
drivers/usb/musb/cppi_dma.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Copyright (C) 2005-2006 by Texas Instruments 4 - * 5 - * This file implements a DMA interface using TI's CPPI DMA. 6 - * For now it's DaVinci-only, but CPPI isn't specific to DaVinci or USB. 7 - * The TUSB6020, using VLYNQ, has CPPI that looks much like DaVinci. 8 - */ 9 - 10 - #include <linux/module.h> 11 - #include <linux/platform_device.h> 12 - #include <linux/slab.h> 13 - #include <linux/usb.h> 14 - 15 - #include "musb_core.h" 16 - #include "musb_debug.h" 17 - #include "cppi_dma.h" 18 - #include "davinci.h" 19 - 20 - 21 - /* CPPI DMA status 7-mar-2006: 22 - * 23 - * - See musb_{host,gadget}.c for more info 24 - * 25 - * - Correct RX DMA generally forces the engine into irq-per-packet mode, 26 - * which can easily saturate the CPU under non-mass-storage loads. 27 - * 28 - * NOTES 24-aug-2006 (2.6.18-rc4): 29 - * 30 - * - peripheral RXDMA wedged in a test with packets of length 512/512/1. 31 - * evidently after the 1 byte packet was received and acked, the queue 32 - * of BDs got garbaged so it wouldn't empty the fifo. (rxcsr 0x2003, 33 - * and RX DMA0: 4 left, 80000000 8feff880, 8feff860 8feff860; 8f321401 34 - * 004001ff 00000001 .. 8feff860) Host was just getting NAKed on tx 35 - * of its next (512 byte) packet. IRQ issues? 36 - * 37 - * REVISIT: the "transfer DMA" glue between CPPI and USB fifos will 38 - * evidently also directly update the RX and TX CSRs ... so audit all 39 - * host and peripheral side DMA code to avoid CSR access after DMA has 40 - * been started. 41 - */ 42 - 43 - /* REVISIT now we can avoid preallocating these descriptors; or 44 - * more simply, switch to a global freelist not per-channel ones. 45 - * Note: at full speed, 64 descriptors == 4K bulk data. 46 - */ 47 - #define NUM_TXCHAN_BD 64 48 - #define NUM_RXCHAN_BD 64 49 - 50 - static inline void cpu_drain_writebuffer(void) 51 - { 52 - wmb(); 53 - #ifdef CONFIG_CPU_ARM926T 54 - /* REVISIT this "should not be needed", 55 - * but lack of it sure seemed to hurt ... 56 - */ 57 - asm("mcr p15, 0, r0, c7, c10, 4 @ drain write buffer\n"); 58 - #endif 59 - } 60 - 61 - static inline struct cppi_descriptor *cppi_bd_alloc(struct cppi_channel *c) 62 - { 63 - struct cppi_descriptor *bd = c->freelist; 64 - 65 - if (bd) 66 - c->freelist = bd->next; 67 - return bd; 68 - } 69 - 70 - static inline void 71 - cppi_bd_free(struct cppi_channel *c, struct cppi_descriptor *bd) 72 - { 73 - if (!bd) 74 - return; 75 - bd->next = c->freelist; 76 - c->freelist = bd; 77 - } 78 - 79 - /* 80 - * Start DMA controller 81 - * 82 - * Initialize the DMA controller as necessary. 83 - */ 84 - 85 - /* zero out entire rx state RAM entry for the channel */ 86 - static void cppi_reset_rx(struct cppi_rx_stateram __iomem *rx) 87 - { 88 - musb_writel(&rx->rx_skipbytes, 0, 0); 89 - musb_writel(&rx->rx_head, 0, 0); 90 - musb_writel(&rx->rx_sop, 0, 0); 91 - musb_writel(&rx->rx_current, 0, 0); 92 - musb_writel(&rx->rx_buf_current, 0, 0); 93 - musb_writel(&rx->rx_len_len, 0, 0); 94 - musb_writel(&rx->rx_cnt_cnt, 0, 0); 95 - } 96 - 97 - /* zero out entire tx state RAM entry for the channel */ 98 - static void cppi_reset_tx(struct cppi_tx_stateram __iomem *tx, u32 ptr) 99 - { 100 - musb_writel(&tx->tx_head, 0, 0); 101 - musb_writel(&tx->tx_buf, 0, 0); 102 - musb_writel(&tx->tx_current, 0, 0); 103 - musb_writel(&tx->tx_buf_current, 0, 0); 104 - musb_writel(&tx->tx_info, 0, 0); 105 - musb_writel(&tx->tx_rem_len, 0, 0); 106 - /* musb_writel(&tx->tx_dummy, 0, 0); */ 107 - musb_writel(&tx->tx_complete, 0, ptr); 108 - } 109 - 110 - static void cppi_pool_init(struct cppi *cppi, struct cppi_channel *c) 111 - { 112 - int j; 113 - 114 - /* initialize channel fields */ 115 - c->head = NULL; 116 - c->tail = NULL; 117 - c->last_processed = NULL; 118 - c->channel.status = MUSB_DMA_STATUS_UNKNOWN; 119 - c->controller = cppi; 120 - c->is_rndis = 0; 121 - c->freelist = NULL; 122 - 123 - /* build the BD Free list for the channel */ 124 - for (j = 0; j < NUM_TXCHAN_BD + 1; j++) { 125 - struct cppi_descriptor *bd; 126 - dma_addr_t dma; 127 - 128 - bd = dma_pool_alloc(cppi->pool, GFP_KERNEL, &dma); 129 - bd->dma = dma; 130 - cppi_bd_free(c, bd); 131 - } 132 - } 133 - 134 - static int cppi_channel_abort(struct dma_channel *); 135 - 136 - static void cppi_pool_free(struct cppi_channel *c) 137 - { 138 - struct cppi *cppi = c->controller; 139 - struct cppi_descriptor *bd; 140 - 141 - (void) cppi_channel_abort(&c->channel); 142 - c->channel.status = MUSB_DMA_STATUS_UNKNOWN; 143 - c->controller = NULL; 144 - 145 - /* free all its bds */ 146 - bd = c->last_processed; 147 - do { 148 - if (bd) 149 - dma_pool_free(cppi->pool, bd, bd->dma); 150 - bd = cppi_bd_alloc(c); 151 - } while (bd); 152 - c->last_processed = NULL; 153 - } 154 - 155 - static void cppi_controller_start(struct cppi *controller) 156 - { 157 - void __iomem *tibase; 158 - int i; 159 - 160 - /* do whatever is necessary to start controller */ 161 - for (i = 0; i < ARRAY_SIZE(controller->tx); i++) { 162 - controller->tx[i].transmit = true; 163 - controller->tx[i].index = i; 164 - } 165 - for (i = 0; i < ARRAY_SIZE(controller->rx); i++) { 166 - controller->rx[i].transmit = false; 167 - controller->rx[i].index = i; 168 - } 169 - 170 - /* setup BD list on a per channel basis */ 171 - for (i = 0; i < ARRAY_SIZE(controller->tx); i++) 172 - cppi_pool_init(controller, controller->tx + i); 173 - for (i = 0; i < ARRAY_SIZE(controller->rx); i++) 174 - cppi_pool_init(controller, controller->rx + i); 175 - 176 - tibase = controller->tibase; 177 - INIT_LIST_HEAD(&controller->tx_complete); 178 - 179 - /* initialise tx/rx channel head pointers to zero */ 180 - for (i = 0; i < ARRAY_SIZE(controller->tx); i++) { 181 - struct cppi_channel *tx_ch = controller->tx + i; 182 - struct cppi_tx_stateram __iomem *tx; 183 - 184 - INIT_LIST_HEAD(&tx_ch->tx_complete); 185 - 186 - tx = tibase + DAVINCI_TXCPPI_STATERAM_OFFSET(i); 187 - tx_ch->state_ram = tx; 188 - cppi_reset_tx(tx, 0); 189 - } 190 - for (i = 0; i < ARRAY_SIZE(controller->rx); i++) { 191 - struct cppi_channel *rx_ch = controller->rx + i; 192 - struct cppi_rx_stateram __iomem *rx; 193 - 194 - INIT_LIST_HEAD(&rx_ch->tx_complete); 195 - 196 - rx = tibase + DAVINCI_RXCPPI_STATERAM_OFFSET(i); 197 - rx_ch->state_ram = rx; 198 - cppi_reset_rx(rx); 199 - } 200 - 201 - /* enable individual cppi channels */ 202 - musb_writel(tibase, DAVINCI_TXCPPI_INTENAB_REG, 203 - DAVINCI_DMA_ALL_CHANNELS_ENABLE); 204 - musb_writel(tibase, DAVINCI_RXCPPI_INTENAB_REG, 205 - DAVINCI_DMA_ALL_CHANNELS_ENABLE); 206 - 207 - /* enable tx/rx CPPI control */ 208 - musb_writel(tibase, DAVINCI_TXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_ENABLE); 209 - musb_writel(tibase, DAVINCI_RXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_ENABLE); 210 - 211 - /* disable RNDIS mode, also host rx RNDIS autorequest */ 212 - musb_writel(tibase, DAVINCI_RNDIS_REG, 0); 213 - musb_writel(tibase, DAVINCI_AUTOREQ_REG, 0); 214 - } 215 - 216 - /* 217 - * Stop DMA controller 218 - * 219 - * De-Init the DMA controller as necessary. 220 - */ 221 - 222 - static void cppi_controller_stop(struct cppi *controller) 223 - { 224 - void __iomem *tibase; 225 - int i; 226 - struct musb *musb; 227 - 228 - musb = controller->controller.musb; 229 - 230 - tibase = controller->tibase; 231 - /* DISABLE INDIVIDUAL CHANNEL Interrupts */ 232 - musb_writel(tibase, DAVINCI_TXCPPI_INTCLR_REG, 233 - DAVINCI_DMA_ALL_CHANNELS_ENABLE); 234 - musb_writel(tibase, DAVINCI_RXCPPI_INTCLR_REG, 235 - DAVINCI_DMA_ALL_CHANNELS_ENABLE); 236 - 237 - musb_dbg(musb, "Tearing down RX and TX Channels"); 238 - for (i = 0; i < ARRAY_SIZE(controller->tx); i++) { 239 - /* FIXME restructure of txdma to use bds like rxdma */ 240 - controller->tx[i].last_processed = NULL; 241 - cppi_pool_free(controller->tx + i); 242 - } 243 - for (i = 0; i < ARRAY_SIZE(controller->rx); i++) 244 - cppi_pool_free(controller->rx + i); 245 - 246 - /* in Tx Case proper teardown is supported. We resort to disabling 247 - * Tx/Rx CPPI after cleanup of Tx channels. Before TX teardown is 248 - * complete TX CPPI cannot be disabled. 249 - */ 250 - /*disable tx/rx cppi */ 251 - musb_writel(tibase, DAVINCI_TXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_DISABLE); 252 - musb_writel(tibase, DAVINCI_RXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_DISABLE); 253 - } 254 - 255 - /* While dma channel is allocated, we only want the core irqs active 256 - * for fault reports, otherwise we'd get irqs that we don't care about. 257 - * Except for TX irqs, where dma done != fifo empty and reusable ... 258 - * 259 - * NOTE: docs don't say either way, but irq masking **enables** irqs. 260 - * 261 - * REVISIT same issue applies to pure PIO usage too, and non-cppi dma... 262 - */ 263 - static inline void core_rxirq_disable(void __iomem *tibase, unsigned epnum) 264 - { 265 - musb_writel(tibase, DAVINCI_USB_INT_MASK_CLR_REG, 1 << (epnum + 8)); 266 - } 267 - 268 - static inline void core_rxirq_enable(void __iomem *tibase, unsigned epnum) 269 - { 270 - musb_writel(tibase, DAVINCI_USB_INT_MASK_SET_REG, 1 << (epnum + 8)); 271 - } 272 - 273 - 274 - /* 275 - * Allocate a CPPI Channel for DMA. With CPPI, channels are bound to 276 - * each transfer direction of a non-control endpoint, so allocating 277 - * (and deallocating) is mostly a way to notice bad housekeeping on 278 - * the software side. We assume the irqs are always active. 279 - */ 280 - static struct dma_channel * 281 - cppi_channel_allocate(struct dma_controller *c, 282 - struct musb_hw_ep *ep, u8 transmit) 283 - { 284 - struct cppi *controller; 285 - u8 index; 286 - struct cppi_channel *cppi_ch; 287 - void __iomem *tibase; 288 - struct musb *musb; 289 - 290 - controller = container_of(c, struct cppi, controller); 291 - tibase = controller->tibase; 292 - musb = c->musb; 293 - 294 - /* ep0 doesn't use DMA; remember cppi indices are 0..N-1 */ 295 - index = ep->epnum - 1; 296 - 297 - /* return the corresponding CPPI Channel Handle, and 298 - * probably disable the non-CPPI irq until we need it. 299 - */ 300 - if (transmit) { 301 - if (index >= ARRAY_SIZE(controller->tx)) { 302 - musb_dbg(musb, "no %cX%d CPPI channel", 'T', index); 303 - return NULL; 304 - } 305 - cppi_ch = controller->tx + index; 306 - } else { 307 - if (index >= ARRAY_SIZE(controller->rx)) { 308 - musb_dbg(musb, "no %cX%d CPPI channel", 'R', index); 309 - return NULL; 310 - } 311 - cppi_ch = controller->rx + index; 312 - core_rxirq_disable(tibase, ep->epnum); 313 - } 314 - 315 - /* REVISIT make this an error later once the same driver code works 316 - * with the other DMA engine too 317 - */ 318 - if (cppi_ch->hw_ep) 319 - musb_dbg(musb, "re-allocating DMA%d %cX channel %p", 320 - index, transmit ? 'T' : 'R', cppi_ch); 321 - cppi_ch->hw_ep = ep; 322 - cppi_ch->channel.status = MUSB_DMA_STATUS_FREE; 323 - cppi_ch->channel.max_len = 0x7fffffff; 324 - 325 - musb_dbg(musb, "Allocate CPPI%d %cX", index, transmit ? 'T' : 'R'); 326 - return &cppi_ch->channel; 327 - } 328 - 329 - /* Release a CPPI Channel. */ 330 - static void cppi_channel_release(struct dma_channel *channel) 331 - { 332 - struct cppi_channel *c; 333 - void __iomem *tibase; 334 - 335 - /* REVISIT: for paranoia, check state and abort if needed... */ 336 - 337 - c = container_of(channel, struct cppi_channel, channel); 338 - tibase = c->controller->tibase; 339 - if (!c->hw_ep) 340 - musb_dbg(c->controller->controller.musb, 341 - "releasing idle DMA channel %p", c); 342 - else if (!c->transmit) 343 - core_rxirq_enable(tibase, c->index + 1); 344 - 345 - /* for now, leave its cppi IRQ enabled (we won't trigger it) */ 346 - c->hw_ep = NULL; 347 - channel->status = MUSB_DMA_STATUS_UNKNOWN; 348 - } 349 - 350 - /* Context: controller irqlocked */ 351 - static void 352 - cppi_dump_rx(int level, struct cppi_channel *c, const char *tag) 353 - { 354 - void __iomem *base = c->controller->mregs; 355 - struct cppi_rx_stateram __iomem *rx = c->state_ram; 356 - 357 - musb_ep_select(base, c->index + 1); 358 - 359 - musb_dbg(c->controller->controller.musb, 360 - "RX DMA%d%s: %d left, csr %04x, " 361 - "%08x H%08x S%08x C%08x, " 362 - "B%08x L%08x %08x .. %08x", 363 - c->index, tag, 364 - musb_readl(c->controller->tibase, 365 - DAVINCI_RXCPPI_BUFCNT0_REG + 4 * c->index), 366 - musb_readw(c->hw_ep->regs, MUSB_RXCSR), 367 - 368 - musb_readl(&rx->rx_skipbytes, 0), 369 - musb_readl(&rx->rx_head, 0), 370 - musb_readl(&rx->rx_sop, 0), 371 - musb_readl(&rx->rx_current, 0), 372 - 373 - musb_readl(&rx->rx_buf_current, 0), 374 - musb_readl(&rx->rx_len_len, 0), 375 - musb_readl(&rx->rx_cnt_cnt, 0), 376 - musb_readl(&rx->rx_complete, 0) 377 - ); 378 - } 379 - 380 - /* Context: controller irqlocked */ 381 - static void 382 - cppi_dump_tx(int level, struct cppi_channel *c, const char *tag) 383 - { 384 - void __iomem *base = c->controller->mregs; 385 - struct cppi_tx_stateram __iomem *tx = c->state_ram; 386 - 387 - musb_ep_select(base, c->index + 1); 388 - 389 - musb_dbg(c->controller->controller.musb, 390 - "TX DMA%d%s: csr %04x, " 391 - "H%08x S%08x C%08x %08x, " 392 - "F%08x L%08x .. %08x", 393 - c->index, tag, 394 - musb_readw(c->hw_ep->regs, MUSB_TXCSR), 395 - 396 - musb_readl(&tx->tx_head, 0), 397 - musb_readl(&tx->tx_buf, 0), 398 - musb_readl(&tx->tx_current, 0), 399 - musb_readl(&tx->tx_buf_current, 0), 400 - 401 - musb_readl(&tx->tx_info, 0), 402 - musb_readl(&tx->tx_rem_len, 0), 403 - /* dummy/unused word 6 */ 404 - musb_readl(&tx->tx_complete, 0) 405 - ); 406 - } 407 - 408 - /* Context: controller irqlocked */ 409 - static inline void 410 - cppi_rndis_update(struct cppi_channel *c, int is_rx, 411 - void __iomem *tibase, int is_rndis) 412 - { 413 - /* we may need to change the rndis flag for this cppi channel */ 414 - if (c->is_rndis != is_rndis) { 415 - u32 value = musb_readl(tibase, DAVINCI_RNDIS_REG); 416 - u32 temp = 1 << (c->index); 417 - 418 - if (is_rx) 419 - temp <<= 16; 420 - if (is_rndis) 421 - value |= temp; 422 - else 423 - value &= ~temp; 424 - musb_writel(tibase, DAVINCI_RNDIS_REG, value); 425 - c->is_rndis = is_rndis; 426 - } 427 - } 428 - 429 - static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd) 430 - { 431 - pr_debug("RXBD/%s %08x: " 432 - "nxt %08x buf %08x off.blen %08x opt.plen %08x\n", 433 - tag, bd->dma, 434 - bd->hw_next, bd->hw_bufp, bd->hw_off_len, 435 - bd->hw_options); 436 - } 437 - 438 - static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx) 439 - { 440 - struct cppi_descriptor *bd; 441 - 442 - cppi_dump_rx(level, rx, tag); 443 - if (rx->last_processed) 444 - cppi_dump_rxbd("last", rx->last_processed); 445 - for (bd = rx->head; bd; bd = bd->next) 446 - cppi_dump_rxbd("active", bd); 447 - } 448 - 449 - 450 - /* NOTE: DaVinci autoreq is ignored except for host side "RNDIS" mode RX; 451 - * so we won't ever use it (see "CPPI RX Woes" below). 452 - */ 453 - static inline int cppi_autoreq_update(struct cppi_channel *rx, 454 - void __iomem *tibase, int onepacket, unsigned n_bds) 455 - { 456 - u32 val; 457 - 458 - #ifdef RNDIS_RX_IS_USABLE 459 - u32 tmp; 460 - /* assert(is_host_active(musb)) */ 461 - 462 - /* start from "AutoReq never" */ 463 - tmp = musb_readl(tibase, DAVINCI_AUTOREQ_REG); 464 - val = tmp & ~((0x3) << (rx->index * 2)); 465 - 466 - /* HCD arranged reqpkt for packet #1. we arrange int 467 - * for all but the last one, maybe in two segments. 468 - */ 469 - if (!onepacket) { 470 - #if 0 471 - /* use two segments, autoreq "all" then the last "never" */ 472 - val |= ((0x3) << (rx->index * 2)); 473 - n_bds--; 474 - #else 475 - /* one segment, autoreq "all-but-last" */ 476 - val |= ((0x1) << (rx->index * 2)); 477 - #endif 478 - } 479 - 480 - if (val != tmp) { 481 - int n = 100; 482 - 483 - /* make sure that autoreq is updated before continuing */ 484 - musb_writel(tibase, DAVINCI_AUTOREQ_REG, val); 485 - do { 486 - tmp = musb_readl(tibase, DAVINCI_AUTOREQ_REG); 487 - if (tmp == val) 488 - break; 489 - cpu_relax(); 490 - } while (n-- > 0); 491 - } 492 - #endif 493 - 494 - /* REQPKT is turned off after each segment */ 495 - if (n_bds && rx->channel.actual_len) { 496 - void __iomem *regs = rx->hw_ep->regs; 497 - 498 - val = musb_readw(regs, MUSB_RXCSR); 499 - if (!(val & MUSB_RXCSR_H_REQPKT)) { 500 - val |= MUSB_RXCSR_H_REQPKT | MUSB_RXCSR_H_WZC_BITS; 501 - musb_writew(regs, MUSB_RXCSR, val); 502 - /* flush writebuffer */ 503 - val = musb_readw(regs, MUSB_RXCSR); 504 - } 505 - } 506 - return n_bds; 507 - } 508 - 509 - 510 - /* Buffer enqueuing Logic: 511 - * 512 - * - RX builds new queues each time, to help handle routine "early 513 - * termination" cases (faults, including errors and short reads) 514 - * more correctly. 515 - * 516 - * - for now, TX reuses the same queue of BDs every time 517 - * 518 - * REVISIT long term, we want a normal dynamic model. 519 - * ... the goal will be to append to the 520 - * existing queue, processing completed "dma buffers" (segments) on the fly. 521 - * 522 - * Otherwise we force an IRQ latency between requests, which slows us a lot 523 - * (especially in "transparent" dma). Unfortunately that model seems to be 524 - * inherent in the DMA model from the Mentor code, except in the rare case 525 - * of transfers big enough (~128+ KB) that we could append "middle" segments 526 - * in the TX paths. (RX can't do this, see below.) 527 - * 528 - * That's true even in the CPPI- friendly iso case, where most urbs have 529 - * several small segments provided in a group and where the "packet at a time" 530 - * "transparent" DMA model is always correct, even on the RX side. 531 - */ 532 - 533 - /* 534 - * CPPI TX: 535 - * ======== 536 - * TX is a lot more reasonable than RX; it doesn't need to run in 537 - * irq-per-packet mode very often. RNDIS mode seems to behave too 538 - * (except how it handles the exactly-N-packets case). Building a 539 - * txdma queue with multiple requests (urb or usb_request) looks 540 - * like it would work ... but fault handling would need much testing. 541 - * 542 - * The main issue with TX mode RNDIS relates to transfer lengths that 543 - * are an exact multiple of the packet length. It appears that there's 544 - * a hiccup in that case (maybe the DMA completes before the ZLP gets 545 - * written?) boiling down to not being able to rely on CPPI writing any 546 - * terminating zero length packet before the next transfer is written. 547 - * So that's punted to PIO; better yet, gadget drivers can avoid it. 548 - * 549 - * Plus, there's allegedly an undocumented constraint that rndis transfer 550 - * length be a multiple of 64 bytes ... but the chip doesn't act that 551 - * way, and we really don't _want_ that behavior anyway. 552 - * 553 - * On TX, "transparent" mode works ... although experiments have shown 554 - * problems trying to use the SOP/EOP bits in different USB packets. 555 - * 556 - * REVISIT try to handle terminating zero length packets using CPPI 557 - * instead of doing it by PIO after an IRQ. (Meanwhile, make Ethernet 558 - * links avoid that issue by forcing them to avoid zlps.) 559 - */ 560 - static void 561 - cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx) 562 - { 563 - unsigned maxpacket = tx->maxpacket; 564 - dma_addr_t addr = tx->buf_dma + tx->offset; 565 - size_t length = tx->buf_len - tx->offset; 566 - struct cppi_descriptor *bd; 567 - unsigned n_bds; 568 - unsigned i; 569 - struct cppi_tx_stateram __iomem *tx_ram = tx->state_ram; 570 - int rndis; 571 - 572 - /* TX can use the CPPI "rndis" mode, where we can probably fit this 573 - * transfer in one BD and one IRQ. The only time we would NOT want 574 - * to use it is when hardware constraints prevent it, or if we'd 575 - * trigger the "send a ZLP?" confusion. 576 - */ 577 - rndis = (maxpacket & 0x3f) == 0 578 - && length > maxpacket 579 - && length < 0xffff 580 - && (length % maxpacket) != 0; 581 - 582 - if (rndis) { 583 - maxpacket = length; 584 - n_bds = 1; 585 - } else { 586 - if (length) 587 - n_bds = DIV_ROUND_UP(length, maxpacket); 588 - else 589 - n_bds = 1; 590 - n_bds = min(n_bds, (unsigned) NUM_TXCHAN_BD); 591 - length = min(n_bds * maxpacket, length); 592 - } 593 - 594 - musb_dbg(musb, "TX DMA%d, pktSz %d %s bds %d dma 0x%llx len %u", 595 - tx->index, 596 - maxpacket, 597 - rndis ? "rndis" : "transparent", 598 - n_bds, 599 - (unsigned long long)addr, length); 600 - 601 - cppi_rndis_update(tx, 0, musb->ctrl_base, rndis); 602 - 603 - /* assuming here that channel_program is called during 604 - * transfer initiation ... current code maintains state 605 - * for one outstanding request only (no queues, not even 606 - * the implicit ones of an iso urb). 607 - */ 608 - 609 - bd = tx->freelist; 610 - tx->head = bd; 611 - tx->last_processed = NULL; 612 - 613 - /* FIXME use BD pool like RX side does, and just queue 614 - * the minimum number for this request. 615 - */ 616 - 617 - /* Prepare queue of BDs first, then hand it to hardware. 618 - * All BDs except maybe the last should be of full packet 619 - * size; for RNDIS there _is_ only that last packet. 620 - */ 621 - for (i = 0; i < n_bds; ) { 622 - if (++i < n_bds && bd->next) 623 - bd->hw_next = bd->next->dma; 624 - else 625 - bd->hw_next = 0; 626 - 627 - bd->hw_bufp = tx->buf_dma + tx->offset; 628 - 629 - /* FIXME set EOP only on the last packet, 630 - * SOP only on the first ... avoid IRQs 631 - */ 632 - if ((tx->offset + maxpacket) <= tx->buf_len) { 633 - tx->offset += maxpacket; 634 - bd->hw_off_len = maxpacket; 635 - bd->hw_options = CPPI_SOP_SET | CPPI_EOP_SET 636 - | CPPI_OWN_SET | maxpacket; 637 - } else { 638 - /* only this one may be a partial USB Packet */ 639 - u32 partial_len; 640 - 641 - partial_len = tx->buf_len - tx->offset; 642 - tx->offset = tx->buf_len; 643 - bd->hw_off_len = partial_len; 644 - 645 - bd->hw_options = CPPI_SOP_SET | CPPI_EOP_SET 646 - | CPPI_OWN_SET | partial_len; 647 - if (partial_len == 0) 648 - bd->hw_options |= CPPI_ZERO_SET; 649 - } 650 - 651 - musb_dbg(musb, "TXBD %p: nxt %08x buf %08x len %04x opt %08x", 652 - bd, bd->hw_next, bd->hw_bufp, 653 - bd->hw_off_len, bd->hw_options); 654 - 655 - /* update the last BD enqueued to the list */ 656 - tx->tail = bd; 657 - bd = bd->next; 658 - } 659 - 660 - /* BDs live in DMA-coherent memory, but writes might be pending */ 661 - cpu_drain_writebuffer(); 662 - 663 - /* Write to the HeadPtr in state RAM to trigger */ 664 - musb_writel(&tx_ram->tx_head, 0, (u32)tx->freelist->dma); 665 - 666 - cppi_dump_tx(5, tx, "/S"); 667 - } 668 - 669 - /* 670 - * CPPI RX Woes: 671 - * ============= 672 - * Consider a 1KB bulk RX buffer in two scenarios: (a) it's fed two 300 byte 673 - * packets back-to-back, and (b) it's fed two 512 byte packets back-to-back. 674 - * (Full speed transfers have similar scenarios.) 675 - * 676 - * The correct behavior for Linux is that (a) fills the buffer with 300 bytes, 677 - * and the next packet goes into a buffer that's queued later; while (b) fills 678 - * the buffer with 1024 bytes. How to do that with CPPI? 679 - * 680 - * - RX queues in "rndis" mode -- one single BD -- handle (a) correctly, but 681 - * (b) loses **BADLY** because nothing (!) happens when that second packet 682 - * fills the buffer, much less when a third one arrives. (Which makes this 683 - * not a "true" RNDIS mode. In the RNDIS protocol short-packet termination 684 - * is optional, and it's fine if peripherals -- not hosts! -- pad messages 685 - * out to end-of-buffer. Standard PCI host controller DMA descriptors 686 - * implement that mode by default ... which is no accident.) 687 - * 688 - * - RX queues in "transparent" mode -- two BDs with 512 bytes each -- have 689 - * converse problems: (b) is handled right, but (a) loses badly. CPPI RX 690 - * ignores SOP/EOP markings and processes both of those BDs; so both packets 691 - * are loaded into the buffer (with a 212 byte gap between them), and the next 692 - * buffer queued will NOT get its 300 bytes of data. (It seems like SOP/EOP 693 - * are intended as outputs for RX queues, not inputs...) 694 - * 695 - * - A variant of "transparent" mode -- one BD at a time -- is the only way to 696 - * reliably make both cases work, with software handling both cases correctly 697 - * and at the significant penalty of needing an IRQ per packet. (The lack of 698 - * I/O overlap can be slightly ameliorated by enabling double buffering.) 699 - * 700 - * So how to get rid of IRQ-per-packet? The transparent multi-BD case could 701 - * be used in special cases like mass storage, which sets URB_SHORT_NOT_OK 702 - * (or maybe its peripheral side counterpart) to flag (a) scenarios as errors 703 - * with guaranteed driver level fault recovery and scrubbing out what's left 704 - * of that garbaged datastream. 705 - * 706 - * But there seems to be no way to identify the cases where CPPI RNDIS mode 707 - * is appropriate -- which do NOT include RNDIS host drivers, but do include 708 - * the CDC Ethernet driver! -- and the documentation is incomplete/wrong. 709 - * So we can't _ever_ use RX RNDIS mode ... except by using a heuristic 710 - * that applies best on the peripheral side (and which could fail rudely). 711 - * 712 - * Leaving only "transparent" mode; we avoid multi-bd modes in almost all 713 - * cases other than mass storage class. Otherwise we're correct but slow, 714 - * since CPPI penalizes our need for a "true RNDIS" default mode. 715 - */ 716 - 717 - 718 - /* Heuristic, intended to kick in for ethernet/rndis peripheral ONLY 719 - * 720 - * IFF 721 - * (a) peripheral mode ... since rndis peripherals could pad their 722 - * writes to hosts, causing i/o failure; or we'd have to cope with 723 - * a largely unknowable variety of host side protocol variants 724 - * (b) and short reads are NOT errors ... since full reads would 725 - * cause those same i/o failures 726 - * (c) and read length is 727 - * - less than 64KB (max per cppi descriptor) 728 - * - not a multiple of 4096 (g_zero default, full reads typical) 729 - * - N (>1) packets long, ditto (full reads not EXPECTED) 730 - * THEN 731 - * try rx rndis mode 732 - * 733 - * Cost of heuristic failing: RXDMA wedges at the end of transfers that 734 - * fill out the whole buffer. Buggy host side usb network drivers could 735 - * trigger that, but "in the field" such bugs seem to be all but unknown. 736 - * 737 - * So this module parameter lets the heuristic be disabled. When using 738 - * gadgetfs, the heuristic will probably need to be disabled. 739 - */ 740 - static bool cppi_rx_rndis = 1; 741 - 742 - module_param(cppi_rx_rndis, bool, 0); 743 - MODULE_PARM_DESC(cppi_rx_rndis, "enable/disable RX RNDIS heuristic"); 744 - 745 - 746 - /** 747 - * cppi_next_rx_segment - dma read for the next chunk of a buffer 748 - * @musb: the controller 749 - * @rx: dma channel 750 - * @onepacket: true unless caller treats short reads as errors, and 751 - * performs fault recovery above usbcore. 752 - * Context: controller irqlocked 753 - * 754 - * See above notes about why we can't use multi-BD RX queues except in 755 - * rare cases (mass storage class), and can never use the hardware "rndis" 756 - * mode (since it's not a "true" RNDIS mode) with complete safety.. 757 - * 758 - * It's ESSENTIAL that callers specify "onepacket" mode unless they kick in 759 - * code to recover from corrupted datastreams after each short transfer. 760 - */ 761 - static void 762 - cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket) 763 - { 764 - unsigned maxpacket = rx->maxpacket; 765 - dma_addr_t addr = rx->buf_dma + rx->offset; 766 - size_t length = rx->buf_len - rx->offset; 767 - struct cppi_descriptor *bd, *tail; 768 - unsigned n_bds; 769 - unsigned i; 770 - void __iomem *tibase = musb->ctrl_base; 771 - int is_rndis = 0; 772 - struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram; 773 - struct cppi_descriptor *d; 774 - 775 - if (onepacket) { 776 - /* almost every USB driver, host or peripheral side */ 777 - n_bds = 1; 778 - 779 - /* maybe apply the heuristic above */ 780 - if (cppi_rx_rndis 781 - && is_peripheral_active(musb) 782 - && length > maxpacket 783 - && (length & ~0xffff) == 0 784 - && (length & 0x0fff) != 0 785 - && (length & (maxpacket - 1)) == 0) { 786 - maxpacket = length; 787 - is_rndis = 1; 788 - } 789 - } else { 790 - /* virtually nothing except mass storage class */ 791 - if (length > 0xffff) { 792 - n_bds = 0xffff / maxpacket; 793 - length = n_bds * maxpacket; 794 - } else { 795 - n_bds = DIV_ROUND_UP(length, maxpacket); 796 - } 797 - if (n_bds == 1) 798 - onepacket = 1; 799 - else 800 - n_bds = min(n_bds, (unsigned) NUM_RXCHAN_BD); 801 - } 802 - 803 - /* In host mode, autorequest logic can generate some IN tokens; it's 804 - * tricky since we can't leave REQPKT set in RXCSR after the transfer 805 - * finishes. So: multipacket transfers involve two or more segments. 806 - * And always at least two IRQs ... RNDIS mode is not an option. 807 - */ 808 - if (is_host_active(musb)) 809 - n_bds = cppi_autoreq_update(rx, tibase, onepacket, n_bds); 810 - 811 - cppi_rndis_update(rx, 1, musb->ctrl_base, is_rndis); 812 - 813 - length = min(n_bds * maxpacket, length); 814 - 815 - musb_dbg(musb, "RX DMA%d seg, maxp %d %s bds %d (cnt %d) " 816 - "dma 0x%llx len %u %u/%u", 817 - rx->index, maxpacket, 818 - onepacket 819 - ? (is_rndis ? "rndis" : "onepacket") 820 - : "multipacket", 821 - n_bds, 822 - musb_readl(tibase, 823 - DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4)) 824 - & 0xffff, 825 - (unsigned long long)addr, length, 826 - rx->channel.actual_len, rx->buf_len); 827 - 828 - /* only queue one segment at a time, since the hardware prevents 829 - * correct queue shutdown after unexpected short packets 830 - */ 831 - bd = cppi_bd_alloc(rx); 832 - rx->head = bd; 833 - 834 - /* Build BDs for all packets in this segment */ 835 - for (i = 0, tail = NULL; bd && i < n_bds; i++, tail = bd) { 836 - u32 bd_len; 837 - 838 - if (i) { 839 - bd = cppi_bd_alloc(rx); 840 - if (!bd) 841 - break; 842 - tail->next = bd; 843 - tail->hw_next = bd->dma; 844 - } 845 - bd->hw_next = 0; 846 - 847 - /* all but the last packet will be maxpacket size */ 848 - if (maxpacket < length) 849 - bd_len = maxpacket; 850 - else 851 - bd_len = length; 852 - 853 - bd->hw_bufp = addr; 854 - addr += bd_len; 855 - rx->offset += bd_len; 856 - 857 - bd->hw_off_len = (0 /*offset*/ << 16) + bd_len; 858 - bd->buflen = bd_len; 859 - 860 - bd->hw_options = CPPI_OWN_SET | (i == 0 ? length : 0); 861 - length -= bd_len; 862 - } 863 - 864 - /* we always expect at least one reusable BD! */ 865 - if (!tail) { 866 - WARNING("rx dma%d -- no BDs? need %d\n", rx->index, n_bds); 867 - return; 868 - } else if (i < n_bds) 869 - WARNING("rx dma%d -- only %d of %d BDs\n", rx->index, i, n_bds); 870 - 871 - tail->next = NULL; 872 - tail->hw_next = 0; 873 - 874 - bd = rx->head; 875 - rx->tail = tail; 876 - 877 - /* short reads and other faults should terminate this entire 878 - * dma segment. we want one "dma packet" per dma segment, not 879 - * one per USB packet, terminating the whole queue at once... 880 - * NOTE that current hardware seems to ignore SOP and EOP. 881 - */ 882 - bd->hw_options |= CPPI_SOP_SET; 883 - tail->hw_options |= CPPI_EOP_SET; 884 - 885 - for (d = rx->head; d; d = d->next) 886 - cppi_dump_rxbd("S", d); 887 - 888 - /* in case the preceding transfer left some state... */ 889 - tail = rx->last_processed; 890 - if (tail) { 891 - tail->next = bd; 892 - tail->hw_next = bd->dma; 893 - } 894 - 895 - core_rxirq_enable(tibase, rx->index + 1); 896 - 897 - /* BDs live in DMA-coherent memory, but writes might be pending */ 898 - cpu_drain_writebuffer(); 899 - 900 - /* REVISIT specs say to write this AFTER the BUFCNT register 901 - * below ... but that loses badly. 902 - */ 903 - musb_writel(&rx_ram->rx_head, 0, bd->dma); 904 - 905 - /* bufferCount must be at least 3, and zeroes on completion 906 - * unless it underflows below zero, or stops at two, or keeps 907 - * growing ... grr. 908 - */ 909 - i = musb_readl(tibase, 910 - DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4)) 911 - & 0xffff; 912 - 913 - if (!i) 914 - musb_writel(tibase, 915 - DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4), 916 - n_bds + 2); 917 - else if (n_bds > (i - 3)) 918 - musb_writel(tibase, 919 - DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4), 920 - n_bds - (i - 3)); 921 - 922 - i = musb_readl(tibase, 923 - DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4)) 924 - & 0xffff; 925 - if (i < (2 + n_bds)) { 926 - musb_dbg(musb, "bufcnt%d underrun - %d (for %d)", 927 - rx->index, i, n_bds); 928 - musb_writel(tibase, 929 - DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4), 930 - n_bds + 2); 931 - } 932 - 933 - cppi_dump_rx(4, rx, "/S"); 934 - } 935 - 936 - /** 937 - * cppi_channel_program - program channel for data transfer 938 - * @ch: the channel 939 - * @maxpacket: max packet size 940 - * @mode: For RX, 1 unless the usb protocol driver promised to treat 941 - * all short reads as errors and kick in high level fault recovery. 942 - * For TX, ignored because of RNDIS mode races/glitches. 943 - * @dma_addr: dma address of buffer 944 - * @len: length of buffer 945 - * Context: controller irqlocked 946 - */ 947 - static int cppi_channel_program(struct dma_channel *ch, 948 - u16 maxpacket, u8 mode, 949 - dma_addr_t dma_addr, u32 len) 950 - { 951 - struct cppi_channel *cppi_ch; 952 - struct cppi *controller; 953 - struct musb *musb; 954 - 955 - cppi_ch = container_of(ch, struct cppi_channel, channel); 956 - controller = cppi_ch->controller; 957 - musb = controller->controller.musb; 958 - 959 - switch (ch->status) { 960 - case MUSB_DMA_STATUS_BUS_ABORT: 961 - case MUSB_DMA_STATUS_CORE_ABORT: 962 - /* fault irq handler should have handled cleanup */ 963 - WARNING("%cX DMA%d not cleaned up after abort!\n", 964 - cppi_ch->transmit ? 'T' : 'R', 965 - cppi_ch->index); 966 - /* WARN_ON(1); */ 967 - break; 968 - case MUSB_DMA_STATUS_BUSY: 969 - WARNING("program active channel? %cX DMA%d\n", 970 - cppi_ch->transmit ? 'T' : 'R', 971 - cppi_ch->index); 972 - /* WARN_ON(1); */ 973 - break; 974 - case MUSB_DMA_STATUS_UNKNOWN: 975 - musb_dbg(musb, "%cX DMA%d not allocated!", 976 - cppi_ch->transmit ? 'T' : 'R', 977 - cppi_ch->index); 978 - fallthrough; 979 - case MUSB_DMA_STATUS_FREE: 980 - break; 981 - } 982 - 983 - ch->status = MUSB_DMA_STATUS_BUSY; 984 - 985 - /* set transfer parameters, then queue up its first segment */ 986 - cppi_ch->buf_dma = dma_addr; 987 - cppi_ch->offset = 0; 988 - cppi_ch->maxpacket = maxpacket; 989 - cppi_ch->buf_len = len; 990 - cppi_ch->channel.actual_len = 0; 991 - 992 - /* TX channel? or RX? */ 993 - if (cppi_ch->transmit) 994 - cppi_next_tx_segment(musb, cppi_ch); 995 - else 996 - cppi_next_rx_segment(musb, cppi_ch, mode); 997 - 998 - return true; 999 - } 1000 - 1001 - static bool cppi_rx_scan(struct cppi *cppi, unsigned ch) 1002 - { 1003 - struct cppi_channel *rx = &cppi->rx[ch]; 1004 - struct cppi_rx_stateram __iomem *state = rx->state_ram; 1005 - struct cppi_descriptor *bd; 1006 - struct cppi_descriptor *last = rx->last_processed; 1007 - bool completed = false; 1008 - bool acked = false; 1009 - int i; 1010 - dma_addr_t safe2ack; 1011 - void __iomem *regs = rx->hw_ep->regs; 1012 - struct musb *musb = cppi->controller.musb; 1013 - 1014 - cppi_dump_rx(6, rx, "/K"); 1015 - 1016 - bd = last ? last->next : rx->head; 1017 - if (!bd) 1018 - return false; 1019 - 1020 - /* run through all completed BDs */ 1021 - for (i = 0, safe2ack = musb_readl(&state->rx_complete, 0); 1022 - (safe2ack || completed) && bd && i < NUM_RXCHAN_BD; 1023 - i++, bd = bd->next) { 1024 - u16 len; 1025 - 1026 - /* catch latest BD writes from CPPI */ 1027 - rmb(); 1028 - if (!completed && (bd->hw_options & CPPI_OWN_SET)) 1029 - break; 1030 - 1031 - musb_dbg(musb, "C/RXBD %llx: nxt %08x buf %08x " 1032 - "off.len %08x opt.len %08x (%d)", 1033 - (unsigned long long)bd->dma, bd->hw_next, bd->hw_bufp, 1034 - bd->hw_off_len, bd->hw_options, 1035 - rx->channel.actual_len); 1036 - 1037 - /* actual packet received length */ 1038 - if ((bd->hw_options & CPPI_SOP_SET) && !completed) 1039 - len = bd->hw_off_len & CPPI_RECV_PKTLEN_MASK; 1040 - else 1041 - len = 0; 1042 - 1043 - if (bd->hw_options & CPPI_EOQ_MASK) 1044 - completed = true; 1045 - 1046 - if (!completed && len < bd->buflen) { 1047 - /* NOTE: when we get a short packet, RXCSR_H_REQPKT 1048 - * must have been cleared, and no more DMA packets may 1049 - * active be in the queue... TI docs didn't say, but 1050 - * CPPI ignores those BDs even though OWN is still set. 1051 - */ 1052 - completed = true; 1053 - musb_dbg(musb, "rx short %d/%d (%d)", 1054 - len, bd->buflen, 1055 - rx->channel.actual_len); 1056 - } 1057 - 1058 - /* If we got here, we expect to ack at least one BD; meanwhile 1059 - * CPPI may completing other BDs while we scan this list... 1060 - * 1061 - * RACE: we can notice OWN cleared before CPPI raises the 1062 - * matching irq by writing that BD as the completion pointer. 1063 - * In such cases, stop scanning and wait for the irq, avoiding 1064 - * lost acks and states where BD ownership is unclear. 1065 - */ 1066 - if (bd->dma == safe2ack) { 1067 - musb_writel(&state->rx_complete, 0, safe2ack); 1068 - safe2ack = musb_readl(&state->rx_complete, 0); 1069 - acked = true; 1070 - if (bd->dma == safe2ack) 1071 - safe2ack = 0; 1072 - } 1073 - 1074 - rx->channel.actual_len += len; 1075 - 1076 - cppi_bd_free(rx, last); 1077 - last = bd; 1078 - 1079 - /* stop scanning on end-of-segment */ 1080 - if (bd->hw_next == 0) 1081 - completed = true; 1082 - } 1083 - rx->last_processed = last; 1084 - 1085 - /* dma abort, lost ack, or ... */ 1086 - if (!acked && last) { 1087 - int csr; 1088 - 1089 - if (safe2ack == 0 || safe2ack == rx->last_processed->dma) 1090 - musb_writel(&state->rx_complete, 0, safe2ack); 1091 - if (safe2ack == 0) { 1092 - cppi_bd_free(rx, last); 1093 - rx->last_processed = NULL; 1094 - 1095 - /* if we land here on the host side, H_REQPKT will 1096 - * be clear and we need to restart the queue... 1097 - */ 1098 - WARN_ON(rx->head); 1099 - } 1100 - musb_ep_select(cppi->mregs, rx->index + 1); 1101 - csr = musb_readw(regs, MUSB_RXCSR); 1102 - if (csr & MUSB_RXCSR_DMAENAB) { 1103 - musb_dbg(musb, "list%d %p/%p, last %llx%s, csr %04x", 1104 - rx->index, 1105 - rx->head, rx->tail, 1106 - rx->last_processed 1107 - ? (unsigned long long) 1108 - rx->last_processed->dma 1109 - : 0, 1110 - completed ? ", completed" : "", 1111 - csr); 1112 - cppi_dump_rxq(4, "/what?", rx); 1113 - } 1114 - } 1115 - if (!completed) { 1116 - int csr; 1117 - 1118 - rx->head = bd; 1119 - 1120 - /* REVISIT seems like "autoreq all but EOP" doesn't... 1121 - * setting it here "should" be racey, but seems to work 1122 - */ 1123 - csr = musb_readw(rx->hw_ep->regs, MUSB_RXCSR); 1124 - if (is_host_active(cppi->controller.musb) 1125 - && bd 1126 - && !(csr & MUSB_RXCSR_H_REQPKT)) { 1127 - csr |= MUSB_RXCSR_H_REQPKT; 1128 - musb_writew(regs, MUSB_RXCSR, 1129 - MUSB_RXCSR_H_WZC_BITS | csr); 1130 - csr = musb_readw(rx->hw_ep->regs, MUSB_RXCSR); 1131 - } 1132 - } else { 1133 - rx->head = NULL; 1134 - rx->tail = NULL; 1135 - } 1136 - 1137 - cppi_dump_rx(6, rx, completed ? "/completed" : "/cleaned"); 1138 - return completed; 1139 - } 1140 - 1141 - irqreturn_t cppi_interrupt(int irq, void *dev_id) 1142 - { 1143 - struct musb *musb = dev_id; 1144 - struct cppi *cppi; 1145 - void __iomem *tibase; 1146 - struct musb_hw_ep *hw_ep = NULL; 1147 - u32 rx, tx; 1148 - int i, index; 1149 - unsigned long flags; 1150 - 1151 - cppi = container_of(musb->dma_controller, struct cppi, controller); 1152 - if (cppi->irq) 1153 - spin_lock_irqsave(&musb->lock, flags); 1154 - 1155 - tibase = musb->ctrl_base; 1156 - 1157 - tx = musb_readl(tibase, DAVINCI_TXCPPI_MASKED_REG); 1158 - rx = musb_readl(tibase, DAVINCI_RXCPPI_MASKED_REG); 1159 - 1160 - if (!tx && !rx) { 1161 - if (cppi->irq) 1162 - spin_unlock_irqrestore(&musb->lock, flags); 1163 - return IRQ_NONE; 1164 - } 1165 - 1166 - musb_dbg(musb, "CPPI IRQ Tx%x Rx%x", tx, rx); 1167 - 1168 - /* process TX channels */ 1169 - for (index = 0; tx; tx = tx >> 1, index++) { 1170 - struct cppi_channel *tx_ch; 1171 - struct cppi_tx_stateram __iomem *tx_ram; 1172 - bool completed = false; 1173 - struct cppi_descriptor *bd; 1174 - 1175 - if (!(tx & 1)) 1176 - continue; 1177 - 1178 - tx_ch = cppi->tx + index; 1179 - tx_ram = tx_ch->state_ram; 1180 - 1181 - /* FIXME need a cppi_tx_scan() routine, which 1182 - * can also be called from abort code 1183 - */ 1184 - 1185 - cppi_dump_tx(5, tx_ch, "/E"); 1186 - 1187 - bd = tx_ch->head; 1188 - 1189 - /* 1190 - * If Head is null then this could mean that a abort interrupt 1191 - * that needs to be acknowledged. 1192 - */ 1193 - if (NULL == bd) { 1194 - musb_dbg(musb, "null BD"); 1195 - musb_writel(&tx_ram->tx_complete, 0, 0); 1196 - continue; 1197 - } 1198 - 1199 - /* run through all completed BDs */ 1200 - for (i = 0; !completed && bd && i < NUM_TXCHAN_BD; 1201 - i++, bd = bd->next) { 1202 - u16 len; 1203 - 1204 - /* catch latest BD writes from CPPI */ 1205 - rmb(); 1206 - if (bd->hw_options & CPPI_OWN_SET) 1207 - break; 1208 - 1209 - musb_dbg(musb, "C/TXBD %p n %x b %x off %x opt %x", 1210 - bd, bd->hw_next, bd->hw_bufp, 1211 - bd->hw_off_len, bd->hw_options); 1212 - 1213 - len = bd->hw_off_len & CPPI_BUFFER_LEN_MASK; 1214 - tx_ch->channel.actual_len += len; 1215 - 1216 - tx_ch->last_processed = bd; 1217 - 1218 - /* write completion register to acknowledge 1219 - * processing of completed BDs, and possibly 1220 - * release the IRQ; EOQ might not be set ... 1221 - * 1222 - * REVISIT use the same ack strategy as rx 1223 - * 1224 - * REVISIT have observed bit 18 set; huh?? 1225 - */ 1226 - /* if ((bd->hw_options & CPPI_EOQ_MASK)) */ 1227 - musb_writel(&tx_ram->tx_complete, 0, bd->dma); 1228 - 1229 - /* stop scanning on end-of-segment */ 1230 - if (bd->hw_next == 0) 1231 - completed = true; 1232 - } 1233 - 1234 - /* on end of segment, maybe go to next one */ 1235 - if (completed) { 1236 - /* cppi_dump_tx(4, tx_ch, "/complete"); */ 1237 - 1238 - /* transfer more, or report completion */ 1239 - if (tx_ch->offset >= tx_ch->buf_len) { 1240 - tx_ch->head = NULL; 1241 - tx_ch->tail = NULL; 1242 - tx_ch->channel.status = MUSB_DMA_STATUS_FREE; 1243 - 1244 - hw_ep = tx_ch->hw_ep; 1245 - 1246 - musb_dma_completion(musb, index + 1, 1); 1247 - 1248 - } else { 1249 - /* Bigger transfer than we could fit in 1250 - * that first batch of descriptors... 1251 - */ 1252 - cppi_next_tx_segment(musb, tx_ch); 1253 - } 1254 - } else 1255 - tx_ch->head = bd; 1256 - } 1257 - 1258 - /* Start processing the RX block */ 1259 - for (index = 0; rx; rx = rx >> 1, index++) { 1260 - 1261 - if (rx & 1) { 1262 - struct cppi_channel *rx_ch; 1263 - 1264 - rx_ch = cppi->rx + index; 1265 - 1266 - /* let incomplete dma segments finish */ 1267 - if (!cppi_rx_scan(cppi, index)) 1268 - continue; 1269 - 1270 - /* start another dma segment if needed */ 1271 - if (rx_ch->channel.actual_len != rx_ch->buf_len 1272 - && rx_ch->channel.actual_len 1273 - == rx_ch->offset) { 1274 - cppi_next_rx_segment(musb, rx_ch, 1); 1275 - continue; 1276 - } 1277 - 1278 - /* all segments completed! */ 1279 - rx_ch->channel.status = MUSB_DMA_STATUS_FREE; 1280 - 1281 - hw_ep = rx_ch->hw_ep; 1282 - 1283 - core_rxirq_disable(tibase, index + 1); 1284 - musb_dma_completion(musb, index + 1, 0); 1285 - } 1286 - } 1287 - 1288 - /* write to CPPI EOI register to re-enable interrupts */ 1289 - musb_writel(tibase, DAVINCI_CPPI_EOI_REG, 0); 1290 - 1291 - if (cppi->irq) 1292 - spin_unlock_irqrestore(&musb->lock, flags); 1293 - 1294 - return IRQ_HANDLED; 1295 - } 1296 - EXPORT_SYMBOL_GPL(cppi_interrupt); 1297 - 1298 - /* Instantiate a software object representing a DMA controller. */ 1299 - struct dma_controller * 1300 - cppi_dma_controller_create(struct musb *musb, void __iomem *mregs) 1301 - { 1302 - struct cppi *controller; 1303 - struct device *dev = musb->controller; 1304 - struct platform_device *pdev = to_platform_device(dev); 1305 - int irq = platform_get_irq_byname(pdev, "dma"); 1306 - 1307 - controller = kzalloc(sizeof *controller, GFP_KERNEL); 1308 - if (!controller) 1309 - return NULL; 1310 - 1311 - controller->mregs = mregs; 1312 - controller->tibase = mregs - DAVINCI_BASE_OFFSET; 1313 - 1314 - controller->controller.musb = musb; 1315 - controller->controller.channel_alloc = cppi_channel_allocate; 1316 - controller->controller.channel_release = cppi_channel_release; 1317 - controller->controller.channel_program = cppi_channel_program; 1318 - controller->controller.channel_abort = cppi_channel_abort; 1319 - 1320 - /* NOTE: allocating from on-chip SRAM would give the least 1321 - * contention for memory access, if that ever matters here. 1322 - */ 1323 - 1324 - /* setup BufferPool */ 1325 - controller->pool = dma_pool_create("cppi", 1326 - controller->controller.musb->controller, 1327 - sizeof(struct cppi_descriptor), 1328 - CPPI_DESCRIPTOR_ALIGN, 0); 1329 - if (!controller->pool) { 1330 - kfree(controller); 1331 - return NULL; 1332 - } 1333 - 1334 - if (irq > 0) { 1335 - if (request_irq(irq, cppi_interrupt, 0, "cppi-dma", musb)) { 1336 - dev_err(dev, "request_irq %d failed!\n", irq); 1337 - musb_dma_controller_destroy(&controller->controller); 1338 - return NULL; 1339 - } 1340 - controller->irq = irq; 1341 - } 1342 - 1343 - cppi_controller_start(controller); 1344 - return &controller->controller; 1345 - } 1346 - EXPORT_SYMBOL_GPL(cppi_dma_controller_create); 1347 - 1348 - /* 1349 - * Destroy a previously-instantiated DMA controller. 1350 - */ 1351 - void cppi_dma_controller_destroy(struct dma_controller *c) 1352 - { 1353 - struct cppi *cppi; 1354 - 1355 - cppi = container_of(c, struct cppi, controller); 1356 - 1357 - cppi_controller_stop(cppi); 1358 - 1359 - if (cppi->irq) 1360 - free_irq(cppi->irq, cppi->controller.musb); 1361 - 1362 - /* assert: caller stopped the controller first */ 1363 - dma_pool_destroy(cppi->pool); 1364 - 1365 - kfree(cppi); 1366 - } 1367 - EXPORT_SYMBOL_GPL(cppi_dma_controller_destroy); 1368 - 1369 - /* 1370 - * Context: controller irqlocked, endpoint selected 1371 - */ 1372 - static int cppi_channel_abort(struct dma_channel *channel) 1373 - { 1374 - struct cppi_channel *cppi_ch; 1375 - struct cppi *controller; 1376 - void __iomem *mbase; 1377 - void __iomem *tibase; 1378 - void __iomem *regs; 1379 - u32 value; 1380 - struct cppi_descriptor *queue; 1381 - 1382 - cppi_ch = container_of(channel, struct cppi_channel, channel); 1383 - 1384 - controller = cppi_ch->controller; 1385 - 1386 - switch (channel->status) { 1387 - case MUSB_DMA_STATUS_BUS_ABORT: 1388 - case MUSB_DMA_STATUS_CORE_ABORT: 1389 - /* from RX or TX fault irq handler */ 1390 - case MUSB_DMA_STATUS_BUSY: 1391 - /* the hardware needs shutting down */ 1392 - regs = cppi_ch->hw_ep->regs; 1393 - break; 1394 - case MUSB_DMA_STATUS_UNKNOWN: 1395 - case MUSB_DMA_STATUS_FREE: 1396 - return 0; 1397 - default: 1398 - return -EINVAL; 1399 - } 1400 - 1401 - if (!cppi_ch->transmit && cppi_ch->head) 1402 - cppi_dump_rxq(3, "/abort", cppi_ch); 1403 - 1404 - mbase = controller->mregs; 1405 - tibase = controller->tibase; 1406 - 1407 - queue = cppi_ch->head; 1408 - cppi_ch->head = NULL; 1409 - cppi_ch->tail = NULL; 1410 - 1411 - /* REVISIT should rely on caller having done this, 1412 - * and caller should rely on us not changing it. 1413 - * peripheral code is safe ... check host too. 1414 - */ 1415 - musb_ep_select(mbase, cppi_ch->index + 1); 1416 - 1417 - if (cppi_ch->transmit) { 1418 - struct cppi_tx_stateram __iomem *tx_ram; 1419 - /* REVISIT put timeouts on these controller handshakes */ 1420 - 1421 - cppi_dump_tx(6, cppi_ch, " (teardown)"); 1422 - 1423 - /* teardown DMA engine then usb core */ 1424 - do { 1425 - value = musb_readl(tibase, DAVINCI_TXCPPI_TEAR_REG); 1426 - } while (!(value & CPPI_TEAR_READY)); 1427 - musb_writel(tibase, DAVINCI_TXCPPI_TEAR_REG, cppi_ch->index); 1428 - 1429 - tx_ram = cppi_ch->state_ram; 1430 - do { 1431 - value = musb_readl(&tx_ram->tx_complete, 0); 1432 - } while (0xFFFFFFFC != value); 1433 - 1434 - /* FIXME clean up the transfer state ... here? 1435 - * the completion routine should get called with 1436 - * an appropriate status code. 1437 - */ 1438 - 1439 - value = musb_readw(regs, MUSB_TXCSR); 1440 - value &= ~MUSB_TXCSR_DMAENAB; 1441 - value |= MUSB_TXCSR_FLUSHFIFO; 1442 - musb_writew(regs, MUSB_TXCSR, value); 1443 - musb_writew(regs, MUSB_TXCSR, value); 1444 - 1445 - /* 1446 - * 1. Write to completion Ptr value 0x1(bit 0 set) 1447 - * (write back mode) 1448 - * 2. Wait for abort interrupt and then put the channel in 1449 - * compare mode by writing 1 to the tx_complete register. 1450 - */ 1451 - cppi_reset_tx(tx_ram, 1); 1452 - cppi_ch->head = NULL; 1453 - musb_writel(&tx_ram->tx_complete, 0, 1); 1454 - cppi_dump_tx(5, cppi_ch, " (done teardown)"); 1455 - 1456 - /* REVISIT tx side _should_ clean up the same way 1457 - * as the RX side ... this does no cleanup at all! 1458 - */ 1459 - 1460 - } else /* RX */ { 1461 - u16 csr; 1462 - 1463 - /* NOTE: docs don't guarantee any of this works ... we 1464 - * expect that if the usb core stops telling the cppi core 1465 - * to pull more data from it, then it'll be safe to flush 1466 - * current RX DMA state iff any pending fifo transfer is done. 1467 - */ 1468 - 1469 - core_rxirq_disable(tibase, cppi_ch->index + 1); 1470 - 1471 - /* for host, ensure ReqPkt is never set again */ 1472 - if (is_host_active(cppi_ch->controller->controller.musb)) { 1473 - value = musb_readl(tibase, DAVINCI_AUTOREQ_REG); 1474 - value &= ~((0x3) << (cppi_ch->index * 2)); 1475 - musb_writel(tibase, DAVINCI_AUTOREQ_REG, value); 1476 - } 1477 - 1478 - csr = musb_readw(regs, MUSB_RXCSR); 1479 - 1480 - /* for host, clear (just) ReqPkt at end of current packet(s) */ 1481 - if (is_host_active(cppi_ch->controller->controller.musb)) { 1482 - csr |= MUSB_RXCSR_H_WZC_BITS; 1483 - csr &= ~MUSB_RXCSR_H_REQPKT; 1484 - } else 1485 - csr |= MUSB_RXCSR_P_WZC_BITS; 1486 - 1487 - /* clear dma enable */ 1488 - csr &= ~(MUSB_RXCSR_DMAENAB); 1489 - musb_writew(regs, MUSB_RXCSR, csr); 1490 - csr = musb_readw(regs, MUSB_RXCSR); 1491 - 1492 - /* Quiesce: wait for current dma to finish (if not cleanup). 1493 - * We can't use bit zero of stateram->rx_sop, since that 1494 - * refers to an entire "DMA packet" not just emptying the 1495 - * current fifo. Most segments need multiple usb packets. 1496 - */ 1497 - if (channel->status == MUSB_DMA_STATUS_BUSY) 1498 - udelay(50); 1499 - 1500 - /* scan the current list, reporting any data that was 1501 - * transferred and acking any IRQ 1502 - */ 1503 - cppi_rx_scan(controller, cppi_ch->index); 1504 - 1505 - /* clobber the existing state once it's idle 1506 - * 1507 - * NOTE: arguably, we should also wait for all the other 1508 - * RX channels to quiesce (how??) and then temporarily 1509 - * disable RXCPPI_CTRL_REG ... but it seems that we can 1510 - * rely on the controller restarting from state ram, with 1511 - * only RXCPPI_BUFCNT state being bogus. BUFCNT will 1512 - * correct itself after the next DMA transfer though. 1513 - * 1514 - * REVISIT does using rndis mode change that? 1515 - */ 1516 - cppi_reset_rx(cppi_ch->state_ram); 1517 - 1518 - /* next DMA request _should_ load cppi head ptr */ 1519 - 1520 - /* ... we don't "free" that list, only mutate it in place. */ 1521 - cppi_dump_rx(5, cppi_ch, " (done abort)"); 1522 - 1523 - /* clean up previously pending bds */ 1524 - cppi_bd_free(cppi_ch, cppi_ch->last_processed); 1525 - cppi_ch->last_processed = NULL; 1526 - 1527 - while (queue) { 1528 - struct cppi_descriptor *tmp = queue->next; 1529 - 1530 - cppi_bd_free(cppi_ch, queue); 1531 - queue = tmp; 1532 - } 1533 - } 1534 - 1535 - channel->status = MUSB_DMA_STATUS_FREE; 1536 - cppi_ch->buf_dma = 0; 1537 - cppi_ch->offset = 0; 1538 - cppi_ch->buf_len = 0; 1539 - cppi_ch->maxpacket = 0; 1540 - return 0; 1541 - } 1542 - 1543 - /* TBD Queries: 1544 - * 1545 - * Power Management ... probably turn off cppi during suspend, restart; 1546 - * check state ram? Clocking is presumably shared with usb core. 1547 - */
-606
drivers/usb/musb/davinci.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Copyright (C) 2005-2006 by Texas Instruments 4 - * 5 - * This file is part of the Inventra Controller Driver for Linux. 6 - */ 7 - 8 - #include <linux/module.h> 9 - #include <linux/kernel.h> 10 - #include <linux/sched.h> 11 - #include <linux/list.h> 12 - #include <linux/delay.h> 13 - #include <linux/clk.h> 14 - #include <linux/err.h> 15 - #include <linux/io.h> 16 - #include <linux/gpio/consumer.h> 17 - #include <linux/platform_device.h> 18 - #include <linux/dma-mapping.h> 19 - #include <linux/usb/usb_phy_generic.h> 20 - 21 - #include <mach/cputype.h> 22 - #include <mach/hardware.h> 23 - 24 - #include <asm/mach-types.h> 25 - 26 - #include "musb_core.h" 27 - 28 - #include "davinci.h" 29 - #include "cppi_dma.h" 30 - 31 - 32 - #define USB_PHY_CTRL IO_ADDRESS(USBPHY_CTL_PADDR) 33 - #define DM355_DEEPSLEEP IO_ADDRESS(DM355_DEEPSLEEP_PADDR) 34 - 35 - struct davinci_glue { 36 - struct device *dev; 37 - struct platform_device *musb; 38 - struct clk *clk; 39 - bool vbus_state; 40 - struct gpio_desc *vbus; 41 - struct work_struct vbus_work; 42 - }; 43 - 44 - /* REVISIT (PM) we should be able to keep the PHY in low power mode most 45 - * of the time (24 MHZ oscillator and PLL off, etc) by setting POWER.D0 46 - * and, when in host mode, autosuspending idle root ports... PHYPLLON 47 - * (overriding SUSPENDM?) then likely needs to stay off. 48 - */ 49 - 50 - static inline void phy_on(void) 51 - { 52 - u32 phy_ctrl = __raw_readl(USB_PHY_CTRL); 53 - 54 - /* power everything up; start the on-chip PHY and its PLL */ 55 - phy_ctrl &= ~(USBPHY_OSCPDWN | USBPHY_OTGPDWN | USBPHY_PHYPDWN); 56 - phy_ctrl |= USBPHY_SESNDEN | USBPHY_VBDTCTEN | USBPHY_PHYPLLON; 57 - __raw_writel(phy_ctrl, USB_PHY_CTRL); 58 - 59 - /* wait for PLL to lock before proceeding */ 60 - while ((__raw_readl(USB_PHY_CTRL) & USBPHY_PHYCLKGD) == 0) 61 - cpu_relax(); 62 - } 63 - 64 - static inline void phy_off(void) 65 - { 66 - u32 phy_ctrl = __raw_readl(USB_PHY_CTRL); 67 - 68 - /* powerdown the on-chip PHY, its PLL, and the OTG block */ 69 - phy_ctrl &= ~(USBPHY_SESNDEN | USBPHY_VBDTCTEN | USBPHY_PHYPLLON); 70 - phy_ctrl |= USBPHY_OSCPDWN | USBPHY_OTGPDWN | USBPHY_PHYPDWN; 71 - __raw_writel(phy_ctrl, USB_PHY_CTRL); 72 - } 73 - 74 - static int dma_off = 1; 75 - 76 - static void davinci_musb_enable(struct musb *musb) 77 - { 78 - u32 tmp, old, val; 79 - 80 - /* workaround: setup irqs through both register sets */ 81 - tmp = (musb->epmask & DAVINCI_USB_TX_ENDPTS_MASK) 82 - << DAVINCI_USB_TXINT_SHIFT; 83 - musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_SET_REG, tmp); 84 - old = tmp; 85 - tmp = (musb->epmask & (0xfffe & DAVINCI_USB_RX_ENDPTS_MASK)) 86 - << DAVINCI_USB_RXINT_SHIFT; 87 - musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_SET_REG, tmp); 88 - tmp |= old; 89 - 90 - val = ~MUSB_INTR_SOF; 91 - tmp |= ((val & 0x01ff) << DAVINCI_USB_USBINT_SHIFT); 92 - musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_SET_REG, tmp); 93 - 94 - if (is_dma_capable() && !dma_off) 95 - printk(KERN_WARNING "%s %s: dma not reactivated\n", 96 - __FILE__, __func__); 97 - else 98 - dma_off = 0; 99 - 100 - /* force a DRVVBUS irq so we can start polling for ID change */ 101 - musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG, 102 - DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT); 103 - } 104 - 105 - /* 106 - * Disable the HDRC and flush interrupts 107 - */ 108 - static void davinci_musb_disable(struct musb *musb) 109 - { 110 - /* because we don't set CTRLR.UINT, "important" to: 111 - * - not read/write INTRUSB/INTRUSBE 112 - * - (except during initial setup, as workaround) 113 - * - use INTSETR/INTCLRR instead 114 - */ 115 - musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_CLR_REG, 116 - DAVINCI_USB_USBINT_MASK 117 - | DAVINCI_USB_TXINT_MASK 118 - | DAVINCI_USB_RXINT_MASK); 119 - musb_writel(musb->ctrl_base, DAVINCI_USB_EOI_REG, 0); 120 - 121 - if (is_dma_capable() && !dma_off) 122 - WARNING("dma still active\n"); 123 - } 124 - 125 - 126 - #define portstate(stmt) stmt 127 - 128 - /* 129 - * VBUS SWITCHING IS BOARD-SPECIFIC ... at least for the DM6446 EVM, 130 - * which doesn't wire DRVVBUS to the FET that switches it. Unclear 131 - * if that's a problem with the DM6446 chip or just with that board. 132 - * 133 - * In either case, the DM355 EVM automates DRVVBUS the normal way, 134 - * when J10 is out, and TI documents it as handling OTG. 135 - */ 136 - 137 - /* I2C operations are always synchronous, and require a task context. 138 - * With unloaded systems, using the shared workqueue seems to suffice 139 - * to satisfy the 100msec A_WAIT_VRISE timeout... 140 - */ 141 - static void evm_deferred_drvvbus(struct work_struct *work) 142 - { 143 - struct davinci_glue *glue = container_of(work, struct davinci_glue, 144 - vbus_work); 145 - 146 - gpiod_set_value_cansleep(glue->vbus, glue->vbus_state); 147 - glue->vbus_state = !glue->vbus_state; 148 - } 149 - 150 - static void davinci_musb_source_power(struct musb *musb, int is_on, 151 - int immediate) 152 - { 153 - struct davinci_glue *glue = dev_get_drvdata(musb->controller->parent); 154 - 155 - /* This GPIO handling is entirely optional */ 156 - if (!glue->vbus) 157 - return; 158 - 159 - if (is_on) 160 - is_on = 1; 161 - 162 - if (glue->vbus_state == is_on) 163 - return; 164 - /* 0/1 vs "-1 == unknown/init" */ 165 - glue->vbus_state = !is_on; 166 - 167 - if (machine_is_davinci_evm()) { 168 - if (immediate) 169 - gpiod_set_value_cansleep(glue->vbus, glue->vbus_state); 170 - else 171 - schedule_work(&glue->vbus_work); 172 - } 173 - if (immediate) 174 - glue->vbus_state = is_on; 175 - } 176 - 177 - static void davinci_musb_set_vbus(struct musb *musb, int is_on) 178 - { 179 - WARN_ON(is_on && is_peripheral_active(musb)); 180 - davinci_musb_source_power(musb, is_on, 0); 181 - } 182 - 183 - 184 - #define POLL_SECONDS 2 185 - 186 - static void otg_timer(struct timer_list *t) 187 - { 188 - struct musb *musb = from_timer(musb, t, dev_timer); 189 - void __iomem *mregs = musb->mregs; 190 - u8 devctl; 191 - unsigned long flags; 192 - 193 - /* We poll because DaVinci's won't expose several OTG-critical 194 - * status change events (from the transceiver) otherwise. 195 - */ 196 - devctl = musb_readb(mregs, MUSB_DEVCTL); 197 - dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl, 198 - usb_otg_state_string(musb->xceiv->otg->state)); 199 - 200 - spin_lock_irqsave(&musb->lock, flags); 201 - switch (musb->xceiv->otg->state) { 202 - case OTG_STATE_A_WAIT_VFALL: 203 - /* Wait till VBUS falls below SessionEnd (~0.2V); the 1.3 RTL 204 - * seems to mis-handle session "start" otherwise (or in our 205 - * case "recover"), in routine "VBUS was valid by the time 206 - * VBUSERR got reported during enumeration" cases. 207 - */ 208 - if (devctl & MUSB_DEVCTL_VBUS) { 209 - mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 210 - break; 211 - } 212 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; 213 - musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG, 214 - MUSB_INTR_VBUSERROR << DAVINCI_USB_USBINT_SHIFT); 215 - break; 216 - case OTG_STATE_B_IDLE: 217 - /* 218 - * There's no ID-changed IRQ, so we have no good way to tell 219 - * when to switch to the A-Default state machine (by setting 220 - * the DEVCTL.SESSION flag). 221 - * 222 - * Workaround: whenever we're in B_IDLE, try setting the 223 - * session flag every few seconds. If it works, ID was 224 - * grounded and we're now in the A-Default state machine. 225 - * 226 - * NOTE setting the session flag is _supposed_ to trigger 227 - * SRP, but clearly it doesn't. 228 - */ 229 - musb_writeb(mregs, MUSB_DEVCTL, 230 - devctl | MUSB_DEVCTL_SESSION); 231 - devctl = musb_readb(mregs, MUSB_DEVCTL); 232 - if (devctl & MUSB_DEVCTL_BDEVICE) 233 - mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 234 - else 235 - musb->xceiv->otg->state = OTG_STATE_A_IDLE; 236 - break; 237 - default: 238 - break; 239 - } 240 - spin_unlock_irqrestore(&musb->lock, flags); 241 - } 242 - 243 - static irqreturn_t davinci_musb_interrupt(int irq, void *__hci) 244 - { 245 - unsigned long flags; 246 - irqreturn_t retval = IRQ_NONE; 247 - struct musb *musb = __hci; 248 - struct usb_otg *otg = musb->xceiv->otg; 249 - void __iomem *tibase = musb->ctrl_base; 250 - struct cppi *cppi; 251 - u32 tmp; 252 - 253 - spin_lock_irqsave(&musb->lock, flags); 254 - 255 - /* NOTE: DaVinci shadows the Mentor IRQs. Don't manage them through 256 - * the Mentor registers (except for setup), use the TI ones and EOI. 257 - * 258 - * Docs describe irq "vector" registers associated with the CPPI and 259 - * USB EOI registers. These hold a bitmask corresponding to the 260 - * current IRQ, not an irq handler address. Would using those bits 261 - * resolve some of the races observed in this dispatch code?? 262 - */ 263 - 264 - /* CPPI interrupts share the same IRQ line, but have their own 265 - * mask, state, "vector", and EOI registers. 266 - */ 267 - cppi = container_of(musb->dma_controller, struct cppi, controller); 268 - if (is_cppi_enabled(musb) && musb->dma_controller && !cppi->irq) 269 - retval = cppi_interrupt(irq, __hci); 270 - 271 - /* ack and handle non-CPPI interrupts */ 272 - tmp = musb_readl(tibase, DAVINCI_USB_INT_SRC_MASKED_REG); 273 - musb_writel(tibase, DAVINCI_USB_INT_SRC_CLR_REG, tmp); 274 - dev_dbg(musb->controller, "IRQ %08x\n", tmp); 275 - 276 - musb->int_rx = (tmp & DAVINCI_USB_RXINT_MASK) 277 - >> DAVINCI_USB_RXINT_SHIFT; 278 - musb->int_tx = (tmp & DAVINCI_USB_TXINT_MASK) 279 - >> DAVINCI_USB_TXINT_SHIFT; 280 - musb->int_usb = (tmp & DAVINCI_USB_USBINT_MASK) 281 - >> DAVINCI_USB_USBINT_SHIFT; 282 - 283 - /* DRVVBUS irqs are the only proxy we have (a very poor one!) for 284 - * DaVinci's missing ID change IRQ. We need an ID change IRQ to 285 - * switch appropriately between halves of the OTG state machine. 286 - * Managing DEVCTL.SESSION per Mentor docs requires we know its 287 - * value, but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. 288 - * Also, DRVVBUS pulses for SRP (but not at 5V) ... 289 - */ 290 - if (tmp & (DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT)) { 291 - int drvvbus = musb_readl(tibase, DAVINCI_USB_STAT_REG); 292 - void __iomem *mregs = musb->mregs; 293 - u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 294 - int err = musb->int_usb & MUSB_INTR_VBUSERROR; 295 - 296 - err = musb->int_usb & MUSB_INTR_VBUSERROR; 297 - if (err) { 298 - /* The Mentor core doesn't debounce VBUS as needed 299 - * to cope with device connect current spikes. This 300 - * means it's not uncommon for bus-powered devices 301 - * to get VBUS errors during enumeration. 302 - * 303 - * This is a workaround, but newer RTL from Mentor 304 - * seems to allow a better one: "re"starting sessions 305 - * without waiting (on EVM, a **long** time) for VBUS 306 - * to stop registering in devctl. 307 - */ 308 - musb->int_usb &= ~MUSB_INTR_VBUSERROR; 309 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; 310 - mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 311 - WARNING("VBUS error workaround (delay coming)\n"); 312 - } else if (drvvbus) { 313 - MUSB_HST_MODE(musb); 314 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; 315 - portstate(musb->port1_status |= USB_PORT_STAT_POWER); 316 - del_timer(&musb->dev_timer); 317 - } else { 318 - musb->is_active = 0; 319 - MUSB_DEV_MODE(musb); 320 - musb->xceiv->otg->state = OTG_STATE_B_IDLE; 321 - portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); 322 - } 323 - 324 - /* NOTE: this must complete poweron within 100 msec 325 - * (OTG_TIME_A_WAIT_VRISE) but we don't check for that. 326 - */ 327 - davinci_musb_source_power(musb, drvvbus, 0); 328 - dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 329 - drvvbus ? "on" : "off", 330 - usb_otg_state_string(musb->xceiv->otg->state), 331 - err ? " ERROR" : "", 332 - devctl); 333 - retval = IRQ_HANDLED; 334 - } 335 - 336 - if (musb->int_tx || musb->int_rx || musb->int_usb) 337 - retval |= musb_interrupt(musb); 338 - 339 - /* irq stays asserted until EOI is written */ 340 - musb_writel(tibase, DAVINCI_USB_EOI_REG, 0); 341 - 342 - /* poll for ID change */ 343 - if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) 344 - mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 345 - 346 - spin_unlock_irqrestore(&musb->lock, flags); 347 - 348 - return retval; 349 - } 350 - 351 - static int davinci_musb_set_mode(struct musb *musb, u8 mode) 352 - { 353 - /* EVM can't do this (right?) */ 354 - return -EIO; 355 - } 356 - 357 - static int davinci_musb_init(struct musb *musb) 358 - { 359 - void __iomem *tibase = musb->ctrl_base; 360 - u32 revision; 361 - int ret = -ENODEV; 362 - 363 - musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 364 - if (IS_ERR_OR_NULL(musb->xceiv)) { 365 - ret = -EPROBE_DEFER; 366 - goto unregister; 367 - } 368 - 369 - musb->mregs += DAVINCI_BASE_OFFSET; 370 - 371 - /* returns zero if e.g. not clocked */ 372 - revision = musb_readl(tibase, DAVINCI_USB_VERSION_REG); 373 - if (revision == 0) 374 - goto fail; 375 - 376 - timer_setup(&musb->dev_timer, otg_timer, 0); 377 - 378 - davinci_musb_source_power(musb, 0, 1); 379 - 380 - /* dm355 EVM swaps D+/D- for signal integrity, and 381 - * is clocked from the main 24 MHz crystal. 382 - */ 383 - if (machine_is_davinci_dm355_evm()) { 384 - u32 phy_ctrl = __raw_readl(USB_PHY_CTRL); 385 - 386 - phy_ctrl &= ~(3 << 9); 387 - phy_ctrl |= USBPHY_DATAPOL; 388 - __raw_writel(phy_ctrl, USB_PHY_CTRL); 389 - } 390 - 391 - /* On dm355, the default-A state machine needs DRVVBUS control. 392 - * If we won't be a host, there's no need to turn it on. 393 - */ 394 - if (cpu_is_davinci_dm355()) { 395 - u32 deepsleep = __raw_readl(DM355_DEEPSLEEP); 396 - 397 - deepsleep &= ~DRVVBUS_FORCE; 398 - __raw_writel(deepsleep, DM355_DEEPSLEEP); 399 - } 400 - 401 - /* reset the controller */ 402 - musb_writel(tibase, DAVINCI_USB_CTRL_REG, 0x1); 403 - 404 - /* start the on-chip PHY and its PLL */ 405 - phy_on(); 406 - 407 - msleep(5); 408 - 409 - /* NOTE: irqs are in mixed mode, not bypass to pure-musb */ 410 - pr_debug("DaVinci OTG revision %08x phy %03x control %02x\n", 411 - revision, __raw_readl(USB_PHY_CTRL), 412 - musb_readb(tibase, DAVINCI_USB_CTRL_REG)); 413 - 414 - musb->isr = davinci_musb_interrupt; 415 - return 0; 416 - 417 - fail: 418 - usb_put_phy(musb->xceiv); 419 - unregister: 420 - usb_phy_generic_unregister(); 421 - return ret; 422 - } 423 - 424 - static int davinci_musb_exit(struct musb *musb) 425 - { 426 - int maxdelay = 30; 427 - u8 devctl, warn = 0; 428 - 429 - del_timer_sync(&musb->dev_timer); 430 - 431 - /* force VBUS off */ 432 - if (cpu_is_davinci_dm355()) { 433 - u32 deepsleep = __raw_readl(DM355_DEEPSLEEP); 434 - 435 - deepsleep &= ~DRVVBUS_FORCE; 436 - deepsleep |= DRVVBUS_OVERRIDE; 437 - __raw_writel(deepsleep, DM355_DEEPSLEEP); 438 - } 439 - 440 - davinci_musb_source_power(musb, 0 /*off*/, 1); 441 - 442 - /* 443 - * delay, to avoid problems with module reload. 444 - * if there's no peripheral connected, this can take a 445 - * long time to fall, especially on EVM with huge C133. 446 - */ 447 - do { 448 - devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 449 - if (!(devctl & MUSB_DEVCTL_VBUS)) 450 - break; 451 - if ((devctl & MUSB_DEVCTL_VBUS) != warn) { 452 - warn = devctl & MUSB_DEVCTL_VBUS; 453 - dev_dbg(musb->controller, "VBUS %d\n", 454 - warn >> MUSB_DEVCTL_VBUS_SHIFT); 455 - } 456 - msleep(1000); 457 - maxdelay--; 458 - } while (maxdelay > 0); 459 - 460 - /* in OTG mode, another host might be connected */ 461 - if (devctl & MUSB_DEVCTL_VBUS) 462 - dev_dbg(musb->controller, "VBUS off timeout (devctl %02x)\n", devctl); 463 - 464 - phy_off(); 465 - 466 - usb_put_phy(musb->xceiv); 467 - 468 - return 0; 469 - } 470 - 471 - static const struct musb_platform_ops davinci_ops = { 472 - .quirks = MUSB_DMA_CPPI, 473 - .init = davinci_musb_init, 474 - .exit = davinci_musb_exit, 475 - 476 - #ifdef CONFIG_USB_TI_CPPI_DMA 477 - .dma_init = cppi_dma_controller_create, 478 - .dma_exit = cppi_dma_controller_destroy, 479 - #endif 480 - .enable = davinci_musb_enable, 481 - .disable = davinci_musb_disable, 482 - 483 - .set_mode = davinci_musb_set_mode, 484 - 485 - .set_vbus = davinci_musb_set_vbus, 486 - }; 487 - 488 - static const struct platform_device_info davinci_dev_info = { 489 - .name = "musb-hdrc", 490 - .id = PLATFORM_DEVID_AUTO, 491 - .dma_mask = DMA_BIT_MASK(32), 492 - }; 493 - 494 - static int davinci_probe(struct platform_device *pdev) 495 - { 496 - struct resource musb_resources[3]; 497 - struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 498 - struct platform_device *musb; 499 - struct davinci_glue *glue; 500 - struct platform_device_info pinfo; 501 - struct clk *clk; 502 - 503 - int ret = -ENOMEM; 504 - 505 - glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); 506 - if (!glue) 507 - goto err0; 508 - 509 - clk = devm_clk_get(&pdev->dev, "usb"); 510 - if (IS_ERR(clk)) { 511 - dev_err(&pdev->dev, "failed to get clock\n"); 512 - ret = PTR_ERR(clk); 513 - goto err0; 514 - } 515 - 516 - ret = clk_enable(clk); 517 - if (ret) { 518 - dev_err(&pdev->dev, "failed to enable clock\n"); 519 - goto err0; 520 - } 521 - 522 - glue->dev = &pdev->dev; 523 - glue->clk = clk; 524 - 525 - pdata->platform_ops = &davinci_ops; 526 - 527 - glue->vbus = devm_gpiod_get_optional(&pdev->dev, NULL, GPIOD_OUT_LOW); 528 - if (IS_ERR(glue->vbus)) { 529 - ret = PTR_ERR(glue->vbus); 530 - goto err0; 531 - } else { 532 - glue->vbus_state = -1; 533 - INIT_WORK(&glue->vbus_work, evm_deferred_drvvbus); 534 - } 535 - 536 - usb_phy_generic_register(); 537 - platform_set_drvdata(pdev, glue); 538 - 539 - memset(musb_resources, 0x00, sizeof(*musb_resources) * 540 - ARRAY_SIZE(musb_resources)); 541 - 542 - musb_resources[0].name = pdev->resource[0].name; 543 - musb_resources[0].start = pdev->resource[0].start; 544 - musb_resources[0].end = pdev->resource[0].end; 545 - musb_resources[0].flags = pdev->resource[0].flags; 546 - 547 - musb_resources[1].name = pdev->resource[1].name; 548 - musb_resources[1].start = pdev->resource[1].start; 549 - musb_resources[1].end = pdev->resource[1].end; 550 - musb_resources[1].flags = pdev->resource[1].flags; 551 - 552 - /* 553 - * For DM6467 3 resources are passed. A placeholder for the 3rd 554 - * resource is always there, so it's safe to always copy it... 555 - */ 556 - musb_resources[2].name = pdev->resource[2].name; 557 - musb_resources[2].start = pdev->resource[2].start; 558 - musb_resources[2].end = pdev->resource[2].end; 559 - musb_resources[2].flags = pdev->resource[2].flags; 560 - 561 - pinfo = davinci_dev_info; 562 - pinfo.parent = &pdev->dev; 563 - pinfo.res = musb_resources; 564 - pinfo.num_res = ARRAY_SIZE(musb_resources); 565 - pinfo.data = pdata; 566 - pinfo.size_data = sizeof(*pdata); 567 - 568 - glue->musb = musb = platform_device_register_full(&pinfo); 569 - if (IS_ERR(musb)) { 570 - ret = PTR_ERR(musb); 571 - dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); 572 - goto err1; 573 - } 574 - 575 - return 0; 576 - 577 - err1: 578 - clk_disable(clk); 579 - 580 - err0: 581 - return ret; 582 - } 583 - 584 - static int davinci_remove(struct platform_device *pdev) 585 - { 586 - struct davinci_glue *glue = platform_get_drvdata(pdev); 587 - 588 - platform_device_unregister(glue->musb); 589 - usb_phy_generic_unregister(); 590 - clk_disable(glue->clk); 591 - 592 - return 0; 593 - } 594 - 595 - static struct platform_driver davinci_driver = { 596 - .probe = davinci_probe, 597 - .remove = davinci_remove, 598 - .driver = { 599 - .name = "musb-davinci", 600 - }, 601 - }; 602 - 603 - MODULE_DESCRIPTION("DaVinci MUSB Glue Layer"); 604 - MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 605 - MODULE_LICENSE("GPL v2"); 606 - module_platform_driver(davinci_driver);
-103
drivers/usb/musb/davinci.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * Copyright (C) 2005-2006 by Texas Instruments 4 - */ 5 - 6 - #ifndef __MUSB_HDRDF_H__ 7 - #define __MUSB_HDRDF_H__ 8 - 9 - /* 10 - * DaVinci-specific definitions 11 - */ 12 - 13 - /* Integrated highspeed/otg PHY */ 14 - #define USBPHY_CTL_PADDR 0x01c40034 15 - #define USBPHY_DATAPOL BIT(11) /* (dm355) switch D+/D- */ 16 - #define USBPHY_PHYCLKGD BIT(8) 17 - #define USBPHY_SESNDEN BIT(7) /* v(sess_end) comparator */ 18 - #define USBPHY_VBDTCTEN BIT(6) /* v(bus) comparator */ 19 - #define USBPHY_VBUSSENS BIT(5) /* (dm355,ro) is vbus > 0.5V */ 20 - #define USBPHY_PHYPLLON BIT(4) /* override pll suspend */ 21 - #define USBPHY_CLKO1SEL BIT(3) 22 - #define USBPHY_OSCPDWN BIT(2) 23 - #define USBPHY_OTGPDWN BIT(1) 24 - #define USBPHY_PHYPDWN BIT(0) 25 - 26 - #define DM355_DEEPSLEEP_PADDR 0x01c40048 27 - #define DRVVBUS_FORCE BIT(2) 28 - #define DRVVBUS_OVERRIDE BIT(1) 29 - 30 - /* For now include usb OTG module registers here */ 31 - #define DAVINCI_USB_VERSION_REG 0x00 32 - #define DAVINCI_USB_CTRL_REG 0x04 33 - #define DAVINCI_USB_STAT_REG 0x08 34 - #define DAVINCI_RNDIS_REG 0x10 35 - #define DAVINCI_AUTOREQ_REG 0x14 36 - #define DAVINCI_USB_INT_SOURCE_REG 0x20 37 - #define DAVINCI_USB_INT_SET_REG 0x24 38 - #define DAVINCI_USB_INT_SRC_CLR_REG 0x28 39 - #define DAVINCI_USB_INT_MASK_REG 0x2c 40 - #define DAVINCI_USB_INT_MASK_SET_REG 0x30 41 - #define DAVINCI_USB_INT_MASK_CLR_REG 0x34 42 - #define DAVINCI_USB_INT_SRC_MASKED_REG 0x38 43 - #define DAVINCI_USB_EOI_REG 0x3c 44 - #define DAVINCI_USB_EOI_INTVEC 0x40 45 - 46 - /* BEGIN CPPI-generic (?) */ 47 - 48 - /* CPPI related registers */ 49 - #define DAVINCI_TXCPPI_CTRL_REG 0x80 50 - #define DAVINCI_TXCPPI_TEAR_REG 0x84 51 - #define DAVINCI_CPPI_EOI_REG 0x88 52 - #define DAVINCI_CPPI_INTVEC_REG 0x8c 53 - #define DAVINCI_TXCPPI_MASKED_REG 0x90 54 - #define DAVINCI_TXCPPI_RAW_REG 0x94 55 - #define DAVINCI_TXCPPI_INTENAB_REG 0x98 56 - #define DAVINCI_TXCPPI_INTCLR_REG 0x9c 57 - 58 - #define DAVINCI_RXCPPI_CTRL_REG 0xC0 59 - #define DAVINCI_RXCPPI_MASKED_REG 0xD0 60 - #define DAVINCI_RXCPPI_RAW_REG 0xD4 61 - #define DAVINCI_RXCPPI_INTENAB_REG 0xD8 62 - #define DAVINCI_RXCPPI_INTCLR_REG 0xDC 63 - 64 - #define DAVINCI_RXCPPI_BUFCNT0_REG 0xE0 65 - #define DAVINCI_RXCPPI_BUFCNT1_REG 0xE4 66 - #define DAVINCI_RXCPPI_BUFCNT2_REG 0xE8 67 - #define DAVINCI_RXCPPI_BUFCNT3_REG 0xEC 68 - 69 - /* CPPI state RAM entries */ 70 - #define DAVINCI_CPPI_STATERAM_BASE_OFFSET 0x100 71 - 72 - #define DAVINCI_TXCPPI_STATERAM_OFFSET(chnum) \ 73 - (DAVINCI_CPPI_STATERAM_BASE_OFFSET + ((chnum) * 0x40)) 74 - #define DAVINCI_RXCPPI_STATERAM_OFFSET(chnum) \ 75 - (DAVINCI_CPPI_STATERAM_BASE_OFFSET + 0x20 + ((chnum) * 0x40)) 76 - 77 - /* CPPI masks */ 78 - #define DAVINCI_DMA_CTRL_ENABLE 1 79 - #define DAVINCI_DMA_CTRL_DISABLE 0 80 - 81 - #define DAVINCI_DMA_ALL_CHANNELS_ENABLE 0xF 82 - #define DAVINCI_DMA_ALL_CHANNELS_DISABLE 0xF 83 - 84 - /* END CPPI-generic (?) */ 85 - 86 - #define DAVINCI_USB_TX_ENDPTS_MASK 0x1f /* ep0 + 4 tx */ 87 - #define DAVINCI_USB_RX_ENDPTS_MASK 0x1e /* 4 rx */ 88 - 89 - #define DAVINCI_USB_USBINT_SHIFT 16 90 - #define DAVINCI_USB_TXINT_SHIFT 0 91 - #define DAVINCI_USB_RXINT_SHIFT 8 92 - 93 - #define DAVINCI_INTR_DRVVBUS 0x0100 94 - 95 - #define DAVINCI_USB_USBINT_MASK 0x01ff0000 /* 8 Mentor, DRVVBUS */ 96 - #define DAVINCI_USB_TXINT_MASK \ 97 - (DAVINCI_USB_TX_ENDPTS_MASK << DAVINCI_USB_TXINT_SHIFT) 98 - #define DAVINCI_USB_RXINT_MASK \ 99 - (DAVINCI_USB_RX_ENDPTS_MASK << DAVINCI_USB_RXINT_SHIFT) 100 - 101 - #define DAVINCI_BASE_OFFSET 0x400 102 - 103 - #endif /* __MUSB_HDRDF_H__ */
+54 -8
drivers/usb/musb/jz4740.c
··· 11 11 #include <linux/kernel.h> 12 12 #include <linux/module.h> 13 13 #include <linux/of_device.h> 14 + #include <linux/phy/phy.h> 14 15 #include <linux/platform_device.h> 15 16 #include <linux/usb/role.h> 16 17 #include <linux/usb/usb_phy_generic.h> ··· 82 81 struct jz4740_glue *glue = usb_role_switch_get_drvdata(sw); 83 82 struct usb_phy *phy = glue->musb->xceiv; 84 83 84 + if (!phy) 85 + return 0; 86 + 85 87 switch (role) { 86 88 case USB_ROLE_NONE: 87 89 atomic_notifier_call_chain(&phy->notifier, USB_EVENT_NONE, phy); ··· 109 105 .driver_data = glue, 110 106 .fwnode = dev_fwnode(dev), 111 107 }; 108 + int err; 112 109 113 110 glue->musb = musb; 114 111 115 - if (dev->of_node) 116 - musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0); 117 - else 118 - musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 119 - if (IS_ERR(musb->xceiv)) 120 - return dev_err_probe(dev, PTR_ERR(musb->xceiv), 121 - "No transceiver configured\n"); 112 + if (IS_ENABLED(CONFIG_GENERIC_PHY)) { 113 + musb->phy = devm_of_phy_get_by_index(dev, dev->of_node, 0); 114 + if (IS_ERR(musb->phy)) { 115 + err = PTR_ERR(musb->phy); 116 + if (err != -ENODEV) { 117 + dev_err(dev, "Unable to get PHY\n"); 118 + return err; 119 + } 120 + 121 + musb->phy = NULL; 122 + } 123 + } 124 + 125 + if (musb->phy) { 126 + err = phy_init(musb->phy); 127 + if (err) { 128 + dev_err(dev, "Failed to init PHY\n"); 129 + return err; 130 + } 131 + 132 + err = phy_power_on(musb->phy); 133 + if (err) { 134 + dev_err(dev, "Unable to power on PHY\n"); 135 + goto err_phy_shutdown; 136 + } 137 + } else { 138 + if (dev->of_node) 139 + musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0); 140 + else 141 + musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 142 + if (IS_ERR(musb->xceiv)) { 143 + dev_err(dev, "No transceiver configured\n"); 144 + return PTR_ERR(musb->xceiv); 145 + } 146 + } 122 147 123 148 glue->role_sw = usb_role_switch_register(dev, &role_sw_desc); 124 149 if (IS_ERR(glue->role_sw)) { 125 150 dev_err(dev, "Failed to register USB role switch\n"); 126 - return PTR_ERR(glue->role_sw); 151 + err = PTR_ERR(glue->role_sw); 152 + goto err_phy_power_down; 127 153 } 128 154 129 155 /* ··· 165 131 musb->isr = jz4740_musb_interrupt; 166 132 167 133 return 0; 134 + 135 + err_phy_power_down: 136 + if (musb->phy) 137 + phy_power_off(musb->phy); 138 + err_phy_shutdown: 139 + if (musb->phy) 140 + phy_exit(musb->phy); 141 + return err; 168 142 } 169 143 170 144 static int jz4740_musb_exit(struct musb *musb) ··· 180 138 struct jz4740_glue *glue = dev_get_drvdata(musb->controller->parent); 181 139 182 140 usb_role_switch_unregister(glue->role_sw); 141 + if (musb->phy) { 142 + phy_power_off(musb->phy); 143 + phy_exit(musb->phy); 144 + } 183 145 184 146 return 0; 185 147 }
+51 -56
drivers/usb/musb/musb_core.c
··· 502 502 503 503 init_data: 504 504 musb->is_active = 1; 505 - musb->xceiv->otg->state = OTG_STATE_A_IDLE; 505 + musb_set_state(musb, OTG_STATE_A_IDLE); 506 506 MUSB_HST_MODE(musb); 507 507 508 508 return error; ··· 549 549 550 550 init_data: 551 551 musb->is_active = 0; 552 - musb->xceiv->otg->state = OTG_STATE_B_IDLE; 552 + musb_set_state(musb, OTG_STATE_B_IDLE); 553 553 MUSB_DEV_MODE(musb); 554 554 555 555 return error; ··· 599 599 unsigned long flags; 600 600 601 601 spin_lock_irqsave(&musb->lock, flags); 602 - switch (musb->xceiv->otg->state) { 602 + switch (musb_get_state(musb)) { 603 603 case OTG_STATE_B_WAIT_ACON: 604 604 musb_dbg(musb, 605 605 "HNP: b_wait_acon timeout; back to b_peripheral"); 606 606 musb_g_disconnect(musb); 607 - musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; 607 + musb_set_state(musb, OTG_STATE_B_PERIPHERAL); 608 608 musb->is_active = 0; 609 609 break; 610 610 case OTG_STATE_A_SUSPEND: 611 611 case OTG_STATE_A_WAIT_BCON: 612 612 musb_dbg(musb, "HNP: %s timeout", 613 - usb_otg_state_string(musb->xceiv->otg->state)); 613 + musb_otg_state_string(musb)); 614 614 musb_platform_set_vbus(musb, 0); 615 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; 615 + musb_set_state(musb, OTG_STATE_A_WAIT_VFALL); 616 616 break; 617 617 default: 618 618 musb_dbg(musb, "HNP: Unhandled mode %s", 619 - usb_otg_state_string(musb->xceiv->otg->state)); 619 + musb_otg_state_string(musb)); 620 620 } 621 621 spin_unlock_irqrestore(&musb->lock, flags); 622 622 } ··· 630 630 void __iomem *mbase = musb->mregs; 631 631 u8 reg; 632 632 633 - musb_dbg(musb, "HNP: stop from %s", 634 - usb_otg_state_string(musb->xceiv->otg->state)); 633 + musb_dbg(musb, "HNP: stop from %s", musb_otg_state_string(musb)); 635 634 636 - switch (musb->xceiv->otg->state) { 635 + switch (musb_get_state(musb)) { 637 636 case OTG_STATE_A_PERIPHERAL: 638 637 musb_g_disconnect(musb); 639 - musb_dbg(musb, "HNP: back to %s", 640 - usb_otg_state_string(musb->xceiv->otg->state)); 638 + musb_dbg(musb, "HNP: back to %s", musb_otg_state_string(musb)); 641 639 break; 642 640 case OTG_STATE_B_HOST: 643 641 musb_dbg(musb, "HNP: Disabling HR"); 644 642 if (hcd) 645 643 hcd->self.is_b_host = 0; 646 - musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; 644 + musb_set_state(musb, OTG_STATE_B_PERIPHERAL); 647 645 MUSB_DEV_MODE(musb); 648 646 reg = musb_readb(mbase, MUSB_POWER); 649 647 reg |= MUSB_POWER_SUSPENDM; ··· 650 652 break; 651 653 default: 652 654 musb_dbg(musb, "HNP: Stopping in unknown state %s", 653 - usb_otg_state_string(musb->xceiv->otg->state)); 655 + musb_otg_state_string(musb)); 654 656 } 655 657 656 658 /* ··· 665 667 666 668 static void musb_handle_intr_resume(struct musb *musb, u8 devctl) 667 669 { 668 - musb_dbg(musb, "RESUME (%s)", 669 - usb_otg_state_string(musb->xceiv->otg->state)); 670 + musb_dbg(musb, "RESUME (%s)", musb_otg_state_string(musb)); 670 671 671 672 if (devctl & MUSB_DEVCTL_HM) { 672 - switch (musb->xceiv->otg->state) { 673 + switch (musb_get_state(musb)) { 673 674 case OTG_STATE_A_SUSPEND: 674 675 /* remote wakeup? */ 675 676 musb->port1_status |= ··· 676 679 | MUSB_PORT_STAT_RESUME; 677 680 musb->rh_timer = jiffies 678 681 + msecs_to_jiffies(USB_RESUME_TIMEOUT); 679 - musb->xceiv->otg->state = OTG_STATE_A_HOST; 682 + musb_set_state(musb, OTG_STATE_A_HOST); 680 683 musb->is_active = 1; 681 684 musb_host_resume_root_hub(musb); 682 685 schedule_delayed_work(&musb->finish_resume_work, 683 686 msecs_to_jiffies(USB_RESUME_TIMEOUT)); 684 687 break; 685 688 case OTG_STATE_B_WAIT_ACON: 686 - musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; 689 + musb_set_state(musb, OTG_STATE_B_PERIPHERAL); 687 690 musb->is_active = 1; 688 691 MUSB_DEV_MODE(musb); 689 692 break; 690 693 default: 691 694 WARNING("bogus %s RESUME (%s)\n", 692 695 "host", 693 - usb_otg_state_string(musb->xceiv->otg->state)); 696 + musb_otg_state_string(musb)); 694 697 } 695 698 } else { 696 - switch (musb->xceiv->otg->state) { 699 + switch (musb_get_state(musb)) { 697 700 case OTG_STATE_A_SUSPEND: 698 701 /* possibly DISCONNECT is upcoming */ 699 - musb->xceiv->otg->state = OTG_STATE_A_HOST; 702 + musb_set_state(musb, OTG_STATE_A_HOST); 700 703 musb_host_resume_root_hub(musb); 701 704 break; 702 705 case OTG_STATE_B_WAIT_ACON: ··· 719 722 default: 720 723 WARNING("bogus %s RESUME (%s)\n", 721 724 "peripheral", 722 - usb_otg_state_string(musb->xceiv->otg->state)); 725 + musb_otg_state_string(musb)); 723 726 } 724 727 } 725 728 } ··· 735 738 return IRQ_HANDLED; 736 739 } 737 740 738 - musb_dbg(musb, "SESSION_REQUEST (%s)", 739 - usb_otg_state_string(musb->xceiv->otg->state)); 741 + musb_dbg(musb, "SESSION_REQUEST (%s)", musb_otg_state_string(musb)); 740 742 741 743 /* IRQ arrives from ID pin sense or (later, if VBUS power 742 744 * is removed) SRP. responses are time critical: ··· 746 750 */ 747 751 musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION); 748 752 musb->ep0_stage = MUSB_EP0_START; 749 - musb->xceiv->otg->state = OTG_STATE_A_IDLE; 753 + musb_set_state(musb, OTG_STATE_A_IDLE); 750 754 MUSB_HST_MODE(musb); 751 755 musb_platform_set_vbus(musb, 1); 752 756 ··· 773 777 * REVISIT: do delays from lots of DEBUG_KERNEL checks 774 778 * make trouble here, keeping VBUS < 4.4V ? 775 779 */ 776 - switch (musb->xceiv->otg->state) { 780 + switch (musb_get_state(musb)) { 777 781 case OTG_STATE_A_HOST: 778 782 /* recovery is dicey once we've gotten past the 779 783 * initial stages of enumeration, but if VBUS ··· 802 806 803 807 dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller, 804 808 "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n", 805 - usb_otg_state_string(musb->xceiv->otg->state), 809 + musb_otg_state_string(musb), 806 810 devctl, 807 811 ({ char *s; 808 812 switch (devctl & MUSB_DEVCTL_VBUS) { ··· 827 831 static void musb_handle_intr_suspend(struct musb *musb, u8 devctl) 828 832 { 829 833 musb_dbg(musb, "SUSPEND (%s) devctl %02x", 830 - usb_otg_state_string(musb->xceiv->otg->state), devctl); 834 + musb_otg_state_string(musb), devctl); 831 835 832 - switch (musb->xceiv->otg->state) { 836 + switch (musb_get_state(musb)) { 833 837 case OTG_STATE_A_PERIPHERAL: 834 838 /* We also come here if the cable is removed, since 835 839 * this silicon doesn't report ID-no-longer-grounded. ··· 854 858 musb_g_suspend(musb); 855 859 musb->is_active = musb->g.b_hnp_enable; 856 860 if (musb->is_active) { 857 - musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON; 861 + musb_set_state(musb, OTG_STATE_B_WAIT_ACON); 858 862 musb_dbg(musb, "HNP: Setting timer for b_ase0_brst"); 859 863 mod_timer(&musb->otg_timer, jiffies 860 864 + msecs_to_jiffies( ··· 867 871 + msecs_to_jiffies(musb->a_wait_bcon)); 868 872 break; 869 873 case OTG_STATE_A_HOST: 870 - musb->xceiv->otg->state = OTG_STATE_A_SUSPEND; 874 + musb_set_state(musb, OTG_STATE_A_SUSPEND); 871 875 musb->is_active = musb->hcd->self.b_hnp_enable; 872 876 break; 873 877 case OTG_STATE_B_HOST: ··· 905 909 musb->port1_status |= USB_PORT_STAT_LOW_SPEED; 906 910 907 911 /* indicate new connection to OTG machine */ 908 - switch (musb->xceiv->otg->state) { 912 + switch (musb_get_state(musb)) { 909 913 case OTG_STATE_B_PERIPHERAL: 910 914 if (int_usb & MUSB_INTR_SUSPEND) { 911 915 musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host"); ··· 917 921 case OTG_STATE_B_WAIT_ACON: 918 922 musb_dbg(musb, "HNP: CONNECT, now b_host"); 919 923 b_host: 920 - musb->xceiv->otg->state = OTG_STATE_B_HOST; 924 + musb_set_state(musb, OTG_STATE_B_HOST); 921 925 if (musb->hcd) 922 926 musb->hcd->self.is_b_host = 1; 923 927 del_timer(&musb->otg_timer); ··· 925 929 default: 926 930 if ((devctl & MUSB_DEVCTL_VBUS) 927 931 == (3 << MUSB_DEVCTL_VBUS_SHIFT)) { 928 - musb->xceiv->otg->state = OTG_STATE_A_HOST; 932 + musb_set_state(musb, OTG_STATE_A_HOST); 929 933 if (hcd) 930 934 hcd->self.is_b_host = 0; 931 935 } ··· 935 939 musb_host_poke_root_hub(musb); 936 940 937 941 musb_dbg(musb, "CONNECT (%s) devctl %02x", 938 - usb_otg_state_string(musb->xceiv->otg->state), devctl); 942 + musb_otg_state_string(musb), devctl); 939 943 } 940 944 941 945 static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl) 942 946 { 943 947 musb_dbg(musb, "DISCONNECT (%s) as %s, devctl %02x", 944 - usb_otg_state_string(musb->xceiv->otg->state), 948 + musb_otg_state_string(musb), 945 949 MUSB_MODE(musb), devctl); 946 950 947 - switch (musb->xceiv->otg->state) { 951 + switch (musb_get_state(musb)) { 948 952 case OTG_STATE_A_HOST: 949 953 case OTG_STATE_A_SUSPEND: 950 954 musb_host_resume_root_hub(musb); ··· 962 966 musb_root_disconnect(musb); 963 967 if (musb->hcd) 964 968 musb->hcd->self.is_b_host = 0; 965 - musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; 969 + musb_set_state(musb, OTG_STATE_B_PERIPHERAL); 966 970 MUSB_DEV_MODE(musb); 967 971 musb_g_disconnect(musb); 968 972 break; ··· 977 981 break; 978 982 default: 979 983 WARNING("unhandled DISCONNECT transition (%s)\n", 980 - usb_otg_state_string(musb->xceiv->otg->state)); 984 + musb_otg_state_string(musb)); 981 985 break; 982 986 } 983 987 } ··· 1000 1004 dev_err(musb->controller, "Babble\n"); 1001 1005 musb_recover_from_babble(musb); 1002 1006 } else { 1003 - musb_dbg(musb, "BUS RESET as %s", 1004 - usb_otg_state_string(musb->xceiv->otg->state)); 1005 - switch (musb->xceiv->otg->state) { 1007 + musb_dbg(musb, "BUS RESET as %s", musb_otg_state_string(musb)); 1008 + switch (musb_get_state(musb)) { 1006 1009 case OTG_STATE_A_SUSPEND: 1007 1010 musb_g_reset(musb); 1008 1011 fallthrough; 1009 1012 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ 1010 1013 /* never use invalid T(a_wait_bcon) */ 1011 1014 musb_dbg(musb, "HNP: in %s, %d msec timeout", 1012 - usb_otg_state_string(musb->xceiv->otg->state), 1015 + musb_otg_state_string(musb), 1013 1016 TA_WAIT_BCON(musb)); 1014 1017 mod_timer(&musb->otg_timer, jiffies 1015 1018 + msecs_to_jiffies(TA_WAIT_BCON(musb))); ··· 1019 1024 break; 1020 1025 case OTG_STATE_B_WAIT_ACON: 1021 1026 musb_dbg(musb, "HNP: RESET (%s), to b_peripheral", 1022 - usb_otg_state_string(musb->xceiv->otg->state)); 1023 - musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; 1027 + musb_otg_state_string(musb)); 1028 + musb_set_state(musb, OTG_STATE_B_PERIPHERAL); 1024 1029 musb_g_reset(musb); 1025 1030 break; 1026 1031 case OTG_STATE_B_IDLE: 1027 - musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; 1032 + musb_set_state(musb, OTG_STATE_B_PERIPHERAL); 1028 1033 fallthrough; 1029 1034 case OTG_STATE_B_PERIPHERAL: 1030 1035 musb_g_reset(musb); 1031 1036 break; 1032 1037 default: 1033 1038 musb_dbg(musb, "Unhandled BUS RESET as %s", 1034 - usb_otg_state_string(musb->xceiv->otg->state)); 1039 + musb_otg_state_string(musb)); 1035 1040 } 1036 1041 } 1037 1042 } ··· 1211 1216 * (c) peripheral initiates, using SRP 1212 1217 */ 1213 1218 if (musb->port_mode != MUSB_HOST && 1214 - musb->xceiv->otg->state != OTG_STATE_A_WAIT_BCON && 1215 - (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) { 1219 + musb_get_state(musb) != OTG_STATE_A_WAIT_BCON && 1220 + (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) { 1216 1221 musb->is_active = 1; 1217 1222 } else { 1218 1223 devctl |= MUSB_DEVCTL_SESSION; ··· 1858 1863 int ret; 1859 1864 1860 1865 spin_lock_irqsave(&musb->lock, flags); 1861 - ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->otg->state)); 1866 + ret = sprintf(buf, "%s\n", musb_otg_state_string(musb)); 1862 1867 spin_unlock_irqrestore(&musb->lock, flags); 1863 1868 1864 1869 return ret; ··· 1903 1908 spin_lock_irqsave(&musb->lock, flags); 1904 1909 /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */ 1905 1910 musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ; 1906 - if (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON) 1911 + if (musb_get_state(musb) == OTG_STATE_A_WAIT_BCON) 1907 1912 musb->is_active = 0; 1908 1913 musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val)); 1909 1914 spin_unlock_irqrestore(&musb->lock, flags); ··· 2084 2089 2085 2090 musb_pm_runtime_check_session(musb); 2086 2091 2087 - if (musb->xceiv->otg->state != musb->xceiv_old_state) { 2088 - musb->xceiv_old_state = musb->xceiv->otg->state; 2092 + if (musb_get_state(musb) != musb->xceiv_old_state) { 2093 + musb->xceiv_old_state = musb_get_state(musb); 2089 2094 sysfs_notify(&musb->controller->kobj, NULL, "mode"); 2090 2095 } 2091 2096 ··· 2448 2453 else 2449 2454 musb->io.set_toggle = musb_default_set_toggle; 2450 2455 2451 - if (!musb->xceiv->io_ops) { 2456 + if (IS_ENABLED(CONFIG_USB_PHY) && musb->xceiv && !musb->xceiv->io_ops) { 2452 2457 musb->xceiv->io_dev = musb->controller; 2453 2458 musb->xceiv->io_priv = musb->mregs; 2454 2459 musb->xceiv->io_ops = &musb_ulpi_access; ··· 2527 2532 } 2528 2533 2529 2534 MUSB_DEV_MODE(musb); 2530 - musb->xceiv->otg->state = OTG_STATE_B_IDLE; 2535 + musb_set_state(musb, OTG_STATE_B_IDLE); 2531 2536 2532 2537 switch (musb->port_mode) { 2533 2538 case MUSB_HOST:
+24
drivers/usb/musb/musb_core.h
··· 339 339 struct usb_phy *xceiv; 340 340 struct phy *phy; 341 341 342 + enum usb_otg_state otg_state; 343 + 342 344 int nIrq; 343 345 unsigned irq_wake:1; 344 346 ··· 592 590 { 593 591 if (musb->ops->clear_ep_rxintr) 594 592 musb->ops->clear_ep_rxintr(musb, epnum); 593 + } 594 + 595 + static inline void musb_set_state(struct musb *musb, 596 + enum usb_otg_state otg_state) 597 + { 598 + if (musb->xceiv) 599 + musb->xceiv->otg->state = otg_state; 600 + else 601 + musb->otg_state = otg_state; 602 + } 603 + 604 + static inline enum usb_otg_state musb_get_state(struct musb *musb) 605 + { 606 + if (musb->xceiv) 607 + return musb->xceiv->otg->state; 608 + 609 + return musb->otg_state; 610 + } 611 + 612 + static inline const char *musb_otg_state_string(struct musb *musb) 613 + { 614 + return usb_otg_state_string(musb_get_state(musb)); 595 615 } 596 616 597 617 /*
+3 -3
drivers/usb/musb/musb_debugfs.c
··· 235 235 u8 reg; 236 236 int connect; 237 237 238 - switch (musb->xceiv->otg->state) { 238 + switch (musb_get_state(musb)) { 239 239 case OTG_STATE_A_HOST: 240 240 case OTG_STATE_A_WAIT_BCON: 241 241 pm_runtime_get_sync(musb->controller); ··· 275 275 276 276 pm_runtime_get_sync(musb->controller); 277 277 if (!strncmp(buf, "0", 1)) { 278 - switch (musb->xceiv->otg->state) { 278 + switch (musb_get_state(musb)) { 279 279 case OTG_STATE_A_HOST: 280 280 musb_root_disconnect(musb); 281 281 reg = musb_readb(musb->mregs, MUSB_DEVCTL); ··· 286 286 break; 287 287 } 288 288 } else if (!strncmp(buf, "1", 1)) { 289 - switch (musb->xceiv->otg->state) { 289 + switch (musb_get_state(musb)) { 290 290 case OTG_STATE_A_WAIT_BCON: 291 291 /* 292 292 * musb_save_context() called in musb_runtime_suspend()
+3 -10
drivers/usb/musb/musb_dma.h
··· 61 61 #define musb_dma_cppi41(musb) 0 62 62 #endif 63 63 64 - #ifdef CONFIG_USB_TI_CPPI_DMA 65 - #define musb_dma_cppi(musb) (musb->ops->quirks & MUSB_DMA_CPPI) 66 - #else 67 - #define musb_dma_cppi(musb) 0 68 - #endif 69 - 70 64 #ifdef CONFIG_USB_TUSB_OMAP_DMA 71 65 #define tusb_dma_omap(musb) (musb->ops->quirks & MUSB_DMA_TUSB_OMAP) 72 66 #else ··· 73 79 #define musb_dma_inventra(musb) 0 74 80 #endif 75 81 76 - #if defined(CONFIG_USB_TI_CPPI_DMA) || defined(CONFIG_USB_TI_CPPI41_DMA) 77 - #define is_cppi_enabled(musb) \ 78 - (musb_dma_cppi(musb) || musb_dma_cppi41(musb)) 82 + #if defined(CONFIG_USB_TI_CPPI41_DMA) 83 + #define is_cppi_enabled(musb) musb_dma_cppi41(musb) 79 84 #else 80 - #define is_cppi_enabled(musb) 0 85 + #define is_cppi_enabled(musb) 0 81 86 #endif 82 87 83 88 /*
+34 -27
drivers/usb/musb/musb_gadget.c
··· 1523 1523 1524 1524 spin_lock_irqsave(&musb->lock, flags); 1525 1525 1526 - switch (musb->xceiv->otg->state) { 1526 + switch (musb_get_state(musb)) { 1527 1527 case OTG_STATE_B_PERIPHERAL: 1528 1528 /* NOTE: OTG state machine doesn't include B_SUSPENDED; 1529 1529 * that's part of the standard usb 1.1 state machine, and ··· 1552 1552 break; 1553 1553 } 1554 1554 1555 - spin_unlock_irqrestore(&musb->lock, flags); 1556 - otg_start_srp(musb->xceiv->otg); 1557 - spin_lock_irqsave(&musb->lock, flags); 1555 + if (musb->xceiv) { 1556 + spin_unlock_irqrestore(&musb->lock, flags); 1557 + otg_start_srp(musb->xceiv->otg); 1558 + spin_lock_irqsave(&musb->lock, flags); 1559 + } 1558 1560 1559 1561 /* Block idling for at least 1s */ 1560 1562 musb_platform_try_idle(musb, ··· 1566 1564 goto done; 1567 1565 default: 1568 1566 musb_dbg(musb, "Unhandled wake: %s", 1569 - usb_otg_state_string(musb->xceiv->otg->state)); 1567 + musb_otg_state_string(musb)); 1570 1568 goto done; 1571 1569 } 1572 1570 ··· 1630 1628 { 1631 1629 struct musb *musb = gadget_to_musb(gadget); 1632 1630 1633 - if (!musb->xceiv->set_power) 1634 - return -EOPNOTSUPP; 1635 1631 return usb_phy_set_power(musb->xceiv, mA); 1636 1632 } 1637 1633 ··· 1787 1787 musb->g.speed = USB_SPEED_UNKNOWN; 1788 1788 1789 1789 MUSB_DEV_MODE(musb); 1790 - musb->xceiv->otg->state = OTG_STATE_B_IDLE; 1790 + musb_set_state(musb, OTG_STATE_B_IDLE); 1791 1791 1792 1792 /* this "gadget" abstracts/virtualizes the controller */ 1793 1793 musb->g.name = musb_driver_name; ··· 1834 1834 struct usb_gadget_driver *driver) 1835 1835 { 1836 1836 struct musb *musb = gadget_to_musb(g); 1837 - struct usb_otg *otg = musb->xceiv->otg; 1838 1837 unsigned long flags; 1839 1838 int retval = 0; 1840 1839 ··· 1850 1851 spin_lock_irqsave(&musb->lock, flags); 1851 1852 musb->is_active = 1; 1852 1853 1853 - otg_set_peripheral(otg, &musb->g); 1854 - musb->xceiv->otg->state = OTG_STATE_B_IDLE; 1854 + if (musb->xceiv) 1855 + otg_set_peripheral(musb->xceiv->otg, &musb->g); 1856 + else 1857 + phy_set_mode(musb->phy, PHY_MODE_USB_DEVICE); 1858 + 1859 + musb_set_state(musb, OTG_STATE_B_IDLE); 1855 1860 spin_unlock_irqrestore(&musb->lock, flags); 1856 1861 1857 1862 musb_start(musb); ··· 1864 1861 * handles power budgeting ... this way also 1865 1862 * ensures HdrcStart is indirectly called. 1866 1863 */ 1867 - if (musb->xceiv->last_event == USB_EVENT_ID) 1864 + if (musb->xceiv && musb->xceiv->last_event == USB_EVENT_ID) 1868 1865 musb_platform_set_vbus(musb, 1); 1869 1866 1870 1867 pm_runtime_mark_last_busy(musb->controller); ··· 1900 1897 1901 1898 (void) musb_gadget_vbus_draw(&musb->g, 0); 1902 1899 1903 - musb->xceiv->otg->state = OTG_STATE_UNDEFINED; 1900 + musb_set_state(musb, OTG_STATE_UNDEFINED); 1904 1901 musb_stop(musb); 1905 - otg_set_peripheral(musb->xceiv->otg, NULL); 1902 + 1903 + if (musb->xceiv) 1904 + otg_set_peripheral(musb->xceiv->otg, NULL); 1905 + else 1906 + phy_set_mode(musb->phy, PHY_MODE_INVALID); 1906 1907 1907 1908 musb->is_active = 0; 1908 1909 musb->gadget_driver = NULL; ··· 1933 1926 void musb_g_resume(struct musb *musb) 1934 1927 { 1935 1928 musb->is_suspended = 0; 1936 - switch (musb->xceiv->otg->state) { 1929 + switch (musb_get_state(musb)) { 1937 1930 case OTG_STATE_B_IDLE: 1938 1931 break; 1939 1932 case OTG_STATE_B_WAIT_ACON: ··· 1947 1940 break; 1948 1941 default: 1949 1942 WARNING("unhandled RESUME transition (%s)\n", 1950 - usb_otg_state_string(musb->xceiv->otg->state)); 1943 + musb_otg_state_string(musb)); 1951 1944 } 1952 1945 } 1953 1946 ··· 1959 1952 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 1960 1953 musb_dbg(musb, "musb_g_suspend: devctl %02x", devctl); 1961 1954 1962 - switch (musb->xceiv->otg->state) { 1955 + switch (musb_get_state(musb)) { 1963 1956 case OTG_STATE_B_IDLE: 1964 1957 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) 1965 - musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; 1958 + musb_set_state(musb, OTG_STATE_B_PERIPHERAL); 1966 1959 break; 1967 1960 case OTG_STATE_B_PERIPHERAL: 1968 1961 musb->is_suspended = 1; ··· 1977 1970 * A_PERIPHERAL may need care too 1978 1971 */ 1979 1972 WARNING("unhandled SUSPEND transition (%s)", 1980 - usb_otg_state_string(musb->xceiv->otg->state)); 1973 + musb_otg_state_string(musb)); 1981 1974 } 1982 1975 } 1983 1976 ··· 2008 2001 spin_lock(&musb->lock); 2009 2002 } 2010 2003 2011 - switch (musb->xceiv->otg->state) { 2004 + switch (musb_get_state(musb)) { 2012 2005 default: 2013 2006 musb_dbg(musb, "Unhandled disconnect %s, setting a_idle", 2014 - usb_otg_state_string(musb->xceiv->otg->state)); 2015 - musb->xceiv->otg->state = OTG_STATE_A_IDLE; 2007 + musb_otg_state_string(musb)); 2008 + musb_set_state(musb, OTG_STATE_A_IDLE); 2016 2009 MUSB_HST_MODE(musb); 2017 2010 break; 2018 2011 case OTG_STATE_A_PERIPHERAL: 2019 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; 2012 + musb_set_state(musb, OTG_STATE_A_WAIT_BCON); 2020 2013 MUSB_HST_MODE(musb); 2021 2014 break; 2022 2015 case OTG_STATE_B_WAIT_ACON: 2023 2016 case OTG_STATE_B_HOST: 2024 2017 case OTG_STATE_B_PERIPHERAL: 2025 2018 case OTG_STATE_B_IDLE: 2026 - musb->xceiv->otg->state = OTG_STATE_B_IDLE; 2019 + musb_set_state(musb, OTG_STATE_B_IDLE); 2027 2020 break; 2028 2021 case OTG_STATE_B_SRP_INIT: 2029 2022 break; ··· 2087 2080 * In that case, do not rely on devctl for setting 2088 2081 * peripheral mode. 2089 2082 */ 2090 - musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; 2083 + musb_set_state(musb, OTG_STATE_B_PERIPHERAL); 2091 2084 musb->g.is_a_peripheral = 0; 2092 2085 } else if (devctl & MUSB_DEVCTL_BDEVICE) { 2093 - musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; 2086 + musb_set_state(musb, OTG_STATE_B_PERIPHERAL); 2094 2087 musb->g.is_a_peripheral = 0; 2095 2088 } else { 2096 - musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL; 2089 + musb_set_state(musb, OTG_STATE_A_PERIPHERAL); 2097 2090 musb->g.is_a_peripheral = 1; 2098 2091 } 2099 2092
+12 -6
drivers/usb/musb/musb_host.c
··· 2501 2501 if (!is_host_active(musb)) 2502 2502 return 0; 2503 2503 2504 - switch (musb->xceiv->otg->state) { 2504 + switch (musb_get_state(musb)) { 2505 2505 case OTG_STATE_A_SUSPEND: 2506 2506 return 0; 2507 2507 case OTG_STATE_A_WAIT_VRISE: ··· 2511 2511 */ 2512 2512 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 2513 2513 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) 2514 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; 2514 + musb_set_state(musb, OTG_STATE_A_WAIT_BCON); 2515 2515 break; 2516 2516 default: 2517 2517 break; ··· 2519 2519 2520 2520 if (musb->is_active) { 2521 2521 WARNING("trying to suspend as %s while active\n", 2522 - usb_otg_state_string(musb->xceiv->otg->state)); 2522 + musb_otg_state_string(musb)); 2523 2523 return -EBUSY; 2524 2524 } else 2525 2525 return 0; ··· 2720 2720 2721 2721 if (musb->port_mode == MUSB_HOST) { 2722 2722 MUSB_HST_MODE(musb); 2723 - musb->xceiv->otg->state = OTG_STATE_A_IDLE; 2723 + musb_set_state(musb, OTG_STATE_A_IDLE); 2724 2724 } 2725 - otg_set_host(musb->xceiv->otg, &hcd->self); 2725 + 2726 + if (musb->xceiv) { 2727 + otg_set_host(musb->xceiv->otg, &hcd->self); 2728 + musb->xceiv->otg->host = &hcd->self; 2729 + } else { 2730 + phy_set_mode(musb->phy, PHY_MODE_USB_HOST); 2731 + } 2732 + 2726 2733 /* don't support otg protocols */ 2727 2734 hcd->self.otg_port = 0; 2728 - musb->xceiv->otg->host = &hcd->self; 2729 2735 hcd->power_budget = 2 * (power_budget ? : 250); 2730 2736 hcd->skip_phy_initialization = 1; 2731 2737
+16 -17
drivers/usb/musb/musb_virthub.c
··· 43 43 musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; 44 44 usb_hcd_poll_rh_status(musb->hcd); 45 45 /* NOTE: it might really be A_WAIT_BCON ... */ 46 - musb->xceiv->otg->state = OTG_STATE_A_HOST; 46 + musb_set_state(musb, OTG_STATE_A_HOST); 47 47 48 48 spin_unlock_irqrestore(&musb->lock, flags); 49 49 } 50 50 51 51 int musb_port_suspend(struct musb *musb, bool do_suspend) 52 52 { 53 - struct usb_otg *otg = musb->xceiv->otg; 54 53 u8 power; 55 54 void __iomem *mbase = musb->mregs; 56 55 ··· 84 85 musb_dbg(musb, "Root port suspended, power %02x", power); 85 86 86 87 musb->port1_status |= USB_PORT_STAT_SUSPEND; 87 - switch (musb->xceiv->otg->state) { 88 + switch (musb_get_state(musb)) { 88 89 case OTG_STATE_A_HOST: 89 - musb->xceiv->otg->state = OTG_STATE_A_SUSPEND; 90 - musb->is_active = otg->host->b_hnp_enable; 90 + musb_set_state(musb, OTG_STATE_A_SUSPEND); 91 + musb->is_active = musb->xceiv && 92 + musb->xceiv->otg->host->b_hnp_enable; 91 93 if (musb->is_active) 92 94 mod_timer(&musb->otg_timer, jiffies 93 95 + msecs_to_jiffies( ··· 96 96 musb_platform_try_idle(musb, 0); 97 97 break; 98 98 case OTG_STATE_B_HOST: 99 - musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON; 100 - musb->is_active = otg->host->b_hnp_enable; 99 + musb_set_state(musb, OTG_STATE_B_WAIT_ACON); 100 + musb->is_active = musb->xceiv && 101 + musb->xceiv->otg->host->b_hnp_enable; 101 102 musb_platform_try_idle(musb, 0); 102 103 break; 103 104 default: 104 105 musb_dbg(musb, "bogus rh suspend? %s", 105 - usb_otg_state_string(musb->xceiv->otg->state)); 106 + musb_otg_state_string(musb)); 106 107 } 107 108 } else if (power & MUSB_POWER_SUSPENDM) { 108 109 power &= ~MUSB_POWER_SUSPENDM; ··· 124 123 u8 power; 125 124 void __iomem *mbase = musb->mregs; 126 125 127 - if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) { 126 + if (musb_get_state(musb) == OTG_STATE_B_IDLE) { 128 127 musb_dbg(musb, "HNP: Returning from HNP; no hub reset from b_idle"); 129 128 musb->port1_status &= ~USB_PORT_STAT_RESET; 130 129 return; ··· 197 196 198 197 void musb_root_disconnect(struct musb *musb) 199 198 { 200 - struct usb_otg *otg = musb->xceiv->otg; 201 - 202 199 musb->port1_status = USB_PORT_STAT_POWER 203 200 | (USB_PORT_STAT_C_CONNECTION << 16); 204 201 205 202 usb_hcd_poll_rh_status(musb->hcd); 206 203 musb->is_active = 0; 207 204 208 - switch (musb->xceiv->otg->state) { 205 + switch (musb_get_state(musb)) { 209 206 case OTG_STATE_A_SUSPEND: 210 - if (otg->host->b_hnp_enable) { 211 - musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL; 207 + if (musb->xceiv && musb->xceiv->otg->host->b_hnp_enable) { 208 + musb_set_state(musb, OTG_STATE_A_PERIPHERAL); 212 209 musb->g.is_a_peripheral = 1; 213 210 break; 214 211 } 215 212 fallthrough; 216 213 case OTG_STATE_A_HOST: 217 - musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; 214 + musb_set_state(musb, OTG_STATE_A_WAIT_BCON); 218 215 musb->is_active = 0; 219 216 break; 220 217 case OTG_STATE_A_WAIT_VFALL: 221 - musb->xceiv->otg->state = OTG_STATE_B_IDLE; 218 + musb_set_state(musb, OTG_STATE_B_IDLE); 222 219 break; 223 220 default: 224 221 musb_dbg(musb, "host disconnect (%s)", 225 - usb_otg_state_string(musb->xceiv->otg->state)); 222 + musb_otg_state_string(musb)); 226 223 } 227 224 } 228 225 EXPORT_SYMBOL_GPL(musb_root_disconnect);
+54
drivers/usb/musb/omap2430.c
··· 15 15 #include <linux/list.h> 16 16 #include <linux/io.h> 17 17 #include <linux/of.h> 18 + #include <linux/of_irq.h> 18 19 #include <linux/platform_device.h> 19 20 #include <linux/dma-mapping.h> 20 21 #include <linux/pm_runtime.h> ··· 311 310 struct device_node *control_node; 312 311 struct platform_device *control_pdev; 313 312 int ret = -ENOMEM, val; 313 + bool populate_irqs = false; 314 314 315 315 if (!np) 316 316 return -ENODEV; ··· 329 327 musb->dev.parent = &pdev->dev; 330 328 musb->dev.dma_mask = &omap2430_dmamask; 331 329 musb->dev.coherent_dma_mask = omap2430_dmamask; 330 + 331 + /* 332 + * Legacy SoCs using omap_device get confused if node is moved 333 + * because of interconnect properties mixed into the node. 334 + */ 335 + if (of_get_property(np, "ti,hwmods", NULL)) { 336 + dev_warn(&pdev->dev, "please update to probe with ti-sysc\n"); 337 + populate_irqs = true; 338 + } else { 339 + device_set_of_node_from_dev(&musb->dev, &pdev->dev); 340 + } 341 + of_node_put(np); 332 342 333 343 glue->dev = &pdev->dev; 334 344 glue->musb = musb; ··· 401 387 if (ret) { 402 388 dev_err(&pdev->dev, "failed to add resources\n"); 403 389 goto err2; 390 + } 391 + 392 + if (populate_irqs) { 393 + struct resource musb_res[3]; 394 + struct resource *res; 395 + int i = 0; 396 + 397 + memset(musb_res, 0, sizeof(*musb_res) * ARRAY_SIZE(musb_res)); 398 + 399 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 400 + if (!res) 401 + goto err2; 402 + 403 + musb_res[i].start = res->start; 404 + musb_res[i].end = res->end; 405 + musb_res[i].flags = res->flags; 406 + musb_res[i].name = res->name; 407 + i++; 408 + 409 + ret = of_irq_get_byname(np, "mc"); 410 + if (ret > 0) { 411 + musb_res[i].start = ret; 412 + musb_res[i].flags = IORESOURCE_IRQ; 413 + musb_res[i].name = "mc"; 414 + i++; 415 + } 416 + 417 + ret = of_irq_get_byname(np, "dma"); 418 + if (ret > 0) { 419 + musb_res[i].start = ret; 420 + musb_res[i].flags = IORESOURCE_IRQ; 421 + musb_res[i].name = "dma"; 422 + i++; 423 + } 424 + 425 + ret = platform_device_add_resources(musb, musb_res, i); 426 + if (ret) { 427 + dev_err(&pdev->dev, "failed to add IRQ resources\n"); 428 + goto err2; 429 + } 404 430 } 405 431 406 432 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
+5 -9
drivers/usb/phy/Kconfig
··· 93 93 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'" 94 94 depends on GPIOLIB || COMPILE_TEST 95 95 depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' 96 + depends on !USB_CONN_GPIO 96 97 select USB_PHY 97 98 help 98 99 Provides simple GPIO VBUS sensing for controllers with an 99 100 internal transceiver via the usb_phy interface, and 100 101 optionally control of a D+ pullup GPIO as well as a VBUS 101 - current limit regulator. 102 + current limit regulator. This driver is for devices that do 103 + NOT support role switch. OTG devices that can do role switch 104 + (master/peripheral) shall use the USB based connection 105 + detection driver USB_CONN_GPIO. 102 106 103 107 config OMAP_OTG 104 108 tristate "OMAP USB OTG controller driver" ··· 188 184 help 189 185 Provides read/write operations to the ULPI phy register set for 190 186 controllers with a viewport register (e.g. Chipidea/ARC controllers). 191 - 192 - config JZ4770_PHY 193 - tristate "Ingenic SoCs Transceiver Driver" 194 - depends on MIPS || COMPILE_TEST 195 - select USB_PHY 196 - help 197 - This driver provides PHY support for the USB controller found 198 - on the JZ-series and X-series SoCs from Ingenic. 199 187 200 188 endmenu
-1
drivers/usb/phy/Makefile
··· 24 24 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o 25 25 obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o 26 26 obj-$(CONFIG_KEYSTONE_USB_PHY) += phy-keystone.o 27 - obj-$(CONFIG_JZ4770_PHY) += phy-jz4770.o
+9 -9
drivers/usb/phy/phy-generic.c
··· 209 209 int err = 0; 210 210 211 211 u32 clk_rate = 0; 212 - bool needs_vcc = false, needs_clk = false; 212 + bool needs_clk = false; 213 213 214 214 if (dev->of_node) { 215 215 struct device_node *node = dev->of_node; ··· 217 217 if (of_property_read_u32(node, "clock-frequency", &clk_rate)) 218 218 clk_rate = 0; 219 219 220 - needs_vcc = of_property_read_bool(node, "vcc-supply"); 221 220 needs_clk = of_property_read_bool(node, "clocks"); 222 221 } 223 222 nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset", ··· 256 257 } 257 258 } 258 259 259 - nop->vcc = devm_regulator_get(dev, "vcc"); 260 - if (IS_ERR(nop->vcc)) { 261 - dev_dbg(dev, "Error getting vcc regulator: %ld\n", 262 - PTR_ERR(nop->vcc)); 263 - if (needs_vcc) 264 - return -EPROBE_DEFER; 265 - } 260 + nop->vcc = devm_regulator_get_optional(dev, "vcc"); 261 + if (IS_ERR(nop->vcc) && PTR_ERR(nop->vcc) != -ENODEV) 262 + return dev_err_probe(dev, PTR_ERR(nop->vcc), 263 + "could not get vcc regulator\n"); 266 264 267 265 nop->vbus_draw = devm_regulator_get_exclusive(dev, "vbus"); 268 266 if (PTR_ERR(nop->vbus_draw) == -ENODEV) ··· 286 290 static int usb_phy_generic_probe(struct platform_device *pdev) 287 291 { 288 292 struct device *dev = &pdev->dev; 293 + struct device_node *dn = dev->of_node; 289 294 struct usb_phy_generic *nop; 290 295 int err; 291 296 ··· 323 326 } 324 327 325 328 platform_set_drvdata(pdev, nop); 329 + 330 + device_set_wakeup_capable(&pdev->dev, 331 + of_property_read_bool(dn, "wakeup-source")); 326 332 327 333 return 0; 328 334 }
+12
drivers/usb/phy/phy-gpio-vbus-usb.c
··· 366 366 367 367 MODULE_ALIAS("platform:gpio-vbus"); 368 368 369 + /* 370 + * NOTE: this driver matches against "gpio-usb-b-connector" for 371 + * devices that do NOT support role switch. 372 + */ 373 + static const struct of_device_id gpio_vbus_of_match[] = { 374 + { 375 + .compatible = "gpio-usb-b-connector", 376 + }, 377 + {}, 378 + }; 379 + 369 380 static struct platform_driver gpio_vbus_driver = { 370 381 .driver = { 371 382 .name = "gpio-vbus", 372 383 #ifdef CONFIG_PM 373 384 .pm = &gpio_vbus_dev_pm_ops, 374 385 #endif 386 + .of_match_table = gpio_vbus_of_match, 375 387 }, 376 388 .probe = gpio_vbus_probe, 377 389 .remove = gpio_vbus_remove,
+2 -2
drivers/usb/phy/phy-isp1301-omap.c
··· 1471 1471 /*-------------------------------------------------------------------------*/ 1472 1472 1473 1473 static int 1474 - isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id) 1474 + isp1301_probe(struct i2c_client *i2c) 1475 1475 { 1476 1476 int status; 1477 1477 struct isp1301 *isp; ··· 1616 1616 .driver = { 1617 1617 .name = "isp1301_omap", 1618 1618 }, 1619 - .probe = isp1301_probe, 1619 + .probe_new = isp1301_probe, 1620 1620 .remove = isp1301_remove, 1621 1621 .id_table = isp1301_id, 1622 1622 };
+2 -3
drivers/usb/phy/phy-isp1301.c
··· 92 92 return 0; 93 93 } 94 94 95 - static int isp1301_probe(struct i2c_client *client, 96 - const struct i2c_device_id *i2c_id) 95 + static int isp1301_probe(struct i2c_client *client) 97 96 { 98 97 struct isp1301 *isp; 99 98 struct usb_phy *phy; ··· 132 133 .name = DRV_NAME, 133 134 .of_match_table = isp1301_of_match, 134 135 }, 135 - .probe = isp1301_probe, 136 + .probe_new = isp1301_probe, 136 137 .remove = isp1301_remove, 137 138 .id_table = isp1301_id, 138 139 };
-353
drivers/usb/phy/phy-jz4770.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Ingenic SoCs USB PHY driver 4 - * Copyright (c) Paul Cercueil <paul@crapouillou.net> 5 - * Copyright (c) 漆鹏振 (Qi Pengzhen) <aric.pzqi@ingenic.com> 6 - * Copyright (c) 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com> 7 - */ 8 - 9 - #include <linux/clk.h> 10 - #include <linux/io.h> 11 - #include <linux/module.h> 12 - #include <linux/platform_device.h> 13 - #include <linux/regulator/consumer.h> 14 - #include <linux/usb/otg.h> 15 - #include <linux/usb/phy.h> 16 - 17 - /* OTGPHY register offsets */ 18 - #define REG_USBPCR_OFFSET 0x00 19 - #define REG_USBRDT_OFFSET 0x04 20 - #define REG_USBVBFIL_OFFSET 0x08 21 - #define REG_USBPCR1_OFFSET 0x0c 22 - 23 - /* bits within the USBPCR register */ 24 - #define USBPCR_USB_MODE BIT(31) 25 - #define USBPCR_AVLD_REG BIT(30) 26 - #define USBPCR_COMMONONN BIT(25) 27 - #define USBPCR_VBUSVLDEXT BIT(24) 28 - #define USBPCR_VBUSVLDEXTSEL BIT(23) 29 - #define USBPCR_POR BIT(22) 30 - #define USBPCR_SIDDQ BIT(21) 31 - #define USBPCR_OTG_DISABLE BIT(20) 32 - #define USBPCR_TXPREEMPHTUNE BIT(6) 33 - 34 - #define USBPCR_IDPULLUP_LSB 28 35 - #define USBPCR_IDPULLUP_MASK GENMASK(29, USBPCR_IDPULLUP_LSB) 36 - #define USBPCR_IDPULLUP_ALWAYS (0x2 << USBPCR_IDPULLUP_LSB) 37 - #define USBPCR_IDPULLUP_SUSPEND (0x1 << USBPCR_IDPULLUP_LSB) 38 - #define USBPCR_IDPULLUP_OTG (0x0 << USBPCR_IDPULLUP_LSB) 39 - 40 - #define USBPCR_COMPDISTUNE_LSB 17 41 - #define USBPCR_COMPDISTUNE_MASK GENMASK(19, USBPCR_COMPDISTUNE_LSB) 42 - #define USBPCR_COMPDISTUNE_DFT (0x4 << USBPCR_COMPDISTUNE_LSB) 43 - 44 - #define USBPCR_OTGTUNE_LSB 14 45 - #define USBPCR_OTGTUNE_MASK GENMASK(16, USBPCR_OTGTUNE_LSB) 46 - #define USBPCR_OTGTUNE_DFT (0x4 << USBPCR_OTGTUNE_LSB) 47 - 48 - #define USBPCR_SQRXTUNE_LSB 11 49 - #define USBPCR_SQRXTUNE_MASK GENMASK(13, USBPCR_SQRXTUNE_LSB) 50 - #define USBPCR_SQRXTUNE_DCR_20PCT (0x7 << USBPCR_SQRXTUNE_LSB) 51 - #define USBPCR_SQRXTUNE_DFT (0x3 << USBPCR_SQRXTUNE_LSB) 52 - 53 - #define USBPCR_TXFSLSTUNE_LSB 7 54 - #define USBPCR_TXFSLSTUNE_MASK GENMASK(10, USBPCR_TXFSLSTUNE_LSB) 55 - #define USBPCR_TXFSLSTUNE_DCR_50PPT (0xf << USBPCR_TXFSLSTUNE_LSB) 56 - #define USBPCR_TXFSLSTUNE_DCR_25PPT (0x7 << USBPCR_TXFSLSTUNE_LSB) 57 - #define USBPCR_TXFSLSTUNE_DFT (0x3 << USBPCR_TXFSLSTUNE_LSB) 58 - #define USBPCR_TXFSLSTUNE_INC_25PPT (0x1 << USBPCR_TXFSLSTUNE_LSB) 59 - #define USBPCR_TXFSLSTUNE_INC_50PPT (0x0 << USBPCR_TXFSLSTUNE_LSB) 60 - 61 - #define USBPCR_TXHSXVTUNE_LSB 4 62 - #define USBPCR_TXHSXVTUNE_MASK GENMASK(5, USBPCR_TXHSXVTUNE_LSB) 63 - #define USBPCR_TXHSXVTUNE_DFT (0x3 << USBPCR_TXHSXVTUNE_LSB) 64 - #define USBPCR_TXHSXVTUNE_DCR_15MV (0x1 << USBPCR_TXHSXVTUNE_LSB) 65 - 66 - #define USBPCR_TXRISETUNE_LSB 4 67 - #define USBPCR_TXRISETUNE_MASK GENMASK(5, USBPCR_TXRISETUNE_LSB) 68 - #define USBPCR_TXRISETUNE_DFT (0x3 << USBPCR_TXRISETUNE_LSB) 69 - 70 - #define USBPCR_TXVREFTUNE_LSB 0 71 - #define USBPCR_TXVREFTUNE_MASK GENMASK(3, USBPCR_TXVREFTUNE_LSB) 72 - #define USBPCR_TXVREFTUNE_INC_25PPT (0x7 << USBPCR_TXVREFTUNE_LSB) 73 - #define USBPCR_TXVREFTUNE_DFT (0x5 << USBPCR_TXVREFTUNE_LSB) 74 - 75 - /* bits within the USBRDTR register */ 76 - #define USBRDT_UTMI_RST BIT(27) 77 - #define USBRDT_HB_MASK BIT(26) 78 - #define USBRDT_VBFIL_LD_EN BIT(25) 79 - #define USBRDT_IDDIG_EN BIT(24) 80 - #define USBRDT_IDDIG_REG BIT(23) 81 - #define USBRDT_VBFIL_EN BIT(2) 82 - 83 - /* bits within the USBPCR1 register */ 84 - #define USBPCR1_BVLD_REG BIT(31) 85 - #define USBPCR1_DPPD BIT(29) 86 - #define USBPCR1_DMPD BIT(28) 87 - #define USBPCR1_USB_SEL BIT(28) 88 - #define USBPCR1_WORD_IF_16BIT BIT(19) 89 - 90 - enum ingenic_usb_phy_version { 91 - ID_JZ4770, 92 - ID_JZ4780, 93 - ID_X1000, 94 - ID_X1830, 95 - }; 96 - 97 - struct ingenic_soc_info { 98 - enum ingenic_usb_phy_version version; 99 - 100 - void (*usb_phy_init)(struct usb_phy *phy); 101 - }; 102 - 103 - struct jz4770_phy { 104 - const struct ingenic_soc_info *soc_info; 105 - 106 - struct usb_phy phy; 107 - struct usb_otg otg; 108 - struct device *dev; 109 - void __iomem *base; 110 - struct clk *clk; 111 - struct regulator *vcc_supply; 112 - }; 113 - 114 - static inline struct jz4770_phy *otg_to_jz4770_phy(struct usb_otg *otg) 115 - { 116 - return container_of(otg, struct jz4770_phy, otg); 117 - } 118 - 119 - static inline struct jz4770_phy *phy_to_jz4770_phy(struct usb_phy *phy) 120 - { 121 - return container_of(phy, struct jz4770_phy, phy); 122 - } 123 - 124 - static int ingenic_usb_phy_set_peripheral(struct usb_otg *otg, 125 - struct usb_gadget *gadget) 126 - { 127 - struct jz4770_phy *priv = otg_to_jz4770_phy(otg); 128 - u32 reg; 129 - 130 - if (priv->soc_info->version >= ID_X1000) { 131 - reg = readl(priv->base + REG_USBPCR1_OFFSET); 132 - reg |= USBPCR1_BVLD_REG; 133 - writel(reg, priv->base + REG_USBPCR1_OFFSET); 134 - } 135 - 136 - reg = readl(priv->base + REG_USBPCR_OFFSET); 137 - reg &= ~USBPCR_USB_MODE; 138 - reg |= USBPCR_VBUSVLDEXT | USBPCR_VBUSVLDEXTSEL | USBPCR_OTG_DISABLE; 139 - writel(reg, priv->base + REG_USBPCR_OFFSET); 140 - 141 - return 0; 142 - } 143 - 144 - static int ingenic_usb_phy_set_host(struct usb_otg *otg, struct usb_bus *host) 145 - { 146 - struct jz4770_phy *priv = otg_to_jz4770_phy(otg); 147 - u32 reg; 148 - 149 - reg = readl(priv->base + REG_USBPCR_OFFSET); 150 - reg &= ~(USBPCR_VBUSVLDEXT | USBPCR_VBUSVLDEXTSEL | USBPCR_OTG_DISABLE); 151 - reg |= USBPCR_USB_MODE; 152 - writel(reg, priv->base + REG_USBPCR_OFFSET); 153 - 154 - return 0; 155 - } 156 - 157 - static int ingenic_usb_phy_init(struct usb_phy *phy) 158 - { 159 - struct jz4770_phy *priv = phy_to_jz4770_phy(phy); 160 - int err; 161 - u32 reg; 162 - 163 - err = regulator_enable(priv->vcc_supply); 164 - if (err) { 165 - dev_err(priv->dev, "Unable to enable VCC: %d\n", err); 166 - return err; 167 - } 168 - 169 - err = clk_prepare_enable(priv->clk); 170 - if (err) { 171 - dev_err(priv->dev, "Unable to start clock: %d\n", err); 172 - return err; 173 - } 174 - 175 - priv->soc_info->usb_phy_init(phy); 176 - 177 - /* Wait for PHY to reset */ 178 - usleep_range(30, 300); 179 - reg = readl(priv->base + REG_USBPCR_OFFSET); 180 - writel(reg & ~USBPCR_POR, priv->base + REG_USBPCR_OFFSET); 181 - usleep_range(300, 1000); 182 - 183 - return 0; 184 - } 185 - 186 - static void ingenic_usb_phy_shutdown(struct usb_phy *phy) 187 - { 188 - struct jz4770_phy *priv = phy_to_jz4770_phy(phy); 189 - 190 - clk_disable_unprepare(priv->clk); 191 - regulator_disable(priv->vcc_supply); 192 - } 193 - 194 - static void ingenic_usb_phy_remove(void *phy) 195 - { 196 - usb_remove_phy(phy); 197 - } 198 - 199 - static void jz4770_usb_phy_init(struct usb_phy *phy) 200 - { 201 - struct jz4770_phy *priv = phy_to_jz4770_phy(phy); 202 - u32 reg; 203 - 204 - reg = USBPCR_AVLD_REG | USBPCR_COMMONONN | USBPCR_IDPULLUP_ALWAYS | 205 - USBPCR_COMPDISTUNE_DFT | USBPCR_OTGTUNE_DFT | USBPCR_SQRXTUNE_DFT | 206 - USBPCR_TXFSLSTUNE_DFT | USBPCR_TXRISETUNE_DFT | USBPCR_TXVREFTUNE_DFT | 207 - USBPCR_POR; 208 - writel(reg, priv->base + REG_USBPCR_OFFSET); 209 - } 210 - 211 - static void jz4780_usb_phy_init(struct usb_phy *phy) 212 - { 213 - struct jz4770_phy *priv = phy_to_jz4770_phy(phy); 214 - u32 reg; 215 - 216 - reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_USB_SEL | 217 - USBPCR1_WORD_IF_16BIT; 218 - writel(reg, priv->base + REG_USBPCR1_OFFSET); 219 - 220 - reg = USBPCR_TXPREEMPHTUNE | USBPCR_COMMONONN | USBPCR_POR; 221 - writel(reg, priv->base + REG_USBPCR_OFFSET); 222 - } 223 - 224 - static void x1000_usb_phy_init(struct usb_phy *phy) 225 - { 226 - struct jz4770_phy *priv = phy_to_jz4770_phy(phy); 227 - u32 reg; 228 - 229 - reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_WORD_IF_16BIT; 230 - writel(reg, priv->base + REG_USBPCR1_OFFSET); 231 - 232 - reg = USBPCR_SQRXTUNE_DCR_20PCT | USBPCR_TXPREEMPHTUNE | 233 - USBPCR_TXHSXVTUNE_DCR_15MV | USBPCR_TXVREFTUNE_INC_25PPT | 234 - USBPCR_COMMONONN | USBPCR_POR; 235 - writel(reg, priv->base + REG_USBPCR_OFFSET); 236 - } 237 - 238 - static void x1830_usb_phy_init(struct usb_phy *phy) 239 - { 240 - struct jz4770_phy *priv = phy_to_jz4770_phy(phy); 241 - u32 reg; 242 - 243 - /* rdt */ 244 - writel(USBRDT_VBFIL_EN | USBRDT_UTMI_RST, priv->base + REG_USBRDT_OFFSET); 245 - 246 - reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_WORD_IF_16BIT | 247 - USBPCR1_DMPD | USBPCR1_DPPD; 248 - writel(reg, priv->base + REG_USBPCR1_OFFSET); 249 - 250 - reg = USBPCR_IDPULLUP_OTG | USBPCR_VBUSVLDEXT | USBPCR_TXPREEMPHTUNE | 251 - USBPCR_COMMONONN | USBPCR_POR; 252 - writel(reg, priv->base + REG_USBPCR_OFFSET); 253 - } 254 - 255 - static const struct ingenic_soc_info jz4770_soc_info = { 256 - .version = ID_JZ4770, 257 - 258 - .usb_phy_init = jz4770_usb_phy_init, 259 - }; 260 - 261 - static const struct ingenic_soc_info jz4780_soc_info = { 262 - .version = ID_JZ4780, 263 - 264 - .usb_phy_init = jz4780_usb_phy_init, 265 - }; 266 - 267 - static const struct ingenic_soc_info x1000_soc_info = { 268 - .version = ID_X1000, 269 - 270 - .usb_phy_init = x1000_usb_phy_init, 271 - }; 272 - 273 - static const struct ingenic_soc_info x1830_soc_info = { 274 - .version = ID_X1830, 275 - 276 - .usb_phy_init = x1830_usb_phy_init, 277 - }; 278 - 279 - static const struct of_device_id ingenic_usb_phy_of_matches[] = { 280 - { .compatible = "ingenic,jz4770-phy", .data = &jz4770_soc_info }, 281 - { .compatible = "ingenic,jz4780-phy", .data = &jz4780_soc_info }, 282 - { .compatible = "ingenic,x1000-phy", .data = &x1000_soc_info }, 283 - { .compatible = "ingenic,x1830-phy", .data = &x1830_soc_info }, 284 - { /* sentinel */ } 285 - }; 286 - MODULE_DEVICE_TABLE(of, ingenic_usb_phy_of_matches); 287 - 288 - static int jz4770_phy_probe(struct platform_device *pdev) 289 - { 290 - struct device *dev = &pdev->dev; 291 - struct jz4770_phy *priv; 292 - int err; 293 - 294 - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 295 - if (!priv) 296 - return -ENOMEM; 297 - 298 - priv->soc_info = device_get_match_data(&pdev->dev); 299 - if (!priv->soc_info) { 300 - dev_err(&pdev->dev, "Error: No device match found\n"); 301 - return -ENODEV; 302 - } 303 - 304 - platform_set_drvdata(pdev, priv); 305 - priv->dev = dev; 306 - priv->phy.dev = dev; 307 - priv->phy.otg = &priv->otg; 308 - priv->phy.label = "ingenic-usb-phy"; 309 - priv->phy.init = ingenic_usb_phy_init; 310 - priv->phy.shutdown = ingenic_usb_phy_shutdown; 311 - 312 - priv->otg.state = OTG_STATE_UNDEFINED; 313 - priv->otg.usb_phy = &priv->phy; 314 - priv->otg.set_host = ingenic_usb_phy_set_host; 315 - priv->otg.set_peripheral = ingenic_usb_phy_set_peripheral; 316 - 317 - priv->base = devm_platform_ioremap_resource(pdev, 0); 318 - if (IS_ERR(priv->base)) { 319 - dev_err(dev, "Failed to map registers\n"); 320 - return PTR_ERR(priv->base); 321 - } 322 - 323 - priv->clk = devm_clk_get(dev, NULL); 324 - if (IS_ERR(priv->clk)) 325 - return dev_err_probe(dev, PTR_ERR(priv->clk), 326 - "Failed to get clock\n"); 327 - 328 - priv->vcc_supply = devm_regulator_get(dev, "vcc"); 329 - if (IS_ERR(priv->vcc_supply)) 330 - return dev_err_probe(dev, PTR_ERR(priv->vcc_supply), 331 - "Failed to get regulator\n"); 332 - 333 - err = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2); 334 - if (err) 335 - return dev_err_probe(dev, err, "Unable to register PHY\n"); 336 - 337 - return devm_add_action_or_reset(dev, ingenic_usb_phy_remove, &priv->phy); 338 - } 339 - 340 - static struct platform_driver ingenic_phy_driver = { 341 - .probe = jz4770_phy_probe, 342 - .driver = { 343 - .name = "jz4770-phy", 344 - .of_match_table = ingenic_usb_phy_of_matches, 345 - }, 346 - }; 347 - module_platform_driver(ingenic_phy_driver); 348 - 349 - MODULE_AUTHOR("周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>"); 350 - MODULE_AUTHOR("漆鹏振 (Qi Pengzhen) <aric.pzqi@ingenic.com>"); 351 - MODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>"); 352 - MODULE_DESCRIPTION("Ingenic SoCs USB PHY driver"); 353 - MODULE_LICENSE("GPL");
+4 -1
drivers/usb/roles/class.c
··· 106 106 struct fwnode_handle *parent = fwnode_get_parent(fwnode); 107 107 struct device *dev; 108 108 109 - if (!parent || !fwnode_property_present(parent, "usb-role-switch")) 109 + if (!fwnode_property_present(parent, "usb-role-switch")) { 110 + fwnode_handle_put(parent); 110 111 return NULL; 112 + } 111 113 112 114 dev = class_find_device_by_fwnode(role_class, parent); 115 + fwnode_handle_put(parent); 113 116 return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); 114 117 } 115 118
+17 -4
drivers/usb/serial/cp210x.c
··· 195 195 { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */ 196 196 { USB_DEVICE(0x17A8, 0x0001) }, /* Kamstrup Optical Eye/3-wire */ 197 197 { USB_DEVICE(0x17A8, 0x0005) }, /* Kamstrup M-Bus Master MultiPort 250D */ 198 + { USB_DEVICE(0x17A8, 0x0011) }, /* Kamstrup 444 MHz RF sniffer */ 199 + { USB_DEVICE(0x17A8, 0x0013) }, /* Kamstrup 870 MHz RF sniffer */ 198 200 { USB_DEVICE(0x17A8, 0x0101) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Int Ant) */ 199 201 { USB_DEVICE(0x17A8, 0x0102) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Ext Ant) */ 200 202 { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */ ··· 1049 1047 struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1050 1048 u32 baud; 1051 1049 1050 + if (tty->termios.c_ospeed == 0) 1051 + return; 1052 + 1052 1053 /* 1053 1054 * This maps the requested rate to the actual rate, a valid rate on 1054 1055 * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed]. 1055 - * 1056 - * NOTE: B0 is not implemented. 1057 1056 */ 1058 1057 baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed); 1059 1058 ··· 1147 1144 tty->termios.c_iflag &= ~(IXON | IXOFF); 1148 1145 } 1149 1146 1150 - if (old_termios && 1147 + if (tty->termios.c_ospeed != 0 && 1148 + old_termios && old_termios->c_ospeed != 0 && 1151 1149 C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS) && 1152 1150 I_IXON(tty) == (old_termios->c_iflag & IXON) && 1153 1151 I_IXOFF(tty) == (old_termios->c_iflag & IXOFF) && ··· 1172 1168 } 1173 1169 1174 1170 mutex_lock(&port_priv->mutex); 1171 + 1172 + if (tty->termios.c_ospeed == 0) { 1173 + port_priv->dtr = false; 1174 + port_priv->rts = false; 1175 + } else if (old_termios && old_termios->c_ospeed == 0) { 1176 + port_priv->dtr = true; 1177 + port_priv->rts = true; 1178 + } 1175 1179 1176 1180 ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, 1177 1181 sizeof(flow_ctl)); ··· 1253 1241 u16 bits; 1254 1242 int ret; 1255 1243 1256 - if (old_termios && !cp210x_termios_change(&tty->termios, old_termios)) 1244 + if (old_termios && !cp210x_termios_change(&tty->termios, old_termios) && 1245 + tty->termios.c_ospeed != 0) 1257 1246 return; 1258 1247 1259 1248 if (!old_termios || tty->termios.c_ospeed != old_termios->c_ospeed)
+7 -5
drivers/usb/serial/f81232.c
··· 130 130 131 131 static int calc_baud_divisor(speed_t baudrate, speed_t clockrate) 132 132 { 133 - if (!baudrate) 134 - return 0; 135 - 136 133 return DIV_ROUND_CLOSEST(clockrate, baudrate); 137 134 } 138 135 ··· 495 498 speed_t baud_list[] = { baudrate, old_baudrate, F81232_DEF_BAUDRATE }; 496 499 497 500 for (i = 0; i < ARRAY_SIZE(baud_list); ++i) { 498 - idx = f81232_find_clk(baud_list[i]); 501 + baudrate = baud_list[i]; 502 + if (baudrate == 0) { 503 + tty_encode_baud_rate(tty, 0, 0); 504 + return; 505 + } 506 + 507 + idx = f81232_find_clk(baudrate); 499 508 if (idx >= 0) { 500 - baudrate = baud_list[i]; 501 509 tty_encode_baud_rate(tty, baudrate, baudrate); 502 510 break; 503 511 }
+7 -5
drivers/usb/serial/f81534.c
··· 536 536 537 537 static u32 f81534_calc_baud_divisor(u32 baudrate, u32 clockrate) 538 538 { 539 - if (!baudrate) 540 - return 0; 541 - 542 539 /* Round to nearest divisor */ 543 540 return DIV_ROUND_CLOSEST(clockrate, baudrate); 544 541 } ··· 565 568 u32 baud_list[] = {baudrate, old_baudrate, F81534_DEFAULT_BAUD_RATE}; 566 569 567 570 for (i = 0; i < ARRAY_SIZE(baud_list); ++i) { 568 - idx = f81534_find_clk(baud_list[i]); 571 + baudrate = baud_list[i]; 572 + if (baudrate == 0) { 573 + tty_encode_baud_rate(tty, 0, 0); 574 + return 0; 575 + } 576 + 577 + idx = f81534_find_clk(baudrate); 569 578 if (idx >= 0) { 570 - baudrate = baud_list[i]; 571 579 tty_encode_baud_rate(tty, baudrate, baudrate); 572 580 break; 573 581 }
+3
drivers/usb/serial/option.c
··· 255 255 #define QUECTEL_PRODUCT_EP06 0x0306 256 256 #define QUECTEL_PRODUCT_EM05G 0x030a 257 257 #define QUECTEL_PRODUCT_EM060K 0x030b 258 + #define QUECTEL_PRODUCT_EM05G_SG 0x0311 258 259 #define QUECTEL_PRODUCT_EM12 0x0512 259 260 #define QUECTEL_PRODUCT_RM500Q 0x0800 260 261 #define QUECTEL_PRODUCT_RM520N 0x0801 ··· 1160 1159 .driver_info = RSVD(1) | RSVD(2) | RSVD(3) | RSVD(4) | NUMEP2 }, 1161 1160 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06, 0xff, 0, 0) }, 1162 1161 { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G, 0xff), 1162 + .driver_info = RSVD(6) | ZLP }, 1163 + { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G_SG, 0xff), 1163 1164 .driver_info = RSVD(6) | ZLP }, 1164 1165 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0x00, 0x40) }, 1165 1166 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0xff, 0x30) },
-2
drivers/usb/serial/xr_serial.c
··· 749 749 750 750 if (tty->termios.c_ospeed) 751 751 lc->dwDTERate = cpu_to_le32(tty->termios.c_ospeed); 752 - else if (old_termios) 753 - lc->dwDTERate = cpu_to_le32(old_termios->c_ospeed); 754 752 else 755 753 lc->dwDTERate = cpu_to_le32(9600); 756 754
+2
drivers/usb/storage/alauda.c
··· 438 438 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift); 439 439 MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); 440 440 MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); 441 + if (MEDIA_INFO(us).pba_to_lba == NULL || MEDIA_INFO(us).lba_to_pba == NULL) 442 + return USB_STOR_TRANSPORT_ERROR; 441 443 442 444 if (alauda_reset_media(us) != USB_STOR_XFER_GOOD) 443 445 return USB_STOR_TRANSPORT_ERROR;
+2 -3
drivers/usb/typec/anx7411.c
··· 1440 1440 return PTR_ERR_OR_ZERO(ctx->psy); 1441 1441 } 1442 1442 1443 - static int anx7411_i2c_probe(struct i2c_client *client, 1444 - const struct i2c_device_id *id) 1443 + static int anx7411_i2c_probe(struct i2c_client *client) 1445 1444 { 1446 1445 struct anx7411_data *plat; 1447 1446 struct device *dev = &client->dev; ··· 1584 1585 .of_match_table = anx_match_table, 1585 1586 .pm = &anx7411_pm_ops, 1586 1587 }, 1587 - .probe = anx7411_i2c_probe, 1588 + .probe_new = anx7411_i2c_probe, 1588 1589 .remove = anx7411_i2c_remove, 1589 1590 1590 1591 .id_table = anx7411_id,
+1 -1
drivers/usb/typec/bus.c
··· 134 134 if (!adev || !adev->active) 135 135 return 0; 136 136 137 - if (!pdev->ops || !pdev->ops->enter) 137 + if (!pdev->ops || !pdev->ops->exit) 138 138 return -EOPNOTSUPP; 139 139 140 140 /* Moving to USB Safe State */
+19
drivers/usb/typec/class.c
··· 822 822 EXPORT_SYMBOL_GPL(typec_partner_set_svdm_version); 823 823 824 824 /** 825 + * typec_partner_usb_power_delivery_register - Register Type-C partner USB Power Delivery Support 826 + * @partner: Type-C partner device. 827 + * @desc: Description of the USB PD contract. 828 + * 829 + * This routine is a wrapper around usb_power_delivery_register(). It registers 830 + * USB Power Delivery Capabilities for a Type-C partner device. Specifically, 831 + * it sets the Type-C partner device as a parent for the resulting USB Power Delivery object. 832 + * 833 + * Returns handle to struct usb_power_delivery or ERR_PTR. 834 + */ 835 + struct usb_power_delivery * 836 + typec_partner_usb_power_delivery_register(struct typec_partner *partner, 837 + struct usb_power_delivery_desc *desc) 838 + { 839 + return usb_power_delivery_register(&partner->dev, desc); 840 + } 841 + EXPORT_SYMBOL_GPL(typec_partner_usb_power_delivery_register); 842 + 843 + /** 825 844 * typec_register_partner - Register a USB Type-C Partner 826 845 * @port: The USB Type-C Port the partner is connected to 827 846 * @desc: Description of the partner
+2 -3
drivers/usb/typec/hd3ss3220.c
··· 148 148 .max_register = 0x0A, 149 149 }; 150 150 151 - static int hd3ss3220_probe(struct i2c_client *client, 152 - const struct i2c_device_id *id) 151 + static int hd3ss3220_probe(struct i2c_client *client) 153 152 { 154 153 struct typec_capability typec_cap = { }; 155 154 struct hd3ss3220 *hd3ss3220; ··· 263 264 .name = "hd3ss3220", 264 265 .of_match_table = of_match_ptr(dev_ids), 265 266 }, 266 - .probe = hd3ss3220_probe, 267 + .probe_new = hd3ss3220_probe, 267 268 .remove = hd3ss3220_remove, 268 269 }; 269 270
+2 -14
drivers/usb/typec/retimer.c
··· 17 17 #include "class.h" 18 18 #include "retimer.h" 19 19 20 - static bool dev_name_ends_with(struct device *dev, const char *suffix) 21 - { 22 - const char *name = dev_name(dev); 23 - const int name_len = strlen(name); 24 - const int suffix_len = strlen(suffix); 25 - 26 - if (suffix_len > name_len) 27 - return false; 28 - 29 - return strcmp(name + (name_len - suffix_len), suffix) == 0; 30 - } 31 - 32 20 static int retimer_fwnode_match(struct device *dev, const void *fwnode) 33 21 { 34 - return device_match_fwnode(dev, fwnode) && dev_name_ends_with(dev, "-retimer"); 22 + return is_typec_retimer(dev) && device_match_fwnode(dev, fwnode); 35 23 } 36 24 37 25 static void *typec_retimer_match(struct fwnode_handle *fwnode, const char *id, void *data) ··· 85 97 kfree(to_typec_retimer(dev)); 86 98 } 87 99 88 - static const struct device_type typec_retimer_dev_type = { 100 + const struct device_type typec_retimer_dev_type = { 89 101 .name = "typec_retimer", 90 102 .release = typec_retimer_release, 91 103 };
+4
drivers/usb/typec/retimer.h
··· 12 12 13 13 #define to_typec_retimer(_dev_) container_of(_dev_, struct typec_retimer, dev) 14 14 15 + const struct device_type typec_retimer_dev_type; 16 + 17 + #define is_typec_retimer(dev) ((dev)->type == &typec_retimer_dev_type) 18 + 15 19 #endif /* __USB_TYPEC_RETIMER__ */
+2 -3
drivers/usb/typec/tcpm/fusb302.c
··· 1677 1677 return fwnode; 1678 1678 } 1679 1679 1680 - static int fusb302_probe(struct i2c_client *client, 1681 - const struct i2c_device_id *id) 1680 + static int fusb302_probe(struct i2c_client *client) 1682 1681 { 1683 1682 struct fusb302_chip *chip; 1684 1683 struct i2c_adapter *adapter = client->adapter; ··· 1836 1837 .pm = &fusb302_pm_ops, 1837 1838 .of_match_table = of_match_ptr(fusb302_dt_match), 1838 1839 }, 1839 - .probe = fusb302_probe, 1840 + .probe_new = fusb302_probe, 1840 1841 .remove = fusb302_remove, 1841 1842 .id_table = fusb302_i2c_device_id, 1842 1843 };
+6 -4
drivers/usb/typec/tcpm/tcpci.c
··· 794 794 return ERR_PTR(err); 795 795 796 796 tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc); 797 - if (IS_ERR(tcpci->port)) 797 + if (IS_ERR(tcpci->port)) { 798 + fwnode_handle_put(tcpci->tcpc.fwnode); 798 799 return ERR_CAST(tcpci->port); 800 + } 799 801 800 802 return tcpci; 801 803 } ··· 806 804 void tcpci_unregister_port(struct tcpci *tcpci) 807 805 { 808 806 tcpm_unregister_port(tcpci->port); 807 + fwnode_handle_put(tcpci->tcpc.fwnode); 809 808 } 810 809 EXPORT_SYMBOL_GPL(tcpci_unregister_port); 811 810 812 - static int tcpci_probe(struct i2c_client *client, 813 - const struct i2c_device_id *i2c_id) 811 + static int tcpci_probe(struct i2c_client *client) 814 812 { 815 813 struct tcpci_chip *chip; 816 814 int err; ··· 880 878 .name = "tcpci", 881 879 .of_match_table = of_match_ptr(tcpci_of_match), 882 880 }, 883 - .probe = tcpci_probe, 881 + .probe_new = tcpci_probe, 884 882 .remove = tcpci_remove, 885 883 .id_table = tcpci_id, 886 884 };
+2 -2
drivers/usb/typec/tcpm/tcpci_maxim.c
··· 438 438 return -1; 439 439 } 440 440 441 - static int max_tcpci_probe(struct i2c_client *client, const struct i2c_device_id *i2c_id) 441 + static int max_tcpci_probe(struct i2c_client *client) 442 442 { 443 443 int ret; 444 444 struct max_tcpci_chip *chip; ··· 519 519 .name = "maxtcpc", 520 520 .of_match_table = of_match_ptr(max_tcpci_of_match), 521 521 }, 522 - .probe = max_tcpci_probe, 522 + .probe_new = max_tcpci_probe, 523 523 .remove = max_tcpci_remove, 524 524 .id_table = max_tcpci_id, 525 525 };
+2 -3
drivers/usb/typec/tcpm/tcpci_rt1711h.c
··· 327 327 return ret; 328 328 } 329 329 330 - static int rt1711h_probe(struct i2c_client *client, 331 - const struct i2c_device_id *i2c_id) 330 + static int rt1711h_probe(struct i2c_client *client) 332 331 { 333 332 int ret; 334 333 struct rt1711h_chip *chip; ··· 412 413 .name = "rt1711h", 413 414 .of_match_table = of_match_ptr(rt1711h_of_match), 414 415 }, 415 - .probe = rt1711h_probe, 416 + .probe_new = rt1711h_probe, 416 417 .remove = rt1711h_remove, 417 418 .id_table = rt1711h_id, 418 419 };
+12 -8
drivers/usb/typec/tipd/core.c
··· 14 14 #include <linux/regmap.h> 15 15 #include <linux/interrupt.h> 16 16 #include <linux/usb/typec.h> 17 + #include <linux/usb/typec_altmode.h> 17 18 #include <linux/usb/role.h> 18 19 19 20 #include "tps6598x.h" ··· 258 257 typec_set_orientation(tps->port, TYPEC_ORIENTATION_REVERSE); 259 258 else 260 259 typec_set_orientation(tps->port, TYPEC_ORIENTATION_NORMAL); 260 + typec_set_mode(tps->port, TYPEC_STATE_USB); 261 261 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), true); 262 262 263 263 tps->partner = typec_register_partner(tps->port, &desc); ··· 282 280 typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status)); 283 281 typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status)); 284 282 typec_set_orientation(tps->port, TYPEC_ORIENTATION_NONE); 283 + typec_set_mode(tps->port, TYPEC_STATE_SAFE); 285 284 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), false); 286 285 287 286 power_supply_changed(tps->psy); ··· 817 814 818 815 ret = devm_tps6598_psy_register(tps); 819 816 if (ret) 820 - return ret; 817 + goto err_role_put; 821 818 822 819 tps->port = typec_register_port(&client->dev, &typec_cap); 823 820 if (IS_ERR(tps->port)) { 824 821 ret = PTR_ERR(tps->port); 825 822 goto err_role_put; 826 823 } 827 - fwnode_handle_put(fwnode); 828 824 829 825 if (status & TPS_STATUS_PLUG_PRESENT) { 830 826 ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status); 831 827 if (ret < 0) { 832 828 dev_err(tps->dev, "failed to read power status: %d\n", ret); 833 - goto err_role_put; 829 + goto err_unregister_port; 834 830 } 835 831 ret = tps6598x_connect(tps, status); 836 832 if (ret) ··· 840 838 irq_handler, 841 839 IRQF_SHARED | IRQF_ONESHOT, 842 840 dev_name(&client->dev), tps); 843 - if (ret) { 844 - tps6598x_disconnect(tps, 0); 845 - typec_unregister_port(tps->port); 846 - goto err_role_put; 847 - } 841 + if (ret) 842 + goto err_disconnect; 848 843 849 844 i2c_set_clientdata(client, tps); 845 + fwnode_handle_put(fwnode); 850 846 851 847 return 0; 852 848 849 + err_disconnect: 850 + tps6598x_disconnect(tps, 0); 851 + err_unregister_port: 852 + typec_unregister_port(tps->port); 853 853 err_role_put: 854 854 usb_role_switch_put(tps->role_sw); 855 855 err_fwnode_put:
+13 -4
drivers/usb/typec/ucsi/ucsi.c
··· 1270 1270 return ret; 1271 1271 } 1272 1272 1273 - int ucsi_resume(struct ucsi *ucsi) 1273 + static void ucsi_resume_work(struct work_struct *work) 1274 1274 { 1275 + struct ucsi *ucsi = container_of(work, struct ucsi, resume_work); 1275 1276 struct ucsi_connector *con; 1276 1277 u64 command; 1277 1278 int ret; ··· 1280 1279 /* Restore UCSI notification enable mask after system resume */ 1281 1280 command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy; 1282 1281 ret = ucsi_send_command(ucsi, command, NULL, 0); 1283 - if (ret < 0) 1284 - return ret; 1282 + if (ret < 0) { 1283 + dev_err(ucsi->dev, "failed to re-enable notifications (%d)\n", ret); 1284 + return; 1285 + } 1285 1286 1286 1287 for (con = ucsi->connector; con->port; con++) { 1287 1288 mutex_lock(&con->lock); 1288 - ucsi_check_connection(con); 1289 + ucsi_partner_task(con, ucsi_check_connection, 1, 0); 1289 1290 mutex_unlock(&con->lock); 1290 1291 } 1292 + } 1291 1293 1294 + int ucsi_resume(struct ucsi *ucsi) 1295 + { 1296 + queue_work(system_long_wq, &ucsi->resume_work); 1292 1297 return 0; 1293 1298 } 1294 1299 EXPORT_SYMBOL_GPL(ucsi_resume); ··· 1354 1347 if (!ucsi) 1355 1348 return ERR_PTR(-ENOMEM); 1356 1349 1350 + INIT_WORK(&ucsi->resume_work, ucsi_resume_work); 1357 1351 INIT_DELAYED_WORK(&ucsi->work, ucsi_init_work); 1358 1352 mutex_init(&ucsi->ppm_lock); 1359 1353 ucsi->dev = dev; ··· 1409 1401 1410 1402 /* Make sure that we are not in the middle of driver initialization */ 1411 1403 cancel_delayed_work_sync(&ucsi->work); 1404 + cancel_work_sync(&ucsi->resume_work); 1412 1405 1413 1406 /* Disable notifications */ 1414 1407 ucsi->ops->async_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd));
+1
drivers/usb/typec/ucsi/ucsi.h
··· 287 287 struct ucsi_capability cap; 288 288 struct ucsi_connector *connector; 289 289 290 + struct work_struct resume_work; 290 291 struct delayed_work work; 291 292 int work_count; 292 293 #define UCSI_ROLE_SWITCH_RETRY_PER_HZ 10
+2 -3
drivers/usb/typec/ucsi/ucsi_ccg.c
··· 1338 1338 }; 1339 1339 ATTRIBUTE_GROUPS(ucsi_ccg); 1340 1340 1341 - static int ucsi_ccg_probe(struct i2c_client *client, 1342 - const struct i2c_device_id *id) 1341 + static int ucsi_ccg_probe(struct i2c_client *client) 1343 1342 { 1344 1343 struct device *dev = &client->dev; 1345 1344 struct ucsi_ccg *uc; ··· 1481 1482 .dev_groups = ucsi_ccg_groups, 1482 1483 .acpi_match_table = amd_i2c_ucsi_match, 1483 1484 }, 1484 - .probe = ucsi_ccg_probe, 1485 + .probe_new = ucsi_ccg_probe, 1485 1486 .remove = ucsi_ccg_remove, 1486 1487 .id_table = ucsi_ccg_device_id, 1487 1488 };
+2 -2
drivers/usb/typec/ucsi/ucsi_stm32g0.c
··· 626 626 return 0; 627 627 } 628 628 629 - static int ucsi_stm32g0_probe(struct i2c_client *client, const struct i2c_device_id *id) 629 + static int ucsi_stm32g0_probe(struct i2c_client *client) 630 630 { 631 631 struct device *dev = &client->dev; 632 632 struct ucsi_stm32g0 *g0; ··· 763 763 .of_match_table = of_match_ptr(ucsi_stm32g0_typec_of_match), 764 764 .pm = pm_sleep_ptr(&ucsi_stm32g0_pm_ops), 765 765 }, 766 - .probe = ucsi_stm32g0_probe, 766 + .probe_new = ucsi_stm32g0_probe, 767 767 .remove = ucsi_stm32g0_remove, 768 768 .id_table = ucsi_stm32g0_typec_i2c_devid 769 769 };
+1 -1
drivers/usb/typec/wusb3801.c
··· 364 364 /* Initialize the hardware with the devicetree settings. */ 365 365 ret = wusb3801_hw_init(wusb3801); 366 366 if (ret) 367 - return ret; 367 + goto err_put_connector; 368 368 369 369 wusb3801->cap.revision = USB_TYPEC_REV_1_2; 370 370 wusb3801->cap.accessory[0] = TYPEC_ACCESSORY_AUDIO;
-1
drivers/usb/usb-skeleton.c
··· 564 564 int minor = interface->minor; 565 565 566 566 dev = usb_get_intfdata(interface); 567 - usb_set_intfdata(interface, NULL); 568 567 569 568 /* give back our minor */ 570 569 usb_deregister_dev(interface, &skel_class);
+3 -1
drivers/usb/usbip/stub_dev.c
··· 30 30 status = sdev->ud.status; 31 31 spin_unlock_irq(&sdev->ud.lock); 32 32 33 - return snprintf(buf, PAGE_SIZE, "%d\n", status); 33 + return sysfs_emit(buf, "%d\n", status); 34 34 } 35 35 static DEVICE_ATTR_RO(usbip_status); 36 36 ··· 117 117 118 118 } else { 119 119 dev_info(dev, "stub down\n"); 120 + 121 + mutex_lock(&sdev->ud.sysfs_lock); 120 122 121 123 spin_lock_irq(&sdev->ud.lock); 122 124 if (sdev->ud.status != SDEV_ST_USED)
+3 -1
drivers/usb/usbip/vudc_rx.c
··· 149 149 urb_p->urb->status = -EINPROGRESS; 150 150 151 151 /* FIXME: more pipe setup to please usbip_common */ 152 - urb_p->urb->pipe &= ~(3 << 30); 152 + BUILD_BUG_ON_MSG(PIPE_BULK != 3, "PIPE_* doesn't range from 0 to 3"); 153 + 154 + urb_p->urb->pipe &= ~(PIPE_BULK << 30); 153 155 switch (urb_p->ep->type) { 154 156 case USB_ENDPOINT_XFER_BULK: 155 157 urb_p->urb->pipe |= (PIPE_BULK << 30);
+1 -1
drivers/usb/usbip/vudc_sysfs.c
··· 242 242 status = udc->ud.status; 243 243 spin_unlock_irq(&udc->ud.lock); 244 244 245 - return snprintf(out, PAGE_SIZE, "%d\n", status); 245 + return sysfs_emit(out, "%d\n", status); 246 246 } 247 247 static DEVICE_ATTR_RO(usbip_status); 248 248
+12
include/linux/usb.h
··· 265 265 return dev_get_drvdata(&intf->dev); 266 266 } 267 267 268 + /** 269 + * usb_set_intfdata() - associate driver-specific data with the interface 270 + * @intf: the usb interface 271 + * @data: pointer to the device priv structure or %NULL 272 + * 273 + * Drivers should use this function in their probe() to associate their 274 + * driver-specific data with the usb interface. 275 + * 276 + * When disconnecting, the core will take care of setting @intf back to %NULL, 277 + * so no actions are needed on the driver side. The interface should not be set 278 + * to %NULL before all actions completed (e.g. no outsanding URB remaining). 279 + */ 268 280 static inline void usb_set_intfdata(struct usb_interface *intf, void *data) 269 281 { 270 282 dev_set_drvdata(&intf->dev, data);
+3
include/linux/usb/hcd.h
··· 269 269 /* called after entering D0 (etc), before resuming the hub */ 270 270 int (*pci_resume)(struct usb_hcd *hcd, bool hibernated); 271 271 272 + /* called just before hibernate final D3 state, allows host to poweroff parts */ 273 + int (*pci_poweroff_late)(struct usb_hcd *hcd, bool do_wakeup); 274 + 272 275 /* cleanly make HCD stop writing memory and doing I/O */ 273 276 void (*stop) (struct usb_hcd *hcd); 274 277
+4
include/linux/usb/typec.h
··· 23 23 struct device; 24 24 25 25 struct usb_power_delivery; 26 + struct usb_power_delivery_desc; 26 27 27 28 enum typec_port_type { 28 29 TYPEC_PORT_SRC, ··· 327 326 void typec_partner_set_svdm_version(struct typec_partner *partner, 328 327 enum usb_pd_svdm_ver svdm_version); 329 328 int typec_get_negotiated_svdm_version(struct typec_port *port); 329 + 330 + struct usb_power_delivery *typec_partner_usb_power_delivery_register(struct typec_partner *partner, 331 + struct usb_power_delivery_desc *desc); 330 332 331 333 int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd); 332 334 int typec_partner_set_usb_power_delivery(struct typec_partner *partner,
+3
include/uapi/linux/usb/g_uvc.h
··· 21 21 #define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5) 22 22 #define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5) 23 23 24 + #define UVC_STRING_CONTROL_IDX 0 25 + #define UVC_STRING_STREAMING_IDX 1 26 + 24 27 struct uvc_request_data { 25 28 __s32 length; 26 29 __u8 data[60];
+2 -2
include/uapi/linux/usb/video.h
··· 466 466 __u8 bDefaultFrameIndex; 467 467 __u8 bAspectRatioX; 468 468 __u8 bAspectRatioY; 469 - __u8 bmInterfaceFlags; 469 + __u8 bmInterlaceFlags; 470 470 __u8 bCopyProtect; 471 471 } __attribute__((__packed__)); 472 472 ··· 522 522 __u8 bDefaultFrameIndex; 523 523 __u8 bAspectRatioX; 524 524 __u8 bAspectRatioY; 525 - __u8 bmInterfaceFlags; 525 + __u8 bmInterlaceFlags; 526 526 __u8 bCopyProtect; 527 527 } __attribute__((__packed__)); 528 528
+31 -13
tools/usb/ffs-aio-example/simple/device_app/aio_simple.c
··· 25 25 * For more information, please refer to <http://unlicense.org/> 26 26 */ 27 27 28 - #define _BSD_SOURCE /* for endian.h */ 28 + /* $(CROSS_COMPILE)cc -g -o aio_simple aio_simple.c -laio */ 29 + 30 + #define _DEFAULT_SOURCE /* for endian.h */ 29 31 30 32 #include <endian.h> 31 33 #include <errno.h> ··· 51 49 52 50 #define BUF_LEN 8192 53 51 52 + /* 53 + * cpu_to_le16/32 are used when initializing structures, a context where a 54 + * function call is not allowed. To solve this, we code cpu_to_le16/32 in a way 55 + * that allows them to be used when initializing structures. 56 + */ 57 + 58 + #if BYTE_ORDER == __LITTLE_ENDIAN 59 + #define cpu_to_le16(x) (x) 60 + #define cpu_to_le32(x) (x) 61 + #else 62 + #define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)) 63 + #define cpu_to_le32(x) \ 64 + ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \ 65 + (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24)) 66 + #endif 67 + 54 68 /******************** Descriptors and Strings *******************************/ 55 69 56 70 static const struct { ··· 80 62 } __attribute__ ((__packed__)) fs_descs, hs_descs; 81 63 } __attribute__ ((__packed__)) descriptors = { 82 64 .header = { 83 - .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2), 84 - .flags = htole32(FUNCTIONFS_HAS_FS_DESC | 65 + .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2), 66 + .flags = cpu_to_le32(FUNCTIONFS_HAS_FS_DESC | 85 67 FUNCTIONFS_HAS_HS_DESC), 86 - .length = htole32(sizeof(descriptors)), 68 + .length = cpu_to_le32(sizeof(descriptors)), 87 69 }, 88 - .fs_count = htole32(3), 70 + .fs_count = cpu_to_le32(3), 89 71 .fs_descs = { 90 72 .intf = { 91 73 .bLength = sizeof(descriptors.fs_descs.intf), ··· 107 89 .bmAttributes = USB_ENDPOINT_XFER_BULK, 108 90 }, 109 91 }, 110 - .hs_count = htole32(3), 92 + .hs_count = cpu_to_le32(3), 111 93 .hs_descs = { 112 94 .intf = { 113 95 .bLength = sizeof(descriptors.hs_descs.intf), ··· 121 103 .bDescriptorType = USB_DT_ENDPOINT, 122 104 .bEndpointAddress = 1 | USB_DIR_IN, 123 105 .bmAttributes = USB_ENDPOINT_XFER_BULK, 124 - .wMaxPacketSize = htole16(512), 106 + .wMaxPacketSize = cpu_to_le16(512), 125 107 }, 126 108 .bulk_source = { 127 109 .bLength = sizeof(descriptors.hs_descs.bulk_source), 128 110 .bDescriptorType = USB_DT_ENDPOINT, 129 111 .bEndpointAddress = 2 | USB_DIR_OUT, 130 112 .bmAttributes = USB_ENDPOINT_XFER_BULK, 131 - .wMaxPacketSize = htole16(512), 113 + .wMaxPacketSize = cpu_to_le16(512), 132 114 }, 133 115 }, 134 116 }; ··· 143 125 } __attribute__ ((__packed__)) lang0; 144 126 } __attribute__ ((__packed__)) strings = { 145 127 .header = { 146 - .magic = htole32(FUNCTIONFS_STRINGS_MAGIC), 147 - .length = htole32(sizeof(strings)), 148 - .str_count = htole32(1), 149 - .lang_count = htole32(1), 128 + .magic = cpu_to_le32(FUNCTIONFS_STRINGS_MAGIC), 129 + .length = cpu_to_le32(sizeof(strings)), 130 + .str_count = cpu_to_le32(1), 131 + .lang_count = cpu_to_le32(1), 150 132 }, 151 133 .lang0 = { 152 - htole16(0x0409), /* en-us */ 134 + cpu_to_le16(0x0409), /* en-us */ 153 135 STR_INTERFACE, 154 136 }, 155 137 };