0003-usb-fotg210-Compile-into-one-module.patch 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. From 0dbc77a99267a5efef0603a4b49ac02ece6a3f23 Mon Sep 17 00:00:00 2001
  2. From: Linus Walleij <[email protected]>
  3. Date: Sun, 23 Oct 2022 16:47:07 +0200
  4. Subject: [PATCH 03/29] usb: fotg210: Compile into one module
  5. It is since ages perfectly possible to compile both of these
  6. modules into the same kernel, which makes no sense since it
  7. is one piece of hardware.
  8. Compile one module named "fotg210.ko" for both HCD and UDC
  9. drivers by collecting the init calls into a fotg210-core.c
  10. file and start to centralize things handling one and the same
  11. piece of hardware.
  12. Stub out the initcalls if one or the other part of the driver
  13. was not selected.
  14. Tested by compiling one or the other or both of the drivers
  15. into the kernel and as modules.
  16. Cc: Fabian Vogt <[email protected]>
  17. Cc: Yuan-Hsin Chen <[email protected]>
  18. Cc: Felipe Balbi <[email protected]>
  19. Signed-off-by: Linus Walleij <[email protected]>
  20. Link: https://lore.kernel.org/r/[email protected]
  21. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  22. ---
  23. --- a/drivers/usb/fotg210/Kconfig
  24. +++ b/drivers/usb/fotg210/Kconfig
  25. @@ -12,7 +12,7 @@ config USB_FOTG210
  26. if USB_FOTG210
  27. config USB_FOTG210_HCD
  28. - tristate "Faraday FOTG210 USB Host Controller support"
  29. + bool "Faraday FOTG210 USB Host Controller support"
  30. depends on USB
  31. help
  32. Faraday FOTG210 is an OTG controller which can be configured as
  33. @@ -24,7 +24,7 @@ config USB_FOTG210_HCD
  34. config USB_FOTG210_UDC
  35. depends on USB_GADGET
  36. - tristate "Faraday FOTG210 USB Peripheral Controller support"
  37. + bool "Faraday FOTG210 USB Peripheral Controller support"
  38. help
  39. Faraday USB2.0 OTG controller which can be configured as
  40. high speed or full speed USB device. This driver suppports
  41. --- a/drivers/usb/fotg210/Makefile
  42. +++ b/drivers/usb/fotg210/Makefile
  43. @@ -1,3 +1,10 @@
  44. # SPDX-License-Identifier: GPL-2.0
  45. -obj-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o
  46. -obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
  47. +
  48. +# This setup links the different object files into one single
  49. +# module so we don't have to EXPORT() a lot of internal symbols
  50. +# or create unnecessary submodules.
  51. +fotg210-objs-y += fotg210-core.o
  52. +fotg210-objs-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o
  53. +fotg210-objs-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
  54. +fotg210-objs := $(fotg210-objs-y)
  55. +obj-$(CONFIG_USB_FOTG210) += fotg210.o
  56. --- /dev/null
  57. +++ b/drivers/usb/fotg210/fotg210-core.c
  58. @@ -0,0 +1,79 @@
  59. +// SPDX-License-Identifier: GPL-2.0+
  60. +/*
  61. + * Central probing code for the FOTG210 dual role driver
  62. + * We register one driver for the hardware and then we decide
  63. + * whether to proceed with probing the host or the peripheral
  64. + * driver.
  65. + */
  66. +#include <linux/device.h>
  67. +#include <linux/module.h>
  68. +#include <linux/of.h>
  69. +#include <linux/platform_device.h>
  70. +#include <linux/usb.h>
  71. +
  72. +#include "fotg210.h"
  73. +
  74. +static int fotg210_probe(struct platform_device *pdev)
  75. +{
  76. + int ret;
  77. +
  78. + if (IS_ENABLED(CONFIG_USB_FOTG210_HCD)) {
  79. + ret = fotg210_hcd_probe(pdev);
  80. + if (ret)
  81. + return ret;
  82. + }
  83. + if (IS_ENABLED(CONFIG_USB_FOTG210_UDC))
  84. + ret = fotg210_udc_probe(pdev);
  85. +
  86. + return ret;
  87. +}
  88. +
  89. +static int fotg210_remove(struct platform_device *pdev)
  90. +{
  91. + if (IS_ENABLED(CONFIG_USB_FOTG210_HCD))
  92. + fotg210_hcd_remove(pdev);
  93. + if (IS_ENABLED(CONFIG_USB_FOTG210_UDC))
  94. + fotg210_udc_remove(pdev);
  95. +
  96. + return 0;
  97. +}
  98. +
  99. +#ifdef CONFIG_OF
  100. +static const struct of_device_id fotg210_of_match[] = {
  101. + { .compatible = "faraday,fotg210" },
  102. + {},
  103. +};
  104. +MODULE_DEVICE_TABLE(of, fotg210_of_match);
  105. +#endif
  106. +
  107. +static struct platform_driver fotg210_driver = {
  108. + .driver = {
  109. + .name = "fotg210",
  110. + .of_match_table = of_match_ptr(fotg210_of_match),
  111. + },
  112. + .probe = fotg210_probe,
  113. + .remove = fotg210_remove,
  114. +};
  115. +
  116. +static int __init fotg210_init(void)
  117. +{
  118. + if (usb_disabled())
  119. + return -ENODEV;
  120. +
  121. + if (IS_ENABLED(CONFIG_USB_FOTG210_HCD))
  122. + fotg210_hcd_init();
  123. + return platform_driver_register(&fotg210_driver);
  124. +}
  125. +module_init(fotg210_init);
  126. +
  127. +static void __exit fotg210_cleanup(void)
  128. +{
  129. + platform_driver_unregister(&fotg210_driver);
  130. + if (IS_ENABLED(CONFIG_USB_FOTG210_HCD))
  131. + fotg210_hcd_cleanup();
  132. +}
  133. +module_exit(fotg210_cleanup);
  134. +
  135. +MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang");
  136. +MODULE_LICENSE("GPL");
  137. +MODULE_DESCRIPTION("FOTG210 Dual Role Controller Driver");
  138. --- a/drivers/usb/fotg210/fotg210-hcd.c
  139. +++ b/drivers/usb/fotg210/fotg210-hcd.c
  140. @@ -39,8 +39,8 @@
  141. #include <asm/irq.h>
  142. #include <asm/unaligned.h>
  143. -#define DRIVER_AUTHOR "Yuan-Hsin Chen"
  144. -#define DRIVER_DESC "FOTG210 Host Controller (EHCI) Driver"
  145. +#include "fotg210.h"
  146. +
  147. static const char hcd_name[] = "fotg210_hcd";
  148. #undef FOTG210_URB_TRACE
  149. @@ -5490,9 +5490,6 @@ static int fotg210_get_frame(struct usb_
  150. * functions and in order to facilitate role switching we cannot
  151. * give the fotg210 driver exclusive access to those.
  152. */
  153. -MODULE_DESCRIPTION(DRIVER_DESC);
  154. -MODULE_AUTHOR(DRIVER_AUTHOR);
  155. -MODULE_LICENSE("GPL");
  156. static const struct hc_driver fotg210_fotg210_hc_driver = {
  157. .description = hcd_name,
  158. @@ -5560,7 +5557,7 @@ static void fotg210_init(struct fotg210_
  159. * then invokes the start() method for the HCD associated with it
  160. * through the hotplug entry's driver_data.
  161. */
  162. -static int fotg210_hcd_probe(struct platform_device *pdev)
  163. +int fotg210_hcd_probe(struct platform_device *pdev)
  164. {
  165. struct device *dev = &pdev->dev;
  166. struct usb_hcd *hcd;
  167. @@ -5652,7 +5649,7 @@ fail_create_hcd:
  168. * @dev: USB Host Controller being removed
  169. *
  170. */
  171. -static int fotg210_hcd_remove(struct platform_device *pdev)
  172. +int fotg210_hcd_remove(struct platform_device *pdev)
  173. {
  174. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  175. struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
  176. @@ -5668,27 +5665,8 @@ static int fotg210_hcd_remove(struct pla
  177. return 0;
  178. }
  179. -#ifdef CONFIG_OF
  180. -static const struct of_device_id fotg210_of_match[] = {
  181. - { .compatible = "faraday,fotg210" },
  182. - {},
  183. -};
  184. -MODULE_DEVICE_TABLE(of, fotg210_of_match);
  185. -#endif
  186. -
  187. -static struct platform_driver fotg210_hcd_driver = {
  188. - .driver = {
  189. - .name = "fotg210-hcd",
  190. - .of_match_table = of_match_ptr(fotg210_of_match),
  191. - },
  192. - .probe = fotg210_hcd_probe,
  193. - .remove = fotg210_hcd_remove,
  194. -};
  195. -
  196. -static int __init fotg210_hcd_init(void)
  197. +int __init fotg210_hcd_init(void)
  198. {
  199. - int retval = 0;
  200. -
  201. if (usb_disabled())
  202. return -ENODEV;
  203. @@ -5704,24 +5682,11 @@ static int __init fotg210_hcd_init(void)
  204. fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root);
  205. - retval = platform_driver_register(&fotg210_hcd_driver);
  206. - if (retval < 0)
  207. - goto clean;
  208. - return retval;
  209. -
  210. -clean:
  211. - debugfs_remove(fotg210_debug_root);
  212. - fotg210_debug_root = NULL;
  213. -
  214. - clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  215. - return retval;
  216. + return 0;
  217. }
  218. -module_init(fotg210_hcd_init);
  219. -static void __exit fotg210_hcd_cleanup(void)
  220. +void __exit fotg210_hcd_cleanup(void)
  221. {
  222. - platform_driver_unregister(&fotg210_hcd_driver);
  223. debugfs_remove(fotg210_debug_root);
  224. clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
  225. }
  226. -module_exit(fotg210_hcd_cleanup);
  227. --- a/drivers/usb/fotg210/fotg210-udc.c
  228. +++ b/drivers/usb/fotg210/fotg210-udc.c
  229. @@ -16,6 +16,7 @@
  230. #include <linux/usb/ch9.h>
  231. #include <linux/usb/gadget.h>
  232. +#include "fotg210.h"
  233. #include "fotg210-udc.h"
  234. #define DRIVER_DESC "FOTG210 USB Device Controller Driver"
  235. @@ -1081,7 +1082,7 @@ static const struct usb_gadget_ops fotg2
  236. .udc_stop = fotg210_udc_stop,
  237. };
  238. -static int fotg210_udc_remove(struct platform_device *pdev)
  239. +int fotg210_udc_remove(struct platform_device *pdev)
  240. {
  241. struct fotg210_udc *fotg210 = platform_get_drvdata(pdev);
  242. int i;
  243. @@ -1098,7 +1099,7 @@ static int fotg210_udc_remove(struct pla
  244. return 0;
  245. }
  246. -static int fotg210_udc_probe(struct platform_device *pdev)
  247. +int fotg210_udc_probe(struct platform_device *pdev)
  248. {
  249. struct resource *res, *ires;
  250. struct fotg210_udc *fotg210 = NULL;
  251. @@ -1223,17 +1224,3 @@ err_alloc:
  252. err:
  253. return ret;
  254. }
  255. -
  256. -static struct platform_driver fotg210_driver = {
  257. - .driver = {
  258. - .name = udc_name,
  259. - },
  260. - .probe = fotg210_udc_probe,
  261. - .remove = fotg210_udc_remove,
  262. -};
  263. -
  264. -module_platform_driver(fotg210_driver);
  265. -
  266. -MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang <[email protected]>");
  267. -MODULE_LICENSE("GPL");
  268. -MODULE_DESCRIPTION(DRIVER_DESC);
  269. --- /dev/null
  270. +++ b/drivers/usb/fotg210/fotg210.h
  271. @@ -0,0 +1,42 @@
  272. +/* SPDX-License-Identifier: GPL-2.0 */
  273. +#ifndef __FOTG210_H
  274. +#define __FOTG210_H
  275. +
  276. +#ifdef CONFIG_USB_FOTG210_HCD
  277. +int fotg210_hcd_probe(struct platform_device *pdev);
  278. +int fotg210_hcd_remove(struct platform_device *pdev);
  279. +int fotg210_hcd_init(void);
  280. +void fotg210_hcd_cleanup(void);
  281. +#else
  282. +static inline int fotg210_hcd_probe(struct platform_device *pdev)
  283. +{
  284. + return 0;
  285. +}
  286. +static inline int fotg210_hcd_remove(struct platform_device *pdev)
  287. +{
  288. + return 0;
  289. +}
  290. +static inline int fotg210_hcd_init(void)
  291. +{
  292. + return 0;
  293. +}
  294. +static inline void fotg210_hcd_cleanup(void)
  295. +{
  296. +}
  297. +#endif
  298. +
  299. +#ifdef CONFIG_USB_FOTG210_UDC
  300. +int fotg210_udc_probe(struct platform_device *pdev);
  301. +int fotg210_udc_remove(struct platform_device *pdev);
  302. +#else
  303. +static inline int fotg210_udc_probe(struct platform_device *pdev)
  304. +{
  305. + return 0;
  306. +}
  307. +static inline int fotg210_udc_remove(struct platform_device *pdev)
  308. +{
  309. + return 0;
  310. +}
  311. +#endif
  312. +
  313. +#endif /* __FOTG210_H */