From patchwork Thu Feb 9 23:30:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 55132 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp637106wrn; Thu, 9 Feb 2023 15:36:27 -0800 (PST) X-Google-Smtp-Source: AK7set8/VasXvbJkpYQQV70h4fxBO23gnUX2ndTKVaThZhWMpZtDuQkAq1gENKaLWAhIl8bI38Qt X-Received: by 2002:a17:90b:d87:b0:230:8ddd:3878 with SMTP id bg7-20020a17090b0d8700b002308ddd3878mr13941590pjb.42.1675985787494; Thu, 09 Feb 2023 15:36:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675985787; cv=none; d=google.com; s=arc-20160816; b=Dzu5f2yLvjYNYYwJ412EPUKlcgUNgqgsdxlgwsYqDgj+0uS9FH8Lugo6CWK/inQevP BvGtJ3Eu7R+9ZI0lR3I8XAzT4nylVRaGnOFa5rcMtk7ZkW7f6G3srFRZ59xagIqpA4XZ pKB6Vykj4P7uEjIsW51OrZ78AsHTMtHk38EDHGlJATbKk4fpOWNtne5yMFyAEh5PZ3di D9mvwVx8XgdgXaeokyACdKz0eAcjAMKAPZnISw27A4Fzq5dCr5yNFAjK2YxjzLHYRj2G zc6E9Y5DFPmP8K22PxMgr2TVNkk4XVnQRX+d4Eu7eaWBI1VHUXu0z0y4XloHGRnIZ8UN /p1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=QzPaA9LMi+2QSUovS7QqfAbESJvm6hen1n40XGXCACA=; b=YnevwZ1lAxibzf9or2SjG9dVta0izS10MGEiuON2wfaE3hExhajQHvKQkVPVZ+WO62 cxW//HaFoGlZQdhz8O2VZoEegg/jqNZF4+KnMl8/Vdt1AGVWHuqPmmnc8em8sw/+luZd cFcv0/N9EjMlHHjhqVyEcuMH/jUSYfSLoNRqw7vIdNaXS6Sp3JLmwNh/T52JKTR/xlhP HDibsfJD75YHPlcIanxLM4Cx41iSsvF25eFz30GgVQkmtNj1CNskEJJm14BFffkq15b8 X15PjlJ/oq+xv3f/q9SZ12NzYTaZkCBDRf9QooW7uRPwid4zJ58P+HpAM9vWjzW1Oxgx hGkA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a6566c5000000b004b92aef22f7si3042972pgw.3.2023.02.09.15.36.15; Thu, 09 Feb 2023 15:36:27 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbjBIXcY (ORCPT + 99 others); Thu, 9 Feb 2023 18:32:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229827AbjBIXcX (ORCPT ); Thu, 9 Feb 2023 18:32:23 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09D2FA247; Thu, 9 Feb 2023 15:32:22 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pQGOp-0002Fp-20; Fri, 10 Feb 2023 00:32:19 +0100 Date: Thu, 9 Feb 2023 23:30:38 +0000 From: Daniel Golle To: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Russell King , Heiner Kallweit , Lorenzo Bianconi , Mark Lee , John Crispin , Felix Fietkau , AngeloGioacchino Del Regno , Matthias Brugger , DENG Qingfang , Landen Chao , Sean Wang , Paolo Abeni , Jakub Kicinski , Eric Dumazet , "David S. Miller" , Vladimir Oltean , Florian Fainelli , Andrew Lunn Cc: Jianhui Zhao , =?iso-8859-1?q?Bj=F8rn?= Mork Subject: [PATCH v3 05/12] net: ethernet: mtk_eth_soc: set MDIO bus clock frequency Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757398473290566755?= X-GMAIL-MSGID: =?utf-8?q?1757398473290566755?= Set MDIO bus clock frequency and allow setting a custom maximum frequency from device tree. Reviewed-by: Andrew Lunn Tested-by: Bjørn Mork Signed-off-by: Daniel Golle Reviewed-by: Florian Fainelli --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 21 +++++++++++++++++++++ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index cfb15a84b894..030d87c42bd4 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -789,8 +789,10 @@ static const struct phylink_mac_ops mtk_phylink_ops = { static int mtk_mdio_init(struct mtk_eth *eth) { + unsigned int max_clk = 2500000, divider; struct device_node *mii_np; int ret; + u32 val; mii_np = of_get_child_by_name(eth->dev->of_node, "mdio-bus"); if (!mii_np) { @@ -818,6 +820,25 @@ static int mtk_mdio_init(struct mtk_eth *eth) eth->mii_bus->parent = eth->dev; snprintf(eth->mii_bus->id, MII_BUS_ID_SIZE, "%pOFn", mii_np); + + if (!of_property_read_u32(mii_np, "clock-frequency", &val)) { + if (val > MDC_MAX_FREQ || val < MDC_MAX_FREQ / MDC_MAX_DIVIDER) { + dev_err(eth->dev, "MDIO clock frequency out of range"); + ret = -EINVAL; + goto err_put_node; + } + max_clk = val; + } + divider = min_t(unsigned int, DIV_ROUND_UP(MDC_MAX_FREQ, max_clk), 63); + + /* Configure MDC Divider */ + val = mtk_r32(eth, MTK_PPSC); + val &= ~PPSC_MDC_CFG; + val |= FIELD_PREP(PPSC_MDC_CFG, divider) | PPSC_MDC_TURBO; + mtk_w32(eth, val, MTK_PPSC); + + dev_dbg(eth->dev, "MDC is running on %d Hz\n", MDC_MAX_FREQ / divider); + ret = of_mdiobus_register(eth->mii_bus, mii_np); err_put_node: diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index 7230dcb29315..7014c02ba2d4 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -363,6 +363,13 @@ #define RX_DMA_VTAG_V2 BIT(0) #define RX_DMA_L4_VALID_V2 BIT(2) +/* PHY Polling and SMI Master Control registers */ +#define MTK_PPSC 0x10000 +#define PPSC_MDC_CFG GENMASK(29, 24) +#define PPSC_MDC_TURBO BIT(20) +#define MDC_MAX_FREQ 25000000 +#define MDC_MAX_DIVIDER 63 + /* PHY Indirect Access Control registers */ #define MTK_PHY_IAC 0x10004 #define PHY_IAC_ACCESS BIT(31)