an8855: add MFD driver
Subsystems (5)
v3 cover an8855: add MFD driver
This micro series is the AN8855 MFD driver that can go parallel to the DSA driver.
Changes v3:
- Rebase on top of linux-next
- Reintroduce switch part
- Add already reviwed switch and phy part
- Use fwnode API
- Use __free for mdio_np
- Use capital letter for node
- Reorder header list
- Use ret directly instead of ret < 0 ...
- Use macro for u32 shift
- Use full 100 column char
- Use unique ddata instead of nested one
Changes v2:
- Rebase on top of linux-next
- Drop switch part from DT patch
Christian Marangi (4):
dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
dt-bindings: net: Document support for AN8855 Switch Internal PHY
dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
mfd: an8855: Add support for Airoha AN8855 Switch
.../bindings/mfd/airoha,an8855.yaml | 176 ++++++ .../bindings/net/airoha,an8855-phy.yaml | 83 +++ .../net/dsa/airoha,an8855-switch.yaml | 86 +++ drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 568 ++++++++++++++++++ 6 files changed, 928 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml create mode 100644 drivers/mfd/airoha-an8855.c
Signature · 1 line
2.55.0
PATCH v3 1/4 dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
Document support for Airoha AN8855 5-port Gigabit Switch.
It does expose the 5 Internal PHYs on the MDIO bus and each port can access the Switch register space by configuring the PHY page.
--- .../net/dsa/airoha,an8855-switch.yaml | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml
Documentation/devicetree/bindings/net/dsa/airoha,an8855-switch.yaml new file +86 -0
@@ -0,0 +1,86 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/airoha,an8855-switch.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN8855 Gigabit Switch + +maintainers: + - Christian Marangi <[email protected]> + +description: > + Airoha AN8855 is a 5-port Gigabit Switch. + + It does expose the 5 Internal PHYs on the MDIO bus and each port + can access the Switch register space by configuring the PHY page. + +$ref: dsa.yaml#/$defs/ethernet-ports + +properties: + compatible: + const: airoha,an8855-switch + +required: + - compatible + +unevaluatedProperties: false + +examples: + - | + ethernet-switch { + compatible = "airoha,an8855-switch"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + label = "lan1"; + phy-mode = "internal"; + phy-handle = <&internal_phy1>; + }; + + port@1 { + reg = <1>; + label = "lan2"; + phy-mode = "internal"; + phy-handle = <&internal_phy2>; + }; + + port@2 { + reg = <2>; + label = "lan3"; + phy-mode = "internal"; + phy-handle = <&internal_phy3>; + }; + + port@3 { + reg = <3>; + label = "lan4"; + phy-mode = "internal"; + phy-handle = <&internal_phy4>; + }; + + port@4 { + reg = <4>; + label = "wan"; + phy-mode = "internal"; + phy-handle = <&internal_phy5>; + }; + + port@5 { + reg = <5>; + label = "cpu"; + ethernet = <&gmac0>; + phy-mode = "2500base-x"; + + fixed-link { + speed = <2500>; + full-duplex; + pause; + }; + }; + }; + };
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v3 1/4] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Document support for Airoha AN8855 5-port Gigabit Switch.
It does expose the 5 Internal PHYs on the MDIO bus and each port can access the Switch register space by configuring the PHY page.
Signed-off-by Christian Marangi <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v3 2/4 dt-bindings: net: Document support for AN8855 Switch Internal PHY
In reply to Christian MarangiDocument support for AN8855 Switch Internal PHY.
Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal PHYs on the MDIO bus.
Each PHY might need to be calibrated to correctly work with the use of the eFUSE provided by the Switch SoC. This can be enabled by defining in the PHY node the NVMEM cell properties.
--- .../bindings/net/airoha,an8855-phy.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml
Documentation/devicetree/bindings/net/airoha,an8855-phy.yaml new file +83 -0
@@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/airoha,an8855-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN8855 Switch Internal PHY + +maintainers: + - Christian Marangi <[email protected]> + +description: > + Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal + PHYs on the MDIO bus. + + Each PHY might need to be calibrated to correctly work with the + use of the eFUSE provided by the Switch SoC. + +allOf: + - $ref: ethernet-phy.yaml# + +select: + properties: + compatible: + contains: + enum: + - ethernet-phy-idc0ff.0410 + required: + - compatible + +properties: + reg: + maxItems: 1 + + nvmem-cells: + items: + - description: phandle to SoC eFUSE tx_a + - description: phandle to SoC eFUSE tx_b + - description: phandle to SoC eFUSE tx_c + - description: phandle to SoC eFUSE tx_d + + nvmem-cell-names: + items: + - const: tx_a + - const: tx_b + - const: tx_c + - const: tx_d + +required: + - compatible + - reg + +dependentRequired: + nvmem-cells: [ nvmem-cell-names ] + +unevaluatedProperties: false + +examples: + - | + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy@1 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c45"; + + reg = <1>; + }; + + ethernet-phy@2 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c45"; + + reg = <2>; + + nvmem-cells = <&shift_sel_port0_tx_a>, + <&shift_sel_port0_tx_b>, + <&shift_sel_port0_tx_c>, + <&shift_sel_port0_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + };
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v3 2/4] dt-bindings: net: Document support for AN8855 Switch Internal PHY
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
Document support for AN8855 Switch Internal PHY.
Airoha AN8855 is a 5-port Gigabit Switch that expose the Internal PHYs on the MDIO bus.
Each PHY might need to be calibrated to correctly work with the use of the eFUSE provided by the Switch SoC. This can be enabled by defining in the PHY node the NVMEM cell properties.
Signed-off-by Christian Marangi <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v3 3/4 dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
In reply to Christian MarangiDocument support for Airoha AN8855 Switch SoC. This SoC expose various peripherals like an Ethernet Switch, a NVMEM provider and Ethernet PHYs.
It does also support i2c and timers but those are not currently supported/used.
--- .../bindings/mfd/airoha,an8855.yaml | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/airoha,an8855.yaml
Documentation/devicetree/bindings/mfd/airoha,an8855.yaml new file +176 -0
@@ -0,0 +1,176 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/airoha,an8855.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN8855 Switch SoC + +maintainers: + - Christian Marangi <[email protected]> + +description: > + Airoha AN8855 Switch is a SoC that expose various peripherals like an + Ethernet Switch, a NVMEM provider and Ethernet PHYs. + + It does also support i2c and timers but those are not currently + supported/used. + +properties: + compatible: + const: airoha,an8855 + + reg: + maxItems: 1 + + reset-gpios: + maxItems: 1 + + efuse: + type: object + $ref: /schemas/nvmem/airoha,an8855-efuse.yaml + description: EFUSE exposed by the Airoha AN8855 SoC + + ethernet-switch: + type: object + $ref: /schemas/net/dsa/airoha,an8855-switch.yaml + description: Switch exposed by the Airoha AN8855 SoC + + mdio: + type: object + $ref: /schemas/net/mdio.yaml# + description: MDIO exposed by the Airoha AN8855 SoC + unevaluatedProperties: false + +required: + - compatible + - reg + - mdio + - ethernet-switch + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + soc@1 { + compatible = "airoha,an8855"; + reg = <1>; + + reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>; + + efuse { + compatible = "airoha,an8855-efuse"; + + #nvmem-cell-cells = <0>; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + shift_sel_port0_tx_a: shift-sel-port0-tx-a@c { + reg = <0xc 0x4>; + }; + + shift_sel_port0_tx_b: shift-sel-port0-tx-b@10 { + reg = <0x10 0x4>; + }; + + shift_sel_port0_tx_c: shift-sel-port0-tx-c@14 { + reg = <0x14 0x4>; + }; + + shift_sel_port0_tx_d: shift-sel-port0-tx-d@18 { + reg = <0x18 0x4>; + }; + + shift_sel_port1_tx_a: shift-sel-port1-tx-a@1c { + reg = <0x1c 0x4>; + }; + + shift_sel_port1_tx_b: shift-sel-port1-tx-b@20 { + reg = <0x20 0x4>; + }; + + shift_sel_port1_tx_c: shift-sel-port1-tx-c@24 { + reg = <0x24 0x4>; + }; + + shift_sel_port1_tx_d: shift-sel-port1-tx-d@28 { + reg = <0x28 0x4>; + }; + }; + }; + + ethernet-switch { + compatible = "airoha,an8855-switch"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + label = "lan1"; + phy-mode = "internal"; + phy-handle = <&internal_phy1>; + }; + + port@1 { + reg = <1>; + label = "lan2"; + phy-mode = "internal"; + phy-handle = <&internal_phy2>; + }; + + port@5 { + reg = <5>; + label = "cpu"; + ethernet = <&gmac0>; + phy-mode = "2500base-x"; + + fixed-link { + speed = <2500>; + full-duplex; + pause; + }; + }; + }; + }; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + internal_phy1: ethernet-phy@1 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c22"; + reg = <1>; + + nvmem-cells = <&shift_sel_port0_tx_a>, + <&shift_sel_port0_tx_b>, + <&shift_sel_port0_tx_c>, + <&shift_sel_port0_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + + internal_phy2: ethernet-phy@2 { + compatible = "ethernet-phy-idc0ff.0410", + "ethernet-phy-ieee802.3-c22"; + reg = <2>; + + nvmem-cells = <&shift_sel_port1_tx_a>, + <&shift_sel_port1_tx_b>, + <&shift_sel_port1_tx_c>, + <&shift_sel_port1_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + }; + }; + };
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v3 3/4] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
Document support for Airoha AN8855 Switch SoC. This SoC expose various peripherals like an Ethernet Switch, a NVMEM provider and Ethernet PHYs.
It does also support i2c and timers but those are not currently supported/used.
Signed-off-by Christian Marangi <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v3 4/4 mfd: an8855: Add support for Airoha AN8855 Switch
In reply to Christian MarangiAdd support for Airoha AN8855 Switch that provide support for a DSA switch and a NVMEM provider.
Also make use of the mdio-regmap driver and register a regmap for each internal PHY of the switch.
This is needed to handle the double usage of the PHYs as both PHY and Switch accessor.
--- drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/airoha-an8855.c | 568 ++++++++++++++++++++++++++++++++++++ 3 files changed, 583 insertions(+) create mode 100644 drivers/mfd/airoha-an8855.c
drivers/mfd/Kconfig +14 -0
@@ -54,6 +54,20 @@ config MFD_ALTERA_SYSMGR using regmap_mmio accesses for ARM32 parts and SMC calls to EL3 for ARM64 parts. +config MFD_AIROHA_AN8855 + tristate "Airoha AN8855 Switch Core" + select MFD_CORE + select REGMAP + select PHYLIB + select MDIO_REGMAP + depends on NETDEVICES && OF + help + Support for the Airoha AN8855 Switch Core. This is an SoC + that provides various peripherals, to count, i2c, an Ethrnet + Switch, a CPU timer, GPIO, eFUSE. + + Currently it provides a DSA switch and a NVMEM provider. + config MFD_ACT8945A tristate "Active-semi ACT8945A" select MFD_CORE
drivers/mfd/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o obj-$(CONFIG_MFD_88PM800) += 88pm800.o 88pm80x.o obj-$(CONFIG_MFD_88PM805) += 88pm805.o 88pm80x.o obj-$(CONFIG_MFD_88PM886_PMIC) += 88pm886.o +obj-$(CONFIG_MFD_AIROHA_AN8855) += airoha-an8855.o obj-$(CONFIG_MFD_ACT8945A) += act8945a.o obj-$(CONFIG_MFD_SM501) += sm501.o obj-$(CONFIG_MFD_ASUS_TRANSFORMER_EC) += asus-transformer-ec.o
drivers/mfd/airoha-an8855.c new file +568 -0
568 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v3 4/4] mfd: an8855: Add support for Airoha AN8855 Switch
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] mfd: an8855: missing reset-gpios handling in an8855_probe() - [Medium] mfd: an8855: missing…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] mfd: an8855: missing reset-gpios handling in an8855_probe()
- [Medium] mfd: an8855: missing PHY_MAX_ADDR check in an8855_phy_bus_register()
- [Medium] mfd: an8855: PHY registration before efuse MFD cell in an8855_probe()
- [Low] mfd: an8855: cleanup helper and goto mixing in an8855_mdio_register()
--
commit b4187acae4b9834706a08e5702a986758362581b
Author: Christian Marangi <[email protected]>
mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds the core MFD driver for the Airoha AN8855 switch, providing regmap access over MDIO, virtual MDIO buses for the internal PHYs, and MFD cells for the efuse NVMEM provider and DSA switch.
Quoted 5 lines
drivers/mfd/airoha-an8855.c new file +0
-0
[ ... ]
Quoted 8 lines
drivers/mfd/airoha-an8855.c new file +8
-0+static int an8855_phy_bus_register (struct device *dev,struct an8855 *ddata, +struct fwnode_handle *phy_np, +struct an8855_phy_bus *phy_bus_info) +{ +struct mdio_regmap_config mrc = { }; +struct an8855_phy *phy_ddata; +struct regmap *regmap; +u32 addr, phy_offset;
drivers/mfd/airoha-an8855.c line 410
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+struct mii_bus *bus; +int ret; + + ret =fwnode_property_read_u32 (phy_np,"reg" , &addr); +if (ret) +return ret; + + phy_offset = addr - ddata->switch_addr; +if (phy_offset >=AN8855_MAX_PHY_PORT ) +return -EINVAL ;
[Severity: Medium]
Can addr exceed PHY_MAX_ADDR - 1 here when ddata->switch_addr is 28..31?
If a child PHY node specifies reg >= 32 while addr - ddata->switch_addr is still less than AN8855_MAX_PHY_PORT (5), an8855_probe() passes addr to fwnode_mdiobus_register_phy() -> fwnode_mdiobus_phy_device_register() -> phy_device_register() -> mdiobus_register_device(), which indexes mdio->irq[addr] and mdiodev->bus->mdio_map[addr] (both sized PHY_MAX_ADDR =
32) out of bounds and shifts 1 << addr.
[ ... ]
Quoted 25 lines
drivers/mfd/airoha-an8855.c new file +25
-0+static int an8855_mdio_register (struct device *dev,struct an8855 *ddata, +struct an8855_phy_bus *phy_bus_infos) +{ + struct fwnode_handle *mdio_np __free(fwnode_handle) = NULL; +int phy =0 ; +int ret =0 ; + + mdio_np =fwnode_get_named_child_node (dev_fwnode (dev),"mdio" ); +if (!mdio_np) +return -ENODEV ; + +fwnode_for_each_available_child_node_scoped (mdio_np, phy_np) { +if (phy >=AN8855_MAX_PHY_PORT ) { + ret = -EINVAL ; + goto exit; + } + + ret =an8855_phy_bus_register (dev, ddata, phy_np, + &phy_bus_infos[phy]); +if (ret) + goto exit; + + phy++; + } +
drivers/mfd/airoha-an8855.c line 478
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+exit: +if (ret) { +while (phy--) +fwnode_handle_put (phy_bus_infos[phy].node); + +return ret; + } + +return phy; +}
[Severity: Low]
This isn't a bug, but an8855_mdio_register() mixes scope-based cleanup helpers (__free(fwnode_handle) and fwnode_for_each_available_child_node_scoped()) with goto error handling, and declares mdio_np = NULL at the top of the function instead of defining and initializing it in one statement.
Quoted 3 lines
drivers/mfd/airoha-an8855.c new file +3
-0+ +static int an8855_probe (struct mdio_device *mdiodev) +{
[ ... ]
Quoted 6 lines
drivers/mfd/airoha-an8855.c new file +6
-0+/* Reset PHY page for switch address */ +mutex_lock_nested (&ddata->bus->mdio_lock,MDIO_MUTEX_NESTED ); + ret =an8855_mii_set_page (ddata, ddata->switch_addr, +AN8855_PHY_PAGE_STANDARD ); +mutex_unlock (&ddata->bus->mdio_lock); +if (ret)
drivers/mfd/airoha-an8855.c line 525
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+ goto err_put_fwnodes; + + ret =an8855_read_switch_id (dev, regmap); +if (ret) + goto err_put_fwnodes; + +/* Release global PHY power down */ + ret =regmap_write (regmap,AN8855_RG_GPHY_AFE_PWD ,0x0 ); +if (ret) + goto err_put_fwnodes;
[Severity: High]
Should an8855_probe() acquire and deassert reset-gpios before accessing the switch over MDIO?
The airoha,an8855 binding places reset-gpios on this MFD node, and the MDIO core only handles reset-gpios for PHY devices:
drivers/net/phy/mdio_device.c:mdiobus_register_device() {
...
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
err = mdio_device_register_reset(mdiodev);
if (err)
return err;
/* Assert the reset signal */
mdio_device_reset(mdiodev, 1);
}
...
}On boards where reset-gpios is asserted at boot, an8855_mii_set_page() or an8855_read_switch_id() will read 0xffff while the SoC is held in reset and fail probe with -ENODEV. Conversely, if a child driver resets the chip later during devm_mfd_add_devices(), it will wipe out the AN8855_RG_GPHY_AFE_PWD write and internal PHY state configured here. Also, <linux/gpio/consumer.h> and AN8855_HWTRAP at the top of the file are currently unused.
Quoted 6 lines
drivers/mfd/airoha-an8855.c new file +6
-0+ +/* Register PHYs */ +for (phy =0 ; phy < num_phys; phy++) { + ret =fwnode_mdiobus_register_phy (phy_bus_infos[phy].bus, + phy_bus_infos[phy].node, + phy_bus_infos[phy].addr);
drivers/mfd/airoha-an8855.c line 541
Quoted 10 lines
drivers/mfd/airoha-an8855.c new file +10
-0+fwnode_handle_put (phy_bus_infos[phy].node); + phy_bus_infos[phy].node =NULL ; + +if (ret) + goto err_put_fwnodes; + } + +return devm_mfd_add_devices (dev,PLATFORM_DEVID_AUTO , an8855_cells, +ARRAY_SIZE (an8855_cells),NULL ,0 , +NULL );
[Severity: Medium]
Does registering the internal PHYs before an8855-efuse cause them to defer probe and risk binding to genphy_driver?
The internal ethernet-phy nodes consume nvmem-cells from an8855-efuse, so fw_devlink defers each PHY probe during fwnode_mdiobus_register_phy() because an8855-efuse has not been registered yet. When devm_mfd_add_devices() then registers an8855-efuse and immediately probes an8855-switch in the same loop, an8855-switch can call phy_attach_direct() before deferred_probe_work runs on the workqueue; phy_attach_direct() sees !d->driver on the deferred PHY and binds genphy_driver instead of the AN8855 PHY driver.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4