emu10k1-gp.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 const 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. struct emu *emu;
  53. struct gameport *port;
  54. int error;
  55. emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
  56. port = gameport_allocate_port();
  57. if (!emu || !port) {
  58. printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
  59. error = -ENOMEM;
  60. goto err_out_free;
  61. }
  62. error = pci_enable_device(pdev);
  63. if (error)
  64. goto err_out_free;
  65. emu->io = pci_resource_start(pdev, 0);
  66. emu->size = pci_resource_len(pdev, 0);
  67. emu->dev = pdev;
  68. emu->gameport = port;
  69. gameport_set_name(port, "EMU10K1");
  70. gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
  71. port->dev.parent = &pdev->dev;
  72. port->io = emu->io;
  73. if (!request_region(emu->io, emu->size, "emu10k1-gp")) {
  74. printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n",
  75. emu->io, emu->io + emu->size - 1);
  76. error = -EBUSY;
  77. goto err_out_disable_dev;
  78. }
  79. pci_set_drvdata(pdev, emu);
  80. gameport_register_port(port);
  81. return 0;
  82. err_out_disable_dev:
  83. pci_disable_device(pdev);
  84. err_out_free:
  85. gameport_free_port(port);
  86. kfree(emu);
  87. return error;
  88. }
  89. static void __devexit emu_remove(struct pci_dev *pdev)
  90. {
  91. struct emu *emu = pci_get_drvdata(pdev);
  92. gameport_unregister_port(emu->gameport);
  93. release_region(emu->io, emu->size);
  94. kfree(emu);
  95. pci_disable_device(pdev);
  96. }
  97. static struct pci_driver emu_driver = {
  98. .name = "Emu10k1_gameport",
  99. .id_table = emu_tbl,
  100. .probe = emu_probe,
  101. .remove = __devexit_p(emu_remove),
  102. };
  103. static int __init emu_init(void)
  104. {
  105. return pci_register_driver(&emu_driver);
  106. }
  107. static void __exit emu_exit(void)
  108. {
  109. pci_unregister_driver(&emu_driver);
  110. }
  111. module_init(emu_init);
  112. module_exit(emu_exit);