cx18-irq.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  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. #include "cx18-driver.h"
  22. #include "cx18-io.h"
  23. #include "cx18-firmware.h"
  24. #include "cx18-fileops.h"
  25. #include "cx18-queue.h"
  26. #include "cx18-irq.h"
  27. #include "cx18-ioctl.h"
  28. #include "cx18-mailbox.h"
  29. #include "cx18-vbi.h"
  30. #include "cx18-scb.h"
  31. #include "cx18-dvb.h"
  32. void cx18_work_handler(struct work_struct *work)
  33. {
  34. struct cx18 *cx = container_of(work, struct cx18, work);
  35. if (test_and_clear_bit(CX18_F_I_WORK_HANDLER_DVB, &cx->i_flags))
  36. cx18_dvb_work_handler(cx);
  37. }
  38. static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb)
  39. {
  40. u32 handle = mb->args[0];
  41. struct cx18_stream *s = NULL;
  42. struct cx18_buffer *buf;
  43. u32 off;
  44. int i;
  45. int id;
  46. for (i = 0; i < CX18_MAX_STREAMS; i++) {
  47. s = &cx->streams[i];
  48. if ((handle == s->handle) && (s->dvb.enabled))
  49. break;
  50. if (s->v4l2dev && handle == s->handle)
  51. break;
  52. }
  53. if (i == CX18_MAX_STREAMS) {
  54. CX18_WARN("Got DMA done notification for unknown/inactive"
  55. " handle %d\n", handle);
  56. mb->error = CXERR_NOT_OPEN;
  57. mb->cmd = 0;
  58. cx18_mb_ack(cx, mb);
  59. return;
  60. }
  61. off = mb->args[1];
  62. if (mb->args[2] != 1)
  63. CX18_WARN("Ack struct = %d for %s\n",
  64. mb->args[2], s->name);
  65. id = cx18_read_enc(cx, off);
  66. buf = cx18_queue_get_buf_irq(s, id, cx18_read_enc(cx, off + 4));
  67. CX18_DEBUG_HI_DMA("DMA DONE for %s (buffer %d)\n", s->name, id);
  68. if (buf) {
  69. cx18_buf_sync_for_cpu(s, buf);
  70. if (s->type == CX18_ENC_STREAM_TYPE_TS && s->dvb.enabled) {
  71. CX18_DEBUG_HI_DMA("TS recv bytesused = %d\n",
  72. buf->bytesused);
  73. set_bit(CX18_F_I_WORK_HANDLER_DVB, &cx->i_flags);
  74. set_bit(CX18_F_I_HAVE_WORK, &cx->i_flags);
  75. } else
  76. set_bit(CX18_F_B_NEED_BUF_SWAP, &buf->b_flags);
  77. } else {
  78. CX18_WARN("Could not find buf %d for stream %s\n",
  79. cx18_read_enc(cx, off), s->name);
  80. }
  81. mb->error = 0;
  82. mb->cmd = 0;
  83. cx18_mb_ack(cx, mb);
  84. wake_up(&cx->dma_waitq);
  85. if (s->id != -1)
  86. wake_up(&s->waitq);
  87. }
  88. static void epu_debug(struct cx18 *cx, struct cx18_mailbox *mb)
  89. {
  90. char str[256] = { 0 };
  91. char *p;
  92. if (mb->args[1]) {
  93. cx18_setup_page(cx, mb->args[1]);
  94. cx18_memcpy_fromio(cx, str, cx->enc_mem + mb->args[1], 252);
  95. str[252] = 0;
  96. }
  97. cx18_mb_ack(cx, mb);
  98. CX18_DEBUG_INFO("%x %s\n", mb->args[0], str);
  99. p = strchr(str, '.');
  100. if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags) && p && p > str)
  101. CX18_INFO("FW version: %s\n", p - 1);
  102. }
  103. static void epu_cmd(struct cx18 *cx, u32 sw1)
  104. {
  105. struct cx18_mailbox mb;
  106. if (sw1 & IRQ_CPU_TO_EPU) {
  107. cx18_memcpy_fromio(cx, &mb, &cx->scb->cpu2epu_mb, sizeof(mb));
  108. mb.error = 0;
  109. switch (mb.cmd) {
  110. case CX18_EPU_DMA_DONE:
  111. epu_dma_done(cx, &mb);
  112. break;
  113. case CX18_EPU_DEBUG:
  114. epu_debug(cx, &mb);
  115. break;
  116. default:
  117. CX18_WARN("Unknown CPU_TO_EPU mailbox command %#08x\n",
  118. mb.cmd);
  119. break;
  120. }
  121. }
  122. if (sw1 & IRQ_APU_TO_EPU) {
  123. cx18_memcpy_fromio(cx, &mb, &cx->scb->apu2epu_mb, sizeof(mb));
  124. CX18_WARN("Unknown APU_TO_EPU mailbox command %#08x\n", mb.cmd);
  125. }
  126. if (sw1 & IRQ_HPU_TO_EPU) {
  127. cx18_memcpy_fromio(cx, &mb, &cx->scb->hpu2epu_mb, sizeof(mb));
  128. CX18_WARN("Unknown HPU_TO_EPU mailbox command %#08x\n", mb.cmd);
  129. }
  130. }
  131. static void xpu_ack(struct cx18 *cx, u32 sw2)
  132. {
  133. if (sw2 & IRQ_CPU_TO_EPU_ACK)
  134. wake_up(&cx->mb_cpu_waitq);
  135. if (sw2 & IRQ_APU_TO_EPU_ACK)
  136. wake_up(&cx->mb_apu_waitq);
  137. if (sw2 & IRQ_HPU_TO_EPU_ACK)
  138. wake_up(&cx->mb_hpu_waitq);
  139. }
  140. irqreturn_t cx18_irq_handler(int irq, void *dev_id)
  141. {
  142. struct cx18 *cx = (struct cx18 *)dev_id;
  143. u32 sw1, sw1_mask;
  144. u32 sw2, sw2_mask;
  145. u32 hw2, hw2_mask;
  146. sw1_mask = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
  147. sw1 = cx18_read_reg(cx, SW1_INT_STATUS) & sw1_mask;
  148. sw2_mask = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
  149. sw2 = cx18_read_reg(cx, SW2_INT_STATUS) & sw2_mask;
  150. hw2_mask = cx18_read_reg(cx, HW2_INT_MASK5_PCI);
  151. hw2 = cx18_read_reg(cx, HW2_INT_CLR_STATUS) & hw2_mask;
  152. if (sw1)
  153. cx18_write_reg_expect(cx, sw1, SW1_INT_STATUS, ~sw1, sw1);
  154. if (sw2)
  155. cx18_write_reg_expect(cx, sw2, SW2_INT_STATUS, ~sw2, sw2);
  156. if (hw2)
  157. cx18_write_reg_expect(cx, hw2, HW2_INT_CLR_STATUS, ~hw2, hw2);
  158. if (sw1 || sw2 || hw2)
  159. CX18_DEBUG_HI_IRQ("SW1: %x SW2: %x HW2: %x\n", sw1, sw2, hw2);
  160. /* To do: interrupt-based I2C handling
  161. if (hw2 & (HW2_I2C1_INT|HW2_I2C2_INT)) {
  162. }
  163. */
  164. if (sw2)
  165. xpu_ack(cx, sw2);
  166. if (sw1)
  167. epu_cmd(cx, sw1);
  168. if (test_and_clear_bit(CX18_F_I_HAVE_WORK, &cx->i_flags))
  169. schedule_work(&cx->work);
  170. return (sw1 || sw2 || hw2) ? IRQ_HANDLED : IRQ_NONE;
  171. }