Commit 7f37cc9b authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB (10710): zoran: cleanups in an attempt to make the source a bit more readable.

Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent aff88bca
...@@ -919,15 +919,12 @@ zoran_check_jpg_settings (struct zoran *zr, ...@@ -919,15 +919,12 @@ zoran_check_jpg_settings (struct zoran *zr,
err0++; err0++;
if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH)
err0++; err0++;
if (settings->img_y + settings->img_height > if (settings->img_y + settings->img_height > BUZ_MAX_HEIGHT / 2)
BUZ_MAX_HEIGHT / 2)
err0++; err0++;
if (settings->HorDcm && settings->VerDcm) { if (settings->HorDcm && settings->VerDcm) {
if (settings->img_width % if (settings->img_width % (16 * settings->HorDcm) != 0)
(16 * settings->HorDcm) != 0)
err0++; err0++;
if (settings->img_height % if (settings->img_height % (8 * settings->VerDcm) != 0)
(8 * settings->VerDcm) != 0)
err0++; err0++;
} }
......
...@@ -1208,22 +1208,52 @@ zoran_reap_stat_com (struct zoran *zr) ...@@ -1208,22 +1208,52 @@ zoran_reap_stat_com (struct zoran *zr)
} }
} }
static void zoran_restart(struct zoran *zr)
{
/* Now the stat_comm buffer is ready for restart */
int status, mode;
if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
decoder_command(zr, DECODER_GET_STATUS, &status);
mode = CODEC_DO_COMPRESSION;
} else {
status = 0;
mode = CODEC_DO_EXPANSION;
}
if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
(status & DECODER_STATUS_GOOD)) {
/********** RESTART code *************/
jpeg_codec_reset(zr);
zr->codec->set_mode(zr->codec, mode);
zr36057_set_jpg(zr, zr->codec_mode);
jpeg_start(zr);
if (zr->num_errors <= 8)
dprintk(2, KERN_INFO "%s: Restart\n",
ZR_DEVNAME(zr));
zr->JPEG_missed = 0;
zr->JPEG_error = 2;
/********** End RESTART code ***********/
}
}
static void static void
error_handler (struct zoran *zr, error_handler (struct zoran *zr,
u32 astat, u32 astat,
u32 stat) u32 stat)
{ {
int i, j;
/* This is JPEG error handling part */ /* This is JPEG error handling part */
if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) && if (zr->codec_mode != BUZ_MODE_MOTION_COMPRESS &&
(zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) { zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS) {
//dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
return; return;
} }
if ((stat & 1) == 0 && if ((stat & 1) == 0 &&
zr->codec_mode == BUZ_MODE_MOTION_COMPRESS && zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
zr->jpg_dma_tail - zr->jpg_que_tail >= zr->jpg_dma_tail - zr->jpg_que_tail >= zr->jpg_buffers.num_buffers) {
zr->jpg_buffers.num_buffers) {
/* No free buffers... */ /* No free buffers... */
zoran_reap_stat_com(zr); zoran_reap_stat_com(zr);
zoran_feed_stat_com(zr); zoran_feed_stat_com(zr);
...@@ -1232,7 +1262,11 @@ error_handler (struct zoran *zr, ...@@ -1232,7 +1262,11 @@ error_handler (struct zoran *zr,
return; return;
} }
if (zr->JPEG_error != 1) { if (zr->JPEG_error == 1) {
zoran_restart(zr);
return;
}
/* /*
* First entry: error just happened during normal operation * First entry: error just happened during normal operation
* *
...@@ -1260,43 +1294,28 @@ error_handler (struct zoran *zr, ...@@ -1260,43 +1294,28 @@ error_handler (struct zoran *zr,
/* Report error */ /* Report error */
if (zr36067_debug > 1 && zr->num_errors <= 8) { if (zr36067_debug > 1 && zr->num_errors <= 8) {
long frame; long frame;
frame =
zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME]; frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
printk(KERN_ERR printk(KERN_ERR
"%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ", "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
ZR_DEVNAME(zr), stat, zr->last_isr, ZR_DEVNAME(zr), stat, zr->last_isr,
zr->jpg_que_tail, zr->jpg_dma_tail, zr->jpg_que_tail, zr->jpg_dma_tail,
zr->jpg_dma_head, zr->jpg_que_head, zr->jpg_dma_head, zr->jpg_que_head,
zr->jpg_seq_num, frame); zr->jpg_seq_num, frame);
printk("stat_com frames:"); printk(KERN_INFO "stat_com frames:");
{
int i, j;
for (j = 0; j < BUZ_NUM_STAT_COM; j++) { for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
for (i = 0; for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
i < zr->jpg_buffers.num_buffers; if (le32_to_cpu(zr->stat_com[j]) == zr->jpg_buffers.buffer[i].frag_tab_bus)
i++) { printk(KERN_CONT "% d->%d", j, i);
if (le32_to_cpu(zr->stat_com[j]) ==
zr->jpg_buffers.
buffer[i].
frag_tab_bus) {
printk("% d->%d",
j, i);
}
}
} }
printk("\n");
} }
printk(KERN_CONT "\n");
} }
/* Find an entry in stat_com and rotate contents */ /* Find an entry in stat_com and rotate contents */
{
int i;
if (zr->jpg_settings.TmpDcm == 1) if (zr->jpg_settings.TmpDcm == 1)
i = (zr->jpg_dma_tail - i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
else else
i = ((zr->jpg_dma_tail - i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2;
zr->jpg_err_shift) & 1) * 2;
if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) { if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
/* Mimic zr36067 operation */ /* Mimic zr36067 operation */
zr->stat_com[i] |= cpu_to_le32(1); zr->stat_com[i] |= cpu_to_le32(1);
...@@ -1308,12 +1327,9 @@ error_handler (struct zoran *zr, ...@@ -1308,12 +1327,9 @@ error_handler (struct zoran *zr,
wake_up_interruptible(&zr->jpg_capq); wake_up_interruptible(&zr->jpg_capq);
/* Find an entry in stat_com again after refill */ /* Find an entry in stat_com again after refill */
if (zr->jpg_settings.TmpDcm == 1) if (zr->jpg_settings.TmpDcm == 1)
i = (zr->jpg_dma_tail - i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
zr->jpg_err_shift) &
BUZ_MASK_STAT_COM;
else else
i = ((zr->jpg_dma_tail - i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2;
zr->jpg_err_shift) & 1) * 2;
} }
if (i) { if (i) {
/* Rotate stat_comm entries to make current entry first */ /* Rotate stat_comm entries to make current entry first */
...@@ -1324,50 +1340,17 @@ error_handler (struct zoran *zr, ...@@ -1324,50 +1340,17 @@ error_handler (struct zoran *zr,
* is already in little endian format, so * is already in little endian format, so
* no endian conversions here * no endian conversions here
*/ */
memcpy(bus_addr, zr->stat_com, memcpy(bus_addr, zr->stat_com, sizeof(bus_addr));
sizeof(bus_addr));
for (j = 0; j < BUZ_NUM_STAT_COM; j++) { for (j = 0; j < BUZ_NUM_STAT_COM; j++)
zr->stat_com[j] = zr->stat_com[j] = bus_addr[(i + j) & BUZ_MASK_STAT_COM];
bus_addr[(i + j) &
BUZ_MASK_STAT_COM];
}
zr->jpg_err_shift += i; zr->jpg_err_shift += i;
zr->jpg_err_shift &= BUZ_MASK_STAT_COM; zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
} }
if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */ zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */
} zoran_restart(zr);
}
/* Now the stat_comm buffer is ready for restart */
do {
int status, mode;
if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
decoder_command(zr, DECODER_GET_STATUS, &status);
mode = CODEC_DO_COMPRESSION;
} else {
status = 0;
mode = CODEC_DO_EXPANSION;
}
if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
(status & DECODER_STATUS_GOOD)) {
/********** RESTART code *************/
jpeg_codec_reset(zr);
zr->codec->set_mode(zr->codec, mode);
zr36057_set_jpg(zr, zr->codec_mode);
jpeg_start(zr);
if (zr->num_errors <= 8)
dprintk(2, KERN_INFO "%s: Restart\n",
ZR_DEVNAME(zr));
zr->JPEG_missed = 0;
zr->JPEG_error = 2;
/********** End RESTART code ***********/
}
} while (0);
} }
irqreturn_t irqreturn_t
...@@ -1425,10 +1408,8 @@ zoran_irq (int irq, ...@@ -1425,10 +1408,8 @@ zoran_irq (int irq,
* We simply ignore them */ * We simply ignore them */
if (zr->v4l_memgrab_active) { if (zr->v4l_memgrab_active) {
/* A lot more checks should be here ... */ /* A lot more checks should be here ... */
if ((btread(ZR36057_VSSFGR) & if ((btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot) == 0)
ZR36057_VSSFGR_SnapShot) == 0)
dprintk(1, dprintk(1,
KERN_WARNING KERN_WARNING
"%s: BuzIRQ with SnapShot off ???\n", "%s: BuzIRQ with SnapShot off ???\n",
...@@ -1436,10 +1417,7 @@ zoran_irq (int irq, ...@@ -1436,10 +1417,7 @@ zoran_irq (int irq,
if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) { if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
/* There is a grab on a frame going on, check if it has finished */ /* There is a grab on a frame going on, check if it has finished */
if ((btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_FrameGrab) == 0) {
if ((btread(ZR36057_VSSFGR) &
ZR36057_VSSFGR_FrameGrab) ==
0) {
/* it is finished, notify the user */ /* it is finished, notify the user */
zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE; zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
...@@ -1457,9 +1435,7 @@ zoran_irq (int irq, ...@@ -1457,9 +1435,7 @@ zoran_irq (int irq,
if (zr->v4l_grab_frame == NO_GRAB_ACTIVE && if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
zr->v4l_pend_tail != zr->v4l_pend_head) { zr->v4l_pend_tail != zr->v4l_pend_head) {
int frame = zr->v4l_pend[zr->v4l_pend_tail & V4L_MASK_FRAME];
int frame = zr->v4l_pend[zr->v4l_pend_tail &
V4L_MASK_FRAME];
u32 reg; u32 reg;
zr->v4l_grab_frame = frame; zr->v4l_grab_frame = frame;
...@@ -1468,27 +1444,17 @@ zoran_irq (int irq, ...@@ -1468,27 +1444,17 @@ zoran_irq (int irq,
/* Buffer address */ /* Buffer address */
reg = reg = zr->v4l_buffers.buffer[frame].fbuffer_bus;
zr->v4l_buffers.buffer[frame].
fbuffer_bus;
btwrite(reg, ZR36057_VDTR); btwrite(reg, ZR36057_VDTR);
if (zr->v4l_settings.height > if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2)
BUZ_MAX_HEIGHT / 2) reg += zr->v4l_settings.bytesperline;
reg +=
zr->v4l_settings.
bytesperline;
btwrite(reg, ZR36057_VDBR); btwrite(reg, ZR36057_VDBR);
/* video stride, status, and frame grab register */ /* video stride, status, and frame grab register */
reg = 0; reg = 0;
if (zr->v4l_settings.height > if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2)
BUZ_MAX_HEIGHT / 2) reg += zr->v4l_settings.bytesperline;
reg += reg = (reg << ZR36057_VSSFGR_DispStride);
zr->v4l_settings.
bytesperline;
reg =
(reg <<
ZR36057_VSSFGR_DispStride);
reg |= ZR36057_VSSFGR_VidOvf; reg |= ZR36057_VSSFGR_VidOvf;
reg |= ZR36057_VSSFGR_SnapShot; reg |= ZR36057_VSSFGR_SnapShot;
reg |= ZR36057_VSSFGR_FrameGrab; reg |= ZR36057_VSSFGR_FrameGrab;
...@@ -1506,31 +1472,28 @@ zoran_irq (int irq, ...@@ -1506,31 +1472,28 @@ zoran_irq (int irq,
#if (IRQ_MASK & ZR36057_ISR_CodRepIRQ) #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
if (astat & ZR36057_ISR_CodRepIRQ) { if (astat & ZR36057_ISR_CodRepIRQ) {
zr->intr_counter_CodRepIRQ++; zr->intr_counter_CodRepIRQ++;
IDEBUG(printk IDEBUG(printk(KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
(KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
ZR_DEVNAME(zr))); ZR_DEVNAME(zr)));
btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR); btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
} }
#endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */ #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
#if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
if (astat & ZR36057_ISR_JPEGRepIRQ) { if ((astat & ZR36057_ISR_JPEGRepIRQ) &&
(zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)) {
if (zr36067_debug > 1 && (!zr->frame_num || zr->JPEG_error)) {
char sc[] = "0000";
char sv[5];
int i;
if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
if (zr36067_debug > 1 &&
(!zr->frame_num || zr->JPEG_error)) {
printk(KERN_INFO printk(KERN_INFO
"%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n", "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
ZR_DEVNAME(zr), stat, ZR_DEVNAME(zr), stat,
zr->jpg_settings.odd_even, zr->jpg_settings.odd_even,
zr->jpg_settings. zr->jpg_settings.field_per_buff,
field_per_buff,
zr->JPEG_missed); zr->JPEG_missed);
{
char sc[] = "0000";
char sv[5];
int i;
strcpy(sv, sc); strcpy(sv, sc);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (le32_to_cpu(zr->stat_com[i]) & 1) if (le32_to_cpu(zr->stat_com[i]) & 1)
...@@ -1544,26 +1507,24 @@ zoran_irq (int irq, ...@@ -1544,26 +1507,24 @@ zoran_irq (int irq,
zr->jpg_dma_tail, zr->jpg_dma_tail,
zr->jpg_dma_head, zr->jpg_dma_head,
zr->jpg_que_head); zr->jpg_que_head);
}
} else { } else {
if (zr->JPEG_missed > zr->JPEG_max_missed) // Get statistics /* Get statistics */
zr->JPEG_max_missed = if (zr->JPEG_missed > zr->JPEG_max_missed)
zr->JPEG_missed; zr->JPEG_max_missed = zr->JPEG_missed;
if (zr->JPEG_missed < if (zr->JPEG_missed < zr->JPEG_min_missed)
zr->JPEG_min_missed) zr->JPEG_min_missed = zr->JPEG_missed;
zr->JPEG_min_missed =
zr->JPEG_missed;
} }
if (zr36067_debug > 2 && zr->frame_num < 6) { if (zr36067_debug > 2 && zr->frame_num < 6) {
int i; int i;
printk("%s: seq=%ld stat_com:",
printk(KERN_INFO "%s: seq=%ld stat_com:",
ZR_DEVNAME(zr), zr->jpg_seq_num); ZR_DEVNAME(zr), zr->jpg_seq_num);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
printk(" %08x", printk(KERN_CONT " %08x",
le32_to_cpu(zr->stat_com[i])); le32_to_cpu(zr->stat_com[i]));
} }
printk("\n"); printk(KERN_CONT "\n");
} }
zr->frame_num++; zr->frame_num++;
zr->JPEG_missed = 0; zr->JPEG_missed = 0;
...@@ -1571,12 +1532,6 @@ zoran_irq (int irq, ...@@ -1571,12 +1532,6 @@ zoran_irq (int irq,
zoran_reap_stat_com(zr); zoran_reap_stat_com(zr);
zoran_feed_stat_com(zr); zoran_feed_stat_com(zr);
wake_up_interruptible(&zr->jpg_capq); wake_up_interruptible(&zr->jpg_capq);
} /*else {
dprintk(1,
KERN_ERR
"%s: JPEG interrupt while not in motion (de)compress mode!\n",
ZR_DEVNAME(zr));
}*/
} }
#endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */ #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
...@@ -1585,8 +1540,7 @@ zoran_irq (int irq, ...@@ -1585,8 +1540,7 @@ zoran_irq (int irq,
zr->JPEG_missed > 25 || zr->JPEG_missed > 25 ||
zr->JPEG_error == 1 || zr->JPEG_error == 1 ||
((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) && ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
(zr->frame_num & (zr->JPEG_missed > (zr->frame_num & (zr->JPEG_missed > zr->jpg_settings.field_per_buff)))) {
zr->jpg_settings.field_per_buff)))) {
error_handler(zr, astat, stat); error_handler(zr, astat, stat);
} }
......
...@@ -2314,7 +2314,7 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh, ...@@ -2314,7 +2314,7 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh,
} }
/* we actually need to set 'real' parameters now */ /* we actually need to set 'real' parameters now */
if ((fmt->fmt.pix.height * 2) > BUZ_MAX_HEIGHT) if (fmt->fmt.pix.height * 2 > BUZ_MAX_HEIGHT)
settings.TmpDcm = 1; settings.TmpDcm = 1;
else else
settings.TmpDcm = 2; settings.TmpDcm = 2;
...@@ -2501,7 +2501,7 @@ static int zoran_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffe ...@@ -2501,7 +2501,7 @@ static int zoran_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffe
if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) { if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) {
dprintk(1, dprintk(1,
KERN_ERR KERN_ERR
"%s: VIDIOC_REQBUFS - buffers allready allocated\n", "%s: VIDIOC_REQBUFS - buffers already allocated\n",
ZR_DEVNAME(zr)); ZR_DEVNAME(zr));
res = -EBUSY; res = -EBUSY;
goto v4l2reqbuf_unlock_and_return; goto v4l2reqbuf_unlock_and_return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment