ixj_pcmcia.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/cistpl.h>
  9. #include <pcmcia/ds.h>
  10. #include "ixj.h"
  11. /*
  12. * PCMCIA service support for Quicknet cards
  13. */
  14. typedef struct ixj_info_t {
  15. int ndev;
  16. struct ixj *port;
  17. } ixj_info_t;
  18. static void ixj_detach(struct pcmcia_device *p_dev);
  19. static int ixj_config(struct pcmcia_device * link);
  20. static void ixj_cs_release(struct pcmcia_device * link);
  21. static int ixj_probe(struct pcmcia_device *p_dev)
  22. {
  23. dev_dbg(&p_dev->dev, "ixj_attach()\n");
  24. /* Create new ixj device */
  25. p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
  26. if (!p_dev->priv) {
  27. return -ENOMEM;
  28. }
  29. return ixj_config(p_dev);
  30. }
  31. static void ixj_detach(struct pcmcia_device *link)
  32. {
  33. dev_dbg(&link->dev, "ixj_detach\n");
  34. ixj_cs_release(link);
  35. kfree(link->priv);
  36. }
  37. static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
  38. {
  39. char *str;
  40. int i, place;
  41. dev_dbg(&link->dev, "ixj_get_serial\n");
  42. str = link->prod_id[0];
  43. if (!str)
  44. goto failed;
  45. printk("%s", str);
  46. str = link->prod_id[1];
  47. if (!str)
  48. goto failed;
  49. printk(" %s", str);
  50. str = link->prod_id[2];
  51. if (!str)
  52. goto failed;
  53. place = 1;
  54. for (i = strlen(str) - 1; i >= 0; i--) {
  55. switch (str[i]) {
  56. case '0':
  57. case '1':
  58. case '2':
  59. case '3':
  60. case '4':
  61. case '5':
  62. case '6':
  63. case '7':
  64. case '8':
  65. case '9':
  66. j->serial += (str[i] - 48) * place;
  67. break;
  68. case 'A':
  69. case 'B':
  70. case 'C':
  71. case 'D':
  72. case 'E':
  73. case 'F':
  74. j->serial += (str[i] - 55) * place;
  75. break;
  76. case 'a':
  77. case 'b':
  78. case 'c':
  79. case 'd':
  80. case 'e':
  81. case 'f':
  82. j->serial += (str[i] - 87) * place;
  83. break;
  84. }
  85. place = place * 0x10;
  86. }
  87. str = link->prod_id[3];
  88. if (!str)
  89. goto failed;
  90. printk(" version %s\n", str);
  91. failed:
  92. return;
  93. }
  94. static int ixj_config_check(struct pcmcia_device *p_dev, void *priv_data)
  95. {
  96. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  97. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
  98. p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
  99. p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
  100. p_dev->io_lines = 3;
  101. return pcmcia_request_io(p_dev);
  102. }
  103. static int ixj_config(struct pcmcia_device * link)
  104. {
  105. IXJ *j;
  106. ixj_info_t *info;
  107. info = link->priv;
  108. dev_dbg(&link->dev, "ixj_config\n");
  109. link->config_flags = CONF_AUTO_SET_IO;
  110. if (pcmcia_loop_config(link, ixj_config_check, NULL))
  111. goto failed;
  112. if (pcmcia_enable_device(link))
  113. goto failed;
  114. /*
  115. * Register the card with the core.
  116. */
  117. j = ixj_pcmcia_probe(link->resource[0]->start,
  118. link->resource[0]->start + 0x10);
  119. info->ndev = 1;
  120. ixj_get_serial(link, j);
  121. return 0;
  122. failed:
  123. ixj_cs_release(link);
  124. return -ENODEV;
  125. }
  126. static void ixj_cs_release(struct pcmcia_device *link)
  127. {
  128. ixj_info_t *info = link->priv;
  129. dev_dbg(&link->dev, "ixj_cs_release\n");
  130. info->ndev = 0;
  131. pcmcia_disable_device(link);
  132. }
  133. static const struct pcmcia_device_id ixj_ids[] = {
  134. PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
  135. PCMCIA_DEVICE_NULL
  136. };
  137. MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
  138. static struct pcmcia_driver ixj_driver = {
  139. .owner = THIS_MODULE,
  140. .name = "ixj_cs",
  141. .probe = ixj_probe,
  142. .remove = ixj_detach,
  143. .id_table = ixj_ids,
  144. };
  145. static int __init ixj_pcmcia_init(void)
  146. {
  147. return pcmcia_register_driver(&ixj_driver);
  148. }
  149. static void ixj_pcmcia_exit(void)
  150. {
  151. pcmcia_unregister_driver(&ixj_driver);
  152. }
  153. module_init(ixj_pcmcia_init);
  154. module_exit(ixj_pcmcia_exit);
  155. MODULE_LICENSE("GPL");