ixj_pcmcia.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
  40. if (!p_dev->priv) {
  41. return -ENOMEM;
  42. }
  43. memset(p_dev->priv, 0, sizeof(struct ixj_info_t));
  44. return ixj_config(p_dev);
  45. }
  46. static void ixj_detach(struct pcmcia_device *link)
  47. {
  48. DEBUG(0, "ixj_detach(0x%p)\n", link);
  49. ixj_cs_release(link);
  50. kfree(link->priv);
  51. }
  52. #define CS_CHECK(fn, ret) \
  53. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  54. static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
  55. {
  56. char *str;
  57. int i, place;
  58. DEBUG(0, "ixj_get_serial(0x%p)\n", link);
  59. str = link->prod_id[0];
  60. if (!str)
  61. goto cs_failed;
  62. printk("%s", str);
  63. str = link->prod_id[1];
  64. if (!str)
  65. goto cs_failed;
  66. printk(" %s", str);
  67. str = link->prod_id[2];
  68. if (!str)
  69. goto cs_failed;
  70. place = 1;
  71. for (i = strlen(str) - 1; i >= 0; i--) {
  72. switch (str[i]) {
  73. case '0':
  74. case '1':
  75. case '2':
  76. case '3':
  77. case '4':
  78. case '5':
  79. case '6':
  80. case '7':
  81. case '8':
  82. case '9':
  83. j->serial += (str[i] - 48) * place;
  84. break;
  85. case 'A':
  86. case 'B':
  87. case 'C':
  88. case 'D':
  89. case 'E':
  90. case 'F':
  91. j->serial += (str[i] - 55) * place;
  92. break;
  93. case 'a':
  94. case 'b':
  95. case 'c':
  96. case 'd':
  97. case 'e':
  98. case 'f':
  99. j->serial += (str[i] - 87) * place;
  100. break;
  101. }
  102. place = place * 0x10;
  103. }
  104. str = link->prod_id[3];
  105. if (!str)
  106. goto cs_failed;
  107. printk(" version %s\n", str);
  108. cs_failed:
  109. return;
  110. }
  111. static int ixj_config(struct pcmcia_device * link)
  112. {
  113. IXJ *j;
  114. ixj_info_t *info;
  115. tuple_t tuple;
  116. u_short buf[128];
  117. cisparse_t parse;
  118. cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
  119. cistpl_cftable_entry_t dflt =
  120. {
  121. 0
  122. };
  123. int last_ret, last_fn;
  124. info = link->priv;
  125. DEBUG(0, "ixj_config(0x%p)\n", link);
  126. tuple.TupleData = (cisdata_t *) buf;
  127. tuple.TupleOffset = 0;
  128. tuple.TupleDataMax = 255;
  129. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  130. tuple.Attributes = 0;
  131. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  132. while (1) {
  133. if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
  134. pcmcia_parse_tuple(link, &tuple, &parse) != 0)
  135. goto next_entry;
  136. if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
  137. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
  138. link->conf.ConfigIndex = cfg->index;
  139. link->io.BasePort1 = io->win[0].base;
  140. link->io.NumPorts1 = io->win[0].len;
  141. if (io->nwin == 2) {
  142. link->io.BasePort2 = io->win[1].base;
  143. link->io.NumPorts2 = io->win[1].len;
  144. }
  145. if (pcmcia_request_io(link, &link->io) != 0)
  146. goto next_entry;
  147. /* If we've got this far, we're done */
  148. break;
  149. }
  150. next_entry:
  151. if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
  152. dflt = *cfg;
  153. CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
  154. }
  155. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
  156. /*
  157. * Register the card with the core.
  158. */
  159. j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10);
  160. info->ndev = 1;
  161. info->node.major = PHONE_MAJOR;
  162. link->dev_node = &info->node;
  163. ixj_get_serial(link, j);
  164. return 0;
  165. cs_failed:
  166. cs_error(link, last_fn, last_ret);
  167. ixj_cs_release(link);
  168. return -ENODEV;
  169. }
  170. static void ixj_cs_release(struct pcmcia_device *link)
  171. {
  172. ixj_info_t *info = link->priv;
  173. DEBUG(0, "ixj_cs_release(0x%p)\n", link);
  174. info->ndev = 0;
  175. pcmcia_disable_device(link);
  176. }
  177. static struct pcmcia_device_id ixj_ids[] = {
  178. PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
  179. PCMCIA_DEVICE_NULL
  180. };
  181. MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
  182. static struct pcmcia_driver ixj_driver = {
  183. .owner = THIS_MODULE,
  184. .drv = {
  185. .name = "ixj_cs",
  186. },
  187. .probe = ixj_probe,
  188. .remove = ixj_detach,
  189. .id_table = ixj_ids,
  190. };
  191. static int __init ixj_pcmcia_init(void)
  192. {
  193. return pcmcia_register_driver(&ixj_driver);
  194. }
  195. static void ixj_pcmcia_exit(void)
  196. {
  197. pcmcia_unregister_driver(&ixj_driver);
  198. }
  199. module_init(ixj_pcmcia_init);
  200. module_exit(ixj_pcmcia_exit);
  201. MODULE_LICENSE("GPL");