avm_cs.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 <pcmcia/cistpl.h>
  21. #include <pcmcia/ciscode.h>
  22. #include <pcmcia/ds.h>
  23. #include <pcmcia/cisreg.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/capi.h>
  26. #include <linux/b1lli.h>
  27. #include <linux/b1pcmcia.h>
  28. /*====================================================================*/
  29. MODULE_DESCRIPTION("CAPI4Linux: PCMCIA client driver for AVM B1/M1/M2");
  30. MODULE_AUTHOR("Carsten Paeth");
  31. MODULE_LICENSE("GPL");
  32. /*====================================================================*/
  33. static int avmcs_config(struct pcmcia_device *link);
  34. static void avmcs_release(struct pcmcia_device *link);
  35. static void avmcs_detach(struct pcmcia_device *p_dev);
  36. static int avmcs_probe(struct pcmcia_device *p_dev)
  37. {
  38. /* General socket configuration */
  39. p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  40. p_dev->config_index = 1;
  41. p_dev->config_regs = PRESENT_OPTION;
  42. return avmcs_config(p_dev);
  43. } /* avmcs_attach */
  44. static void avmcs_detach(struct pcmcia_device *link)
  45. {
  46. avmcs_release(link);
  47. } /* avmcs_detach */
  48. static int avmcs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
  49. {
  50. p_dev->resource[0]->end = 16;
  51. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  52. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
  53. return pcmcia_request_io(p_dev);
  54. }
  55. static int avmcs_config(struct pcmcia_device *link)
  56. {
  57. int i = -1;
  58. char devname[128];
  59. int cardtype;
  60. int (*addcard)(unsigned int port, unsigned irq);
  61. devname[0] = 0;
  62. if (link->prod_id[1])
  63. strlcpy(devname, link->prod_id[1], sizeof(devname));
  64. /*
  65. * find IO port
  66. */
  67. if (pcmcia_loop_config(link, avmcs_configcheck, NULL))
  68. return -ENODEV;
  69. do {
  70. if (!link->irq) {
  71. /* undo */
  72. pcmcia_disable_device(link);
  73. break;
  74. }
  75. /*
  76. * configure the PCMCIA socket
  77. */
  78. i = pcmcia_enable_device(link);
  79. if (i != 0) {
  80. pcmcia_disable_device(link);
  81. break;
  82. }
  83. } while (0);
  84. if (devname[0]) {
  85. char *s = strrchr(devname, ' ');
  86. if (!s)
  87. s = devname;
  88. else s++;
  89. if (strcmp("M1", s) == 0) {
  90. cardtype = AVM_CARDTYPE_M1;
  91. } else if (strcmp("M2", s) == 0) {
  92. cardtype = AVM_CARDTYPE_M2;
  93. } else {
  94. cardtype = AVM_CARDTYPE_B1;
  95. }
  96. } else
  97. cardtype = AVM_CARDTYPE_B1;
  98. /* If any step failed, release any partially configured state */
  99. if (i != 0) {
  100. avmcs_release(link);
  101. return -ENODEV;
  102. }
  103. switch (cardtype) {
  104. case AVM_CARDTYPE_M1: addcard = b1pcmcia_addcard_m1; break;
  105. case AVM_CARDTYPE_M2: addcard = b1pcmcia_addcard_m2; break;
  106. default:
  107. case AVM_CARDTYPE_B1: addcard = b1pcmcia_addcard_b1; break;
  108. }
  109. if ((i = (*addcard)(link->resource[0]->start, link->irq)) < 0) {
  110. dev_err(&link->dev,
  111. "avm_cs: failed to add AVM-Controller at i/o %#x, irq %d\n",
  112. (unsigned int) link->resource[0]->start, link->irq);
  113. avmcs_release(link);
  114. return -ENODEV;
  115. }
  116. return 0;
  117. } /* avmcs_config */
  118. static void avmcs_release(struct pcmcia_device *link)
  119. {
  120. b1pcmcia_delcard(link->resource[0]->start, link->irq);
  121. pcmcia_disable_device(link);
  122. } /* avmcs_release */
  123. static const struct pcmcia_device_id avmcs_ids[] = {
  124. PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
  125. PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M1", 0x95d42008, 0x81e10430),
  126. PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M2", 0x95d42008, 0x18e8558a),
  127. PCMCIA_DEVICE_NULL
  128. };
  129. MODULE_DEVICE_TABLE(pcmcia, avmcs_ids);
  130. static struct pcmcia_driver avmcs_driver = {
  131. .owner = THIS_MODULE,
  132. .name = "avm_cs",
  133. .probe = avmcs_probe,
  134. .remove = avmcs_detach,
  135. .id_table = avmcs_ids,
  136. };
  137. module_pcmcia_driver(avmcs_driver);