Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp118185ybz; Tue, 21 Apr 2020 05:56:37 -0700 (PDT) X-Google-Smtp-Source: APiQypKG+SFn5ZWZekBo7BWLhmxWufGVQoy5zg4YGcDD2yxiblUnMC7VTXLycjck0r1GBCR00yrb X-Received: by 2002:a17:906:1a06:: with SMTP id i6mr20570804ejf.90.1587473796966; Tue, 21 Apr 2020 05:56:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587473796; cv=none; d=google.com; s=arc-20160816; b=mDFL8JCb0CW/YmXIqNGq2g9hGNDD5J+OtwRxIWTpnj1AgplCqt2KzVpc8ae6pTGQbS vQ/ZK1dmyzygrWIjcwBNQIROtUZ+i+5oHrikf7occvnDAUkg5/ePXZdKdy6UJZYWjs1f 7KkSRSv3p5WJQ7sWn+5hKeaKrdL0EihpRnrXb/ySxizpcCG4cOulr6W2vNr1Df52307N q+kbf17IWDkDkqIHOJZgwXr5Dlui9f0+HKEE36bPwN5SP2VQbfYjc1D9lqAQUkVc4Wy6 yHCaz/LD1eFr+gKjjESujsjsqpEwCQ2ho+7Rs1G4nd2FYjW9xTmIKFrJKv+QtF9JcRrK BCqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pereMtLlV3kqHrXmPnv98GRn9CTFmlmpRx491TFUpTo=; b=BVz554GuEJjICbkTXrxy6r8cm+rKBV50Oysu6e6eRmZ/wcOvRBRiTPkjcRf3hG6FBV rBqLah1DC3kxWufAGsD2JLPaTWBpq7gkoz8GAmc+P3JxJzjPKZBAHZlMND0v6C5eWIm1 6Z3MND+iBThU6qbn2NwyRAXNut3pdQYG2ImhvGtZb5u3RYPK3+1st59EGVRRMFLNm8eG 67IGQy8VcIHWhNVQunG6Hez20UU5AndYtx6hOsDRVOGxTYQNqbFT4bUtaSuGP1NGg6/q PT3mFBFMHlDs7fQdAz345RYhgu01TfNZ/NU+RdiuzCAqdzKJGaJ3WuVzi8ZIt+xy3xOp O5vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m17si1491209eds.553.2020.04.21.05.56.13; Tue, 21 Apr 2020 05:56:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728909AbgDUMwr (ORCPT + 99 others); Tue, 21 Apr 2020 08:52:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728769AbgDUMwb (ORCPT ); Tue, 21 Apr 2020 08:52:31 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD1CBC061A41 for ; Tue, 21 Apr 2020 05:52:30 -0700 (PDT) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jQsNz-0004N6-SH; Tue, 21 Apr 2020 14:52:23 +0200 Received: from ore by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1jQsNx-0002JF-Gk; Tue, 21 Apr 2020 14:52:21 +0200 From: Oleksij Rempel To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Mark Rutland , Rob Herring Cc: Oleksij Rempel , Pengutronix Kernel Team , linux-kernel@vger.kernel.org, "David S. Miller" , netdev@vger.kernel.org, Marek Vasut , David Jander , devicetree@vger.kernel.org Subject: [PATCH net-next v4 4/4] net: phy: tja11xx: add delayed registration of TJA1102 PHY1 Date: Tue, 21 Apr 2020 14:52:19 +0200 Message-Id: <20200421125219.8402-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200421125219.8402-1-o.rempel@pengutronix.de> References: <20200421125219.8402-1-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TJA1102 is a dual PHY package with PHY0 having proper PHYID and PHY1 having no ID. On one hand it is possible to for PHY detection by compatible, on other hand we should be able to reset complete chip before PHY1 configured it, and we need to define dependencies for proper power management. We can solve it by defining PHY1 as child of PHY0: tja1102_phy0: ethernet-phy@4 { reg = <0x4>; interrupts-extended = <&gpio5 8 IRQ_TYPE_LEVEL_LOW>; reset-gpios = <&gpio5 9 GPIO_ACTIVE_LOW>; reset-assert-us = <20>; reset-deassert-us = <2000>; tja1102_phy1: ethernet-phy@5 { reg = <0x5>; interrupts-extended = <&gpio5 8 IRQ_TYPE_LEVEL_LOW>; }; }; The PHY1 should be a subnode of PHY0 and registered only after PHY0 was completely reset and initialized. Signed-off-by: Oleksij Rempel --- drivers/net/phy/nxp-tja11xx.c | 112 +++++++++++++++++++++++++++++++--- 1 file changed, 105 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c index a064e4ab3616..2bde9386baf1 100644 --- a/drivers/net/phy/nxp-tja11xx.c +++ b/drivers/net/phy/nxp-tja11xx.c @@ -6,11 +6,14 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #define PHY_ID_MASK 0xfffffff0 #define PHY_ID_TJA1100 0x0180dc40 @@ -57,6 +60,8 @@ struct tja11xx_priv { char *hwmon_name; struct device *hwmon_dev; + struct phy_device *phydev; + struct work_struct phy_register_work; }; struct tja11xx_phy_stats { @@ -333,16 +338,12 @@ static const struct hwmon_chip_info tja11xx_hwmon_chip_info = { .info = tja11xx_hwmon_info, }; -static int tja11xx_probe(struct phy_device *phydev) +static int tja11xx_hwmon_register(struct phy_device *phydev, + struct tja11xx_priv *priv) { struct device *dev = &phydev->mdio.dev; - struct tja11xx_priv *priv; int i; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL); if (!priv->hwmon_name) return -ENOMEM; @@ -360,6 +361,103 @@ static int tja11xx_probe(struct phy_device *phydev) return PTR_ERR_OR_ZERO(priv->hwmon_dev); } +static int tja11xx_probe(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + struct tja11xx_priv *priv; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->phydev = phydev; + + return tja11xx_hwmon_register(phydev, priv); +} + +static void tja1102_p1_register(struct work_struct *work) +{ + struct tja11xx_priv *priv = container_of(work, struct tja11xx_priv, + phy_register_work); + struct phy_device *phydev_phy0 = priv->phydev; + struct mii_bus *bus = phydev_phy0->mdio.bus; + struct device *dev = &phydev_phy0->mdio.dev; + struct device_node *np = dev->of_node; + struct device_node *child; + int ret; + + for_each_available_child_of_node(np, child) { + struct phy_device *phy; + int addr; + + addr = of_mdio_parse_addr(dev, child); + if (addr < 0) { + dev_err(dev, "Can't parse addr\n"); + continue; + } else if (addr != phydev_phy0->mdio.addr + 1) { + /* Currently we care only about double PHY chip TJA1102. + * If some day NXP will decide to bring chips with more + * PHYs, this logic should be reworked. + */ + dev_err(dev, "Unexpected address. Should be: %i\n", + phydev_phy0->mdio.addr + 1); + continue; + } + + if (mdiobus_is_registered_device(bus, addr)) { + dev_err(dev, "device is already registered\n"); + continue; + } + + /* Real PHY ID of Port 1 is 0 */ + phy = phy_device_create(bus, addr, PHY_ID_TJA1102, false, NULL); + if (IS_ERR(phy)) { + dev_err(dev, "Can't create PHY device for Port 1: %i\n", + addr); + continue; + } + + /* Overwrite parent device. phy_device_create() set parent to + * the mii_bus->dev, which is not correct in case. + */ + phy->mdio.dev.parent = dev; + + ret = __of_mdiobus_register_phy(bus, phy, child, addr); + if (ret) { + /* All resources needed for Port 1 should be already + * available for Port 0. Both ports use the same + * interrupt line, so -EPROBE_DEFER would make no sense + * here. + */ + dev_err(dev, "Can't register Port 1. Unexpected error: %i\n", + ret); + phy_device_free(phy); + } + } +} + +static int tja1102_p0_probe(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + struct tja11xx_priv *priv; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->phydev = phydev; + INIT_WORK(&priv->phy_register_work, tja1102_p1_register); + + ret = tja11xx_hwmon_register(phydev, priv); + if (ret) + return ret; + + schedule_work(&priv->phy_register_work); + + return 0; +} + static int tja1102_match_phy_device(struct phy_device *phydev, bool port0) { int ret; @@ -443,7 +541,7 @@ static struct phy_driver tja11xx_driver[] = { }, { .name = "NXP TJA1102 Port 0", .features = PHY_BASIC_T1_FEATURES, - .probe = tja11xx_probe, + .probe = tja1102_p0_probe, .soft_reset = tja11xx_soft_reset, .config_init = tja11xx_config_init, .read_status = tja11xx_read_status, -- 2.25.1