Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright (c) 2001 Vojtech Pavlik |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * EMU10k1 - SB Live / Audigy - gameport driver for Linux |
| 8 | */ |
| 9 | |
| 10 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <asm/io.h> |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/gameport.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/pci.h> |
| 20 | |
| 21 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 22 | MODULE_DESCRIPTION("EMU10k1 gameport driver"); |
| 23 | MODULE_LICENSE("GPL"); |
| 24 | |
| 25 | struct emu { |
| 26 | struct pci_dev *dev; |
| 27 | struct gameport *gameport; |
| 28 | int io; |
| 29 | int size; |
| 30 | }; |
| 31 | |
Márton Németh | a9844b1 | 2010-01-09 23:23:58 -0800 | [diff] [blame] | 32 | static const struct pci_device_id emu_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | { 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */ |
| 35 | { 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */ |
| 36 | { 0x1102, 0x7004, PCI_ANY_ID, PCI_ANY_ID }, /* Dell SB Live */ |
| 37 | { 0x1102, 0x7005, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy LS gameport */ |
| 38 | { 0, } |
| 39 | }; |
| 40 | |
| 41 | MODULE_DEVICE_TABLE(pci, emu_tbl); |
| 42 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 43 | static int emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | struct emu *emu; |
| 46 | struct gameport *port; |
Dmitry Torokhov | 7aed3fb7 | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 47 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Pekka Enberg | a97e148 | 2005-09-06 15:18:33 -0700 | [diff] [blame] | 49 | emu = kzalloc(sizeof(struct emu), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | port = gameport_allocate_port(); |
| 51 | if (!emu || !port) { |
| 52 | printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n"); |
Dmitry Torokhov | 7aed3fb7 | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 53 | error = -ENOMEM; |
| 54 | goto err_out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Dmitry Torokhov | 7aed3fb7 | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 57 | error = pci_enable_device(pdev); |
| 58 | if (error) |
| 59 | goto err_out_free; |
| 60 | |
| 61 | emu->io = pci_resource_start(pdev, 0); |
| 62 | emu->size = pci_resource_len(pdev, 0); |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | emu->dev = pdev; |
| 65 | emu->gameport = port; |
| 66 | |
| 67 | gameport_set_name(port, "EMU10K1"); |
| 68 | gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev)); |
| 69 | port->dev.parent = &pdev->dev; |
Dmitry Torokhov | 7aed3fb7 | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 70 | port->io = emu->io; |
| 71 | |
| 72 | if (!request_region(emu->io, emu->size, "emu10k1-gp")) { |
| 73 | printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n", |
| 74 | emu->io, emu->io + emu->size - 1); |
| 75 | error = -EBUSY; |
| 76 | goto err_out_disable_dev; |
| 77 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | pci_set_drvdata(pdev, emu); |
| 80 | |
| 81 | gameport_register_port(port); |
| 82 | |
| 83 | return 0; |
Dmitry Torokhov | 7aed3fb7 | 2010-09-29 18:50:17 -0700 | [diff] [blame] | 84 | |
| 85 | err_out_disable_dev: |
| 86 | pci_disable_device(pdev); |
| 87 | err_out_free: |
| 88 | gameport_free_port(port); |
| 89 | kfree(emu); |
| 90 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 93 | static void emu_remove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
| 95 | struct emu *emu = pci_get_drvdata(pdev); |
| 96 | |
| 97 | gameport_unregister_port(emu->gameport); |
| 98 | release_region(emu->io, emu->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | kfree(emu); |
Dmitry Torokhov | d345d97 | 2010-09-29 18:17:16 -0700 | [diff] [blame] | 100 | |
| 101 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static struct pci_driver emu_driver = { |
| 105 | .name = "Emu10k1_gameport", |
| 106 | .id_table = emu_tbl, |
| 107 | .probe = emu_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 108 | .remove = emu_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Axel Lin | 5d06647 | 2012-04-21 23:37:53 -0700 | [diff] [blame] | 111 | module_pci_driver(emu_driver); |