diff driver/pt1_pci.c @ 137:4303bbfd5d37

Support Linux-3.x kernel delete asm/system.h
author Naoya OYAMA <naoya.oyama@gmail.com>
date Thu, 28 Jun 2012 00:16:47 +0900
parents c8cfd684fee8
children ac23a9b417a2
line wrap: on
line diff
--- a/driver/pt1_pci.c	Wed Jun 27 23:41:49 2012 +0900
+++ b/driver/pt1_pci.c	Thu Jun 28 00:16:47 2012 +0900
@@ -10,14 +10,18 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 
-#include <asm/system.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/uaccess.h>
 #include <linux/version.h>
 #include <linux/mutex.h>
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
-#include <linux/freezer.h>
+  #include <linux/freezer.h>
+  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
+    #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
+      #include <linux/smp_lock.h>
+    #endif
+  #endif
 #else
 #define set_freezable()
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
@@ -76,6 +80,7 @@
 #define		DMA_SIZE	4096			// DMAバッファサイズ
 #define		DMA_RING_SIZE	128			// RINGサイズ
 #define		DMA_RING_MAX	511			// 1RINGにいくつ詰めるか(1023はNGで511まで)
+#define		MAX_READ_SIZE	(1024 * 4)
 #define		CHANEL_DMA_SIZE	(2*1024*1024)	// 地デジ用(16Mbps)
 #define		BS_CHANEL_DMA_SIZE	(4*1024*1024)	// BS用(32Mbps)
 
@@ -144,6 +149,10 @@
 #define		PT1MAJOR	251
 #define		DRIVERNAME	"pt1video"
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
+static DEFINE_MUTEX(pt1_ioctl_mutex);
+#endif
+
 static	void	reset_dma(PT1_DEVICE *dev_conf)
 {
 
@@ -309,12 +318,12 @@
 			// 頻度を落す(4Kで起動させる)
 			for(lp = 0 ; lp < MAX_CHANNEL ; lp++){
 				channel = dev_conf->channel[real_channel[lp]] ;
-				if((channel->size >= DMA_SIZE) && (channel->valid == TRUE)){
+				if((channel->size >= MAX_READ_SIZE ) && (channel->valid == TRUE)){
 					wake_up(&channel->wait_q);
 				}
 			}
 		}
-		schedule_timeout_interruptible(msecs_to_jiffies(1));
+		schedule_timeout_interruptible(msecs_to_jiffies(10));
 	}
 	return 0 ;
 }
@@ -403,9 +412,9 @@
 	__u32	size ;
 	unsigned long dummy;
 
-	// 4K単位で起こされるのを待つ(CPU負荷対策)
-	if(channel->size < DMA_SIZE){
-		wait_event_timeout(channel->wait_q, (channel->size >= DMA_SIZE),
+	// 128K単位で起こされるのを待つ(CPU負荷対策)
+	if(channel->size < MAX_READ_SIZE){
+		wait_event_timeout(channel->wait_q, (channel->size >= MAX_READ_SIZE),
 							msecs_to_jiffies(500));
 	}
 	mutex_lock(&channel->lock);
@@ -533,6 +542,7 @@
 			return 0 ;
 		case STOP_REC:
 			SetStream(channel->ptr->regs, channel->channel, FALSE);
+			schedule_timeout_interruptible(msecs_to_jiffies(100));
 			return 0 ;
 		case GET_SIGNAL_STRENGTH:
 			switch(channel->type){
@@ -568,6 +578,25 @@
 	return -EINVAL;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) 
+static long pt1_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+	long rc;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
+	if(mutex_lock_interruptible(&pt1_ioctl_mutex))
+		return -EINTR;
+	rc = pt1_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
+	mutex_unlock(&pt1_ioctl_mutex);
+#else
+	lock_kernel();
+	rc = pt1_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
+	unlock_kernel();
+#endif
+	return rc;
+}
+#endif
+
 /*
 */
 static const struct file_operations pt1_fops = {
@@ -575,7 +604,11 @@
 	.open		=	pt1_open,
 	.release	=	pt1_release,
 	.read		=	pt1_read,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
+	.unlocked_ioctl	=	pt1_unlocked_ioctl,
+#else
 	.ioctl		=	pt1_ioctl,
+#endif
 	.llseek		=	no_llseek,
 };
 
@@ -970,8 +1003,8 @@
 
 static void __exit pt1_pci_cleanup(void)
 {
+	pci_unregister_driver(&pt1_driver);
 	class_destroy(pt1video_class);
-	pci_unregister_driver(&pt1_driver);
 }
 
 module_init(pt1_pci_init);