From patchwork Mon Feb 22 13:22:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 8376331 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7A8BAC0553 for ; Mon, 22 Feb 2016 13:22:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5AFC2204EB for ; Mon, 22 Feb 2016 13:22:36 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id F0BE22047B for ; Mon, 22 Feb 2016 13:22:34 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0DD05265B3F; Mon, 22 Feb 2016 14:22:34 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 3C81F265A1D; Mon, 22 Feb 2016 14:22:26 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1BA37265A3C; Mon, 22 Feb 2016 14:22:25 +0100 (CET) Received: from mail-pf0-f169.google.com (mail-pf0-f169.google.com [209.85.192.169]) by alsa0.perex.cz (Postfix) with ESMTP id D907C2606B8 for ; Mon, 22 Feb 2016 14:22:17 +0100 (CET) Received: by mail-pf0-f169.google.com with SMTP id x65so92826915pfb.1 for ; Mon, 22 Feb 2016 05:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=QTjCyqF3TTvtIZcqi0eYVj8fkPTR8FT/GlTS8oTwEgE=; b=p4TxUIJzYmDFesfvRLuMU741aUXNqS0ovfvpwRBTKu41M5gdnwHMuEltOAG/ugVe8q /1M/y6EYJouTWaOONe0ftv1Qxiqq5iPXHv9SgfvfrQB1qD+ahnm3d5TaiTuXNYjaQZhx twIzkIObG2RdZ62iDk6pBBXgAMVmRIUN7AsTKLXE0ZdWj5L5WqbaI88UVxrJFkK8BYrg UIzzGxD3eVqeTHLOTRe7oyXLb3Qxraqyh74cYqC8iSiW+thZ3UIP4dB3sgQLNseKow58 vLHL/tWjSbEXoIS+4v//JnYGiTT4Knmhz3TBXUOUt8CW3SlRG0HtpLwYhXMDo1/qoRMr ftow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QTjCyqF3TTvtIZcqi0eYVj8fkPTR8FT/GlTS8oTwEgE=; b=ahlUKMHCEfEFocON0gch7kdIgPhkqe3yI5W+cAr1q6A17hF1ihGtfEDnOxUaU851TT ZCVUJrxdTOT9uoJe8fOWCbCyIwu5XAM0HSzGEHeRA/LbE8qEqLMUUuFVr1ue+BoTFaIC a1h93PmZiWYnRM3DBj+GRi5aUpzFIGohVK6fr614Jr4RCGjBnCX3iuu4fdzhJfta9oIR EeY0Pu0U2JxYEFNwAXGmX7Zjn5pQsH5tps3bEOwmTeWlvhh+++RqCEi9hYUhxqi8ZurJ +aNYB/oe1B0sji5rWJXFwU6Rsz50HuJh2YGyWwWdp9sEKa3gcGfSOcOoswdHNsDRK89G Gh5Q== X-Gm-Message-State: AG10YOQaFl5cCIGOByLBYMA0ksM8D3ogEUPwYgVgmDaH468h7hf1cI1FTULQJuYu88LeSA== X-Received: by 10.98.70.80 with SMTP id t77mr37470151pfa.107.1456147336888; Mon, 22 Feb 2016 05:22:16 -0800 (PST) Received: from sudip-pc.vectortproxy.org ([14.195.238.223]) by smtp.gmail.com with ESMTPSA id t29sm37078617pfi.8.2016.02.22.05.22.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 05:22:16 -0800 (PST) From: Sudip Mukherjee To: Jaroslav Kysela , Takashi Iwai Date: Mon, 22 Feb 2016 18:52:08 +0530 Message-Id: <1456147328-16083-1-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.9.1 Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Sudip Mukherjee Subject: [alsa-devel] [PATCH] ALSA: mts64: use new parport device model X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- exactly same changes as done in portman2x4. BTW, there is one portman2x4 available on ebay. I was bidding for it but someone is more desperate than I am and outbidding me everytime :( sound/drivers/mts64.c | 95 +++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 52 deletions(-) diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c index 2a008a9..c76bd87 100644 --- a/sound/drivers/mts64.c +++ b/sound/drivers/mts64.c @@ -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; @@ -850,30 +848,6 @@ __out: 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; @@ -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, }; /********************************************************************* @@ -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); } @@ -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); @@ -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); @@ -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; @@ -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; @@ -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; @@ -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,