mixart_core.c 18 KB

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