emu10k1-gp.c 3.3 KB

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