fman.c 2.2 KB

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