mixart_core.c 18 KB

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