Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4604264rwb; Tue, 8 Nov 2022 20:43:36 -0800 (PST) X-Google-Smtp-Source: AMsMyM7JUcDzeUj0kDgFIbtYdlA58Bo8S2k35Kqw93Mbl1jnEQhk23FpuRv7V5BOqbBexb77jf8+ X-Received: by 2002:aa7:ce16:0:b0:461:865a:ae44 with SMTP id d22-20020aa7ce16000000b00461865aae44mr57051440edv.280.1667969016540; Tue, 08 Nov 2022 20:43:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667969016; cv=none; d=google.com; s=arc-20160816; b=dhWduLq+h1NFj1FIiWk/uLEU+CCzUG07QOiXshjKo4zLE6OrGYRN4mOCzNveR87v5Q Y0IX1q/Hvr/joRmHwQJ6WwRZSwLMgPMTcw/xoM8I7hQgrjtWvump0brdfPQRo8FsNGNL 8EqFu7CbCl4qBL81lB/N46PH1pTvYc3nwbLfe2gmFmm7o9Z5hhz71eZYCKc8+UxpdCc4 J10N+Np1kYtFjXgXqNa1W8NUfb4lqrm7opYVdGz+lBFp6j6MxQwY3BHTWLUxS68LQw5T hFBV9U/PaPQMudbEJDTCw4QKhhKSPq0Gxi4Y6YqLRB10uiqyqex2McEVbXcNOwlfTCF9 JYGw== 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=RBnzGDITsnmgAmda1HLuNmjSC20+kjgG18pJ0qrLfgs=; b=abFMCgcZbfcU5lmSiW1GF8K9DaoYsp01d9Ii41FseF94fxjjBiqI5Cf7QIrnnNsbI+ B792O0SK5XWUsnUc8RvyqlIl9yKIH6Ne2HjJUFGfOrBdZ+za0h7OjOZJyk+WrQkJ61RF 9VQoOJQzQVFi7ri0xxT2SwKNKh65xSHy5slVeGB9NGQRqi01w4FwW9hIPk4Bs3DB4ob9 iNDbWf09eSfeep+LRCP3ncCK56wxzix+8cesij67Rw9mx+NBXCLLWcnS3tLkmwKFGCLf WIFSjZM62qQsYOABFZWf+jaf8LNdmxr0KlvtK/EWlr3o9AJsoviZ+6g4kmEFZzAFnBAu EI6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=U8vjFU1V; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a170906854b00b0078decbc3fe4si10840080ejy.274.2022.11.08.20.43.00; Tue, 08 Nov 2022 20:43:36 -0800 (PST) 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=@ti.com header.s=ti-com-17Q1 header.b=U8vjFU1V; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbiKIEXY (ORCPT + 93 others); Tue, 8 Nov 2022 23:23:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbiKIEXB (ORCPT ); Tue, 8 Nov 2022 23:23:01 -0500 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 122891FF8F; Tue, 8 Nov 2022 20:22:47 -0800 (PST) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2A94MNgs075081; Tue, 8 Nov 2022 22:22:23 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1667967743; bh=RBnzGDITsnmgAmda1HLuNmjSC20+kjgG18pJ0qrLfgs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=U8vjFU1VZCE4U+c4kIx0kOZjTuwF87sEsEbHg2D05NZcBOU7byU6C1P/d4aU+abtO YhxUYUB4hf7H51cUDjiSE9x7zbhsjQ5qk9KZ//ndaZ3kVZ2S/USDGOAl88M5lh0f1h MqCSJovuCj2dfz2vnOEc6Cs6vfUoau2qoX/p4JSE= Received: from DFLE108.ent.ti.com (dfle108.ent.ti.com [10.64.6.29]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2A94MNbI032611 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 8 Nov 2022 22:22:23 -0600 Received: from DFLE113.ent.ti.com (10.64.6.34) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.6; Tue, 8 Nov 2022 22:22:23 -0600 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.6 via Frontend Transport; Tue, 8 Nov 2022 22:22:23 -0600 Received: from uda0492258.dhcp.ti.com (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2A94M4RA111905; Tue, 8 Nov 2022 22:22:19 -0600 From: Siddharth Vadapalli To: , , , , , , , , , , CC: , , , , , Subject: [PATCH net-next v5 3/3] net: ethernet: ti: am65-cpsw: Add support for SERDES configuration Date: Wed, 9 Nov 2022 09:52:03 +0530 Message-ID: <20221109042203.375042-4-s-vadapalli@ti.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221109042203.375042-1-s-vadapalli@ti.com> References: <20221109042203.375042-1-s-vadapalli@ti.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 Use PHY framework APIs to initialize the SERDES PHY connected to CPSW MAC. Define the functions am65_cpsw_disable_phy(), am65_cpsw_enable_phy(), am65_cpsw_disable_serdes_phy() and am65_cpsw_enable_serdes_phy(). Power on and initialize the SerDes PHY in am65_cpsw_nuss_init_slave_ports() by invoking am65_cpsw_enable_serdes_phy(). Power off the SerDes PHY in am65_cpsw_nuss_remove() by invoking am65_cpsw_disable_serdes_phy(). Signed-off-by: Siddharth Vadapalli --- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index bc9f29d10c22..83349d24a0e6 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c @@ -1444,6 +1444,65 @@ static const struct net_device_ops am65_cpsw_nuss_netdev_ops = { .ndo_setup_tc = am65_cpsw_qos_ndo_setup_tc, }; +static void am65_cpsw_disable_phy(struct phy *phy) +{ + phy_power_off(phy); + phy_exit(phy); +} + +static int am65_cpsw_enable_phy(struct phy *phy) +{ + int ret; + + ret = phy_init(phy); + if (ret < 0) + return ret; + + ret = phy_power_on(phy); + if (ret < 0) { + phy_exit(phy); + return ret; + } + + return 0; +} + +static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common) +{ + struct device_node *node, *port_np; + struct device *dev = common->dev; + const char *name = "serdes-phy"; + struct phy *phy; + + node = of_get_child_by_name(dev->of_node, "ethernet-ports"); + + for_each_child_of_node(node, port_np) { + phy = devm_of_phy_get(dev, port_np, name); + am65_cpsw_disable_phy(phy); + } +} + +static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *port_np) +{ + const char *name = "serdes-phy"; + struct phy *phy; + int ret; + + phy = devm_of_phy_get(dev, port_np, name); + if (PTR_ERR(phy) == -ENODEV) + return 0; + + ret = am65_cpsw_enable_phy(phy); + if (ret < 0) + goto err_phy; + + return 0; + +err_phy: + devm_phy_put(dev, phy); + return ret; +} + static void am65_cpsw_nuss_mac_config(struct phylink_config *config, unsigned int mode, const struct phylink_link_state *state) { @@ -1941,6 +2000,11 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common) goto of_node_put; } + /* Initialize the phy for the port */ + ret = am65_cpsw_init_serdes_phy(dev, port_np); + if (ret) + return ret; + port->slave.mac_only = of_property_read_bool(port_np, "ti,mac-only"); @@ -2868,6 +2932,7 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev) am65_cpsw_nuss_phylink_cleanup(common); am65_cpsw_unregister_devlink(common); + am65_cpsw_disable_serdes_phy(common); am65_cpsw_unregister_notifiers(common); /* must unregister ndevs here because DD release_driver routine calls -- 2.25.1