blob: 21937d5cbb1295232b8c3045d131767624f5582e [file] [log] [blame]
Steven Tothd19770e2007-03-11 20:44:05 -03001/*
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"
Steven Tothd19770e2007-03-11 20:44:05 -030031#include <media/v4l2-common.h>
32
33#include "s5h1409.h"
34#include "mt2131.h"
Michael Krufky3ba71d22007-12-07 01:40:36 -030035#include "tda8290.h"
Michael Krufky4041f1a2007-12-24 04:52:08 -030036#include "tda18271.h"
Michael Krufky9bc37ca2007-09-08 15:17:13 -030037#include "lgdt330x.h"
Steven Tothd1987d52007-12-18 01:57:06 -030038#include "xc5000.h"
Michael Krufky9bc37ca2007-09-08 15:17:13 -030039#include "dvb-pll.h"
Michael Krufky07b4a832007-12-18 01:09:11 -030040#include "tuner-xc2028.h"
41#include "tuner-xc2028-types.h"
Steven Tothd19770e2007-03-11 20:44:05 -030042
Steven Toth4513fc692008-01-12 11:36:36 -030043static unsigned int debug;
Steven Tothd19770e2007-03-11 20:44:05 -030044
Steven Toth4513fc692008-01-12 11:36:36 -030045#define dprintk(level, fmt, arg...)\
46 do { if (debug >= level)\
47 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
48 } while (0)
Steven Tothd19770e2007-03-11 20:44:05 -030049
50/* ------------------------------------------------------------------ */
51
Michael Krufky3ba71d22007-12-07 01:40:36 -030052static unsigned int alt_tuner;
53module_param(alt_tuner, int, 0644);
54MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
55
56/* ------------------------------------------------------------------ */
57
Steven Tothd19770e2007-03-11 20:44:05 -030058static int dvb_buf_setup(struct videobuf_queue *q,
59 unsigned int *count, unsigned int *size)
60{
61 struct cx23885_tsport *port = q->priv_data;
62
63 port->ts_packet_size = 188 * 4;
64 port->ts_packet_count = 32;
65
66 *size = port->ts_packet_size * port->ts_packet_count;
67 *count = 32;
68 return 0;
69}
70
Michael Krufky44a64812007-03-20 23:00:18 -030071static int dvb_buf_prepare(struct videobuf_queue *q,
72 struct videobuf_buffer *vb, enum v4l2_field field)
Steven Tothd19770e2007-03-11 20:44:05 -030073{
74 struct cx23885_tsport *port = q->priv_data;
Michael Krufky44a64812007-03-20 23:00:18 -030075 return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
Steven Tothd19770e2007-03-11 20:44:05 -030076}
77
78static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
79{
80 struct cx23885_tsport *port = q->priv_data;
81 cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
82}
83
Michael Krufky44a64812007-03-20 23:00:18 -030084static void dvb_buf_release(struct videobuf_queue *q,
85 struct videobuf_buffer *vb)
Steven Tothd19770e2007-03-11 20:44:05 -030086{
87 cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
88}
89
Steven Tothd1987d52007-12-18 01:57:06 -030090static int cx23885_request_firmware(struct dvb_frontend *fe,
91 const struct firmware **fw, char *name)
92{
93 struct cx23885_tsport *port = fe->dvb->priv;
94 struct cx23885_dev *dev = port->dev;
95
96 dprintk(1, "%s(?,?,%s)\n", __FUNCTION__, name);
97
98 return request_firmware(fw, name, &dev->pci->dev);
99}
100
101static int hauppauge_hvr1500q_tuner_reset(struct dvb_frontend *fe)
102{
103 struct cx23885_tsport *port = fe->dvb->priv;
104 struct cx23885_dev *dev = port->dev;
105
106 dprintk(1, "%s()\n", __FUNCTION__);
107
108 /* Drive the tuner into reset back back */
109 cx_clear(GP0_IO, 0x00000004);
110 mdelay(200);
111 cx_set(GP0_IO, 0x00000004);
112
113 return 0;
114}
115
Steven Tothd19770e2007-03-11 20:44:05 -0300116static struct videobuf_queue_ops dvb_qops = {
117 .buf_setup = dvb_buf_setup,
118 .buf_prepare = dvb_buf_prepare,
119 .buf_queue = dvb_buf_queue,
120 .buf_release = dvb_buf_release,
121};
122
Steven Toth86184e02007-09-04 21:40:47 -0300123static struct s5h1409_config hauppauge_generic_config = {
Steven Tothd19770e2007-03-11 20:44:05 -0300124 .demod_address = 0x32 >> 1,
125 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothfc959be2007-09-08 19:08:17 -0300126 .gpio = S5H1409_GPIO_ON,
Michael Krufky2b032382007-12-13 10:04:10 -0300127 .qam_if = 44000,
Steven Tothfc959be2007-09-08 19:08:17 -0300128 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300129 .status_mode = S5H1409_DEMODLOCKING,
130 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothfc959be2007-09-08 19:08:17 -0300131};
132
Michael Krufky3ba71d22007-12-07 01:40:36 -0300133static struct s5h1409_config hauppauge_ezqam_config = {
134 .demod_address = 0x32 >> 1,
135 .output_mode = S5H1409_SERIAL_OUTPUT,
136 .gpio = S5H1409_GPIO_OFF,
137 .qam_if = 4000,
138 .inversion = S5H1409_INVERSION_ON,
Steven Tothdfc1c082008-01-15 21:35:22 -0300139 .status_mode = S5H1409_DEMODLOCKING,
140 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300141};
142
Steven Tothfc959be2007-09-08 19:08:17 -0300143static struct s5h1409_config hauppauge_hvr1800lp_config = {
144 .demod_address = 0x32 >> 1,
145 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothd19770e2007-03-11 20:44:05 -0300146 .gpio = S5H1409_GPIO_OFF,
Michael Krufky2b032382007-12-13 10:04:10 -0300147 .qam_if = 44000,
Steven Tothfe475162007-03-20 15:27:53 -0300148 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300149 .status_mode = S5H1409_DEMODLOCKING,
150 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd19770e2007-03-11 20:44:05 -0300151};
152
Michael Krufky07b4a832007-12-18 01:09:11 -0300153static struct s5h1409_config hauppauge_hvr1500_config = {
154 .demod_address = 0x32 >> 1,
155 .output_mode = S5H1409_SERIAL_OUTPUT,
156 .gpio = S5H1409_GPIO_OFF,
157 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300158 .status_mode = S5H1409_DEMODLOCKING,
159 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky07b4a832007-12-18 01:09:11 -0300160};
161
Steven Toth86184e02007-09-04 21:40:47 -0300162static struct mt2131_config hauppauge_generic_tunerconfig = {
Steven Totha77743b2007-08-22 21:01:20 -0300163 0x61
164};
165
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300166static struct lgdt330x_config fusionhdtv_5_express = {
167 .demod_address = 0x0e,
168 .demod_chip = LGDT3303,
169 .serial_mpeg = 0x40,
170};
171
Steven Tothd1987d52007-12-18 01:57:06 -0300172static struct s5h1409_config hauppauge_hvr1500q_config = {
173 .demod_address = 0x32 >> 1,
174 .output_mode = S5H1409_SERIAL_OUTPUT,
175 .gpio = S5H1409_GPIO_ON,
176 .qam_if = 44000,
177 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300178 .status_mode = S5H1409_DEMODLOCKING,
179 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd1987d52007-12-18 01:57:06 -0300180};
181
182static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
Steven Tothe12671c2007-12-20 01:14:43 -0300183 .i2c_address = 0x61,
184 .if_khz = 5380,
Steven Tothd1987d52007-12-18 01:57:06 -0300185 .request_firmware = cx23885_request_firmware,
Steven Tothe12671c2007-12-20 01:14:43 -0300186 .tuner_reset = hauppauge_hvr1500q_tuner_reset
Steven Tothd1987d52007-12-18 01:57:06 -0300187};
188
Michael Krufky4041f1a2007-12-24 04:52:08 -0300189static struct tda829x_config tda829x_no_probe = {
190 .probe_tuner = TDA829X_DONT_PROBE,
191};
192
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300193static struct tda18271_std_map hauppauge_tda18271_std_map = {
Michael Krufky2ba65d52008-01-03 01:17:45 -0300194 .atsc_6 = { .if_freq = 5380, .std_bits = 0x1b },
195 .qam_6 = { .if_freq = 4000, .std_bits = 0x18 },
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300196};
197
198static struct tda18271_config hauppauge_tda18271_config = {
199 .std_map = &hauppauge_tda18271_std_map,
200 .gate = TDA18271_GATE_ANALOG,
201};
202
Michael Krufky07b4a832007-12-18 01:09:11 -0300203static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
204{
205 struct cx23885_tsport *port = ptr;
206 struct cx23885_dev *dev = port->dev;
207
208 switch (command) {
209 case XC2028_TUNER_RESET:
210 /* Send the tuner in then out of reset */
211 /* GPIO-2 xc3028 tuner */
212 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg);
213
214 cx_set(GP0_IO, 0x00040000);
215 cx_clear(GP0_IO, 0x00000004);
216 msleep(5);
217
218 cx_set(GP0_IO, 0x00040004);
219 msleep(5);
220 break;
221 case XC2028_RESET_CLK:
222 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg);
223 break;
224 default:
225 dprintk(1, "%s: unknown command %d, arg %d\n", __FUNCTION__,
226 command, arg);
227 return -EINVAL;
228 }
229
230 return 0;
231}
232
Steven Tothd19770e2007-03-11 20:44:05 -0300233static int dvb_register(struct cx23885_tsport *port)
234{
235 struct cx23885_dev *dev = port->dev;
Michael Krufkyf139fa72007-09-09 03:55:34 -0300236 struct cx23885_i2c *i2c_bus = NULL;
Steven Tothd19770e2007-03-11 20:44:05 -0300237
238 /* init struct videobuf_dvb */
239 port->dvb.name = dev->name;
240
241 /* init frontend */
242 switch (dev->board) {
Steven Totha77743b2007-08-22 21:01:20 -0300243 case CX23885_BOARD_HAUPPAUGE_HVR1250:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300244 i2c_bus = &dev->i2c_bus[0];
Steven Tothd19770e2007-03-11 20:44:05 -0300245 port->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Toth86184e02007-09-04 21:40:47 -0300246 &hauppauge_generic_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300247 &i2c_bus->i2c_adap);
Steven Tothd19770e2007-03-11 20:44:05 -0300248 if (port->dvb.frontend != NULL) {
Michael Krufky44a64812007-03-20 23:00:18 -0300249 dvb_attach(mt2131_attach, port->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300250 &i2c_bus->i2c_adap,
Steven Toth86184e02007-09-04 21:40:47 -0300251 &hauppauge_generic_tunerconfig, 0);
Steven Tothd19770e2007-03-11 20:44:05 -0300252 }
253 break;
Michael Krufky3ba71d22007-12-07 01:40:36 -0300254 case CX23885_BOARD_HAUPPAUGE_HVR1800:
255 i2c_bus = &dev->i2c_bus[0];
256 switch (alt_tuner) {
257 case 1:
258 port->dvb.frontend =
259 dvb_attach(s5h1409_attach,
260 &hauppauge_ezqam_config,
261 &i2c_bus->i2c_adap);
262 if (port->dvb.frontend != NULL) {
263 dvb_attach(tda829x_attach, port->dvb.frontend,
264 &dev->i2c_bus[1].i2c_adap, 0x42,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300265 &tda829x_no_probe);
266 dvb_attach(tda18271_attach, port->dvb.frontend,
267 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300268 &hauppauge_tda18271_config);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300269 }
270 break;
271 case 0:
272 default:
273 port->dvb.frontend =
274 dvb_attach(s5h1409_attach,
275 &hauppauge_generic_config,
276 &i2c_bus->i2c_adap);
277 if (port->dvb.frontend != NULL)
278 dvb_attach(mt2131_attach, port->dvb.frontend,
279 &i2c_bus->i2c_adap,
280 &hauppauge_generic_tunerconfig, 0);
281 break;
282 }
283 break;
Steven Tothfc959be2007-09-08 19:08:17 -0300284 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300285 i2c_bus = &dev->i2c_bus[0];
Steven Tothfc959be2007-09-08 19:08:17 -0300286 port->dvb.frontend = dvb_attach(s5h1409_attach,
287 &hauppauge_hvr1800lp_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300288 &i2c_bus->i2c_adap);
Steven Tothfc959be2007-09-08 19:08:17 -0300289 if (port->dvb.frontend != NULL) {
290 dvb_attach(mt2131_attach, port->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300291 &i2c_bus->i2c_adap,
Steven Tothfc959be2007-09-08 19:08:17 -0300292 &hauppauge_generic_tunerconfig, 0);
293 }
294 break;
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300295 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300296 i2c_bus = &dev->i2c_bus[0];
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300297 port->dvb.frontend = dvb_attach(lgdt330x_attach,
298 &fusionhdtv_5_express,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300299 &i2c_bus->i2c_adap);
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300300 if (port->dvb.frontend != NULL) {
Michael Krufkyf139fa72007-09-09 03:55:34 -0300301 dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61,
302 &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF);
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300303 }
304 break;
Steven Tothd1987d52007-12-18 01:57:06 -0300305 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
306 i2c_bus = &dev->i2c_bus[1];
307 port->dvb.frontend = dvb_attach(s5h1409_attach,
308 &hauppauge_hvr1500q_config,
309 &dev->i2c_bus[0].i2c_adap);
310 if (port->dvb.frontend != NULL) {
311 dvb_attach(xc5000_attach, port->dvb.frontend,
312 &i2c_bus->i2c_adap,
313 &hauppauge_hvr1500q_tunerconfig);
314 }
315 break;
Michael Krufky07b4a832007-12-18 01:09:11 -0300316 case CX23885_BOARD_HAUPPAUGE_HVR1500:
317 i2c_bus = &dev->i2c_bus[1];
318 port->dvb.frontend = dvb_attach(s5h1409_attach,
319 &hauppauge_hvr1500_config,
320 &dev->i2c_bus[0].i2c_adap);
321 if (port->dvb.frontend != NULL) {
322 struct dvb_frontend *fe;
323 struct xc2028_config cfg = {
324 .i2c_adap = &i2c_bus->i2c_adap,
325 .i2c_addr = 0x61,
326 .video_dev = port,
327 .callback = cx23885_hvr1500_xc3028_callback,
328 };
329 static struct xc2028_ctrl ctl = {
330 .fname = "xc3028-v27.fw",
331 .max_len = 64,
332 .scode_table = OREN538,
333 };
334
335 fe = dvb_attach(xc2028_attach,
336 port->dvb.frontend, &cfg);
337 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
338 fe->ops.tuner_ops.set_config(fe, &ctl);
339 }
340 break;
Steven Tothd19770e2007-03-11 20:44:05 -0300341 default:
342 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
343 dev->name);
344 break;
345 }
346 if (NULL == port->dvb.frontend) {
347 printk("%s: frontend initialization failed\n", dev->name);
348 return -1;
349 }
350
351 /* Put the analog decoder in standby to keep it quiet */
Michael Krufkyf139fa72007-09-09 03:55:34 -0300352 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
Steven Tothd19770e2007-03-11 20:44:05 -0300353
Michael Krufky3ba71d22007-12-07 01:40:36 -0300354 if (port->dvb.frontend->ops.analog_ops.standby)
355 port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend);
356
Steven Tothd19770e2007-03-11 20:44:05 -0300357 /* register everything */
Michael Krufky44a64812007-03-20 23:00:18 -0300358 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
359 &dev->pci->dev);
Steven Tothd19770e2007-03-11 20:44:05 -0300360}
361
362int cx23885_dvb_register(struct cx23885_tsport *port)
363{
364 struct cx23885_dev *dev = port->dev;
365 int err;
366
Michael Krufky44a64812007-03-20 23:00:18 -0300367 dprintk(1, "%s\n", __FUNCTION__);
368 dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
Steven Tothd19770e2007-03-11 20:44:05 -0300369 dev->board,
370 dev->name,
371 dev->pci_bus,
372 dev->pci_slot);
373
374 err = -ENODEV;
Steven Tothd19770e2007-03-11 20:44:05 -0300375
376 /* dvb stuff */
377 printk("%s: cx23885 based dvb card\n", dev->name);
Mauro Carvalho Chehabaecfde52007-10-08 09:04:09 -0300378 videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock,
Michael Krufky44a64812007-03-20 23:00:18 -0300379 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
380 sizeof(struct cx23885_buffer), port);
Steven Tothd19770e2007-03-11 20:44:05 -0300381 err = dvb_register(port);
382 if (err != 0)
383 printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
384
Steven Tothd19770e2007-03-11 20:44:05 -0300385 return err;
386}
387
388int cx23885_dvb_unregister(struct cx23885_tsport *port)
389{
390 /* dvb */
391 if(port->dvb.frontend)
392 videobuf_dvb_unregister(&port->dvb);
393
394 return 0;
395}
Michael Krufky44a64812007-03-20 23:00:18 -0300396
397/*
398 * Local variables:
399 * c-basic-offset: 8
400 * End:
401 * 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
402*/