cpsw-common.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * CPSW common - libs used across TI ethernet devices.
  4. *
  5. * Copyright (C) 2016, Texas Instruments, Incorporated
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <fdt_support.h>
  10. #include <asm/global_data.h>
  11. #include <asm/io.h>
  12. #include <cpsw.h>
  13. #include <dm/device_compat.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. #define CTRL_MAC_REG(offset, id) ((offset) + 0x8 * (id))
  16. static void davinci_emac_3517_get_macid(u32 addr, u8 *mac_addr)
  17. {
  18. /* try reading mac address from efuse */
  19. u32 macid_lsb = readl(addr);
  20. u32 macid_msb = readl(addr + 4);
  21. mac_addr[0] = (macid_msb >> 16) & 0xff;
  22. mac_addr[1] = (macid_msb >> 8) & 0xff;
  23. mac_addr[2] = macid_msb & 0xff;
  24. mac_addr[3] = (macid_lsb >> 16) & 0xff;
  25. mac_addr[4] = (macid_lsb >> 8) & 0xff;
  26. mac_addr[5] = macid_lsb & 0xff;
  27. }
  28. static void cpsw_am33xx_cm_get_macid(u32 addr, u8 *mac_addr)
  29. {
  30. /* try reading mac address from efuse */
  31. u32 macid_lo = readl(addr);
  32. u32 macid_hi = readl(addr + 4);
  33. mac_addr[5] = (macid_lo >> 8) & 0xff;
  34. mac_addr[4] = macid_lo & 0xff;
  35. mac_addr[3] = (macid_hi >> 24) & 0xff;
  36. mac_addr[2] = (macid_hi >> 16) & 0xff;
  37. mac_addr[1] = (macid_hi >> 8) & 0xff;
  38. mac_addr[0] = macid_hi & 0xff;
  39. }
  40. void ti_cm_get_macid(struct udevice *dev, struct cpsw_platform_data *data,
  41. u8 *mac_addr)
  42. {
  43. if (!strcmp(data->macid_sel_compat, "cpsw,am33xx"))
  44. cpsw_am33xx_cm_get_macid(data->syscon_addr, mac_addr);
  45. else if (!strcmp(data->macid_sel_compat, "davinci,emac"))
  46. davinci_emac_3517_get_macid(data->syscon_addr, mac_addr);
  47. }
  48. int ti_cm_get_macid_addr(struct udevice *dev, int slave,
  49. struct cpsw_platform_data *data)
  50. {
  51. void *fdt = (void *)gd->fdt_blob;
  52. int node = dev_of_offset(dev);
  53. fdt32_t gmii = 0;
  54. int syscon;
  55. u16 offset;
  56. if (of_machine_is_compatible("ti,dm8148")) {
  57. offset = 0x630;
  58. data->macid_sel_compat = "cpsw,am33xx";
  59. } else if (of_machine_is_compatible("ti,am33xx")) {
  60. offset = 0x630;
  61. data->macid_sel_compat = "cpsw,am33xx";
  62. } else if (device_is_compatible(dev, "ti,am3517-emac")) {
  63. offset = 0x110;
  64. data->macid_sel_compat = "davinci,emac";
  65. } else if (device_is_compatible(dev, "ti,dm816-emac")) {
  66. offset = 0x30;
  67. data->macid_sel_compat = "cpsw,am33xx";
  68. } else if (of_machine_is_compatible("ti,am43")) {
  69. offset = 0x630;
  70. data->macid_sel_compat = "cpsw,am33xx";
  71. } else if (of_machine_is_compatible("ti,dra7")) {
  72. offset = 0x514;
  73. data->macid_sel_compat = "davinci,emac";
  74. } else {
  75. dev_err(dev, "incompatible machine/device type for reading mac address\n");
  76. return -ENOENT;
  77. }
  78. syscon = fdtdec_lookup_phandle(fdt, node, "syscon");
  79. if (syscon < 0) {
  80. pr_err("Syscon offset not found\n");
  81. return -ENOENT;
  82. }
  83. data->syscon_addr = (u32)map_physmem(fdt_translate_address(fdt, syscon,
  84. &gmii),
  85. sizeof(u32), MAP_NOCACHE);
  86. if (data->syscon_addr == FDT_ADDR_T_NONE) {
  87. pr_err("Not able to get syscon address to get mac efuse address\n");
  88. return -ENOENT;
  89. }
  90. data->syscon_addr += CTRL_MAC_REG(offset, slave);
  91. return 0;
  92. }