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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull USB fixes from Greg KH:
"Here are a bunch of small USB fixes for reported problems and
regressions for 6.9-rc2. Included in here are:

- deadlock fixes for long-suffering issues

- USB phy driver revert for reported problem

- typec fixes for reported problems

- duplicate id in dwc3 dropped

- dwc2 driver fixes

- udc driver warning fix

- cdc-wdm race bugfix

- other tiny USB bugfixes

All of these have been in linux-next this past week with no reported
issues"

* tag 'usb-6.9-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (26 commits)
USB: core: Fix deadlock in port "disable" sysfs attribute
USB: core: Add hub_get() and hub_put() routines
usb: typec: ucsi: Check capabilities before cable and identity discovery
usb: typec: ucsi: Clear UCSI_CCI_RESET_COMPLETE before reset
usb: typec: ucsi_acpi: Refactor and fix DELL quirk
usb: typec: ucsi: Ack unsupported commands
usb: typec: ucsi: Check for notifications after init
usb: typec: ucsi: Clear EVENT_PENDING under PPM lock
usb: typec: Return size of buffer if pd_set operation succeeds
usb: udc: remove warning when queue disabled ep
usb: dwc3: pci: Drop duplicate ID
usb: dwc3: Properly set system wakeup
Revert "usb: phy: generic: Get the vbus supply"
usb: cdc-wdm: close race between read and workqueue
usb: dwc2: gadget: LPM flow fix
usb: dwc2: gadget: Fix exiting from clock gating
usb: dwc2: host: Fix ISOC flow in DDMA mode
usb: dwc2: host: Fix remote wakeup from hibernation
usb: dwc2: host: Fix hibernation flow
USB: core: Fix deadlock in usb_deauthorize_interface()
...

