changeset 9:07b2fc07ff48

updated to current driver to support signal strength.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 23 Feb 2009 14:28:35 +0900
parents 6da603afd363
children e3059e3cf5e7
files driver/Makefile driver/pt1_ioctl.h driver/pt1_pci.c driver/pt1_tuner.c driver/pt1_tuner.h driver/pt1_tuner_data.c driver/pt1_tuner_data.h
diffstat 7 files changed, 108 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/driver/Makefile	Mon Feb 23 03:06:17 2009 +0900
+++ b/driver/Makefile	Mon Feb 23 14:28:35 2009 +0900
@@ -5,10 +5,10 @@
 all: ${TARGET}
 
 pt1_drv.ko: pt1_pci.c pt1_i2c.c pt1_tuner.c pt1_tuner_data.c
-	make -C /usr/src/linux-`uname -r` M=`pwd` V=1 modules
+	make -C /lib/modules/`uname -r`/build M=`pwd` V=1 modules
 
 clean:
-	make -C /usr/src/linux-`uname -r` M=`pwd` V=1 clean
+	make -C /lib/modules/`uname -r`/build M=`pwd` V=1 clean
 
 obj-m:= pt1_drv.o
 
--- a/driver/pt1_ioctl.h	Mon Feb 23 03:06:17 2009 +0900
+++ b/driver/pt1_ioctl.h	Mon Feb 23 14:28:35 2009 +0900
@@ -14,4 +14,7 @@
 #define		SET_CHANNEL	_IOW(0x8D, 0x01, FREQUENCY)
 #define		START_REC	_IO(0x8D, 0x02)
 #define		STOP_REC	_IO(0x8D, 0x03)
+#define		GET_SIGNAL_STRENGTH	_IOR(0x8D, 0x04, int *)
+#define		LNB_ENABLE	_IO(0x8D, 0x05)
+#define		LNB_DISABLE	_IO(0x8D, 0x06)
 #endif
--- a/driver/pt1_pci.c	Mon Feb 23 03:06:17 2009 +0900
+++ b/driver/pt1_pci.c	Mon Feb 23 14:28:35 2009 +0900
@@ -67,13 +67,13 @@
 #define		DEV_NAME	"pt1video"
 
 #define		MAX_READ_BLOCK	4			// 1度に読み出す最大DMAバッファ数
-#define		MAX_PCI_DEVICE		64		// 最大64枚
+#define		MAX_PCI_DEVICE		128		// 最大64枚
 #define		DMA_SIZE	4096			// DMAバッファサイズ
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) 
-#define		DMA_RING_SIZE	64			// RINGサイズ
+#define		DMA_RING_SIZE	128			// RINGサイズ
 #define		DMA_RING_MAX	511			// 1RINGにいくつ詰めるか(1023はNGで511まで)
-#define		CHANEL_DMA_SIZE	(1*1024*1024)	// 地デジ用(16Mbps)
-#define		BS_CHANEL_DMA_SIZE	(1*1024*1024)	// BS用(32Mbps)
+#define		CHANEL_DMA_SIZE	(2*1024*1024)	// 地デジ用(16Mbps)
+#define		BS_CHANEL_DMA_SIZE	(4*1024*1024)	// BS用(32Mbps)
 #else
 #define		DMA_RING_SIZE	28			// RINGサイズ
 #define		DMA_RING_MAX	511			// 1RINGにいくつ詰めるか(1023はNGで511まで)
@@ -136,6 +136,7 @@
 									CHANNEL_TYPE_ISDB_T, CHANNEL_TYPE_ISDB_T};
 
 static	PT1_DEVICE	*device[MAX_PCI_DEVICE];
+static struct class	*pt1video_class;
 
 #define		PT1MAJOR	251
 #define		DRIVERNAME	"pt1video"
@@ -153,10 +154,7 @@
 	for(ring_pos = 0 ; ring_pos < DMA_RING_SIZE ; ring_pos++){
 		for(data_pos = 0 ; data_pos < DMA_RING_MAX ; data_pos++){
 			dataptr = dev_conf->dmactl[ring_pos].data[data_pos];
-			// データあり?
-			if(dataptr[(DMA_SIZE / sizeof(__u32)) - 2] == 0){
-				break ;
-			}
+			dataptr[(DMA_SIZE / sizeof(__u32)) - 2] = 0;
 		}
 	}
 	// 転送カウンタをリセット
@@ -295,15 +293,11 @@
 		if(device[lp] == NULL){
 			return -EIO ;
 		}
