comphy.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (C) 2015-2016 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef _COMPHY_H_
  7. #define _COMPHY_H_
  8. #include <dt-bindings/comphy/comphy_data.h>
  9. #include <fdtdec.h>
  10. #if defined(DEBUG)
  11. #define debug_enter() printf("----> Enter %s\n", __func__);
  12. #define debug_exit() printf("<---- Exit %s\n", __func__);
  13. #else
  14. #define debug_enter()
  15. #define debug_exit()
  16. #endif
  17. /* COMPHY registers */
  18. #define COMMON_PHY_CFG1_REG 0x0
  19. #define COMMON_PHY_CFG1_PWR_UP_OFFSET 1
  20. #define COMMON_PHY_CFG1_PWR_UP_MASK \
  21. (0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET)
  22. #define COMMON_PHY_CFG1_PIPE_SELECT_OFFSET 2
  23. #define COMMON_PHY_CFG1_PIPE_SELECT_MASK \
  24. (0x1 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET)
  25. #define COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET 13
  26. #define COMMON_PHY_CFG1_PWR_ON_RESET_MASK \
  27. (0x1 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET)
  28. #define COMMON_PHY_CFG1_CORE_RSTN_OFFSET 14
  29. #define COMMON_PHY_CFG1_CORE_RSTN_MASK \
  30. (0x1 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET)
  31. #define COMMON_PHY_PHY_MODE_OFFSET 15
  32. #define COMMON_PHY_PHY_MODE_MASK \
  33. (0x1 << COMMON_PHY_PHY_MODE_OFFSET)
  34. #define COMMON_PHY_CFG6_REG 0x14
  35. #define COMMON_PHY_CFG6_IF_40_SEL_OFFSET 18
  36. #define COMMON_PHY_CFG6_IF_40_SEL_MASK \
  37. (0x1 << COMMON_PHY_CFG6_IF_40_SEL_OFFSET)
  38. #define COMMON_SELECTOR_PHY_OFFSET 0x140
  39. #define COMMON_SELECTOR_PIPE_OFFSET 0x144
  40. #define COMMON_PHY_SD_CTRL1 0x148
  41. #define COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_OFFSET 0
  42. #define COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_MASK 0xFFFF
  43. #define COMMON_PHY_SD_CTRL1_PCIE_X4_EN_OFFSET 24
  44. #define COMMON_PHY_SD_CTRL1_PCIE_X4_EN_MASK \
  45. (0x1 << COMMON_PHY_SD_CTRL1_PCIE_X4_EN_OFFSET)
  46. #define COMMON_PHY_SD_CTRL1_PCIE_X2_EN_OFFSET 25
  47. #define COMMON_PHY_SD_CTRL1_PCIE_X2_EN_MASK \
  48. (0x1 << COMMON_PHY_SD_CTRL1_PCIE_X2_EN_OFFSET)
  49. #define COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET 26
  50. #define COMMON_PHY_SD_CTRL1_RXAUI1_MASK \
  51. (0x1 << COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET)
  52. #define COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET 27
  53. #define COMMON_PHY_SD_CTRL1_RXAUI0_MASK \
  54. (0x1 << COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET)
  55. /* ToDo: Get this address via DT */
  56. #define MVEBU_CP0_REGS_BASE 0xF2000000UL
  57. #define DFX_DEV_GEN_CTRL12 (MVEBU_CP0_REGS_BASE + 0x400280)
  58. #define DFX_DEV_GEN_PCIE_CLK_SRC_OFFSET 7
  59. #define DFX_DEV_GEN_PCIE_CLK_SRC_MASK \
  60. (0x3 << DFX_DEV_GEN_PCIE_CLK_SRC_OFFSET)
  61. #define MAX_LANE_OPTIONS 10
  62. #define MAX_UTMI_PHY_COUNT 3
  63. struct comphy_mux_options {
  64. u32 type;
  65. u32 mux_value;
  66. };
  67. struct comphy_mux_data {
  68. u32 max_lane_values;
  69. struct comphy_mux_options mux_values[MAX_LANE_OPTIONS];
  70. };
  71. struct comphy_map {
  72. u32 type;
  73. u32 speed;
  74. u32 invert;
  75. bool clk_src;
  76. };
  77. struct chip_serdes_phy_config {
  78. struct comphy_mux_data *mux_data;
  79. int (*ptr_comphy_chip_init)(struct chip_serdes_phy_config *,
  80. struct comphy_map *);
  81. void __iomem *comphy_base_addr;
  82. void __iomem *hpipe3_base_addr;
  83. u32 comphy_lanes_count;
  84. u32 comphy_mux_bitcount;
  85. u32 comphy_index;
  86. };
  87. /* Register helper functions */
  88. void reg_set(void __iomem *addr, u32 data, u32 mask);
  89. void reg_set_silent(void __iomem *addr, u32 data, u32 mask);
  90. void reg_set16(void __iomem *addr, u16 data, u16 mask);
  91. void reg_set_silent16(void __iomem *addr, u16 data, u16 mask);
  92. /* SoC specific init functions */
  93. #ifdef CONFIG_ARMADA_3700
  94. int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  95. struct comphy_map *serdes_map);
  96. #else
  97. static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  98. struct comphy_map *serdes_map)
  99. {
  100. /*
  101. * This function should never be called in this configuration, so
  102. * lets return an error here.
  103. */
  104. return -1;
  105. }
  106. #endif
  107. #ifdef CONFIG_ARMADA_8K
  108. int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  109. struct comphy_map *serdes_map);
  110. #else
  111. static inline int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  112. struct comphy_map *serdes_map)
  113. {
  114. /*
  115. * This function should never be called in this configuration, so
  116. * lets return an error here.
  117. */
  118. return -1;
  119. }
  120. #endif
  121. void comphy_dedicated_phys_init(void);
  122. /* MUX function */
  123. void comphy_mux_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  124. struct comphy_map *comphy_map_data,
  125. void __iomem *selector_base);
  126. void comphy_pcie_config_set(u32 comphy_max_count,
  127. struct comphy_map *serdes_map);
  128. void comphy_pcie_config_detect(u32 comphy_max_count,
  129. struct comphy_map *serdes_map);
  130. void comphy_pcie_unit_general_config(u32 pex_index);
  131. #endif /* _COMPHY_H_ */