From patchwork Mon Dec 18 09:18:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 10118551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AEFD56019C for ; Mon, 18 Dec 2017 09:19:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A678D28DC5 for ; Mon, 18 Dec 2017 09:19:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B13E28ECC; Mon, 18 Dec 2017 09:19:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1E80D28DC5 for ; Mon, 18 Dec 2017 09:19:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=weegGY2tjmFJJ424ZIBv5kht1EodoSUk7xvKVQBb7Gg=; b=u+dutPuyjqiYlTHrmJxrj+jEO+ mZaRkBWVyxeR5zns/9adH6TTSAEgY3O2lPp/UMipVR9J/JWO96Hi3K5TUkX4ZL761vsINXYkEWdL3 SmduNXyvCa+qYFTNkBS4qN8K04KIf7W/RjaK+NTkh49fcf8TW6BIPAhfUfLTAeSe8cmsFxBVdHxc5 Gl/2xEsyGBUJgHNeYFhvucsZtjd+YqfYLSNg0DkyMJu2PDky5Sh/AoMS+RCGsB59v5guK4zkZxjoK s1GWYY9w213oq6vN4QGWCxG/aPQpcIm6cY1YvokAQnA2AEomslDjpcHsWBKMEkKVjMQczQ2XWWqKD JQppWaVA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eQraU-0006V8-AP; Mon, 18 Dec 2017 09:19:54 +0000 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eQrZI-0005Lq-Jk for linux-arm-kernel@lists.infradead.org; Mon, 18 Dec 2017 09:18:51 +0000 Received: by mail-lf0-x244.google.com with SMTP id j124so16949511lfg.2 for ; Mon, 18 Dec 2017 01:18:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V6c/fgwy55nbCFI7VAWAtG97lHlAQpLwz6l8MV90oKo=; b=pguGqqBrMYGAZ55g8o/TuL6lQv6Q9u8YztYs847r1RVlBxDzoMHfQzPtrH6sbT9mjm o72UbynDq/6+xeUnWMMM34kh/NkmCDuGEyYW+vdwdJuJccm7Ms7HW1L9tXhY4GVzUX9D TEOriOEifKOx9Y1cpNetTJth4/4vmtj0V24AiTi4CJgpw36rpKwvW9D2lNRv7xkKNMFX H5KDVS1aZUAXOIOexPBZpcVZbBvtQc2gIq9yC5xy4xQkQliCs1Jjsezv63+80RVnpX9V MArm5ZQ083QhdHpNdIdmn8l7SHjVFM/hoUn8J95ZURudl4FTMVRFVlo8WaWgWCCyagaQ +amA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=V6c/fgwy55nbCFI7VAWAtG97lHlAQpLwz6l8MV90oKo=; b=NbfGxwL5EmdMLGq7m/5YgJ3ln9NJuIuxY/Wz1d6xrspYHNeSKUPwlQiLH49NDF8ZDN 8KAOhjJRw2RPc1pK2iyW3O3wQMuolXFrDBC3XrAzIjV+39vVPmTrr2X0GwDGl1C4fDaG HGOOwXuwOJQHpAdh8lOyLZ0Scx9sdISI4lFNyWExaOYk3XJGtUczRbFwwczb/MBC4UEW Mw1Qk6M84zFaIDaeHLXjaebHNA9/yMKUMiL7mGOlCER9c/Yx8i9boxxQ1Jyq/n1R4tQa IjYMGDqvUeITo1c+IP+LDOgVradBF6+MfD1AFebb55UIVcwHaykUjfww1AURdNb/8aO5 EqjQ== X-Gm-Message-State: AKGB3mIXr7Xofuu9KfpniIZb/gwT8/Fg1wIAffTQBI0bNBCUNTylaLYk wpJ4RIdFwHX3GiM0pJYmZUvq4oLlqqU= X-Google-Smtp-Source: ACJfBosHiG/aKLU2LurGkgoBKKbpreCVmSVBQvb0z5+83TA/Vyh+6j8O0p6h9suzG2NH71sYOg7OSw== X-Received: by 10.46.34.134 with SMTP id i128mr10272379lji.11.1513588698230; Mon, 18 Dec 2017 01:18:18 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r16sm2407186ljd.18.2017.12.18.01.18.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 01:18:17 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Subject: [net-next: PATCH 4/8] net: mvmdio: add ACPI support Date: Mon, 18 Dec 2017 10:18:00 +0100 Message-Id: <1513588684-15647-5-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513588684-15647-1-git-send-email-mw@semihalf.com> References: <1513588684-15647-1-git-send-email-mw@semihalf.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171218_011841_625451_84D7085E X-CRM114-Status: GOOD ( 18.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thomas.petazzoni@free-electrons.com, andrew@lunn.ch, f.fainelli@gmail.com, linux@arm.linux.org.uk, ard.biesheuvel@linaro.org, jaz@semihalf.com, antoine.tenart@free-electrons.com, rafael.j.wysocki@intel.com, nadavh@marvell.com, neta@marvell.com, ezequiel.garcia@free-electrons.com, tn@semihalf.com, gregory.clement@free-electrons.com, mw@semihalf.com, davem@davemloft.net MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch introducing ACPI support for the mvmdio driver by adding acpi_match_table with two entries: * "MRVL0100" for the SMI operation * "MRVL0101" for the XSMI mode Also clk enabling is skipped, because the tables do not contain such data and clock maintenance relies on the firmware. The MDIO bus is registered using newly introduced fwnode_mdiobus_register(). Memory region used by mvmdio driver is usually placed in the middle of the address space of the network controller (e.g. NETA or PP2). The MDIO base address is obtained without requesting memory region (by devm_ioremap() call), later overlapping resources are requested by the network driver, where care is taken to avoid concurrent access. This way of solving problem occurred to be not sufficient with ACPI, because resources declared in the table and used once, appear as 'in-use' in the OS. This patch also ensures releasing resources by mvmdio driver prior to initializing the network controller driver. Signed-off-by: Marcin Wojtas --- drivers/net/ethernet/marvell/mvmdio.c | 42 +++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 0495487..31d758a 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -17,6 +17,7 @@ * warranty of any kind, whether express or implied. */ +#include #include #include #include @@ -279,9 +280,19 @@ static int orion_mdio_probe(struct platform_device *pdev) struct resource *r; struct mii_bus *bus; struct orion_mdio_dev *dev; + const struct acpi_device_id *acpi_id; + bool use_acpi = false; int i, ret; - type = (enum orion_mdio_bus_type)of_device_get_match_data(&pdev->dev); + if (has_acpi_companion(&pdev->dev)) { + acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table, + &pdev->dev); + type = (enum orion_mdio_bus_type)acpi_id->driver_data; + use_acpi = true; + } else { + type = + (enum orion_mdio_bus_type)of_device_get_match_data(&pdev->dev); + } r = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!r) { @@ -319,7 +330,7 @@ static int orion_mdio_probe(struct platform_device *pdev) init_waitqueue_head(&dev->smi_busy_wait); - for (i = 0; i < ARRAY_SIZE(dev->clk); i++) { + for (i = 0; !use_acpi && i < ARRAY_SIZE(dev->clk); i++) { dev->clk[i] = of_clk_get(pdev->dev.of_node, i); if (IS_ERR(dev->clk[i])) break; @@ -350,6 +361,8 @@ static int orion_mdio_probe(struct platform_device *pdev) if (pdev->dev.of_node) ret = of_mdiobus_register(bus, pdev->dev.of_node); + else if (use_acpi) + ret = fwnode_mdiobus_register(bus, pdev->dev.fwnode); else ret = mdiobus_register(bus); if (ret < 0) { @@ -357,6 +370,15 @@ static int orion_mdio_probe(struct platform_device *pdev) goto out_mdio; } + /* In case of ACPI resources declared in the tables and used + * once, appear as 'in-use' in the OS. Make sure they are released, + * before the network driver possibly requests it again during + * its initialization. The care is taken there to avoid + * concurrent access to this memory region. + */ + if (use_acpi) + release_resource(r); + platform_set_drvdata(pdev, bus); return 0; @@ -365,6 +387,11 @@ static int orion_mdio_probe(struct platform_device *pdev) if (dev->err_interrupt > 0) writel(0, dev->regs + MVMDIO_ERR_INT_MASK); + if (use_acpi) { + release_resource(r); + return ret; + } + for (i = 0; i < ARRAY_SIZE(dev->clk); i++) { if (IS_ERR(dev->clk[i])) break; @@ -385,6 +412,9 @@ static int orion_mdio_remove(struct platform_device *pdev) writel(0, dev->regs + MVMDIO_ERR_INT_MASK); mdiobus_unregister(bus); + if (has_acpi_companion(&pdev->dev)) + return 0; + for (i = 0; i < ARRAY_SIZE(dev->clk); i++) { if (IS_ERR(dev->clk[i])) break; @@ -402,12 +432,20 @@ static const struct of_device_id orion_mdio_match[] = { }; MODULE_DEVICE_TABLE(of, orion_mdio_match); +static const struct acpi_device_id orion_mdio_acpi_match[] = { + { "MRVL0100", BUS_TYPE_SMI }, + { "MRVL0101", BUS_TYPE_XSMI }, + { }, +}; +MODULE_DEVICE_TABLE(acpi, orion_mdio_acpi_match); + static struct platform_driver orion_mdio_driver = { .probe = orion_mdio_probe, .remove = orion_mdio_remove, .driver = { .name = "orion-mdio", .of_match_table = orion_mdio_match, + .acpi_match_table = ACPI_PTR(orion_mdio_acpi_match), }, };