Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mpeg2] Porting kfir for kernel 2.6



Hi!

I didn't see my first mail come through, here again:

I had some spare time, and made a patch which makes the kfir and saa7113
drivers compile and load under 2.6. This is against current CVS version.

As I know almost nothing about writing kernel code, or how these drivers
work, It's most likely that these drivers won't work (yet).
But, I don't even have such card so I can't really test/debug this, or
test how the 2.4 works.

I hope someone could test this, and see what happens (or even fix it)...


It now uses hotplug firmware loading, so hotplug must be present and the altera_keb_plx_5e.rbf and MPEG1_6.HLD should be in /usr/lib/hotplug/firmware/ or /lib/hotplug/firmware/, depending on distro.

--
Anssi Hannula
diff -Nur -x CVS -x kfir_micro.h -x micro kfir/driver/kfir.c kfir-cvs-2.6/driver/kfir.c
--- kfir/driver/kfir.c	2002-12-17 11:20:00.000000000 +0200
+++ kfir-cvs-2.6/driver/kfir.c	2004-12-29 16:13:48.571702488 +0200
@@ -24,8 +24,11 @@
  * The author can be reached at ralph@convergence.de, 
 
  * the project's page is at http://linuxtv.org/mpeg2/
+ 
+ * Ported for linux 2.6 by Anssi Hannula <anssi.hannula@mbnet.fi>
+ 
  */
-
+ 
 #define __KERNEL_SYSCALLS__
 #include <linux/poll.h>
 #include <linux/fs.h>
@@ -36,10 +39,11 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/pci.h>
-#include <linux/wrapper.h>
+//#include <linux/wrapper.h>
 #include <linux/init.h>
 #include <linux/ctype.h>
 #include <asm/io.h>
+
 #if defined(MODVERSIONS)
 #include <linux/modversions.h>
 #endif
@@ -56,6 +60,9 @@
 #include <linux/video_decoder.h>
 #endif
 
+#include <linux/firmware.h>
+#include <linux/interrupt.h>
+
 #include "kfir_micro.h"
 #include "kfir.h"
 #include "plx9054.h"
@@ -136,7 +143,7 @@
 }
 
 static int errno;
-static int do_firmread(const char *fn, char **fp)
+/*static int do_firmread(const char *fn, char **fp)
 {
         int fd;
 	long l;
@@ -185,7 +192,7 @@
 	r = do_firmread(fn, fp);
 	set_fs(fs);
 	return r;
-}
+}*/
 
 /* ----------------------------------------------------------------------- */
 /* ADSP functions                                                          */
@@ -278,15 +285,33 @@
 	u16 *Boundary;
 	u16 Data, BlockSize, adr;
 
-	u32 microlen;
+// 	u32 microlen;
 	u16 *micro;
 	
-	if (
-#ifdef __KFIR_PACK__
-	    !(microlen=firmread("micro/MPEG1_6.HLD", (char**) &micro)) &&
-#endif
-	    !(microlen=firmread(KFIR_MICRO_PATH "MPEG1_6.HLD", (char**) &micro)))
+// 	if (
+// #ifdef __KFIR_PACK__
+// 	    !(microlen=firmread("micro/MPEG1_6.HLD", (char**) &micro)) &&
+// #endif
+// 	    !(microlen=firmread(KFIR_MICRO_PATH "MPEG1_6.HLD", (char**) &micro)))
+// 		return -1;
+
+// hotplug firmware
+	int ret;
+	const struct firmware *fw;
+	ret = request_firmware(&fw, "MPEG1_6.HLD", &kfir->pdev->dev);
+	if (ret) {
+		if (ret == -ENOENT) {
+			printk(KERN_ERR "kfir: could not load firmware,"
+			       " file not found: MPEG1_6.HLD\n");
+			printk(KERN_ERR "kfir: usually this should be in"
+			       " /usr/lib/hotplug/firmware\n");
+		} else
+			printk(KERN_ERR "kfir: cannot request firmware"
+			       " (error %i)\n", ret);
 		return -1;
+	}
+	// Hope this works, I _really_ have no idea about anything I do
+	micro = (u16 *) fw->data;
 
 	CodePtr = micro+5;
 	Boundary= CodePtr+micro[1];
