602-rt2x00-introduce-rt2x00eeprom.patch 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. --- a/.local-symbols
  2. +++ b/.local-symbols
  3. @@ -336,6 +336,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. @@ -69,6 +69,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. @@ -215,6 +216,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. @@ -265,6 +267,9 @@ config RT2X00_LIB_FIRMWARE
  30. config RT2X00_LIB_CRYPTO
  31. bool
  32. +config RT2X00_LIB_EEPROM
  33. + boolean
  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. @@ -7,6 +7,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. @@ -20,6 +20,8 @@
  50. #ifndef RT2800LIB_H
  51. #define RT2800LIB_H
  52. +#include "rt2800.h"
  53. +
  54. struct rt2800_ops {
  55. void (*register_read)(struct rt2x00_dev *rt2x00dev,
  56. const unsigned int offset, u32 *value);
  57. @@ -119,6 +121,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. @@ -102,19 +102,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. @@ -178,7 +165,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. @@ -701,6 +701,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. @@ -976,6 +977,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. @@ -1346,6 +1346,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. @@ -1484,6 +1488,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,105 @@
  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. + release_firmware(rt2x00dev->eeprom_file);
  249. + rt2x00dev->eeprom_file = NULL;
  250. +}
  251. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00lib.h
  252. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00lib.h
  253. @@ -297,6 +297,22 @@ static inline void rt2x00lib_free_firmwa
  254. #endif /* CPTCFG_RT2X00_LIB_FIRMWARE */
  255. /*
  256. + * EEPROM file handlers.
  257. + */
  258. +#ifdef CPTCFG_RT2X00_LIB_EEPROM
  259. +int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev);
  260. +void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev);
  261. +#else
  262. +static inline int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
  263. +{
  264. + return 0;
  265. +}
  266. +static inline void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
  267. +{
  268. +}
  269. +#endif /* CPTCFG_RT2X00_LIB_EEPROM */
  270. +
  271. +/*
  272. * Debugfs handlers.
  273. */
  274. #ifdef CPTCFG_RT2X00_LIB_DEBUGFS
  275. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
  276. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
  277. @@ -97,6 +97,7 @@ int rt2x00soc_probe(struct platform_devi
  278. if (IS_ERR(rt2x00dev->clk))
  279. rt2x00dev->clk = NULL;
  280. + set_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags);
  281. rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  282. retval = rt2x00soc_alloc_reg(rt2x00dev);