0117-NET-add-of_get_mac_address_mtd.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. From 1282a0da09e059288eb8b576998ea001680f6628 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Sun, 14 Jul 2013 23:26:15 +0200
  4. Subject: [PATCH 117/133] NET: add of_get_mac_address_mtd()
  5. Many embedded devices have information such as mac addresses stored inside mtd
  6. devices. This patch allows us to add a property inside a node describing a
  7. network interface. The new property points at a mtd partition with an offset
  8. where the mac address can be found.
  9. Signed-off-by: John Crispin <[email protected]>
  10. ---
  11. drivers/of/of_net.c | 37 +++++++++++++++++++++++++++++++++++++
  12. include/linux/of_net.h | 1 +
  13. 2 files changed, 38 insertions(+)
  14. --- a/drivers/of/of_net.c
  15. +++ b/drivers/of/of_net.c
  16. @@ -10,6 +10,7 @@
  17. #include <linux/of_net.h>
  18. #include <linux/phy.h>
  19. #include <linux/export.h>
  20. +#include <linux/mtd/mtd.h>
  21. /**
  22. * It maps 'enum phy_interface_t' found in include/linux/phy.h
  23. @@ -92,3 +93,39 @@ const void *of_get_mac_address(struct de
  24. return NULL;
  25. }
  26. EXPORT_SYMBOL(of_get_mac_address);
  27. +
  28. +int of_get_mac_address_mtd(struct device_node *np, void *mac)
  29. +{
  30. + struct device_node *mtd_np = NULL;
  31. + size_t retlen;
  32. + int size, ret;
  33. + struct mtd_info *mtd;
  34. + const char *part;
  35. + const __be32 *list;
  36. + phandle phandle;
  37. +
  38. + list = of_get_property(np, "mtd-mac-address", &size);
  39. + if (!list || (size != (2 * sizeof(*list))))
  40. + return -ENOENT;
  41. +
  42. + phandle = be32_to_cpup(list++);
  43. + if (phandle)
  44. + mtd_np = of_find_node_by_phandle(phandle);
  45. +
  46. + if (!mtd_np)
  47. + return -ENOENT;
  48. +
  49. + part = of_get_property(mtd_np, "label", NULL);
  50. + if (!part)
  51. + part = mtd_np->name;
  52. +
  53. + mtd = get_mtd_device_nm(part);
  54. + if (IS_ERR(mtd))
  55. + return PTR_ERR(mtd);
  56. +
  57. + ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, (u_char *) mac);
  58. + put_mtd_device(mtd);
  59. +
  60. + return ret;
  61. +}
  62. +EXPORT_SYMBOL_GPL(of_get_mac_address_mtd);
  63. --- a/include/linux/of_net.h
  64. +++ b/include/linux/of_net.h
  65. @@ -11,6 +11,7 @@
  66. #include <linux/of.h>
  67. extern const int of_get_phy_mode(struct device_node *np);
  68. extern const void *of_get_mac_address(struct device_node *np);
  69. +extern int of_get_mac_address_mtd(struct device_node *np, void *mac);
  70. #else
  71. static inline const int of_get_phy_mode(struct device_node *np)
  72. {