Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (c) 2001 Vojtech Pavlik |
| 3 | */ |
| 4 | |
| 5 | /* |
| 6 | * EMU10k1 - SB Live / Audigy - gameport driver for Linux |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | * Should you need to contact me, the author, you can do so either by |
| 25 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: |
| 26 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic |
| 27 | */ |
| 28 | |
| 29 | #include <asm/io.h> |
| 30 | |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/init.h> |
| 34 | #include <linux/gameport.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/pci.h> |
| 37 | |
| 38 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 39 | MODULE_DESCRIPTION("EMU10k1 gameport driver"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
| 42 | struct emu { |
| 43 | struct pci_dev *dev; |
| 44 | struct gameport *gameport; |
| 45 | int io; |
| 46 | int size; |
| 47 | }; |
| 48 | |
Márton Németh | a9844b1 | 2010-01-09 23:23:58 -0800 | [diff] [blame] | 49 | static const struct pci_device_id emu_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | { 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */ |
| 52 | { 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */ |
| 53 | { 0x1102, 0x7004, PCI_ANY_ID, PCI_ANY_ID }, /* Dell SB Live */ |
| 54 | { 0x1102, 0x7005, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy LS gameport */ |
| 55 | { 0, } |
| 56 | }; |
| 57 | |
| 58 | MODULE_DEVICE_TABLE(pci, emu_tbl); |
| 59 | |
| 60 | static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 61 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | struct emu *emu; |
| 63 | struct gameport *port; |
Dmitry Torokhov | 7aed3fb | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 64 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Pekka Enberg | a97e148 | 2005-09-06 15:18:33 -0700 | [diff] [blame] | 66 | emu = kzalloc(sizeof(struct emu), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | port = gameport_allocate_port(); |
| 68 | if (!emu || !port) { |
| 69 | printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n"); |
Dmitry Torokhov | 7aed3fb | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 70 | error = -ENOMEM; |
| 71 | goto err_out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Dmitry Torokhov | 7aed3fb | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 74 | error = pci_enable_device(pdev); |
| 75 | if (error) |
| 76 | goto err_out_free; |
| 77 | |
| 78 | emu->io = pci_resource_start(pdev, 0); |
| 79 | emu->size = pci_resource_len(pdev, 0); |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | emu->dev = pdev; |
| 82 | emu->gameport = port; |
| 83 | |
| 84 | gameport_set_name(port, "EMU10K1"); |
| 85 | gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev)); |
| 86 | port->dev.parent = &pdev->dev; |
Dmitry Torokhov | 7aed3fb | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 87 | port->io = emu->io; |
| 88 | |
| 89 | if (!request_region(emu->io, emu->size, "emu10k1-gp")) { |
| 90 | printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n", |
| 91 | emu->io, emu->io + emu->size - 1); |
| 92 | error = -EBUSY; |
| 93 | goto err_out_disable_dev; |
| 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | pci_set_drvdata(pdev, emu); |
| 97 | |
| 98 | gameport_register_port(port); |
| 99 | |
| 100 | return 0; |
Dmitry Torokhov | 7aed3fb | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 101 | |
| 102 | err_out_disable_dev: |
| 103 | pci_disable_device(pdev); |
| 104 | err_out_free: |
| 105 | gameport_free_port(port); |
| 106 | kfree(emu); |
| 107 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static void __devexit emu_remove(struct pci_dev *pdev) |
| 111 | { |
| 112 | struct emu *emu = pci_get_drvdata(pdev); |
| 113 | |
| 114 | gameport_unregister_port(emu->gameport); |
| 115 | release_region(emu->io, emu->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | kfree(emu); |
Dmitry Torokhov | d345d97 | 2010-09-29 18:17:16 -0700 | [diff] [blame] | 117 | |
| 118 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static struct pci_driver emu_driver = { |
| 122 | .name = "Emu10k1_gameport", |
| 123 | .id_table = emu_tbl, |
| 124 | .probe = emu_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame^] | 125 | .remove = emu_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
Axel Lin | 5d06647 | 2012-04-21 23:37:53 -0700 | [diff] [blame] | 128 | module_pci_driver(emu_driver); |