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: 849913 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="pguGqqBr"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z0b8L1lSVz9rxm for ; Mon, 18 Dec 2017 20:19:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933344AbdLRJSY (ORCPT ); Mon, 18 Dec 2017 04:18:24 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:36926 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933324AbdLRJST (ORCPT ); Mon, 18 Dec 2017 04:18:19 -0500 Received: by mail-lf0-f65.google.com with SMTP id a12so16945998lfe.4 for ; Mon, 18 Dec 2017 01:18:18 -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=Ak87f4DD6BISaWmbW4Z+Sb6oLwbkqprRH77nqIGOF4gqNr5spXhYhXq07XbhSxsXAP +nym7TP2zbTXSIj1afaOEHzYODx7gteAQbStsP0QE1Ng/nxhdDxrXZMEhUiMy7pj0ZSM RV9NpqKNaBkTxq3kCHKyAp6TfmKbKc/8VSFyP1TSrOYs/ZCo5zxRlOeZurQI1TQKI/F2 3dKAPRzv3hyelWE3XJ3rD6aD01K2zzB+IzpUAuTnN6asXT4iYuYQmzfT6T8Ae0hth26r 6Yv9VLyNs685OMj85hv8cxx6KJoUHLo1ONZJnk9SqmU6GwsrFDNfUAyrZx7ntC36mO2i Uh/g== X-Gm-Message-State: AKGB3mIgrJcHJqt5vfJfZic/1p/tp5mWhWZwl7eKc8W+t/2ravColctp ML+9aZYOTlbvcbZ+h/UQl/xsTg== 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 Cc: davem@davemloft.net, linux@arm.linux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, ezequiel.garcia@free-electrons.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com 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> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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), }, };