comphy_core.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015-2016 Marvell International Ltd.
  4. *
  5. * Copyright (C) 2016 Stefan Roese <sr@denx.de>
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <fdtdec.h>
  10. #include <asm/global_data.h>
  11. #include <asm/io.h>
  12. #include <dm/device_compat.h>
  13. #include <linux/err.h>
  14. #include <linux/errno.h>
  15. #include <linux/libfdt.h>
  16. #include "comphy_core.h"
  17. #define COMPHY_MAX_CHIP 4
  18. DECLARE_GLOBAL_DATA_PTR;
  19. static const char *get_speed_string(u32 speed)
  20. {
  21. static const char * const speed_strings[] = {
  22. "1.25 Gbps", "2.5 Gbps", "3.125 Gbps",
  23. "5 Gbps", "5.125 Gpbs", "6 Gbps",
  24. "10.3125 Gbps"
  25. };
  26. if (speed < 0 || speed > COMPHY_SPEED_MAX)
  27. return "invalid";
  28. return speed_strings[speed];
  29. }
  30. static const char *get_type_string(u32 type)
  31. {
  32. static const char * const type_strings[] = {
  33. "UNCONNECTED", "PEX0", "PEX1", "PEX2", "PEX3",
  34. "SATA0", "SATA1", "SGMII0", "SGMII1", "SGMII2",
  35. "USB3", "USB3_HOST0", "USB3_HOST1",
  36. "USB3_DEVICE", "RXAUI0", "RXAUI1", "SFI0", "SFI1", "AP",
  37. "IGNORE"
  38. };
  39. if (type < 0 || type > COMPHY_TYPE_MAX)
  40. return "invalid";
  41. return type_strings[type];
  42. }
  43. void comphy_print(struct chip_serdes_phy_config *chip_cfg,
  44. struct comphy_map *comphy_map_data)
  45. {
  46. u32 lane;
  47. for (lane = 0; lane < chip_cfg->comphy_lanes_count;
  48. lane++, comphy_map_data++) {
  49. if (comphy_map_data->speed == COMPHY_SPEED_INVALID) {
  50. printf("Comphy-%d: %-13s\n", lane,
  51. get_type_string(comphy_map_data->type));
  52. } else {
  53. printf("Comphy-%d: %-13s %-10s\n", lane,
  54. get_type_string(comphy_map_data->type),
  55. get_speed_string(comphy_map_data->speed));
  56. }
  57. }
  58. }
  59. int comphy_rx_training(struct udevice *dev, u32 lane)
  60. {
  61. struct chip_serdes_phy_config *chip_cfg = dev_get_priv(dev);
  62. if (chip_cfg->rx_training)
  63. return chip_cfg->rx_training(chip_cfg, lane);
  64. return 0;
  65. }
  66. static int comphy_probe(struct udevice *dev)
  67. {
  68. int node = dev_of_offset(dev);
  69. struct chip_serdes_phy_config *chip_cfg = dev_get_priv(dev);
  70. int last_idx = 0;
  71. static int current_idx;
  72. int res;
  73. /* Save base addresses for later use */
  74. chip_cfg->comphy_base_addr = devfdt_get_addr_index_ptr(dev, 0);
  75. if (!chip_cfg->comphy_base_addr)
  76. return -EINVAL;
  77. chip_cfg->hpipe3_base_addr = devfdt_get_addr_index_ptr(dev, 1);
  78. if (!chip_cfg->hpipe3_base_addr)
  79. return -EINVAL;
  80. if (device_is_compatible(dev, "marvell,comphy-a3700")) {
  81. chip_cfg->comphy_init_map = comphy_a3700_init_serdes_map;
  82. chip_cfg->ptr_comphy_chip_init = comphy_a3700_init;
  83. chip_cfg->rx_training = NULL;
  84. }
  85. if (device_is_compatible(dev, "marvell,comphy-cp110")) {
  86. chip_cfg->comphy_init_map = comphy_cp110_init_serdes_map;
  87. chip_cfg->ptr_comphy_chip_init = comphy_cp110_init;
  88. chip_cfg->rx_training = comphy_cp110_sfi_rx_training;
  89. }
  90. /*
  91. * Bail out if no chip_init function is defined, e.g. no
  92. * compatible node is found
  93. */
  94. if (!chip_cfg->ptr_comphy_chip_init) {
  95. dev_err(dev, "comphy: No compatible DT node found\n");
  96. return -ENODEV;
  97. }
  98. res = chip_cfg->comphy_init_map(node, chip_cfg);
  99. if (res < 0)
  100. return res;
  101. /* Save CP index for MultiCP devices (A8K) */
  102. chip_cfg->cp_index = current_idx++;
  103. /* PHY power UP sequence */
  104. chip_cfg->ptr_comphy_chip_init(chip_cfg, chip_cfg->comphy_map_data);
  105. /* PHY print SerDes status */
  106. printf("Comphy chip #%d:\n", chip_cfg->cp_index);
  107. comphy_print(chip_cfg, chip_cfg->comphy_map_data);
  108. /*
  109. * Only run the dedicated PHY init code once, in the last PHY init call
  110. */
  111. if (of_machine_is_compatible("marvell,armada8040"))
  112. last_idx = 1;
  113. if (chip_cfg->cp_index == last_idx) {
  114. /* Initialize dedicated PHYs (not muxed SerDes lanes) */
  115. comphy_dedicated_phys_init();
  116. }
  117. return 0;
  118. }
  119. static const struct udevice_id comphy_ids[] = {
  120. { .compatible = "marvell,mvebu-comphy" },
  121. { .compatible = "marvell,comphy-a3700" },
  122. { }
  123. };
  124. U_BOOT_DRIVER(mvebu_comphy) = {
  125. .name = "mvebu_comphy",
  126. .id = UCLASS_MISC,
  127. .of_match = comphy_ids,
  128. .probe = comphy_probe,
  129. .priv_auto = sizeof(struct chip_serdes_phy_config),
  130. };