blob: 34910368049e5a5ea990ef9cda73f3cdee552561 [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,
129 .status_mode = S5H1409_DEMODLOCKING
130};
131
Michael Krufky3ba71d22007-12-07 01:40:36 -0300132static struct s5h1409_config hauppauge_ezqam_config = {
133 .demod_address = 0x32 >> 1,
134 .output_mode = S5H1409_SERIAL_OUTPUT,
135 .gpio = S5H1409_GPIO_OFF,
136 .qam_if = 4000,
137 .inversion = S5H1409_INVERSION_ON,
138 .status_mode = S5H1409_DEMODLOCKING
139};
140
Steven Tothfc959be2007-09-08 19:08:17 -0300141static struct s5h1409_config hauppauge_hvr1800lp_config = {
142 .demod_address = 0x32 >> 1,
143 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothd19770e2007-03-11 20:44:05 -0300144 .gpio = S5H1409_GPIO_OFF,
Michael Krufky2b032382007-12-13 10:04:10 -0300145 .qam_if = 44000,
Steven Tothfe4751632007-03-20 15:27:53 -0300146 .inversion = S5H1409_INVERSION_OFF,
147 .status_mode = S5H1409_DEMODLOCKING
Steven Tothd19770e2007-03-11 20:44:05 -0300148};
149
Michael Krufky07b4a832007-12-18 01:09:11 -0300150static struct s5h1409_config hauppauge_hvr1500_config = {
151 .demod_address = 0x32 >> 1,
152 .output_mode = S5H1409_SERIAL_OUTPUT,
153 .gpio = S5H1409_GPIO_OFF,
154 .inversion = S5H1409_INVERSION_OFF,
155 .status_mode = S5H1409_DEMODLOCKING
156};
157
Steven Toth86184e02007-09-04 21:40:47 -0300158static struct mt2131_config hauppauge_generic_tunerconfig = {
Steven Totha77743b2007-08-22 21:01:20 -0300159 0x61
160};
161
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300162static struct lgdt330x_config fusionhdtv_5_express = {
163 .demod_address = 0x0e,
164 .demod_chip = LGDT3303,
165 .serial_mpeg = 0x40,
166};
167
Steven Tothd1987d52007-12-18 01:57:06 -0300168static struct s5h1409_config hauppauge_hvr1500q_config = {
169 .demod_address = 0x32 >> 1,
170 .output_mode = S5H1409_SERIAL_OUTPUT,
171 .gpio = S5H1409_GPIO_ON,
172 .qam_if = 44000,
173 .inversion = S5H1409_INVERSION_OFF,
174 .status_mode = S5H1409_DEMODLOCKING
175};
176
177static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
Steven Tothe12671cf2007-12-20 01:14:43 -0300178 .i2c_address = 0x61,
179 .if_khz = 5380,
Steven Tothd1987d52007-12-18 01:57:06 -0300180 .request_firmware = cx23885_request_firmware,
Steven Tothe12671cf2007-12-20 01:14:43 -0300181 .tuner_reset = hauppauge_hvr1500q_tuner_reset
Steven Tothd1987d52007-12-18 01:57:06 -0300182};
183
Michael Krufky4041f1a2007-12-24 04:52:08 -0300184static struct tda829x_config tda829x_no_probe = {
185 .probe_tuner = TDA829X_DONT_PROBE,
186};
187
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300188static struct tda18271_std_map hauppauge_tda18271_std_map = {
Michael Krufky2ba65d52008-01-03 01:17:45 -0300189 .atsc_6 = { .if_freq = 5380, .std_bits = 0x1b },
190 .qam_6 = { .if_freq = 4000, .std_bits = 0x18 },
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300191};
192
193static struct tda18271_config hauppauge_tda18271_config = {
194 .std_map = &hauppauge_tda18271_std_map,
195 .gate = TDA18271_GATE_ANALOG,
196};
197
Michael Krufky07b4a832007-12-18 01:09:11 -0300198static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
199{
200 struct cx23885_tsport *port = ptr;
201 struct cx23885_dev *dev = port->dev;
202
203 switch (command) {
204 case XC2028_TUNER_RESET:
205 /* Send the tuner in then out of reset */
206 /* GPIO-2 xc3028 tuner */
207 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg);
208
209 cx_set(GP0_IO, 0x00040000);
210 cx_clear(GP0_IO, 0x00000004);
211 msleep(5);
212
213 cx_set(GP0_IO, 0x00040004);
214 msleep(5);
215 break;
216 case XC2028_RESET_CLK:
217 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg);
218 break;
219 default:
220 dprintk(1, "%s: unknown command %d, arg %d\n", __FUNCTION__,
221 command, arg);
222 return -EINVAL;
223 }
224
225 return 0;
226}
227
Steven Tothd19770e2007-03-11 20:44:05 -0300228static int dvb_register(struct cx23885_tsport *port)
229{
230 struct cx23885_dev *dev = port->dev;
Michael Krufkyf139fa72007-09-09 03:55:34 -0300231 struct cx23885_i2c *i2c_bus = NULL;
Steven Tothd19770e2007-03-11 20:44:05 -0300232
233 /* init struct videobuf_dvb */
234 port->dvb.name = dev->name;
235
236 /* init frontend */
237 switch (dev->board) {
Steven Totha77743b2007-08-22 21:01:20 -0300238 case CX23885_BOARD_HAUPPAUGE_HVR1250:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300239 i2c_bus = &dev->i2c_bus[0];
Steven Tothd19770e2007-03-11 20:44:05 -0300240 port->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Toth86184e02007-09-04 21:40:47 -0300241 &hauppauge_generic_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300242 &i2c_bus->i2c_adap);
Steven Tothd19770e2007-03-11 20:44:05 -0300243 if (port->dvb.frontend != NULL) {
Michael Krufky44a64812007-03-20 23:00:18 -0300244 dvb_attach(mt2131_attach, port->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300245 &i2c_bus->i2c_adap,
Steven Toth86184e02007-09-04 21:40:47 -0300246 &hauppauge_generic_tunerconfig, 0);
Steven Tothd19770e2007-03-11 20:44:05 -0300247 }
248 break;
Michael Krufky3ba71d22007-12-07 01:40:36 -0300249 case CX23885_BOARD_HAUPPAUGE_HVR1800:
250 i2c_bus = &dev->i2c_bus[0];
251 switch (alt_tuner) {
252 case 1:
253 port->dvb.frontend =
254 dvb_attach(s5h1409_attach,
255 &hauppauge_ezqam_config,
256 &i2c_bus->i2c_adap);
257 if (port->dvb.frontend != NULL) {
258 dvb_attach(tda829x_attach, port->dvb.frontend,
259 &dev->i2c_bus[1].i2c_adap, 0x42,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300260 &tda829x_no_probe);
261 dvb_attach(tda18271_attach, port->dvb.frontend,
262 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300263 &hauppauge_tda18271_config);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300264 }
265 break;
266 case 0:
267 default:
268 port->dvb.frontend =
269 dvb_attach(s5h1409_attach,
270 &hauppauge_generic_config,
271 &i2c_bus->i2c_adap);
272 if (port->dvb.frontend != NULL)
273 dvb_attach(mt2131_attach, port->dvb.frontend,
274 &i2c_bus->i2c_adap,
275 &hauppauge_generic_tunerconfig, 0);
276 break;
277 }
278 break;
Steven Tothfc959be2007-09-08 19:08:17 -0300279 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300280 i2c_bus = &dev->i2c_bus[0];
Steven Tothfc959be2007-09-08 19:08:17 -0300281 port->dvb.frontend = dvb_attach(s5h1409_attach,
282 &hauppauge_hvr1800lp_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300283 &i2c_bus->i2c_adap);
Steven Tothfc959be2007-09-08 19:08:17 -0300284 if (port->dvb.frontend != NULL) {
285 dvb_attach(mt2131_attach, port->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300286 &i2c_bus->i2c_adap,
Steven Tothfc959be2007-09-08 19:08:17 -0300287 &hauppauge_generic_tunerconfig, 0);
288 }
289 break;
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300290 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300291 i2c_bus = &dev->i2c_bus[0];
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300292 port->dvb.frontend = dvb_attach(lgdt330x_attach,
293 &fusionhdtv_5_express,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300294 &i2c_bus->i2c_adap);
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300295 if (port->dvb.frontend != NULL) {
Michael Krufkyf139fa72007-09-09 03:55:34 -0300296 dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61,
297 &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF);
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300298 }
299 break;
Steven Tothd1987d52007-12-18 01:57:06 -0300300 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
301 i2c_bus = &dev->i2c_bus[1];
302 port->dvb.frontend = dvb_attach(s5h1409_attach,
303 &hauppauge_hvr1500q_config,
304 &dev->i2c_bus[0].i2c_adap);
305 if (port->dvb.frontend != NULL) {
306 dvb_attach(xc5000_attach, port->dvb.frontend,
307 &i2c_bus->i2c_adap,
308 &hauppauge_hvr1500q_tunerconfig);
309 }
310 break;
Michael Krufky07b4a832007-12-18 01:09:11 -0300311 case CX23885_BOARD_HAUPPAUGE_HVR1500:
312 i2c_bus = &dev->i2c_bus[1];
313 port->dvb.frontend = dvb_attach(s5h1409_attach,
314 &hauppauge_hvr1500_config,
315 &dev->i2c_bus[0].i2c_adap);
316 if (port->dvb.frontend != NULL) {
317 struct dvb_frontend *fe;
318 struct xc2028_config cfg = {
319 .i2c_adap = &i2c_bus->i2c_adap,
320 .i2c_addr = 0x61,
321 .video_dev = port,
322 .callback = cx23885_hvr1500_xc3028_callback,
323 };
324 static struct xc2028_ctrl ctl = {
325 .fname = "xc3028-v27.fw",
326 .max_len = 64,
327 .scode_table = OREN538,
328 };
329
330 fe = dvb_attach(xc2028_attach,
331 port->dvb.frontend, &cfg);
332 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
333 fe->ops.tuner_ops.set_config(fe, &ctl);
334 }
335 break;
Steven Tothd19770e2007-03-11 20:44:05 -0300336 default:
337 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
338 dev->name);
339 break;
340 }
341 if (NULL == port->dvb.frontend) {
342 printk("%s: frontend initialization failed\n", dev->name);
343 return -1;
344 }
345
346 /* Put the analog decoder in standby to keep it quiet */
Michael Krufkyf139fa72007-09-09 03:55:34 -0300347 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
Steven Tothd19770e2007-03-11 20:44:05 -0300348
Michael Krufky3ba71d22007-12-07 01:40:36 -0300349 if (port->dvb.frontend->ops.analog_ops.standby)
350 port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend);
351
Steven Tothd19770e2007-03-11 20:44:05 -0300352 /* register everything */
Michael Krufky44a64812007-03-20 23:00:18 -0300353 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
354 &dev->pci->dev);
Steven Tothd19770e2007-03-11 20:44:05 -0300355}
356
357int cx23885_dvb_register(struct cx23885_tsport *port)
358{
359 struct cx23885_dev *dev = port->dev;
360 int err;
361
Michael Krufky44a64812007-03-20 23:00:18 -0300362 dprintk(1, "%s\n", __FUNCTION__);
363 dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
Steven Tothd19770e2007-03-11 20:44:05 -0300364 dev->board,
365 dev->name,
366 dev->pci_bus,
367 dev->pci_slot);
368
369 err = -ENODEV;
Steven Tothd19770e2007-03-11 20:44:05 -0300370
371 /* dvb stuff */
372 printk("%s: cx23885 based dvb card\n", dev->name);
Mauro Carvalho Chehabaecfde52007-10-08 09:04:09 -0300373 videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock,
Michael Krufky44a64812007-03-20 23:00:18 -0300374 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
375 sizeof(struct cx23885_buffer), port);
Steven Tothd19770e2007-03-11 20:44:05 -0300376 err = dvb_register(port);
377 if (err != 0)
378 printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
379
Steven Tothd19770e2007-03-11 20:44:05 -0300380 return err;
381}
382
383int cx23885_dvb_unregister(struct cx23885_tsport *port)
384{
385 /* dvb */
386 if(port->dvb.frontend)
387 videobuf_dvb_unregister(&port->dvb);
388
389 return 0;
390}
Michael Krufky44a64812007-03-20 23:00:18 -0300391
392/*
393 * Local variables:
394 * c-basic-offset: 8
395 * End:
396 * 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
397*/