PageRenderTime 26ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/target/linux/sunxi/patches-3.13/180-1-usb-ohci-platform-dt-instantiation.patch

https://gitlab.com/shinvdu/openwrt
Patch | 322 lines | 295 code | 27 blank | 0 comment | 0 complexity | cd3b4bab503efd118b7c2e4feb2ae978 MD5 | raw file
  1. From 6b63b9b2093258541dd79a3ed311cd1d0412b846 Mon Sep 17 00:00:00 2001
  2. From: Hans de Goede <hdegoede@redhat.com>
  3. Date: Sun, 5 Jan 2014 14:42:39 +0100
  4. Subject: [PATCH] ohci-platform: Add support for devicetree instantiation
  5. Add support for ohci-platform instantiation from devicetree, including
  6. optionally getting clks and a phy from devicetree, and enabling / disabling
  7. those on power_on / off.
  8. This should allow using ohci-platform from devicetree in various cases.
  9. Specifically after this commit it can be used for the ohci controller found
  10. on Allwinner sunxi SoCs.
  11. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  12. Acked-by: Alan Stern <stern@rowland.harvard.edu>
  13. ---
  14. Documentation/devicetree/bindings/usb/usb-ohci.txt | 22 +++
  15. drivers/usb/host/ohci-platform.c | 162 ++++++++++++++++++---
  16. 2 files changed, 162 insertions(+), 22 deletions(-)
  17. create mode 100644 Documentation/devicetree/bindings/usb/usb-ohci.txt
  18. diff --git a/Documentation/devicetree/bindings/usb/usb-ohci.txt b/Documentation/devicetree/bindings/usb/usb-ohci.txt
  19. new file mode 100644
  20. index 0000000..6ba38d9
  21. --- /dev/null
  22. +++ b/Documentation/devicetree/bindings/usb/usb-ohci.txt
  23. @@ -0,0 +1,22 @@
  24. +USB OHCI controllers
  25. +
  26. +Required properties:
  27. +- compatible : "usb-ohci"
  28. +- reg : ohci controller register range (address and length)
  29. +- interrupts : ohci controller interrupt
  30. +
  31. +Optional properties:
  32. +- clocks : a list of phandle + clock specifier pairs
  33. +- phys : phandle + phy specifier pair
  34. +- phy-names : "usb"
  35. +
  36. +Example:
  37. +
  38. + ohci0: usb@01c14400 {
  39. + compatible = "allwinner,sun4i-a10-ohci", "usb-ohci";
  40. + reg = <0x01c14400 0x100>;
  41. + interrupts = <64>;
  42. + clocks = <&usb_clk 6>, <&ahb_gates 2>;
  43. + phys = <&usbphy 1>;
  44. + phy-names = "usb";
  45. + };
  46. diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
  47. index 68f674c..49304dd 100644
  48. --- a/drivers/usb/host/ohci-platform.c
  49. +++ b/drivers/usb/host/ohci-platform.c
  50. @@ -3,6 +3,7 @@
  51. *
  52. * Copyright 2007 Michael Buesch <m@bues.ch>
  53. * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
  54. + * Copyright 2014 Hans de Goede <hdegoede@redhat.com>
  55. *
  56. * Derived from the OCHI-SSB driver
  57. * Derived from the OHCI-PCI driver
  58. @@ -14,11 +15,14 @@
  59. * Licensed under the GNU/GPL. See COPYING for details.
  60. */
  61. +#include <linux/clk.h>
  62. +#include <linux/dma-mapping.h>
  63. #include <linux/hrtimer.h>
  64. #include <linux/io.h>
  65. #include <linux/kernel.h>
  66. #include <linux/module.h>
  67. #include <linux/err.h>
  68. +#include <linux/phy/phy.h>
  69. #include <linux/platform_device.h>
  70. #include <linux/usb/ohci_pdriver.h>
  71. #include <linux/usb.h>
  72. @@ -27,6 +31,13 @@
  73. #include "ohci.h"
  74. #define DRIVER_DESC "OHCI generic platform driver"
  75. +#define OHCI_MAX_CLKS 3
  76. +#define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv)
  77. +
  78. +struct ohci_platform_priv {
  79. + struct clk *clks[OHCI_MAX_CLKS];
  80. + struct phy *phy;
  81. +};
  82. static const char hcd_name[] = "ohci-platform";
  83. @@ -48,11 +59,67 @@ static int ohci_platform_reset(struct usb_hcd *hcd)
  84. return ohci_setup(hcd);
  85. }
  86. +static int ohci_platform_power_on(struct platform_device *dev)
  87. +{
  88. + struct usb_hcd *hcd = platform_get_drvdata(dev);
  89. + struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
  90. + int clk, ret;
  91. +
  92. + for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) {
  93. + ret = clk_prepare_enable(priv->clks[clk]);
  94. + if (ret)
  95. + goto err_disable_clks;
  96. + }
  97. +
  98. + if (priv->phy) {
  99. + ret = phy_init(priv->phy);
  100. + if (ret)
  101. + goto err_disable_clks;
  102. +
  103. + ret = phy_power_on(priv->phy);
  104. + if (ret)
  105. + goto err_exit_phy;
  106. + }
  107. +
  108. + return 0;
  109. +
  110. +err_exit_phy:
  111. + phy_exit(priv->phy);
  112. +err_disable_clks:
  113. + while (--clk >= 0)
  114. + clk_disable_unprepare(priv->clks[clk]);
  115. +
  116. + return ret;
  117. +}
  118. +
  119. +static void ohci_platform_power_off(struct platform_device *dev)
  120. +{
  121. + struct usb_hcd *hcd = platform_get_drvdata(dev);
  122. + struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
  123. + int clk;
  124. +
  125. + if (priv->phy) {
  126. + phy_power_off(priv->phy);
  127. + phy_exit(priv->phy);
  128. + }
  129. +
  130. + for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--)
  131. + if (priv->clks[clk])
  132. + clk_disable_unprepare(priv->clks[clk]);
  133. +}
  134. +
  135. static struct hc_driver __read_mostly ohci_platform_hc_driver;
  136. static const struct ohci_driver_overrides platform_overrides __initconst = {
  137. - .product_desc = "Generic Platform OHCI controller",
  138. - .reset = ohci_platform_reset,
  139. + .product_desc = "Generic Platform OHCI controller",
  140. + .reset = ohci_platform_reset,
  141. + .extra_priv_size = sizeof(struct ohci_platform_priv),
  142. +};
  143. +
  144. +static struct usb_ohci_pdata ohci_platform_defaults = {
  145. + .power_on = ohci_platform_power_on,
  146. + .power_suspend = ohci_platform_power_off,
  147. + .power_off = ohci_platform_power_off,
  148. };
  149. static int ohci_platform_probe(struct platform_device *dev)
  150. @@ -60,17 +127,23 @@ static int ohci_platform_probe(struct platform_device *dev)
  151. struct usb_hcd *hcd;
  152. struct resource *res_mem;
  153. struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
  154. - int irq;
  155. - int err = -ENOMEM;
  156. -
  157. - if (!pdata) {
  158. - WARN_ON(1);
  159. - return -ENODEV;
  160. - }
  161. + struct ohci_platform_priv *priv;
  162. + int err, irq, clk = 0;
  163. if (usb_disabled())
  164. return -ENODEV;
  165. + /*
  166. + * Use reasonable defaults so platforms don't have to provide these
  167. + * with DT probing on ARM.
  168. + */
  169. + if (!pdata)
  170. + pdata = &ohci_platform_defaults;
  171. +
  172. + err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
  173. + if (err)
  174. + return err;
  175. +
  176. irq = platform_get_irq(dev, 0);
  177. if (irq < 0) {
  178. dev_err(&dev->dev, "no irq provided");
  179. @@ -83,17 +156,40 @@ static int ohci_platform_probe(struct platform_device *dev)
  180. return -ENXIO;
  181. }
  182. + hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
  183. + dev_name(&dev->dev));
  184. + if (!hcd)
  185. + return -ENOMEM;
  186. +
  187. + platform_set_drvdata(dev, hcd);
  188. + dev->dev.platform_data = pdata;
  189. + priv = hcd_to_ohci_priv(hcd);
  190. +
  191. + if (pdata == &ohci_platform_defaults && dev->dev.of_node) {
  192. + priv->phy = devm_phy_get(&dev->dev, "usb");
  193. + if (IS_ERR(priv->phy)) {
  194. + err = PTR_ERR(priv->phy);
  195. + if (err == -EPROBE_DEFER)
  196. + goto err_put_hcd;
  197. + priv->phy = NULL;
  198. + }
  199. +
  200. + for (clk = 0; clk < OHCI_MAX_CLKS; clk++) {
  201. + priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
  202. + if (IS_ERR(priv->clks[clk])) {
  203. + err = PTR_ERR(priv->clks[clk]);
  204. + if (err == -EPROBE_DEFER)
  205. + goto err_put_clks;
  206. + priv->clks[clk] = NULL;
  207. + break;
  208. + }
  209. + }
  210. + }
  211. +
  212. if (pdata->power_on) {
  213. err = pdata->power_on(dev);
  214. if (err < 0)
  215. - return err;
  216. - }
  217. -
  218. - hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
  219. - dev_name(&dev->dev));
  220. - if (!hcd) {
  221. - err = -ENOMEM;
  222. - goto err_power;
  223. + goto err_put_clks;
  224. }
  225. hcd->rsrc_start = res_mem->start;
  226. @@ -102,11 +198,11 @@ static int ohci_platform_probe(struct platform_device *dev)
  227. hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
  228. if (IS_ERR(hcd->regs)) {
  229. err = PTR_ERR(hcd->regs);
  230. - goto err_put_hcd;
  231. + goto err_power;
  232. }
  233. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  234. if (err)
  235. - goto err_put_hcd;
  236. + goto err_power;
  237. device_wakeup_enable(hcd->self.controller);
  238. @@ -114,11 +210,17 @@ static int ohci_platform_probe(struct platform_device *dev)
  239. return err;
  240. -err_put_hcd:
  241. - usb_put_hcd(hcd);
  242. err_power:
  243. if (pdata->power_off)
  244. pdata->power_off(dev);
  245. +err_put_clks:
  246. + while (--clk >= 0)
  247. + clk_put(priv->clks[clk]);
  248. +err_put_hcd:
  249. + if (pdata == &ohci_platform_defaults)
  250. + dev->dev.platform_data = NULL;
  251. +
  252. + usb_put_hcd(hcd);
  253. return err;
  254. }
  255. @@ -127,13 +229,22 @@ static int ohci_platform_remove(struct platform_device *dev)
  256. {
  257. struct usb_hcd *hcd = platform_get_drvdata(dev);
  258. struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
  259. + struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
  260. + int clk;
  261. usb_remove_hcd(hcd);
  262. - usb_put_hcd(hcd);
  263. if (pdata->power_off)
  264. pdata->power_off(dev);
  265. + for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++)
  266. + clk_put(priv->clks[clk]);
  267. +
  268. + usb_put_hcd(hcd);
  269. +
  270. + if (pdata == &ohci_platform_defaults)
  271. + dev->dev.platform_data = NULL;
  272. +
  273. return 0;
  274. }
  275. @@ -180,6 +291,12 @@ static int ohci_platform_resume(struct device *dev)
  276. #define ohci_platform_resume NULL
  277. #endif /* CONFIG_PM */
  278. +static const struct of_device_id ohci_platform_ids[] = {
  279. + { .compatible = "usb-ohci", },
  280. + { }
  281. +};
  282. +MODULE_DEVICE_TABLE(of, ohci_platform_ids);
  283. +
  284. static const struct platform_device_id ohci_platform_table[] = {
  285. { "ohci-platform", 0 },
  286. { }
  287. @@ -200,6 +317,7 @@ static int ohci_platform_resume(struct device *dev)
  288. .owner = THIS_MODULE,
  289. .name = "ohci-platform",
  290. .pm = &ohci_platform_pm_ops,
  291. + .of_match_table = ohci_platform_ids,
  292. }
  293. };
  294. --
  295. 1.8.5.5