-		printk(KERN_INFO "(%d)base_minor=%d: MAX=%d(%d)\n",
-				lp, device[lp]->base_minor,
-				(device[lp]->base_minor + MAX_CHANNEL), minor);
 		if((device[lp]->base_minor <= minor) &&
 			((device[lp]->base_minor + MAX_CHANNEL) > minor)){
 			mutex_lock(&device[lp]->lock);
 			for(lp2 = 0 ; lp2 < MAX_CHANNEL ; lp2++){
 				channel = device[lp]->channel[lp2] ;
-				printk(KERN_INFO "Minor(%d:%d)\n", channel->minor, minor);
 				if(channel->minor == minor){
 					if(channel->valid == TRUE){
 						mutex_unlock(&device[lp]->lock);
@@ -378,7 +372,7 @@
 		}
 	}
 	// 読み終わったかつ使用しているのがが4K以下
-	if((channel->req_dma == TRUE) && (channel->size < DMA_SIZE)){
+	if(channel->req_dma == TRUE){
 		channel->req_dma = FALSE ;
 		wake_up(&channel->ptr->dma_wait_q);
 	}
@@ -392,8 +386,6 @@
 		case CHANNEL_TYPE_ISDB_S:
 			{
 				ISDB_S_TMCC		tmcc ;
-				int				lp ;
-
 				if(bs_tune(channel->ptr->regs,
 						&channel->ptr->lock,
 						channel->address,
@@ -401,9 +393,6 @@
 						&tmcc) < 0){
 					return -EIO ;
 				}
-				printk(KERN_INFO "cn = (%x:%x)\n", (tmcc.cn[0] & 0xFF),
-						(tmcc.cn[1] & 0xFF));
-				printk(KERN_INFO "agc = (%x)\n", (tmcc.agc & 0xFF));
 
 #if 0
 				printk(KERN_INFO "clockmargin = (%x)\n", (tmcc.clockmargin & 0xFF));
@@ -442,6 +431,7 @@
 static	int	pt1_ioctl(struct inode *inode, struct file  *file, unsigned int cmd, void *arg)
 {
 	PT1_CHANNEL	*channel = file->private_data;
+	int			signal ;
 
 	switch(cmd){
 		case SET_CHANNEL:
@@ -456,6 +446,33 @@
 		case STOP_REC:
 			SetStream(channel->ptr->regs, channel->channel, FALSE);
 			return 0 ;
+		case GET_SIGNAL_STRENGTH:
+			switch(channel->type){
+				case CHANNEL_TYPE_ISDB_S:
+					{
+						signal = isdb_s_read_signal_strength(channel->ptr->regs,
+													&channel->ptr->lock,
+													channel->address);
+					}
+					break ;
+				case CHANNEL_TYPE_ISDB_T:
+                	// calc C/N
+					signal = isdb_t_read_signal_strength(channel->ptr->regs, 
+												&channel->ptr->lock, channel->address);
+					break ;
+			}
+			copy_to_user(arg, &signal, sizeof(int));
+			return 0 ;
+		case LNB_ENABLE:
+			if(lnb){
+				settuner_reset(channel->ptr->regs, lnb, TUNER_POWER_ON_RESET_DISABLE);
+			}
+			return 0 ;
+		case LNB_DISABLE:
+			if(lnb){
+				settuner_reset(channel->ptr->regs, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE);
+			}
+			return 0 ;
 	}
 	return -EINVAL;
 }
@@ -606,7 +623,7 @@
 	settuner_reset(dev_conf->regs, LNB_OFF, TUNER_POWER_ON_RESET_ENABLE);
 	schedule_timeout_interruptible(msecs_to_jiffies(50));
 
-	settuner_reset(dev_conf->regs, lnb, TUNER_POWER_ON_RESET_DISABLE);
+	settuner_reset(dev_conf->regs, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE);
 	schedule_timeout_interruptible(msecs_to_jiffies(10));
 	mutex_init(&dev_conf->lock);
 
@@ -638,7 +655,6 @@
 	for(lp = 0 ; lp < MAX_PCI_DEVICE ; lp++){
 		if(device[lp] == NULL){
 			device[lp] = dev_conf ;
-			printk(KERN_INFO "Alloc[%d]\n", lp);
 			break ;
 		}
 	}
@@ -657,7 +673,6 @@
 		channel->req_dma = FALSE ;
 		// マイナー番号設定
 		channel->minor = MINOR(dev_conf->dev) + lp ;
-		printk(KERN_INFO "Minor[%d]\n", channel->minor);
 		// 対象のI2Cデバイス
 		channel->address = i2c_address[lp] ;
 		channel->type = channeltype[lp] ;
@@ -682,6 +697,16 @@
 		if(channel->buf == NULL){
 			goto out_err_v4l;
 		}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
+		device_create(pt1video_class, NULL, MKDEV(MAJOR(dev_conf->dev),
+						(MINOR(dev_conf->dev) + lp)), NULL,
+						"pt1video%u", MINOR(dev_conf->dev) + lp);
+#else
+		device_create(pt1video_class, NULL, MKDEV(MAJOR(dev_conf->dev),
+						(MINOR(dev_conf->dev) + lp)),
+						"pt1video%u", MINOR(dev_conf->dev) + lp);
+#endif
+
 #if 0
 		dev_conf->vdev[lp] = video_device_alloc();
 		memcpy(dev_conf->vdev[lp], &pt1_template, sizeof(pt1_template));
@@ -747,6 +772,8 @@
 				kfree(dev_conf->channel[lp]->buf);
 				kfree(dev_conf->channel[lp]);
 			}
+			device_destroy(pt1video_class, 
+							MKDEV(MAJOR(dev_conf->dev), (MINOR(dev_conf->dev) + lp)));
 		}
 		unregister_chrdev_region(dev_conf->dev, MAX_CHANNEL);
 		writel(0xb0b0000, dev_conf->regs);
@@ -788,12 +815,16 @@
 
 static int __init pt1_pci_init(void)
 {
+	pt1video_class = class_create(THIS_MODULE, DRIVERNAME);
+	if (IS_ERR(pt1video_class))
+		return PTR_ERR(pt1video_class);
 	return pci_register_driver(&pt1_driver);
 }
 
 
 static void __exit pt1_pci_cleanup(void)
 {
+	class_destroy(pt1video_class);
 	pci_unregister_driver (&pt1_driver);
 }
 
--- a/driver/pt1_tuner.c	Mon Feb 23 03:06:17 2009 +0900
+++ b/driver/pt1_tuner.c	Mon Feb 23 14:28:35 2009 +0900
@@ -18,17 +18,7 @@
 #include	"pt1_i2c.h"
 #include	"pt1_tuner.h"
 #include	"pt1_tuner_data.h"
-/*
-  LNB  : BIT 2 1
-   OFF :     0 0
-   +15V:     1 1
-   +11V:     1 0
 
-  TUNER: BIT        3 0
-   POWER-OFF      : 0 0
-   POWER-ON RESET : 0 1
-   POWER-ON ONLY  : 1 1
-*/
 typedef	struct	_TUNER_INFO{
 	int		isdb_s ;
 	int		isdb_t ;
@@ -67,7 +57,7 @@
 
 	switch(tuner){
 		case TUNER_POWER_ON_RESET_ENABLE: val |= (1 << BIT_TUNER) ; break ;
-		case TUNER_POWER_ON_RESET_DISABLE: val = (1 << BIT_TUNER) | (1 << BIT_RESET) ; break ;
+		case TUNER_POWER_ON_RESET_DISABLE: val |= (1 << BIT_TUNER) | (1 << BIT_RESET) ; break ;
 	}
 
 	writel(val, (regs + 4));
@@ -307,16 +297,8 @@
 		tsid += 1;
 	}
 
-	memcpy(&wk, &bs_get_cn, sizeof(WBLOCK));
-	wk.addr = addr;
-	tmcc->cn[0] = i2c_read(regs, lock, &wk, 1);
-
 	memcpy(&wk, &bs_get_agc, sizeof(WBLOCK));
 	wk.addr = addr;
-	tmcc->cn[1] = i2c_read(regs, lock, &wk, 1);
-
-	memcpy(&wk, &bs_get_maxagc, sizeof(WBLOCK));
-	wk.addr = addr;
 	tmcc->agc = i2c_read(regs, lock, &wk, 1);
 
 	// TS-ID別の情報を取得
@@ -347,6 +329,25 @@
 	tmcc->carriermargin = i2c_read(regs, lock, &wk, 1);
 	return 0 ;
 }
+int		isdb_s_read_signal_strength(void __iomem *regs, struct mutex *lock, int addr)
+{
+	WBLOCK	wk;
+	__u32	val ;
+	__u32	val2;
+	int		val3 ;
+
+	memcpy(&wk, &bs_get_signal1, sizeof(WBLOCK));
+	wk.addr = addr;
+	val = i2c_read(regs, lock, &wk, 1);
+
+	memcpy(&wk, &bs_get_signal2, sizeof(WBLOCK));
+	wk.addr = addr;
+	val2 = i2c_read(regs, lock, &wk, 1);
+	val3 = (((val << 8) & 0XFF00) | (val2 & 0XFF));
+
+	return val3 ;
+}
+
 __u32	getfrequency_add(__u32 channel)
 {
 	int		lp ;
@@ -446,6 +447,24 @@
 	}
 	return 0 ;
 }
