[sane-devel] [PATCH] plustek_pp driver devfs support

Felipe W Damasio felipewd@terra.com.br
Thu, 16 Sep 2004 03:56:44 -0300


This is a multi-part message in MIME format.
--------------080909080901040701020702
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

	Greetings,

	This is a initial attempt to add devfs support to the plustek_pp driver 
to the 2.6 series of the linux kernel.

	Polite suggestions and patches are more than welcome.

	Cheers,

Felipe

--------------080909080901040701020702
Content-Type: text/x-patch;
 name="sane.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="sane.patch"

diff -urN a/backend/plustek-pp_ptdrv.c b/backend/plustek-pp_ptdrv.c
--- a/backend/plustek-pp_ptdrv.c	2004-04-14 17:22:07.000000000 -0300
+++ b/backend/plustek-pp_ptdrv.c	2004-09-16 03:37:12.012791808 -0300
@@ -105,6 +105,7 @@
 #   error "DEVFS not supported for this kernel-version"
 #  endif
 #  include <linux/devfs_fs_kernel.h>
+#  include <linux/device.h>
 # endif
 #endif
 
@@ -203,7 +204,8 @@
 #endif
 
 #ifdef CONFIG_DEVFS_FS
-static devfs_handle_t devfs_handle = NULL;
+static int devfs_handle;
+static struct class_simple *ptdrv_class;
 #endif
 
 /*
@@ -1567,11 +1569,9 @@
     DBG( DBG_HIGH, "pt_drv: init_module()\n" );
 
 #ifdef CONFIG_DEVFS_FS
-	devfs_handle = devfs_mk_dir(NULL, "scanner", NULL);
-	if( devfs_register_chrdev(_PTDRV_MAJOR, _DRV_NAME, &pt_drv_fops)) {
-#else
-	if( register_chrdev(_PTDRV_MAJOR, _DRV_NAME, &pt_drv_fops)) {
+	devfs_handle = devfs_mk_dir("scanner");
 #endif
+	if( register_chrdev(_PTDRV_MAJOR, _DRV_NAME, &pt_drv_fops)) {
 
 	    _PRINT(KERN_INFO "pt_drv: unable to get major %d for pt_drv devices\n",
 			    _PTDRV_MAJOR);
@@ -1597,11 +1597,10 @@
 		    	PtDrvDevices[i]->flags |= _PTDRV_INITALIZED;
 
 #ifdef CONFIG_DEVFS_FS
-				sprintf( controlname, "scanner/pt_drv%d", devCount );
-				devfs_register( NULL, controlname,
-            					DEVFS_FL_DEFAULT, _PTDRV_MAJOR, 0,
-                                (S_IFCHR | S_IRUGO | S_IWUGO | S_IFCHR),
-            					&pt_drv_fops, NULL );
+				sprintf (controlname, "scanner/pt_drv%d", devCount);
+				ptdrv_class = class_simple_create (THIS_MODULE, _DRV_NAME);
+				class_simple_device_add (ptdrv_class, MKDEV(_PTDRV_MAJOR, devCount), NULL, controlname);
+				devfs_mk_cdev (MKDEV(_PTDRV_MAJOR, devCount),  S_IFCHR | S_IRUGO | S_IWUGO, controlname);
 #endif
 
 				ProcFsRegisterDevice( PtDrvDevices[i] );
@@ -1620,10 +1619,10 @@
 	if( devCount == 0 ) {
 
 #ifdef CONFIG_DEVFS_FS
-        devfs_unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME );
-#else
-        unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME );
+	class_simple_device_remove (MKDEV(_PTDRV_MAJOR, devCount));
+	class_simple_destroy (ptdrv_class);
 #endif
+        unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME );
 		ProcFsShutdown();
 
 #ifdef __KERNEL__
@@ -1652,11 +1651,6 @@
 {
 	UInt 	  i;
 	pScanData ps;
-#ifdef CONFIG_DEVFS_FS
-	char           controlname[24];
-	devfs_handle_t master;
-#endif
-
 	DBG( DBG_HIGH, "pt_drv: cleanup_module()\n" );
 
 	for ( i = 0; i < _MAX_PTDEVS; i++ ) {
@@ -1666,10 +1660,9 @@
 
 	    if ( NULL != ps ) {
 #ifdef CONFIG_DEVFS_FS
-            sprintf( controlname, "scanner/pt_drv%d", i );
-            master = devfs_find_handle( NULL,controlname, 0, 0,
-                                        DEVFS_SPECIAL_CHR, 0 );
-            devfs_unregister( master );
+	    		devfs_remove ("scanner/pt_drv%d", i );
+			class_simple_device_remove (MKDEV(_PTDRV_MAJOR, i));
+			
 #endif
 			ptdrvShutdown( ps );
 			ProcFsUnregisterDevice( ps );
@@ -1677,10 +1670,9 @@
 	}
 
 #ifdef CONFIG_DEVFS_FS
-    devfs_unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME );
-#else
-    unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME );
+	class_simple_destroy (ptdrv_class);
 #endif
+    	unregister_chrdev( _PTDRV_MAJOR, _DRV_NAME );
 	ProcFsShutdown();
 
 	DBG( DBG_HIGH, "pt_drv: cleanup done.\n" );

--------------080909080901040701020702--