Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'riscv-spacemit-add-ethernet-support-for-k3'

Inochi Amaoto says:

====================
riscv: spacemit: Add ethernet support for K3

Add initial support for ethernet controller of the Spacemit K3 SoC.
This ethernet controller is almost a standard Synopsys DesignWare
MAC (version 5.40a). This controller require a syscon device to
configure some basic features, like interface type and internal delay.
====================

Link: https://patch.msgid.link/20260316010041.164360-1-inochiama@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+351
+2
Documentation/devicetree/bindings/net/snps,dwmac.yaml
··· 109 109 - snps,dwmac-5.10a 110 110 - snps,dwmac-5.20 111 111 - snps,dwmac-5.30a 112 + - snps,dwmac-5.40a 112 113 - snps,dwxgmac 113 114 - snps,dwxgmac-2.10 114 115 - sophgo,sg2042-dwmac ··· 657 656 - snps,dwmac-5.10a 658 657 - snps,dwmac-5.20 659 658 - snps,dwmac-5.30a 659 + - snps,dwmac-5.40a 660 660 - snps,dwxgmac 661 661 - snps,dwxgmac-2.10 662 662 - st,spear600-gmac
+102
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/net/spacemit,k3-dwmac.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Spacemit K3 DWMAC glue layer 8 + 9 + maintainers: 10 + - Inochi Amaoto <inochiama@gmail.com> 11 + 12 + select: 13 + properties: 14 + compatible: 15 + contains: 16 + const: spacemit,k3-dwmac 17 + required: 18 + - compatible 19 + 20 + properties: 21 + compatible: 22 + items: 23 + - const: spacemit,k3-dwmac 24 + - const: snps,dwmac-5.40a 25 + 26 + reg: 27 + maxItems: 1 28 + 29 + clocks: 30 + items: 31 + - description: GMAC application clock 32 + - description: PTP clock 33 + - description: TX clock 34 + 35 + clock-names: 36 + items: 37 + - const: stmmaceth 38 + - const: ptp_ref 39 + - const: tx 40 + 41 + interrupts: 42 + minItems: 1 43 + items: 44 + - description: MAC interrupt 45 + - description: MAC wake interrupt 46 + 47 + interrupt-names: 48 + minItems: 1 49 + items: 50 + - const: macirq 51 + - const: eth_wake_irq 52 + 53 + resets: 54 + maxItems: 1 55 + 56 + reset-names: 57 + const: stmmaceth 58 + 59 + spacemit,apmu: 60 + $ref: /schemas/types.yaml#/definitions/phandle-array 61 + items: 62 + - items: 63 + - description: phandle to the syscon node which control the glue register 64 + - description: offset of the control register 65 + - description: offset of the dline register 66 + description: 67 + A phandle to syscon with offset to control registers for this MAC 68 + 69 + required: 70 + - compatible 71 + - reg 72 + - clocks 73 + - clock-names 74 + - interrupts 75 + - interrupt-names 76 + - resets 77 + - reset-names 78 + - spacemit,apmu 79 + 80 + allOf: 81 + - $ref: snps,dwmac.yaml# 82 + 83 + unevaluatedProperties: false 84 + 85 + examples: 86 + - | 87 + #include <dt-bindings/interrupt-controller/irq.h> 88 + 89 + ethernet@cac80000 { 90 + compatible = "spacemit,k3-dwmac", "snps,dwmac-5.40a"; 91 + reg = <0xcac80000 0x2000>; 92 + clocks = <&syscon_apmu 66>, <&syscon_apmu 68>, 93 + <&syscon_apmu 69>; 94 + clock-names = "stmmaceth", "ptp_ref", "tx"; 95 + interrupts = <131 IRQ_TYPE_LEVEL_HIGH>, <276 IRQ_TYPE_LEVEL_HIGH>; 96 + interrupt-names = "macirq", "eth_wake_irq"; 97 + phy-mode = "rgmii-id"; 98 + phy-handle = <&phy0>; 99 + resets = <&syscon_apmu 67>; 100 + reset-names = "stmmaceth"; 101 + spacemit,apmu = <&syscon_apmu 0x384 0x38c>; 102 + };
+6
MAINTAINERS
··· 24827 24827 Q: http://patchwork.linuxtv.org/project/linux-media/list/ 24828 24828 F: drivers/media/dvb-frontends/sp2* 24829 24829 24830 + SPACEMIT DWMAC GLUE LAYER 24831 + M: Inochi Amaoto <inochiama@gmail.com> 24832 + S: Maintained 24833 + F: Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml 24834 + F: drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c 24835 + 24830 24836 SPACEMIT K1 I2C DRIVER 24831 24837 M: Troy Mitchell <troy.mitchell@linux.spacemit.com> 24832 24838 S: Maintained
+12
drivers/net/ethernet/stmicro/stmmac/Kconfig
··· 216 216 for the stmmac device driver. This driver is used for the 217 217 ethernet controllers on various Sophgo SoCs. 218 218 219 + config DWMAC_SPACEMIT 220 + tristate "Spacemit dwmac support" 221 + depends on OF && (ARCH_SPACEMIT || COMPILE_TEST) 222 + select MFD_SYSCON 223 + default m if ARCH_SPACEMIT 224 + help 225 + Support for ethernet controllers on Spacemit RISC-V SoCs 226 + 227 + This selects the Spacemit platform specific glue layer support 228 + for the stmmac device driver. This driver is used for the 229 + Spacemit K3 ethernet controllers. 230 + 219 231 config DWMAC_STARFIVE 220 232 tristate "StarFive dwmac support" 221 233 depends on OF && (ARCH_STARFIVE || COMPILE_TEST)
+1
drivers/net/ethernet/stmicro/stmmac/Makefile
··· 27 27 obj-$(CONFIG_DWMAC_S32) += dwmac-s32.o 28 28 obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-altr-socfpga.o 29 29 obj-$(CONFIG_DWMAC_SOPHGO) += dwmac-sophgo.o 30 + obj-$(CONFIG_DWMAC_SPACEMIT) += dwmac-spacemit.o 30 31 obj-$(CONFIG_DWMAC_STARFIVE) += dwmac-starfive.o 31 32 obj-$(CONFIG_DWMAC_STI) += dwmac-sti.o 32 33 obj-$(CONFIG_DWMAC_STM32) += dwmac-stm32.o
+227
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Spacemit DWMAC platform driver 4 + * 5 + * Copyright (C) 2026 Inochi Amaoto <inochiama@gmail.com> 6 + */ 7 + 8 + #include <linux/clk.h> 9 + #include <linux/math.h> 10 + #include <linux/mod_devicetable.h> 11 + #include <linux/module.h> 12 + #include <linux/mfd/syscon.h> 13 + #include <linux/of.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/property.h> 16 + #include <linux/regmap.h> 17 + 18 + #include "stmmac_platform.h" 19 + 20 + /* ctrl register bits */ 21 + #define CTRL_PHY_INTF_RGMII BIT(3) 22 + #define CTRL_PHY_INTF_MII BIT(4) 23 + #define CTRL_WAKE_IRQ_EN BIT(9) 24 + #define CTRL_PHY_IRQ_EN BIT(12) 25 + 26 + /* dline register bits */ 27 + #define RGMII_RX_DLINE_EN BIT(0) 28 + #define RGMII_RX_DLINE_STEP GENMASK(5, 4) 29 + #define RGMII_RX_DLINE_CODE GENMASK(15, 8) 30 + #define RGMII_TX_DLINE_EN BIT(16) 31 + #define RGMII_TX_DLINE_STEP GENMASK(21, 20) 32 + #define RGMII_TX_DLINE_CODE GENMASK(31, 24) 33 + 34 + #define MAX_DLINE_DELAY_CODE 0xff 35 + #define MAX_WORKED_DELAY 2800 36 + /* Note: the delay step value is at 0.1ps */ 37 + #define K3_DELAY_STEP 367 38 + 39 + struct spacmit_dwmac { 40 + struct regmap *apmu; 41 + unsigned int ctrl_offset; 42 + unsigned int dline_offset; 43 + }; 44 + 45 + static int spacemit_dwmac_set_delay(struct spacmit_dwmac *dwmac, 46 + unsigned int tx_code, unsigned int rx_code) 47 + { 48 + unsigned int mask, val; 49 + 50 + mask = RGMII_TX_DLINE_STEP | RGMII_TX_DLINE_CODE | RGMII_TX_DLINE_EN | 51 + RGMII_RX_DLINE_STEP | RGMII_RX_DLINE_CODE | RGMII_RX_DLINE_EN; 52 + 53 + /* 54 + * Since the delay step provided by config 0 is small enough, and 55 + * it can cover the range of the valid delay, so there is no needed 56 + * to use other step config. 57 + */ 58 + val = FIELD_PREP(RGMII_TX_DLINE_STEP, 0) | 59 + FIELD_PREP(RGMII_TX_DLINE_CODE, tx_code) | RGMII_TX_DLINE_EN | 60 + FIELD_PREP(RGMII_RX_DLINE_STEP, 0) | 61 + FIELD_PREP(RGMII_RX_DLINE_CODE, rx_code) | RGMII_RX_DLINE_EN; 62 + 63 + return regmap_update_bits(dwmac->apmu, dwmac->dline_offset, 64 + mask, val); 65 + } 66 + 67 + static int spacemit_dwmac_detected_delay_value(unsigned int delay) 68 + { 69 + if (delay == 0) 70 + return 0; 71 + 72 + if (delay > MAX_WORKED_DELAY) 73 + return -EINVAL; 74 + 75 + /* 76 + * Note K3 require a specific factor for calculate 77 + * the delay, in this scenario it is 0.9. So the 78 + * formula is code * step / 10 * 0.9 79 + */ 80 + return DIV_ROUND_CLOSEST(delay * 10 * 10, K3_DELAY_STEP * 9); 81 + } 82 + 83 + static int spacemit_dwmac_fix_delay(struct spacmit_dwmac *dwmac, 84 + unsigned int tx_delay, 85 + unsigned int rx_delay) 86 + { 87 + int rx_code; 88 + int tx_code; 89 + 90 + rx_code = spacemit_dwmac_detected_delay_value(rx_delay); 91 + if (rx_code < 0) 92 + return rx_code; 93 + 94 + tx_code = spacemit_dwmac_detected_delay_value(tx_delay); 95 + if (tx_code < 0) 96 + return tx_code; 97 + 98 + return spacemit_dwmac_set_delay(dwmac, tx_code, rx_code); 99 + } 100 + 101 + static int spacemit_dwmac_update_irq_config(struct spacmit_dwmac *dwmac, 102 + struct stmmac_resources *stmmac_res) 103 + { 104 + unsigned int val = stmmac_res->wol_irq >= 0 ? CTRL_WAKE_IRQ_EN : 0; 105 + unsigned int mask = CTRL_WAKE_IRQ_EN; 106 + 107 + return regmap_update_bits(dwmac->apmu, dwmac->ctrl_offset, 108 + mask, val); 109 + } 110 + 111 + static void spacemit_get_interfaces(struct stmmac_priv *priv, void *bsp_priv, 112 + unsigned long *interfaces) 113 + { 114 + __set_bit(PHY_INTERFACE_MODE_MII, interfaces); 115 + __set_bit(PHY_INTERFACE_MODE_RMII, interfaces); 116 + phy_interface_set_rgmii(interfaces); 117 + } 118 + 119 + static int spacemit_set_phy_intf_sel(void *bsp_priv, u8 phy_intf_sel) 120 + { 121 + unsigned int mask = CTRL_PHY_INTF_MII | CTRL_PHY_INTF_RGMII; 122 + struct spacmit_dwmac *dwmac = bsp_priv; 123 + unsigned int val = 0; 124 + 125 + switch (phy_intf_sel) { 126 + case PHY_INTF_SEL_GMII_MII: 127 + val = CTRL_PHY_INTF_MII; 128 + break; 129 + 130 + case PHY_INTF_SEL_RMII: 131 + break; 132 + 133 + case PHY_INTF_SEL_RGMII: 134 + val = CTRL_PHY_INTF_RGMII; 135 + break; 136 + 137 + default: 138 + return -EINVAL; 139 + } 140 + 141 + return regmap_update_bits(dwmac->apmu, dwmac->ctrl_offset, 142 + mask, val); 143 + } 144 + 145 + static int spacemit_dwmac_probe(struct platform_device *pdev) 146 + { 147 + struct plat_stmmacenet_data *plat_dat; 148 + struct stmmac_resources stmmac_res; 149 + struct device *dev = &pdev->dev; 150 + struct spacmit_dwmac *dwmac; 151 + unsigned int offset[2]; 152 + struct regmap *apmu; 153 + struct clk *clk_tx; 154 + u32 rx_delay = 0; 155 + u32 tx_delay = 0; 156 + int ret; 157 + 158 + ret = stmmac_get_platform_resources(pdev, &stmmac_res); 159 + if (ret) 160 + return dev_err_probe(dev, ret, 161 + "failed to get platform resources\n"); 162 + 163 + dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); 164 + if (!dwmac) 165 + return -ENOMEM; 166 + 167 + plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac); 168 + if (IS_ERR(plat_dat)) 169 + return dev_err_probe(dev, PTR_ERR(plat_dat), 170 + "failed to parse DT parameters\n"); 171 + 172 + clk_tx = devm_clk_get_enabled(&pdev->dev, "tx"); 173 + if (IS_ERR(clk_tx)) 174 + return dev_err_probe(&pdev->dev, PTR_ERR(clk_tx), 175 + "failed to get tx clock\n"); 176 + 177 + apmu = syscon_regmap_lookup_by_phandle_args(pdev->dev.of_node, 178 + "spacemit,apmu", 2, 179 + offset); 180 + if (IS_ERR(apmu)) 181 + return dev_err_probe(dev, PTR_ERR(apmu), 182 + "Failed to get apmu regmap\n"); 183 + 184 + dwmac->apmu = apmu; 185 + dwmac->ctrl_offset = offset[0]; 186 + dwmac->dline_offset = offset[1]; 187 + 188 + ret = spacemit_dwmac_update_irq_config(dwmac, &stmmac_res); 189 + if (ret) 190 + return dev_err_probe(dev, ret, "Failed to configure irq config\n"); 191 + 192 + of_property_read_u32(pdev->dev.of_node, "tx-internal-delay-ps", 193 + &tx_delay); 194 + of_property_read_u32(pdev->dev.of_node, "rx-internal-delay-ps", 195 + &rx_delay); 196 + 197 + plat_dat->get_interfaces = spacemit_get_interfaces; 198 + plat_dat->set_phy_intf_sel = spacemit_set_phy_intf_sel; 199 + plat_dat->bsp_priv = dwmac; 200 + 201 + ret = spacemit_dwmac_fix_delay(dwmac, tx_delay, rx_delay); 202 + if (ret) 203 + return dev_err_probe(dev, ret, "Failed to configure delay\n"); 204 + 205 + return stmmac_dvr_probe(dev, plat_dat, &stmmac_res); 206 + } 207 + 208 + static const struct of_device_id spacemit_dwmac_match[] = { 209 + { .compatible = "spacemit,k3-dwmac" }, 210 + { /* sentinel */ } 211 + }; 212 + MODULE_DEVICE_TABLE(of, spacemit_dwmac_match); 213 + 214 + static struct platform_driver spacemit_dwmac_driver = { 215 + .probe = spacemit_dwmac_probe, 216 + .remove = stmmac_pltfr_remove, 217 + .driver = { 218 + .name = "spacemit-dwmac", 219 + .pm = &stmmac_pltfr_pm_ops, 220 + .of_match_table = spacemit_dwmac_match, 221 + }, 222 + }; 223 + module_platform_driver(spacemit_dwmac_driver); 224 + 225 + MODULE_AUTHOR("Inochi Amaoto <inochiama@gmail.com>"); 226 + MODULE_DESCRIPTION("Spacemit DWMAC platform driver"); 227 + MODULE_LICENSE("GPL");
+1
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
··· 403 403 "snps,dwmac-5.10a", 404 404 "snps,dwmac-5.20", 405 405 "snps,dwmac-5.30a", 406 + "snps,dwmac-5.40a", 406 407 NULL 407 408 }; 408 409