emu10k1-gp.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/gameport.h>
  30. #include <linux/slab.h>
  31. #include <linux/pci.h>
  32. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  33. MODULE_DESCRIPTION("EMU10k1 gameport driver");
  34. MODULE_LICENSE("GPL");
  35. struct emu {
  36. struct pci_dev *dev;
  37. struct gameport *gameport;
  38. int io;
  39. int size;
  40. };
  41. static const struct pci_device_id emu_tbl[] = {
  42. { 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */
  43. { 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */
  44. { 0x1102, 0x7004, PCI_ANY_ID, PCI_ANY_ID }, /* Dell SB Live */
  45. { 0x1102, 0x7005, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy LS gameport */
  46. { 0, }
  47. };
  48. MODULE_DEVICE_TABLE(pci, emu_tbl);
  49. static int emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  50. {
  51. struct emu *emu;
  52. struct gameport *port;
  53. int error;
  54. emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
  55. port = gameport_allocate_port();
  56. if (!emu || !port) {
  57. printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
  58. error = -ENOMEM;
  59. goto err_out_free;
  60. }
  61. error = pci_enable_device(pdev);
  62. if (error)
  63. goto err_out_free;
  64. emu->io = pci_resource_start(pdev, 0);
  65. emu->size = pci_resource_len(pdev, 0);
  66. emu->dev = pdev;
  67. emu->gameport = port;
  68. gameport_set_name(port, "EMU10K1");
  69. gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
  70. port->dev.parent = &pdev->dev;
  71. port->io = emu->io;
  72. if (!request_region(emu->io, emu->size, "emu10k1-gp")) {
  73. printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n",
  74. emu->io, emu->io + emu->size - 1);
  75. error = -EBUSY;
  76. goto err_out_disable_dev;
  77. }
  78. pci_set_drvdata(pdev, emu);
  79. gameport_register_port(port);
  80. return 0;
  81. err_out_disable_dev:
  82. pci_disable_device(pdev);
  83. err_out_free:
  84. gameport_free_port(port);
  85. kfree(emu);
  86. return error;
  87. }
  88. static void emu_remove(struct pci_dev *pdev)
  89. {
  90. struct emu *emu = pci_get_drvdata(pdev);
  91. gameport_unregister_port(emu->gameport);
  92. release_region(emu->io, emu->size);
  93. kfree(emu);
  94. pci_disable_device(pdev);
  95. }
  96. static struct pci_driver emu_driver = {
  97. .name = "Emu10k1_gameport",
  98. .id_table = emu_tbl,
  99. .probe = emu_probe,
  100. .remove = emu_remove,
  101. };
  102. module_pci_driver(emu_driver);