16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/device.h>
19 #include <linux/pci.h>
21 #include <linux/poll.h>
24 #include <linux/slab.h>
26 #include <linux/sched.h>
32 #define PHANTOM_VERSION "n0.9.8"
34 #define PHANTOM_MAX_MINORS 8
36 #define PHN_IRQCTL 0x4c
42 static struct class *phantom_class;
43 static int phantom_major;
75 }
else if ((dev->
status & PHB_RUNNING) && !(newstat & PHB_RUNNING)) {
89 static long phantom_ioctl(
struct file *
file,
unsigned int cmd,
110 phantom_status(dev, dev->
status | PHB_RUNNING)){
111 spin_unlock_irqrestore(&dev->
regs_lock, flags);
115 pr_debug(
"phantom: writing %x to %u\n",
r.value,
r.reg);
128 phantom_status(dev, dev->
status & ~PHB_RUNNING);
129 spin_unlock_irqrestore(&dev->
regs_lock, flags);
136 pr_debug(
"phantom: SRS %u regs %x\n",
rs.count,
rs.mask);
142 for (i = 0; i <
m; i++)
143 if (
rs.mask &
BIT(i))
147 spin_unlock_irqrestore(&dev->
regs_lock, flags);
171 pr_debug(
"phantom: GRS %u regs %x\n",
rs.count,
rs.mask);
173 for (i = 0; i <
m; i++)
174 if (
rs.mask &
BIT(i))
177 spin_unlock_irqrestore(&dev->
regs_lock, flags);
184 if (dev->
status & PHB_RUNNING) {
186 "before you start the device!\n");
187 spin_unlock_irqrestore(&dev->
regs_lock, flags);
191 spin_unlock_irqrestore(&dev->
regs_lock, flags);
208 return phantom_ioctl(filp, cmd, (
unsigned long)compat_ptr(arg));
211 #define phantom_compat_ioctl NULL
214 static int phantom_open(
struct inode *
inode,
struct file *file)
244 static int phantom_release(
struct inode *
inode,
struct file *file)
251 phantom_status(dev, dev->
status & ~PHB_RUNNING);
259 static unsigned int phantom_poll(
struct file *file,
poll_table *
wait)
262 unsigned int mask = 0;
265 poll_wait(file, &dev->
wait, wait);
267 if (!(dev->
status & PHB_RUNNING))
278 .open = phantom_open,
279 .release = phantom_release,
280 .unlocked_ioctl = phantom_ioctl,
282 .poll = phantom_poll,
306 for (i = 0; i <
m; i++)
327 static unsigned int __devinit phantom_get_free(
void)
332 if (phantom_devices[i] == 0)
347 dev_err(&pdev->
dev,
"pci_enable_device failed!\n");
351 minor = phantom_get_free();
352 if (minor == PHANTOM_MAX_MINORS) {
353 dev_err(&pdev->
dev,
"too many devices found!\n");
358 phantom_devices[minor] = 1;
362 dev_err(&pdev->
dev,
"pci_request_regions failed!\n");
369 dev_err(&pdev->
dev,
"unable to allocate device\n");
373 pht->
caddr = pci_iomap(pdev, 0, 0);
375 dev_err(&pdev->
dev,
"can't remap conf space\n");
378 pht->
iaddr = pci_iomap(pdev, 2, 0);
380 dev_err(&pdev->
dev,
"can't remap input space\n");
383 pht->
oaddr = pci_iomap(pdev, 3, 0);
385 dev_err(&pdev->
dev,
"can't remap output space\n");
406 dev_err(&pdev->
dev,
"chardev registration failed\n");
412 "phantom%u", minor)))
415 pci_set_drvdata(pdev, pht);
431 phantom_devices[minor] = 0;
441 unsigned int minor =
MINOR(pht->
cdev.dev);
459 phantom_devices[minor] = 0;
486 #define phantom_suspend NULL
487 #define phantom_resume NULL
498 static struct pci_driver phantom_pci_driver = {
500 .id_table = phantom_pci_tbl,
501 .probe = phantom_probe,
509 static int __init phantom_init(
void)
515 if (IS_ERR(phantom_class)) {
516 retval = PTR_ERR(phantom_class);
531 phantom_major =
MAJOR(dev);
533 retval = pci_register_driver(&phantom_pci_driver);
553 static void __exit phantom_exit(
void)
562 pr_debug(
"phantom: module successfully removed\n");