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