ixj_pcmcia.c 5.7 KB

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