ixj_pcmcia.c 4.9 KB

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