ixj_pcmcia.c 5.8 KB

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