1
0

604-rt2x00-load-eeprom-on-SoC-from-a-mtd-device-defines-.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. From 339fe73f340161a624cc08e738d2244814852c3e Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Sun, 17 Mar 2013 00:55:04 +0100
  4. Subject: [PATCH] rt2x00: load eeprom on SoC from a mtd device defines inside
  5. OF
  6. Signed-off-by: John Crispin <blogic@openwrt.org>
  7. ---
  8. drivers/net/wireless/ralink/rt2x00/Kconfig | 1 +
  9. drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c | 65 +++++++++++++++++++++++
  10. 2 files changed, 66 insertions(+)
  11. --- a/drivers/net/wireless/ralink/rt2x00/Kconfig
  12. +++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
  13. @@ -220,6 +220,7 @@ config RT2800SOC
  14. select RT2X00_LIB_EEPROM
  15. select RT2800_LIB
  16. select RT2800_LIB_MMIO
  17. + select MTD if SOC_RT288X || SOC_RT305X
  18. help
  19. This adds support for Ralink WiSoC devices.
  20. Supported chips: RT2880, RT3050, RT3052, RT3350, RT3352.
  21. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
  22. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
  23. @@ -26,11 +26,76 @@
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. +#if IS_ENABLED(CONFIG_MTD)
  27. +#include <linux/mtd/mtd.h>
  28. +#include <linux/mtd/partitions.h>
  29. +#endif
  30. #include <linux/of.h>
  31. #include "rt2x00.h"
  32. #include "rt2x00lib.h"
  33. +#if IS_ENABLED(CONFIG_MTD)
  34. +static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
  35. +{
  36. + int ret = -EINVAL;
  37. +#ifdef CONFIG_OF
  38. + static struct firmware mtd_fw;
  39. + struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
  40. + size_t retlen, len = rt2x00dev->ops->eeprom_size;
  41. + int i, size, offset = 0;
  42. + struct mtd_info *mtd;
  43. + const char *part;
  44. + const __be32 *list;
  45. + phandle phandle;
  46. +
  47. + list = of_get_property(np, "ralink,mtd-eeprom", &size);
  48. + if (!list)
  49. + return -ENOENT;
  50. +
  51. + phandle = be32_to_cpup(list++);
  52. + if (phandle)
  53. + mtd_np = of_find_node_by_phandle(phandle);
  54. + if (!mtd_np) {
  55. + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
  56. + return -EINVAL;
  57. + }
  58. +
  59. + part = of_get_property(mtd_np, "label", NULL);
  60. + if (!part)
  61. + part = mtd_np->name;
  62. +
  63. + mtd = get_mtd_device_nm(part);
  64. + if (IS_ERR(mtd)) {
  65. + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
  66. + return PTR_ERR(mtd);
  67. + }
  68. +
  69. + if (size > sizeof(*list))
  70. + offset = be32_to_cpup(list);
  71. +
  72. + ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom);
  73. + put_mtd_device(mtd);
  74. +
  75. + if ((retlen != rt2x00dev->ops->eeprom_size) || ret) {
  76. + dev_err(rt2x00dev->dev, "failed to load eeprom from device \"%s\"\n", part);
  77. + return ret;
  78. + }
  79. +
  80. + if (of_find_property(np, "ralink,mtd-eeprom-swap", NULL))
  81. + for (i = 0; i < len/sizeof(u16); i++)
  82. + rt2x00dev->eeprom[i] = swab16(rt2x00dev->eeprom[i]);
  83. +
  84. + rt2x00dev->eeprom_file = &mtd_fw;
  85. + mtd_fw.data = (const u8 *) rt2x00dev->eeprom;
  86. +
  87. + dev_info(rt2x00dev->dev, "loaded eeprom from mtd device \"%s\"\n", part);
  88. +#endif
  89. +
  90. + return ret;
  91. +}
  92. +#endif
  93. +
  94. static const char *
  95. rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
  96. {
  97. @@ -58,6 +123,11 @@ static int rt2x00lib_request_eeprom_file
  98. const char *ee_name;
  99. int retval;
  100. +#if IS_ENABLED(CONFIG_MTD)
  101. + if (!rt2800lib_read_eeprom_mtd(rt2x00dev))
  102. + return 0;
  103. +#endif
  104. +
  105. ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
  106. if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
  107. rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");