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

net: stmmac: Use driver data and callbacks tied with compatible strings

The stmmac driver core allows passing feature flags and callbacks via
platform data. Add a similar stmmac_of_data to pass flags and callbacks
tied to compatible strings. This allows us to extend stmmac with glue
layers for different SoCs.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Chen-Yu Tsai and committed by
David S. Miller
022066f5 436f7ecd

+52 -10
+34 -10
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
··· 26 26 #include <linux/io.h> 27 27 #include <linux/of.h> 28 28 #include <linux/of_net.h> 29 + #include <linux/of_device.h> 29 30 #include "stmmac.h" 31 + 32 + static const struct of_device_id stmmac_dt_ids[] = { 33 + /* SoC specific glue layers should come before generic bindings */ 34 + { .compatible = "st,spear600-gmac"}, 35 + { .compatible = "snps,dwmac-3.610"}, 36 + { .compatible = "snps,dwmac-3.70a"}, 37 + { .compatible = "snps,dwmac-3.710"}, 38 + { .compatible = "snps,dwmac"}, 39 + { /* sentinel */ } 40 + }; 41 + MODULE_DEVICE_TABLE(of, stmmac_dt_ids); 30 42 31 43 #ifdef CONFIG_OF 32 44 static int stmmac_probe_config_dt(struct platform_device *pdev, ··· 47 35 { 48 36 struct device_node *np = pdev->dev.of_node; 49 37 struct stmmac_dma_cfg *dma_cfg; 38 + const struct of_device_id *device; 50 39 51 40 if (!np) 52 41 return -ENODEV; 42 + 43 + device = of_match_device(stmmac_dt_ids, &pdev->dev); 44 + if (!device) 45 + return -ENODEV; 46 + 47 + if (device->data) { 48 + const struct stmmac_of_data *data = device->data; 49 + plat->has_gmac = data->has_gmac; 50 + plat->enh_desc = data->enh_desc; 51 + plat->tx_coe = data->tx_coe; 52 + plat->rx_coe = data->rx_coe; 53 + plat->bugged_jumbo = data->bugged_jumbo; 54 + plat->pmt = data->pmt; 55 + plat->riwt_off = data->riwt_off; 56 + plat->fix_mac_speed = data->fix_mac_speed; 57 + plat->bus_setup = data->bus_setup; 58 + plat->setup = data->setup; 59 + plat->free = data->free; 60 + plat->init = data->init; 61 + plat->exit = data->exit; 62 + } 53 63 54 64 *mac = of_get_mac_address(np); 55 65 plat->interface = of_get_phy_mode(np); ··· 292 258 293 259 static SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops, 294 260 stmmac_pltfr_suspend, stmmac_pltfr_resume); 295 - 296 - static const struct of_device_id stmmac_dt_ids[] = { 297 - { .compatible = "st,spear600-gmac"}, 298 - { .compatible = "snps,dwmac-3.610"}, 299 - { .compatible = "snps,dwmac-3.70a"}, 300 - { .compatible = "snps,dwmac-3.710"}, 301 - { .compatible = "snps,dwmac"}, 302 - { /* sentinel */ } 303 - }; 304 - MODULE_DEVICE_TABLE(of, stmmac_dt_ids); 305 261 306 262 struct platform_driver stmmac_pltfr_driver = { 307 263 .probe = stmmac_pltfr_probe,
+18
include/linux/stmmac.h
··· 121 121 void *custom_data; 122 122 void *bsp_priv; 123 123 }; 124 + 125 + /* of_data for SoC glue layer device tree bindings */ 126 + 127 + struct stmmac_of_data { 128 + int has_gmac; 129 + int enh_desc; 130 + int tx_coe; 131 + int rx_coe; 132 + int bugged_jumbo; 133 + int pmt; 134 + int riwt_off; 135 + void (*fix_mac_speed)(void *priv, unsigned int speed); 136 + void (*bus_setup)(void __iomem *ioaddr); 137 + void *(*setup)(struct platform_device *pdev); 138 + void (*free)(struct platform_device *pdev, void *priv); 139 + int (*init)(struct platform_device *pdev, void *priv); 140 + void (*exit)(struct platform_device *pdev, void *priv); 141 + }; 124 142 #endif