mdio-xgene.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Applied Micro X-Gene SoC MDIO Driver
  2. *
  3. * Copyright (c) 2016, Applied Micro Circuits Corporation
  4. * Author: Iyappan Subramanian <isubramanian@apm.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __MDIO_XGENE_H__
  20. #define __MDIO_XGENE_H__
  21. #define BLOCK_XG_MDIO_CSR_OFFSET 0x5000
  22. #define BLOCK_DIAG_CSR_OFFSET 0xd000
  23. #define XGENET_CONFIG_REG_ADDR 0x20
  24. #define MAC_ADDR_REG_OFFSET 0x00
  25. #define MAC_COMMAND_REG_OFFSET 0x04
  26. #define MAC_WRITE_REG_OFFSET 0x08
  27. #define MAC_READ_REG_OFFSET 0x0c
  28. #define MAC_COMMAND_DONE_REG_OFFSET 0x10
  29. #define CLKEN_OFFSET 0x08
  30. #define SRST_OFFSET 0x00
  31. #define MENET_CFG_MEM_RAM_SHUTDOWN_ADDR 0x70
  32. #define MENET_BLOCK_MEM_RDY_ADDR 0x74
  33. #define MAC_CONFIG_1_ADDR 0x00
  34. #define MII_MGMT_COMMAND_ADDR 0x24
  35. #define MII_MGMT_ADDRESS_ADDR 0x28
  36. #define MII_MGMT_CONTROL_ADDR 0x2c
  37. #define MII_MGMT_STATUS_ADDR 0x30
  38. #define MII_MGMT_INDICATORS_ADDR 0x34
  39. #define SOFT_RESET BIT(31)
  40. #define MII_MGMT_CONFIG_ADDR 0x20
  41. #define MII_MGMT_COMMAND_ADDR 0x24
  42. #define MII_MGMT_ADDRESS_ADDR 0x28
  43. #define MII_MGMT_CONTROL_ADDR 0x2c
  44. #define MII_MGMT_STATUS_ADDR 0x30
  45. #define MII_MGMT_INDICATORS_ADDR 0x34
  46. #define MIIM_COMMAND_ADDR 0x20
  47. #define MIIM_FIELD_ADDR 0x24
  48. #define MIIM_CONFIGURATION_ADDR 0x28
  49. #define MIIM_LINKFAILVECTOR_ADDR 0x2c
  50. #define MIIM_INDICATOR_ADDR 0x30
  51. #define MIIMRD_FIELD_ADDR 0x34
  52. #define MDIO_CSR_OFFSET 0x5000
  53. #define REG_ADDR_POS 0
  54. #define REG_ADDR_LEN 5
  55. #define PHY_ADDR_POS 8
  56. #define PHY_ADDR_LEN 5
  57. #define HSTMIIMWRDAT_POS 0
  58. #define HSTMIIMWRDAT_LEN 16
  59. #define HSTPHYADX_POS 23
  60. #define HSTPHYADX_LEN 5
  61. #define HSTREGADX_POS 18
  62. #define HSTREGADX_LEN 5
  63. #define HSTLDCMD BIT(3)
  64. #define HSTMIIMCMD_POS 0
  65. #define HSTMIIMCMD_LEN 3
  66. #define BUSY_MASK BIT(0)
  67. #define READ_CYCLE_MASK BIT(0)
  68. enum xgene_enet_cmd {
  69. XGENE_ENET_WR_CMD = BIT(31),
  70. XGENE_ENET_RD_CMD = BIT(30)
  71. };
  72. enum {
  73. MIIM_CMD_IDLE,
  74. MIIM_CMD_LEGACY_WRITE,
  75. MIIM_CMD_LEGACY_READ,
  76. };
  77. enum xgene_mdio_id {
  78. XGENE_MDIO_RGMII = 1,
  79. XGENE_MDIO_XFI
  80. };
  81. struct xgene_mdio_pdata {
  82. struct clk *clk;
  83. struct device *dev;
  84. void __iomem *mac_csr_addr;
  85. void __iomem *diag_csr_addr;
  86. void __iomem *mdio_csr_addr;
  87. struct mii_bus *mdio_bus;
  88. int mdio_id;
  89. };
  90. /* Set the specified value into a bit-field defined by its starting position
  91. * and length within a single u64.
  92. */
  93. static inline u64 xgene_enet_set_field_value(int pos, int len, u64 val)
  94. {
  95. return (val & ((1ULL << len) - 1)) << pos;
  96. }
  97. #define SET_VAL(field, val) \
  98. xgene_enet_set_field_value(field ## _POS, field ## _LEN, val)
  99. #define SET_BIT(field) \
  100. xgene_enet_set_field_value(field ## _POS, 1, 1)
  101. /* Get the value from a bit-field defined by its starting position
  102. * and length within the specified u64.
  103. */
  104. static inline u64 xgene_enet_get_field_value(int pos, int len, u64 src)
  105. {
  106. return (src >> pos) & ((1ULL << len) - 1);
  107. }
  108. #define GET_VAL(field, src) \
  109. xgene_enet_get_field_value(field ## _POS, field ## _LEN, src)
  110. #define GET_BIT(field, src) \
  111. xgene_enet_get_field_value(field ## _POS, 1, src)
  112. int xgene_mdio_rgmii_read(struct mii_bus *bus, int phy_id, int reg);
  113. int xgene_mdio_rgmii_write(struct mii_bus *bus, int phy_id, int reg, u16 data);
  114. struct phy_device *xgene_enet_phy_register(struct mii_bus *bus, int phy_addr);
  115. #endif /* __MDIO_XGENE_H__ */