Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Faraday FTMAC100 Ethernet |
| 3 | * |
| 4 | * (C) Copyright 2009 Faraday Technology |
| 5 | * Po-Yu Chuang <ratbert@faraday-tech.com> |
| 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <config.h> |
| 11 | #include <common.h> |
| 12 | #include <malloc.h> |
| 13 | #include <net.h> |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 14 | #include <linux/io.h> |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 15 | |
| 16 | #include "ftmac100.h" |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 17 | #ifdef CONFIG_DM_ETH |
| 18 | #include <dm.h> |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | #endif |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 21 | #define ETH_ZLEN 60 |
| 22 | |
| 23 | struct ftmac100_data { |
Po-Yu Chuang | 767ba6f | 2011-01-21 15:50:37 +0800 | [diff] [blame] | 24 | struct ftmac100_txdes txdes[1]; |
| 25 | struct ftmac100_rxdes rxdes[PKTBUFSRX]; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 26 | int rx_index; |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 27 | const char *name; |
| 28 | phys_addr_t iobase; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * Reset MAC |
| 33 | */ |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 34 | static void ftmac100_reset(struct ftmac100_data *priv) |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 35 | { |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 36 | struct ftmac100 *ftmac100 = (struct ftmac100 *)priv->iobase; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 37 | |
| 38 | debug ("%s()\n", __func__); |
| 39 | |
| 40 | writel (FTMAC100_MACCR_SW_RST, &ftmac100->maccr); |
| 41 | |
| 42 | while (readl (&ftmac100->maccr) & FTMAC100_MACCR_SW_RST) |
| 43 | ; |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * Set MAC address |
| 48 | */ |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 49 | static void ftmac100_set_mac(struct ftmac100_data *priv , |
| 50 | const unsigned char *mac) |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 51 | { |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 52 | struct ftmac100 *ftmac100 = (struct ftmac100 *)priv->iobase; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 53 | unsigned int maddr = mac[0] << 8 | mac[1]; |
| 54 | unsigned int laddr = mac[2] << 24 | mac[3] << 16 | mac[4] << 8 | mac[5]; |
| 55 | |
| 56 | debug ("%s(%x %x)\n", __func__, maddr, laddr); |
| 57 | |
| 58 | writel (maddr, &ftmac100->mac_madr); |
| 59 | writel (laddr, &ftmac100->mac_ladr); |
| 60 | } |
| 61 | |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 62 | /* |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 63 | * Disable MAC |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 64 | */ |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 65 | static void _ftmac100_halt(struct ftmac100_data *priv) |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 66 | { |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 67 | struct ftmac100 *ftmac100 = (struct ftmac100 *)priv->iobase; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 68 | debug ("%s()\n", __func__); |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 69 | writel (0, &ftmac100->maccr); |
| 70 | } |
| 71 | |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 72 | /* |
| 73 | * Initialize MAC |
| 74 | */ |
| 75 | static int _ftmac100_init(struct ftmac100_data *priv, unsigned char enetaddr[6]) |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 76 | { |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 77 | struct ftmac100 *ftmac100 = (struct ftmac100 *)priv->iobase; |
Po-Yu Chuang | 767ba6f | 2011-01-21 15:50:37 +0800 | [diff] [blame] | 78 | struct ftmac100_txdes *txdes = priv->txdes; |
| 79 | struct ftmac100_rxdes *rxdes = priv->rxdes; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 80 | unsigned int maccr; |
| 81 | int i; |
| 82 | |
| 83 | debug ("%s()\n", __func__); |
| 84 | |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 85 | ftmac100_reset(priv); |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 86 | |
| 87 | /* set the ethernet address */ |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 88 | ftmac100_set_mac(priv, enetaddr); |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 89 | |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 90 | |
| 91 | /* disable all interrupts */ |
| 92 | |
| 93 | writel (0, &ftmac100->imr); |
| 94 | |
| 95 | /* initialize descriptors */ |
| 96 | |
| 97 | priv->rx_index = 0; |
| 98 | |
| 99 | txdes[0].txdes1 = FTMAC100_TXDES1_EDOTR; |
| 100 | rxdes[PKTBUFSRX - 1].rxdes1 = FTMAC100_RXDES1_EDORR; |
| 101 | |
| 102 | for (i = 0; i < PKTBUFSRX; i++) { |
| 103 | /* RXBUF_BADR */ |
Joe Hershberger | 9f09a36 | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 104 | rxdes[i].rxdes2 = (unsigned int)net_rx_packets[i]; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 105 | rxdes[i].rxdes1 |= FTMAC100_RXDES1_RXBUF_SIZE (PKTSIZE_ALIGN); |
| 106 | rxdes[i].rxdes0 = FTMAC100_RXDES0_RXDMA_OWN; |
| 107 | } |
| 108 | |
| 109 | /* transmit ring */ |
| 110 | |
| 111 | writel ((unsigned int)txdes, &ftmac100->txr_badr); |
| 112 | |
| 113 | /* receive ring */ |
| 114 | |
| 115 | writel ((unsigned int)rxdes, &ftmac100->rxr_badr); |
| 116 | |
| 117 | /* poll receive descriptor automatically */ |
| 118 | |
| 119 | writel (FTMAC100_APTC_RXPOLL_CNT (1), &ftmac100->aptc); |
| 120 | |
| 121 | /* enable transmitter, receiver */ |
| 122 | |
| 123 | maccr = FTMAC100_MACCR_XMT_EN | |
| 124 | FTMAC100_MACCR_RCV_EN | |
| 125 | FTMAC100_MACCR_XDMA_EN | |
| 126 | FTMAC100_MACCR_RDMA_EN | |
| 127 | FTMAC100_MACCR_CRC_APD | |
| 128 | FTMAC100_MACCR_ENRX_IN_HALFTX | |
| 129 | FTMAC100_MACCR_RX_RUNT | |
| 130 | FTMAC100_MACCR_RX_BROADPKT; |
| 131 | |
| 132 | writel (maccr, &ftmac100->maccr); |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | /* |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 138 | * Free receiving buffer |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 139 | */ |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 140 | static int _ftmac100_free_pkt(struct ftmac100_data *priv) |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 141 | { |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 142 | struct ftmac100_rxdes *curr_des; |
| 143 | curr_des = &priv->rxdes[priv->rx_index]; |
| 144 | /* release buffer to DMA */ |
| 145 | curr_des->rxdes0 |= FTMAC100_RXDES0_RXDMA_OWN; |
| 146 | priv->rx_index = (priv->rx_index + 1) % PKTBUFSRX; |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | /* |
| 151 | * Receive a data block via Ethernet |
| 152 | */ |
| 153 | static int __ftmac100_recv(struct ftmac100_data *priv) |
| 154 | { |
Po-Yu Chuang | 767ba6f | 2011-01-21 15:50:37 +0800 | [diff] [blame] | 155 | struct ftmac100_rxdes *curr_des; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 156 | unsigned short rxlen; |
| 157 | |
| 158 | curr_des = &priv->rxdes[priv->rx_index]; |
| 159 | |
| 160 | if (curr_des->rxdes0 & FTMAC100_RXDES0_RXDMA_OWN) |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 161 | return 0; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 162 | |
| 163 | if (curr_des->rxdes0 & (FTMAC100_RXDES0_RX_ERR | |
| 164 | FTMAC100_RXDES0_CRC_ERR | |
| 165 | FTMAC100_RXDES0_FTL | |
| 166 | FTMAC100_RXDES0_RUNT | |
| 167 | FTMAC100_RXDES0_RX_ODD_NB)) { |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 168 | return 0; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | rxlen = FTMAC100_RXDES0_RFL (curr_des->rxdes0); |
| 172 | |
| 173 | debug ("%s(): RX buffer %d, %x received\n", |
| 174 | __func__, priv->rx_index, rxlen); |
| 175 | |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 176 | return rxlen; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Send a data block via Ethernet |
| 181 | */ |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 182 | static int _ftmac100_send(struct ftmac100_data *priv, void *packet, int length) |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 183 | { |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 184 | struct ftmac100 *ftmac100 = (struct ftmac100 *)priv->iobase; |
Po-Yu Chuang | 767ba6f | 2011-01-21 15:50:37 +0800 | [diff] [blame] | 185 | struct ftmac100_txdes *curr_des = priv->txdes; |
Po-Yu Chuang | 0bed917 | 2011-01-21 15:51:25 +0800 | [diff] [blame] | 186 | ulong start; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 187 | |
| 188 | if (curr_des->txdes0 & FTMAC100_TXDES0_TXDMA_OWN) { |
| 189 | debug ("%s(): no TX descriptor available\n", __func__); |
| 190 | return -1; |
| 191 | } |
| 192 | |
| 193 | debug ("%s(%x, %x)\n", __func__, (int)packet, length); |
| 194 | |
| 195 | length = (length < ETH_ZLEN) ? ETH_ZLEN : length; |
| 196 | |
| 197 | /* initiate a transmit sequence */ |
| 198 | |
| 199 | curr_des->txdes2 = (unsigned int)packet; /* TXBUF_BADR */ |
| 200 | |
| 201 | curr_des->txdes1 &= FTMAC100_TXDES1_EDOTR; |
| 202 | curr_des->txdes1 |= FTMAC100_TXDES1_FTS | |
| 203 | FTMAC100_TXDES1_LTS | |
| 204 | FTMAC100_TXDES1_TXBUF_SIZE (length); |
| 205 | |
| 206 | curr_des->txdes0 = FTMAC100_TXDES0_TXDMA_OWN; |
| 207 | |
| 208 | /* start transmit */ |
| 209 | |
| 210 | writel (1, &ftmac100->txpd); |
| 211 | |
| 212 | /* wait for transfer to succeed */ |
| 213 | |
Po-Yu Chuang | 0bed917 | 2011-01-21 15:51:25 +0800 | [diff] [blame] | 214 | start = get_timer(0); |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 215 | while (curr_des->txdes0 & FTMAC100_TXDES0_TXDMA_OWN) { |
Po-Yu Chuang | 0bed917 | 2011-01-21 15:51:25 +0800 | [diff] [blame] | 216 | if (get_timer(start) >= 5) { |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 217 | debug ("%s(): timed out\n", __func__); |
| 218 | return -1; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | debug ("%s(): packet sent\n", __func__); |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 227 | #ifndef CONFIG_DM_ETH |
| 228 | /* |
| 229 | * disable transmitter, receiver |
| 230 | */ |
| 231 | static void ftmac100_halt(struct eth_device *dev) |
| 232 | { |
| 233 | struct ftmac100_data *priv = dev->priv; |
| 234 | return _ftmac100_halt(priv); |
| 235 | } |
| 236 | |
| 237 | static int ftmac100_init(struct eth_device *dev, bd_t *bd) |
| 238 | { |
| 239 | struct ftmac100_data *priv = dev->priv; |
| 240 | return _ftmac100_init(priv , dev->enetaddr); |
| 241 | } |
| 242 | |
| 243 | static int _ftmac100_recv(struct ftmac100_data *priv) |
| 244 | { |
| 245 | struct ftmac100_rxdes *curr_des; |
| 246 | unsigned short len; |
| 247 | curr_des = &priv->rxdes[priv->rx_index]; |
| 248 | len = __ftmac100_recv(priv); |
| 249 | if (len) { |
| 250 | /* pass the packet up to the protocol layers. */ |
| 251 | net_process_received_packet((void *)curr_des->rxdes2, len); |
| 252 | _ftmac100_free_pkt(priv); |
| 253 | } |
| 254 | return len ? 1 : 0; |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * Get a data block via Ethernet |
| 259 | */ |
| 260 | static int ftmac100_recv(struct eth_device *dev) |
| 261 | { |
| 262 | struct ftmac100_data *priv = dev->priv; |
| 263 | return _ftmac100_recv(priv); |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Send a data block via Ethernet |
| 268 | */ |
| 269 | static int ftmac100_send(struct eth_device *dev, void *packet, int length) |
| 270 | { |
| 271 | struct ftmac100_data *priv = dev->priv; |
| 272 | return _ftmac100_send(priv , packet , length); |
| 273 | } |
| 274 | |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 275 | int ftmac100_initialize (bd_t *bd) |
| 276 | { |
| 277 | struct eth_device *dev; |
| 278 | struct ftmac100_data *priv; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 279 | dev = malloc (sizeof *dev); |
| 280 | if (!dev) { |
| 281 | printf ("%s(): failed to allocate dev\n", __func__); |
| 282 | goto out; |
| 283 | } |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 284 | /* Transmit and receive descriptors should align to 16 bytes */ |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 285 | priv = memalign (16, sizeof (struct ftmac100_data)); |
| 286 | if (!priv) { |
| 287 | printf ("%s(): failed to allocate priv\n", __func__); |
| 288 | goto free_dev; |
| 289 | } |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 290 | memset (dev, 0, sizeof (*dev)); |
| 291 | memset (priv, 0, sizeof (*priv)); |
| 292 | |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 293 | strcpy(dev->name, "FTMAC100"); |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 294 | dev->iobase = CONFIG_FTMAC100_BASE; |
| 295 | dev->init = ftmac100_init; |
| 296 | dev->halt = ftmac100_halt; |
| 297 | dev->send = ftmac100_send; |
| 298 | dev->recv = ftmac100_recv; |
| 299 | dev->priv = priv; |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 300 | priv->iobase = dev->iobase; |
Po-Yu Chuang | 50253b8 | 2009-08-10 11:00:00 +0800 | [diff] [blame] | 301 | eth_register (dev); |
| 302 | |
| 303 | return 1; |
| 304 | |
| 305 | free_dev: |
| 306 | free (dev); |
| 307 | out: |
| 308 | return 0; |
| 309 | } |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 310 | #endif |
| 311 | |
| 312 | #ifdef CONFIG_DM_ETH |
| 313 | static int ftmac100_start(struct udevice *dev) |
| 314 | { |
| 315 | struct eth_pdata *plat = dev_get_platdata(dev); |
| 316 | struct ftmac100_data *priv = dev_get_priv(dev); |
| 317 | |
| 318 | return _ftmac100_init(priv, plat->enetaddr); |
| 319 | } |
| 320 | |
| 321 | static void ftmac100_stop(struct udevice *dev) |
| 322 | { |
| 323 | struct ftmac100_data *priv = dev_get_priv(dev); |
| 324 | _ftmac100_halt(priv); |
| 325 | } |
| 326 | |
| 327 | static int ftmac100_send(struct udevice *dev, void *packet, int length) |
| 328 | { |
| 329 | struct ftmac100_data *priv = dev_get_priv(dev); |
| 330 | int ret; |
| 331 | ret = _ftmac100_send(priv , packet , length); |
| 332 | return ret ? 0 : -ETIMEDOUT; |
| 333 | } |
| 334 | |
| 335 | static int ftmac100_recv(struct udevice *dev, int flags, uchar **packetp) |
| 336 | { |
| 337 | struct ftmac100_data *priv = dev_get_priv(dev); |
| 338 | struct ftmac100_rxdes *curr_des; |
| 339 | curr_des = &priv->rxdes[priv->rx_index]; |
| 340 | int len; |
| 341 | len = __ftmac100_recv(priv); |
| 342 | if (len) |
| 343 | *packetp = (void *)curr_des->rxdes2; |
| 344 | |
| 345 | return len ? len : -EAGAIN; |
| 346 | } |
| 347 | |
| 348 | static int ftmac100_free_pkt(struct udevice *dev, uchar *packet, int length) |
| 349 | { |
| 350 | struct ftmac100_data *priv = dev_get_priv(dev); |
| 351 | _ftmac100_free_pkt(priv); |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | int ftmac100_read_rom_hwaddr(struct udevice *dev) |
| 356 | { |
| 357 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 358 | eth_getenv_enetaddr("ethaddr", pdata->enetaddr); |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | static const char *dtbmacaddr(u32 ifno) |
| 363 | { |
| 364 | int node, len; |
| 365 | char enet[16]; |
| 366 | const char *mac; |
| 367 | const char *path; |
| 368 | if (gd->fdt_blob == NULL) { |
| 369 | printf("%s: don't have a valid gd->fdt_blob!\n", __func__); |
| 370 | return NULL; |
| 371 | } |
| 372 | node = fdt_path_offset(gd->fdt_blob, "/aliases"); |
| 373 | if (node < 0) |
| 374 | return NULL; |
| 375 | |
| 376 | sprintf(enet, "ethernet%d", ifno); |
| 377 | path = fdt_getprop(gd->fdt_blob, node, enet, NULL); |
| 378 | if (!path) { |
| 379 | printf("no alias for %s\n", enet); |
| 380 | return NULL; |
| 381 | } |
| 382 | node = fdt_path_offset(gd->fdt_blob, path); |
| 383 | mac = fdt_getprop(gd->fdt_blob, node, "mac-address", &len); |
| 384 | if (mac && is_valid_ethaddr((u8 *)mac)) |
| 385 | return mac; |
| 386 | |
| 387 | return NULL; |
| 388 | } |
| 389 | |
| 390 | static int ftmac100_ofdata_to_platdata(struct udevice *dev) |
| 391 | { |
| 392 | struct ftmac100_data *priv = dev_get_priv(dev); |
| 393 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 394 | const char *mac; |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame^] | 395 | pdata->iobase = devfdt_get_addr(dev); |
rick | dc24dac | 2017-05-23 13:48:27 +0800 | [diff] [blame] | 396 | priv->iobase = pdata->iobase; |
| 397 | mac = dtbmacaddr(0); |
| 398 | if (mac) |
| 399 | memcpy(pdata->enetaddr , mac , 6); |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static int ftmac100_probe(struct udevice *dev) |
| 405 | { |
| 406 | struct ftmac100_data *priv = dev_get_priv(dev); |
| 407 | priv->name = dev->name; |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | static int ftmac100_bind(struct udevice *dev) |
| 412 | { |
| 413 | return device_set_name(dev, dev->name); |
| 414 | } |
| 415 | |
| 416 | static const struct eth_ops ftmac100_ops = { |
| 417 | .start = ftmac100_start, |
| 418 | .send = ftmac100_send, |
| 419 | .recv = ftmac100_recv, |
| 420 | .stop = ftmac100_stop, |
| 421 | .free_pkt = ftmac100_free_pkt, |
| 422 | }; |
| 423 | |
| 424 | static const struct udevice_id ftmac100_ids[] = { |
| 425 | { .compatible = "andestech,atmac100" }, |
| 426 | { } |
| 427 | }; |
| 428 | |
| 429 | U_BOOT_DRIVER(ftmac100) = { |
| 430 | .name = "nds32_mac", |
| 431 | .id = UCLASS_ETH, |
| 432 | .of_match = ftmac100_ids, |
| 433 | .bind = ftmac100_bind, |
| 434 | .ofdata_to_platdata = ftmac100_ofdata_to_platdata, |
| 435 | .probe = ftmac100_probe, |
| 436 | .ops = &ftmac100_ops, |
| 437 | .priv_auto_alloc_size = sizeof(struct ftmac100_data), |
| 438 | .platdata_auto_alloc_size = sizeof(struct eth_pdata), |
| 439 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 440 | }; |
| 441 | #endif |