fman.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /*
  27. * Given the following ...
  28. *
  29. * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
  30. * compatible string and 'addr' physical address)
  31. *
  32. * 2) The name of an alias that points to the ethernet-phy node (usually inside
  33. * a virtual MDIO node)
  34. *
  35. * ... update that Ethernet node's phy-handle property to point to the
  36. * ethernet-phy node. This is how we link an Ethernet node to its PHY, so each
  37. * PHY in a virtual MDIO node must have an alias.
  38. */
  39. void fdt_set_phy_handle(void *fdt, char *compat, phys_addr_t addr,
  40. const char *alias)
  41. {
  42. int offset, ph;
  43. const char *path;
  44. /* Get a path to the node that 'alias' points to */
  45. path = fdt_get_alias(fdt, alias);
  46. if (path) {
  47. /* Get the offset of that node */
  48. int off = fdt_path_offset(fdt, path);
  49. if (off > 0)
  50. ph = fdt_create_phandle(fdt, off);
  51. else
  52. return;
  53. } else {
  54. return ;
  55. }
  56. /* failed to create a phandle */
  57. if (ph <= 0)
  58. return ;
  59. offset = fdt_node_offset_by_compat_reg(fdt, compat, addr);
  60. if (offset > 0)
  61. fdt_setprop(fdt, offset, "phy-handle", &ph, sizeof(ph));
  62. }