avm_cs.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* $Id: avm_cs.c,v 1.4.6.3 2001/09/23 22:24:33 kai Exp $
  2. *
  3. * A PCMCIA client driver for AVM B1/M1/M2
  4. *
  5. * Copyright 1999 by Carsten Paeth <calle@calle.de>
  6. *
  7. * This software may be used and distributed according to the terms
  8. * of the GNU General Public License, incorporated herein by reference.
  9. *
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/ptrace.h>
  15. #include <linux/string.h>
  16. #include <linux/tty.h>
  17. #include <linux/serial.h>
  18. #include <linux/major.h>
  19. #include <asm/io.h>
  20. #include <asm/system.h>
  21. #include <pcmcia/cistpl.h>
  22. #include <pcmcia/ciscode.h>
  23. #include <pcmcia/ds.h>
  24. #include <pcmcia/cisreg.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/capi.h>
  27. #include <linux/b1lli.h>
  28. #include <linux/b1pcmcia.h>
  29. /*====================================================================*/
  30. MODULE_DESCRIPTION("CAPI4Linux: PCMCIA client driver for AVM B1/M1/M2");
  31. MODULE_AUTHOR("Carsten Paeth");
  32. MODULE_LICENSE("GPL");
  33. /*====================================================================*/
  34. static int avmcs_config(struct pcmcia_device *link);
  35. static void avmcs_release(struct pcmcia_device *link);
  36. static void avmcs_detach(struct pcmcia_device *p_dev);
  37. static int avmcs_probe(struct pcmcia_device *p_dev)
  38. {
  39. /* General socket configuration */
  40. p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  41. p_dev->config_index = 1;
  42. p_dev->config_regs = PRESENT_OPTION;
  43. return avmcs_config(p_dev);
  44. } /* avmcs_attach */
  45. static void avmcs_detach(struct pcmcia_device *link)
  46. {
  47. avmcs_release(link);
  48. } /* avmcs_detach */
  49. static int avmcs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
  50. {
  51. p_dev->resource[0]->end = 16;
  52. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  53. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
  54. return pcmcia_request_io(p_dev);
  55. }
  56. static int avmcs_config(struct pcmcia_device *link)
  57. {
  58. int i = -1;
  59. char devname[128];
  60. int cardtype;
  61. int (*addcard)(unsigned int port, unsigned irq);
  62. devname[0] = 0;
  63. if (link->prod_id[1])
  64. strlcpy(devname, link->prod_id[1], sizeof(devname));
  65. /*
  66. * find IO port
  67. */
  68. if (pcmcia_loop_config(link, avmcs_configcheck, NULL))
  69. return -ENODEV;
  70. do {
  71. if (!link->irq) {
  72. /* undo */
  73. pcmcia_disable_device(link);
  74. break;
  75. }
  76. /*
  77. * configure the PCMCIA socket
  78. */
  79. i = pcmcia_enable_device(link);
  80. if (i != 0) {
  81. pcmcia_disable_device(link);
  82. break;
  83. }
  84. } while (0);
  85. if (devname[0]) {
  86. char *s = strrchr(devname, ' ');
  87. if (!s)
  88. s = devname;
  89. else s++;
  90. if (strcmp("M1", s) == 0) {
  91. cardtype = AVM_CARDTYPE_M1;
  92. } else if (strcmp("M2", s) == 0) {
  93. cardtype = AVM_CARDTYPE_M2;
  94. } else {
  95. cardtype = AVM_CARDTYPE_B1;
  96. }
  97. } else
  98. cardtype = AVM_CARDTYPE_B1;
  99. /* If any step failed, release any partially configured state */
  100. if (i != 0) {
  101. avmcs_release(link);
  102. return -ENODEV;
  103. }
  104. switch (cardtype) {
  105. case AVM_CARDTYPE_M1: addcard = b1pcmcia_addcard_m1; break;
  106. case AVM_CARDTYPE_M2: addcard = b1pcmcia_addcard_m2; break;
  107. default:
  108. case AVM_CARDTYPE_B1: addcard = b1pcmcia_addcard_b1; break;
  109. }
  110. if ((i = (*addcard)(link->resource[0]->start, link->irq)) < 0) {
  111. dev_err(&link->dev,
  112. "avm_cs: failed to add AVM-Controller at i/o %#x, irq %d\n",
  113. (unsigned int) link->resource[0]->start, link->irq);
  114. avmcs_release(link);
  115. return -ENODEV;
  116. }
  117. return 0;
  118. } /* avmcs_config */
  119. static void avmcs_release(struct pcmcia_device *link)
  120. {
  121. b1pcmcia_delcard(link->resource[0]->start, link->irq);
  122. pcmcia_disable_device(link);
  123. } /* avmcs_release */
  124. static const struct pcmcia_device_id avmcs_ids[] = {
  125. PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
  126. PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M1", 0x95d42008, 0x81e10430),
  127. PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M2", 0x95d42008, 0x18e8558a),
  128. PCMCIA_DEVICE_NULL
  129. };
  130. MODULE_DEVICE_TABLE(pcmcia, avmcs_ids);
  131. static struct pcmcia_driver avmcs_driver = {
  132. .owner = THIS_MODULE,
  133. .name = "avm_cs",
  134. .probe = avmcs_probe,
  135. .remove = avmcs_detach,
  136. .id_table = avmcs_ids,
  137. };
  138. static int __init avmcs_init(void)
  139. {
  140. return pcmcia_register_driver(&avmcs_driver);
  141. }
  142. static void __exit avmcs_exit(void)
  143. {
  144. pcmcia_unregister_driver(&avmcs_driver);
  145. }
  146. module_init(avmcs_init);
  147. module_exit(avmcs_exit);