From patchwork Wed Feb 23 14:45:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1596756 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=wtuvJAFG; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K3f3y1sGSz9sGj for ; Thu, 24 Feb 2022 01:46:06 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 687E183A8D; Wed, 23 Feb 2022 15:45:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="wtuvJAFG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 38A7383C97; Wed, 23 Feb 2022 15:45:52 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3045983A8D for ; Wed, 23 Feb 2022 15:45:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x52d.google.com with SMTP id w3so44589851edu.8 for ; Wed, 23 Feb 2022 06:45:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xu9Orh1kslf1pcUXcrZt6WOzazvR9o1E+hpxGXLfasE=; b=wtuvJAFGf4FTSfmX8BnJ4epiziCgJZ6sNTMOizCTMhwClc0Ixlew6q7/MzIOPYJMvN 25YmeTUr+i+OOcLVLzPUMDRNI8P6MR8aJJfRzS/BzaaUpYjKpNIQACuvbk4B3yu+9rtg rD0pvDktHBmR5hhRwELp/nKd42g5f6Ablh4EQj5UQ4IB+48XPzOgtO+9Vmhl5k24ru85 irpLcARbgqNPaG3orz4pFG4jwEAsR97DoNJbgkS+jnwf5mZ4H7qeaMKiQs6AwJ/nBY5Y PAM9o5mKsPRGX+/sOjJ0xPWXxrfkwG6AtAKIyH6R5PsWf5a/s/+aGZtAGVHdtApRSZBr t16g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Xu9Orh1kslf1pcUXcrZt6WOzazvR9o1E+hpxGXLfasE=; b=X+kyQfKatsxrvooYsJ22xxVODAuy+DxtnAWl8gF1LldJaSPz3p5LzwkutioJtF06jb T4/8HxtCkiK6fot7/WikQmzHvnRrrlpZRxJJD8TkW4DtO/EJHPlrj9DVHrg+v5RP9DTW 3ZuxXpZLB+rqrHVxd2yG6qT1soK91Hrn2hGq41zoKE76wa05boaipkiwt3YB2PW/Znsn J5I7OYLnkN3nfgdz27O6sbBr0urMOwz6ebn9yPiSQIMV0lbRNoyzKLTqkbtlgVS9oHYn ZeqYpZJaq38W4bIeJTdd7z4frVL6am9wJeo7F0JyVTDRsxBEhoLkn5STAi3kMdV21QUy g3Hg== X-Gm-Message-State: AOAM5301/bzNUymkNF7gjY9xCjOFWJtOoF5NDcJE3NNKa2clSSz+8+We ySC6w/P6351RHjEASioovVodWqaJIY6BtA== X-Google-Smtp-Source: ABdhPJw5dHeazidFoZ7f4SnF2Jc+wN6IcrOz/hSG6/NDuY/k8h3/O/VshrxIk49RMqpB3KVswRjA+w== X-Received: by 2002:a05:6402:492:b0:404:c4bf:8b7e with SMTP id k18-20020a056402049200b00404c4bf8b7emr31048712edv.318.1645627545587; Wed, 23 Feb 2022 06:45:45 -0800 (PST) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id l19sm12354456edb.87.2022.02.23.06.45.45 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Feb 2022 06:45:45 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Joe Hershberger , Simon Glass Subject: [PATCH 1/3] net: phy: Add new read ethernet phy id function Date: Wed, 23 Feb 2022 15:45:40 +0100 Message-Id: <16019efb3820a50330935fdaae191cec1f101b5c.1645627539.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Add new function to get ethernet phy id from compatible property of the mdio phy node. Signed-off-by: Michal Simek Signed-off-by: T Karthik Reddy --- drivers/core/ofnode.c | 36 ++++++++++++++++++++++++++++++++++++ include/dm/ofnode.h | 13 +++++++++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 709bea272a6e..8042847f3c14 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -898,6 +898,42 @@ int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device) return -ENOENT; } +int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device) +{ + const char *list, *end; + int len; + + list = ofnode_get_property(node, "compatible", &len); + + if (!list) + return -ENOENT; + + end = list + len; + while (list < end) { + len = strlen(list); + + if (len >= strlen("ethernet-phy-idVVVV,DDDD")) { + char *s = strstr(list, "ethernet-phy-id"); + + /* + * check if the string is something like + * ethernet-phy-idVVVV,DDDD + */ + if (s && s[19] == '.') { + s += strlen("ethernet-phy-id"); + *vendor = simple_strtol(s, NULL, 16); + s += 5; + *device = simple_strtol(s, NULL, 16); + + return 0; + } + } + list += (len + 1); + } + + return -ENOENT; +} + int ofnode_read_addr_cells(ofnode node) { if (ofnode_is_np(node)) { diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0cb324c8b0c1..744dffe0a2dd 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -894,6 +894,19 @@ int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type, */ int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device); +/** + * ofnode_read_eth_phy_id() - look up eth phy vendor and device id + * + * Look at the compatible property of a device node that represents a eth phy + * device and extract phy vendor id and device id from it. + * + * @param node node to examine + * @param vendor vendor id of the eth phy device + * @param device device id of the eth phy device + * @return 0 if ok, negative on error + */ +int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device); + /** * ofnode_read_addr_cells() - Get the number of address cells for a node * From patchwork Wed Feb 23 14:45:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1596757 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=eR4Pj9OE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K3f481dLtz9sGj for ; Thu, 24 Feb 2022 01:46:16 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9BE7483CA3; Wed, 23 Feb 2022 15:46:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="eR4Pj9OE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6DB1E83C90; Wed, 23 Feb 2022 15:45:51 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D4B0E8354B for ; Wed, 23 Feb 2022 15:45:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62f.google.com with SMTP id gb39so53043572ejc.1 for ; Wed, 23 Feb 2022 06:45:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l108K6tZCdjqZq3QbUuUVnV8wcBj5sODLOSUgm2UVz8=; b=eR4Pj9OETSP0Ajb8ESpYKie5SAK2L3N5rD4pTlLPchM0bewVNix94mu1cApohpsTXk iGUf2bBX6FCOtp3znlcDoH6Iup8X9rTHEfOKUNuWdD/qrOBzFa0zDVSzjq7Lv8OchkNT 5KQYbgsk7oMhb5rSrcgiOW3SM745trcbqpTkyLAzM7PwLt+O6+vp2tUJZESffwHAlrhq lHNXxEXnVBsbbS0pRuLLVozbN4oXGKwUPF4KVgDcz/B1voqL+SMj+qe+Vl5KFWr3BM17 DYnAr8b92rzi2FrC8YAZexP6+BLQATezHK6dg56Dy4SO29eAT72c9Tbf/SCpBx81PG4p 7hsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=l108K6tZCdjqZq3QbUuUVnV8wcBj5sODLOSUgm2UVz8=; b=A0vKiyuTvsMvZtyso+U6jb1629GqmChnttUVwAcNMO1ZzH+Tb9q7ai0kpOaCOQeO/g NNxczT84lvULzZGKvp0w/W9/eSpPgaHZO3Xy51uiGY38d5+fozZpKqFVFJDWqvDLBADB nGCJWZI8jWlYHOPEG2CWC4lrhg7v1wEwj/PzGfHfVJT+qAq/3Rs6jTWJtlomxdG0iNYQ hLxznjX8J4nlAzToc6vm2hRcpakrQtbLXMlmYhO85AAYHkdQMuaVGTGv9DKXFG6LPR/h QiPWZQxwVUphZQhxdoVJ0OyrMz5hYTDdadcAxc2Fqm/cO5PZhVs9l9pyO+gHyLHxdOtU VWbQ== X-Gm-Message-State: AOAM5307QH8oa81/1kJhaD+/G9cRB/XKsgCUJgylrdQrzyVtPScEe1AH ahkjaZlut55UrMK1MeNQinB+0x4GJtxlyA== X-Google-Smtp-Source: ABdhPJzOciCopYI0dpgt2Xyhhr0bt7qQZICIN9mhW02iey3LyupHEsboVW7z49jzJnypCnslyjYj4Q== X-Received: by 2002:a17:906:e288:b0:6cf:bb19:bc23 with SMTP id gg8-20020a170906e28800b006cfbb19bc23mr51150ejb.73.1645627547190; Wed, 23 Feb 2022 06:45:47 -0800 (PST) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id bo11sm7488885ejb.24.2022.02.23.06.45.46 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Feb 2022 06:45:46 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Bin Meng , Joe Hershberger , Priyanka Jain , "Radu Pirea (NXP OSS)" , Ramon Fried , T Karthik Reddy , Vladimir Oltean , Wolfgang Denk Subject: [PATCH 2/3] net: phy: Remove static return type for phy_device_create() Date: Wed, 23 Feb 2022 15:45:41 +0100 Message-Id: <1517f4053403fbd53e899d500e7485d068a4f0b6.1645627539.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Remove static return type for phy_device_create() to avoid file scope for this function. Also add required prototype in phy.h. Signed-off-by: Michal Simek Signed-off-by: T Karthik Reddy --- drivers/net/phy/phy.c | 6 +++--- include/phy.h | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index c9fc20855ba1..f63705e1b9a1 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -659,9 +659,9 @@ static struct phy_driver *get_phy_driver(struct phy_device *phydev, return generic_for_interface(interface); } -static struct phy_device *phy_device_create(struct mii_dev *bus, int addr, - u32 phy_id, bool is_c45, - phy_interface_t interface) +struct phy_device *phy_device_create(struct mii_dev *bus, int addr, + u32 phy_id, bool is_c45, + phy_interface_t interface) { struct phy_device *dev; diff --git a/include/phy.h b/include/phy.h index c66fd43ea887..832d7a169578 100644 --- a/include/phy.h +++ b/include/phy.h @@ -454,6 +454,19 @@ void phy_connect_dev(struct phy_device *phydev, struct udevice *dev); struct phy_device *phy_connect(struct mii_dev *bus, int addr, struct udevice *dev, phy_interface_t interface); +/** + * phy_device_create() - Create a PHY device + * + * @bus: MII/MDIO bus that hosts the PHY + * @addr: PHY address on MDIO bus + * @phy_id: where to store the ID retrieved + * @is_c45: Device Identifiers if is_c45 + * @interface: interface between the MAC and PHY + * @return: pointer to phy_device if a PHY is found, or NULL otherwise + */ +struct phy_device *phy_device_create(struct mii_dev *bus, int addr, + u32 phy_id, bool is_c45, + phy_interface_t interface); static inline ofnode phy_get_ofnode(struct phy_device *phydev) { From patchwork Wed Feb 23 14:45:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1596758 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=7E+1FUpt; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K3f4L16jTz9sGj for ; Thu, 24 Feb 2022 01:46:26 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C544183CB6; Wed, 23 Feb 2022 15:46:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="7E+1FUpt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D4A878354B; Wed, 23 Feb 2022 15:45:56 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8DC9A83C37 for ; Wed, 23 Feb 2022 15:45:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62c.google.com with SMTP id a8so53056263ejc.8 for ; Wed, 23 Feb 2022 06:45:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JdPzxI6M3/Mp5JlIa+EB/SXiu8zcN6SFedkRSoE7u+Y=; b=7E+1FUptFlk1AhAZ170l8nL4BjK98Ul9b5ltZtjk9+DpNhJTpfE9hTMR5KyHC8ygRf LufNydBH5KxFcT63+Vi6rdHsEIq2z52g1/Q1j5rTtmbMpDWCuo1EDVv2yDCq6P7+9Cl6 sR0tzNSJD/8fmUW2gWmmAYgT94CQ7I/vZmCfxlG7y9mvkW7HCJczsuLVsBJaqinZwOM2 qzawarQMD2OTwS0bmEmCDD3DF1NZvkZvewQtEDy/wcfokME9lVUwa0Fq/oQvWaOenmAC AVu3imoMCIL6Vn6a77r2oEuLZ9SbZ/wmOKn8PI1o9lQB6FxprTe1+Tpvgv9MXNrU25Wh VoiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=JdPzxI6M3/Mp5JlIa+EB/SXiu8zcN6SFedkRSoE7u+Y=; b=bESz/eNv6lL/pW11ZFFyTW6KaKm2uE49m+i4emvqiwat1tEZ79eADL1AMdZhxkVR7W SGwsjLEs7JrG3vgaobQlcvqbfpwT26tFC53t4s7lJ2/On9KYEUsn5Sewz+fNHCGGXWm4 ifjqyCXmfEO+XXBBiQGrvqbtGjD/OSNwVzACoy69ILjIFtdwCEj/riiz+luhC5ARwCIY bRAJHJtY0Oyln9V7C/vDt3MPvve9jDxYxB+qESIZ6vD3BzwbxClpyHnm3C3K/4CPpZLl uy0tjghGoXrxEi6YTV/SWxxRkbQfdJ+BQxlnYIuIsX2um3Pv68baoboGP67xysAOl67j oi5w== X-Gm-Message-State: AOAM530gw4JMbewrQ5K6GLAQ34rUS1J9SuwgNX8QBRxWldbJ4qnVYLjw 1kmbVKLsD9a033FQe+aOjiB8QSOocObk3g== X-Google-Smtp-Source: ABdhPJyMV37U8zmgnMxSnP64VCfVqAmiFU0zMexxz9VI5fBeKrnZQaG/dU4XOEuIXggopbPyPTNm1g== X-Received: by 2002:a17:907:9719:b0:6d1:8c46:678d with SMTP id jg25-20020a170907971900b006d18c46678dmr77207ejc.168.1645627548773; Wed, 23 Feb 2022 06:45:48 -0800 (PST) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id f22sm12164591edf.95.2022.02.23.06.45.48 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Feb 2022 06:45:48 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Bin Meng , Christian Gmeiner , Dominic Rath , Joe Hershberger , Kuldeep Singh , Michal Simek , Priyanka Jain , "Radu Pirea (NXP OSS)" , Ramon Fried , Samuel Holland , T Karthik Reddy , Vladimir Oltean , Wolfgang Denk Subject: [PATCH 3/3] net: phy: Add support for ethernet-phy-id with gpio reset Date: Wed, 23 Feb 2022 15:45:42 +0100 Message-Id: <70ab7d71c812b2c972d48c129e416c921af0d7f5.1645627539.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Ethernet phy like dp83867 is using strapping resistors to setup PHY address. On Xilinx boards strapping is setup on wires which are connected to SOC where internal pull ups/downs influnce phy address. That's why there is a need to setup pins properly (via pinctrl driver for example) and then perform phy reset. I can be workarounded by reset gpio done for mdio bus but this is not working properly when multiply phys sitting on the same bus. That's why it needs to be done via ethernet-phy-id driver where dt binding has gpio reset per phy. DT binding is available here: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/net/ethernet-phy.yaml The driver is are reading the vendor and device id from valid phy node using ofnode_read_eth_phy_id() and creating a phy device. Kconfig PHY_ETHERNET_ID symbol is used because not every platform has gpio support. Signed-off-by: Michal Simek Signed-off-by: T Karthik Reddy --- MAINTAINERS | 1 + drivers/net/phy/Kconfig | 8 ++++ drivers/net/phy/Makefile | 1 + drivers/net/phy/ethernet_id.c | 69 +++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 5 +++ include/phy.h | 13 +++++++ 6 files changed, 97 insertions(+) create mode 100644 drivers/net/phy/ethernet_id.c diff --git a/MAINTAINERS b/MAINTAINERS index c1a5ac95f295..a75f429cb972 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -617,6 +617,7 @@ F: drivers/i2c/muxes/pca954x.c F: drivers/i2c/zynq_i2c.c F: drivers/mmc/zynq_sdhci.c F: drivers/mtd/nand/raw/zynq_nand.c +F: drivers/net/phy/ethernet_id.c F: drivers/net/phy/xilinx_phy.c F: drivers/net/zynq_gem.c F: drivers/pinctrl/pinctrl-zynqmp.c diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 4f8d33ce8fd5..74339a25ca53 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -307,6 +307,14 @@ config PHY_XILINX_GMII2RGMII as bridge between MAC connected over GMII and external phy that is connected over RGMII interface. +config PHY_ETHERNET_ID + bool "Read ethernet PHY id" + depends on DM_GPIO + default y if ZYNQ_GEM + help + Enable this config to read ethernet phy id from the phy node of DT + and create a phy device using id. + config PHY_FIXED bool "Fixed-Link PHY" depends on DM_ETH diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 77f7f606215c..b28440bc4e52 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -32,6 +32,7 @@ obj-$(CONFIG_PHY_TI_DP83867) += dp83867.o obj-$(CONFIG_PHY_TI_DP83869) += dp83869.o obj-$(CONFIG_PHY_XILINX) += xilinx_phy.o obj-$(CONFIG_PHY_XILINX_GMII2RGMII) += xilinx_gmii2rgmii.o +obj-$(CONFIG_PHY_ETHERNET_ID) += ethernet_id.o obj-$(CONFIG_PHY_VITESSE) += vitesse.o obj-$(CONFIG_PHY_MSCC) += mscc.o obj-$(CONFIG_PHY_FIXED) += fixed.o diff --git a/drivers/net/phy/ethernet_id.c b/drivers/net/phy/ethernet_id.c new file mode 100644 index 000000000000..5617ac3ad62f --- /dev/null +++ b/drivers/net/phy/ethernet_id.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Xilinx ethernet phy reset driver + * + * Copyright (C) 2022 Xilinx, Inc. + */ + +#include +#include +#include +#include +#include + +struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, + phy_interface_t interface) +{ + struct phy_device *phydev; + struct ofnode_phandle_args phandle_args; + struct gpio_desc gpio; + ofnode node; + u32 id, assert, deassert; + u16 vendor, device; + int ret; + + if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, + &phandle_args)) + return NULL; + + if (!ofnode_valid(phandle_args.node)) + return NULL; + + node = phandle_args.node; + + ret = ofnode_read_eth_phy_id(node, &vendor, &device); + if (ret) { + dev_err(dev, "Failed to read eth PHY id, err: %d\n", ret); + return NULL; + } + + ret = gpio_request_by_name_nodev(node, "reset-gpios", 0, &gpio, + GPIOD_ACTIVE_LOW); + if (!ret) { + assert = ofnode_read_u32_default(node, "reset-assert-us", 0); + deassert = ofnode_read_u32_default(node, + "reset-deassert-us", 0); + ret = dm_gpio_set_value(&gpio, 1); + if (ret) { + dev_err(dev, "Failed assert gpio, err: %d\n", ret); + return NULL; + } + + udelay(assert); + + ret = dm_gpio_set_value(&gpio, 0); + if (ret) { + dev_err(dev, "Failed deassert gpio, err: %d\n", ret); + return NULL; + } + + udelay(deassert); + } + + id = vendor << 16 | device; + phydev = phy_device_create(bus, 0, id, false, interface); + if (phydev) + phydev->node = node; + + return phydev; +} diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index f63705e1b9a1..fffa10f68b3c 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1047,6 +1047,11 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr, phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false, interface); #endif +#ifdef CONFIG_PHY_ETHERNET_ID + if (!phydev) + phydev = phy_connect_phy_id(bus, dev, interface); +#endif + #ifdef CONFIG_PHY_XILINX_GMII2RGMII if (!phydev) phydev = phy_connect_gmii2rgmii(bus, dev, interface); diff --git a/include/phy.h b/include/phy.h index 832d7a169578..9ea4bd42db4d 100644 --- a/include/phy.h +++ b/include/phy.h @@ -468,6 +468,19 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr, u32 phy_id, bool is_c45, phy_interface_t interface); +/** + * phy_connect_phy_id() - Connect to phy device by reading PHY id + * from phy node. + * + * @bus: MII/MDIO bus that hosts the PHY + * @dev: Ethernet device to associate to the PHY + * @interface: Interface between the MAC and PHY + * @return: pointer to phy_device if a PHY is found, + * or NULL otherwise + */ +struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, + phy_interface_t interface); + static inline ofnode phy_get_ofnode(struct phy_device *phydev) { if (ofnode_valid(phydev->node))