@@ -305,7 +330,8 @@
 		while(BlockSize-- && CodePtr < Boundary) 
 			ADSPWriteData(*(CodePtr++));
 	}
-	vfree(micro);
+	release_firmware(fw);
+//	vfree(micro);
 	udelay(5);
 	
 	ADSPWriteAddr(0x1);
@@ -384,7 +410,8 @@
 		waltl(ALT_ADR_ADSP_IRQ, Data);
 		
 		Data |= ALT_D_ADSP_IRQ_E | ALT_D_ADSP_IRQ_2;
-		Data=waltl(ALT_ADR_ADSP_IRQ, Data);
+		waltl(ALT_ADR_ADSP_IRQ, Data);
+		Data=raltl(ALT_ADR_ADSP_IRQ);
 		
 		// Some magic
 		ADSPWriteAddr(0);
@@ -934,7 +961,7 @@
 static int Kfir_DownLoadParams(struct kfir_dev *kfir)
 {
 	DWORD MulFrameRate;
-	DWORD FrameRate;
+// 	DWORD FrameRate;
 	DWORD r;
 	DWORD mbWidth;
 	DWORD mbHeight;
@@ -1050,7 +1077,7 @@
 		MulFrameRate = 30000;
 		break;
 	}
-	FrameRate=((double)MulFrameRate)/1000.0;
+// 	FrameRate=((double)MulFrameRate)/1000.0;
 	r = (((4000 * MulBitRate) / MulFrameRate) + 1)/2;
 	
 	kfir->Par[KFIR_ADR_D0_I_0/4] = (WORD)((RMUL(10l,r,31l)>>2) & 0xffff);
@@ -1076,7 +1103,7 @@
 
 	kfir->Par[KFIR_ADR_STD_PICT_DEL/4] = (WORD)(90000000UL/MulFrameRate);
 	kfir->Par[KFIR_ADR_FIRST_PICT_DEL/4] = 
-		(WORD) ((((((double)Params->VBFBufferSize)*16384.0*2.0)/8.0)*90000.0)/((double)MulBitRate));
+		(WORD) (((((Params->VBFBufferSize)*16384*2)/8)*90000)/(MulBitRate));
 
 
 	Data=RMUL(MulBitRate*2, 
@@ -1151,7 +1178,6 @@
 		break;
 	}
 	kfir->Par[KFIR_ADR_VIB_DEC_PATTERN/4] = (WORD)Data;
