emu10k1-gp.c 3.0 KB

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