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

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