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: 101725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp71475vqr; Wed, 31 May 2023 22:48:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ40LUfeORpgUyheoGDIBe2XR8pw2BjsoEJXQ86EkiYdxDynUVLB1DWPONfV3lCsLEpg1H7S X-Received: by 2002:a05:6808:14c7:b0:398:6292:23f5 with SMTP id f7-20020a05680814c700b00398629223f5mr8432276oiw.53.1685598496795; Wed, 31 May 2023 22:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685598496; cv=none; d=google.com; s=arc-20160816; b=YvS8JQMfI8LEzloN+B5J65zZw0UslS3HNblAu2j+gaTH9963ZGAy61YVC201OaVgd7 8tiPQ1uzU+WAbmHxvW6Npp+mQizwHeSsXfBxGY6oYPpQS39EA7rmPxshd6Zv62xHHGex VKaMKuaXq8sr9La+D5LB+HNVojWrpv/5FD9Djr2JBUaY0aFnsRZ9iuzkXd2elP+NoD4u cLuTW9acZ7OM+KDDnu4Sz/im98pEfCDHEmHbX8yj2vddnmnyiW7olGnkKBgVEVCkMFne /MgEag3JTa9gHBn49uYdWVM70H+ZsI0AlmsyGa9+GkmF+bhwbfet5X+MHcEuXFqKHNSL uLUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DFRrRs5yJB6I1NZ9/5/odctWMT+EMqwMMh4rTW/kIxM=; b=bpBYQPMLB+z2BQcIuwgMs/T+SvrLvusBdDkCzKT9Qoigurp25hUrU6Py2MWSJFdvQ+ b0ShVDS5XJsqsnbJs8JwUmlZUVZkl3bQK4BFWdtM+eReyKkIiSyUWZ21n1pK5bRkSPOT /zkNfQUySa1TSo64k4eqXmz35IzKdUcJ7JPQPoVegIr2yd5vLtVbNCBPDK+JrYDxWjHa RkRwROY72kFe/B8pVpRQL1wBCEasfwyU68NpttrIzuhFvCr/dLxXhIl+ERirsXYN1BSy PUlvifbwk7RGyKLCgIxmKzhihNnzXCku5f4yXMlmYdblmuHP72aPFA7G4sGlXst+w9wE YmYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@maquefel.me header.s=mail header.b=q0FI6OYN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a170902e94500b0019aa0d010eesi2140934pll.308.2023.05.31.22.48.02; Wed, 31 May 2023 22:48:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@maquefel.me header.s=mail header.b=q0FI6OYN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231388AbjFAFqC (ORCPT + 99 others); Thu, 1 Jun 2023 01:46:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231254AbjFAFp6 (ORCPT ); Thu, 1 Jun 2023 01:45:58 -0400 Received: from forward102a.mail.yandex.net (forward102a.mail.yandex.net [178.154.239.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E88CE2; Wed, 31 May 2023 22:45:56 -0700 (PDT) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764053551852101156?= X-GMAIL-MSGID: =?utf-8?q?1767478129287161176?= - 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, }, };