-	
 	switch (Params->KF_HorResolution) {
 	case KFIR_H_160:
 		Data = KFIR_ADR_VIB_DEC_SIZE_160;
@@ -1236,7 +1262,7 @@
 	kfir->Par[KFIR_ADR_FILE_MODE/4] = Params->Video_Source == VT_KFIR_FILE ? 1 : 0;
 	{
 		DWORD gopr = RMUL(MulBitRate*2, Params->KF_GOP_N, MulFrameRate/125);
-		//(DWORD)((Params->KF_GOP_N*MulBitRate)/FrameRate)/4;
+ 		//(DWORD)((Params->KF_GOP_N*MulBitRate)/FrameRate)/4;
 		DWORD vtmp1;
 		DWORD init_T;
 		
@@ -1384,19 +1410,19 @@
 	return state;
 }
 
-static void kfir_inc_use(struct i2c_adapter *adap)
-{
-	MOD_INC_USE_COUNT;
-}
-
-static void kfir_dec_use(struct i2c_adapter *adap)
-{
-	MOD_DEC_USE_COUNT;
-}
+// static void kfir_inc_use(struct i2c_adapter *adap)
+// {
+// 	MOD_INC_USE_COUNT;
+// }
+
+// static void kfir_dec_use(struct i2c_adapter *adap)
+// {
+// 	MOD_DEC_USE_COUNT;
+// }
 
 static int attach_inform(struct i2c_client *client)
 {
-        struct kfir_dev *kfir = (struct kfir_dev *) client->adapter->data;
+        struct kfir_dev *kfir = (struct kfir_dev *) i2c_get_adapdata(client->adapter);
 	
 	if (client->driver->id==I2C_DRIVERID_SAA7113) {
 		if (!kfir->decoder) 
@@ -1417,33 +1443,36 @@
 }
 
 static struct i2c_algo_bit_data i2c_algo_template = {
-	NULL, 
-	kfir_bit_setsda,
-	kfir_bit_setscl,
-	kfir_bit_getsda,
-	kfir_bit_getscl,
-	10, 10, 100,
+	data:		NULL, 
+	setsda:		kfir_bit_setsda,
+	setscl:		kfir_bit_setscl,
+	getsda:		kfir_bit_getsda,
+	getscl:		kfir_bit_getscl,
+	udelay:		10,
+	mdelay:		10,
+	timeout:	100,
 };
 
 static struct i2c_adapter i2c_adap_template = {
-	"kfir",
-	I2C_HW_B_BT848,
-	NULL,
-	NULL,
-	kfir_inc_use,
-	kfir_dec_use,
-	attach_inform,
-	detach_inform,
-	NULL,
+	owner:		THIS_MODULE,
+	name:		"kfir",
+	id:		I2C_HW_B_BT848,
+	algo:		NULL,
+	algo_data:	NULL,
+/*	kfir_inc_use,
+	kfir_dec_use,  FIXME: client->usage_count should be used? */ 
+	client_register:	attach_inform,
+	client_unregister:	detach_inform
+// 	NULL,
 };
 
 static struct i2c_client i2c_client_template = {
-        "kfir internal",
-        -1,
-        0,
-        0,
-        NULL,
-        NULL
+        name:		"kfir internal",
+        id:		-1,
+        flags:		0,
+        addr:		0,
+        adapter:	NULL,
+        driver:		NULL
 };
 
 static int init_i2c(struct kfir_dev *kfir)
@@ -1455,7 +1484,7 @@
 
 	sprintf(kfir->i2c_adap.name+strlen(kfir->i2c_adap.name), " #%d", num_kfir-1);
         kfir->i2c_algo.data = kfir;
-        kfir->i2c_adap.data = kfir;
+        i2c_set_adapdata(&kfir->i2c_adap, kfir);
         kfir->i2c_adap.algo_data = &kfir->i2c_algo;
         kfir->i2c_client.adapter = &kfir->i2c_adap;
 
@@ -1657,22 +1686,39 @@
 	int result=0;
 
 	if (!loaded) {
-		if (
-#ifdef __KFIR_PACK__
-		    !(microlen=firmread("micro/altera_keb_plx_5e.rbf", 
-					(char**) &micro)) &&
-#endif
-		    !(microlen=firmread(KFIR_MICRO_PATH "altera_keb_plx_5e.rbf", 
-					(char**) &micro)))
-		return -1;
+ /*		if (
+  #ifdef __KFIR_PACK__
+  		    !(microlen=firmread("micro/altera_keb_plx_5e.rbf", 
+  					(char**) &micro)) &&
+  #endif
+  		    !(microlen=firmread(KFIR_MICRO_PATH "altera_keb_plx_5e.rbf", 
+  					(char**) &micro)))
+ 		return -1;*/
+ 		int ret;
+ 		const struct firmware *fw;
+ 		ret = request_firmware(&fw, "altera_keb_plx_5e.rbf", &kfir->pdev->dev);
+ 		if (ret) {
+ 			if (ret == -ENOENT) {
+ 				printk(KERN_ERR "kfir: could not load firmware,"
+ 				" file not found: altera_keb_plx_5e.rbf\n");
+ 				printk(KERN_ERR "kfir: usually this should be in"
+ 				" /usr/lib/hotplug/firmware\n");
+ 			} else
+ 				printk(KERN_ERR "kfir: cannot request firmware"
+ 				" (error %i)\n", ret);
+ 			return -1;
+ 		}
+ 		// Hope this works, I _really_ have no idea about anything I do
+ 		micro = fw->data;
+ 		microlen = fw->size;
 
 		printk("loaded microcode with length %d\n", microlen);
 		Sleep(1000);
 		//Data=rplxl(PLX9054_CNTRL_OFFSET);
 		
 		result=AlteraWriteMicro(kfir, micro, microlen);
-
-		vfree(micro);
+		release_firmware(fw);
+// 		vfree(micro);
 		if (result<0)
 			return result;
 	}
@@ -1746,7 +1792,7 @@
 	return;
 }
 
-static void kfir_irq(int irq, void *dev_id, struct pt_regs * regs)
+static irqreturn_t kfir_irq(int irq, void *dev_id, struct pt_regs * regs)
 {
 	struct kfir_dev *kfir= (struct kfir_dev *) dev_id;
 	u32 plxstat;
@@ -1760,7 +1806,7 @@
 		//dprintk("kfir: irq_stat=%08x\n", plxstat);
 
 		if (!(plxstat&(LOCAL_INT_ACTIVE|DMA0_INT_ACTIVE|(1<<14))))
-			return;
+			return 0;
 
 		/* Error on PCI bus ? */
 		if (plxstat & (1<<14)) {
@@ -1871,6 +1917,7 @@
 			wplxl(PLX9054_INT_CNTRL_STS, 0);
 		}
 	}
+	return 0;
 }
 
 
