ixj_pcmcia.c 4.0 KB

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