parport_cs.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*======================================================================
  2. A driver for PCMCIA parallel port adapters
  3. (specifically, for the Quatech SPP-100 EPP card: other cards will
  4. probably require driver tweaks)
  5. parport_cs.c 1.29 2002/10/11 06:57:41
  6. The contents of this file are subject to the Mozilla Public
  7. License Version 1.1 (the "License"); you may not use this file
  8. except in compliance with the License. You may obtain a copy of
  9. the License at http://www.mozilla.org/MPL/
  10. Software distributed under the License is distributed on an "AS
  11. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  12. implied. See the License for the specific language governing
  13. rights and limitations under the License.
  14. The initial developer of the original code is David A. Hinds
  15. <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  16. are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  17. Alternatively, the contents of this file may be used under the
  18. terms of the GNU General Public License version 2 (the "GPL"), in
  19. which case the provisions of the GPL are applicable instead of the
  20. above. If you wish to allow the use of your version of this file
  21. only under the terms of the GPL and not to allow others to use
  22. your version of this file under the MPL, indicate your decision
  23. by deleting the provisions above and replace them with the notice
  24. and other provisions required by the GPL. If you do not delete
  25. the provisions above, a recipient may use your version of this
  26. file under either the MPL or the GPL.
  27. ======================================================================*/
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/init.h>
  31. #include <linux/ptrace.h>
  32. #include <linux/slab.h>
  33. #include <linux/string.h>
  34. #include <linux/timer.h>
  35. #include <linux/ioport.h>
  36. #include <linux/major.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/parport.h>
  39. #include <linux/parport_pc.h>
  40. #include <pcmcia/cistpl.h>
  41. #include <pcmcia/ds.h>
  42. #include <pcmcia/cisreg.h>
  43. #include <pcmcia/ciscode.h>
  44. /*====================================================================*/
  45. /* Module parameters */
  46. MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
  47. MODULE_DESCRIPTION("PCMCIA parallel port card driver");
  48. MODULE_LICENSE("Dual MPL/GPL");
  49. #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
  50. INT_MODULE_PARM(epp_mode, 1);
  51. /*====================================================================*/
  52. #define FORCE_EPP_MODE 0x08
  53. typedef struct parport_info_t {
  54. struct pcmcia_device *p_dev;
  55. int ndev;
  56. struct parport *port;
  57. } parport_info_t;
  58. static void parport_detach(struct pcmcia_device *p_dev);
  59. static int parport_config(struct pcmcia_device *link);
  60. static void parport_cs_release(struct pcmcia_device *);
  61. static int parport_probe(struct pcmcia_device *link)
  62. {
  63. parport_info_t *info;
  64. dev_dbg(&link->dev, "parport_attach()\n");
  65. /* Create new parport device */
  66. info = kzalloc(sizeof(*info), GFP_KERNEL);
  67. if (!info) return -ENOMEM;
  68. link->priv = info;
  69. info->p_dev = link;
  70. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  71. return parport_config(link);
  72. } /* parport_attach */
  73. static void parport_detach(struct pcmcia_device *link)
  74. {
  75. dev_dbg(&link->dev, "parport_detach\n");
  76. parport_cs_release(link);
  77. kfree(link->priv);
  78. } /* parport_detach */
  79. static int parport_config_check(struct pcmcia_device *p_dev, void *priv_data)
  80. {
  81. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  82. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
  83. p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
  84. p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
  85. return pcmcia_request_io(p_dev);
  86. }
  87. static int parport_config(struct pcmcia_device *link)
  88. {
  89. parport_info_t *info = link->priv;
  90. struct parport *p;
  91. int ret;
  92. dev_dbg(&link->dev, "parport_config\n");
  93. if (epp_mode)
  94. link->config_index |= FORCE_EPP_MODE;
  95. ret = pcmcia_loop_config(link, parport_config_check, NULL);
  96. if (ret)
  97. goto failed;
  98. if (!link->irq)
  99. goto failed;
  100. ret = pcmcia_enable_device(link);
  101. if (ret)
  102. goto failed;
  103. p = parport_pc_probe_port(link->resource[0]->start,
  104. link->resource[1]->start,
  105. link->irq, PARPORT_DMA_NONE,
  106. &link->dev, IRQF_SHARED);
  107. if (p == NULL) {
  108. printk(KERN_NOTICE "parport_cs: parport_pc_probe_port() at "
  109. "0x%3x, irq %u failed\n",
  110. (unsigned int) link->resource[0]->start,
  111. link->irq);
  112. goto failed;
  113. }
  114. p->modes |= PARPORT_MODE_PCSPP;
  115. if (epp_mode)
  116. p->modes |= PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP;
  117. info->ndev = 1;
  118. info->port = p;
  119. return 0;
  120. failed:
  121. parport_cs_release(link);
  122. return -ENODEV;
  123. } /* parport_config */
  124. static void parport_cs_release(struct pcmcia_device *link)
  125. {
  126. parport_info_t *info = link->priv;
  127. dev_dbg(&link->dev, "parport_release\n");
  128. if (info->ndev) {
  129. struct parport *p = info->port;
  130. parport_pc_unregister_port(p);
  131. }
  132. info->ndev = 0;
  133. pcmcia_disable_device(link);
  134. } /* parport_cs_release */
  135. static const struct pcmcia_device_id parport_ids[] = {
  136. PCMCIA_DEVICE_FUNC_ID(3),
  137. PCMCIA_MFC_DEVICE_PROD_ID12(1,"Elan","Serial+Parallel Port: SP230",0x3beb8cf2,0xdb9e58bc),
  138. PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0003),
  139. PCMCIA_DEVICE_NULL
  140. };
  141. MODULE_DEVICE_TABLE(pcmcia, parport_ids);
  142. static struct pcmcia_driver parport_cs_driver = {
  143. .owner = THIS_MODULE,
  144. .name = "parport_cs",
  145. .probe = parport_probe,
  146. .remove = parport_detach,
  147. .id_table = parport_ids,
  148. };
  149. module_pcmcia_driver(parport_cs_driver);