@@ -2176,19 +2223,19 @@
 	return 0;
 }
 
-
-static int kfir_open(struct video_device *dev, int flags)
+static int kfir_open(struct inode *inode, struct file *file)
 {
+	struct video_device *dev = video_devdata(file);
 	struct kfir_dev *kfir = (struct kfir_dev *) dev;
 
 	kfir->recording=0;
-	MOD_INC_USE_COUNT;
+// 	MOD_INC_USE_COUNT;
 	return 0;   
 }
 
-
-static void kfir_close(struct video_device *dev)
+static int kfir_close(struct inode *inode, struct file *file)
 {
+	struct video_device *dev = file->private_data;
 	struct kfir_dev *kfir = (struct kfir_dev *) dev;
 
 	kfir->recording=2;
@@ -2220,16 +2267,17 @@
 		
 		printk("eready=%08x\n",KfirRegRead(KFIR_ADR_EREADY));
 	}
-	MOD_DEC_USE_COUNT;  
+// 	MOD_DEC_USE_COUNT;  
+	return 0;
 }
 
 static unsigned int kfir_poll
 (
-	struct video_device *dev,
 	struct file *file,
 	poll_table *wait
 ) 
 {
+	struct video_device *dev = file->private_data;
 	struct kfir_dev *kfir=(struct kfir_dev *) dev;
 
 	if (kfir->readp == kfir->writep)
@@ -2244,7 +2292,7 @@
 	}
 }
 
-static int kfir_mmap(struct video_device *dev, const char *adr, unsigned long size)
+static int kfir_mmap(struct file *file, struct vm_area_struct *area)
 {
 	//struct kfir_dev * kfir = (struct kfir_dev *)dev;
 
@@ -2256,8 +2304,10 @@
         { 1, "S-Video", 0, 0, 1, 0},
 };
 
-static int kfir_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
+
+static int kfir_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg)
 {
+	struct video_device *dev = file->private_data;
 	struct kfir_dev * kfir = (struct kfir_dev *) dev;
 	
 		switch (cmd)
@@ -2441,9 +2491,14 @@
 	return 0;
 }        
 
+static int kfir_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+	// Again, I don't have a slightest idea what am I doing (usercopying something? ;)
+	return video_usercopy(inode, file, cmd, arg, kfir_do_ioctl);
+}
 
-static long kfir_write(struct video_device *dev, const char *buf,
-		       unsigned long count, int nonblock)
+static ssize_t kfir_write(struct file *file, const char __user *buf,
+		       size_t count, loff_t *lof)
 {
 	/* not supported by Kfir1 */
         return 0;
@@ -2518,19 +2573,31 @@
 }
 
 
-static long kfir_read(struct video_device *dev, char *buf,
-		      unsigned long count, int nonblock)
+static ssize_t kfir_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 {
+	struct video_device *dev = file->private_data;
 	struct kfir_dev * kfir = (struct kfir_dev *) dev;
 
-	return record(kfir, buf, count, nonblock);
-}
-
-static int kfir_init_done(struct video_device *dev)
-{
-	return 0;
+	return record(kfir, buf, count, 1);
 }
 
