From patchwork Wed Feb 17 12:56:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 8338501 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 D3F0CC02AA for ; Wed, 17 Feb 2016 12:57:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85E3720384 for ; Wed, 17 Feb 2016 12:56:58 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 2C7FE20376 for ; Wed, 17 Feb 2016 12:56:57 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 8FCC12666D7; Wed, 17 Feb 2016 13:56:54 +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, NO_DNS_FOR_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 D59DB2664A0; Wed, 17 Feb 2016 13:56:46 +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 897FC2664A3; Wed, 17 Feb 2016 13:56:45 +0100 (CET) Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by alsa0.perex.cz (Postfix) with ESMTP id 0D9CA2661CD for ; Wed, 17 Feb 2016 13:56:38 +0100 (CET) Received: by mail-pa0-f49.google.com with SMTP id fl4so11099557pad.0 for ; Wed, 17 Feb 2016 04:56:37 -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=amM2vubnlcXzIdC8pBHs+/QboqHK6T7/pE/fUiPUCFQ=; b=dftWu42P67xNfBb/TLEkK09v2aVQa2n/GTo/+ly8gjvQyCKUZzSPQYOsvhWpLY9iVK +lQ0uZGThYP/iK3Lvg10lkrxZTt1JsbjwN5/3ha92fkVsrccnngKXB9C8kWIX0Rjg90+ BYbt6BlQS0Z9WbOYNAeeQ7l+zfW+/0eDmJN1c6gyYg9r+JRyWcZLX2A2zpWu2Jq2GbUE G8K1/wZI/k4Hzhu6YLu6FmRv3Ivuib6ZZK8GYX1lyHx0Y1hUb99zw3lsk29+51ir2vkW cgQu8sZLeNZnVV7v0LbJD0itbgXdHkgUCq8FI8HbaAC6s2pye9Ojmpr9lZHiqIoGqvre WteQ== 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=amM2vubnlcXzIdC8pBHs+/QboqHK6T7/pE/fUiPUCFQ=; b=W88S8t0VFbjBhWCcodT1vWgeN+Lj5RI/HzqjgoVlf5f2vNrWmePWPaDPW3Sp/jXPiT 9f4uM6sA9eIdhLxegTZK9muHxtqsGytyW0JFU2d3UH/bgW20GsTEhKcGkrJPv5oCSVAO bH2I2WlRRCrFm+LRkwzBZa7WLhxm2g3bUuzz2JuqcAb+SPsp0UfpBk+rFlFWXrJklBUQ J5Q4bth/v4R2h+6svK6/L+Mwh+A6HpbsziZXdIa2yhNFqOVGi1Lyzev+IGYMNNyHK+rV PVuv+dOsJinmnd08qSHv9nAuQ743pfyh2GDrEyFG2JqacepX6aHcXPDBLxh12PanBu/5 z07g== X-Gm-Message-State: AG10YOSXHz5OpqDmX3Uv8YMFE033/NVBTwhBfnujxBVWjEM1dHfR9DBBUpShWiZ2++caqA== X-Received: by 10.66.101.2 with SMTP id fc2mr1884688pab.96.1455713796026; Wed, 17 Feb 2016 04:56:36 -0800 (PST) Received: from sudip-pc.vectortproxy.org ([49.206.197.43]) by smtp.gmail.com with ESMTPSA id v7sm2687447pfi.56.2016.02.17.04.56.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Feb 2016 04:56:35 -0800 (PST) From: Sudip Mukherjee To: Jaroslav Kysela , Takashi Iwai Date: Wed, 17 Feb 2016 18:26:27 +0530 Message-Id: <1455713787-13382-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 v5] portman2x4 - 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 portman driver to use the new parallel port device model. The advantage of using the device model is that the device 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 portman card is removed and portman_probe() is used in the probe callback. Signed-off-by: Sudip Mukherjee --- v5: claimed flag and one call to parport_claim() removed. v4: temporary device to probe is removed. v3: changed commit message v2: 1. pardev_cb is initialized while declaring, thus removing the use of memset. 2. used pdev->id. 3. v1 did not have the parport probe callback, but we will need the probe callback for binding as the name of the driver and the name of the device is different. 4. in v1 I missed modifying snd_portman_probe_port(). sound/drivers/portman2x4.c | 93 +++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 51 deletions(-) diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c index 464385a..362533f 100644 --- a/sound/drivers/portman2x4.c +++ b/sound/drivers/portman2x4.c @@ -83,8 +83,6 @@ struct portman { struct snd_card *card; struct snd_rawmidi *rmidi; struct pardevice *pardev; - int pardev_claimed; - int open_count; int mode[PORTMAN_NUM_INPUT_PORTS]; struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS]; @@ -648,30 +646,6 @@ static void snd_portman_interrupt(void *userdata) spin_unlock(&pm->reg_lock); } -static int snd_portman_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 = portman_probe(p); - - parport_release(pardev); - parport_unregister_device(pardev); - - return res ? -EIO : 0; -} - static void snd_portman_attach(struct parport *p) { struct platform_device *device; @@ -705,10 +679,20 @@ static void snd_portman_detach(struct parport *p) /* nothing to do here */ } +static int snd_portman_dev_probe(struct pardevice *pardev) +{ + if (strcmp(pardev->name, DRIVER_NAME)) + return -ENODEV; + + return 0; +} + static struct parport_driver portman_parport_driver = { - .name = "portman2x4", - .attach = snd_portman_attach, - .detach = snd_portman_detach + .name = "portman2x4", + .probe = snd_portman_dev_probe, + .match_port = snd_portman_attach, + .detach = snd_portman_detach, + .devmodel = true, }; /********************************************************************* @@ -720,8 +704,7 @@ static void snd_portman_card_private_free(struct snd_card *card) struct pardevice *pardev = pm->pardev; if (pardev) { - if (pm->pardev_claimed) - parport_release(pardev); + parport_release(pardev); parport_unregister_device(pardev); } @@ -736,6 +719,12 @@ static int snd_portman_probe(struct platform_device *pdev) struct snd_card *card = NULL; struct portman *pm = NULL; int err; + struct pardev_cb portman_cb = { + .preempt = NULL, + .wakeup = NULL, + .irq_func = snd_portman_interrupt, /* ISR */ + .flags = PARPORT_DEV_EXCL, /* flags */ + }; p = platform_get_drvdata(pdev); platform_set_drvdata(pdev, NULL); @@ -745,9 +734,6 @@ static int snd_portman_probe(struct platform_device *pdev) if (!enable[dev]) return -ENOENT; - if ((err = snd_portman_probe_port(p)) < 0) - return err; - err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE, 0, &card); if (err < 0) { @@ -759,23 +745,32 @@ static int snd_portman_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_portman_interrupt, /* ISR */ - PARPORT_DEV_EXCL, /* flags */ - (void *)card); /* private */ + portman_cb.private = card; /* private */ + pardev = parport_register_dev_model(p, /* port */ + DRIVER_NAME, /* name */ + &portman_cb, /* callbacks */ + pdev->id); /* device number */ if (pardev == NULL) { 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 = portman_probe(p); + if (err) { + err = -EIO; + goto release_pardev; + } + if ((err = portman_create(card, pardev, &pm)) < 0) { snd_printd("Cannot create main component\n"); - parport_unregister_device(pardev); - goto __err; + goto release_pardev; } card->private_data = pm; card->private_free = snd_portman_card_private_free; @@ -785,14 +780,6 @@ static int snd_portman_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; - } - pm->pardev_claimed = 1; - /* init device */ if ((err = portman_device_init(pm)) < 0) goto __err; @@ -808,6 +795,10 @@ static int snd_portman_probe(struct platform_device *pdev) snd_printk(KERN_INFO "Portman 2x4 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;