Char: istallion, fix enabling
PATCH 1/5 Char: istallion, fix enabling
istallion, fix enabling
Enable ISA cards before pci_register_driver and then, enable each PCI card in probe function.
---
commit 2f1c6f8998c724f6b323dfc913a650f26cc02efa
tree b03b4c776ba221373f755c5970a8dd41e8796ce7
parent d58848fe07c13a82e9d429d481f9677857e73019
author Jiri Slaby <[email protected]> Sat, 11 Nov 2006 01:38:17 +0100 committer Jiri Slaby <[email protected]> Sat, 11 Nov 2006 22:23:16 +0100
drivers/char/istallion.c | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-)
drivers/char/istallion.c +11 -7
@@ -3968,6 +3968,10 @@ static int __devinit stli_pciprobe(struc brdp->state |=BST_PROBED ;pci_set_drvdata (pdev, brdp); +EBRDENABLE (brdp); + brdp->enable =NULL ; + brdp->disable =NULL ; +return 0 ; err_null: stli_brds[brdp->brdnr] =NULL ;
@@ -4054,13 +4058,6 @@ static int stli_initbrds(void)if (retval >0 ) found += retval; - retval =pci_register_driver (&stli_pcidriver); -if (retval && found ==0 ) { -printk (KERN_ERR "Neither isa nor eisa cards found nor pci " -"driver can be registered!\n" ); - goto err; - } -/* * All found boards are initialized. Now for a little optimization, if * no boards are sharing the "shared memory" regions then we can just
@@ -4099,6 +4096,13 @@ static int stli_initbrds(void) } } + retval =pci_register_driver (&stli_pcidriver); +if (retval && found ==0 ) { +printk (KERN_ERR "Neither isa nor eisa cards found nor pci " +"driver can be registered!\n" ); + goto err; + } +return 0 ; err:return retval;
PATCH 2/5 Char: istallion, move init and exit code
istallion, move init and exit code
Let's have these function at the end of the driver and expand stli_init directly into module_init fucntion, since there is nothing other to have there.
---
commit d804883791d787b9c0bc0b79ccec78d0d20d850d
tree 8b3975ffcc507aeab7081767816ce66f191ce653
parent 2f1c6f8998c724f6b323dfc913a650f26cc02efa
author Jiri Slaby <[email protected]> Sat, 11 Nov 2006 01:41:37 +0100 committer Jiri Slaby <[email protected]> Sat, 11 Nov 2006 22:23:34 +0100
drivers/char/istallion.c | 113 +++++++++++++++++++++------------------------- 1 files changed, 52 insertions(+), 61 deletions(-)
drivers/char/istallion.c +52 -61
@@ -595,7 +595,6 @@ #define MINOR2PORT(min) ((min) & 0x3f)*/ static int stli_parsebrd (struct stlconf *confp,char **argp); -static int stli_init (void );static int stli_open (struct tty_struct *tty,struct file *filp);static void stli_close (struct tty_struct *tty,struct file *filp);static int stli_write (struct tty_struct *tty,const unsigned char *buf,int count);
@@ -744,65 +743,6 @@ static void stli_cleanup_ports(struct st } } -/* -* Loadable module initialization stuff. -*/ - -static int __init istallion_module_init (void ) -{ -stli_init (); -return 0 ; -} - -/*****************************************************************************/ - -static void __exit istallion_module_exit(void) -{ -struct stlibrd *brdp; -unsigned int j; -int i; - -printk (KERN_INFO "Unloading %s: version %s\n" , stli_drvtitle, - stli_drvversion); - -pci_unregister_driver (&stli_pcidriver); -/* -* Free up all allocated resources used by the ports. This includes -* memory and interrupts. -*/ -if (stli_timeron) { - stli_timeron =0 ; -del_timer_sync (&stli_timerlist); - } - - i =tty_unregister_driver (stli_serial); -put_tty_driver (stli_serial); -for (j =0 ; j <4 ; j++) -class_device_destroy (istallion_class,MKDEV (STL_SIOMEMMAJOR , j)); -class_destroy (istallion_class); -if ((i =unregister_chrdev (STL_SIOMEMMAJOR ,"staliomem" ))) -printk ("STALLION: failed to un-register serial memory device, " -"errno=%d\n" , -i); - -kfree (stli_txcookbuf); - -for (j =0 ; (j < stli_nrbrds); j++) { -if ((brdp = stli_brds[j]) ==NULL || (brdp->state &BST_PROBED )) -continue ; - -stli_cleanup_ports (brdp); - -iounmap (brdp->membase); -if (brdp->iosize >0 ) -release_region (brdp->iobase, brdp->iosize); -kfree (brdp); - stli_brds[j] =NULL ; - } -} - -module_init (istallion_module_init); -module_exit (istallion_module_exit); -/*****************************************************************************/ /*
@@ -4601,10 +4541,14 @@ static const struct tty_operations stli_ };/*****************************************************************************/ +/* +* Loadable module initialization stuff. +*/ -static int __init stli_init (void ) +static int __init istallion_module_init (void ) {int i; +printk (KERN_INFO "%s: version %s\n" , stli_drvtitle, stli_drvversion);spin_lock_init (&stli_lock);
@@ -4661,3 +4605,50 @@ static int __init stli_init(void) }/*****************************************************************************/ + +static void __exit istallion_module_exit(void) +{ +struct stlibrd *brdp; +unsigned int j; +int i; + +printk (KERN_INFO "Unloading %s: version %s\n" , stli_drvtitle, + stli_drvversion); + +pci_unregister_driver (&stli_pcidriver); +/* +* Free up all allocated resources used by the ports. This includes +* memory and interrupts. +*/ +if (stli_timeron) { + stli_timeron =0 ; +del_timer_sync (&stli_timerlist); + } + + i =tty_unregister_driver (stli_serial); +put_tty_driver (stli_serial); +for (j =0 ; j <4 ; j++) +class_device_destroy (istallion_class,MKDEV (STL_SIOMEMMAJOR , j)); +class_destroy (istallion_class); +if ((i =unregister_chrdev (STL_SIOMEMMAJOR ,"staliomem" ))) +printk ("STALLION: failed to un-register serial memory device, " +"errno=%d\n" , -i); + +kfree (stli_txcookbuf); + +for (j =0 ; (j < stli_nrbrds); j++) { +if ((brdp = stli_brds[j]) ==NULL || (brdp->state &BST_PROBED )) +continue ; + +stli_cleanup_ports (brdp); + +iounmap (brdp->membase); +if (brdp->iosize >0 ) +release_region (brdp->iobase, brdp->iosize); +kfree (brdp); + stli_brds[j] =NULL ; + } +} + +module_init (istallion_module_init); +module_exit (istallion_module_exit);
PATCH 3/5 Char: istallion, change init sequence
In reply to Jiri Slabyistallion, change init sequence
Reorganizate module init and exit and implement logic, when something fails in these functions. The former is needed for proper handling dynamic tty_register_device.
---
commit 92452a22c4ada362e991cbf0de84c8914525672a
tree 6e6dc05ce30f3cf7f159842136f96b2009dbbaa1
parent d804883791d787b9c0bc0b79ccec78d0d20d850d
author Jiri Slaby <[email protected]> Sat, 11 Nov 2006 02:17:14 +0100 committer Jiri Slaby <[email protected]> Sat, 11 Nov 2006 22:23:35 +0100
drivers/char/istallion.c | 130 +++++++++++++++++++++++++++------------------- 1 files changed, 75 insertions(+), 55 deletions(-)
drivers/char/istallion.c +75 -55
@@ -4545,46 +4545,49 @@ static const struct tty_operations stli_* Loadable module initialization stuff. */ +static void istallion_cleanup_isa (void ) +{ +struct stlibrd *brdp; +unsigned int j; + +for (j =0 ; (j < stli_nrbrds); j++) { +if ((brdp = stli_brds[j]) ==NULL || (brdp->state &BST_PROBED )) +continue ; + +stli_cleanup_ports (brdp); + +iounmap (brdp->membase); +if (brdp->iosize >0 ) +release_region (brdp->iobase, brdp->iosize); +kfree (brdp); + stli_brds[j] =NULL ; + } +} +static int __init istallion_module_init (void ) { -int i; +unsigned int i; +int retval;printk (KERN_INFO "%s: version %s\n" , stli_drvtitle, stli_drvversion);spin_lock_init (&stli_lock);spin_lock_init (&brd_lock); -stli_initbrds (); - - stli_serial =alloc_tty_driver (STL_MAXBRDS *STL_MAXPORTS ); -if (!stli_serial) -return -ENOMEM ; - -/* -* Allocate a temporary write buffer. -*/ stli_txcookbuf =kmalloc (STLI_TXBUFSIZE ,GFP_KERNEL ); -if (!stli_txcookbuf) +if (!stli_txcookbuf) {printk (KERN_ERR "STALLION: failed to allocate memory " "(size=%d)\n" ,STLI_TXBUFSIZE ); + retval = -ENOMEM ; + goto err; + } -/* -* Set up a character driver for the shared memory region. We need this -* to down load the slave code image. Also it is a useful debugging tool. -*/ -if (register_chrdev (STL_SIOMEMMAJOR ,"staliomem" , &stli_fsiomem)) -printk (KERN_ERR "STALLION: failed to register serial memory " -"device\n" ); - - istallion_class =class_create (THIS_MODULE ,"staliomem" ); -for (i =0 ; i <4 ; i++) -class_device_create (istallion_class,NULL , -MKDEV (STL_SIOMEMMAJOR , i), -NULL ,"staliomem%d" , i); + stli_serial =alloc_tty_driver (STL_MAXBRDS *STL_MAXPORTS ); +if (!stli_serial) { + retval = -ENOMEM ; + goto err_free; + } -/* -* Set up the tty driver structure and register us as a driver. -*/ stli_serial->owner =THIS_MODULE ; stli_serial->driver_name = stli_drvname; stli_serial->name = stli_serialname;
@@ -4596,58 +4599,75 @@ static int __init istallion_module_init( stli_serial->flags =TTY_DRIVER_REAL_RAW ;tty_set_operations (stli_serial, &stli_ops); -if (tty_register_driver (stli_serial)) { -put_tty_driver (stli_serial); + retval =tty_register_driver (stli_serial); +if (retval) {printk (KERN_ERR "STALLION: failed to register serial driver\n" ); -return -EBUSY ; + goto err_ttyput; + } + + retval =stli_initbrds (); +if (retval) + goto err_ttyunr; + +/* +* Set up a character driver for the shared memory region. We need this +* to down load the slave code image. Also it is a useful debugging tool. +*/ + retval =register_chrdev (STL_SIOMEMMAJOR ,"staliomem" , &stli_fsiomem); +if (retval) { +printk (KERN_ERR "STALLION: failed to register serial memory " +"device\n" ); + goto err_deinit; } + + istallion_class =class_create (THIS_MODULE ,"staliomem" ); +for (i =0 ; i <4 ; i++) +class_device_create (istallion_class,NULL , +MKDEV (STL_SIOMEMMAJOR , i), +NULL ,"staliomem%d" , i); +return 0 ; +err_deinit: +pci_unregister_driver (&stli_pcidriver); +istallion_cleanup_isa (); +err_ttyunr: +tty_unregister_driver (stli_serial); +err_ttyput: +put_tty_driver (stli_serial); +err_free: +kfree (stli_txcookbuf); +err: +return retval; }/*****************************************************************************/ static void __exit istallion_module_exit(void) { -struct stlibrd *brdp;unsigned int j; -int i;printk (KERN_INFO "Unloading %s: version %s\n" , stli_drvtitle, stli_drvversion); -pci_unregister_driver (&stli_pcidriver); -/* -* Free up all allocated resources used by the ports. This includes -* memory and interrupts. -*/ if (stli_timeron) { stli_timeron =0 ;del_timer_sync (&stli_timerlist); } - i =tty_unregister_driver (stli_serial); -put_tty_driver (stli_serial); +unregister_chrdev (STL_SIOMEMMAJOR ,"staliomem" ); +for (j =0 ; j <4 ; j++) -class_device_destroy (istallion_class,MKDEV (STL_SIOMEMMAJOR , j)); +class_device_destroy (istallion_class,MKDEV (STL_SIOMEMMAJOR , + j));class_destroy (istallion_class); -if ((i =unregister_chrdev (STL_SIOMEMMAJOR ,"staliomem" ))) -printk ("STALLION: failed to un-register serial memory device, " -"errno=%d\n" , -i); - -kfree (stli_txcookbuf); -for (j =0 ; (j < stli_nrbrds); j++) { -if ((brdp = stli_brds[j]) ==NULL || (brdp->state &BST_PROBED )) -continue ; +pci_unregister_driver (&stli_pcidriver); +istallion_cleanup_isa (); -stli_cleanup_ports (brdp); +tty_unregister_driver (stli_serial); +put_tty_driver (stli_serial); -iounmap (brdp->membase); -if (brdp->iosize >0 ) -release_region (brdp->iobase, brdp->iosize); -kfree (brdp); - stli_brds[j] =NULL ; - } +kfree (stli_txcookbuf); }module_init (istallion_module_init);
PATCH 4/5 Char: istallion, dynamic tty device
In reply to Jiri Slabyistallion, dynamic tty device
register tty device dynamically according to the count of board ports.
---
commit 010cb3032661418012dd0949ff3566927ed430cd
tree 3da0c21735d8a6e32c59dde2ec2979c9dc9680c7
parent 92452a22c4ada362e991cbf0de84c8914525672a
author Jiri Slaby <[email protected]> Sat, 11 Nov 2006 02:29:24 +0100 committer Jiri Slaby <[email protected]> Sat, 11 Nov 2006 22:23:36 +0100
drivers/char/istallion.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-)
drivers/char/istallion.c +14 -1
@@ -3846,6 +3846,10 @@ static int stli_findeisabrds(void) stli_brds[brdp->brdnr] = brdp; found++; + +for (i =0 ; i < brdp->nrports; i++) +tty_register_device (stli_serial, + brdp->brdnr *STL_MAXPORTS + i,NULL ); }return found;
@@ -3872,6 +3876,7 @@ static int __devinit stli_pciprobe(struc const struct pci_device_id *ent) {struct stlibrd *brdp; +unsigned int i;int brdnr, retval = -EIO ; retval =pci_enable_device (pdev);
@@ -3912,6 +3917,10 @@ static int __devinit stli_pciprobe(struc brdp->enable =NULL ; brdp->disable =NULL ; +for (i =0 ; i < brdp->nrports; i++) +tty_register_device (stli_serial, brdp->brdnr *STL_MAXPORTS + i, + &pdev->dev); +return 0 ; err_null: stli_brds[brdp->brdnr] =NULL ;
@@ -3992,6 +4001,10 @@ static int stli_initbrds(void) } stli_brds[brdp->brdnr] = brdp; found++; + +for (i =0 ; i < brdp->nrports; i++) +tty_register_device (stli_serial, + brdp->brdnr *STL_MAXPORTS + i,NULL ); } retval =stli_findeisabrds ();
@@ -4596,7 +4609,7 @@ static int __init istallion_module_init( stli_serial->type =TTY_DRIVER_TYPE_SERIAL ; stli_serial->subtype =SERIAL_TYPE_NORMAL ; stli_serial->init_termios = stli_deftermios; - stli_serial->flags =TTY_DRIVER_REAL_RAW ; + stli_serial->flags =TTY_DRIVER_REAL_RAW |TTY_DRIVER_DYNAMIC_DEV ;tty_set_operations (stli_serial, &stli_ops); retval =tty_register_driver (stli_serial);
PATCH 5/5 Char: istallion, use mod_timer
In reply to Jiri Slabyistallion, use mod_timer
do not set expires by hand, use kernel helper, which also calls add_timer.
---
commit fc0e3ad83dbfac6d4b245319faff5f726974a3cf
tree 00cda6f05eb6e27a5e5043b0ce7e4fb512ea7287
parent 010cb3032661418012dd0949ff3566927ed430cd
author Jiri Slaby <[email protected]> Sat, 11 Nov 2006 02:32:18 +0100 committer Jiri Slaby <[email protected]> Sat, 11 Nov 2006 22:23:37 +0100
drivers/char/istallion.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/char/istallion.c +2 -4
@@ -2545,8 +2545,7 @@ static void stli_poll(unsigned long arg)struct stlibrd *brdp;unsigned int brdnr; - stli_timerlist.expires =STLI_TIMEOUT ; -add_timer (&stli_timerlist); +mod_timer (&stli_timerlist,STLI_TIMEOUT );/* * Check each board and do any servicing required.
@@ -3610,8 +3609,7 @@ stli_donestartup:if (! stli_timeron) { stli_timeron++; - stli_timerlist.expires =STLI_TIMEOUT ; -add_timer (&stli_timerlist); +mod_timer (&stli_timerlist,STLI_TIMEOUT ); }return rc;