+374 -158
+5 -1
drivers/usb/class/cdc-wdm.c
··· 485 485 static int service_outstanding_interrupt(struct wdm_device *desc) 486 486 { 487 487 int rv = 0; 488 + int used; 488 489 489 490 /* submit read urb only if the device is waiting for it */ 490 491 if (!desc->resp_count || !--desc->resp_count) ··· 500 499 goto out; 501 500 } 502 501 503 - set_bit(WDM_RESPONDING, &desc->flags); 502 + used = test_and_set_bit(WDM_RESPONDING, &desc->flags); 503 + if (used) 504 + goto out; 505 + 504 506 spin_unlock_irq(&desc->iuspin); 505 507 rv = usb_submit_urb(desc->response, GFP_KERNEL); 506 508 spin_lock_irq(&desc->iuspin);
+16 -7
drivers/usb/core/hub.c
··· 130 130 #define HUB_DEBOUNCE_STEP 25 131 131 #define HUB_DEBOUNCE_STABLE 100 132 132 133 - static void hub_release(struct kref *kref); 134 133 static int usb_reset_and_verify_device(struct usb_device *udev); 135 134 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state); 136 135 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, ··· 719 720 */ 720 721 intf = to_usb_interface(hub->intfdev); 721 722 usb_autopm_get_interface_no_resume(intf); 722 - kref_get(&hub->kref); 723 + hub_get(hub); 723 724 724 725 if (queue_work(hub_wq, &hub->events)) 725 726 return; 726 727 727 728 /* the work has already been scheduled */ 728 729 usb_autopm_put_interface_async(intf); 729 - kref_put(&hub->kref, hub_release); 730 + hub_put(hub); 730 731 } 731 732 732 733 void usb_kick_hub_wq(struct usb_device *hdev) ··· 1094 1095 goto init2; 1095 1096 goto init3; 1096 1097 } 1097 - kref_get(&hub->kref); 1098 + hub_get(hub); 1098 1099 1099 1100 /* The superspeed hub except for root hub has to use Hub Depth 1100 1101 * value as an offset into the route string to locate the bits ··· 1342 1343 device_unlock(&hdev->dev); 1343 1344 } 1344 1345 1345 - kref_put(&hub->kref, hub_release); 1346 + hub_put(hub); 1346 1347 } 1347 1348 1348 1349 /* Implement the continuations for the delays above */ ··· 1758 1759 kfree(hub); 1759 1760 } 1760 1761 1762 + void hub_get(struct usb_hub *hub) 1763 + { 1764 + kref_get(&hub->kref); 1765 + } 1766 + 1767 + void hub_put(struct usb_hub *hub) 1768 + { 1769 + kref_put(&hub->kref, hub_release); 1770 + } 1771 + 1761 1772 static unsigned highspeed_hubs; 1762 1773 1763 1774 static void hub_disconnect(struct usb_interface *intf) ··· 1816 1807 1817 1808 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs); 1818 1809 1819 - kref_put(&hub->kref, hub_release); 1810 + hub_put(hub); 1820 1811 } 1821 1812 1822 1813 static bool hub_descriptor_is_sane(struct usb_host_interface *desc) ··· 5943 5934 5944 5935 /* Balance the stuff in kick_hub_wq() and allow autosuspend */ 5945 5936 usb_autopm_put_interface(intf); 5946 - kref_put(&hub->kref, hub_release); 5937 + hub_put(hub); 5947 5938 5948 5939 kcov_remote_stop(); 5949 5940 }
+2
drivers/usb/core/hub.h
··· 129 129 extern int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, 130 130 int port1, bool set); 131 131 extern struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev); 132 + extern void hub_get(struct usb_hub *hub); 133 + extern void hub_put(struct usb_hub *hub); 132 134 extern int hub_port_debounce(struct usb_hub *hub, int port1, 133 135 bool must_be_connected); 134 136 extern int usb_clear_port_feature(struct usb_device *hdev,
+34 -4
drivers/usb/core/port.c
··· 56 56 u16 portstatus, unused; 57 57 bool disabled; 58 58 int rc; 59 + struct kernfs_node *kn; 59 60 61 + hub_get(hub); 60 62 rc = usb_autopm_get_interface(intf); 61 63 if (rc < 0) 62 - return rc; 64 + goto out_hub_get; 63 65 66 + /* 67 + * Prevent deadlock if another process is concurrently 68 + * trying to unregister hdev. 69 + */ 70 + kn = sysfs_break_active_protection(&dev->kobj, &attr->attr); 71 + if (!kn) { 72 + rc = -ENODEV; 73 + goto out_autopm; 74 + } 64 75 usb_lock_device(hdev); 65 76 if (hub->disconnected) { 66 77 rc = -ENODEV; ··· 81 70 usb_hub_port_status(hub, port1, &portstatus, &unused); 82 71 disabled = !usb_port_is_power_on(hub, portstatus); 83 72 84 - out_hdev_lock: 73 + out_hdev_lock: 85 74 usb_unlock_device(hdev); 75 + sysfs_unbreak_active_protection(kn); 76 + out_autopm: 86 77 usb_autopm_put_interface(intf); 78 + out_hub_get: 79 + hub_put(hub); 87 80 88 81 if (rc) 89 82 return rc; ··· 105 90 int port1 = port_dev->portnum; 106 91 bool disabled; 107 92 int rc; 93 + struct kernfs_node *kn; 108 94 109 95 rc = kstrtobool(buf, &disabled); 110 96 if (rc) 111 97 return rc; 112 98 99 + hub_get(hub); 113 100 rc = usb_autopm_get_interface(intf); 114 101 if (rc < 0) 115 - return rc; 102 + goto out_hub_get; 116 103 104 + /* 105 + * Prevent deadlock if another process is concurrently 106 + * trying to unregister hdev. 107 + */ 108 + kn = sysfs_break_active_protection(&dev->kobj, &attr->attr); 109 + if (!kn) { 110 + rc = -ENODEV; 111 + goto out_autopm; 112 + } 117 113 usb_lock_device(hdev); 118 114 if (hub->disconnected) { 119 115 rc = -ENODEV; ··· 145 119 if (!rc) 146 120 rc = count; 147 121 148 - out_hdev_lock: 122 + out_hdev_lock: 149 123 usb_unlock_device(hdev); 124 + sysfs_unbreak_active_protection(kn); 125 + out_autopm: 150 126 usb_autopm_put_interface(intf); 127 + out_hub_get: 128 + hub_put(hub); 151 129 152 130 return rc; 153 131 }
+13 -3
drivers/usb/core/sysfs.c
··· 1217 1217 { 1218 1218 struct usb_interface *intf = to_usb_interface(dev); 1219 1219 bool val; 1220 + struct kernfs_node *kn; 1220 1221 1221 1222 if (kstrtobool(buf, &val) != 0) 1222 1223 return -EINVAL; 1223 1224 1224 - if (val) 1225 + if (val) { 1225 1226 usb_authorize_interface(intf); 1226 - else 1227 - usb_deauthorize_interface(intf); 1227 + } else { 1228 + /* 1229 + * Prevent deadlock if another process is concurrently 1230 + * trying to unregister intf. 1231 + */ 1232 + kn = sysfs_break_active_protection(&dev->kobj, &attr->attr); 1233 + if (kn) { 1234 + usb_deauthorize_interface(intf); 1235 + sysfs_unbreak_active_protection(kn); 1236 + } 1237 + } 1228 1238 1229 1239 return count; 1230 1240 }
+14
drivers/usb/dwc2/core.h
··· 729 729 * struct dwc2_hregs_backup - Holds host registers state before 730 730 * entering partial power down 731 731 * @hcfg: Backup of HCFG register 732 + * @hflbaddr: Backup of HFLBADDR register 732 733 * @haintmsk: Backup of HAINTMSK register 734 + * @hcchar: Backup of HCCHAR register 735 + * @hcsplt: Backup of HCSPLT register 733 736 * @hcintmsk: Backup of HCINTMSK register 737 + * @hctsiz: Backup of HCTSIZ register 738 + * @hdma: Backup of HCDMA register 739 + * @hcdmab: Backup of HCDMAB register 734 740 * @hprt0: Backup of HPTR0 register 735 741 * @hfir: Backup of HFIR register 736 742 * @hptxfsiz: Backup of HPTXFSIZ register ··· 744 738 */ 745 739 struct dwc2_hregs_backup { 746 740 u32 hcfg; 741 + u32 hflbaddr; 747 742 u32 haintmsk; 743 + u32 hcchar[MAX_EPS_CHANNELS]; 744 + u32 hcsplt[MAX_EPS_CHANNELS]; 748 745 u32 hcintmsk[MAX_EPS_CHANNELS]; 746 + u32 hctsiz[MAX_EPS_CHANNELS]; 747 + u32 hcidma[MAX_EPS_CHANNELS]; 748 + u32 hcidmab[MAX_EPS_CHANNELS]; 749 749 u32 hprt0; 750 750 u32 hfir; 751 751 u32 hptxfsiz; ··· 1098 1086 bool needs_byte_swap; 1099 1087 1100 1088 /* DWC OTG HW Release versions */ 1089 + #define DWC2_CORE_REV_4_30a 0x4f54430a 1101 1090 #define DWC2_CORE_REV_2_71a 0x4f54271a 1102 1091 #define DWC2_CORE_REV_2_72a 0x4f54272a 1103 1092 #define DWC2_CORE_REV_2_80a 0x4f54280a ··· 1336 1323 int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg); 1337 1324 1338 1325 void dwc2_enable_acg(struct dwc2_hsotg *hsotg); 1326 + void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg, bool remotewakeup); 1339 1327 1340 1328 /* This function should be called on every hardware interrupt. */ 1341 1329 irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
+48 -24
drivers/usb/dwc2/core_intr.c
··· 297 297 298 298 /* Exit gadget mode clock gating. */ 299 299 if (hsotg->params.power_down == 300 - DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended) 300 + DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended && 301 + !hsotg->params.no_clock_gating) 301 302 dwc2_gadget_exit_clock_gating(hsotg, 0); 302 303 } 303 304 ··· 323 322 * @hsotg: Programming view of DWC_otg controller 324 323 * 325 324 */ 326 - static void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg) 325 + void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg, bool remotewakeup) 327 326 { 328 327 u32 glpmcfg; 329 - u32 i = 0; 328 + u32 pcgctl; 329 + u32 dctl; 330 330 331 331 if (hsotg->lx_state != DWC2_L1) { 332 332 dev_err(hsotg->dev, "Core isn't in DWC2_L1 state\n"); ··· 336 334 337 335 glpmcfg = dwc2_readl(hsotg, GLPMCFG); 338 336 if (dwc2_is_device_mode(hsotg)) { 339 - dev_dbg(hsotg->dev, "Exit from L1 state\n"); 337 + dev_dbg(hsotg->dev, "Exit from L1 state, remotewakeup=%d\n", remotewakeup); 340 338 glpmcfg &= ~GLPMCFG_ENBLSLPM; 341 - glpmcfg &= ~GLPMCFG_HIRD_THRES_EN; 339 + glpmcfg &= ~GLPMCFG_HIRD_THRES_MASK; 342 340 dwc2_writel(hsotg, glpmcfg, GLPMCFG); 343 341 344 - do { 345 - glpmcfg = dwc2_readl(hsotg, GLPMCFG); 342 + pcgctl = dwc2_readl(hsotg, PCGCTL); 343 + pcgctl &= ~PCGCTL_ENBL_SLEEP_GATING; 344 + dwc2_writel(hsotg, pcgctl, PCGCTL); 346 345 347 - if (!(glpmcfg & (GLPMCFG_COREL1RES_MASK | 348 - GLPMCFG_L1RESUMEOK | GLPMCFG_SLPSTS))) 349 - break; 346 + glpmcfg = dwc2_readl(hsotg, GLPMCFG); 347 + if (glpmcfg & GLPMCFG_ENBESL) { 348 + glpmcfg |= GLPMCFG_RSTRSLPSTS; 349 + dwc2_writel(hsotg, glpmcfg, GLPMCFG); 350 + } 350 351 351 - udelay(1); 352 - } while (++i < 200); 352 + if (remotewakeup) { 353 + if (dwc2_hsotg_wait_bit_set(hsotg, GLPMCFG, GLPMCFG_L1RESUMEOK, 1000)) { 354 + dev_warn(hsotg->dev, "%s: timeout GLPMCFG_L1RESUMEOK\n", __func__); 355 + goto fail; 356 + return; 357 + } 353 358 354 - if (i == 200) { 355 - dev_err(hsotg->dev, "Failed to exit L1 sleep state in 200us.\n"); 359 + dctl = dwc2_readl(hsotg, DCTL); 360 + dctl |= DCTL_RMTWKUPSIG; 361 + dwc2_writel(hsotg, dctl, DCTL); 362 + 363 + if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, GINTSTS_WKUPINT, 1000)) { 364 + dev_warn(hsotg->dev, "%s: timeout GINTSTS_WKUPINT\n", __func__); 365 + goto fail; 366 + return; 367 + } 368 + } 369 + 370 + glpmcfg = dwc2_readl(hsotg, GLPMCFG); 371 + if (glpmcfg & GLPMCFG_COREL1RES_MASK || glpmcfg & GLPMCFG_SLPSTS || 372 + glpmcfg & GLPMCFG_L1RESUMEOK) { 373 + goto fail; 356 374 return; 357 375 } 358 - dwc2_gadget_init_lpm(hsotg); 376 + 377 + /* Inform gadget to exit from L1 */ 378 + call_gadget(hsotg, resume); 379 + /* Change to L0 state */ 380 + hsotg->lx_state = DWC2_L0; 381 + hsotg->bus_suspended = false; 382 + fail: dwc2_gadget_init_lpm(hsotg); 359 383 } else { 360 384 /* TODO */ 361 385 dev_err(hsotg->dev, "Host side LPM is not supported.\n"); 362 386 return; 363 387 } 364 - 365 - /* Change to L0 state */ 366 - hsotg->lx_state = DWC2_L0; 367 - 368 - /* Inform gadget to exit from L1 */ 369 - call_gadget(hsotg, resume); 370 388 } 371 389 372 390 /* ··· 407 385 dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state); 408 386 409 387 if (hsotg->lx_state == DWC2_L1) { 410 - dwc2_wakeup_from_lpm_l1(hsotg); 388 + dwc2_wakeup_from_lpm_l1(hsotg, false); 411 389 return; 412 390 } 413 391 ··· 430 408 431 409 /* Exit gadget mode clock gating. */ 432 410 if (hsotg->params.power_down == 433 - DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended) 411 + DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended && 412 + !hsotg->params.no_clock_gating) 434 413 dwc2_gadget_exit_clock_gating(hsotg, 0); 435 414 } else { 436 415 /* Change to L0 state */ ··· 448 425 } 449 426 450 427 if (hsotg->params.power_down == 451 - DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended) 428 + DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended && 429 + !hsotg->params.no_clock_gating) 452 430 dwc2_host_exit_clock_gating(hsotg, 1); 453 431 454 432 /*
+10
drivers/usb/dwc2/gadget.c
··· 1415 1415 ep->name, req, req->length, req->buf, req->no_interrupt, 1416 1416 req->zero, req->short_not_ok); 1417 1417 1418 + if (hs->lx_state == DWC2_L1) { 1419 + dwc2_wakeup_from_lpm_l1(hs, true); 1420 + } 1421 + 1418 1422 /* Prevent new request submission when controller is suspended */ 1419 1423 if (hs->lx_state != DWC2_L0) { 1420 1424 dev_dbg(hs->dev, "%s: submit request only in active state\n", ··· 3730 3726 /* This event must be used only if controller is suspended */ 3731 3727 if (hsotg->in_ppd && hsotg->lx_state == DWC2_L2) 3732 3728 dwc2_exit_partial_power_down(hsotg, 0, true); 3729 + 3730 + /* Exit gadget mode clock gating. */ 3731 + if (hsotg->params.power_down == 3732 + DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended && 3733 + !hsotg->params.no_clock_gating) 3734 + dwc2_gadget_exit_clock_gating(hsotg, 0); 3733 3735 3734 3736 hsotg->lx_state = DWC2_L0; 3735 3737 }
+40 -9
drivers/usb/dwc2/hcd.c
··· 2701 2701 hsotg->available_host_channels--; 2702 2702 } 2703 2703 qh = list_entry(qh_ptr, struct dwc2_qh, qh_list_entry); 2704 - if (dwc2_assign_and_init_hc(hsotg, qh)) 2704 + if (dwc2_assign_and_init_hc(hsotg, qh)) { 2705 + if (hsotg->params.uframe_sched) 2706 + hsotg->available_host_channels++; 2705 2707 break; 2708 + } 2706 2709 2707 2710 /* 2708 2711 * Move the QH from the periodic ready schedule to the ··· 2738 2735 hsotg->available_host_channels--; 2739 2736 } 2740 2737 2741 - if (dwc2_assign_and_init_hc(hsotg, qh)) 2738 + if (dwc2_assign_and_init_hc(hsotg, qh)) { 2739 + if (hsotg->params.uframe_sched) 2740 + hsotg->available_host_channels++; 2742 2741 break; 2742 + } 2743 2743 2744 2744 /* 2745 2745 * Move the QH from the non-periodic inactive schedule to the ··· 4149 4143 urb->actual_length); 4150 4144 4151 4145 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { 4146 + if (!hsotg->params.dma_desc_enable) 4147 + urb->start_frame = qtd->qh->start_active_frame; 4152 4148 urb->error_count = dwc2_hcd_urb_get_error_count(qtd->urb); 4153 4149 for (i = 0; i < urb->number_of_packets; ++i) { 4154 4150 urb->iso_frame_desc[i].actual_length = ··· 4657 4649 } 4658 4650 4659 4651 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE && 4660 - hsotg->bus_suspended) { 4652 + hsotg->bus_suspended && !hsotg->params.no_clock_gating) { 4661 4653 if (dwc2_is_device_mode(hsotg)) 4662 4654 dwc2_gadget_exit_clock_gating(hsotg, 0); 4663 4655 else ··· 5414 5406 /* Backup Host regs */ 5415 5407 hr = &hsotg->hr_backup; 5416 5408 hr->hcfg = dwc2_readl(hsotg, HCFG); 5409 + hr->hflbaddr = dwc2_readl(hsotg, HFLBADDR); 5417 5410 hr->haintmsk = dwc2_readl(hsotg, HAINTMSK); 5418 - for (i = 0; i < hsotg->params.host_channels; ++i) 5411 + for (i = 0; i < hsotg->params.host_channels; ++i) { 5412 + hr->hcchar[i] = dwc2_readl(hsotg, HCCHAR(i)); 5413 + hr->hcsplt[i] = dwc2_readl(hsotg, HCSPLT(i)); 5419 5414 hr->hcintmsk[i] = dwc2_readl(hsotg, HCINTMSK(i)); 5415 + hr->hctsiz[i] = dwc2_readl(hsotg, HCTSIZ(i)); 5416 + hr->hcidma[i] = dwc2_readl(hsotg, HCDMA(i)); 5417 + hr->hcidmab[i] = dwc2_readl(hsotg, HCDMAB(i)); 5418 + } 5420 5419 5421 5420 hr->hprt0 = dwc2_read_hprt0(hsotg); 5422 5421 hr->hfir = dwc2_readl(hsotg, HFIR); ··· 5457 5442 hr->valid = false; 5458 5443 5459 5444 dwc2_writel(hsotg, hr->hcfg, HCFG); 5445 + dwc2_writel(hsotg, hr->hflbaddr, HFLBADDR); 5460 5446 dwc2_writel(hsotg, hr->haintmsk, HAINTMSK); 5461 5447 5462 - for (i = 0; i < hsotg->params.host_channels; ++i) 5448 + for (i = 0; i < hsotg->params.host_channels; ++i) { 5449 + dwc2_writel(hsotg, hr->hcchar[i], HCCHAR(i)); 5450 + dwc2_writel(hsotg, hr->hcsplt[i], HCSPLT(i)); 5463 5451 dwc2_writel(hsotg, hr->hcintmsk[i], HCINTMSK(i)); 5452 + dwc2_writel(hsotg, hr->hctsiz[i], HCTSIZ(i)); 5453 + dwc2_writel(hsotg, hr->hcidma[i], HCDMA(i)); 5454 + dwc2_writel(hsotg, hr->hcidmab[i], HCDMAB(i)); 5455 + } 5464 5456 5465 5457 dwc2_writel(hsotg, hr->hprt0, HPRT0); 5466 5458 dwc2_writel(hsotg, hr->hfir, HFIR); ··· 5632 5610 dwc2_writel(hsotg, hr->hcfg, HCFG); 5633 5611 5634 5612 /* De-assert Wakeup Logic */ 5635 - gpwrdn = dwc2_readl(hsotg, GPWRDN); 5636 - gpwrdn &= ~GPWRDN_PMUACTV; 5637 - dwc2_writel(hsotg, gpwrdn, GPWRDN); 5638 - udelay(10); 5613 + if (!(rem_wakeup && hsotg->hw_params.snpsid >= DWC2_CORE_REV_4_30a)) { 5614 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5615 + gpwrdn &= ~GPWRDN_PMUACTV; 5616 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5617 + udelay(10); 5618 + } 5639 5619 5640 5620 hprt0 = hr->hprt0; 5641 5621 hprt0 |= HPRT0_PWR; ··· 5662 5638 hprt0 |= HPRT0_RES; 5663 5639 dwc2_writel(hsotg, hprt0, HPRT0); 5664 5640 5641 + /* De-assert Wakeup Logic */ 5642 + if ((rem_wakeup && hsotg->hw_params.snpsid >= DWC2_CORE_REV_4_30a)) { 5643 + gpwrdn = dwc2_readl(hsotg, GPWRDN); 5644 + gpwrdn &= ~GPWRDN_PMUACTV; 5645 + dwc2_writel(hsotg, gpwrdn, GPWRDN); 5646 + udelay(10); 5647 + } 5665 5648 /* Wait for Resume time and then program HPRT again */ 5666 5649 mdelay(100); 5667 5650 hprt0 &= ~HPRT0_RES;
+11 -6
drivers/usb/dwc2/hcd_ddma.c
··· 559 559 idx = qh->td_last; 560 560 inc = qh->host_interval; 561 561 hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg); 562 - cur_idx = dwc2_frame_list_idx(hsotg->frame_number); 562 + cur_idx = idx; 563 563 next_idx = dwc2_desclist_idx_inc(qh->td_last, inc, qh->dev_speed); 564 564 565 565 /* ··· 866 866 { 867 867 struct dwc2_dma_desc *dma_desc; 868 868 struct dwc2_hcd_iso_packet_desc *frame_desc; 869 + u16 frame_desc_idx; 870 + struct urb *usb_urb = qtd->urb->priv; 869 871 u16 remain = 0; 870 872 int rc = 0; 871 873 ··· 880 878 DMA_FROM_DEVICE); 881 879 882 880 dma_desc = &qh->desc_list[idx]; 881 + frame_desc_idx = (idx - qtd->isoc_td_first) & (usb_urb->number_of_packets - 1); 883 882 884 - frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last]; 883 + frame_desc = &qtd->urb->iso_descs[frame_desc_idx]; 884 + if (idx == qtd->isoc_td_first) 885 + usb_urb->start_frame = dwc2_hcd_get_frame_number(hsotg); 885 886 dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset); 886 887 if (chan->ep_is_in) 887 888 remain = (dma_desc->status & HOST_DMA_ISOC_NBYTES_MASK) >> ··· 905 900 frame_desc->status = 0; 906 901 } 907 902 908 - if (++qtd->isoc_frame_index == qtd->urb->packet_count) { 903 + if (++qtd->isoc_frame_index == usb_urb->number_of_packets) { 909 904 /* 910 905 * urb->status is not used for isoc transfers here. The 911 906 * individual frame_desc status are used instead. ··· 1010 1005 return; 1011 1006 idx = dwc2_desclist_idx_inc(idx, qh->host_interval, 1012 1007 chan->speed); 1013 - if (!rc) 1008 + if (rc == 0) 1014 1009 continue; 1015 1010 1016 - if (rc == DWC2_CMPL_DONE) 1017 - break; 1011 + if (rc == DWC2_CMPL_DONE || rc == DWC2_CMPL_STOP) 1012 + goto stop_scan; 1018 1013 1019 1014 /* rc == DWC2_CMPL_STOP */ 1020 1015
+1 -1
drivers/usb/dwc2/hw.h
··· 698 698 #define TXSTS_QTOP_TOKEN_MASK (0x3 << 25) 699 699 #define TXSTS_QTOP_TOKEN_SHIFT 25 700 700 #define TXSTS_QTOP_TERMINATE BIT(24) 701 - #define TXSTS_QSPCAVAIL_MASK (0xff << 16) 701 + #define TXSTS_QSPCAVAIL_MASK (0x7f << 16) 702 702 #define TXSTS_QSPCAVAIL_SHIFT 16 703 703 #define TXSTS_FSPCAVAIL_MASK (0xffff << 0) 704 704 #define TXSTS_FSPCAVAIL_SHIFT 0
+1 -1
drivers/usb/dwc2/platform.c
··· 331 331 332 332 /* Exit clock gating when driver is removed. */ 333 333 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE && 334 - hsotg->bus_suspended) { 334 + hsotg->bus_suspended && !hsotg->params.no_clock_gating) { 335 335 if (dwc2_is_device_mode(hsotg)) 336 336 dwc2_gadget_exit_clock_gating(hsotg, 0); 337 337 else
+2
drivers/usb/dwc3/core.c
··· 1519 1519 else 1520 1520 dwc->sysdev = dwc->dev; 1521 1521 1522 + dwc->sys_wakeup = device_may_wakeup(dwc->sysdev); 1523 + 1522 1524 ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name); 1523 1525 if (ret >= 0) { 1524 1526 dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
+2
drivers/usb/dwc3/core.h
··· 1133 1133 * 3 - Reserved 1134 1134 * @dis_metastability_quirk: set to disable metastability quirk. 1135 1135 * @dis_split_quirk: set to disable split boundary. 1136 + * @sys_wakeup: set if the device may do system wakeup. 1136 1137 * @wakeup_configured: set if the device is configured for remote wakeup. 1137 1138 * @suspended: set to track suspend event due to U3/L2. 1138 1139 * @imod_interval: set the interrupt moderation interval in 250ns ··· 1358 1357 1359 1358 unsigned dis_split_quirk:1; 1360 1359 unsigned async_callbacks:1; 1360 + unsigned sys_wakeup:1; 1361 1361 unsigned wakeup_configured:1; 1362 1362 unsigned suspended:1; 1363 1363
-2
drivers/usb/dwc3/dwc3-pci.c
··· 51 51 #define PCI_DEVICE_ID_INTEL_MTLP 0x7ec1 52 52 #define PCI_DEVICE_ID_INTEL_MTLS 0x7f6f 53 53 #define PCI_DEVICE_ID_INTEL_MTL 0x7e7e 54 - #define PCI_DEVICE_ID_INTEL_ARLH 0x7ec1 55 54 #define PCI_DEVICE_ID_INTEL_ARLH_PCH 0x777e 56 55 #define PCI_DEVICE_ID_INTEL_TGL 0x9a15 57 56 #define PCI_DEVICE_ID_AMD_MR 0x163a ··· 422 423 { PCI_DEVICE_DATA(INTEL, MTLP, &dwc3_pci_intel_swnode) }, 423 424 { PCI_DEVICE_DATA(INTEL, MTL, &dwc3_pci_intel_swnode) }, 424 425 { PCI_DEVICE_DATA(INTEL, MTLS, &dwc3_pci_intel_swnode) }, 425 - { PCI_DEVICE_DATA(INTEL, ARLH, &dwc3_pci_intel_swnode) }, 426 426 { PCI_DEVICE_DATA(INTEL, ARLH_PCH, &dwc3_pci_intel_swnode) }, 427 427 { PCI_DEVICE_DATA(INTEL, TGL, &dwc3_pci_intel_swnode) }, 428 428
+10
drivers/usb/dwc3/gadget.c
··· 2955 2955 dwc->gadget_driver = driver; 2956 2956 spin_unlock_irqrestore(&dwc->lock, flags); 2957 2957 2958 + if (dwc->sys_wakeup) 2959 + device_wakeup_enable(dwc->sysdev); 2960 + 2958 2961 return 0; 2959 2962 } 2960 2963 ··· 2972 2969 { 2973 2970 struct dwc3 *dwc = gadget_to_dwc(g); 2974 2971 unsigned long flags; 2972 + 2973 + if (dwc->sys_wakeup) 2974 + device_wakeup_disable(dwc->sysdev); 2975 2975 2976 2976 spin_lock_irqsave(&dwc->lock, flags); 2977 2977 dwc->gadget_driver = NULL; ··· 4656 4650 dwc3_gadget_set_ssp_rate(dwc->gadget, dwc->max_ssp_rate); 4657 4651 else 4658 4652 dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); 4653 + 4654 + /* No system wakeup if no gadget driver bound */ 4655 + if (dwc->sys_wakeup) 4656 + device_wakeup_disable(dwc->sysdev); 4659 4657 4660 4658 return 0; 4661 4659
+11
drivers/usb/dwc3/host.c
··· 173 173 goto err; 174 174 } 175 175 176 + if (dwc->sys_wakeup) { 177 + /* Restore wakeup setting if switched from device */ 178 + device_wakeup_enable(dwc->sysdev); 179 + 180 + /* Pass on wakeup setting to the new xhci platform device */ 181 + device_init_wakeup(&xhci->dev, true); 182 + } 183 + 176 184 return 0; 177 185 err: 178 186 platform_device_put(xhci); ··· 189 181 190 182 void dwc3_host_exit(struct dwc3 *dwc) 191 183 { 184 + if (dwc->sys_wakeup) 185 + device_init_wakeup(&dwc->xhci->dev, false); 186 + 192 187 platform_device_unregister(dwc->xhci); 193 188 dwc->xhci = NULL; 194 189 }
+3 -1
drivers/usb/gadget/udc/core.c
··· 292 292 { 293 293 int ret = 0; 294 294 295 - if (WARN_ON_ONCE(!ep->enabled && ep->address)) { 295 + if (!ep->enabled && ep->address) { 296 + pr_debug("USB gadget: queue request to disabled ep 0x%x (%s)\n", 297 + ep->address, ep->name); 296 298 ret = -ESHUTDOWN; 297 299 goto out; 298 300 }
+9 -13
drivers/usb/misc/usb-ljca.c
··· 518 518 int ret; 519 519 520 520 client = kzalloc(sizeof *client, GFP_KERNEL); 521 - if (!client) 521 + if (!client) { 522 + kfree(data); 522 523 return -ENOMEM; 524 + } 523 525 524 526 client->type = type; 525 527 client->id = id; ··· 537 535 auxdev->dev.release = ljca_auxdev_release; 538 536 539 537 ret = auxiliary_device_init(auxdev); 540 - if (ret) 538 + if (ret) { 539 + kfree(data); 541 540 goto err_free; 541 + } 542 542 543 543 ljca_auxdev_acpi_bind(adap, auxdev, adr, id); 544 544 ··· 594 590 valid_pin[i] = get_unaligned_le32(&desc->bank_desc[i].valid_pins); 595 591 bitmap_from_arr32(gpio_info->valid_pin_map, valid_pin, gpio_num); 596 592 597 - ret = ljca_new_client_device(adap, LJCA_CLIENT_GPIO, 0, "ljca-gpio", 593 + return ljca_new_client_device(adap, LJCA_CLIENT_GPIO, 0, "ljca-gpio", 598 594 gpio_info, LJCA_GPIO_ACPI_ADR); 599 - if (ret) 600 - kfree(gpio_info); 601 - 602 - return ret; 603 595 } 604 596 605 597 static int ljca_enumerate_i2c(struct ljca_adapter *adap) ··· 629 629 ret = ljca_new_client_device(adap, LJCA_CLIENT_I2C, i, 630 630 "ljca-i2c", i2c_info, 631 631 LJCA_I2C1_ACPI_ADR + i); 632 - if (ret) { 633 - kfree(i2c_info); 632 + if (ret) 634 633 return ret; 635 - } 636 634 } 637 635 638 636 return 0; ··· 667 669 ret = ljca_new_client_device(adap, LJCA_CLIENT_SPI, i, 668 670 "ljca-spi", spi_info, 669 671 LJCA_SPI1_ACPI_ADR + i); 670 - if (ret) { 671 - kfree(spi_info); 672 + if (ret) 672 673 return ret; 673 - } 674 674 } 675 675 676 676 return 0;
-7
drivers/usb/phy/phy-generic.c
··· 262 262 return dev_err_probe(dev, PTR_ERR(nop->vbus_draw), 263 263 "could not get vbus regulator\n"); 264 264 265 - nop->vbus_draw = devm_regulator_get_exclusive(dev, "vbus"); 266 - if (PTR_ERR(nop->vbus_draw) == -ENODEV) 267 - nop->vbus_draw = NULL; 268 - if (IS_ERR(nop->vbus_draw)) 269 - return dev_err_probe(dev, PTR_ERR(nop->vbus_draw), 270 - "could not get vbus regulator\n"); 271 - 272 265 nop->dev = dev; 273 266 nop->phy.dev = nop->dev; 274 267 nop->phy.label = "nop-xceiv";
+13 -15
drivers/usb/storage/uas.c
··· 533 533 * daft to me. 534 534 */ 535 535 536 - static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) 536 + static int uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) 537 537 { 538 538 struct uas_dev_info *devinfo = cmnd->device->hostdata; 539 539 struct urb *urb; ··· 541 541 542 542 urb = uas_alloc_sense_urb(devinfo, gfp, cmnd); 543 543 if (!urb) 544 - return NULL; 544 + return -ENOMEM; 545 545 usb_anchor_urb(urb, &devinfo->sense_urbs); 546 546 err = usb_submit_urb(urb, gfp); 547 547 if (err) { 548 548 usb_unanchor_urb(urb); 549 549 uas_log_cmd_state(cmnd, "sense submit err", err); 550 550 usb_free_urb(urb); 551 - return NULL; 552 551 } 553 - return urb; 552 + return err; 554 553 } 555 554 556 555 static int uas_submit_urbs(struct scsi_cmnd *cmnd, 557 556 struct uas_dev_info *devinfo) 558 557 { 559 558 struct uas_cmd_info *cmdinfo = scsi_cmd_priv(cmnd); 560 - struct urb *urb; 561 559 int err; 562 560 563 561 lockdep_assert_held(&devinfo->lock); 564 562 if (cmdinfo->state & SUBMIT_STATUS_URB) { 565 - urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); 566 - if (!urb) 567 - return SCSI_MLQUEUE_DEVICE_BUSY; 563 + err = uas_submit_sense_urb(cmnd, GFP_ATOMIC); 564 + if (err) 565 + return err; 568 566 cmdinfo->state &= ~SUBMIT_STATUS_URB; 569 567 } 570 568 ··· 570 572 cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, 571 573 cmnd, DMA_FROM_DEVICE); 572 574 if (!cmdinfo->data_in_urb) 573 - return SCSI_MLQUEUE_DEVICE_BUSY; 575 + return -ENOMEM; 574 576 cmdinfo->state &= ~ALLOC_DATA_IN_URB; 575 577 } 576 578 ··· 580 582 if (err) { 581 583 usb_unanchor_urb(cmdinfo->data_in_urb); 582 584 uas_log_cmd_state(cmnd, "data in submit err", err); 583 - return SCSI_MLQUEUE_DEVICE_BUSY; 585 + return err; 584 586 } 585 587 cmdinfo->state &= ~SUBMIT_DATA_IN_URB; 586 588 cmdinfo->state |= DATA_IN_URB_INFLIGHT; ··· 590 592 cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, 591 593 cmnd, DMA_TO_DEVICE); 592 594 if (!cmdinfo->data_out_urb) 593 - return SCSI_MLQUEUE_DEVICE_BUSY; 595 + return -ENOMEM; 594 596 cmdinfo->state &= ~ALLOC_DATA_OUT_URB; 595 597 } 596 598 ··· 600 602 if (err) { 601 603 usb_unanchor_urb(cmdinfo->data_out_urb); 602 604 uas_log_cmd_state(cmnd, "data out submit err", err); 603 - return SCSI_MLQUEUE_DEVICE_BUSY; 605 + return err; 604 606 } 605 607 cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; 606 608 cmdinfo->state |= DATA_OUT_URB_INFLIGHT; ··· 609 611 if (cmdinfo->state & ALLOC_CMD_URB) { 610 612 cmdinfo->cmd_urb = uas_alloc_cmd_urb(devinfo, GFP_ATOMIC, cmnd); 611 613 if (!cmdinfo->cmd_urb) 612 - return SCSI_MLQUEUE_DEVICE_BUSY; 614 + return -ENOMEM; 613 615 cmdinfo->state &= ~ALLOC_CMD_URB; 614 616 } 615 617 ··· 619 621 if (err) { 620 622 usb_unanchor_urb(cmdinfo->cmd_urb); 621 623 uas_log_cmd_state(cmnd, "cmd submit err", err); 622 - return SCSI_MLQUEUE_DEVICE_BUSY; 624 + return err; 623 625 } 624 626 cmdinfo->cmd_urb = NULL; 625 627 cmdinfo->state &= ~SUBMIT_CMD_URB; ··· 696 698 * of queueing, no matter how fatal the error 697 699 */ 698 700 if (err == -ENODEV) { 699 - set_host_byte(cmnd, DID_ERROR); 701 + set_host_byte(cmnd, DID_NO_CONNECT); 700 702 scsi_done(cmnd); 701 703 goto zombie; 702 704 }
+6 -1
drivers/usb/typec/class.c
··· 1310 1310 { 1311 1311 struct typec_port *port = to_typec_port(dev); 1312 1312 struct usb_power_delivery *pd; 1313 + int ret; 1313 1314 1314 1315 if (!port->ops || !port->ops->pd_set) 1315 1316 return -EOPNOTSUPP; ··· 1319 1318 if (!pd) 1320 1319 return -EINVAL; 1321 1320 1322 - return port->ops->pd_set(port, pd); 1321 + ret = port->ops->pd_set(port, pd); 1322 + if (ret) 1323 + return ret; 1324 + 1325 + return size; 1323 1326 } 1324 1327 1325 1328 static ssize_t select_usb_power_delivery_show(struct device *dev,
+3 -3
drivers/usb/typec/tcpm/tcpm.c
··· 6861 6861 6862 6862 if (data->source_desc.pdo[0]) { 6863 6863 for (i = 0; i < PDO_MAX_OBJECTS && data->source_desc.pdo[i]; i++) 6864 - port->snk_pdo[i] = data->source_desc.pdo[i]; 6864 + port->src_pdo[i] = data->source_desc.pdo[i]; 6865 6865 port->nr_src_pdo = i + 1; 6866 6866 } 6867 6867 ··· 6910 6910 6911 6911 port->port_source_caps = data->source_cap; 6912 6912 port->port_sink_caps = data->sink_cap; 6913 + typec_port_set_usb_power_delivery(p, NULL); 6913 6914 port->selected_pd = pd; 6915 + typec_port_set_usb_power_delivery(p, port->selected_pd); 6914 6916 unlock: 6915 6917 mutex_unlock(&port->lock); 6916 6918 return ret; ··· 6945 6943 port->port_source_caps = NULL; 6946 6944 for (i = 0; i < port->pd_count; i++) { 6947 6945 usb_power_delivery_unregister_capabilities(port->pd_list[i]->sink_cap); 6948 - kfree(port->pd_list[i]->sink_cap); 6949 6946 usb_power_delivery_unregister_capabilities(port->pd_list[i]->source_cap); 6950 - kfree(port->pd_list[i]->source_cap); 6951 6947 devm_kfree(port->dev, port->pd_list[i]); 6952 6948 port->pd_list[i] = NULL; 6953 6949 usb_power_delivery_unregister(port->pds[i]);
+72 -18
drivers/usb/typec/ucsi/ucsi.c
··· 151 151 if (!(cci & UCSI_CCI_COMMAND_COMPLETE)) 152 152 return -EIO; 153 153 154 - if (cci & UCSI_CCI_NOT_SUPPORTED) 154 + if (cci & UCSI_CCI_NOT_SUPPORTED) { 155 + if (ucsi_acknowledge_command(ucsi) < 0) 156 + dev_err(ucsi->dev, 157 + "ACK of unsupported command failed\n"); 155 158 return -EOPNOTSUPP; 159 + } 156 160 157 161 if (cci & UCSI_CCI_ERROR) { 158 162 if (cmd == UCSI_GET_ERROR_STATUS) ··· 1137 1133 if (ret < 0) 1138 1134 return ret; 1139 1135 1140 - ret = ucsi_get_cable_identity(con); 1141 - if (ret < 0) 1142 - return ret; 1136 + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) { 1137 + ret = ucsi_get_cable_identity(con); 1138 + if (ret < 0) 1139 + return ret; 1140 + } 1143 1141 1144 - ret = ucsi_register_plug(con); 1145 - if (ret < 0) 1146 - return ret; 1142 + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) { 1143 + ret = ucsi_register_plug(con); 1144 + if (ret < 0) 1145 + return ret; 1147 1146 1148 - ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P); 1149 - if (ret < 0) 1150 - return ret; 1147 + ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P); 1148 + if (ret < 0) 1149 + return ret; 1150 + } 1151 1151 1152 1152 return 0; 1153 1153 } ··· 1197 1189 ucsi_register_partner(con); 1198 1190 ucsi_partner_task(con, ucsi_check_connection, 1, HZ); 1199 1191 ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ); 1200 - ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ); 1201 - ucsi_partner_task(con, ucsi_check_cable, 1, HZ); 1192 + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) 1193 + ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ); 1194 + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS) 1195 + ucsi_partner_task(con, ucsi_check_cable, 1, HZ); 1202 1196 1203 1197 if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == 1204 1198 UCSI_CONSTAT_PWR_OPMODE_PD) ··· 1225 1215 if (con->status.change & UCSI_CONSTAT_CAM_CHANGE) 1226 1216 ucsi_partner_task(con, ucsi_check_altmodes, 1, 0); 1227 1217 1228 - clear_bit(EVENT_PENDING, &con->ucsi->flags); 1229 - 1230 1218 mutex_lock(&ucsi->ppm_lock); 1219 + clear_bit(EVENT_PENDING, &con->ucsi->flags); 1231 1220 ret = ucsi_acknowledge_connector_change(ucsi); 1232 1221 mutex_unlock(&ucsi->ppm_lock); 1222 + 1233 1223 if (ret) 1234 1224 dev_err(ucsi->dev, "%s: ACK failed (%d)", __func__, ret); 1235 1225 ··· 1247 1237 struct ucsi_connector *con = &ucsi->connector[num - 1]; 1248 1238 1249 1239 if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) { 1250 - dev_dbg(ucsi->dev, "Bogus connector change event\n"); 1240 + dev_dbg(ucsi->dev, "Early connector change event\n"); 1251 1241 return; 1252 1242 } 1253 1243 ··· 1270 1260 1271 1261 static int ucsi_reset_ppm(struct ucsi *ucsi) 1272 1262 { 1273 - u64 command = UCSI_PPM_RESET; 1263 + u64 command; 1274 1264 unsigned long tmo; 1275 1265 u32 cci; 1276 1266 int ret; 1277 1267 1278 1268 mutex_lock(&ucsi->ppm_lock); 1279 1269 1270 + ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); 1271 + if (ret < 0) 1272 + goto out; 1273 + 1274 + /* 1275 + * If UCSI_CCI_RESET_COMPLETE is already set we must clear 1276 + * the flag before we start another reset. Send a 1277 + * UCSI_SET_NOTIFICATION_ENABLE command to achieve this. 1278 + * Ignore a timeout and try the reset anyway if this fails. 1279 + */ 1280 + if (cci & UCSI_CCI_RESET_COMPLETE) { 1281 + command = UCSI_SET_NOTIFICATION_ENABLE; 1282 + ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command, 1283 + sizeof(command)); 1284 + if (ret < 0) 1285 + goto out; 1286 + 1287 + tmo = jiffies + msecs_to_jiffies(UCSI_TIMEOUT_MS); 1288 + do { 1289 + ret = ucsi->ops->read(ucsi, UCSI_CCI, 1290 + &cci, sizeof(cci)); 1291 + if (ret < 0) 1292 + goto out; 1293 + if (cci & UCSI_CCI_COMMAND_COMPLETE) 1294 + break; 1295 + if (time_is_before_jiffies(tmo)) 1296 + break; 1297 + msleep(20); 1298 + } while (1); 1299 + 1300 + WARN_ON(cci & UCSI_CCI_RESET_COMPLETE); 1301 + } 1302 + 1303 + command = UCSI_PPM_RESET; 1280 1304 ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command, 1281 1305 sizeof(command)); 1282 1306 if (ret < 0) ··· 1633 1589 ucsi_register_partner(con); 1634 1590 ucsi_pwr_opmode_change(con); 1635 1591 ucsi_port_psy_changed(con); 1636 - ucsi_get_partner_identity(con); 1637 - ucsi_check_cable(con); 1592 + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) 1593 + ucsi_get_partner_identity(con); 1594 + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS) 1595 + ucsi_check_cable(con); 1638 1596 } 1639 1597 1640 1598 /* Only notify USB controller if partner supports USB data */ ··· 1682 1636 { 1683 1637 struct ucsi_connector *con, *connector; 1684 1638 u64 command, ntfy; 1639 + u32 cci; 1685 1640 int ret; 1686 1641 int i; 1687 1642 ··· 1735 1688 1736 1689 ucsi->connector = connector; 1737 1690 ucsi->ntfy = ntfy; 1691 + 1692 + ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); 1693 + if (ret) 1694 + return ret; 1695 + if (UCSI_CCI_CONNECTOR(READ_ONCE(cci))) 1696 + ucsi_connector_change(ucsi, cci); 1697 + 1738 1698 return 0; 1739 1699 1740 1700 err_unregister:
+3 -2
drivers/usb/typec/ucsi/ucsi.h
··· 206 206 #define UCSI_CAP_ATTR_POWER_OTHER BIT(10) 207 207 #define UCSI_CAP_ATTR_POWER_VBUS BIT(14) 208 208 u8 num_connectors; 209 - u8 features; 209 + u16 features; 210 210 #define UCSI_CAP_SET_UOM BIT(0) 211 211 #define UCSI_CAP_SET_PDM BIT(1) 212 212 #define UCSI_CAP_ALT_MODE_DETAILS BIT(2) ··· 215 215 #define UCSI_CAP_CABLE_DETAILS BIT(5) 216 216 #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6) 217 217 #define UCSI_CAP_PD_RESET BIT(7) 218 - u16 reserved_1; 218 + #define UCSI_CAP_GET_PD_MESSAGE BIT(8) 219 + u8 reserved_1; 219 220 u8 num_alt_modes; 220 221 u8 reserved_2; 221 222 u16 bc_version;
+31 -40
drivers/usb/typec/ucsi/ucsi_acpi.c
··· 23 23 void *base; 24 24 struct completion complete; 25 25 unsigned long flags; 26 + #define UCSI_ACPI_SUPPRESS_EVENT 0 27 + #define UCSI_ACPI_COMMAND_PENDING 1 28 + #define UCSI_ACPI_ACK_PENDING 2 26 29 guid_t guid; 27 30 u64 cmd; 28 - bool dell_quirk_probed; 29 - bool dell_quirk_active; 30 31 }; 31 32 32 33 static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func) ··· 80 79 int ret; 81 80 82 81 if (ack) 83 - set_bit(ACK_PENDING, &ua->flags); 82 + set_bit(UCSI_ACPI_ACK_PENDING, &ua->flags); 84 83 else 85 - set_bit(COMMAND_PENDING, &ua->flags); 84 + set_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags); 86 85 87 86 ret = ucsi_acpi_async_write(ucsi, offset, val, val_len); 88 87 if (ret) ··· 93 92 94 93 out_clear_bit: 95 94 if (ack) 96 - clear_bit(ACK_PENDING, &ua->flags); 95 + clear_bit(UCSI_ACPI_ACK_PENDING, &ua->flags); 97 96 else 98 - clear_bit(COMMAND_PENDING, &ua->flags); 97 + clear_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags); 99 98 100 99 return ret; 101 100 } ··· 130 129 }; 131 130 132 131 /* 133 - * Some Dell laptops expect that an ACK command with the 134 - * UCSI_ACK_CONNECTOR_CHANGE bit set is followed by a (separate) 135 - * ACK command that only has the UCSI_ACK_COMMAND_COMPLETE bit set. 136 - * If this is not done events are not delivered to OSPM and 137 - * subsequent commands will timeout. 132 + * Some Dell laptops don't like ACK commands with the 133 + * UCSI_ACK_CONNECTOR_CHANGE but not the UCSI_ACK_COMMAND_COMPLETE 134 + * bit set. To work around this send a dummy command and bundle the 135 + * UCSI_ACK_CONNECTOR_CHANGE with the UCSI_ACK_COMMAND_COMPLETE 136 + * for the dummy command. 138 137 */ 139 138 static int 140 139 ucsi_dell_sync_write(struct ucsi *ucsi, unsigned int offset, 141 140 const void *val, size_t val_len) 142 141 { 143 142 struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 144 - u64 cmd = *(u64 *)val, ack = 0; 143 + u64 cmd = *(u64 *)val; 144 + u64 dummycmd = UCSI_GET_CAPABILITY; 145 145 int ret; 146 146 147 - if (UCSI_COMMAND(cmd) == UCSI_ACK_CC_CI && 148 - cmd & UCSI_ACK_CONNECTOR_CHANGE) 149 - ack = UCSI_ACK_CC_CI | UCSI_ACK_COMMAND_COMPLETE; 147 + if (cmd == (UCSI_ACK_CC_CI | UCSI_ACK_CONNECTOR_CHANGE)) { 148 + cmd |= UCSI_ACK_COMMAND_COMPLETE; 150 149 151 - ret = ucsi_acpi_sync_write(ucsi, offset, val, val_len); 152 - if (ret != 0) 153 - return ret; 154 - if (ack == 0) 155 - return ret; 150 + /* 151 + * The UCSI core thinks it is sending a connector change ack 152 + * and will accept new connector change events. We don't want 153 + * this to happen for the dummy command as its response will 154 + * still report the very event that the core is trying to clear. 155 + */ 156 + set_bit(UCSI_ACPI_SUPPRESS_EVENT, &ua->flags); 157 + ret = ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &dummycmd, 158 + sizeof(dummycmd)); 159 + clear_bit(UCSI_ACPI_SUPPRESS_EVENT, &ua->flags); 156 160 157 - if (!ua->dell_quirk_probed) { 158 - ua->dell_quirk_probed = true; 159 - 160 - cmd = UCSI_GET_CAPABILITY; 161 - ret = ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &cmd, 162 - sizeof(cmd)); 163 - if (ret == 0) 164 - return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, 165 - &ack, sizeof(ack)); 166 - if (ret != -ETIMEDOUT) 161 + if (ret < 0) 167 162 return ret; 168 - 169 - ua->dell_quirk_active = true; 170 - dev_err(ua->dev, "Firmware bug: Additional ACK required after ACKing a connector change.\n"); 171 - dev_err(ua->dev, "Firmware bug: Enabling workaround\n"); 172 163 } 173 164 174 - if (!ua->dell_quirk_active) 175 - return ret; 176 - 177 - return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &ack, sizeof(ack)); 165 + return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd)); 178 166 } 179 167 180 168 static const struct ucsi_operations ucsi_dell_ops = { ··· 199 209 if (ret) 200 210 return; 201 211 202 - if (UCSI_CCI_CONNECTOR(cci)) 212 + if (UCSI_CCI_CONNECTOR(cci) && 213 + !test_bit(UCSI_ACPI_SUPPRESS_EVENT, &ua->flags)) 203 214 ucsi_connector_change(ua->ucsi, UCSI_CCI_CONNECTOR(cci)); 204 215 205 216 if (cci & UCSI_CCI_ACK_COMPLETE && test_bit(ACK_PENDING, &ua->flags)) 206 217 complete(&ua->complete); 207 218 if (cci & UCSI_CCI_COMMAND_COMPLETE && 208 - test_bit(COMMAND_PENDING, &ua->flags)) 219 + test_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags)) 209 220 complete(&ua->complete); 210 221 } 211 222
+14
drivers/usb/typec/ucsi/ucsi_glink.c
··· 255 255 static void pmic_glink_ucsi_register(struct work_struct *work) 256 256 { 257 257 struct pmic_glink_ucsi *ucsi = container_of(work, struct pmic_glink_ucsi, register_work); 258 + int orientation; 259 + int i; 260 + 261 + for (i = 0; i < PMIC_GLINK_MAX_PORTS; i++) { 262 + if (!ucsi->port_orientation[i]) 263 + continue; 264 + orientation = gpiod_get_value(ucsi->port_orientation[i]); 265 + 266 + if (orientation >= 0) { 267 + typec_switch_set(ucsi->port_switch[i], 268 + orientation ? TYPEC_ORIENTATION_REVERSE 269 + : TYPEC_ORIENTATION_NORMAL); 270 + } 271 + } 258 272 259 273 ucsi_register(ucsi->ucsi); 260 274 }