Skip to content

Commit

Permalink
ALSA: mts64: use new parport device model
Browse files Browse the repository at this point in the history
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: Sudip Mukherjee <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
sudipm-mukherjee authored and tiwai committed Feb 22, 2016
1 parent c3a9005 commit 94a5735
Showing 1 changed file with 43 additions and 52 deletions.
95 changes: 43 additions & 52 deletions sound/drivers/mts64.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ struct mts64 {
struct snd_card *card;
struct snd_rawmidi *rmidi;
struct pardevice *pardev;
int pardev_claimed;

int open_count;
int current_midi_output_port;
int current_midi_input_port;
Expand Down Expand Up @@ -850,30 +848,6 @@ static void snd_mts64_interrupt(void *private)
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)
{
struct platform_device *device;
Expand Down Expand Up @@ -907,10 +881,20 @@ static void snd_mts64_detach(struct parport *p)
/* 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 = {
.name = "mts64",
.attach = snd_mts64_attach,
.detach = snd_mts64_detach
.name = "mts64",
.probe = snd_mts64_dev_probe,
.match_port = snd_mts64_attach,
.detach = snd_mts64_detach,
.devmodel = true,
};

/*********************************************************************
Expand All @@ -922,8 +906,7 @@ static void snd_mts64_card_private_free(struct snd_card *card)
struct pardevice *pardev = mts->pardev;

if (pardev) {
if (mts->pardev_claimed)
parport_release(pardev);
parport_release(pardev);
parport_unregister_device(pardev);
}

Expand All @@ -938,6 +921,12 @@ static int snd_mts64_probe(struct platform_device *pdev)
struct snd_card *card = NULL;
struct mts64 *mts = NULL;
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);
platform_set_drvdata(pdev, NULL);
Expand All @@ -946,8 +935,6 @@ static int snd_mts64_probe(struct platform_device *pdev)
return -ENODEV;
if (!enable[dev])
return -ENOENT;
if ((err = snd_mts64_probe_port(p)) < 0)
return err;

err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE,
0, &card);
Expand All @@ -960,23 +947,32 @@ static int snd_mts64_probe(struct platform_device *pdev)
sprintf(card->longname, "%s at 0x%lx, irq %i",
card->shortname, p->base, p->irq);

pardev = parport_register_device(p, /* port */
DRIVER_NAME, /* name */
NULL, /* preempt */
NULL, /* wakeup */
snd_mts64_interrupt, /* ISR */
PARPORT_DEV_EXCL, /* flags */
(void *)card); /* private */
if (pardev == NULL) {
mts64_cb.private = card; /* private */
pardev = parport_register_dev_model(p, /* port */
DRIVER_NAME, /* name */
&mts64_cb, /* callbacks */
pdev->id); /* device number */
if (!pardev) {
snd_printd("Cannot register pardevice\n");
err = -EIO;
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) {
snd_printd("Cannot create main component\n");
parport_unregister_device(pardev);
goto __err;
goto release_pardev;
}
card->private_data = mts;
card->private_free = snd_mts64_card_private_free;
Expand All @@ -986,14 +982,6 @@ static int snd_mts64_probe(struct platform_device *pdev)
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 */
if ((err = mts64_device_init(p)) < 0)
goto __err;
Expand All @@ -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);
return 0;

release_pardev:
parport_release(pardev);
free_pardev:
parport_unregister_device(pardev);
__err:
snd_card_free(card);
return err;
Expand All @@ -1024,7 +1016,6 @@ static int snd_mts64_remove(struct platform_device *pdev)
return 0;
}


static struct platform_driver snd_mts64_driver = {
.probe = snd_mts64_probe,
.remove = snd_mts64_remove,
Expand Down

0 comments on commit 94a5735

Please sign in to comment.