Commit | Line | Data |
---|---|---|
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" | |
3ba71d21 | 35 | #include "tda8290.h" |
4041f1a5 | 36 | #include "tda18271.h" |
9bc37caa | 37 | #include "lgdt330x.h" |
d1987d55 | 38 | #include "xc5000.h" |
9bc37caa | 39 | #include "dvb-pll.h" |
07b4a835 MK |
40 | #include "tuner-xc2028.h" |
41 | #include "tuner-xc2028-types.h" | |
d19770e5 | 42 | |
4513fc69 | 43 | static unsigned int debug; |
d19770e5 | 44 | |
4513fc69 ST |
45 | #define dprintk(level, fmt, arg...)\ |
46 | do { if (debug >= level)\ | |
47 | printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\ | |
48 | } while (0) | |
d19770e5 ST |
49 | |
50 | /* ------------------------------------------------------------------ */ | |
51 | ||
3ba71d21 MK |
52 | static unsigned int alt_tuner; |
53 | module_param(alt_tuner, int, 0644); | |
54 | MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration"); | |
55 | ||
56 | /* ------------------------------------------------------------------ */ | |
57 | ||
d19770e5 ST |
58 | static 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 | ||
44a6481d MK |
71 | static int dvb_buf_prepare(struct videobuf_queue *q, |
72 | struct videobuf_buffer *vb, enum v4l2_field field) | |
d19770e5 ST |
73 | { |
74 | struct cx23885_tsport *port = q->priv_data; | |
44a6481d | 75 | return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field); |
d19770e5 ST |
76 | } |
77 | ||
78 | static 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 | ||
44a6481d MK |
84 | static void dvb_buf_release(struct videobuf_queue *q, |
85 | struct videobuf_buffer *vb) | |
d19770e5 ST |
86 | { |
87 | cx23885_free_buffer(q, (struct cx23885_buffer*)vb); | |
88 | } | |
89 | ||
d1987d55 ST |
90 | static 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 | ||
101 | static 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 | ||
d19770e5 ST |
116 | static 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 | ||
86184e06 | 123 | static struct s5h1409_config hauppauge_generic_config = { |
fc959bef ST |
124 | .demod_address = 0x32 >> 1, |
125 | .output_mode = S5H1409_SERIAL_OUTPUT, | |
126 | .gpio = S5H1409_GPIO_ON, | |
2b03238a | 127 | .qam_if = 44000, |
fc959bef ST |
128 | .inversion = S5H1409_INVERSION_OFF, |
129 | .status_mode = S5H1409_DEMODLOCKING | |
130 | }; | |
131 | ||
3ba71d21 MK |
132 | static 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 | ||
fc959bef | 141 | static struct s5h1409_config hauppauge_hvr1800lp_config = { |
d19770e5 ST |
142 | .demod_address = 0x32 >> 1, |
143 | .output_mode = S5H1409_SERIAL_OUTPUT, | |
144 | .gpio = S5H1409_GPIO_OFF, | |
2b03238a | 145 | .qam_if = 44000, |
fe475163 ST |
146 | .inversion = S5H1409_INVERSION_OFF, |
147 | .status_mode = S5H1409_DEMODLOCKING | |
d19770e5 ST |
148 | }; |
149 | ||
07b4a835 MK |
150 | static 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 | ||
86184e06 | 158 | static struct mt2131_config hauppauge_generic_tunerconfig = { |
a77743bc ST |
159 | 0x61 |
160 | }; | |
161 | ||
9bc37caa MK |
162 | static struct lgdt330x_config fusionhdtv_5_express = { |
163 | .demod_address = 0x0e, | |
164 | .demod_chip = LGDT3303, | |
165 | .serial_mpeg = 0x40, | |
166 | }; | |
167 | ||
d1987d55 ST |
168 | static 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 | ||
177 | static struct xc5000_config hauppauge_hvr1500q_tunerconfig = { | |
e12671cf ST |
178 | .i2c_address = 0x61, |
179 | .if_khz = 5380, | |
d1987d55 | 180 | .request_firmware = cx23885_request_firmware, |
e12671cf | 181 | .tuner_reset = hauppauge_hvr1500q_tuner_reset |
d1987d55 ST |
182 | }; |
183 | ||
4041f1a5 MK |
184 | static struct tda829x_config tda829x_no_probe = { |
185 | .probe_tuner = TDA829X_DONT_PROBE, | |
186 | }; | |
187 | ||
f21e0d7f | 188 | static struct tda18271_std_map hauppauge_tda18271_std_map = { |
2ba65d51 MK |
189 | .atsc_6 = { .if_freq = 5380, .std_bits = 0x1b }, |
190 | .qam_6 = { .if_freq = 4000, .std_bits = 0x18 }, | |
f21e0d7f MK |
191 | }; |
192 | ||
193 | static struct tda18271_config hauppauge_tda18271_config = { | |
194 | .std_map = &hauppauge_tda18271_std_map, | |
195 | .gate = TDA18271_GATE_ANALOG, | |
196 | }; | |
197 | ||
07b4a835 MK |
198 | static 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 | ||
d19770e5 ST |
228 | static int dvb_register(struct cx23885_tsport *port) |
229 | { | |
230 | struct cx23885_dev *dev = port->dev; | |
f139fa71 | 231 | struct cx23885_i2c *i2c_bus = NULL; |
d19770e5 ST |
232 | |
233 | /* init struct videobuf_dvb */ | |
234 | port->dvb.name = dev->name; | |
235 | ||
236 | /* init frontend */ | |
237 | switch (dev->board) { | |
a77743bc | 238 | case CX23885_BOARD_HAUPPAUGE_HVR1250: |
f139fa71 | 239 | i2c_bus = &dev->i2c_bus[0]; |
d19770e5 | 240 | port->dvb.frontend = dvb_attach(s5h1409_attach, |
86184e06 | 241 | &hauppauge_generic_config, |
f139fa71 | 242 | &i2c_bus->i2c_adap); |
d19770e5 | 243 | if (port->dvb.frontend != NULL) { |
44a6481d | 244 | dvb_attach(mt2131_attach, port->dvb.frontend, |
f139fa71 | 245 | &i2c_bus->i2c_adap, |
86184e06 | 246 | &hauppauge_generic_tunerconfig, 0); |
d19770e5 ST |
247 | } |
248 | break; | |
3ba71d21 MK |
249 | 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, | |
4041f1a5 MK |
260 | &tda829x_no_probe); |
261 | dvb_attach(tda18271_attach, port->dvb.frontend, | |
262 | 0x60, &dev->i2c_bus[1].i2c_adap, | |
f21e0d7f | 263 | &hauppauge_tda18271_config); |
3ba71d21 MK |
264 | } |
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; | |
fc959bef | 279 | case CX23885_BOARD_HAUPPAUGE_HVR1800lp: |
f139fa71 | 280 | i2c_bus = &dev->i2c_bus[0]; |
fc959bef ST |
281 | port->dvb.frontend = dvb_attach(s5h1409_attach, |
282 | &hauppauge_hvr1800lp_config, | |
f139fa71 | 283 | &i2c_bus->i2c_adap); |
fc959bef ST |
284 | if (port->dvb.frontend != NULL) { |
285 | dvb_attach(mt2131_attach, port->dvb.frontend, | |
f139fa71 | 286 | &i2c_bus->i2c_adap, |
fc959bef ST |
287 | &hauppauge_generic_tunerconfig, 0); |
288 | } | |
289 | break; | |
9bc37caa | 290 | case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP: |
f139fa71 | 291 | i2c_bus = &dev->i2c_bus[0]; |
9bc37caa MK |
292 | port->dvb.frontend = dvb_attach(lgdt330x_attach, |
293 | &fusionhdtv_5_express, | |
f139fa71 | 294 | &i2c_bus->i2c_adap); |
9bc37caa | 295 | if (port->dvb.frontend != NULL) { |
f139fa71 MK |
296 | dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61, |
297 | &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF); | |
9bc37caa MK |
298 | } |
299 | break; | |
d1987d55 ST |
300 | 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; | |
07b4a835 MK |
311 | 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; | |
d19770e5 ST |
336 | 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 */ | |
f139fa71 | 347 | cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL); |
d19770e5 | 348 | |
3ba71d21 MK |
349 | if (port->dvb.frontend->ops.analog_ops.standby) |
350 | port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend); | |
351 | ||
d19770e5 | 352 | /* register everything */ |
44a6481d MK |
353 | return videobuf_dvb_register(&port->dvb, THIS_MODULE, port, |
354 | &dev->pci->dev); | |
d19770e5 ST |
355 | } |
356 | ||
357 | int cx23885_dvb_register(struct cx23885_tsport *port) | |
358 | { | |
359 | struct cx23885_dev *dev = port->dev; | |
360 | int err; | |
361 | ||
44a6481d MK |
362 | dprintk(1, "%s\n", __FUNCTION__); |
363 | dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n", | |
d19770e5 ST |
364 | dev->board, |
365 | dev->name, | |
366 | dev->pci_bus, | |
367 | dev->pci_slot); | |
368 | ||
369 | err = -ENODEV; | |
d19770e5 ST |
370 | |
371 | /* dvb stuff */ | |
372 | printk("%s: cx23885 based dvb card\n", dev->name); | |
aecfde53 | 373 | videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock, |
44a6481d MK |
374 | V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP, |
375 | sizeof(struct cx23885_buffer), port); | |
d19770e5 ST |
376 | err = dvb_register(port); |
377 | if (err != 0) | |
378 | printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err); | |
379 | ||
d19770e5 ST |
380 | return err; |
381 | } | |
382 | ||
383 | int 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 | } | |
44a6481d MK |
391 | |
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 | */ |