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