diff options
author | Steven Toth <stoth@hauppauge.com> | 2008-04-18 20:34:00 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-04-24 13:09:42 -0400 |
commit | 265a6510629ab39f33ece43a857089dd37978184 (patch) | |
tree | 021773e15d68f7d99c571d723a48397ae9cf9ef5 /drivers/media/video | |
parent | c8234ea37fb8b7a904223672edf36d269ea569a2 (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')
-rw-r--r-- | drivers/media/video/Kconfig | 2 | ||||
-rw-r--r-- | drivers/media/video/Makefile | 2 | ||||
-rw-r--r-- | drivers/media/video/au0828/Kconfig | 10 | ||||
-rw-r--r-- | drivers/media/video/au0828/Makefile | 9 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-cards.c | 144 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-cards.h | 25 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-core.c | 252 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-dvb.c | 371 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-i2c.c | 402 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-reg.h | 35 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828.h | 117 |
11 files changed, 1369 insertions, 0 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index 54b9f84e9a3e..fe9a4cc14141 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig | |||
@@ -698,6 +698,8 @@ source "drivers/media/video/cx88/Kconfig" | |||
698 | 698 | ||
699 | source "drivers/media/video/cx23885/Kconfig" | 699 | source "drivers/media/video/cx23885/Kconfig" |
700 | 700 | ||
701 | source "drivers/media/video/au0828/Kconfig" | ||
702 | |||
701 | source "drivers/media/video/ivtv/Kconfig" | 703 | source "drivers/media/video/ivtv/Kconfig" |
702 | 704 | ||
703 | config VIDEO_M32R_AR | 705 | config VIDEO_M32R_AR |
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index fe3be94afd10..be14227f3726 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile | |||
@@ -143,5 +143,7 @@ obj-$(CONFIG_SOC_CAMERA) += soc_camera.o | |||
143 | obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o | 143 | obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o |
144 | obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o | 144 | obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o |
145 | 145 | ||
146 | obj-$(CONFIG_VIDEO_AU0828) += au0828/ | ||
147 | |||
146 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core | 148 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core |
147 | EXTRA_CFLAGS += -Idrivers/media/dvb/frontends | 149 | EXTRA_CFLAGS += -Idrivers/media/dvb/frontends |
diff --git a/drivers/media/video/au0828/Kconfig b/drivers/media/video/au0828/Kconfig new file mode 100644 index 000000000000..38d68ee8026a --- /dev/null +++ b/drivers/media/video/au0828/Kconfig | |||
@@ -0,0 +1,10 @@ | |||
1 | |||
2 | config VIDEO_AU0828 | ||
3 | tristate "Auvitek AU0828 support" | ||
4 | depends on VIDEO_DEV && I2C && INPUT | ||
5 | select I2C_ALGOBIT | ||
6 | ---help--- | ||
7 | This is a video4linux driver for Auvitek's USB device. | ||
8 | |||
9 | To compile this driver as a module, choose M here: the | ||
10 | module will be called ambarella | ||
diff --git a/drivers/media/video/au0828/Makefile b/drivers/media/video/au0828/Makefile new file mode 100644 index 000000000000..9f4f572c89c5 --- /dev/null +++ b/drivers/media/video/au0828/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o | ||
2 | |||
3 | obj-$(CONFIG_VIDEO_AU0828) += au0828.o | ||
4 | |||
5 | EXTRA_CFLAGS += -Idrivers/media/video | ||
6 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core | ||
7 | EXTRA_CFLAGS += -Idrivers/media/dvb/frontends | ||
8 | |||
9 | EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m) | ||
diff --git a/drivers/media/video/au0828/au0828-cards.c b/drivers/media/video/au0828/au0828-cards.c new file mode 100644 index 000000000000..c4cb11e9d6fc --- /dev/null +++ b/drivers/media/video/au0828/au0828-cards.c | |||
@@ -0,0 +1,144 @@ | |||
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 "au0828.h" | ||
23 | #include "au0828-cards.h" | ||
24 | |||
25 | #define _dbg(level, fmt, arg...)\ | ||
26 | do {\ | ||
27 | if (debug >= level) \ | ||
28 | printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\ | ||
29 | } while (0) | ||
30 | |||
31 | struct au0828_board au0828_boards[] = { | ||
32 | [AU0828_BOARD_UNKNOWN] = { | ||
33 | .name = "Unknown board", | ||
34 | }, | ||
35 | [AU0828_BOARD_HAUPPAUGE_HVR850] = { | ||
36 | .name = "Hauppauge HVR850", | ||
37 | }, | ||
38 | [AU0828_BOARD_HAUPPAUGE_HVR950Q] = { | ||
39 | .name = "Hauppauge HVR950Q", | ||
40 | }, | ||
41 | [AU0828_BOARD_DVICO_FUSIONHDTV7] = { | ||
42 | .name = "DViCO FusionHDTV USB", | ||
43 | }, | ||
44 | }; | ||
45 | const unsigned int au0828_bcount = ARRAY_SIZE(au0828_boards); | ||
46 | |||
47 | /* Tuner callback function for au0828 boards. Currently only needed | ||
48 | * for HVR1500Q, which has an xc5000 tuner. | ||
49 | */ | ||
50 | int au0828_tuner_callback(void *priv, int command, int arg) | ||
51 | { | ||
52 | struct au0828_dev *dev = priv; | ||
53 | |||
54 | switch(dev->board) { | ||
55 | case AU0828_BOARD_HAUPPAUGE_HVR850: | ||
56 | case AU0828_BOARD_HAUPPAUGE_HVR950Q: | ||
57 | case AU0828_BOARD_DVICO_FUSIONHDTV7: | ||
58 | if(command == 0) { | ||
59 | /* Tuner Reset Command from xc5000 */ | ||
60 | /* Drive the tuner into reset and out */ | ||
61 | au0828_clear(dev, REG_001, 2); | ||
62 | mdelay(200); | ||
63 | au0828_set(dev, REG_001, 2); | ||
64 | mdelay(50); | ||
65 | return 0; | ||
66 | } | ||
67 | else { | ||
68 | printk(KERN_ERR | ||
69 | "%s(): Unknown command.\n", __FUNCTION__); | ||
70 | return -EINVAL; | ||
71 | } | ||
72 | break; | ||
73 | } | ||
74 | |||
75 | return 0; /* Should never be here */ | ||
76 | } | ||
77 | |||
78 | /* | ||
79 | * The bridge has between 8 and 12 gpios. | ||
80 | * Regs 1 and 0 deal with output enables. | ||
81 | * Regs 3 and 2 * deal with direction. | ||
82 | */ | ||
83 | void au0828_gpio_setup(struct au0828_dev *dev) | ||
84 | { | ||
85 | switch(dev->board) { | ||
86 | case AU0828_BOARD_HAUPPAUGE_HVR850: | ||
87 | case AU0828_BOARD_HAUPPAUGE_HVR950Q: | ||
88 | /* GPIO's | ||
89 | * 4 - CS5340 | ||
90 | * 5 - AU8522 Demodulator | ||
91 | * 6 - eeprom W/P | ||
92 | * 9 - XC5000 Tuner | ||
93 | */ | ||
94 | |||
95 | /* Into reset */ | ||
96 | au0828_write(dev, REG_003, 0x02); | ||
97 | au0828_write(dev, REG_002, 0x88 | 0x20); | ||
98 | au0828_write(dev, REG_001, 0x0); | ||
99 | au0828_write(dev, REG_000, 0x0); | ||
100 | msleep(100); | ||
101 | |||
102 | /* Out of reset */ | ||
103 | au0828_write(dev, REG_003, 0x02); | ||
104 | au0828_write(dev, REG_001, 0x02); | ||
105 | au0828_write(dev, REG_002, 0x88 | 0x20); | ||
106 | au0828_write(dev, REG_000, 0x88 | 0x20 | 0x40); | ||
107 | msleep(250); | ||
108 | break; | ||
109 | case AU0828_BOARD_DVICO_FUSIONHDTV7: | ||
110 | /* GPIO's | ||
111 | * 6 - ? | ||
112 | * 8 - AU8522 Demodulator | ||
113 | * 9 - XC5000 Tuner | ||
114 | */ | ||
115 | |||
116 | /* Into reset */ | ||
117 | au0828_write(dev, REG_003, 0x02); | ||
118 | au0828_write(dev, REG_002, 0xa0); | ||
119 | au0828_write(dev, REG_001, 0x0); | ||
120 | au0828_write(dev, REG_000, 0x0); | ||
121 | msleep(100); | ||
122 | |||
123 | /* Out of reset */ | ||
124 | au0828_write(dev, REG_003, 0x02); | ||
125 | au0828_write(dev, REG_002, 0xa0); | ||
126 | au0828_write(dev, REG_001, 0x02); | ||
127 | au0828_write(dev, REG_000, 0xa0); | ||
128 | msleep(250); | ||
129 | break; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | /* table of devices that work with this driver */ | ||
134 | struct usb_device_id au0828_usb_id_table [] = { | ||
135 | { USB_DEVICE(0x2040, 0x7200), | ||
136 | .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q }, | ||
137 | { USB_DEVICE(0x2040, 0x7240), | ||
138 | .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 }, | ||
139 | { USB_DEVICE(0x0fe9, 0xd620), | ||
140 | .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 }, | ||
141 | { }, | ||
142 | }; | ||
143 | |||
144 | MODULE_DEVICE_TABLE(usb, au0828_usb_id_table); | ||
diff --git a/drivers/media/video/au0828/au0828-cards.h b/drivers/media/video/au0828/au0828-cards.h new file mode 100644 index 000000000000..e26f54a961d0 --- /dev/null +++ b/drivers/media/video/au0828/au0828-cards.h | |||
@@ -0,0 +1,25 @@ | |||
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 | #define AU0828_BOARD_UNKNOWN 0 | ||
23 | #define AU0828_BOARD_HAUPPAUGE_HVR950Q 1 | ||
24 | #define AU0828_BOARD_HAUPPAUGE_HVR850 2 | ||
25 | #define AU0828_BOARD_DVICO_FUSIONHDTV7 3 | ||
diff --git a/drivers/media/video/au0828/au0828-core.c b/drivers/media/video/au0828/au0828-core.c new file mode 100644 index 000000000000..8d0b8a8b06bd --- /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 | |||
29 | static unsigned int debug; | ||
30 | module_param(debug, int, 0644); | ||
31 | MODULE_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 | |||
52 | static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value, | ||
53 | u16 index, unsigned char *cp, u16 size); | ||
54 | static 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 | |||
61 | u32 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 | |||
68 | u32 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 | |||
74 | static 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 | |||
92 | static 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 | |||
120 | static 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 | } | ||
151 | static 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 | |||
173 | static 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 | |||
222 | static 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 | |||
229 | static 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 | |||
242 | static void __exit au0828_exit(void) | ||
243 | { | ||
244 | usb_deregister(&au0828_usb_driver); | ||
245 | } | ||
246 | |||
247 | module_init(au0828_init); | ||
248 | module_exit(au0828_exit); | ||
249 | |||
250 | MODULE_DESCRIPTION("Driver for Auvitek AU0828 based products"); | ||
251 | MODULE_AUTHOR("Steven Toth <stoth@hauppauge.com>"); | ||
252 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/video/au0828/au0828-dvb.c b/drivers/media/video/au0828/au0828-dvb.c new file mode 100644 index 000000000000..3c8a29eafc2d --- /dev/null +++ b/drivers/media/video/au0828/au0828-dvb.c | |||
@@ -0,0 +1,371 @@ | |||
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/init.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/suspend.h> | ||
26 | #include <media/v4l2-common.h> | ||
27 | |||
28 | #include "au0828.h" | ||
29 | |||
30 | #include "au8522.h" | ||
31 | #include "xc5000.h" | ||
32 | |||
33 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | ||
34 | |||
35 | unsigned int dvb_debug = 1; | ||
36 | |||
37 | #define _dbg(level, fmt, arg...)\ | ||
38 | do { if (dvb_debug >= level)\ | ||
39 | printk(KERN_DEBUG "%s/0: " fmt, DRIVER_NAME, ## arg);\ | ||
40 | } while (0) | ||
41 | |||
42 | static struct au8522_config hauppauge_hvr950q_config = { | ||
43 | .demod_address = 0x8e >> 1, | ||
44 | .status_mode = AU8522_DEMODLOCKING, | ||
45 | }; | ||
46 | |||
47 | static struct xc5000_config hauppauge_hvr950q_tunerconfig = { | ||
48 | .i2c_address = 0x61, | ||
49 | .if_khz = 6000, | ||
50 | .tuner_callback = au0828_tuner_callback | ||
51 | }; | ||
52 | |||
53 | /*-------------------------------------------------------------------*/ | ||
54 | static void urb_completion(struct urb *purb) | ||
55 | { | ||
56 | u8 *ptr; | ||
57 | struct au0828_dev *dev = purb->context; | ||
58 | int ptype = usb_pipetype(purb->pipe); | ||
59 | |||
60 | if (dev->urb_streaming == 0) | ||
61 | return; | ||
62 | |||
63 | if (ptype != PIPE_BULK) { | ||
64 | printk(KERN_ERR "%s() Unsupported URB type %d\n", __FUNCTION__, ptype); | ||
65 | return; | ||
66 | } | ||
67 | |||
68 | ptr = (u8 *)purb->transfer_buffer; | ||
69 | |||
70 | /* Feed the transport payload into the kernel demux */ | ||
71 | dvb_dmx_swfilter_packets(&dev->dvb.demux, purb->transfer_buffer, purb->actual_length / 188); | ||
72 | |||
73 | /* Clean the buffer before we requeue */ | ||
74 | memset(purb->transfer_buffer, 0, URB_BUFSIZE); | ||
75 | |||
76 | /* Requeue URB */ | ||
77 | usb_submit_urb(purb, GFP_ATOMIC); | ||
78 | } | ||
79 | |||
80 | static int stop_urb_transfer(struct au0828_dev *dev) | ||
81 | { | ||
82 | int i; | ||
83 | |||
84 | printk(KERN_INFO "%s()\n", __FUNCTION__); | ||
85 | |||
86 | /* FIXME: Do we need to free the transfer_buffers? */ | ||
87 | for (i = 0; i < URB_COUNT; i++) { | ||
88 | usb_kill_urb(dev->urbs[i]); | ||
89 | kfree(dev->urbs[i]->transfer_buffer); | ||
90 | usb_free_urb(dev->urbs[i]); | ||
91 | } | ||
92 | |||
93 | dev->urb_streaming = 0; | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | #define _AU0828_BULKPIPE 0x83 | ||
99 | #define _BULKPIPESIZE 0xe522 | ||
100 | |||
101 | static int start_urb_transfer(struct au0828_dev *dev) | ||
102 | { | ||
103 | struct urb *purb; | ||
104 | int i, ret = -ENOMEM; | ||
105 | unsigned int pipe = usb_rcvbulkpipe(dev->usbdev, _AU0828_BULKPIPE); | ||
106 | int pipesize = usb_maxpacket(dev->usbdev, pipe, usb_pipeout(pipe)); | ||
107 | int packets = _BULKPIPESIZE / pipesize; | ||
108 | int transfer_buflen = packets * pipesize; | ||
109 | |||
110 | printk(KERN_INFO "%s() transfer_buflen = %d\n", __FUNCTION__, transfer_buflen); | ||
111 | |||
112 | if (dev->urb_streaming) { | ||
113 | printk("%s: iso xfer already running!\n", __FUNCTION__); | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | for (i = 0; i < URB_COUNT; i++) { | ||
118 | |||
119 | dev->urbs[i] = usb_alloc_urb(0, GFP_KERNEL); | ||
120 | if (!dev->urbs[i]) { | ||
121 | goto err; | ||
122 | } | ||
123 | |||
124 | purb = dev->urbs[i]; | ||
125 | |||
126 | purb->transfer_buffer = kzalloc(URB_BUFSIZE, GFP_KERNEL); | ||
127 | if (!purb->transfer_buffer) { | ||
128 | usb_free_urb(purb); | ||
129 | dev->urbs[i] = 0; | ||
130 | goto err; | ||
131 | } | ||
132 | |||
133 | purb->status = -EINPROGRESS; | ||
134 | usb_fill_bulk_urb(purb, | ||
135 | dev->usbdev, | ||
136 | usb_rcvbulkpipe(dev->usbdev, _AU0828_BULKPIPE), | ||
137 | purb->transfer_buffer, | ||
138 | URB_BUFSIZE, | ||
139 | urb_completion, | ||
140 | dev); | ||
141 | |||
142 | } | ||
143 | |||
144 | for (i = 0; i < URB_COUNT; i++) { | ||
145 | ret = usb_submit_urb(dev->urbs[i], GFP_ATOMIC); | ||
146 | if (ret != 0) { | ||
147 | stop_urb_transfer(dev); | ||
148 | printk("%s: failed urb submission, err = %d\n", __FUNCTION__, ret); | ||
149 | return ret; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | dev->urb_streaming = 1; | ||
154 | ret = 0; | ||
155 | |||
156 | err: | ||
157 | return ret; | ||
158 | } | ||
159 | |||
160 | static int au0828_dvb_start_feed(struct dvb_demux_feed *feed) | ||
161 | { | ||
162 | struct dvb_demux *demux = feed->demux; | ||
163 | struct au0828_dev *dev = (struct au0828_dev *) demux->priv; | ||
164 | struct au0828_dvb *dvb = &dev->dvb; | ||
165 | int ret = 0; | ||
166 | |||
167 | printk(KERN_INFO "%s() pid = 0x%x index = %d\n", __FUNCTION__, feed->pid, feed->index); | ||
168 | |||
169 | if (!demux->dmx.frontend) | ||
170 | return -EINVAL; | ||
171 | |||
172 | printk(KERN_INFO "%s() Preparing, feeding = %d\n", __FUNCTION__, dvb->feeding); | ||
173 | if (dvb) { | ||
174 | mutex_lock(&dvb->lock); | ||
175 | if (dvb->feeding++ == 0) { | ||
176 | printk(KERN_INFO "%s() Starting Transport DMA\n", | ||
177 | __FUNCTION__); | ||
178 | au0828_write(dev, 0x608, 0x90); | ||
179 | au0828_write(dev, 0x609, 0x72); | ||
180 | au0828_write(dev, 0x60a, 0x71); | ||
181 | au0828_write(dev, 0x60b, 0x01); | ||
182 | ret = start_urb_transfer(dev); | ||
183 | } | ||
184 | mutex_unlock(&dvb->lock); | ||
185 | } | ||
186 | |||
187 | return ret; | ||
188 | } | ||
189 | |||
190 | static int au0828_dvb_stop_feed(struct dvb_demux_feed *feed) | ||
191 | { | ||
192 | struct dvb_demux *demux = feed->demux; | ||
193 | struct au0828_dev *dev = (struct au0828_dev *) demux->priv; | ||
194 | struct au0828_dvb *dvb = &dev->dvb; | ||
195 | int ret = 0; | ||
196 | |||
197 | printk(KERN_INFO "%s() pid = 0x%x index = %d\n", __FUNCTION__, feed->pid, feed->index); | ||
198 | |||
199 | if (dvb) { | ||
200 | mutex_lock(&dvb->lock); | ||
201 | if (--dvb->feeding == 0) { | ||
202 | printk(KERN_INFO "%s() Stopping Transport DMA\n", | ||
203 | __FUNCTION__); | ||
204 | au0828_write(dev, 0x608, 0x00); | ||
205 | au0828_write(dev, 0x609, 0x00); | ||
206 | au0828_write(dev, 0x60a, 0x00); | ||
207 | au0828_write(dev, 0x60b, 0x00); | ||
208 | ret = stop_urb_transfer(dev); | ||
209 | } | ||
210 | mutex_unlock(&dvb->lock); | ||
211 | } | ||
212 | |||
213 | return ret; | ||
214 | } | ||
215 | |||
216 | int dvb_register(struct au0828_dev *dev) | ||
217 | { | ||
218 | struct au0828_dvb *dvb = &dev->dvb; | ||
219 | int result; | ||
220 | |||
221 | /* register adapter */ | ||
222 | result = dvb_register_adapter(&dvb->adapter, DRIVER_NAME, THIS_MODULE, | ||
223 | &dev->usbdev->dev, adapter_nr); | ||
224 | if (result < 0) { | ||
225 | printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", | ||
226 | DRIVER_NAME, result); | ||
227 | goto fail_adapter; | ||
228 | } | ||
229 | dvb->adapter.priv = dev; | ||
230 | |||
231 | /* register frontend */ | ||
232 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); | ||
233 | if (result < 0) { | ||
234 | printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", | ||
235 | DRIVER_NAME, result); | ||
236 | goto fail_frontend; | ||
237 | } | ||
238 | |||
239 | /* register demux stuff */ | ||
240 | dvb->demux.dmx.capabilities = | ||
241 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | | ||
242 | DMX_MEMORY_BASED_FILTERING; | ||
243 | dvb->demux.priv = dev; | ||
244 | dvb->demux.filternum = 256; | ||
245 | dvb->demux.feednum = 256; | ||
246 | dvb->demux.start_feed = au0828_dvb_start_feed; | ||
247 | dvb->demux.stop_feed = au0828_dvb_stop_feed; | ||
248 | result = dvb_dmx_init(&dvb->demux); | ||
249 | if (result < 0) { | ||
250 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", | ||
251 | DRIVER_NAME, result); | ||
252 | goto fail_dmx; | ||
253 | } | ||
254 | |||
255 | dvb->dmxdev.filternum = 256; | ||
256 | dvb->dmxdev.demux = &dvb->demux.dmx; | ||
257 | dvb->dmxdev.capabilities = 0; | ||
258 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); | ||
259 | if (result < 0) { | ||
260 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", | ||
261 | DRIVER_NAME, result); | ||
262 | goto fail_dmxdev; | ||
263 | } | ||
264 | |||
265 | dvb->fe_hw.source = DMX_FRONTEND_0; | ||
266 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
267 | if (result < 0) { | ||
268 | printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", | ||
269 | DRIVER_NAME, result); | ||
270 | goto fail_fe_hw; | ||
271 | } | ||
272 | |||
273 | dvb->fe_mem.source = DMX_MEMORY_FE; | ||
274 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); | ||
275 | if (result < 0) { | ||
276 | printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", | ||
277 | DRIVER_NAME, result); | ||
278 | goto fail_fe_mem; | ||
279 | } | ||
280 | |||
281 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
282 | if (result < 0) { | ||
283 | printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", | ||
284 | DRIVER_NAME, result); | ||
285 | goto fail_fe_conn; | ||
286 | } | ||
287 | |||
288 | /* register network adapter */ | ||
289 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); | ||
290 | return 0; | ||
291 | |||
292 | fail_fe_conn: | ||
293 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); | ||
294 | fail_fe_mem: | ||
295 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
296 | fail_fe_hw: | ||
297 | dvb_dmxdev_release(&dvb->dmxdev); | ||
298 | fail_dmxdev: | ||
299 | dvb_dmx_release(&dvb->demux); | ||
300 | fail_dmx: | ||
301 | dvb_unregister_frontend(dvb->frontend); | ||
302 | fail_frontend: | ||
303 | dvb_frontend_detach(dvb->frontend); | ||
304 | dvb_unregister_adapter(&dvb->adapter); | ||
305 | fail_adapter: | ||
306 | return result; | ||
307 | } | ||
308 | |||
309 | void au0828_dvb_unregister(struct au0828_dev *dev) | ||
310 | { | ||
311 | struct au0828_dvb *dvb = &dev->dvb; | ||
312 | |||
313 | dvb_net_release(&dvb->net); | ||
314 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); | ||
315 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
316 | dvb_dmxdev_release(&dvb->dmxdev); | ||
317 | dvb_dmx_release(&dvb->demux); | ||
318 | dvb_unregister_frontend(dvb->frontend); | ||
319 | dvb_frontend_detach(dvb->frontend); | ||
320 | dvb_unregister_adapter(&dvb->adapter); | ||
321 | } | ||
322 | |||
323 | /* All the DVB attach calls go here, this function get's modified | ||
324 | * for each new card. No other function in this file needs | ||
325 | * to change. | ||
326 | */ | ||
327 | int au0828_dvb_register(struct au0828_dev *dev) | ||
328 | { | ||
329 | struct au0828_dvb *dvb = &dev->dvb; | ||
330 | int ret; | ||
331 | |||
332 | /* init frontend */ | ||
333 | switch (dev->board) { | ||
334 | case AU0828_BOARD_HAUPPAUGE_HVR850: | ||
335 | case AU0828_BOARD_HAUPPAUGE_HVR950Q: | ||
336 | case AU0828_BOARD_DVICO_FUSIONHDTV7: | ||
337 | dvb->frontend = dvb_attach(au8522_attach, | ||
338 | &hauppauge_hvr950q_config, | ||
339 | &dev->i2c_adap); | ||
340 | if (dvb->frontend != NULL) { | ||
341 | hauppauge_hvr950q_tunerconfig.priv = dev; | ||
342 | dvb_attach(xc5000_attach, dvb->frontend, | ||
343 | &dev->i2c_adap, | ||
344 | &hauppauge_hvr950q_tunerconfig); | ||
345 | } | ||
346 | break; | ||
347 | default: | ||
348 | printk("The frontend of your DVB/ATSC card isn't supported yet\n"); | ||
349 | break; | ||
350 | } | ||
351 | if (NULL == dvb->frontend) { | ||
352 | printk("Frontend initialization failed\n"); | ||
353 | return -1; | ||
354 | } | ||
355 | |||
356 | /* Put the analog decoder in standby to keep it quiet */ | ||
357 | au0828_call_i2c_clients(dev, TUNER_SET_STANDBY, NULL); | ||
358 | |||
359 | if (dvb->frontend->ops.analog_ops.standby) | ||
360 | dvb->frontend->ops.analog_ops.standby(dvb->frontend); | ||
361 | |||
362 | /* register everything */ | ||
363 | ret = dvb_register(dev); | ||
364 | if (ret < 0) { | ||
365 | if (dvb->frontend->ops.release) | ||
366 | dvb->frontend->ops.release(dvb->frontend); | ||
367 | return ret; | ||
368 | } | ||
369 | |||
370 | return 0; | ||
371 | } | ||
diff --git a/drivers/media/video/au0828/au0828-i2c.c b/drivers/media/video/au0828/au0828-i2c.c new file mode 100644 index 000000000000..3e7482481152 --- /dev/null +++ b/drivers/media/video/au0828/au0828-i2c.c | |||
@@ -0,0 +1,402 @@ | |||
1 | /* | ||
2 | * Driver for the Auvitek AU0828 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/moduleparam.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <asm/io.h> | ||
27 | |||
28 | #include "au0828.h" | ||
29 | |||
30 | #include <media/v4l2-common.h> | ||
31 | |||
32 | static unsigned int i2c_debug; | ||
33 | module_param(i2c_debug, int, 0644); | ||
34 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); | ||
35 | |||
36 | static unsigned int i2c_scan = 0; | ||
37 | module_param(i2c_scan, int, 0444); | ||
38 | MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); | ||
39 | |||
40 | #define dprintk(level, fmt, arg...)\ | ||
41 | do { if (i2c_debug >= level)\ | ||
42 | printk(KERN_DEBUG "%s/0: " fmt, DRIVER_NAME, ## arg);\ | ||
43 | } while (0) | ||
44 | |||
45 | #define I2C_WAIT_DELAY 512 | ||
46 | #define I2C_WAIT_RETRY 64 | ||
47 | |||
48 | static inline int i2c_slave_did_write_ack(struct i2c_adapter *i2c_adap) | ||
49 | { | ||
50 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
51 | return au0828_read(dev, REG_201) & 0x08 ? 0 : 1; | ||
52 | } | ||
53 | |||
54 | static inline int i2c_slave_did_read_ack(struct i2c_adapter *i2c_adap) | ||
55 | { | ||
56 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
57 | return au0828_read(dev, REG_201) & 0x02 ? 0 : 1; | ||
58 | } | ||
59 | |||
60 | static int i2c_wait_read_ack(struct i2c_adapter *i2c_adap) | ||
61 | { | ||
62 | int count; | ||
63 | |||
64 | for (count = 0; count < I2C_WAIT_RETRY; count++) { | ||
65 | if (!i2c_slave_did_read_ack(i2c_adap)) | ||
66 | break; | ||
67 | udelay(I2C_WAIT_DELAY); | ||
68 | } | ||
69 | |||
70 | if (I2C_WAIT_RETRY == count) | ||
71 | return 0; | ||
72 | |||
73 | return 1; | ||
74 | } | ||
75 | |||
76 | static inline int i2c_is_read_busy(struct i2c_adapter *i2c_adap) | ||
77 | { | ||
78 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
79 | return au0828_read(dev, REG_201) & 0x01 ? 0 : 1; | ||
80 | } | ||
81 | |||
82 | static int i2c_wait_read_done(struct i2c_adapter *i2c_adap) | ||
83 | { | ||
84 | int count; | ||
85 | |||
86 | for (count = 0; count < I2C_WAIT_RETRY; count++) { | ||
87 | if (!i2c_is_read_busy(i2c_adap)) | ||
88 | break; | ||
89 | udelay(I2C_WAIT_DELAY); | ||
90 | } | ||
91 | |||
92 | if (I2C_WAIT_RETRY == count) | ||
93 | return 0; | ||
94 | |||
95 | return 1; | ||
96 | } | ||
97 | |||
98 | static inline int i2c_is_write_done(struct i2c_adapter *i2c_adap) | ||
99 | { | ||
100 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
101 | return au0828_read(dev, REG_201) & 0x04 ? 1 : 0; | ||
102 | } | ||
103 | |||
104 | static int i2c_wait_write_done(struct i2c_adapter *i2c_adap) | ||
105 | { | ||
106 | int count; | ||
107 | |||
108 | for (count = 0; count < I2C_WAIT_RETRY; count++) { | ||
109 | if (i2c_is_write_done(i2c_adap)) | ||
110 | break; | ||
111 | udelay(I2C_WAIT_DELAY); | ||
112 | } | ||
113 | |||
114 | if (I2C_WAIT_RETRY == count) | ||
115 | return 0; | ||
116 | |||
117 | return 1; | ||
118 | } | ||
119 | |||
120 | static inline int i2c_is_busy(struct i2c_adapter *i2c_adap) | ||
121 | { | ||
122 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
123 | return au0828_read(dev, REG_201) & 0x10 ? 1 : 0; | ||
124 | } | ||
125 | |||
126 | static int i2c_wait_done(struct i2c_adapter *i2c_adap) | ||
127 | { | ||
128 | int count; | ||
129 | |||
130 | for (count = 0; count < I2C_WAIT_RETRY; count++) { | ||
131 | if (!i2c_is_busy(i2c_adap)) | ||
132 | break; | ||
133 | udelay(I2C_WAIT_DELAY); | ||
134 | } | ||
135 | |||
136 | if (I2C_WAIT_RETRY == count) | ||
137 | return 0; | ||
138 | |||
139 | return 1; | ||
140 | } | ||
141 | |||
142 | /* FIXME: Implement join handling correctly */ | ||
143 | static int i2c_sendbytes(struct i2c_adapter *i2c_adap, | ||
144 | const struct i2c_msg *msg, int joined_rlen) | ||
145 | { | ||
146 | int i, strobe = 0; | ||
147 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
148 | |||
149 | dprintk(1, "%s()\n", __FUNCTION__); | ||
150 | |||
151 | au0828_write(dev, REG_2FF, 0x01); | ||
152 | au0828_write(dev, REG_202, 0x07); | ||
153 | |||
154 | /* Hardware needs 8 bit addresses */ | ||
155 | au0828_write(dev, REG_203, msg->addr << 1); | ||
156 | |||
157 | if (i2c_debug) | ||
158 | dprintk(1, "SEND: %02x\n", msg->addr); | ||
159 | |||
160 | for (i=0; i < msg->len;) { | ||
161 | |||
162 | if (i2c_debug) | ||
163 | dprintk(1, " %02x\n", msg->buf[i]); | ||
164 | |||
165 | au0828_write(dev, REG_205, msg->buf[i]); | ||
166 | |||
167 | strobe++; | ||
168 | i++; | ||
169 | |||
170 | if ((strobe >= 4) || (i >= msg->len)) { | ||
171 | |||
172 | /* Strobe the byte into the bus */ | ||
173 | if (i < msg->len) | ||
174 | au0828_write(dev, REG_200, 0x41); | ||
175 | else | ||
176 | au0828_write(dev, REG_200, 0x01); | ||
177 | |||
178 | /* Reset strobe trigger */ | ||
179 | strobe = 0; | ||
180 | |||
181 | if (!i2c_wait_write_done(i2c_adap)) | ||
182 | return -EIO; | ||
183 | |||
184 | } | ||
185 | |||
186 | } | ||
187 | if (!i2c_wait_done(i2c_adap)) | ||
188 | return -EIO; | ||
189 | |||
190 | if (i2c_debug) | ||
191 | dprintk(1, "\n"); | ||
192 | |||
193 | return msg->len; | ||
194 | } | ||
195 | |||
196 | /* FIXME: Implement join handling correctly */ | ||
197 | static int i2c_readbytes(struct i2c_adapter *i2c_adap, | ||
198 | const struct i2c_msg *msg, int joined) | ||
199 | { | ||
200 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
201 | int i; | ||
202 | |||
203 | dprintk(1, "%s()\n", __FUNCTION__); | ||
204 | |||
205 | au0828_write(dev, REG_2FF, 0x01); | ||
206 | au0828_write(dev, REG_202, 0x07); | ||
207 | |||
208 | /* Hardware needs 8 bit addresses */ | ||
209 | au0828_write(dev, REG_203, msg->addr << 1); | ||
210 | |||
211 | if (i2c_debug) | ||
212 | dprintk(1, " RECV:\n"); | ||
213 | |||
214 | /* Deal with i2c_scan */ | ||
215 | if (msg->len == 0) { | ||
216 | au0828_write(dev, REG_200, 0x20); | ||
217 | if (i2c_wait_read_ack(i2c_adap)) | ||
218 | return -EIO; | ||
219 | return 0; | ||
220 | } | ||
221 | |||
222 | for (i=0; i < msg->len;) { | ||
223 | |||
224 | i++; | ||
225 | |||
226 | if (i < msg->len) | ||
227 | au0828_write(dev, REG_200, 0x60); | ||
228 | else | ||
229 | au0828_write(dev, REG_200, 0x20); | ||
230 | |||
231 | if (!i2c_wait_read_done(i2c_adap)) | ||
232 | return -EIO; | ||
233 | |||
234 | msg->buf[i-1] = au0828_read(dev, REG_209) & 0xff; | ||
235 | |||
236 | if (i2c_debug) | ||
237 | dprintk(1, " %02x\n", msg->buf[i-1]); | ||
238 | } | ||
239 | if (!i2c_wait_done(i2c_adap)) | ||
240 | return -EIO; | ||
241 | |||
242 | if (i2c_debug) | ||
243 | dprintk(1, "\n"); | ||
244 | |||
245 | return msg->len; | ||
246 | } | ||
247 | |||
248 | static int i2c_xfer(struct i2c_adapter *i2c_adap, | ||
249 | struct i2c_msg *msgs, int num) | ||
250 | { | ||
251 | int i, retval = 0; | ||
252 | |||
253 | dprintk(1, "%s(num = %d)\n", __FUNCTION__, num); | ||
254 | |||
255 | for (i = 0 ; i < num; i++) { | ||
256 | dprintk(1, "%s(num = %d) addr = 0x%02x len = 0x%x\n", | ||
257 | __FUNCTION__, num, msgs[i].addr, msgs[i].len); | ||
258 | if (msgs[i].flags & I2C_M_RD) { | ||
259 | /* read */ | ||
260 | retval = i2c_readbytes(i2c_adap, &msgs[i], 0); | ||
261 | } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) && | ||
262 | msgs[i].addr == msgs[i + 1].addr) { | ||
263 | /* write then read from same address */ | ||
264 | retval = i2c_sendbytes(i2c_adap, &msgs[i], | ||
265 | msgs[i + 1].len); | ||
266 | if (retval < 0) | ||
267 | goto err; | ||
268 | i++; | ||
269 | retval = i2c_readbytes(i2c_adap, &msgs[i], 1); | ||
270 | } else { | ||
271 | /* write */ | ||
272 | retval = i2c_sendbytes(i2c_adap, &msgs[i], 0); | ||
273 | } | ||
274 | if (retval < 0) | ||
275 | goto err; | ||
276 | } | ||
277 | return num; | ||
278 | |||
279 | err: | ||
280 | return retval; | ||
281 | } | ||
282 | |||
283 | static int attach_inform(struct i2c_client *client) | ||
284 | { | ||
285 | dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n", | ||
286 | client->driver->driver.name, client->addr, client->name); | ||
287 | |||
288 | if (!client->driver->command) | ||
289 | return 0; | ||
290 | |||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | static int detach_inform(struct i2c_client *client) | ||
295 | { | ||
296 | dprintk(1, "i2c detach [client=%s]\n", client->name); | ||
297 | |||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | void au0828_call_i2c_clients(struct au0828_dev *dev, | ||
302 | unsigned int cmd, void *arg) | ||
303 | { | ||
304 | if (dev->i2c_rc != 0) | ||
305 | return; | ||
306 | |||
307 | i2c_clients_command(&dev->i2c_adap, cmd, arg); | ||
308 | } | ||
309 | |||
310 | static u32 au0828_functionality(struct i2c_adapter *adap) | ||
311 | { | ||
312 | return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; | ||
313 | } | ||
314 | |||
315 | static struct i2c_algorithm au0828_i2c_algo_template = { | ||
316 | .master_xfer = i2c_xfer, | ||
317 | .functionality = au0828_functionality, | ||
318 | }; | ||
319 | |||
320 | /* ----------------------------------------------------------------------- */ | ||
321 | |||
322 | static struct i2c_adapter au0828_i2c_adap_template = { | ||
323 | .name = DRIVER_NAME, | ||
324 | .owner = THIS_MODULE, | ||
325 | .id = I2C_HW_B_AU0828, | ||
326 | .algo = &au0828_i2c_algo_template, | ||
327 | .class = I2C_CLASS_TV_ANALOG, | ||
328 | .client_register = attach_inform, | ||
329 | .client_unregister = detach_inform, | ||
330 | }; | ||
331 | |||
332 | static struct i2c_client au0828_i2c_client_template = { | ||
333 | .name = "au0828 internal", | ||
334 | }; | ||
335 | |||
336 | static char *i2c_devs[128] = { | ||
337 | [ 0x8e >> 1 ] = "au8522", | ||
338 | [ 0xa0 >> 1 ] = "eeprom", | ||
339 | [ 0xc2 >> 1 ] = "tuner/xc5000", | ||
340 | }; | ||
341 | |||
342 | static void do_i2c_scan(char *name, struct i2c_client *c) | ||
343 | { | ||
344 | unsigned char buf; | ||
345 | int i, rc; | ||
346 | |||
347 | for (i = 0; i < 128; i++) { | ||
348 | c->addr = i; | ||
349 | rc = i2c_master_recv(c, &buf, 0); | ||
350 | if (rc < 0) | ||
351 | continue; | ||
352 | printk("%s: i2c scan: found device @ 0x%x [%s]\n", | ||
353 | name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); | ||
354 | } | ||
355 | } | ||
356 | |||
357 | /* init + register i2c algo-bit adapter */ | ||
358 | int au0828_i2c_register(struct au0828_dev *dev) | ||
359 | { | ||
360 | dprintk(1, "%s()\n", __FUNCTION__); | ||
361 | |||
362 | memcpy(&dev->i2c_adap, &au0828_i2c_adap_template, | ||
363 | sizeof(dev->i2c_adap)); | ||
364 | memcpy(&dev->i2c_algo, &au0828_i2c_algo_template, | ||
365 | sizeof(dev->i2c_algo)); | ||
366 | memcpy(&dev->i2c_client, &au0828_i2c_client_template, | ||
367 | sizeof(dev->i2c_client)); | ||
368 | |||
369 | dev->i2c_adap.dev.parent = &dev->usbdev->dev; | ||
370 | |||
371 | strlcpy(dev->i2c_adap.name, DRIVER_NAME, | ||
372 | sizeof(dev->i2c_adap.name)); | ||
373 | |||
374 | dev->i2c_algo.data = dev; | ||
375 | dev->i2c_adap.algo_data = dev; | ||
376 | i2c_set_adapdata(&dev->i2c_adap, dev); | ||
377 | i2c_add_adapter(&dev->i2c_adap); | ||
378 | |||
379 | dev->i2c_client.adapter = &dev->i2c_adap; | ||
380 | |||
381 | if (0 == dev->i2c_rc) { | ||
382 | printk("%s: i2c bus registered\n", DRIVER_NAME); | ||
383 | if (i2c_scan) | ||
384 | do_i2c_scan(DRIVER_NAME, &dev->i2c_client); | ||
385 | } else | ||
386 | printk("%s: i2c bus register FAILED\n", DRIVER_NAME); | ||
387 | return dev->i2c_rc; | ||
388 | } | ||
389 | |||
390 | int au0828_i2c_unregister(struct au0828_dev *dev) | ||
391 | { | ||
392 | i2c_del_adapter(&dev->i2c_adap); | ||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | /* ----------------------------------------------------------------------- */ | ||
397 | |||
398 | /* | ||
399 | * Local variables: | ||
400 | * c-basic-offset: 8 | ||
401 | * End: | ||
402 | */ | ||
diff --git a/drivers/media/video/au0828/au0828-reg.h b/drivers/media/video/au0828/au0828-reg.h new file mode 100644 index 000000000000..c501f6a52af3 --- /dev/null +++ b/drivers/media/video/au0828/au0828-reg.h | |||
@@ -0,0 +1,35 @@ | |||
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 | #define REG_000 0x000 | ||
23 | #define REG_001 0x001 | ||
24 | #define REG_002 0x002 | ||
25 | #define REG_003 0x003 | ||
26 | |||
27 | #define REG_200 0x200 | ||
28 | #define REG_201 0x201 | ||
29 | #define REG_202 0x202 | ||
30 | #define REG_203 0x203 | ||
31 | #define REG_205 0x205 | ||
32 | #define REG_209 0x209 | ||
33 | #define REG_2FF 0x2ff | ||
34 | |||
35 | #define REG_600 0x600 | ||
diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h new file mode 100644 index 000000000000..517227667040 --- /dev/null +++ b/drivers/media/video/au0828/au0828.h | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | * Driver for the Auvitek AU0828 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/usb.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/i2c-algo-bit.h> | ||
25 | |||
26 | /* DVB */ | ||
27 | #include "demux.h" | ||
28 | #include "dmxdev.h" | ||
29 | #include "dvb_demux.h" | ||
30 | #include "dvb_frontend.h" | ||
31 | #include "dvb_net.h" | ||
32 | #include "dvbdev.h" | ||
33 | |||
34 | #include "au0828-reg.h" | ||
35 | #include "au0828-cards.h" | ||
36 | |||
37 | #define DRIVER_NAME "au0828" | ||
38 | #define URB_COUNT 16 | ||
39 | //#define URB_BUFSIZE (312 * 188) | ||
40 | #define URB_BUFSIZE (0xe522) | ||
41 | |||
42 | struct au0828_board { | ||
43 | char *name; | ||
44 | }; | ||
45 | |||
46 | struct au0828_dvb { | ||
47 | struct mutex lock; | ||
48 | struct dvb_adapter adapter; | ||
49 | struct dvb_frontend *frontend; | ||
50 | struct dvb_demux demux; | ||
51 | struct dmxdev dmxdev; | ||
52 | struct dmx_frontend fe_hw; | ||
53 | struct dmx_frontend fe_mem; | ||
54 | struct dvb_net net; | ||
55 | int feeding; | ||
56 | }; | ||
57 | |||
58 | struct au0828_dev { | ||
59 | struct mutex mutex; | ||
60 | struct usb_device *usbdev; | ||
61 | int board; | ||
62 | u8 ctrlmsg[64]; | ||
63 | |||
64 | /* I2C */ | ||
65 | struct i2c_adapter i2c_adap; | ||
66 | struct i2c_algo_bit_data i2c_algo; | ||
67 | struct i2c_client i2c_client; | ||
68 | u32 i2c_rc; | ||
69 | |||
70 | /* Digital */ | ||
71 | struct au0828_dvb dvb; | ||
72 | |||
73 | /* USB / URB Related */ | ||
74 | int urb_streaming; | ||
75 | struct urb *urbs[URB_COUNT]; | ||
76 | |||
77 | }; | ||
78 | |||
79 | struct au0828_buff { | ||
80 | struct au0828_dev *dev; | ||
81 | struct urb *purb; | ||
82 | struct list_head buff_list; | ||
83 | }; | ||
84 | |||
85 | /* ----------------------------------------------------------- */ | ||
86 | #define au0828_read(dev,reg) au0828_readreg(dev,reg) | ||
87 | #define au0828_write(dev,reg,value) au0828_writereg(dev,reg,value) | ||
88 | #define au0828_andor(dev,reg,mask,value) \ | ||
89 | au0828_writereg(dev,reg,(au0828_readreg(dev,reg)&~(mask))|((value)&(mask))) | ||
90 | |||
91 | #define au0828_set(dev,reg,bit) au0828_andor(dev,(reg),(bit),(bit)) | ||
92 | #define au0828_clear(dev,reg,bit) au0828_andor(dev,(reg),(bit),0) | ||
93 | |||
94 | /* ----------------------------------------------------------- */ | ||
95 | /* au0828-core.c */ | ||
96 | extern u32 au0828_read(struct au0828_dev *dev, u16 reg); | ||
97 | extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val); | ||
98 | |||
99 | /* ----------------------------------------------------------- */ | ||
100 | /* au0828-cards.c */ | ||
101 | extern struct au0828_board au0828_boards[]; | ||
102 | extern struct usb_device_id au0828_usb_id_table[]; | ||
103 | extern const unsigned int au0828_bcount; | ||
104 | extern void au0828_gpio_setup(struct au0828_dev *dev); | ||
105 | extern int au0828_tuner_callback(void *priv, int command, int arg); | ||
106 | |||
107 | /* ----------------------------------------------------------- */ | ||
108 | /* au0828-i2c.c */ | ||
109 | extern int au0828_i2c_register(struct au0828_dev *dev); | ||
110 | extern int au0828_i2c_unregister(struct au0828_dev *dev); | ||
111 | extern void au0828_call_i2c_clients(struct au0828_dev *dev, | ||
112 | unsigned int cmd, void *arg); | ||
113 | |||
114 | /* ----------------------------------------------------------- */ | ||
115 | /* au0828-dvb.c */ | ||
116 | extern int au0828_dvb_register(struct au0828_dev *dev); | ||
117 | extern void au0828_dvb_unregister(struct au0828_dev *dev); | ||