195-2-ehci-plat-changes.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. From 738b350437abfca820dae226549ecf4fb100fa30 Mon Sep 17 00:00:00 2001
  2. From: Hans de Goede <hdegoede@redhat.com>
  3. Date: Sun, 5 Jan 2014 00:04:02 +0100
  4. Subject: [PATCH] ehci-platform: Add support for clks and phy passed through
  5. devicetree
  6. Currently ehci-platform is only used in combination with devicetree when used
  7. with some Via socs. By extending it to (optionally) get clks and a phy from
  8. devicetree, and enabling / disabling those on power_on / off, it can be used
  9. more generically. Specifically after this commit it can be used for the
  10. ehci controller on Allwinner sunxi SoCs.
  11. Since ehci-platform is intended to handle any generic enough non pci ehci
  12. device, add a "usb-ehci" compatibility string.
  13. There already is a usb-ehci device-tree bindings document, update this
  14. with clks and phy bindings info.
  15. Although actually quite generic so far the via,vt8500 compatibilty string
  16. had its own bindings document. Somehow we even ended up with 2 of them. Since
  17. these provide no extra information over the generic usb-ehci documentation,
  18. this patch removes them.
  19. The ehci-ppc-of.c driver also claims the usb-ehci compatibility string,
  20. even though it mostly is ibm,usb-ehci-440epx specific. ehci-platform.c is
  21. not needed on ppc platforms, so add a !PPC_OF dependency to it to avoid
  22. 2 drivers claiming the same compatibility string getting build on ppc.
  23. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  24. Acked-by: Alan Stern <stern@rowland.harvard.edu>
  25. ---
  26. Documentation/devicetree/bindings/usb/usb-ehci.txt | 25 +++-
  27. .../devicetree/bindings/usb/via,vt8500-ehci.txt | 15 ---
  28. .../devicetree/bindings/usb/vt8500-ehci.txt | 12 --
  29. drivers/usb/host/Kconfig | 1 +
  30. drivers/usb/host/ehci-platform.c | 147 +++++++++++++++++----
  31. 5 files changed, 142 insertions(+), 58 deletions(-)
  32. delete mode 100644 Documentation/devicetree/bindings/usb/via,vt8500-ehci.txt
  33. delete mode 100644 Documentation/devicetree/bindings/usb/vt8500-ehci.txt
  34. --- a/Documentation/devicetree/bindings/usb/usb-ehci.txt
  35. +++ b/Documentation/devicetree/bindings/usb/usb-ehci.txt
  36. @@ -1,19 +1,20 @@
  37. USB EHCI controllers
  38. Required properties:
  39. - - compatible : should be "usb-ehci".
  40. + - compatible : should be "generic-ehci".
  41. - reg : should contain at least address and length of the standard EHCI
  42. register set for the device. Optional platform-dependent registers
  43. (debug-port or other) can be also specified here, but only after
  44. definition of standard EHCI registers.
  45. - interrupts : one EHCI interrupt should be described here.
  46. -If device registers are implemented in big endian mode, the device
  47. -node should have "big-endian-regs" property.
  48. -If controller implementation operates with big endian descriptors,
  49. -"big-endian-desc" property should be specified.
  50. -If both big endian registers and descriptors are used by the controller
  51. -implementation, "big-endian" property can be specified instead of having
  52. -both "big-endian-regs" and "big-endian-desc".
  53. +
  54. +Optional properties:
  55. + - big-endian-regs : boolean, set this for hcds with big-endian registers
  56. + - big-endian-desc : boolean, set this for hcds with big-endian descriptors
  57. + - big-endian : boolean, for hcds with big-endian-regs + big-endian-desc
  58. + - clocks : a list of phandle + clock specifier pairs
  59. + - phys : phandle + phy specifier pair
  60. + - phy-names : "usb"
  61. Example (Sequoia 440EPx):
  62. ehci@e0000300 {
  63. @@ -23,3 +24,13 @@ Example (Sequoia 440EPx):
  64. reg = <0 e0000300 90 0 e0000390 70>;
  65. big-endian;
  66. };
  67. +
  68. +Example (Allwinner sun4i A10 SoC):
  69. + ehci0: usb@01c14000 {
  70. + compatible = "allwinner,sun4i-a10-ehci", "generic-ehci";
  71. + reg = <0x01c14000 0x100>;
  72. + interrupts = <39>;
  73. + clocks = <&ahb_gates 1>;
  74. + phys = <&usbphy 1>;
  75. + phy-names = "usb";
  76. + };
  77. --- a/Documentation/devicetree/bindings/usb/via,vt8500-ehci.txt
  78. +++ /dev/null
  79. @@ -1,15 +0,0 @@
  80. -VIA/Wondermedia VT8500 EHCI Controller
  81. ------------------------------------------------------
  82. -
  83. -Required properties:
  84. -- compatible : "via,vt8500-ehci"
  85. -- reg : Should contain 1 register ranges(address and length)
  86. -- interrupts : ehci controller interrupt
  87. -
  88. -Example:
  89. -
  90. - ehci@d8007900 {
  91. - compatible = "via,vt8500-ehci";
  92. - reg = <0xd8007900 0x200>;
  93. - interrupts = <43>;
  94. - };
  95. --- a/Documentation/devicetree/bindings/usb/vt8500-ehci.txt
  96. +++ /dev/null
  97. @@ -1,12 +0,0 @@
  98. -VIA VT8500 and Wondermedia WM8xxx SoC USB controllers.
  99. -
  100. -Required properties:
  101. - - compatible: Should be "via,vt8500-ehci" or "wm,prizm-ehci".
  102. - - reg: Address range of the ehci registers. size should be 0x200
  103. - - interrupts: Should contain the ehci interrupt.
  104. -
  105. -usb: ehci@D8007100 {
  106. - compatible = "wm,prizm-ehci", "usb-ehci";
  107. - reg = <0xD8007100 0x200>;
  108. - interrupts = <1>;
  109. -};
  110. --- a/drivers/usb/host/ehci-platform.c
  111. +++ b/drivers/usb/host/ehci-platform.c
  112. @@ -3,6 +3,7 @@
  113. *
  114. * Copyright 2007 Steven Brown <sbrown@cortland.com>
  115. * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
  116. + * Copyright 2014 Hans de Goede <hdegoede@redhat.com>
  117. *
  118. * Derived from the ohci-ssb driver
  119. * Copyright 2007 Michael Buesch <m@bues.ch>
  120. @@ -18,6 +19,7 @@
  121. *
  122. * Licensed under the GNU/GPL. See COPYING for details.
  123. */
  124. +#include <linux/clk.h>
  125. #include <linux/dma-mapping.h>
  126. #include <linux/err.h>
  127. #include <linux/kernel.h>
  128. @@ -25,6 +27,7 @@
  129. #include <linux/io.h>
  130. #include <linux/module.h>
  131. #include <linux/of.h>
  132. +#include <linux/phy/phy.h>
  133. #include <linux/platform_device.h>
  134. #include <linux/usb.h>
  135. #include <linux/usb/hcd.h>
  136. @@ -33,6 +36,13 @@
  137. #include "ehci.h"
  138. #define DRIVER_DESC "EHCI generic platform driver"
  139. +#define EHCI_MAX_CLKS 3
  140. +#define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv)
  141. +
  142. +struct ehci_platform_priv {
  143. + struct clk *clks[EHCI_MAX_CLKS];
  144. + struct phy *phy;
  145. +};
  146. static const char hcd_name[] = "ehci-platform";
  147. @@ -45,8 +55,10 @@ static int ehci_platform_reset(struct us
  148. hcd->has_tt = pdata->has_tt;
  149. ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
  150. - ehci->big_endian_desc = pdata->big_endian_desc;
  151. - ehci->big_endian_mmio = pdata->big_endian_mmio;
  152. + if (pdata->big_endian_desc)
  153. + ehci->big_endian_desc = 1;
  154. + if (pdata->big_endian_mmio)
  155. + ehci->big_endian_mmio = 1;
  156. ehci->ignore_oc = pdata->ignore_oc;
  157. if (pdata->pre_setup) {
  158. @@ -65,38 +77,91 @@ static int ehci_platform_reset(struct us
  159. return 0;
  160. }
  161. +static int ehci_platform_power_on(struct platform_device *dev)
  162. +{
  163. + struct usb_hcd *hcd = platform_get_drvdata(dev);
  164. + struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
  165. + int clk, ret;
  166. +
  167. + for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++) {
  168. + ret = clk_prepare_enable(priv->clks[clk]);
  169. + if (ret)
  170. + goto err_disable_clks;
  171. + }
  172. +
  173. + if (priv->phy) {
  174. + ret = phy_init(priv->phy);
  175. + if (ret)
  176. + goto err_disable_clks;
  177. +
  178. + ret = phy_power_on(priv->phy);
  179. + if (ret)
  180. + goto err_exit_phy;
  181. + }
  182. +
  183. + return 0;
  184. +
  185. +err_exit_phy:
  186. + phy_exit(priv->phy);
  187. +err_disable_clks:
  188. + while (--clk >= 0)
  189. + clk_disable_unprepare(priv->clks[clk]);
  190. +
  191. + return ret;
  192. +}
  193. +
  194. +static void ehci_platform_power_off(struct platform_device *dev)
  195. +{
  196. + struct usb_hcd *hcd = platform_get_drvdata(dev);
  197. + struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
  198. + int clk;
  199. +
  200. + if (priv->phy) {
  201. + phy_power_off(priv->phy);
  202. + phy_exit(priv->phy);
  203. + }
  204. +
  205. + for (clk = EHCI_MAX_CLKS - 1; clk >= 0; clk--)
  206. + if (priv->clks[clk])
  207. + clk_disable_unprepare(priv->clks[clk]);
  208. +}
  209. +
  210. static struct hc_driver __read_mostly ehci_platform_hc_driver;
  211. static const struct ehci_driver_overrides platform_overrides __initconst = {
  212. - .reset = ehci_platform_reset,
  213. + .reset = ehci_platform_reset,
  214. + .extra_priv_size = sizeof(struct ehci_platform_priv),
  215. };
  216. -static struct usb_ehci_pdata ehci_platform_defaults;
  217. +static struct usb_ehci_pdata ehci_platform_defaults = {
  218. + .power_on = ehci_platform_power_on,
  219. + .power_suspend = ehci_platform_power_off,
  220. + .power_off = ehci_platform_power_off,
  221. +};
  222. static int ehci_platform_probe(struct platform_device *dev)
  223. {
  224. struct usb_hcd *hcd;
  225. struct resource *res_mem;
  226. - struct usb_ehci_pdata *pdata;
  227. - int irq;
  228. - int err;
  229. + struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
  230. + struct ehci_platform_priv *priv;
  231. + struct ehci_hcd *ehci;
  232. + int err, irq, clk = 0;
  233. if (usb_disabled())
  234. return -ENODEV;
  235. /*
  236. - * use reasonable defaults so platforms don't have to provide these.
  237. - * with DT probing on ARM, none of these are set.
  238. + * Use reasonable defaults so platforms don't have to provide these
  239. + * with DT probing on ARM.
  240. */
  241. - if (!dev_get_platdata(&dev->dev))
  242. - dev->dev.platform_data = &ehci_platform_defaults;
  243. + if (!pdata)
  244. + pdata = &ehci_platform_defaults;
  245. err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
  246. if (err)
  247. return err;
  248. - pdata = dev_get_platdata(&dev->dev);
  249. -
  250. irq = platform_get_irq(dev, 0);
  251. if (irq < 0) {
  252. dev_err(&dev->dev, "no irq provided");
  253. @@ -108,17 +173,66 @@ static int ehci_platform_probe(struct pl
  254. return -ENXIO;
  255. }
  256. + hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
  257. + dev_name(&dev->dev));
  258. + if (!hcd)
  259. + return -ENOMEM;
  260. +
  261. + platform_set_drvdata(dev, hcd);
  262. + dev->dev.platform_data = pdata;
  263. + priv = hcd_to_ehci_priv(hcd);
  264. + ehci = hcd_to_ehci(hcd);
  265. +
  266. + if (pdata == &ehci_platform_defaults && dev->dev.of_node) {
  267. + if (of_property_read_bool(dev->dev.of_node, "big-endian-regs"))
  268. + ehci->big_endian_mmio = 1;
  269. +
  270. + if (of_property_read_bool(dev->dev.of_node, "big-endian-desc"))
  271. + ehci->big_endian_desc = 1;
  272. +
  273. + if (of_property_read_bool(dev->dev.of_node, "big-endian"))
  274. + ehci->big_endian_mmio = ehci->big_endian_desc = 1;
  275. +
  276. +#ifndef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  277. + if (ehci->big_endian_mmio) {
  278. + dev_err(&dev->dev,
  279. + "Error big-endian-regs not compiled in\n");
  280. + err = -EINVAL;
  281. + goto err_put_hcd;
  282. + }
  283. +#endif
  284. +#ifndef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
  285. + if (ehci->big_endian_desc) {
  286. + dev_err(&dev->dev,
  287. + "Error big-endian-desc not compiled in\n");
  288. + err = -EINVAL;
  289. + goto err_put_hcd;
  290. + }
  291. +#endif
  292. + priv->phy = devm_phy_get(&dev->dev, "usb");
  293. + if (IS_ERR(priv->phy)) {
  294. + err = PTR_ERR(priv->phy);
  295. + if (err == -EPROBE_DEFER)
  296. + goto err_put_hcd;
  297. + priv->phy = NULL;
  298. + }
  299. +
  300. + for (clk = 0; clk < EHCI_MAX_CLKS; clk++) {
  301. + priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
  302. + if (IS_ERR(priv->clks[clk])) {
  303. + err = PTR_ERR(priv->clks[clk]);
  304. + if (err == -EPROBE_DEFER)
  305. + goto err_put_clks;
  306. + priv->clks[clk] = NULL;
  307. + break;
  308. + }
  309. + }
  310. + }
  311. +
  312. if (pdata->power_on) {
  313. err = pdata->power_on(dev);
  314. if (err < 0)
  315. - return err;
  316. - }
  317. -
  318. - hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
  319. - dev_name(&dev->dev));
  320. - if (!hcd) {
  321. - err = -ENOMEM;
  322. - goto err_power;
  323. + goto err_put_clks;
  324. }
  325. hcd->rsrc_start = res_mem->start;
  326. @@ -127,22 +241,28 @@ static int ehci_platform_probe(struct pl
  327. hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
  328. if (IS_ERR(hcd->regs)) {
  329. err = PTR_ERR(hcd->regs);
  330. - goto err_put_hcd;
  331. + goto err_power;
  332. }
  333. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  334. if (err)
  335. - goto err_put_hcd;
  336. + goto err_power;
  337. device_wakeup_enable(hcd->self.controller);
  338. platform_set_drvdata(dev, hcd);
  339. return err;
  340. -err_put_hcd:
  341. - usb_put_hcd(hcd);
  342. err_power:
  343. if (pdata->power_off)
  344. pdata->power_off(dev);
  345. +err_put_clks:
  346. + while (--clk >= 0)
  347. + clk_put(priv->clks[clk]);
  348. +err_put_hcd:
  349. + if (pdata == &ehci_platform_defaults)
  350. + dev->dev.platform_data = NULL;
  351. +
  352. + usb_put_hcd(hcd);
  353. return err;
  354. }
  355. @@ -151,13 +271,19 @@ static int ehci_platform_remove(struct p
  356. {
  357. struct usb_hcd *hcd = platform_get_drvdata(dev);
  358. struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
  359. + struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
  360. + int clk;
  361. usb_remove_hcd(hcd);
  362. - usb_put_hcd(hcd);
  363. if (pdata->power_off)
  364. pdata->power_off(dev);
  365. + for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++)
  366. + clk_put(priv->clks[clk]);
  367. +
  368. + usb_put_hcd(hcd);
  369. +
  370. if (pdata == &ehci_platform_defaults)
  371. dev->dev.platform_data = NULL;
  372. @@ -208,8 +334,10 @@ static int ehci_platform_resume(struct d
  373. static const struct of_device_id vt8500_ehci_ids[] = {
  374. { .compatible = "via,vt8500-ehci", },
  375. { .compatible = "wm,prizm-ehci", },
  376. + { .compatible = "generic-ehci", },
  377. {}
  378. };
  379. +MODULE_DEVICE_TABLE(of, vt8500_ehci_ids);
  380. static const struct platform_device_id ehci_platform_table[] = {
  381. { "ehci-platform", 0 },