ixj_pcmcia.c 4.3 KB

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