Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4938579rwj; Tue, 20 Dec 2022 17:41:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXvFvGhoEY+DHInt4N5mSE0hBw1tl8ZPcuuRnTD6gSvhWeDAaGT99R5g3PaoPzipCH5Vqtth X-Received: by 2002:a17:90b:30ce:b0:219:8cba:cbbd with SMTP id hi14-20020a17090b30ce00b002198cbacbbdmr180026pjb.32.1671586889114; Tue, 20 Dec 2022 17:41:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671586889; cv=none; d=google.com; s=arc-20160816; b=y+P8HNkqoGdoPyXmNHqptXtWawCRVL1dXm1knXVS7IdEP7WZ74OGeyY2LjmTgmN4ac QQbm+q0XlrRZJoNAQQpRCyAWraBnKN1JX2uOaAbv6hGnUXDZYDJgrxgLQr2LmCYwvlRe PIjaxBJvHkbBEissRSpM8Ot+1p7fH3nbMxq3yjjiw4ebUgBd7I3t5hERTY6fc091hWd8 18vQD4VXVgcjKw9q8cDXmgdWbzW+geOxRlrF2z8LsDwyRsCVeN4iL5wkv8ZqHkU8whWU O39NnYB4GD/b9e9u3Pm5xSDJxi/BcVQmH0GQ7PuGcg8mtChCgWgTcsXkM4KNhC5UFGqq 9HIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=KDUZtfEZHFIhQportP1L+V7XukVGZnyx6ClOJPEfBos=; b=LyM/Svyr6/8sSUMgmTLDYGO8WuV1LFNvcdV3tWljXr6da3nyr8RL9gO/2IN6aTiOjt j7aw4uqWkONARjIj+tnndP0RkrNw95NA1cSRDtACGaYTxpBLuldnpFU6s1Of48rlyZpZ FXgw+nIa6hY/F/ZbAa5QFJp209Ioxh4TF5GqR2rx4Bh03V0jEd0iyv2p4lIeyudrqd6p Gpyb5dvJTvqCGYuI2hwPrsool+nwsexN1r/WI8YSrRHuHwCWkUURIKwNLOEkcuVm8z4J eVogPNKm63JrI63J2wTSgsiFyTiAucapWX+YOG588cqKvftOXUMLJkcbsxvf3nR6xLvR edXg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s16-20020a656910000000b004791644f520si15932057pgq.437.2022.12.20.17.41.19; Tue, 20 Dec 2022 17:41:29 -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 S234302AbiLUBQ3 (ORCPT + 68 others); Tue, 20 Dec 2022 20:16:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233966AbiLUBQ1 (ORCPT ); Tue, 20 Dec 2022 20:16:27 -0500 Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3F36100B; Tue, 20 Dec 2022 17:16:21 -0800 (PST) Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id DFDDC24DBBD; Wed, 21 Dec 2022 09:16:18 +0800 (CST) Received: from EXMBX173.cuchost.com (172.16.6.93) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 21 Dec 2022 09:16:18 +0800 Received: from [192.168.120.49] (171.223.208.138) by EXMBX173.cuchost.com (172.16.6.93) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 21 Dec 2022 09:16:17 +0800 Message-ID: Date: Wed, 21 Dec 2022 09:16:17 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v2 6/9] net: phy: motorcomm: Add YT8531 phy support To: Heiner Kallweit , , , , CC: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Emil Renner Berthing , Richard Cochran , Andrew Lunn , Peter Geis References: <20221216070632.11444-1-yanhong.wang@starfivetech.com> <20221216070632.11444-7-yanhong.wang@starfivetech.com> <2542ec57-9de7-880c-c0d4-35f0aef738bc@gmail.com> Content-Language: en-US From: yanhong wang In-Reply-To: <2542ec57-9de7-880c-c0d4-35f0aef738bc@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [171.223.208.138] X-ClientProxiedBy: EXCAS061.cuchost.com (172.16.6.21) To EXMBX173.cuchost.com (172.16.6.93) X-YovoleRuleAgent: yovoleflag X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 On 2022/12/16 19:58, Heiner Kallweit wrote: > On 16.12.2022 08:06, Yanhong Wang wrote: >> This adds basic support for the Motorcomm YT8531 >> Gigabit Ethernet PHY. >> >> Signed-off-by: Yanhong Wang >> --- >> drivers/net/phy/Kconfig | 3 +- >> drivers/net/phy/motorcomm.c | 202 ++++++++++++++++++++++++++++++++++++ >> 2 files changed, 204 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig >> index c57a0262fb64..86399254d9ff 100644 >> --- a/drivers/net/phy/Kconfig >> +++ b/drivers/net/phy/Kconfig >> @@ -258,9 +258,10 @@ config MICROSEMI_PHY >> >> config MOTORCOMM_PHY >> tristate "Motorcomm PHYs" >> + default SOC_STARFIVE > > Both are completely independent. This default should be removed. > >> help >> Enables support for Motorcomm network PHYs. >> - Currently supports the YT8511 gigabit PHY. >> + Currently supports the YT8511 and YT8531 gigabit PHYs. >> > > This doesn't apply. Parts of your patch exist already in net-next. > Support for YT8531S has been added in the meantime. Please rebase > your patch on net-next and annotate your patch as net-next. > Thanks. Parts of this patch exist already, after discussion unanimity was achieved, i will remove the parts of YT8531 in the next version. >> config NATIONAL_PHY >> tristate "National Semiconductor PHYs" >> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c >> index 7e6ac2c5e27e..bca03185b338 100644 >> --- a/drivers/net/phy/motorcomm.c >> +++ b/drivers/net/phy/motorcomm.c >> @@ -3,13 +3,17 @@ >> * Driver for Motorcomm PHYs >> * >> * Author: Peter Geis >> + * >> */ >> >> +#include >> #include >> #include >> +#include >> #include >> >> #define PHY_ID_YT8511 0x0000010a >> +#define PHY_ID_YT8531 0x4f51e91b >> >> #define YT8511_PAGE_SELECT 0x1e >> #define YT8511_PAGE 0x1f >> @@ -17,6 +21,10 @@ >> #define YT8511_EXT_DELAY_DRIVE 0x0d >> #define YT8511_EXT_SLEEP_CTRL 0x27 >> >> +#define YTPHY_EXT_SMI_SDS_PHY 0xa000 >> +#define YTPHY_EXT_CHIP_CONFIG 0xa001 >> +#define YTPHY_EXT_RGMII_CONFIG1 0xa003 >> + >> /* 2b00 25m from pll >> * 2b01 25m from xtl *default* >> * 2b10 62.m from pll >> @@ -38,6 +46,51 @@ >> #define YT8511_DELAY_FE_TX_EN (0xf << 12) >> #define YT8511_DELAY_FE_TX_DIS (0x2 << 12) >> >> +struct ytphy_reg_field { >> + char *name; >> + u32 mask; >> + u8 dflt; /* Default value */ >> +}; >> + >> +struct ytphy_priv_t { >> + u32 tx_inverted_1000; >> + u32 tx_inverted_100; >> + u32 tx_inverted_10; >> +}; >> + >> +/* rx_delay_sel: RGMII rx clock delay train configuration, about 150ps per >> + * step. Delay = 150ps * N >> + * >> + * tx_delay_sel_fe: RGMII tx clock delay train configuration when speed is >> + * 100Mbps or 10Mbps, it's 150ps per step. Delay = 150ps * N >> + * >> + * tx_delay_sel: RGMII tx clock delay train configuration when speed is >> + * 1000Mbps, it's 150ps per step. Delay = 150ps * N >> + */ >> +static const struct ytphy_reg_field ytphy_rxtxd_grp[] = { >> + { "rx_delay_sel", GENMASK(13, 10), 0x0 }, >> + { "tx_delay_sel_fe", GENMASK(7, 4), 0xf }, >> + { "tx_delay_sel", GENMASK(3, 0), 0x1 } >> +}; >> + >> +/* tx_inverted_x: Use original or inverted RGMII TX_CLK to drive the RGMII >> + * TX_CLK delay train configuration when speed is >> + * xMbps(10/100/1000Mbps). >> + * 0: original, 1: inverted >> + */ >> +static const struct ytphy_reg_field ytphy_txinver_grp[] = { >> + { "tx_inverted_1000", BIT(14), 0x0 }, >> + { "tx_inverted_100", BIT(14), 0x0 }, >> + { "tx_inverted_10", BIT(14), 0x0 } > > Copy & Paste error that mask is the same for all entries? > >> +}; >> + >> +/* rxc_dly_en: RGMII clk 2ns delay control bit. >> + * 0: disable 1: enable >> + */ >> +static const struct ytphy_reg_field ytphy_rxden_grp[] = { >> + { "rxc_dly_en", BIT(8), 0x1 } >> +}; >> + >> static int yt8511_read_page(struct phy_device *phydev) >> { >> return __phy_read(phydev, YT8511_PAGE_SELECT); >> @@ -48,6 +101,33 @@ static int yt8511_write_page(struct phy_device *phydev, int page) >> return __phy_write(phydev, YT8511_PAGE_SELECT, page); >> }; >> >> +static int ytphy_read_ext(struct phy_device *phydev, u32 regnum) >> +{ >> + int ret; >> + int val; >> + >> + ret = __phy_write(phydev, YT8511_PAGE_SELECT, regnum); >> + if (ret < 0) >> + return ret; >> + >> + val = __phy_read(phydev, YT8511_PAGE); >> + >> + return val; >> +} >> + >> +static int ytphy_write_ext(struct phy_device *phydev, u32 regnum, u16 val) >> +{ >> + int ret; >> + >> + ret = __phy_write(phydev, YT8511_PAGE_SELECT, regnum); >> + if (ret < 0) >> + return ret; >> + >> + ret = __phy_write(phydev, YT8511_PAGE, val); >> + >> + return ret; >> +} >> + >> static int yt8511_config_init(struct phy_device *phydev) >> { >> int oldpage, ret = 0; >> @@ -111,6 +191,116 @@ static int yt8511_config_init(struct phy_device *phydev) >> return phy_restore_page(phydev, oldpage, ret); >> } >> >> +static int ytphy_config_init(struct phy_device *phydev) >> +{ >> + struct device_node *of_node; >> + u32 val; >> + u32 mask; >> + u32 cfg; >> + int ret; >> + int i = 0; >> + >> + of_node = phydev->mdio.dev.of_node; >> + if (of_node) { >> + ret = of_property_read_u32(of_node, ytphy_rxden_grp[0].name, &cfg); >> + if (!ret) { >> + mask = ytphy_rxden_grp[0].mask; >> + val = ytphy_read_ext(phydev, YTPHY_EXT_CHIP_CONFIG); >> + >> + /* check the cfg overflow or not */ >> + cfg = cfg > mask >> (ffs(mask) - 1) ? mask : cfg; >> + >> + val &= ~mask; >> + val |= FIELD_PREP(mask, cfg); >> + ytphy_write_ext(phydev, YTPHY_EXT_CHIP_CONFIG, val); > > This is the unlocked version. MDIO bus locking is missing. > >> + } >> + >> + val = ytphy_read_ext(phydev, YTPHY_EXT_RGMII_CONFIG1); >> + for (i = 0; i < ARRAY_SIZE(ytphy_rxtxd_grp); i++) { >> + ret = of_property_read_u32(of_node, ytphy_rxtxd_grp[i].name, &cfg); >> + if (!ret) { >> + mask = ytphy_rxtxd_grp[i].mask; >> + >> + /* check the cfg overflow or not */ >> + cfg = cfg > mask >> (ffs(mask) - 1) ? mask : cfg; >> + >> + val &= ~mask; >> + val |= cfg << (ffs(mask) - 1); >> + } >> + } >> + return ytphy_write_ext(phydev, YTPHY_EXT_RGMII_CONFIG1, val); >> + } >> + >> + phydev_err(phydev, "Get of node fail\n"); >> + > > Please consider that the PHY may be used on non-DT systems. > >> + return -EINVAL; >> +} >> + >> +static void ytphy_link_change_notify(struct phy_device *phydev) >> +{ >> + u32 val; >> + struct ytphy_priv_t *ytphy_priv = phydev->priv; >> + >> + if (phydev->speed < 0) >> + return; >> + >> + val = ytphy_read_ext(phydev, YTPHY_EXT_RGMII_CONFIG1); >> + switch (phydev->speed) { >> + case SPEED_1000: >> + val &= ~ytphy_txinver_grp[0].mask; >> + val |= FIELD_PREP(ytphy_txinver_grp[0].mask, >> + ytphy_priv->tx_inverted_1000); >> + break; >> + >> + case SPEED_100: >> + val &= ~ytphy_txinver_grp[1].mask; >> + val |= FIELD_PREP(ytphy_txinver_grp[1].mask, >> + ytphy_priv->tx_inverted_100); >> + break; >> + >> + case SPEED_10: >> + val &= ~ytphy_txinver_grp[2].mask; >> + val |= FIELD_PREP(ytphy_txinver_grp[2].mask, >> + ytphy_priv->tx_inverted_10); >> + break; >> + >> + default: >> + break; >> + } >> + >> + ytphy_write_ext(phydev, YTPHY_EXT_RGMII_CONFIG1, val); >> +} >> + >> +static int yt8531_probe(struct phy_device *phydev) >> +{ >> + struct ytphy_priv_t *priv; >> + const struct device_node *of_node; >> + u32 val; >> + int ret; >> + >> + priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); >> + if (!priv) >> + return -ENOMEM; >> + >> + of_node = phydev->mdio.dev.of_node; >> + if (of_node) { >> + ret = of_property_read_u32(of_node, ytphy_txinver_grp[0].name, &val); >> + if (!ret) >> + priv->tx_inverted_1000 = val; >> + >> + ret = of_property_read_u32(of_node, ytphy_txinver_grp[1].name, &val); >> + if (!ret) >> + priv->tx_inverted_100 = val; >> + >> + ret = of_property_read_u32(of_node, ytphy_txinver_grp[2].name, &val); >> + if (!ret) >> + priv->tx_inverted_10 = val; >> + } >> + phydev->priv = priv; >> + >> + return 0; >> +} >> + >> static struct phy_driver motorcomm_phy_drvs[] = { >> { >> PHY_ID_MATCH_EXACT(PHY_ID_YT8511), >> @@ -120,6 +310,17 @@ static struct phy_driver motorcomm_phy_drvs[] = { >> .resume = genphy_resume, >> .read_page = yt8511_read_page, >> .write_page = yt8511_write_page, >> + }, { >> + PHY_ID_MATCH_EXACT(PHY_ID_YT8531), >> + .name = "YT8531 Gigabit Ethernet", >> + .probe = yt8531_probe, >> + .config_init = ytphy_config_init, >> + .read_status = genphy_read_status, >> + .suspend = genphy_suspend, >> + .resume = genphy_resume, >> + .read_page = yt8511_read_page, >> + .write_page = yt8511_write_page, >> + .link_change_notify = ytphy_link_change_notify, >> }, >> }; >> >> @@ -131,6 +332,7 @@ MODULE_LICENSE("GPL"); >> >> static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = { >> { PHY_ID_MATCH_EXACT(PHY_ID_YT8511) }, >> + { PHY_ID_MATCH_EXACT(PHY_ID_YT8531) }, >> { /* sentinal */ } >> }; >> >