sgmii_riser.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Freescale SGMII Riser Card
  3. *
  4. * This driver supports the SGMII Riser card found on the
  5. * "DS" style of development board from Freescale.
  6. *
  7. * This software may be used and distributed according to the
  8. * terms of the GNU Public License, Version 2, incorporated
  9. * herein by reference.
  10. *
  11. * Copyright 2008 Freescale Semiconductor, Inc.
  12. *
  13. */
  14. #include <config.h>
  15. #include <common.h>
  16. #include <net.h>
  17. #include <libfdt.h>
  18. #include <tsec.h>
  19. void fsl_sgmii_riser_init(struct tsec_info_struct *tsec_info, int num)
  20. {
  21. int i;
  22. for (i = 0; i < num; i++)
  23. if (tsec_info[i].flags & TSEC_SGMII)
  24. tsec_info[i].phyaddr += SGMII_RISER_PHY_OFFSET;
  25. }
  26. void fsl_sgmii_riser_fdt_fixup(void *fdt)
  27. {
  28. struct eth_device *dev;
  29. int node;
  30. int i = -1;
  31. int etsec_num = 0;
  32. node = fdt_path_offset(fdt, "/aliases");
  33. if (node < 0)
  34. return;
  35. while ((dev = eth_get_dev_by_index(++i)) != NULL) {
  36. struct tsec_private *priv;
  37. int enet_node;
  38. char enet[16];
  39. const u32 *phyh;
  40. int phynode;
  41. const char *model;
  42. const char *path;
  43. if (!strstr(dev->name, "eTSEC"))
  44. continue;
  45. sprintf(enet, "ethernet%d", etsec_num++);
  46. path = fdt_getprop(fdt, node, enet, NULL);
  47. if (!path) {
  48. debug("No alias for %s\n", enet);
  49. continue;
  50. }
  51. enet_node = fdt_path_offset(fdt, path);
  52. if (enet_node < 0)
  53. continue;
  54. model = fdt_getprop(fdt, enet_node, "model", NULL);
  55. /*
  56. * We only want to do this to eTSECs. On some platforms
  57. * there are more than one type of gianfar-style ethernet
  58. * controller, and as we are creating an implicit connection
  59. * between ethernet nodes and eTSEC devices, it is best to
  60. * make the connection use as much explicit information
  61. * as exists.
  62. */
  63. if (!strstr(model, "TSEC"))
  64. continue;
  65. phyh = fdt_getprop(fdt, enet_node, "phy-handle", NULL);
  66. if (!phyh)
  67. continue;
  68. phynode = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*phyh));
  69. priv = dev->priv;
  70. if (priv->flags & TSEC_SGMII)
  71. fdt_setprop_cell(fdt, phynode, "reg", priv->phyaddr);
  72. }
  73. }