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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. @@ -219,6 +219,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,73 @@
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. +#include <linux/mtd/mtd.h>
  27. +#include <linux/mtd/partitions.h>
  28. #include <linux/of.h>
  29. #include "rt2x00.h"
  30. #include "rt2x00lib.h"
  31. +static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
  32. +{
  33. + int ret = -EINVAL;
  34. +#ifdef CONFIG_OF
  35. + static struct firmware mtd_fw;
  36. + struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
  37. + size_t retlen, len = rt2x00dev->ops->eeprom_size;
  38. + int i, size, offset = 0;
  39. + struct mtd_info *mtd;
  40. + const char *part;
  41. + const __be32 *list;
  42. + phandle phandle;
  43. +
  44. + list = of_get_property(np, "ralink,mtd-eeprom", &size);
  45. + if (!list)
  46. + return -ENOENT;
  47. +
  48. + phandle = be32_to_cpup(list++);
  49. + if (phandle)
  50. + mtd_np = of_find_node_by_phandle(phandle);
  51. + if (!mtd_np) {
  52. + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
  53. + return -EINVAL;
  54. + }
  55. +
  56. + part = of_get_property(mtd_np, "label", NULL);
  57. + if (!part)
  58. + part = mtd_np->name;
  59. +
  60. + mtd = get_mtd_device_nm(part);
  61. + if (IS_ERR(mtd)) {
  62. + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
  63. + return PTR_ERR(mtd);
  64. + }
  65. +
  66. + if (size > sizeof(*list))
  67. + offset = be32_to_cpup(list);
  68. +
  69. + ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom);
  70. + put_mtd_device(mtd);
  71. +
  72. + if ((retlen != rt2x00dev->ops->eeprom_size) || ret) {
  73. + dev_err(rt2x00dev->dev, "failed to load eeprom from device \"%s\"\n", part);
  74. + return ret;
  75. + }
  76. +
  77. + if (of_find_property(np, "ralink,mtd-eeprom-swap", NULL))
  78. + for (i = 0; i < len/sizeof(u16); i++)
  79. + rt2x00dev->eeprom[i] = swab16(rt2x00dev->eeprom[i]);
  80. +
  81. + rt2x00dev->eeprom_file = &mtd_fw;
  82. + mtd_fw.size = len;
  83. + mtd_fw.data = (const u8 *) rt2x00dev->eeprom;
  84. +
  85. + dev_info(rt2x00dev->dev, "loaded eeprom from mtd device \"%s\"\n", part);
  86. +#endif
  87. +
  88. + return ret;
  89. +}
  90. +
  91. static const char *
  92. rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
  93. {
  94. @@ -58,6 +120,9 @@ static int rt2x00lib_request_eeprom_file
  95. const char *ee_name;
  96. int retval;
  97. + if (!rt2800lib_read_eeprom_mtd(rt2x00dev))
  98. + return 0;
  99. +
  100. ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
  101. if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
  102. rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");