ixj_pcmcia.c 5.5 KB

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