Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934948AbcLPQkR (ORCPT ); Fri, 16 Dec 2016 11:40:17 -0500 Received: from mail-by2nam01on0076.outbound.protection.outlook.com ([104.47.34.76]:54352 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1161165AbcLPQjE (ORCPT ); Fri, 16 Dec 2016 11:39:04 -0500 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; X-IncomingTopHeaderMarker: OriginalChecksum:;UpperCasedChecksum:;SizeAsReceived:981;Count:10 From: Stuart Yoder To: CC: , , , , , , , , , , Haiying Wang , Stuart Yoder Subject: [PATCH v5 7/8] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver Date: Fri, 16 Dec 2016 10:31:05 -0600 Message-ID: <1481905866-10816-8-git-send-email-stuart.yoder@nxp.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1481905866-10816-1-git-send-email-stuart.yoder@nxp.com> References: <1481905866-10816-1-git-send-email-stuart.yoder@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131263799370260994;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(336005)(7916002)(39400400002)(39410400002)(39850400002)(39380400002)(39860400002)(39840400002)(39450400003)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(77096006)(38730400001)(50986999)(189998001)(50466002)(76176999)(2351001)(86362001)(5003940100001)(97736004)(7416002)(5660300001)(626004)(47776003)(48376002)(2950100002)(106466001)(36756003)(6916009)(6666003)(110136003)(33646002)(105606002)(85426001)(92566002)(104016004)(8936002)(50226002)(305945005)(8676002)(4326007)(68736007)(8666005)(356003)(2906002)(81156014)(81166006)(7059030)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR0301MB0743;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD027;1:fHFhjo9Jqk+LVHX+JP/LRmJiaq73RU5LyuFExxMDdfzq8h1yXK4qGIhmZPRJNQ+bDhsQhiD8ygV6V5p0sni7jov+DFmfX+aAEPNr4MYtpwtU/NxzMgkpuR8GoRlh2L6VbM0LXW5psFqVA7/quyqV9OBipf3SNVferewySz3k9HwRVsdiTTcqklk/Ad/pU7FdOwHQ7DUWCX1v91mxnhTm4geONeTwsThdX76s9QqLoehdoymVVuYT+FL1lvHQEDRw4GX0ZJwpKbc8ith+yfP+679jVvM/UtodlgvAlhpb9RIxRhFo0GBz5+mSMKTCsnedM3qQW2XJlj6RB0yKNd7G6373nvN0ib3o4NAJP3icynD5N+07pvcAa6GVcXNE77kl+vBMFD9VPrzNeFBMKEkLw7xw7JAiiEvw4mtsRqp/DsotcP+jwTpTZfGND/FlgwVozVH9UTAwDwK8qAqBDBsuokvoKcahSOn8LAyb4Cd7zRQ/sPaTnh7R5O0Q69tKlcHL9rSpeFrMj1IqOmyJD4NG6BPavxcb0MNAAhVYACG1y2Y+wtNZIhKAGw8F4bjBCKRPRsSpqxYJlPIxGZs95f8yOHXssBdsmewk3NR9bqHKk0rwlAkNXsXOiCk3ArdPVK+cDy+I1LssJnawd7LH59A2Z80JPiY8vJpfl5BLI0FMJuXJO6//Tf9anWs1/XLABCk2RlTFK5G7u2ge5hsQBmL5vdZZGznNuYK3ue6+SZoK3Lg= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 203518c7-6270-4b11-c0a1-08d425d207c9 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BY2PR0301MB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t/XtUYExbIlq68hFeEeOL5+gL3sfqYNqzymNjIfCKc8qxAYkq0bfeDx4Qiq9blxisejLLPM2Lz7cK34SzAGtHvOXwp5mrKusdG0aGSvb7P0+oAWb8z5lKj3AnosGDNlxwEIZ8JVOYD/hMU93HQiZkS18trVERukEWMPtmxmN8pHdhze/LKI7ZB7Azp+B8q/o= X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB0743;31:BTXKFnwcwtX6cRSvivsFIHzHrk0NMdFDRPBA5iI/g+j5OJZs8aw64kiEoUJ8Fo3KSK9U2o2VXx7iaH2YWuQ834FxaefekbApVS2V8rvgLJvxxYT4f/qQALu3SwEbKjKamNjo6HOgzeyOwokgLPUMFYzigT9wmb1W9uTgQZSQe7Km78Kkg4rtxDoEFW1baFn9zBFLOndWCOB9yDIjHD3CPwv2u/GjgWzLmX21lYBczwFnBVDd3fAqD+GeJNMmbOU7PX3hxKmPrg1yMCLBFwz05ddgR+qqsJJODUbEieaffZ2RhKnOgiKShlQQHxrYnKVX X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(275809806118684); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095060)(601004)(2401047)(8121501046)(5005006)(13023025)(13024025)(13017025)(13018025)(13015025)(10201501046)(3002001)(6055026)(6096035)(20161123561025)(20161123556025)(20161123559025)(20161123565025)(20161123563025);SRVR:BY2PR0301MB0743;BCL:0;PCL:0;RULEID:(400006);SRVR:BY2PR0301MB0743; X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB0743;4:A1zke+NGudM5JtuuRaDlYs9Lshi/Mvuy5+YCohnHJhymEQtn51V9/so60Da90DqIQhG9nR9gKOrJx2oYtUzB/hFiACgvVa2aY91hHJhFDhkQ/6Ql5Pb60X7iDT+IGBn7xh3oBU46Na15TXLTwe0/6GoAS9lHTA3uss201WV+V7lY7f/TcVH9/82QIqXfPLYX8NNRCb3krX7pmyW3DE0l0WHKHRRv1KvdiUe7u72rzvB8jEnxiqGmIIaBoRR3r1xPJN7c4JMx8YL4MfvtPXAR8vPZO7PbXWrDurrhlzO+n4w1XmwsyCdlNpVznyTKvriOHZ8Nw/sBFS/sxDLaHg017K3By6hZkmyAo89FogqIxICB2TzqjcrD+2I37OySLfb2SWSDjyZG5SJtMPONdUnk4jtVwezPsqEmOv962HKFqSqNMVqdU4TMeTLemd/BQWaH0AINtdPJ+yVnMSXoqY3rFX6Y/j4Z30HG6i6sPWbqIK8q8lzl49lmgesXw3kSbtezQubxcFZYzY6ise4jMq/BeCi2R7Ax0WcUMES+61VGMbefVmvvffac+CiCvNxT2UVK8mR1uTZYXiLdY29dPrcXvku/muBkjOQfZX1j4sYxab60YuZMuOUh1uNWykBRY+IQS5wAbR5d1PHZbeF2l67vameN8gnn5GoxUFGoG1wjyM9hD4DsBNV6mg4CzQ0jqHl2cvGJ1i9Z0xjJfY/tAOYKJx961TvR/StJ7IoBmn6llAjdRZ443LSxHIrbUMZVd8rQevEjxZ1X4+XMWDikDnsjXQ== X-Forefront-PRVS: 01583E185C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR0301MB0743;23:WhfIWwOuv29YowC5Oy34a2PL845igpHJ+pohN6b?= =?us-ascii?Q?4PZd7NKGmGbjkjTL6iujaOC8gCn1tZsj4j5Kj8Vbw8hI7ZFPkK/8AaHNmjUe?= =?us-ascii?Q?IehBqCbwQ64mHnFlNuHArC226ugzyJ/DW0d4nm1wJBwifz1/Jkn/Zm9ct0Tb?= =?us-ascii?Q?ebkotM9HTzSXES7rVyo+LJaneVQ8Fj14LSCNwDkO+81zWNM+OoeRAoRx8TRg?= =?us-ascii?Q?WWPFZT32shA2eAUxG4q6RHUfsY+RevvZV3nGoDuWm3IeJH7iAAKl66Xq20RH?= =?us-ascii?Q?lIPLvshkcTEo+DHB3VXqV0xNohSo+maV8SRxLwgjOD7APVwR7wiV9F0u76hi?= =?us-ascii?Q?HCygBxODDtTk/mjhCcmUbUr6U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?= =?us-ascii?Q?+kRG3vj274NJBQvEgHEct1xRTcUpPZ5dz25h4Vwh/U0lC9CGwMZqQqQ0c/fx?= =?us-ascii?Q?FSycauu75dwlISbdW6nYUUr8=3D?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB0743;6:HDXJBmS8XiIJowF4ArS8hVfrSlor8lfYAMjrMIGENEJF7Kue9oJ+kGQ33NkamTG5zwQGAMpKN1kx+K2ovwEQCOqHcuxvhVQ4PNiQeFhamU3nsN5N65knvV8wAkedjLLRqH64tsx52ictmKN33AN8EuCmp0Zy35P1qjNCiGF/h/NorQG8C42fFLz5YvTAg1hn8kxMLy4DQbmlI4A+FClBG/DcEOUmCiYiFEO1BZZORtKr1CEvBsiHpkJzh5x57DDR2nMjWy0FwOVXLYoLbpdCAzsaW991s+93D5+vf0CLfWyBW3wYYq8TjLCBPcAIJxlp0LrixoIRyfUxWIGnSTOyHIvIQTzE8WopL2NVGkIvFL4TGbuaAe9N9fEkuKOvXUfLCO4Nv9vxwbTSp7ofV9UPhb6YB4fM3LlEvlypJR8Yt6/SW2PPh4JVjpui3PoEq0Mg;5:xCc6HEK4HdZGz/dVedjXpMBwiIQACWZAHEDtmqN2QgQFHHOed/8UIl/PnuuHILzk2G53gTTPKKrLxtyHyAbQgiV6EzFjeueld3bL6v6zicKDOqB029NW/TaOzf7lGShsnXg1+E9PxwYNu6vUsySFf89tyxp1DNlek01lyhOnubhHj6QXgYe5BfRy5iFo7SYO;24:fW8is/Z1TqvFpk7VdEEWetxlRBlNyz5TcjDLqAClUjOYRQkrWzeTzzOTm4bEulSQtXPn3u2pWC/XwBZofF4E0eFgmma2Fqvyjm1C0rvwg+w= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB0743;7:hk9Kpvtz5IcBFpahh6AbbX6L7bBstF4D9aK/D+6K5/PDPyQVGNzF9CPA3q7Pkc14lp04ZMYG8uS93DLEwnqJ9+Q3zWRJ1DyJQ0NFMvxtAET3KBVfX7Y8zNseaF4cmI/OlHRP1AdjyAiyiakFkTGoAkP1QH7tTKnYuWV4UVHtp2JfS2R9BJXvHTvDVMsTfDvw8pzAdIRx+IU4cxpLf6xth5M8dp0etJD6bqvKsyqw7kv4leRmiapwaHtCaxNg3taIK1lnx+tmhJyl/B+6PWAxQ7enNsDwqg/X6DKwnD531ighagCvJEHBZnKMOu28rJCCyuvM2LWmZ4tO/rcPlbh8dlXBE7wjVX2E29MlSmd7hE1PEE/Ri2lsqbvH06L4F2ocrv/ct5tMVK6CrQqA9b0W34H4ftwsTCrHeOsRVwzVMnoD7MQI8zCrQQ/daZeajHK/wNANmiee1tJxa2xyHfk6Yg== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2016 16:38:56.7920 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB0743 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9887 Lines: 341 From: Roy Pledge The DPIO driver registers with the fsl-mc bus to handle bus-related events for DPIO objects. Key responsibility is mapping I/O regions, setting up interrupt handlers, and calling the DPIO service initialization during probe. Signed-off-by: Roy Pledge Signed-off-by: Haiying Wang Signed-off-by: Stuart Yoder --- Notes: -v4 -updated copyright -adjust file location to be in drivers/staging -whitespace alignment cleanup -v3 -no changes -v2 -handle error case where number of DPIOs > NR_CPUs drivers/staging/fsl-mc/bus/dpio/Makefile | 2 +- drivers/staging/fsl-mc/bus/dpio/dpio-driver.c | 296 ++++++++++++++++++++++++++ 2 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio-driver.c diff --git a/drivers/staging/fsl-mc/bus/dpio/Makefile b/drivers/staging/fsl-mc/bus/dpio/Makefile index 0778da7..837d330 100644 --- a/drivers/staging/fsl-mc/bus/dpio/Makefile +++ b/drivers/staging/fsl-mc/bus/dpio/Makefile @@ -6,4 +6,4 @@ subdir-ccflags-y := -Werror obj-$(CONFIG_FSL_MC_DPIO) += fsl-mc-dpio.o -fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o +fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o dpio-driver.o diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c new file mode 100644 index 0000000..e36da20 --- /dev/null +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c @@ -0,0 +1,296 @@ +/* + * Copyright 2014-2016 Freescale Semiconductor Inc. + * Copyright NXP 2016 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Freescale Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../include/mc.h" +#include "../../include/dpaa2-io.h" + +#include "qbman-portal.h" +#include "dpio.h" +#include "dpio-cmd.h" + +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_AUTHOR("Freescale Semiconductor, Inc"); +MODULE_DESCRIPTION("DPIO Driver"); + +struct dpio_priv { + struct dpaa2_io *io; +}; + +static irqreturn_t dpio_irq_handler(int irq_num, void *arg) +{ + struct device *dev = (struct device *)arg; + struct dpio_priv *priv = dev_get_drvdata(dev); + + return dpaa2_io_irq(priv->io); +} + +static void unregister_dpio_irq_handlers(struct fsl_mc_device *dpio_dev) +{ + struct fsl_mc_device_irq *irq; + + irq = dpio_dev->irqs[0]; + + /* clear the affinity hint */ + irq_set_affinity_hint(irq->msi_desc->irq, NULL); +} + +static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int cpu) +{ + struct dpio_priv *priv; + int error; + struct fsl_mc_device_irq *irq; + cpumask_t mask; + + priv = dev_get_drvdata(&dpio_dev->dev); + + irq = dpio_dev->irqs[0]; + error = devm_request_irq(&dpio_dev->dev, + irq->msi_desc->irq, + dpio_irq_handler, + 0, + dev_name(&dpio_dev->dev), + &dpio_dev->dev); + if (error < 0) { + dev_err(&dpio_dev->dev, + "devm_request_irq() failed: %d\n", + error); + return error; + } + + /* set the affinity hint */ + cpumask_clear(&mask); + cpumask_set_cpu(cpu, &mask); + if (irq_set_affinity_hint(irq->msi_desc->irq, &mask)) + dev_err(&dpio_dev->dev, + "irq_set_affinity failed irq %d cpu %d\n", + irq->msi_desc->irq, cpu); + + return 0; +} + +static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) +{ + struct dpio_attr dpio_attrs; + struct dpaa2_io_desc desc; + struct dpio_priv *priv; + int err = -ENOMEM; + struct device *dev = &dpio_dev->dev; + static int next_cpu = -1; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + goto err_priv_alloc; + + dev_set_drvdata(dev, priv); + + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io); + if (err) { + dev_dbg(dev, "MC portal allocation failed\n"); + err = -EPROBE_DEFER; + goto err_mcportal; + } + + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id, + &dpio_dev->mc_handle); + if (err) { + dev_err(dev, "dpio_open() failed\n"); + goto err_open; + } + + err = dpio_get_attributes(dpio_dev->mc_io, 0, dpio_dev->mc_handle, + &dpio_attrs); + if (err) { + dev_err(dev, "dpio_get_attributes() failed %d\n", err); + goto err_get_attr; + } + desc.qman_version = dpio_attrs.qbman_version; + + err = dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + if (err) { + dev_err(dev, "dpio_enable() failed %d\n", err); + goto err_get_attr; + } + + /* initialize DPIO descriptor */ + desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0; + desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0; + desc.dpio_id = dpio_dev->obj_desc.id; + + /* get the cpu to use for the affinity hint */ + if (next_cpu == -1) + next_cpu = cpumask_first(cpu_online_mask); + else + next_cpu = cpumask_next(next_cpu, cpu_online_mask); + + if (!cpu_possible(next_cpu)) { + dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n"); + err = -ERANGE; + goto err_allocate_irqs; + } + desc.cpu = next_cpu; + + /* + * Set the CENA regs to be the cache inhibited area of the portal to + * avoid coherency issues if a user migrates to another core. + */ + desc.regs_cena = ioremap_wc(dpio_dev->regions[1].start, + resource_size(&dpio_dev->regions[1])); + desc.regs_cinh = ioremap(dpio_dev->regions[1].start, + resource_size(&dpio_dev->regions[1])); + + err = fsl_mc_allocate_irqs(dpio_dev); + if (err) { + dev_err(dev, "fsl_mc_allocate_irqs failed. err=%d\n", err); + goto err_allocate_irqs; + } + + err = register_dpio_irq_handlers(dpio_dev, desc.cpu); + if (err) + goto err_register_dpio_irq; + + priv->io = dpaa2_io_create(&desc); + if (!priv->io) { + dev_err(dev, "dpaa2_io_create failed\n"); + goto err_dpaa2_io_create; + } + + dev_info(dev, "probed\n"); + dev_dbg(dev, " receives_notifications = %d\n", + desc.receives_notifications); + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + fsl_mc_portal_free(dpio_dev->mc_io); + + return 0; + +err_dpaa2_io_create: + unregister_dpio_irq_handlers(dpio_dev); +err_register_dpio_irq: + fsl_mc_free_irqs(dpio_dev); +err_allocate_irqs: + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); +err_get_attr: + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); +err_open: + fsl_mc_portal_free(dpio_dev->mc_io); +err_mcportal: + dev_set_drvdata(dev, NULL); +err_priv_alloc: + return err; +} + +/* Tear down interrupts for a given DPIO object */ +static void dpio_teardown_irqs(struct fsl_mc_device *dpio_dev) +{ + unregister_dpio_irq_handlers(dpio_dev); + fsl_mc_free_irqs(dpio_dev); +} + +static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev) +{ + struct device *dev; + struct dpio_priv *priv; + int err; + + dev = &dpio_dev->dev; + priv = dev_get_drvdata(dev); + + dpaa2_io_down(priv->io); + + dpio_teardown_irqs(dpio_dev); + + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io); + if (err) { + dev_err(dev, "MC portal allocation failed\n"); + goto err_mcportal; + } + + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id, + &dpio_dev->mc_handle); + if (err) { + dev_err(dev, "dpio_open() failed\n"); + goto err_open; + } + + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + + fsl_mc_portal_free(dpio_dev->mc_io); + + dev_set_drvdata(dev, NULL); + + return 0; + +err_open: + fsl_mc_portal_free(dpio_dev->mc_io); +err_mcportal: + return err; +} + +static const struct fsl_mc_device_id dpaa2_dpio_match_id_table[] = { + { + .vendor = FSL_MC_VENDOR_FREESCALE, + .obj_type = "dpio", + }, + { .vendor = 0x0 } +}; + +static struct fsl_mc_driver dpaa2_dpio_driver = { + .driver = { + .name = KBUILD_MODNAME, + .owner = THIS_MODULE, + }, + .probe = dpaa2_dpio_probe, + .remove = dpaa2_dpio_remove, + .match_id_table = dpaa2_dpio_match_id_table +}; + +static int dpio_driver_init(void) +{ + return fsl_mc_driver_register(&dpaa2_dpio_driver); +} + +static void dpio_driver_exit(void) +{ + fsl_mc_driver_unregister(&dpaa2_dpio_driver); +} +module_init(dpio_driver_init); +module_exit(dpio_driver_exit); -- 1.9.0