23 #include <linux/module.h>
25 #include <linux/slab.h>
30 static unsigned int debug;
34 static inline void print_err_status(
struct stk1160 *
dev,
37 char *errmsg =
"Unknown";
41 errmsg =
"unlinked synchronuously";
44 errmsg =
"unlinked asynchronuously";
47 errmsg =
"Buffer error (overrun)";
50 errmsg =
"Stalled (device not responding)";
53 errmsg =
"Babble (bad cable?)";
56 errmsg =
"Bit-stuff error (bad cable?)";
59 errmsg =
"CRC/Timeout (could be anything)";
62 errmsg =
"Device does not respond";
71 packet, status, errmsg);
78 unsigned long flags = 0;
89 spin_unlock_irqrestore(&dev->
buf_lock, flags);
95 void stk1160_buffer_done(
struct stk1160 *dev)
106 vb2_set_plane_payload(&buf->
vb, 0, buf->
bytesused);
113 void stk1160_copy_video(
struct stk1160 *dev,
u8 *
src,
int len)
115 int linesdone, lineoff, lencopy;
144 dst += linesdone * bytesperline * 2 + lineoff;
147 if (remain < (bytesperline - lineoff))
150 lencopy = bytesperline - lineoff;
162 if (lencopy == 0 || remain == 0)
171 if ((
unsigned long)dst + lencopy >
177 memcpy(dst, src, lencopy);
190 if (remain < bytesperline)
205 if (lencopy == 0 || remain == 0)
213 if ((
unsigned long)dst + lencopy >
219 memcpy(dst, src, lencopy);
230 static void stk1160_process_isoc(
struct stk1160 *dev,
struct urb *
urb)
240 if (urb->status < 0) {
242 print_err_status(dev, -1, urb->status);
246 for (i = 0; i < urb->number_of_packets; i++) {
247 status = urb->iso_frame_desc[
i].status;
249 print_err_status(dev, i, status);
254 p = urb->transfer_buffer + urb->iso_frame_desc[
i].offset;
255 len = urb->iso_frame_desc[
i].actual_length;
276 stk1160_buffer_done(dev);
278 dev->
isoc_ctl.buf = stk1160_next_buffer(dev);
290 if (p[0] == 0xc0 || p[0] == 0x80) {
300 stk1160_copy_video(dev, p, len);
308 static void stk1160_isoc_irq(
struct urb *urb)
311 struct stk1160 *dev = urb->context;
313 switch (urb->status) {
322 stk1160_err(
"urb error! status %d\n", urb->status);
326 stk1160_process_isoc(dev, urb);
329 for (i = 0; i < urb->number_of_packets; i++) {
330 urb->iso_frame_desc[
i].status = 0;
331 urb->iso_frame_desc[
i].actual_length = 0;
345 int i, num_bufs = dev->
isoc_ctl.num_bufs;
356 for (i = 0; i < num_bufs; i++) {
376 int i, num_bufs = dev->
isoc_ctl.num_bufs;
378 stk1160_dbg(
"freeing %d urb buffers...\n", num_bufs);
380 for (i = 0; i < num_bufs; i++) {
385 if (dev->
isoc_ctl.transfer_buffer[i]) {
386 #ifndef CONFIG_DMA_NONCOHERENT
388 urb->transfer_buffer_length,
427 int i,
j,
k, sb_size, max_packets, num_bufs;
451 dev->
isoc_ctl.transfer_buffer = kzalloc(
sizeof(
void *)*num_bufs,
453 if (!dev->
isoc_ctl.transfer_buffer) {
460 for (i = 0; i < num_bufs; i++) {
469 #ifndef CONFIG_DMA_NONCOHERENT
475 if (!dev->
isoc_ctl.transfer_buffer[i]) {
476 stk1160_err(
"cannot alloc %d bytes for tx[%d] buffer\n",
485 urb->dev = dev->
udev;
487 urb->transfer_buffer = dev->
isoc_ctl.transfer_buffer[
i];
488 urb->transfer_buffer_length = sb_size;
489 urb->complete = stk1160_isoc_irq;
492 urb->start_frame = 0;
493 urb->number_of_packets = max_packets;
494 #ifndef CONFIG_DMA_NONCOHERENT
495 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
497 urb->transfer_flags = URB_ISO_ASAP;
501 for (j = 0; j < max_packets; j++) {
502 urb->iso_frame_desc[
j].offset =
k;
503 urb->iso_frame_desc[
j].length =