fman.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <libfdt.h>
  24. #include <libfdt_env.h>
  25. #include <fdt_support.h>
  26. #include <fm_eth.h>
  27. #include <asm/fsl_serdes.h>
  28. /*
  29. * Given the following ...
  30. *
  31. * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
  32. * compatible string and 'addr' physical address)
  33. *
  34. * 2) The name of an alias that points to the ethernet-phy node (usually inside
  35. * a virtual MDIO node)
  36. *
  37. * ... update that Ethernet node's phy-handle property to point to the
  38. * ethernet-phy node. This is how we link an Ethernet node to its PHY, so each
  39. * PHY in a virtual MDIO node must have an alias.
  40. *
  41. * Returns 0 on success, or a negative FDT error code on error.
  42. */
  43. int fdt_set_phy_handle(void *fdt, char *compat, phys_addr_t addr,
  44. const char *alias)
  45. {
  46. int offset;
  47. unsigned int ph;
  48. const char *path;
  49. /* Get a path to the node that 'alias' points to */
  50. path = fdt_get_alias(fdt, alias);
  51. if (!path)
  52. return -FDT_ERR_BADPATH;
  53. /* Get the offset of that node */
  54. offset = fdt_path_offset(fdt, path);
  55. if (offset < 0)
  56. return offset;
  57. ph = fdt_create_phandle(fdt, offset);
  58. if (!ph)
  59. return -FDT_ERR_BADPHANDLE;
  60. offset = fdt_node_offset_by_compat_reg(fdt, compat, addr);
  61. if (offset < 0)
  62. return offset;
  63. return fdt_setprop(fdt, offset, "phy-handle", &ph, sizeof(ph));
  64. }
  65. /*
  66. * Return the SerDes device enum for a given Fman port
  67. *
  68. * This function just maps the fm_port namespace to the srds_prtcl namespace.
  69. */
  70. enum srds_prtcl serdes_device_from_fm_port(enum fm_port port)
  71. {
  72. static const enum srds_prtcl srds_table[] = {
  73. [FM1_DTSEC1] = SGMII_FM1_DTSEC1,
  74. [FM1_DTSEC2] = SGMII_FM1_DTSEC2,
  75. [FM1_DTSEC3] = SGMII_FM1_DTSEC3,
  76. [FM1_DTSEC4] = SGMII_FM1_DTSEC4,
  77. [FM1_DTSEC5] = SGMII_FM1_DTSEC5,
  78. [FM1_10GEC1] = XAUI_FM1,
  79. [FM2_DTSEC1] = SGMII_FM2_DTSEC1,
  80. [FM2_DTSEC2] = SGMII_FM2_DTSEC2,
  81. [FM2_DTSEC3] = SGMII_FM2_DTSEC3,
  82. [FM2_DTSEC4] = SGMII_FM2_DTSEC4,
  83. [FM2_DTSEC5] = SGMII_FM2_DTSEC5,
  84. [FM2_10GEC1] = XAUI_FM2,
  85. };
  86. if ((port < FM1_DTSEC1) || (port > FM2_10GEC1))
  87. return NONE;
  88. else
  89. return srds_table[port];
  90. }