2
0

790-04-v6.4-net-dsa-mt7530-refactor-SGMII-PCS-creation.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. From 8f83ad87e2df26ddf9b8afd4d2873644a872d929 Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Mon, 3 Apr 2023 02:17:30 +0100
  4. Subject: [PATCH 04/48] net: dsa: mt7530: refactor SGMII PCS creation
  5. Instead of macro templates use a dedidated function and allocated
  6. regmap_config when creating the regmaps for the pcs-mtk-lynxi
  7. instances.
  8. This is in preparation to switching to use unlocked regmap accessors
  9. and have regmap's locking API handle locking for us.
  10. Signed-off-by: Daniel Golle <[email protected]>
  11. Reviewed-by: Andrew Lunn <[email protected]>
  12. Signed-off-by: David S. Miller <[email protected]>
  13. ---
  14. drivers/net/dsa/mt7530.c | 74 +++++++++++++++++++++++++++-------------
  15. 1 file changed, 50 insertions(+), 24 deletions(-)
  16. --- a/drivers/net/dsa/mt7530.c
  17. +++ b/drivers/net/dsa/mt7530.c
  18. @@ -3001,26 +3001,56 @@ static const struct regmap_bus mt7531_re
  19. .reg_update_bits = mt7530_regmap_update_bits,
  20. };
  21. -#define MT7531_PCS_REGMAP_CONFIG(_name, _reg_base) \
  22. - { \
  23. - .name = _name, \
  24. - .reg_bits = 16, \
  25. - .val_bits = 32, \
  26. - .reg_stride = 4, \
  27. - .reg_base = _reg_base, \
  28. - .max_register = 0x17c, \
  29. +static int
  30. +mt7531_create_sgmii(struct mt7530_priv *priv)
  31. +{
  32. + struct regmap_config *mt7531_pcs_config[2];
  33. + struct phylink_pcs *pcs;
  34. + struct regmap *regmap;
  35. + int i, ret = 0;
  36. +
  37. + for (i = 0; i < 2; i++) {
  38. + mt7531_pcs_config[i] = devm_kzalloc(priv->dev,
  39. + sizeof(struct regmap_config),
  40. + GFP_KERNEL);
  41. + if (!mt7531_pcs_config[i]) {
  42. + ret = -ENOMEM;
  43. + break;
  44. + }
  45. +
  46. + mt7531_pcs_config[i]->name = i ? "port6" : "port5";
  47. + mt7531_pcs_config[i]->reg_bits = 16;
  48. + mt7531_pcs_config[i]->val_bits = 32;
  49. + mt7531_pcs_config[i]->reg_stride = 4;
  50. + mt7531_pcs_config[i]->reg_base = MT7531_SGMII_REG_BASE(5 + i);
  51. + mt7531_pcs_config[i]->max_register = 0x17c;
  52. +
  53. + regmap = devm_regmap_init(priv->dev,
  54. + &mt7531_regmap_bus, priv,
  55. + mt7531_pcs_config[i]);
  56. + if (IS_ERR(regmap)) {
  57. + ret = PTR_ERR(regmap);
  58. + break;
  59. + }
  60. + pcs = mtk_pcs_lynxi_create(priv->dev, regmap,
  61. + MT7531_PHYA_CTRL_SIGNAL3, 0);
  62. + if (!pcs) {
  63. + ret = -ENXIO;
  64. + break;
  65. + }
  66. + priv->ports[5 + i].sgmii_pcs = pcs;
  67. }
  68. -static const struct regmap_config mt7531_pcs_config[] = {
  69. - MT7531_PCS_REGMAP_CONFIG("port5", MT7531_SGMII_REG_BASE(5)),
  70. - MT7531_PCS_REGMAP_CONFIG("port6", MT7531_SGMII_REG_BASE(6)),
  71. -};
  72. + if (ret && i)
  73. + mtk_pcs_lynxi_destroy(priv->ports[5].sgmii_pcs);
  74. +
  75. + return ret;
  76. +}
  77. static int
  78. mt753x_setup(struct dsa_switch *ds)
  79. {
  80. struct mt7530_priv *priv = ds->priv;
  81. - struct regmap *regmap;
  82. int i, ret;
  83. /* Initialise the PCS devices */
  84. @@ -3042,15 +3072,11 @@ mt753x_setup(struct dsa_switch *ds)
  85. if (ret && priv->irq)
  86. mt7530_free_irq_common(priv);
  87. - if (priv->id == ID_MT7531)
  88. - for (i = 0; i < 2; i++) {
  89. - regmap = devm_regmap_init(ds->dev,
  90. - &mt7531_regmap_bus, priv,
  91. - &mt7531_pcs_config[i]);
  92. - priv->ports[5 + i].sgmii_pcs =
  93. - mtk_pcs_lynxi_create(ds->dev, regmap,
  94. - MT7531_PHYA_CTRL_SIGNAL3, 0);
  95. - }
  96. + if (priv->id == ID_MT7531) {
  97. + ret = mt7531_create_sgmii(priv);
  98. + if (ret && priv->irq)
  99. + mt7530_free_irq_common(priv);
  100. + }
  101. return ret;
  102. }