net: phy: Support DT PHY package
Subsystems (7)
v2 cover net: phy: Support DT PHY package
Idea of this big series is to introduce the concept of PHY package in DT and generalize the support of it by PHY driver.
The concept of PHY package is nothing new and is already a thing in the kernel with the API phy_package_join/leave/read/write.
The main idea of those API is to permit the PHY to have a shared global data and to run probe/config only once for the PHY package. There are various example of this already in the kernel with the mscc, bcm54140 mediatek ge and micrle driver and they all follow the same pattern.
What is currently lacking is describing this in DT and better reference the PHY in charge of global configuration of the PHY package. For the already present PHY, the implementation is simple enough with only one PHY having the required regs to apply global configuration.
This can be ok for simple PHY package but some Qcom PHY package on ""modern"" SoC have more complex implementation. One example is the PHY for qca807x where some global regs are present in the so-called "combo" port and everything about psgmii calibration is placed in a 5th port in the PHY package.
Given these additional thing, the original phy_package API are extended with support for multiple global PHY for configuration. Each PHY driver will have an enum of the ID for the global PHY to reference and is required to pass to the read/write function.
On top of this, it's added correct DT support for describing PHY package.
One example is this:
ethernet-phy-package@0 {
#address-cells = <1>;
#size-cells = <0>;
reg = <0>;
ethernet-phy@1 {
compatible = "ethernet-phy-ieee802.3-c22";
reg = <1>;
};
phy4: ethernet-phy@4 {
compatible = "ethernet-phy-ieee802.3-c22";
reg = <4>;
};
};The mdio parse functions are changed to address for this additional special node, the function is changed to simply detect this node and search also in this.
If this is detected phy core will join each PHY present in the node and use (if defined) the additional info in the PHY driver to probe/config once the PHY package.
I hope this implementation is clean enough as I expect more and more of these configuration to appear in the future.
(For Andrew, we are looking intro making this in at803x PHY driver and see what functions can be reused, idea is to move the driver to a dedicated directory and create something like at803x-common.c as the at803x PHY driver is too bloated and splitting it it's a better approach)
Changes v2:
- Drop compatible "ethernet-phy-package", use node name prefix matching instead
- Improve DT example
- Add reg for ethernet-phy-package
- Drop phy-mode for ethernet-phy-package
- Drop patch for generalization of phy-mode
- Drop global-phy property (handle internally to the PHY driver)
- Rework OF phy package code and PHY driver to handle base address
- Fix missing of_node_put
- Add some missing docs for added variables in struct
- Move some define from dt-bindings include to PHY driver
- Handle qsgmii validation in PHY driver
- Fix wrong include for gpiolib
- Drop reduntant version.h include
Christian Marangi (9):
net: phy: extend PHY package API to support multiple global address
dt-bindings: net: document ethernet PHY package nodes
net: phy: add initial support for PHY package in DT
net: phy: add support for shared priv data size for PHY package in DT
net: phy: add support for driver specific PHY package probe/config
net: phy: move mmd_phy_indirect to generic header
net: phy: add support for PHY package MMD read/write
dt-bindings: net: Document Qcom QCA807x PHY package
net: phy: qca807x: Add support for configurable LED
Robert Marko (2):
dt-bindings: net: add QCA807x PHY defines
net: phy: add Qualcom QCA807x driver
.../bindings/net/ethernet-phy-package.yaml | 66 + .../devicetree/bindings/net/qcom,qca807x.yaml | 148 ++ drivers/net/mdio/of_mdio.c | 68 +- drivers/net/phy/Kconfig | 7 + drivers/net/phy/Makefile | 1 + drivers/net/phy/bcm54140.c | 23 +- drivers/net/phy/mdio_bus.c | 35 +- drivers/net/phy/mediatek-ge-soc.c | 11 +- drivers/net/phy/micrel.c | 13 +- drivers/net/phy/mscc/mscc.h | 7 + drivers/net/phy/mscc/mscc_main.c | 16 +- drivers/net/phy/phy-core.c | 14 - drivers/net/phy/phy_device.c | 165 +- drivers/net/phy/qca807x.c | 1324 +++++++++++++++++ include/dt-bindings/net/qcom-qca807x.h | 30 + include/linux/phy.h | 170 ++- 16 files changed, 1996 insertions(+), 102 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/ethernet-phy-package.yaml create mode 100644 Documentation/devicetree/bindings/net/qcom,qca807x.yaml create mode 100644 drivers/net/phy/qca807x.c create mode 100644 include/dt-bindings/net/qcom-qca807x.h
Signature · 1 line
2.40.1
RFC PATCH v2 1/11 net: phy: extend PHY package API to support multiple global address
Current API for PHY package are limited to single address to configure global settings for the PHY package.
It was found that some PHY package (for example the qca807x, a PHY package that is shipped with a bundle of 5 PHY) require multiple PHY address to configure global settings. An example scenario is a PHY that have a dedicated PHY for PSGMII/serdes calibrarion and have a specific PHY in the package where the global PHY mode is set and affects every other PHY in the package.
Change the API in the following way:
- Make phy_package_join() require a list of address to be passed and the number of address in the list
- On shared data init, each address is the list is checked and added to the shared struct.
- Make __/phy_package_write/read() require an additional arg that select what global PHY address to use in the provided list.
Each user of this API is updated to follow this new implementation following a pattern where an enum is defined to declare the index of the addr and the addr list is passed.
--- drivers/net/phy/bcm54140.c | 23 +++++++-- drivers/net/phy/mediatek-ge-soc.c | 11 +++- drivers/net/phy/micrel.c | 13 +++-- drivers/net/phy/mscc/mscc.h | 7 +++ drivers/net/phy/mscc/mscc_main.c | 16 ++++-- drivers/net/phy/phy_device.c | 85 ++++++++++++++++++++----------- include/linux/phy.h | 51 +++++++++++++------ 7 files changed, 147 insertions(+), 59 deletions(-)
drivers/net/phy/bcm54140.c +18 -5
@@ -128,6 +128,12 @@#define BCM54140_DEFAULT_DOWNSHIFT 5#define BCM54140_MAX_DOWNSHIFT 9 +enum bcm54140_global_phy { +BCM54140_BASE_ADDR =0 , + + __BCM54140_GLOBAL_PHY_MAX, +}; +struct bcm54140_priv {int port;int base_addr;
@@ -429,11 +435,13 @@ static int bcm54140_base_read_rdb(struct phy_device *phydev, u16 rdb)int ret;phy_lock_mdio_bus (phydev); - ret =__phy_package_write (phydev,MII_BCM54XX_RDB_ADDR , rdb); + ret =__phy_package_write (phydev,BCM54140_BASE_ADDR , +MII_BCM54XX_RDB_ADDR , rdb);if (ret <0 ) goto out; - ret =__phy_package_read (phydev,MII_BCM54XX_RDB_DATA ); + ret =__phy_package_read (phydev,BCM54140_BASE_ADDR , +MII_BCM54XX_RDB_DATA ); out:phy_unlock_mdio_bus (phydev);
@@ -446,11 +454,13 @@ static int bcm54140_base_write_rdb(struct phy_device *phydev,int ret;phy_lock_mdio_bus (phydev); - ret =__phy_package_write (phydev,MII_BCM54XX_RDB_ADDR , rdb); + ret =__phy_package_write (phydev,BCM54140_BASE_ADDR , +MII_BCM54XX_RDB_ADDR , rdb);if (ret <0 ) goto out; - ret =__phy_package_write (phydev,MII_BCM54XX_RDB_DATA , val); + ret =__phy_package_write (phydev,BCM54140_BASE_ADDR , +MII_BCM54XX_RDB_DATA , val); out:phy_unlock_mdio_bus (phydev);
@@ -570,6 +580,7 @@ static int bcm54140_get_base_addr_and_port(struct phy_device *phydev)static int bcm54140_probe (struct phy_device *phydev) { +int addrs[__BCM54140_GLOBAL_PHY_MAX];struct bcm54140_priv *priv;int ret;
@@ -583,7 +594,9 @@ static int bcm54140_probe(struct phy_device *phydev)if (ret)return ret; -devm_phy_package_join (&phydev->mdio.dev, phydev, priv->base_addr,0 ); + addrs[BCM54140_BASE_ADDR ] = priv->base_addr; +devm_phy_package_join (&phydev->mdio.dev, phydev, addrs, +ARRAY_SIZE (addrs),0 );#if IS_ENABLED (CONFIG_HWMON )mutex_init (&priv->alarm_lock);
drivers/net/phy/mediatek-ge-soc.c +10 -1
@@ -298,6 +298,12 @@ struct mtk_socphy_priv {unsigned long led_state; }; +enum mtk_global_phy { +MTK_BASE_ADDR =0 , + + __MTK_GLOBAL_PHY_MAX +}; +struct mtk_socphy_shared {u32 boottrap;struct mtk_socphy_priv priv[4 ];
@@ -1431,13 +1437,16 @@ static void mt798x_phy_leds_state_init(struct phy_device *phydev)static int mt7988_phy_probe (struct phy_device *phydev) {struct mtk_socphy_shared *shared; +int addrs[__MTK_GLOBAL_PHY_MAX];struct mtk_socphy_priv *priv;int err;if (phydev->mdio.addr >3 )return -EINVAL ; - err =devm_phy_package_join (&phydev->mdio.dev, phydev,0 , + addrs[MTK_BASE_ADDR ] =0 ; + err =devm_phy_package_join (&phydev->mdio.dev, phydev, + addrs,ARRAY_SIZE (addrs),sizeof (struct mtk_socphy_shared ));if (err)return err;
drivers/net/phy/micrel.c +10 -3
@@ -328,6 +328,12 @@ struct kszphy_ptp_priv {spinlock_t seconds_lock; }; +enum ksz_global_phy { +KSZ_BASE_ADDR =0 , + + __KZS_GLOBAL_PHY_MAX, +}; +struct kszphy_priv {struct kszphy_ptp_priv ptp_priv;const struct kszphy_type *type;
@@ -3274,8 +3280,8 @@ static int lan8814_release_coma_mode(struct phy_device *phydev)static int lan8814_probe (struct phy_device *phydev) {const struct kszphy_type *type = phydev->drv->driver_data; +int addrs[__KZS_GLOBAL_PHY_MAX];struct kszphy_priv *priv; -u16 addr;int err; priv =devm_kzalloc (&phydev->mdio.dev,sizeof (*priv),GFP_KERNEL );
@@ -3291,9 +3297,10 @@ static int lan8814_probe(struct phy_device *phydev)/* Strap-in value for PHY address, below register read gives starting * phy address value */ - addr =lanphy_read_page_reg (phydev,4 ,0 ) &0x1F ; + addrs[KSZ_BASE_ADDR ] =lanphy_read_page_reg (phydev,4 ,0 ) &0x1F ;devm_phy_package_join (&phydev->mdio.dev, phydev, - addr,sizeof (struct lan8814_shared_priv )); + addrs,ARRAY_SIZE (addrs), +sizeof (struct lan8814_shared_priv ));if (phy_package_init_once (phydev)) { err =lan8814_release_coma_mode (phydev);
drivers/net/phy/mscc/mscc.h +7 -0
@@ -416,6 +416,13 @@ struct vsc8531_private {* gpio_lock: used for PHC operations. Common for all PHYs as the load/save GPIO * is shared. */ + +enum vsc85xx_global_phy { +VSC88XX_BASE_ADDR =0 , + + __VSC8XX_GLOBAL_PHY_MAX, +}; +struct vsc85xx_shared_private {struct mutex gpio_lock; };
drivers/net/phy/mscc/mscc_main.c +11 -5
@@ -711,7 +711,7 @@ int phy_base_write(struct phy_device *phydev, u32 regnum, u16 val)dump_stack (); } -return __phy_package_write (phydev, regnum, val); +return __phy_package_write (phydev,VSC88XX_BASE_ADDR , regnum, val); }/* phydev->bus->mdio_lock should be locked when using this function */
@@ -722,7 +722,7 @@ int phy_base_read(struct phy_device *phydev, u32 regnum)dump_stack (); } -return __phy_package_read (phydev, regnum); +return __phy_package_read (phydev,VSC88XX_BASE_ADDR , regnum); } u32 vsc85xx_csr_read(struct phy_device *phydev,
@@ -2204,6 +2204,7 @@ static int vsc85xx_read_status(struct phy_device *phydev)static int vsc8514_probe (struct phy_device *phydev) { +int addrs[__VSC8XX_GLOBAL_PHY_MAX];struct vsc8531_private *vsc8531;u32 default_mode[4 ] = {VSC8531_LINK_1000_ACTIVITY ,VSC8531_LINK_100_ACTIVITY ,VSC8531_LINK_ACTIVITY ,
@@ -2216,8 +2217,9 @@ static int vsc8514_probe(struct phy_device *phydev) phydev->priv = vsc8531;vsc8584_get_base_addr (phydev); + addrs[VSC88XX_BASE_ADDR ] = vsc8531->base_addr;devm_phy_package_join (&phydev->mdio.dev, phydev, - vsc8531->base_addr,0 ); + addrs,ARRAY_SIZE (addrs),0 ); vsc8531->nleds =4 ; vsc8531->supp_led_modes =VSC85XX_SUPP_LED_MODES ;
@@ -2233,6 +2235,7 @@ static int vsc8514_probe(struct phy_device *phydev)static int vsc8574_probe (struct phy_device *phydev) { +int addrs[__VSC8XX_GLOBAL_PHY_MAX];struct vsc8531_private *vsc8531;u32 default_mode[4 ] = {VSC8531_LINK_1000_ACTIVITY ,VSC8531_LINK_100_ACTIVITY ,VSC8531_LINK_ACTIVITY ,
@@ -2245,8 +2248,9 @@ static int vsc8574_probe(struct phy_device *phydev) phydev->priv = vsc8531;vsc8584_get_base_addr (phydev); + addrs[VSC88XX_BASE_ADDR ] = vsc8531->base_addr;devm_phy_package_join (&phydev->mdio.dev, phydev, - vsc8531->base_addr,0 ); + addrs,ARRAY_SIZE (addrs),0 ); vsc8531->nleds =4 ; vsc8531->supp_led_modes =VSC8584_SUPP_LED_MODES ;
@@ -2262,6 +2266,7 @@ static int vsc8574_probe(struct phy_device *phydev)static int vsc8584_probe (struct phy_device *phydev) { +int addrs[__VSC8XX_GLOBAL_PHY_MAX];struct vsc8531_private *vsc8531;u32 default_mode[4 ] = {VSC8531_LINK_1000_ACTIVITY ,VSC8531_LINK_100_ACTIVITY ,VSC8531_LINK_ACTIVITY ,
@@ -2280,7 +2285,8 @@ static int vsc8584_probe(struct phy_device *phydev) phydev->priv = vsc8531;vsc8584_get_base_addr (phydev); -devm_phy_package_join (&phydev->mdio.dev, phydev, vsc8531->base_addr, + addrs[VSC88XX_BASE_ADDR ] = vsc8531->base_addr; +devm_phy_package_join (&phydev->mdio.dev, phydev, addrs,ARRAY_SIZE (addrs),sizeof (struct vsc85xx_shared_private )); vsc8531->nleds =4 ;
drivers/net/phy/phy_device.c +56 -29
155 lines not on this page · raw message
include/linux/phy.h +35 -16
105 lines not on this page · raw message
Signature · 1 line
2.40.1
RFC PATCH v2 2/11 dt-bindings: net: document ethernet PHY package nodes
In reply to Christian MarangiDocument ethernet PHY package nodes used to describe PHY shipped in bundle of 4-5 PHY. These particular PHY require specific PHY in the package for global onfiguration of the PHY package.
Example are PHY package that have some regs only in one PHY of the package and will affect every other PHY in the package, for example related to PHY interface mode calibration or global PHY mode selection.
The PHY package node MUST declare the base address used by the PHY driver for global configuration by calculating the offsets of the global PHY based on the base address of the PHY package.
--- .../bindings/net/ethernet-phy-package.yaml | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/ethernet-phy-package.yaml
Documentation/devicetree/bindings/net/ethernet-phy-package.yaml new file +66 -0
@@ -0,0 +1,66 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/ethernet-phy-package.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Ethernet PHY Package Common Properties + +maintainers: + - Christian Marangi <[email protected] + +select: + properties: + $nodename: + pattern: "^ethernet-phy-package(@[a-f0-9]+)?$" + + required: + - $nodename + +properties: + $nodename: + pattern: "^ethernet-phy-package(@[a-f0-9]+)?$" + + reg: + minimum: 0 + maximum: 31 + description: + The ID number for the PHY. + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + ^ethernet-phy(@[a-f0-9]+)?$: + $ref: /schemas/net/ethernet-phy.yaml# + +required: + - reg + +additionalProperties: true + +examples: + - | + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy-package@0 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0>; + + ethernet-phy@0 { + compatible = "ethernet-phy-ieee802.3-c22"; + reg = <0>; + }; + + phy4: ethernet-phy@4 { + compatible = "ethernet-phy-ieee802.3-c22"; + reg = <4>; + }; + }; + };
Signature · 1 line
2.40.1
RFC PATCH v2 3/11 net: phy: add initial support for PHY package in DT
In reply to Christian MarangiAdd initial support for PHY package in DT.
Make it easier to define PHY package and describe the global PHY directly in DT by refereincing them by phandles instead of custom functions in each PHY driver.
Each PHY in a package needs to be defined in a dedicated node in the mdio node. This dedicated node needs to have the node name with the prefix "ethernet-phy-package".
With this defined, the generic PHY probe will join each PHY in this dedicated node to the package.
PHY driver MUST set the required global PHY count in .phy_package_global_phy_num and define .phy_package_global_phys_offset as the table of offset of the required global PHYs for PHY package global configuration.
mdio_bus.c and of_mdio.c is updated to now support and parse also PHY package subnote by checking if the node name have the prefix "ethernet-phy-package".
--- drivers/net/mdio/of_mdio.c | 68 +++++++++++++++++++++++++----------- drivers/net/phy/mdio_bus.c | 35 ++++++++++++++----- drivers/net/phy/phy_device.c | 61 ++++++++++++++++++++++++++++++++ include/linux/phy.h | 9 +++++ 4 files changed, 144 insertions(+), 29 deletions(-)
drivers/net/mdio/of_mdio.c +47 -21
@@ -139,6 +139,47 @@ bool of_mdiobus_child_is_phy(struct device_node *child) }EXPORT_SYMBOL (of_mdiobus_child_is_phy); +static int __of_mdiobus_parse_phys (struct mii_bus *mdio,struct device_node *np, +bool *scanphys) +{ +struct device_node *child; +int addr, rc =0 ; + +/* Loop over the child nodes and register a phy_device for each phy */ +for_each_available_child_of_node (np, child) { +if (of_node_name_prefix (child,"ethernet-phy-package" )) { + rc =__of_mdiobus_parse_phys (mdio, child, scanphys); +if (rc && rc != -ENODEV ) + goto exit; + +continue ; + } + + addr =of_mdio_parse_addr (&mdio->dev, child); +if (addr <0 ) { + *scanphys = true; +continue ; + } + +if (of_mdiobus_child_is_phy (child)) + rc =of_mdiobus_register_phy (mdio, child, addr); +else + rc =of_mdiobus_register_device (mdio, child, addr); + +if (rc == -ENODEV ) +dev_err (&mdio->dev, +"MDIO device at address %d is missing.\n" , + addr); +else if (rc) + goto exit; + } + +return 0 ; +exit: +of_node_put (child); +return rc; +} +/** * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree * @mdio: pointer to mii_bus structure
@@ -180,25 +221,9 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np,return rc;/* Loop over the child nodes and register a phy_device for each phy */ -for_each_available_child_of_node (np, child) { - addr =of_mdio_parse_addr (&mdio->dev, child); -if (addr <0 ) { - scanphys = true; -continue ; - } - -if (of_mdiobus_child_is_phy (child)) - rc =of_mdiobus_register_phy (mdio, child, addr); -else - rc =of_mdiobus_register_device (mdio, child, addr); - -if (rc == -ENODEV ) -dev_err (&mdio->dev, -"MDIO device at address %d is missing.\n" , - addr); -else if (rc) - goto unregister; - } + rc =__of_mdiobus_parse_phys (mdio, np, &scanphys); +if (rc) + goto unregister;if (!scanphys)return 0 ;
@@ -227,15 +252,16 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np,if (!rc)break ;if (rc != -ENODEV ) - goto unregister; + goto put_unregister; } } }return 0 ; -unregister: +put_unregister:of_node_put (child); +unregister:mdiobus_unregister (mdio);return rc; }
drivers/net/phy/mdio_bus.c +27 -8
@@ -455,19 +455,25 @@ EXPORT_SYMBOL(of_mdio_find_bus);* found, set the of_node pointer for the mdio device. This allows * auto-probed phy devices to be supplied with information passed in * via DT. +* If a PHY package is found, PHY is searched also there. */ -static void of_mdiobus_link_mdiodev (struct mii_bus *bus, -struct mdio_device *mdiodev) +static int of_mdiobus_find_phy (struct device *dev,struct mdio_device *mdiodev, +struct device_node *np) { -struct device *dev = &mdiodev->dev;struct device_node *child; -if (dev->of_node || !bus->dev.of_node) -return ; - -for_each_available_child_of_node (bus->dev.of_node, child) { +for_each_available_child_of_node (np, child) {int addr; +if (of_node_name_prefix (child,"ethernet-phy-package" )) { +if (!of_mdiobus_find_phy (dev, mdiodev, child)) { +of_node_put (child); +return 0 ; + } + +continue ; + } + addr =of_mdio_parse_addr (dev, child);if (addr <0 )continue ;
@@ -477,9 +483,22 @@ static void of_mdiobus_link_mdiodev(struct mii_bus *bus,/* The refcount on "child" is passed to the mdio * device. Do _not_ use of_node_put(child) here. */ - return; + return 0; } } + +return -ENODEV ; +} + +static void of_mdiobus_link_mdiodev (struct mii_bus *bus, +struct mdio_device *mdiodev) +{ +struct device *dev = &mdiodev->dev; + +if (dev->of_node || !bus->dev.of_node) +return ; + +of_mdiobus_find_phy (dev, mdiodev, bus->dev.of_node); }#else /* !IS_ENABLED(CONFIG_OF_MDIO) */ static inline void of_mdiobus_link_mdiodev(struct mii_bus *mdio,
drivers/net/phy/phy_device.c +61 -0
73 lines not on this page · raw message
include/linux/phy.h +9 -0
@@ -327,6 +327,7 @@ struct mdio_bus_stats {/** * struct phy_package_shared - Shared information in PHY packages +* @np: Pointer to the Device Node if PHY package defined in DT * @addrs: List of common PHY addresses used to combine PHYs in one package * @addrs_num: Number of common PHY addresses in addrs list * @refcnt: Number of PHYs connected to this shared data
@@ -339,6 +340,8 @@ struct mdio_bus_stats {* phy_package_leave(). */ struct phy_package_shared { +/* With PHY package defined in DT this points to the PHY package node */ +struct device_node *np;/* addrs list pointer */ /* note that this pointer is shared between different phydevs. * It is allocated and freed automatically by phy_package_join() and
@@ -888,6 +891,10 @@ struct phy_led {* @flags: A bitfield defining certain other features this PHY * supports (like interrupts) * @driver_data: Static driver data +* @phy_package_global_phys_offset: Table of offset of the required +* global PHYs for PHY package global configuration. +* @phy_package_global_phys_num: Num of the required global PHYs +* for PHY package global configuration. * * All functions are optional. If config_aneg or read_status * are not implemented, the phy core uses the genphy versions.
@@ -905,6 +912,8 @@ struct phy_driver {const unsigned long *const features;u32 flags;const void *driver_data; +const u8 *phy_package_global_phys_offset; +const u8 phy_package_global_phys_num;/** * @soft_reset: Called to issue a PHY software reset
Signature · 1 line
2.40.1
RFC PATCH v2 4/11 net: phy: add support for shared priv data size for PHY package in DT
In reply to Christian MarangiAdd support for defining shared data size for PHY package defined in DT.
A PHY driver has to define the value .phy_package_priv_data_size to make the generic OF PHY package function alloc priv data in the shared struct for the PHY package.
--- drivers/net/phy/phy_device.c | 7 ++++++- include/linux/phy.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/phy/phy_device.c +6 -1
@@ -3198,6 +3198,7 @@ static int of_phy_package(struct phy_device *phydev)struct device_node *node = phydev->mdio.dev.of_node;struct device_node *package_node;const u8 *global_phys_offset; +int shared_priv_data_size;int *global_phys_addr;u8 global_phys_num;u32 base_addr;
@@ -3236,8 +3237,12 @@ static int of_phy_package(struct phy_device *phydev) global_phys_addr[i] = addr; } + shared_priv_data_size =0 ; +if (phydev->drv->phy_package_priv_data_size) + shared_priv_data_size = phydev->drv->phy_package_priv_data_size; + ret =devm_phy_package_join (&phydev->mdio.dev, phydev, global_phys_addr, - global_phys_num,0 ); + global_phys_num, shared_priv_data_size);if (ret) goto exit;
include/linux/phy.h +3 -0
@@ -895,6 +895,8 @@ struct phy_led {* global PHYs for PHY package global configuration. * @phy_package_global_phys_num: Num of the required global PHYs * for PHY package global configuration. +* @phy_package_priv_data_size: Size of the priv data to alloc +* for shared struct of PHY package. * * All functions are optional. If config_aneg or read_status * are not implemented, the phy core uses the genphy versions.
@@ -914,6 +916,7 @@ struct phy_driver {const void *driver_data;const u8 *phy_package_global_phys_offset;const u8 phy_package_global_phys_num; +unsigned int phy_package_priv_data_size;/** * @soft_reset: Called to issue a PHY software reset
Signature · 1 line
2.40.1
RFC PATCH v2 5/11 net: phy: add support for driver specific PHY package probe/config
In reply to Christian MarangiAdd PHY driver specific function to probe and configure PHY package. These function are run only once before the PHY probe and config_init.
They are used in conjunction with DT PHY package define for basic PHY package implementation to setup and probe PHY package with simple functions directly defined in the PHY driver struct.
--- drivers/net/phy/phy_device.c | 14 ++++++++++++++ include/linux/phy.h | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+)
drivers/net/phy/phy_device.c +14 -0
@@ -1246,6 +1246,13 @@ int phy_init_hw(struct phy_device *phydev)if (ret <0 )return ret; +if (phydev->drv->phy_package_config_init_once && +phy_package_init_once (phydev)) { + ret = phydev->drv->phy_package_config_init_once (phydev); +if (ret <0 ) +return ret; + } +if (phydev->drv->config_init) { ret = phydev->drv->config_init (phydev);if (ret <0 )
@@ -3370,6 +3377,13 @@ static int phy_probe(struct device *dev)/* Deassert the reset signal */ phy_device_reset (phydev,0 ); +if (phydev->drv->phy_package_probe_once && +phy_package_probe_once (phydev)) { + err = phydev->drv->phy_package_probe_once (phydev); +if (err) + goto out; + } +if (phydev->drv->probe) { err = phydev->drv->probe (phydev);if (err)
include/linux/phy.h +21 -0
@@ -923,12 +923,33 @@ struct phy_driver {*/ int (*soft_reset)(struct phy_device *phydev); +/** +* @phy_package_config_init_once: Driver specific PHY package +* config init call +* @def: PHY device to use to probe PHY package +* +* Called to initialize the PHY package, including after +* a reset. +* Called BEFORE PHY config_init. +*/ +int (*phy_package_config_init_once)(struct phy_device *dev); +/** * @config_init: Called to initialize the PHY, * including after a reset */ int (*config_init)(struct phy_device *phydev); +/** +* @phy_package_probe_once: Driver specific PHY package probe +* @def: PHY device to use to probe PHY package +* +* Called during discovery once per PHY package. Used to set +* up device-specific PHY package structures, if any. +* Called BEFORE PHY probe. +*/ +int (*phy_package_probe_once)(struct phy_device *dev); +/** * @probe: Called during discovery. Used to set * up device-specific structures, if any
Signature · 1 line
2.40.1
RFC PATCH v2 6/11 net: phy: move mmd_phy_indirect to generic header
In reply to Christian MarangiMove mmd_phy_indirect function from phy-core to generic phy.h to permit future usage for PHY package read/write_mmd.
--- drivers/net/phy/phy-core.c | 14 -------------- include/linux/phy.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/net/phy/phy-core.c +0 -14
@@ -526,20 +526,6 @@ int phy_speed_down_core(struct phy_device *phydev)return 0 ; } -static void mmd_phy_indirect (struct mii_bus *bus,int phy_addr,int devad, -u16 regnum) -{ -/* Write the desired MMD Devad */ -__mdiobus_write (bus, phy_addr,MII_MMD_CTRL , devad); - -/* Write the desired MMD register address */ -__mdiobus_write (bus, phy_addr,MII_MMD_DATA , regnum); - -/* Select the Function : DATA with no post increment */ -__mdiobus_write (bus, phy_addr,MII_MMD_CTRL , - devad |MII_MMD_CTRL_NOINCR ); -} -/** * __phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY.
include/linux/phy.h +14 -0
@@ -1356,6 +1356,20 @@ static inline int __phy_modify_changed(struct phy_device *phydev, u32 regnum, regnum, mask, set); } +static inline void mmd_phy_indirect (struct mii_bus *bus,int phy_addr,int devad, +u16 regnum) +{ +/* Write the desired MMD Devad */ +__mdiobus_write (bus, phy_addr,MII_MMD_CTRL , devad); + +/* Write the desired MMD register address */ +__mdiobus_write (bus, phy_addr,MII_MMD_DATA , regnum); + +/* Select the Function : DATA with no post increment */ +__mdiobus_write (bus, phy_addr,MII_MMD_CTRL , + devad |MII_MMD_CTRL_NOINCR ); +} +/* * phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY.
Signature · 1 line
2.40.1
RFC PATCH v2 7/11 net: phy: add support for PHY package MMD read/write
In reply to Christian MarangiSome PHY in PHY package may require to read/write MMD regs to correctly configure the PHY package.
Add support for these additional required function in both lock and no lock variant.
--- include/linux/phy.h | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+)
include/linux/phy.h +72 -0
@@ -2104,6 +2104,78 @@ static inline int __phy_package_write(struct phy_device *phydev,return __mdiobus_write (phydev->mdio.bus, addr, regnum, val); } +static inline int phy_package_read_mmd (struct phy_device *phydev, +int global_phy_index,int devad,u32 regnum) +{ +struct phy_package_shared *shared = phydev->shared; +struct mii_bus *bus = phydev->mdio.bus; +int addr, val; + +if (!shared || global_phy_index > shared->addrs_num -1 ) +return -EIO ; + + addr = shared->addrs[global_phy_index]; + +phy_lock_mdio_bus (phydev); +mmd_phy_indirect (bus, addr, devad, regnum); + val =__mdiobus_read (bus, addr,MII_MMD_DATA ); +phy_unlock_mdio_bus (phydev); + +return val; +} + +static inline int __phy_package_read_mmd (struct phy_device *phydev, +int global_phy_index,int devad,u32 regnum) +{ +struct phy_package_shared *shared = phydev->shared; +struct mii_bus *bus = phydev->mdio.bus; +int addr; + +if (!shared || global_phy_index > shared->addrs_num -1 ) +return -EIO ; + + addr = shared->addrs[global_phy_index]; +mmd_phy_indirect (bus, addr, devad, regnum); +return __mdiobus_read (bus, addr,MII_MMD_DATA ); +} + +static inline int phy_package_write_mmd (struct phy_device *phydev, +int global_phy_index,int devad, +u32 regnum,u16 val) +{ +struct phy_package_shared *shared = phydev->shared; +struct mii_bus *bus = phydev->mdio.bus; +int addr, ret; + +if (!shared || global_phy_index > shared->addrs_num -1 ) +return -EIO ; + + addr = shared->addrs[global_phy_index]; + +phy_lock_mdio_bus (phydev); +mmd_phy_indirect (bus, addr, devad, regnum); + ret =__mdiobus_write (bus, addr,MII_MMD_DATA , val); +phy_unlock_mdio_bus (phydev); + +return ret; +} + +static inline int __phy_package_write_mmd (struct phy_device *phydev, +int global_phy_index,int devad, +u32 regnum,u16 val) +{ +struct phy_package_shared *shared = phydev->shared; +struct mii_bus *bus = phydev->mdio.bus; +int addr; + +if (!shared || global_phy_index > shared->addrs_num -1 ) +return -EIO ; + + addr = shared->addrs[global_phy_index]; +mmd_phy_indirect (bus, addr, devad, regnum); +return __mdiobus_write (bus, addr,MII_MMD_DATA , val); +} +static inline bool __phy_package_set_once (struct phy_device *phydev,unsigned int b) {
Signature · 1 line
2.40.1
RFC PATCH v2 8/11 dt-bindings: net: add QCA807x PHY defines
In reply to Christian MarangiFrom: Robert Marko <[email protected]>
Add DT bindings defined for Qualcomm QCA807x PHY series related to calibration and DAC settings.
--- include/dt-bindings/net/qcom-qca807x.h | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 include/dt-bindings/net/qcom-qca807x.h
include/dt-bindings/net/qcom-qca807x.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* +* Device Tree constants for the Qualcomm QCA807X PHYs +*/ + +#ifndef _DT_BINDINGS_QCOM_QCA807X_H +#define _DT_BINDINGS_QCOM_QCA807X_H + +/* Full amplitude, full bias current */ +#define QCA807X_CONTROL_DAC_FULL_VOLT_BIAS 0 +/* Amplitude follow DSP (amplitude is adjusted based on cable length), half bias current */ +#define QCA807X_CONTROL_DAC_DSP_VOLT_HALF_BIAS 1 +/* Full amplitude, bias current follow DSP (bias current is adjusted based on cable length) */ +#define QCA807X_CONTROL_DAC_FULL_VOLT_DSP_BIAS 2 +/* Both amplitude and bias current follow DSP */ +#define QCA807X_CONTROL_DAC_DSP_VOLT_BIAS 3 +/* Full amplitude, half bias current */ +#define QCA807X_CONTROL_DAC_FULL_VOLT_HALF_BIAS 4 +/* Amplitude follow DSP setting; 1/4 bias current when cable<10m, +* otherwise half bias current +*/ +#define QCA807X_CONTROL_DAC_DSP_VOLT_QUARTER_BIAS 5 +/* Full amplitude; same bias current setting with “010” and “011”, +* but half more bias is reduced when cable <10m +*/ +#define QCA807X_CONTROL_DAC_FULL_VOLT_HALF_BIAS_SHORT 6 +/* Amplitude follow DSP; same bias current setting with “110”, default value */ +#define QCA807X_CONTROL_DAC_DSP_VOLT_HALF_BIAS_SHORT 7 + +#endif
Signature · 1 line
2.40.1
RFC PATCH v2 9/11 dt-bindings: net: Document Qcom QCA807x PHY package
In reply to Christian MarangiDocument Qcom QCA807x PHY package.
Qualcomm QCA807X Ethernet PHY is PHY package of 2 or 5 IEEE 802.3 clause 22 compliant 10BASE-Te, 100BASE-TX and 1000BASE-T PHY-s.
Document the required property to make the PHY package correctly configure and work.
--- .../devicetree/bindings/net/qcom,qca807x.yaml | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/qcom,qca807x.yaml
Documentation/devicetree/bindings/net/qcom,qca807x.yaml new file +148 -0
@@ -0,0 +1,148 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/qcom,qca807x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm QCA807X Ethernet PHY + +maintainers: + - Christian Marangi <[email protected]> + - Robert Marko <[email protected]> + +description: | + Qualcomm QCA807X Ethernet PHY is PHY package of 2 or 5 + IEEE 802.3 clause 22 compliant 10BASE-Te, 100BASE-TX and + 1000BASE-T PHY-s. + + They feature 2 SerDes, one for PSGMII or QSGMII connection with + MAC, while second one is SGMII for connection to MAC or fiber. + + Both models have a combo port that supports 1000BASE-X and + 100BASE-FX fiber. + + Each PHY inside of QCA807x series has 4 digitally controlled + output only pins that natively drive LED-s for up to 2 attached + LEDs. Some vendor also use these 4 output for GPIO usage without + attaching LEDs. + + Note that output pins can be set to drive LEDs OR GPIO, mixed + definition are not accepted. + +allOf: + - $ref: ethernet-phy-package.yaml# + +select: + properties: + $nodename: + pattern: "^ethernet-phy-package(@[a-f0-9]+)?$" + + patternProperties: + ^ethernet-phy(@[a-f0-9]+)?$: + properties: + compatible: + contains: + enum: + - ethernet-phy-id004d.d0b2 + - ethernet-phy-id004d.d0b1 + + required: + - compatible + + required: + - $nodename + +properties: + qcom,package-mode: + enum: + - qsgmii + - psgmii + + qcom,tx-driver-strength: + enum: [140, 160, 180, 200, 220 + 240, 260, 280, 300, 320 + 400, 500, 600] + +patternProperties: + ^ethernet-phy(@[a-f0-9]+)?$: + $ref: /schemas/net/ethernet-phy.yaml# + + properties: + gpio-controller: + description: set the output lines as GPIO instead of LEDs + type: boolean + + '#gpio-cells': + description: number of GPIO cells for the PHY + const: 2 + + dependencies: + gpio-controller: ['#gpio-cells'] + + if: + required: + - gpio-controller + then: + properties: + leds: false + + unevaluatedProperties: false + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/leds/common.h> + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy-package@0 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0>; + + qcom,package-mode = "qsgmii"; + + ethernet-phy@0 { + compatible = "ethernet-phy-id004d.d0b2"; + reg = <0>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = <LED_COLOR_ID_GREEN>; + function = LED_FUNCTION_LAN; + default-state = "keep"; + }; + }; + }; + + ethernet-phy@1 { + compatible = "ethernet-phy-id004d.d0b2"; + reg = <1>; + }; + + ethernet-phy@2 { + compatible = "ethernet-phy-id004d.d0b2"; + reg = <2>; + + gpio-controller; + #gpio-cells = <2>; + }; + + ethernet-phy@3 { + compatible = "ethernet-phy-id004d.d0b2"; + reg = <3>; + }; + + ethernet-phy@4 { + compatible = "ethernet-phy-id004d.d0b2"; + reg = <4>; + }; + }; + };
Signature · 1 line
2.40.1
RFC PATCH v2 10/11 net: phy: add Qualcom QCA807x driver
In reply to Christian MarangiFrom: Robert Marko <[email protected]>
This adds driver for the Qualcomm QCA8072 and QCA8075 PHY-s.
They are 2 or 5 port IEEE 802.3 clause 22 compliant 10BASE-Te, 100BASE-TX and 1000BASE-T PHY-s.
They feature 2 SerDes, one for PSGMII or QSGMII connection with MAC, while second one is SGMII for connection to MAC or fiber.
Both models have a combo port that supports 1000BASE-X and 100BASE-FX fiber.
Each PHY inside of QCA807x series has 4 digitally controlled output only pins that natively drive LED-s.
But some vendors used these to driver generic LED-s controlled by userspace, so lets enable registering each PHY as GPIO controller and add driver for it.
These are commonly used in Qualcomm IPQ40xx, IPQ60xx and IPQ807x boards.
--- drivers/net/phy/Kconfig | 7 + drivers/net/phy/Makefile | 1 + drivers/net/phy/qca807x.c | 956 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 964 insertions(+) create mode 100644 drivers/net/phy/qca807x.c
drivers/net/phy/Kconfig +7 -0
@@ -325,6 +325,13 @@ config AT803X_PHY Currently supports the AR8030, AR8031, AR8033, AR8035 and internal QCA8337(Internal qca8k PHY) model +config QCA807X_PHY + tristate "Qualcomm QCA807x PHYs" + depends on OF_MDIO + help + Currently supports the Qualcomm QCA8072, QCA8075 and the PSGMII + control PHY. + config QSEMI_PHY tristate "Quality Semiconductor PHYs" help
drivers/net/phy/Makefile +1 -0
@@ -82,6 +82,7 @@ obj-$(CONFIG_NCN26000_PHY) += ncn26000.o obj-$(CONFIG_NXP_C45_TJA11XX_PHY) += nxp-c45-tja11xx.o obj-$(CONFIG_NXP_CBTX_PHY) += nxp-cbtx.o obj-$(CONFIG_NXP_TJA11XX_PHY) += nxp-tja11xx.o +obj-$(CONFIG_QCA807X_PHY) += qca807x.o obj-$(CONFIG_QSEMI_PHY) += qsemi.o obj-$(CONFIG_REALTEK_PHY) += realtek.o obj-$(CONFIG_RENESAS_PHY) += uPD60620.o
drivers/net/phy/qca807x.c new file +956 -0
956 lines not on this page · raw message
Signature · 1 line
2.40.1
RFC PATCH v2 11/11 net: phy: qca807x: Add support for configurable LED
In reply to Christian MarangiQCA8072/5 have up to 2 LEDs attached for PHY.
LEDs can be configured to be ON/hw blink or be set to HW control.
Hw blink mode is set to blink at 4Hz or 250ms.
PHY can support both copper (TP) or fiber (FIBRE) kind and supports different HW control modes based on the port type.
HW control modes supported for netdev trigger for copper ports are:
- LINK_10
- LINK_100
- LINK_1000
- TX
- RX
- FULL_DUPLEX
- HALF_DUPLEX
HW control modes supported for netdev trigger for fiber ports are:
- LINK_100
- LINK_1000
- TX
- RX
- FULL_DUPLEX
- HALF_DUPLEX
LED support conflicts with GPIO controller feature and must be disabled if gpio-controller is used for the PHY.
--- drivers/net/phy/qca807x.c | 382 +++++++++++++++++++++++++++++++++++++- 1 file changed, 375 insertions(+), 7 deletions(-)
drivers/net/phy/qca807x.c +375 -7
@@ -79,17 +79,60 @@#define QCA807X_MMD7_1000BASE_T_POWER_SAVE_PER_CABLE_LENGTH 0x801a#define QCA807X_CONTROL_DAC_MASK GENMASK(2, 0) +#define QCA807X_MMD7_LED_GLOBAL 0x8073 +#define QCA807X_LED_BLINK_1 GENMASK(11, 6) +#define QCA807X_LED_BLINK_2 GENMASK(5, 0) +/* Values are the same for both BLINK_1 and BLINK_2 */ +#define QCA807X_LED_BLINK_FREQ_MASK GENMASK(5, 3) +#define QCA807X_LED_BLINK_FREQ_2HZ FIELD_PREP(QCA807X_LED_BLINK_FREQ_MASK, 0x0) +#define QCA807X_LED_BLINK_FREQ_4HZ FIELD_PREP(QCA807X_LED_BLINK_FREQ_MASK, 0x1) +#define QCA807X_LED_BLINK_FREQ_8HZ FIELD_PREP(QCA807X_LED_BLINK_FREQ_MASK, 0x2) +#define QCA807X_LED_BLINK_FREQ_16HZ FIELD_PREP(QCA807X_LED_BLINK_FREQ_MASK, 0x3) +#define QCA807X_LED_BLINK_FREQ_32HZ FIELD_PREP(QCA807X_LED_BLINK_FREQ_MASK, 0x4) +#define QCA807X_LED_BLINK_FREQ_64HZ FIELD_PREP(QCA807X_LED_BLINK_FREQ_MASK, 0x5) +#define QCA807X_LED_BLINK_FREQ_128HZ FIELD_PREP(QCA807X_LED_BLINK_FREQ_MASK, 0x6) +#define QCA807X_LED_BLINK_FREQ_256HZ FIELD_PREP(QCA807X_LED_BLINK_FREQ_MASK, 0x7) +#define QCA807X_LED_BLINK_DUTY_MASK GENMASK(2, 0) +#define QCA807X_LED_BLINK_DUTY_50_50 FIELD_PREP(QCA807X_LED_BLINK_DUTY_MASK, 0x0) +#define QCA807X_LED_BLINK_DUTY_75_25 FIELD_PREP(QCA807X_LED_BLINK_DUTY_MASK, 0x1) +#define QCA807X_LED_BLINK_DUTY_25_75 FIELD_PREP(QCA807X_LED_BLINK_DUTY_MASK, 0x2) +#define QCA807X_LED_BLINK_DUTY_33_67 FIELD_PREP(QCA807X_LED_BLINK_DUTY_MASK, 0x3) +#define QCA807X_LED_BLINK_DUTY_67_33 FIELD_PREP(QCA807X_LED_BLINK_DUTY_MASK, 0x4) +#define QCA807X_LED_BLINK_DUTY_17_83 FIELD_PREP(QCA807X_LED_BLINK_DUTY_MASK, 0x5) +#define QCA807X_LED_BLINK_DUTY_83_17 FIELD_PREP(QCA807X_LED_BLINK_DUTY_MASK, 0x6) +#define QCA807X_LED_BLINK_DUTY_8_92 FIELD_PREP(QCA807X_LED_BLINK_DUTY_MASK, 0x7)#define QCA807X_MMD7_LED_100N_1 0x8074#define QCA807X_MMD7_LED_100N_2 0x8075#define QCA807X_MMD7_LED_1000N_1 0x8076#define QCA807X_MMD7_LED_1000N_2 0x8077 -#define QCA807X_LED_TXACT_BLK_EN_2 BIT(10) -#define QCA807X_LED_RXACT_BLK_EN_2 BIT(9) -#define QCA807X_LED_GT_ON_EN_2 BIT(6) -#define QCA807X_LED_HT_ON_EN_2 BIT(5) -#define QCA807X_LED_BT_ON_EN_2 BIT(4) -#define QCA807X_GPIO_FORCE_EN BIT(15) -#define QCA807X_GPIO_FORCE_MODE_MASK GENMASK(14, 13) +/* Values are the same for LED1 and LED2 */ +/* Values for control 1 */ +#define QCA807X_LED_COPPER_ON_BLINK_MASK GENMASK(12, 0) +#define QCA807X_LED_FDX_ON_EN BIT(12) +#define QCA807X_LED_HDX_ON_EN BIT(11) +#define QCA807X_LED_TXACT_BLK_EN BIT(10) +#define QCA807X_LED_RXACT_BLK_EN BIT(9) +#define QCA807X_LED_GT_ON_EN BIT(6) +#define QCA807X_LED_HT_ON_EN BIT(5) +#define QCA807X_LED_BT_ON_EN BIT(4) +/* Values for control 2 */ +#define QCA807X_LED_FORCE_EN BIT(15) +#define QCA807X_LED_FORCE_MODE_MASK GENMASK(14, 13) +#define QCA807X_LED_FORCE_BLINK_1 FIELD_PREP(QCA807X_LED_FORCE_MODE_MASK, 0x3) +#define QCA807X_LED_FORCE_BLINK_2 FIELD_PREP(QCA807X_LED_FORCE_MODE_MASK, 0x2) +#define QCA807X_LED_FORCE_ON FIELD_PREP(QCA807X_LED_FORCE_MODE_MASK, 0x1) +#define QCA807X_LED_FORCE_OFF FIELD_PREP(QCA807X_LED_FORCE_MODE_MASK, 0x0) +#define QCA807X_LED_FIBER_ON_BLINK_MASK GENMASK(11, 1) +#define QCA807X_LED_FIBER_TXACT_BLK_EN BIT(10) +#define QCA807X_LED_FIBER_RXACT_BLK_EN BIT(9) +#define QCA807X_LED_FIBER_FDX_ON_EN BIT(6) +#define QCA807X_LED_FIBER_HDX_ON_EN BIT(5) +#define QCA807X_LED_FIBER_1000BX_ON_EN BIT(2) +#define QCA807X_LED_FIBER_100FX_ON_EN BIT(1) + +/* Some device repurpose the LED as GPIO out */ +#define QCA807X_GPIO_FORCE_EN QCA807X_LED_FORCE_EN +#define QCA807X_GPIO_FORCE_MODE_MASK QCA807X_LED_FORCE_MODE_MASK#define QCA807X_INTR_ENABLE 0x12#define QCA807X_INTR_STATUS 0x13
@@ -357,6 +400,320 @@ static int qca807x_cable_test_start(struct phy_device *phydev)return ret; } +static int qca807x_led_parse_netdev (struct phy_device *phydev,unsigned long rules, +u16 *offload_trigger) +{ +/* Parsing specific to netdev trigger */ +switch (phydev->port) { +case PORT_TP : +if (test_bit (TRIGGER_NETDEV_TX , &rules)) + *offload_trigger |=QCA807X_LED_TXACT_BLK_EN ; +if (test_bit (TRIGGER_NETDEV_RX , &rules)) + *offload_trigger |=QCA807X_LED_RXACT_BLK_EN ; +if (test_bit (TRIGGER_NETDEV_LINK_10 , &rules)) + *offload_trigger |=QCA807X_LED_BT_ON_EN ; +if (test_bit (TRIGGER_NETDEV_LINK_100 , &rules)) + *offload_trigger |=QCA807X_LED_HT_ON_EN ; +if (test_bit (TRIGGER_NETDEV_LINK_1000 , &rules)) + *offload_trigger |=QCA807X_LED_GT_ON_EN ; +if (test_bit (TRIGGER_NETDEV_HALF_DUPLEX , &rules)) + *offload_trigger |=QCA807X_LED_HDX_ON_EN ; +if (test_bit (TRIGGER_NETDEV_FULL_DUPLEX , &rules)) + *offload_trigger |=QCA807X_LED_FDX_ON_EN ; +break ; +case PORT_FIBRE : +if (test_bit (TRIGGER_NETDEV_TX , &rules)) + *offload_trigger |=QCA807X_LED_FIBER_TXACT_BLK_EN ; +if (test_bit (TRIGGER_NETDEV_RX , &rules)) + *offload_trigger |=QCA807X_LED_FIBER_RXACT_BLK_EN ; +if (test_bit (TRIGGER_NETDEV_LINK_100 , &rules)) + *offload_trigger |=QCA807X_LED_FIBER_100FX_ON_EN ; +if (test_bit (TRIGGER_NETDEV_LINK_1000 , &rules)) + *offload_trigger |=QCA807X_LED_FIBER_1000BX_ON_EN ; +if (test_bit (TRIGGER_NETDEV_HALF_DUPLEX , &rules)) + *offload_trigger |=QCA807X_LED_FIBER_HDX_ON_EN ; +if (test_bit (TRIGGER_NETDEV_FULL_DUPLEX , &rules)) + *offload_trigger |=QCA807X_LED_FIBER_FDX_ON_EN ; +break ; +default : +return -EOPNOTSUPP ; + } + +if (rules && !*offload_trigger) +return -EOPNOTSUPP ; + +return 0 ; +} + +static int qca807x_led_hw_control_enable (struct phy_device *phydev,u8 index) +{ +int val, reg, ret; + +switch (index) { +case 0 : + reg =QCA807X_MMD7_LED_100N_2 ; +break ; +case 1 : + reg =QCA807X_MMD7_LED_1000N_2 ; +break ; +default : +return -EINVAL ; + } + + val =phy_read_mmd (phydev,MDIO_MMD_AN , reg); + val &= ~QCA807X_LED_FORCE_EN ; + ret =phy_write_mmd (phydev,MDIO_MMD_AN , reg, val); + +return ret; +} + +static int qca807x_led_hw_is_supported (struct phy_device *phydev,u8 index, +unsigned long rules) +{ +u16 offload_trigger =0 ; + +if (index >1 ) +return -EINVAL ; + +return qca807x_led_parse_netdev (phydev, rules, &offload_trigger); +} + +static int qca807x_led_hw_control_set (struct phy_device *phydev,u8 index, +unsigned long rules) +{ +int val, ret, copper_reg, fibre_reg; +u16 offload_trigger =0 ; + +switch (index) { +case 0 : + copper_reg =QCA807X_MMD7_LED_100N_1 ; + fibre_reg =QCA807X_MMD7_LED_100N_2 ; +break ; +case 1 : + copper_reg =QCA807X_MMD7_LED_1000N_1 ; + fibre_reg =QCA807X_MMD7_LED_1000N_2 ; +break ; +default : +return -EINVAL ; + } + + ret =qca807x_led_parse_netdev (phydev, rules, &offload_trigger); +if (ret) +return ret; + + ret =qca807x_led_hw_control_enable (phydev, index); +if (ret) +return ret; + +switch (phydev->port) { +case PORT_TP : + val =phy_read_mmd (phydev,MDIO_MMD_AN , copper_reg); + val &= ~QCA807X_LED_COPPER_ON_BLINK_MASK ; + val |= offload_trigger; + ret =phy_write_mmd (phydev,MDIO_MMD_AN , copper_reg, val); +break ; +case PORT_FIBRE : + val =phy_read_mmd (phydev,MDIO_MMD_AN , fibre_reg); + val &= ~QCA807X_LED_FIBER_ON_BLINK_MASK ; + val |= offload_trigger; + ret =phy_write_mmd (phydev,MDIO_MMD_AN , fibre_reg, val); +break ; +default : +return -EINVAL ; + } + +return ret; +} + +static bool qca807x_led_hw_control_status (struct phy_device *phydev,u8 index) +{ +int val, reg; + +switch (index) { +case 0 : + reg =QCA807X_MMD7_LED_100N_2 ; +break ; +case 1 : + reg =QCA807X_MMD7_LED_1000N_2 ; +break ; +default : +return false; + } + + val =phy_read_mmd (phydev,MDIO_MMD_AN , reg); + +return !(val &QCA807X_LED_FORCE_EN ); +} + +static int qca807x_led_hw_control_get (struct phy_device *phydev,u8 index, +unsigned long *rules) +{ +int val, copper_reg, fibre_reg; + +switch (index) { +case 0 : + copper_reg =QCA807X_MMD7_LED_100N_1 ; + fibre_reg =QCA807X_MMD7_LED_100N_2 ; +break ; +case 1 : + copper_reg =QCA807X_MMD7_LED_1000N_1 ; + fibre_reg =QCA807X_MMD7_LED_100N_2 ; +break ; +default : +return -EINVAL ; + } + +/* Check if we have hw control enabled */ +if (qca807x_led_hw_control_status (phydev, index)) +return -EINVAL ; + +/* Parsing specific to netdev trigger */ +switch (phydev->port) { +case PORT_TP : + val =phy_read_mmd (phydev,MDIO_MMD_AN , copper_reg); +if (val &QCA807X_LED_TXACT_BLK_EN ) +set_bit (TRIGGER_NETDEV_TX , rules); +if (val &QCA807X_LED_RXACT_BLK_EN ) +set_bit (TRIGGER_NETDEV_RX , rules); +if (val &QCA807X_LED_BT_ON_EN ) +set_bit (TRIGGER_NETDEV_LINK_10 , rules); +if (val &QCA807X_LED_HT_ON_EN ) +set_bit (TRIGGER_NETDEV_LINK_100 , rules); +if (val &QCA807X_LED_GT_ON_EN ) +set_bit (TRIGGER_NETDEV_LINK_1000 , rules); +if (val &QCA807X_LED_HDX_ON_EN ) +set_bit (TRIGGER_NETDEV_HALF_DUPLEX , rules); +if (val &QCA807X_LED_FDX_ON_EN ) +set_bit (TRIGGER_NETDEV_FULL_DUPLEX , rules); +break ; +case PORT_FIBRE : + val =phy_read_mmd (phydev,MDIO_MMD_AN , fibre_reg); +if (val &QCA807X_LED_FIBER_TXACT_BLK_EN ) +set_bit (TRIGGER_NETDEV_TX , rules); +if (val &QCA807X_LED_FIBER_RXACT_BLK_EN ) +set_bit (TRIGGER_NETDEV_RX , rules); +if (val &QCA807X_LED_FIBER_100FX_ON_EN ) +set_bit (TRIGGER_NETDEV_LINK_100 , rules); +if (val &QCA807X_LED_FIBER_1000BX_ON_EN ) +set_bit (TRIGGER_NETDEV_LINK_1000 , rules); +if (val &QCA807X_LED_FIBER_HDX_ON_EN ) +set_bit (TRIGGER_NETDEV_HALF_DUPLEX , rules); +if (val &QCA807X_LED_FIBER_FDX_ON_EN ) +set_bit (TRIGGER_NETDEV_FULL_DUPLEX , rules); +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int qca807x_led_hw_control_reset (struct phy_device *phydev,u8 index) +{ +int val, copper_reg, fibre_reg, ret; + +switch (index) { +case 0 : + copper_reg =QCA807X_MMD7_LED_100N_1 ; + fibre_reg =QCA807X_MMD7_LED_100N_2 ; +break ; +case 1 : + copper_reg =QCA807X_MMD7_LED_1000N_1 ; + fibre_reg =QCA807X_MMD7_LED_100N_2 ; +break ; +default : +return -EINVAL ; + } + +switch (phydev->port) { +case PORT_TP : + val =phy_read_mmd (phydev,MDIO_MMD_AN , copper_reg); + val &= ~QCA807X_LED_COPPER_ON_BLINK_MASK ; + ret =phy_write_mmd (phydev,MDIO_MMD_AN , copper_reg, val); +break ; +case PORT_FIBRE : + val =phy_read_mmd (phydev,MDIO_MMD_AN , fibre_reg); + val &= ~QCA807X_LED_FIBER_ON_BLINK_MASK ; + ret =phy_write_mmd (phydev,MDIO_MMD_AN , fibre_reg, val); +break ; +default : +return -EINVAL ; + } + +return ret; +} + +static int qca807x_led_brightness_set (struct phy_device *phydev, +u8 index,enum led_brightness value) +{ +int val, ret; +u16 reg; + +switch (index) { +case 0 : + reg =QCA807X_MMD7_LED_100N_2 ; +break ; +case 1 : + reg =QCA807X_MMD7_LED_1000N_2 ; +break ; +default : +return -EINVAL ; + } + +/* If we are setting off the LED reset any hw control rule */ +if (!value) { + ret =qca807x_led_hw_control_reset (phydev, index); +if (ret) +return ret; + } + + val =phy_read_mmd (phydev,MDIO_MMD_AN , reg); + val &= ~(QCA807X_LED_FORCE_EN |QCA807X_LED_FORCE_MODE_MASK ); + val |=QCA807X_LED_FORCE_EN ; +if (value) + val |=QCA807X_LED_FORCE_ON ; + ret =phy_write_mmd (phydev,MDIO_MMD_AN , reg, val); + +return ret; +} + +static int qca807x_led_blink_set (struct phy_device *phydev,u8 index, +unsigned long *delay_on, +unsigned long *delay_off) +{ +int val, ret; +u16 reg; + +switch (index) { +case 0 : + reg =QCA807X_MMD7_LED_100N_2 ; +break ; +case 1 : + reg =QCA807X_MMD7_LED_1000N_2 ; +break ; +default : +return -EINVAL ; + } + +/* Set blink to 50% off, 50% on at 4Hz by default */ + val =phy_read_mmd (phydev,MDIO_MMD_AN ,QCA807X_MMD7_LED_GLOBAL ); + val &= ~(QCA807X_LED_BLINK_FREQ_MASK |QCA807X_LED_BLINK_DUTY_MASK ); + val |=QCA807X_LED_BLINK_FREQ_4HZ |QCA807X_LED_BLINK_DUTY_50_50 ; + ret =phy_write_mmd (phydev,MDIO_MMD_AN ,QCA807X_MMD7_LED_GLOBAL , val); + +/* We use BLINK_1 for normal blinking */ + val =phy_read_mmd (phydev,MDIO_MMD_AN , reg); + val &= ~(QCA807X_LED_FORCE_EN |QCA807X_LED_FORCE_MODE_MASK ); + val |=QCA807X_LED_FORCE_EN |QCA807X_LED_FORCE_BLINK_1 ; + ret =phy_write_mmd (phydev,MDIO_MMD_AN , reg, val); + +/* We set blink to 4Hz, aka 250ms */ + *delay_on =250 /2 ; + *delay_off =250 /2 ; + +return ret; +} +#ifdef CONFIG_GPIOLIB static int qca807x_gpio_get_direction (struct gpio_chip *gc,unsigned int offset) {
@@ -746,6 +1103,12 @@ static int qca807x_probe(struct phy_device *phydev) ret =qca807x_gpio (phydev);if (ret)return ret; + + phydev->drv->led_brightness_set =NULL ; + phydev->drv->led_blink_set =NULL ; + phydev->drv->led_hw_is_supported =NULL ; + phydev->drv->led_hw_control_set =NULL ; + phydev->drv->led_hw_control_get =NULL ; } }
@@ -933,6 +1296,11 @@ static struct phy_driver qca807x_drivers[] = { .suspend = genphy_suspend, .cable_test_start = qca807x_cable_test_start, .cable_test_get_status = qca807x_cable_test_get_status, + .led_brightness_set = qca807x_led_brightness_set, + .led_blink_set = qca807x_led_blink_set, + .led_hw_is_supported = qca807x_led_hw_is_supported, + .led_hw_control_set = qca807x_led_hw_control_set, + .led_hw_control_get = qca807x_led_hw_control_get,/* PHY package define */ .phy_package_global_phys_offset = qca807x_global_phys_offset, .phy_package_global_phys_num = ARRAY_SIZE(qca807x_global_phys_offset),
Signature · 1 line
2.40.1
Andrew Lunn
maintainerQuoted 5 lines
One example is this:
ethernet-phy-package@0 { #address-cells = <1>; #size-cells = <0>;
Please extend this example with a compatible, and include a property which is global.
Quoted 4 lines
(For Andrew, we are looking intro making this in at803x PHY driver and see what functions can be reused, idea is to move the driver to a dedicated directory and create something like
at803x-common.cas the at803x PHY driver is too bloated and splitting it it's a better approach)
This sounds good.
Andrew
Quoted 9 lines · Andrew Lunn
Quoted 5 lines
One example is this:
ethernet-phy-package@0 { #address-cells = <1>; #size-cells = <0>;Please extend this example with a compatible, and include a property which is global.
Hi, don't know if you notice the changelog, I now check with the node name prefix instead of using compatible ethernet-phy-package. (some requested and didn't like using it) (easy to reintroduce, was just a small proposal/idea)
Also in theory the compatible for specific PHY package can also be skipped. (we can use the select way and match for PHY id. Can also be introduced easily but shouldn't that be checked in some way? Or it's ok to have a compatible that will only be used for documentation?)
Quoted 7 lines
Quoted 4 lines
(For Andrew, we are looking intro making this in at803x PHY driver and see what functions can be reused, idea is to move the driver to a dedicated directory and create something like
at803x-common.cas the at803x PHY driver is too bloated and splitting it it's a better approach)This sounds good.
Thanks, also for Russell, I forgot to include the PHY mode in the qca807x commit, will include that once I will move the code to the shared implementation with at803x. (sorry)
Signature · 1 line
Ansuel
Andrew Lunn
maintainerRe: [net-next RFC PATCH v2 01/11] net: phy: extend PHY package API to support multiple global address
In reply to Christian MarangiQuoted 10 lines · Christian Marangi
Current API for PHY package are limited to single address to configure global settings for the PHY package.
It was found that some PHY package (for example the qca807x, a PHY package that is shipped with a bundle of 5 PHY) require multiple PHY address to configure global settings. An example scenario is a PHY that have a dedicated PHY for PSGMII/serdes calibrarion and have a specific PHY in the package where the global PHY mode is set and affects every other PHY in the package.
Quoted 7 lines
Change the API in the following way:
- Makephy_package_join()require a list of address to be passed and the number of address in the list
- On shared data init, each address is the list is checked and added to the shared struct.
- Make __/phy_package_write/read() require an additional arg that select what global PHY address to use in the provided list.
I think this is overly complex.
I would rename struct phy_package_shared addr to base_addr. phy_package_join() would then pass the base address of the package, which is the same as your reg property for the package in DT.
I think all current users of devm_phy_package_join() already do pass the lowest address in the package, so this should not cause any problems. Most drivers even call it base address, rather than cookie, which the documentation uses.
I would then extend __phy_package_read() etc to take an offset, which is added to base_addr, and the read is performed on that address. All the existing users would pass 0, and your new driver can pass other values.
I also think you can split this out from the DT binding. Make it two patch sets. One patch set is about extended the package concept to allow access to global registers at addresses other than the base. The DT patch is about properties which are shared by the package. These seems like two mostly orthogonal concepts.
Andrew
Re: [net-next RFC PATCH v2 01/11] net: phy: extend PHY package API to support multiple global address
Quoted 35 lines · Andrew Lunn
Quoted 10 lines · Christian Marangi
Current API for PHY package are limited to single address to configure global settings for the PHY package.
It was found that some PHY package (for example the qca807x, a PHY package that is shipped with a bundle of 5 PHY) require multiple PHY address to configure global settings. An example scenario is a PHY that have a dedicated PHY for PSGMII/serdes calibrarion and have a specific PHY in the package where the global PHY mode is set and affects every other PHY in the package.
Quoted 7 lines
Change the API in the following way:
- Makephy_package_join()require a list of address to be passed and the number of address in the list
- On shared data init, each address is the list is checked and added to the shared struct.
- Make __/phy_package_write/read() require an additional arg that select what global PHY address to use in the provided list.I think this is overly complex.
I would rename struct
phy_package_sharedaddr tobase_addr.phy_package_join()would then pass the base address of the package, which is the same as your reg property for the package in DT.I think all current users of
devm_phy_package_join()already do pass the lowest address in the package, so this should not cause any problems. Most drivers even call it base address, rather than cookie, which the documentation uses.I would then extend
__phy_package_read()etc to take an offset, which is added tobase_addr, and the read is performed on that address. All the existing users would pass 0, and your new driver can pass other values.
Quoted 6 lines
I also think you can split this out from the DT binding. Make it two patch sets. One patch set is about extended the package concept to allow access to global registers at addresses other than the base. The DT patch is about properties which are shared by the package. These seems like two mostly orthogonal concepts.
Yes can be detached. Making addr to base_addr would change the thing but can confirm, any user of the API always used the base addr as cookie, so it won't change a thing.
Will have to make the separate commit a dependency to this series but i expect this change to be merged before this RFC is completed. Good idea.
Signature · 1 line
Ansuel
Andrew Lunn
maintainerRe: [net-next RFC PATCH v2 02/11] dt-bindings: net: document ethernet PHY package nodes
In reply to Christian MarangiQuoted 3 lines · Christian Marangi
Document ethernet PHY package nodes used to describe PHY shipped in bundle of 4-5 PHY. These particular PHY require specific PHY in the package for global onfiguration of the PHY package.
I would not say that is true. We have been able to handle such PHYs without a problem so far. This binding is not about a collection of PHYs in one package with shared registers. Its about DT properties which are shared across the package.
This binding is simply a container. It contains properties shared by all PHYs in the container, and it contains the PHYs itself. The properties should be described in another DT scheme, selected by a compatible for the PHY package. The PHYs themselves a follow the standard ethernet-phy scheme.
I would also add a comment about the reg value in the PHY properties being absolute, not relative. You can make this clearer in the example, by using a base address of 16, and PHYs 16 and 20.
Please include this is in the binding itself, as part of the documentation.
Quoted 12 lines
Documentation/devicetree/bindings/net/ethernet-phy-package.yaml new file +12
-0+properties: + $nodename: + pattern: "^ethernet-phy-package(@[a-f0-9]+)?$" + + reg: + minimum: 0 + maximum: 31 + description: + The ID number for the PHY. + + '#address-cells': + const: 1
Documentation/devicetree/bindings/net/ethernet-phy-package.yaml line 41
Quoted 10 lines
Documentation/devicetree/bindings/net/ethernet-phy-package.yaml new file +10
-0+ + '#size-cells': + const: 0 + +patternProperties: + ^ethernet-phy(@[a-f0-9]+)?$: + $ref: /schemas/net/ethernet-phy.yaml# + +required: + - reg
A compatible is required.
Documentation/devicetree/bindings/net/ethernet-phy-package.yaml line 51
Quoted 7 lines
Documentation/devicetree/bindings/net/ethernet-phy-package.yaml new file +7
-0+examples: + - | + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy-package@0 {
A compatible is needed here.
Documentation/devicetree/bindings/net/ethernet-phy-package.yaml line 57
Quoted 6 lines
Documentation/devicetree/bindings/net/ethernet-phy-package.yaml new file +6
-0+ #address-cells = <1>; + #size-cells = <0>; + reg = <0>; + + ethernet-phy@0 { + compatible = "ethernet-phy-ieee802.3-c22";
This compatible is optional, and c22 is the default, so i would not list it.
Andrew
Andrew Lunn
maintainerRe: [net-next RFC PATCH v2 01/11] net: phy: extend PHY package API to support multiple global address
In reply to Christian MarangiQuoted 6 lines
Yes can be detached. Making addr to
base_addrwould change the thing but can confirm, any user of the API always used the base addr as cookie, so it won't change a thing.Will have to make the separate commit a dependency to this series but i expect this change to be merged before this RFC is completed. Good idea.
A change like this can be merged quickly. You can keep the DT package as an RFC, we don't yet seem to have a clear concept what it is.
Andrew