Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5877580pxb; Thu, 27 Jan 2022 01:12:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9avvV65Co6f2TQKkf2pojmpM1sWojMs99uRLCnvp7zqs67funfPE/syDexIigkF+UhuVk X-Received: by 2002:a17:90b:390e:: with SMTP id ob14mr3337733pjb.42.1643274740862; Thu, 27 Jan 2022 01:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643274740; cv=none; d=google.com; s=arc-20160816; b=Q1Q6Kfv20SUETm7/aM7cZvsDnQBBY6uwfWzSvgFKuEYXvx1X8DUxrnh0Qd+Yj57G+j Ta39R3zUcNoNEdIhKD1eV5WY2a5h5ZgYL/GvWkXsSChDamAB81DsminOhQxXdf6YC9XI LggI4GZGLc8fEr4VMMjsN0HuRH1TEfJ7EgQ4fvRF9nPN6BxFSm0wGE2uMa6tiFqNwex1 CCDZaJVEIklK37V3rQSv9mf4lDoeSw5AOexCYuziWB2DnOwB2eYuTdbsGT5PuZ/9WVQ6 cTcN5PYV6KTRo8ipHMUfmXTD+y9mSep48MJsuonlmiH8Y8J98Xwb2daHhyGBoLbuXZGX sr7Q== 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; bh=oLjg/1/azlp5Q6X66Ebq4pCG+O1TgwtlOfs3nAiNs8s=; b=sIArCkabsct8NsHpUFqMml6wY4dNtfgVaa0Pi1bH/DmubfuiJRyRMheHBX++pSbKon gteXa43DACIJfATFlEA48SyMVt/vHoEtJ+lpNPSw7anv98vdXPGzT3kdb5DsaMnQI6wg kaYFh2g8+See/VDyy6rcmbnwJ+MCOFDs+0bsjYnsx3VJriRgYv3t66LVJbTsXDO0Y1C/ 6zeugcJIQ5+Mvvn0hIgf/34JceCO02Dn1x8wXZJ506Nolqf5tl2m8svWYV8sClX5Npmw 8YdIQ4Q9b9nyquqOYd8w2mKocslh9SKw5tqwOyTCqubaukDFN+8SBdc5JiIHkZftxbpv SZ+Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y2si1668269pfi.316.2022.01.27.01.12.08; Thu, 27 Jan 2022 01:12:20 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234860AbiA0B70 (ORCPT + 99 others); Wed, 26 Jan 2022 20:59:26 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:47510 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S234831AbiA0B7M (ORCPT ); Wed, 26 Jan 2022 20:59:12 -0500 X-UUID: ce175f520511464798346547ed2f56e7-20220127 X-UUID: ce175f520511464798346547ed2f56e7-20220127 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 652676736; Thu, 27 Jan 2022 09:59:08 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Thu, 27 Jan 2022 09:59:06 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 27 Jan 2022 09:59:05 +0800 From: Biao Huang To: David Miller , Rob Herring , Bartosz Golaszewski , Fabien Parent CC: Jakub Kicinski , Felix Fietkau , "John Crispin" , Sean Wang , Mark Lee , Matthias Brugger , , , , , , Biao Huang , Yinghua Pan , , Macpaul Lin Subject: [PATCH net-next v2 6/9] net: ethernet: mtk-star-emac: add timing adjustment support Date: Thu, 27 Jan 2022 09:58:54 +0800 Message-ID: <20220127015857.9868-7-biao.huang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127015857.9868-1-biao.huang@mediatek.com> References: <20220127015857.9868-1-biao.huang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add simple clock inversion for timing adjustment in driver. Add property "mediatek,txc-inverse" or "mediatek,rxc-inverse" to device node when necessary. Signed-off-by: Biao Huang Signed-off-by: Yinghua Pan --- drivers/net/ethernet/mediatek/mtk_star_emac.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/net/ethernet/mediatek/mtk_star_emac.c b/drivers/net/ethernet/mediatek/mtk_star_emac.c index d69f75661e75..d5e974e0db6d 100644 --- a/drivers/net/ethernet/mediatek/mtk_star_emac.c +++ b/drivers/net/ethernet/mediatek/mtk_star_emac.c @@ -131,6 +131,11 @@ static const char *const mtk_star_clk_names[] = { "core", "reg", "trans" }; #define MTK_STAR_REG_INT_MASK 0x0054 #define MTK_STAR_BIT_INT_MASK_FNRC BIT(6) +/* Delay-Macro Register */ +#define MTK_STAR_REG_TEST0 0x0058 +#define MTK_STAR_BIT_INV_RX_CLK BIT(30) +#define MTK_STAR_BIT_INV_TX_CLK BIT(31) + /* Misc. Config Register */ #define MTK_STAR_REG_TEST1 0x005c #define MTK_STAR_BIT_TEST1_RST_HASH_MBIST BIT(31) @@ -268,6 +273,8 @@ struct mtk_star_priv { int duplex; int pause; bool rmii_rxc; + bool rx_inv; + bool tx_inv; const struct mtk_star_compat *compat_data; @@ -1450,6 +1457,25 @@ static void mtk_star_clk_disable_unprepare(void *data) clk_bulk_disable_unprepare(MTK_STAR_NCLKS, priv->clks); } +static int mtk_star_set_timing(struct mtk_star_priv *priv) +{ + struct device *dev = mtk_star_get_dev(priv); + unsigned int delay_val = 0; + + switch (priv->phy_intf) { + case PHY_INTERFACE_MODE_RMII: + delay_val |= FIELD_PREP(MTK_STAR_BIT_INV_RX_CLK, priv->rx_inv); + delay_val |= FIELD_PREP(MTK_STAR_BIT_INV_TX_CLK, priv->tx_inv); + break; + default: + dev_err(dev, "This interface not supported\n"); + return -EINVAL; + } + + regmap_write(priv->regs, MTK_STAR_REG_TEST0, delay_val); + + return 0; +} static int mtk_star_probe(struct platform_device *pdev) { struct device_node *of_node; @@ -1532,6 +1558,8 @@ static int mtk_star_probe(struct platform_device *pdev) } priv->rmii_rxc = of_property_read_bool(of_node, "mediatek,rmii-rxc"); + priv->rx_inv = of_property_read_bool(of_node, "mediatek,rxc-inverse"); + priv->tx_inv = of_property_read_bool(of_node, "mediatek,txc-inverse"); if (priv->compat_data->set_interface_mode) { ret = priv->compat_data->set_interface_mode(ndev); @@ -1541,6 +1569,12 @@ static int mtk_star_probe(struct platform_device *pdev) } } + ret = mtk_star_set_timing(priv); + if (ret) { + dev_err(dev, "Failed to set timing, err = %d\n", ret); + return -EINVAL; + } + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); if (ret) { dev_err(dev, "unsupported DMA mask\n"); -- 2.25.1