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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6EAFFC433F5 for ; Fri, 28 Jan 2022 08:13:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 658AF83885; Fri, 28 Jan 2022 09:12:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="Z9nVNYsX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C13FB837E7; Fri, 28 Jan 2022 09:12:24 +0100 (CET) Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 211B983863 for ; Fri, 28 Jan 2022 09:12:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=a-govindraju@ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 20S8CHhZ004058; Fri, 28 Jan 2022 02:12:17 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1643357537; bh=fyZ1c5mbCHRa5HW9He09iY3vGawxehmTSlRd7Ohc/Pc=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Z9nVNYsXwbLi98FmjtmT23Wa3w6O8foOPxrLaKPQymQl0HYPIAAK2vizWfc8vJ3wi GOlm45FfXOMeYqlFspG4S/HEfi29DhcziWk0maWYelcVtw1aM4EZv8HE4P4QAHuBqR g+ue1GwVe+zibwdxujMi9nLkf/1WtdjnA9qQJ5FQ= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 20S8CH3T014523 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 28 Jan 2022 02:12:17 -0600 Received: from DLEE111.ent.ti.com (157.170.170.22) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Fri, 28 Jan 2022 02:12:16 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14 via Frontend Transport; Fri, 28 Jan 2022 02:12:16 -0600 Received: from gsaswath-HP-ProBook-640-G5.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 20S8BqpE098664; Fri, 28 Jan 2022 02:12:14 -0600 From: Aswath Govindraju To: CC: , Sanket Parmar , Alan Douglas , Swapnil Jakhade , Kishon Vijay Abraham I , Tero Kristo , Vignesh Raghavendra , Aswath Govindraju Subject: [PATCH v2 08/25] phy: cadence: Sierra: Add a UCLASS_PHY device for links Date: Fri, 28 Jan 2022 13:41:35 +0530 Message-ID: <20220128081152.14901-9-a-govindraju@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220128081152.14901-1-a-govindraju@ti.com> References: <20220128081152.14901-1-a-govindraju@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 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 a driver of type UCLASS_PHY for each of the link nodes in the serdes instance. Signed-off-by: Aswath Govindraju --- drivers/phy/cadence/phy-cadence-sierra.c | 116 +++++++++++++++-------- 1 file changed, 75 insertions(+), 41 deletions(-) diff --git a/drivers/phy/cadence/phy-cadence-sierra.c b/drivers/phy/cadence/phy-cadence-sierra.c index 90699f2fa653..af67df6d06cb 100644 --- a/drivers/phy/cadence/phy-cadence-sierra.c +++ b/drivers/phy/cadence/phy-cadence-sierra.c @@ -203,7 +203,7 @@ struct cdns_sierra_phy { size_t size; struct regmap *regmap; struct cdns_sierra_data *init_data; - struct cdns_sierra_inst phys[SIERRA_MAX_LANES]; + struct cdns_sierra_inst *phys[SIERRA_MAX_LANES]; struct reset_control *phy_rst; struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES]; struct regmap *regmap_phy_config_ctrl; @@ -242,8 +242,8 @@ static inline struct cdns_sierra_inst *phy_get_drvdata(struct phy *phy) return NULL; for (index = 0; index < sp->nsubnodes; index++) { - if (phy->id == sp->phys[index].mlane) - return &sp->phys[index]; + if (phy->id == sp->phys[index]->mlane) + return sp->phys[index]; } return NULL; @@ -500,13 +500,79 @@ static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp, return 0; } +static int cdns_sierra_bind_link_nodes(struct cdns_sierra_phy *sp) +{ + struct udevice *dev = sp->dev; + struct driver *link_drv; + ofnode child; + int rc; + + link_drv = lists_driver_lookup_name("sierra_phy_link"); + if (!link_drv) { + dev_err(dev, "Cannot find driver 'sierra_phy_link'\n"); + return -ENOENT; + } + + ofnode_for_each_subnode(child, dev_ofnode(dev)) { + if (!(ofnode_name_eq(child, "phy") || + ofnode_name_eq(child, "link"))) + continue; + + rc = device_bind(dev, link_drv, "link", NULL, child, NULL); + if (rc) { + dev_err(dev, "cannot bind driver for link\n"); + return rc; + } + } + + return 0; +} + +static int cdns_sierra_link_probe(struct udevice *dev) +{ + struct cdns_sierra_inst *inst = dev_get_priv(dev); + struct cdns_sierra_phy *sp = dev_get_priv(dev->parent); + struct reset_ctl_bulk *rst; + int ret, node; + + rst = devm_reset_bulk_get_by_node(dev, dev_ofnode(dev)); + if (IS_ERR(rst)) { + ret = PTR_ERR(rst); + dev_err(dev, "failed to get reset\n"); + return ret; + } + inst->lnk_rst = rst; + + ret = cdns_sierra_get_optional(inst, dev_ofnode(dev)); + if (ret) { + dev_err(dev, "missing property in node\n"); + return ret; + } + node = sp->nsubnodes; + sp->phys[node] = inst; + sp->nsubnodes += 1; + sp->num_lanes += inst->num_lanes; + + /* If more than one subnode, configure the PHY as multilink */ + if (!sp->autoconf && sp->nsubnodes > 1) + regmap_field_write(sp->phy_pll_cfg_1, 0x1); + + return 0; +} + +U_BOOT_DRIVER(sierra_phy_link) = { + .name = "sierra_phy_link", + .id = UCLASS_PHY, + .probe = cdns_sierra_link_probe, + .priv_auto = sizeof(struct cdns_sierra_inst), +}; + static int cdns_sierra_phy_probe(struct udevice *dev) { struct cdns_sierra_phy *sp = dev_get_priv(dev); struct cdns_sierra_data *data; unsigned int id_value; int ret, node = 0; - ofnode child; sp->dev = dev; @@ -558,46 +624,14 @@ static int cdns_sierra_phy_probe(struct udevice *dev) } sp->autoconf = dev_read_bool(dev, "cdns,autoconf"); - - ofnode_for_each_subnode(child, dev_ofnode(dev)) { - if (!(ofnode_name_eq(child, "phy") || - ofnode_name_eq(child, "link"))) - continue; - - sp->phys[node].lnk_rst = devm_reset_bulk_get_by_node(dev, - child); - if (IS_ERR(sp->phys[node].lnk_rst)) { - ret = PTR_ERR(sp->phys[node].lnk_rst); - dev_err(dev, "failed to get reset %s\n", - ofnode_get_name(child)); - goto put_child2; - } - - if (!sp->autoconf) { - ret = cdns_sierra_get_optional(&sp->phys[node], child); - if (ret) { - dev_err(dev, "missing property in node %s\n", - ofnode_get_name(child)); - goto put_child; - } - } - sp->num_lanes += sp->phys[node].num_lanes; - - node++; - } - sp->nsubnodes = node; - - /* If more than one subnode, configure the PHY as multilink */ - if (!sp->autoconf && sp->nsubnodes > 1) - regmap_field_write(sp->phy_pll_cfg_1, 0x1); + /* Binding link nodes as children to serdes */ + ret = cdns_sierra_bind_link_nodes(sp); + if (ret) + goto clk_disable; dev_info(dev, "sierra probed\n"); return 0; -put_child: - node++; -put_child2: - clk_disable: clk_disable_unprepare(sp->input_clks[PHY_CLK]); return ret; @@ -615,7 +649,7 @@ static int cdns_sierra_phy_remove(struct udevice *dev) * Need to put the subnode resets here though. */ for (i = 0; i < phy->nsubnodes; i++) - reset_assert_bulk(phy->phys[i].lnk_rst); + reset_assert_bulk(phy->phys[i]->lnk_rst); clk_disable_unprepare(phy->input_clks[PHY_CLK]); -- 2.17.1