emu10k1-gp.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2001 Vojtech Pavlik
  3. */
  4. /*
  5. * EMU10k1 - SB Live / Audigy - gameport driver for Linux
  6. */
  7. /*
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * Should you need to contact me, the author, you can do so either by
  23. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  24. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  25. */
  26. #include <asm/io.h>
  27. #include <linux/module.h>
  28. #include <linux/ioport.h>
  29. #include <linux/init.h>
  30. #include <linux/gameport.h>
  31. #include <linux/slab.h>
  32. #include <linux/pci.h>
  33. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  34. MODULE_DESCRIPTION("EMU10k1 gameport driver");
  35. MODULE_LICENSE("GPL");
  36. struct emu {
  37. struct pci_dev *dev;
  38. struct gameport *gameport;
  39. int io;
  40. int size;
  41. };
  42. static struct pci_device_id emu_tbl[] = {
  43. { 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */
  44. { 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */
  45. { 0x1102, 0x7004, PCI_ANY_ID, PCI_ANY_ID }, /* Dell SB Live */
  46. { 0x1102, 0x7005, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy LS gameport */
  47. { 0, }
  48. };
  49. MODULE_DEVICE_TABLE(pci, emu_tbl);
  50. static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  51. {
  52. int ioport, iolen;
  53. struct emu *emu;
  54. struct gameport *port;
  55. if (pci_enable_device(pdev))
  56. return -EBUSY;
  57. ioport = pci_resource_start(pdev, 0);
  58. iolen = pci_resource_len(pdev, 0);
  59. if (!request_region(ioport, iolen, "emu10k1-gp"))
  60. return -EBUSY;
  61. emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
  62. port = gameport_allocate_port();
  63. if (!emu || !port) {
  64. printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
  65. release_region(ioport, iolen);
  66. kfree(emu);
  67. gameport_free_port(port);
  68. return -ENOMEM;
  69. }
  70. emu->io = ioport;
  71. emu->size = iolen;
  72. emu->dev = pdev;
  73. emu->gameport = port;
  74. gameport_set_name(port, "EMU10K1");
  75. gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
  76. port->dev.parent = &pdev->dev;
  77. port->io = ioport;
  78. pci_set_drvdata(pdev, emu);
  79. gameport_register_port(port);
  80. return 0;
  81. }
  82. static void __devexit emu_remove(struct pci_dev *pdev)
  83. {
  84. struct emu *emu = pci_get_drvdata(pdev);
  85. gameport_unregister_port(emu->gameport);
  86. release_region(emu->io, emu->size);
  87. kfree(emu);
  88. }
  89. static struct pci_driver emu_driver = {
  90. .name = "Emu10k1_gameport",
  91. .id_table = emu_tbl,
  92. .probe = emu_probe,
  93. .remove = __devexit_p(emu_remove),
  94. };
  95. static int __init emu_init(void)
  96. {
  97. return pci_register_driver(&emu_driver);
  98. }
  99. static void __exit emu_exit(void)
  100. {
  101. pci_unregister_driver(&emu_driver);
  102. }
  103. module_init(emu_init);
  104. module_exit(emu_exit);