sgmii_riser.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. printf("Updating PHY address for %s\n", dev->name);
  44. if (!strstr(dev->name, "eTSEC"))
  45. continue;
  46. sprintf(enet, "ethernet%d", etsec_num++);
  47. path = fdt_getprop(fdt, node, enet, NULL);
  48. if (!path) {
  49. debug("No alias for %s\n", enet);
  50. continue;
  51. }
  52. enet_node = fdt_path_offset(fdt, path);
  53. if (enet_node < 0)
  54. continue;
  55. model = fdt_getprop(fdt, enet_node, "model", NULL);
  56. printf("%s's model is %s\n", enet, model);
  57. /*
  58. * We only want to do this to eTSECs. On some platforms
  59. * there are more than one type of gianfar-style ethernet
  60. * controller, and as we are creating an implicit connection
  61. * between ethernet nodes and eTSEC devices, it is best to
  62. * make the connection use as much explicit information
  63. * as exists.
  64. */
  65. if (!strstr(model, "TSEC"))
  66. continue;
  67. phyh = fdt_getprop(fdt, enet_node, "phy-handle", NULL);
  68. if (!phyh)
  69. continue;
  70. phynode = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*phyh));
  71. priv = dev->priv;
  72. printf("Device flags are %x\n", priv->flags);
  73. if (priv->flags & TSEC_SGMII)
  74. fdt_setprop_cell(fdt, phynode, "reg", priv->phyaddr);
  75. }
  76. }