fman.c 2.1 KB

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