fman.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2011-2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <libfdt.h>
  8. #include <libfdt_env.h>
  9. #include <fdt_support.h>
  10. #include <fm_eth.h>
  11. #ifdef CONFIG_FSL_LAYERSCAPE
  12. #include <asm/arch/fsl_serdes.h>
  13. #else
  14. #include <asm/fsl_serdes.h>
  15. #endif
  16. /*
  17. * Given the following ...
  18. *
  19. * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
  20. * compatible string and 'addr' physical address)
  21. *
  22. * 2) The name of an alias that points to the ethernet-phy node (usually inside
  23. * a virtual MDIO node)
  24. *
  25. * ... update that Ethernet node's phy-handle property to point to the
  26. * ethernet-phy node. This is how we link an Ethernet node to its PHY, so each
  27. * PHY in a virtual MDIO node must have an alias.
  28. *
  29. * Returns 0 on success, or a negative FDT error code on error.
  30. */
  31. int fdt_set_phy_handle(void *fdt, char *compat, phys_addr_t addr,
  32. const char *alias)
  33. {
  34. int offset;
  35. unsigned int ph;
  36. const char *path;
  37. /* Get a path to the node that 'alias' points to */
  38. path = fdt_get_alias(fdt, alias);
  39. if (!path)
  40. return -FDT_ERR_BADPATH;
  41. /* Get the offset of that node */
  42. offset = fdt_path_offset(fdt, path);
  43. if (offset < 0)
  44. return offset;
  45. ph = fdt_create_phandle(fdt, offset);
  46. if (!ph)
  47. return -FDT_ERR_BADPHANDLE;
  48. ph = cpu_to_fdt32(ph);
  49. offset = fdt_node_offset_by_compat_reg(fdt, compat, addr);
  50. if (offset < 0)
  51. return offset;
  52. return fdt_setprop(fdt, offset, "phy-handle", &ph, sizeof(ph));
  53. }
  54. /*
  55. * Return the SerDes device enum for a given Fman port
  56. *
  57. * This function just maps the fm_port namespace to the srds_prtcl namespace.
  58. */
  59. enum srds_prtcl serdes_device_from_fm_port(enum fm_port port)
  60. {
  61. static const enum srds_prtcl srds_table[] = {
  62. [FM1_DTSEC1] = SGMII_FM1_DTSEC1,
  63. [FM1_DTSEC2] = SGMII_FM1_DTSEC2,
  64. [FM1_DTSEC3] = SGMII_FM1_DTSEC3,
  65. [FM1_DTSEC4] = SGMII_FM1_DTSEC4,
  66. [FM1_DTSEC5] = SGMII_FM1_DTSEC5,
  67. [FM1_10GEC1] = XAUI_FM1,
  68. [FM2_DTSEC1] = SGMII_FM2_DTSEC1,
  69. [FM2_DTSEC2] = SGMII_FM2_DTSEC2,
  70. [FM2_DTSEC3] = SGMII_FM2_DTSEC3,
  71. [FM2_DTSEC4] = SGMII_FM2_DTSEC4,
  72. [FM2_DTSEC5] = SGMII_FM2_DTSEC5,
  73. [FM2_10GEC1] = XAUI_FM2,
  74. };
  75. if ((port < FM1_DTSEC1) || (port > FM2_10GEC1))
  76. return NONE;
  77. else
  78. return srds_table[port];
  79. }