From patchwork Thu Dec 24 11:42:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kishon Vijay Abraham I X-Patchwork-Id: 351900 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp6949175jai; Thu, 24 Dec 2020 03:45:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwPPBhH6R/0YkVinm2Z7n54td6q1gPw0EH2hqy8HqyyL2+32KPVhGWzDTngXxISwIEcnwZ9 X-Received: by 2002:aa7:d2c9:: with SMTP id k9mr28220096edr.74.1608810314284; Thu, 24 Dec 2020 03:45:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608810314; cv=none; d=google.com; s=arc-20160816; b=SQ9YAXoWVK1TfTFTmq0K3njiX8TQsWHsMimvc96wgKzT6ADOYVPei8nZabcvHCwsZA cqdVLQfGsLhVRXEOwg2K6MqW8W1CmnlTRdkbwx37qEb8/pMxwjJ14oEQ6qW/DJr4O3EZ 7m4xw020EKh01yCM/oYsjrMmHUvFbBm4WRpOwHDguCvWZ39in3Png2Quqsu2Hqo71Ojg j2UYO84liYwBfYevBGTTJPGDJiHzZ2GA6rY+kCE9gQYZdi9wtmpDMAIKC1LwApHzGNdC FUHpfZETpGWcusuX+589fTIvlAbdNG3vv6inaiFe2DNLIVnVRlT3iFTpuyF8hGdPZHUw XdzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=R5Xa44jBVuv2Xt7dKXCPPYky4afTZPCkQ/UEaLszPCE=; b=TQwwVqgQ89hmWUskx8APN8ewh08dT/5w/IXJCeIBp40/ZvpXXzCVrt4MQgsdodHUsf i+Jqp44Ssu5fBLaITzC6DV3XERI7vgiG05POVNJLBifORIHlUYpTef3W+8CSTmKqiBBh lNWo0lJNeoH2N1qGEFEAZvan/4kxQABlxzbF/QvDqxQcaGEg9HA5EUTRHinaVM9dzJ4B IWaO4QQ38CKiyqMJLfFMA5Ik2UGtSVIMAp1rpwUNQnLjNcmB4ik+8b8QD5RQLwCbjg+F P/Yg8Vqo6E43dVityNe0bNZVQizY7iXKMmODTfA4/8qqJcpYYCt6KWveTNgfkO8sNBmz 2y4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=lDZtUI0e; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o4si12933767ejr.495.2020.12.24.03.45.14; Thu, 24 Dec 2020 03:45:14 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=lDZtUI0e; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-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 S1727865AbgLXLoY (ORCPT + 7 others); Thu, 24 Dec 2020 06:44:24 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:39704 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726609AbgLXLoX (ORCPT ); Thu, 24 Dec 2020 06:44:23 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0BOBhUps083394; Thu, 24 Dec 2020 05:43:30 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1608810210; bh=R5Xa44jBVuv2Xt7dKXCPPYky4afTZPCkQ/UEaLszPCE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=lDZtUI0ekK5fU4lirGgmSO0Y7kMlkvBbp3bXcE5Qs2OtDgWF4eZ0FBjYCWZMF4hio sTHrKhi8fbjeiBHPx56Y7C3Wcu6JAxMy2M8U8OSX50tttpQOIeY62SVXfh9H+9vfZD lux2Af+8tU/t9SuzM4y7V6XnAWIZFyqoJOPy444U= Received: from DLEE104.ent.ti.com (dlee104.ent.ti.com [157.170.170.34]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0BOBhUMC097972 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 24 Dec 2020 05:43:30 -0600 Received: from DLEE114.ent.ti.com (157.170.170.25) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Thu, 24 Dec 2020 05:43:30 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Thu, 24 Dec 2020 05:43:30 -0600 Received: from a0393678-ssd.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0BOBgtwZ026267; Thu, 24 Dec 2020 05:43:26 -0600 From: Kishon Vijay Abraham I To: Kishon Vijay Abraham I , Vinod Koul , Rob Herring , Nishanth Menon , Swapnil Jakhade , Peter Rosin CC: , , Subject: [PATCH 6/7] phy: ti: j721e-wiz: Enable reference clock output in cmn_refclk_

Date: Thu, 24 Dec 2020 17:12:49 +0530 Message-ID: <20201224114250.1083-7-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201224114250.1083-1-kishon@ti.com> References: <20201224114250.1083-1-kishon@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org cmn_refclk_

lines in Torrent SERDES is used for connecting external reference clock. cmn_refclk_

can also be configured to output the reference clock. In order to drive the refclk out from the SERDES (Cadence Torrent), PHY_EN_REFCLK should be set in SERDES_RST of WIZ. Model PHY_EN_REFCLK as a clock, so that platforms like AM642 EVM can enable it. Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/ti/phy-j721e-wiz.c | 115 +++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) -- 2.17.1 diff --git a/drivers/phy/ti/phy-j721e-wiz.c b/drivers/phy/ti/phy-j721e-wiz.c index 08acfab1ebe6..d60a9a01a8b2 100644 --- a/drivers/phy/ti/phy-j721e-wiz.c +++ b/drivers/phy/ti/phy-j721e-wiz.c @@ -54,6 +54,7 @@ enum wiz_refclk_div_sel { static const struct reg_field por_en = REG_FIELD(WIZ_SERDES_CTRL, 31, 31); static const struct reg_field phy_reset_n = REG_FIELD(WIZ_SERDES_RST, 31, 31); +static const struct reg_field phy_en_refclk = REG_FIELD(WIZ_SERDES_RST, 30, 30); static const struct reg_field pll1_refclk_mux_sel = REG_FIELD(WIZ_SERDES_RST, 29, 29); static const struct reg_field pll0_refclk_mux_sel = @@ -141,6 +142,15 @@ struct wiz_clk_div_sel { const char *node_name; }; +struct wiz_phy_en_refclk { + struct clk_hw hw; + struct regmap_field *phy_en_refclk; + struct clk_init_data clk_data; +}; + +#define to_wiz_phy_en_refclk(_hw) \ + container_of(_hw, struct wiz_phy_en_refclk, hw) + static struct wiz_clk_mux_sel clk_mux_sel_16g[] = { { /* @@ -214,6 +224,7 @@ struct wiz { unsigned int clk_div_sel_num; struct regmap_field *por_en; struct regmap_field *phy_reset_n; + struct regmap_field *phy_en_refclk; struct regmap_field *p_enable[WIZ_MAX_LANES]; struct regmap_field *p_align[WIZ_MAX_LANES]; struct regmap_field *p_raw_auto_start[WIZ_MAX_LANES]; @@ -450,9 +461,96 @@ static int wiz_regfield_init(struct wiz *wiz) return PTR_ERR(wiz->typec_ln10_swap); } + wiz->phy_en_refclk = devm_regmap_field_alloc(dev, regmap, + phy_en_refclk); + if (IS_ERR(wiz->phy_en_refclk)) { + dev_err(dev, "PHY_EN_REFCLK reg field init failed\n"); + return PTR_ERR(wiz->phy_en_refclk); + } + return 0; } +static int wiz_phy_en_refclk_enable(struct clk_hw *hw) +{ + struct wiz_phy_en_refclk *wiz_phy_en_refclk = to_wiz_phy_en_refclk(hw); + struct regmap_field *phy_en_refclk = wiz_phy_en_refclk->phy_en_refclk; + + regmap_field_write(phy_en_refclk, 1); + + return 0; +} + +static void wiz_phy_en_refclk_disable(struct clk_hw *hw) +{ + struct wiz_phy_en_refclk *wiz_phy_en_refclk = to_wiz_phy_en_refclk(hw); + struct regmap_field *phy_en_refclk = wiz_phy_en_refclk->phy_en_refclk; + + regmap_field_write(phy_en_refclk, 0); +} + +static int wiz_phy_en_refclk_is_enabled(struct clk_hw *hw) +{ + struct wiz_phy_en_refclk *wiz_phy_en_refclk = to_wiz_phy_en_refclk(hw); + struct regmap_field *phy_en_refclk = wiz_phy_en_refclk->phy_en_refclk; + int val; + + regmap_field_read(phy_en_refclk, &val); + + return !!val; +} + +static const struct clk_ops wiz_phy_en_refclk_ops = { + .enable = wiz_phy_en_refclk_enable, + .disable = wiz_phy_en_refclk_disable, + .is_enabled = wiz_phy_en_refclk_is_enabled, +}; + +static int wiz_phy_en_refclk_register(struct wiz *wiz, struct device_node *node, + struct regmap_field *phy_en_refclk) +{ + struct wiz_phy_en_refclk *wiz_phy_en_refclk; + struct device *dev = wiz->dev; + struct clk_init_data *init; + unsigned int num_parents; + const char *parent_name; + char clk_name[100]; + struct clk *clk; + int ret; + + wiz_phy_en_refclk = devm_kzalloc(dev, sizeof(*wiz_phy_en_refclk), + GFP_KERNEL); + if (!wiz_phy_en_refclk) + return -ENOMEM; + + num_parents = of_clk_get_parent_count(node); + parent_name = of_clk_get_parent_name(node, 0); + + snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), + node->name); + + init = &wiz_phy_en_refclk->clk_data; + + init->ops = &wiz_phy_en_refclk_ops; + init->flags = 0; + init->parent_names = parent_name ? &parent_name : NULL; + init->num_parents = num_parents ? 1 : 0; + init->name = clk_name; + + wiz_phy_en_refclk->phy_en_refclk = phy_en_refclk; + wiz_phy_en_refclk->hw.init = init; + + clk = devm_clk_register(dev, &wiz_phy_en_refclk->hw); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); + if (ret) + dev_err(dev, "Fail to add clock provider: %s\n", clk_name); + + return ret; +} + static u8 wiz_clk_mux_get_parent(struct clk_hw *hw) { struct wiz_clk_mux *mux = to_wiz_clk_mux(hw); @@ -713,6 +811,20 @@ static int wiz_clock_init(struct wiz *wiz, struct device_node *node) of_node_put(clk_node); } + clk_node = of_get_child_by_name(node, "phy-en-refclk"); + if (clk_node) { + ret = wiz_phy_en_refclk_register(wiz, clk_node, + wiz->phy_en_refclk); + if (ret) { + dev_err(dev, "Failed to register %s clock\n", + node_name); + of_node_put(clk_node); + goto err; + } + + of_node_put(clk_node); + } + return 0; err: wiz_clock_cleanup(wiz, node); @@ -828,6 +940,9 @@ static int wiz_get_lane_phy_types(struct device *dev, struct wiz *wiz) of_node_name_eq(subnode, "link"))) continue; + if (!(of_node_name_eq(subnode, "link"))) + continue; + ret = of_property_read_u32(subnode, "reg", ®); if (ret) { dev_err(dev,