emu10k1-gp.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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