From patchwork Thu Jun 1 05:45:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Shubin X-Patchwork-Id: 13263028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF776C77B7E for ; Thu, 1 Jun 2023 05:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=m3BP32doWbmZ7hoaAOlOlqDyDGu7F76Bif6uEQF3aCU=; b=dnOAZZjt0io+l/ HcUY1jWL/eVeCGOaNZqVriDb+Jll3fdZfabICm+86m9yGEZm6cERFkLpkaR7LZEL3DOSsSDO0+JzL 28kPGAzviwbb2blShiHCgn3WVSMIAIIXqL58BN9g+ykL3fwjhstit6TlGgRMX986UHadOdsHFil1A ajcVMRIHqyxaow1Yf1Kb5S2k4gZXF4tY+GmlxwegQCdCzLTrq3Lfge0/YgWGubbk3DPQ++aSibnvR eb/xqQQ5wF/z0PUgnHvz8OUXdeEEX1xjPTKtI2sFwu4ta3AYhPA4tWe7brQo9ufUXy3bCUDKpwmuX DEplx89WK80cK2LUr5ZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q4b8N-0024Au-00; Thu, 01 Jun 2023 05:46:03 +0000 Received: from forward102a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:d102]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q4b8K-00249k-1q for linux-arm-kernel@lists.infradead.org; Thu, 01 Jun 2023 05:46:02 +0000 Received: from mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:5e51:0:640:23ee:0]) by forward102a.mail.yandex.net (Yandex) with ESMTP id 033424231D; Thu, 1 Jun 2023 08:45:55 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id pjGDMhnDduQ0-aOvwslIN; Thu, 01 Jun 2023 08:45:54 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1685598354; bh=DFRrRs5yJB6I1NZ9/5/odctWMT+EMqwMMh4rTW/kIxM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=q0FI6OYNleFFyvjkySIRTvmRWW9IGtRpLHzuEmzI9GViPQq+8NKNZ6J96pZ8RCtfm 3p2fbF3ouAKcm9U16K45Kuv5AMjYp5dNUUq4/Dyjn99yYcox4xq/fBaBjlNdpSJ+sH 9BLp1zEsFd729J3y5Iu7J2yIU+Qc8RmesCe01kyg= Authentication-Results: mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net; dkim=pass header.i=@maquefel.me From: Nikita Shubin To: Alexander Sverdlin , Arnd Bergmann , Linus Walleij , Hartley Sweeten , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Nikita Shubin , Michael Peters , Kris Bahnsen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v1 20/43] net: cirrus: add DT support for Cirrus EP93xx Date: Thu, 1 Jun 2023 08:45:25 +0300 Message-Id: <20230601054549.10843-2-nikita.shubin@maquefel.me> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20230424123522.18302-1-nikita.shubin@maquefel.me> References: <20230424123522.18302-1-nikita.shubin@maquefel.me> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230531_224600_789812_1DBFFD48 X-CRM114-Status: GOOD ( 21.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org - find register range from the device tree - get "copy_addr" from the device tree - get phy_id from the device tree Signed-off-by: Nikita Shubin Reviewed-by: Linus Walleij Reviewed-by: Andrew Lunn Tested-by: Alexander Sverdlin --- Notes: v0 -> v1: - dropped platform data entirely - dropped copy_addr - use phy-handle instead of using non-conventional phy-id arch/arm/mach-ep93xx/platform.h | 2 +- drivers/net/ethernet/cirrus/ep93xx_eth.c | 67 +++++++++++++----------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/arch/arm/mach-ep93xx/platform.h b/arch/arm/mach-ep93xx/platform.h index 5fb1b919133f..3cf2113491d8 100644 --- a/arch/arm/mach-ep93xx/platform.h +++ b/arch/arm/mach-ep93xx/platform.h @@ -5,8 +5,8 @@ #ifndef __ASSEMBLY__ -#include #include +#include struct device; struct i2c_board_info; diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c index 8627ab19d470..41096d4830ff 100644 --- a/drivers/net/ethernet/cirrus/ep93xx_eth.c +++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c @@ -17,12 +17,11 @@ #include #include #include +#include #include #include #include -#include - #define DRV_MODULE_NAME "ep93xx-eth" #define RX_QUEUE_ENTRIES 64 @@ -738,25 +737,6 @@ static const struct net_device_ops ep93xx_netdev_ops = { .ndo_set_mac_address = eth_mac_addr, }; -static struct net_device *ep93xx_dev_alloc(struct ep93xx_eth_data *data) -{ - struct net_device *dev; - - dev = alloc_etherdev(sizeof(struct ep93xx_priv)); - if (dev == NULL) - return NULL; - - eth_hw_addr_set(dev, data->dev_addr); - - dev->ethtool_ops = &ep93xx_ethtool_ops; - dev->netdev_ops = &ep93xx_netdev_ops; - - dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; - - return dev; -} - - static int ep93xx_eth_remove(struct platform_device *pdev) { struct net_device *dev; @@ -788,27 +768,51 @@ static int ep93xx_eth_remove(struct platform_device *pdev) static int ep93xx_eth_probe(struct platform_device *pdev) { - struct ep93xx_eth_data *data; struct net_device *dev; struct ep93xx_priv *ep; struct resource *mem; + void __iomem *base_addr; + struct device_node *np; + u32 phy_id; int irq; int err; if (pdev == NULL) return -ENODEV; - data = dev_get_platdata(&pdev->dev); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); irq = platform_get_irq(pdev, 0); if (!mem || irq < 0) return -ENXIO; - dev = ep93xx_dev_alloc(data); + base_addr = ioremap(mem->start, resource_size(mem)); + if (!base_addr) { + dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n"); + return -EIO; + } + + np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0); + if (!np) { + dev_err(&pdev->dev, "Please provide \"phy-handle\"\n"); + return -ENODEV; + } + + if (of_property_read_u32(np, "reg", &phy_id)) { + dev_err(&pdev->dev, "Failed to locate \"phy_id\"\n"); + return -ENOENT; + } + + dev = alloc_etherdev(sizeof(struct ep93xx_priv)); if (dev == NULL) { err = -ENOMEM; goto err_out; } + + eth_hw_addr_set(dev, base_addr + 0x50); + dev->ethtool_ops = &ep93xx_ethtool_ops; + dev->netdev_ops = &ep93xx_netdev_ops; + dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; + ep = netdev_priv(dev); ep->dev = dev; SET_NETDEV_DEV(dev, &pdev->dev); @@ -824,15 +828,10 @@ static int ep93xx_eth_probe(struct platform_device *pdev) goto err_out; } - ep->base_addr = ioremap(mem->start, resource_size(mem)); - if (ep->base_addr == NULL) { - dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n"); - err = -EIO; - goto err_out; - } + ep->base_addr = base_addr; ep->irq = irq; - ep->mii.phy_id = data->phy_id; + ep->mii.phy_id = phy_id; ep->mii.phy_id_mask = 0x1f; ep->mii.reg_num_mask = 0x1f; ep->mii.dev = dev; @@ -859,12 +858,18 @@ static int ep93xx_eth_probe(struct platform_device *pdev) return err; } +static const struct of_device_id ep93xx_eth_of_ids[] = { + { .compatible = "cirrus,ep9301-eth" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, ep93xx_eth_of_ids); static struct platform_driver ep93xx_eth_driver = { .probe = ep93xx_eth_probe, .remove = ep93xx_eth_remove, .driver = { .name = "ep93xx-eth", + .of_match_table = ep93xx_eth_of_ids, }, };