0004-usb-fotg210-Select-subdriver-by-mode.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From 7c0b661926097e935f2711857596fc2277b2304a Mon Sep 17 00:00:00 2001
  2. From: Linus Walleij <[email protected]>
  3. Date: Sun, 23 Oct 2022 16:47:08 +0200
  4. Subject: [PATCH 04/29] usb: fotg210: Select subdriver by mode
  5. Check which mode the hardware is in, and selecte the peripheral
  6. driver if the hardware is in explicit peripheral mode, otherwise
  7. select host mode.
  8. This should solve the immediate problem that both subdrivers
  9. can get probed.
  10. Cc: Fabian Vogt <[email protected]>
  11. Cc: Yuan-Hsin Chen <[email protected]>
  12. Cc: Felipe Balbi <[email protected]>
  13. Signed-off-by: Linus Walleij <[email protected]>
  14. Link: https://lore.kernel.org/r/[email protected]
  15. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  16. ---
  17. --- a/drivers/usb/fotg210/fotg210-core.c
  18. +++ b/drivers/usb/fotg210/fotg210-core.c
  19. @@ -10,30 +10,37 @@
  20. #include <linux/of.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/usb.h>
  23. +#include <linux/usb/otg.h>
  24. #include "fotg210.h"
  25. static int fotg210_probe(struct platform_device *pdev)
  26. {
  27. + struct device *dev = &pdev->dev;
  28. + enum usb_dr_mode mode;
  29. int ret;
  30. - if (IS_ENABLED(CONFIG_USB_FOTG210_HCD)) {
  31. - ret = fotg210_hcd_probe(pdev);
  32. - if (ret)
  33. - return ret;
  34. - }
  35. - if (IS_ENABLED(CONFIG_USB_FOTG210_UDC))
  36. + mode = usb_get_dr_mode(dev);
  37. +
  38. + if (mode == USB_DR_MODE_PERIPHERAL)
  39. ret = fotg210_udc_probe(pdev);
  40. + else
  41. + ret = fotg210_hcd_probe(pdev);
  42. return ret;
  43. }
  44. static int fotg210_remove(struct platform_device *pdev)
  45. {
  46. - if (IS_ENABLED(CONFIG_USB_FOTG210_HCD))
  47. - fotg210_hcd_remove(pdev);
  48. - if (IS_ENABLED(CONFIG_USB_FOTG210_UDC))
  49. + struct device *dev = &pdev->dev;
  50. + enum usb_dr_mode mode;
  51. +
  52. + mode = usb_get_dr_mode(dev);
  53. +
  54. + if (mode == USB_DR_MODE_PERIPHERAL)
  55. fotg210_udc_remove(pdev);
  56. + else
  57. + fotg210_hcd_remove(pdev);
  58. return 0;
  59. }