2008-04-29 06:24:33 +07:00
|
|
|
/*
|
|
|
|
* cx18 interrupt handling
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
* 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cx18-driver.h"
|
2008-08-31 02:03:44 +07:00
|
|
|
#include "cx18-io.h"
|
2008-04-29 06:24:33 +07:00
|
|
|
#include "cx18-firmware.h"
|
|
|
|
#include "cx18-fileops.h"
|
|
|
|
#include "cx18-queue.h"
|
|
|
|
#include "cx18-irq.h"
|
|
|
|
#include "cx18-ioctl.h"
|
|
|
|
#include "cx18-mailbox.h"
|
|
|
|
#include "cx18-vbi.h"
|
|
|
|
#include "cx18-scb.h"
|
2008-11-05 10:49:14 +07:00
|
|
|
#include "cx18-dvb.h"
|
|
|
|
|
|
|
|
void cx18_work_handler(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct cx18 *cx = container_of(work, struct cx18, work);
|
|
|
|
if (test_and_clear_bit(CX18_F_I_WORK_HANDLER_DVB, &cx->i_flags))
|
|
|
|
cx18_dvb_work_handler(cx);
|
|
|
|
}
|
2008-04-29 06:24:33 +07:00
|
|
|
|
2008-11-06 11:15:41 +07:00
|
|
|
static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb, int rpu)
|
2008-04-29 06:24:33 +07:00
|
|
|
{
|
|
|
|
u32 handle = mb->args[0];
|
|
|
|
struct cx18_stream *s = NULL;
|
|
|
|
struct cx18_buffer *buf;
|
|
|
|
u32 off;
|
|
|
|
int i;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
for (i = 0; i < CX18_MAX_STREAMS; i++) {
|
|
|
|
s = &cx->streams[i];
|
|
|
|
if ((handle == s->handle) && (s->dvb.enabled))
|
|
|
|
break;
|
|
|
|
if (s->v4l2dev && handle == s->handle)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == CX18_MAX_STREAMS) {
|
2008-10-05 05:09:41 +07:00
|
|
|
CX18_WARN("Got DMA done notification for unknown/inactive"
|
|
|
|
" handle %d\n", handle);
|
2008-04-29 06:24:33 +07:00
|
|
|
mb->error = CXERR_NOT_OPEN;
|
|
|
|
mb->cmd = 0;
|
2008-11-06 11:15:41 +07:00
|
|
|
cx18_mb_ack(cx, mb, rpu);
|
2008-04-29 06:24:33 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
off = mb->args[1];
|
|
|
|
if (mb->args[2] != 1)
|
|
|
|
CX18_WARN("Ack struct = %d for %s\n",
|
|
|
|
mb->args[2], s->name);
|
2008-08-31 02:03:44 +07:00
|
|
|
id = cx18_read_enc(cx, off);
|
|
|
|
buf = cx18_queue_get_buf_irq(s, id, cx18_read_enc(cx, off + 4));
|
2008-04-29 06:24:33 +07:00
|
|
|
CX18_DEBUG_HI_DMA("DMA DONE for %s (buffer %d)\n", s->name, id);
|
|
|
|
if (buf) {
|
|
|
|
cx18_buf_sync_for_cpu(s, buf);
|
|
|
|
if (s->type == CX18_ENC_STREAM_TYPE_TS && s->dvb.enabled) {
|
2008-11-05 10:49:14 +07:00
|
|
|
CX18_DEBUG_HI_DMA("TS recv bytesused = %d\n",
|
2008-04-29 06:24:33 +07:00
|
|
|
buf->bytesused);
|
|
|
|
|
2008-11-05 10:49:14 +07:00
|
|
|
set_bit(CX18_F_I_WORK_HANDLER_DVB, &cx->i_flags);
|
|
|
|
set_bit(CX18_F_I_HAVE_WORK, &cx->i_flags);
|
2008-04-29 06:24:33 +07:00
|
|
|
} else
|
|
|
|
set_bit(CX18_F_B_NEED_BUF_SWAP, &buf->b_flags);
|
|
|
|
} else {
|
|
|
|
CX18_WARN("Could not find buf %d for stream %s\n",
|
2008-08-31 02:03:44 +07:00
|
|
|
cx18_read_enc(cx, off), s->name);
|
2008-04-29 06:24:33 +07:00
|
|
|
}
|
|
|
|
mb->error = 0;
|
|
|
|
mb->cmd = 0;
|
2008-11-06 11:15:41 +07:00
|
|
|
cx18_mb_ack(cx, mb, rpu);
|
2008-04-29 06:24:33 +07:00
|
|
|
wake_up(&cx->dma_waitq);
|
|
|
|
if (s->id != -1)
|
|
|
|
wake_up(&s->waitq);
|
|
|
|
}
|
|
|
|
|
2008-11-06 11:15:41 +07:00
|
|
|
static void epu_debug(struct cx18 *cx, struct cx18_mailbox *mb, int rpu)
|
2008-04-29 06:24:33 +07:00
|
|
|
{
|
|
|
|
char str[256] = { 0 };
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (mb->args[1]) {
|
2008-08-31 02:03:44 +07:00
|
|
|
cx18_setup_page(cx, mb->args[1]);
|
|
|
|
cx18_memcpy_fromio(cx, str, cx->enc_mem + mb->args[1], 252);
|
2008-04-29 06:24:33 +07:00
|
|
|
str[252] = 0;
|
|
|
|
}
|
2008-11-06 11:15:41 +07:00
|
|
|
cx18_mb_ack(cx, mb, rpu);
|
2008-04-29 06:24:33 +07:00
|
|
|
CX18_DEBUG_INFO("%x %s\n", mb->args[0], str);
|
|
|
|
p = strchr(str, '.');
|
|
|
|
if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags) && p && p > str)
|
|
|
|
CX18_INFO("FW version: %s\n", p - 1);
|
|
|
|
}
|
|
|
|
|
2008-11-05 08:02:23 +07:00
|
|
|
static void epu_cmd(struct cx18 *cx, u32 sw1)
|
2008-04-29 06:24:33 +07:00
|
|
|
{
|
|
|
|
struct cx18_mailbox mb;
|
|
|
|
|
|
|
|
if (sw1 & IRQ_CPU_TO_EPU) {
|
2008-08-31 02:03:44 +07:00
|
|
|
cx18_memcpy_fromio(cx, &mb, &cx->scb->cpu2epu_mb, sizeof(mb));
|
2008-04-29 06:24:33 +07:00
|
|
|
mb.error = 0;
|
|
|
|
|
|
|
|
switch (mb.cmd) {
|
|
|
|
case CX18_EPU_DMA_DONE:
|
2008-11-06 11:15:41 +07:00
|
|
|
epu_dma_done(cx, &mb, CPU);
|
2008-04-29 06:24:33 +07:00
|
|
|
break;
|
|
|
|
case CX18_EPU_DEBUG:
|
2008-11-06 11:15:41 +07:00
|
|
|
epu_debug(cx, &mb, CPU);
|
2008-04-29 06:24:33 +07:00
|
|
|
break;
|
|
|
|
default:
|
2008-11-05 08:02:23 +07:00
|
|
|
CX18_WARN("Unknown CPU_TO_EPU mailbox command %#08x\n",
|
|
|
|
mb.cmd);
|
2008-04-29 06:24:33 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-05 08:02:23 +07:00
|
|
|
|
|
|
|
if (sw1 & IRQ_APU_TO_EPU) {
|
|
|
|
cx18_memcpy_fromio(cx, &mb, &cx->scb->apu2epu_mb, sizeof(mb));
|
|
|
|
CX18_WARN("Unknown APU_TO_EPU mailbox command %#08x\n", mb.cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xpu_ack(struct cx18 *cx, u32 sw2)
|
|
|
|
{
|
|
|
|
if (sw2 & IRQ_CPU_TO_EPU_ACK)
|
|
|
|
wake_up(&cx->mb_cpu_waitq);
|
|
|
|
if (sw2 & IRQ_APU_TO_EPU_ACK)
|
|
|
|
wake_up(&cx->mb_apu_waitq);
|
2008-04-29 06:24:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
irqreturn_t cx18_irq_handler(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct cx18 *cx = (struct cx18 *)dev_id;
|
|
|
|
u32 sw1, sw1_mask;
|
|
|
|
u32 sw2, sw2_mask;
|
|
|
|
u32 hw2, hw2_mask;
|
|
|
|
|
2008-11-05 08:02:23 +07:00
|
|
|
sw1_mask = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
|
2008-08-31 02:03:44 +07:00
|
|
|
sw1 = cx18_read_reg(cx, SW1_INT_STATUS) & sw1_mask;
|
2008-11-05 08:02:23 +07:00
|
|
|
sw2_mask = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
|
2008-11-01 06:49:12 +07:00
|
|
|
sw2 = cx18_read_reg(cx, SW2_INT_STATUS) & sw2_mask;
|
|
|
|
hw2_mask = cx18_read_reg(cx, HW2_INT_MASK5_PCI);
|
|
|
|
hw2 = cx18_read_reg(cx, HW2_INT_CLR_STATUS) & hw2_mask;
|
2008-04-29 06:24:33 +07:00
|
|
|
|
2008-11-01 06:49:12 +07:00
|
|
|
if (sw1)
|
|
|
|
cx18_write_reg_expect(cx, sw1, SW1_INT_STATUS, ~sw1, sw1);
|
|
|
|
if (sw2)
|
|
|
|
cx18_write_reg_expect(cx, sw2, SW2_INT_STATUS, ~sw2, sw2);
|
|
|
|
if (hw2)
|
|
|
|
cx18_write_reg_expect(cx, hw2, HW2_INT_CLR_STATUS, ~hw2, hw2);
|
2008-04-29 06:24:33 +07:00
|
|
|
|
|
|
|
if (sw1 || sw2 || hw2)
|
|
|
|
CX18_DEBUG_HI_IRQ("SW1: %x SW2: %x HW2: %x\n", sw1, sw2, hw2);
|
|
|
|
|
|
|
|
/* To do: interrupt-based I2C handling
|
2008-11-05 08:02:23 +07:00
|
|
|
if (hw2 & (HW2_I2C1_INT|HW2_I2C2_INT)) {
|
2008-04-29 06:24:33 +07:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2008-11-05 08:02:23 +07:00
|
|
|
if (sw2)
|
|
|
|
xpu_ack(cx, sw2);
|
2008-04-29 06:24:33 +07:00
|
|
|
|
|
|
|
if (sw1)
|
2008-11-05 08:02:23 +07:00
|
|
|
epu_cmd(cx, sw1);
|
2008-04-29 06:24:33 +07:00
|
|
|
|
2008-11-05 10:49:14 +07:00
|
|
|
if (test_and_clear_bit(CX18_F_I_HAVE_WORK, &cx->i_flags))
|
2008-11-06 07:19:15 +07:00
|
|
|
schedule_work(&cx->work);
|
2008-11-05 10:49:14 +07:00
|
|
|
|
2008-11-01 06:49:12 +07:00
|
|
|
return (sw1 || sw2 || hw2) ? IRQ_HANDLED : IRQ_NONE;
|
2008-04-29 06:24:33 +07:00
|
|
|
}
|