avma1_cs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * PCMCIA client driver for AVM A1 / Fritz!PCMCIA
  3. *
  4. * Author Carsten Paeth
  5. * Copyright 1998-2001 by Carsten Paeth <calle@calle.in-berlin.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/slab.h>
  16. #include <linux/string.h>
  17. #include <asm/io.h>
  18. #include <pcmcia/cistpl.h>
  19. #include <pcmcia/ds.h>
  20. #include "hisax_cfg.h"
  21. MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards");
  22. MODULE_AUTHOR("Carsten Paeth");
  23. MODULE_LICENSE("GPL");
  24. /*====================================================================*/
  25. /* Parameters that can be set with 'insmod' */
  26. static int isdnprot = 2;
  27. module_param(isdnprot, int, 0);
  28. /*====================================================================*/
  29. static int avma1cs_config(struct pcmcia_device *link);
  30. static void avma1cs_release(struct pcmcia_device *link);
  31. static void avma1cs_detach(struct pcmcia_device *p_dev);
  32. static int avma1cs_probe(struct pcmcia_device *p_dev)
  33. {
  34. dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
  35. /* General socket configuration */
  36. p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  37. p_dev->config_index = 1;
  38. p_dev->config_regs = PRESENT_OPTION;
  39. return avma1cs_config(p_dev);
  40. } /* avma1cs_attach */
  41. static void avma1cs_detach(struct pcmcia_device *link)
  42. {
  43. dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
  44. avma1cs_release(link);
  45. kfree(link->priv);
  46. } /* avma1cs_detach */
  47. static int avma1cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
  48. {
  49. p_dev->resource[0]->end = 16;
  50. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  51. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
  52. p_dev->io_lines = 5;
  53. return pcmcia_request_io(p_dev);
  54. }
  55. static int avma1cs_config(struct pcmcia_device *link)
  56. {
  57. int i = -1;
  58. char devname[128];
  59. IsdnCard_t icard;
  60. int busy = 0;
  61. dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
  62. devname[0] = 0;
  63. if (link->prod_id[1])
  64. strlcpy(devname, link->prod_id[1], sizeof(devname));
  65. if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
  66. return -ENODEV;
  67. do {
  68. /*
  69. * allocate an interrupt line
  70. */
  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 any step failed, release any partially configured state */
  86. if (i != 0) {
  87. avma1cs_release(link);
  88. return -ENODEV;
  89. }
  90. icard.para[0] = link->irq;
  91. icard.para[1] = link->resource[0]->start;
  92. icard.protocol = isdnprot;
  93. icard.typ = ISDN_CTYPE_A1_PCMCIA;
  94. i = hisax_init_pcmcia(link, &busy, &icard);
  95. if (i < 0) {
  96. printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 "
  97. "PCMCIA %d at i/o %#x\n", i,
  98. (unsigned int) link->resource[0]->start);
  99. avma1cs_release(link);
  100. return -ENODEV;
  101. }
  102. link->priv = (void *) (unsigned long) i;
  103. return 0;
  104. } /* avma1cs_config */
  105. static void avma1cs_release(struct pcmcia_device *link)
  106. {
  107. unsigned long minor = (unsigned long) link->priv;
  108. dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
  109. /* now unregister function with hisax */
  110. HiSax_closecard(minor);
  111. pcmcia_disable_device(link);
  112. } /* avma1cs_release */
  113. static const struct pcmcia_device_id avma1cs_ids[] = {
  114. PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
  115. PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
  116. PCMCIA_DEVICE_NULL
  117. };
  118. MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
  119. static struct pcmcia_driver avma1cs_driver = {
  120. .owner = THIS_MODULE,
  121. .name = "avma1_cs",
  122. .probe = avma1cs_probe,
  123. .remove = avma1cs_detach,
  124. .id_table = avma1cs_ids,
  125. };
  126. module_pcmcia_driver(avma1cs_driver);