fec.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) 2019 Angelo Dureghello <angelo.dureghello@timesys.com>
  4. */
  5. #include <common.h>
  6. #include <asm/global_data.h>
  7. #include <linux/libfdt.h>
  8. #include <fdt_support.h>
  9. DECLARE_GLOBAL_DATA_PTR;
  10. #if defined(CONFIG_MCFFEC) || defined(CONFIG_FSLDMAFEC)
  11. static int fec_get_node(int fec_idx)
  12. {
  13. char fec_alias[5] = {"fec"};
  14. const char *path;
  15. int node;
  16. if (fec_idx > 1) {
  17. puts("Invalid MII base index");
  18. return -ENOENT;
  19. }
  20. fec_alias[3] = fec_idx + '0';
  21. path = fdt_get_alias(gd->fdt_blob, fec_alias);
  22. if (!path) {
  23. puts("Invalid MII path");
  24. return -ENOENT;
  25. }
  26. node = fdt_path_offset(gd->fdt_blob, path);
  27. if (node < 0)
  28. return -ENOENT;
  29. return node;
  30. }
  31. int fec_get_fdt_prop(int fec_idx, const char *prop, u32 *value)
  32. {
  33. int node;
  34. const u32 *val;
  35. node = fec_get_node(fec_idx);
  36. if (node < 0)
  37. return node;
  38. val = fdt_getprop(gd->fdt_blob, node, prop, NULL);
  39. if (!val)
  40. return -ENOENT;
  41. *value = fdt32_to_cpu(*val);
  42. return 0;
  43. }
  44. int fec_get_base_addr(int fec_idx, u32 *fec_iobase)
  45. {
  46. int node;
  47. fdt_size_t size;
  48. fdt_addr_t addr;
  49. node = fec_get_node(fec_idx);
  50. if (node < 0)
  51. return node;
  52. addr = fdtdec_get_addr_size(gd->fdt_blob, node, "reg", &size);
  53. *fec_iobase = (u32)addr;
  54. return 0;
  55. }
  56. int fec_get_mii_base(int fec_idx, u32 *mii_base)
  57. {
  58. return fec_get_fdt_prop(fec_idx, "mii-base", mii_base);
  59. }
  60. #endif //CONFIG_MCFFEC || CONFIG_FSLDMAFEC