提交 077d0ac5 编写于 作者: T Takashi Iwai 提交者: Jaroslav Kysela

[ALSA] mtpav - Use platform_device

Modules: Generic drivers

Rewrite the probe/remove code using platform_device.
Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 6e65c1cc
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
#include <sound/driver.h> #include <sound/driver.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
...@@ -125,16 +127,16 @@ MODULE_PARM_DESC(hwports, "Hardware ports # for MotuMTPAV MIDI."); ...@@ -125,16 +127,16 @@ MODULE_PARM_DESC(hwports, "Hardware ports # for MotuMTPAV MIDI.");
/* /*
*/ */
typedef struct mtpav_port { struct mtpav_port {
u8 number; u8 number;
u8 hwport; u8 hwport;
u8 mode; u8 mode;
u8 running_status; u8 running_status;
struct snd_rawmidi_substream *input; struct snd_rawmidi_substream *input;
struct snd_rawmidi_substream *output; struct snd_rawmidi_substream *output;
} mtpav_port_t; };
typedef struct mtpav { struct mtpav {
struct snd_card *card; struct snd_card *card;
unsigned long port; unsigned long port;
struct resource *res_port; struct resource *res_port;
...@@ -145,21 +147,15 @@ typedef struct mtpav { ...@@ -145,21 +147,15 @@ typedef struct mtpav {
struct timer_list timer; /* timer interrupts for outputs */ struct timer_list timer; /* timer interrupts for outputs */
struct snd_rawmidi *rmidi; struct snd_rawmidi *rmidi;
int num_ports; /* number of hw ports (1-8) */ int num_ports; /* number of hw ports (1-8) */
mtpav_port_t ports[NUMPORTS]; /* all ports including computer, adat and bc */ struct mtpav_port ports[NUMPORTS]; /* all ports including computer, adat and bc */
u32 inmidiport; /* selected input midi port */ u32 inmidiport; /* selected input midi port */
u32 inmidistate; /* during midi command 0xf5 */ u32 inmidistate; /* during midi command 0xf5 */
u32 outmidihwport; /* selected output midi hw port */ u32 outmidihwport; /* selected output midi hw port */
} mtpav_t; };
/*
* global instance
* hey, we handle at most only one card..
*/
static mtpav_t *mtp_card;
/* /*
* possible hardware ports (selected by 0xf5 port message) * possible hardware ports (selected by 0xf5 port message)
* 0x00 all ports * 0x00 all ports
...@@ -183,7 +179,7 @@ static mtpav_t *mtp_card; ...@@ -183,7 +179,7 @@ static mtpav_t *mtp_card;
#define MTPAV_PIDX_BROADCAST 2 #define MTPAV_PIDX_BROADCAST 2
static int translate_subdevice_to_hwport(mtpav_t *chip, int subdev) static int translate_subdevice_to_hwport(struct mtpav *chip, int subdev)
{ {
if (subdev < 0) if (subdev < 0)
return 0x01; /* invalid - use port 0 as default */ return 0x01; /* invalid - use port 0 as default */
...@@ -198,7 +194,7 @@ static int translate_subdevice_to_hwport(mtpav_t *chip, int subdev) ...@@ -198,7 +194,7 @@ static int translate_subdevice_to_hwport(mtpav_t *chip, int subdev)
return 0; /* all ports */ return 0; /* all ports */
} }
static int translate_hwport_to_subdevice(mtpav_t *chip, int hwport) static int translate_hwport_to_subdevice(struct mtpav *chip, int hwport)
{ {
int p; int p;
if (hwport <= 0x00) /* all ports */ if (hwport <= 0x00) /* all ports */
...@@ -223,7 +219,7 @@ static int translate_hwport_to_subdevice(mtpav_t *chip, int hwport) ...@@ -223,7 +219,7 @@ static int translate_hwport_to_subdevice(mtpav_t *chip, int hwport)
/* /*
*/ */
static u8 snd_mtpav_getreg(mtpav_t *chip, u16 reg) static u8 snd_mtpav_getreg(struct mtpav *chip, u16 reg)
{ {
u8 rval = 0; u8 rval = 0;
...@@ -241,19 +237,16 @@ static u8 snd_mtpav_getreg(mtpav_t *chip, u16 reg) ...@@ -241,19 +237,16 @@ static u8 snd_mtpav_getreg(mtpav_t *chip, u16 reg)
/* /*
*/ */
static void snd_mtpav_mputreg(mtpav_t *chip, u16 reg, u8 val) static inline void snd_mtpav_mputreg(struct mtpav *chip, u16 reg, u8 val)
{ {
if (reg == DREG) { if (reg == DREG || reg == CREG)
outb(val, chip->port + DREG); outb(val, chip->port + reg);
} else if (reg == CREG) {
outb(val, chip->port + CREG);
}
} }
/* /*
*/ */
static void snd_mtpav_wait_rfdhi(mtpav_t *chip) static void snd_mtpav_wait_rfdhi(struct mtpav *chip)
{ {
int counts = 10000; int counts = 10000;
u8 sbyte; u8 sbyte;
...@@ -265,7 +258,7 @@ static void snd_mtpav_wait_rfdhi(mtpav_t *chip) ...@@ -265,7 +258,7 @@ static void snd_mtpav_wait_rfdhi(mtpav_t *chip)
} }
} }
static void snd_mtpav_send_byte(mtpav_t *chip, u8 byte) static void snd_mtpav_send_byte(struct mtpav *chip, u8 byte)
{ {
u8 tcbyt; u8 tcbyt;
u8 clrwrite; u8 clrwrite;
...@@ -291,7 +284,8 @@ static void snd_mtpav_send_byte(mtpav_t *chip, u8 byte) ...@@ -291,7 +284,8 @@ static void snd_mtpav_send_byte(mtpav_t *chip, u8 byte)
*/ */
/* call this with spin lock held */ /* call this with spin lock held */
static void snd_mtpav_output_port_write(mtpav_port_t *port, static void snd_mtpav_output_port_write(struct mtpav *mtp_card,
struct mtpav_port *portp,
struct snd_rawmidi_substream *substream) struct snd_rawmidi_substream *substream)
{ {
u8 outbyte; u8 outbyte;
...@@ -303,22 +297,22 @@ static void snd_mtpav_output_port_write(mtpav_port_t *port, ...@@ -303,22 +297,22 @@ static void snd_mtpav_output_port_write(mtpav_port_t *port,
// send port change command if necessary // send port change command if necessary
if (port->hwport != mtp_card->outmidihwport) { if (portp->hwport != mtp_card->outmidihwport) {
mtp_card->outmidihwport = port->hwport; mtp_card->outmidihwport = portp->hwport;
snd_mtpav_send_byte(mtp_card, 0xf5); snd_mtpav_send_byte(mtp_card, 0xf5);
snd_mtpav_send_byte(mtp_card, port->hwport); snd_mtpav_send_byte(mtp_card, portp->hwport);
//snd_printk("new outport: 0x%x\n", (unsigned int) port->hwport); //snd_printk("new outport: 0x%x\n", (unsigned int) portp->hwport);
if (!(outbyte & 0x80) && port->running_status) if (!(outbyte & 0x80) && portp->running_status)
snd_mtpav_send_byte(mtp_card, port->running_status); snd_mtpav_send_byte(mtp_card, portp->running_status);
} }
// send data // send data
do { do {
if (outbyte & 0x80) if (outbyte & 0x80)
port->running_status = outbyte; portp->running_status = outbyte;
snd_mtpav_send_byte(mtp_card, outbyte); snd_mtpav_send_byte(mtp_card, outbyte);
} while (snd_rawmidi_transmit(substream, &outbyte, 1) == 1); } while (snd_rawmidi_transmit(substream, &outbyte, 1) == 1);
...@@ -326,11 +320,12 @@ static void snd_mtpav_output_port_write(mtpav_port_t *port, ...@@ -326,11 +320,12 @@ static void snd_mtpav_output_port_write(mtpav_port_t *port,
static void snd_mtpav_output_write(struct snd_rawmidi_substream *substream) static void snd_mtpav_output_write(struct snd_rawmidi_substream *substream)
{ {
mtpav_port_t *port = &mtp_card->ports[substream->number]; struct mtpav *mtp_card = substream->rmidi->private_data;
struct mtpav_port *portp = &mtp_card->ports[substream->number];
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&mtp_card->spinlock, flags); spin_lock_irqsave(&mtp_card->spinlock, flags);
snd_mtpav_output_port_write(port, substream); snd_mtpav_output_port_write(mtp_card, portp, substream);
spin_unlock_irqrestore(&mtp_card->spinlock, flags); spin_unlock_irqrestore(&mtp_card->spinlock, flags);
} }
...@@ -339,7 +334,7 @@ static void snd_mtpav_output_write(struct snd_rawmidi_substream *substream) ...@@ -339,7 +334,7 @@ static void snd_mtpav_output_write(struct snd_rawmidi_substream *substream)
* mtpav control * mtpav control
*/ */
static void snd_mtpav_portscan(mtpav_t *chip) // put mtp into smart routing mode static void snd_mtpav_portscan(struct mtpav *chip) // put mtp into smart routing mode
{ {
u8 p; u8 p;
...@@ -355,10 +350,10 @@ static void snd_mtpav_portscan(mtpav_t *chip) // put mtp into smart routing mode ...@@ -355,10 +350,10 @@ static void snd_mtpav_portscan(mtpav_t *chip) // put mtp into smart routing mode
static int snd_mtpav_input_open(struct snd_rawmidi_substream *substream) static int snd_mtpav_input_open(struct snd_rawmidi_substream *substream)
{ {
struct mtpav *mtp_card = substream->rmidi->private_data;
struct mtpav_port *portp = &mtp_card->ports[substream->number];
unsigned long flags; unsigned long flags;
mtpav_port_t *portp = &mtp_card->ports[substream->number];
//printk("mtpav port: %d opened\n", (int) substream->number);
spin_lock_irqsave(&mtp_card->spinlock, flags); spin_lock_irqsave(&mtp_card->spinlock, flags);
portp->mode |= MTPAV_MODE_INPUT_OPENED; portp->mode |= MTPAV_MODE_INPUT_OPENED;
portp->input = substream; portp->input = substream;
...@@ -373,18 +368,15 @@ static int snd_mtpav_input_open(struct snd_rawmidi_substream *substream) ...@@ -373,18 +368,15 @@ static int snd_mtpav_input_open(struct snd_rawmidi_substream *substream)
static int snd_mtpav_input_close(struct snd_rawmidi_substream *substream) static int snd_mtpav_input_close(struct snd_rawmidi_substream *substream)
{ {
struct mtpav *mtp_card = substream->rmidi->private_data;
struct mtpav_port *portp = &mtp_card->ports[substream->number];
unsigned long flags; unsigned long flags;
mtpav_port_t *portp = &mtp_card->ports[substream->number];
//printk("mtpav port: %d closed\n", (int) portp);
spin_lock_irqsave(&mtp_card->spinlock, flags); spin_lock_irqsave(&mtp_card->spinlock, flags);
portp->mode &= ~MTPAV_MODE_INPUT_OPENED;
portp->mode &= (~MTPAV_MODE_INPUT_OPENED);
portp->input = NULL; portp->input = NULL;
if (--mtp_card->share_irq == 0) if (--mtp_card->share_irq == 0)
snd_mtpav_mputreg(mtp_card, CREG, 0); // disable pport interrupts snd_mtpav_mputreg(mtp_card, CREG, 0); // disable pport interrupts
spin_unlock_irqrestore(&mtp_card->spinlock, flags); spin_unlock_irqrestore(&mtp_card->spinlock, flags);
return 0; return 0;
} }
...@@ -394,8 +386,9 @@ static int snd_mtpav_input_close(struct snd_rawmidi_substream *substream) ...@@ -394,8 +386,9 @@ static int snd_mtpav_input_close(struct snd_rawmidi_substream *substream)
static void snd_mtpav_input_trigger(struct snd_rawmidi_substream *substream, int up) static void snd_mtpav_input_trigger(struct snd_rawmidi_substream *substream, int up)
{ {
struct mtpav *mtp_card = substream->rmidi->private_data;
struct mtpav_port *portp = &mtp_card->ports[substream->number];
unsigned long flags; unsigned long flags;
mtpav_port_t *portp = &mtp_card->ports[substream->number];
spin_lock_irqsave(&mtp_card->spinlock, flags); spin_lock_irqsave(&mtp_card->spinlock, flags);
if (up) if (up)
...@@ -414,7 +407,7 @@ static void snd_mtpav_input_trigger(struct snd_rawmidi_substream *substream, int ...@@ -414,7 +407,7 @@ static void snd_mtpav_input_trigger(struct snd_rawmidi_substream *substream, int
static void snd_mtpav_output_timer(unsigned long data) static void snd_mtpav_output_timer(unsigned long data)
{ {
unsigned long flags; unsigned long flags;
mtpav_t *chip = (mtpav_t *)data; struct mtpav *chip = (struct mtpav *)data;
int p; int p;
spin_lock_irqsave(&chip->spinlock, flags); spin_lock_irqsave(&chip->spinlock, flags);
...@@ -423,25 +416,22 @@ static void snd_mtpav_output_timer(unsigned long data) ...@@ -423,25 +416,22 @@ static void snd_mtpav_output_timer(unsigned long data)
add_timer(&chip->timer); add_timer(&chip->timer);
/* process each port */ /* process each port */
for (p = 0; p <= chip->num_ports * 2 + MTPAV_PIDX_BROADCAST; p++) { for (p = 0; p <= chip->num_ports * 2 + MTPAV_PIDX_BROADCAST; p++) {
mtpav_port_t *portp = &mtp_card->ports[p]; struct mtpav_port *portp = &chip->ports[p];
if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED) && portp->output) if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED) && portp->output)
snd_mtpav_output_port_write(portp, portp->output); snd_mtpav_output_port_write(chip, portp, portp->output);
} }
spin_unlock_irqrestore(&chip->spinlock, flags); spin_unlock_irqrestore(&chip->spinlock, flags);
} }
/* spinlock held! */ /* spinlock held! */
static void snd_mtpav_add_output_timer(mtpav_t *chip) static void snd_mtpav_add_output_timer(struct mtpav *chip)
{ {
init_timer(&chip->timer);
chip->timer.function = snd_mtpav_output_timer;
chip->timer.data = (unsigned long) mtp_card;
chip->timer.expires = 1 + jiffies; chip->timer.expires = 1 + jiffies;
add_timer(&chip->timer); add_timer(&chip->timer);
} }
/* spinlock held! */ /* spinlock held! */
static void snd_mtpav_remove_output_timer(mtpav_t *chip) static void snd_mtpav_remove_output_timer(struct mtpav *chip)
{ {
del_timer(&chip->timer); del_timer(&chip->timer);
} }
...@@ -451,8 +441,9 @@ static void snd_mtpav_remove_output_timer(mtpav_t *chip) ...@@ -451,8 +441,9 @@ static void snd_mtpav_remove_output_timer(mtpav_t *chip)
static int snd_mtpav_output_open(struct snd_rawmidi_substream *substream) static int snd_mtpav_output_open(struct snd_rawmidi_substream *substream)
{ {
struct mtpav *mtp_card = substream->rmidi->private_data;
struct mtpav_port *portp = &mtp_card->ports[substream->number];
unsigned long flags; unsigned long flags;
mtpav_port_t *portp = &mtp_card->ports[substream->number];
spin_lock_irqsave(&mtp_card->spinlock, flags); spin_lock_irqsave(&mtp_card->spinlock, flags);
portp->mode |= MTPAV_MODE_OUTPUT_OPENED; portp->mode |= MTPAV_MODE_OUTPUT_OPENED;
...@@ -466,11 +457,12 @@ static int snd_mtpav_output_open(struct snd_rawmidi_substream *substream) ...@@ -466,11 +457,12 @@ static int snd_mtpav_output_open(struct snd_rawmidi_substream *substream)
static int snd_mtpav_output_close(struct snd_rawmidi_substream *substream) static int snd_mtpav_output_close(struct snd_rawmidi_substream *substream)
{ {
struct mtpav *mtp_card = substream->rmidi->private_data;
struct mtpav_port *portp = &mtp_card->ports[substream->number];
unsigned long flags; unsigned long flags;
mtpav_port_t *portp = &mtp_card->ports[substream->number];
spin_lock_irqsave(&mtp_card->spinlock, flags); spin_lock_irqsave(&mtp_card->spinlock, flags);
portp->mode &= (~MTPAV_MODE_OUTPUT_OPENED); portp->mode &= ~MTPAV_MODE_OUTPUT_OPENED;
portp->output = NULL; portp->output = NULL;
spin_unlock_irqrestore(&mtp_card->spinlock, flags); spin_unlock_irqrestore(&mtp_card->spinlock, flags);
return 0; return 0;
...@@ -481,8 +473,9 @@ static int snd_mtpav_output_close(struct snd_rawmidi_substream *substream) ...@@ -481,8 +473,9 @@ static int snd_mtpav_output_close(struct snd_rawmidi_substream *substream)
static void snd_mtpav_output_trigger(struct snd_rawmidi_substream *substream, int up) static void snd_mtpav_output_trigger(struct snd_rawmidi_substream *substream, int up)
{ {
struct mtpav *mtp_card = substream->rmidi->private_data;
struct mtpav_port *portp = &mtp_card->ports[substream->number];
unsigned long flags; unsigned long flags;
mtpav_port_t *portp = &mtp_card->ports[substream->number];
spin_lock_irqsave(&mtp_card->spinlock, flags); spin_lock_irqsave(&mtp_card->spinlock, flags);
if (up) { if (up) {
...@@ -506,23 +499,20 @@ static void snd_mtpav_output_trigger(struct snd_rawmidi_substream *substream, in ...@@ -506,23 +499,20 @@ static void snd_mtpav_output_trigger(struct snd_rawmidi_substream *substream, in
* midi interrupt for inputs * midi interrupt for inputs
*/ */
static void snd_mtpav_inmidi_process(mtpav_t *mcrd, u8 inbyte) static void snd_mtpav_inmidi_process(struct mtpav *mcrd, u8 inbyte)
{ {
mtpav_port_t *portp; struct mtpav_port *portp;
if ((int)mcrd->inmidiport > mcrd->num_ports * 2 + MTPAV_PIDX_BROADCAST) if ((int)mcrd->inmidiport > mcrd->num_ports * 2 + MTPAV_PIDX_BROADCAST)
return; return;
portp = &mcrd->ports[mcrd->inmidiport]; portp = &mcrd->ports[mcrd->inmidiport];
if (portp->mode & MTPAV_MODE_INPUT_TRIGGERED) { if (portp->mode & MTPAV_MODE_INPUT_TRIGGERED)
snd_rawmidi_receive(portp->input, &inbyte, 1); snd_rawmidi_receive(portp->input, &inbyte, 1);
}
} }
static void snd_mtpav_inmidi_h(mtpav_t * mcrd, u8 inbyte) static void snd_mtpav_inmidi_h(struct mtpav *mcrd, u8 inbyte)
{ {
snd_assert(mcrd, return);
if (inbyte >= 0xf8) { if (inbyte >= 0xf8) {
/* real-time midi code */ /* real-time midi code */
snd_mtpav_inmidi_process(mcrd, inbyte); snd_mtpav_inmidi_process(mcrd, inbyte);
...@@ -540,7 +530,7 @@ static void snd_mtpav_inmidi_h(mtpav_t * mcrd, u8 inbyte) ...@@ -540,7 +530,7 @@ static void snd_mtpav_inmidi_h(mtpav_t * mcrd, u8 inbyte)
} }
} }
static void snd_mtpav_read_bytes(mtpav_t * mcrd) static void snd_mtpav_read_bytes(struct mtpav *mcrd)
{ {
u8 clrread, setread; u8 clrread, setread;
u8 mtp_read_byte; u8 mtp_read_byte;
...@@ -580,9 +570,8 @@ static void snd_mtpav_read_bytes(mtpav_t * mcrd) ...@@ -580,9 +570,8 @@ static void snd_mtpav_read_bytes(mtpav_t * mcrd)
static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id, struct pt_regs *regs) static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id, struct pt_regs *regs)
{ {
mtpav_t *mcard = dev_id; struct mtpav *mcard = dev_id;
//printk("irqh()\n");
spin_lock(&mcard->spinlock); spin_lock(&mcard->spinlock);
snd_mtpav_read_bytes(mcard); snd_mtpav_read_bytes(mcard);
spin_unlock(&mcard->spinlock); spin_unlock(&mcard->spinlock);
...@@ -592,14 +581,14 @@ static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id, struct pt_regs *regs) ...@@ -592,14 +581,14 @@ static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id, struct pt_regs *regs)
/* /*
* get ISA resources * get ISA resources
*/ */
static int snd_mtpav_get_ISA(mtpav_t * mcard) static int __init snd_mtpav_get_ISA(struct mtpav * mcard)
{ {
if ((mcard->res_port = request_region(port, 3, "MotuMTPAV MIDI")) == NULL) { if ((mcard->res_port = request_region(port, 3, "MotuMTPAV MIDI")) == NULL) {
snd_printk("MTVAP port 0x%lx is busy\n", port); snd_printk("MTVAP port 0x%lx is busy\n", port);
return -EBUSY; return -EBUSY;
} }
mcard->port = port; mcard->port = port;
if (request_irq(irq, snd_mtpav_irqh, SA_INTERRUPT, "MOTU MTPAV", (void *)mcard)) { if (request_irq(irq, snd_mtpav_irqh, SA_INTERRUPT, "MOTU MTPAV", mcard)) {
snd_printk("MTVAP IRQ %d busy\n", irq); snd_printk("MTVAP IRQ %d busy\n", irq);
return -EBUSY; return -EBUSY;
} }
...@@ -628,7 +617,8 @@ static struct snd_rawmidi_ops snd_mtpav_input = { ...@@ -628,7 +617,8 @@ static struct snd_rawmidi_ops snd_mtpav_input = {
* get RAWMIDI resources * get RAWMIDI resources
*/ */
static void snd_mtpav_set_name(mtpav_t *chip, struct snd_rawmidi_substream *substream) static void __init snd_mtpav_set_name(struct mtpav *chip,
struct snd_rawmidi_substream *substream)
{ {
if (substream->number >= 0 && substream->number < chip->num_ports) if (substream->number >= 0 && substream->number < chip->num_ports)
sprintf(substream->name, "MTP direct %d", (substream->number % chip->num_ports) + 1); sprintf(substream->name, "MTP direct %d", (substream->number % chip->num_ports) + 1);
...@@ -642,20 +632,17 @@ static void snd_mtpav_set_name(mtpav_t *chip, struct snd_rawmidi_substream *subs ...@@ -642,20 +632,17 @@ static void snd_mtpav_set_name(mtpav_t *chip, struct snd_rawmidi_substream *subs
strcpy(substream->name, "MTP broadcast"); strcpy(substream->name, "MTP broadcast");
} }
static int snd_mtpav_get_RAWMIDI(mtpav_t * mcard) static int __init snd_mtpav_get_RAWMIDI(struct mtpav *mcard)
{ {
int rval = 0; int rval;
struct snd_rawmidi *rawmidi; struct snd_rawmidi *rawmidi;
struct snd_rawmidi_substream *substream; struct snd_rawmidi_substream *substream;
struct list_head *list; struct list_head *list;
//printk("entering snd_mtpav_get_RAWMIDI\n");
if (hwports < 1) if (hwports < 1)
mcard->num_ports = 1; hwports = 1;
else if (hwports > 8) else if (hwports > 8)
mcard->num_ports = 8; hwports = 8;
else
mcard->num_ports = hwports; mcard->num_ports = hwports;
if ((rval = snd_rawmidi_new(mcard->card, "MotuMIDI", 0, if ((rval = snd_rawmidi_new(mcard->card, "MotuMIDI", 0,
...@@ -664,6 +651,7 @@ static int snd_mtpav_get_RAWMIDI(mtpav_t * mcard) ...@@ -664,6 +651,7 @@ static int snd_mtpav_get_RAWMIDI(mtpav_t * mcard)
&mcard->rmidi)) < 0) &mcard->rmidi)) < 0)
return rval; return rval;
rawmidi = mcard->rmidi; rawmidi = mcard->rmidi;
rawmidi->private_data = mcard;
list_for_each(list, &rawmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) { list_for_each(list, &rawmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) {
substream = list_entry(list, struct snd_rawmidi_substream, list); substream = list_entry(list, struct snd_rawmidi_substream, list);
...@@ -679,36 +667,15 @@ static int snd_mtpav_get_RAWMIDI(mtpav_t * mcard) ...@@ -679,36 +667,15 @@ static int snd_mtpav_get_RAWMIDI(mtpav_t * mcard)
rawmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | rawmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT |
SNDRV_RAWMIDI_INFO_DUPLEX; SNDRV_RAWMIDI_INFO_DUPLEX;
sprintf(rawmidi->name, "MTP AV MIDI"); sprintf(rawmidi->name, "MTP AV MIDI");
//printk("exiting snd_mtpav_get_RAWMIDI() \n");
return 0; return 0;
} }
/* /*
*/ */
static mtpav_t *new_mtpav(void) static void snd_mtpav_free(struct snd_card *card)
{
mtpav_t *ncrd = kzalloc(sizeof(*ncrd), GFP_KERNEL);
if (ncrd != NULL) {
spin_lock_init(&ncrd->spinlock);
init_timer(&ncrd->timer);
ncrd->card = NULL;
ncrd->irq = -1;
ncrd->share_irq = 0;
ncrd->inmidiport = 0xffffffff;
ncrd->inmidistate = 0;
ncrd->outmidihwport = 0xffffffff;
}
return ncrd;
}
/*
*/
static void free_mtpav(mtpav_t * crd)
{ {
struct mtpav *crd = card->private_data;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&crd->spinlock, flags); spin_lock_irqsave(&crd->spinlock, flags);
...@@ -718,78 +685,101 @@ static void free_mtpav(mtpav_t * crd) ...@@ -718,78 +685,101 @@ static void free_mtpav(mtpav_t * crd)
if (crd->irq >= 0) if (crd->irq >= 0)
free_irq(crd->irq, (void *)crd); free_irq(crd->irq, (void *)crd);
release_and_free_resource(crd->res_port); release_and_free_resource(crd->res_port);
kfree(crd);
} }
/* /*
*/ */
static int __init snd_mtpav_probe(struct platform_device *dev)
static int __init alsa_card_mtpav_init(void)
{ {
int err = 0; struct snd_card *card;
char longname_buffer[80]; int err;
struct mtpav *mtp_card;
mtp_card = new_mtpav(); card = snd_card_new(index, id, THIS_MODULE, sizeof(*mtp_card));
if (mtp_card == NULL) if (! card)
return -ENOMEM; return -ENOMEM;
mtp_card->card = snd_card_new(index, id, THIS_MODULE, 0); mtp_card = card->private_data;
if (mtp_card->card == NULL) { spin_lock_init(&mtp_card->spinlock);
free_mtpav(mtp_card); init_timer(&mtp_card->timer);
return -ENOMEM; mtp_card->card = card;
} mtp_card->irq = -1;
mtp_card->share_irq = 0;
mtp_card->inmidiport = 0xffffffff;
mtp_card->inmidistate = 0;
mtp_card->outmidihwport = 0xffffffff;
init_timer(&mtp_card->timer);
mtp_card->timer.function = snd_mtpav_output_timer;
mtp_card->timer.data = (unsigned long) mtp_card;
card->private_free = snd_mtpav_free;
err = snd_mtpav_get_ISA(mtp_card); err = snd_mtpav_get_ISA(mtp_card);
//printk("snd_mtpav_get_ISA returned: %d\n", err);
if (err < 0) if (err < 0)
goto __error; goto __error;
strcpy(mtp_card->card->driver, "MTPAV"); strcpy(card->driver, "MTPAV");
strcpy(mtp_card->card->shortname, "MTPAV on parallel port"); strcpy(card->shortname, "MTPAV on parallel port");
memset(longname_buffer, 0, sizeof(longname_buffer)); snprintf(card->longname, sizeof(card->longname),
sprintf(longname_buffer, "MTPAV on parallel port at"); "MTPAV on parallel port at 0x%lx", port);
err = snd_mtpav_get_RAWMIDI(mtp_card); err = snd_mtpav_get_RAWMIDI(mtp_card);
//snd_printk("snd_mtapv_get_RAWMIDI returned: %d\n", err);
if (err < 0) if (err < 0)
goto __error; goto __error;
if ((err = snd_card_set_generic_dev(mtp_card->card)) < 0) snd_mtpav_portscan(mtp_card);
goto __error;
err = snd_card_register(mtp_card->card); // don't snd_card_register until AFTER all cards reources done!
//printk("snd_card_register returned %d\n", err); snd_card_set_dev(card, &dev->dev);
err = snd_card_register(mtp_card->card);
if (err < 0) if (err < 0)
goto __error; goto __error;
platform_set_drvdata(dev, card);
snd_mtpav_portscan(mtp_card);
printk(KERN_INFO "Motu MidiTimePiece on parallel port irq: %d ioport: 0x%lx\n", irq, port); printk(KERN_INFO "Motu MidiTimePiece on parallel port irq: %d ioport: 0x%lx\n", irq, port);
return 0; return 0;
__error: __error:
snd_card_free(mtp_card->card); snd_card_free(card);
free_mtpav(mtp_card);
return err; return err;
} }
/* static int snd_mtpav_remove(struct platform_device *devptr)
*/ {
snd_card_free(platform_get_drvdata(devptr));
platform_set_drvdata(devptr, NULL);
return 0;
}
static void __exit alsa_card_mtpav_exit(void) #define SND_MTPAV_DRIVER "snd_mtpav"
static struct platform_driver snd_mtpav_driver = {
.probe = snd_mtpav_probe,
.remove = snd_mtpav_remove,
.driver = {
.name = SND_MTPAV_DRIVER
},
};
static int __init alsa_card_mtpav_init(void)
{ {
if (mtp_card == NULL) int err;
return; struct platform_device *device;
if (mtp_card->card)
snd_card_free(mtp_card->card); if ((err = platform_driver_register(&snd_mtpav_driver)) < 0)
free_mtpav(mtp_card); return err;
device = platform_device_register_simple(SND_MTPAV_DRIVER, -1, NULL, 0);
if (IS_ERR(device)) {
platform_driver_unregister(&snd_mtpav_driver);
return PTR_ERR(device);
}
return 0;
} }
/* static void __exit alsa_card_mtpav_exit(void)
*/ {
platform_driver_unregister(&snd_mtpav_driver);
}
module_init(alsa_card_mtpav_init) module_init(alsa_card_mtpav_init)
module_exit(alsa_card_mtpav_exit) module_exit(alsa_card_mtpav_exit)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册