From patchwork Sun Mar 19 12:57:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 71773 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp715877wrt; Sun, 19 Mar 2023 06:09:51 -0700 (PDT) X-Google-Smtp-Source: AK7set8G1YkZN/oRLTP4mse8VWc+89+qBkJx4+WG8HRjsclFK7K7EJAczxXl0VF5TAIfHG+jeN89 X-Received: by 2002:a17:902:f552:b0:1a1:cf70:33d5 with SMTP id h18-20020a170902f55200b001a1cf7033d5mr257023plf.56.1679231390787; Sun, 19 Mar 2023 06:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679231390; cv=none; d=google.com; s=arc-20160816; b=firnG5SYv24S3oLFEPlW62SOdCkkaY30+IJcbJ4Y28qQE3xUaSrOKQkSN5fEu1MGVE 9UtmmnfPbsYkLkWVL0a6OmpwsLRpMxQqzAGAZdDwhuiuyn4+n+6YUhAyPZ3vC9BfDbSY /nSxkXQiG8CINOQRMYwIlIX5riuj0DrxSTN8BOeWHTIwteyD0OoavgHs+MbokgDmOlxs 1WVu5kKqCE8xk91P/a8H6LCunI8OTDVqmUrUevsCcMAO8WMfOQDeMqDLcxKY7vpIo3+t XtQrM6vTF/oeUhnJLsHkCK7JG0JSUyTUU5e4v0QBN7UytualkOrA/H+0iufJOZOLIcoO ypBQ== 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=jHUUq2tBKXPUE8yhESSVKu7uCiBLuSgBDxG1c/cNWVI=; b=m2TUS6UKA62SlnUx6xvkhRs7i/r8p82YGjwreSPpPEG8r4Ea91zItpXYDzWJPvEAmJ PraVb0RhmhwFDbpFOt/UM01SYlg3v2dLt2bpHH9CzDPZ3KnCJcIA1VMMQRyRmypnD4+z b5psJF5eQix5f+D5O8a8CcVEuhnqBxEALpPtAk+bSXHOjeFg+ECavYkUht83ISiz6m3Y C4p9PlkgYVvTSWpJmqGJzc23KmUJ6Eu+Fyt+N42ibPe1zNLkpqaombcjCqBRz8rLVfmc Ny6YiplrCWCCx92Q4QaVAiIrnnzf+P1r+a8bKYg5dB0q6k9ci9MQABU0a02P2UhOptRA MDZw== 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 jd3-20020a170903260300b0019f24b0388csi7538672plb.486.2023.03.19.06.09.34; Sun, 19 Mar 2023 06:09:50 -0700 (PDT) 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 S230288AbjCSM7Z (ORCPT + 99 others); Sun, 19 Mar 2023 08:59:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbjCSM7R (ORCPT ); Sun, 19 Mar 2023 08:59:17 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BE2D19F37; Sun, 19 Mar 2023 05:58:55 -0700 (PDT) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pdscf-0001J5-1J; Sun, 19 Mar 2023 13:58:53 +0100 Date: Sun, 19 Mar 2023 12:57:15 +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 , Vladimir Oltean Cc: =?iso-8859-1?q?Bj=F8rn?= Mork , Frank Wunderlich , Alexander Couzens Subject: [PATCH net-next v14 5/9] net: ethernet: mtk_eth_soc: set MDIO bus clock frequency Message-ID: <2eb2313be774bcea25a5ce661ab69f1e7c7928ac.1679230025.git.daniel@makrotopia.org> 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?1760801735228365669?= X-GMAIL-MSGID: =?utf-8?q?1760801735228365669?= Set MDIO bus clock frequency and allow setting a custom maximum frequency from device tree. Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli Tested-by: Bjørn Mork Signed-off-by: Daniel Golle --- 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 40490197e124..6fe0e9e843cc 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -765,8 +765,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) { @@ -794,6 +796,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 adf01f894b02..529c95c481b7 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)