mixart_core.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. * Driver for Digigram miXart soundcards
  3. *
  4. * low level interface with interrupt handling and mail box implementation
  5. *
  6. * Copyright (c) 2003 by Digigram <alsa@digigram.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <sound/driver.h>
  23. #include <linux/interrupt.h>
  24. #include <asm/io.h>
  25. #include <sound/core.h>
  26. #include "mixart.h"
  27. #include "mixart_hwdep.h"
  28. #include "mixart_core.h"
  29. #define MSG_TIMEOUT_JIFFIES (400 * HZ) / 1000 /* 400 ms */
  30. #define MSG_DESCRIPTOR_SIZE 0x24
  31. #define MSG_HEADER_SIZE (MSG_DESCRIPTOR_SIZE + 4)
  32. #define MSG_DEFAULT_SIZE 512
  33. #define MSG_TYPE_MASK 0x00000003 /* mask for following types */
  34. #define MSG_TYPE_NOTIFY 0 /* embedded -> driver (only notification, do not get_msg() !) */
  35. #define MSG_TYPE_COMMAND 1 /* driver <-> embedded (a command has no answer) */
  36. #define MSG_TYPE_REQUEST 2 /* driver -> embedded (request will get an answer back) */
  37. #define MSG_TYPE_ANSWER 3 /* embedded -> driver */
  38. #define MSG_CANCEL_NOTIFY_MASK 0x80000000 /* this bit is set for a notification that has been canceled */
  39. static int retrieve_msg_frame(struct mixart_mgr *mgr, u32 *msg_frame)
  40. {
  41. /* read the message frame fifo */
  42. u32 headptr, tailptr;
  43. tailptr = readl_be(MIXART_MEM(mgr, MSG_OUTBOUND_POST_TAIL));
  44. headptr = readl_be(MIXART_MEM(mgr, MSG_OUTBOUND_POST_HEAD));
  45. if (tailptr == headptr)
  46. return 0; /* no message posted */
  47. snd_assert( tailptr >= MSG_OUTBOUND_POST_STACK, return 0); /* error */
  48. snd_assert( tailptr < (MSG_OUTBOUND_POST_STACK+MSG_BOUND_STACK_SIZE), return 0); /* error */
  49. *msg_frame = readl_be(MIXART_MEM(mgr, tailptr));
  50. /* increment the tail index */
  51. tailptr += 4;
  52. if( tailptr >= (MSG_OUTBOUND_POST_STACK+MSG_BOUND_STACK_SIZE) )
  53. tailptr = MSG_OUTBOUND_POST_STACK;
  54. writel_be(tailptr, MIXART_MEM(mgr, MSG_OUTBOUND_POST_TAIL));
  55. return 1;
  56. }
  57. static int get_msg(struct mixart_mgr *mgr, struct mixart_msg *resp,
  58. u32 msg_frame_address )
  59. {
  60. unsigned long flags;
  61. u32 headptr;
  62. u32 size;
  63. int err;
  64. #ifndef __BIG_ENDIAN
  65. unsigned int i;
  66. #endif
  67. spin_lock_irqsave(&mgr->msg_lock, flags);
  68. err = 0;
  69. /* copy message descriptor from miXart to driver */
  70. size = readl_be(MIXART_MEM(mgr, msg_frame_address)); /* size of descriptor + response */
  71. resp->message_id = readl_be(MIXART_MEM(mgr, msg_frame_address + 4)); /* dwMessageID */
  72. resp->uid.object_id = readl_be(MIXART_MEM(mgr, msg_frame_address + 8)); /* uidDest */
  73. resp->uid.desc = readl_be(MIXART_MEM(mgr, msg_frame_address + 12)); /* */
  74. if( (size < MSG_DESCRIPTOR_SIZE) || (resp->size < (size - MSG_DESCRIPTOR_SIZE))) {
  75. err = -EINVAL;
  76. snd_printk(KERN_ERR "problem with response size = %d\n", size);
  77. goto _clean_exit;
  78. }
  79. size -= MSG_DESCRIPTOR_SIZE;
  80. memcpy_fromio(resp->data, MIXART_MEM(mgr, msg_frame_address + MSG_HEADER_SIZE ), size);
  81. resp->size = size;
  82. /* swap if necessary */
  83. #ifndef __BIG_ENDIAN
  84. size /= 4; /* u32 size */
  85. for(i=0; i < size; i++) {
  86. ((u32*)resp->data)[i] = be32_to_cpu(((u32*)resp->data)[i]);
  87. }
  88. #endif
  89. /*
  90. * free message frame address
  91. */
  92. headptr = readl_be(MIXART_MEM(mgr, MSG_OUTBOUND_FREE_HEAD));
  93. if( (headptr < MSG_OUTBOUND_FREE_STACK) || ( headptr >= (MSG_OUTBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE))) {
  94. err = -EINVAL;
  95. goto _clean_exit;
  96. }
  97. /* give address back to outbound fifo */
  98. writel_be(msg_frame_address, MIXART_MEM(mgr, headptr));
  99. /* increment the outbound free head */
  100. headptr += 4;
  101. if( headptr >= (MSG_OUTBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE) )
  102. headptr = MSG_OUTBOUND_FREE_STACK;
  103. writel_be(headptr, MIXART_MEM(mgr, MSG_OUTBOUND_FREE_HEAD));
  104. _clean_exit:
  105. spin_unlock_irqrestore(&mgr->msg_lock, flags);
  106. return err;
  107. }
  108. /*
  109. * send a message to miXart. return: the msg_frame used for this message
  110. */
  111. /* call with mgr->msg_lock held! */
  112. static int send_msg( struct mixart_mgr *mgr,
  113. struct mixart_msg *msg,
  114. int max_answersize,
  115. int mark_pending,
  116. u32 *msg_event)
  117. {
  118. u32 headptr, tailptr;
  119. u32 msg_frame_address;
  120. int err, i;
  121. snd_assert(msg->size % 4 == 0, return -EINVAL);
  122. err = 0;
  123. /* get message frame address */
  124. tailptr = readl_be(MIXART_MEM(mgr, MSG_INBOUND_FREE_TAIL));
  125. headptr = readl_be(MIXART_MEM(mgr, MSG_INBOUND_FREE_HEAD));
  126. if (tailptr == headptr) {
  127. snd_printk(KERN_ERR "error: no message frame available\n");
  128. return -EBUSY;
  129. }
  130. if( (tailptr < MSG_INBOUND_FREE_STACK) || (tailptr >= (MSG_INBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE))) {
  131. return -EINVAL;
  132. }
  133. msg_frame_address = readl_be(MIXART_MEM(mgr, tailptr));
  134. writel(0, MIXART_MEM(mgr, tailptr)); /* set address to zero on this fifo position */
  135. /* increment the inbound free tail */
  136. tailptr += 4;
  137. if( tailptr >= (MSG_INBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE) )
  138. tailptr = MSG_INBOUND_FREE_STACK;
  139. writel_be(tailptr, MIXART_MEM(mgr, MSG_INBOUND_FREE_TAIL));
  140. /* TODO : use memcpy_toio() with intermediate buffer to copy the message */
  141. /* copy message descriptor to card memory */
  142. writel_be( msg->size + MSG_DESCRIPTOR_SIZE, MIXART_MEM(mgr, msg_frame_address) ); /* size of descriptor + request */
  143. writel_be( msg->message_id , MIXART_MEM(mgr, msg_frame_address + 4) ); /* dwMessageID */
  144. writel_be( msg->uid.object_id, MIXART_MEM(mgr, msg_frame_address + 8) ); /* uidDest */
  145. writel_be( msg->uid.desc, MIXART_MEM(mgr, msg_frame_address + 12) ); /* */
  146. writel_be( MSG_DESCRIPTOR_SIZE, MIXART_MEM(mgr, msg_frame_address + 16) ); /* SizeHeader */
  147. writel_be( MSG_DESCRIPTOR_SIZE, MIXART_MEM(mgr, msg_frame_address + 20) ); /* OffsetDLL_T16 */
  148. writel_be( msg->size, MIXART_MEM(mgr, msg_frame_address + 24) ); /* SizeDLL_T16 */
  149. writel_be( MSG_DESCRIPTOR_SIZE, MIXART_MEM(mgr, msg_frame_address + 28) ); /* OffsetDLL_DRV */
  150. writel_be( 0, MIXART_MEM(mgr, msg_frame_address + 32) ); /* SizeDLL_DRV */
  151. writel_be( MSG_DESCRIPTOR_SIZE + max_answersize, MIXART_MEM(mgr, msg_frame_address + 36) ); /* dwExpectedAnswerSize */
  152. /* copy message data to card memory */
  153. for( i=0; i < msg->size; i+=4 ) {
  154. writel_be( *(u32*)(msg->data + i), MIXART_MEM(mgr, MSG_HEADER_SIZE + msg_frame_address + i) );
  155. }
  156. if( mark_pending ) {
  157. if( *msg_event ) {
  158. /* the pending event is the notification we wait for ! */
  159. mgr->pending_event = *msg_event;
  160. }
  161. else {
  162. /* the pending event is the answer we wait for (same address than the request)! */
  163. mgr->pending_event = msg_frame_address;
  164. /* copy address back to caller */
  165. *msg_event = msg_frame_address;
  166. }
  167. }
  168. /* mark the frame as a request (will have an answer) */
  169. msg_frame_address |= MSG_TYPE_REQUEST;
  170. /* post the frame */
  171. headptr = readl_be(MIXART_MEM(mgr, MSG_INBOUND_POST_HEAD));
  172. if( (headptr < MSG_INBOUND_POST_STACK) || (headptr >= (MSG_INBOUND_POST_STACK+MSG_BOUND_STACK_SIZE))) {
  173. return -EINVAL;
  174. }
  175. writel_be(msg_frame_address, MIXART_MEM(mgr, headptr));
  176. /* increment the inbound post head */
  177. headptr += 4;
  178. if( headptr >= (MSG_INBOUND_POST_STACK+MSG_BOUND_STACK_SIZE) )
  179. headptr = MSG_INBOUND_POST_STACK;
  180. writel_be(headptr, MIXART_MEM(mgr, MSG_INBOUND_POST_HEAD));
  181. return 0;
  182. }
  183. int snd_mixart_send_msg(struct mixart_mgr *mgr, struct mixart_msg *request, int max_resp_size, void *resp_data)
  184. {
  185. struct mixart_msg resp;
  186. u32 msg_frame = 0; /* set to 0, so it's no notification to wait for, but the answer */
  187. int err;
  188. wait_queue_t wait;
  189. long timeout;
  190. down(&mgr->msg_mutex);
  191. init_waitqueue_entry(&wait, current);
  192. spin_lock_irq(&mgr->msg_lock);
  193. /* send the message */
  194. err = send_msg(mgr, request, max_resp_size, 1, &msg_frame); /* send and mark the answer pending */
  195. if (err) {
  196. spin_unlock_irq(&mgr->msg_lock);
  197. up(&mgr->msg_mutex);
  198. return err;
  199. }
  200. set_current_state(TASK_UNINTERRUPTIBLE);
  201. add_wait_queue(&mgr->msg_sleep, &wait);
  202. spin_unlock_irq(&mgr->msg_lock);
  203. timeout = schedule_timeout(MSG_TIMEOUT_JIFFIES);
  204. remove_wait_queue(&mgr->msg_sleep, &wait);
  205. if (! timeout) {
  206. /* error - no ack */
  207. up(&mgr->msg_mutex);
  208. snd_printk(KERN_ERR "error: no reponse on msg %x\n", msg_frame);
  209. return -EIO;
  210. }
  211. /* retrieve the answer into the same struct mixart_msg */
  212. resp.message_id = 0;
  213. resp.uid = (struct mixart_uid){0,0};
  214. resp.data = resp_data;
  215. resp.size = max_resp_size;
  216. err = get_msg(mgr, &resp, msg_frame);
  217. if( request->message_id != resp.message_id )
  218. snd_printk(KERN_ERR "REPONSE ERROR!\n");
  219. up(&mgr->msg_mutex);
  220. return err;
  221. }
  222. int snd_mixart_send_msg_wait_notif(struct mixart_mgr *mgr,
  223. struct mixart_msg *request, u32 notif_event)
  224. {
  225. int err;
  226. wait_queue_t wait;
  227. long timeout;
  228. snd_assert(notif_event != 0, return -EINVAL);
  229. snd_assert((notif_event & MSG_TYPE_MASK) == MSG_TYPE_NOTIFY, return -EINVAL);
  230. snd_assert((notif_event & MSG_CANCEL_NOTIFY_MASK) == 0, return -EINVAL);
  231. down(&mgr->msg_mutex);
  232. init_waitqueue_entry(&wait, current);
  233. spin_lock_irq(&mgr->msg_lock);
  234. /* send the message */
  235. err = send_msg(mgr, request, MSG_DEFAULT_SIZE, 1, &notif_event); /* send and mark the notification event pending */
  236. if(err) {
  237. spin_unlock_irq(&mgr->msg_lock);
  238. up(&mgr->msg_mutex);
  239. return err;
  240. }
  241. set_current_state(TASK_UNINTERRUPTIBLE);
  242. add_wait_queue(&mgr->msg_sleep, &wait);
  243. spin_unlock_irq(&mgr->msg_lock);
  244. timeout = schedule_timeout(MSG_TIMEOUT_JIFFIES);
  245. remove_wait_queue(&mgr->msg_sleep, &wait);
  246. if (! timeout) {
  247. /* error - no ack */
  248. up(&mgr->msg_mutex);
  249. snd_printk(KERN_ERR "error: notification %x not received\n", notif_event);
  250. return -EIO;
  251. }
  252. up(&mgr->msg_mutex);
  253. return 0;
  254. }
  255. int snd_mixart_send_msg_nonblock(struct mixart_mgr *mgr, struct mixart_msg *request)
  256. {
  257. u32 message_frame;
  258. unsigned long flags;
  259. int err;
  260. /* just send the message (do not mark it as a pending one) */
  261. spin_lock_irqsave(&mgr->msg_lock, flags);
  262. err = send_msg(mgr, request, MSG_DEFAULT_SIZE, 0, &message_frame);
  263. spin_unlock_irqrestore(&mgr->msg_lock, flags);
  264. /* the answer will be handled by snd_struct mixart_msgasklet() */
  265. atomic_inc(&mgr->msg_processed);
  266. return err;
  267. }
  268. /* common buffer of tasklet and interrupt to send/receive messages */
  269. static u32 mixart_msg_data[MSG_DEFAULT_SIZE / 4];
  270. void snd_mixart_msg_tasklet(unsigned long arg)
  271. {
  272. struct mixart_mgr *mgr = ( struct mixart_mgr*)(arg);
  273. struct mixart_msg resp;
  274. u32 msg, addr, type;
  275. int err;
  276. spin_lock(&mgr->lock);
  277. while (mgr->msg_fifo_readptr != mgr->msg_fifo_writeptr) {
  278. msg = mgr->msg_fifo[mgr->msg_fifo_readptr];
  279. mgr->msg_fifo_readptr++;
  280. mgr->msg_fifo_readptr %= MSG_FIFO_SIZE;
  281. /* process the message ... */
  282. addr = msg & ~MSG_TYPE_MASK;
  283. type = msg & MSG_TYPE_MASK;
  284. switch (type) {
  285. case MSG_TYPE_ANSWER:
  286. /* answer to a message on that we did not wait for (send_msg_nonblock) */
  287. resp.message_id = 0;
  288. resp.data = mixart_msg_data;
  289. resp.size = sizeof(mixart_msg_data);
  290. err = get_msg(mgr, &resp, addr);
  291. if( err < 0 ) {
  292. snd_printk(KERN_ERR "tasklet: error(%d) reading mf %x\n", err, msg);
  293. break;
  294. }
  295. switch(resp.message_id) {
  296. case MSG_STREAM_START_INPUT_STAGE_PACKET:
  297. case MSG_STREAM_START_OUTPUT_STAGE_PACKET:
  298. case MSG_STREAM_STOP_INPUT_STAGE_PACKET:
  299. case MSG_STREAM_STOP_OUTPUT_STAGE_PACKET:
  300. if(mixart_msg_data[0])
  301. snd_printk(KERN_ERR "tasklet : error MSG_STREAM_ST***_***PUT_STAGE_PACKET status=%x\n", mixart_msg_data[0]);
  302. break;
  303. default:
  304. snd_printdd("tasklet received mf(%x) : msg_id(%x) uid(%x, %x) size(%zd)\n",
  305. msg, resp.message_id, resp.uid.object_id, resp.uid.desc, resp.size);
  306. break;
  307. }
  308. break;
  309. case MSG_TYPE_NOTIFY:
  310. /* msg contains no address ! do not get_msg() ! */
  311. case MSG_TYPE_COMMAND:
  312. /* get_msg() necessary */
  313. default:
  314. snd_printk(KERN_ERR "tasklet doesn't know what to do with message %x\n", msg);
  315. } /* switch type */
  316. /* decrement counter */
  317. atomic_dec(&mgr->msg_processed);
  318. } /* while there is a msg in fifo */
  319. spin_unlock(&mgr->lock);
  320. }
  321. irqreturn_t snd_mixart_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  322. {
  323. struct mixart_mgr *mgr = dev_id;
  324. int err;
  325. struct mixart_msg resp;
  326. u32 msg;
  327. u32 it_reg;
  328. spin_lock(&mgr->lock);
  329. it_reg = readl_le(MIXART_REG(mgr, MIXART_PCI_OMISR_OFFSET));
  330. if( !(it_reg & MIXART_OIDI) ) {
  331. /* this device did not cause the interrupt */
  332. spin_unlock(&mgr->lock);
  333. return IRQ_NONE;
  334. }
  335. /* mask all interrupts */
  336. writel_le(MIXART_HOST_ALL_INTERRUPT_MASKED, MIXART_REG(mgr, MIXART_PCI_OMIMR_OFFSET));
  337. /* outdoorbell register clear */
  338. it_reg = readl(MIXART_REG(mgr, MIXART_PCI_ODBR_OFFSET));
  339. writel(it_reg, MIXART_REG(mgr, MIXART_PCI_ODBR_OFFSET));
  340. /* clear interrupt */
  341. writel_le( MIXART_OIDI, MIXART_REG(mgr, MIXART_PCI_OMISR_OFFSET) );
  342. /* process interrupt */
  343. while (retrieve_msg_frame(mgr, &msg)) {
  344. switch (msg & MSG_TYPE_MASK) {
  345. case MSG_TYPE_COMMAND:
  346. resp.message_id = 0;
  347. resp.data = mixart_msg_data;
  348. resp.size = sizeof(mixart_msg_data);
  349. err = get_msg(mgr, &resp, msg & ~MSG_TYPE_MASK);
  350. if( err < 0 ) {
  351. snd_printk(KERN_ERR "interrupt: error(%d) reading mf %x\n", err, msg);
  352. break;
  353. }
  354. if(resp.message_id == MSG_SERVICES_TIMER_NOTIFY) {
  355. int i;
  356. struct mixart_timer_notify *notify;
  357. notify = (struct mixart_timer_notify *)mixart_msg_data;
  358. for(i=0; i<notify->stream_count; i++) {
  359. u32 buffer_id = notify->streams[i].buffer_id;
  360. unsigned int chip_number = (buffer_id & MIXART_NOTIFY_CARD_MASK) >> MIXART_NOTIFY_CARD_OFFSET; /* card0 to 3 */
  361. unsigned int pcm_number = (buffer_id & MIXART_NOTIFY_PCM_MASK ) >> MIXART_NOTIFY_PCM_OFFSET; /* pcm0 to 3 */
  362. unsigned int sub_number = buffer_id & MIXART_NOTIFY_SUBS_MASK; /* 0 to MIXART_PLAYBACK_STREAMS */
  363. unsigned int is_capture = ((buffer_id & MIXART_NOTIFY_CAPT_MASK) != 0); /* playback == 0 / capture == 1 */
  364. struct snd_mixart *chip = mgr->chip[chip_number];
  365. struct mixart_stream *stream;
  366. if ((chip_number >= mgr->num_cards) || (pcm_number >= MIXART_PCM_TOTAL) || (sub_number >= MIXART_PLAYBACK_STREAMS)) {
  367. snd_printk(KERN_ERR "error MSG_SERVICES_TIMER_NOTIFY buffer_id (%x) pos(%d)\n",
  368. buffer_id, notify->streams[i].sample_pos_low_part);
  369. break;
  370. }
  371. if (is_capture)
  372. stream = &chip->capture_stream[pcm_number];
  373. else
  374. stream = &chip->playback_stream[pcm_number][sub_number];
  375. if (stream->substream && (stream->status == MIXART_STREAM_STATUS_RUNNING)) {
  376. struct snd_pcm_runtime *runtime = stream->substream->runtime;
  377. int elapsed = 0;
  378. u64 sample_count = ((u64)notify->streams[i].sample_pos_high_part) << 32;
  379. sample_count |= notify->streams[i].sample_pos_low_part;
  380. while (1) {
  381. u64 new_elapse_pos = stream->abs_period_elapsed + runtime->period_size;
  382. if (new_elapse_pos > sample_count) {
  383. break; /* while */
  384. }
  385. else {
  386. elapsed = 1;
  387. stream->buf_periods++;
  388. if (stream->buf_periods >= runtime->periods)
  389. stream->buf_periods = 0;
  390. stream->abs_period_elapsed = new_elapse_pos;
  391. }
  392. }
  393. stream->buf_period_frag = (u32)( sample_count - stream->abs_period_elapsed );
  394. if(elapsed) {
  395. spin_unlock(&mgr->lock);
  396. snd_pcm_period_elapsed(stream->substream);
  397. spin_lock(&mgr->lock);
  398. }
  399. }
  400. }
  401. break;
  402. }
  403. if(resp.message_id == MSG_SERVICES_REPORT_TRACES) {
  404. if(resp.size > 1) {
  405. #ifndef __BIG_ENDIAN
  406. /* Traces are text: the swapped msg_data has to be swapped back ! */
  407. int i;
  408. for(i=0; i<(resp.size/4); i++) {
  409. (mixart_msg_data)[i] = cpu_to_be32((mixart_msg_data)[i]);
  410. }
  411. #endif
  412. ((char*)mixart_msg_data)[resp.size - 1] = 0;
  413. snd_printdd("MIXART TRACE : %s\n", (char*)mixart_msg_data);
  414. }
  415. break;
  416. }
  417. snd_printdd("command %x not handled\n", resp.message_id);
  418. break;
  419. case MSG_TYPE_NOTIFY:
  420. if(msg & MSG_CANCEL_NOTIFY_MASK) {
  421. msg &= ~MSG_CANCEL_NOTIFY_MASK;
  422. snd_printk(KERN_ERR "canceled notification %x !\n", msg);
  423. }
  424. /* no break, continue ! */
  425. case MSG_TYPE_ANSWER:
  426. /* answer or notification to a message we are waiting for*/
  427. spin_lock(&mgr->msg_lock);
  428. if( (msg & ~MSG_TYPE_MASK) == mgr->pending_event ) {
  429. wake_up(&mgr->msg_sleep);
  430. mgr->pending_event = 0;
  431. }
  432. /* answer to a message we did't want to wait for */
  433. else {
  434. mgr->msg_fifo[mgr->msg_fifo_writeptr] = msg;
  435. mgr->msg_fifo_writeptr++;
  436. mgr->msg_fifo_writeptr %= MSG_FIFO_SIZE;
  437. tasklet_hi_schedule(&mgr->msg_taskq);
  438. }
  439. spin_unlock(&mgr->msg_lock);
  440. break;
  441. case MSG_TYPE_REQUEST:
  442. default:
  443. snd_printdd("interrupt received request %x\n", msg);
  444. /* TODO : are there things to do here ? */
  445. break;
  446. } /* switch on msg type */
  447. } /* while there are msgs */
  448. /* allow interrupt again */
  449. writel_le( MIXART_ALLOW_OUTBOUND_DOORBELL, MIXART_REG( mgr, MIXART_PCI_OMIMR_OFFSET));
  450. spin_unlock(&mgr->lock);
  451. return IRQ_HANDLED;
  452. }
  453. void snd_mixart_init_mailbox(struct mixart_mgr *mgr)
  454. {
  455. writel( 0, MIXART_MEM( mgr, MSG_HOST_RSC_PROTECTION ) );
  456. writel( 0, MIXART_MEM( mgr, MSG_AGENT_RSC_PROTECTION ) );
  457. /* allow outbound messagebox to generate interrupts */
  458. if(mgr->irq >= 0) {
  459. writel_le( MIXART_ALLOW_OUTBOUND_DOORBELL, MIXART_REG( mgr, MIXART_PCI_OMIMR_OFFSET));
  460. }
  461. return;
  462. }
  463. void snd_mixart_exit_mailbox(struct mixart_mgr *mgr)
  464. {
  465. /* no more interrupts on outbound messagebox */
  466. writel_le( MIXART_HOST_ALL_INTERRUPT_MASKED, MIXART_REG( mgr, MIXART_PCI_OMIMR_OFFSET));
  467. return;
  468. }
  469. void snd_mixart_reset_board(struct mixart_mgr *mgr)
  470. {
  471. /* reset miXart */
  472. writel_be( 1, MIXART_REG(mgr, MIXART_BA1_BRUTAL_RESET_OFFSET) );
  473. return;
  474. }