aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/au0828/au0828-core.c
diff options
context:
space:
mode:
authorSteven Toth <stoth@hauppauge.com>2008-04-18 20:34:00 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-04-24 13:09:42 -0400
commit265a6510629ab39f33ece43a857089dd37978184 (patch)
tree021773e15d68f7d99c571d723a48397ae9cf9ef5 /drivers/media/video/au0828/au0828-core.c
parentc8234ea37fb8b7a904223672edf36d269ea569a2 (diff)
V4L/DVB (7621): Add support for Hauppauge HVR950Q/HVR850/FusioHDTV7-USB
Including support for the AU0828 USB Bridge. Including support for the AU8522 ATSC/QAM Demodulator. Including support for the AU8522 ATSC/QAM Demodulator. Signed-off-by: Steven Toth <stoth@hauppauge.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/au0828/au0828-core.c')
-rw-r--r--drivers/media/video/au0828/au0828-core.c252
1 files changed, 252 insertions, 0 deletions
diff --git a/drivers/media/video/au0828/au0828-core.c b/drivers/media/video/au0828/au0828-core.c
new file mode 100644
index 00000000000..8d0b8a8b06b
--- /dev/null
+++ b/drivers/media/video/au0828/au0828-core.c
@@ -0,0 +1,252 @@
1/*
2 * Driver for the Auvitek USB bridge
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/videodev2.h>
24#include <media/v4l2-common.h>
25#include <linux/mutex.h>
26
27#include "au0828.h"
28
29static unsigned int debug;
30module_param(debug, int, 0644);
31MODULE_PARM_DESC(debug, "enable debug messages");
32
33#define _err(fmt, arg...)\
34 do {\
35 printk(KERN_ERR DRIVER_NAME "/0: " fmt, ## arg);\
36 } while (0)
37
38#define _info(fmt, arg...)\
39 do {\
40 printk(KERN_INFO DRIVER_NAME "/0: " fmt, ## arg);\
41 } while (0)
42
43#define _dbg(level, fmt, arg...)\
44 do {\
45 if (debug >= level) \
46 printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\
47 } while (0)
48
49#define _AU0828_BULKPIPE 0x03
50#define _BULKPIPESIZE 0xffff
51
52static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value,
53 u16 index, unsigned char *cp, u16 size);
54static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value,
55 u16 index, unsigned char *cp, u16 size);
56
57/* USB Direction */
58#define CMD_REQUEST_IN 0x00
59#define CMD_REQUEST_OUT 0x01
60
61u32 au0828_readreg(struct au0828_dev *dev, u16 reg)
62{
63 recv_control_msg(dev, CMD_REQUEST_IN, 0, reg, dev->ctrlmsg, 1);
64 _dbg(3,"%s(0x%x) = 0x%x\n", __FUNCTION__, reg, dev->ctrlmsg[0]);
65 return dev->ctrlmsg[0];
66}
67
68u32 au0828_writereg(struct au0828_dev *dev, u16 reg, u32 val)
69{
70 _dbg(3,"%s(0x%x, 0x%x)\n", __FUNCTION__, reg, val);
71 return send_control_msg(dev, CMD_REQUEST_OUT, val, reg, dev->ctrlmsg, 0);
72}
73
74static void cmd_msg_dump(struct au0828_dev *dev)
75{
76 int i;
77
78 for (i = 0;i < sizeof(dev->ctrlmsg); i+=16)
79 _dbg(1,"%s() %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x "
80 "%02x %02x %02x %02x %02x %02x\n",
81 __FUNCTION__,
82 dev->ctrlmsg[i+0], dev->ctrlmsg[i+1],
83 dev->ctrlmsg[i+2], dev->ctrlmsg[i+3],
84 dev->ctrlmsg[i+4], dev->ctrlmsg[i+5],
85 dev->ctrlmsg[i+6], dev->ctrlmsg[i+7],
86 dev->ctrlmsg[i+8], dev->ctrlmsg[i+9],
87 dev->ctrlmsg[i+10], dev->ctrlmsg[i+11],
88 dev->ctrlmsg[i+12], dev->ctrlmsg[i+13],
89 dev->ctrlmsg[i+14], dev->ctrlmsg[i+15]);
90}
91
92static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value,
93 u16 index, unsigned char *cp, u16 size)
94{
95 int status = -ENODEV;
96 mutex_lock(&dev->mutex);
97 if (dev->usbdev) {
98
99 /* cp must be memory that has been allocated by kmalloc */
100 status = usb_control_msg(dev->usbdev,
101 usb_sndctrlpipe(dev->usbdev, 0),
102 request,
103 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
104 value, index,
105 cp, size, 1000);
106
107 status = min(status, 0);
108
109 if (status < 0) {
110 _err("%s() Failed sending control message, error %d.\n",
111 __FUNCTION__,
112 status);
113 }
114
115 }
116 mutex_unlock(&dev->mutex);
117 return status;
118}
119
120static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value,
121 u16 index, unsigned char *cp, u16 size)
122{
123 int status = -ENODEV;
124 mutex_lock(&dev->mutex);
125 if (dev->usbdev) {
126
127 memset(dev->ctrlmsg, 0, sizeof(dev->ctrlmsg));
128
129 /* cp must be memory that has been allocated by kmalloc */
130 status = usb_control_msg(dev->usbdev,
131 usb_rcvctrlpipe(dev->usbdev, 0),
132 request,
133 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
134 value, index,
135 cp, size, 1000);
136
137 status = min(status, 0);
138
139 if (status < 0) {
140 _err("%s() Failed receiving ctrl msg, error %d.\n",
141 __FUNCTION__,
142 status);
143 }
144 else
145 if (debug > 4)
146 cmd_msg_dump(dev);
147 }
148 mutex_unlock(&dev->mutex);
149 return status;
150}
151static void au0828_usb_disconnect(struct usb_interface *interface)
152{
153 struct au0828_dev *dev = usb_get_intfdata(interface);
154
155 _dbg(1,"%s()\n", __FUNCTION__);
156
157 /* Digital TV */
158 au0828_dvb_unregister(dev);
159
160 /* I2C */
161 au0828_i2c_unregister(dev);
162
163 usb_set_intfdata(interface, NULL);
164
165 mutex_lock(&dev->mutex);
166 dev->usbdev = NULL;
167 mutex_unlock(&dev->mutex);
168
169 kfree(dev);
170
171}
172
173static int au0828_usb_probe (struct usb_interface *interface,
174 const struct usb_device_id *id)
175{
176 int ifnum;
177 struct au0828_dev *dev;
178 struct usb_device *usbdev = interface_to_usbdev(interface);
179
180 ifnum = interface->altsetting->desc.bInterfaceNumber;
181
182 if (ifnum != 0)
183 return -ENODEV;
184
185 _dbg(1,"%s() vendor id 0x%x device id 0x%x ifnum:%d\n",
186 __FUNCTION__,
187 le16_to_cpu(usbdev->descriptor.idVendor),
188 le16_to_cpu(usbdev->descriptor.idProduct),
189 ifnum);
190
191 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
192 if (dev == NULL) {
193 _err("Unable to allocate memory\n");
194 return -ENOMEM;
195 }
196
197 mutex_init(&dev->mutex);
198 mutex_init(&dev->dvb.lock);
199 dev->usbdev = usbdev;
200 dev->board = id->driver_info;
201
202 usb_set_intfdata(interface, dev);
203
204 /* Power Up the bridge */
205 au0828_write(dev, REG_600, 1 << 4);
206
207 /* Bring up the GPIO's and supporting devices */
208 au0828_gpio_setup(dev);
209
210 /* I2C */
211 au0828_i2c_register(dev);
212
213 /* Digital TV */
214 au0828_dvb_register(dev);
215
216 _info("Registered device AU0828 [%s]\n",
217 au0828_boards[dev->board].name);
218
219 return 0;
220}
221
222static struct usb_driver au0828_usb_driver = {
223 .name = DRIVER_NAME,
224 .probe = au0828_usb_probe,
225 .disconnect = au0828_usb_disconnect,
226 .id_table = au0828_usb_id_table,
227};
228
229static int __init au0828_init(void)
230{
231 int ret;
232
233 _info("au0828 driver loaded\n");
234
235 ret = usb_register(&au0828_usb_driver);
236 if (ret)
237 _err("usb_register failed, error = %d\n", ret);
238
239 return ret;
240}
241
242static void __exit au0828_exit(void)
243{
244 usb_deregister(&au0828_usb_driver);
245}
246
247module_init(au0828_init);
248module_exit(au0828_exit);
249
250MODULE_DESCRIPTION("Driver for Auvitek AU0828 based products");
251MODULE_AUTHOR("Steven Toth <stoth@hauppauge.com>");
252MODULE_LICENSE("GPL");