From patchwork Mon Apr 24 12:34:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Shubin X-Patchwork-Id: 86982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2643680vqo; Mon, 24 Apr 2023 03:36:05 -0700 (PDT) X-Google-Smtp-Source: AKy350Ym22GCjeTFzanOAxCtHAG556VbYlt5kj2FotijqWRqYDgN5OTOgI6QcPHyIOCZNkAkzWHC X-Received: by 2002:a17:90b:1c8f:b0:249:822d:e5bc with SMTP id oo15-20020a17090b1c8f00b00249822de5bcmr12464839pjb.5.1682332565356; Mon, 24 Apr 2023 03:36:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682332565; cv=none; d=google.com; s=arc-20160816; b=kLCiKyKcvutLa0TFiEWcn3QypfKoieCAEoP9b/CiukjXLYYUdLTyXpjCmqxmA3if3O wjYLzo2QDscUDPi924iEsWmp7c7pBfQ0iWWWsBz/MhYx1cYsxjcRfktqAsnAQkLu0EmM EpraCUHkT9c/BVQkuQzrpTMRRw3QR9yYV136/Zhb6jPVakZcGkDhenmgEIYFqN49zmlB wneu4cU4c0npRU66XMgaQC55qY+zSm5yTMglj7VKJU27GxnXl5buKGtUAcucXbx6bCPP NZvC0ukcezFGcQ8u8Bk+IAdpp4wDvc1Zh8RhfgFNqgO/oZvLywFtsb7zGXWZYpRY+D2M Mbfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=H/MzURm8LBkdmNsr58WR1SK4CDr2JEUu6baOETb8+Wg=; b=syE/NU6BgLxvxilhybqt9EALDlfIPpNtbboo+IHYEH/Dckf7uoKDVHQ8UYxUJzqMpG FFUH5Gyxv0dJfYL73kfk/w4z212Vy9kUYGE5miZmL+HOUT2/IN0/NJuIm3o8ouG3XLSI tlrJGYP/qJYrij+XlbY5Ha2AohOQDlt9yA4dNZ0P3gYL4hl2QV8sDvlrE8HemSOTmwww pPnZo/hh58eKZYKx/k06ze4e1kiwWsHShCJkCrI66Xskrq1vESdj/m3b1W6l4rmA6VhX 6TwdHnOmgXVrIgppdRzMeFkeMTknS0fqa8H4DpLtU2yYDFJwtVCwRFDZ6CzD2gZ8+YFo PmqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@maquefel.me header.s=mail header.b=tYpH8ota; 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 s1-20020a63dc01000000b005250c235984si3769607pgg.860.2023.04.24.03.35.50; Mon, 24 Apr 2023 03:36:05 -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=fail header.i=@maquefel.me header.s=mail header.b=tYpH8ota; 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 S231315AbjDXKfJ (ORCPT + 99 others); Mon, 24 Apr 2023 06:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231223AbjDXKeq (ORCPT ); Mon, 24 Apr 2023 06:34:46 -0400 Received: from forward502c.mail.yandex.net (forward502c.mail.yandex.net [178.154.239.210]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E42C8E68; Mon, 24 Apr 2023 03:34:22 -0700 (PDT) Received: from mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:261e:0:640:2e3d:0]) by forward502c.mail.yandex.net (Yandex) with ESMTP id 2A07A5ECF3; Mon, 24 Apr 2023 12:35:52 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id JZBb1pbWwKo0-bZjfcDZh; Mon, 24 Apr 2023 12:35:51 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1682328951; bh=H/MzURm8LBkdmNsr58WR1SK4CDr2JEUu6baOETb8+Wg=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=tYpH8otaP3x9f/8bRSAqZu82nnrxTEkZHlayhCB9QMaQcNZBH0DY//Dg5uGzu+1ns KYepJxdWKlIOUaF3KNmwGNqIfoWpcK2LJ+vK6ddbxRuwOghoWcuZzEEEjYOl3EjVFS 1YyW/N6nmcrttqIhmnf0ys65Wv67QgrP9FIDzwT4= Authentication-Results: mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net; dkim=pass header.i=@maquefel.me From: Nikita Shubin Cc: Arnd Bergmann , Linus Walleij , Alexander Sverdlin , Hartley Sweeten , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 19/43] net: cirrus: add DT support for Cirrus EP93xx Date: Mon, 24 Apr 2023 15:34:35 +0300 Message-Id: <20230424123522.18302-20-nikita.shubin@maquefel.me> X-Mailer: git-send-email 2.39.2 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,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 To: unlisted-recipients:; (no To-header on input) 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?1764053551852101156?= - 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 --- Notes: rfc->v0 Fixed warnings on "(base_addr == NULL)", pace required before the open parenthesis '('. Arnd Bergmann: - wildcards ep93xx to something meaningful, i.e. ep9301 - drop wrappers drivers/net/ethernet/cirrus/ep93xx_eth.c | 49 +++++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c index 8627ab19d470..b156cc75daad 100644 --- a/drivers/net/ethernet/cirrus/ep93xx_eth.c +++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include #include @@ -792,6 +794,8 @@ static int ep93xx_eth_probe(struct platform_device *pdev) struct net_device *dev; struct ep93xx_priv *ep; struct resource *mem; + void __iomem *base_addr; + struct device_node *np; int irq; int err; @@ -804,6 +808,38 @@ static int ep93xx_eth_probe(struct platform_device *pdev) if (!mem || irq < 0) return -ENXIO; + base_addr = ioremap(mem->start, resource_size(mem)); + if (!base_addr) { + dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n"); + return -EIO; + } + + if (!data) { + np = pdev->dev.of_node; + if (IS_ENABLED(CONFIG_OF) && np) { + u32 phy_id; + + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + if (of_property_read_bool(np, "copy_addr")) { + memcpy_fromio(data->dev_addr, base_addr + 0x50, 6); + dev_info(&pdev->dev, "MAC=%pM\n", data->dev_addr); + } + + if (of_property_read_u32(np, "phy_id", &phy_id)) { + dev_err(&pdev->dev, "Failed to parse \"phy_id\"\n"); + return -ENOENT; + } + + data->phy_id = phy_id; + } + } + + if (!data) + return -ENOENT; + dev = ep93xx_dev_alloc(data); if (dev == NULL) { err = -ENOMEM; @@ -824,12 +860,7 @@ 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; @@ -859,12 +890,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" }, + {}, +}; +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, }, };