ramips: switch to linux 4.14
[openwrt/openwrt.git] / target / linux / ramips / files-4.9 / drivers / net / ethernet / mtk / soc_rt2880.c
1 /* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License as published by
3 * the Free Software Foundation; version 2 of the License
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
9 *
10 * Copyright (C) 2009-2015 John Crispin <blogic@openwrt.org>
11 * Copyright (C) 2009-2015 Felix Fietkau <nbd@nbd.name>
12 * Copyright (C) 2013-2015 Michael Lee <igvtee@gmail.com>
13 */
14
15 #include <linux/module.h>
16
17 #include <asm/mach-ralink/ralink_regs.h>
18
19 #include "mtk_eth_soc.h"
20 #include "mdio_rt2880.h"
21
22 #define RT2880_RESET_FE BIT(18)
23
24 static void rt2880_init_data(struct fe_soc_data *data,
25 struct net_device *netdev)
26 {
27 struct fe_priv *priv = netdev_priv(netdev);
28
29 priv->flags = FE_FLAG_PADDING_64B | FE_FLAG_PADDING_BUG |
30 FE_FLAG_JUMBO_FRAME | FE_FLAG_CALIBRATE_CLK;
31 netdev->hw_features = NETIF_F_SG | NETIF_F_HW_VLAN_CTAG_TX;
32 /* this should work according to the datasheet but actually does not*/
33 /* netdev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM; */
34 }
35
36 void rt2880_fe_reset(void)
37 {
38 fe_reset(RT2880_RESET_FE);
39 }
40
41 static int rt2880_fwd_config(struct fe_priv *priv)
42 {
43 int ret;
44
45 ret = fe_set_clock_cycle(priv);
46 if (ret)
47 return ret;
48
49 fe_fwd_config(priv);
50 fe_w32(FE_PSE_FQFC_CFG_INIT, FE_PSE_FQ_CFG);
51 fe_csum_config(priv);
52
53 return ret;
54 }
55
56 struct fe_soc_data rt2880_data = {
57 .init_data = rt2880_init_data,
58 .reset_fe = rt2880_fe_reset,
59 .fwd_config = rt2880_fwd_config,
60 .pdma_glo_cfg = FE_PDMA_SIZE_8DWORDS,
61 .checksum_bit = RX_DMA_L4VALID,
62 .rx_int = FE_RX_DONE_INT,
63 .tx_int = FE_TX_DONE_INT,
64 .status_int = FE_CNT_GDM_AF,
65 .mdio_read = rt2880_mdio_read,
66 .mdio_write = rt2880_mdio_write,
67 .mdio_adjust_link = rt2880_mdio_link_adjust,
68 .port_init = rt2880_port_init,
69 };
70
71 const struct of_device_id of_fe_match[] = {
72 { .compatible = "ralink,rt2880-eth", .data = &rt2880_data },
73 {},
74 };
75
76 MODULE_DEVICE_TABLE(of, of_fe_match);