ixj_pcmcia.c 3.8 KB

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