Path: blob/master/drivers/input/gameport/emu10k1-gp.c
17602 views
/*1* Copyright (c) 2001 Vojtech Pavlik2*/34/*5* EMU10k1 - SB Live / Audigy - gameport driver for Linux6*/78/*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA22*23* Should you need to contact me, the author, you can do so either by24* e-mail - mail your message to <[email protected]>, or by paper mail:25* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic26*/2728#include <asm/io.h>2930#include <linux/module.h>31#include <linux/ioport.h>32#include <linux/init.h>33#include <linux/gameport.h>34#include <linux/slab.h>35#include <linux/pci.h>3637MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");38MODULE_DESCRIPTION("EMU10k1 gameport driver");39MODULE_LICENSE("GPL");4041struct emu {42struct pci_dev *dev;43struct gameport *gameport;44int io;45int size;46};4748static const struct pci_device_id emu_tbl[] = {4950{ 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */51{ 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */52{ 0x1102, 0x7004, PCI_ANY_ID, PCI_ANY_ID }, /* Dell SB Live */53{ 0x1102, 0x7005, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy LS gameport */54{ 0, }55};5657MODULE_DEVICE_TABLE(pci, emu_tbl);5859static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)60{61struct emu *emu;62struct gameport *port;63int error;6465emu = kzalloc(sizeof(struct emu), GFP_KERNEL);66port = gameport_allocate_port();67if (!emu || !port) {68printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");69error = -ENOMEM;70goto err_out_free;71}7273error = pci_enable_device(pdev);74if (error)75goto err_out_free;7677emu->io = pci_resource_start(pdev, 0);78emu->size = pci_resource_len(pdev, 0);7980emu->dev = pdev;81emu->gameport = port;8283gameport_set_name(port, "EMU10K1");84gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));85port->dev.parent = &pdev->dev;86port->io = emu->io;8788if (!request_region(emu->io, emu->size, "emu10k1-gp")) {89printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n",90emu->io, emu->io + emu->size - 1);91error = -EBUSY;92goto err_out_disable_dev;93}9495pci_set_drvdata(pdev, emu);9697gameport_register_port(port);9899return 0;100101err_out_disable_dev:102pci_disable_device(pdev);103err_out_free:104gameport_free_port(port);105kfree(emu);106return error;107}108109static void __devexit emu_remove(struct pci_dev *pdev)110{111struct emu *emu = pci_get_drvdata(pdev);112113gameport_unregister_port(emu->gameport);114release_region(emu->io, emu->size);115kfree(emu);116117pci_disable_device(pdev);118}119120static struct pci_driver emu_driver = {121.name = "Emu10k1_gameport",122.id_table = emu_tbl,123.probe = emu_probe,124.remove = __devexit_p(emu_remove),125};126127static int __init emu_init(void)128{129return pci_register_driver(&emu_driver);130}131132static void __exit emu_exit(void)133{134pci_unregister_driver(&emu_driver);135}136137module_init(emu_init);138module_exit(emu_exit);139140141