diff driver/pt1_pci.c @ 95:a201531113ca

implement decent LNB management
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 09 Feb 2010 06:27:01 +0900
parents ee357d8f987f
children 6e661e828b43
line wrap: on
line diff
--- a/driver/pt1_pci.c	Sat Feb 06 03:04:11 2010 +0900
+++ b/driver/pt1_pci.c	Tue Feb 09 06:27:01 2010 +0900
@@ -51,8 +51,6 @@
 
 static int debug = 7;			/* 1 normal messages, 0 quiet .. 7 verbose. */
 static int lnb = 0;			/* LNB OFF:0 +11V:1 +15V:2 */
-static int lnb_ref_count = 0;
-struct mutex lnb_mutex;
 
 module_param(debug, int, 0);
 module_param(lnb, int, 0);
@@ -480,14 +478,32 @@
 	}
 	return 0 ;
 }
+
+static int count_used_bs_tuners(PT1_DEVICE *device)
+{
+	int count = 0;
+	int i;
+
+	for(i=0; i<MAX_CHANNEL; i++) {
+		if(device && device->channel[i] &&
+		   device->channel[i]->type == CHANNEL_TYPE_ISDB_S &&
+		   device->channel[i]->valid)
+			count++;
+	}
+
+	printk(KERN_INFO "used bs tuners on %p = %d\n", device, count);
+	return count;
+}
+
 static	int	pt1_ioctl(struct inode *inode, struct file  *file, unsigned int cmd, unsigned long arg0)
 {
 	PT1_CHANNEL	*channel = file->private_data;
-	int		signal ;
+	int		signal;
 	unsigned long	dummy;
 	void		*arg = (void *)arg0;
 	int		lnb_eff, lnb_usr;
 	char *voltage[] = {"0V", "11V", "15V"};
+	int count;
 
 	switch(cmd){
 		case SET_CHANNEL:
@@ -517,22 +533,20 @@
 			dummy = copy_to_user(arg, &signal, sizeof(int));
 			return 0 ;
 		case LNB_ENABLE:
-			lnb_usr = (int)arg0;
-			lnb_eff = lnb_usr ? lnb_usr : lnb;
-			mutex_lock(&lnb_mutex);
-			lnb_ref_count += 1;
-			settuner_reset(channel->ptr->regs, channel->ptr->cardtype, lnb_eff, TUNER_POWER_ON_RESET_DISABLE);
-			mutex_unlock(&lnb_mutex);
-			printk(KERN_INFO "PT1:LNB = %s\n", voltage[lnb_eff]);
-			printk(KERN_INFO "PT1:LNB ref_count = %d\n", lnb_ref_count);
+			count = count_used_bs_tuners(channel->ptr);
+			if(count <= 1) {
+				lnb_usr = (int)arg0;
+				lnb_eff = lnb_usr ? lnb_usr : lnb;
+				settuner_reset(channel->ptr->regs, channel->ptr->cardtype, lnb_eff, TUNER_POWER_ON_RESET_DISABLE);
+				printk(KERN_INFO "PT1:LNB on %s\n", voltage[lnb_eff]);
+			}
 			return 0 ;
 		case LNB_DISABLE:
-			mutex_lock(&lnb_mutex);
-			lnb_ref_count -= 1;
-			if(!lnb_ref_count)
+			count = count_used_bs_tuners(channel->ptr);
+			if(count <= 1) {
 				settuner_reset(channel->ptr->regs, channel->ptr->cardtype, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE);
-			mutex_unlock(&lnb_mutex);
-			printk(KERN_INFO "PT1:LNB ref_count = %d\n", lnb_ref_count);
+				printk(KERN_INFO "PT1:LNB off\n");
+			}
 			return 0 ;
 	}
 	return -EINVAL;
@@ -713,7 +727,6 @@
 	settuner_reset(dev_conf->regs, dev_conf->cardtype, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE);
 	schedule_timeout_interruptible(msecs_to_jiffies(10));
 	mutex_init(&dev_conf->lock);
-	mutex_init(&lnb_mutex);
 
 	// Tuner 初期化処理
 	for(lp = 0 ; lp < MAX_TUNER ; lp++){