0004-phy-add-ath79-usb-phys.patch 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. From 08c9d6ceef01893678a5d2e8a15517c745417f21 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <john@phrozen.org>
  3. Date: Tue, 6 Mar 2018 10:04:05 +0100
  4. Subject: [PATCH 04/27] phy: add ath79 usb phys
  5. Signed-off-by: John Crispin <john@phrozen.org>
  6. ---
  7. drivers/phy/Kconfig | 16 ++++++
  8. drivers/phy/Makefile | 2 +
  9. drivers/phy/phy-ar7100-usb.c | 124 +++++++++++++++++++++++++++++++++++++++++++
  10. drivers/phy/phy-ar7200-usb.c | 108 +++++++++++++++++++++++++++++++++++++
  11. 4 files changed, 250 insertions(+)
  12. create mode 100644 drivers/phy/phy-ar7100-usb.c
  13. create mode 100644 drivers/phy/phy-ar7200-usb.c
  14. --- a/drivers/phy/Kconfig
  15. +++ b/drivers/phy/Kconfig
  16. @@ -15,6 +15,22 @@ config GENERIC_PHY
  17. phy users can obtain reference to the PHY. All the users of this
  18. framework should select this config.
  19. +config PHY_AR7100_USB
  20. + tristate "Atheros AR7100 USB PHY driver"
  21. + depends on ATH79 || COMPILE_TEST
  22. + default y if USB_EHCI_HCD_PLATFORM
  23. + select PHY_SIMPLE
  24. + help
  25. + Enable this to support the USB PHY on Atheros AR7100 SoCs.
  26. +
  27. +config PHY_AR7200_USB
  28. + tristate "Atheros AR7200 USB PHY driver"
  29. + depends on ATH79 || COMPILE_TEST
  30. + default y if USB_EHCI_HCD_PLATFORM
  31. + select PHY_SIMPLE
  32. + help
  33. + Enable this to support the USB PHY on Atheros AR7200 SoCs.
  34. +
  35. config PHY_LPC18XX_USB_OTG
  36. tristate "NXP LPC18xx/43xx SoC USB OTG PHY driver"
  37. depends on OF && (ARCH_LPC18XX || COMPILE_TEST)
  38. --- a/drivers/phy/Makefile
  39. +++ b/drivers/phy/Makefile
  40. @@ -4,6 +4,8 @@
  41. #
  42. obj-$(CONFIG_GENERIC_PHY) += phy-core.o
  43. +obj-$(CONFIG_PHY_AR7100_USB) += phy-ar7100-usb.o
  44. +obj-$(CONFIG_PHY_AR7200_USB) += phy-ar7200-usb.o
  45. obj-$(CONFIG_PHY_LPC18XX_USB_OTG) += phy-lpc18xx-usb-otg.o
  46. obj-$(CONFIG_PHY_XGENE) += phy-xgene.o
  47. obj-$(CONFIG_PHY_PISTACHIO_USB) += phy-pistachio-usb.o
  48. --- /dev/null
  49. +++ b/drivers/phy/phy-ar7100-usb.c
  50. @@ -0,0 +1,140 @@
  51. +/*
  52. + * Copyright (C) 2018 John Crispin <john@phrozen.org>
  53. + *
  54. + * This program is free software; you can redistribute it and/or modify
  55. + * it under the terms of the GNU General Public License as published by
  56. + * the Free Software Foundation; either version 2 of the License, or
  57. + * (at your option) any later version.
  58. + */
  59. +
  60. +#include <linux/module.h>
  61. +#include <linux/platform_device.h>
  62. +#include <linux/phy/phy.h>
  63. +#include <linux/delay.h>
  64. +#include <linux/reset.h>
  65. +#include <linux/of_gpio.h>
  66. +
  67. +#include <asm/mach-ath79/ath79.h>
  68. +#include <asm/mach-ath79/ar71xx_regs.h>
  69. +
  70. +struct ar7100_usb_phy {
  71. + struct reset_control *rst_phy;
  72. + struct reset_control *rst_host;
  73. + struct reset_control *rst_ohci_dll;
  74. + void __iomem *io_base;
  75. + struct phy *phy;
  76. + int gpio;
  77. +};
  78. +
  79. +static int ar7100_usb_phy_power_off(struct phy *phy)
  80. +{
  81. + struct ar7100_usb_phy *priv = phy_get_drvdata(phy);
  82. + int err = 0;
  83. +
  84. + err |= reset_control_assert(priv->rst_host);
  85. + err |= reset_control_assert(priv->rst_phy);
  86. + err |= reset_control_assert(priv->rst_ohci_dll);
  87. +
  88. + return err;
  89. +}
  90. +
  91. +static int ar7100_usb_phy_power_on(struct phy *phy)
  92. +{
  93. + struct ar7100_usb_phy *priv = phy_get_drvdata(phy);
  94. + int err = 0;
  95. +
  96. + err |= ar7100_usb_phy_power_off(phy);
  97. + mdelay(100);
  98. + err |= reset_control_deassert(priv->rst_ohci_dll);
  99. + err |= reset_control_deassert(priv->rst_phy);
  100. + err |= reset_control_deassert(priv->rst_host);
  101. + mdelay(500);
  102. + iowrite32(0xf0000, priv->io_base + AR71XX_USB_CTRL_REG_CONFIG);
  103. + iowrite32(0x20c00, priv->io_base + AR71XX_USB_CTRL_REG_FLADJ);
  104. +
  105. + return err;
  106. +}
  107. +
  108. +static const struct phy_ops ar7100_usb_phy_ops = {
  109. + .power_on = ar7100_usb_phy_power_on,
  110. + .power_off = ar7100_usb_phy_power_off,
  111. + .owner = THIS_MODULE,
  112. +};
  113. +
  114. +static int ar7100_usb_phy_probe(struct platform_device *pdev)
  115. +{
  116. + struct phy_provider *phy_provider;
  117. + struct resource *res;
  118. + struct ar7100_usb_phy *priv;
  119. +
  120. + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  121. + if (!priv)
  122. + return -ENOMEM;
  123. +
  124. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  125. + priv->io_base = devm_ioremap_resource(&pdev->dev, res);
  126. + if (IS_ERR(priv->io_base))
  127. + return PTR_ERR(priv->io_base);
  128. +
  129. + priv->rst_phy = devm_reset_control_get(&pdev->dev, "usb-phy");
  130. + if (IS_ERR(priv->rst_phy)) {
  131. + dev_err(&pdev->dev, "phy reset is missing\n");
  132. + return PTR_ERR(priv->rst_phy);
  133. + }
  134. +
  135. + priv->rst_host = devm_reset_control_get(&pdev->dev, "usb-host");
  136. + if (IS_ERR(priv->rst_host)) {
  137. + dev_err(&pdev->dev, "host reset is missing\n");
  138. + return PTR_ERR(priv->rst_host);
  139. + }
  140. +
  141. + priv->rst_ohci_dll = devm_reset_control_get(&pdev->dev, "usb-ohci-dll");
  142. + if (IS_ERR(priv->rst_ohci_dll)) {
  143. + dev_err(&pdev->dev, "ohci-dll reset is missing\n");
  144. + return PTR_ERR(priv->rst_host);
  145. + }
  146. +
  147. + priv->phy = devm_phy_create(&pdev->dev, NULL, &ar7100_usb_phy_ops);
  148. + if (IS_ERR(priv->phy)) {
  149. + dev_err(&pdev->dev, "failed to create PHY\n");
  150. + return PTR_ERR(priv->phy);
  151. + }
  152. +
  153. + priv->gpio = of_get_gpio(pdev->dev.of_node, 0);
  154. + if (priv->gpio >= 0) {
  155. + int ret = devm_gpio_request(&pdev->dev, priv->gpio, dev_name(&pdev->dev));
  156. +
  157. + if (ret) {
  158. + dev_err(&pdev->dev, "failed to request gpio\n");
  159. + return ret;
  160. + }
  161. + gpio_export_with_name(priv->gpio, 0, dev_name(&pdev->dev));
  162. + gpio_set_value(priv->gpio, 1);
  163. + }
  164. +
  165. + phy_set_drvdata(priv->phy, priv);
  166. +
  167. + phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate);
  168. +
  169. +
  170. + return PTR_ERR_OR_ZERO(phy_provider);
  171. +}
  172. +
  173. +static const struct of_device_id ar7100_usb_phy_of_match[] = {
  174. + { .compatible = "qca,ar7100-usb-phy" },
  175. + {}
  176. +};
  177. +MODULE_DEVICE_TABLE(of, ar7100_usb_phy_of_match);
  178. +
  179. +static struct platform_driver ar7100_usb_phy_driver = {
  180. + .probe = ar7100_usb_phy_probe,
  181. + .driver = {
  182. + .of_match_table = ar7100_usb_phy_of_match,
  183. + .name = "ar7100-usb-phy",
  184. + }
  185. +};
  186. +module_platform_driver(ar7100_usb_phy_driver);
  187. +
  188. +MODULE_DESCRIPTION("ATH79 USB PHY driver");
  189. +MODULE_AUTHOR("Alban Bedel <albeu@free.fr>");
  190. +MODULE_LICENSE("GPL");
  191. --- /dev/null
  192. +++ b/drivers/phy/phy-ar7200-usb.c
  193. @@ -0,0 +1,123 @@
  194. +/*
  195. + * Copyright (C) 2015 Alban Bedel <albeu@free.fr>
  196. + *
  197. + * This program is free software; you can redistribute it and/or modify
  198. + * it under the terms of the GNU General Public License as published by
  199. + * the Free Software Foundation; either version 2 of the License, or
  200. + * (at your option) any later version.
  201. + */
  202. +
  203. +#include <linux/module.h>
  204. +#include <linux/platform_device.h>
  205. +#include <linux/phy/phy.h>
  206. +#include <linux/reset.h>
  207. +#include <linux/of_gpio.h>
  208. +
  209. +struct ar7200_usb_phy {
  210. + struct reset_control *rst_phy;
  211. + struct reset_control *suspend_override;
  212. + struct phy *phy;
  213. + int gpio;
  214. +};
  215. +
  216. +static int ar7200_usb_phy_power_on(struct phy *phy)
  217. +{
  218. + struct ar7200_usb_phy *priv = phy_get_drvdata(phy);
  219. + int err = 0;
  220. +
  221. + if (priv->rst_phy)
  222. + err = reset_control_deassert(priv->rst_phy);
  223. + if (!err && priv->suspend_override)
  224. + err = reset_control_assert(priv->suspend_override);
  225. + if (err && priv->rst_phy)
  226. + err = reset_control_assert(priv->rst_phy);
  227. +
  228. + return err;
  229. +}
  230. +
  231. +static int ar7200_usb_phy_power_off(struct phy *phy)
  232. +{
  233. + struct ar7200_usb_phy *priv = phy_get_drvdata(phy);
  234. + int err = 0;
  235. +
  236. + if (priv->suspend_override)
  237. + err = reset_control_deassert(priv->suspend_override);
  238. + if (priv->rst_phy)
  239. + err |= reset_control_assert(priv->rst_phy);
  240. +
  241. + return err;
  242. +}
  243. +
  244. +static const struct phy_ops ar7200_usb_phy_ops = {
  245. + .power_on = ar7200_usb_phy_power_on,
  246. + .power_off = ar7200_usb_phy_power_off,
  247. + .owner = THIS_MODULE,
  248. +};
  249. +
  250. +static int ar7200_usb_phy_probe(struct platform_device *pdev)
  251. +{
  252. + struct phy_provider *phy_provider;
  253. + struct ar7200_usb_phy *priv;
  254. +
  255. + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  256. + if (!priv)
  257. + return -ENOMEM;
  258. +
  259. + priv->rst_phy = devm_reset_control_get(&pdev->dev, "usb-phy");
  260. + if (IS_ERR(priv->rst_phy)) {
  261. + dev_err(&pdev->dev, "phy reset is missing\n");
  262. + return PTR_ERR(priv->rst_phy);
  263. + }
  264. +
  265. + priv->suspend_override = devm_reset_control_get_optional(
  266. + &pdev->dev, "usb-suspend-override");
  267. + if (IS_ERR(priv->suspend_override)) {
  268. + if (PTR_ERR(priv->suspend_override) == -ENOENT)
  269. + priv->suspend_override = NULL;
  270. + else
  271. + return PTR_ERR(priv->suspend_override);
  272. + }
  273. +
  274. + priv->phy = devm_phy_create(&pdev->dev, NULL, &ar7200_usb_phy_ops);
  275. + if (IS_ERR(priv->phy)) {
  276. + dev_err(&pdev->dev, "failed to create PHY\n");
  277. + return PTR_ERR(priv->phy);
  278. + }
  279. +
  280. + priv->gpio = of_get_gpio(pdev->dev.of_node, 0);
  281. + if (priv->gpio >= 0) {
  282. + int ret = devm_gpio_request(&pdev->dev, priv->gpio, dev_name(&pdev->dev));
  283. +
  284. + if (ret) {
  285. + dev_err(&pdev->dev, "failed to request gpio\n");
  286. + return ret;
  287. + }
  288. + gpio_export_with_name(priv->gpio, 0, dev_name(&pdev->dev));
  289. + gpio_set_value(priv->gpio, 1);
  290. + }
  291. +
  292. + phy_set_drvdata(priv->phy, priv);
  293. +
  294. + phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate);
  295. +
  296. + return PTR_ERR_OR_ZERO(phy_provider);
  297. +}
  298. +
  299. +static const struct of_device_id ar7200_usb_phy_of_match[] = {
  300. + { .compatible = "qca,ar7200-usb-phy" },
  301. + {}
  302. +};
  303. +MODULE_DEVICE_TABLE(of, ar7200_usb_phy_of_match);
  304. +
  305. +static struct platform_driver ar7200_usb_phy_driver = {
  306. + .probe = ar7200_usb_phy_probe,
  307. + .driver = {
  308. + .of_match_table = ar7200_usb_phy_of_match,
  309. + .name = "ar7200-usb-phy",
  310. + }
  311. +};
  312. +module_platform_driver(ar7200_usb_phy_driver);
  313. +
  314. +MODULE_DESCRIPTION("ATH79 USB PHY driver");
  315. +MODULE_AUTHOR("Alban Bedel <albeu@free.fr>");
  316. +MODULE_LICENSE("GPL");