Jesse Keating 2f82dd
diff -Naurp a/drivers/media/video/hdpvr/hdpvr-core.c b/drivers/media/video/hdpvr/hdpvr-core.c
Jesse Keating 2f82dd
--- a/drivers/media/video/hdpvr/hdpvr-core.c	2010-07-06 17:36:44.000000000 -0400
Jesse Keating 2f82dd
+++ b/drivers/media/video/hdpvr/hdpvr-core.c	2010-07-06 17:38:13.000000000 -0400
Jesse Keating 2f82dd
@@ -363,9 +363,8 @@ static int hdpvr_probe(struct usb_interf
Jesse Keating 2f82dd
 		goto error;
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-#ifdef CONFIG_I2C
Jesse Keating 2f82dd
-	/* until i2c is working properly */
Jesse Keating 2f82dd
-	retval = 0; /* hdpvr_register_i2c_adapter(dev); */
Jesse Keating 2f82dd
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Jesse Keating 2f82dd
+	retval = hdpvr_register_i2c_adapter(dev);
Jesse Keating 2f82dd
 	if (retval < 0) {
Jesse Keating 2f82dd
 		v4l2_err(&dev->v4l2_dev, "registering i2c adapter failed\n");
Jesse Keating 2f82dd
 		goto error;
Jesse Keating 2f82dd
@@ -411,12 +410,9 @@ static void hdpvr_disconnect(struct usb_
Jesse Keating 2f82dd
 	mutex_unlock(&dev->io_mutex);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	/* deregister I2C adapter */
Jesse Keating 2f82dd
-#ifdef CONFIG_I2C
Jesse Keating 2f82dd
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Jesse Keating 2f82dd
 	mutex_lock(&dev->i2c_mutex);
Jesse Keating 2f82dd
-	if (dev->i2c_adapter)
Jesse Keating 2f82dd
-		i2c_del_adapter(dev->i2c_adapter);
Jesse Keating 2f82dd
-	kfree(dev->i2c_adapter);
Jesse Keating 2f82dd
-	dev->i2c_adapter = NULL;
Jesse Keating 2f82dd
+	i2c_del_adapter(&dev->i2c_adapter);
Jesse Keating 2f82dd
 	mutex_unlock(&dev->i2c_mutex);
Jesse Keating 2f82dd
 #endif /* CONFIG_I2C */
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
diff -Naurp a/drivers/media/video/hdpvr/hdpvr.h b/drivers/media/video/hdpvr/hdpvr.h
Jesse Keating 2f82dd
--- a/drivers/media/video/hdpvr/hdpvr.h	2010-02-24 13:52:17.000000000 -0500
Jesse Keating 2f82dd
+++ b/drivers/media/video/hdpvr/hdpvr.h	2010-07-06 17:42:20.000000000 -0400
Jesse Keating 2f82dd
@@ -101,7 +101,7 @@ struct hdpvr_device {
Jesse Keating 2f82dd
 	struct work_struct	worker;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	/* I2C adapter */
Jesse Keating 2f82dd
-	struct i2c_adapter	*i2c_adapter;
Jesse Keating 2f82dd
+	struct i2c_adapter	i2c_adapter;
Jesse Keating 2f82dd
 	/* I2C lock */
Jesse Keating 2f82dd
 	struct mutex		i2c_mutex;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
diff -Naurp a/drivers/media/video/hdpvr/hdpvr-i2c.c b/drivers/media/video/hdpvr/hdpvr-i2c.c
Jesse Keating 2f82dd
--- a/drivers/media/video/hdpvr/hdpvr-i2c.c	2010-07-06 17:36:51.000000000 -0400
Jesse Keating 2f82dd
+++ b/drivers/media/video/hdpvr/hdpvr-i2c.c	2010-07-06 17:45:50.000000000 -0400
Jesse Keating 2f82dd
@@ -10,6 +10,8 @@
Jesse Keating 2f82dd
  *
Jesse Keating 2f82dd
  */
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 #include <linux i2c.h="">
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 #include "hdpvr.h"
Jesse Keating 2f82dd
@@ -19,10 +21,13 @@
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 #define REQTYPE_I2C_READ	0xb1
Jesse Keating 2f82dd
 #define REQTYPE_I2C_WRITE	0xb0
Jesse Keating 2f82dd
-#define REQTYPE_I2C_WRITE_STATT	0xd0
Jesse Keating 2f82dd
+#define REQTYPE_I2C_WRITE_STAT	0xd0
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+#define HDPVR_HW_Z8F0811_IR_TX_I2C_ADDR	0x70
Jesse Keating 2f82dd
+#define HDPVR_HW_Z8F0811_IR_RX_I2C_ADDR	0x71
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int hdpvr_i2c_read(struct hdpvr_device *dev, unsigned char addr,
Jesse Keating 2f82dd
-			  char *data, int len)
Jesse Keating 2f82dd
+			  char *data, int len, int bus)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int ret;
Jesse Keating 2f82dd
 	char *buf = kmalloc(len, GFP_KERNEL);
Jesse Keating 2f82dd
@@ -32,7 +37,7 @@ static int hdpvr_i2c_read(struct hdpvr_d
Jesse Keating 2f82dd
 	ret = usb_control_msg(dev->udev,
Jesse Keating 2f82dd
 			      usb_rcvctrlpipe(dev->udev, 0),
Jesse Keating 2f82dd
 			      REQTYPE_I2C_READ, CTRL_READ_REQUEST,
Jesse Keating 2f82dd
-			      0x100|addr, 0, buf, len, 1000);
Jesse Keating 2f82dd
+			      bus<<8 | addr, 0, buf, len, 1000);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (ret == len) {
Jesse Keating 2f82dd
 		memcpy(data, buf, len);
Jesse Keating 2f82dd
@@ -46,7 +51,7 @@ static int hdpvr_i2c_read(struct hdpvr_d
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 static int hdpvr_i2c_write(struct hdpvr_device *dev, unsigned char addr,
Jesse Keating 2f82dd
-			   char *data, int len)
Jesse Keating 2f82dd
+			   char *data, int len, int bus)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
 	int ret;
Jesse Keating 2f82dd
 	char *buf = kmalloc(len, GFP_KERNEL);
Jesse Keating 2f82dd
@@ -57,17 +62,17 @@ static int hdpvr_i2c_write(struct hdpvr_
Jesse Keating 2f82dd
 	ret = usb_control_msg(dev->udev,
Jesse Keating 2f82dd
 			      usb_sndctrlpipe(dev->udev, 0),
Jesse Keating 2f82dd
 			      REQTYPE_I2C_WRITE, CTRL_WRITE_REQUEST,
Jesse Keating 2f82dd
-			      0x100|addr, 0, buf, len, 1000);
Jesse Keating 2f82dd
+			      bus<<8 | addr, 0, buf, len, 1000);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	if (ret < 0)
Jesse Keating 2f82dd
 		goto error;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	ret = usb_control_msg(dev->udev,
Jesse Keating 2f82dd
 			      usb_rcvctrlpipe(dev->udev, 0),
Jesse Keating 2f82dd
-			      REQTYPE_I2C_WRITE_STATT, CTRL_READ_REQUEST,
Jesse Keating 2f82dd
+			      REQTYPE_I2C_WRITE_STAT, CTRL_READ_REQUEST,
Jesse Keating 2f82dd
 			      0, 0, buf, 2, 1000);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	if (ret == 2)
Jesse Keating 2f82dd
+	if (ret == 2 && buf[1] == (len - 1))
Jesse Keating 2f82dd
 		ret = 0;
Jesse Keating 2f82dd
 	else if (ret >= 0)
Jesse Keating 2f82dd
 		ret = -EIO;
Jesse Keating 2f82dd
@@ -93,10 +98,10 @@ static int hdpvr_transfer(struct i2c_ada
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 		if (msgs[i].flags & I2C_M_RD)
Jesse Keating 2f82dd
 			retval = hdpvr_i2c_read(dev, addr, msgs[i].buf,
Jesse Keating 2f82dd
-						msgs[i].len);
Jesse Keating 2f82dd
+						msgs[i].len, 1);
Jesse Keating 2f82dd
 		else
Jesse Keating 2f82dd
 			retval = hdpvr_i2c_write(dev, addr, msgs[i].buf,
Jesse Keating 2f82dd
-						 msgs[i].len);
Jesse Keating 2f82dd
+						 msgs[i].len, 1);
Jesse Keating 2f82dd
 	}
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 	mutex_unlock(&dev->i2c_mutex);
Jesse Keating 2f82dd
@@ -114,31 +119,61 @@ static struct i2c_algorithm hdpvr_algo =
Jesse Keating 2f82dd
 	.functionality = hdpvr_functionality,
Jesse Keating 2f82dd
 };
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
+static struct i2c_adapter hdpvr_i2c_adap_template = {
Jesse Keating 2f82dd
+	.name		= "Hauppauge HD PVR I2C",
Jesse Keating 2f82dd
+	.owner		= THIS_MODULE,
Jesse Keating 2f82dd
+	.id		= I2C_HW_B_HDPVR,
Jesse Keating 2f82dd
+	.algo		= &hdpvr_algo,
Jesse Keating 2f82dd
+	.algo_data	= NULL,
Jesse Keating 2f82dd
+	.class		= I2C_CLASS_TV_ANALOG,
Jesse Keating 2f82dd
+};
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static struct i2c_board_info hdpvr_i2c_board_info = {
Jesse Keating 2f82dd
+	I2C_BOARD_INFO("ir_tx_z8f0811_haup", HDPVR_HW_Z8F0811_IR_TX_I2C_ADDR),
Jesse Keating 2f82dd
+	I2C_BOARD_INFO("ir_rx_z8f0811_haup", HDPVR_HW_Z8F0811_IR_RX_I2C_ADDR),
Jesse Keating 2f82dd
+};
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+static int hdpvr_activate_ir(struct hdpvr_device *dev)
Jesse Keating 2f82dd
+{
Jesse Keating 2f82dd
+	char buffer[8];
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	mutex_lock(&dev->i2c_mutex);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	hdpvr_i2c_read(dev, 0x54, buffer, 1, 0);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	buffer[0] = 0;
Jesse Keating 2f82dd
+	buffer[1] = 0x8;
Jesse Keating 2f82dd
+	hdpvr_i2c_write(dev, 0x54, buffer, 2, 1);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	buffer[1] = 0x18;
Jesse Keating 2f82dd
+	hdpvr_i2c_write(dev, 0x54, buffer, 2, 1);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	mutex_unlock(&dev->i2c_mutex);
Jesse Keating 2f82dd
+	return 0;
Jesse Keating 2f82dd
+}
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
 int hdpvr_register_i2c_adapter(struct hdpvr_device *dev)
Jesse Keating 2f82dd
 {
Jesse Keating 2f82dd
-	struct i2c_adapter *i2c_adap;
Jesse Keating 2f82dd
 	int retval = -ENOMEM;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	i2c_adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
Jesse Keating 2f82dd
-	if (i2c_adap == NULL)
Jesse Keating 2f82dd
+	hdpvr_activate_ir(dev);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	memcpy(&dev->i2c_adapter, &hdpvr_i2c_adap_template,
Jesse Keating 2f82dd
+	       sizeof(struct i2c_adapter));
Jesse Keating 2f82dd
+	dev->i2c_adapter.dev.parent = &dev->udev->dev;
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	i2c_set_adapdata(&dev->i2c_adapter, dev);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	retval = i2c_add_adapter(&dev->i2c_adapter);
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+	if (retval)
Jesse Keating 2f82dd
 		goto error;
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
-	strlcpy(i2c_adap->name, "Hauppauge HD PVR I2C",
Jesse Keating 2f82dd
-		sizeof(i2c_adap->name));
Jesse Keating 2f82dd
-	i2c_adap->algo  = &hdpvr_algo;
Jesse Keating 2f82dd
-	i2c_adap->class = I2C_CLASS_TV_ANALOG;
Jesse Keating 2f82dd
-	i2c_adap->owner = THIS_MODULE;
Jesse Keating 2f82dd
-	i2c_adap->dev.parent = &dev->udev->dev;
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	i2c_set_adapdata(i2c_adap, dev);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	retval = i2c_add_adapter(i2c_adap);
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-	if (!retval)
Jesse Keating 2f82dd
-		dev->i2c_adapter = i2c_adap;
Jesse Keating 2f82dd
-	else
Jesse Keating 2f82dd
-		kfree(i2c_adap);
Jesse Keating 2f82dd
+	i2c_new_device(&dev->i2c_adapter, &hdpvr_i2c_board_info);
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 error:
Jesse Keating 2f82dd
 	return retval;
Jesse Keating 2f82dd
 }
Jesse Keating 2f82dd
+
Jesse Keating 2f82dd
+#endif /* CONFIG_I2C */
Jesse Keating 2f82dd
diff -Naurp a/drivers/media/video/hdpvr/Makefile b/drivers/media/video/hdpvr/Makefile
Jesse Keating 2f82dd
--- a/drivers/media/video/hdpvr/Makefile	2010-07-06 17:36:38.000000000 -0400
Jesse Keating 2f82dd
+++ b/drivers/media/video/hdpvr/Makefile	2010-07-06 17:35:17.000000000 -0400
Jesse Keating 2f82dd
@@ -1,6 +1,4 @@
Jesse Keating 2f82dd
-hdpvr-objs	:= hdpvr-control.o hdpvr-core.o hdpvr-video.o
Jesse Keating 2f82dd
-
Jesse Keating 2f82dd
-hdpvr-$(CONFIG_I2C) += hdpvr-i2c.o
Jesse Keating 2f82dd
+hdpvr-objs	:= hdpvr-control.o hdpvr-core.o hdpvr-i2c.o hdpvr-video.o
Jesse Keating 2f82dd
 
Jesse Keating 2f82dd
 obj-$(CONFIG_VIDEO_HDPVR) += hdpvr.o
Jesse Keating 2f82dd