2
0

707-v6.8-11-net-phy-at803x-move-at8031-functions-in-dedicated-se.patch 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. From f932a6dc8bae0dae9645b5b1b4c65aed8a8acb2a Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Fri, 8 Dec 2023 15:51:58 +0100
  4. Subject: [PATCH 11/13] net: phy: at803x: move at8031 functions in dedicated
  5. section
  6. Move at8031 functions in dedicated section with dedicated at8031
  7. parse_dt and probe.
  8. Signed-off-by: Christian Marangi <[email protected]>
  9. Signed-off-by: David S. Miller <[email protected]>
  10. ---
  11. drivers/net/phy/at803x.c | 266 +++++++++++++++++++--------------------
  12. 1 file changed, 133 insertions(+), 133 deletions(-)
  13. --- a/drivers/net/phy/at803x.c
  14. +++ b/drivers/net/phy/at803x.c
  15. @@ -583,139 +583,6 @@ static int at803x_resume(struct phy_devi
  16. return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
  17. }
  18. -static int at8031_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
  19. - unsigned int selector)
  20. -{
  21. - struct phy_device *phydev = rdev_get_drvdata(rdev);
  22. -
  23. - if (selector)
  24. - return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
  25. - 0, AT803X_DEBUG_RGMII_1V8);
  26. - else
  27. - return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
  28. - AT803X_DEBUG_RGMII_1V8, 0);
  29. -}
  30. -
  31. -static int at8031_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
  32. -{
  33. - struct phy_device *phydev = rdev_get_drvdata(rdev);
  34. - int val;
  35. -
  36. - val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
  37. - if (val < 0)
  38. - return val;
  39. -
  40. - return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
  41. -}
  42. -
  43. -static const struct regulator_ops vddio_regulator_ops = {
  44. - .list_voltage = regulator_list_voltage_table,
  45. - .set_voltage_sel = at8031_rgmii_reg_set_voltage_sel,
  46. - .get_voltage_sel = at8031_rgmii_reg_get_voltage_sel,
  47. -};
  48. -
  49. -static const unsigned int vddio_voltage_table[] = {
  50. - 1500000,
  51. - 1800000,
  52. -};
  53. -
  54. -static const struct regulator_desc vddio_desc = {
  55. - .name = "vddio",
  56. - .of_match = of_match_ptr("vddio-regulator"),
  57. - .n_voltages = ARRAY_SIZE(vddio_voltage_table),
  58. - .volt_table = vddio_voltage_table,
  59. - .ops = &vddio_regulator_ops,
  60. - .type = REGULATOR_VOLTAGE,
  61. - .owner = THIS_MODULE,
  62. -};
  63. -
  64. -static const struct regulator_ops vddh_regulator_ops = {
  65. -};
  66. -
  67. -static const struct regulator_desc vddh_desc = {
  68. - .name = "vddh",
  69. - .of_match = of_match_ptr("vddh-regulator"),
  70. - .n_voltages = 1,
  71. - .fixed_uV = 2500000,
  72. - .ops = &vddh_regulator_ops,
  73. - .type = REGULATOR_VOLTAGE,
  74. - .owner = THIS_MODULE,
  75. -};
  76. -
  77. -static int at8031_register_regulators(struct phy_device *phydev)
  78. -{
  79. - struct at803x_priv *priv = phydev->priv;
  80. - struct device *dev = &phydev->mdio.dev;
  81. - struct regulator_config config = { };
  82. -
  83. - config.dev = dev;
  84. - config.driver_data = phydev;
  85. -
  86. - priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
  87. - if (IS_ERR(priv->vddio_rdev)) {
  88. - phydev_err(phydev, "failed to register VDDIO regulator\n");
  89. - return PTR_ERR(priv->vddio_rdev);
  90. - }
  91. -
  92. - priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
  93. - if (IS_ERR(priv->vddh_rdev)) {
  94. - phydev_err(phydev, "failed to register VDDH regulator\n");
  95. - return PTR_ERR(priv->vddh_rdev);
  96. - }
  97. -
  98. - return 0;
  99. -}
  100. -
  101. -static int at8031_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
  102. -{
  103. - struct phy_device *phydev = upstream;
  104. - __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support);
  105. - __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
  106. - DECLARE_PHY_INTERFACE_MASK(interfaces);
  107. - phy_interface_t iface;
  108. -
  109. - linkmode_zero(phy_support);
  110. - phylink_set(phy_support, 1000baseX_Full);
  111. - phylink_set(phy_support, 1000baseT_Full);
  112. - phylink_set(phy_support, Autoneg);
  113. - phylink_set(phy_support, Pause);
  114. - phylink_set(phy_support, Asym_Pause);
  115. -
  116. - linkmode_zero(sfp_support);
  117. - sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces);
  118. - /* Some modules support 10G modes as well as others we support.
  119. - * Mask out non-supported modes so the correct interface is picked.
  120. - */
  121. - linkmode_and(sfp_support, phy_support, sfp_support);
  122. -
  123. - if (linkmode_empty(sfp_support)) {
  124. - dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
  125. - return -EINVAL;
  126. - }
  127. -
  128. - iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
  129. -
  130. - /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes
  131. - * interface for use with SFP modules.
  132. - * However, some copper modules detected as having a preferred SGMII
  133. - * interface do default to and function in 1000Base-X mode, so just
  134. - * print a warning and allow such modules, as they may have some chance
  135. - * of working.
  136. - */
  137. - if (iface == PHY_INTERFACE_MODE_SGMII)
  138. - dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n");
  139. - else if (iface != PHY_INTERFACE_MODE_1000BASEX)
  140. - return -EINVAL;
  141. -
  142. - return 0;
  143. -}
  144. -
  145. -static const struct sfp_upstream_ops at8031_sfp_ops = {
  146. - .attach = phy_sfp_attach,
  147. - .detach = phy_sfp_detach,
  148. - .module_insert = at8031_sfp_insert,
  149. -};
  150. -
  151. static int at803x_parse_dt(struct phy_device *phydev)
  152. {
  153. struct device_node *node = phydev->mdio.dev.of_node;
  154. @@ -1498,6 +1365,139 @@ static int at803x_cable_test_start(struc
  155. return 0;
  156. }
  157. +static int at8031_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
  158. + unsigned int selector)
  159. +{
  160. + struct phy_device *phydev = rdev_get_drvdata(rdev);
  161. +
  162. + if (selector)
  163. + return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
  164. + 0, AT803X_DEBUG_RGMII_1V8);
  165. + else
  166. + return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
  167. + AT803X_DEBUG_RGMII_1V8, 0);
  168. +}
  169. +
  170. +static int at8031_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
  171. +{
  172. + struct phy_device *phydev = rdev_get_drvdata(rdev);
  173. + int val;
  174. +
  175. + val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
  176. + if (val < 0)
  177. + return val;
  178. +
  179. + return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
  180. +}
  181. +
  182. +static const struct regulator_ops vddio_regulator_ops = {
  183. + .list_voltage = regulator_list_voltage_table,
  184. + .set_voltage_sel = at8031_rgmii_reg_set_voltage_sel,
  185. + .get_voltage_sel = at8031_rgmii_reg_get_voltage_sel,
  186. +};
  187. +
  188. +static const unsigned int vddio_voltage_table[] = {
  189. + 1500000,
  190. + 1800000,
  191. +};
  192. +
  193. +static const struct regulator_desc vddio_desc = {
  194. + .name = "vddio",
  195. + .of_match = of_match_ptr("vddio-regulator"),
  196. + .n_voltages = ARRAY_SIZE(vddio_voltage_table),
  197. + .volt_table = vddio_voltage_table,
  198. + .ops = &vddio_regulator_ops,
  199. + .type = REGULATOR_VOLTAGE,
  200. + .owner = THIS_MODULE,
  201. +};
  202. +
  203. +static const struct regulator_ops vddh_regulator_ops = {
  204. +};
  205. +
  206. +static const struct regulator_desc vddh_desc = {
  207. + .name = "vddh",
  208. + .of_match = of_match_ptr("vddh-regulator"),
  209. + .n_voltages = 1,
  210. + .fixed_uV = 2500000,
  211. + .ops = &vddh_regulator_ops,
  212. + .type = REGULATOR_VOLTAGE,
  213. + .owner = THIS_MODULE,
  214. +};
  215. +
  216. +static int at8031_register_regulators(struct phy_device *phydev)
  217. +{
  218. + struct at803x_priv *priv = phydev->priv;
  219. + struct device *dev = &phydev->mdio.dev;
  220. + struct regulator_config config = { };
  221. +
  222. + config.dev = dev;
  223. + config.driver_data = phydev;
  224. +
  225. + priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
  226. + if (IS_ERR(priv->vddio_rdev)) {
  227. + phydev_err(phydev, "failed to register VDDIO regulator\n");
  228. + return PTR_ERR(priv->vddio_rdev);
  229. + }
  230. +
  231. + priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
  232. + if (IS_ERR(priv->vddh_rdev)) {
  233. + phydev_err(phydev, "failed to register VDDH regulator\n");
  234. + return PTR_ERR(priv->vddh_rdev);
  235. + }
  236. +
  237. + return 0;
  238. +}
  239. +
  240. +static int at8031_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
  241. +{
  242. + struct phy_device *phydev = upstream;
  243. + __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support);
  244. + __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
  245. + DECLARE_PHY_INTERFACE_MASK(interfaces);
  246. + phy_interface_t iface;
  247. +
  248. + linkmode_zero(phy_support);
  249. + phylink_set(phy_support, 1000baseX_Full);
  250. + phylink_set(phy_support, 1000baseT_Full);
  251. + phylink_set(phy_support, Autoneg);
  252. + phylink_set(phy_support, Pause);
  253. + phylink_set(phy_support, Asym_Pause);
  254. +
  255. + linkmode_zero(sfp_support);
  256. + sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces);
  257. + /* Some modules support 10G modes as well as others we support.
  258. + * Mask out non-supported modes so the correct interface is picked.
  259. + */
  260. + linkmode_and(sfp_support, phy_support, sfp_support);
  261. +
  262. + if (linkmode_empty(sfp_support)) {
  263. + dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
  264. + return -EINVAL;
  265. + }
  266. +
  267. + iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
  268. +
  269. + /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes
  270. + * interface for use with SFP modules.
  271. + * However, some copper modules detected as having a preferred SGMII
  272. + * interface do default to and function in 1000Base-X mode, so just
  273. + * print a warning and allow such modules, as they may have some chance
  274. + * of working.
  275. + */
  276. + if (iface == PHY_INTERFACE_MODE_SGMII)
  277. + dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n");
  278. + else if (iface != PHY_INTERFACE_MODE_1000BASEX)
  279. + return -EINVAL;
  280. +
  281. + return 0;
  282. +}
  283. +
  284. +static const struct sfp_upstream_ops at8031_sfp_ops = {
  285. + .attach = phy_sfp_attach,
  286. + .detach = phy_sfp_detach,
  287. + .module_insert = at8031_sfp_insert,
  288. +};
  289. +
  290. static int at8031_parse_dt(struct phy_device *phydev)
  291. {
  292. struct device_node *node = phydev->mdio.dev.of_node;