+// static int kfir_init_done(struct video_device *dev)
+// {
+// 	return 0;
+// }
+
+
+/* template for file_operations-structure */
+static struct file_operations kfir_fops = {
+	owner:		THIS_MODULE,
+	open:		kfir_open,
+	read:		kfir_read,
+	write:		kfir_write,
+	poll:		kfir_poll,
+	ioctl:		kfir_ioctl,
+	mmap:		kfir_mmap,
+	release:	kfir_close
+};
 
 /* template for video_device-structure */
 static struct video_device kfir_template = {
@@ -2538,19 +2605,20 @@
 name:         "Kfir",
 type:         VID_TYPE_MPEG_ENCODER,  
 hardware:     VID_HARDWARE_SAA7146,  //FIXME: need to get VID_HARDWARE_KFIR registered
-open:         kfir_open,
+/*open:         kfir_open,
 close:        kfir_close,
 read:         kfir_read,
 write:        kfir_write,		
 poll:	      kfir_poll,
 ioctl:	      kfir_ioctl,
 mmap:         kfir_mmap,
-initialize:   kfir_init_done,
+initialize:   kfir_init_done,*/
 priv:         NULL,
 #if 0 // this field seems to be no longer present since kernel 2.4.19
 busy:         0,
 #endif
 minor:        0,
+fops:		&kfir_fops
 };
 
 static int kfir_init_device (struct pci_dev *pdev)
@@ -2564,7 +2632,7 @@
 	kfir=&kfirs[num_kfir];
 	num_kfir++;
 #if LINUX_VERSION_CODE >= 0x020300
-	pdev->driver_data=kfir;
+	pci_set_drvdata(pdev, kfir);
 #endif
 	memset(kfir, 0, sizeof(struct kfir_dev));
 
@@ -2745,7 +2813,9 @@
 
 static void __devexit kfir_remove_one (struct pci_dev *pdev)
 {
-	return kfir_remove_device((struct kfir_dev *) pdev->driver_data);
+// 	return kfir_remove_device((struct kfir_dev *) pdev->driver_data);
+	return kfir_remove_device((struct kfir_dev *) pci_get_drvdata(pdev));
+
 }
 
 static int kfir_suspend(struct pci_dev *pdev, u32 state)
diff -Nur -x CVS -x kfir_micro.h -x micro kfir/driver/Makefile kfir-cvs-2.6/driver/Makefile
--- kfir/driver/Makefile	2001-04-12 01:03:33.000000000 +0300
+++ kfir-cvs-2.6/driver/Makefile	2004-12-29 16:02:35.374044088 +0200
@@ -1,63 +1,77 @@
-CURRENT=$(shell uname -r)
-KERNEL_LOCATION=/usr/src/linux
+KERNELRELEASE := $(shell uname -r)
+KERNELSRCDIR := /lib/modules/$(KERNELRELEASE)/build
+KERNELBUILDDIR := $(KERNELSRCDIR)
+BUILD_DIR := $(shell pwd)
 
-M_OBJS       = kfir.o saa7113.o
-MX_OBJS      = i2c-core.o i2c-algo-bit.o videodev.o
-obj-m        = $(MX_OBJS) $(M_OBJS)
-EXTRA_CFLAGS = -D__KFIR_PACK__
-
-here:
-	DIR=`pwd`; (cd $(KERNEL_LOCATION); make SUBDIRS=$$DIR modules)
-	@echo
+include $(KERNELBUILDDIR)/.config
+
+ifneq ($(KERNELBUILDDIR),$(KERNELSRCDIR))
+KBUILDO=O=$(KERNELBUILDDIR)
+endif
+
+#CURRENT=$(shell uname -r)
+#KERNEL_LOCATION=/usr/src/linux
+
+#M_OBJS       = kfir.o saa7113.o
+#MX_OBJS      = i2c-core.o i2c-algo-bit.o videodev.o
+#obj-m        = $(MX_OBJS) $(M_OBJS)
+
+obj-m += kfir.o saa7113.o
+
+#EXTRA_CFLAGS = -mhard-float
+
+all:
+	$(MAKE) -C $(KERNELSRCDIR) $(KBUILDO) SUBDIRS=$(BUILD_DIR)
 
 install:
