cpsw-common.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/of.h>
  15. #include <linux/of_device.h>
  16. #include <linux/regmap.h>
  17. #include <linux/mfd/syscon.h>
  18. #include "cpsw.h"
  19. #define CTRL_MAC_LO_REG(offset, id) ((offset) + 0x8 * (id))
  20. #define CTRL_MAC_HI_REG(offset, id) ((offset) + 0x8 * (id) + 0x4)
  21. static int davinci_emac_3517_get_macid(struct device *dev, u16 offset,
  22. int slave, u8 *mac_addr)
  23. {
  24. u32 macid_lsb;
  25. u32 macid_msb;
  26. struct regmap *syscon;
  27. syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
  28. if (IS_ERR(syscon)) {
  29. if (PTR_ERR(syscon) == -ENODEV)
  30. return 0;
  31. return PTR_ERR(syscon);
  32. }
  33. regmap_read(syscon, CTRL_MAC_LO_REG(offset, slave), &macid_lsb);
  34. regmap_read(syscon, CTRL_MAC_HI_REG(offset, slave), &macid_msb);
  35. mac_addr[0] = (macid_msb >> 16) & 0xff;
  36. mac_addr[1] = (macid_msb >> 8) & 0xff;
  37. mac_addr[2] = macid_msb & 0xff;
  38. mac_addr[3] = (macid_lsb >> 16) & 0xff;
  39. mac_addr[4] = (macid_lsb >> 8) & 0xff;
  40. mac_addr[5] = macid_lsb & 0xff;
  41. return 0;
  42. }
  43. static int cpsw_am33xx_cm_get_macid(struct device *dev, u16 offset, int slave,
  44. u8 *mac_addr)
  45. {
  46. u32 macid_lo;
  47. u32 macid_hi;
  48. struct regmap *syscon;
  49. syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
  50. if (IS_ERR(syscon)) {
  51. if (PTR_ERR(syscon) == -ENODEV)
  52. return 0;
  53. return PTR_ERR(syscon);
  54. }
  55. regmap_read(syscon, CTRL_MAC_LO_REG(offset, slave), &macid_lo);
  56. regmap_read(syscon, CTRL_MAC_HI_REG(offset, slave), &macid_hi);
  57. mac_addr[5] = (macid_lo >> 8) & 0xff;
  58. mac_addr[4] = macid_lo & 0xff;
  59. mac_addr[3] = (macid_hi >> 24) & 0xff;
  60. mac_addr[2] = (macid_hi >> 16) & 0xff;
  61. mac_addr[1] = (macid_hi >> 8) & 0xff;
  62. mac_addr[0] = macid_hi & 0xff;
  63. return 0;
  64. }
  65. int ti_cm_get_macid(struct device *dev, int slave, u8 *mac_addr)
  66. {
  67. if (of_machine_is_compatible("ti,dm8148"))
  68. return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
  69. if (of_machine_is_compatible("ti,am33xx"))
  70. return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
  71. if (of_device_is_compatible(dev->of_node, "ti,am3517-emac"))
  72. return davinci_emac_3517_get_macid(dev, 0x110, slave, mac_addr);
  73. if (of_device_is_compatible(dev->of_node, "ti,dm816-emac"))
  74. return cpsw_am33xx_cm_get_macid(dev, 0x30, slave, mac_addr);
  75. if (of_machine_is_compatible("ti,am4372"))
  76. return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
  77. if (of_machine_is_compatible("ti,dra7"))
  78. return davinci_emac_3517_get_macid(dev, 0x514, slave, mac_addr);
  79. dev_err(dev, "incompatible machine/device type for reading mac address\n");
  80. return -ENOENT;
  81. }
  82. EXPORT_SYMBOL_GPL(ti_cm_get_macid);
  83. MODULE_LICENSE("GPL");