Ignore:
Timestamp:
Jul 23, 2006, 11:54:27 AM (19 years ago)
Author:
vladest
Message:

Provide sources to latest exist binary. See changelog for changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk/alsa-kernel/drivers/mpu401/mpu401_uart.c

    r34 r77  
    9191}
    9292
     93static void uart_interrupt_tx(struct snd_mpu401 *mpu)
     94{
     95    if (test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode) &&
     96        test_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode)) {
     97        spin_lock(&mpu->output_lock);
     98        snd_mpu401_uart_output_write(mpu);
     99        spin_unlock(&mpu->output_lock);
     100    }
     101}
     102
    93103static void _snd_mpu401_uart_interrupt(struct snd_mpu401 *mpu)
    94104{
    95         spin_lock(&mpu->input_lock);
    96         if (test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode)) {
    97                 snd_mpu401_uart_input_read(mpu);
    98         } else {
    99                 snd_mpu401_uart_clear_rx(mpu);
    100         }
    101         spin_unlock(&mpu->input_lock);
    102         /* ok. for better Tx performance try do some output when input is done */
    103         if (test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode) &&
    104             test_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode)) {
    105                 spin_lock(&mpu->output_lock);
    106                 snd_mpu401_uart_output_write(mpu);
    107                 spin_unlock(&mpu->output_lock);
    108         }
     105    if (mpu->info_flags & MPU401_INFO_INPUT) {
     106        spin_lock(&mpu->input_lock);
     107        if (test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode))
     108            snd_mpu401_uart_input_read(mpu);
     109        else
     110            snd_mpu401_uart_clear_rx(mpu);
     111        spin_unlock(&mpu->input_lock);
     112    }
     113    if (! (mpu->info_flags & MPU401_INFO_TX_IRQ))
     114        /* ok. for better Tx performance try do some output
     115         when input is done */
     116        uart_interrupt_tx(mpu);
    109117}
    110118
     
    126134        return IRQ_HANDLED;
    127135}
     136
     137/**
     138 * snd_mpu401_uart_interrupt_tx - generic MPU401-UART transmit irq handler
     139 * @irq: the irq number
     140 * @dev_id: mpu401 instance
     141 * @regs: the reigster
     142 *
     143 * Processes the interrupt for MPU401-UART output.
     144 */
     145irqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id,
     146                                         struct pt_regs *regs)
     147{
     148    struct snd_mpu401 *mpu = dev_id;
     149
     150    if (mpu == NULL)
     151        return IRQ_NONE;
     152    uart_interrupt_tx(mpu);
     153    return IRQ_HANDLED;
     154}
     155
     156EXPORT_SYMBOL(snd_mpu401_uart_interrupt_tx);
    128157
    129158/*
     
    327356        unsigned char byte;
    328357
    329         while (max-- > 0) {
    330                 if (snd_mpu401_input_avail(mpu)) {
    331                         byte = mpu->read(mpu, MPU401D(mpu));
    332                         if (test_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode))
    333                                 snd_rawmidi_receive(mpu->substream_input, &byte, 1);
    334                 } else {
    335                         break; /* input not available */
    336                 }
     358        while (max-- > 0) {
     359            if (! snd_mpu401_input_avail(mpu))
     360                break; /* input not available */
     361            byte = mpu->read(mpu, MPU401D(mpu));
     362            if (test_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode))
     363                snd_rawmidi_receive(mpu->substream_input, &byte, 1);
    337364        }
    338365}
     
    355382        int max = 256, timeout;
    356383
    357         do {
    358                 if (snd_rawmidi_transmit_peek(mpu->substream_output, &byte, 1) == 1) {
    359                         for (timeout = 100; timeout > 0; timeout--) {
    360                                 if (snd_mpu401_output_ready(mpu)) {
    361                                         mpu->write(mpu, byte, MPU401D(mpu));
    362                                         snd_rawmidi_transmit_ack(mpu->substream_output, 1);
    363                                         break;
    364                                 }
    365                         }
    366                         if (timeout == 0)
    367                                 break;  /* Tx FIFO full - try again later */
    368                 } else {
    369                         snd_mpu401_uart_remove_timer (mpu, 0);
    370                         break;  /* no other data - leave the tx loop */
    371                 }
     384        do {
     385            if (snd_rawmidi_transmit_peek(mpu->substream_output,
     386                                          &byte, 1) == 1) {
     387                for (timeout = 100; timeout > 0; timeout--) {
     388                    if (snd_mpu401_output_ready(mpu))
     389                        break;
     390                }
     391                if (timeout == 0)
     392                    break;      /* Tx FIFO full - try again later */
     393                mpu->write(mpu, byte, MPU401D(mpu));
     394                snd_rawmidi_transmit_ack(mpu->substream_output, 1);
     395            } else {
     396                snd_mpu401_uart_remove_timer (mpu, 0);
     397                break;  /* no other data - leave the tx loop */
     398            }
    372399        } while (--max > 0);
    373400}
     
    388415                 * since the output timer might have been removed in
    389416                 * snd_mpu401_uart_output_write().
    390                 */
    391                 snd_mpu401_uart_add_timer(mpu, 0);
    392 
     417                */
     418                if (! (mpu->info_flags & MPU401_INFO_TX_IRQ))
     419                    snd_mpu401_uart_add_timer(mpu, 0);
    393420                /* output pending data */
    394421                spin_lock_irqsave(&mpu->output_lock, flags);
    395422                snd_mpu401_uart_output_write(mpu);
    396423                spin_unlock_irqrestore(&mpu->output_lock, flags);
    397         } else {
    398                 snd_mpu401_uart_remove_timer(mpu, 0);
    399                 clear_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode);
     424        } else {
     425            if (! (mpu->info_flags & MPU401_INFO_TX_IRQ))
     426                snd_mpu401_uart_remove_timer(mpu, 0);
     427            clear_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode);
    400428        }
    401429}
     
    437465 * @hardware: the hardware type, MPU401_HW_XXXX
    438466 * @port: the base address of MPU401 port
    439  * @integrated: non-zero if the port was already reserved by the chip
     467 * @info_flags: bitflags MPU401_INFO_XXX
    440468 * @irq: the irq number, -1 if no interrupt for mpu
    441469 * @irq_flags: the irq request flags (SA_XXX), 0 if irq was already reserved.
     
    451479 */
    452480int snd_mpu401_uart_new(struct snd_card *card, int device,
    453                         unsigned short hardware,
    454                         unsigned long port, int integrated,
     481                        unsigned short hardware,
     482                        unsigned long port,
     483                        unsigned int info_flags,
    455484                        int irq, int irq_flags,
    456485                        struct snd_rawmidi ** rrawmidi)
    457486{
    458487        struct snd_mpu401 *mpu;
    459         struct snd_rawmidi *rmidi;
     488        struct snd_rawmidi *rmidi;
     489        int in_enable, out_enable;
    460490        int err;
    461491
    462492        if (rrawmidi)
    463                 *rrawmidi = NULL;
    464         if ((err = snd_rawmidi_new(card, "MPU-401U", device, 1, 1, &rmidi)) < 0)
    465                 return err;
     493            *rrawmidi = NULL;
     494        if (! (info_flags & (MPU401_INFO_INPUT | MPU401_INFO_OUTPUT)))
     495                info_flags |= MPU401_INFO_INPUT | MPU401_INFO_OUTPUT;
     496        in_enable = (info_flags & MPU401_INFO_INPUT) ? 1 : 0;
     497        out_enable = (info_flags & MPU401_INFO_OUTPUT) ? 1 : 0;
     498        if ((err = snd_rawmidi_new(card, "MPU-401U", device,
     499                                   out_enable, in_enable, &rmidi)) < 0)
     500            return err;
    466501        mpu = (struct snd_mpu401 *)kzalloc(sizeof(*mpu), GFP_KERNEL);
    467502        if (mpu == NULL) {
     
    475510        spin_lock_init(&mpu->output_lock);
    476511        spin_lock_init(&mpu->timer_lock);
    477         mpu->hardware = hardware;
    478         if (!integrated) {
     512        mpu->hardware = hardware;
     513        if (! (info_flags & MPU401_INFO_INTEGRATED)) {
    479514                int res_size = hardware == MPU401_HW_PC98II ? 4 : 2;
    480515                if ((mpu->res = request_region(port, res_size, "MPU401 UART")) == NULL) {
     
    483518                        return -EBUSY;
    484519                }
    485         }
    486         switch (hardware) {
    487         case MPU401_HW_AUREAL:
     520        }
     521        if (info_flags & MPU401_INFO_MMIO) {
    488522                mpu->write = mpu401_write_mmio;
    489                 mpu->read = mpu401_read_mmio;
    490                 break;
    491         default:
     523                mpu->read = mpu401_read_mmio;
     524        } else {
    492525                mpu->write = mpu401_write_port;
    493526                mpu->read = mpu401_read_port;
    494                 break;
    495527        }
    496528        mpu->port = port;
     
    505537                        return -EBUSY;
    506538                }
    507         }
     539        }
     540        mpu->info_flags = info_flags;
    508541        mpu->irq = irq;
    509542        mpu->irq_flags = irq_flags;
     
    511544                sprintf(rmidi->name, "%s MIDI", card->shortname);
    512545        else
    513                 sprintf(rmidi->name, "MPU-401 MIDI %d-%d", card->number, device);
    514         snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_mpu401_uart_output);
    515         snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_mpu401_uart_input);
    516         rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
    517                              SNDRV_RAWMIDI_INFO_INPUT |
    518                              SNDRV_RAWMIDI_INFO_DUPLEX;
    519         mpu->rmidi = rmidi;
     546            sprintf(rmidi->name, "MPU-401 MIDI %d-%d", card->number, device);
     547        if (out_enable) {
     548            snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
     549                                &snd_mpu401_uart_output);
     550            rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
     551        }
     552        if (in_enable) {
     553            snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
     554                                &snd_mpu401_uart_input);
     555            rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
     556            if (out_enable)
     557                rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
     558        }
     559        mpu->rmidi = rmidi;
    520560        if (rrawmidi)
    521561                *rrawmidi = rmidi;
Note: See TracChangeset for help on using the changeset viewer.