Commit 94a57350 authored by Sudip Mukherjee's avatar Sudip Mukherjee Committed by Takashi Iwai

ALSA: mts64: use new parport device model

Modify mts64 driver to use the new parallel port device model.
The advantage of using the device model is that the driver gets binded
to the hardware, we get the feature of hotplug, we can bind/unbind the
driver at runtime.
The changes are in the way the driver gets registered with the parallel
port subsystem and the temporary device to probe mts64 card is removed
and mts64_probe() is used in the probe callback.
Signed-off-by: default avatarSudip Mukherjee <sudip.mukherjee@codethink.co.uk>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c3a90058
...@@ -65,8 +65,6 @@ struct mts64 { ...@@ -65,8 +65,6 @@ struct mts64 {
struct snd_card *card; struct snd_card *card;
struct snd_rawmidi *rmidi; struct snd_rawmidi *rmidi;
struct pardevice *pardev; struct pardevice *pardev;
int pardev_claimed;
int open_count; int open_count;
int current_midi_output_port; int current_midi_output_port;
int current_midi_input_port; int current_midi_input_port;
...@@ -850,30 +848,6 @@ static void snd_mts64_interrupt(void *private) ...@@ -850,30 +848,6 @@ static void snd_mts64_interrupt(void *private)
spin_unlock(&mts->lock); spin_unlock(&mts->lock);
} }
static int snd_mts64_probe_port(struct parport *p)
{
struct pardevice *pardev;
int res;
pardev = parport_register_device(p, DRIVER_NAME,
NULL, NULL, NULL,
0, NULL);
if (!pardev)
return -EIO;
if (parport_claim(pardev)) {
parport_unregister_device(pardev);
return -EIO;
}
res = mts64_probe(p);
parport_release(pardev);
parport_unregister_device(pardev);
return res;
}
static void snd_mts64_attach(struct parport *p) static void snd_mts64_attach(struct parport *p)
{ {
struct platform_device *device; struct platform_device *device;
...@@ -907,10 +881,20 @@ static void snd_mts64_detach(struct parport *p) ...@@ -907,10 +881,20 @@ static void snd_mts64_detach(struct parport *p)
/* nothing to do here */ /* nothing to do here */
} }
static int snd_mts64_dev_probe(struct pardevice *pardev)
{
if (strcmp(pardev->name, DRIVER_NAME))
return -ENODEV;
return 0;
}
static struct parport_driver mts64_parport_driver = { static struct parport_driver mts64_parport_driver = {
.name = "mts64", .name = "mts64",
.attach = snd_mts64_attach, .probe = snd_mts64_dev_probe,
.detach = snd_mts64_detach .match_port = snd_mts64_attach,
.detach = snd_mts64_detach,
.devmodel = true,
}; };
/********************************************************************* /*********************************************************************
...@@ -922,8 +906,7 @@ static void snd_mts64_card_private_free(struct snd_card *card) ...@@ -922,8 +906,7 @@ static void snd_mts64_card_private_free(struct snd_card *card)
struct pardevice *pardev = mts->pardev; struct pardevice *pardev = mts->pardev;
if (pardev) { if (pardev) {
if (mts->pardev_claimed) parport_release(pardev);
parport_release(pardev);
parport_unregister_device(pardev); parport_unregister_device(pardev);
} }
...@@ -938,6 +921,12 @@ static int snd_mts64_probe(struct platform_device *pdev) ...@@ -938,6 +921,12 @@ static int snd_mts64_probe(struct platform_device *pdev)
struct snd_card *card = NULL; struct snd_card *card = NULL;
struct mts64 *mts = NULL; struct mts64 *mts = NULL;
int err; int err;
struct pardev_cb mts64_cb = {
.preempt = NULL,
.wakeup = NULL,
.irq_func = snd_mts64_interrupt, /* ISR */
.flags = PARPORT_DEV_EXCL, /* flags */
};
p = platform_get_drvdata(pdev); p = platform_get_drvdata(pdev);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
...@@ -946,8 +935,6 @@ static int snd_mts64_probe(struct platform_device *pdev) ...@@ -946,8 +935,6 @@ static int snd_mts64_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
if (!enable[dev]) if (!enable[dev])
return -ENOENT; return -ENOENT;
if ((err = snd_mts64_probe_port(p)) < 0)
return err;
err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE, err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE,
0, &card); 0, &card);
...@@ -960,23 +947,32 @@ static int snd_mts64_probe(struct platform_device *pdev) ...@@ -960,23 +947,32 @@ static int snd_mts64_probe(struct platform_device *pdev)
sprintf(card->longname, "%s at 0x%lx, irq %i", sprintf(card->longname, "%s at 0x%lx, irq %i",
card->shortname, p->base, p->irq); card->shortname, p->base, p->irq);
pardev = parport_register_device(p, /* port */ mts64_cb.private = card; /* private */
DRIVER_NAME, /* name */ pardev = parport_register_dev_model(p, /* port */
NULL, /* preempt */ DRIVER_NAME, /* name */
NULL, /* wakeup */ &mts64_cb, /* callbacks */
snd_mts64_interrupt, /* ISR */ pdev->id); /* device number */
PARPORT_DEV_EXCL, /* flags */ if (!pardev) {
(void *)card); /* private */
if (pardev == NULL) {
snd_printd("Cannot register pardevice\n"); snd_printd("Cannot register pardevice\n");
err = -EIO; err = -EIO;
goto __err; goto __err;
} }
/* claim parport */
if (parport_claim(pardev)) {
snd_printd("Cannot claim parport 0x%lx\n", pardev->port->base);
err = -EIO;
goto free_pardev;
}
err = mts64_probe(p);
if (err) {
err = -EIO;
goto release_pardev;
}
if ((err = snd_mts64_create(card, pardev, &mts)) < 0) { if ((err = snd_mts64_create(card, pardev, &mts)) < 0) {
snd_printd("Cannot create main component\n"); snd_printd("Cannot create main component\n");
parport_unregister_device(pardev); goto release_pardev;
goto __err;
} }
card->private_data = mts; card->private_data = mts;
card->private_free = snd_mts64_card_private_free; card->private_free = snd_mts64_card_private_free;
...@@ -986,14 +982,6 @@ static int snd_mts64_probe(struct platform_device *pdev) ...@@ -986,14 +982,6 @@ static int snd_mts64_probe(struct platform_device *pdev)
goto __err; goto __err;
} }
/* claim parport */
if (parport_claim(pardev)) {
snd_printd("Cannot claim parport 0x%lx\n", pardev->port->base);
err = -EIO;
goto __err;
}
mts->pardev_claimed = 1;
/* init device */ /* init device */
if ((err = mts64_device_init(p)) < 0) if ((err = mts64_device_init(p)) < 0)
goto __err; goto __err;
...@@ -1009,6 +997,10 @@ static int snd_mts64_probe(struct platform_device *pdev) ...@@ -1009,6 +997,10 @@ static int snd_mts64_probe(struct platform_device *pdev)
snd_printk(KERN_INFO "ESI Miditerminal 4140 on 0x%lx\n", p->base); snd_printk(KERN_INFO "ESI Miditerminal 4140 on 0x%lx\n", p->base);
return 0; return 0;
release_pardev:
parport_release(pardev);
free_pardev:
parport_unregister_device(pardev);
__err: __err:
snd_card_free(card); snd_card_free(card);
return err; return err;
...@@ -1024,7 +1016,6 @@ static int snd_mts64_remove(struct platform_device *pdev) ...@@ -1024,7 +1016,6 @@ static int snd_mts64_remove(struct platform_device *pdev)
return 0; return 0;
} }
static struct platform_driver snd_mts64_driver = { static struct platform_driver snd_mts64_driver = {
.probe = snd_mts64_probe, .probe = snd_mts64_probe,
.remove = snd_mts64_remove, .remove = snd_mts64_remove,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment