Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2001 Vojtech Pavlik
4 */
5
6/*
7 * EMU10k1 - SB Live / Audigy - gameport driver for Linux
8 */
9
10/*
11 */
12
13#include <asm/io.h>
14
15#include <linux/module.h>
16#include <linux/ioport.h>
17#include <linux/gameport.h>
18#include <linux/slab.h>
19#include <linux/pci.h>
20
21MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
22MODULE_DESCRIPTION("EMU10k1 gameport driver");
23MODULE_LICENSE("GPL");
24
25struct emu {
26 struct pci_dev *dev;
27 struct gameport *gameport;
28 int io;
29 int size;
30};
31
32static const struct pci_device_id emu_tbl[] = {
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
41MODULE_DEVICE_TABLE(pci, emu_tbl);
42
43static int emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44{
45 struct emu *emu;
46 struct gameport *port;
47 int error;
48
49 emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
50 port = gameport_allocate_port();
51 if (!emu || !port) {
52 printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
53 error = -ENOMEM;
54 goto err_out_free;
55 }
56
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
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;
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 }
78
79 pci_set_drvdata(pdev, emu);
80
81 gameport_register_port(port);
82
83 return 0;
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;
91}
92
93static void emu_remove(struct pci_dev *pdev)
94{
95 struct emu *emu = pci_get_drvdata(pdev);
96
97 gameport_unregister_port(emu->gameport);
98 release_region(emu->io, emu->size);
99 kfree(emu);
100
101 pci_disable_device(pdev);
102}
103
104static struct pci_driver emu_driver = {
105 .name = "Emu10k1_gameport",
106 .id_table = emu_tbl,
107 .probe = emu_probe,
108 .remove = emu_remove,
109};
110
111module_pci_driver(emu_driver);
1/*
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>
33#include <linux/gameport.h>
34#include <linux/slab.h>
35#include <linux/pci.h>
36
37MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
38MODULE_DESCRIPTION("EMU10k1 gameport driver");
39MODULE_LICENSE("GPL");
40
41struct emu {
42 struct pci_dev *dev;
43 struct gameport *gameport;
44 int io;
45 int size;
46};
47
48static const struct pci_device_id emu_tbl[] = {
49
50 { 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};
56
57MODULE_DEVICE_TABLE(pci, emu_tbl);
58
59static int emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
60{
61 struct emu *emu;
62 struct gameport *port;
63 int error;
64
65 emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
66 port = gameport_allocate_port();
67 if (!emu || !port) {
68 printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
69 error = -ENOMEM;
70 goto err_out_free;
71 }
72
73 error = pci_enable_device(pdev);
74 if (error)
75 goto err_out_free;
76
77 emu->io = pci_resource_start(pdev, 0);
78 emu->size = pci_resource_len(pdev, 0);
79
80 emu->dev = pdev;
81 emu->gameport = port;
82
83 gameport_set_name(port, "EMU10K1");
84 gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
85 port->dev.parent = &pdev->dev;
86 port->io = emu->io;
87
88 if (!request_region(emu->io, emu->size, "emu10k1-gp")) {
89 printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n",
90 emu->io, emu->io + emu->size - 1);
91 error = -EBUSY;
92 goto err_out_disable_dev;
93 }
94
95 pci_set_drvdata(pdev, emu);
96
97 gameport_register_port(port);
98
99 return 0;
100
101 err_out_disable_dev:
102 pci_disable_device(pdev);
103 err_out_free:
104 gameport_free_port(port);
105 kfree(emu);
106 return error;
107}
108
109static void emu_remove(struct pci_dev *pdev)
110{
111 struct emu *emu = pci_get_drvdata(pdev);
112
113 gameport_unregister_port(emu->gameport);
114 release_region(emu->io, emu->size);
115 kfree(emu);
116
117 pci_disable_device(pdev);
118}
119
120static struct pci_driver emu_driver = {
121 .name = "Emu10k1_gameport",
122 .id_table = emu_tbl,
123 .probe = emu_probe,
124 .remove = emu_remove,
125};
126
127module_pci_driver(emu_driver);