Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 1 | /* |
Robert P. J. Day | 8c60f92 | 2016-05-04 04:47:31 -0400 | [diff] [blame] | 2 | * sh_eth.c - Driver for Renesas ethernet controller. |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 3 | * |
Nobuhiro Iwamatsu | 9dfac0a | 2011-11-14 16:56:59 +0900 | [diff] [blame] | 4 | * Copyright (C) 2008, 2011 Renesas Solutions Corp. |
Nobuhiro Iwamatsu | 5ba66ad | 2014-11-04 09:15:48 +0900 | [diff] [blame] | 5 | * Copyright (c) 2008, 2011, 2014 2014 Nobuhiro Iwamatsu |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 6 | * Copyright (c) 2007 Carlos Munoz <carlos@kenati.com> |
Nobuhiro Iwamatsu | 5ba66ad | 2014-11-04 09:15:48 +0900 | [diff] [blame] | 7 | * Copyright (C) 2013, 2014 Renesas Electronics Corporation |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 8 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <config.h> |
| 13 | #include <common.h> |
| 14 | #include <malloc.h> |
| 15 | #include <net.h> |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 16 | #include <netdev.h> |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 17 | #include <miiphy.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 18 | #include <linux/errno.h> |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 19 | #include <asm/io.h> |
| 20 | |
| 21 | #include "sh_eth.h" |
| 22 | |
| 23 | #ifndef CONFIG_SH_ETHER_USE_PORT |
| 24 | # error "Please define CONFIG_SH_ETHER_USE_PORT" |
| 25 | #endif |
| 26 | #ifndef CONFIG_SH_ETHER_PHY_ADDR |
| 27 | # error "Please define CONFIG_SH_ETHER_PHY_ADDR" |
| 28 | #endif |
Nobuhiro Iwamatsu | 6bff09d | 2013-08-22 13:22:01 +0900 | [diff] [blame] | 29 | |
Nobuhiro Iwamatsu | ee74c70 | 2013-08-22 13:22:03 +0900 | [diff] [blame] | 30 | #if defined(CONFIG_SH_ETHER_CACHE_WRITEBACK) && !defined(CONFIG_SYS_DCACHE_OFF) |
| 31 | #define flush_cache_wback(addr, len) \ |
Nobuhiro Iwamatsu | 425a3a5 | 2017-12-01 13:56:08 +0900 | [diff] [blame] | 32 | flush_dcache_range((u32)addr, \ |
| 33 | (u32)(addr + ALIGN(len, CONFIG_SH_ETHER_ALIGNE_SIZE))) |
Yoshihiro Shimoda | 281aa05 | 2011-01-27 10:06:08 +0900 | [diff] [blame] | 34 | #else |
| 35 | #define flush_cache_wback(...) |
| 36 | #endif |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 37 | |
Nobuhiro Iwamatsu | ee74c70 | 2013-08-22 13:22:03 +0900 | [diff] [blame] | 38 | #if defined(CONFIG_SH_ETHER_CACHE_INVALIDATE) && defined(CONFIG_ARM) |
| 39 | #define invalidate_cache(addr, len) \ |
| 40 | { \ |
| 41 | u32 line_size = CONFIG_SH_ETHER_ALIGNE_SIZE; \ |
| 42 | u32 start, end; \ |
| 43 | \ |
| 44 | start = (u32)addr; \ |
| 45 | end = start + len; \ |
| 46 | start &= ~(line_size - 1); \ |
| 47 | end = ((end + line_size - 1) & ~(line_size - 1)); \ |
| 48 | \ |
| 49 | invalidate_dcache_range(start, end); \ |
| 50 | } |
| 51 | #else |
| 52 | #define invalidate_cache(...) |
| 53 | #endif |
| 54 | |
Nobuhiro Iwamatsu | 71f507c | 2012-01-11 10:23:51 +0900 | [diff] [blame] | 55 | #define TIMEOUT_CNT 1000 |
| 56 | |
Marek Vasut | 044eb2d | 2018-01-21 14:27:51 +0100 | [diff] [blame] | 57 | static int sh_eth_send_common(struct sh_eth_dev *eth, void *packet, int len) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 58 | { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 59 | int port = eth->port, ret = 0, timeout; |
| 60 | struct sh_eth_info *port_info = ð->port_info[port]; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 61 | |
| 62 | if (!packet || len > 0xffff) { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 63 | printf(SHETHER_NAME ": %s: Invalid argument\n", __func__); |
| 64 | ret = -EINVAL; |
| 65 | goto err; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /* packet must be a 4 byte boundary */ |
Nobuhiro Iwamatsu | 5880290 | 2012-02-02 21:28:49 +0000 | [diff] [blame] | 69 | if ((int)packet & 3) { |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 70 | printf(SHETHER_NAME ": %s: packet not 4 byte aligned\n" |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 71 | , __func__); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 72 | ret = -EFAULT; |
| 73 | goto err; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /* Update tx descriptor */ |
Yoshihiro Shimoda | 281aa05 | 2011-01-27 10:06:08 +0900 | [diff] [blame] | 77 | flush_cache_wback(packet, len); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 78 | port_info->tx_desc_cur->td2 = ADDR_TO_PHY(packet); |
| 79 | port_info->tx_desc_cur->td1 = len << 16; |
| 80 | /* Must preserve the end of descriptor list indication */ |
| 81 | if (port_info->tx_desc_cur->td0 & TD_TDLE) |
| 82 | port_info->tx_desc_cur->td0 = TD_TACT | TD_TFP | TD_TDLE; |
| 83 | else |
| 84 | port_info->tx_desc_cur->td0 = TD_TACT | TD_TFP; |
| 85 | |
Nobuhiro Iwamatsu | 5ba66ad | 2014-11-04 09:15:48 +0900 | [diff] [blame] | 86 | flush_cache_wback(port_info->tx_desc_cur, sizeof(struct tx_desc_s)); |
| 87 | |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 88 | /* Restart the transmitter if disabled */ |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 89 | if (!(sh_eth_read(port_info, EDTRR) & EDTRR_TRNS)) |
| 90 | sh_eth_write(port_info, EDTRR_TRNS, EDTRR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 91 | |
| 92 | /* Wait until packet is transmitted */ |
Nobuhiro Iwamatsu | 71f507c | 2012-01-11 10:23:51 +0900 | [diff] [blame] | 93 | timeout = TIMEOUT_CNT; |
Nobuhiro Iwamatsu | ee74c70 | 2013-08-22 13:22:03 +0900 | [diff] [blame] | 94 | do { |
| 95 | invalidate_cache(port_info->tx_desc_cur, |
| 96 | sizeof(struct tx_desc_s)); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 97 | udelay(100); |
Nobuhiro Iwamatsu | ee74c70 | 2013-08-22 13:22:03 +0900 | [diff] [blame] | 98 | } while (port_info->tx_desc_cur->td0 & TD_TACT && timeout--); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 99 | |
| 100 | if (timeout < 0) { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 101 | printf(SHETHER_NAME ": transmit timeout\n"); |
| 102 | ret = -ETIMEDOUT; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 103 | goto err; |
| 104 | } |
| 105 | |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 106 | port_info->tx_desc_cur++; |
| 107 | if (port_info->tx_desc_cur >= port_info->tx_desc_base + NUM_TX_DESC) |
| 108 | port_info->tx_desc_cur = port_info->tx_desc_base; |
| 109 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 110 | err: |
| 111 | return ret; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 112 | } |
| 113 | |
Marek Vasut | 044eb2d | 2018-01-21 14:27:51 +0100 | [diff] [blame] | 114 | static int sh_eth_send_legacy(struct eth_device *dev, void *packet, int len) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 115 | { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 116 | struct sh_eth_dev *eth = dev->priv; |
Marek Vasut | 044eb2d | 2018-01-21 14:27:51 +0100 | [diff] [blame] | 117 | |
| 118 | return sh_eth_send_common(eth, packet, len); |
| 119 | } |
| 120 | |
Marek Vasut | 48de90d | 2018-01-21 15:39:50 +0100 | [diff] [blame^] | 121 | static int sh_eth_recv_start(struct sh_eth_dev *eth) |
Marek Vasut | 044eb2d | 2018-01-21 14:27:51 +0100 | [diff] [blame] | 122 | { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 123 | int port = eth->port, len = 0; |
| 124 | struct sh_eth_info *port_info = ð->port_info[port]; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 125 | |
| 126 | /* Check if the rx descriptor is ready */ |
Nobuhiro Iwamatsu | ee74c70 | 2013-08-22 13:22:03 +0900 | [diff] [blame] | 127 | invalidate_cache(port_info->rx_desc_cur, sizeof(struct rx_desc_s)); |
Marek Vasut | 48de90d | 2018-01-21 15:39:50 +0100 | [diff] [blame^] | 128 | if (port_info->rx_desc_cur->rd0 & RD_RACT) |
| 129 | return -EINVAL; |
| 130 | |
| 131 | /* Check for errors */ |
| 132 | if (port_info->rx_desc_cur->rd0 & RD_RFE) |
| 133 | return -EINVAL; |
| 134 | |
| 135 | len = port_info->rx_desc_cur->rd1 & 0xffff; |
| 136 | |
| 137 | return len; |
| 138 | } |
| 139 | |
| 140 | static void sh_eth_recv_finish(struct sh_eth_dev *eth) |
| 141 | { |
| 142 | struct sh_eth_info *port_info = ð->port_info[eth->port]; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 143 | |
Marek Vasut | 48de90d | 2018-01-21 15:39:50 +0100 | [diff] [blame^] | 144 | /* Make current descriptor available again */ |
| 145 | if (port_info->rx_desc_cur->rd0 & RD_RDLE) |
| 146 | port_info->rx_desc_cur->rd0 = RD_RACT | RD_RDLE; |
| 147 | else |
| 148 | port_info->rx_desc_cur->rd0 = RD_RACT; |
Nobuhiro Iwamatsu | 5ba66ad | 2014-11-04 09:15:48 +0900 | [diff] [blame] | 149 | |
Marek Vasut | 48de90d | 2018-01-21 15:39:50 +0100 | [diff] [blame^] | 150 | flush_cache_wback(port_info->rx_desc_cur, |
| 151 | sizeof(struct rx_desc_s)); |
| 152 | |
| 153 | /* Point to the next descriptor */ |
| 154 | port_info->rx_desc_cur++; |
| 155 | if (port_info->rx_desc_cur >= |
| 156 | port_info->rx_desc_base + NUM_RX_DESC) |
| 157 | port_info->rx_desc_cur = port_info->rx_desc_base; |
| 158 | } |
| 159 | |
| 160 | static int sh_eth_recv_common(struct sh_eth_dev *eth) |
| 161 | { |
| 162 | int port = eth->port, len = 0; |
| 163 | struct sh_eth_info *port_info = ð->port_info[port]; |
| 164 | uchar *packet = (uchar *)ADDR_TO_P2(port_info->rx_desc_cur->rd2); |
Nobuhiro Iwamatsu | 5ba66ad | 2014-11-04 09:15:48 +0900 | [diff] [blame] | 165 | |
Marek Vasut | 48de90d | 2018-01-21 15:39:50 +0100 | [diff] [blame^] | 166 | len = sh_eth_recv_start(eth); |
| 167 | if (len > 0) { |
| 168 | invalidate_cache(packet, len); |
| 169 | net_process_received_packet(packet, len); |
| 170 | sh_eth_recv_finish(eth); |
| 171 | } else |
| 172 | len = 0; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 173 | |
| 174 | /* Restart the receiver if disabled */ |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 175 | if (!(sh_eth_read(port_info, EDRRR) & EDRRR_R)) |
| 176 | sh_eth_write(port_info, EDRRR_R, EDRRR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 177 | |
| 178 | return len; |
| 179 | } |
| 180 | |
Marek Vasut | 044eb2d | 2018-01-21 14:27:51 +0100 | [diff] [blame] | 181 | static int sh_eth_recv_legacy(struct eth_device *dev) |
| 182 | { |
| 183 | struct sh_eth_dev *eth = dev->priv; |
| 184 | |
| 185 | return sh_eth_recv_common(eth); |
| 186 | } |
| 187 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 188 | static int sh_eth_reset(struct sh_eth_dev *eth) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 189 | { |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 190 | struct sh_eth_info *port_info = ð->port_info[eth->port]; |
Nobuhiro Iwamatsu | 46288f4 | 2014-01-23 07:52:18 +0900 | [diff] [blame] | 191 | #if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ) |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 192 | int ret = 0, i; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 193 | |
| 194 | /* Start e-dmac transmitter and receiver */ |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 195 | sh_eth_write(port_info, EDSR_ENALL, EDSR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 196 | |
| 197 | /* Perform a software reset and wait for it to complete */ |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 198 | sh_eth_write(port_info, EDMR_SRST, EDMR); |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 199 | for (i = 0; i < TIMEOUT_CNT; i++) { |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 200 | if (!(sh_eth_read(port_info, EDMR) & EDMR_SRST)) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 201 | break; |
| 202 | udelay(1000); |
| 203 | } |
| 204 | |
Nobuhiro Iwamatsu | 71f507c | 2012-01-11 10:23:51 +0900 | [diff] [blame] | 205 | if (i == TIMEOUT_CNT) { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 206 | printf(SHETHER_NAME ": Software reset timeout\n"); |
| 207 | ret = -EIO; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 208 | } |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 209 | |
| 210 | return ret; |
Yoshihiro Shimoda | 34cca92 | 2011-01-18 17:53:45 +0900 | [diff] [blame] | 211 | #else |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 212 | sh_eth_write(port_info, sh_eth_read(port_info, EDMR) | EDMR_SRST, EDMR); |
Yoshihiro Shimoda | 34cca92 | 2011-01-18 17:53:45 +0900 | [diff] [blame] | 213 | udelay(3000); |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 214 | sh_eth_write(port_info, |
| 215 | sh_eth_read(port_info, EDMR) & ~EDMR_SRST, EDMR); |
Yoshihiro Shimoda | 34cca92 | 2011-01-18 17:53:45 +0900 | [diff] [blame] | 216 | |
| 217 | return 0; |
| 218 | #endif |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 219 | } |
| 220 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 221 | static int sh_eth_tx_desc_init(struct sh_eth_dev *eth) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 222 | { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 223 | int port = eth->port, i, ret = 0; |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 224 | u32 alloc_desc_size = NUM_TX_DESC * sizeof(struct tx_desc_s); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 225 | struct sh_eth_info *port_info = ð->port_info[port]; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 226 | struct tx_desc_s *cur_tx_desc; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 227 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 228 | /* |
Nobuhiro Iwamatsu | c24b3eb | 2014-11-04 09:15:46 +0900 | [diff] [blame] | 229 | * Allocate rx descriptors. They must be aligned to size of struct |
| 230 | * tx_desc_s. |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 231 | */ |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 232 | port_info->tx_desc_alloc = |
| 233 | memalign(sizeof(struct tx_desc_s), alloc_desc_size); |
| 234 | if (!port_info->tx_desc_alloc) { |
| 235 | printf(SHETHER_NAME ": memalign failed\n"); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 236 | ret = -ENOMEM; |
| 237 | goto err; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 238 | } |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 239 | |
Nobuhiro Iwamatsu | 425a3a5 | 2017-12-01 13:56:08 +0900 | [diff] [blame] | 240 | flush_cache_wback(port_info->tx_desc_alloc, alloc_desc_size); |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 241 | |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 242 | /* Make sure we use a P2 address (non-cacheable) */ |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 243 | port_info->tx_desc_base = |
| 244 | (struct tx_desc_s *)ADDR_TO_P2((u32)port_info->tx_desc_alloc); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 245 | port_info->tx_desc_cur = port_info->tx_desc_base; |
| 246 | |
| 247 | /* Initialize all descriptors */ |
| 248 | for (cur_tx_desc = port_info->tx_desc_base, i = 0; i < NUM_TX_DESC; |
| 249 | cur_tx_desc++, i++) { |
| 250 | cur_tx_desc->td0 = 0x00; |
| 251 | cur_tx_desc->td1 = 0x00; |
| 252 | cur_tx_desc->td2 = 0x00; |
| 253 | } |
| 254 | |
| 255 | /* Mark the end of the descriptors */ |
| 256 | cur_tx_desc--; |
| 257 | cur_tx_desc->td0 |= TD_TDLE; |
| 258 | |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 259 | /* |
| 260 | * Point the controller to the tx descriptor list. Must use physical |
| 261 | * addresses |
| 262 | */ |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 263 | sh_eth_write(port_info, ADDR_TO_PHY(port_info->tx_desc_base), TDLAR); |
Nobuhiro Iwamatsu | 46288f4 | 2014-01-23 07:52:18 +0900 | [diff] [blame] | 264 | #if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 265 | sh_eth_write(port_info, ADDR_TO_PHY(port_info->tx_desc_base), TDFAR); |
| 266 | sh_eth_write(port_info, ADDR_TO_PHY(cur_tx_desc), TDFXR); |
| 267 | sh_eth_write(port_info, 0x01, TDFFR);/* Last discriptor bit */ |
Yoshihiro Shimoda | 34cca92 | 2011-01-18 17:53:45 +0900 | [diff] [blame] | 268 | #endif |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 269 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 270 | err: |
| 271 | return ret; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 272 | } |
| 273 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 274 | static int sh_eth_rx_desc_init(struct sh_eth_dev *eth) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 275 | { |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 276 | int port = eth->port, i, ret = 0; |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 277 | u32 alloc_desc_size = NUM_RX_DESC * sizeof(struct rx_desc_s); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 278 | struct sh_eth_info *port_info = ð->port_info[port]; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 279 | struct rx_desc_s *cur_rx_desc; |
| 280 | u8 *rx_buf; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 281 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 282 | /* |
Nobuhiro Iwamatsu | c24b3eb | 2014-11-04 09:15:46 +0900 | [diff] [blame] | 283 | * Allocate rx descriptors. They must be aligned to size of struct |
| 284 | * rx_desc_s. |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 285 | */ |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 286 | port_info->rx_desc_alloc = |
| 287 | memalign(sizeof(struct rx_desc_s), alloc_desc_size); |
| 288 | if (!port_info->rx_desc_alloc) { |
| 289 | printf(SHETHER_NAME ": memalign failed\n"); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 290 | ret = -ENOMEM; |
| 291 | goto err; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 292 | } |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 293 | |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 294 | flush_cache_wback(port_info->rx_desc_alloc, alloc_desc_size); |
| 295 | |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 296 | /* Make sure we use a P2 address (non-cacheable) */ |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 297 | port_info->rx_desc_base = |
| 298 | (struct rx_desc_s *)ADDR_TO_P2((u32)port_info->rx_desc_alloc); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 299 | |
| 300 | port_info->rx_desc_cur = port_info->rx_desc_base; |
| 301 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 302 | /* |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 303 | * Allocate rx data buffers. They must be RX_BUF_ALIGNE_SIZE bytes |
| 304 | * aligned and in P2 area. |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 305 | */ |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 306 | port_info->rx_buf_alloc = |
| 307 | memalign(RX_BUF_ALIGNE_SIZE, NUM_RX_DESC * MAX_BUF_SIZE); |
| 308 | if (!port_info->rx_buf_alloc) { |
| 309 | printf(SHETHER_NAME ": alloc failed\n"); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 310 | ret = -ENOMEM; |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 311 | goto err_buf_alloc; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 312 | } |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 313 | |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 314 | port_info->rx_buf_base = (u8 *)ADDR_TO_P2((u32)port_info->rx_buf_alloc); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 315 | |
| 316 | /* Initialize all descriptors */ |
| 317 | for (cur_rx_desc = port_info->rx_desc_base, |
| 318 | rx_buf = port_info->rx_buf_base, i = 0; |
| 319 | i < NUM_RX_DESC; cur_rx_desc++, rx_buf += MAX_BUF_SIZE, i++) { |
| 320 | cur_rx_desc->rd0 = RD_RACT; |
| 321 | cur_rx_desc->rd1 = MAX_BUF_SIZE << 16; |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 322 | cur_rx_desc->rd2 = (u32)ADDR_TO_PHY(rx_buf); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /* Mark the end of the descriptors */ |
| 326 | cur_rx_desc--; |
| 327 | cur_rx_desc->rd0 |= RD_RDLE; |
| 328 | |
| 329 | /* Point the controller to the rx descriptor list */ |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 330 | sh_eth_write(port_info, ADDR_TO_PHY(port_info->rx_desc_base), RDLAR); |
Nobuhiro Iwamatsu | 46288f4 | 2014-01-23 07:52:18 +0900 | [diff] [blame] | 331 | #if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 332 | sh_eth_write(port_info, ADDR_TO_PHY(port_info->rx_desc_base), RDFAR); |
| 333 | sh_eth_write(port_info, ADDR_TO_PHY(cur_rx_desc), RDFXR); |
| 334 | sh_eth_write(port_info, RDFFR_RDLF, RDFFR); |
Yoshihiro Shimoda | 34cca92 | 2011-01-18 17:53:45 +0900 | [diff] [blame] | 335 | #endif |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 336 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 337 | return ret; |
| 338 | |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 339 | err_buf_alloc: |
| 340 | free(port_info->rx_desc_alloc); |
| 341 | port_info->rx_desc_alloc = NULL; |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 342 | |
| 343 | err: |
| 344 | return ret; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 345 | } |
| 346 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 347 | static void sh_eth_tx_desc_free(struct sh_eth_dev *eth) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 348 | { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 349 | int port = eth->port; |
| 350 | struct sh_eth_info *port_info = ð->port_info[port]; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 351 | |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 352 | if (port_info->tx_desc_alloc) { |
| 353 | free(port_info->tx_desc_alloc); |
| 354 | port_info->tx_desc_alloc = NULL; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 355 | } |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static void sh_eth_rx_desc_free(struct sh_eth_dev *eth) |
| 359 | { |
| 360 | int port = eth->port; |
| 361 | struct sh_eth_info *port_info = ð->port_info[port]; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 362 | |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 363 | if (port_info->rx_desc_alloc) { |
| 364 | free(port_info->rx_desc_alloc); |
| 365 | port_info->rx_desc_alloc = NULL; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 366 | } |
| 367 | |
Nobuhiro Iwamatsu | 1c82211 | 2014-11-04 09:15:47 +0900 | [diff] [blame] | 368 | if (port_info->rx_buf_alloc) { |
| 369 | free(port_info->rx_buf_alloc); |
| 370 | port_info->rx_buf_alloc = NULL; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 374 | static int sh_eth_desc_init(struct sh_eth_dev *eth) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 375 | { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 376 | int ret = 0; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 377 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 378 | ret = sh_eth_tx_desc_init(eth); |
| 379 | if (ret) |
| 380 | goto err_tx_init; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 381 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 382 | ret = sh_eth_rx_desc_init(eth); |
| 383 | if (ret) |
| 384 | goto err_rx_init; |
| 385 | |
| 386 | return ret; |
| 387 | err_rx_init: |
| 388 | sh_eth_tx_desc_free(eth); |
| 389 | |
| 390 | err_tx_init: |
| 391 | return ret; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 392 | } |
| 393 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 394 | static int sh_eth_phy_config(struct sh_eth_dev *eth) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 395 | { |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 396 | int port = eth->port, ret = 0; |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 397 | struct sh_eth_info *port_info = ð->port_info[port]; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 398 | struct eth_device *dev = port_info->dev; |
| 399 | struct phy_device *phydev; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 400 | |
Nobuhiro Iwamatsu | 5880290 | 2012-02-02 21:28:49 +0000 | [diff] [blame] | 401 | phydev = phy_connect( |
| 402 | miiphy_get_dev_by_name(dev->name), |
Nobuhiro Iwamatsu | 475f40d | 2012-05-15 15:49:39 +0000 | [diff] [blame] | 403 | port_info->phy_addr, dev, CONFIG_SH_ETHER_PHY_MODE); |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 404 | port_info->phydev = phydev; |
| 405 | phy_config(phydev); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 406 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 407 | return ret; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 408 | } |
| 409 | |
Nobuhiro Iwamatsu | 65a81a4 | 2017-12-01 08:08:47 +0900 | [diff] [blame] | 410 | static int sh_eth_config(struct sh_eth_dev *eth) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 411 | { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 412 | int port = eth->port, ret = 0; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 413 | u32 val; |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 414 | struct sh_eth_info *port_info = ð->port_info[port]; |
Mike Frysinger | a86bf13 | 2009-02-11 19:14:09 -0500 | [diff] [blame] | 415 | struct eth_device *dev = port_info->dev; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 416 | struct phy_device *phy; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 417 | |
| 418 | /* Configure e-dmac registers */ |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 419 | sh_eth_write(port_info, (sh_eth_read(port_info, EDMR) & ~EMDR_DESC_R) | |
Nobuhiro Iwamatsu | 7a2142c | 2013-08-22 13:22:02 +0900 | [diff] [blame] | 420 | (EMDR_DESC | EDMR_EL), EDMR); |
| 421 | |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 422 | sh_eth_write(port_info, 0, EESIPR); |
| 423 | sh_eth_write(port_info, 0, TRSCER); |
| 424 | sh_eth_write(port_info, 0, TFTR); |
| 425 | sh_eth_write(port_info, (FIFO_SIZE_T | FIFO_SIZE_R), FDR); |
| 426 | sh_eth_write(port_info, RMCR_RST, RMCR); |
Nobuhiro Iwamatsu | 46288f4 | 2014-01-23 07:52:18 +0900 | [diff] [blame] | 427 | #if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 428 | sh_eth_write(port_info, 0, RPADIR); |
Yoshihiro Shimoda | 34cca92 | 2011-01-18 17:53:45 +0900 | [diff] [blame] | 429 | #endif |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 430 | sh_eth_write(port_info, (FIFO_F_D_RFF | FIFO_F_D_RFD), FCFTR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 431 | |
| 432 | /* Configure e-mac registers */ |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 433 | sh_eth_write(port_info, 0, ECSIPR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 434 | |
| 435 | /* Set Mac address */ |
Mike Frysinger | a86bf13 | 2009-02-11 19:14:09 -0500 | [diff] [blame] | 436 | val = dev->enetaddr[0] << 24 | dev->enetaddr[1] << 16 | |
| 437 | dev->enetaddr[2] << 8 | dev->enetaddr[3]; |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 438 | sh_eth_write(port_info, val, MAHR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 439 | |
Mike Frysinger | a86bf13 | 2009-02-11 19:14:09 -0500 | [diff] [blame] | 440 | val = dev->enetaddr[4] << 8 | dev->enetaddr[5]; |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 441 | sh_eth_write(port_info, val, MALR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 442 | |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 443 | sh_eth_write(port_info, RFLR_RFL_MIN, RFLR); |
Yoshihiro Shimoda | 9d55303 | 2012-06-26 16:38:06 +0000 | [diff] [blame] | 444 | #if defined(SH_ETH_TYPE_GETHER) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 445 | sh_eth_write(port_info, 0, PIPR); |
Nobuhiro Iwamatsu | 46288f4 | 2014-01-23 07:52:18 +0900 | [diff] [blame] | 446 | #endif |
| 447 | #if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 448 | sh_eth_write(port_info, APR_AP, APR); |
| 449 | sh_eth_write(port_info, MPR_MP, MPR); |
| 450 | sh_eth_write(port_info, TPAUSER_TPAUSE, TPAUSER); |
Yoshihiro Shimoda | 34cca92 | 2011-01-18 17:53:45 +0900 | [diff] [blame] | 451 | #endif |
Nobuhiro Iwamatsu | 9dfac0a | 2011-11-14 16:56:59 +0900 | [diff] [blame] | 452 | |
Nobuhiro Iwamatsu | 4ad2c2a | 2012-08-02 22:08:40 +0000 | [diff] [blame] | 453 | #if defined(CONFIG_CPU_SH7734) || defined(CONFIG_R8A7740) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 454 | sh_eth_write(port_info, CONFIG_SH_ETHER_SH7734_MII, RMII_MII); |
Marek Vasut | ee2f21b | 2018-01-22 01:42:32 +0100 | [diff] [blame] | 455 | #elif defined(CONFIG_RCAR_GEN2) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 456 | sh_eth_write(port_info, sh_eth_read(port_info, RMIIMR) | 0x1, RMIIMR); |
Nobuhiro Iwamatsu | 475f40d | 2012-05-15 15:49:39 +0000 | [diff] [blame] | 457 | #endif |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 458 | /* Configure phy */ |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 459 | ret = sh_eth_phy_config(eth); |
| 460 | if (ret) { |
Nobuhiro Iwamatsu | fc4b0a2 | 2009-06-25 16:33:04 +0900 | [diff] [blame] | 461 | printf(SHETHER_NAME ": phy config timeout\n"); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 462 | goto err_phy_cfg; |
| 463 | } |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 464 | phy = port_info->phydev; |
Timur Tabi | 4238746 | 2012-07-09 08:52:43 +0000 | [diff] [blame] | 465 | ret = phy_startup(phy); |
| 466 | if (ret) { |
| 467 | printf(SHETHER_NAME ": phy startup failure\n"); |
| 468 | return ret; |
| 469 | } |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 470 | |
Nobuhiro Iwamatsu | 9dfac0a | 2011-11-14 16:56:59 +0900 | [diff] [blame] | 471 | val = 0; |
| 472 | |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 473 | /* Set the transfer speed */ |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 474 | if (phy->speed == 100) { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 475 | printf(SHETHER_NAME ": 100Base/"); |
Yoshihiro Shimoda | 9d55303 | 2012-06-26 16:38:06 +0000 | [diff] [blame] | 476 | #if defined(SH_ETH_TYPE_GETHER) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 477 | sh_eth_write(port_info, GECMR_100B, GECMR); |
Yoshihiro Shimoda | d27e8c9 | 2012-11-04 15:54:30 +0000 | [diff] [blame] | 478 | #elif defined(CONFIG_CPU_SH7757) || defined(CONFIG_CPU_SH7752) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 479 | sh_eth_write(port_info, 1, RTRATE); |
Marek Vasut | ee2f21b | 2018-01-22 01:42:32 +0100 | [diff] [blame] | 480 | #elif defined(CONFIG_CPU_SH7724) || defined(CONFIG_RCAR_GEN2) |
Nobuhiro Iwamatsu | 9dfac0a | 2011-11-14 16:56:59 +0900 | [diff] [blame] | 481 | val = ECMR_RTM; |
| 482 | #endif |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 483 | } else if (phy->speed == 10) { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 484 | printf(SHETHER_NAME ": 10Base/"); |
Yoshihiro Shimoda | 9d55303 | 2012-06-26 16:38:06 +0000 | [diff] [blame] | 485 | #if defined(SH_ETH_TYPE_GETHER) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 486 | sh_eth_write(port_info, GECMR_10B, GECMR); |
Yoshihiro Shimoda | d27e8c9 | 2012-11-04 15:54:30 +0000 | [diff] [blame] | 487 | #elif defined(CONFIG_CPU_SH7757) || defined(CONFIG_CPU_SH7752) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 488 | sh_eth_write(port_info, 0, RTRATE); |
Yoshihiro Shimoda | 34cca92 | 2011-01-18 17:53:45 +0900 | [diff] [blame] | 489 | #endif |
Nobuhiro Iwamatsu | 9dfac0a | 2011-11-14 16:56:59 +0900 | [diff] [blame] | 490 | } |
Yoshihiro Shimoda | 9d55303 | 2012-06-26 16:38:06 +0000 | [diff] [blame] | 491 | #if defined(SH_ETH_TYPE_GETHER) |
Nobuhiro Iwamatsu | 475f40d | 2012-05-15 15:49:39 +0000 | [diff] [blame] | 492 | else if (phy->speed == 1000) { |
| 493 | printf(SHETHER_NAME ": 1000Base/"); |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 494 | sh_eth_write(port_info, GECMR_1000B, GECMR); |
Nobuhiro Iwamatsu | 475f40d | 2012-05-15 15:49:39 +0000 | [diff] [blame] | 495 | } |
| 496 | #endif |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 497 | |
| 498 | /* Check if full duplex mode is supported by the phy */ |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 499 | if (phy->duplex) { |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 500 | printf("Full\n"); |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 501 | sh_eth_write(port_info, |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 502 | val | (ECMR_CHG_DM | ECMR_RE | ECMR_TE | ECMR_DM), |
Yoshihiro Shimoda | 4c4aa6c | 2012-06-26 16:38:09 +0000 | [diff] [blame] | 503 | ECMR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 504 | } else { |
| 505 | printf("Half\n"); |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 506 | sh_eth_write(port_info, |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 507 | val | (ECMR_CHG_DM | ECMR_RE | ECMR_TE), |
| 508 | ECMR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 509 | } |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 510 | |
| 511 | return ret; |
| 512 | |
| 513 | err_phy_cfg: |
| 514 | return ret; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 515 | } |
| 516 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 517 | static void sh_eth_start(struct sh_eth_dev *eth) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 518 | { |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 519 | struct sh_eth_info *port_info = ð->port_info[eth->port]; |
| 520 | |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 521 | /* |
| 522 | * Enable the e-dmac receiver only. The transmitter will be enabled when |
| 523 | * we have something to transmit |
| 524 | */ |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 525 | sh_eth_write(port_info, EDRRR_R, EDRRR); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 526 | } |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 527 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 528 | static void sh_eth_stop(struct sh_eth_dev *eth) |
| 529 | { |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 530 | struct sh_eth_info *port_info = ð->port_info[eth->port]; |
| 531 | |
| 532 | sh_eth_write(port_info, ~EDRRR_R, EDRRR); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 533 | } |
| 534 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 535 | int sh_eth_init(struct eth_device *dev, bd_t *bd) |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 536 | { |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 537 | int ret = 0; |
| 538 | struct sh_eth_dev *eth = dev->priv; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 539 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 540 | ret = sh_eth_reset(eth); |
| 541 | if (ret) |
| 542 | goto err; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 543 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 544 | ret = sh_eth_desc_init(eth); |
| 545 | if (ret) |
| 546 | goto err; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 547 | |
Nobuhiro Iwamatsu | 65a81a4 | 2017-12-01 08:08:47 +0900 | [diff] [blame] | 548 | ret = sh_eth_config(eth); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 549 | if (ret) |
| 550 | goto err_config; |
| 551 | |
| 552 | sh_eth_start(eth); |
| 553 | |
| 554 | return ret; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 555 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 556 | err_config: |
| 557 | sh_eth_tx_desc_free(eth); |
| 558 | sh_eth_rx_desc_free(eth); |
| 559 | |
| 560 | err: |
| 561 | return ret; |
| 562 | } |
| 563 | |
| 564 | void sh_eth_halt(struct eth_device *dev) |
| 565 | { |
| 566 | struct sh_eth_dev *eth = dev->priv; |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 567 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 568 | sh_eth_stop(eth); |
| 569 | } |
| 570 | |
| 571 | int sh_eth_initialize(bd_t *bd) |
| 572 | { |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 573 | int ret = 0; |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 574 | struct sh_eth_dev *eth = NULL; |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 575 | struct eth_device *dev = NULL; |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 576 | struct mii_dev *mdiodev; |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 577 | |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 578 | eth = (struct sh_eth_dev *)malloc(sizeof(struct sh_eth_dev)); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 579 | if (!eth) { |
| 580 | printf(SHETHER_NAME ": %s: malloc failed\n", __func__); |
| 581 | ret = -ENOMEM; |
| 582 | goto err; |
| 583 | } |
| 584 | |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 585 | dev = (struct eth_device *)malloc(sizeof(struct eth_device)); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 586 | if (!dev) { |
| 587 | printf(SHETHER_NAME ": %s: malloc failed\n", __func__); |
| 588 | ret = -ENOMEM; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 589 | goto err; |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 590 | } |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 591 | memset(dev, 0, sizeof(struct eth_device)); |
| 592 | memset(eth, 0, sizeof(struct sh_eth_dev)); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 593 | |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 594 | eth->port = CONFIG_SH_ETHER_USE_PORT; |
| 595 | eth->port_info[eth->port].phy_addr = CONFIG_SH_ETHER_PHY_ADDR; |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 596 | eth->port_info[eth->port].iobase = |
| 597 | (void __iomem *)(BASE_IO_ADDR + 0x800 * eth->port); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 598 | |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 599 | dev->priv = (void *)eth; |
| 600 | dev->iobase = 0; |
| 601 | dev->init = sh_eth_init; |
| 602 | dev->halt = sh_eth_halt; |
Marek Vasut | 044eb2d | 2018-01-21 14:27:51 +0100 | [diff] [blame] | 603 | dev->send = sh_eth_send_legacy; |
| 604 | dev->recv = sh_eth_recv_legacy; |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 605 | eth->port_info[eth->port].dev = dev; |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 606 | |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 607 | strcpy(dev->name, SHETHER_NAME); |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 608 | |
Nobuhiro Iwamatsu | 31e84df | 2014-01-23 07:52:19 +0900 | [diff] [blame] | 609 | /* Register Device to EtherNet subsystem */ |
| 610 | eth_register(dev); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 611 | |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 612 | bb_miiphy_buses[0].priv = eth; |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 613 | mdiodev = mdio_alloc(); |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 614 | if (!mdiodev) |
| 615 | return -ENOMEM; |
| 616 | strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN); |
| 617 | mdiodev->read = bb_miiphy_read; |
| 618 | mdiodev->write = bb_miiphy_write; |
| 619 | |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 620 | ret = mdio_register(mdiodev); |
| 621 | if (ret < 0) |
| 622 | return ret; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 623 | |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 624 | if (!eth_env_get_enetaddr("ethaddr", dev->enetaddr)) |
Mike Frysinger | a86bf13 | 2009-02-11 19:14:09 -0500 | [diff] [blame] | 625 | puts("Please set MAC address\n"); |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 626 | |
| 627 | return ret; |
| 628 | |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 629 | err: |
Nobuhiro Iwamatsu | d8f5d50 | 2008-11-21 12:04:18 +0900 | [diff] [blame] | 630 | if (dev) |
| 631 | free(dev); |
| 632 | |
| 633 | if (eth) |
| 634 | free(eth); |
| 635 | |
| 636 | printf(SHETHER_NAME ": Failed\n"); |
| 637 | return ret; |
Nobuhiro Iwamatsu | 240b723 | 2008-06-11 21:05:00 +0900 | [diff] [blame] | 638 | } |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 639 | |
| 640 | /******* for bb_miiphy *******/ |
| 641 | static int sh_eth_bb_init(struct bb_miiphy_bus *bus) |
| 642 | { |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus) |
| 647 | { |
| 648 | struct sh_eth_dev *eth = bus->priv; |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 649 | struct sh_eth_info *port_info = ð->port_info[eth->port]; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 650 | |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 651 | sh_eth_write(port_info, sh_eth_read(port_info, PIR) | PIR_MMD, PIR); |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 652 | |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | static int sh_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) |
| 657 | { |
| 658 | struct sh_eth_dev *eth = bus->priv; |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 659 | struct sh_eth_info *port_info = ð->port_info[eth->port]; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 660 | |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 661 | sh_eth_write(port_info, sh_eth_read(port_info, PIR) & ~PIR_MMD, PIR); |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 662 | |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | static int sh_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) |
| 667 | { |
| 668 | struct sh_eth_dev *eth = bus->priv; |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 669 | struct sh_eth_info *port_info = ð->port_info[eth->port]; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 670 | |
| 671 | if (v) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 672 | sh_eth_write(port_info, |
| 673 | sh_eth_read(port_info, PIR) | PIR_MDO, PIR); |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 674 | else |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 675 | sh_eth_write(port_info, |
| 676 | sh_eth_read(port_info, PIR) & ~PIR_MDO, PIR); |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | static int sh_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) |
| 682 | { |
| 683 | struct sh_eth_dev *eth = bus->priv; |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 684 | struct sh_eth_info *port_info = ð->port_info[eth->port]; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 685 | |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 686 | *v = (sh_eth_read(port_info, PIR) & PIR_MDI) >> 3; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | static int sh_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) |
| 692 | { |
| 693 | struct sh_eth_dev *eth = bus->priv; |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 694 | struct sh_eth_info *port_info = ð->port_info[eth->port]; |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 695 | |
| 696 | if (v) |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 697 | sh_eth_write(port_info, |
| 698 | sh_eth_read(port_info, PIR) | PIR_MDC, PIR); |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 699 | else |
Nobuhiro Iwamatsu | ec921f1 | 2017-12-01 08:10:32 +0900 | [diff] [blame] | 700 | sh_eth_write(port_info, |
| 701 | sh_eth_read(port_info, PIR) & ~PIR_MDC, PIR); |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static int sh_eth_bb_delay(struct bb_miiphy_bus *bus) |
| 707 | { |
| 708 | udelay(10); |
| 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | struct bb_miiphy_bus bb_miiphy_buses[] = { |
| 714 | { |
| 715 | .name = "sh_eth", |
| 716 | .init = sh_eth_bb_init, |
| 717 | .mdio_active = sh_eth_bb_mdio_active, |
| 718 | .mdio_tristate = sh_eth_bb_mdio_tristate, |
| 719 | .set_mdio = sh_eth_bb_set_mdio, |
| 720 | .get_mdio = sh_eth_bb_get_mdio, |
| 721 | .set_mdc = sh_eth_bb_set_mdc, |
| 722 | .delay = sh_eth_bb_delay, |
| 723 | } |
| 724 | }; |
Nobuhiro Iwamatsu | ca36b0e | 2017-12-01 08:08:00 +0900 | [diff] [blame] | 725 | |
Yoshihiro Shimoda | 677f6cd | 2011-10-11 18:10:14 +0900 | [diff] [blame] | 726 | int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); |