spectrum_cs.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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 orinoco.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 orinoco.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/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/firmware.h>
  27. #include <pcmcia/cs_types.h>
  28. #include <pcmcia/cs.h>
  29. #include <pcmcia/cistpl.h>
  30. #include <pcmcia/cisreg.h>
  31. #include <pcmcia/ds.h>
  32. #include "orinoco.h"
  33. static const char primary_fw_name[] = "symbol_sp24t_prim_fw";
  34. static const char secondary_fw_name[] = "symbol_sp24t_sec_fw";
  35. /********************************************************************/
  36. /* Module stuff */
  37. /********************************************************************/
  38. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");
  39. MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader");
  40. MODULE_LICENSE("Dual MPL/GPL");
  41. /* Module parameters */
  42. /* Some D-Link cards have buggy CIS. They do work at 5v properly, but
  43. * don't have any CIS entry for it. This workaround it... */
  44. static int ignore_cis_vcc; /* = 0 */
  45. module_param(ignore_cis_vcc, int, 0);
  46. MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket");
  47. /********************************************************************/
  48. /* Data structures */
  49. /********************************************************************/
  50. /* PCMCIA specific device information (goes in the card field of
  51. * struct orinoco_private */
  52. struct orinoco_pccard {
  53. struct pcmcia_device *p_dev;
  54. dev_node_t node;
  55. };
  56. /********************************************************************/
  57. /* Function prototypes */
  58. /********************************************************************/
  59. static int spectrum_cs_config(struct pcmcia_device *link);
  60. static void spectrum_cs_release(struct pcmcia_device *link);
  61. /********************************************************************/
  62. /* Firmware downloader */
  63. /********************************************************************/
  64. /* Position of PDA in the adapter memory */
  65. #define EEPROM_ADDR 0x3000
  66. #define EEPROM_LEN 0x200
  67. #define PDA_OFFSET 0x100
  68. #define PDA_ADDR (EEPROM_ADDR + PDA_OFFSET)
  69. #define PDA_WORDS ((EEPROM_LEN - PDA_OFFSET) / 2)
  70. /* Constants for the CISREG_CCSR register */
  71. #define HCR_RUN 0x07 /* run firmware after reset */
  72. #define HCR_IDLE 0x0E /* don't run firmware after reset */
  73. #define HCR_MEM16 0x10 /* memory width bit, should be preserved */
  74. /*
  75. * AUX port access. To unlock the AUX port write the access keys to the
  76. * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL
  77. * register. Then read it and make sure it's HERMES_AUX_ENABLED.
  78. */
  79. #define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */
  80. #define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */
  81. #define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */
  82. #define HERMES_AUX_PW0 0xFE01
  83. #define HERMES_AUX_PW1 0xDC23
  84. #define HERMES_AUX_PW2 0xBA45
  85. /* End markers */
  86. #define PDI_END 0x00000000 /* End of PDA */
  87. #define BLOCK_END 0xFFFFFFFF /* Last image block */
  88. #define TEXT_END 0x1A /* End of text header */
  89. /*
  90. * The following structures have little-endian fields denoted by
  91. * the leading underscore. Don't access them directly - use inline
  92. * functions defined below.
  93. */
  94. /*
  95. * The binary image to be downloaded consists of series of data blocks.
  96. * Each block has the following structure.
  97. */
  98. struct dblock {
  99. __le32 addr; /* adapter address where to write the block */
  100. __le16 len; /* length of the data only, in bytes */
  101. char data[0]; /* data to be written */
  102. } __attribute__ ((packed));
  103. /*
  104. * Plug Data References are located in in the image after the last data
  105. * block. They refer to areas in the adapter memory where the plug data
  106. * items with matching ID should be written.
  107. */
  108. struct pdr {
  109. __le32 id; /* record ID */
  110. __le32 addr; /* adapter address where to write the data */
  111. __le32 len; /* expected length of the data, in bytes */
  112. char next[0]; /* next PDR starts here */
  113. } __attribute__ ((packed));
  114. /*
  115. * Plug Data Items are located in the EEPROM read from the adapter by
  116. * primary firmware. They refer to the device-specific data that should
  117. * be plugged into the secondary firmware.
  118. */
  119. struct pdi {
  120. __le16 len; /* length of ID and data, in words */
  121. __le16 id; /* record ID */
  122. char data[0]; /* plug data */
  123. } __attribute__ ((packed));
  124. /* Functions for access to little-endian data */
  125. static inline u32
  126. dblock_addr(const struct dblock *blk)
  127. {
  128. return le32_to_cpu(blk->addr);
  129. }
  130. static inline u32
  131. dblock_len(const struct dblock *blk)
  132. {
  133. return le16_to_cpu(blk->len);
  134. }
  135. static inline u32
  136. pdr_id(const struct pdr *pdr)
  137. {
  138. return le32_to_cpu(pdr->id);
  139. }
  140. static inline u32
  141. pdr_addr(const struct pdr *pdr)
  142. {
  143. return le32_to_cpu(pdr->addr);
  144. }
  145. static inline u32
  146. pdr_len(const struct pdr *pdr)
  147. {
  148. return le32_to_cpu(pdr->len);
  149. }
  150. static inline u32
  151. pdi_id(const struct pdi *pdi)
  152. {
  153. return le16_to_cpu(pdi->id);
  154. }
  155. /* Return length of the data only, in bytes */
  156. static inline u32
  157. pdi_len(const struct pdi *pdi)
  158. {
  159. return 2 * (le16_to_cpu(pdi->len) - 1);
  160. }
  161. /* Set address of the auxiliary port */
  162. static inline void
  163. spectrum_aux_setaddr(hermes_t *hw, u32 addr)
  164. {
  165. hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));
  166. hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));
  167. }
  168. /* Open access to the auxiliary port */
  169. static int
  170. spectrum_aux_open(hermes_t *hw)
  171. {
  172. int i;
  173. /* Already open? */
  174. if (hermes_read_reg(hw, HERMES_CONTROL) == HERMES_AUX_ENABLED)
  175. return 0;
  176. hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);
  177. hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);
  178. hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);
  179. hermes_write_reg(hw, HERMES_CONTROL, HERMES_AUX_ENABLE);
  180. for (i = 0; i < 20; i++) {
  181. udelay(10);
  182. if (hermes_read_reg(hw, HERMES_CONTROL) ==
  183. HERMES_AUX_ENABLED)
  184. return 0;
  185. }
  186. return -EBUSY;
  187. }
  188. #define CS_CHECK(fn, ret) \
  189. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  190. /*
  191. * Reset the card using configuration registers COR and CCSR.
  192. * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
  193. */
  194. static int
  195. spectrum_reset(struct pcmcia_device *link, int idle)
  196. {
  197. int last_ret, last_fn;
  198. conf_reg_t reg;
  199. u_int save_cor;
  200. /* Doing it if hardware is gone is guaranteed crash */
  201. if (!pcmcia_dev_present(link))
  202. return -ENODEV;
  203. /* Save original COR value */
  204. reg.Function = 0;
  205. reg.Action = CS_READ;
  206. reg.Offset = CISREG_COR;
  207. CS_CHECK(AccessConfigurationRegister,
  208. pcmcia_access_configuration_register(link, &reg));
  209. save_cor = reg.Value;
  210. /* Soft-Reset card */
  211. reg.Action = CS_WRITE;
  212. reg.Offset = CISREG_COR;
  213. reg.Value = (save_cor | COR_SOFT_RESET);
  214. CS_CHECK(AccessConfigurationRegister,
  215. pcmcia_access_configuration_register(link, &reg));
  216. udelay(1000);
  217. /* Read CCSR */
  218. reg.Action = CS_READ;
  219. reg.Offset = CISREG_CCSR;
  220. CS_CHECK(AccessConfigurationRegister,
  221. pcmcia_access_configuration_register(link, &reg));
  222. /*
  223. * Start or stop the firmware. Memory width bit should be
  224. * preserved from the value we've just read.
  225. */
  226. reg.Action = CS_WRITE;
  227. reg.Offset = CISREG_CCSR;
  228. reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16);
  229. CS_CHECK(AccessConfigurationRegister,
  230. pcmcia_access_configuration_register(link, &reg));
  231. udelay(1000);
  232. /* Restore original COR configuration index */
  233. reg.Action = CS_WRITE;
  234. reg.Offset = CISREG_COR;
  235. reg.Value = (save_cor & ~COR_SOFT_RESET);
  236. CS_CHECK(AccessConfigurationRegister,
  237. pcmcia_access_configuration_register(link, &reg));
  238. udelay(1000);
  239. return 0;
  240. cs_failed:
  241. cs_error(link, last_fn, last_ret);
  242. return -ENODEV;
  243. }
  244. /*
  245. * Scan PDR for the record with the specified RECORD_ID.
  246. * If it's not found, return NULL.
  247. */
  248. static struct pdr *
  249. spectrum_find_pdr(struct pdr *first_pdr, u32 record_id)
  250. {
  251. struct pdr *pdr = first_pdr;
  252. while (pdr_id(pdr) != PDI_END) {
  253. /*
  254. * PDR area is currently not terminated by PDI_END.
  255. * It's followed by CRC records, which have the type
  256. * field where PDR has length. The type can be 0 or 1.
  257. */
  258. if (pdr_len(pdr) < 2)
  259. return NULL;
  260. /* If the record ID matches, we are done */
  261. if (pdr_id(pdr) == record_id)
  262. return pdr;
  263. pdr = (struct pdr *) pdr->next;
  264. }
  265. return NULL;
  266. }
  267. /* Process one Plug Data Item - find corresponding PDR and plug it */
  268. static int
  269. spectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi)
  270. {
  271. struct pdr *pdr;
  272. /* Find the PDI corresponding to this PDR */
  273. pdr = spectrum_find_pdr(first_pdr, pdi_id(pdi));
  274. /* No match is found, safe to ignore */
  275. if (!pdr)
  276. return 0;
  277. /* Lengths of the data in PDI and PDR must match */
  278. if (pdi_len(pdi) != pdr_len(pdr))
  279. return -EINVAL;
  280. /* do the actual plugging */
  281. spectrum_aux_setaddr(hw, pdr_addr(pdr));
  282. hermes_write_bytes(hw, HERMES_AUXDATA, pdi->data, pdi_len(pdi));
  283. return 0;
  284. }
  285. /* Read PDA from the adapter */
  286. static int
  287. spectrum_read_pda(hermes_t *hw, __le16 *pda, int pda_len)
  288. {
  289. int ret;
  290. int pda_size;
  291. /* Issue command to read EEPROM */
  292. ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
  293. if (ret)
  294. return ret;
  295. /* Open auxiliary port */
  296. ret = spectrum_aux_open(hw);
  297. if (ret)
  298. return ret;
  299. /* read PDA from EEPROM */
  300. spectrum_aux_setaddr(hw, PDA_ADDR);
  301. hermes_read_words(hw, HERMES_AUXDATA, pda, pda_len / 2);
  302. /* Check PDA length */
  303. pda_size = le16_to_cpu(pda[0]);
  304. if (pda_size > pda_len)
  305. return -EINVAL;
  306. return 0;
  307. }
  308. /* Parse PDA and write the records into the adapter */
  309. static int
  310. spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block,
  311. __le16 *pda)
  312. {
  313. int ret;
  314. struct pdi *pdi;
  315. struct pdr *first_pdr;
  316. const struct dblock *blk = first_block;
  317. /* Skip all blocks to locate Plug Data References */
  318. while (dblock_addr(blk) != BLOCK_END)
  319. blk = (struct dblock *) &blk->data[dblock_len(blk)];
  320. first_pdr = (struct pdr *) blk;
  321. /* Go through every PDI and plug them into the adapter */
  322. pdi = (struct pdi *) (pda + 2);
  323. while (pdi_id(pdi) != PDI_END) {
  324. ret = spectrum_plug_pdi(hw, first_pdr, pdi);
  325. if (ret)
  326. return ret;
  327. /* Increment to the next PDI */
  328. pdi = (struct pdi *) &pdi->data[pdi_len(pdi)];
  329. }
  330. return 0;
  331. }
  332. /* Load firmware blocks into the adapter */
  333. static int
  334. spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block)
  335. {
  336. const struct dblock *blk;
  337. u32 blkaddr;
  338. u32 blklen;
  339. blk = first_block;
  340. blkaddr = dblock_addr(blk);
  341. blklen = dblock_len(blk);
  342. while (dblock_addr(blk) != BLOCK_END) {
  343. spectrum_aux_setaddr(hw, blkaddr);
  344. hermes_write_bytes(hw, HERMES_AUXDATA, blk->data,
  345. blklen);
  346. blk = (struct dblock *) &blk->data[blklen];
  347. blkaddr = dblock_addr(blk);
  348. blklen = dblock_len(blk);
  349. }
  350. return 0;
  351. }
  352. /*
  353. * Process a firmware image - stop the card, load the firmware, reset
  354. * the card and make sure it responds. For the secondary firmware take
  355. * care of the PDA - read it and then write it on top of the firmware.
  356. */
  357. static int
  358. spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link,
  359. const unsigned char *image, int secondary)
  360. {
  361. int ret;
  362. const unsigned char *ptr;
  363. const struct dblock *first_block;
  364. /* Plug Data Area (PDA) */
  365. __le16 pda[PDA_WORDS];
  366. /* Binary block begins after the 0x1A marker */
  367. ptr = image;
  368. while (*ptr++ != TEXT_END);
  369. first_block = (const struct dblock *) ptr;
  370. /* Read the PDA */
  371. if (secondary) {
  372. ret = spectrum_read_pda(hw, pda, sizeof(pda));
  373. if (ret)
  374. return ret;
  375. }
  376. /* Stop the firmware, so that it can be safely rewritten */
  377. ret = spectrum_reset(link, 1);
  378. if (ret)
  379. return ret;
  380. /* Program the adapter with new firmware */
  381. ret = spectrum_load_blocks(hw, first_block);
  382. if (ret)
  383. return ret;
  384. /* Write the PDA to the adapter */
  385. if (secondary) {
  386. ret = spectrum_apply_pda(hw, first_block, pda);
  387. if (ret)
  388. return ret;
  389. }
  390. /* Run the firmware */
  391. ret = spectrum_reset(link, 0);
  392. if (ret)
  393. return ret;
  394. /* Reset hermes chip and make sure it responds */
  395. ret = hermes_init(hw);
  396. /* hermes_reset() should return 0 with the secondary firmware */
  397. if (secondary && ret != 0)
  398. return -ENODEV;
  399. /* And this should work with any firmware */
  400. if (!hermes_present(hw))
  401. return -ENODEV;
  402. return 0;
  403. }
  404. /*
  405. * Download the firmware into the card, this also does a PCMCIA soft
  406. * reset on the card, to make sure it's in a sane state.
  407. */
  408. static int
  409. spectrum_dl_firmware(hermes_t *hw, struct pcmcia_device *link)
  410. {
  411. int ret;
  412. const struct firmware *fw_entry;
  413. if (request_firmware(&fw_entry, primary_fw_name,
  414. &handle_to_dev(link)) != 0) {
  415. printk(KERN_ERR PFX "Cannot find firmware: %s\n",
  416. primary_fw_name);
  417. return -ENOENT;
  418. }
  419. /* Load primary firmware */
  420. ret = spectrum_dl_image(hw, link, fw_entry->data, 0);
  421. release_firmware(fw_entry);
  422. if (ret) {
  423. printk(KERN_ERR PFX "Primary firmware download failed\n");
  424. return ret;
  425. }
  426. if (request_firmware(&fw_entry, secondary_fw_name,
  427. &handle_to_dev(link)) != 0) {
  428. printk(KERN_ERR PFX "Cannot find firmware: %s\n",
  429. secondary_fw_name);
  430. return -ENOENT;
  431. }
  432. /* Load secondary firmware */
  433. ret = spectrum_dl_image(hw, link, fw_entry->data, 1);
  434. release_firmware(fw_entry);
  435. if (ret) {
  436. printk(KERN_ERR PFX "Secondary firmware download failed\n");
  437. }
  438. return ret;
  439. }
  440. /********************************************************************/
  441. /* Device methods */
  442. /********************************************************************/
  443. static int
  444. spectrum_cs_hard_reset(struct orinoco_private *priv)
  445. {
  446. struct orinoco_pccard *card = priv->card;
  447. struct pcmcia_device *link = card->p_dev;
  448. int err;
  449. if (!hermes_present(&priv->hw)) {
  450. /* The firmware needs to be reloaded */
  451. if (spectrum_dl_firmware(&priv->hw, link) != 0) {
  452. printk(KERN_ERR PFX "Firmware download failed\n");
  453. err = -ENODEV;
  454. }
  455. } else {
  456. /* Soft reset using COR and HCR */
  457. spectrum_reset(link, 0);
  458. }
  459. return 0;
  460. }
  461. /********************************************************************/
  462. /* PCMCIA stuff */
  463. /********************************************************************/
  464. /*
  465. * This creates an "instance" of the driver, allocating local data
  466. * structures for one device. The device is registered with Card
  467. * Services.
  468. *
  469. * The dev_link structure is initialized, but we don't actually
  470. * configure the card at this point -- we wait until we receive a card
  471. * insertion event. */
  472. static int
  473. spectrum_cs_probe(struct pcmcia_device *link)
  474. {
  475. struct net_device *dev;
  476. struct orinoco_private *priv;
  477. struct orinoco_pccard *card;
  478. dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset);
  479. if (! dev)
  480. return -ENOMEM;
  481. priv = netdev_priv(dev);
  482. card = priv->card;
  483. /* Link both structures together */
  484. card->p_dev = link;
  485. link->priv = dev;
  486. /* Interrupt setup */
  487. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  488. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  489. link->irq.Handler = orinoco_interrupt;
  490. link->irq.Instance = dev;
  491. /* General socket configuration defaults can go here. In this
  492. * client, we assume very little, and rely on the CIS for
  493. * almost everything. In most clients, many details (i.e.,
  494. * number, sizes, and attributes of IO windows) are fixed by
  495. * the nature of the device, and can be hard-wired here. */
  496. link->conf.Attributes = 0;
  497. link->conf.IntType = INT_MEMORY_AND_IO;
  498. return spectrum_cs_config(link);
  499. } /* spectrum_cs_attach */
  500. /*
  501. * This deletes a driver "instance". The device is de-registered with
  502. * Card Services. If it has been released, all local data structures
  503. * are freed. Otherwise, the structures will be freed when the device
  504. * is released.
  505. */
  506. static void spectrum_cs_detach(struct pcmcia_device *link)
  507. {
  508. struct net_device *dev = link->priv;
  509. if (link->dev_node)
  510. unregister_netdev(dev);
  511. spectrum_cs_release(link);
  512. free_orinocodev(dev);
  513. } /* spectrum_cs_detach */
  514. /*
  515. * spectrum_cs_config() is scheduled to run after a CARD_INSERTION
  516. * event is received, to configure the PCMCIA socket, and to make the
  517. * device available to the system.
  518. */
  519. struct spectrum_cs_config_data {
  520. config_info_t conf;
  521. };
  522. static int spectrum_cs_config_check(struct pcmcia_device *p_dev,
  523. cistpl_cftable_entry_t *cfg,
  524. cistpl_cftable_entry_t *dflt,
  525. void *priv_data)
  526. {
  527. struct spectrum_cs_config_data *cfg_mem = priv_data;
  528. if (cfg->index == 0)
  529. goto next_entry;
  530. /* Use power settings for Vcc and Vpp if present */
  531. /* Note that the CIS values need to be rescaled */
  532. if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
  533. if (cfg_mem->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
  534. DEBUG(2, "spectrum_cs_config: Vcc mismatch (cfg_mem->conf.Vcc = %d, CIS = %d)\n", cfg_mem->conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
  535. if (!ignore_cis_vcc)
  536. goto next_entry;
  537. }
  538. } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
  539. if (cfg_mem->conf.Vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000) {
  540. DEBUG(2, "spectrum_cs_config: Vcc mismatch (cfg_mem->conf.Vcc = %d, CIS = %d)\n", cfg_mem->conf.Vcc, dflt->vcc.param[CISTPL_POWER_VNOM] / 10000);
  541. if (!ignore_cis_vcc)
  542. goto next_entry;
  543. }
  544. }
  545. if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
  546. p_dev->conf.Vpp =
  547. cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
  548. else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
  549. p_dev->conf.Vpp =
  550. dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
  551. /* Do we need to allocate an interrupt? */
  552. p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
  553. /* IO window settings */
  554. p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
  555. if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
  556. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
  557. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  558. if (!(io->flags & CISTPL_IO_8BIT))
  559. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  560. if (!(io->flags & CISTPL_IO_16BIT))
  561. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  562. p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
  563. p_dev->io.BasePort1 = io->win[0].base;
  564. p_dev->io.NumPorts1 = io->win[0].len;
  565. if (io->nwin > 1) {
  566. p_dev->io.Attributes2 = p_dev->io.Attributes1;
  567. p_dev->io.BasePort2 = io->win[1].base;
  568. p_dev->io.NumPorts2 = io->win[1].len;
  569. }
  570. /* This reserves IO space but doesn't actually enable it */
  571. if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
  572. goto next_entry;
  573. }
  574. return 0;
  575. next_entry:
  576. pcmcia_disable_device(p_dev);
  577. return -ENODEV;
  578. };
  579. static int
  580. spectrum_cs_config(struct pcmcia_device *link)
  581. {
  582. struct spectrum_cs_config_data *cfg_mem;
  583. struct net_device *dev = link->priv;
  584. struct orinoco_private *priv = netdev_priv(dev);
  585. struct orinoco_pccard *card = priv->card;
  586. hermes_t *hw = &priv->hw;
  587. int last_fn, last_ret;
  588. void __iomem *mem;
  589. cfg_mem = kzalloc(sizeof(struct spectrum_cs_config_data), GFP_KERNEL);
  590. if (!cfg_mem)
  591. return -ENOMEM;
  592. /* Look up the current Vcc */
  593. CS_CHECK(GetConfigurationInfo,
  594. pcmcia_get_configuration_info(link, &cfg_mem->conf));
  595. /*
  596. * In this loop, we scan the CIS for configuration table
  597. * entries, each of which describes a valid card
  598. * configuration, including voltage, IO window, memory window,
  599. * and interrupt settings.
  600. *
  601. * We make no assumptions about the card to be configured: we
  602. * use just the information available in the CIS. In an ideal
  603. * world, this would work for any PCMCIA card, but it requires
  604. * a complete and accurate CIS. In practice, a driver usually
  605. * "knows" most of these things without consulting the CIS,
  606. * and most client drivers will only use the CIS to fill in
  607. * implementation-defined details.
  608. */
  609. last_ret = pcmcia_loop_config(link, spectrum_cs_config_check, cfg_mem);
  610. if (last_ret) {
  611. if (!ignore_cis_vcc)
  612. printk(KERN_ERR PFX "GetNextTuple(): No matching "
  613. "CIS configuration. Maybe you need the "
  614. "ignore_cis_vcc=1 parameter.\n");
  615. cs_error(link, RequestIO, last_ret);
  616. goto failed;
  617. }
  618. /*
  619. * Allocate an interrupt line. Note that this does not assign
  620. * a handler to the interrupt, unless the 'Handler' member of
  621. * the irq structure is initialized.
  622. */
  623. CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
  624. /* We initialize the hermes structure before completing PCMCIA
  625. * configuration just in case the interrupt handler gets
  626. * called. */
  627. mem = ioport_map(link->io.BasePort1, link->io.NumPorts1);
  628. if (!mem)
  629. goto cs_failed;
  630. hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
  631. /*
  632. * This actually configures the PCMCIA socket -- setting up
  633. * the I/O windows and the interrupt mapping, and putting the
  634. * card and host interface into "Memory and IO" mode.
  635. */
  636. CS_CHECK(RequestConfiguration,
  637. pcmcia_request_configuration(link, &link->conf));
  638. /* Ok, we have the configuration, prepare to register the netdev */
  639. dev->base_addr = link->io.BasePort1;
  640. dev->irq = link->irq.AssignedIRQ;
  641. card->node.major = card->node.minor = 0;
  642. /* Reset card and download firmware */
  643. if (spectrum_cs_hard_reset(priv) != 0) {
  644. goto failed;
  645. }
  646. SET_NETDEV_DEV(dev, &handle_to_dev(link));
  647. /* Tell the stack we exist */
  648. if (register_netdev(dev) != 0) {
  649. printk(KERN_ERR PFX "register_netdev() failed\n");
  650. goto failed;
  651. }
  652. /* At this point, the dev_node_t structure(s) needs to be
  653. * initialized and arranged in a linked list at link->dev_node. */
  654. strcpy(card->node.dev_name, dev->name);
  655. link->dev_node = &card->node; /* link->dev_node being non-NULL is also
  656. used to indicate that the
  657. net_device has been registered */
  658. /* Finally, report what we've done */
  659. printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io "
  660. "0x%04x-0x%04x\n", dev->name, dev->dev.parent->bus_id,
  661. link->irq.AssignedIRQ, link->io.BasePort1,
  662. link->io.BasePort1 + link->io.NumPorts1 - 1);
  663. kfree(cfg_mem);
  664. return 0;
  665. cs_failed:
  666. cs_error(link, last_fn, last_ret);
  667. failed:
  668. spectrum_cs_release(link);
  669. kfree(cfg_mem);
  670. return -ENODEV;
  671. } /* spectrum_cs_config */
  672. /*
  673. * After a card is removed, spectrum_cs_release() will unregister the
  674. * device, and release the PCMCIA configuration. If the device is
  675. * still open, this will be postponed until it is closed.
  676. */
  677. static void
  678. spectrum_cs_release(struct pcmcia_device *link)
  679. {
  680. struct net_device *dev = link->priv;
  681. struct orinoco_private *priv = netdev_priv(dev);
  682. unsigned long flags;
  683. /* We're committed to taking the device away now, so mark the
  684. * hardware as unavailable */
  685. spin_lock_irqsave(&priv->lock, flags);
  686. priv->hw_unavailable++;
  687. spin_unlock_irqrestore(&priv->lock, flags);
  688. pcmcia_disable_device(link);
  689. if (priv->hw.iobase)
  690. ioport_unmap(priv->hw.iobase);
  691. } /* spectrum_cs_release */
  692. static int
  693. spectrum_cs_suspend(struct pcmcia_device *link)
  694. {
  695. struct net_device *dev = link->priv;
  696. struct orinoco_private *priv = netdev_priv(dev);
  697. int err = 0;
  698. /* Mark the device as stopped, to block IO until later */
  699. spin_lock(&priv->lock);
  700. err = __orinoco_down(dev);
  701. if (err)
  702. printk(KERN_WARNING "%s: Error %d downing interface\n",
  703. dev->name, err);
  704. netif_device_detach(dev);
  705. priv->hw_unavailable++;
  706. spin_unlock(&priv->lock);
  707. return err;
  708. }
  709. static int
  710. spectrum_cs_resume(struct pcmcia_device *link)
  711. {
  712. struct net_device *dev = link->priv;
  713. struct orinoco_private *priv = netdev_priv(dev);
  714. netif_device_attach(dev);
  715. priv->hw_unavailable--;
  716. schedule_work(&priv->reset_work);
  717. return 0;
  718. }
  719. /********************************************************************/
  720. /* Module initialization */
  721. /********************************************************************/
  722. /* Can't be declared "const" or the whole __initdata section will
  723. * become const */
  724. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  725. " (Pavel Roskin <proski@gnu.org>,"
  726. " David Gibson <hermes@gibson.dropbear.id.au>, et al)";
  727. static struct pcmcia_device_id spectrum_cs_ids[] = {
  728. PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4137 */
  729. PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
  730. PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless LAN PC Card", 0x816cc815, 0x6fbf459a), /* 2011B, not 2011 */
  731. PCMCIA_DEVICE_NULL,
  732. };
  733. MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids);
  734. static struct pcmcia_driver orinoco_driver = {
  735. .owner = THIS_MODULE,
  736. .drv = {
  737. .name = DRIVER_NAME,
  738. },
  739. .probe = spectrum_cs_probe,
  740. .remove = spectrum_cs_detach,
  741. .suspend = spectrum_cs_suspend,
  742. .resume = spectrum_cs_resume,
  743. .id_table = spectrum_cs_ids,
  744. };
  745. static int __init
  746. init_spectrum_cs(void)
  747. {
  748. printk(KERN_DEBUG "%s\n", version);
  749. return pcmcia_register_driver(&orinoco_driver);
  750. }
  751. static void __exit
  752. exit_spectrum_cs(void)
  753. {
  754. pcmcia_unregister_driver(&orinoco_driver);
  755. }
  756. module_init(init_spectrum_cs);
  757. module_exit(exit_spectrum_cs);