cpsw-common.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 AM33XX_CTRL_MAC_LO_REG(offset, id) ((offset) + 0x8 * (id))
  20. #define AM33XX_CTRL_MAC_HI_REG(offset, id) ((offset) + 0x8 * (id) + 0x4)
  21. int cpsw_am33xx_cm_get_macid(struct device *dev, u16 offset, int slave,
  22. u8 *mac_addr)
  23. {
  24. u32 macid_lo;
  25. u32 macid_hi;
  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, AM33XX_CTRL_MAC_LO_REG(offset, slave),
  34. &macid_lo);
  35. regmap_read(syscon, AM33XX_CTRL_MAC_HI_REG(offset, slave),
  36. &macid_hi);
  37. mac_addr[5] = (macid_lo >> 8) & 0xff;
  38. mac_addr[4] = macid_lo & 0xff;
  39. mac_addr[3] = (macid_hi >> 24) & 0xff;
  40. mac_addr[2] = (macid_hi >> 16) & 0xff;
  41. mac_addr[1] = (macid_hi >> 8) & 0xff;
  42. mac_addr[0] = macid_hi & 0xff;
  43. return 0;
  44. }
  45. EXPORT_SYMBOL_GPL(cpsw_am33xx_cm_get_macid);
  46. MODULE_LICENSE("GPL");