0017-usb-fotg210-Acquire-memory-resource-in-core.patch 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. From fa735ad1afeb5791d5562617b9bbed74574d3e81 Mon Sep 17 00:00:00 2001
  2. From: Linus Walleij <[email protected]>
  3. Date: Wed, 18 Jan 2023 08:09:17 +0100
  4. Subject: [PATCH 17/29] usb: fotg210: Acquire memory resource in core
  5. The subdrivers are obtaining and mapping the memory resource
  6. separately. Create a common state container for the shared
  7. resources and start populating this by acquiring the IO
  8. memory resource and remap it and pass this to the subdrivers
  9. for host and peripheral.
  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. @@ -33,9 +33,10 @@
  17. #define GEMINI_MISC_USB0_MINI_B BIT(29)
  18. #define GEMINI_MISC_USB1_MINI_B BIT(30)
  19. -static int fotg210_gemini_init(struct device *dev, struct resource *res,
  20. +static int fotg210_gemini_init(struct fotg210 *fotg, struct resource *res,
  21. enum usb_dr_mode mode)
  22. {
  23. + struct device *dev = fotg->dev;
  24. struct device_node *np = dev->of_node;
  25. struct regmap *map;
  26. bool wakeup;
  27. @@ -47,6 +48,7 @@ static int fotg210_gemini_init(struct de
  28. dev_err(dev, "no syscon\n");
  29. return PTR_ERR(map);
  30. }
  31. + fotg->map = map;
  32. wakeup = of_property_read_bool(np, "wakeup-source");
  33. /*
  34. @@ -55,6 +57,7 @@ static int fotg210_gemini_init(struct de
  35. */
  36. mask = 0;
  37. if (res->start == 0x69000000) {
  38. + fotg->port = GEMINI_PORT_1;
  39. mask = GEMINI_MISC_USB1_VBUS_ON | GEMINI_MISC_USB1_MINI_B |
  40. GEMINI_MISC_USB1_WAKEUP;
  41. if (mode == USB_DR_MODE_HOST)
  42. @@ -64,6 +67,7 @@ static int fotg210_gemini_init(struct de
  43. if (wakeup)
  44. val |= GEMINI_MISC_USB1_WAKEUP;
  45. } else {
  46. + fotg->port = GEMINI_PORT_0;
  47. mask = GEMINI_MISC_USB0_VBUS_ON | GEMINI_MISC_USB0_MINI_B |
  48. GEMINI_MISC_USB0_WAKEUP;
  49. if (mode == USB_DR_MODE_HOST)
  50. @@ -89,23 +93,34 @@ static int fotg210_probe(struct platform
  51. {
  52. struct device *dev = &pdev->dev;
  53. enum usb_dr_mode mode;
  54. + struct fotg210 *fotg;
  55. int ret;
  56. + fotg = devm_kzalloc(dev, sizeof(*fotg), GFP_KERNEL);
  57. + if (!fotg)
  58. + return -ENOMEM;
  59. + fotg->dev = dev;
  60. +
  61. + fotg->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  62. + if (!fotg->res)
  63. + return -ENODEV;
  64. +
  65. + fotg->base = devm_ioremap_resource(dev, fotg->res);
  66. + if (!fotg->base)
  67. + return -ENOMEM;
  68. +
  69. mode = usb_get_dr_mode(dev);
  70. if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
  71. - struct resource *res;
  72. -
  73. - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  74. - ret = fotg210_gemini_init(dev, res, mode);
  75. + ret = fotg210_gemini_init(fotg, fotg->res, mode);
  76. if (ret)
  77. return ret;
  78. }
  79. if (mode == USB_DR_MODE_PERIPHERAL)
  80. - ret = fotg210_udc_probe(pdev);
  81. + ret = fotg210_udc_probe(pdev, fotg);
  82. else
  83. - ret = fotg210_hcd_probe(pdev);
  84. + ret = fotg210_hcd_probe(pdev, fotg);
  85. return ret;
  86. }
  87. --- a/drivers/usb/fotg210/fotg210-hcd.c
  88. +++ b/drivers/usb/fotg210/fotg210-hcd.c
  89. @@ -5557,11 +5557,10 @@ static void fotg210_init(struct fotg210_
  90. * then invokes the start() method for the HCD associated with it
  91. * through the hotplug entry's driver_data.
  92. */
  93. -int fotg210_hcd_probe(struct platform_device *pdev)
  94. +int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg)
  95. {
  96. struct device *dev = &pdev->dev;
  97. struct usb_hcd *hcd;
  98. - struct resource *res;
  99. int irq;
  100. int retval;
  101. struct fotg210_hcd *fotg210;
  102. @@ -5585,18 +5584,14 @@ int fotg210_hcd_probe(struct platform_de
  103. hcd->has_tt = 1;
  104. - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  105. - hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  106. - if (IS_ERR(hcd->regs)) {
  107. - retval = PTR_ERR(hcd->regs);
  108. - goto failed_put_hcd;
  109. - }
  110. + hcd->regs = fotg->base;
  111. - hcd->rsrc_start = res->start;
  112. - hcd->rsrc_len = resource_size(res);
  113. + hcd->rsrc_start = fotg->res->start;
  114. + hcd->rsrc_len = resource_size(fotg->res);
  115. fotg210 = hcd_to_fotg210(hcd);
  116. + fotg210->fotg = fotg;
  117. fotg210->caps = hcd->regs;
  118. /* It's OK not to supply this clock */
  119. --- a/drivers/usb/fotg210/fotg210-hcd.h
  120. +++ b/drivers/usb/fotg210/fotg210-hcd.h
  121. @@ -182,6 +182,7 @@ struct fotg210_hcd { /* one per contro
  122. # define INCR(x) do {} while (0)
  123. #endif
  124. + struct fotg210 *fotg; /* Overarching FOTG210 device */
  125. /* silicon clock */
  126. struct clk *pclk;
  127. };
  128. --- a/drivers/usb/fotg210/fotg210-udc.c
  129. +++ b/drivers/usb/fotg210/fotg210-udc.c
  130. @@ -1155,21 +1155,14 @@ int fotg210_udc_remove(struct platform_d
  131. return 0;
  132. }
  133. -int fotg210_udc_probe(struct platform_device *pdev)
  134. +int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg)
  135. {
  136. - struct resource *res;
  137. struct fotg210_udc *fotg210 = NULL;
  138. struct device *dev = &pdev->dev;
  139. int irq;
  140. int ret = 0;
  141. int i;
  142. - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  143. - if (!res) {
  144. - pr_err("platform_get_resource error.\n");
  145. - return -ENODEV;
  146. - }
  147. -
  148. irq = platform_get_irq(pdev, 0);
  149. if (irq < 0) {
  150. pr_err("could not get irq\n");
  151. @@ -1182,6 +1175,7 @@ int fotg210_udc_probe(struct platform_de
  152. return -ENOMEM;
  153. fotg210->dev = dev;
  154. + fotg210->fotg = fotg;
  155. /* It's OK not to supply this clock */
  156. fotg210->pclk = devm_clk_get(dev, "PCLK");
  157. @@ -1222,11 +1216,7 @@ int fotg210_udc_probe(struct platform_de
  158. goto err_alloc;
  159. }
  160. - fotg210->reg = ioremap(res->start, resource_size(res));
  161. - if (fotg210->reg == NULL) {
  162. - dev_err(dev, "ioremap error\n");
  163. - goto err_alloc;
  164. - }
  165. + fotg210->reg = fotg->base;
  166. spin_lock_init(&fotg210->lock);
  167. --- a/drivers/usb/fotg210/fotg210-udc.h
  168. +++ b/drivers/usb/fotg210/fotg210-udc.h
  169. @@ -236,6 +236,7 @@ struct fotg210_udc {
  170. unsigned long irq_trigger;
  171. struct device *dev;
  172. + struct fotg210 *fotg;
  173. struct usb_phy *phy;
  174. struct usb_gadget gadget;
  175. struct usb_gadget_driver *driver;
  176. --- a/drivers/usb/fotg210/fotg210.h
  177. +++ b/drivers/usb/fotg210/fotg210.h
  178. @@ -2,13 +2,28 @@
  179. #ifndef __FOTG210_H
  180. #define __FOTG210_H
  181. +enum gemini_port {
  182. + GEMINI_PORT_NONE = 0,
  183. + GEMINI_PORT_0,
  184. + GEMINI_PORT_1,
  185. +};
  186. +
  187. +struct fotg210 {
  188. + struct device *dev;
  189. + struct resource *res;
  190. + void __iomem *base;
  191. + struct regmap *map;
  192. + enum gemini_port port;
  193. +};
  194. +
  195. #ifdef CONFIG_USB_FOTG210_HCD
  196. -int fotg210_hcd_probe(struct platform_device *pdev);
  197. +int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg);
  198. int fotg210_hcd_remove(struct platform_device *pdev);
  199. int fotg210_hcd_init(void);
  200. void fotg210_hcd_cleanup(void);
  201. #else
  202. -static inline int fotg210_hcd_probe(struct platform_device *pdev)
  203. +static inline int fotg210_hcd_probe(struct platform_device *pdev,
  204. + struct fotg210 *fotg)
  205. {
  206. return 0;
  207. }
  208. @@ -26,10 +41,11 @@ static inline void fotg210_hcd_cleanup(v
  209. #endif
  210. #ifdef CONFIG_USB_FOTG210_UDC
  211. -int fotg210_udc_probe(struct platform_device *pdev);
  212. +int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg);
  213. int fotg210_udc_remove(struct platform_device *pdev);
  214. #else
  215. -static inline int fotg210_udc_probe(struct platform_device *pdev)
  216. +static inline int fotg210_udc_probe(struct platform_device *pdev,
  217. + struct fotg210 *fotg)
  218. {
  219. return 0;
  220. }