076-phy-qcom-ipq4019-usb-add-driver-for-QCOM-IPQ4019.patch 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. From 633f0e08498aebfdb932bd71319b4cb136709499 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Tue, 24 Jul 2018 14:45:49 +0200
  4. Subject: [PATCH 2/3] phy: qcom-ipq4019-usb: add driver for QCOM/IPQ4019
  5. Add a driver to setup the USB phy on Qualcom Dakota SoCs.
  6. The driver sets up HS and SS phys. In case of HS some magic values need to
  7. be written to magic offsets. These were taken from the SDK driver.
  8. Signed-off-by: John Crispin <[email protected]>
  9. ---
  10. drivers/phy/qualcomm/Kconfig | 7 ++
  11. drivers/phy/qualcomm/Makefile | 1 +
  12. drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c | 188 ++++++++++++++++++++++++++++
  13. 3 files changed, 196 insertions(+)
  14. create mode 100644 drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c
  15. --- a/drivers/phy/qualcomm/Kconfig
  16. +++ b/drivers/phy/qualcomm/Kconfig
  17. @@ -8,6 +8,13 @@ config PHY_QCOM_APQ8064_SATA
  18. depends on OF
  19. select GENERIC_PHY
  20. +config PHY_QCOM_IPQ4019_USB
  21. + tristate "Qualcomm IPQ4019 USB PHY module"
  22. + depends on OF && ARCH_QCOM
  23. + select GENERIC_PHY
  24. + help
  25. + Support for the USB PHY on QCOM IPQ4019/Dakota chipsets.
  26. +
  27. config PHY_QCOM_IPQ806X_SATA
  28. tristate "Qualcomm IPQ806x SATA SerDes/PHY driver"
  29. depends on ARCH_QCOM
  30. --- /dev/null
  31. +++ b/drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c
  32. @@ -0,0 +1,188 @@
  33. +/*
  34. + * Copyright (C) 2018 John Crispin <[email protected]>
  35. + *
  36. + * Based on code from
  37. + * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  38. + *
  39. + * This program is free software; you can redistribute it and/or modify
  40. + * it under the terms of the GNU General Public License as published by
  41. + * the Free Software Foundation; either version 2 of the License, or
  42. + * (at your option) any later version.
  43. + *
  44. + * This program is distributed in the hope that it will be useful,
  45. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  47. + * GNU General Public License for more details.
  48. + */
  49. +
  50. +#include <linux/delay.h>
  51. +#include <linux/err.h>
  52. +#include <linux/io.h>
  53. +#include <linux/kernel.h>
  54. +#include <linux/module.h>
  55. +#include <linux/mutex.h>
  56. +#include <linux/of_platform.h>
  57. +#include <linux/phy/phy.h>
  58. +#include <linux/platform_device.h>
  59. +#include <linux/reset.h>
  60. +
  61. +/*
  62. + * Magic registers copied from the SDK driver code
  63. + */
  64. +#define PHY_CTRL0_ADDR 0x000
  65. +#define PHY_CTRL1_ADDR 0x004
  66. +#define PHY_CTRL2_ADDR 0x008
  67. +#define PHY_CTRL3_ADDR 0x00C
  68. +#define PHY_CTRL4_ADDR 0x010
  69. +#define PHY_MISC_ADDR 0x024
  70. +#define PHY_IPG_ADDR 0x030
  71. +
  72. +#define PHY_CTRL0_VAL 0xA4600015
  73. +#define PHY_CTRL1_VAL 0x09500000
  74. +#define PHY_CTRL2_VAL 0x00058180
  75. +#define PHY_CTRL3_VAL 0x6DB6DCD6
  76. +#define PHY_CTRL4_VAL 0x836DB6DB
  77. +#define PHY_MISC_VAL 0x3803FB0C
  78. +#define PHY_IPG_VAL 0x47323232
  79. +
  80. +struct ipq4019_usb_phy {
  81. + struct device *dev;
  82. + struct phy *phy;
  83. + void __iomem *base;
  84. + struct reset_control *por_rst;
  85. + struct reset_control *srif_rst;
  86. +};
  87. +
  88. +static int ipq4019_ss_phy_power_off(struct phy *_phy)
  89. +{
  90. + struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
  91. +
  92. + reset_control_assert(phy->por_rst);
  93. + msleep(10);
  94. +
  95. + return 0;
  96. +}
  97. +
  98. +static int ipq4019_ss_phy_power_on(struct phy *_phy)
  99. +{
  100. + struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
  101. +
  102. + ipq4019_ss_phy_power_off(_phy);
  103. +
  104. + reset_control_deassert(phy->por_rst);
  105. +
  106. + return 0;
  107. +}
  108. +
  109. +static struct phy_ops ipq4019_usb_ss_phy_ops = {
  110. + .power_on = ipq4019_ss_phy_power_on,
  111. + .power_off = ipq4019_ss_phy_power_off,
  112. +};
  113. +
  114. +static int ipq4019_hs_phy_power_off(struct phy *_phy)
  115. +{
  116. + struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
  117. +
  118. + reset_control_assert(phy->por_rst);
  119. + msleep(10);
  120. +
  121. + reset_control_assert(phy->srif_rst);
  122. + msleep(10);
  123. +
  124. + return 0;
  125. +}
  126. +
  127. +static int ipq4019_hs_phy_power_on(struct phy *_phy)
  128. +{
  129. + struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
  130. +
  131. + ipq4019_hs_phy_power_off(_phy);
  132. +
  133. + reset_control_deassert(phy->srif_rst);
  134. + msleep(10);
  135. +
  136. + writel(PHY_CTRL0_VAL, phy->base + PHY_CTRL0_ADDR);
  137. + writel(PHY_CTRL1_VAL, phy->base + PHY_CTRL1_ADDR);
  138. + writel(PHY_CTRL2_VAL, phy->base + PHY_CTRL2_ADDR);
  139. + writel(PHY_CTRL3_VAL, phy->base + PHY_CTRL3_ADDR);
  140. + writel(PHY_CTRL4_VAL, phy->base + PHY_CTRL4_ADDR);
  141. + writel(PHY_MISC_VAL, phy->base + PHY_MISC_ADDR);
  142. + writel(PHY_IPG_VAL, phy->base + PHY_IPG_ADDR);
  143. + msleep(10);
  144. +
  145. + reset_control_deassert(phy->por_rst);
  146. +
  147. + return 0;
  148. +}
  149. +
  150. +static struct phy_ops ipq4019_usb_hs_phy_ops = {
  151. + .power_on = ipq4019_hs_phy_power_on,
  152. + .power_off = ipq4019_hs_phy_power_off,
  153. +};
  154. +
  155. +static const struct of_device_id ipq4019_usb_phy_of_match[] = {
  156. + { .compatible = "qcom,usb-hs-ipq4019-phy", .data = &ipq4019_usb_hs_phy_ops},
  157. + { .compatible = "qcom,usb-ss-ipq4019-phy", .data = &ipq4019_usb_ss_phy_ops},
  158. + { },
  159. +};
  160. +MODULE_DEVICE_TABLE(of, ipq4019_usb_phy_of_match);
  161. +
  162. +static int ipq4019_usb_phy_probe(struct platform_device *pdev)
  163. +{
  164. + struct device *dev = &pdev->dev;
  165. + struct resource *res;
  166. + struct phy_provider *phy_provider;
  167. + struct ipq4019_usb_phy *phy;
  168. + const struct of_device_id *match;
  169. +
  170. + match = of_match_device(ipq4019_usb_phy_of_match, &pdev->dev);
  171. + if (!match)
  172. + return -ENODEV;
  173. +
  174. + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
  175. + if (!phy)
  176. + return -ENOMEM;
  177. +
  178. + phy->dev = &pdev->dev;
  179. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  180. + phy->base = devm_ioremap_resource(&pdev->dev, res);
  181. + if (IS_ERR(phy->base)) {
  182. + dev_err(dev, "failed to remap register memory\n");
  183. + return PTR_ERR(phy->base);
  184. + }
  185. +
  186. + phy->por_rst = devm_reset_control_get(phy->dev, "por_rst");
  187. + if (IS_ERR(phy->por_rst)) {
  188. + if (PTR_ERR(phy->por_rst) != -EPROBE_DEFER)
  189. + dev_err(dev, "POR reset is missing\n");
  190. + return PTR_ERR(phy->por_rst);
  191. + }
  192. +
  193. + phy->srif_rst = devm_reset_control_get_optional(phy->dev, "srif_rst");
  194. + if (IS_ERR(phy->srif_rst))
  195. + return PTR_ERR(phy->srif_rst);
  196. +
  197. + phy->phy = devm_phy_create(dev, NULL, match->data);
  198. + if (IS_ERR(phy->phy)) {
  199. + dev_err(dev, "failed to create PHY\n");
  200. + return PTR_ERR(phy->phy);
  201. + }
  202. + phy_set_drvdata(phy->phy, phy);
  203. +
  204. + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  205. +
  206. + return PTR_ERR_OR_ZERO(phy_provider);
  207. +}
  208. +
  209. +static struct platform_driver ipq4019_usb_phy_driver = {
  210. + .probe = ipq4019_usb_phy_probe,
  211. + .driver = {
  212. + .of_match_table = ipq4019_usb_phy_of_match,
  213. + .name = "ipq4019-usb-phy",
  214. + }
  215. +};
  216. +module_platform_driver(ipq4019_usb_phy_driver);
  217. +
  218. +MODULE_DESCRIPTION("QCOM/IPQ4019 USB phy driver");
  219. +MODULE_AUTHOR("John Crispin <[email protected]>");
  220. +MODULE_LICENSE("GPL v2");
  221. --- a/drivers/phy/qualcomm/Makefile
  222. +++ b/drivers/phy/qualcomm/Makefile
  223. @@ -1,5 +1,6 @@
  224. # SPDX-License-Identifier: GPL-2.0
  225. obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o
  226. +obj-$(CONFIG_PHY_QCOM_IPQ4019_USB) += phy-qcom-ipq4019-usb.o
  227. obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o
  228. obj-$(CONFIG_PHY_QCOM_QMP) += phy-qcom-qmp.o
  229. obj-$(CONFIG_PHY_QCOM_QUSB2) += phy-qcom-qusb2.o