comphy.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2015-2016 Marvell International Ltd.
  4. */
  5. #ifndef _COMPHY_H_
  6. #define _COMPHY_H_
  7. #include <dt-bindings/comphy/comphy_data.h>
  8. #include <fdtdec.h>
  9. #if defined(DEBUG)
  10. #define debug_enter() printf("----> Enter %s\n", __func__);
  11. #define debug_exit() printf("<---- Exit %s\n", __func__);
  12. #else
  13. #define debug_enter()
  14. #define debug_exit()
  15. #endif
  16. /* COMPHY registers */
  17. #define COMMON_PHY_CFG1_REG 0x0
  18. #define COMMON_PHY_CFG1_PWR_UP_OFFSET 1
  19. #define COMMON_PHY_CFG1_PWR_UP_MASK \
  20. (0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET)
  21. #define COMMON_PHY_CFG1_PIPE_SELECT_OFFSET 2
  22. #define COMMON_PHY_CFG1_PIPE_SELECT_MASK \
  23. (0x1 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET)
  24. #define COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET 13
  25. #define COMMON_PHY_CFG1_PWR_ON_RESET_MASK \
  26. (0x1 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET)
  27. #define COMMON_PHY_CFG1_CORE_RSTN_OFFSET 14
  28. #define COMMON_PHY_CFG1_CORE_RSTN_MASK \
  29. (0x1 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET)
  30. #define COMMON_PHY_PHY_MODE_OFFSET 15
  31. #define COMMON_PHY_PHY_MODE_MASK \
  32. (0x1 << COMMON_PHY_PHY_MODE_OFFSET)
  33. #define COMMON_PHY_CFG6_REG 0x14
  34. #define COMMON_PHY_CFG6_IF_40_SEL_OFFSET 18
  35. #define COMMON_PHY_CFG6_IF_40_SEL_MASK \
  36. (0x1 << COMMON_PHY_CFG6_IF_40_SEL_OFFSET)
  37. #define COMMON_SELECTOR_PHY_OFFSET 0x140
  38. #define COMMON_SELECTOR_PIPE_OFFSET 0x144
  39. #define COMMON_PHY_SD_CTRL1 0x148
  40. #define COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_OFFSET 0
  41. #define COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_MASK 0xFFFF
  42. #define COMMON_PHY_SD_CTRL1_PCIE_X4_EN_OFFSET 24
  43. #define COMMON_PHY_SD_CTRL1_PCIE_X4_EN_MASK \
  44. (0x1 << COMMON_PHY_SD_CTRL1_PCIE_X4_EN_OFFSET)
  45. #define COMMON_PHY_SD_CTRL1_PCIE_X2_EN_OFFSET 25
  46. #define COMMON_PHY_SD_CTRL1_PCIE_X2_EN_MASK \
  47. (0x1 << COMMON_PHY_SD_CTRL1_PCIE_X2_EN_OFFSET)
  48. #define COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET 26
  49. #define COMMON_PHY_SD_CTRL1_RXAUI1_MASK \
  50. (0x1 << COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET)
  51. #define COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET 27
  52. #define COMMON_PHY_SD_CTRL1_RXAUI0_MASK \
  53. (0x1 << COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET)
  54. /* ToDo: Get this address via DT */
  55. #define MVEBU_CP0_REGS_BASE 0xF2000000UL
  56. #define DFX_DEV_GEN_CTRL12 (MVEBU_CP0_REGS_BASE + 0x400280)
  57. #define DFX_DEV_GEN_PCIE_CLK_SRC_OFFSET 7
  58. #define DFX_DEV_GEN_PCIE_CLK_SRC_MASK \
  59. (0x3 << DFX_DEV_GEN_PCIE_CLK_SRC_OFFSET)
  60. #define MAX_LANE_OPTIONS 10
  61. #define MAX_UTMI_PHY_COUNT 3
  62. struct comphy_mux_options {
  63. u32 type;
  64. u32 mux_value;
  65. };
  66. struct comphy_mux_data {
  67. u32 max_lane_values;
  68. struct comphy_mux_options mux_values[MAX_LANE_OPTIONS];
  69. };
  70. struct comphy_map {
  71. u32 type;
  72. u32 speed;
  73. u32 invert;
  74. bool clk_src;
  75. bool end_point;
  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. const fdt32_t *comphy_mux_lane_order;
  86. u32 cp_index;
  87. };
  88. /* Register helper functions */
  89. static inline void reg_set_silent(void __iomem *addr, u32 data, u32 mask)
  90. {
  91. u32 reg_data;
  92. reg_data = readl(addr);
  93. reg_data &= ~mask;
  94. reg_data |= data;
  95. writel(reg_data, addr);
  96. }
  97. static inline void reg_set(void __iomem *addr, u32 data, u32 mask)
  98. {
  99. debug("Write to address = %#010lx, data = %#010x (mask = %#010x) - ",
  100. (unsigned long)addr, data, mask);
  101. debug("old value = %#010x ==> ", readl(addr));
  102. reg_set_silent(addr, data, mask);
  103. debug("new value %#010x\n", readl(addr));
  104. }
  105. static inline void reg_set_silent16(void __iomem *addr, u16 data, u16 mask)
  106. {
  107. u16 reg_data;
  108. reg_data = readw(addr);
  109. reg_data &= ~mask;
  110. reg_data |= data;
  111. writew(reg_data, addr);
  112. }
  113. static inline void reg_set16(void __iomem *addr, u16 data, u16 mask)
  114. {
  115. debug("Write to address = %#010lx, data = %#06x (mask = %#06x) - ",
  116. (unsigned long)addr, data, mask);
  117. debug("old value = %#06x ==> ", readw(addr));
  118. reg_set_silent16(addr, data, mask);
  119. debug("new value %#06x\n", readw(addr));
  120. }
  121. /* SoC specific init functions */
  122. #ifdef CONFIG_ARMADA_3700
  123. int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  124. struct comphy_map *serdes_map);
  125. #else
  126. static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  127. struct comphy_map *serdes_map)
  128. {
  129. /*
  130. * This function should never be called in this configuration, so
  131. * lets return an error here.
  132. */
  133. return -1;
  134. }
  135. #endif
  136. #ifdef CONFIG_ARMADA_8K
  137. int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  138. struct comphy_map *serdes_map);
  139. #else
  140. static inline int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  141. struct comphy_map *serdes_map)
  142. {
  143. /*
  144. * This function should never be called in this configuration, so
  145. * lets return an error here.
  146. */
  147. return -1;
  148. }
  149. #endif
  150. void comphy_dedicated_phys_init(void);
  151. /* MUX function */
  152. void comphy_mux_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  153. struct comphy_map *comphy_map_data,
  154. void __iomem *selector_base);
  155. void comphy_pcie_config_set(u32 comphy_max_count,
  156. struct comphy_map *serdes_map);
  157. void comphy_pcie_config_detect(u32 comphy_max_count,
  158. struct comphy_map *serdes_map);
  159. void comphy_pcie_unit_general_config(u32 pex_index);
  160. #endif /* _COMPHY_H_ */