diff options
author | Kristian Høgsberg <krh@redhat.com> | 2006-11-22 13:46:43 -0500 |
---|---|---|
committer | Kristian Høgsberg <krh@redhat.com> | 2006-11-22 13:46:43 -0500 |
commit | 0b44cc961ff699f5040806b240ec6c061f27a88d (patch) | |
tree | 5513e9d22476a6a7b4511cdb603f29ffc5acdce1 | |
parent | 37b3aa3f985bad56a582f007412d248e21d92816 (diff) |
Use a misc device instead.
-rw-r--r-- | nosy.c | 64 |
1 files changed, 18 insertions, 46 deletions
@@ -28,7 +28,7 @@ #include <linux/pci.h> #include <linux/fs.h> #include <linux/poll.h> -#include <linux/cdev.h> +#include <linux/miscdevice.h> #include <asm/byteorder.h> #include <asm/atomic.h> #include <asm/io.h> @@ -39,7 +39,6 @@ #include "nosy-user.h" #define PCI_DEVICE_ID_TI_PCILYNX 0x8000 -#define NOSY_MAJOR 177 #define notify(s, args...) printk(KERN_NOTICE s, ## args) #define error(s, args...) printk(KERN_ERR s, ## args) @@ -102,9 +101,7 @@ struct pcilynx { spinlock_t client_list_lock; struct list_head client_list; - struct class_device *class_device; - struct cdev char_device; - dev_t devno; + struct miscdevice misc; }; @@ -115,6 +112,9 @@ struct client { struct list_head link; }; +#define MAX_MINORS 64 +struct pcilynx *minors[MAX_MINORS]; + static int packet_buffer_init(struct packet_buffer *buffer, size_t capacity) { @@ -310,11 +310,12 @@ nosy_remove_client(struct client *client) static int nosy_open(struct inode *inode, struct file *file) { - struct pcilynx *lynx; + int minor = iminor(inode); - lynx = container_of(inode->i_cdev, struct pcilynx, char_device); - file->private_data = nosy_add_client(lynx); + if (minor > MAX_MINORS || minors[minor] == NULL) + return -ENODEV; + file->private_data = nosy_add_client(minors[minor]); if (file->private_data == NULL) return -ENOMEM; else @@ -395,11 +396,6 @@ static struct file_operations nosy_ops = { .release = nosy_release, }; -struct class nosy_class = { - .name = "nosy", - .release = NULL, -}; - #define PHY_PACKET_SIZE 12 /* 1 payload, 1 inverse, 1 ack = 3 quadlets */ struct link_packet { @@ -526,8 +522,8 @@ remove_card(struct pci_dev *dev) iounmap(lynx->registers); - class_device_unregister(lynx->class_device); - cdev_del(&lynx->char_device); + minors[lynx->misc.minor] = NULL; + misc_deregister(&lynx->misc); kfree(lynx); } @@ -631,21 +627,12 @@ add_card(struct pci_dev *dev, const struct pci_device_id *unused) if (request_irq(dev->irq, irq_handler, SA_SHIRQ, driver_name, lynx)) FAIL("Failed to allocate shared interrupt %d.", dev->irq); - err = alloc_chrdev_region(&lynx->devno, 0, 1, "nosy"); - if (err) - FAIL("Failed to register char device region."); - - cdev_init(&lynx->char_device, &nosy_ops); - lynx->char_device.owner = THIS_MODULE; - kobject_set_name(&lynx->char_device.kobj, "nosy"); - err = cdev_add(&lynx->char_device, lynx->devno, 1); - if (err) - FAIL("Failed to register char device."); - - lynx->class_device = class_device_create(&nosy_class, NULL, - lynx->devno, - &lynx->pci_device->dev, - (char *) driver_name); + lynx->misc.minor = MISC_DYNAMIC_MINOR; + lynx->misc.name = "nosy"; + lynx->misc.fops = &nosy_ops; + if (misc_register(&lynx->misc)) + FAIL("Failed to register misc char device."); + minors[lynx->misc.minor] = lynx; notify("Initialized PCILynx IEEE1394 card, irq=%d\n", dev->irq); @@ -676,29 +663,14 @@ MODULE_DEVICE_TABLE(pci, pci_table); static int __init nosy_init(void) { - int ret; - - ret = class_register(&nosy_class); - if (ret) { - error("Unable to register nosy class\n"); - return ret; - } - - ret = pci_register_driver(&lynx_pci_driver); - if (ret < 0) { - error("PCI module init failed\n"); - class_unregister(&nosy_class); - } - notify("Loaded %s version %s.\n", driver_name, VERSION); - return ret; + return pci_register_driver(&lynx_pci_driver); } static void __exit nosy_cleanup(void) { pci_unregister_driver(&lynx_pci_driver); - class_unregister(&nosy_class); notify("Unloaded %s.\n", driver_name); } |