aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/hdpvr/hdpvr-i2c.c
diff options
context:
space:
mode:
authorJanne Grunau <j@jannau.net>2009-03-18 17:10:04 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:43:28 -0400
commit9aba42efe85bc7a55e3fed0747ce14abc9ee96e7 (patch)
treeee27b9d4844da17b4d4bb80132991f29d04ff265 /drivers/media/video/hdpvr/hdpvr-i2c.c
parent8c84cfda3e37540abc38f42383b03dd69829faee (diff)
V4L/DVB (11096): V4L2 Driver for the Hauppauge HD PVR usb capture device
The device encodes component video up to 1080i to a MPEG-TS stream with H.264 video and stereo AAC audio. Newer firmwares accept also AC3 (up to 5.1) audio over optical SPDIF without reencoding. Firmware upgrade is unimplemeted but rather unimportant since the firmware sits on a flash chip. The I2C adapter to drive the integrated infrared receiver/sender is currently disabled due to a conflict with cx18-based devices. Tested-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Janne Grunau <j@jannau.net> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/hdpvr/hdpvr-i2c.c')
-rw-r--r--drivers/media/video/hdpvr/hdpvr-i2c.c145
1 files changed, 145 insertions, 0 deletions
diff --git a/drivers/media/video/hdpvr/hdpvr-i2c.c b/drivers/media/video/hdpvr/hdpvr-i2c.c
new file mode 100644
index 000000000000..35096dec2411
--- /dev/null
+++ b/drivers/media/video/hdpvr/hdpvr-i2c.c
@@ -0,0 +1,145 @@
1
2/*
3 * Hauppage HD PVR USB driver
4 *
5 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
10 *
11 */
12
13#include <linux/i2c.h>
14
15#include "hdpvr.h"
16
17#define CTRL_READ_REQUEST 0xb8
18#define CTRL_WRITE_REQUEST 0x38
19
20#define REQTYPE_I2C_READ 0xb1
21#define REQTYPE_I2C_WRITE 0xb0
22#define REQTYPE_I2C_WRITE_STATT 0xd0
23
24static int hdpvr_i2c_read(struct hdpvr_device *dev, unsigned char addr,
25 char *data, int len)
26{
27 int ret;
28 char *buf = kmalloc(len, GFP_KERNEL);
29 if (!buf)
30 return -ENOMEM;
31
32 ret = usb_control_msg(dev->udev,
33 usb_rcvctrlpipe(dev->udev, 0),
34 REQTYPE_I2C_READ, CTRL_READ_REQUEST,
35 0x100|addr, 0, buf, len, 1000);
36
37 if (ret == len) {
38 memcpy(data, buf, len);
39 ret = 0;
40 } else if (ret >= 0)
41 ret = -EIO;
42
43 kfree(buf);
44
45 return ret;
46}
47
48static int hdpvr_i2c_write(struct hdpvr_device *dev, unsigned char addr,
49 char *data, int len)
50{
51 int ret;
52 char *buf = kmalloc(len, GFP_KERNEL);
53 if (!buf)
54 return -ENOMEM;
55
56 memcpy(buf, data, len);
57 ret = usb_control_msg(dev->udev,
58 usb_sndctrlpipe(dev->udev, 0),
59 REQTYPE_I2C_WRITE, CTRL_WRITE_REQUEST,
60 0x100|addr, 0, buf, len, 1000);
61
62 if (ret < 0)
63 goto error;
64
65 ret = usb_control_msg(dev->udev,
66 usb_rcvctrlpipe(dev->udev, 0),
67 REQTYPE_I2C_WRITE_STATT, CTRL_READ_REQUEST,
68 0, 0, buf, 2, 1000);
69
70 if (ret == 2)
71 ret = 0;
72 else if (ret >= 0)
73 ret = -EIO;
74
75error:
76 kfree(buf);
77 return ret;
78}
79
80static int hdpvr_transfer(struct i2c_adapter *i2c_adapter, struct i2c_msg *msgs,
81 int num)
82{
83 struct hdpvr_device *dev = i2c_get_adapdata(i2c_adapter);
84 int retval = 0, i, addr;
85
86 if (num <= 0)
87 return 0;
88
89 mutex_lock(&dev->i2c_mutex);
90
91 for (i = 0; i < num && !retval; i++) {
92 addr = msgs[i].addr << 1;
93
94 if (msgs[i].flags & I2C_M_RD)
95 retval = hdpvr_i2c_read(dev, addr, msgs[i].buf,
96 msgs[i].len);
97 else
98 retval = hdpvr_i2c_write(dev, addr, msgs[i].buf,
99 msgs[i].len);
100 }
101
102 mutex_unlock(&dev->i2c_mutex);
103
104 return retval ? retval : num;
105}
106
107static u32 hdpvr_functionality(struct i2c_adapter *adapter)
108{
109 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
110}
111
112static struct i2c_algorithm hdpvr_algo = {
113 .master_xfer = hdpvr_transfer,
114 .functionality = hdpvr_functionality,
115};
116
117int hdpvr_register_i2c_adapter(struct hdpvr_device *dev)
118{
119 struct i2c_adapter *i2c_adap;
120 int retval = -ENOMEM;
121
122 i2c_adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
123 if (i2c_adap == NULL)
124 goto error;
125
126 strlcpy(i2c_adap->name, "Hauppauge HD PVR I2C",
127 sizeof(i2c_adap->name));
128 i2c_adap->algo = &hdpvr_algo;
129 i2c_adap->class = I2C_CLASS_TV_ANALOG;
130 i2c_adap->id = I2C_HW_B_HDPVR;
131 i2c_adap->owner = THIS_MODULE;
132 i2c_adap->dev.parent = &dev->udev->dev;
133
134 i2c_set_adapdata(i2c_adap, dev);
135
136 retval = i2c_add_adapter(i2c_adap);
137
138 if (!retval)
139 dev->i2c_adapter = i2c_adap;
140 else
141 kfree(i2c_adap);
142
143error:
144 return retval;
145}