Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  Copyright (c) 2001 Vojtech Pavlik
0004  */
0005 
0006 /*
0007  * EMU10k1 - SB Live / Audigy - gameport driver for Linux
0008  */
0009 
0010 /*
0011  */
0012 
0013 #include <asm/io.h>
0014 
0015 #include <linux/module.h>
0016 #include <linux/ioport.h>
0017 #include <linux/gameport.h>
0018 #include <linux/slab.h>
0019 #include <linux/pci.h>
0020 
0021 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
0022 MODULE_DESCRIPTION("EMU10k1 gameport driver");
0023 MODULE_LICENSE("GPL");
0024 
0025 struct emu {
0026     struct pci_dev *dev;
0027     struct gameport *gameport;
0028     int io;
0029     int size;
0030 };
0031 
0032 static const struct pci_device_id emu_tbl[] = {
0033 
0034     { 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */
0035     { 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */
0036     { 0x1102, 0x7004, PCI_ANY_ID, PCI_ANY_ID }, /* Dell SB Live */
0037     { 0x1102, 0x7005, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy LS gameport */
0038     { 0, }
0039 };
0040 
0041 MODULE_DEVICE_TABLE(pci, emu_tbl);
0042 
0043 static int emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
0044 {
0045     struct emu *emu;
0046     struct gameport *port;
0047     int error;
0048 
0049     emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
0050     port = gameport_allocate_port();
0051     if (!emu || !port) {
0052         printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
0053         error = -ENOMEM;
0054         goto err_out_free;
0055     }
0056 
0057     error = pci_enable_device(pdev);
0058     if (error)
0059         goto err_out_free;
0060 
0061     emu->io = pci_resource_start(pdev, 0);
0062     emu->size = pci_resource_len(pdev, 0);
0063 
0064     emu->dev = pdev;
0065     emu->gameport = port;
0066 
0067     gameport_set_name(port, "EMU10K1");
0068     gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
0069     port->dev.parent = &pdev->dev;
0070     port->io = emu->io;
0071 
0072     if (!request_region(emu->io, emu->size, "emu10k1-gp")) {
0073         printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n",
0074             emu->io, emu->io + emu->size - 1);
0075         error = -EBUSY;
0076         goto err_out_disable_dev;
0077     }
0078 
0079     pci_set_drvdata(pdev, emu);
0080 
0081     gameport_register_port(port);
0082 
0083     return 0;
0084 
0085  err_out_disable_dev:
0086     pci_disable_device(pdev);
0087  err_out_free:
0088     gameport_free_port(port);
0089     kfree(emu);
0090     return error;
0091 }
0092 
0093 static void emu_remove(struct pci_dev *pdev)
0094 {
0095     struct emu *emu = pci_get_drvdata(pdev);
0096 
0097     gameport_unregister_port(emu->gameport);
0098     release_region(emu->io, emu->size);
0099     kfree(emu);
0100 
0101     pci_disable_device(pdev);
0102 }
0103 
0104 static struct pci_driver emu_driver = {
0105         .name =         "Emu10k1_gameport",
0106         .id_table =     emu_tbl,
0107         .probe =        emu_probe,
0108     .remove =   emu_remove,
0109 };
0110 
0111 module_pci_driver(emu_driver);