-	su -c "cp -v $(M_OBJS) $(MX_OBJS) /lib/modules/$(CURRENT)/misc"
+	su -c "cp -v $(obj-m) /lib/modules/$(KERNELRELEASE)/misc"
 
 reload: 
 	-make
 	-rmmod kfir
-	-insmod kfir.o loaded=1
+	-insmod kfir.ko loaded=1
 
 insmod:
 	make
-	-insmod videodev	
-	-insmod i2c-core.o	
-	-insmod i2c-algo-bit.o
-	-insmod saa7113.o
-	-insmod kfir.o debug=1;
+	-modprobe videodev
+	-modprobe firmware_class
+	-modprobe i2c-core	
+	-modprobe i2c-algo-bit
+	-insmod saa7113.ko
+	-insmod kfir.ko debug=1;
 
 insmodnk:
 	make
-	-insmod videodev	
-	-insmod i2c-core.o	
-	-insmod i2c-algo-bit.o
-	-insmod saa7113.o
+	-modprobe videodev
+	-modprobe i2c-core	
+	-modprobe i2c-algo-bit
+	-insmod saa7113.ko
 
 svcd22:
 	-rmmod kfir
-	-insmod kfir.o vidrate=2200000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
+	-insmod kfir.ko vidrate=2200000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
 
 svcd20:
 	-rmmod kfir
-	-insmod kfir.o vidrate=2000000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
+	-insmod kfir.ko vidrate=2000000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
 
 svcd18:
 	-rmmod kfir
-	-insmod kfir.o vidrate=1800000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
+	-insmod kfir.ko vidrate=1800000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
 svcd16:
 	-rmmod kfir
-	-insmod kfir.o vidrate=1600000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
+	-insmod kfir.ko vidrate=1600000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
 svcd14:
 	-rmmod kfir
-	-insmod kfir.o vidrate=1400000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
+	-insmod kfir.ko vidrate=1400000 sndfreq=6 vidsize=0x23 vidinput=1 loaded=1
 
 vcd:
 	-rmmod kfir
-	-insmod kfir.o mpeg1mode=1 vidrate=1150000 vidsize=0x23 vidinput=1 loaded=1
+	-insmod kfir.ko mpeg1mode=1 vidrate=1150000 vidsize=0x23 vidinput=1 loaded=1
 
 evcd:
 	-rmmod kfir
-	-insmod kfir.o mpeg1mode=1 vidrate=2000000 sndfreq=6 vidsize=0x12 vidinput=1 loaded=1
+	-insmod kfir.ko mpeg1mode=1 vidrate=2000000 sndfreq=6 vidsize=0x12 vidinput=1 loaded=1
 
 rmmod:
 	(	\
@@ -69,9 +83,9 @@
 
 
 clean:
-	-rm -f $(M_OBJS) $(MX_OBJS) *.o .*.o.flags *~
+	-rm -rf $(M_OBJS) $(MX_OBJS) *.o .*.o.flags *~ *.ko *.cmd .*.cmd .tmp* *.mod.c
 
-include $(KERNEL_LOCATION)/Rules.make
+#include $(KERNEL_LOCATION)/Rules.make
 
 
 
diff -Nur -x CVS -x kfir_micro.h -x micro kfir/driver/saa7113.c kfir-cvs-2.6/driver/saa7113.c
--- kfir/driver/saa7113.c	2001-04-12 01:03:33.000000000 +0300
+++ kfir-cvs-2.6/driver/saa7113.c	2004-12-29 16:06:34.943623976 +0200
@@ -1,6 +1,9 @@
 /* 
     SAA7113 - Philips video decoder driver
-
+    
+    Copyright (C) 2004 Anssi Hannula <anssi.hannula@mbnet.fi>
+                  ported for linux 2.6
+    
     Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
                   for Convergence Integrated Media GmbH
 
@@ -30,13 +33,13 @@
 #include <linux/fs.h>
 #include <linux/kernel.h>
 #include <linux/major.h>
-#include <linux/malloc.h>
+// #include <linux/malloc.h>
 #include <linux/mm.h>
 #include <linux/pci.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
 #include <linux/types.h>
-#include <linux/wrapper.h>
+// #include <linux/wrapper.h>
 #include <linux/video_decoder.h>
 #include <linux/module.h>
 #include <linux/delay.h>
@@ -92,7 +95,13 @@
         ret=i2c_master_send(client, msg, 2);
         if (ret!=2) 
                 printk("writereg error\n");
-        ((struct saa7113 *) client->data)->reg[reg]=data;
+        
+	struct saa7113 *decoder;
+	decoder = (struct saa7113 *) i2c_get_clientdata(client);
+	/* FIXME: What's that compiler warning, I tried everything...
+		It doesn't even occur later */
+	decoder->reg[reg]=data;
+// 	((struct saa7113 *) client->data)->reg[reg]=data;
         return ret;
 }
 
