602-rt2x00-introduce-rt2x00eeprom.patch 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. --- a/local-symbols
  2. +++ b/local-symbols
  3. @@ -347,6 +347,7 @@ RT2X00_LIB_FIRMWARE=
  4. RT2X00_LIB_CRYPTO=
  5. RT2X00_LIB_LEDS=
  6. RT2X00_LIB_DEBUGFS=
  7. +RT2X00_LIB_EEPROM=
  8. RT2X00_DEBUG=
  9. WLAN_VENDOR_REALTEK=
  10. RTL8180=
  11. --- a/drivers/net/wireless/ralink/rt2x00/Kconfig
  12. +++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
  13. @@ -70,6 +70,7 @@ config RT2800PCI
  14. select RT2X00_LIB_MMIO
  15. select RT2X00_LIB_PCI
  16. select RT2X00_LIB_FIRMWARE
  17. + select RT2X00_LIB_EEPROM
  18. select RT2X00_LIB_CRYPTO
  19. depends on CRC_CCITT
  20. depends on EEPROM_93CX6
  21. @@ -216,6 +217,7 @@ config RT2800SOC
  22. select RT2X00_LIB_MMIO
  23. select RT2X00_LIB_CRYPTO
  24. select RT2X00_LIB_FIRMWARE
  25. + select RT2X00_LIB_EEPROM
  26. select RT2800_LIB
  27. select RT2800_LIB_MMIO
  28. help
  29. @@ -266,6 +268,9 @@ config RT2X00_LIB_FIRMWARE
  30. config RT2X00_LIB_CRYPTO
  31. bool
  32. +config RT2X00_LIB_EEPROM
  33. + bool
  34. +
  35. config RT2X00_LIB_LEDS
  36. bool
  37. default y if (RT2X00_LIB=y && LEDS_CLASS=y) || (RT2X00_LIB=m && LEDS_CLASS!=n)
  38. --- a/drivers/net/wireless/ralink/rt2x00/Makefile
  39. +++ b/drivers/net/wireless/ralink/rt2x00/Makefile
  40. @@ -8,6 +8,7 @@ rt2x00lib-$(CPTCFG_RT2X00_LIB_DEBUGFS) +
  41. rt2x00lib-$(CPTCFG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o
  42. rt2x00lib-$(CPTCFG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o
  43. rt2x00lib-$(CPTCFG_RT2X00_LIB_LEDS) += rt2x00leds.o
  44. +rt2x00lib-$(CPTCFG_RT2X00_LIB_EEPROM) += rt2x00eeprom.o
  45. obj-$(CPTCFG_RT2X00_LIB) += rt2x00lib.o
  46. obj-$(CPTCFG_RT2X00_LIB_MMIO) += rt2x00mmio.o
  47. --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
  48. +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
  49. @@ -47,6 +47,8 @@ struct rt2800_drv_data {
  50. struct ieee80211_sta *wcid_to_sta[STA_IDS_SIZE];
  51. };
  52. +#include "rt2800.h"
  53. +
  54. struct rt2800_ops {
  55. u32 (*register_read)(struct rt2x00_dev *rt2x00dev,
  56. const unsigned int offset);
  57. @@ -145,6 +147,15 @@ static inline int rt2800_read_eeprom(str
  58. {
  59. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  60. + if (rt2x00dev->eeprom_file) {
  61. + memcpy(rt2x00dev->eeprom, rt2x00dev->eeprom_file->data,
  62. + EEPROM_SIZE);
  63. + return 0;
  64. + }
  65. +
  66. + if (!rt2800ops->read_eeprom)
  67. + return -EINVAL;
  68. +
  69. return rt2800ops->read_eeprom(rt2x00dev);
  70. }
  71. --- a/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
  72. +++ b/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
  73. @@ -90,19 +90,6 @@ static int rt2800soc_set_device_state(st
  74. return retval;
  75. }
  76. -static int rt2800soc_read_eeprom(struct rt2x00_dev *rt2x00dev)
  77. -{
  78. - void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
  79. -
  80. - if (!base_addr)
  81. - return -ENOMEM;
  82. -
  83. - memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
  84. -
  85. - iounmap(base_addr);
  86. - return 0;
  87. -}
  88. -
  89. /* Firmware functions */
  90. static char *rt2800soc_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  91. {
  92. @@ -168,7 +155,6 @@ static const struct rt2800_ops rt2800soc
  93. .register_multiread = rt2x00mmio_register_multiread,
  94. .register_multiwrite = rt2x00mmio_register_multiwrite,
  95. .regbusy_read = rt2x00mmio_regbusy_read,
  96. - .read_eeprom = rt2800soc_read_eeprom,
  97. .hwcrypt_disabled = rt2800soc_hwcrypt_disabled,
  98. .drv_write_firmware = rt2800soc_write_firmware,
  99. .drv_init_registers = rt2800mmio_init_registers,
  100. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
  101. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
  102. @@ -703,6 +703,7 @@ enum rt2x00_capability_flags {
  103. REQUIRE_HT_TX_DESC,
  104. REQUIRE_PS_AUTOWAKE,
  105. REQUIRE_DELAYED_RFKILL,
  106. + REQUIRE_EEPROM_FILE,
  107. /*
  108. * Capabilities
  109. @@ -980,6 +981,11 @@ struct rt2x00_dev {
  110. const struct firmware *fw;
  111. /*
  112. + * EEPROM image.
  113. + */
  114. + const struct firmware *eeprom_file;
  115. +
  116. + /*
  117. * FIFO for storing tx status reports between isr and tasklet.
  118. */
  119. DECLARE_KFIFO_PTR(txstatus_fifo, u32);
  120. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
  121. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
  122. @@ -1419,6 +1419,10 @@ int rt2x00lib_probe_dev(struct rt2x00_de
  123. INIT_DELAYED_WORK(&rt2x00dev->autowakeup_work, rt2x00lib_autowakeup);
  124. INIT_WORK(&rt2x00dev->sleep_work, rt2x00lib_sleep);
  125. + retval = rt2x00lib_load_eeprom_file(rt2x00dev);
  126. + if (retval)
  127. + goto exit;
  128. +
  129. /*
  130. * Let the driver probe the device to detect the capabilities.
  131. */
  132. @@ -1559,6 +1563,11 @@ void rt2x00lib_remove_dev(struct rt2x00_
  133. * Free the driver data.
  134. */
  135. kfree(rt2x00dev->drv_data);
  136. +
  137. + /*
  138. + * Free EEPROM image.
  139. + */
  140. + rt2x00lib_free_eeprom_file(rt2x00dev);
  141. }
  142. EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
  143. --- /dev/null
  144. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
  145. @@ -0,0 +1,106 @@
  146. +/*
  147. + Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
  148. + Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
  149. + <http://rt2x00.serialmonkey.com>
  150. +
  151. + This program is free software; you can redistribute it and/or modify
  152. + it under the terms of the GNU General Public License as published by
  153. + the Free Software Foundation; either version 2 of the License, or
  154. + (at your option) any later version.
  155. +
  156. + This program is distributed in the hope that it will be useful,
  157. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  158. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  159. + GNU General Public License for more details.
  160. +
  161. + You should have received a copy of the GNU General Public License
  162. + along with this program; if not, write to the
  163. + Free Software Foundation, Inc.,
  164. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  165. + */
  166. +
  167. +/*
  168. + Module: rt2x00lib
  169. + Abstract: rt2x00 eeprom file loading routines.
  170. + */
  171. +
  172. +#include <linux/kernel.h>
  173. +#include <linux/module.h>
  174. +
  175. +#include "rt2x00.h"
  176. +#include "rt2x00lib.h"
  177. +
  178. +static const char *
  179. +rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
  180. +{
  181. + struct rt2x00_platform_data *pdata = rt2x00dev->dev->platform_data;
  182. +
  183. + if (pdata && pdata->eeprom_file_name)
  184. + return pdata->eeprom_file_name;
  185. +
  186. + return NULL;
  187. +}
  188. +
  189. +static int rt2x00lib_request_eeprom_file(struct rt2x00_dev *rt2x00dev)
  190. +{
  191. + const struct firmware *ee;
  192. + const char *ee_name;
  193. + int retval;
  194. +
  195. + ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
  196. + if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
  197. + rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");
  198. + return -EINVAL;
  199. + }
  200. +
  201. + if (!ee_name)
  202. + return 0;
  203. +
  204. + rt2x00_info(rt2x00dev, "Loading EEPROM data from '%s'.\n", ee_name);
  205. +
  206. + retval = request_firmware(&ee, ee_name, rt2x00dev->dev);
  207. + if (retval) {
  208. + rt2x00_err(rt2x00dev, "Failed to request EEPROM.\n");
  209. + return retval;
  210. + }
  211. +
  212. + if (!ee || !ee->size || !ee->data) {
  213. + rt2x00_err(rt2x00dev, "Failed to read EEPROM file.\n");
  214. + retval = -ENOENT;
  215. + goto err_exit;
  216. + }
  217. +
  218. + if (ee->size != rt2x00dev->ops->eeprom_size) {
  219. + rt2x00_err(rt2x00dev,
  220. + "EEPROM file size is invalid, it should be %d bytes\n",
  221. + rt2x00dev->ops->eeprom_size);
  222. + retval = -EINVAL;
  223. + goto err_release_ee;
  224. + }
  225. +
  226. + rt2x00dev->eeprom_file = ee;
  227. + return 0;
  228. +
  229. +err_release_ee:
  230. + release_firmware(ee);
  231. +err_exit:
  232. + return retval;
  233. +}
  234. +
  235. +int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
  236. +{
  237. + int retval;
  238. +
  239. + retval = rt2x00lib_request_eeprom_file(rt2x00dev);
  240. + if (retval)
  241. + return retval;
  242. +
  243. + return 0;
  244. +}
  245. +
  246. +void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
  247. +{
  248. + if (rt2x00dev->eeprom_file && rt2x00dev->eeprom_file->size)
  249. + release_firmware(rt2x00dev->eeprom_file);
  250. + rt2x00dev->eeprom_file = NULL;
  251. +}
  252. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00lib.h
  253. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00lib.h
  254. @@ -286,6 +286,22 @@ static inline void rt2x00lib_free_firmwa
  255. #endif /* CPTCFG_RT2X00_LIB_FIRMWARE */
  256. /*
  257. + * EEPROM file handlers.
  258. + */
  259. +#ifdef CPTCFG_RT2X00_LIB_EEPROM
  260. +int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev);
  261. +void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev);
  262. +#else
  263. +static inline int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
  264. +{
  265. + return 0;
  266. +}
  267. +static inline void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
  268. +{
  269. +}
  270. +#endif /* CPTCFG_RT2X00_LIB_EEPROM */
  271. +
  272. +/*
  273. * Debugfs handlers.
  274. */
  275. #ifdef CPTCFG_RT2X00_LIB_DEBUGFS
  276. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
  277. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
  278. @@ -86,6 +86,7 @@ int rt2x00soc_probe(struct platform_devi
  279. if (IS_ERR(rt2x00dev->clk))
  280. rt2x00dev->clk = NULL;
  281. + set_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags);
  282. rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  283. retval = rt2x00soc_alloc_reg(rt2x00dev);