2 * Driver for the Conexant CX23885 PCIe bridge
4 * Copyright (c) 2006 Steven Toth <stoth@hauppauge.com>
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.
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
15 * GNU General Public License for more details.
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.
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/device.h>
26 #include <linux/kthread.h>
27 #include <linux/file.h>
28 #include <linux/suspend.h>
31 #include <media/v4l2-common.h>
38 #include "tuner-xc2028.h"
39 #include "tuner-xc2028-types.h"
41 static unsigned int debug = 0;
43 #define dprintk(level,fmt, arg...) if (debug >= level) \
44 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg)
46 /* ------------------------------------------------------------------ */
48 static int dvb_buf_setup(struct videobuf_queue *q,
49 unsigned int *count, unsigned int *size)
51 struct cx23885_tsport *port = q->priv_data;
53 port->ts_packet_size = 188 * 4;
54 port->ts_packet_count = 32;
56 *size = port->ts_packet_size * port->ts_packet_count;
61 static int dvb_buf_prepare(struct videobuf_queue *q,
62 struct videobuf_buffer *vb, enum v4l2_field field)
64 struct cx23885_tsport *port = q->priv_data;
65 return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
68 static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
70 struct cx23885_tsport *port = q->priv_data;
71 cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
74 static void dvb_buf_release(struct videobuf_queue *q,
75 struct videobuf_buffer *vb)
77 cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
80 static int cx23885_request_firmware(struct dvb_frontend *fe,
81 const struct firmware **fw, char *name)
83 struct cx23885_tsport *port = fe->dvb->priv;
84 struct cx23885_dev *dev = port->dev;
86 dprintk(1, "%s(?,?,%s)\n", __FUNCTION__, name);
88 return request_firmware(fw, name, &dev->pci->dev);
91 static int hauppauge_hvr1500q_tuner_reset(struct dvb_frontend *fe)
93 struct cx23885_tsport *port = fe->dvb->priv;
94 struct cx23885_dev *dev = port->dev;
96 dprintk(1, "%s()\n", __FUNCTION__);
98 /* Drive the tuner into reset back back */
99 cx_clear(GP0_IO, 0x00000004);
101 cx_set(GP0_IO, 0x00000004);
106 static 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,
113 static struct s5h1409_config hauppauge_generic_config = {
114 .demod_address = 0x32 >> 1,
115 .output_mode = S5H1409_SERIAL_OUTPUT,
116 .gpio = S5H1409_GPIO_ON,
118 .inversion = S5H1409_INVERSION_OFF,
119 .status_mode = S5H1409_DEMODLOCKING
122 static struct s5h1409_config hauppauge_hvr1800lp_config = {
123 .demod_address = 0x32 >> 1,
124 .output_mode = S5H1409_SERIAL_OUTPUT,
125 .gpio = S5H1409_GPIO_OFF,
127 .inversion = S5H1409_INVERSION_OFF,
128 .status_mode = S5H1409_DEMODLOCKING
131 static 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
139 static struct mt2131_config hauppauge_generic_tunerconfig = {
143 static struct lgdt330x_config fusionhdtv_5_express = {
144 .demod_address = 0x0e,
145 .demod_chip = LGDT3303,
149 static struct s5h1409_config hauppauge_hvr1500q_config = {
150 .demod_address = 0x32 >> 1,
151 .output_mode = S5H1409_SERIAL_OUTPUT,
152 .gpio = S5H1409_GPIO_ON,
154 .inversion = S5H1409_INVERSION_OFF,
155 .status_mode = S5H1409_DEMODLOCKING
158 static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
161 .request_firmware = cx23885_request_firmware,
162 .tuner_reset = hauppauge_hvr1500q_tuner_reset
165 static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
167 struct cx23885_tsport *port = ptr;
168 struct cx23885_dev *dev = port->dev;
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);
176 cx_set(GP0_IO, 0x00040000);
177 cx_clear(GP0_IO, 0x00000004);
180 cx_set(GP0_IO, 0x00040004);
183 case XC2028_RESET_CLK:
184 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg);
187 dprintk(1, "%s: unknown command %d, arg %d\n", __FUNCTION__,
195 static int dvb_register(struct cx23885_tsport *port)
197 struct cx23885_dev *dev = port->dev;
198 struct cx23885_i2c *i2c_bus = NULL;
200 /* init struct videobuf_dvb */
201 port->dvb.name = dev->name;
204 switch (dev->board) {
205 case CX23885_BOARD_HAUPPAUGE_HVR1250:
206 case CX23885_BOARD_HAUPPAUGE_HVR1800:
207 i2c_bus = &dev->i2c_bus[0];
208 port->dvb.frontend = dvb_attach(s5h1409_attach,
209 &hauppauge_generic_config,
211 if (port->dvb.frontend != NULL) {
212 dvb_attach(mt2131_attach, port->dvb.frontend,
214 &hauppauge_generic_tunerconfig, 0);
217 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
218 i2c_bus = &dev->i2c_bus[0];
219 port->dvb.frontend = dvb_attach(s5h1409_attach,
220 &hauppauge_hvr1800lp_config,
222 if (port->dvb.frontend != NULL) {
223 dvb_attach(mt2131_attach, port->dvb.frontend,
225 &hauppauge_generic_tunerconfig, 0);
228 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
229 i2c_bus = &dev->i2c_bus[0];
230 port->dvb.frontend = dvb_attach(lgdt330x_attach,
231 &fusionhdtv_5_express,
233 if (port->dvb.frontend != NULL) {
234 dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61,
235 &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF);
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,
246 &hauppauge_hvr1500q_tunerconfig);
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,
260 .callback = cx23885_hvr1500_xc3028_callback,
262 static struct xc2028_ctrl ctl = {
263 .fname = "xc3028-v27.fw",
265 .scode_table = OREN538,
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);
275 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
279 if (NULL == port->dvb.frontend) {
280 printk("%s: frontend initialization failed\n", dev->name);
284 /* Put the analog decoder in standby to keep it quiet */
285 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
287 /* register everything */
288 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
292 int cx23885_dvb_register(struct cx23885_tsport *port)
294 struct cx23885_dev *dev = port->dev;
297 dprintk(1, "%s\n", __FUNCTION__);
298 dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
307 printk("%s: cx23885 based dvb card\n", dev->name);
308 videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock,
309 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
310 sizeof(struct cx23885_buffer), port);
311 err = dvb_register(port);
313 printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
318 int cx23885_dvb_unregister(struct cx23885_tsport *port)
321 if(port->dvb.frontend)
322 videobuf_dvb_unregister(&port->dvb);
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