The USB role callback functions had a parameter pointing to the parent device (struct device) of the switch. The assumption was that the switch parent is always the controller. Firstly, that may not be true in every case, and secondly, it prevents us from supporting devices that supply multiple muxes. Changing the first parameter of usb_role_switch_set_t and usb_role_switch_get_t from struct device to struct usb_role_switch.
Unified · Split
| @@ -330,9 +330,9 @@ exit: · 329 unmodified lines | ||
| 330 | 330 | * |
| 331 | 331 | * Returns role |
| 332 | 332 | */ |
| 333 | −static enum usb_role cdns3_role_get(struct device *dev) | |
| 333 | +static enum usb_role cdns3_role_get(struct usb_role_switch *sw) | |
| 334 | 334 | { |
| 335 | − struct cdns3 *cdns = dev_get_drvdata(dev); | |
| 335 | + struct cdns3 *cdns = usb_role_switch_get_drvdata(sw); | |
| 336 | 336 | |
| 337 | 337 | return cdns->role; |
| 338 | 338 | } |
| @@ -346,9 +346,9 @@ static enum usb_role cdns3_role_get(struct device *dev) · 7 unmodified lines | ||
| 346 | 346 | * - Role switch for dual-role devices |
| 347 | 347 | * - USB_ROLE_GADGET <--> USB_ROLE_NONE for peripheral-only devices |
| 348 | 348 | */ |
| 349 | −static int cdns3_role_set(struct device *dev, enum usb_role role) | |
| 349 | +static int cdns3_role_set(struct usb_role_switch *sw, enum usb_role role) | |
| 350 | 350 | { |
| 351 | − struct cdns3 *cdns = dev_get_drvdata(dev); | |
| 351 | + struct cdns3 *cdns = usb_role_switch_get_drvdata(sw); | |
| 352 | 352 | int ret = 0; |
| 353 | 353 | |
| 354 | 354 | pm_runtime_get_sync(cdns->dev); |
| @@ -423,12 +423,6 @@ pm_put: · 68 unmodified lines | ||
| 423 | 423 | return ret; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | −static const struct usb_role_switch_desc cdns3_switch_desc = { | |
| 427 | − .set = cdns3_role_set, | |
| 428 | − .get = cdns3_role_get, | |
| 429 | − .allow_userspace_control = true, | |
| 430 | −}; | |
| 431 | − | |
| 432 | 426 | /** |
| 433 | 427 | * cdns3_probe - probe for cdns3 core device |
| 434 | 428 | * @pdev: Pointer to cdns3 core platform device |
| @@ -437,6 +431,7 @@ static const struct usb_role_switch_desc cdns3_switch_desc = { · 2 unmodified lines | ||
| 437 | 431 | */ |
| 438 | 432 | static int cdns3_probe(struct platform_device *pdev) |
| 439 | 433 | { |
| 434 | + struct usb_role_switch_desc sw_desc = { }; | |
| 440 | 435 | struct device *dev = &pdev->dev; |
| 441 | 436 | struct resource *res; |
| 442 | 437 | struct cdns3 *cdns; |
| @@ -529,7 +524,12 @@ static int cdns3_probe(struct platform_device *pdev) · 86 unmodified lines | ||
| 529 | 524 | if (ret) |
| 530 | 525 | goto err3; |
| 531 | 526 | |
| 532 | − cdns->role_sw = usb_role_switch_register(dev, &cdns3_switch_desc); | |
| 527 | + sw_desc.set = cdns3_role_set; | |
| 528 | + sw_desc.get = cdns3_role_get; | |
| 529 | + sw_desc.allow_userspace_control = true; | |
| 530 | + sw_desc.driver_data = cdns; | |
| 531 | + | |
| 532 | + cdns->role_sw = usb_role_switch_register(dev, &sw_desc); | |
| 533 | 533 | if (IS_ERR(cdns->role_sw)) { |
| 534 | 534 | ret = PTR_ERR(cdns->role_sw); |
| 535 | 535 | dev_warn(dev, "Unable to register Role Switch\n"); |
| @@ -600,9 +600,9 @@ static int ci_cable_notifier(struct notifier_block *nb, unsigned long event, · 599 unmodified lines | ||
| 600 | 600 | return NOTIFY_DONE; |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | −static enum usb_role ci_usb_role_switch_get(struct device *dev) | |
| 603 | +static enum usb_role ci_usb_role_switch_get(struct usb_role_switch *sw) | |
| 604 | 604 | { |
| 605 | − struct ci_hdrc *ci = dev_get_drvdata(dev); | |
| 605 | + struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw); | |
| 606 | 606 | enum usb_role role; |
| 607 | 607 | unsigned long flags; |
| 608 | 608 | |
| @@ -613,9 +613,10 @@ static enum usb_role ci_usb_role_switch_get(struct device *dev) · 4 unmodified lines | ||
| 613 | 613 | return role; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | −static int ci_usb_role_switch_set(struct device *dev, enum usb_role role) | |
| 616 | +static int ci_usb_role_switch_set(struct usb_role_switch *sw, | |
| 617 | + enum usb_role role) | |
| 617 | 618 | { |
| 618 | − struct ci_hdrc *ci = dev_get_drvdata(dev); | |
| 619 | + struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw); | |
| 619 | 620 | struct ci_hdrc_cable *cable = NULL; |
| 620 | 621 | enum usb_role current_role = ci_role_to_usb_role(ci); |
| 621 | 622 | enum ci_role ci_role = usb_role_to_ci_role(role); |
| @@ -1118,6 +1119,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) · 496 unmodified lines | ||
| 1118 | 1119 | } |
| 1119 | 1120 | |
| 1120 | 1121 | if (ci_role_switch.fwnode) { |
| 1122 | + ci_role_switch.driver_data = ci; | |
| 1121 | 1123 | ci->role_switch = usb_role_switch_register(dev, |
| 1122 | 1124 | &ci_role_switch); |
| 1123 | 1125 | if (IS_ERR(ci->role_switch)) { |
| @@ -321,9 +321,10 @@ static int dwc3_meson_g12a_otg_mode_set(struct dwc3_meson_g12a *priv, · 320 unmodified lines | ||
| 321 | 321 | return 0; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | −static int dwc3_meson_g12a_role_set(struct device *dev, enum usb_role role) | |
| 324 | +static int dwc3_meson_g12a_role_set(struct usb_role_switch *sw, | |
| 325 | + enum usb_role role) | |
| 325 | 326 | { |
| 326 | − struct dwc3_meson_g12a *priv = dev_get_drvdata(dev); | |
| 327 | + struct dwc3_meson_g12a *priv = usb_role_switch_get_drvdata(sw); | |
| 327 | 328 | enum phy_mode mode; |
| 328 | 329 | |
| 329 | 330 | if (role == USB_ROLE_NONE) |
| @@ -338,9 +339,9 @@ static int dwc3_meson_g12a_role_set(struct device *dev, enum usb_role role) · 8 unmodified lines | ||
| 338 | 339 | return dwc3_meson_g12a_otg_mode_set(priv, mode); |
| 339 | 340 | } |
| 340 | 341 | |
| 341 | −static enum usb_role dwc3_meson_g12a_role_get(struct device *dev) | |
| 342 | +static enum usb_role dwc3_meson_g12a_role_get(struct usb_role_switch *sw) | |
| 342 | 343 | { |
| 343 | − struct dwc3_meson_g12a *priv = dev_get_drvdata(dev); | |
| 344 | + struct dwc3_meson_g12a *priv = usb_role_switch_get_drvdata(sw); | |
| 344 | 345 | |
| 345 | 346 | return priv->otg_phy_mode == PHY_MODE_USB_HOST ? |
| 346 | 347 | USB_ROLE_HOST : USB_ROLE_DEVICE; |
| @@ -499,6 +500,7 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev) · 152 unmodified lines | ||
| 499 | 500 | priv->switch_desc.allow_userspace_control = true; |
| 500 | 501 | priv->switch_desc.set = dwc3_meson_g12a_role_set; |
| 501 | 502 | priv->switch_desc.get = dwc3_meson_g12a_role_get; |
| 503 | + priv->switch_desc.driver_data = priv; | |
| 502 | 504 | |
| 503 | 505 | priv->role_switch = usb_role_switch_register(dev, &priv->switch_desc); |
| 504 | 506 | if (IS_ERR(priv->role_switch)) |
| @@ -2355,14 +2355,14 @@ static const struct usb_gadget_ops renesas_usb3_gadget_ops = { · 2354 unmodified lines | ||
| 2355 | 2355 | .set_selfpowered = renesas_usb3_set_selfpowered, |
| 2356 | 2356 | }; |
| 2357 | 2357 | |
| 2358 | −static enum usb_role renesas_usb3_role_switch_get(struct device *dev) | |
| 2358 | +static enum usb_role renesas_usb3_role_switch_get(struct usb_role_switch *sw) | |
| 2359 | 2359 | { |
| 2360 | − struct renesas_usb3 *usb3 = dev_get_drvdata(dev); | |
| 2360 | + struct renesas_usb3 *usb3 = usb_role_switch_get_drvdata(sw); | |
| 2361 | 2361 | enum usb_role cur_role; |
| 2362 | 2362 | |
| 2363 | − pm_runtime_get_sync(dev); | |
| 2363 | + pm_runtime_get_sync(usb3_to_dev(usb3)); | |
| 2364 | 2364 | cur_role = usb3_is_host(usb3) ? USB_ROLE_HOST : USB_ROLE_DEVICE; |
| 2365 | − pm_runtime_put(dev); | |
| 2365 | + pm_runtime_put(usb3_to_dev(usb3)); | |
| 2366 | 2366 | |
| 2367 | 2367 | return cur_role; |
| 2368 | 2368 | } |
| @@ -2372,7 +2372,7 @@ static void handle_ext_role_switch_states(struct device *dev, · 3 unmodified lines | ||
| 2372 | 2372 | { |
| 2373 | 2373 | struct renesas_usb3 *usb3 = dev_get_drvdata(dev); |
| 2374 | 2374 | struct device *host = usb3->host_dev; |
| 2375 | − enum usb_role cur_role = renesas_usb3_role_switch_get(dev); | |
| 2375 | + enum usb_role cur_role = renesas_usb3_role_switch_get(usb3->role_sw); | |
| 2376 | 2376 | |
| 2377 | 2377 | switch (role) { |
| 2378 | 2378 | case USB_ROLE_NONE: |
| @@ -2424,7 +2424,7 @@ static void handle_role_switch_states(struct device *dev, · 45 unmodified lines | ||
| 2424 | 2424 | { |
| 2425 | 2425 | struct renesas_usb3 *usb3 = dev_get_drvdata(dev); |
| 2426 | 2426 | struct device *host = usb3->host_dev; |
| 2427 | − enum usb_role cur_role = renesas_usb3_role_switch_get(dev); | |
| 2427 | + enum usb_role cur_role = renesas_usb3_role_switch_get(usb3->role_sw); | |
| 2428 | 2428 | |
| 2429 | 2429 | if (cur_role == USB_ROLE_HOST && role == USB_ROLE_DEVICE) { |
| 2430 | 2430 | device_release_driver(host); |
| @@ -2438,19 +2438,19 @@ static void handle_role_switch_states(struct device *dev, · 7 unmodified lines | ||
| 2438 | 2438 | } |
| 2439 | 2439 | } |
| 2440 | 2440 | |
| 2441 | −static int renesas_usb3_role_switch_set(struct device *dev, | |
| 2441 | +static int renesas_usb3_role_switch_set(struct usb_role_switch *sw, | |
| 2442 | 2442 | enum usb_role role) |
| 2443 | 2443 | { |
| 2444 | − struct renesas_usb3 *usb3 = dev_get_drvdata(dev); | |
| 2444 | + struct renesas_usb3 *usb3 = usb_role_switch_get_drvdata(sw); | |
| 2445 | 2445 | |
| 2446 | − pm_runtime_get_sync(dev); | |
| 2446 | + pm_runtime_get_sync(usb3_to_dev(usb3)); | |
| 2447 | 2447 | |
| 2448 | 2448 | if (usb3->role_sw_by_connector) |
| 2449 | − handle_ext_role_switch_states(dev, role); | |
| 2449 | + handle_ext_role_switch_states(usb3_to_dev(usb3), role); | |
| 2450 | 2450 | else |
| 2451 | − handle_role_switch_states(dev, role); | |
| 2451 | + handle_role_switch_states(usb3_to_dev(usb3), role); | |
| 2452 | 2452 | |
| 2453 | − pm_runtime_put(dev); | |
| 2453 | + pm_runtime_put(usb3_to_dev(usb3)); | |
| 2454 | 2454 | |
| 2455 | 2455 | return 0; |
| 2456 | 2456 | } |
| @@ -2831,6 +2831,8 @@ static int renesas_usb3_probe(struct platform_device *pdev) · 374 unmodified lines | ||
| 2831 | 2831 | renesas_usb3_role_switch_desc.fwnode = dev_fwnode(&pdev->dev); |
| 2832 | 2832 | } |
| 2833 | 2833 | |
| 2834 | + renesas_usb3_role_switch_desc.driver_data = usb3; | |
| 2835 | + | |
| 2834 | 2836 | INIT_WORK(&usb3->role_work, renesas_usb3_role_work); |
| 2835 | 2837 | usb3->role_sw = usb_role_switch_register(&pdev->dev, |
| 2836 | 2838 | &renesas_usb3_role_switch_desc); |
| @@ -676,12 +676,13 @@ static void tegra_xudc_usb_role_sw_work(struct work_struct *work) · 675 unmodified lines | ||
| 676 | 676 | |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | −static int tegra_xudc_usb_role_sw_set(struct device *dev, enum usb_role role) | |
| 679 | +static int tegra_xudc_usb_role_sw_set(struct usb_role_switch *sw, | |
| 680 | + enum usb_role role) | |
| 680 | 681 | { |
| 681 | − struct tegra_xudc *xudc = dev_get_drvdata(dev); | |
| 682 | + struct tegra_xudc *xudc = usb_role_switch_get_drvdata(sw); | |
| 682 | 683 | unsigned long flags; |
| 683 | 684 | |
| 684 | − dev_dbg(dev, "%s role is %d\n", __func__, role); | |
| 685 | + dev_dbg(xudc->dev, "%s role is %d\n", __func__, role); | |
| 685 | 686 | |
| 686 | 687 | spin_lock_irqsave(&xudc->lock, flags); |
| 687 | 688 | |
| @@ -3590,6 +3591,7 @@ static int tegra_xudc_probe(struct platform_device *pdev) · 2902 unmodified lines | ||
| 3590 | 3591 | if (of_property_read_bool(xudc->dev->of_node, "usb-role-switch")) { |
| 3591 | 3592 | role_sx_desc.set = tegra_xudc_usb_role_sw_set; |
| 3592 | 3593 | role_sx_desc.fwnode = dev_fwnode(xudc->dev); |
| 3594 | + role_sx_desc.driver_data = xudc; | |
| 3593 | 3595 | |
| 3594 | 3596 | xudc->usb_role_sw = usb_role_switch_register(xudc->dev, |
| 3595 | 3597 | &role_sx_desc); |
| @@ -320,9 +320,9 @@ void ssusb_set_force_mode(struct ssusb_mtk *ssusb, · 319 unmodified lines | ||
| 320 | 320 | mtu3_writel(ssusb->ippc_base, SSUSB_U2_CTRL(0), value); |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | −static int ssusb_role_sw_set(struct device *dev, enum usb_role role) | |
| 323 | +static int ssusb_role_sw_set(struct usb_role_switch *sw, enum usb_role role) | |
| 324 | 324 | { |
| 325 | − struct ssusb_mtk *ssusb = dev_get_drvdata(dev); | |
| 325 | + struct ssusb_mtk *ssusb = usb_role_switch_get_drvdata(sw); | |
| 326 | 326 | bool to_host = false; |
| 327 | 327 | |
| 328 | 328 | if (role == USB_ROLE_HOST) |
| @@ -334,9 +334,9 @@ static int ssusb_role_sw_set(struct device *dev, enum usb_role role) · 5 unmodified lines | ||
| 334 | 334 | return 0; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | −static enum usb_role ssusb_role_sw_get(struct device *dev) | |
| 337 | +static enum usb_role ssusb_role_sw_get(struct usb_role_switch *sw) | |
| 338 | 338 | { |
| 339 | − struct ssusb_mtk *ssusb = dev_get_drvdata(dev); | |
| 339 | + struct ssusb_mtk *ssusb = usb_role_switch_get_drvdata(sw); | |
| 340 | 340 | enum usb_role role; |
| 341 | 341 | |
| 342 | 342 | role = ssusb->is_host ? USB_ROLE_HOST : USB_ROLE_DEVICE; |
| @@ -356,6 +356,7 @@ static int ssusb_role_sw_register(struct otg_switch_mtk *otg_sx) · 13 unmodified lines | ||
| 356 | 356 | role_sx_desc.set = ssusb_role_sw_set; |
| 357 | 357 | role_sx_desc.get = ssusb_role_sw_get; |
| 358 | 358 | role_sx_desc.fwnode = dev_fwnode(ssusb->dev); |
| 359 | + role_sx_desc.driver_data = ssusb; | |
| 359 | 360 | otg_sx->role_sw = usb_role_switch_register(ssusb->dev, &role_sx_desc); |
| 360 | 361 | |
| 361 | 362 | return PTR_ERR_OR_ZERO(otg_sx->role_sw); |
| @@ -115,9 +115,8 @@ static void mtk_musb_clks_disable(struct mtk_glue *glue) · 114 unmodified lines | ||
| 115 | 115 | clk_disable_unprepare(glue->main); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | −static int musb_usb_role_sx_set(struct device *dev, enum usb_role role) | |
| 118 | +static int mtk_otg_switch_set(struct mtk_glue *glue, enum usb_role role) | |
| 119 | 119 | { |
| 120 | − struct mtk_glue *glue = dev_get_drvdata(dev); | |
| 121 | 120 | struct musb *musb = glue->musb; |
| 122 | 121 | u8 devctl = readb(musb->mregs + MUSB_DEVCTL); |
| 123 | 122 | enum usb_role new_role; |
| @@ -168,9 +167,14 @@ static int musb_usb_role_sx_set(struct device *dev, enum usb_role role) · 44 unmodified lines | ||
| 168 | 167 | return 0; |
| 169 | 168 | } |
| 170 | 169 | |
| 171 | −static enum usb_role musb_usb_role_sx_get(struct device *dev) | |
| 170 | +static int musb_usb_role_sx_set(struct usb_role_switch *sw, enum usb_role role) | |
| 172 | 171 | { |
| 173 | − struct mtk_glue *glue = dev_get_drvdata(dev); | |
| 172 | + return mtk_otg_switch_set(usb_role_switch_get_drvdata(sw), role); | |
| 173 | +} | |
| 174 | + | |
| 175 | +static enum usb_role musb_usb_role_sx_get(struct usb_role_switch *sw) | |
| 176 | +{ | |
| 177 | + struct mtk_glue *glue = usb_role_switch_get_drvdata(sw); | |
| 174 | 178 | |
| 175 | 179 | return glue->role; |
| 176 | 180 | } |
| @@ -182,6 +186,7 @@ static int mtk_otg_switch_init(struct mtk_glue *glue) · 5 unmodified lines | ||
| 182 | 186 | role_sx_desc.set = musb_usb_role_sx_set; |
| 183 | 187 | role_sx_desc.get = musb_usb_role_sx_get; |
| 184 | 188 | role_sx_desc.fwnode = dev_fwnode(glue->dev); |
| 189 | + role_sx_desc.driver_data = glue; | |
| 185 | 190 | glue->role_sw = usb_role_switch_register(glue->dev, &role_sx_desc); |
| 186 | 191 | |
| 187 | 192 | return PTR_ERR_OR_ZERO(glue->role_sw); |
| @@ -288,8 +293,7 @@ static int mtk_musb_set_mode(struct musb *musb, u8 mode) · 100 unmodified lines | ||
| 288 | 293 | return -EINVAL; |
| 289 | 294 | } |
| 290 | 295 | |
| 291 | − glue->role = new_role; | |
| 292 | − musb_usb_role_sx_set(dev, glue->role); | |
| 296 | + mtk_otg_switch_set(glue, new_role); | |
| 293 | 297 | return 0; |
| 294 | 298 | } |
| 295 | 299 | |
| @@ -48,7 +48,7 @@ int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role) · 47 unmodified lines | ||
| 48 | 48 | |
| 49 | 49 | mutex_lock(&sw->lock); |
| 50 | 50 | |
| 51 | − ret = sw->set(sw->dev.parent, role); | |
| 51 | + ret = sw->set(sw, role); | |
| 52 | 52 | if (!ret) |
| 53 | 53 | sw->role = role; |
| 54 | 54 | |
| @@ -75,7 +75,7 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) · 20 unmodified lines | ||
| 75 | 75 | mutex_lock(&sw->lock); |
| 76 | 76 | |
| 77 | 77 | if (sw->get) |
| 78 | − role = sw->get(sw->dev.parent); | |
| 78 | + role = sw->get(sw); | |
| 79 | 79 | else |
| 80 | 80 | role = sw->role; |
| 81 | 81 | |
| @@ -42,6 +42,7 @@ · 41 unmodified lines | ||
| 42 | 42 | #define DRV_NAME "intel_xhci_usb_sw" |
| 43 | 43 | |
| 44 | 44 | struct intel_xhci_usb_data { |
| 45 | + struct device *dev; | |
| 45 | 46 | struct usb_role_switch *role_sw; |
| 46 | 47 | void __iomem *base; |
| 47 | 48 | bool enable_sw_switch; |
| @@ -51,9 +52,10 @@ static const struct software_node intel_xhci_usb_node = { · 3 unmodified lines | ||
| 51 | 52 | "intel-xhci-usb-sw", |
| 52 | 53 | }; |
| 53 | 54 | |
| 54 | −static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role) | |
| 55 | +static int intel_xhci_usb_set_role(struct usb_role_switch *sw, | |
| 56 | + enum usb_role role) | |
| 55 | 57 | { |
| 56 | − struct intel_xhci_usb_data *data = dev_get_drvdata(dev); | |
| 58 | + struct intel_xhci_usb_data *data = usb_role_switch_get_drvdata(sw); | |
| 57 | 59 | unsigned long timeout; |
| 58 | 60 | acpi_status status; |
| 59 | 61 | u32 glk, val; |
| @@ -66,11 +68,11 @@ static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role) · 6 unmodified lines | ||
| 66 | 68 | */ |
| 67 | 69 | status = acpi_acquire_global_lock(ACPI_WAIT_FOREVER, &glk); |
| 68 | 70 | if (ACPI_FAILURE(status) && status != AE_NOT_CONFIGURED) { |
| 69 | − dev_err(dev, "Error could not acquire lock\n"); | |
| 71 | + dev_err(data->dev, "Error could not acquire lock\n"); | |
| 70 | 72 | return -EIO; |
| 71 | 73 | } |
| 72 | 74 | |
| 73 | − pm_runtime_get_sync(dev); | |
| 75 | + pm_runtime_get_sync(data->dev); | |
| 74 | 76 | |
| 75 | 77 | /* |
| 76 | 78 | * Set idpin value as requested. |
| @@ -112,7 +114,7 @@ static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role) · 35 unmodified lines | ||
| 112 | 114 | do { |
| 113 | 115 | val = readl(data->base + DUAL_ROLE_CFG1); |
| 114 | 116 | if (!!(val & HOST_MODE) == (role == USB_ROLE_HOST)) { |
| 115 | − pm_runtime_put(dev); | |
| 117 | + pm_runtime_put(data->dev); | |
| 116 | 118 | return 0; |
| 117 | 119 | } |
| 118 | 120 | |
| @@ -120,21 +122,21 @@ static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role) · 1 unmodified line | ||
| 120 | 122 | usleep_range(5000, 10000); |
| 121 | 123 | } while (time_before(jiffies, timeout)); |
| 122 | 124 | |
| 123 | − pm_runtime_put(dev); | |
| 125 | + pm_runtime_put(data->dev); | |
| 124 | 126 | |
| 125 | − dev_warn(dev, "Timeout waiting for role-switch\n"); | |
| 127 | + dev_warn(data->dev, "Timeout waiting for role-switch\n"); | |
| 126 | 128 | return -ETIMEDOUT; |
| 127 | 129 | } |
| 128 | 130 | |
| 129 | −static enum usb_role intel_xhci_usb_get_role(struct device *dev) | |
| 131 | +static enum usb_role intel_xhci_usb_get_role(struct usb_role_switch *sw) | |
| 130 | 132 | { |
| 131 | − struct intel_xhci_usb_data *data = dev_get_drvdata(dev); | |
| 133 | + struct intel_xhci_usb_data *data = usb_role_switch_get_drvdata(sw); | |
| 132 | 134 | enum usb_role role; |
| 133 | 135 | u32 val; |
| 134 | 136 | |
| 135 | − pm_runtime_get_sync(dev); | |
| 137 | + pm_runtime_get_sync(data->dev); | |
| 136 | 138 | val = readl(data->base + DUAL_ROLE_CFG0); |
| 137 | − pm_runtime_put(dev); | |
| 139 | + pm_runtime_put(data->dev); | |
| 138 | 140 | |
| 139 | 141 | if (!(val & SW_IDPIN)) |
| 140 | 142 | role = USB_ROLE_HOST; |
| @@ -175,7 +177,9 @@ static int intel_xhci_usb_probe(struct platform_device *pdev) · 34 unmodified lines | ||
| 175 | 177 | sw_desc.get = intel_xhci_usb_get_role, |
| 176 | 178 | sw_desc.allow_userspace_control = true, |
| 177 | 179 | sw_desc.fwnode = software_node_fwnode(&intel_xhci_usb_node); |
| 180 | + sw_desc.driver_data = data; | |
| 178 | 181 | |
| 182 | + data->dev = dev; | |
| 179 | 183 | data->enable_sw_switch = !device_property_read_bool(dev, |
| 180 | 184 | "sw_switch_disable"); |
| 181 | 185 | |
| @@ -13,8 +13,9 @@ enum usb_role { · 12 unmodified lines | ||
| 13 | 13 | USB_ROLE_DEVICE, |
| 14 | 14 | }; |
| 15 | 15 | |
| 16 | −typedef int (*usb_role_switch_set_t)(struct device *dev, enum usb_role role); | |
| 17 | −typedef enum usb_role (*usb_role_switch_get_t)(struct device *dev); | |
| 16 | +typedef int (*usb_role_switch_set_t)(struct usb_role_switch *sw, | |
| 17 | + enum usb_role role); | |
| 18 | +typedef enum usb_role (*usb_role_switch_get_t)(struct usb_role_switch *sw); | |
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * struct usb_role_switch_desc - USB Role Switch Descriptor |