Roy Zang | 111fd19 | 2012-10-08 07:44:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Freescale Semiconductor, Inc. |
| 3 | * Roy Zang <tie-fei.zang@freescale.com> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Roy Zang | 111fd19 | 2012-10-08 07:44:21 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* MAXFRM - maximum frame length */ |
| 9 | #define MAXFRM_MASK 0x0000ffff |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <phy.h> |
| 13 | #include <asm/types.h> |
| 14 | #include <asm/io.h> |
Shaohui Xie | cd348ef | 2015-03-20 19:28:19 -0700 | [diff] [blame] | 15 | #include <fsl_memac.h> |
Roy Zang | 111fd19 | 2012-10-08 07:44:21 +0000 | [diff] [blame] | 16 | |
| 17 | #include "fm.h" |
| 18 | |
| 19 | static void memac_init_mac(struct fsl_enet_mac *mac) |
| 20 | { |
| 21 | struct memac *regs = mac->base; |
| 22 | |
| 23 | /* mask all interrupt */ |
| 24 | out_be32(®s->imask, IMASK_MASK_ALL); |
| 25 | |
| 26 | /* clear all events */ |
| 27 | out_be32(®s->ievent, IEVENT_CLEAR_ALL); |
| 28 | |
| 29 | /* set the max receive length */ |
| 30 | out_be32(®s->maxfrm, mac->max_rx_len & MAXFRM_MASK); |
| 31 | |
| 32 | /* multicast frame reception for the hash entry disable */ |
| 33 | out_be32(®s->hashtable_ctrl, 0); |
| 34 | } |
| 35 | |
| 36 | static void memac_enable_mac(struct fsl_enet_mac *mac) |
| 37 | { |
| 38 | struct memac *regs = mac->base; |
| 39 | |
Shaohui Xie | ff5fb2a | 2014-08-13 18:32:19 +0800 | [diff] [blame] | 40 | setbits_be32(®s->command_config, |
| 41 | MEMAC_CMD_CFG_RXTX_EN | MEMAC_CMD_CFG_NO_LEN_CHK); |
Roy Zang | 111fd19 | 2012-10-08 07:44:21 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static void memac_disable_mac(struct fsl_enet_mac *mac) |
| 45 | { |
| 46 | struct memac *regs = mac->base; |
| 47 | |
| 48 | clrbits_be32(®s->command_config, MEMAC_CMD_CFG_RXTX_EN); |
| 49 | } |
| 50 | |
| 51 | static void memac_set_mac_addr(struct fsl_enet_mac *mac, u8 *mac_addr) |
| 52 | { |
| 53 | struct memac *regs = mac->base; |
| 54 | u32 mac_addr0, mac_addr1; |
| 55 | |
| 56 | /* |
| 57 | * if a station address of 0x12345678ABCD, perform a write to |
| 58 | * MAC_ADDR0 of 0x78563412, MAC_ADDR1 of 0x0000CDAB |
| 59 | */ |
| 60 | mac_addr0 = (mac_addr[3] << 24) | (mac_addr[2] << 16) | \ |
| 61 | (mac_addr[1] << 8) | (mac_addr[0]); |
| 62 | out_be32(®s->mac_addr_0, mac_addr0); |
| 63 | |
| 64 | mac_addr1 = ((mac_addr[5] << 8) | mac_addr[4]) & 0x0000ffff; |
| 65 | out_be32(®s->mac_addr_1, mac_addr1); |
| 66 | } |
| 67 | |
| 68 | static void memac_set_interface_mode(struct fsl_enet_mac *mac, |
| 69 | phy_interface_t type, int speed) |
| 70 | { |
| 71 | /* Roy need more work here */ |
| 72 | |
| 73 | struct memac *regs = mac->base; |
| 74 | u32 if_mode, if_status; |
| 75 | |
| 76 | /* clear all bits relative with interface mode */ |
| 77 | if_mode = in_be32(®s->if_mode); |
| 78 | if_status = in_be32(®s->if_status); |
| 79 | |
| 80 | /* set interface mode */ |
| 81 | switch (type) { |
| 82 | case PHY_INTERFACE_MODE_GMII: |
| 83 | if_mode &= ~IF_MODE_MASK; |
| 84 | if_mode |= IF_MODE_GMII; |
| 85 | break; |
| 86 | case PHY_INTERFACE_MODE_RGMII: |
Madalin Bucur | 3f8f141 | 2017-08-04 09:14:53 +0300 | [diff] [blame] | 87 | case PHY_INTERFACE_MODE_RGMII_TXID: |
Roy Zang | 111fd19 | 2012-10-08 07:44:21 +0000 | [diff] [blame] | 88 | if_mode |= (IF_MODE_GMII | IF_MODE_RG); |
| 89 | break; |
| 90 | case PHY_INTERFACE_MODE_RMII: |
| 91 | if_mode |= (IF_MODE_GMII | IF_MODE_RM); |
| 92 | break; |
| 93 | case PHY_INTERFACE_MODE_SGMII: |
shaohui xie | bead088 | 2016-11-15 14:36:47 +0800 | [diff] [blame] | 94 | case PHY_INTERFACE_MODE_SGMII_2500: |
Shaohui Xie | 1c68d01 | 2013-08-19 18:58:52 +0800 | [diff] [blame] | 95 | case PHY_INTERFACE_MODE_QSGMII: |
Roy Zang | 111fd19 | 2012-10-08 07:44:21 +0000 | [diff] [blame] | 96 | if_mode &= ~IF_MODE_MASK; |
| 97 | if_mode |= (IF_MODE_GMII); |
| 98 | break; |
Shaohui Xie | ff5fb2a | 2014-08-13 18:32:19 +0800 | [diff] [blame] | 99 | case PHY_INTERFACE_MODE_XGMII: |
| 100 | if_mode &= ~IF_MODE_MASK; |
| 101 | if_mode |= IF_MODE_XGMII; |
| 102 | break; |
Roy Zang | 111fd19 | 2012-10-08 07:44:21 +0000 | [diff] [blame] | 103 | default: |
| 104 | break; |
| 105 | } |
Shaohui Xie | ff5fb2a | 2014-08-13 18:32:19 +0800 | [diff] [blame] | 106 | /* Enable automatic speed selection for Non-XGMII */ |
| 107 | if (type != PHY_INTERFACE_MODE_XGMII) |
| 108 | if_mode |= IF_MODE_EN_AUTO; |
Roy Zang | 111fd19 | 2012-10-08 07:44:21 +0000 | [diff] [blame] | 109 | |
Madalin Bucur | 3f8f141 | 2017-08-04 09:14:53 +0300 | [diff] [blame] | 110 | if (type == PHY_INTERFACE_MODE_RGMII || |
| 111 | type == PHY_INTERFACE_MODE_RGMII_TXID) { |
Zang Roy-R61911 | c5729f0 | 2013-03-04 03:59:20 +0000 | [diff] [blame] | 112 | if_mode &= ~IF_MODE_EN_AUTO; |
| 113 | if_mode &= ~IF_MODE_SETSP_MASK; |
| 114 | switch (speed) { |
| 115 | case SPEED_1000: |
| 116 | if_mode |= IF_MODE_SETSP_1000M; |
| 117 | break; |
| 118 | case SPEED_100: |
| 119 | if_mode |= IF_MODE_SETSP_100M; |
| 120 | break; |
| 121 | case SPEED_10: |
| 122 | if_mode |= IF_MODE_SETSP_10M; |
| 123 | default: |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | |
Roy Zang | 111fd19 | 2012-10-08 07:44:21 +0000 | [diff] [blame] | 128 | debug(" %s, if_mode = %x\n", __func__, if_mode); |
| 129 | debug(" %s, if_status = %x\n", __func__, if_status); |
| 130 | out_be32(®s->if_mode, if_mode); |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | void init_memac(struct fsl_enet_mac *mac, void *base, |
| 135 | void *phyregs, int max_rx_len) |
| 136 | { |
| 137 | mac->base = base; |
| 138 | mac->phyregs = phyregs; |
| 139 | mac->max_rx_len = max_rx_len; |
| 140 | mac->init_mac = memac_init_mac; |
| 141 | mac->enable_mac = memac_enable_mac; |
| 142 | mac->disable_mac = memac_disable_mac; |
| 143 | mac->set_mac_addr = memac_set_mac_addr; |
| 144 | mac->set_if_mode = memac_set_interface_mode; |
| 145 | } |