Add basic sysfs support to the slmodem drivers, so that udev can create /dev nodes. - Daniel Drake diff -urp slmodem-2.9.7/drivers/amrmo_init.c slmodem-dsd/drivers/amrmo_init.c --- slmodem-2.9.7/drivers/amrmo_init.c 2004-04-22 16:55:35.000000000 +0100 +++ slmodem-dsd/drivers/amrmo_init.c 2004-06-08 14:51:21.135016736 +0100 @@ -54,6 +54,7 @@ #include #include #include +#include #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) #define OLD_KERNEL 1 @@ -270,7 +271,7 @@ MODULE_DEVICE_TABLE (pci, amrmo_pci_tbl) static struct amrmo_struct *amrmo_table[MAXNUM] = {}; - +static struct class_simple *amrmo_class; /* * debug stuff @@ -613,6 +614,7 @@ static int __init amrmo_pci_probe(struct } #endif #else + class_simple_device_add(amrmo_class, MKDEV(AMRMO_MAJOR, i), NULL, "slamr%d", i); devfs_mk_cdev(MKDEV(AMRMO_MAJOR,i), S_IFCHR|S_IRUSR|S_IWUSR, "slamr%d", i); #endif return 0; @@ -644,6 +646,7 @@ static void __exit amrmo_pci_remove(stru } #endif #else + class_simple_device_remove(MKDEV(AMRMO_MAJOR, amrmo->num)); devfs_remove("slamr%d", amrmo->num); #endif amrmo_table[amrmo->num] = NULL; @@ -731,12 +734,24 @@ static int __init amrmo_init(void) pci_unregister_driver(&amrmo_pci_driver); return -ENOMEM; } +#ifndef OLD_KERNEL + amrmo_class = class_simple_create(THIS_MODULE, "slamr"); + if (IS_ERR(amrmo_class)) { + pci_unregister_driver(&amrmo_pci_driver); + unregister_chrdev(AMRMO_MAJOR, "slamr"); + return PTR_ERR(amrmo_class); + } +#endif + return 0; } static void __exit amrmo_exit(void) { AMRMO_DBG("slamr: exit...\n"); +#ifndef OLD_KERNEL + class_simple_destroy(amrmo_class); +#endif unregister_chrdev(AMRMO_MAJOR,"slamr"); pci_unregister_driver(&amrmo_pci_driver); } diff -urp slmodem-2.9.7/drivers/old_st7554.c slmodem-dsd/drivers/old_st7554.c --- slmodem-2.9.7/drivers/old_st7554.c 2004-01-25 14:20:28.000000000 +0000 +++ slmodem-dsd/drivers/old_st7554.c 2004-06-08 14:53:52.633985392 +0100 @@ -55,6 +55,7 @@ #include #include #include +#include #include @@ -73,6 +74,10 @@ #define MY_MAJOR 213 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) +#define OLD_KERNEL 1 +#endif + static int debug = 0; MODULE_PARM(debug,"i"); MODULE_PARM_DESC(debug,"Debug level: 0-3 (default=0)"); @@ -201,6 +206,7 @@ struct st7554_state { static struct st7554_state *st7554_table[MAX_MODEMS]; +static struct class_simple *st7554_class; static DECLARE_MUTEX(open_sem); @@ -1294,6 +1300,10 @@ static void *st7554_probe(struct usb_dev mo_free(s); mi_free(s); goto error1; } + +#ifndef OLD_KERNEL + class_simple_device_add(st7554_class, MKDEV(MY_MAJOR, s->minor), NULL, "slusb%d", i); +#endif #ifdef CONFIG_DEVFS_FS { char buf[8]; @@ -1328,6 +1338,10 @@ static void st7554_disconnect(struct usb s->file->private_data = NULL; s->file = NULL; } + +#ifndef OLD_KERNEL + class_simple_device_remove(MKDEV(MY_MAJOR, s->minor)); +#endif #ifdef CONFIG_DEVFS_FS { char buf[8]; @@ -1338,6 +1352,7 @@ static void st7554_disconnect(struct usb devfs_unregister (handle); } #endif + st7554_stop(s); st7554_release(s); s->usbdev = NULL; @@ -1366,6 +1381,17 @@ static int __init st7554_modem_init(void usb_deregister(&st7554_usb_driver); return -ENOMEM; } + +#ifndef OLD_KERNEL + st7554_class = class_simple_create(THIS_MODULE, "slusb"); + if (IS_ERR(st7554_class)) { + USB_ERR("failed to create sysfs class\n"); + usb_deregister(&st7554_usb_driver); + unregister_chrdev(MY_MAJOR, "slusb"); + return PTR_ERR(st7554_class); + } +#endif + return 0; } @@ -1373,6 +1399,9 @@ static int __init st7554_modem_init(void static void __exit st7554_modem_exit(void) { USB_DBG ("st7554: exit...\n"); +#ifndef OLD_KERNEL + class_simple_destroy(st7554_class); +#endif unregister_chrdev(MY_MAJOR,"slusb"); usb_deregister(&st7554_usb_driver); } diff -urp slmodem-2.9.7/drivers/st7554.c slmodem-dsd/drivers/st7554.c --- slmodem-2.9.7/drivers/st7554.c 2004-01-25 14:20:28.000000000 +0000 +++ slmodem-dsd/drivers/st7554.c 2004-06-08 14:59:11.296541320 +0100 @@ -55,6 +55,7 @@ #include #include #include +#include #include @@ -67,6 +68,10 @@ #define DEBUG_URB_PRINT 0 #define USB_DBG_URB(fmt...) // USB_DBG(fmt) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) +#define OLD_KERNEL 1 +#endif + static int debug = 0; MODULE_PARM(debug,"i"); MODULE_PARM_DESC(debug,"Debug level: 0-3 (default=0)"); @@ -205,6 +210,7 @@ struct st7554_state { static struct st7554_state *st7554_table[MAX_MODEMS] = {}; +static struct class_simple *st7554_class; static DECLARE_MUTEX(open_sem); @@ -1275,6 +1281,9 @@ static int st7554_probe(struct usb_inter } usb_set_intfdata(interface, s ); +#ifndef OLD_KERNEL + class_simple_device_add(st7554_class, MKDEV(213, i), NULL, "slusb%d", i); +#endif devfs_mk_cdev(MKDEV(213,i),S_IFCHR|S_IRUSR|S_IWUSR,"slusb%d",i); USB_INFO(KERN_INFO "slusb: slusb%d is found.\n", s->minor); @@ -1298,11 +1307,14 @@ static void st7554_disconnect(struct usb struct st7554_state *s = usb_get_intfdata(interface); usb_set_intfdata(interface, NULL ); USB_DBG("st7554 disconnect...\n"); - if (!s || !s->usbdev) { - USB_DBG("st7554 disconnect: no dev.\n"); - return; - } + if (!s || !s->usbdev) { + USB_DBG("st7554 disconnect: no dev.\n"); + return; + } +#ifndef OLD_KERNEL + class_simple_device_remove(MKDEV(213, s->minor)); +#endif devfs_remove("slusb%d",s->minor); st7554_stop(s); @@ -1344,6 +1356,16 @@ static int __init st7554_modem_init(void usb_deregister(&st7554_usb_driver); return -ENOMEM; } +#ifndef OLD_KERNEL + st7554_class = class_simple_create(THIS_MODULE, "slusb"); + if (IS_ERR(st7554_class)) { + USB_ERR("failed to create sysfs class\n"); + usb_deregister(&st7554_usb_driver); + unregister_chrdev(213, "slusb"); + return PTR_ERR(st7554_class); + } +#endif + return 0; } @@ -1351,6 +1373,9 @@ static int __init st7554_modem_init(void static void __exit st7554_modem_exit(void) { USB_DBG ("st7554: exit...\n"); +#ifndef OLD_KERNEL + class_simple_destroy(st7554_class); +#endif unregister_chrdev(213,"slusb"); usb_deregister(&st7554_usb_driver); }