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.h>
  9. #include <pcmcia/cistpl.h>
  10. #include <pcmcia/ds.h>
  11. #include "ixj.h"
  12. /*
  13. * PCMCIA service support for Quicknet cards
  14. */
  15. typedef struct ixj_info_t {
  16. int ndev;
  17. struct ixj *port;
  18. } ixj_info_t;
  19. static void ixj_detach(struct pcmcia_device *p_dev);
  20. static int ixj_config(struct pcmcia_device * link);
  21. static void ixj_cs_release(struct pcmcia_device * link);
  22. static int ixj_probe(struct pcmcia_device *p_dev)
  23. {
  24. dev_dbg(&p_dev->dev, "ixj_attach()\n");
  25. /* Create new ixj device */
  26. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
  27. p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
  28. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  29. p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
  30. if (!p_dev->priv) {
  31. return -ENOMEM;
  32. }
  33. return ixj_config(p_dev);
  34. }
  35. static void ixj_detach(struct pcmcia_device *link)
  36. {
  37. dev_dbg(&link->dev, "ixj_detach\n");
  38. ixj_cs_release(link);
  39. kfree(link->priv);
  40. }
  41. static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
  42. {
  43. char *str;
  44. int i, place;
  45. dev_dbg(&link->dev, "ixj_get_serial\n");
  46. str = link->prod_id[0];
  47. if (!str)
  48. goto failed;
  49. printk("%s", str);
  50. str = link->prod_id[1];
  51. if (!str)
  52. goto failed;
  53. printk(" %s", str);
  54. str = link->prod_id[2];
  55. if (!str)
  56. goto failed;
  57. place = 1;
  58. for (i = strlen(str) - 1; i >= 0; i--) {
  59. switch (str[i]) {
  60. case '0':
  61. case '1':
  62. case '2':
  63. case '3':
  64. case '4':
  65. case '5':
  66. case '6':
  67. case '7':
  68. case '8':
  69. case '9':
  70. j->serial += (str[i] - 48) * place;
  71. break;
  72. case 'A':
  73. case 'B':
  74. case 'C':
  75. case 'D':
  76. case 'E':
  77. case 'F':
  78. j->serial += (str[i] - 55) * place;
  79. break;
  80. case 'a':
  81. case 'b':
  82. case 'c':
  83. case 'd':
  84. case 'e':
  85. case 'f':
  86. j->serial += (str[i] - 87) * place;
  87. break;
  88. }
  89. place = place * 0x10;
  90. }
  91. str = link->prod_id[3];
  92. if (!str)
  93. goto failed;
  94. printk(" version %s\n", str);
  95. failed:
  96. return;
  97. }
  98. static int ixj_config_check(struct pcmcia_device *p_dev,
  99. cistpl_cftable_entry_t *cfg,
  100. cistpl_cftable_entry_t *dflt,
  101. unsigned int vcc,
  102. void *priv_data)
  103. {
  104. if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
  105. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
  106. p_dev->resource[0]->start = io->win[0].base;
  107. p_dev->resource[0]->end = io->win[0].len;
  108. p_dev->io_lines = 3;
  109. if (io->nwin == 2) {
  110. p_dev->resource[1]->start = io->win[1].base;
  111. p_dev->resource[1]->end = io->win[1].len;
  112. }
  113. if (!pcmcia_request_io(p_dev))
  114. return 0;
  115. }
  116. return -ENODEV;
  117. }
  118. static int ixj_config(struct pcmcia_device * link)
  119. {
  120. IXJ *j;
  121. ixj_info_t *info;
  122. cistpl_cftable_entry_t dflt = { 0 };
  123. info = link->priv;
  124. dev_dbg(&link->dev, "ixj_config\n");
  125. if (pcmcia_loop_config(link, ixj_config_check, &dflt))
  126. goto failed;
  127. if (pcmcia_request_configuration(link, &link->conf))
  128. goto failed;
  129. /*
  130. * Register the card with the core.
  131. */
  132. j = ixj_pcmcia_probe(link->resource[0]->start,
  133. link->resource[0]->start + 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");