53d35d0728c29b77c59345643594f4f92ffaa080
[openwrt/openwrt.git] / target / linux / ramips / patches-4.4 / 0507-net-next-mediatek-add-support-for-rt3883.patch
1 From 5ad283c69029a519681ed453e7f7ddf250c10559 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 18 Nov 2015 03:51:24 +0100
4 Subject: [PATCH 507/513] net-next: mediatek: add support for rt3883
5
6 Add support for rt3883 and its smaller version rt3662. They both have a single
7 gBit port that will normally be attached to an external phy of switch.
8
9 Signed-off-by: John Crispin <blogic@openwrt.org>
10 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
11 Signed-off-by: Michael Lee <igvtee@gmail.com>
12 ---
13 drivers/net/ethernet/mediatek/soc_rt3883.c | 75 ++++++++++++++++++++++++++++
14 1 file changed, 75 insertions(+)
15 create mode 100644 drivers/net/ethernet/mediatek/soc_rt3883.c
16
17 --- /dev/null
18 +++ b/drivers/net/ethernet/mediatek/soc_rt3883.c
19 @@ -0,0 +1,75 @@
20 +/* This program is free software; you can redistribute it and/or modify
21 + * it under the terms of the GNU General Public License as published by
22 + * the Free Software Foundation; version 2 of the License
23 + *
24 + * This program is distributed in the hope that it will be useful,
25 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 + * GNU General Public License for more details.
28 + *
29 + * Copyright (C) 2009-2015 John Crispin <blogic@openwrt.org>
30 + * Copyright (C) 2009-2015 Felix Fietkau <nbd@openwrt.org>
31 + * Copyright (C) 2013-2015 Michael Lee <igvtee@gmail.com>
32 + */
33 +
34 +#include <linux/module.h>
35 +
36 +#include <asm/mach-ralink/ralink_regs.h>
37 +
38 +#include "mtk_eth_soc.h"
39 +#include "mdio_rt2880.h"
40 +
41 +#define RT3883_RSTCTRL_FE BIT(21)
42 +
43 +static void rt3883_fe_reset(void)
44 +{
45 + fe_reset(RT3883_RSTCTRL_FE);
46 +}
47 +
48 +static int rt3883_fwd_config(struct fe_priv *priv)
49 +{
50 + int ret;
51 +
52 + ret = fe_set_clock_cycle(priv);
53 + if (ret)
54 + return ret;
55 +
56 + fe_fwd_config(priv);
57 + fe_w32(FE_PSE_FQFC_CFG_256Q, FE_PSE_FQ_CFG);
58 + fe_csum_config(priv);
59 +
60 + return ret;
61 +}
62 +
63 +static void rt3883_init_data(struct fe_soc_data *data,
64 + struct net_device *netdev)
65 +{
66 + struct fe_priv *priv = netdev_priv(netdev);
67 +
68 + priv->flags = FE_FLAG_PADDING_64B | FE_FLAG_PADDING_BUG |
69 + FE_FLAG_JUMBO_FRAME | FE_FLAG_CALIBRATE_CLK;
70 + netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
71 + NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX;
72 +}
73 +
74 +static struct fe_soc_data rt3883_data = {
75 + .init_data = rt3883_init_data,
76 + .reset_fe = rt3883_fe_reset,
77 + .fwd_config = rt3883_fwd_config,
78 + .pdma_glo_cfg = FE_PDMA_SIZE_8DWORDS,
79 + .rx_int = FE_RX_DONE_INT,
80 + .tx_int = FE_TX_DONE_INT,
81 + .status_int = FE_CNT_GDM_AF,
82 + .checksum_bit = RX_DMA_L4VALID,
83 + .mdio_read = rt2880_mdio_read,
84 + .mdio_write = rt2880_mdio_write,
85 + .mdio_adjust_link = rt2880_mdio_link_adjust,
86 + .port_init = rt2880_port_init,
87 +};
88 +
89 +const struct of_device_id of_fe_match[] = {
90 + { .compatible = "ralink,rt3883-eth", .data = &rt3883_data },
91 + {},
92 +};
93 +
94 +MODULE_DEVICE_TABLE(of, of_fe_match);