2
0

0013-usb-host-fotg2-add-silicon-clock-handling.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. From e76906e8e9dfaeeb22a37706aca493b86e4367bd Mon Sep 17 00:00:00 2001
  2. From: Linus Walleij <[email protected]>
  3. Date: Fri, 21 Apr 2017 20:46:12 +0200
  4. Subject: [PATCH 13/18] usb: host: fotg2: add silicon clock handling
  5. When used in a system with software-controlled silicon clocks,
  6. the FOTG210 needs to grab, prepare and enable the clock.
  7. This is needed on for example the Cortina Gemini, where the
  8. platform will by default gate off the clock unless the
  9. peripheral (in this case the USB driver) grabs and enables
  10. the clock.
  11. If there is no clock available on the platform, we live
  12. without it. Make sure to percolate probe deferrals.
  13. Signed-off-by: Linus Walleij <[email protected]>
  14. ---
  15. ChangeLog v1->v2:
  16. - Handle probe deferrals on the clock controller, no matter
  17. how unlikely they are.
  18. - Send the patch to get Gemini USB rolling and try to get some
  19. stuff upstream, this patch should be fine on its own.
  20. ---
  21. drivers/usb/host/fotg210-hcd.c | 33 +++++++++++++++++++++++++++++----
  22. drivers/usb/host/fotg210.h | 3 +++
  23. 2 files changed, 32 insertions(+), 4 deletions(-)
  24. --- a/drivers/usb/host/fotg210-hcd.c
  25. +++ b/drivers/usb/host/fotg210-hcd.c
  26. @@ -31,6 +31,7 @@
  27. #include <linux/uaccess.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/io.h>
  30. +#include <linux/clk.h>
  31. #include <asm/byteorder.h>
  32. #include <asm/irq.h>
  33. @@ -5596,7 +5597,7 @@ static int fotg210_hcd_probe(struct plat
  34. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  35. if (IS_ERR(hcd->regs)) {
  36. retval = PTR_ERR(hcd->regs);
  37. - goto failed;
  38. + goto failed_put_hcd;
  39. }
  40. hcd->rsrc_start = res->start;
  41. @@ -5606,22 +5607,42 @@ static int fotg210_hcd_probe(struct plat
  42. fotg210->caps = hcd->regs;
  43. + /* It's OK not to supply this clock */
  44. + fotg210->pclk = clk_get(dev, "PCLK");
  45. + if (!IS_ERR(fotg210->pclk)) {
  46. + retval = clk_prepare_enable(fotg210->pclk);
  47. + if (retval) {
  48. + dev_err(dev, "failed to enable PCLK\n");
  49. + goto failed_put_hcd;
  50. + }
  51. + } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
  52. + /*
  53. + * Percolate deferrals, for anything else,
  54. + * just live without the clocking.
  55. + */
  56. + retval = PTR_ERR(fotg210->pclk);
  57. + goto failed_dis_clk;
  58. + }
  59. +
  60. retval = fotg210_setup(hcd);
  61. if (retval)
  62. - goto failed;
  63. + goto failed_dis_clk;
  64. fotg210_init(fotg210);
  65. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  66. if (retval) {
  67. dev_err(dev, "failed to add hcd with err %d\n", retval);
  68. - goto failed;
  69. + goto failed_dis_clk;
  70. }
  71. device_wakeup_enable(hcd->self.controller);
  72. return retval;
  73. -failed:
  74. +failed_dis_clk:
  75. + if (!IS_ERR(fotg210->pclk))
  76. + clk_disable_unprepare(fotg210->pclk);
  77. +failed_put_hcd:
  78. usb_put_hcd(hcd);
  79. fail_create_hcd:
  80. dev_err(dev, "init %s fail, %d\n", dev_name(dev), retval);
  81. @@ -5637,6 +5658,10 @@ static int fotg210_hcd_remove(struct pla
  82. {
  83. struct device *dev = &pdev->dev;
  84. struct usb_hcd *hcd = dev_get_drvdata(dev);
  85. + struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
  86. +
  87. + if (!IS_ERR(fotg210->pclk))
  88. + clk_disable_unprepare(fotg210->pclk);
  89. if (!hcd)
  90. return 0;
  91. --- a/drivers/usb/host/fotg210.h
  92. +++ b/drivers/usb/host/fotg210.h
  93. @@ -182,6 +182,9 @@ struct fotg210_hcd { /* one per contro
  94. # define COUNT(x)
  95. #endif
  96. + /* silicon clock */
  97. + struct clk *pclk;
  98. +
  99. /* debug files */
  100. struct dentry *debug_dir;
  101. };