Beniamino Galvani | 0ad5adc | 2014-09-20 15:29:16 +0200 | [diff] [blame] | 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/platform_device.h> |
| 19 | #include <linux/stmmac.h> |
| 20 | |
| 21 | #define ETHMAC_SPEED_100 BIT(1) |
| 22 | |
| 23 | struct meson_dwmac { |
| 24 | struct device *dev; |
| 25 | void __iomem *reg; |
| 26 | }; |
| 27 | |
| 28 | static void meson6_dwmac_fix_mac_speed(void *priv, unsigned int speed) |
| 29 | { |
| 30 | struct meson_dwmac *dwmac = priv; |
| 31 | unsigned int val; |
| 32 | |
| 33 | val = readl(dwmac->reg); |
| 34 | |
| 35 | switch (speed) { |
| 36 | case SPEED_10: |
| 37 | val &= ~ETHMAC_SPEED_100; |
| 38 | break; |
| 39 | case SPEED_100: |
| 40 | val |= ETHMAC_SPEED_100; |
| 41 | break; |
| 42 | } |
| 43 | |
| 44 | writel(val, dwmac->reg); |
| 45 | } |
| 46 | |
| 47 | static void *meson6_dwmac_setup(struct platform_device *pdev) |
| 48 | { |
| 49 | struct meson_dwmac *dwmac; |
| 50 | struct resource *res; |
| 51 | |
| 52 | dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); |
| 53 | if (!dwmac) |
| 54 | return ERR_PTR(-ENOMEM); |
| 55 | |
| 56 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 57 | dwmac->reg = devm_ioremap_resource(&pdev->dev, res); |
| 58 | if (IS_ERR(dwmac->reg)) |
| 59 | return dwmac->reg; |
| 60 | |
| 61 | return dwmac; |
| 62 | } |
| 63 | |
| 64 | const struct stmmac_of_data meson6_dwmac_data = { |
| 65 | .setup = meson6_dwmac_setup, |
| 66 | .fix_mac_speed = meson6_dwmac_fix_mac_speed, |
| 67 | }; |