Ignore:
Timestamp:
Mar 18, 2021, 8:57:36 PM (5 years ago)
Author:
David Azarewicz
Message:

Merge changes from Paul's uniaud32next branch.

Location:
GPL/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/alsa-kernel/drivers/mpu401/mpu401.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Driver for generic MPU-401 boards (UART mode only)
    34 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
    45 *  Copyright (c) 2004 by Castet Matthieu <castet.matthieu@free.fr>
    5  *
    6  *
    7  *   This program is free software; you can redistribute it and/or modify
    8  *   it under the terms of the GNU General Public License as published by
    9  *   the Free Software Foundation; either version 2 of the License, or
    10  *   (at your option) any later version.
    11  *
    12  *   This program is distributed in the hope that it will be useful,
    13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  *   GNU General Public License for more details.
    16  *
    17  *   You should have received a copy of the GNU General Public License
    18  *   along with this program; if not, write to the Free Software
    19  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    20  *
    216 */
    227
    23 #ifdef TARGET_OS2
    24 #include <sound/config.h>
    25 #endif
    268#include <linux/init.h>
    279#include <linux/pnp.h>
    2810#include <linux/err.h>
    2911#include <linux/platform_device.h>
    30 #include <linux/moduleparam.h>
     12#include <linux/module.h>
    3113#include <sound/core.h>
    3214#include <sound/mpu401.h>
     
    4325#endif
    4426static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    45 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;  /* Enable this card */
     27static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
    4628#ifdef CONFIG_PNP
    4729#ifndef TARGET_OS2
    48 static int pnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
     30static bool pnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
    4931#else
    5032static int pnp[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
     
    5436static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;        /* MPU-401 IRQ */
    5537#ifndef TARGET_OS2
    56 static int uart_enter[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
     38static bool uart_enter[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
    5739#else
    5840static int uart_enter[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
     
    6951MODULE_PARM_DESC(pnp, "PnP detection for MPU-401 device.");
    7052#endif
    71 module_param_array(port, long, NULL, 0444);
     53module_param_hw_array(port, long, ioport, NULL, 0444);
    7254MODULE_PARM_DESC(port, "Port # for MPU-401 device.");
    73 module_param_array(irq, int, NULL, 0444);
     55module_param_hw_array(irq, int, irq, NULL, 0444);
    7456MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device.");
    7557module_param_array(uart_enter, bool, NULL, 0444);
     
    8062static unsigned int snd_mpu401_devices;
    8163
    82 static int snd_mpu401_create(int dev, struct snd_card **rcard)
     64static int snd_mpu401_create(struct device *devptr, int dev,
     65                             struct snd_card **rcard)
    8366{
    8467        struct snd_card *card;
     
    8972
    9073        *rcard = NULL;
    91         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     74        err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
     75                           0, &card);
    9276        if (err < 0)
    9377                return err;
     
    10286
    10387        err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port[dev], 0,
    104                                   irq[dev], irq[dev] >= 0 ? IRQF_DISABLED : 0,
    105                                   NULL);
     88                                  irq[dev], NULL);
    10689        if (err < 0) {
    10790                printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
     
    117100}
    118101
    119 static int __devinit snd_mpu401_probe(struct platform_device *devptr)
     102static int snd_mpu401_probe(struct platform_device *devptr)
    120103{
    121104        int dev = devptr->id;
     
    131114                return -EINVAL;
    132115        }
    133         err = snd_mpu401_create(dev, &card);
     116        err = snd_mpu401_create(&devptr->dev, dev, &card);
    134117        if (err < 0)
    135118                return err;
    136         snd_card_set_dev(card, &devptr->dev);
    137119        if ((err = snd_card_register(card)) < 0) {
    138120                snd_card_free(card);
     
    143125}
    144126
    145 static int __devexit snd_mpu401_remove(struct platform_device *devptr)
     127static int snd_mpu401_remove(struct platform_device *devptr)
    146128{
    147129        snd_card_free(platform_get_drvdata(devptr));
    148         platform_set_drvdata(devptr, NULL);
    149130        return 0;
    150131}
     
    154135static struct platform_driver snd_mpu401_driver = {
    155136        .probe          = snd_mpu401_probe,
    156         .remove         = __devexit_p(snd_mpu401_remove),
     137        .remove         = snd_mpu401_remove,
    157138        .driver         = {
    158                 .name   = SND_MPU401_DRIVER
     139                .name   = SND_MPU401_DRIVER,
    159140        },
    160141};
     
    165146#define IO_EXTENT 2
    166147
    167 static struct pnp_device_id snd_mpu401_pnpids[] = {
     148static const struct pnp_device_id snd_mpu401_pnpids[] = {
    168149        { .id = "PNPb006" },
    169150        { .id = "" }
     
    172153MODULE_DEVICE_TABLE(pnp, snd_mpu401_pnpids);
    173154
    174 static int __devinit snd_mpu401_pnp(int dev, struct pnp_dev *device,
    175                                 const struct pnp_device_id *id)
     155static int snd_mpu401_pnp(int dev, struct pnp_dev *device,
     156                          const struct pnp_device_id *id)
    176157{
    177158        if (!pnp_port_valid(device, 0) ||
     
    198179}
    199180
    200 static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
    201                                           const struct pnp_device_id *id)
     181static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
     182                                const struct pnp_device_id *id)
    202183{
    203184        static int dev;
     
    211192                if (err < 0)
    212193                        return err;
    213                 err = snd_mpu401_create(dev, &card);
     194                err = snd_mpu401_create(&pnp_dev->dev, dev, &card);
    214195                if (err < 0)
    215196                        return err;
     
    218199                        return err;
    219200                }
    220                 snd_card_set_dev(card, &pnp_dev->dev);
    221201                pnp_set_drvdata(pnp_dev, card);
    222202                snd_mpu401_devices++;
     
    227207}
    228208
    229 static void __devexit snd_mpu401_pnp_remove(struct pnp_dev *dev)
     209static void snd_mpu401_pnp_remove(struct pnp_dev *dev)
    230210{
    231211        struct snd_card *card = (struct snd_card *) pnp_get_drvdata(dev);
     
    239219        .id_table = snd_mpu401_pnpids,
    240220        .probe = snd_mpu401_pnp_probe,
    241         .remove = __devexit_p(snd_mpu401_pnp_remove),
     221        .remove = snd_mpu401_pnp_remove,
    242222};
    243223#else
  • GPL/trunk/alsa-kernel/drivers/mpu401/mpu401_uart.c

    r399 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    45 *
    56 *  MPU-401 supports UART mode which is not capable generate transmit
    6  *  interrupts thus output is done via polling. Also, if irq < 0, then
     7 *  interrupts thus output is done via polling. Without interrupt,
    78 *  input is done also via polling. Do not expect good performance.
    8  *
    9  *
    10  *   This program is free software; you can redistribute it and/or modify
    11  *   it under the terms of the GNU General Public License as published by
    12  *   the Free Software Foundation; either version 2 of the License, or
    13  *   (at your option) any later version.
    14  *
    15  *   This program is distributed in the hope that it will be useful,
    16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  *   GNU General Public License for more details.
    19  *
    20  *   You should have received a copy of the GNU General Public License
    21  *   along with this program; if not, write to the Free Software
    22  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    239 *
    2410 *   13-03-2003:
     
    2612 *      are port and mmio. For other kind of I/O, set mpu->read and
    2713 *      mpu->write to your own I/O functions.
    28  *
    29  */
    30 
    31 #include <asm/io.h>
     14 */
     15
     16#include <linux/io.h>
    3217#include <linux/delay.h>
    3318#include <linux/init.h>
    3419#include <linux/slab.h>
    3520#include <linux/ioport.h>
     21#include <linux/module.h>
    3622#include <linux/interrupt.h>
    3723#include <linux/errno.h>
     
    129115 *
    130116 * Processes the interrupt for MPU401-UART i/o.
     117 *
     118 * Return: %IRQ_HANDLED if the interrupt was handled. %IRQ_NONE otherwise.
    131119 */
    132120irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id)
     
    134122        struct snd_mpu401 *mpu = dev_id;
    135123       
    136         if (mpu == NULL)
     124        if (!mpu)
    137125                return IRQ_NONE;
    138126        _snd_mpu401_uart_interrupt(mpu);
     
    148136 *
    149137 * Processes the interrupt for MPU401-UART output.
     138 *
     139 * Return: %IRQ_HANDLED if the interrupt was handled. %IRQ_NONE otherwise.
    150140 */
    151141irqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id)
     
    153143        struct snd_mpu401 *mpu = dev_id;
    154144       
    155         if (mpu == NULL)
     145        if (!mpu)
    156146                return IRQ_NONE;
    157147        uart_interrupt_tx(mpu);
     
    161151EXPORT_SYMBOL(snd_mpu401_uart_interrupt_tx);
    162152
     153#define from_timer(var, callback_timer, timer_fieldname) \
     154        container_of(callback_timer, struct snd_mpu401, timer_fieldname)
     155
    163156/*
    164157 * timer callback
    165158 * reprogram the timer and call the interrupt job
    166159 */
    167 static void snd_mpu401_uart_timer(unsigned long data)
    168 {
    169         struct snd_mpu401 *mpu = (struct snd_mpu401 *)data;
     160static void snd_mpu401_uart_timer(struct timer_list *t)
     161{
     162        struct snd_mpu401 *mpu = from_timer(mpu, t, timer);
    170163        unsigned long flags;
    171164
    172165        spin_lock_irqsave(&mpu->timer_lock, flags);
    173166        /*mpu->mode |= MPU401_MODE_TIMER;*/
    174         mpu->timer.expires = 1 + jiffies;
    175         add_timer(&mpu->timer);
     167        mod_timer(&mpu->timer,  1 + jiffies);
    176168        spin_unlock_irqrestore(&mpu->timer_lock, flags);
    177169        if (mpu->rmidi)
     
    188180        spin_lock_irqsave (&mpu->timer_lock, flags);
    189181        if (mpu->timer_invoked == 0) {
     182#ifndef TARGET_OS2
     183                timer_setup(&mpu->timer, snd_mpu401_uart_timer, 0);
     184                mod_timer(&mpu->timer, 1 + jiffies);
     185#else
    190186                init_timer(&mpu->timer);
    191187                mpu->timer.data = (unsigned long)mpu;
    192                 mpu->timer.function = snd_mpu401_uart_timer;
     188                mpu->timer.function = (void(*)(unsigned long))snd_mpu401_uart_timer;
    193189                mpu->timer.expires = 1 + jiffies;
    194190                add_timer(&mpu->timer);
    195         }
     191#endif
     192        }
    196193        mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER :
    197194                MPU401_MODE_OUTPUT_TIMER;
     
    375372                        while (max-- > 0)
    376373                                mpu->read(mpu, MPU401D(mpu));
    377                         if (mpu->irq < 0)
     374                        if (mpu->info_flags & MPU401_INFO_USE_TIMER)
    378375                                snd_mpu401_uart_add_timer(mpu, 1);
    379376                }
     
    384381                spin_unlock_irqrestore(&mpu->input_lock, flags);
    385382        } else {
    386                 if (mpu->irq < 0)
     383                if (mpu->info_flags & MPU401_INFO_USE_TIMER)
    387384                        snd_mpu401_uart_remove_timer(mpu, 1);
    388385                clear_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode);
     
    480477 */
    481478
    482 static struct snd_rawmidi_ops snd_mpu401_uart_output =
     479static const struct snd_rawmidi_ops snd_mpu401_uart_output =
    483480{
    484481        .open =         snd_mpu401_uart_output_open,
     
    487484};
    488485
    489 static struct snd_rawmidi_ops snd_mpu401_uart_input =
     486static const struct snd_rawmidi_ops snd_mpu401_uart_input =
    490487{
    491488        .open =         snd_mpu401_uart_input_open,
     
    497494{
    498495        struct snd_mpu401 *mpu = rmidi->private_data;
    499         if (mpu->irq_flags && mpu->irq >= 0)
     496        if (mpu->irq >= 0)
    500497                free_irq(mpu->irq, (void *) mpu);
    501498        release_and_free_resource(mpu->res);
     
    510507 * @port: the base address of MPU401 port
    511508 * @info_flags: bitflags MPU401_INFO_XXX
    512  * @irq: the irq number, -1 if no interrupt for mpu
    513  * @irq_flags: the irq request flags (SA_XXX), 0 if irq was already reserved.
     509 * @irq: the ISA irq number, -1 if not to be allocated
    514510 * @rrawmidi: the pointer to store the new rawmidi instance
    515511 *
     
    520516 * cast from rawmidi->private_data (with struct snd_mpu401 magic-cast).
    521517 *
    522  * Returns zero if successful, or a negative error code.
     518 * Return: Zero if successful, or a negative error code.
    523519 */
    524520int snd_mpu401_uart_new(struct snd_card *card, int device,
     
    526522                        unsigned long port,
    527523                        unsigned int info_flags,
    528                         int irq, int irq_flags,
     524                        int irq,
    529525                        struct snd_rawmidi ** rrawmidi)
    530526{
     
    544540                return err;
    545541        mpu = kzalloc(sizeof(*mpu), GFP_KERNEL);
    546         if (mpu == NULL) {
    547                 snd_printk(KERN_ERR "mpu401_uart: cannot allocate\n");
    548                 snd_device_free(card, rmidi);
    549                 return -ENOMEM;
     542        if (!mpu) {
     543                err = -ENOMEM;
     544                goto free_device;
    550545        }
    551546        rmidi->private_data = mpu;
     
    555550        spin_lock_init(&mpu->timer_lock);
    556551        mpu->hardware = hardware;
     552        mpu->irq = -1;
    557553        if (! (info_flags & MPU401_INFO_INTEGRATED)) {
    558554                int res_size = hardware == MPU401_HW_PC98II ? 4 : 2;
    559555                mpu->res = request_region(port, res_size, "MPU401 UART");
    560                 if (mpu->res == NULL) {
     556                if (!mpu->res) {
    561557                        snd_printk(KERN_ERR "mpu401_uart: "
    562558                                   "unable to grab port 0x%lx size %d\n",
    563559                                   port, res_size);
    564                         snd_device_free(card, rmidi);
    565                         return -EBUSY;
     560                        err = -EBUSY;
     561                        goto free_device;
    566562                }
    567563        }
     
    578574        else
    579575                mpu->cport = port + 1;
    580         if (irq >= 0 && irq_flags) {
    581                 if (request_irq(irq, snd_mpu401_uart_interrupt, irq_flags,
     576        if (irq >= 0) {
     577                if (request_irq(irq, snd_mpu401_uart_interrupt, 0,
    582578                                "MPU401 UART", (void *) mpu)) {
    583579                        snd_printk(KERN_ERR "mpu401_uart: "
    584580                                   "unable to grab IRQ %d\n", irq);
    585                         snd_device_free(card, rmidi);
    586                         return -EBUSY;
     581                        err = -EBUSY;
     582                        goto free_device;
    587583                }
    588584        }
     585        if (irq < 0 && !(info_flags & MPU401_INFO_IRQ_HOOK))
     586                info_flags |= MPU401_INFO_USE_TIMER;
    589587        mpu->info_flags = info_flags;
    590588        mpu->irq = irq;
    591         mpu->irq_flags = irq_flags;
    592589        if (card->shortname[0])
    593590                snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI",
     
    611608                *rrawmidi = rmidi;
    612609        return 0;
     610free_device:
     611        snd_device_free(card, rmidi);
     612        return err;
    613613}
    614614
    615615EXPORT_SYMBOL(snd_mpu401_uart_new);
    616 
    617 /*
    618  *  INIT part
    619  */
    620 
    621 static int __init alsa_mpu401_uart_init(void)
    622 {
    623         return 0;
    624 }
    625 
    626 static void __exit alsa_mpu401_uart_exit(void)
    627 {
    628 }
    629 
    630 module_init(alsa_mpu401_uart_init)
    631 module_exit(alsa_mpu401_uart_exit)
Note: See TracChangeset for help on using the changeset viewer.