ixj_pcmcia.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #include "ixj-ver.h"
  2. #include <linux/module.h>
  3. #include <linux/init.h>
  4. #include <linux/kernel.h> /* printk() */
  5. #include <linux/fs.h> /* everything... */
  6. #include <linux/errno.h> /* error codes */
  7. #include <linux/slab.h>
  8. #include <pcmcia/cs_types.h>
  9. #include <pcmcia/cs.h>
  10. #include <pcmcia/cistpl.h>
  11. #include <pcmcia/ds.h>
  12. #include "ixj.h"
  13. /*
  14. * PCMCIA service support for Quicknet cards
  15. */
  16. typedef struct ixj_info_t {
  17. int ndev;
  18. struct ixj *port;
  19. } ixj_info_t;
  20. static void ixj_detach(struct pcmcia_device *p_dev);
  21. static int ixj_config(struct pcmcia_device * link);
  22. static void ixj_cs_release(struct pcmcia_device * link);
  23. static int ixj_probe(struct pcmcia_device *p_dev)
  24. {
  25. dev_dbg(&p_dev->dev, "ixj_attach()\n");
  26. /* Create new ixj device */
  27. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  28. p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
  29. p_dev->io.IOAddrLines = 3;
  30. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  31. p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
  32. if (!p_dev->priv) {
  33. return -ENOMEM;
  34. }
  35. return ixj_config(p_dev);
  36. }
  37. static void ixj_detach(struct pcmcia_device *link)
  38. {
  39. dev_dbg(&link->dev, "ixj_detach\n");
  40. ixj_cs_release(link);
  41. kfree(link->priv);
  42. }
  43. static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
  44. {
  45. char *str;
  46. int i, place;
  47. dev_dbg(&link->dev, "ixj_get_serial\n");
  48. str = link->prod_id[0];
  49. if (!str)
  50. goto failed;
  51. printk("%s", str);
  52. str = link->prod_id[1];
  53. if (!str)
  54. goto failed;
  55. printk(" %s", str);
  56. str = link->prod_id[2];
  57. if (!str)
  58. goto failed;
  59. place = 1;
  60. for (i = strlen(str) - 1; i >= 0; i--) {
  61. switch (str[i]) {
  62. case '0':
  63. case '1':
  64. case '2':
  65. case '3':
  66. case '4':
  67. case '5':
  68. case '6':
  69. case '7':
  70. case '8':
  71. case '9':
  72. j->serial += (str[i] - 48) * place;
  73. break;
  74. case 'A':
  75. case 'B':
  76. case 'C':
  77. case 'D':
  78. case 'E':
  79. case 'F':
  80. j->serial += (str[i] - 55) * place;
  81. break;
  82. case 'a':
  83. case 'b':
  84. case 'c':
  85. case 'd':
  86. case 'e':
  87. case 'f':
  88. j->serial += (str[i] - 87) * place;
  89. break;
  90. }
  91. place = place * 0x10;
  92. }
  93. str = link->prod_id[3];
  94. if (!str)
  95. goto failed;
  96. printk(" version %s\n", str);
  97. failed:
  98. return;
  99. }
  100. static int ixj_config_check(struct pcmcia_device *p_dev,
  101. cistpl_cftable_entry_t *cfg,
  102. cistpl_cftable_entry_t *dflt,
  103. unsigned int vcc,
  104. void *priv_data)
  105. {
  106. if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
  107. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
  108. p_dev->io.BasePort1 = io->win[0].base;
  109. p_dev->io.NumPorts1 = io->win[0].len;
  110. if (io->nwin == 2) {
  111. p_dev->io.BasePort2 = io->win[1].base;
  112. p_dev->io.NumPorts2 = io->win[1].len;
  113. }
  114. if (!pcmcia_request_io(p_dev, &p_dev->io))
  115. return 0;
  116. }
  117. return -ENODEV;
  118. }
  119. static int ixj_config(struct pcmcia_device * link)
  120. {
  121. IXJ *j;
  122. ixj_info_t *info;
  123. cistpl_cftable_entry_t dflt = { 0 };
  124. info = link->priv;
  125. dev_dbg(&link->dev, "ixj_config\n");
  126. if (pcmcia_loop_config(link, ixj_config_check, &dflt))
  127. goto failed;
  128. if (pcmcia_request_configuration(link, &link->conf))
  129. goto failed;
  130. /*
  131. * Register the card with the core.
  132. */
  133. j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10);
  134. info->ndev = 1;
  135. ixj_get_serial(link, j);
  136. return 0;
  137. failed:
  138. ixj_cs_release(link);
  139. return -ENODEV;
  140. }
  141. static void ixj_cs_release(struct pcmcia_device *link)
  142. {
  143. ixj_info_t *info = link->priv;
  144. dev_dbg(&link->dev, "ixj_cs_release\n");
  145. info->ndev = 0;
  146. pcmcia_disable_device(link);
  147. }
  148. static struct pcmcia_device_id ixj_ids[] = {
  149. PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
  150. PCMCIA_DEVICE_NULL
  151. };
  152. MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
  153. static struct pcmcia_driver ixj_driver = {
  154. .owner = THIS_MODULE,
  155. .drv = {
  156. .name = "ixj_cs",
  157. },
  158. .probe = ixj_probe,
  159. .remove = ixj_detach,
  160. .id_table = ixj_ids,
  161. };
  162. static int __init ixj_pcmcia_init(void)
  163. {
  164. return pcmcia_register_driver(&ixj_driver);
  165. }
  166. static void ixj_pcmcia_exit(void)
  167. {
  168. pcmcia_unregister_driver(&ixj_driver);
  169. }
  170. module_init(ixj_pcmcia_init);
  171. module_exit(ixj_pcmcia_exit);
  172. MODULE_LICENSE("GPL");