2 **********************************************************************
3 * sblive_mi.c - MIDI UART input HAL for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
6 **********************************************************************
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox clean up
13 **********************************************************************
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
30 **********************************************************************
33 #include <linux/slab.h>
34 #include <linux/jiffies.h>
42 static int emu10k1_mpuin_callback(struct emu10k1_mpuin
*card_mpuin
, u32 msg
, unsigned long data
, u32 bytesvalid
);
44 static int sblive_miStateInit(struct emu10k1_mpuin
*);
45 static int sblive_miStateEntry(struct emu10k1_mpuin
*, u8
);
46 static int sblive_miStateParse(struct emu10k1_mpuin
*, u8
);
47 static int sblive_miState3Byte(struct emu10k1_mpuin
*, u8
);
48 static int sblive_miState3ByteKey(struct emu10k1_mpuin
*, u8
);
49 static int sblive_miState3ByteVel(struct emu10k1_mpuin
*, u8
);
50 static int sblive_miState2Byte(struct emu10k1_mpuin
*, u8
);
51 static int sblive_miState2ByteKey(struct emu10k1_mpuin
*, u8
);
52 static int sblive_miStateSysCommon2(struct emu10k1_mpuin
*, u8
);
53 static int sblive_miStateSysCommon2Key(struct emu10k1_mpuin
*, u8
);
54 static int sblive_miStateSysCommon3(struct emu10k1_mpuin
*, u8
);
55 static int sblive_miStateSysCommon3Key(struct emu10k1_mpuin
*, u8
);
56 static int sblive_miStateSysCommon3Vel(struct emu10k1_mpuin
*, u8
);
57 static int sblive_miStateSysExNorm(struct emu10k1_mpuin
*, u8
);
58 static int sblive_miStateSysReal(struct emu10k1_mpuin
*, u8
);
62 int (*Fn
) (struct emu10k1_mpuin
*, u8
);
66 sblive_miStateParse
}, {
67 sblive_miState3Byte
}, /* 0x8n, 0x9n, 0xAn, 0xBn, 0xEn */
69 sblive_miState3ByteKey
}, /* Byte 1 */
71 sblive_miState3ByteVel
}, /* Byte 2 */
73 sblive_miState2Byte
}, /* 0xCn, 0xDn */
75 sblive_miState2ByteKey
}, /* Byte 1 */
77 sblive_miStateSysCommon2
}, /* 0xF1 , 0xF3 */
79 sblive_miStateSysCommon2Key
}, /* 0xF1 , 0xF3, Byte 1 */
81 sblive_miStateSysCommon3
}, /* 0xF2 */
83 sblive_miStateSysCommon3Key
}, /* 0xF2 , Byte 1 */
85 sblive_miStateSysCommon3Vel
}, /* 0xF2 , Byte 2 */
87 sblive_miStateSysExNorm
}, /* 0xF0, 0xF7, Normal mode */
89 sblive_miStateSysReal
} /* 0xF4 - 0xF6 ,0xF8 - 0xFF */
93 /* Installs the IRQ handler for the MPU in port */
95 /* and initialize parameters */
97 int emu10k1_mpuin_open(struct emu10k1_card
*card
, struct midi_openinfo
*openinfo
)
99 struct emu10k1_mpuin
*card_mpuin
= card
->mpuin
;
101 DPF(2, "emu10k1_mpuin_open\n");
103 if (!(card_mpuin
->status
& FLAGS_AVAILABLE
))
106 /* Copy open info and mark channel as in use */
107 card_mpuin
->openinfo
= *openinfo
;
108 card_mpuin
->status
&= ~FLAGS_AVAILABLE
; /* clear */
109 card_mpuin
->status
|= FLAGS_READY
; /* set */
110 card_mpuin
->status
&= ~FLAGS_MIDM_STARTED
; /* clear */
111 card_mpuin
->firstmidiq
= NULL
;
112 card_mpuin
->lastmidiq
= NULL
;
113 card_mpuin
->qhead
= 0;
114 card_mpuin
->qtail
= 0;
116 sblive_miStateInit(card_mpuin
);
118 emu10k1_mpu_reset(card
);
119 emu10k1_mpu_acquire(card
);
124 int emu10k1_mpuin_close(struct emu10k1_card
*card
)
126 struct emu10k1_mpuin
*card_mpuin
= card
->mpuin
;
128 DPF(2, "emu10k1_mpuin_close()\n");
130 /* Check if there are pending input SysEx buffers */
131 if (card_mpuin
->firstmidiq
!= NULL
) {
136 /* Disable RX interrupt */
137 emu10k1_irq_disable(card
, card
->is_audigy
? A_INTE_MIDIRXENABLE
: INTE_MIDIRXENABLE
);
139 emu10k1_mpu_release(card
);
141 card_mpuin
->status
|= FLAGS_AVAILABLE
; /* set */
142 card_mpuin
->status
&= ~FLAGS_MIDM_STARTED
; /* clear */
147 /* Adds MIDI buffer to local queue list */
149 int emu10k1_mpuin_add_buffer(struct emu10k1_mpuin
*card_mpuin
, struct midi_hdr
*midihdr
)
151 struct midi_queue
*midiq
;
154 DPF(2, "emu10k1_mpuin_add_buffer()\n");
156 /* Update MIDI buffer flags */
157 midihdr
->flags
|= MIDIBUF_INQUEUE
; /* set */
158 midihdr
->flags
&= ~MIDIBUF_DONE
; /* clear */
160 if ((midiq
= kmalloc(sizeof(struct midi_queue
), GFP_ATOMIC
)) == NULL
) {
167 midiq
->length
= midihdr
->bufferlength
;
168 midiq
->sizeLeft
= midihdr
->bufferlength
;
169 midiq
->midibyte
= midihdr
->data
;
170 midiq
->refdata
= (unsigned long) midihdr
;
172 spin_lock_irqsave(&card_mpuin
->lock
, flags
);
174 if (card_mpuin
->firstmidiq
== NULL
) {
175 card_mpuin
->firstmidiq
= midiq
;
176 card_mpuin
->lastmidiq
= midiq
;
178 (card_mpuin
->lastmidiq
)->next
= midiq
;
179 card_mpuin
->lastmidiq
= midiq
;
182 spin_unlock_irqrestore(&card_mpuin
->lock
, flags
);
187 /* First set the Time Stamp if MIDI IN has not started. */
189 /* Then enable RX Irq. */
191 int emu10k1_mpuin_start(struct emu10k1_card
*card
)
193 struct emu10k1_mpuin
*card_mpuin
= card
->mpuin
;
196 DPF(2, "emu10k1_mpuin_start()\n");
198 /* Set timestamp if not set */
199 if (card_mpuin
->status
& FLAGS_MIDM_STARTED
) {
200 DPF(2, "Time Stamp not changed\n");
202 while (!emu10k1_mpu_read_data(card
, &dummy
));
204 card_mpuin
->status
|= FLAGS_MIDM_STARTED
; /* set */
206 /* Set new time stamp */
207 card_mpuin
->timestart
= (jiffies
* 1000) / HZ
;
208 DPD(2, "New Time Stamp = %d\n", card_mpuin
->timestart
);
210 card_mpuin
->qhead
= 0;
211 card_mpuin
->qtail
= 0;
213 emu10k1_irq_enable(card
, card
->is_audigy
? A_INTE_MIDIRXENABLE
: INTE_MIDIRXENABLE
);
219 /* Disable the RX Irq. If a partial recorded buffer */
221 /* exist, send it up to IMIDI level. */
223 int emu10k1_mpuin_stop(struct emu10k1_card
*card
)
225 struct emu10k1_mpuin
*card_mpuin
= card
->mpuin
;
226 struct midi_queue
*midiq
;
229 DPF(2, "emu10k1_mpuin_stop()\n");
231 emu10k1_irq_disable(card
, card
->is_audigy
? A_INTE_MIDIRXENABLE
: INTE_MIDIRXENABLE
);
233 card_mpuin
->status
&= ~FLAGS_MIDM_STARTED
; /* clear */
235 if (card_mpuin
->firstmidiq
) {
236 spin_lock_irqsave(&card_mpuin
->lock
, flags
);
238 midiq
= card_mpuin
->firstmidiq
;
240 if (midiq
->sizeLeft
== midiq
->length
)
243 card_mpuin
->firstmidiq
= midiq
->next
;
244 if (card_mpuin
->firstmidiq
== NULL
)
245 card_mpuin
->lastmidiq
= NULL
;
249 spin_unlock_irqrestore(&card_mpuin
->lock
, flags
);
252 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INLONGERROR
, (unsigned long) midiq
, 0);
260 /* Disable the RX Irq. If any buffer */
262 /* exist, send it up to IMIDI level. */
263 int emu10k1_mpuin_reset(struct emu10k1_card
*card
)
265 struct emu10k1_mpuin
*card_mpuin
= card
->mpuin
;
266 struct midi_queue
*midiq
;
268 DPF(2, "emu10k1_mpuin_reset()\n");
270 emu10k1_irq_disable(card
, card
->is_audigy
? A_INTE_MIDIRXENABLE
: INTE_MIDIRXENABLE
);
272 while (card_mpuin
->firstmidiq
) {
273 midiq
= card_mpuin
->firstmidiq
;
274 card_mpuin
->firstmidiq
= midiq
->next
;
276 if (midiq
->sizeLeft
== midiq
->length
)
277 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INLONGDATA
, (unsigned long) midiq
, 0);
279 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INLONGERROR
, (unsigned long) midiq
, 0);
284 card_mpuin
->lastmidiq
= NULL
;
285 card_mpuin
->status
&= ~FLAGS_MIDM_STARTED
;
290 /* Passes the message with the data back to the client */
292 /* via IRQ & DPC callbacks to Ring 3 */
293 static int emu10k1_mpuin_callback(struct emu10k1_mpuin
*card_mpuin
, u32 msg
, unsigned long data
, u32 bytesvalid
)
295 unsigned long timein
;
296 struct midi_queue
*midiq
;
297 unsigned long callback_msg
[3];
298 struct midi_hdr
*midihdr
;
300 /* Called during ISR. The data & code touched are:
302 * 2. The function to be called
305 timein
= card_mpuin
->timein
;
306 if (card_mpuin
->timestart
<= timein
)
307 callback_msg
[0] = timein
- card_mpuin
->timestart
;
309 callback_msg
[0] = (~0x0L
- card_mpuin
->timestart
) + timein
;
311 if (msg
== ICARDMIDI_INDATA
|| msg
== ICARDMIDI_INDATAERROR
) {
312 callback_msg
[1] = data
;
313 callback_msg
[2] = bytesvalid
;
314 DPD(2, "emu10k1_mpuin_callback: midimsg = %#lx\n", data
);
316 midiq
= (struct midi_queue
*) data
;
317 midihdr
= (struct midi_hdr
*) midiq
->refdata
;
319 callback_msg
[1] = midiq
->length
- midiq
->sizeLeft
;
320 callback_msg
[2] = midiq
->refdata
;
321 midihdr
->flags
&= ~MIDIBUF_INQUEUE
;
322 midihdr
->flags
|= MIDIBUF_DONE
;
324 midihdr
->bytesrecorded
= midiq
->length
- midiq
->sizeLeft
;
327 /* Notify client that Sysex buffer has been sent */
328 emu10k1_midi_callback(msg
, card_mpuin
->openinfo
.refdata
, callback_msg
);
333 void emu10k1_mpuin_bh(unsigned long refdata
)
337 struct emu10k1_mpuin
*card_mpuin
= (struct emu10k1_mpuin
*) refdata
;
340 while (card_mpuin
->qhead
!= card_mpuin
->qtail
) {
341 spin_lock_irqsave(&card_mpuin
->lock
, flags
);
342 idx
= card_mpuin
->qhead
;
343 data
= card_mpuin
->midiq
[idx
].data
;
344 card_mpuin
->timein
= card_mpuin
->midiq
[idx
].timein
;
345 idx
= (idx
+ 1) % MIDIIN_MAX_BUFFER_SIZE
;
346 card_mpuin
->qhead
= idx
;
347 spin_unlock_irqrestore(&card_mpuin
->lock
, flags
);
349 sblive_miStateEntry(card_mpuin
, data
);
355 /* IRQ callback handler routine for the MPU in port */
357 int emu10k1_mpuin_irqhandler(struct emu10k1_card
*card
)
362 struct emu10k1_mpuin
*card_mpuin
= card
->mpuin
;
364 /* IRQ service routine. The data and code touched are:
369 idx
= card_mpuin
->qtail
;
372 if (emu10k1_mpu_read_data(card
, &MPUIvalue
) < 0) {
376 card_mpuin
->midiq
[idx
].data
= MPUIvalue
;
377 card_mpuin
->midiq
[idx
].timein
= (jiffies
* 1000) / HZ
;
378 idx
= (idx
+ 1) % MIDIIN_MAX_BUFFER_SIZE
;
383 card_mpuin
->qtail
= idx
;
385 tasklet_hi_schedule(&card_mpuin
->tasklet
);
391 /*****************************************************************************/
393 /* Supporting functions for Midi-In Interpretation State Machine */
395 /*****************************************************************************/
397 /* FIXME: This should be a macro */
398 static int sblive_miStateInit(struct emu10k1_mpuin
*card_mpuin
)
400 card_mpuin
->status
= 0; /* For MIDI running status */
401 card_mpuin
->fstatus
= 0; /* For 0xFn status only */
402 card_mpuin
->curstate
= STIN_PARSE
;
403 card_mpuin
->laststate
= STIN_PARSE
;
404 card_mpuin
->data
= 0;
405 card_mpuin
->timestart
= 0;
406 card_mpuin
->timein
= 0;
411 /* FIXME: This should be a macro */
412 static int sblive_miStateEntry(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
414 return midistatefn
[card_mpuin
->curstate
].Fn(card_mpuin
, data
);
417 static int sblive_miStateParse(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
419 switch (data
& 0xf0) {
425 card_mpuin
->curstate
= STIN_3BYTE
;
430 card_mpuin
->curstate
= STIN_2BYTE
;
434 /* System messages do not affect the previous running status! */
435 switch (data
& 0x0f) {
437 card_mpuin
->laststate
= card_mpuin
->curstate
;
438 card_mpuin
->curstate
= STIN_SYS_EX_NORM
;
440 if (card_mpuin
->firstmidiq
) {
441 struct midi_queue
*midiq
;
443 midiq
= card_mpuin
->firstmidiq
;
444 *midiq
->midibyte
= data
;
449 return CTSTATUS_NEXT_BYTE
;
452 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATAERROR
, 0xf7, 0);
456 card_mpuin
->laststate
= card_mpuin
->curstate
;
457 card_mpuin
->curstate
= STIN_SYS_COMMON_3
;
462 card_mpuin
->laststate
= card_mpuin
->curstate
;
463 card_mpuin
->curstate
= STIN_SYS_COMMON_2
;
467 /* includes 0xF4 - 0xF6, 0xF8 - 0xFF */
468 return midistatefn
[STIN_SYS_REAL
].Fn(card_mpuin
, data
);
474 DPF(2, "BUG: default case hit\n");
478 return midistatefn
[card_mpuin
->curstate
].Fn(card_mpuin
, data
);
481 static int sblive_miState3Byte(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
483 u8 temp
= data
& 0xf0;
486 return midistatefn
[STIN_3BYTE_KEY
].Fn(card_mpuin
, data
);
487 } else if (temp
<= 0xe0 && temp
!= 0xc0 && temp
!= 0xd0) {
488 card_mpuin
->status
= data
;
489 card_mpuin
->curstate
= STIN_3BYTE_KEY
;
491 return CTSTATUS_NEXT_BYTE
;
494 return midistatefn
[STIN_PARSE
].Fn(card_mpuin
, data
);
497 static int sblive_miState3ByteKey(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
503 /* Real-time messages check */
505 return midistatefn
[STIN_SYS_REAL
].Fn(card_mpuin
, data
);
508 DPF(2, "Invalid data!\n");
510 card_mpuin
->curstate
= STIN_PARSE
;
511 tmp
= ((unsigned long) data
) << 8;
512 tmp
|= (unsigned long) card_mpuin
->status
;
514 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATAERROR
, tmp
, 0);
519 card_mpuin
->data
= data
;
520 card_mpuin
->curstate
= STIN_3BYTE_VEL
;
522 return CTSTATUS_NEXT_BYTE
;
525 static int sblive_miState3ByteVel(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
531 /* Real-time messages check */
533 return midistatefn
[STIN_SYS_REAL
].Fn(card_mpuin
, data
);
536 DPF(2, "Invalid data!\n");
538 card_mpuin
->curstate
= STIN_PARSE
;
539 tmp
= ((unsigned long) data
) << 8;
540 tmp
|= card_mpuin
->data
;
542 tmp
|= (unsigned long) card_mpuin
->status
;
544 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATAERROR
, tmp
, 0);
549 card_mpuin
->curstate
= STIN_3BYTE
;
550 tmp
= (unsigned long) data
;
552 tmp
|= (unsigned long) card_mpuin
->data
;
554 tmp
|= (unsigned long) card_mpuin
->status
;
556 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATA
, tmp
, 3);
561 static int sblive_miState2Byte(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
563 u8 temp
= data
& 0xf0;
565 if ((temp
== 0xc0) || (temp
== 0xd0)) {
566 card_mpuin
->status
= data
;
567 card_mpuin
->curstate
= STIN_2BYTE_KEY
;
569 return CTSTATUS_NEXT_BYTE
;
573 return midistatefn
[STIN_2BYTE_KEY
].Fn(card_mpuin
, data
);
575 return midistatefn
[STIN_PARSE
].Fn(card_mpuin
, data
);
578 static int sblive_miState2ByteKey(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
584 /* Real-time messages check */
586 return midistatefn
[STIN_SYS_REAL
].Fn(card_mpuin
, data
);
589 DPF(2, "Invalid data!\n");
591 card_mpuin
->curstate
= STIN_PARSE
;
592 tmp
= (unsigned long) data
;
594 tmp
|= (unsigned long) card_mpuin
->status
;
596 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATAERROR
, tmp
, 0);
601 card_mpuin
->curstate
= STIN_2BYTE
;
602 tmp
= (unsigned long) data
;
604 tmp
|= (unsigned long) card_mpuin
->status
;
606 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATA
, tmp
, 2);
611 static int sblive_miStateSysCommon2(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
613 card_mpuin
->fstatus
= data
;
614 card_mpuin
->curstate
= STIN_SYS_COMMON_2_KEY
;
616 return CTSTATUS_NEXT_BYTE
;
619 static int sblive_miStateSysCommon2Key(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
625 /* Real-time messages check */
627 return midistatefn
[STIN_SYS_REAL
].Fn(card_mpuin
, data
);
630 DPF(2, "Invalid data!\n");
632 card_mpuin
->curstate
= card_mpuin
->laststate
;
633 tmp
= (unsigned long) data
;
635 tmp
|= (unsigned long) card_mpuin
->fstatus
;
637 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATAERROR
, tmp
, 0);
642 card_mpuin
->curstate
= card_mpuin
->laststate
;
643 tmp
= (unsigned long) data
;
645 tmp
|= (unsigned long) card_mpuin
->fstatus
;
647 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATA
, tmp
, 2);
652 static int sblive_miStateSysCommon3(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
654 card_mpuin
->fstatus
= data
;
655 card_mpuin
->curstate
= STIN_SYS_COMMON_3_KEY
;
657 return CTSTATUS_NEXT_BYTE
;
660 static int sblive_miStateSysCommon3Key(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
666 /* Real-time messages check */
668 return midistatefn
[STIN_SYS_REAL
].Fn(card_mpuin
, data
);
671 DPF(2, "Invalid data!\n");
673 card_mpuin
->curstate
= card_mpuin
->laststate
;
674 tmp
= (unsigned long) data
;
676 tmp
|= (unsigned long) card_mpuin
->fstatus
;
678 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATAERROR
, tmp
, 0);
683 card_mpuin
->data
= data
;
684 card_mpuin
->curstate
= STIN_SYS_COMMON_3_VEL
;
686 return CTSTATUS_NEXT_BYTE
;
689 static int sblive_miStateSysCommon3Vel(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
695 /* Real-time messages check */
697 return midistatefn
[STIN_SYS_REAL
].Fn(card_mpuin
, data
);
700 DPF(2, "Invalid data!\n");
702 card_mpuin
->curstate
= card_mpuin
->laststate
;
703 tmp
= (unsigned long) data
;
705 tmp
|= (unsigned long) card_mpuin
->data
;
707 tmp
|= (unsigned long) card_mpuin
->fstatus
;
709 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATAERROR
, tmp
, 0);
714 card_mpuin
->curstate
= card_mpuin
->laststate
;
715 tmp
= (unsigned long) data
;
717 tmp
|= (unsigned long) card_mpuin
->data
;
719 tmp
|= (unsigned long) card_mpuin
->fstatus
;
721 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATA
, tmp
, 3);
726 static int sblive_miStateSysExNorm(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
730 if ((data
> 0x7f) && (data
!= 0xf7)) {
731 /* Real-time messages check */
733 return midistatefn
[STIN_SYS_REAL
].Fn(card_mpuin
, data
);
736 DPF(2, "Invalid data!\n");
738 card_mpuin
->curstate
= card_mpuin
->laststate
;
740 if (card_mpuin
->firstmidiq
) {
741 struct midi_queue
*midiq
;
743 midiq
= card_mpuin
->firstmidiq
;
744 *midiq
->midibyte
= data
;
748 spin_lock_irqsave(&card_mpuin
->lock
, flags
);
750 card_mpuin
->firstmidiq
= midiq
->next
;
751 if (card_mpuin
->firstmidiq
== NULL
)
752 card_mpuin
->lastmidiq
= NULL
;
754 spin_unlock_irqrestore(&card_mpuin
->lock
, flags
);
756 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INLONGERROR
, (unsigned long) midiq
, 0);
764 if (card_mpuin
->firstmidiq
) {
765 struct midi_queue
*midiq
;
767 midiq
= card_mpuin
->firstmidiq
;
768 *midiq
->midibyte
= data
;
774 /* End of Sysex buffer */
775 /* Send down the buffer */
777 card_mpuin
->curstate
= card_mpuin
->laststate
;
779 if (card_mpuin
->firstmidiq
) {
780 struct midi_queue
*midiq
;
782 midiq
= card_mpuin
->firstmidiq
;
784 spin_lock_irqsave(&card_mpuin
->lock
, flags
);
786 card_mpuin
->firstmidiq
= midiq
->next
;
787 if (card_mpuin
->firstmidiq
== NULL
)
788 card_mpuin
->lastmidiq
= NULL
;
790 spin_unlock_irqrestore(&card_mpuin
->lock
, flags
);
792 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INLONGDATA
, (unsigned long) midiq
, 0);
800 if (card_mpuin
->firstmidiq
) {
801 struct midi_queue
*midiq
;
803 midiq
= card_mpuin
->firstmidiq
;
805 if (midiq
->sizeLeft
== 0) {
808 spin_lock_irqsave(&card_mpuin
->lock
, flags
);
810 card_mpuin
->firstmidiq
= midiq
->next
;
811 if (card_mpuin
->firstmidiq
== NULL
)
812 card_mpuin
->lastmidiq
= NULL
;
814 spin_unlock_irqrestore(&card_mpuin
->lock
, flags
);
816 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INLONGDATA
, (unsigned long) midiq
, 0);
820 return CTSTATUS_NEXT_BYTE
;
824 return CTSTATUS_NEXT_BYTE
;
827 static int sblive_miStateSysReal(struct emu10k1_mpuin
*card_mpuin
, u8 data
)
829 emu10k1_mpuin_callback(card_mpuin
, ICARDMIDI_INDATA
, data
, 1);
831 return CTSTATUS_NEXT_BYTE
;