1 /* 2 * Copyright 2009-2011 Freescale Semiconductor, Inc. 3 * Dave Liu <daveliu@freescale.com> 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License as 7 * published by the Free Software Foundation; either version 2 of 8 * the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 18 * MA 02111-1307 USA 19 */ 20 21 /* MAXFRM - maximum frame length */ 22 #define MAXFRM_MASK 0x0000ffff 23 24 #include <common.h> 25 #include <phy.h> 26 #include <asm/types.h> 27 #include <asm/io.h> 28 #include <asm/fsl_enet.h> 29 #include <asm/fsl_tgec.h> 30 31 #include "fm.h" 32 33 #define TGEC_CMD_CFG_INIT (TGEC_CMD_CFG_NO_LEN_CHK | \ 34 TGEC_CMD_CFG_RX_ER_DISC | \ 35 TGEC_CMD_CFG_STAT_CLR | \ 36 TGEC_CMD_CFG_PAUSE_IGNORE | \ 37 TGEC_CMD_CFG_CRC_FWD) 38 #define TGEC_CMD_CFG_FINAL (TGEC_CMD_CFG_NO_LEN_CHK | \ 39 TGEC_CMD_CFG_RX_ER_DISC | \ 40 TGEC_CMD_CFG_PAUSE_IGNORE | \ 41 TGEC_CMD_CFG_CRC_FWD) 42 43 static void tgec_init_mac(struct fsl_enet_mac *mac) 44 { 45 struct tgec *regs = mac->base; 46 47 /* mask all interrupt */ 48 out_be32(®s->imask, IMASK_MASK_ALL); 49 50 /* clear all events */ 51 out_be32(®s->ievent, IEVENT_CLEAR_ALL); 52 53 /* set the max receive length */ 54 out_be32(®s->maxfrm, mac->max_rx_len & MAXFRM_MASK); 55 56 /* 57 * 1588 disable, insert second mac disable payload length check 58 * disable, normal operation, any rx error frame is discarded, clear 59 * counters, pause frame ignore, no promiscuous, LAN mode Rx CRC no 60 * strip, Tx CRC append, Rx disable and Tx disable 61 */ 62 out_be32(®s->command_config, TGEC_CMD_CFG_INIT); 63 udelay(1000); 64 out_be32(®s->command_config, TGEC_CMD_CFG_FINAL); 65 66 /* multicast frame reception for the hash entry disable */ 67 out_be32(®s->hashtable_ctrl, 0); 68 } 69 70 static void tgec_enable_mac(struct fsl_enet_mac *mac) 71 { 72 struct tgec *regs = mac->base; 73 74 setbits_be32(®s->command_config, TGEC_CMD_CFG_RXTX_EN); 75 } 76 77 static void tgec_disable_mac(struct fsl_enet_mac *mac) 78 { 79 struct tgec *regs = mac->base; 80 81 clrbits_be32(®s->command_config, TGEC_CMD_CFG_RXTX_EN); 82 } 83 84 static void tgec_set_mac_addr(struct fsl_enet_mac *mac, u8 *mac_addr) 85 { 86 struct tgec *regs = mac->base; 87 u32 mac_addr0, mac_addr1; 88 89 /* 90 * if a station address of 0x12345678ABCD, perform a write to 91 * MAC_ADDR0 of 0x78563412, MAC_ADDR1 of 0x0000CDAB 92 */ 93 mac_addr0 = (mac_addr[3] << 24) | (mac_addr[2] << 16) | \ 94 (mac_addr[1] << 8) | (mac_addr[0]); 95 out_be32(®s->mac_addr_0, mac_addr0); 96 97 mac_addr1 = ((mac_addr[5] << 8) | mac_addr[4]) & 0x0000ffff; 98 out_be32(®s->mac_addr_1, mac_addr1); 99 } 100 101 static void tgec_set_interface_mode(struct fsl_enet_mac *mac, 102 phy_interface_t type, int speed) 103 { 104 /* nothing right now */ 105 return; 106 } 107 108 void init_tgec(struct fsl_enet_mac *mac, void *base, 109 void *phyregs, int max_rx_len) 110 { 111 mac->base = base; 112 mac->phyregs = phyregs; 113 mac->max_rx_len = max_rx_len; 114 mac->init_mac = tgec_init_mac; 115 mac->enable_mac = tgec_enable_mac; 116 mac->disable_mac = tgec_disable_mac; 117 mac->set_mac_addr = tgec_set_mac_addr; 118 mac->set_if_mode = tgec_set_interface_mode; 119 } 120