@@ -166,7 +175,7 @@
 
 void init(struct i2c_client *client)
 {
-        struct saa7113 *decoder=(struct saa7113 *) client->data;
+        struct saa7113 *decoder=(struct saa7113 *) i2c_get_clientdata(client);
 
 	decoder->addr = client->addr;
 	decoder->norm = VIDEO_MODE_AUTO;
@@ -204,7 +213,9 @@
                 return -ENOMEM;
         memcpy(client, &client_template, sizeof(struct i2c_client));
         
-        client->data=decoder=kmalloc(sizeof(struct saa7113),GFP_KERNEL);
+        decoder=kmalloc(sizeof(struct saa7113),GFP_KERNEL);
+        i2c_set_clientdata(client, decoder);
+	
         if (decoder==NULL) {
                 kfree(client);
                 return -ENOMEM;
@@ -225,15 +236,16 @@
 
 int detach_client(struct i2c_client *client)
 {
-        i2c_detach_client(client);
-        kfree(client->data);
+        struct saa7113 *decoder=(struct saa7113 *) i2c_get_clientdata(client);
+	i2c_detach_client(client);
         kfree(client);
+        kfree(decoder);
         return 0;
 }
 
 static int saa7113_command(struct i2c_client *client, unsigned int cmd, void *arg)
 {
-        struct saa7113 *decoder= (struct saa7113 *) client->data;
+        struct saa7113 *decoder= (struct saa7113 *) i2c_get_clientdata(client);
         int v;
                 
         switch (cmd) {
@@ -407,39 +419,40 @@
 } 
 
 
-void inc_use (struct i2c_client *client)
-{
-#ifdef MODULE
-        MOD_INC_USE_COUNT;
-#endif
-}
-
-void dec_use (struct i2c_client *client)
-{
-#ifdef MODULE
-        MOD_DEC_USE_COUNT;
-#endif
-}
+// void inc_use (struct i2c_client *client)
+// {
+// #ifdef MODULE
+//         MOD_INC_USE_COUNT;
+// #endif
+// }
+
+// void dec_use (struct i2c_client *client)
+// {
+// #ifdef MODULE
+//         MOD_DEC_USE_COUNT;
+// #endif
+// }
 
 static struct i2c_driver saa7113_driver = {
-        "SAA7113",
-        I2C_DRIVERID_SAA7113,
-        I2C_DF_NOTIFY,
-        attach_adapter,
-        detach_client,
-        saa7113_command,
-        inc_use,
-        dec_use,
+	owner:		THIS_MODULE,
+        name:		"SAA7113",
+        id:		I2C_DRIVERID_SAA7113,
+        flags:		I2C_DF_NOTIFY,
+        attach_adapter:	attach_adapter,
+        detach_client:	detach_client,
+        command:	saa7113_command
+/*        inc_use,
+        dec_use, FIXME: should use usage_count in i2c_client? */
 };
 
 static struct i2c_client client_template = {
-        "SAA7113",
-        I2C_DRIVERID_SAA7113,
-        0,
-        (0x4a >> 1),
-        NULL,
-        &saa7113_driver,
-        NULL
+        name:		"SAA7113",
+        id:		I2C_DRIVERID_SAA7113,
+        flags:		0,
+        addr:		(0x4a >> 1),
+        adapter:	NULL,
+        driver:		&saa7113_driver
+//      data:   NULL
 };
 
 


Home | Main Index | Thread Index