Mailing List archive

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

[linux-dvb] [PATCH] kernel i2c driver for skystar2



Hi,

This patch allows the skystar2 driver to work with
frontends which are converted to use kernel I2C (stv0299).
Please apply.

Regards,
Vadim Catana
? skystar2.patch
Index: linux/drivers/media/dvb/b2c2/skystar2.c
===================================================================
RCS file: /cvs/linuxtv/dvb-kernel/linux/drivers/media/dvb/b2c2/skystar2.c,v
retrieving revision 1.29
diff -p -u -r1.29 skystar2.c
--- linux/drivers/media/dvb/b2c2/skystar2.c	31 Mar 2004 09:55:31 -0000	1.29
+++ linux/drivers/media/dvb/b2c2/skystar2.c	7 Jun 2004 06:52:40 -0000
@@ -35,6 +35,7 @@
 #include <linux/delay.h>
 #include <linux/pci.h>
 #include <linux/init.h>
+#include <linux/version.h>
 
 #include <asm/io.h>
 
@@ -91,6 +92,7 @@ struct adapter {
 	struct dmx_frontend hw_frontend;
 	struct dmx_frontend mem_frontend;
 	struct dvb_i2c_bus *i2c_bus;
+	struct i2c_adapter i2c_adap;	
 	struct dvb_net dvbnet;
 
 	struct semaphore i2c_sem;
@@ -2229,6 +2231,49 @@ static int flexcop_diseqc_ioctl(struct d
 	return 0;
 }
 
+
+int client_register(struct i2c_client *client)
+{
+	struct adapter *adapter = (struct adapter*)i2c_get_adapdata(client->adapter);
+
+	dprintk("client_register\n");
+
+	return client->driver->command(client, FE_REGISTER, adapter->dvb_adapter);
+}
+
+int client_unregister(struct i2c_client *client)
+{
+	struct adapter *adapter = (struct adapter*)i2c_get_adapdata(client->adapter);
+
+	dprintk("client_unregister\n");
+
+	return client->driver->command(client, FE_UNREGISTER, adapter->dvb_adapter);
+}
+
+static int flexcop_i2c_xfer(struct i2c_adapter *i2c_adapter, struct i2c_msg msg[], int num)
+{
+	struct adapter *adapter = i2c_get_adapdata(i2c_adapter);
+
+	dprintk("flexcop_i2c_xfer\n");
+
+	return master_xfer(adapter->i2c_bus, msg, num);
+}
+
+u32 flexcop_i2c_func(struct i2c_adapter *adapter)
+{
+	printk("flexcop_i2c_func\n");
+
+	return I2C_FUNC_I2C;
+}
+
+static struct i2c_algorithm    flexcop_algo = {
+	.name		= "flexcop i2c algorithm",
+	.id		= I2C_ALGO_BIT,
+	.master_xfer	= flexcop_i2c_xfer,
+	.functionality	= flexcop_i2c_func,
+};
+
+
 static int skystar2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct adapter *adapter;
@@ -2259,10 +2304,42 @@ static int skystar2_probe(struct pci_dev
 
 	init_MUTEX(&adapter->i2c_sem);
 
+
+	memset(&adapter->i2c_adap, 0, sizeof(struct i2c_adapter));
+	strcpy(adapter->i2c_adap.name, "Technisat SkyStar2 driver");
+
+#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) )
+	adapter->i2c_adap.data = adapter;
+#else
+	i2c_set_adapdata(&adapter->i2c_adap, adapter);
+
+	#ifdef I2C_ADAP_CLASS_TV_DIGITAL
+	adapter->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL;
+	#else
+	adapter->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
+	#endif
+
+#endif
+	adapter->i2c_adap.algo              = &flexcop_algo;
+	adapter->i2c_adap.algo_data         = NULL;
+	adapter->i2c_adap.id                = I2C_ALGO_BIT;
+	adapter->i2c_adap.client_register   = client_register;
+	adapter->i2c_adap.client_unregister = client_unregister;
+
+
 	adapter->i2c_bus = dvb_register_i2c_bus(master_xfer, adapter, adapter->dvb_adapter, 0);
 
-	if (!adapter->i2c_bus)
+	if (!adapter->i2c_bus) {
+		dvb_unregister_adapter (adapter->dvb_adapter);
+		return -ENOMEM;
+	}
+
+
+	if (i2c_add_adapter(&adapter->i2c_adap) < 0) {
+		dvb_unregister_i2c_bus (master_xfer, adapter->i2c_bus->adapter, adapter->i2c_bus->id);
+		dvb_unregister_adapter (adapter->dvb_adapter);
 		return -ENOMEM;
+	}
 
 	dvb_add_frontend_ioctls(adapter->dvb_adapter, flexcop_diseqc_ioctl, NULL, adapter);
 
@@ -2328,6 +2405,8 @@ static void skystar2_remove(struct pci_d
 		if (adapter->dvb_adapter != NULL) {
 			dvb_remove_frontend_ioctls(adapter->dvb_adapter, flexcop_diseqc_ioctl, NULL);
 
+			i2c_del_adapter(&adapter->i2c_adap);
+
 			if (adapter->i2c_bus != NULL)
 				dvb_unregister_i2c_bus(master_xfer, adapter->i2c_bus->adapter, adapter->i2c_bus->id);
 

Home | Main Index | Thread Index