0018-usb-fotg210-Move-clock-handling-to-core.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. From fb8e1e8dbc47e7aff7624b47adaa0a84d2983802 Mon Sep 17 00:00:00 2001
  2. From: Linus Walleij <[email protected]>
  3. Date: Wed, 18 Jan 2023 08:09:18 +0100
  4. Subject: [PATCH 18/29] usb: fotg210: Move clock handling to core
  5. Grab the optional silicon block clock, prepare and enable it in
  6. the core before proceeding to prepare the host or peripheral
  7. driver. This saves duplicate code and also uses the simple
  8. devm_clk_get_optional_enabled() to do everything we really
  9. want to do.
  10. Signed-off-by: Linus Walleij <[email protected]>
  11. Link: https://lore.kernel.org/r/[email protected]
  12. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  13. ---
  14. --- a/drivers/usb/fotg210/fotg210-core.c
  15. +++ b/drivers/usb/fotg210/fotg210-core.c
  16. @@ -6,6 +6,7 @@
  17. * driver.
  18. */
  19. #include <linux/bitops.h>
  20. +#include <linux/clk.h>
  21. #include <linux/device.h>
  22. #include <linux/mfd/syscon.h>
  23. #include <linux/module.h>
  24. @@ -109,6 +110,10 @@ static int fotg210_probe(struct platform
  25. if (!fotg->base)
  26. return -ENOMEM;
  27. + fotg->pclk = devm_clk_get_optional_enabled(dev, "PCLK");
  28. + if (IS_ERR(fotg->pclk))
  29. + return PTR_ERR(fotg->pclk);
  30. +
  31. mode = usb_get_dr_mode(dev);
  32. if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
  33. --- a/drivers/usb/fotg210/fotg210-hcd.c
  34. +++ b/drivers/usb/fotg210/fotg210-hcd.c
  35. @@ -33,7 +33,6 @@
  36. #include <linux/platform_device.h>
  37. #include <linux/io.h>
  38. #include <linux/iopoll.h>
  39. -#include <linux/clk.h>
  40. #include <asm/byteorder.h>
  41. #include <asm/irq.h>
  42. @@ -5594,44 +5593,22 @@ int fotg210_hcd_probe(struct platform_de
  43. fotg210->fotg = fotg;
  44. fotg210->caps = hcd->regs;
  45. - /* It's OK not to supply this clock */
  46. - fotg210->pclk = clk_get(dev, "PCLK");
  47. - if (!IS_ERR(fotg210->pclk)) {
  48. - retval = clk_prepare_enable(fotg210->pclk);
  49. - if (retval) {
  50. - dev_err(dev, "failed to enable PCLK\n");
  51. - goto failed_put_hcd;
  52. - }
  53. - } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
  54. - /*
  55. - * Percolate deferrals, for anything else,
  56. - * just live without the clocking.
  57. - */
  58. - retval = PTR_ERR(fotg210->pclk);
  59. - goto failed_dis_clk;
  60. - }
  61. -
  62. retval = fotg210_setup(hcd);
  63. if (retval)
  64. - goto failed_dis_clk;
  65. + goto failed_put_hcd;
  66. fotg210_init(fotg210);
  67. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  68. if (retval) {
  69. dev_err(dev, "failed to add hcd with err %d\n", retval);
  70. - goto failed_dis_clk;
  71. + goto failed_put_hcd;
  72. }
  73. device_wakeup_enable(hcd->self.controller);
  74. platform_set_drvdata(pdev, hcd);
  75. return retval;
  76. -failed_dis_clk:
  77. - if (!IS_ERR(fotg210->pclk)) {
  78. - clk_disable_unprepare(fotg210->pclk);
  79. - clk_put(fotg210->pclk);
  80. - }
  81. failed_put_hcd:
  82. usb_put_hcd(hcd);
  83. fail_create_hcd:
  84. @@ -5647,12 +5624,6 @@ fail_create_hcd:
  85. int fotg210_hcd_remove(struct platform_device *pdev)
  86. {
  87. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  88. - struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
  89. -
  90. - if (!IS_ERR(fotg210->pclk)) {
  91. - clk_disable_unprepare(fotg210->pclk);
  92. - clk_put(fotg210->pclk);
  93. - }
  94. usb_remove_hcd(hcd);
  95. usb_put_hcd(hcd);
  96. --- a/drivers/usb/fotg210/fotg210-udc.c
  97. +++ b/drivers/usb/fotg210/fotg210-udc.c
  98. @@ -15,7 +15,6 @@
  99. #include <linux/platform_device.h>
  100. #include <linux/usb/ch9.h>
  101. #include <linux/usb/gadget.h>
  102. -#include <linux/clk.h>
  103. #include <linux/usb/otg.h>
  104. #include <linux/usb/phy.h>
  105. @@ -1147,9 +1146,6 @@ int fotg210_udc_remove(struct platform_d
  106. for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
  107. kfree(fotg210->ep[i]);
  108. - if (!IS_ERR(fotg210->pclk))
  109. - clk_disable_unprepare(fotg210->pclk);
  110. -
  111. kfree(fotg210);
  112. return 0;
  113. @@ -1177,34 +1173,17 @@ int fotg210_udc_probe(struct platform_de
  114. fotg210->dev = dev;
  115. fotg210->fotg = fotg;
  116. - /* It's OK not to supply this clock */
  117. - fotg210->pclk = devm_clk_get(dev, "PCLK");
  118. - if (!IS_ERR(fotg210->pclk)) {
  119. - ret = clk_prepare_enable(fotg210->pclk);
  120. - if (ret) {
  121. - dev_err(dev, "failed to enable PCLK\n");
  122. - goto err;
  123. - }
  124. - } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
  125. - /*
  126. - * Percolate deferrals, for anything else,
  127. - * just live without the clocking.
  128. - */
  129. - ret = -EPROBE_DEFER;
  130. - goto err;
  131. - }
  132. -
  133. fotg210->phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
  134. if (IS_ERR(fotg210->phy)) {
  135. ret = PTR_ERR(fotg210->phy);
  136. if (ret == -EPROBE_DEFER)
  137. - goto err_pclk;
  138. + goto err_free;
  139. dev_info(dev, "no PHY found\n");
  140. fotg210->phy = NULL;
  141. } else {
  142. ret = usb_phy_init(fotg210->phy);
  143. if (ret)
  144. - goto err_pclk;
  145. + goto err_free;
  146. dev_info(dev, "found and initialized PHY\n");
  147. }
  148. @@ -1303,11 +1282,8 @@ err_map:
  149. err_alloc:
  150. for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
  151. kfree(fotg210->ep[i]);
  152. -err_pclk:
  153. - if (!IS_ERR(fotg210->pclk))
  154. - clk_disable_unprepare(fotg210->pclk);
  155. -err:
  156. +err_free:
  157. kfree(fotg210);
  158. return ret;
  159. }
  160. --- a/drivers/usb/fotg210/fotg210-udc.h
  161. +++ b/drivers/usb/fotg210/fotg210-udc.h
  162. @@ -231,7 +231,6 @@ struct fotg210_ep {
  163. struct fotg210_udc {
  164. spinlock_t lock; /* protect the struct */
  165. void __iomem *reg;
  166. - struct clk *pclk;
  167. unsigned long irq_trigger;
  168. --- a/drivers/usb/fotg210/fotg210.h
  169. +++ b/drivers/usb/fotg210/fotg210.h
  170. @@ -12,6 +12,7 @@ struct fotg210 {
  171. struct device *dev;
  172. struct resource *res;
  173. void __iomem *base;
  174. + struct clk *pclk;
  175. struct regmap *map;
  176. enum gemini_port port;
  177. };