diff options
author | Javier Martinez Canillas <martinez.javier@gmail.com> | 2010-11-27 07:49:17 +0100 |
---|---|---|
committer | Javier Martinez Canillas <martinez.javier@gmail.com> | 2010-11-27 07:49:17 +0100 |
commit | ab121f379a3cff458c90e6f480ba4bb68c8733dd (patch) | |
tree | a9851af109ee83646d108bc247d03b131461b764 /pci/pci_skel.c | |
download | ldd3-ab121f379a3cff458c90e6f480ba4bb68c8733dd.tar.gz |
Linux Device Drivers 3 examples
Diffstat (limited to 'pci/pci_skel.c')
-rw-r--r-- | pci/pci_skel.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/pci/pci_skel.c b/pci/pci_skel.c new file mode 100644 index 0000000..f115669 --- /dev/null +++ b/pci/pci_skel.c @@ -0,0 +1,63 @@ +#include <linux/config.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/init.h> + + +static struct pci_device_id ids[] = { + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3), }, + { 0, } +}; +MODULE_DEVICE_TABLE(pci, ids); + +static unsigned char skel_get_revision(struct pci_dev *dev) +{ + u8 revision; + + pci_read_config_byte(dev, PCI_REVISION_ID, &revision); + return revision; +} + +static int probe(struct pci_dev *dev, const struct pci_device_id *id) +{ + /* Do probing type stuff here. + * Like calling request_region(); + */ + pci_enable_device(dev); + + if (skel_get_revision(dev) == 0x42) + return -ENODEV; + + + return 0; +} + +static void remove(struct pci_dev *dev) +{ + /* clean up any allocated resources and stuff here. + * like call release_region(); + */ +} + +static struct pci_driver pci_driver = { + .name = "pci_skel", + .id_table = ids, + .probe = probe, + .remove = remove, +}; + +static int __init pci_skel_init(void) +{ + return pci_register_driver(&pci_driver); +} + +static void __exit pci_skel_exit(void) +{ + pci_unregister_driver(&pci_driver); +} + +MODULE_LICENSE("GPL"); + +module_init(pci_skel_init); +module_exit(pci_skel_exit); |