blob: bc36a6b8f775ac08780c2b5c9f3e6f90ad62e30c [file] [log] [blame]
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001/*
2 * cx18 interrupt handling
3 *
4 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
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 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 * 02111-1307 USA
20 */
21
22#include "cx18-driver.h"
Andy Wallsb1526422008-08-30 16:03:44 -030023#include "cx18-io.h"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030024#include "cx18-irq.h"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030025#include "cx18-mailbox.h"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030026#include "cx18-scb.h"
Andy Walls465f8a82008-11-04 22:02:23 -030027
28static void xpu_ack(struct cx18 *cx, u32 sw2)
29{
30 if (sw2 & IRQ_CPU_TO_EPU_ACK)
31 wake_up(&cx->mb_cpu_waitq);
32 if (sw2 & IRQ_APU_TO_EPU_ACK)
33 wake_up(&cx->mb_apu_waitq);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030034}
35
Andy Wallsee2d64f2008-11-16 01:38:19 -030036static void epu_cmd(struct cx18 *cx, u32 sw1)
37{
38 if (sw1 & IRQ_CPU_TO_EPU)
39 cx18_api_epu_cmd_irq(cx, CPU);
40 if (sw1 & IRQ_APU_TO_EPU)
41 cx18_api_epu_cmd_irq(cx, APU);
42}
43
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030044irqreturn_t cx18_irq_handler(int irq, void *dev_id)
45{
46 struct cx18 *cx = (struct cx18 *)dev_id;
47 u32 sw1, sw1_mask;
48 u32 sw2, sw2_mask;
49 u32 hw2, hw2_mask;
50
Andy Walls465f8a82008-11-04 22:02:23 -030051 sw1_mask = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
Andy Wallsb1526422008-08-30 16:03:44 -030052 sw1 = cx18_read_reg(cx, SW1_INT_STATUS) & sw1_mask;
Andy Walls465f8a82008-11-04 22:02:23 -030053 sw2_mask = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
Andy Wallsf056d292008-10-31 20:49:12 -030054 sw2 = cx18_read_reg(cx, SW2_INT_STATUS) & sw2_mask;
55 hw2_mask = cx18_read_reg(cx, HW2_INT_MASK5_PCI);
56 hw2 = cx18_read_reg(cx, HW2_INT_CLR_STATUS) & hw2_mask;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030057
Andy Wallsf056d292008-10-31 20:49:12 -030058 if (sw1)
59 cx18_write_reg_expect(cx, sw1, SW1_INT_STATUS, ~sw1, sw1);
60 if (sw2)
61 cx18_write_reg_expect(cx, sw2, SW2_INT_STATUS, ~sw2, sw2);
62 if (hw2)
63 cx18_write_reg_expect(cx, hw2, HW2_INT_CLR_STATUS, ~hw2, hw2);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030064
65 if (sw1 || sw2 || hw2)
Andy Wallsac504412008-11-07 23:57:46 -030066 CX18_DEBUG_HI_IRQ("received interrupts "
67 "SW1: %x SW2: %x HW2: %x\n", sw1, sw2, hw2);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030068
Andy Wallsee2d64f2008-11-16 01:38:19 -030069 /*
70 * SW1 responses have to happen first. The sending XPU times out the
71 * incoming mailboxes on us rather rapidly.
72 */
73 if (sw1)
74 epu_cmd(cx, sw1);
75
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030076 /* To do: interrupt-based I2C handling
Andy Walls465f8a82008-11-04 22:02:23 -030077 if (hw2 & (HW2_I2C1_INT|HW2_I2C2_INT)) {
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030078 }
79 */
80
Andy Walls465f8a82008-11-04 22:02:23 -030081 if (sw2)
82 xpu_ack(cx, sw2);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030083
Andy Wallsf056d292008-10-31 20:49:12 -030084 return (sw1 || sw2 || hw2) ? IRQ_HANDLED : IRQ_NONE;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030085}