OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [char/] [joystick/] [pcigame.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * $Id: pcigame.c,v 1.1.1.1 2004-04-15 02:03:30 phoenix Exp $
3
 *
4
 *  Copyright (c) 2000-2001 Vojtech Pavlik
5
 *
6
 *  Based on the work of:
7
 *      Raymond Ingles
8
 *
9
 *  Sponsored by SuSE
10
 */
11
 
12
/*
13
 * Trident 4DWave and Aureal Vortex gameport driver for Linux
14
 */
15
 
16
/*
17
 * This program is free software; you can redistribute it and/or modify
18
 * it under the terms of the GNU General Public License as published by
19
 * the Free Software Foundation; either version 2 of the License, or
20
 * (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
 *
31
 * Should you need to contact me, the author, you can do so either by
32
 * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
33
 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
34
 */
35
 
36
#include <asm/io.h>
37
#include <linux/delay.h>
38
#include <linux/errno.h>
39
#include <linux/ioport.h>
40
#include <linux/kernel.h>
41
#include <linux/module.h>
42
#include <linux/pci.h>
43
#include <linux/init.h>
44
#include <linux/slab.h>
45
#include <linux/gameport.h>
46
#include <linux/pci_gameport.h>
47
 
48
#define PCI_VENDOR_ID_AUREAL    0x12eb
49
 
50
#define PCIGAME_DATA_WAIT       20      /* 20 ms */
51
 
52
 
53
static struct pcigame_data pcigame_data[] __devinitdata = {
54
        { 0x00030, 0x00031, 0x00034, 2, 0xffff, 0x80 },
55
        { 0x1100c, 0x11008, 0x11010, 4, 0x1fff, 0x40 },
56
        { 0x2880c, 0x28808, 0x28810, 4, 0x1fff, 0x40 },
57
        { 0 }
58
};
59
 
60
static unsigned char pcigame_read(struct gameport *gameport)
61
{
62
        struct pcigame *pcigame = gameport->driver;
63
        return readb(pcigame->base + pcigame->data->legacy);
64
}
65
 
66
static void pcigame_trigger(struct gameport *gameport)
67
{
68
        struct pcigame *pcigame = gameport->driver;
69
        writeb(0xff, pcigame->base + pcigame->data->legacy);
70
}
71
 
72
static int pcigame_cooked_read(struct gameport *gameport, int *axes, int *buttons)
73
{
74
        struct pcigame *pcigame = gameport->driver;
75
        int i;
76
 
77
        *buttons = (~readb(pcigame->base + pcigame->data->legacy) >> 4) & 0xf;
78
 
79
        for (i = 0; i < 4; i++) {
80
                axes[i] = readw(pcigame->base + pcigame->data->axes + i * pcigame->data->axsize);
81
                if (axes[i] == pcigame->data->axmax) axes[i] = -1;
82
        }
83
 
84
        return 0;
85
}
86
 
87
static int pcigame_open(struct gameport *gameport, int mode)
88
{
89
        struct pcigame *pcigame = gameport->driver;
90
 
91
        switch (mode) {
92
                case GAMEPORT_MODE_COOKED:
93
                        writeb(pcigame->data->adcmode, pcigame->base + pcigame->data->gcr);
94
                        wait_ms(PCIGAME_DATA_WAIT);
95
                        return 0;
96
                case GAMEPORT_MODE_RAW:
97
                        writeb(0, pcigame->base + pcigame->data->gcr);
98
                        return 0;
99
                default:
100
                        return -1;
101
        }
102
 
103
        return 0;
104
}
105
 
106
struct pcigame *pcigame_attach(struct pci_dev *dev, int type)
107
{
108
        struct pcigame *pcigame;
109
        int i;
110
 
111
        if (!(pcigame = kmalloc(sizeof(struct pcigame), GFP_KERNEL)))
112
                return NULL;
113
        memset(pcigame, 0, sizeof(struct pcigame));
114
 
115
 
116
        pcigame->data = pcigame_data + type;
117
 
118
        pcigame->dev = dev;
119
 
120
        pcigame->gameport.driver = pcigame;
121
        pcigame->gameport.fuzz = 64;
122
 
123
        pcigame->gameport.read = pcigame_read;
124
        pcigame->gameport.trigger = pcigame_trigger;
125
        pcigame->gameport.cooked_read = pcigame_cooked_read;
126
        pcigame->gameport.open = pcigame_open;
127
 
128
        for (i = 0; i < 6; i++)
129
                if (~pci_resource_flags(dev, i) & IORESOURCE_IO)
130
                        break;
131
        if(i==6)
132
                return NULL;
133
 
134
        pci_enable_device(dev);
135
 
136
        pcigame->base = ioremap(pci_resource_start(pcigame->dev, i),
137
                                pci_resource_len(pcigame->dev, i));
138
 
139
        gameport_register_port(&pcigame->gameport);
140
 
141
        printk(KERN_INFO "gameport%d: %s at pci%02x:%02x.%x speed %d kHz\n",
142
                pcigame->gameport.number, dev->name, dev->bus->number,
143
                        PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), pcigame->gameport.speed);
144
 
145
        return pcigame;
146
}
147
 
148
EXPORT_SYMBOL_GPL(pcigame_attach);
149
 
150
 
151
void pcigame_detach(struct pcigame *game)
152
{
153
        gameport_unregister_port(&game->gameport);
154
        iounmap(game->base);
155
        kfree(game);
156
}
157
 
158
EXPORT_SYMBOL_GPL(pcigame_detach);
159
 
160
static __devinit int pcigame_probe(struct pci_dev *dev, const struct pci_device_id *id)
161
{
162
        struct pcigame *r = pcigame_attach(dev, id->driver_data);
163
        if(r == NULL)
164
                return -1;
165
        pci_set_drvdata(dev, r);
166
        return 0;
167
}
168
 
169
static void __devexit pcigame_remove(struct pci_dev *dev)
170
{
171
        struct pcigame *pcigame = pci_get_drvdata(dev);
172
        pcigame_detach(pcigame);
173
}
174
 
175
 
176
static struct pci_device_id pcigame_id_table[] __devinitdata =
177
{
178
/* If the trident is configured in audio grabs it and we get called by
179
   that */
180
#if !defined(CONFIG_SOUND_TRIDENT) && !defined(CONFIG_SOUND_TRIDENT_MODULE)
181
 { PCI_VENDOR_ID_TRIDENT, 0x2000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCIGAME_4DWAVE  },
182
 { PCI_VENDOR_ID_TRIDENT, 0x2001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCIGAME_4DWAVE  },
183
 { PCI_VENDOR_ID_AL,      0x5451, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCIGAME_4DWAVE  },
184
#endif 
185
 { PCI_VENDOR_ID_AUREAL,  0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCIGAME_VORTEX  },
186
 { PCI_VENDOR_ID_AUREAL,  0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCIGAME_VORTEX2 },
187
 { 0 }};
188
 
189
static struct pci_driver pcigame_driver = {
190
        name:           "pcigame",
191
        id_table:       pcigame_id_table,
192
        probe:          pcigame_probe,
193
        remove:         __devexit_p(pcigame_remove),
194
};
195
 
196
int __init pcigame_init(void)
197
{
198
        pci_register_driver(&pcigame_driver);
199
        /* Needed by other modules */
200
        return 0;
201
}
202
 
203
void __exit pcigame_exit(void)
204
{
205
        pci_unregister_driver(&pcigame_driver);
206
}
207
 
208
module_init(pcigame_init);
209
module_exit(pcigame_exit);
210
 
211
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.