blob: 188a5a7819cb1c8fb5ee75f17abcf9deb7c43517 [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"
31#include "dvb-pll.h"
32#include <media/v4l2-common.h>
33
34#include "s5h1409.h"
35#include "mt2131.h"
36
37static unsigned int debug = 2;
38
39#define dprintk(level,fmt, arg...) if (debug >= level) \
40 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg)
41
42/* ------------------------------------------------------------------ */
43
44static int dvb_buf_setup(struct videobuf_queue *q,
45 unsigned int *count, unsigned int *size)
46{
47 struct cx23885_tsport *port = q->priv_data;
48
49 port->ts_packet_size = 188 * 4;
50 port->ts_packet_count = 32;
51
52 *size = port->ts_packet_size * port->ts_packet_count;
53 *count = 32;
54 return 0;
55}
56
57static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
58 enum v4l2_field field)
59{
60 struct cx23885_tsport *port = q->priv_data;
61 return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb,field);
62}
63
64static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
65{
66 struct cx23885_tsport *port = q->priv_data;
67 cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
68}
69
70static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
71{
72 cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
73}
74
75static struct videobuf_queue_ops dvb_qops = {
76 .buf_setup = dvb_buf_setup,
77 .buf_prepare = dvb_buf_prepare,
78 .buf_queue = dvb_buf_queue,
79 .buf_release = dvb_buf_release,
80};
81
82static struct s5h1409_config hauppauge_hvr1800lp_config = {
83 .demod_address = 0x32 >> 1,
84 .output_mode = S5H1409_SERIAL_OUTPUT,
85 .gpio = S5H1409_GPIO_OFF,
86 .if_freq = 44000,
Steven Tothfe4751632007-03-20 15:27:53 -030087 .inversion = S5H1409_INVERSION_OFF,
88 .status_mode = S5H1409_DEMODLOCKING
Steven Tothd19770e2007-03-11 20:44:05 -030089};
90
91static struct s5h1409_config hauppauge_hvr1800_config = {
92 .demod_address = 0x32 >> 1,
93 .output_mode = S5H1409_SERIAL_OUTPUT,
94 .gpio = S5H1409_GPIO_ON,
95 .if_freq = 44000,
Steven Tothfe4751632007-03-20 15:27:53 -030096 .inversion = S5H1409_INVERSION_OFF,
97 .status_mode = S5H1409_DEMODLOCKING
Steven Tothd19770e2007-03-11 20:44:05 -030098};
99
100
101static struct mt2131_config hauppauge_hvr1800lp_rev2_tunerconfig = {
102 0x61
103};
104
105static struct mt2131_config hauppauge_hvr1800_tunerconfig = {
106 0x61
107};
108
109static int dvb_register(struct cx23885_tsport *port)
110{
111 struct cx23885_dev *dev = port->dev;
112
113 /* init struct videobuf_dvb */
114 port->dvb.name = dev->name;
115
116 /* init frontend */
117 switch (dev->board) {
118 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
119 port->dvb.frontend = dvb_attach(s5h1409_attach,
120 &hauppauge_hvr1800lp_config,
121 &dev->i2c_bus[0].i2c_adap);
122 if (port->dvb.frontend != NULL) {
123 dvb_attach(mt2131_attach,
124 port->dvb.frontend,
125 &dev->i2c_bus[0].i2c_adap,
126 &hauppauge_hvr1800lp_rev2_tunerconfig,
127 0);
128 }
129 break;
130 case CX23885_BOARD_HAUPPAUGE_HVR1800:
131 port->dvb.frontend = dvb_attach(s5h1409_attach,
132 &hauppauge_hvr1800_config,
133 &dev->i2c_bus[0].i2c_adap);
134 if (port->dvb.frontend != NULL) {
135 dvb_attach(mt2131_attach,
136 port->dvb.frontend,
137 &dev->i2c_bus[0].i2c_adap,
138 &hauppauge_hvr1800_tunerconfig,
139 0);
140 }
141 break;
142 default:
143 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
144 dev->name);
145 break;
146 }
147 if (NULL == port->dvb.frontend) {
148 printk("%s: frontend initialization failed\n", dev->name);
149 return -1;
150 }
151
152 /* Put the analog decoder in standby to keep it quiet */
153 cx23885_call_i2c_clients (&dev->i2c_bus[0], TUNER_SET_STANDBY, NULL);
154
155 /* register everything */
156 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port, &dev->pci->dev);
157}
158
159int cx23885_dvb_register(struct cx23885_tsport *port)
160{
161 struct cx23885_dev *dev = port->dev;
162 int err;
163
164 dprintk( 1, "%s\n", __FUNCTION__);
165 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
166 dev->board,
167 dev->name,
168 dev->pci_bus,
169 dev->pci_slot);
170
171 err = -ENODEV;
172 if (!(cx23885_boards[dev->board].portc & CX23885_MPEG_DVB))
173 goto fail_core;
174
175 /* dvb stuff */
176 printk("%s: cx23885 based dvb card\n", dev->name);
177 videobuf_queue_init(
178 &port->dvb.dvbq,
179 &dvb_qops,
180 dev->pci,
181 &port->slock,
182 V4L2_BUF_TYPE_VIDEO_CAPTURE,
183 V4L2_FIELD_TOP,
184 sizeof(struct cx23885_buffer),
185 port);
186 err = dvb_register(port);
187 if (err != 0)
188 printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
189
190 fail_core:
191 return err;
192}
193
194int cx23885_dvb_unregister(struct cx23885_tsport *port)
195{
196 /* dvb */
197 if(port->dvb.frontend)
198 videobuf_dvb_unregister(&port->dvb);
199
200 return 0;
201}