comphy_core.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2015-2016 Marvell International Ltd.
  4. */
  5. #ifndef _COMPHY_CORE_H_
  6. #define _COMPHY_CORE_H_
  7. #include <fdtdec.h>
  8. #include <mvebu/comphy.h>
  9. #include <dt-bindings/comphy/comphy_data.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. #define MAX_LANE_OPTIONS 10
  18. #define MAX_UTMI_PHY_COUNT 6
  19. struct comphy_map {
  20. u32 type;
  21. u32 speed;
  22. u32 invert;
  23. bool clk_src;
  24. bool end_point;
  25. };
  26. struct comphy_mux_options {
  27. u32 type;
  28. u32 mux_value;
  29. };
  30. struct comphy_mux_data {
  31. u32 max_lane_values;
  32. struct comphy_mux_options mux_values[MAX_LANE_OPTIONS];
  33. };
  34. struct chip_serdes_phy_config {
  35. struct comphy_mux_data *mux_data;
  36. int (*comphy_init_map)(int, struct chip_serdes_phy_config *);
  37. int (*ptr_comphy_chip_init)(struct chip_serdes_phy_config *,
  38. struct comphy_map *);
  39. int (*rx_training)(struct chip_serdes_phy_config *, u32);
  40. void __iomem *comphy_base_addr;
  41. void __iomem *hpipe3_base_addr;
  42. u32 comphy_lanes_count;
  43. u32 comphy_mux_bitcount;
  44. const fdt32_t *comphy_mux_lane_order;
  45. u32 cp_index;
  46. struct comphy_map comphy_map_data[MAX_LANE_OPTIONS];
  47. };
  48. /* Register helper functions */
  49. static inline void reg_set_silent(void __iomem *addr, u32 data, u32 mask)
  50. {
  51. u32 reg_data;
  52. reg_data = readl(addr);
  53. reg_data &= ~mask;
  54. reg_data |= data;
  55. writel(reg_data, addr);
  56. }
  57. static inline void reg_set(void __iomem *addr, u32 data, u32 mask)
  58. {
  59. debug("Write to address = %#010lx, data = %#010x (mask = %#010x) - ",
  60. (unsigned long)addr, data, mask);
  61. debug("old value = %#010x ==> ", readl(addr));
  62. reg_set_silent(addr, data, mask);
  63. debug("new value %#010x\n", readl(addr));
  64. }
  65. static inline void reg_set_silent16(void __iomem *addr, u16 data, u16 mask)
  66. {
  67. u16 reg_data;
  68. reg_data = readw(addr);
  69. reg_data &= ~mask;
  70. reg_data |= data;
  71. writew(reg_data, addr);
  72. }
  73. static inline void reg_set16(void __iomem *addr, u16 data, u16 mask)
  74. {
  75. debug("Write to address = %#010lx, data = %#06x (mask = %#06x) - ",
  76. (unsigned long)addr, data, mask);
  77. debug("old value = %#06x ==> ", readw(addr));
  78. reg_set_silent16(addr, data, mask);
  79. debug("new value %#06x\n", readw(addr));
  80. }
  81. /* SoC specific init functions */
  82. #ifdef CONFIG_ARMADA_3700
  83. int comphy_a3700_init_serdes_map(int node, struct chip_serdes_phy_config *cfg);
  84. int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  85. struct comphy_map *serdes_map);
  86. #else
  87. static inline int
  88. comphy_a3700_init_serdes_map(int node, struct chip_serdes_phy_config *cfg)
  89. {
  90. /*
  91. * This function should never be called in this configuration, so
  92. * lets return an error here.
  93. */
  94. return -1;
  95. }
  96. static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  97. struct comphy_map *serdes_map)
  98. {
  99. /*
  100. * This function should never be called in this configuration, so
  101. * lets return an error here.
  102. */
  103. return -1;
  104. }
  105. #endif
  106. #ifdef CONFIG_ARMADA_8K
  107. int comphy_cp110_init_serdes_map(int node, struct chip_serdes_phy_config *cfg);
  108. int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  109. struct comphy_map *serdes_map);
  110. int comphy_cp110_sfi_rx_training(struct chip_serdes_phy_config *ptr_chip_cfg,
  111. u32 lane);
  112. #else
  113. static inline int
  114. comphy_cp110_init_serdes_map(int node, struct chip_serdes_phy_config *cfg)
  115. {
  116. /*
  117. * This function should never be called in this configuration, so
  118. * lets return an error here.
  119. */
  120. return -1;
  121. }
  122. static inline int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  123. struct comphy_map *serdes_map)
  124. {
  125. /*
  126. * This function should never be called in this configuration, so
  127. * lets return an error here.
  128. */
  129. return -1;
  130. }
  131. static inline int comphy_cp110_sfi_rx_training(
  132. struct chip_serdes_phy_config *ptr_chip_cfg,
  133. u32 lane)
  134. {
  135. /*
  136. * This function should never be called in this configuration, so
  137. * lets return an error here.
  138. */
  139. return -1;
  140. }
  141. #endif
  142. void comphy_dedicated_phys_init(void);
  143. /* MUX function */
  144. void comphy_mux_init(struct chip_serdes_phy_config *ptr_chip_cfg,
  145. struct comphy_map *comphy_map_data,
  146. void __iomem *selector_base);
  147. void comphy_pcie_config_set(u32 comphy_max_count,
  148. struct comphy_map *serdes_map);
  149. void comphy_pcie_config_detect(u32 comphy_max_count,
  150. struct comphy_map *serdes_map);
  151. void comphy_pcie_unit_general_config(u32 pex_index);
  152. #endif /* _COMPHY_CORE_H_ */