+int		isdb_t_read_signal_strength(void __iomem *regs, struct mutex *lock, int addr)
+{
+	__u32	val ;
+	__u32	val2;
+	__u32	val3;
+	WBLOCK	wk;
+
+	memcpy(&wk, &isdb_t_signal1, sizeof(WBLOCK));
+	wk.addr = addr;
+	val = i2c_read(regs, lock, &wk, 1);
+	printk(KERN_INFO "CN(1)Val(%x)\n", val);
+
+	memcpy(&wk, &isdb_t_signal2, sizeof(WBLOCK));
+	wk.addr = addr;
+	val2 = i2c_read(regs, lock, &wk, 1);
+	val3 = (((val << 8) & 0XFF00) | (val2 & 0XFF));
+	return val3 ;
+}
 #if 0
 int		isdb_t_tune(void __iomem *regs, struct mutex *lock, int addr, int channel, ISDB_T_TMCC *tmcc)
 {
--- a/driver/pt1_tuner.h	Mon Feb 23 03:06:17 2009 +0900
+++ b/driver/pt1_tuner.h	Mon Feb 23 14:28:35 2009 +0900
@@ -64,7 +64,6 @@
 	__u32	ext;					// 拡張フラグ (1ビット)
 	__u32	extdata[2];				// 拡張領域 (61ビット)
 #endif
-	__u32	cn[2] ;					// CN
 	__u32	agc ;					// AGC
 	__u32	clockmargin ;			// クロック周波数誤差
 	__u32	carriermargin ;			// キャリア周波数誤差
@@ -108,4 +107,7 @@
 
 extern	int		isdb_t_tune(void __iomem *, struct mutex *, int, int, ISDB_T_TMCC *);
 extern	int		isdb_t_frequency(void __iomem *, struct mutex *, int, int, int);
+extern	int		isdb_s_read_signal_strength(void __iomem *, struct mutex *, int);
+extern	int		isdb_t_read_signal_strength(void __iomem *, struct mutex *, int);
+
 #endif
--- a/driver/pt1_tuner_data.c	Mon Feb 23 03:06:17 2009 +0900
+++ b/driver/pt1_tuner_data.c	Mon Feb 23 14:28:35 2009 +0900
@@ -375,17 +375,12 @@
 /***************************************************************************/
 /* 地デジ周波数ロックチェック                                              */
 /***************************************************************************/
-WBLOCK	isdb_t_cn_1 = {
-	0,
-	1,
-	{0x8B}
-};
-WBLOCK	isdb_t_cn_2 = {
+WBLOCK	isdb_t_signal1 = {
 	0,
 	1,
 	{0x8C}
 };
-WBLOCK	isdb_t_agc1 = {
+WBLOCK	isdb_t_signal2 = {
 	0,
 	1,
 	{0x8D}
@@ -494,17 +489,17 @@
 /***************************************************************************/
 /* CN/AGC/MAXAGC取得                                                       */
 /***************************************************************************/
-WBLOCK	bs_get_cn = {
+WBLOCK	bs_get_signal1 = {
 	0,
 	1,
 	{0xBC}
 };
-WBLOCK	bs_get_agc = {
+WBLOCK	bs_get_signal2 = {
 	0,
 	1,
 	{0xBD}
 };
-WBLOCK	bs_get_maxagc = {
+WBLOCK	bs_get_agc = {
 	0,
 	1,
 	{0xBA}
--- a/driver/pt1_tuner_data.h	Mon Feb 23 03:06:17 2009 +0900
+++ b/driver/pt1_tuner_data.h	Mon Feb 23 14:28:35 2009 +0900
@@ -41,9 +41,9 @@
 extern	WBLOCK	bs_get_slot;
 extern	WBLOCK	bs_get_clock;
 extern	WBLOCK	bs_get_carrir;
-extern	WBLOCK	bs_get_cn;
+extern	WBLOCK	bs_get_signal1;
+extern	WBLOCK	bs_get_signal2;
 extern	WBLOCK	bs_get_agc;
-extern	WBLOCK	bs_get_maxagc;
 /***************************************************************************/
 /* 地デジ用データ定義                                                      */
 /***************************************************************************/
@@ -54,10 +54,9 @@
 extern	WBLOCK	isdb_t_tune_read;
 extern	WBLOCK	isdb_t_tmcc_read_1;
 extern	WBLOCK	isdb_t_tmcc_read_1;
-extern	WBLOCK	isdb_t_cn_1;
-extern	WBLOCK	isdb_t_cn_2;
-extern	WBLOCK	isdb_t_agc_1;
-extern	WBLOCK	isdb_t_agc_2;
+extern	WBLOCK	isdb_t_signal1;
+extern	WBLOCK	isdb_t_signal2;
+extern	WBLOCK	isdb_t_agc2;
 
 extern	WBLOCK	isdb_t_get_clock;
 extern	WBLOCK	isdb_t_get_carrir;