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 'net-stmmac-loongson1-cleanups'

Russell King says:

====================
net: stmmac: loongson1: cleanups

A couple of patches to cleanup loongson1. First, introducing a match
data struct to allow the per-match data to be extended beyond the init
function pointer, and then adding a setup method to allow the resource
base address to be translated to the MAC index at probe time rather
than repeatedly in the setup function.
====================

Link: https://patch.msgid.link/aFKXzlno7HkG-cNh@shell.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+58 -21
+58 -21
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c
··· 44 44 struct ls1x_dwmac { 45 45 struct plat_stmmacenet_data *plat_dat; 46 46 struct regmap *regmap; 47 + unsigned int id; 47 48 }; 49 + 50 + struct ls1x_data { 51 + int (*setup)(struct platform_device *pdev, 52 + struct plat_stmmacenet_data *plat_dat); 53 + int (*init)(struct platform_device *pdev, void *bsp_priv); 54 + }; 55 + 56 + static int ls1b_dwmac_setup(struct platform_device *pdev, 57 + struct plat_stmmacenet_data *plat_dat) 58 + { 59 + struct ls1x_dwmac *dwmac = plat_dat->bsp_priv; 60 + struct resource *res; 61 + 62 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 63 + if (!res) { 64 + /* This shouldn't fail - stmmac_get_platform_resources() 65 + * already mapped this resource. 66 + */ 67 + dev_err(&pdev->dev, "Could not get IO_MEM resources\n"); 68 + return -EINVAL; 69 + } 70 + 71 + if (res->start == LS1B_GMAC0_BASE) { 72 + dwmac->id = 0; 73 + } else if (res->start == LS1B_GMAC1_BASE) { 74 + dwmac->id = 1; 75 + } else { 76 + dev_err(&pdev->dev, "Invalid Ethernet MAC base address %pR", 77 + res); 78 + return -EINVAL; 79 + } 80 + 81 + return 0; 82 + } 48 83 49 84 static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv) 50 85 { 51 86 struct ls1x_dwmac *dwmac = priv; 52 87 struct plat_stmmacenet_data *plat = dwmac->plat_dat; 53 88 struct regmap *regmap = dwmac->regmap; 54 - struct resource *res; 55 - unsigned long reg_base; 56 89 57 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 58 - if (!res) { 59 - dev_err(&pdev->dev, "Could not get IO_MEM resources\n"); 60 - return -EINVAL; 61 - } 62 - reg_base = (unsigned long)res->start; 63 - 64 - if (reg_base == LS1B_GMAC0_BASE) { 90 + if (dwmac->id == 0) { 65 91 switch (plat->phy_interface) { 66 92 case PHY_INTERFACE_MODE_RGMII_ID: 67 93 regmap_update_bits(regmap, LS1X_SYSCON0, ··· 106 80 } 107 81 108 82 regmap_update_bits(regmap, LS1X_SYSCON0, GMAC0_SHUT, 0); 109 - } else if (reg_base == LS1B_GMAC1_BASE) { 83 + } else if (dwmac->id == 1) { 110 84 regmap_update_bits(regmap, LS1X_SYSCON0, 111 85 GMAC1_USE_UART1 | GMAC1_USE_UART0, 112 86 GMAC1_USE_UART1 | GMAC1_USE_UART0); ··· 130 104 } 131 105 132 106 regmap_update_bits(regmap, LS1X_SYSCON1, GMAC1_SHUT, 0); 133 - } else { 134 - dev_err(&pdev->dev, "Invalid Ethernet MAC base address %lx", 135 - reg_base); 136 - return -EINVAL; 137 107 } 138 108 139 109 return 0; ··· 165 143 { 166 144 struct plat_stmmacenet_data *plat_dat; 167 145 struct stmmac_resources stmmac_res; 146 + const struct ls1x_data *data; 168 147 struct regmap *regmap; 169 148 struct ls1x_dwmac *dwmac; 170 - int (*init)(struct platform_device *pdev, void *priv); 171 149 int ret; 172 150 173 151 ret = stmmac_get_platform_resources(pdev, &stmmac_res); ··· 181 159 return dev_err_probe(&pdev->dev, PTR_ERR(regmap), 182 160 "Unable to find syscon\n"); 183 161 184 - init = of_device_get_match_data(&pdev->dev); 185 - if (!init) { 162 + data = of_device_get_match_data(&pdev->dev); 163 + if (!data) { 186 164 dev_err(&pdev->dev, "No of match data provided\n"); 187 165 return -EINVAL; 188 166 } ··· 197 175 "dt configuration failed\n"); 198 176 199 177 plat_dat->bsp_priv = dwmac; 200 - plat_dat->init = init; 178 + plat_dat->init = data->init; 201 179 dwmac->plat_dat = plat_dat; 202 180 dwmac->regmap = regmap; 181 + 182 + if (data->setup) { 183 + ret = data->setup(pdev, plat_dat); 184 + if (ret) 185 + return ret; 186 + } 203 187 204 188 return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res); 205 189 } 206 190 191 + static const struct ls1x_data ls1b_dwmac_data = { 192 + .setup = ls1b_dwmac_setup, 193 + .init = ls1b_dwmac_syscon_init, 194 + }; 195 + 196 + static const struct ls1x_data ls1c_dwmac_data = { 197 + .init = ls1c_dwmac_syscon_init, 198 + }; 199 + 207 200 static const struct of_device_id ls1x_dwmac_match[] = { 208 201 { 209 202 .compatible = "loongson,ls1b-gmac", 210 - .data = &ls1b_dwmac_syscon_init, 203 + .data = &ls1b_dwmac_data, 211 204 }, 212 205 { 213 206 .compatible = "loongson,ls1c-emac", 214 - .data = &ls1c_dwmac_syscon_init, 207 + .data = &ls1c_dwmac_data, 215 208 }, 216 209 { } 217 210 };