1 /* 2 * Amlogic Meson DWMAC glue layer 3 * 4 * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 * 10 * You should have received a copy of the GNU General Public License 11 * along with this program. If not, see <http://www.gnu.org/licenses/>. 12 */ 13 14 #include <linux/device.h> 15 #include <linux/ethtool.h> 16 #include <linux/io.h> 17 #include <linux/ioport.h> 18 #include <linux/module.h> 19 #include <linux/platform_device.h> 20 #include <linux/stmmac.h> 21 22 #include "stmmac_platform.h" 23 24 #define ETHMAC_SPEED_100 BIT(1) 25 26 struct meson_dwmac { 27 struct device *dev; 28 void __iomem *reg; 29 }; 30 31 static void meson6_dwmac_fix_mac_speed(void *priv, unsigned int speed) 32 { 33 struct meson_dwmac *dwmac = priv; 34 unsigned int val; 35 36 val = readl(dwmac->reg); 37 38 switch (speed) { 39 case SPEED_10: 40 val &= ~ETHMAC_SPEED_100; 41 break; 42 case SPEED_100: 43 val |= ETHMAC_SPEED_100; 44 break; 45 } 46 47 writel(val, dwmac->reg); 48 } 49 50 static void *meson6_dwmac_setup(struct platform_device *pdev) 51 { 52 struct meson_dwmac *dwmac; 53 struct resource *res; 54 55 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); 56 if (!dwmac) 57 return ERR_PTR(-ENOMEM); 58 59 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 60 dwmac->reg = devm_ioremap_resource(&pdev->dev, res); 61 if (IS_ERR(dwmac->reg)) 62 return ERR_CAST(dwmac->reg); 63 64 return dwmac; 65 } 66 67 static const struct stmmac_of_data meson6_dwmac_data = { 68 .setup = meson6_dwmac_setup, 69 .fix_mac_speed = meson6_dwmac_fix_mac_speed, 70 }; 71 72 static const struct of_device_id meson6_dwmac_match[] = { 73 { .compatible = "amlogic,meson6-dwmac", .data = &meson6_dwmac_data}, 74 { } 75 }; 76 MODULE_DEVICE_TABLE(of, meson6_dwmac_match); 77 78 static struct platform_driver meson6_dwmac_driver = { 79 .probe = stmmac_pltfr_probe, 80 .remove = stmmac_pltfr_remove, 81 .driver = { 82 .name = "meson6-dwmac", 83 .pm = &stmmac_pltfr_pm_ops, 84 .of_match_table = meson6_dwmac_match, 85 }, 86 }; 87 module_platform_driver(meson6_dwmac_driver); 88 89 MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>"); 90 MODULE_DESCRIPTION("Amlogic Meson DWMAC glue layer"); 91 MODULE_LICENSE("GPL v2"); 92