vortex.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * $Id: vortex.c,v 1.5 2002/07/01 15:39:30 vojtech Exp $
  3. *
  4. * Copyright (c) 2000-2001 Vojtech Pavlik
  5. *
  6. * Based on the work of:
  7. * Raymond Ingles
  8. */
  9. /*
  10. * Trident 4DWave and Aureal Vortex gameport driver for Linux
  11. */
  12. /*
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. *
  27. * Should you need to contact me, the author, you can do so either by
  28. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  29. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  30. */
  31. #include <asm/io.h>
  32. #include <linux/delay.h>
  33. #include <linux/errno.h>
  34. #include <linux/ioport.h>
  35. #include <linux/kernel.h>
  36. #include <linux/module.h>
  37. #include <linux/pci.h>
  38. #include <linux/init.h>
  39. #include <linux/slab.h>
  40. #include <linux/delay.h>
  41. #include <linux/gameport.h>
  42. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  43. MODULE_DESCRIPTION("Aureal Vortex and Vortex2 gameport driver");
  44. MODULE_LICENSE("GPL");
  45. #define VORTEX_GCR 0x0c /* Gameport control register */
  46. #define VORTEX_LEG 0x08 /* Legacy port location */
  47. #define VORTEX_AXD 0x10 /* Axes start */
  48. #define VORTEX_DATA_WAIT 20 /* 20 ms */
  49. struct vortex {
  50. struct gameport *gameport;
  51. struct pci_dev *dev;
  52. unsigned char __iomem *base;
  53. unsigned char __iomem *io;
  54. };
  55. static unsigned char vortex_read(struct gameport *gameport)
  56. {
  57. struct vortex *vortex = gameport->port_data;
  58. return readb(vortex->io + VORTEX_LEG);
  59. }
  60. static void vortex_trigger(struct gameport *gameport)
  61. {
  62. struct vortex *vortex = gameport->port_data;
  63. writeb(0xff, vortex->io + VORTEX_LEG);
  64. }
  65. static int vortex_cooked_read(struct gameport *gameport, int *axes, int *buttons)
  66. {
  67. struct vortex *vortex = gameport->port_data;
  68. int i;
  69. *buttons = (~readb(vortex->base + VORTEX_LEG) >> 4) & 0xf;
  70. for (i = 0; i < 4; i++) {
  71. axes[i] = readw(vortex->io + VORTEX_AXD + i * sizeof(u32));
  72. if (axes[i] == 0x1fff) axes[i] = -1;
  73. }
  74. return 0;
  75. }
  76. static int vortex_open(struct gameport *gameport, int mode)
  77. {
  78. struct vortex *vortex = gameport->port_data;
  79. switch (mode) {
  80. case GAMEPORT_MODE_COOKED:
  81. writeb(0x40, vortex->io + VORTEX_GCR);
  82. msleep(VORTEX_DATA_WAIT);
  83. return 0;
  84. case GAMEPORT_MODE_RAW:
  85. writeb(0x00, vortex->io + VORTEX_GCR);
  86. return 0;
  87. default:
  88. return -1;
  89. }
  90. return 0;
  91. }
  92. static int __devinit vortex_probe(struct pci_dev *dev, const struct pci_device_id *id)
  93. {
  94. struct vortex *vortex;
  95. struct gameport *port;
  96. int i;
  97. vortex = kcalloc(1, sizeof(struct vortex), GFP_KERNEL);
  98. port = gameport_allocate_port();
  99. if (!vortex || !port) {
  100. printk(KERN_ERR "vortex: Memory allocation failed.\n");
  101. kfree(vortex);
  102. gameport_free_port(port);
  103. return -ENOMEM;
  104. }
  105. for (i = 0; i < 6; i++)
  106. if (~pci_resource_flags(dev, i) & IORESOURCE_IO)
  107. break;
  108. pci_enable_device(dev);
  109. vortex->dev = dev;
  110. vortex->gameport = port;
  111. vortex->base = ioremap(pci_resource_start(vortex->dev, i),
  112. pci_resource_len(vortex->dev, i));
  113. vortex->io = vortex->base + id->driver_data;
  114. pci_set_drvdata(dev, vortex);
  115. port->port_data = vortex;
  116. port->fuzz = 64;
  117. gameport_set_name(port, "AU88x0");
  118. gameport_set_phys(port, "pci%s/gameport0", pci_name(dev));
  119. port->dev.parent = &dev->dev;
  120. port->read = vortex_read;
  121. port->trigger = vortex_trigger;
  122. port->cooked_read = vortex_cooked_read;
  123. port->open = vortex_open;
  124. gameport_register_port(port);
  125. return 0;
  126. }
  127. static void __devexit vortex_remove(struct pci_dev *dev)
  128. {
  129. struct vortex *vortex = pci_get_drvdata(dev);
  130. gameport_unregister_port(vortex->gameport);
  131. iounmap(vortex->base);
  132. kfree(vortex);
  133. }
  134. static struct pci_device_id vortex_id_table[] = {
  135. { 0x12eb, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x11000 },
  136. { 0x12eb, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x28800 },
  137. { 0 }
  138. };
  139. static struct pci_driver vortex_driver = {
  140. .name = "vortex_gameport",
  141. .id_table = vortex_id_table,
  142. .probe = vortex_probe,
  143. .remove = __devexit_p(vortex_remove),
  144. };
  145. static int __init vortex_init(void)
  146. {
  147. return pci_register_driver(&vortex_driver);
  148. }
  149. static void __exit vortex_exit(void)
  150. {
  151. pci_unregister_driver(&vortex_driver);
  152. }
  153. module_init(vortex_init);
  154. module_exit(vortex_exit);