1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
/*
* device driver for Conexant 2388x based TV cards
* MPEG Transport Stream (DVB) routines
*
* (c) 2004 Chris Pascoe <c.pascoe@itee.uq.edu.au>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/fs.h>
#include "cx88.h"
MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
MODULE_LICENSE("GPL");
/* ------------------------------------------------------------------ */
#if 0
static void cx88_dvb_tasklet(unsigned long data)
{
struct cx8800_dvb *dvb = (struct cx8800_dvb *)data;
struct cx8800_dev *dev = dvb->dev;
struct cx88_dmaqueue *q = &dvb->tsq;
struct cx88_buffer *buf;
unsigned long flags;
/* Process any pending buffers */
spin_lock_irqsave(&dev->slock, flags);
while (! list_empty(&q->queued)) {
/* get items */
buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
spin_unlock_irqrestore(&dev->slock, flags);
/* Hand the received frames to the software filter */
(dvb->ts_includes_fec ? dvb_dmx_swfilter_204 : dvb_dmx_swfilter)
(&dvb->demux, (char *)buf->vb.dma.vmalloc,
buf->vb.field_count * buf->bpl);
/* Reactivate the buffer */
spin_lock_irqsave(&dev->slock, flags);
list_del(&buf->vb.queue);
activate_ts_buffer(dvb, buf, 1);
}
spin_unlock_irqrestore(&dev->slock, flags);
}
static void cx8800_wakeup_dvb_tasklet(struct cx8800_dvb *dvb,
unsigned int maxframe, int timeout_case)
{
struct cx88_dmaqueue *q = &dvb->tsq;
struct cx88_buffer *buf;
int processed_buffers = 0;
/* Called with dev->slock held */
dprintk(2, "cx8800_wakeup_dvb_tasklet called, maxframe: %d, "
"timeout_case: %d\n", maxframe, timeout_case);
while (! list_empty(&q->active)) {
buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
/* Calculate how many frames that are waiting for processing */
maxframe &= 0xffff;
buf->count &= 0xffff;
buf->vb.field_count = (maxframe - buf->count) & 0xffff;
dprintk(2, "[%p/%d] wakeup reg=%d buf=%d, field_count=%d, "
"processed=%d\n", buf, buf->vb.i, maxframe, buf->count,
buf->vb.field_count, processed_buffers);
/* Reject any incomplete buffer if we aren't handling a timeout,
* as data transfer into it is still occurring. */
if (buf->vb.field_count < buf->vb.height && !timeout_case) {
if (! processed_buffers) {
dprintk(2, "incomplete buffer: mf: %d, count: "
"%d, fc: %d height: %d\n", maxframe,
buf->count, buf->vb.field_count,
buf->vb.height);
return; /* Don't re-timeout... */
}
break;
}
/* We've got no frames to process, so just reschedule
* the timeout. */
if (buf->vb.field_count == 0) {
dprintk(2, "no frames... %d %d\n", maxframe,
buf->count);
break;
}
/* We can't possibly have more frames than we have size for
* in the buffer, so trim back how many we think we have. */
if (buf->vb.field_count > buf->vb.height) {
if (buf->vb.field_count > buf->vb.height * 2 &&
++too_many_frames_in_one_interrupt == 10) {
printk(KERN_WARNING "%s: you should consider"
"increasing ts_frames_per_irq (%d "
"frame/irq overload)\n", dvb->dev->name,
(buf->vb.field_count - buf->vb.height));
}
buf->vb.field_count = buf->vb.height;
}
/* Mark the buffer as done. */
buf->vb.state = timeout_case ? STATE_ERROR : STATE_DONE;
/* Move the buffer from the active queue to the
* queued-for-processing queue */
list_move_tail(&buf->vb.queue, &q->queued);
/* Schedule the tasklet to process them */
tasklet_schedule(&dvb->dvb_tasklet);
/* Don't queue more than one buffer if we timed out. */
if (timeout_case)
break;
/* Record that we processed a buffer. */
processed_buffers++;
}
if (list_empty(&q->active)) {
del_timer(&q->timeout);
} else {
mod_timer(&q->timeout, jiffies + TS_BUFFER_TIMEOUT);
}
}
/* ---------------------------------------------------------------------------- */
static int master_xfer(struct dvb_i2c_bus *i2c, const struct i2c_msg msgs[],
int num)
{
struct cx8800_dvb *dvb = (struct cx8800_dvb *)i2c->data;
struct cx8800_dev *dev = dvb->dev;
int retval;
if (down_interruptible(&dvb->dvb_i2c_lock))
return -ERESTARTSYS;
retval = i2c_transfer(&dev->i2c_adap, (struct i2c_msg *)msgs, num);
up(&dvb->dvb_i2c_lock);
return retval;
}
static int dvb_cx8800_start_feed(struct dvb_demux_feed *feed)
{
struct dvb_demux *demux = feed->demux;
struct cx8800_dvb *dvb = demux->priv;
dprintk(2, "dvb_cx8800_start_feed\n");
if (!demux->dmx.frontend)
return -EINVAL;
return start_ts_capture(dvb);
}
static int dvb_cx8800_stop_feed(struct dvb_demux_feed *feed)
{
struct dvb_demux *demux = feed->demux;
struct cx8800_dvb *dvb = demux->priv;
dprintk(2, "dvb_cx8800_stop_feed\n");
if (!demux->dmx.frontend)
return -EINVAL;
return stop_ts_capture(dvb);
}
static void cx8800_ts_release_dev(struct cx8800_dev *dev)
{
struct cx8800_dvb *dvb = dev->dvb;
/* Force us to stop any feed */
spin_lock(&dvb->feedlock);
if (dvb->ts_feeding != 0) {
spin_unlock(&dvb->feedlock);
printk("Error: releasing a card while feed in progress\n");
stop_ts_capture(dvb);
} else
spin_unlock(&dvb->feedlock);
/* release everything we registered */
dvb_net_release(&dvb->dvbnet);
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
dvb_dmxdev_release(&dvb->dmxdev);
dvb_dmx_release(&dvb->demux);
dvb_unregister_i2c_bus(master_xfer, dvb->dvb_adapter, 0);
dvb_unregister_adapter(dvb->dvb_adapter);
btcx_riscmem_free(dev->pci, &dvb->tsq.stopper);
/* Free ourselves */
kfree(dvb);
dev->dvb = NULL;
return;
}
static void cx8800_ts_resume_dev(struct cx8800_dev *dev)
{
/* Called with dev->slock held */
cx8800_restart_ts_queue(dev->dvb);
}
static int cx8800_ts_attach_dev(struct cx8800_dev *dev)
{
struct cx8800_dvb *dvb;
int result;
/* Take DVB hardware out of reset */
cx_set(MO_GP0_IO, cx88_boards[dev->board].ts.gpio0);
cx_clear(MO_GP0_IO, cx88_boards[dev->board].ts.gpio0 & 0xff);
udelay(500);
cx_set(MO_GP0_IO, cx88_boards[dev->board].ts.gpio0);
/* Allocate a DVB structure */
dvb = kmalloc(sizeof(struct cx8800_dvb), GFP_KERNEL);
if (dvb == NULL) {
result = -ENOMEM;
goto fail;
}
memset(dvb, 0, sizeof(struct cx8800_dvb));
/* Record our device and details */
dvb->dev = dev;
dvb->irq_handler = cx8800_ts_irq;
dvb->release_dev = cx8800_ts_release_dev;
dvb->resume_dev = cx8800_ts_resume_dev;
/* init TS dma queues */
INIT_LIST_HEAD(&dvb->tsq.active);
INIT_LIST_HEAD(&dvb->tsq.queued);
dvb->tsq.timeout.function = cx8800_ts_timeout;
dvb->tsq.timeout.data = (unsigned long) dvb;
init_timer(&dvb->tsq.timeout);
cx88_risc_stopper(dev->pci, &dvb->tsq.stopper,
MO_TS_DMACNTRL, 0x11, 0x00);
/* init TS feed spinlock */
dvb->feedlock = SPIN_LOCK_UNLOCKED;
/* Clear any pending interrupts */
cx8800_stop_ts_dma(dvb);
if ((result =
dvb_register_adapter(&dvb->dvb_adapter, dev->name,
THIS_MODULE)) < 0) {
printk(KERN_WARNING
"%s: dvb_register_adapter failed (errno = %d)\n",
dev->name, result);
goto fail;
}
init_MUTEX(&dvb->dvb_i2c_lock);
if (! dvb_register_i2c_bus(master_xfer, dvb, dvb->dvb_adapter, 0)) {
printk(KERN_WARNING "%s: dvb_register_i2c_bus failed\n",
dev->name);
result = -EFAULT;
goto fail2;
}
memset(&dvb->demux, 0, sizeof(struct dvb_demux));
dvb->demux.dmx.capabilities =
DMX_TS_FILTERING | DMX_SECTION_FILTERING |
DMX_MEMORY_BASED_FILTERING;
dvb->demux.priv = dvb;
dvb->demux.filternum = 256;
dvb->demux.feednum = 256;
dvb->demux.start_feed = dvb_cx8800_start_feed;
dvb->demux.stop_feed = dvb_cx8800_stop_feed;
dvb->demux.write_to_decoder = NULL;
if ((result = dvb_dmx_init(&dvb->demux)) < 0) {
printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
dev->name, result);
goto fail3;
}
dvb->dmxdev.filternum = 256;
dvb->dmxdev.demux = &dvb->demux.dmx;
dvb->dmxdev.capabilities = 0;
if ((result = dvb_dmxdev_init(&dvb->dmxdev, dvb->dvb_adapter)) < 0) {
printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
dev->name, result);
goto fail4;
}
dvb->fe_hw.source = DMX_FRONTEND_0;
if ((result =
dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw)) < 0) {
printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
dev->name, result);
goto fail5;
}
dvb->fe_mem.source = DMX_MEMORY_FE;
if ((result =
dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem)) < 0) {
printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
dev->name, result);
goto fail6;
}
if ((result =
dvb->demux.dmx.connect_frontend(&dvb->demux.dmx,
&dvb->fe_hw)) < 0) {
printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
dev->name, result);
goto fail7;
}
dvb_net_init(dvb->dvb_adapter, &dvb->dvbnet, &dvb->demux.dmx);
dev->dvb = dvb;
printk(KERN_INFO "DVB attached to dev %p, dvb: %p\n", dev, dvb);
return 0;
fail7:
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
fail6:
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
fail5:
dvb_dmxdev_release(&dvb->dmxdev);
fail4:
dvb_dmx_release(&dvb->demux);
fail3:
dvb_unregister_i2c_bus(master_xfer, dvb->dvb_adapter, 0);
fail2:
dvb_unregister_adapter(dvb->dvb_adapter);
fail:
return result;
}
#endif
|