diff options
Diffstat (limited to 'kernel-devel/module-basics/vain_pci/vain_pci_orig.c')
| -rw-r--r-- | kernel-devel/module-basics/vain_pci/vain_pci_orig.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/kernel-devel/module-basics/vain_pci/vain_pci_orig.c b/kernel-devel/module-basics/vain_pci/vain_pci_orig.c new file mode 100644 index 0000000..d84a54e --- /dev/null +++ b/kernel-devel/module-basics/vain_pci/vain_pci_orig.c @@ -0,0 +1,114 @@ +#include <linux/init.h> +#include <linux/module.h> +#include <linux/pci.h> + +#define PCI_VENDOR_ID_ILLEGAL_VENDOR 0xffff +#define PCI_DEVICE_ID_ILLEGAL_VENDOR_DEVICE 0x2342 + +struct vain_pci_info { + void __iomem *base; + struct pci_dev *pdev; + spinlock_t lock; +}; + +static struct pci_device_id vain_pci_ids[] __devinitdata = { + {PCI_VENDOR_ID_ILLEGAL_VENDOR, PCI_DEVICE_ID_ILLEGAL_VENDOR_DEVICE, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, + {0, } +}; +MODULE_DEVICE_TABLE(pci, vain_pci_ids); + +static int __devinit vain_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *ent) +{ + struct vain_pci_info *info; + int ret; + + dev_dbg(&pdev->dev, "Init, new card found\n"); + + info = kzalloc(sizeof(struct vain_pci_info), GFP_KERNEL); + if (unlikely(!info)) { + dev_err(&pdev->dev, "Could not allocate memory\n"); + ret = -ENOMEM; + goto err_free; + } + + info->pdev = pdev; + + ret = pci_enable_device(pdev); + if (ret) { + dev_err(&pdev->dev, "Failed to enable PCI Device\n"); + goto err_free; + } + + ret = pci_request_regions(pdev, "vain_pci"); + if (ret) { + dev_err(&pdev->dev, "I/O address 0x%04x already in use\n", + (int) /* nozomi_private.io_addr */ 0); + goto err_disable_device; + } + + info->base = pci_ioremap_bar(pdev, 0); + if (!info->base) { + dev_err(&pdev->dev, "Unable to map card MMIO\n"); + ret = -ENODEV; + goto err_rel_regs; + } + + pci_set_drvdata(pdev, info); + + return 0; + +err_rel_regs: + pci_release_regions(pdev); +err_disable_device: + pci_disable_device(pdev); +err_free: + kfree(info); + + return ret; +} + +static void __devexit vain_pci_remove(struct pci_dev *pdev) +{ + struct vain_pci_info *info = pci_get_drvdata(pdev); + + iounmap(info->base); + pci_release_regions(pdev); + pci_disable_device(pdev); + pci_set_drvdata(pdev, NULL); + + kfree (info); +} + +static struct pci_driver vain_pci_driver = { + .name = "vain_pci", + .id_table = vain_pci_ids, + .probe = vain_pci_probe, + .remove = __devexit_p(vain_pci_remove), +}; + +static int vain_pci_init(void) +{ + int err; + + err = pci_register_driver(&vain_pci_driver); + + if (!err) + printk(KERN_INFO "vain_pci_init: done\n"); + return err; +} + +static void vain_pci_exit(void) +{ + pci_unregister_driver(&vain_pci_driver); + printk(KERN_INFO "vain_pci_exit: done\n"); +} + +module_init(vain_pci_init); +module_exit(vain_pci_exit); + +MODULE_AUTHOR("Benedikt Spranger <b.spranger@linutronix.de>"); +MODULE_DESCRIPTION("a more or less useless PCI module"); +MODULE_LICENSE("GPL v2"); +MODULE_VERSION("0815"); |
