0311-net-phy-qca808x-Add-QCA8084-probe-function.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. From a7fe2c13f3188bf01b60fb15063d028c76dd2f1a Mon Sep 17 00:00:00 2001
  2. From: Luo Jie <[email protected]>
  3. Date: Mon, 29 Jan 2024 10:51:38 +0800
  4. Subject: [PATCH] net: phy: qca808x: Add QCA8084 probe function
  5. Add the PHY package probe function. The MDIO slave address of
  6. PHY, PCS and XPCS can be optionally customized by configuring
  7. the PHY package level register.
  8. In addition, enable system clock of PHY and de-assert PHY in
  9. the probe function so that the register of PHY device can be
  10. accessed, and the features of PHY can be acquired.
  11. Change-Id: I2251b9c5c398a21a4ef547a727189a934ad3a44c
  12. Signed-off-by: Luo Jie <[email protected]>
  13. Alex G: include <linux/reset.h>
  14. include "phylib.h" for phy_package_*() declarations
  15. select PHY_PACKAGE in Kconfig
  16. use phy_package_get_node() instead of phylib->shared->np
  17. Signed-off-by: Alexandru Gagniuc <[email protected]>
  18. freckup c89414adf2ec7c
  19. Signed-off-by: Alexandru Gagniuc <[email protected]>
  20. ---
  21. drivers/net/phy/qcom/Kconfig | 1 +
  22. drivers/net/phy/qcom/qca808x.c | 92 ++++++++++++++++++++++++++++++++++
  23. 2 files changed, 93 insertions(+)
  24. --- a/drivers/net/phy/qcom/Kconfig
  25. +++ b/drivers/net/phy/qcom/Kconfig
  26. @@ -18,6 +18,7 @@ config QCA83XX_PHY
  27. config QCA808X_PHY
  28. tristate "Qualcomm QCA808x PHYs"
  29. select QCOM_NET_PHYLIB
  30. + select PHY_PACKAGE
  31. help
  32. Currently supports the QCA8081 model
  33. --- a/drivers/net/phy/qcom/qca808x.c
  34. +++ b/drivers/net/phy/qcom/qca808x.c
  35. @@ -2,7 +2,11 @@
  36. #include <linux/phy.h>
  37. #include <linux/module.h>
  38. +#include <linux/of.h>
  39. +#include <linux/reset.h>
  40. +#include <linux/clk.h>
  41. +#include "../phylib.h"
  42. #include "qcom.h"
  43. /* ADC threshold */
  44. @@ -127,6 +131,21 @@
  45. #define QCA8084_MII_SW_ADDR_MASK GENMASK(31, 24)
  46. #define QCA8084_MII_REG_DATA_UPPER_16_BITS BIT(1)
  47. +/* QCA8084 integrates 4 PHYs, PCS0 and PCS1(includes PCS and XPCS). */
  48. +#define QCA8084_MDIO_DEVICE_NUM 7
  49. +
  50. +#define QCA8084_PCS_CFG 0xc90f014
  51. +#define QCA8084_PCS_ADDR0_MASK GENMASK(4, 0)
  52. +#define QCA8084_PCS_ADDR1_MASK GENMASK(9, 5)
  53. +#define QCA8084_PCS_ADDR2_MASK GENMASK(14, 10)
  54. +
  55. +#define QCA8084_EPHY_CFG 0xc90f018
  56. +#define QCA8084_EPHY_ADDR0_MASK GENMASK(4, 0)
  57. +#define QCA8084_EPHY_ADDR1_MASK GENMASK(9, 5)
  58. +#define QCA8084_EPHY_ADDR2_MASK GENMASK(14, 10)
  59. +#define QCA8084_EPHY_ADDR3_MASK GENMASK(19, 15)
  60. +#define QCA8084_EPHY_LDO_EN GENMASK(21, 20)
  61. +
  62. MODULE_DESCRIPTION("Qualcomm Atheros QCA808X PHY driver");
  63. MODULE_AUTHOR("Matus Ujhelyi, Luo Jie");
  64. MODULE_LICENSE("GPL");
  65. @@ -839,6 +858,78 @@ static void qca8084_link_change_notify(s
  66. QCA8084_IPG_10_TO_11_EN : 0);
  67. }
  68. +static int qca8084_phy_package_probe_once(struct phy_device *phydev)
  69. +{
  70. + int addr[QCA8084_MDIO_DEVICE_NUM] = {0, 1, 2, 3, 4, 5, 6};
  71. + struct device_node *np = phy_package_get_node(phydev);
  72. + int ret, clear, set;
  73. +
  74. + /* Program the MDIO address of PHY and PCS optionally, the MDIO
  75. + * address 0-6 is used for PHY and PCS MDIO devices by default.
  76. + */
  77. + ret = of_property_read_u32_array(np, "qcom,phy-addr-fixup",
  78. + addr, ARRAY_SIZE(addr));
  79. + if (ret && ret != -EINVAL)
  80. + return ret;
  81. +
  82. + /* Configure the MDIO addresses for the four PHY devices. */
  83. + clear = QCA8084_EPHY_ADDR0_MASK | QCA8084_EPHY_ADDR1_MASK |
  84. + QCA8084_EPHY_ADDR2_MASK | QCA8084_EPHY_ADDR3_MASK;
  85. + set = FIELD_PREP(QCA8084_EPHY_ADDR0_MASK, addr[0]);
  86. + set |= FIELD_PREP(QCA8084_EPHY_ADDR1_MASK, addr[1]);
  87. + set |= FIELD_PREP(QCA8084_EPHY_ADDR2_MASK, addr[2]);
  88. + set |= FIELD_PREP(QCA8084_EPHY_ADDR3_MASK, addr[3]);
  89. +
  90. + ret = qca8084_mii_modify(phydev, QCA8084_EPHY_CFG, clear, set);
  91. + if (ret)
  92. + return ret;
  93. +
  94. + /* Configure the MDIO addresses for PCS0 and PCS1 including
  95. + * PCS and XPCS.
  96. + */
  97. + clear = QCA8084_PCS_ADDR0_MASK | QCA8084_PCS_ADDR1_MASK |
  98. + QCA8084_PCS_ADDR2_MASK;
  99. + set = FIELD_PREP(QCA8084_PCS_ADDR0_MASK, addr[4]);
  100. + set |= FIELD_PREP(QCA8084_PCS_ADDR1_MASK, addr[5]);
  101. + set |= FIELD_PREP(QCA8084_PCS_ADDR2_MASK, addr[6]);
  102. +
  103. + return qca8084_mii_modify(phydev, QCA8084_PCS_CFG, clear, set);
  104. +}
  105. +
  106. +static int qca8084_probe(struct phy_device *phydev)
  107. +{
  108. + struct device *dev = &phydev->mdio.dev;
  109. + struct reset_control *rstc;
  110. + struct clk *clk;
  111. + int ret;
  112. +
  113. + ret = devm_of_phy_package_join(dev, phydev, 0);
  114. + if (ret)
  115. + return ret;
  116. +
  117. + if (phy_package_probe_once(phydev)) {
  118. + ret = qca8084_phy_package_probe_once(phydev);
  119. + if (ret)
  120. + return ret;
  121. + }
  122. +
  123. + /* Enable clock of PHY device, so that the PHY register
  124. + * can be accessed to get PHY features.
  125. + */
  126. + clk = devm_clk_get_enabled(dev, NULL);
  127. + if (IS_ERR(clk))
  128. + return dev_err_probe(dev, PTR_ERR(clk),
  129. + "Enable PHY clock failed\n");
  130. +
  131. + /* De-assert PHY reset after the clock of PHY enabled. */
  132. + rstc = devm_reset_control_get_exclusive(dev, NULL);
  133. + if (IS_ERR(rstc))
  134. + return dev_err_probe(dev, PTR_ERR(rstc),
  135. + "Get PHY reset failed\n");
  136. +
  137. + return reset_control_deassert(rstc);
  138. +}
  139. +
  140. static struct phy_driver qca808x_driver[] = {
  141. {
  142. /* Qualcomm QCA8081 */
  143. @@ -889,6 +980,7 @@ static struct phy_driver qca808x_driver[
  144. .cable_test_get_status = qca808x_cable_test_get_status,
  145. .config_init = qca8084_config_init,
  146. .link_change_notify = qca8084_link_change_notify,
  147. + .probe = qca8084_probe,
  148. }, };
  149. module_phy_driver(qca808x_driver);