2 * Copyright 2009-2011 Freescale Semiconductor, Inc.
3 * Dave Liu <daveliu@freescale.com>
5 * SPDX-License-Identifier: GPL-2.0+
8 /* MAXFRM - maximum frame length */
9 #define MAXFRM_MASK 0x0000ffff
13 #include <asm/types.h>
15 #include <asm/fsl_enet.h>
16 #include <asm/fsl_tgec.h>
20 #define TGEC_CMD_CFG_INIT (TGEC_CMD_CFG_NO_LEN_CHK | \
21 TGEC_CMD_CFG_RX_ER_DISC | \
22 TGEC_CMD_CFG_STAT_CLR | \
23 TGEC_CMD_CFG_PAUSE_IGNORE | \
25 #define TGEC_CMD_CFG_FINAL (TGEC_CMD_CFG_NO_LEN_CHK | \
26 TGEC_CMD_CFG_RX_ER_DISC | \
27 TGEC_CMD_CFG_PAUSE_IGNORE | \
30 static void tgec_init_mac(struct fsl_enet_mac *mac)
32 struct tgec *regs = mac->base;
34 /* mask all interrupt */
35 out_be32(®s->imask, IMASK_MASK_ALL);
37 /* clear all events */
38 out_be32(®s->ievent, IEVENT_CLEAR_ALL);
40 /* set the max receive length */
41 out_be32(®s->maxfrm, mac->max_rx_len & MAXFRM_MASK);
44 * 1588 disable, insert second mac disable payload length check
45 * disable, normal operation, any rx error frame is discarded, clear
46 * counters, pause frame ignore, no promiscuous, LAN mode Rx CRC no
47 * strip, Tx CRC append, Rx disable and Tx disable
49 out_be32(®s->command_config, TGEC_CMD_CFG_INIT);
51 out_be32(®s->command_config, TGEC_CMD_CFG_FINAL);
53 /* multicast frame reception for the hash entry disable */
54 out_be32(®s->hashtable_ctrl, 0);
57 static void tgec_enable_mac(struct fsl_enet_mac *mac)
59 struct tgec *regs = mac->base;
61 setbits_be32(®s->command_config, TGEC_CMD_CFG_RXTX_EN);
64 static void tgec_disable_mac(struct fsl_enet_mac *mac)
66 struct tgec *regs = mac->base;
68 clrbits_be32(®s->command_config, TGEC_CMD_CFG_RXTX_EN);
71 static void tgec_set_mac_addr(struct fsl_enet_mac *mac, u8 *mac_addr)
73 struct tgec *regs = mac->base;
74 u32 mac_addr0, mac_addr1;
77 * if a station address of 0x12345678ABCD, perform a write to
78 * MAC_ADDR0 of 0x78563412, MAC_ADDR1 of 0x0000CDAB
80 mac_addr0 = (mac_addr[3] << 24) | (mac_addr[2] << 16) | \
81 (mac_addr[1] << 8) | (mac_addr[0]);
82 out_be32(®s->mac_addr_0, mac_addr0);
84 mac_addr1 = ((mac_addr[5] << 8) | mac_addr[4]) & 0x0000ffff;
85 out_be32(®s->mac_addr_1, mac_addr1);
88 static void tgec_set_interface_mode(struct fsl_enet_mac *mac,
89 phy_interface_t type, int speed)
91 /* nothing right now */
95 void init_tgec(struct fsl_enet_mac *mac, void *base,
96 void *phyregs, int max_rx_len)
99 mac->phyregs = phyregs;
100 mac->max_rx_len = max_rx_len;
101 mac->init_mac = tgec_init_mac;
102 mac->enable_mac = tgec_enable_mac;
103 mac->disable_mac = tgec_disable_mac;
104 mac->set_mac_addr = tgec_set_mac_addr;
105 mac->set_if_mode = tgec_set_interface_mode;