V4L/DVB (6899): Kconfig: VIDEO_CX23885 must select TUNER_XC2028 if !DVB_FE_CUSTOMIZE
[deliverable/linux.git] / drivers / media / video / cx23885 / cx23885-dvb.c
CommitLineData
d19770e5
ST
1/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
4 * Copyright (c) 2006 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/fs.h>
26#include <linux/kthread.h>
27#include <linux/file.h>
28#include <linux/suspend.h>
29
30#include "cx23885.h"
d19770e5
ST
31#include <media/v4l2-common.h>
32
33#include "s5h1409.h"
34#include "mt2131.h"
9bc37caa 35#include "lgdt330x.h"
d1987d55 36#include "xc5000.h"
9bc37caa 37#include "dvb-pll.h"
07b4a835
MK
38#include "tuner-xc2028.h"
39#include "tuner-xc2028-types.h"
d19770e5 40
2e52f215 41static unsigned int debug = 0;
d19770e5
ST
42
43#define dprintk(level,fmt, arg...) if (debug >= level) \
44 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg)
45
46/* ------------------------------------------------------------------ */
47
48static int dvb_buf_setup(struct videobuf_queue *q,
49 unsigned int *count, unsigned int *size)
50{
51 struct cx23885_tsport *port = q->priv_data;
52
53 port->ts_packet_size = 188 * 4;
54 port->ts_packet_count = 32;
55
56 *size = port->ts_packet_size * port->ts_packet_count;
57 *count = 32;
58 return 0;
59}
60
44a6481d
MK
61static int dvb_buf_prepare(struct videobuf_queue *q,
62 struct videobuf_buffer *vb, enum v4l2_field field)
d19770e5
ST
63{
64 struct cx23885_tsport *port = q->priv_data;
44a6481d 65 return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
d19770e5
ST
66}
67
68static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
69{
70 struct cx23885_tsport *port = q->priv_data;
71 cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
72}
73
44a6481d
MK
74static void dvb_buf_release(struct videobuf_queue *q,
75 struct videobuf_buffer *vb)
d19770e5
ST
76{
77 cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
78}
79
d1987d55
ST
80static int cx23885_request_firmware(struct dvb_frontend *fe,
81 const struct firmware **fw, char *name)
82{
83 struct cx23885_tsport *port = fe->dvb->priv;
84 struct cx23885_dev *dev = port->dev;
85
86 dprintk(1, "%s(?,?,%s)\n", __FUNCTION__, name);
87
88 return request_firmware(fw, name, &dev->pci->dev);
89}
90
91static int hauppauge_hvr1500q_tuner_reset(struct dvb_frontend *fe)
92{
93 struct cx23885_tsport *port = fe->dvb->priv;
94 struct cx23885_dev *dev = port->dev;
95
96 dprintk(1, "%s()\n", __FUNCTION__);
97
98 /* Drive the tuner into reset back back */
99 cx_clear(GP0_IO, 0x00000004);
100 mdelay(200);
101 cx_set(GP0_IO, 0x00000004);
102
103 return 0;
104}
105
d19770e5
ST
106static struct videobuf_queue_ops dvb_qops = {
107 .buf_setup = dvb_buf_setup,
108 .buf_prepare = dvb_buf_prepare,
109 .buf_queue = dvb_buf_queue,
110 .buf_release = dvb_buf_release,
111};
112
86184e06 113static struct s5h1409_config hauppauge_generic_config = {
fc959bef
ST
114 .demod_address = 0x32 >> 1,
115 .output_mode = S5H1409_SERIAL_OUTPUT,
116 .gpio = S5H1409_GPIO_ON,
2b03238a 117 .qam_if = 44000,
fc959bef
ST
118 .inversion = S5H1409_INVERSION_OFF,
119 .status_mode = S5H1409_DEMODLOCKING
120};
121
122static struct s5h1409_config hauppauge_hvr1800lp_config = {
d19770e5
ST
123 .demod_address = 0x32 >> 1,
124 .output_mode = S5H1409_SERIAL_OUTPUT,
125 .gpio = S5H1409_GPIO_OFF,
2b03238a 126 .qam_if = 44000,
fe475163
ST
127 .inversion = S5H1409_INVERSION_OFF,
128 .status_mode = S5H1409_DEMODLOCKING
d19770e5
ST
129};
130
07b4a835
MK
131static struct s5h1409_config hauppauge_hvr1500_config = {
132 .demod_address = 0x32 >> 1,
133 .output_mode = S5H1409_SERIAL_OUTPUT,
134 .gpio = S5H1409_GPIO_OFF,
135 .inversion = S5H1409_INVERSION_OFF,
136 .status_mode = S5H1409_DEMODLOCKING
137};
138
86184e06 139static struct mt2131_config hauppauge_generic_tunerconfig = {
a77743bc
ST
140 0x61
141};
142
9bc37caa
MK
143static struct lgdt330x_config fusionhdtv_5_express = {
144 .demod_address = 0x0e,
145 .demod_chip = LGDT3303,
146 .serial_mpeg = 0x40,
147};
148
d1987d55
ST
149static struct s5h1409_config hauppauge_hvr1500q_config = {
150 .demod_address = 0x32 >> 1,
151 .output_mode = S5H1409_SERIAL_OUTPUT,
152 .gpio = S5H1409_GPIO_ON,
153 .qam_if = 44000,
154 .inversion = S5H1409_INVERSION_OFF,
155 .status_mode = S5H1409_DEMODLOCKING
156};
157
158static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
e12671cf
ST
159 .i2c_address = 0x61,
160 .if_khz = 5380,
d1987d55 161 .request_firmware = cx23885_request_firmware,
e12671cf 162 .tuner_reset = hauppauge_hvr1500q_tuner_reset
d1987d55
ST
163};
164
07b4a835
MK
165static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
166{
167 struct cx23885_tsport *port = ptr;
168 struct cx23885_dev *dev = port->dev;
169
170 switch (command) {
171 case XC2028_TUNER_RESET:
172 /* Send the tuner in then out of reset */
173 /* GPIO-2 xc3028 tuner */
174 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg);
175
176 cx_set(GP0_IO, 0x00040000);
177 cx_clear(GP0_IO, 0x00000004);
178 msleep(5);
179
180 cx_set(GP0_IO, 0x00040004);
181 msleep(5);
182 break;
183 case XC2028_RESET_CLK:
184 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg);
185 break;
186 default:
187 dprintk(1, "%s: unknown command %d, arg %d\n", __FUNCTION__,
188 command, arg);
189 return -EINVAL;
190 }
191
192 return 0;
193}
194
d19770e5
ST
195static int dvb_register(struct cx23885_tsport *port)
196{
197 struct cx23885_dev *dev = port->dev;
f139fa71 198 struct cx23885_i2c *i2c_bus = NULL;
d19770e5
ST
199
200 /* init struct videobuf_dvb */
201 port->dvb.name = dev->name;
202
203 /* init frontend */
204 switch (dev->board) {
a77743bc 205 case CX23885_BOARD_HAUPPAUGE_HVR1250:
d19770e5 206 case CX23885_BOARD_HAUPPAUGE_HVR1800:
f139fa71 207 i2c_bus = &dev->i2c_bus[0];
d19770e5 208 port->dvb.frontend = dvb_attach(s5h1409_attach,
86184e06 209 &hauppauge_generic_config,
f139fa71 210 &i2c_bus->i2c_adap);
d19770e5 211 if (port->dvb.frontend != NULL) {
44a6481d 212 dvb_attach(mt2131_attach, port->dvb.frontend,
f139fa71 213 &i2c_bus->i2c_adap,
86184e06 214 &hauppauge_generic_tunerconfig, 0);
d19770e5
ST
215 }
216 break;
fc959bef 217 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
f139fa71 218 i2c_bus = &dev->i2c_bus[0];
fc959bef
ST
219 port->dvb.frontend = dvb_attach(s5h1409_attach,
220 &hauppauge_hvr1800lp_config,
f139fa71 221 &i2c_bus->i2c_adap);
fc959bef
ST
222 if (port->dvb.frontend != NULL) {
223 dvb_attach(mt2131_attach, port->dvb.frontend,
f139fa71 224 &i2c_bus->i2c_adap,
fc959bef
ST
225 &hauppauge_generic_tunerconfig, 0);
226 }
227 break;
9bc37caa 228 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
f139fa71 229 i2c_bus = &dev->i2c_bus[0];
9bc37caa
MK
230 port->dvb.frontend = dvb_attach(lgdt330x_attach,
231 &fusionhdtv_5_express,
f139fa71 232 &i2c_bus->i2c_adap);
9bc37caa 233 if (port->dvb.frontend != NULL) {
f139fa71
MK
234 dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61,
235 &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF);
9bc37caa
MK
236 }
237 break;
d1987d55
ST
238 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
239 i2c_bus = &dev->i2c_bus[1];
240 port->dvb.frontend = dvb_attach(s5h1409_attach,
241 &hauppauge_hvr1500q_config,
242 &dev->i2c_bus[0].i2c_adap);
243 if (port->dvb.frontend != NULL) {
244 dvb_attach(xc5000_attach, port->dvb.frontend,
245 &i2c_bus->i2c_adap,
246 &hauppauge_hvr1500q_tunerconfig);
247 }
248 break;
07b4a835
MK
249 case CX23885_BOARD_HAUPPAUGE_HVR1500:
250 i2c_bus = &dev->i2c_bus[1];
251 port->dvb.frontend = dvb_attach(s5h1409_attach,
252 &hauppauge_hvr1500_config,
253 &dev->i2c_bus[0].i2c_adap);
254 if (port->dvb.frontend != NULL) {
255 struct dvb_frontend *fe;
256 struct xc2028_config cfg = {
257 .i2c_adap = &i2c_bus->i2c_adap,
258 .i2c_addr = 0x61,
259 .video_dev = port,
260 .callback = cx23885_hvr1500_xc3028_callback,
261 };
262 static struct xc2028_ctrl ctl = {
263 .fname = "xc3028-v27.fw",
264 .max_len = 64,
265 .scode_table = OREN538,
266 };
267
268 fe = dvb_attach(xc2028_attach,
269 port->dvb.frontend, &cfg);
270 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
271 fe->ops.tuner_ops.set_config(fe, &ctl);
272 }
273 break;
d19770e5
ST
274 default:
275 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
276 dev->name);
277 break;
278 }
279 if (NULL == port->dvb.frontend) {
280 printk("%s: frontend initialization failed\n", dev->name);
281 return -1;
282 }
283
284 /* Put the analog decoder in standby to keep it quiet */
f139fa71 285 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
d19770e5
ST
286
287 /* register everything */
44a6481d
MK
288 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
289 &dev->pci->dev);
d19770e5
ST
290}
291
292int cx23885_dvb_register(struct cx23885_tsport *port)
293{
294 struct cx23885_dev *dev = port->dev;
295 int err;
296
44a6481d
MK
297 dprintk(1, "%s\n", __FUNCTION__);
298 dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
d19770e5
ST
299 dev->board,
300 dev->name,
301 dev->pci_bus,
302 dev->pci_slot);
303
304 err = -ENODEV;
d19770e5
ST
305
306 /* dvb stuff */
307 printk("%s: cx23885 based dvb card\n", dev->name);
aecfde53 308 videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock,
44a6481d
MK
309 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
310 sizeof(struct cx23885_buffer), port);
d19770e5
ST
311 err = dvb_register(port);
312 if (err != 0)
313 printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
314
d19770e5
ST
315 return err;
316}
317
318int cx23885_dvb_unregister(struct cx23885_tsport *port)
319{
320 /* dvb */
321 if(port->dvb.frontend)
322 videobuf_dvb_unregister(&port->dvb);
323
324 return 0;
325}
44a6481d
MK
326
327/*
328 * Local variables:
329 * c-basic-offset: 8
330 * End:
331 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
332*/
This page took 0.082282 seconds and 5 git commands to generate.