603-rt2x00-introduce-rt2x00eeprom.patch 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. --- a/.local-symbols
  2. +++ b/.local-symbols
  3. @@ -331,6 +331,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. @@ -46,6 +46,8 @@ struct rt2800_drv_data {
  50. } shmem_lock;
  51. };
  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. @@ -179,6 +181,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. @@ -699,6 +699,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. @@ -968,6 +969,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. @@ -1334,6 +1334,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. @@ -1477,6 +1481,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,111 @@
  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) {
  197. + rt2x00_err(rt2x00dev,
  198. + "Invalid EEPROM filename.\n"
  199. + "Please file bug report to %s.\n", DRV_PROJECT);
  200. + return -EINVAL;
  201. + }
  202. +
  203. + rt2x00_info(rt2x00dev, "Loading EEPROM data from '%s'.\n", ee_name);
  204. +
  205. + retval = request_firmware(&ee, ee_name, rt2x00dev->dev);
  206. + if (retval) {
  207. + rt2x00_err(rt2x00dev, "Failed to request EEPROM.\n");
  208. + return retval;
  209. + }
  210. +
  211. + if (!ee || !ee->size || !ee->data) {
  212. + rt2x00_err(rt2x00dev, "Failed to read EEPROM file.\n");
  213. + retval = -ENOENT;
  214. + goto err_exit;
  215. + }
  216. +
  217. + if (ee->size != rt2x00dev->ops->eeprom_size) {
  218. + rt2x00_err(rt2x00dev,
  219. + "EEPROM file size is invalid, it should be %d bytes\n",
  220. + rt2x00dev->ops->eeprom_size);
  221. + retval = -EINVAL;
  222. + goto err_release_ee;
  223. + }
  224. +
  225. + rt2x00dev->eeprom_file = ee;
  226. + return 0;
  227. +
  228. +err_release_ee:
  229. + release_firmware(ee);
  230. +err_exit:
  231. + return retval;
  232. +}
  233. +
  234. +int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
  235. +{
  236. + int retval;
  237. +
  238. + if (!rt2x00lib_get_eeprom_file_name(rt2x00dev))
  239. + return 0;
  240. +
  241. + set_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags);
  242. +
  243. + if (!rt2x00dev->eeprom_file) {
  244. + retval = rt2x00lib_request_eeprom_file(rt2x00dev);
  245. + if (retval)
  246. + return retval;
  247. + }
  248. +
  249. + return 0;
  250. +}
  251. +
  252. +void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
  253. +{
  254. + release_firmware(rt2x00dev->eeprom_file);
  255. + rt2x00dev->eeprom_file = NULL;
  256. +}
  257. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00lib.h
  258. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00lib.h
  259. @@ -320,6 +320,22 @@ static inline void rt2x00lib_free_firmwa
  260. #endif /* CPTCFG_RT2X00_LIB_FIRMWARE */
  261. /*
  262. + * EEPROM file handlers.
  263. + */
  264. +#ifdef CPTCFG_RT2X00_LIB_EEPROM
  265. +int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev);
  266. +void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev);
  267. +#else
  268. +static inline int rt2x00lib_load_eeprom_file(struct rt2x00_dev *rt2x00dev)
  269. +{
  270. + return 0;
  271. +}
  272. +static inline void rt2x00lib_free_eeprom_file(struct rt2x00_dev *rt2x00dev)
  273. +{
  274. +}
  275. +#endif /* CPTCFG_RT2X00_LIB_EEPROM */
  276. +
  277. +/*
  278. * Debugfs handlers.
  279. */
  280. #ifdef CPTCFG_RT2X00_LIB_DEBUGFS
  281. --- a/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
  282. +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
  283. @@ -92,6 +92,7 @@ int rt2x00soc_probe(struct platform_devi
  284. rt2x00dev->hw = hw;
  285. rt2x00dev->irq = platform_get_irq(pdev, 0);
  286. rt2x00dev->name = pdev->dev.driver->name;
  287. + set_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags);
  288. rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);