spectrum_cs.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * Driver for 802.11b cards using RAM-loadable Symbol firmware, such as
  3. * Symbol Wireless Networker LA4137, CompactFlash cards by Socket
  4. * Communications and Intel PRO/Wireless 2011B.
  5. *
  6. * The driver implements Symbol firmware download. The rest is handled
  7. * in hermes.c and main.c.
  8. *
  9. * Utilities for downloading the Symbol firmware are available at
  10. * http://sourceforge.net/projects/orinoco/
  11. *
  12. * Copyright (C) 2002-2005 Pavel Roskin <proski@gnu.org>
  13. * Portions based on orinoco_cs.c:
  14. * Copyright (C) David Gibson, Linuxcare Australia
  15. * Portions based on Spectrum24tDnld.c from original spectrum24 driver:
  16. * Copyright (C) Symbol Technologies.
  17. *
  18. * See copyright notice in file main.c.
  19. */
  20. #define DRIVER_NAME "spectrum_cs"
  21. #define PFX DRIVER_NAME ": "
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/delay.h>
  25. #include <pcmcia/cistpl.h>
  26. #include <pcmcia/cisreg.h>
  27. #include <pcmcia/ds.h>
  28. #include "orinoco.h"
  29. /********************************************************************/
  30. /* Module stuff */
  31. /********************************************************************/
  32. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");
  33. MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader");
  34. MODULE_LICENSE("Dual MPL/GPL");
  35. /* Module parameters */
  36. /* Some D-Link cards have buggy CIS. They do work at 5v properly, but
  37. * don't have any CIS entry for it. This workaround it... */
  38. static int ignore_cis_vcc; /* = 0 */
  39. module_param(ignore_cis_vcc, int, 0);
  40. MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket");
  41. /********************************************************************/
  42. /* Data structures */
  43. /********************************************************************/
  44. /* PCMCIA specific device information (goes in the card field of
  45. * struct orinoco_private */
  46. struct orinoco_pccard {
  47. struct pcmcia_device *p_dev;
  48. };
  49. /********************************************************************/
  50. /* Function prototypes */
  51. /********************************************************************/
  52. static int spectrum_cs_config(struct pcmcia_device *link);
  53. static void spectrum_cs_release(struct pcmcia_device *link);
  54. /* Constants for the CISREG_CCSR register */
  55. #define HCR_RUN 0x07 /* run firmware after reset */
  56. #define HCR_IDLE 0x0E /* don't run firmware after reset */
  57. #define HCR_MEM16 0x10 /* memory width bit, should be preserved */
  58. /*
  59. * Reset the card using configuration registers COR and CCSR.
  60. * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
  61. */
  62. static int
  63. spectrum_reset(struct pcmcia_device *link, int idle)
  64. {
  65. int ret;
  66. u8 save_cor;
  67. u8 ccsr;
  68. /* Doing it if hardware is gone is guaranteed crash */
  69. if (!pcmcia_dev_present(link))
  70. return -ENODEV;
  71. /* Save original COR value */
  72. ret = pcmcia_read_config_byte(link, CISREG_COR, &save_cor);
  73. if (ret)
  74. goto failed;
  75. /* Soft-Reset card */
  76. ret = pcmcia_write_config_byte(link, CISREG_COR,
  77. (save_cor | COR_SOFT_RESET));
  78. if (ret)
  79. goto failed;
  80. udelay(1000);
  81. /* Read CCSR */
  82. ret = pcmcia_read_config_byte(link, CISREG_CCSR, &ccsr);
  83. if (ret)
  84. goto failed;
  85. /*
  86. * Start or stop the firmware. Memory width bit should be
  87. * preserved from the value we've just read.
  88. */
  89. ccsr = (idle ? HCR_IDLE : HCR_RUN) | (ccsr & HCR_MEM16);
  90. ret = pcmcia_write_config_byte(link, CISREG_CCSR, ccsr);
  91. if (ret)
  92. goto failed;
  93. udelay(1000);
  94. /* Restore original COR configuration index */
  95. ret = pcmcia_write_config_byte(link, CISREG_COR,
  96. (save_cor & ~COR_SOFT_RESET));
  97. if (ret)
  98. goto failed;
  99. udelay(1000);
  100. return 0;
  101. failed:
  102. return -ENODEV;
  103. }
  104. /********************************************************************/
  105. /* Device methods */
  106. /********************************************************************/
  107. static int
  108. spectrum_cs_hard_reset(struct orinoco_private *priv)
  109. {
  110. struct orinoco_pccard *card = priv->card;
  111. struct pcmcia_device *link = card->p_dev;
  112. /* Soft reset using COR and HCR */
  113. spectrum_reset(link, 0);
  114. return 0;
  115. }
  116. static int
  117. spectrum_cs_stop_firmware(struct orinoco_private *priv, int idle)
  118. {
  119. struct orinoco_pccard *card = priv->card;
  120. struct pcmcia_device *link = card->p_dev;
  121. return spectrum_reset(link, idle);
  122. }
  123. /********************************************************************/
  124. /* PCMCIA stuff */
  125. /********************************************************************/
  126. static int
  127. spectrum_cs_probe(struct pcmcia_device *link)
  128. {
  129. struct orinoco_private *priv;
  130. struct orinoco_pccard *card;
  131. priv = alloc_orinocodev(sizeof(*card), &link->dev,
  132. spectrum_cs_hard_reset,
  133. spectrum_cs_stop_firmware);
  134. if (!priv)
  135. return -ENOMEM;
  136. card = priv->card;
  137. /* Link both structures together */
  138. card->p_dev = link;
  139. link->priv = priv;
  140. return spectrum_cs_config(link);
  141. } /* spectrum_cs_attach */
  142. static void spectrum_cs_detach(struct pcmcia_device *link)
  143. {
  144. struct orinoco_private *priv = link->priv;
  145. orinoco_if_del(priv);
  146. spectrum_cs_release(link);
  147. free_orinocodev(priv);
  148. } /* spectrum_cs_detach */
  149. static int spectrum_cs_config_check(struct pcmcia_device *p_dev,
  150. void *priv_data)
  151. {
  152. if (p_dev->config_index == 0)
  153. return -EINVAL;
  154. return pcmcia_request_io(p_dev);
  155. };
  156. static int
  157. spectrum_cs_config(struct pcmcia_device *link)
  158. {
  159. struct orinoco_private *priv = link->priv;
  160. struct hermes *hw = &priv->hw;
  161. int ret;
  162. void __iomem *mem;
  163. link->config_flags |= CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC |
  164. CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
  165. if (ignore_cis_vcc)
  166. link->config_flags &= ~CONF_AUTO_CHECK_VCC;
  167. ret = pcmcia_loop_config(link, spectrum_cs_config_check, NULL);
  168. if (ret) {
  169. if (!ignore_cis_vcc)
  170. printk(KERN_ERR PFX "GetNextTuple(): No matching "
  171. "CIS configuration. Maybe you need the "
  172. "ignore_cis_vcc=1 parameter.\n");
  173. goto failed;
  174. }
  175. mem = ioport_map(link->resource[0]->start,
  176. resource_size(link->resource[0]));
  177. if (!mem)
  178. goto failed;
  179. /* We initialize the hermes structure before completing PCMCIA
  180. * configuration just in case the interrupt handler gets
  181. * called. */
  182. hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
  183. hw->eeprom_pda = true;
  184. ret = pcmcia_request_irq(link, orinoco_interrupt);
  185. if (ret)
  186. goto failed;
  187. ret = pcmcia_enable_device(link);
  188. if (ret)
  189. goto failed;
  190. /* Reset card */
  191. if (spectrum_cs_hard_reset(priv) != 0)
  192. goto failed;
  193. /* Initialise the main driver */
  194. if (orinoco_init(priv) != 0) {
  195. printk(KERN_ERR PFX "orinoco_init() failed\n");
  196. goto failed;
  197. }
  198. /* Register an interface with the stack */
  199. if (orinoco_if_add(priv, link->resource[0]->start,
  200. link->irq, NULL) != 0) {
  201. printk(KERN_ERR PFX "orinoco_if_add() failed\n");
  202. goto failed;
  203. }
  204. return 0;
  205. failed:
  206. spectrum_cs_release(link);
  207. return -ENODEV;
  208. } /* spectrum_cs_config */
  209. static void
  210. spectrum_cs_release(struct pcmcia_device *link)
  211. {
  212. struct orinoco_private *priv = link->priv;
  213. unsigned long flags;
  214. /* We're committed to taking the device away now, so mark the
  215. * hardware as unavailable */
  216. priv->hw.ops->lock_irqsave(&priv->lock, &flags);
  217. priv->hw_unavailable++;
  218. priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
  219. pcmcia_disable_device(link);
  220. if (priv->hw.iobase)
  221. ioport_unmap(priv->hw.iobase);
  222. } /* spectrum_cs_release */
  223. static int
  224. spectrum_cs_suspend(struct pcmcia_device *link)
  225. {
  226. struct orinoco_private *priv = link->priv;
  227. int err = 0;
  228. /* Mark the device as stopped, to block IO until later */
  229. orinoco_down(priv);
  230. return err;
  231. }
  232. static int
  233. spectrum_cs_resume(struct pcmcia_device *link)
  234. {
  235. struct orinoco_private *priv = link->priv;
  236. int err = orinoco_up(priv);
  237. return err;
  238. }
  239. /********************************************************************/
  240. /* Module initialization */
  241. /********************************************************************/
  242. static const struct pcmcia_device_id spectrum_cs_ids[] = {
  243. PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4137 */
  244. PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
  245. PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless LAN PC Card", 0x816cc815, 0x6fbf459a), /* 2011B, not 2011 */
  246. PCMCIA_DEVICE_NULL,
  247. };
  248. MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids);
  249. static struct pcmcia_driver orinoco_driver = {
  250. .owner = THIS_MODULE,
  251. .name = DRIVER_NAME,
  252. .probe = spectrum_cs_probe,
  253. .remove = spectrum_cs_detach,
  254. .suspend = spectrum_cs_suspend,
  255. .resume = spectrum_cs_resume,
  256. .id_table = spectrum_cs_ids,
  257. };
  258. module_pcmcia_driver(orinoco_driver);