Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | /* ********************************************************************** * cardmo.c - MIDI UART output HAL for emu10k1 driver * Copyright 1999, 2000 Creative Labs, Inc. * ********************************************************************** * * Date Author Summary of changes * ---- ------ ------------------ * October 20, 1999 Bertrand Lee base code release * November 2, 1999 Alan Cox cleaned up * ********************************************************************** * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, * USA. * ********************************************************************** */ #include "hwaccess.h" #include "cardmo.h" /* Installs the IRQ handler for the MPU out port * * and initialize parameters */ int emu10k1_mpuout_open(struct emu10k1_card *card, struct midi_openinfo *openinfo) { struct emu10k1_mpuout *card_mpuout = card->mpuout; DPF(2, "emu10k1_mpuout_open()\n"); if (!(card_mpuout->status & FLAGS_AVAILABLE)) return CTSTATUS_INUSE; /* Copy open info and mark channel as in use */ card_mpuout->intr = 0; card_mpuout->openinfo = *openinfo; card_mpuout->status &= ~FLAGS_AVAILABLE; card_mpuout->laststatus = 0x80; card_mpuout->firstmidiq = NULL; card_mpuout->lastmidiq = NULL; emu10k1_mpu_reset(card); emu10k1_mpu_acquire(card); return CTSTATUS_SUCCESS; } int emu10k1_mpuout_close(struct emu10k1_card *card) { struct emu10k1_mpuout *card_mpuout = card->mpuout; struct midi_queue *midiq; struct midi_hdr *midihdr; unsigned long flags; DPF(2, "emu10k1_mpuout_close()\n"); emu10k1_irq_disable(card, INTE_MIDITXENABLE); spin_lock_irqsave(&card_mpuout->lock, flags); while (card_mpuout->firstmidiq != NULL) { midiq = card_mpuout->firstmidiq; midihdr = (struct midi_hdr *) midiq->refdata; card_mpuout->firstmidiq = midiq->next; kfree(midihdr->data); kfree(midihdr); kfree(midiq); } card_mpuout->lastmidiq = NULL; emu10k1_mpu_release(card); card_mpuout->status |= FLAGS_AVAILABLE; spin_unlock_irqrestore(&card_mpuout->lock, flags); return CTSTATUS_SUCCESS; } /* If there isn't enough buffer space, reject Midi Buffer. * * Otherwise, disable TX, create object to hold Midi * * uffer, update buffer flags and other parameters * * before enabling TX again. */ int emu10k1_mpuout_add_buffer(struct emu10k1_card *card, struct midi_hdr *midihdr) { struct emu10k1_mpuout *card_mpuout = card->mpuout; struct midi_queue *midiq; unsigned long flags; DPF(2, "emu10k1_mpuout_add_buffer()\n"); if (card_mpuout->state == CARDMIDIOUT_STATE_SUSPEND) return CTSTATUS_SUCCESS; midihdr->flags |= MIDIBUF_INQUEUE; midihdr->flags &= ~MIDIBUF_DONE; if ((midiq = (struct midi_queue *) kmalloc(sizeof(struct midi_queue), GFP_KERNEL)) == NULL) { /* Message lost */ return CTSTATUS_NOMEMORY; } midiq->next = NULL; midiq->qtype = 1; midiq->length = midihdr->bufferlength; midiq->sizeLeft = midihdr->bufferlength; midiq->midibyte = midihdr->data; midiq->refdata = (unsigned long) midihdr; spin_lock_irqsave(&card_mpuout->lock, flags); if (card_mpuout->firstmidiq == NULL) { card_mpuout->firstmidiq = midiq; card_mpuout->lastmidiq = midiq; } else { (card_mpuout->lastmidiq)->next = midiq; card_mpuout->lastmidiq = midiq; } card_mpuout->intr = 0; emu10k1_irq_enable(card, INTE_MIDITXENABLE); spin_unlock_irqrestore(&card_mpuout->lock, flags); return CTSTATUS_SUCCESS; } void emu10k1_mpuout_bh(unsigned long refdata) { struct emu10k1_card *card = (struct emu10k1_card *) refdata; struct emu10k1_mpuout *card_mpuout = card->mpuout; int cByteSent = 0; int status; struct midi_queue *midiq; struct midi_queue *doneq = NULL; unsigned long flags; spin_lock_irqsave(&card_mpuout->lock, flags); while (card_mpuout->firstmidiq != NULL) { midiq = card_mpuout->firstmidiq; while (cByteSent < 4 && midiq->sizeLeft) { status = emu10k1_mpu_write_data(card, *midiq->midibyte); if (status == CTSTATUS_SUCCESS) { ++cByteSent; --midiq->sizeLeft; ++midiq->midibyte; } else { DPF(2, "emu10k1_mpuoutDpcCallback error!!\n"); } } if (midiq->sizeLeft == 0) { if (doneq == NULL) doneq = midiq; card_mpuout->firstmidiq = midiq->next; } else break; } if (card_mpuout->firstmidiq == NULL) card_mpuout->lastmidiq = NULL; if (doneq != NULL) { while (doneq != card_mpuout->firstmidiq) { unsigned long callback_msg[3]; midiq = doneq; doneq = midiq->next; if (midiq->qtype) { callback_msg[0] = 0; callback_msg[1] = midiq->length; callback_msg[2] = midiq->refdata; emu10k1_midi_callback(ICARDMIDI_OUTLONGDATA, card_mpuout->openinfo.refdata, callback_msg); } else if (((u8) midiq->refdata) < 0xF0 && ((u8) midiq->refdata) > 0x7F) card_mpuout->laststatus = (u8) midiq->refdata; kfree(midiq); } } if ((card_mpuout->firstmidiq != NULL) || cByteSent) { card_mpuout->intr = 0; emu10k1_irq_enable(card, INTE_MIDITXENABLE); } spin_unlock_irqrestore(&card_mpuout->lock, flags); return; } int emu10k1_mpuout_irqhandler(struct emu10k1_card *card) { struct emu10k1_mpuout *card_mpuout = card->mpuout; DPF(4, "emu10k1_mpuout_irqhandler\n"); card_mpuout->intr = 1; emu10k1_irq_disable(card, INTE_MIDITXENABLE); tasklet_hi_schedule(&card_mpuout->tasklet); return CTSTATUS_SUCCESS; } |