From nobody Tue Apr 14 14:22:20 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94ED3C25B08 for ; Wed, 17 Aug 2022 20:03:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241677AbiHQUDw (ORCPT ); Wed, 17 Aug 2022 16:03:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232057AbiHQUDr (ORCPT ); Wed, 17 Aug 2022 16:03:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECD5B1F623 for ; Wed, 17 Aug 2022 13:03:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A5C65B81F61 for ; Wed, 17 Aug 2022 20:03:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBB2FC4347C; Wed, 17 Aug 2022 20:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660766623; bh=wv0Zebl3/M8/sl1p7uqmjBF5ITW2e0LsrTBPWFRbNuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IybX3rRa0kAATdNa9CEutWHHd6nJNB/y5T4vkHUm4SCBxsG8J6o2lnKb5ITB9GZwT WOunqvHZDReF98jHFUrT4omATeTvB3UCsg/rZDPxcxrrDrtzAcum1B8j4gTkqj0NLe en9O7rOnvqqyggowmKPE4BeGmXuDlKMcTntGHaJ3PwQamtksLtjybpR/aPxmhpwVMg pA2qJizPk36y4j50+h95mxHjC0e9BVblhawKMwatNS0D4RpoUMf6u6kUMoXnrzZfTH 6NXMp7SKRpNPotFkq14UcIQPtJFT6KTkDsDWLgb0zPPUVkbS/L4c+4E5yToxy65t3j CT26aaydcxB2A== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Vinod Koul , Kishon Vijay Abraham I , Linux Phy , Kees Cook , Andy Shevchenko Cc: Daniel Scally , Gregory Clement , Heikki Krogerus , Sakari Ailus , linux-kernel@vger.kernel.org, pali@kernel.org, josef.schlehofer@nic.cz, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH linux-phy v2 1/4] string.h: Add str_has_proper_prefix() Date: Wed, 17 Aug 2022 22:03:32 +0200 Message-Id: <20220817200335.911-2-kabel@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220817200335.911-1-kabel@kernel.org> References: <20220817200335.911-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add str_has_proper_prefix(), similar to str_has_prefix(), but requires that the prefix is proper: the string itself must be longer than the prefix. Signed-off-by: Marek Beh=C3=BAn --- Andy, Kees, could you ack this if it is ok? --- include/linux/string.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 61ec7e4f6311..375f51b9182c 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -316,4 +316,22 @@ static __always_inline size_t str_has_prefix(const cha= r *str, const char *prefix return strncmp(str, prefix, len) =3D=3D 0 ? len : 0; } =20 +/** + * str_has_proper_prefix - Test if a string has a proper prefix + * @str: The string to test + * @prefix: The string to see if @str starts with + * + * This is like str_has_prefix(), but fails if the strings are equal. + * + * Returns: + * * strlen(@prefix) if @str starts with @prefix and they aren't equal + * * 0 otherwise + */ +static __always_inline size_t str_has_proper_prefix(const char *str, + const char *prefix) +{ + size_t len =3D strlen(prefix); + return strncmp(str, prefix, len) =3D=3D 0 && len !=3D strlen(str) ? len := 0; +} + #endif /* _LINUX_STRING_H_ */ --=20 2.35.1 From nobody Tue Apr 14 14:22:20 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8546C32772 for ; Wed, 17 Aug 2022 20:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241693AbiHQUD6 (ORCPT ); Wed, 17 Aug 2022 16:03:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241670AbiHQUDu (ORCPT ); Wed, 17 Aug 2022 16:03:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1F51237C6 for ; Wed, 17 Aug 2022 13:03:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 75F70B81F60 for ; Wed, 17 Aug 2022 20:03:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8820C43470; Wed, 17 Aug 2022 20:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660766626; bh=xoSj1JpELAuTG/WCX3GOaVx+5vM2XwQeuT06KHfLqk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y2XewTojGKRqC7pumHvuCgCJUMC1tOuAq2KQOSSO4uALMisMqEEZhGqGfA0rKk2wc OZyjqQOXqLFPcYUaXUXnE0pOm6ifAz+HWXj8qKgqapeM83eOL+lr3C4YGeHdo2Xuc3 aGwjf7IHbKtxIGbwwzRbVWgQiG8BR2kuCgT862+B56pkYVakQk4r8ismVoqWmte7YG kVcWOeV678nbduRAkHOZYvJDKmxcM5obtfNXk5nrynAv5sUi4W/FaQQMGJo9BXdbEl qGAfsnO+ccXb9eFu+9XTYOVl3knpWy3rTYrZ4fMqzNgaoKBUfF+SoTERUZYj/arV3U NUKjjzcY4KYiQ== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Vinod Koul , Kishon Vijay Abraham I , Linux Phy , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus Cc: Gregory Clement , Kees Cook , linux-kernel@vger.kernel.org, pali@kernel.org, josef.schlehofer@nic.cz, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH linux-phy v2 2/4] device property: Add {fwnode/device}_get_tx_p2p_amplitude() Date: Wed, 17 Aug 2022 22:03:33 +0200 Message-Id: <20220817200335.911-3-kabel@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220817200335.911-1-kabel@kernel.org> References: <20220817200335.911-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add functions fwnode_get_tx_p2p_amplitude() and device_get_tx_p2p_amplitude() that parse the 'tx-p2p-microvolt' and 'tx-p2p-microvolt-names' properties and return peak to peak transmit amplitude in microvolts for given PHY mode. The functions search for mode name in 'tx-p2p-microvolt-names' property, and return amplitude at the corresponding index in the 'tx-p2p-microvolt' property. If given mode is not matched in 'tx-p2p-microvolt-names' array, the mode name is generalized (for example "pcie3" -> "pcie" -> "default", or "usb-ss" -> "usb" -> "default"). If the 'tx-p2p-microvolt-names' is not present, the 'tx-p2p-microvolt' property is expected to contain only one value, which is considered default, and will be returned for any mode. Signed-off-by: Marek Beh=C3=BAn --- Andy et al. can I get Ack for this if this is okay? --- drivers/base/property.c | 130 +++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 5 ++ 2 files changed, 135 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index ed6f449f8e5c..34b763436c30 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -921,6 +921,136 @@ int device_get_phy_mode(struct device *dev) } EXPORT_SYMBOL_GPL(device_get_phy_mode); =20 +/** + * fwnode_get_tx_p2p_amplitude - Get peak to peak transmit amplitude for g= iven + * PHY mode + * @fwnode: Pointer to the given node + * @mode: Name of the PHY mode, or "default" / NULL + * @amplitude: Pointer where to store the amplitude + * + * Gets the peak to peak transmit amplitude in microvolts for a given PHY = mode + * by parsing the 'tx-p2p-microvolt' and 'tx-p2p-microvolt-names' properti= es. + * If amplitude is not specified for @mode exactly, tries a more generic m= ode, + * and if that isn't specified, tries "default". + * + * For example if @mode is "pcie3", we first try searching for value + * corresponding to "pcie3", then to "pcie", and finally to "default". + * + * Return: %0 if the amplitude was read (success), + * %-EINVAL if given arguments are not valid, + * %-ENODATA if the required properties do not have a value, + * %-EPROTO if the property is not an array of strings, + * %-ENXIO if no suitable firmware interface is present, + * %-ENOMEM if out of memory. + */ +int fwnode_get_tx_p2p_amplitude(struct fwnode_handle *fwnode, const char *= mode, + u32 *amplitude) +{ + static const char *names_prop =3D "tx-p2p-microvolt-names", + *vals_prop =3D "tx-p2p-microvolt"; + const char **names; + int cnt, idx, ret; + u32 *vals; + + cnt =3D fwnode_property_string_array_count(fwnode, names_prop); + if (!cnt || cnt =3D=3D -EINVAL) + /* + * If the names property does not exist or is empty, we expect + * the values property to contain only one, default value. + */ + return fwnode_property_read_u32(fwnode, vals_prop, amplitude); + else if (cnt < 0) + return cnt; + + names =3D kcalloc(cnt, sizeof(*names), GFP_KERNEL); + if (!names) + return -ENOMEM; + + ret =3D fwnode_property_read_string_array(fwnode, names_prop, names, cnt); + if (ret < 0) { + kfree(names); + return ret; + } + + if (!mode) + mode =3D "default"; + + do { + static const char * const gen_table[] =3D { + "pcie", "usb", "ufs-hs", "dp", "mipi-dphy", + }; + size_t i; + + idx =3D match_string(names, cnt, mode); + if (idx >=3D 0) + break; + + /* If mode was not matched, try more generic mode */ + for (i =3D 0; i < ARRAY_SIZE(gen_table); ++i) { + if (str_has_proper_prefix(mode, gen_table[i])) { + mode =3D gen_table[i]; + break; + } + } + + /* Or "default" */ + if (i =3D=3D ARRAY_SIZE(gen_table)) { + if (strcmp(mode, "default")) + mode =3D "default"; + else + mode =3D NULL; + } + } while (mode); + + kfree(names); + + if (idx < 0) + return -ENODATA; + + vals =3D kcalloc(cnt, sizeof(*vals), GFP_KERNEL); + if (!vals) + return -ENOMEM; + + ret =3D fwnode_property_read_u32_array(fwnode, vals_prop, vals, cnt); + if (ret) + goto out; + + *amplitude =3D vals[idx]; +out: + kfree(vals); + return ret; +} +EXPORT_SYMBOL_GPL(fwnode_get_tx_p2p_amplitude); + +/** + * device_get_tx_p2p_amplitude - Get peak to peak transmit amplitude for g= iven + * PHY mode + * @dev: Pointer to the given device + * @mode: Name of the PHY mode, or "default" / NULL + * @amplitude: Pointer where to store the amplitude + * + * Gets the peak to peak transmit amplitude in microvolts for a given PHY = mode + * by parsing the 'tx-p2p-microvolt' and 'tx-p2p-microvolt-names' properti= es. + * If amplitude is not specified for @mode exactly, tries a more generic m= ode, + * and if that isn't specified, tries "default". + * + * For example if @mode is "pcie3", we first try searching for value + * corresponding to "pcie3", then to "pcie", and finally to "default". + * + * Return: %0 if the amplitude was read (success), + * %-EINVAL if given arguments are not valid, + * %-ENODATA if the required properties do not have a value, + * %-EPROTO if the property is not an array of strings, + * %-ENXIO if no suitable firmware interface is present, + * %-ENOMEM if out of memory. + */ +int device_get_tx_p2p_amplitude(struct device *dev, const char *mode, + u32 *amplitude) +{ + return fwnode_get_tx_p2p_amplitude(dev_fwnode(dev), mode, amplitude); +} +EXPORT_SYMBOL_GPL(device_get_tx_p2p_amplitude); + /** * fwnode_iomap - Maps the memory mapped IO for a given fwnode * @fwnode: Pointer to the firmware node diff --git a/include/linux/property.h b/include/linux/property.h index a5b429d623f6..91b12a79e245 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -392,6 +392,11 @@ const void *device_get_match_data(struct device *dev); int device_get_phy_mode(struct device *dev); int fwnode_get_phy_mode(struct fwnode_handle *fwnode); =20 +int fwnode_get_tx_p2p_amplitude(struct fwnode_handle *fwnode, const char *= mode, + u32 *amplitude); +int device_get_tx_p2p_amplitude(struct device *dev, const char *mode, + u32 *amplitude); + void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index); =20 struct fwnode_handle *fwnode_graph_get_next_endpoint( --=20 2.35.1 From nobody Tue Apr 14 14:22:20 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0204BC25B08 for ; Wed, 17 Aug 2022 20:04:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241691AbiHQUEA (ORCPT ); Wed, 17 Aug 2022 16:04:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241676AbiHQUDv (ORCPT ); Wed, 17 Aug 2022 16:03:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 554BC24F37 for ; Wed, 17 Aug 2022 13:03:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 954306151B for ; Wed, 17 Aug 2022 20:03:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87076C43143; Wed, 17 Aug 2022 20:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660766629; bh=Q+R9USyKy7p7mEYIj9z8Lowa0yqJDDTBygy/2GjV1T8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ppqaUYsbIJC8pN4ebTEfrBqnmX1EqQbKaLHcDoFsD0ave51ycO5RZ2ZJGwA0/hAOe BiydbR8W48AoFyOB4jBNOL30/5ye16yXz/i5oSHGgVm6eNGOtQ410ytJYubDF2d5Ah sTUPCNbtSdsND5LmM0x1oMl6Nsm+GLoS066hwdmfX8vFD1MqEuUgJR0xA52B0e0HH8 p4RLl4fDH/apj+Wgjy0AwMkP50+iHjbQZk9q7flVHwkfcfZoTUPB7OX2jXZdtDBJTF Bndx3F+WEJiRViHZ6Bq9y8ugzbGSpZXIRMGnfGIwXVbUlX713u7fZO7+fdp2lsFlZS Ppp5vxbyoqsPw== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Vinod Koul , Kishon Vijay Abraham I , Linux Phy Cc: Andy Shevchenko , Daniel Scally , Gregory Clement , Heikki Krogerus , Kees Cook , Sakari Ailus , linux-kernel@vger.kernel.org, pali@kernel.org, josef.schlehofer@nic.cz, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH linux-phy v2 3/4] phy: marvell: phy-mvebu-a3700-comphy: Support changing tx amplitude for ethernet Date: Wed, 17 Aug 2022 22:03:34 +0200 Message-Id: <20220817200335.911-4-kabel@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220817200335.911-1-kabel@kernel.org> References: <20220817200335.911-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to set SerDes transmit amplitude if specified via the 'tx-p2p-microvolt' and 'tx-p2p-microvolt-names' device-tree properties. This support is currently only for ethernet mode. Signed-off-by: Marek Beh=C3=BAn --- drivers/phy/marvell/phy-mvebu-a3700-comphy.c | 109 ++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c b/drivers/phy/mar= vell/phy-mvebu-a3700-comphy.c index a4d7d9bd100d..7fabd959ae0f 100644 --- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c +++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c @@ -68,6 +68,16 @@ #define SPEED_PLL_MASK GENMASK(7, 2) #define SPEED_PLL_VALUE_16 FIELD_PREP(SPEED_PLL_MASK, 0x10) =20 +#define COMPHY_GEN1_SET0 0x0d +#define COMPHY_GEN2_SET0 0x0f +#define COMPHY_GEN3_SET0 0x11 +#define COMPHY_GEN4_SET0 0x13 +#define COMPHY_GENx_SET0(x) (0x0d + (((x) & 3) - 1) * 2) +#define Gx_TX_AMP_MASK GENMASK(5, 1) +#define Gx_TX_AMP_VALUE(x) FIELD_PREP(Gx_TX_AMP_MASK, x) +#define Gx_TX_AMP_ADJ BIT(6) +#define Gx_TX_AMP_1025MV (Gx_TX_AMP_VALUE(0x12) | Gx_TX_AMP_ADJ) + #define COMPHY_DIG_LOOPBACK_EN 0x23 #define SEL_DATA_WIDTH_MASK GENMASK(11, 10) #define DATA_WIDTH_10BIT FIELD_PREP(SEL_DATA_WIDTH_MASK, 0x0) @@ -269,6 +279,7 @@ struct mvebu_a3700_comphy_priv { struct mvebu_a3700_comphy_lane { struct mvebu_a3700_comphy_priv *priv; struct device *dev; + struct phy *phy; unsigned int id; enum phy_mode mode; int submode; @@ -385,6 +396,15 @@ static inline void comphy_reg_set16(void __iomem *addr= , u16 data, u16 mask) } =20 /* Used for accessing lane 2 registers (SATA/USB3 PHY) */ +static u16 comphy_get_indirect(struct mvebu_a3700_comphy_priv *priv, u32 o= ffset) +{ + writel(offset, + priv->lane2_phy_indirect + COMPHY_LANE2_INDIR_ADDR); + + /* We need to read the register with 32-bit read */ + return readl(priv->lane2_phy_indirect + COMPHY_LANE2_INDIR_DATA); +} + static void comphy_set_indirect(struct mvebu_a3700_comphy_priv *priv, u32 offset, u16 data, u16 mask) { @@ -394,6 +414,21 @@ static void comphy_set_indirect(struct mvebu_a3700_com= phy_priv *priv, data, mask); } =20 +static u16 comphy_lane_reg_get(struct mvebu_a3700_comphy_lane *lane, u16 r= eg) +{ + if (lane->id =3D=3D 2) { + /* lane 2 PHY registers are accessed indirectly */ + return comphy_get_indirect(lane->priv, + reg + COMPHY_LANE2_REGS_BASE); + } else { + void __iomem *base =3D lane->id =3D=3D 1 ? + lane->priv->lane1_phy_regs : + lane->priv->lane0_phy_regs; + + return readw(base + COMPHY_LANE_REG_DIRECT(reg)); + } +} + static void comphy_lane_reg_set(struct mvebu_a3700_comphy_lane *lane, u16 reg, u16 data, u16 mask) { @@ -624,10 +659,53 @@ static void comphy_gbe_phy_init(struct mvebu_a3700_co= mphy_lane *lane, } } =20 +static u8 comphy_find_best_tx_amp(bool full_swing, u32 amp, u32 *true_amp) +{ + static const u32 half_swing_table[32] =3D { + 250, 270, 290, 310, 330, 345, 365, 380, + 400, 420, 435, 455, 470, 490, 505, 525, + 485, 520, 555, 590, 625, 660, 695, 730, + 765, 800, 830, 865, 900, 930, 965, 1000, + }; + static const u32 full_swing_table[22] =3D { + 470, 505, 540, 575, 610, 645, 680, 715, + 750, 785, 820, 850, 885, 915, 950, 980, + 900, 965, 1025, 1095, 1160, 1220, + }; + u32 diff, min_diff; + const u32 *table; + size_t len; + u8 res; + + if (full_swing) { + table =3D full_swing_table; + len =3D ARRAY_SIZE(full_swing_table); + } else { + table =3D half_swing_table; + len =3D ARRAY_SIZE(half_swing_table); + } + + res =3D 0; + min_diff =3D abs(amp - table[0]); + + for (size_t i =3D 1; i < len; ++i) { + diff =3D abs(amp - table[i]); + if (diff < min_diff) { + min_diff =3D diff; + res =3D i; + } + } + + if (true_amp) + *true_amp =3D table[res]; + + return res; +} + static int mvebu_a3700_comphy_ethernet_power_on(struct mvebu_a3700_comphy_lane *lane) { - u32 mask, data, speed_sel; + u32 mask, data, speed_sel, tx_amp_uv; int ret; =20 /* Set selector */ @@ -746,6 +824,34 @@ mvebu_a3700_comphy_ethernet_power_on(struct mvebu_a370= 0_comphy_lane *lane) comphy_gbe_phy_init(lane, lane->submode !=3D PHY_INTERFACE_MODE_2500BASEX); =20 + /* + * Change transmit amplitude if specified in device-tree. + */ + if (!device_get_tx_p2p_amplitude(&lane->phy->dev, + phy_modes(lane->submode), + &tx_amp_uv)) { + u32 tx_amp_mv, true_tx_amp_mv; + bool full_swing; + u8 tx_amp; + u16 reg; + + reg =3D COMPHY_GENx_SET0(speed_sel + 1); + + data =3D comphy_lane_reg_get(lane, reg); + full_swing =3D data & Gx_TX_AMP_ADJ; + tx_amp_mv =3D DIV_ROUND_CLOSEST(tx_amp_uv, 1000); + tx_amp =3D comphy_find_best_tx_amp(full_swing, tx_amp_mv, + &true_tx_amp_mv); + + data =3D Gx_TX_AMP_VALUE(tx_amp); + mask =3D Gx_TX_AMP_MASK; + comphy_lane_reg_set(lane, reg, data, mask); + + dev_dbg(lane->dev, + "changed tx amplitude to %u mV (requested %u mV) on lane %d\n", + true_tx_amp_mv, tx_amp_mv, lane->id); + } + /* * 14. Check the PHY Polarity invert bit */ @@ -1382,6 +1488,7 @@ static int mvebu_a3700_comphy_probe(struct platform_d= evice *pdev) =20 lane->priv =3D priv; lane->dev =3D &pdev->dev; + lane->phy =3D phy; lane->mode =3D PHY_MODE_INVALID; lane->submode =3D PHY_INTERFACE_MODE_NA; lane->id =3D lane_id; --=20 2.35.1 From nobody Tue Apr 14 14:22:20 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2ED6EC2BB41 for ; Wed, 17 Aug 2022 20:04:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241697AbiHQUED (ORCPT ); Wed, 17 Aug 2022 16:04:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241680AbiHQUDy (ORCPT ); Wed, 17 Aug 2022 16:03:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDA1C27B05 for ; Wed, 17 Aug 2022 13:03:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 68DB56151E for ; Wed, 17 Aug 2022 20:03:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6340CC43470; Wed, 17 Aug 2022 20:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660766631; bh=SNZ70vt4bNjbtH48RRhcFsT0HkyKYDhAfV/NNF8Sj9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=taN9Qch78MvSeXbDyWhIPR+suwZFNPzyZmAzLyaR8NSXf4mh7CdyLT7HVxlXTnPNq T/i1I8SetYLuOCZkc2llJ3tcbeIPqTr0ehmxYsJOjjVvF0c8+a7ajJ3QjE+b/9e+7f r9k6dPFiBV9QJP6TypHRyedePbioXwEtckP3Qdz+fIShsVIIW2fr3W2CxSGN7stVLq 5BRjY4Te5NT9sd8GO5i4YGbKHiZc/pOGu19BP1yEHJMFNT1LcwPOX82Or3HscGafKt bbMEGjFAPBlHqKea0D5eQu6L5hWRWQ1D1nfxltwTKwJPmDm9xuV6BlO/ijoCjxnYzR mRB3pVzkAtsrw== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Vinod Koul , Kishon Vijay Abraham I , Linux Phy , Gregory Clement Cc: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Kees Cook , Sakari Ailus , linux-kernel@vger.kernel.org, pali@kernel.org, josef.schlehofer@nic.cz, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH linux-phy v2 4/4] arm64: dts: armada-3720-turris-mox: Change comphy tx amplitude for 2500base-x mode Date: Wed, 17 Aug 2022 22:03:35 +0200 Message-Id: <20220817200335.911-5-kabel@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220817200335.911-1-kabel@kernel.org> References: <20220817200335.911-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Change comphy transmit amplitude to 1025 mV for 2500base-x mode on comphy connected to Topaz. This fixes issue wherein if the 8b/10b encoded packet contains a long enough alternating sequence of bits (010101... or 101010...), which happens if the packet contains a sequence of 'J' or '\xb5' bytes, the packet may be lost when sent from A3720 to Topaz due to FCS error. The probability of loss grows with the number of 'J's with default transmit amplitude setting - with 114 'J's the probability is about 50%, with 125 'J's almost 100% of packets are lost. Fixes: 7109d817db2e ("arm64: dts: marvell: add DTS for Turris Mox") Signed-off-by: Marek Beh=C3=BAn --- arch/arm64/boot/dts/marvell/armada-3720-turris-mox.dts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/boot/dts/marvell/armada-3720-turris-mox.dts b/arch/= arm64/boot/dts/marvell/armada-3720-turris-mox.dts index ada164d423f3..74a7ac1f8ecb 100644 --- a/arch/arm64/boot/dts/marvell/armada-3720-turris-mox.dts +++ b/arch/arm64/boot/dts/marvell/armada-3720-turris-mox.dts @@ -181,6 +181,16 @@ ð1 { phys =3D <&comphy0 1>; }; =20 +&comphy0 { + /* + * Set peak to peak transmit amplitude to 1025 mV to fix issue wherein + * a packet may be lost if it contains a long enough sequence of 'J' + * or '\xb5' bytes. + */ + tx-p2p-microvolt =3D <1025000>; + tx-p2p-microvolt-names =3D "2500base-x"; +}; + &sdhci0 { wp-inverted; bus-width =3D <4>; --=20 2.35.1