···11+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)22+%YAML 1.233+---44+$id: http://devicetree.org/schemas/phy/phy-common-props.yaml#55+$schema: http://devicetree.org/meta-schemas/core.yaml#66+77+title: Common PHY and network PCS properties88+99+description:1010+ Common PHY and network PCS properties, such as peak-to-peak transmit1111+ amplitude.1212+1313+maintainers:1414+ - Marek Behún <kabel@kernel.org>1515+1616+$defs:1717+ protocol-names:1818+ description:1919+ Names of the PHY modes. If a value of 'default' is provided, the system2020+ should use it for any PHY mode that is otherwise not defined here. If2121+ 'default' is not provided, the system should use manufacturer default value.2222+ minItems: 12323+ maxItems: 162424+ uniqueItems: true2525+ items:2626+ enum:2727+ - default2828+2929+ # ethernet modes3030+ - sgmii3131+ - qsgmii3232+ - xgmii3333+ - 1000base-x3434+ - 2500base-x3535+ - 5gbase-r3636+ - rxaui3737+ - xaui3838+ - 10gbase-kr3939+ - usxgmii4040+ - 10gbase-r4141+ - 25gbase-r4242+4343+ # PCIe modes4444+ - pcie4545+ - pcie14646+ - pcie24747+ - pcie34848+ - pcie44949+ - pcie55050+ - pcie65151+5252+ # USB modes5353+ - usb5454+ - usb-ls5555+ - usb-fs5656+ - usb-hs5757+ - usb-ss5858+ - usb-ss+5959+ - usb-46060+6161+ # storage modes6262+ - sata6363+ - ufs-hs6464+ - ufs-hs-a6565+ - ufs-hs-b6666+6767+ # display modes6868+ - lvds6969+ - dp7070+ - dp-rbr7171+ - dp-hbr7272+ - dp-hbr27373+ - dp-hbr37474+ - dp-uhbr-107575+ - dp-uhbr-13.57676+ - dp-uhbr-207777+7878+ # camera modes7979+ - mipi-dphy8080+ - mipi-dphy-univ8181+ - mipi-dphy-v2.5-univ8282+8383+properties:8484+ tx-p2p-microvolt:8585+ description:8686+ Transmit amplitude voltages in microvolts, peak-to-peak. If this property8787+ contains multiple values for various PHY modes, the8888+ 'tx-p2p-microvolt-names' property must be provided and contain8989+ corresponding mode names.9090+9191+ tx-p2p-microvolt-names:9292+ description:9393+ Names of the modes corresponding to voltages in the 'tx-p2p-microvolt'9494+ property. Required only if multiple voltages are provided.9595+ $ref: "#/$defs/protocol-names"9696+9797+ rx-polarity:9898+ description:9999+ An array of values indicating whether the differential receiver's100100+ polarity is inverted. Each value can be one of101101+ PHY_POL_NORMAL (0) which means the negative signal is decoded from the102102+ RXN input, and the positive signal from the RXP input;103103+ PHY_POL_INVERT (1) which means the negative signal is decoded from the104104+ RXP input, and the positive signal from the RXN input;105105+ PHY_POL_AUTO (2) which means the receiver performs automatic polarity106106+ detection and correction, which is a mandatory part of link training for107107+ some protocols (PCIe, USB SS).108108+109109+ The values are defined in <dt-bindings/phy/phy.h>. If the property is110110+ absent, the default value is undefined.111111+112112+ Note that the RXP and RXN inputs refer to the block that this property is113113+ under, and do not necessarily directly translate to external pins.114114+115115+ If this property contains multiple values for various protocols, the116116+ 'rx-polarity-names' property must be provided.117117+ $ref: /schemas/types.yaml#/definitions/uint32-array118118+ minItems: 1119119+ maxItems: 16120120+ items:121121+ enum: [0, 1, 2]122122+123123+ rx-polarity-names:124124+ $ref: '#/$defs/protocol-names'125125+126126+ tx-polarity:127127+ description:128128+ Like 'rx-polarity', except it applies to differential transmitters,129129+ and only the values of PHY_POL_NORMAL and PHY_POL_INVERT are possible.130130+ $ref: /schemas/types.yaml#/definitions/uint32-array131131+ minItems: 1132132+ maxItems: 16133133+ items:134134+ enum: [0, 1]135135+136136+ tx-polarity-names:137137+ $ref: '#/$defs/protocol-names'138138+139139+dependencies:140140+ tx-p2p-microvolt-names: [ tx-p2p-microvolt ]141141+ rx-polarity-names: [ rx-polarity ]142142+ tx-polarity-names: [ tx-polarity ]143143+144144+additionalProperties: true145145+146146+examples:147147+ - |148148+ #include <dt-bindings/phy/phy.h>149149+150150+ phy: phy {151151+ #phy-cells = <1>;152152+ tx-p2p-microvolt = <915000>, <1100000>, <1200000>;153153+ tx-p2p-microvolt-names = "2500base-x", "usb-hs", "usb-ss";154154+ rx-polarity = <PHY_POL_AUTO>, <PHY_POL_NORMAL>;155155+ rx-polarity-names = "usb-ss", "default";156156+ tx-polarity = <PHY_POL_INVERT>;157157+ };
···11-# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)22-%YAML 1.233----44-$id: http://devicetree.org/schemas/phy/transmit-amplitude.yaml#55-$schema: http://devicetree.org/meta-schemas/core.yaml#66-77-title: Common PHY and network PCS transmit amplitude property88-99-description:1010- Binding describing the peak-to-peak transmit amplitude for common PHYs1111- and network PCSes.1212-1313-maintainers:1414- - Marek Behún <kabel@kernel.org>1515-1616-properties:1717- tx-p2p-microvolt:1818- description:1919- Transmit amplitude voltages in microvolts, peak-to-peak. If this property2020- contains multiple values for various PHY modes, the2121- 'tx-p2p-microvolt-names' property must be provided and contain2222- corresponding mode names.2323-2424- tx-p2p-microvolt-names:2525- description: |2626- Names of the modes corresponding to voltages in the 'tx-p2p-microvolt'2727- property. Required only if multiple voltages are provided.2828-2929- If a value of 'default' is provided, the system should use it for any PHY3030- mode that is otherwise not defined here. If 'default' is not provided, the3131- system should use manufacturer default value.3232- minItems: 13333- maxItems: 163434- items:3535- enum:3636- - default3737-3838- # ethernet modes3939- - sgmii4040- - qsgmii4141- - xgmii4242- - 1000base-x4343- - 2500base-x4444- - 5gbase-r4545- - rxaui4646- - xaui4747- - 10gbase-kr4848- - usxgmii4949- - 10gbase-r5050- - 25gbase-r5151-5252- # PCIe modes5353- - pcie5454- - pcie15555- - pcie25656- - pcie35757- - pcie45858- - pcie55959- - pcie66060-6161- # USB modes6262- - usb6363- - usb-ls6464- - usb-fs6565- - usb-hs6666- - usb-ss6767- - usb-ss+6868- - usb-46969-7070- # storage modes7171- - sata7272- - ufs-hs7373- - ufs-hs-a7474- - ufs-hs-b7575-7676- # display modes7777- - lvds7878- - dp7979- - dp-rbr8080- - dp-hbr8181- - dp-hbr28282- - dp-hbr38383- - dp-uhbr-108484- - dp-uhbr-13.58585- - dp-uhbr-208686-8787- # camera modes8888- - mipi-dphy8989- - mipi-dphy-univ9090- - mipi-dphy-v2.5-univ9191-9292-dependencies:9393- tx-p2p-microvolt-names: [ tx-p2p-microvolt ]9494-9595-additionalProperties: true9696-9797-examples:9898- - |9999- phy: phy {100100- #phy-cells = <1>;101101- tx-p2p-microvolt = <915000>, <1100000>, <1200000>;102102- tx-p2p-microvolt-names = "2500base-x", "usb-hs", "usb-ss";103103- };
+10
MAINTAINERS
···2051720517S: Maintained2051820518F: drivers/mtd/devices/phram.c20519205192052020520+PHY COMMON PROPERTIES2052120521+M: Vladimir Oltean <vladimir.oltean@nxp.com>2052220522+L: netdev@vger.kernel.org2052320523+S: Maintained2052420524+Q: https://patchwork.kernel.org/project/netdevbpf/list/2052520525+F: Documentation/devicetree/bindings/phy/phy-common-props.yaml2052620526+F: drivers/phy/phy-common-props-test.c2052720527+F: drivers/phy/phy-common-props.c2052820528+F: include/linux/phy/phy-common-props.h2052920529+2052020530PICOLCD HID DRIVER2052120531M: Bruno Prémont <bonbons@linux-vserver.org>2052220532L: linux-input@vger.kernel.org
+22
drivers/phy/Kconfig
···5566menu "PHY Subsystem"7788+config PHY_COMMON_PROPS99+ bool1010+ help1111+ This parses properties common between generic PHYs and Ethernet PHYs.1212+1313+ Select this from consumer drivers to gain access to helpers for1414+ parsing properties from the1515+ Documentation/devicetree/bindings/phy/phy-common-props.yaml schema.1616+1717+config PHY_COMMON_PROPS_TEST1818+ tristate "KUnit tests for PHY common props" if !KUNIT_ALL_TESTS1919+ select PHY_COMMON_PROPS2020+ depends on KUNIT2121+ default KUNIT_ALL_TESTS2222+ help2323+ This builds KUnit tests for the PHY common property API.2424+2525+ For more information on KUnit and unit tests in general,2626+ please refer to the KUnit documentation in Documentation/dev-tools/kunit/.2727+2828+ When in doubt, say N.2929+830config GENERIC_PHY931 bool "PHY Core"1032 help
+2
drivers/phy/Makefile
···33# Makefile for the phy drivers.44#5566+obj-$(CONFIG_PHY_COMMON_PROPS) += phy-common-props.o77+obj-$(CONFIG_PHY_COMMON_PROPS_TEST) += phy-common-props-test.o68obj-$(CONFIG_GENERIC_PHY) += phy-core.o79obj-$(CONFIG_GENERIC_PHY_MIPI_DPHY) += phy-core-mipi-dphy.o810obj-$(CONFIG_PHY_CAN_TRANSCEIVER) += phy-can-transceiver.o
···11+// SPDX-License-Identifier: GPL-2.0-or-later22+/*33+ * phy-common-props.c -- Common PHY properties44+ *55+ * Copyright 2025-2026 NXP66+ */77+#include <linux/export.h>88+#include <linux/fwnode.h>99+#include <linux/phy/phy-common-props.h>1010+#include <linux/printk.h>1111+#include <linux/property.h>1212+#include <linux/slab.h>1313+1414+/**1515+ * fwnode_get_u32_prop_for_name - Find u32 property by name, or default value1616+ * @fwnode: Pointer to firmware node, or NULL to use @default_val1717+ * @name: Property name used as lookup key in @names_title (must not be NULL)1818+ * @props_title: Name of u32 array property holding values1919+ * @names_title: Name of string array property holding lookup keys2020+ * @default_val: Default value if @fwnode is NULL or @props_title is empty2121+ * @val: Pointer to store the returned value2222+ *2323+ * This function retrieves a u32 value from @props_title based on a name lookup2424+ * in @names_title. The value stored in @val is determined as follows:2525+ *2626+ * - If @fwnode is NULL or @props_title is empty: @default_val is used2727+ * - If @props_title has exactly one element and @names_title is empty:2828+ * that element is used2929+ * - Otherwise: @val is set to the element at the same index where @name is3030+ * found in @names_title.3131+ * - If @name is not found, the function looks for a "default" entry in3232+ * @names_title and uses the corresponding value from @props_title3333+ *3434+ * When both @props_title and @names_title are present, they must have the3535+ * same number of elements (except when @props_title has exactly one element).3636+ *3737+ * Return: zero on success, negative error on failure.3838+ */3939+static int fwnode_get_u32_prop_for_name(struct fwnode_handle *fwnode,4040+ const char *name,4141+ const char *props_title,4242+ const char *names_title,4343+ unsigned int default_val,4444+ unsigned int *val)4545+{4646+ int err, n_props, n_names, idx;4747+ u32 *props;4848+4949+ if (!name) {5050+ pr_err("Lookup key inside \"%s\" is mandatory\n", names_title);5151+ return -EINVAL;5252+ }5353+5454+ n_props = fwnode_property_count_u32(fwnode, props_title);5555+ if (n_props <= 0) {5656+ /* fwnode is NULL, or is missing requested property */5757+ *val = default_val;5858+ return 0;5959+ }6060+6161+ n_names = fwnode_property_string_array_count(fwnode, names_title);6262+ if (n_names >= 0 && n_props != n_names) {6363+ pr_err("%pfw mismatch between \"%s\" and \"%s\" property count (%d vs %d)\n",6464+ fwnode, props_title, names_title, n_props, n_names);6565+ return -EINVAL;6666+ }6767+6868+ idx = fwnode_property_match_string(fwnode, names_title, name);6969+ if (idx < 0)7070+ idx = fwnode_property_match_string(fwnode, names_title, "default");7171+ /*7272+ * If the mode name is missing, it can only mean the specified property7373+ * is the default one for all modes, so reject any other property count7474+ * than 1.7575+ */7676+ if (idx < 0 && n_props != 1) {7777+ pr_err("%pfw \"%s \" property has %d elements, but cannot find \"%s\" in \"%s\" and there is no default value\n",7878+ fwnode, props_title, n_props, name, names_title);7979+ return -EINVAL;8080+ }8181+8282+ if (n_props == 1) {8383+ err = fwnode_property_read_u32(fwnode, props_title, val);8484+ if (err)8585+ return err;8686+8787+ return 0;8888+ }8989+9090+ /* We implicitly know idx >= 0 here */9191+ props = kcalloc(n_props, sizeof(*props), GFP_KERNEL);9292+ if (!props)9393+ return -ENOMEM;9494+9595+ err = fwnode_property_read_u32_array(fwnode, props_title, props, n_props);9696+ if (err >= 0)9797+ *val = props[idx];9898+9999+ kfree(props);100100+101101+ return err;102102+}103103+104104+static int phy_get_polarity_for_mode(struct fwnode_handle *fwnode,105105+ const char *mode_name,106106+ unsigned int supported,107107+ unsigned int default_val,108108+ const char *polarity_prop,109109+ const char *names_prop,110110+ unsigned int *val)111111+{112112+ int err;113113+114114+ err = fwnode_get_u32_prop_for_name(fwnode, mode_name, polarity_prop,115115+ names_prop, default_val, val);116116+ if (err)117117+ return err;118118+119119+ if (!(supported & BIT(*val))) {120120+ pr_err("%d is not a supported value for %pfw '%s' element '%s'\n",121121+ *val, fwnode, polarity_prop, mode_name);122122+ err = -EOPNOTSUPP;123123+ }124124+125125+ return err;126126+}127127+128128+/**129129+ * phy_get_rx_polarity - Get RX polarity for PHY differential lane130130+ * @fwnode: Pointer to the PHY's firmware node.131131+ * @mode_name: The name of the PHY mode to look up.132132+ * @supported: Bit mask of PHY_POL_NORMAL, PHY_POL_INVERT and PHY_POL_AUTO133133+ * @default_val: Default polarity value if property is missing134134+ * @val: Pointer to returned polarity.135135+ *136136+ * Return: zero on success, negative error on failure.137137+ */138138+int __must_check phy_get_rx_polarity(struct fwnode_handle *fwnode,139139+ const char *mode_name,140140+ unsigned int supported,141141+ unsigned int default_val,142142+ unsigned int *val)143143+{144144+ return phy_get_polarity_for_mode(fwnode, mode_name, supported,145145+ default_val, "rx-polarity",146146+ "rx-polarity-names", val);147147+}148148+EXPORT_SYMBOL_GPL(phy_get_rx_polarity);149149+150150+/**151151+ * phy_get_tx_polarity - Get TX polarity for PHY differential lane152152+ * @fwnode: Pointer to the PHY's firmware node.153153+ * @mode_name: The name of the PHY mode to look up.154154+ * @supported: Bit mask of PHY_POL_NORMAL and PHY_POL_INVERT155155+ * @default_val: Default polarity value if property is missing156156+ * @val: Pointer to returned polarity.157157+ *158158+ * Return: zero on success, negative error on failure.159159+ */160160+int __must_check phy_get_tx_polarity(struct fwnode_handle *fwnode,161161+ const char *mode_name, unsigned int supported,162162+ unsigned int default_val, unsigned int *val)163163+{164164+ return phy_get_polarity_for_mode(fwnode, mode_name, supported,165165+ default_val, "tx-polarity",166166+ "tx-polarity-names", val);167167+}168168+EXPORT_SYMBOL_GPL(phy_get_tx_polarity);169169+170170+/**171171+ * phy_get_manual_rx_polarity - Get manual RX polarity for PHY differential lane172172+ * @fwnode: Pointer to the PHY's firmware node.173173+ * @mode_name: The name of the PHY mode to look up.174174+ * @val: Pointer to returned polarity.175175+ *176176+ * Helper for PHYs which do not support protocols with automatic RX polarity177177+ * detection and correction.178178+ *179179+ * Return: zero on success, negative error on failure.180180+ */181181+int __must_check phy_get_manual_rx_polarity(struct fwnode_handle *fwnode,182182+ const char *mode_name,183183+ unsigned int *val)184184+{185185+ return phy_get_rx_polarity(fwnode, mode_name,186186+ BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT),187187+ PHY_POL_NORMAL, val);188188+}189189+EXPORT_SYMBOL_GPL(phy_get_manual_rx_polarity);190190+191191+/**192192+ * phy_get_manual_tx_polarity - Get manual TX polarity for PHY differential lane193193+ * @fwnode: Pointer to the PHY's firmware node.194194+ * @mode_name: The name of the PHY mode to look up.195195+ * @val: Pointer to returned polarity.196196+ *197197+ * Helper for PHYs without any custom default value for the TX polarity.198198+ *199199+ * Return: zero on success, negative error on failure.200200+ */201201+int __must_check phy_get_manual_tx_polarity(struct fwnode_handle *fwnode,202202+ const char *mode_name,203203+ unsigned int *val)204204+{205205+ return phy_get_tx_polarity(fwnode, mode_name,206206+ BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT),207207+ PHY_POL_NORMAL, val);208208+}209209+EXPORT_SYMBOL_GPL(phy_get_manual_tx_polarity);