mixart_core.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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 <linux/pci.h>
  25. #include <linux/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. if (tailptr < MSG_OUTBOUND_POST_STACK)
  49. return 0; /* error */
  50. if (tailptr >= MSG_OUTBOUND_POST_STACK + MSG_BOUND_STACK_SIZE)
  51. return 0; /* error */
  52. *msg_frame = readl_be(MIXART_MEM(mgr, tailptr));
  53. /* increment the tail index */
  54. tailptr += 4;
  55. if( tailptr >= (MSG_OUTBOUND_POST_STACK+MSG_BOUND_STACK_SIZE) )
  56. tailptr = MSG_OUTBOUND_POST_STACK;
  57. writel_be(tailptr, MIXART_MEM(mgr, MSG_OUTBOUND_POST_TAIL));
  58. return 1;
  59. }
  60. static int get_msg(struct mixart_mgr *mgr, struct mixart_msg *resp,
  61. u32 msg_frame_address )
  62. {
  63. u32 headptr;
  64. u32 size;
  65. int err;
  66. #ifndef __BIG_ENDIAN
  67. unsigned int i;
  68. #endif
  69. mutex_lock(&mgr->msg_lock);
  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. dev_err(&mgr->pci->dev,
  79. "problem with response size = %d\n", size);
  80. goto _clean_exit;
  81. }
  82. size -= MSG_DESCRIPTOR_SIZE;
  83. memcpy_fromio(resp->data, MIXART_MEM(mgr, msg_frame_address + MSG_HEADER_SIZE ), size);
  84. resp->size = size;
  85. /* swap if necessary */
  86. #ifndef __BIG_ENDIAN
  87. size /= 4; /* u32 size */
  88. for(i=0; i < size; i++) {
  89. ((u32*)resp->data)[i] = be32_to_cpu(((u32*)resp->data)[i]);
  90. }
  91. #endif
  92. /*
  93. * free message frame address
  94. */
  95. headptr = readl_be(MIXART_MEM(mgr, MSG_OUTBOUND_FREE_HEAD));
  96. if( (headptr < MSG_OUTBOUND_FREE_STACK) || ( headptr >= (MSG_OUTBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE))) {
  97. err = -EINVAL;
  98. goto _clean_exit;
  99. }
  100. /* give address back to outbound fifo */
  101. writel_be(msg_frame_address, MIXART_MEM(mgr, headptr));
  102. /* increment the outbound free head */
  103. headptr += 4;
  104. if( headptr >= (MSG_OUTBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE) )
  105. headptr = MSG_OUTBOUND_FREE_STACK;
  106. writel_be(headptr, MIXART_MEM(mgr, MSG_OUTBOUND_FREE_HEAD));
  107. _clean_exit:
  108. mutex_unlock(&mgr->msg_lock);
  109. return err;
  110. }
  111. /*
  112. * send a message to miXart. return: the msg_frame used for this message
  113. */
  114. /* call with mgr->msg_lock held! */
  115. static int send_msg( struct mixart_mgr *mgr,
  116. struct mixart_msg *msg,
  117. int max_answersize,
  118. int mark_pending,
  119. u32 *msg_event)
  120. {
  121. u32 headptr, tailptr;
  122. u32 msg_frame_address;
  123. int i;
  124. if (snd_BUG_ON(msg->size % 4))
  125. return -EINVAL;
  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. dev_err(&mgr->pci->dev, "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. init_waitqueue_entry(&wait, current);
  194. mutex_lock(&mgr->msg_lock);
  195. /* send the message */
  196. err = send_msg(mgr, request, max_resp_size, 1, &msg_frame); /* send and mark the answer pending */
  197. if (err) {
  198. mutex_unlock(&mgr->msg_lock);
  199. return err;
  200. }
  201. set_current_state(TASK_UNINTERRUPTIBLE);
  202. add_wait_queue(&mgr->msg_sleep, &wait);
  203. mutex_unlock(&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. dev_err(&mgr->pci->dev,
  209. "error: no response 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. dev_err(&mgr->pci->dev, "RESPONSE ERROR!\n");
  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. if (snd_BUG_ON(!notif_event))
  229. return -EINVAL;
  230. if (snd_BUG_ON((notif_event & MSG_TYPE_MASK) != MSG_TYPE_NOTIFY))
  231. return -EINVAL;
  232. if (snd_BUG_ON(notif_event & MSG_CANCEL_NOTIFY_MASK))
  233. return -EINVAL;
  234. init_waitqueue_entry(&wait, current);
  235. mutex_lock(&mgr->msg_lock);
  236. /* send the message */
  237. err = send_msg(mgr, request, MSG_DEFAULT_SIZE, 1, &notif_event); /* send and mark the notification event pending */
  238. if(err) {
  239. mutex_unlock(&mgr->msg_lock);
  240. return err;
  241. }
  242. set_current_state(TASK_UNINTERRUPTIBLE);
  243. add_wait_queue(&mgr->msg_sleep, &wait);
  244. mutex_unlock(&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. dev_err(&mgr->pci->dev,
  250. "error: notification %x not received\n", notif_event);
  251. return -EIO;
  252. }
  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. int err;
  259. /* just send the message (do not mark it as a pending one) */
  260. mutex_lock(&mgr->msg_lock);
  261. err = send_msg(mgr, request, MSG_DEFAULT_SIZE, 0, &message_frame);
  262. mutex_unlock(&mgr->msg_lock);
  263. /* the answer will be handled by snd_struct mixart_msgasklet() */
  264. atomic_inc(&mgr->msg_processed);
  265. return err;
  266. }
  267. /* common buffer of interrupt to send/receive messages */
  268. static u32 mixart_msg_data[MSG_DEFAULT_SIZE / 4];
  269. static void snd_mixart_process_msg(struct mixart_mgr *mgr)
  270. {
  271. struct mixart_msg resp;
  272. u32 msg, addr, type;
  273. int err;
  274. while (mgr->msg_fifo_readptr != mgr->msg_fifo_writeptr) {
  275. msg = mgr->msg_fifo[mgr->msg_fifo_readptr];
  276. mgr->msg_fifo_readptr++;
  277. mgr->msg_fifo_readptr %= MSG_FIFO_SIZE;
  278. /* process the message ... */
  279. addr = msg & ~MSG_TYPE_MASK;
  280. type = msg & MSG_TYPE_MASK;
  281. switch (type) {
  282. case MSG_TYPE_ANSWER:
  283. /* answer to a message on that we did not wait for (send_msg_nonblock) */
  284. resp.message_id = 0;
  285. resp.data = mixart_msg_data;
  286. resp.size = sizeof(mixart_msg_data);
  287. err = get_msg(mgr, &resp, addr);
  288. if( err < 0 ) {
  289. dev_err(&mgr->pci->dev,
  290. "error(%d) reading mf %x\n",
  291. err, msg);
  292. break;
  293. }
  294. switch(resp.message_id) {
  295. case MSG_STREAM_START_INPUT_STAGE_PACKET:
  296. case MSG_STREAM_START_OUTPUT_STAGE_PACKET:
  297. case MSG_STREAM_STOP_INPUT_STAGE_PACKET:
  298. case MSG_STREAM_STOP_OUTPUT_STAGE_PACKET:
  299. if(mixart_msg_data[0])
  300. dev_err(&mgr->pci->dev,
  301. "error MSG_STREAM_ST***_***PUT_STAGE_PACKET status=%x\n",
  302. mixart_msg_data[0]);
  303. break;
  304. default:
  305. dev_dbg(&mgr->pci->dev,
  306. "received mf(%x) : msg_id(%x) uid(%x, %x) size(%zd)\n",
  307. msg, resp.message_id, resp.uid.object_id, resp.uid.desc, resp.size);
  308. break;
  309. }
  310. break;
  311. case MSG_TYPE_NOTIFY:
  312. /* msg contains no address ! do not get_msg() ! */
  313. case MSG_TYPE_COMMAND:
  314. /* get_msg() necessary */
  315. default:
  316. dev_err(&mgr->pci->dev,
  317. "doesn't know what to do with message %x\n",
  318. msg);
  319. } /* switch type */
  320. /* decrement counter */
  321. atomic_dec(&mgr->msg_processed);
  322. } /* while there is a msg in fifo */
  323. }
  324. irqreturn_t snd_mixart_interrupt(int irq, void *dev_id)
  325. {
  326. struct mixart_mgr *mgr = dev_id;
  327. u32 it_reg;
  328. it_reg = readl_le(MIXART_REG(mgr, MIXART_PCI_OMISR_OFFSET));
  329. if( !(it_reg & MIXART_OIDI) ) {
  330. /* this device did not cause the interrupt */
  331. return IRQ_NONE;
  332. }
  333. /* mask all interrupts */
  334. writel_le(MIXART_HOST_ALL_INTERRUPT_MASKED, MIXART_REG(mgr, MIXART_PCI_OMIMR_OFFSET));
  335. /* outdoorbell register clear */
  336. it_reg = readl(MIXART_REG(mgr, MIXART_PCI_ODBR_OFFSET));
  337. writel(it_reg, MIXART_REG(mgr, MIXART_PCI_ODBR_OFFSET));
  338. /* clear interrupt */
  339. writel_le( MIXART_OIDI, MIXART_REG(mgr, MIXART_PCI_OMISR_OFFSET) );
  340. return IRQ_WAKE_THREAD;
  341. }
  342. irqreturn_t snd_mixart_threaded_irq(int irq, void *dev_id)
  343. {
  344. struct mixart_mgr *mgr = dev_id;
  345. int err;
  346. struct mixart_msg resp;
  347. u32 msg;
  348. mutex_lock(&mgr->lock);
  349. /* process interrupt */
  350. while (retrieve_msg_frame(mgr, &msg)) {
  351. switch (msg & MSG_TYPE_MASK) {
  352. case MSG_TYPE_COMMAND:
  353. resp.message_id = 0;
  354. resp.data = mixart_msg_data;
  355. resp.size = sizeof(mixart_msg_data);
  356. err = get_msg(mgr, &resp, msg & ~MSG_TYPE_MASK);
  357. if( err < 0 ) {
  358. dev_err(&mgr->pci->dev,
  359. "interrupt: error(%d) reading mf %x\n",
  360. err, msg);
  361. break;
  362. }
  363. if(resp.message_id == MSG_SERVICES_TIMER_NOTIFY) {
  364. int i;
  365. struct mixart_timer_notify *notify;
  366. notify = (struct mixart_timer_notify *)mixart_msg_data;
  367. for(i=0; i<notify->stream_count; i++) {
  368. u32 buffer_id = notify->streams[i].buffer_id;
  369. unsigned int chip_number = (buffer_id & MIXART_NOTIFY_CARD_MASK) >> MIXART_NOTIFY_CARD_OFFSET; /* card0 to 3 */
  370. unsigned int pcm_number = (buffer_id & MIXART_NOTIFY_PCM_MASK ) >> MIXART_NOTIFY_PCM_OFFSET; /* pcm0 to 3 */
  371. unsigned int sub_number = buffer_id & MIXART_NOTIFY_SUBS_MASK; /* 0 to MIXART_PLAYBACK_STREAMS */
  372. unsigned int is_capture = ((buffer_id & MIXART_NOTIFY_CAPT_MASK) != 0); /* playback == 0 / capture == 1 */
  373. struct snd_mixart *chip = mgr->chip[chip_number];
  374. struct mixart_stream *stream;
  375. if ((chip_number >= mgr->num_cards) || (pcm_number >= MIXART_PCM_TOTAL) || (sub_number >= MIXART_PLAYBACK_STREAMS)) {
  376. dev_err(&mgr->pci->dev,
  377. "error MSG_SERVICES_TIMER_NOTIFY buffer_id (%x) pos(%d)\n",
  378. buffer_id, notify->streams[i].sample_pos_low_part);
  379. break;
  380. }
  381. if (is_capture)
  382. stream = &chip->capture_stream[pcm_number];
  383. else
  384. stream = &chip->playback_stream[pcm_number][sub_number];
  385. if (stream->substream && (stream->status == MIXART_STREAM_STATUS_RUNNING)) {
  386. struct snd_pcm_runtime *runtime = stream->substream->runtime;
  387. int elapsed = 0;
  388. u64 sample_count = ((u64)notify->streams[i].sample_pos_high_part) << 32;
  389. sample_count |= notify->streams[i].sample_pos_low_part;
  390. while (1) {
  391. u64 new_elapse_pos = stream->abs_period_elapsed + runtime->period_size;
  392. if (new_elapse_pos > sample_count) {
  393. break; /* while */
  394. }
  395. else {
  396. elapsed = 1;
  397. stream->buf_periods++;
  398. if (stream->buf_periods >= runtime->periods)
  399. stream->buf_periods = 0;
  400. stream->abs_period_elapsed = new_elapse_pos;
  401. }
  402. }
  403. stream->buf_period_frag = (u32)( sample_count - stream->abs_period_elapsed );
  404. if(elapsed) {
  405. mutex_unlock(&mgr->lock);
  406. snd_pcm_period_elapsed(stream->substream);
  407. mutex_lock(&mgr->lock);
  408. }
  409. }
  410. }
  411. break;
  412. }
  413. if(resp.message_id == MSG_SERVICES_REPORT_TRACES) {
  414. if(resp.size > 1) {
  415. #ifndef __BIG_ENDIAN
  416. /* Traces are text: the swapped msg_data has to be swapped back ! */
  417. int i;
  418. for(i=0; i<(resp.size/4); i++) {
  419. (mixart_msg_data)[i] = cpu_to_be32((mixart_msg_data)[i]);
  420. }
  421. #endif
  422. ((char*)mixart_msg_data)[resp.size - 1] = 0;
  423. dev_dbg(&mgr->pci->dev,
  424. "MIXART TRACE : %s\n",
  425. (char *)mixart_msg_data);
  426. }
  427. break;
  428. }
  429. dev_dbg(&mgr->pci->dev, "command %x not handled\n",
  430. resp.message_id);
  431. break;
  432. case MSG_TYPE_NOTIFY:
  433. if(msg & MSG_CANCEL_NOTIFY_MASK) {
  434. msg &= ~MSG_CANCEL_NOTIFY_MASK;
  435. dev_err(&mgr->pci->dev,
  436. "canceled notification %x !\n", msg);
  437. }
  438. /* no break, continue ! */
  439. case MSG_TYPE_ANSWER:
  440. /* answer or notification to a message we are waiting for*/
  441. mutex_lock(&mgr->msg_lock);
  442. if( (msg & ~MSG_TYPE_MASK) == mgr->pending_event ) {
  443. wake_up(&mgr->msg_sleep);
  444. mgr->pending_event = 0;
  445. }
  446. /* answer to a message we did't want to wait for */
  447. else {
  448. mgr->msg_fifo[mgr->msg_fifo_writeptr] = msg;
  449. mgr->msg_fifo_writeptr++;
  450. mgr->msg_fifo_writeptr %= MSG_FIFO_SIZE;
  451. snd_mixart_process_msg(mgr);
  452. }
  453. mutex_unlock(&mgr->msg_lock);
  454. break;
  455. case MSG_TYPE_REQUEST:
  456. default:
  457. dev_dbg(&mgr->pci->dev,
  458. "interrupt received request %x\n", msg);
  459. /* TODO : are there things to do here ? */
  460. break;
  461. } /* switch on msg type */
  462. } /* while there are msgs */
  463. /* allow interrupt again */
  464. writel_le( MIXART_ALLOW_OUTBOUND_DOORBELL, MIXART_REG( mgr, MIXART_PCI_OMIMR_OFFSET));
  465. mutex_unlock(&mgr->lock);
  466. return IRQ_HANDLED;
  467. }
  468. void snd_mixart_init_mailbox(struct mixart_mgr *mgr)
  469. {
  470. writel( 0, MIXART_MEM( mgr, MSG_HOST_RSC_PROTECTION ) );
  471. writel( 0, MIXART_MEM( mgr, MSG_AGENT_RSC_PROTECTION ) );
  472. /* allow outbound messagebox to generate interrupts */
  473. if(mgr->irq >= 0) {
  474. writel_le( MIXART_ALLOW_OUTBOUND_DOORBELL, MIXART_REG( mgr, MIXART_PCI_OMIMR_OFFSET));
  475. }
  476. return;
  477. }
  478. void snd_mixart_exit_mailbox(struct mixart_mgr *mgr)
  479. {
  480. /* no more interrupts on outbound messagebox */
  481. writel_le( MIXART_HOST_ALL_INTERRUPT_MASKED, MIXART_REG( mgr, MIXART_PCI_OMIMR_OFFSET));
  482. return;
  483. }
  484. void snd_mixart_reset_board(struct mixart_mgr *mgr)
  485. {
  486. /* reset miXart */
  487. writel_be( 1, MIXART_REG(mgr, MIXART_BA1_BRUTAL_RESET_OFFSET) );
  488. return;
  489. }