19751ee09SNobuhiro Iwamatsu /* 29751ee09SNobuhiro Iwamatsu * sh_eth.c - Driver for Renesas SH7763's ethernet controler. 39751ee09SNobuhiro Iwamatsu * 4*3bb4cc31SNobuhiro Iwamatsu * Copyright (C) 2008, 2011 Renesas Solutions Corp. 5*3bb4cc31SNobuhiro Iwamatsu * Copyright (c) 2008, 2011 Nobuhiro Iwamatsu 69751ee09SNobuhiro Iwamatsu * Copyright (c) 2007 Carlos Munoz <carlos@kenati.com> 79751ee09SNobuhiro Iwamatsu * 89751ee09SNobuhiro Iwamatsu * This program is free software; you can redistribute it and/or modify 99751ee09SNobuhiro Iwamatsu * it under the terms of the GNU General Public License as published by 109751ee09SNobuhiro Iwamatsu * the Free Software Foundation; either version 2 of the License, or 119751ee09SNobuhiro Iwamatsu * (at your option) any later version. 129751ee09SNobuhiro Iwamatsu * 139751ee09SNobuhiro Iwamatsu * This program is distributed in the hope that it will be useful, 149751ee09SNobuhiro Iwamatsu * but WITHOUT ANY WARRANTY; without even the implied warranty of 159751ee09SNobuhiro Iwamatsu * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 169751ee09SNobuhiro Iwamatsu * GNU General Public License for more details. 179751ee09SNobuhiro Iwamatsu * 189751ee09SNobuhiro Iwamatsu * You should have received a copy of the GNU General Public License 199751ee09SNobuhiro Iwamatsu * along with this program; if not, write to the Free Software 209751ee09SNobuhiro Iwamatsu * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 219751ee09SNobuhiro Iwamatsu */ 229751ee09SNobuhiro Iwamatsu 239751ee09SNobuhiro Iwamatsu #include <config.h> 249751ee09SNobuhiro Iwamatsu #include <common.h> 259751ee09SNobuhiro Iwamatsu #include <malloc.h> 269751ee09SNobuhiro Iwamatsu #include <net.h> 27bd3980ccSNobuhiro Iwamatsu #include <netdev.h> 28bd1024b0SYoshihiro Shimoda #include <miiphy.h> 299751ee09SNobuhiro Iwamatsu #include <asm/errno.h> 309751ee09SNobuhiro Iwamatsu #include <asm/io.h> 319751ee09SNobuhiro Iwamatsu 329751ee09SNobuhiro Iwamatsu #include "sh_eth.h" 339751ee09SNobuhiro Iwamatsu 349751ee09SNobuhiro Iwamatsu #ifndef CONFIG_SH_ETHER_USE_PORT 359751ee09SNobuhiro Iwamatsu # error "Please define CONFIG_SH_ETHER_USE_PORT" 369751ee09SNobuhiro Iwamatsu #endif 379751ee09SNobuhiro Iwamatsu #ifndef CONFIG_SH_ETHER_PHY_ADDR 389751ee09SNobuhiro Iwamatsu # error "Please define CONFIG_SH_ETHER_PHY_ADDR" 399751ee09SNobuhiro Iwamatsu #endif 4068260aabSYoshihiro Shimoda #ifdef CONFIG_SH_ETHER_CACHE_WRITEBACK 4168260aabSYoshihiro Shimoda #define flush_cache_wback(addr, len) \ 4268260aabSYoshihiro Shimoda dcache_wback_range((u32)addr, (u32)(addr + len - 1)) 4368260aabSYoshihiro Shimoda #else 4468260aabSYoshihiro Shimoda #define flush_cache_wback(...) 4568260aabSYoshihiro Shimoda #endif 469751ee09SNobuhiro Iwamatsu 47bd3980ccSNobuhiro Iwamatsu #define SH_ETH_PHY_DELAY 50000 489751ee09SNobuhiro Iwamatsu 49bd3980ccSNobuhiro Iwamatsu int sh_eth_send(struct eth_device *dev, volatile void *packet, int len) 509751ee09SNobuhiro Iwamatsu { 51bd3980ccSNobuhiro Iwamatsu struct sh_eth_dev *eth = dev->priv; 52bd3980ccSNobuhiro Iwamatsu int port = eth->port, ret = 0, timeout; 53bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 549751ee09SNobuhiro Iwamatsu 559751ee09SNobuhiro Iwamatsu if (!packet || len > 0xffff) { 56bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": %s: Invalid argument\n", __func__); 57bd3980ccSNobuhiro Iwamatsu ret = -EINVAL; 58bd3980ccSNobuhiro Iwamatsu goto err; 599751ee09SNobuhiro Iwamatsu } 609751ee09SNobuhiro Iwamatsu 619751ee09SNobuhiro Iwamatsu /* packet must be a 4 byte boundary */ 629751ee09SNobuhiro Iwamatsu if ((int)packet & (4 - 1)) { 63bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": %s: packet not 4 byte alligned\n", __func__); 64bd3980ccSNobuhiro Iwamatsu ret = -EFAULT; 65bd3980ccSNobuhiro Iwamatsu goto err; 669751ee09SNobuhiro Iwamatsu } 679751ee09SNobuhiro Iwamatsu 689751ee09SNobuhiro Iwamatsu /* Update tx descriptor */ 6968260aabSYoshihiro Shimoda flush_cache_wback(packet, len); 709751ee09SNobuhiro Iwamatsu port_info->tx_desc_cur->td2 = ADDR_TO_PHY(packet); 719751ee09SNobuhiro Iwamatsu port_info->tx_desc_cur->td1 = len << 16; 729751ee09SNobuhiro Iwamatsu /* Must preserve the end of descriptor list indication */ 739751ee09SNobuhiro Iwamatsu if (port_info->tx_desc_cur->td0 & TD_TDLE) 749751ee09SNobuhiro Iwamatsu port_info->tx_desc_cur->td0 = TD_TACT | TD_TFP | TD_TDLE; 759751ee09SNobuhiro Iwamatsu else 769751ee09SNobuhiro Iwamatsu port_info->tx_desc_cur->td0 = TD_TACT | TD_TFP; 779751ee09SNobuhiro Iwamatsu 789751ee09SNobuhiro Iwamatsu /* Restart the transmitter if disabled */ 799751ee09SNobuhiro Iwamatsu if (!(inl(EDTRR(port)) & EDTRR_TRNS)) 809751ee09SNobuhiro Iwamatsu outl(EDTRR_TRNS, EDTRR(port)); 819751ee09SNobuhiro Iwamatsu 829751ee09SNobuhiro Iwamatsu /* Wait until packet is transmitted */ 839751ee09SNobuhiro Iwamatsu timeout = 1000; 849751ee09SNobuhiro Iwamatsu while (port_info->tx_desc_cur->td0 & TD_TACT && timeout--) 859751ee09SNobuhiro Iwamatsu udelay(100); 869751ee09SNobuhiro Iwamatsu 879751ee09SNobuhiro Iwamatsu if (timeout < 0) { 88bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": transmit timeout\n"); 89bd3980ccSNobuhiro Iwamatsu ret = -ETIMEDOUT; 909751ee09SNobuhiro Iwamatsu goto err; 919751ee09SNobuhiro Iwamatsu } 929751ee09SNobuhiro Iwamatsu 939751ee09SNobuhiro Iwamatsu port_info->tx_desc_cur++; 949751ee09SNobuhiro Iwamatsu if (port_info->tx_desc_cur >= port_info->tx_desc_base + NUM_TX_DESC) 959751ee09SNobuhiro Iwamatsu port_info->tx_desc_cur = port_info->tx_desc_base; 969751ee09SNobuhiro Iwamatsu 97bd3980ccSNobuhiro Iwamatsu return ret; 98bd3980ccSNobuhiro Iwamatsu err: 99bd3980ccSNobuhiro Iwamatsu return ret; 1009751ee09SNobuhiro Iwamatsu } 1019751ee09SNobuhiro Iwamatsu 102bd3980ccSNobuhiro Iwamatsu int sh_eth_recv(struct eth_device *dev) 1039751ee09SNobuhiro Iwamatsu { 104bd3980ccSNobuhiro Iwamatsu struct sh_eth_dev *eth = dev->priv; 105bd3980ccSNobuhiro Iwamatsu int port = eth->port, len = 0; 106bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 1079751ee09SNobuhiro Iwamatsu volatile u8 *packet; 1089751ee09SNobuhiro Iwamatsu 1099751ee09SNobuhiro Iwamatsu /* Check if the rx descriptor is ready */ 1109751ee09SNobuhiro Iwamatsu if (!(port_info->rx_desc_cur->rd0 & RD_RACT)) { 1119751ee09SNobuhiro Iwamatsu /* Check for errors */ 1129751ee09SNobuhiro Iwamatsu if (!(port_info->rx_desc_cur->rd0 & RD_RFE)) { 1139751ee09SNobuhiro Iwamatsu len = port_info->rx_desc_cur->rd1 & 0xffff; 1149751ee09SNobuhiro Iwamatsu packet = (volatile u8 *) 1159751ee09SNobuhiro Iwamatsu ADDR_TO_P2(port_info->rx_desc_cur->rd2); 1169751ee09SNobuhiro Iwamatsu NetReceive(packet, len); 1179751ee09SNobuhiro Iwamatsu } 1189751ee09SNobuhiro Iwamatsu 1199751ee09SNobuhiro Iwamatsu /* Make current descriptor available again */ 1209751ee09SNobuhiro Iwamatsu if (port_info->rx_desc_cur->rd0 & RD_RDLE) 1219751ee09SNobuhiro Iwamatsu port_info->rx_desc_cur->rd0 = RD_RACT | RD_RDLE; 1229751ee09SNobuhiro Iwamatsu else 1239751ee09SNobuhiro Iwamatsu port_info->rx_desc_cur->rd0 = RD_RACT; 1249751ee09SNobuhiro Iwamatsu 1259751ee09SNobuhiro Iwamatsu /* Point to the next descriptor */ 1269751ee09SNobuhiro Iwamatsu port_info->rx_desc_cur++; 1279751ee09SNobuhiro Iwamatsu if (port_info->rx_desc_cur >= 1289751ee09SNobuhiro Iwamatsu port_info->rx_desc_base + NUM_RX_DESC) 1299751ee09SNobuhiro Iwamatsu port_info->rx_desc_cur = port_info->rx_desc_base; 1309751ee09SNobuhiro Iwamatsu } 1319751ee09SNobuhiro Iwamatsu 1329751ee09SNobuhiro Iwamatsu /* Restart the receiver if disabled */ 1339751ee09SNobuhiro Iwamatsu if (!(inl(EDRRR(port)) & EDRRR_R)) 1349751ee09SNobuhiro Iwamatsu outl(EDRRR_R, EDRRR(port)); 1359751ee09SNobuhiro Iwamatsu 1369751ee09SNobuhiro Iwamatsu return len; 1379751ee09SNobuhiro Iwamatsu } 1389751ee09SNobuhiro Iwamatsu 1399751ee09SNobuhiro Iwamatsu #define EDMR_INIT_CNT 1000 140bd3980ccSNobuhiro Iwamatsu static int sh_eth_reset(struct sh_eth_dev *eth) 1419751ee09SNobuhiro Iwamatsu { 142bd3980ccSNobuhiro Iwamatsu int port = eth->port; 143903de461SYoshihiro Shimoda #if defined(CONFIG_CPU_SH7763) 144bd3980ccSNobuhiro Iwamatsu int ret = 0, i; 1459751ee09SNobuhiro Iwamatsu 1469751ee09SNobuhiro Iwamatsu /* Start e-dmac transmitter and receiver */ 1479751ee09SNobuhiro Iwamatsu outl(EDSR_ENALL, EDSR(port)); 1489751ee09SNobuhiro Iwamatsu 1499751ee09SNobuhiro Iwamatsu /* Perform a software reset and wait for it to complete */ 1509751ee09SNobuhiro Iwamatsu outl(EDMR_SRST, EDMR(port)); 1519751ee09SNobuhiro Iwamatsu for (i = 0; i < EDMR_INIT_CNT; i++) { 1529751ee09SNobuhiro Iwamatsu if (!(inl(EDMR(port)) & EDMR_SRST)) 1539751ee09SNobuhiro Iwamatsu break; 1549751ee09SNobuhiro Iwamatsu udelay(1000); 1559751ee09SNobuhiro Iwamatsu } 1569751ee09SNobuhiro Iwamatsu 1579751ee09SNobuhiro Iwamatsu if (i == EDMR_INIT_CNT) { 158bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": Software reset timeout\n"); 159bd3980ccSNobuhiro Iwamatsu ret = -EIO; 1609751ee09SNobuhiro Iwamatsu } 1619751ee09SNobuhiro Iwamatsu 162bd3980ccSNobuhiro Iwamatsu return ret; 163903de461SYoshihiro Shimoda #else 164903de461SYoshihiro Shimoda outl(inl(EDMR(port)) | EDMR_SRST, EDMR(port)); 165903de461SYoshihiro Shimoda udelay(3000); 166903de461SYoshihiro Shimoda outl(inl(EDMR(port)) & ~EDMR_SRST, EDMR(port)); 167903de461SYoshihiro Shimoda 168903de461SYoshihiro Shimoda return 0; 169903de461SYoshihiro Shimoda #endif 170bd3980ccSNobuhiro Iwamatsu } 171bd3980ccSNobuhiro Iwamatsu 172bd3980ccSNobuhiro Iwamatsu static int sh_eth_tx_desc_init(struct sh_eth_dev *eth) 1739751ee09SNobuhiro Iwamatsu { 174bd3980ccSNobuhiro Iwamatsu int port = eth->port, i, ret = 0; 1759751ee09SNobuhiro Iwamatsu u32 tmp_addr; 176bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 1779751ee09SNobuhiro Iwamatsu struct tx_desc_s *cur_tx_desc; 1789751ee09SNobuhiro Iwamatsu 179bd3980ccSNobuhiro Iwamatsu /* 180bd3980ccSNobuhiro Iwamatsu * Allocate tx descriptors. They must be TX_DESC_SIZE bytes aligned 181bd3980ccSNobuhiro Iwamatsu */ 182bd3980ccSNobuhiro Iwamatsu port_info->tx_desc_malloc = malloc(NUM_TX_DESC * 1839751ee09SNobuhiro Iwamatsu sizeof(struct tx_desc_s) + 184bd3980ccSNobuhiro Iwamatsu TX_DESC_SIZE - 1); 185bd3980ccSNobuhiro Iwamatsu if (!port_info->tx_desc_malloc) { 186bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": malloc failed\n"); 187bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 188bd3980ccSNobuhiro Iwamatsu goto err; 1899751ee09SNobuhiro Iwamatsu } 190bd3980ccSNobuhiro Iwamatsu 1919751ee09SNobuhiro Iwamatsu tmp_addr = (u32) (((int)port_info->tx_desc_malloc + TX_DESC_SIZE - 1) & 1929751ee09SNobuhiro Iwamatsu ~(TX_DESC_SIZE - 1)); 19368260aabSYoshihiro Shimoda flush_cache_wback(tmp_addr, NUM_TX_DESC * sizeof(struct tx_desc_s)); 1949751ee09SNobuhiro Iwamatsu /* Make sure we use a P2 address (non-cacheable) */ 1959751ee09SNobuhiro Iwamatsu port_info->tx_desc_base = (struct tx_desc_s *)ADDR_TO_P2(tmp_addr); 1969751ee09SNobuhiro Iwamatsu port_info->tx_desc_cur = port_info->tx_desc_base; 1979751ee09SNobuhiro Iwamatsu 1989751ee09SNobuhiro Iwamatsu /* Initialize all descriptors */ 1999751ee09SNobuhiro Iwamatsu for (cur_tx_desc = port_info->tx_desc_base, i = 0; i < NUM_TX_DESC; 2009751ee09SNobuhiro Iwamatsu cur_tx_desc++, i++) { 2019751ee09SNobuhiro Iwamatsu cur_tx_desc->td0 = 0x00; 2029751ee09SNobuhiro Iwamatsu cur_tx_desc->td1 = 0x00; 2039751ee09SNobuhiro Iwamatsu cur_tx_desc->td2 = 0x00; 2049751ee09SNobuhiro Iwamatsu } 2059751ee09SNobuhiro Iwamatsu 2069751ee09SNobuhiro Iwamatsu /* Mark the end of the descriptors */ 2079751ee09SNobuhiro Iwamatsu cur_tx_desc--; 2089751ee09SNobuhiro Iwamatsu cur_tx_desc->td0 |= TD_TDLE; 2099751ee09SNobuhiro Iwamatsu 2109751ee09SNobuhiro Iwamatsu /* Point the controller to the tx descriptor list. Must use physical 2119751ee09SNobuhiro Iwamatsu addresses */ 2129751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(port_info->tx_desc_base), TDLAR(port)); 213903de461SYoshihiro Shimoda #if defined(CONFIG_CPU_SH7763) 2149751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(port_info->tx_desc_base), TDFAR(port)); 2159751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(cur_tx_desc), TDFXR(port)); 2169751ee09SNobuhiro Iwamatsu outl(0x01, TDFFR(port));/* Last discriptor bit */ 217903de461SYoshihiro Shimoda #endif 2189751ee09SNobuhiro Iwamatsu 219bd3980ccSNobuhiro Iwamatsu err: 220bd3980ccSNobuhiro Iwamatsu return ret; 2219751ee09SNobuhiro Iwamatsu } 2229751ee09SNobuhiro Iwamatsu 223bd3980ccSNobuhiro Iwamatsu static int sh_eth_rx_desc_init(struct sh_eth_dev *eth) 2249751ee09SNobuhiro Iwamatsu { 225bd3980ccSNobuhiro Iwamatsu int port = eth->port, i , ret = 0; 226bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 2279751ee09SNobuhiro Iwamatsu struct rx_desc_s *cur_rx_desc; 228bd3980ccSNobuhiro Iwamatsu u32 tmp_addr; 2299751ee09SNobuhiro Iwamatsu u8 *rx_buf; 2309751ee09SNobuhiro Iwamatsu 231bd3980ccSNobuhiro Iwamatsu /* 232bd3980ccSNobuhiro Iwamatsu * Allocate rx descriptors. They must be RX_DESC_SIZE bytes aligned 233bd3980ccSNobuhiro Iwamatsu */ 234bd3980ccSNobuhiro Iwamatsu port_info->rx_desc_malloc = malloc(NUM_RX_DESC * 2359751ee09SNobuhiro Iwamatsu sizeof(struct rx_desc_s) + 236bd3980ccSNobuhiro Iwamatsu RX_DESC_SIZE - 1); 237bd3980ccSNobuhiro Iwamatsu if (!port_info->rx_desc_malloc) { 238bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": malloc failed\n"); 239bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 240bd3980ccSNobuhiro Iwamatsu goto err; 2419751ee09SNobuhiro Iwamatsu } 242bd3980ccSNobuhiro Iwamatsu 2439751ee09SNobuhiro Iwamatsu tmp_addr = (u32) (((int)port_info->rx_desc_malloc + RX_DESC_SIZE - 1) & 2449751ee09SNobuhiro Iwamatsu ~(RX_DESC_SIZE - 1)); 24568260aabSYoshihiro Shimoda flush_cache_wback(tmp_addr, NUM_RX_DESC * sizeof(struct rx_desc_s)); 2469751ee09SNobuhiro Iwamatsu /* Make sure we use a P2 address (non-cacheable) */ 2479751ee09SNobuhiro Iwamatsu port_info->rx_desc_base = (struct rx_desc_s *)ADDR_TO_P2(tmp_addr); 2489751ee09SNobuhiro Iwamatsu 2499751ee09SNobuhiro Iwamatsu port_info->rx_desc_cur = port_info->rx_desc_base; 2509751ee09SNobuhiro Iwamatsu 251bd3980ccSNobuhiro Iwamatsu /* 252bd3980ccSNobuhiro Iwamatsu * Allocate rx data buffers. They must be 32 bytes aligned and in 253bd3980ccSNobuhiro Iwamatsu * P2 area 254bd3980ccSNobuhiro Iwamatsu */ 255bd3980ccSNobuhiro Iwamatsu port_info->rx_buf_malloc = malloc(NUM_RX_DESC * MAX_BUF_SIZE + 31); 256bd3980ccSNobuhiro Iwamatsu if (!port_info->rx_buf_malloc) { 257bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": malloc failed\n"); 258bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 259bd3980ccSNobuhiro Iwamatsu goto err_buf_malloc; 2609751ee09SNobuhiro Iwamatsu } 261bd3980ccSNobuhiro Iwamatsu 2629751ee09SNobuhiro Iwamatsu tmp_addr = (u32)(((int)port_info->rx_buf_malloc + (32 - 1)) & 2639751ee09SNobuhiro Iwamatsu ~(32 - 1)); 2649751ee09SNobuhiro Iwamatsu port_info->rx_buf_base = (u8 *)ADDR_TO_P2(tmp_addr); 2659751ee09SNobuhiro Iwamatsu 2669751ee09SNobuhiro Iwamatsu /* Initialize all descriptors */ 2679751ee09SNobuhiro Iwamatsu for (cur_rx_desc = port_info->rx_desc_base, 2689751ee09SNobuhiro Iwamatsu rx_buf = port_info->rx_buf_base, i = 0; 2699751ee09SNobuhiro Iwamatsu i < NUM_RX_DESC; cur_rx_desc++, rx_buf += MAX_BUF_SIZE, i++) { 2709751ee09SNobuhiro Iwamatsu cur_rx_desc->rd0 = RD_RACT; 2719751ee09SNobuhiro Iwamatsu cur_rx_desc->rd1 = MAX_BUF_SIZE << 16; 2729751ee09SNobuhiro Iwamatsu cur_rx_desc->rd2 = (u32) ADDR_TO_PHY(rx_buf); 2739751ee09SNobuhiro Iwamatsu } 2749751ee09SNobuhiro Iwamatsu 2759751ee09SNobuhiro Iwamatsu /* Mark the end of the descriptors */ 2769751ee09SNobuhiro Iwamatsu cur_rx_desc--; 2779751ee09SNobuhiro Iwamatsu cur_rx_desc->rd0 |= RD_RDLE; 2789751ee09SNobuhiro Iwamatsu 2799751ee09SNobuhiro Iwamatsu /* Point the controller to the rx descriptor list */ 2809751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(port_info->rx_desc_base), RDLAR(port)); 281903de461SYoshihiro Shimoda #if defined(CONFIG_CPU_SH7763) 2829751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(port_info->rx_desc_base), RDFAR(port)); 2839751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(cur_rx_desc), RDFXR(port)); 2849751ee09SNobuhiro Iwamatsu outl(RDFFR_RDLF, RDFFR(port)); 285903de461SYoshihiro Shimoda #endif 2869751ee09SNobuhiro Iwamatsu 287bd3980ccSNobuhiro Iwamatsu return ret; 288bd3980ccSNobuhiro Iwamatsu 289bd3980ccSNobuhiro Iwamatsu err_buf_malloc: 290bd3980ccSNobuhiro Iwamatsu free(port_info->rx_desc_malloc); 291bd3980ccSNobuhiro Iwamatsu port_info->rx_desc_malloc = NULL; 292bd3980ccSNobuhiro Iwamatsu 293bd3980ccSNobuhiro Iwamatsu err: 294bd3980ccSNobuhiro Iwamatsu return ret; 2959751ee09SNobuhiro Iwamatsu } 2969751ee09SNobuhiro Iwamatsu 297bd3980ccSNobuhiro Iwamatsu static void sh_eth_tx_desc_free(struct sh_eth_dev *eth) 2989751ee09SNobuhiro Iwamatsu { 299bd3980ccSNobuhiro Iwamatsu int port = eth->port; 300bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 3019751ee09SNobuhiro Iwamatsu 3029751ee09SNobuhiro Iwamatsu if (port_info->tx_desc_malloc) { 3039751ee09SNobuhiro Iwamatsu free(port_info->tx_desc_malloc); 3049751ee09SNobuhiro Iwamatsu port_info->tx_desc_malloc = NULL; 3059751ee09SNobuhiro Iwamatsu } 306bd3980ccSNobuhiro Iwamatsu } 307bd3980ccSNobuhiro Iwamatsu 308bd3980ccSNobuhiro Iwamatsu static void sh_eth_rx_desc_free(struct sh_eth_dev *eth) 309bd3980ccSNobuhiro Iwamatsu { 310bd3980ccSNobuhiro Iwamatsu int port = eth->port; 311bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 3129751ee09SNobuhiro Iwamatsu 3139751ee09SNobuhiro Iwamatsu if (port_info->rx_desc_malloc) { 3149751ee09SNobuhiro Iwamatsu free(port_info->rx_desc_malloc); 3159751ee09SNobuhiro Iwamatsu port_info->rx_desc_malloc = NULL; 3169751ee09SNobuhiro Iwamatsu } 3179751ee09SNobuhiro Iwamatsu 3189751ee09SNobuhiro Iwamatsu if (port_info->rx_buf_malloc) { 3199751ee09SNobuhiro Iwamatsu free(port_info->rx_buf_malloc); 3209751ee09SNobuhiro Iwamatsu port_info->rx_buf_malloc = NULL; 3219751ee09SNobuhiro Iwamatsu } 3229751ee09SNobuhiro Iwamatsu } 3239751ee09SNobuhiro Iwamatsu 324bd3980ccSNobuhiro Iwamatsu static int sh_eth_desc_init(struct sh_eth_dev *eth) 3259751ee09SNobuhiro Iwamatsu { 326bd3980ccSNobuhiro Iwamatsu int ret = 0; 3279751ee09SNobuhiro Iwamatsu 328bd3980ccSNobuhiro Iwamatsu ret = sh_eth_tx_desc_init(eth); 329bd3980ccSNobuhiro Iwamatsu if (ret) 330bd3980ccSNobuhiro Iwamatsu goto err_tx_init; 331bd3980ccSNobuhiro Iwamatsu 332bd3980ccSNobuhiro Iwamatsu ret = sh_eth_rx_desc_init(eth); 333bd3980ccSNobuhiro Iwamatsu if (ret) 334bd3980ccSNobuhiro Iwamatsu goto err_rx_init; 335bd3980ccSNobuhiro Iwamatsu 336bd3980ccSNobuhiro Iwamatsu return ret; 337bd3980ccSNobuhiro Iwamatsu err_rx_init: 338bd3980ccSNobuhiro Iwamatsu sh_eth_tx_desc_free(eth); 339bd3980ccSNobuhiro Iwamatsu 340bd3980ccSNobuhiro Iwamatsu err_tx_init: 341bd3980ccSNobuhiro Iwamatsu return ret; 3429751ee09SNobuhiro Iwamatsu } 3439751ee09SNobuhiro Iwamatsu 344bd3980ccSNobuhiro Iwamatsu static int sh_eth_phy_config(struct sh_eth_dev *eth) 3459751ee09SNobuhiro Iwamatsu { 346bd1024b0SYoshihiro Shimoda int port = eth->port, ret = 0; 347bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 348bd1024b0SYoshihiro Shimoda struct eth_device *dev = port_info->dev; 349bd1024b0SYoshihiro Shimoda struct phy_device *phydev; 350bd3980ccSNobuhiro Iwamatsu 351bd1024b0SYoshihiro Shimoda phydev = phy_connect(miiphy_get_dev_by_name(dev->name), 352bd1024b0SYoshihiro Shimoda port_info->phy_addr, dev, PHY_INTERFACE_MODE_MII); 353bd1024b0SYoshihiro Shimoda port_info->phydev = phydev; 354bd1024b0SYoshihiro Shimoda phy_config(phydev); 355bd3980ccSNobuhiro Iwamatsu 356bd3980ccSNobuhiro Iwamatsu return ret; 3579751ee09SNobuhiro Iwamatsu } 3589751ee09SNobuhiro Iwamatsu 359bd3980ccSNobuhiro Iwamatsu static int sh_eth_config(struct sh_eth_dev *eth, bd_t *bd) 3609751ee09SNobuhiro Iwamatsu { 361bd3980ccSNobuhiro Iwamatsu int port = eth->port, ret = 0; 362bd1024b0SYoshihiro Shimoda u32 val; 363bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 364c527ce92SMike Frysinger struct eth_device *dev = port_info->dev; 365bd1024b0SYoshihiro Shimoda struct phy_device *phy; 3669751ee09SNobuhiro Iwamatsu 3679751ee09SNobuhiro Iwamatsu /* Configure e-dmac registers */ 3689751ee09SNobuhiro Iwamatsu outl((inl(EDMR(port)) & ~EMDR_DESC_R) | EDMR_EL, EDMR(port)); 3699751ee09SNobuhiro Iwamatsu outl(0, EESIPR(port)); 3709751ee09SNobuhiro Iwamatsu outl(0, TRSCER(port)); 3719751ee09SNobuhiro Iwamatsu outl(0, TFTR(port)); 3729751ee09SNobuhiro Iwamatsu outl((FIFO_SIZE_T | FIFO_SIZE_R), FDR(port)); 3739751ee09SNobuhiro Iwamatsu outl(RMCR_RST, RMCR(port)); 374*3bb4cc31SNobuhiro Iwamatsu #if !defined(CONFIG_CPU_SH7757) && !defined(CONFIG_CPU_SH7724) 3759751ee09SNobuhiro Iwamatsu outl(0, RPADIR(port)); 376903de461SYoshihiro Shimoda #endif 3779751ee09SNobuhiro Iwamatsu outl((FIFO_F_D_RFF | FIFO_F_D_RFD), FCFTR(port)); 3789751ee09SNobuhiro Iwamatsu 3799751ee09SNobuhiro Iwamatsu /* Configure e-mac registers */ 380903de461SYoshihiro Shimoda #if defined(CONFIG_CPU_SH7757) 381903de461SYoshihiro Shimoda outl(ECSIPR_BRCRXIP | ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | 382903de461SYoshihiro Shimoda ECSIPR_MPDIP | ECSIPR_ICDIP, ECSIPR(port)); 383903de461SYoshihiro Shimoda #else 3849751ee09SNobuhiro Iwamatsu outl(0, ECSIPR(port)); 385903de461SYoshihiro Shimoda #endif 3869751ee09SNobuhiro Iwamatsu 3879751ee09SNobuhiro Iwamatsu /* Set Mac address */ 388c527ce92SMike Frysinger val = dev->enetaddr[0] << 24 | dev->enetaddr[1] << 16 | 389c527ce92SMike Frysinger dev->enetaddr[2] << 8 | dev->enetaddr[3]; 3909751ee09SNobuhiro Iwamatsu outl(val, MAHR(port)); 3919751ee09SNobuhiro Iwamatsu 392c527ce92SMike Frysinger val = dev->enetaddr[4] << 8 | dev->enetaddr[5]; 3939751ee09SNobuhiro Iwamatsu outl(val, MALR(port)); 3949751ee09SNobuhiro Iwamatsu 3959751ee09SNobuhiro Iwamatsu outl(RFLR_RFL_MIN, RFLR(port)); 396*3bb4cc31SNobuhiro Iwamatsu #if !defined(CONFIG_CPU_SH7757) && !defined(CONFIG_CPU_SH7724) 3979751ee09SNobuhiro Iwamatsu outl(0, PIPR(port)); 398903de461SYoshihiro Shimoda #endif 399*3bb4cc31SNobuhiro Iwamatsu #if !defined(CONFIG_CPU_SH7724) 4009751ee09SNobuhiro Iwamatsu outl(APR_AP, APR(port)); 4019751ee09SNobuhiro Iwamatsu outl(MPR_MP, MPR(port)); 402903de461SYoshihiro Shimoda #endif 403*3bb4cc31SNobuhiro Iwamatsu #if defined(CONFIG_CPU_SH7763) 404*3bb4cc31SNobuhiro Iwamatsu outl(TPAUSER_TPAUSE, TPAUSER(port)); 405*3bb4cc31SNobuhiro Iwamatsu #elif defined(CONFIG_CPU_SH7757) 406*3bb4cc31SNobuhiro Iwamatsu outl(TPAUSER_UNLIMITED, TPAUSER(port)); 407*3bb4cc31SNobuhiro Iwamatsu #endif 408*3bb4cc31SNobuhiro Iwamatsu 4099751ee09SNobuhiro Iwamatsu /* Configure phy */ 410bd3980ccSNobuhiro Iwamatsu ret = sh_eth_phy_config(eth); 411bd3980ccSNobuhiro Iwamatsu if (ret) { 41288a4c2e7SNobuhiro Iwamatsu printf(SHETHER_NAME ": phy config timeout\n"); 413bd3980ccSNobuhiro Iwamatsu goto err_phy_cfg; 414bd3980ccSNobuhiro Iwamatsu } 415bd1024b0SYoshihiro Shimoda phy = port_info->phydev; 416bd1024b0SYoshihiro Shimoda phy_startup(phy); 4179751ee09SNobuhiro Iwamatsu 418*3bb4cc31SNobuhiro Iwamatsu val = 0; 419*3bb4cc31SNobuhiro Iwamatsu 4209751ee09SNobuhiro Iwamatsu /* Set the transfer speed */ 421bd1024b0SYoshihiro Shimoda if (phy->speed == 100) { 422bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": 100Base/"); 423*3bb4cc31SNobuhiro Iwamatsu #ifdef CONFIG_CPU_SH7763 4249751ee09SNobuhiro Iwamatsu outl(GECMR_100B, GECMR(port)); 425*3bb4cc31SNobuhiro Iwamatsu #elif defined(CONFIG_CPU_SH7757) 426*3bb4cc31SNobuhiro Iwamatsu outl(1, RTRATE(port)); 427*3bb4cc31SNobuhiro Iwamatsu #elif defined(CONFIG_CPU_SH7724) 428*3bb4cc31SNobuhiro Iwamatsu val = ECMR_RTM; 429*3bb4cc31SNobuhiro Iwamatsu #endif 430bd1024b0SYoshihiro Shimoda } else if (phy->speed == 10) { 431bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": 10Base/"); 432*3bb4cc31SNobuhiro Iwamatsu #ifdef CONFIG_CPU_SH7763 4339751ee09SNobuhiro Iwamatsu outl(GECMR_10B, GECMR(port)); 434*3bb4cc31SNobuhiro Iwamatsu #elif defined(CONFIG_CPU_SH7757) 435903de461SYoshihiro Shimoda outl(0, RTRATE(port)); 436903de461SYoshihiro Shimoda #endif 437*3bb4cc31SNobuhiro Iwamatsu } 4389751ee09SNobuhiro Iwamatsu 4399751ee09SNobuhiro Iwamatsu /* Check if full duplex mode is supported by the phy */ 440bd1024b0SYoshihiro Shimoda if (phy->duplex) { 4419751ee09SNobuhiro Iwamatsu printf("Full\n"); 442*3bb4cc31SNobuhiro Iwamatsu outl(val | (ECMR_CHG_DM|ECMR_RE|ECMR_TE|ECMR_DM), ECMR(port)); 4439751ee09SNobuhiro Iwamatsu } else { 4449751ee09SNobuhiro Iwamatsu printf("Half\n"); 445*3bb4cc31SNobuhiro Iwamatsu outl(val | (ECMR_CHG_DM|ECMR_RE|ECMR_TE), ECMR(port)); 4469751ee09SNobuhiro Iwamatsu } 447bd3980ccSNobuhiro Iwamatsu 448bd3980ccSNobuhiro Iwamatsu return ret; 449bd3980ccSNobuhiro Iwamatsu 450bd3980ccSNobuhiro Iwamatsu err_phy_cfg: 451bd3980ccSNobuhiro Iwamatsu return ret; 4529751ee09SNobuhiro Iwamatsu } 4539751ee09SNobuhiro Iwamatsu 454bd3980ccSNobuhiro Iwamatsu static void sh_eth_start(struct sh_eth_dev *eth) 4559751ee09SNobuhiro Iwamatsu { 4569751ee09SNobuhiro Iwamatsu /* 4579751ee09SNobuhiro Iwamatsu * Enable the e-dmac receiver only. The transmitter will be enabled when 4589751ee09SNobuhiro Iwamatsu * we have something to transmit 4599751ee09SNobuhiro Iwamatsu */ 460bd3980ccSNobuhiro Iwamatsu outl(EDRRR_R, EDRRR(eth->port)); 461bd3980ccSNobuhiro Iwamatsu } 4629751ee09SNobuhiro Iwamatsu 463bd3980ccSNobuhiro Iwamatsu static void sh_eth_stop(struct sh_eth_dev *eth) 464bd3980ccSNobuhiro Iwamatsu { 465bd3980ccSNobuhiro Iwamatsu outl(~EDRRR_R, EDRRR(eth->port)); 4669751ee09SNobuhiro Iwamatsu } 4679751ee09SNobuhiro Iwamatsu 468bd3980ccSNobuhiro Iwamatsu int sh_eth_init(struct eth_device *dev, bd_t *bd) 4699751ee09SNobuhiro Iwamatsu { 470bd3980ccSNobuhiro Iwamatsu int ret = 0; 471bd3980ccSNobuhiro Iwamatsu struct sh_eth_dev *eth = dev->priv; 472bd3980ccSNobuhiro Iwamatsu 473bd3980ccSNobuhiro Iwamatsu ret = sh_eth_reset(eth); 474bd3980ccSNobuhiro Iwamatsu if (ret) 475bd3980ccSNobuhiro Iwamatsu goto err; 476bd3980ccSNobuhiro Iwamatsu 477bd3980ccSNobuhiro Iwamatsu ret = sh_eth_desc_init(eth); 478bd3980ccSNobuhiro Iwamatsu if (ret) 479bd3980ccSNobuhiro Iwamatsu goto err; 480bd3980ccSNobuhiro Iwamatsu 481bd3980ccSNobuhiro Iwamatsu ret = sh_eth_config(eth, bd); 482bd3980ccSNobuhiro Iwamatsu if (ret) 483bd3980ccSNobuhiro Iwamatsu goto err_config; 484bd3980ccSNobuhiro Iwamatsu 485bd3980ccSNobuhiro Iwamatsu sh_eth_start(eth); 486bd3980ccSNobuhiro Iwamatsu 487bd3980ccSNobuhiro Iwamatsu return ret; 488bd3980ccSNobuhiro Iwamatsu 489bd3980ccSNobuhiro Iwamatsu err_config: 490bd3980ccSNobuhiro Iwamatsu sh_eth_tx_desc_free(eth); 491bd3980ccSNobuhiro Iwamatsu sh_eth_rx_desc_free(eth); 492bd3980ccSNobuhiro Iwamatsu 493bd3980ccSNobuhiro Iwamatsu err: 494bd3980ccSNobuhiro Iwamatsu return ret; 4959751ee09SNobuhiro Iwamatsu } 4969751ee09SNobuhiro Iwamatsu 497bd3980ccSNobuhiro Iwamatsu void sh_eth_halt(struct eth_device *dev) 498bd3980ccSNobuhiro Iwamatsu { 499bd3980ccSNobuhiro Iwamatsu struct sh_eth_dev *eth = dev->priv; 500bd3980ccSNobuhiro Iwamatsu sh_eth_stop(eth); 501bd3980ccSNobuhiro Iwamatsu } 502bd3980ccSNobuhiro Iwamatsu 503bd3980ccSNobuhiro Iwamatsu int sh_eth_initialize(bd_t *bd) 504bd3980ccSNobuhiro Iwamatsu { 505bd3980ccSNobuhiro Iwamatsu int ret = 0; 506bd3980ccSNobuhiro Iwamatsu struct sh_eth_dev *eth = NULL; 507bd3980ccSNobuhiro Iwamatsu struct eth_device *dev = NULL; 508bd3980ccSNobuhiro Iwamatsu 509bd3980ccSNobuhiro Iwamatsu eth = (struct sh_eth_dev *)malloc(sizeof(struct sh_eth_dev)); 510bd3980ccSNobuhiro Iwamatsu if (!eth) { 511bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": %s: malloc failed\n", __func__); 512bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 513bd3980ccSNobuhiro Iwamatsu goto err; 514bd3980ccSNobuhiro Iwamatsu } 515bd3980ccSNobuhiro Iwamatsu 516bd3980ccSNobuhiro Iwamatsu dev = (struct eth_device *)malloc(sizeof(struct eth_device)); 517bd3980ccSNobuhiro Iwamatsu if (!dev) { 518bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": %s: malloc failed\n", __func__); 519bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 520bd3980ccSNobuhiro Iwamatsu goto err; 521bd3980ccSNobuhiro Iwamatsu } 522bd3980ccSNobuhiro Iwamatsu memset(dev, 0, sizeof(struct eth_device)); 523bd3980ccSNobuhiro Iwamatsu memset(eth, 0, sizeof(struct sh_eth_dev)); 524bd3980ccSNobuhiro Iwamatsu 525bd3980ccSNobuhiro Iwamatsu eth->port = CONFIG_SH_ETHER_USE_PORT; 526bd3980ccSNobuhiro Iwamatsu eth->port_info[eth->port].phy_addr = CONFIG_SH_ETHER_PHY_ADDR; 527bd3980ccSNobuhiro Iwamatsu 528bd3980ccSNobuhiro Iwamatsu dev->priv = (void *)eth; 529bd3980ccSNobuhiro Iwamatsu dev->iobase = 0; 530bd3980ccSNobuhiro Iwamatsu dev->init = sh_eth_init; 531bd3980ccSNobuhiro Iwamatsu dev->halt = sh_eth_halt; 532bd3980ccSNobuhiro Iwamatsu dev->send = sh_eth_send; 533bd3980ccSNobuhiro Iwamatsu dev->recv = sh_eth_recv; 534bd3980ccSNobuhiro Iwamatsu eth->port_info[eth->port].dev = dev; 535bd3980ccSNobuhiro Iwamatsu 536bd3980ccSNobuhiro Iwamatsu sprintf(dev->name, SHETHER_NAME); 537bd3980ccSNobuhiro Iwamatsu 538bd3980ccSNobuhiro Iwamatsu /* Register Device to EtherNet subsystem */ 539bd3980ccSNobuhiro Iwamatsu eth_register(dev); 5409751ee09SNobuhiro Iwamatsu 541bd1024b0SYoshihiro Shimoda bb_miiphy_buses[0].priv = eth; 542bd1024b0SYoshihiro Shimoda miiphy_register(dev->name, bb_miiphy_read, bb_miiphy_write); 543bd1024b0SYoshihiro Shimoda 544c527ce92SMike Frysinger if (!eth_getenv_enetaddr("ethaddr", dev->enetaddr)) 545c527ce92SMike Frysinger puts("Please set MAC address\n"); 5469751ee09SNobuhiro Iwamatsu 547bd3980ccSNobuhiro Iwamatsu return ret; 5489751ee09SNobuhiro Iwamatsu 5499751ee09SNobuhiro Iwamatsu err: 550bd3980ccSNobuhiro Iwamatsu if (dev) 5519751ee09SNobuhiro Iwamatsu free(dev); 552bd3980ccSNobuhiro Iwamatsu 553bd3980ccSNobuhiro Iwamatsu if (eth) 554bd3980ccSNobuhiro Iwamatsu free(eth); 555bd3980ccSNobuhiro Iwamatsu 556bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": Failed\n"); 557bd3980ccSNobuhiro Iwamatsu return ret; 5589751ee09SNobuhiro Iwamatsu } 559bd1024b0SYoshihiro Shimoda 560bd1024b0SYoshihiro Shimoda /******* for bb_miiphy *******/ 561bd1024b0SYoshihiro Shimoda static int sh_eth_bb_init(struct bb_miiphy_bus *bus) 562bd1024b0SYoshihiro Shimoda { 563bd1024b0SYoshihiro Shimoda return 0; 564bd1024b0SYoshihiro Shimoda } 565bd1024b0SYoshihiro Shimoda 566bd1024b0SYoshihiro Shimoda static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus) 567bd1024b0SYoshihiro Shimoda { 568bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 569bd1024b0SYoshihiro Shimoda int port = eth->port; 570bd1024b0SYoshihiro Shimoda 571bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) | PIR_MMD, PIR(port)); 572bd1024b0SYoshihiro Shimoda 573bd1024b0SYoshihiro Shimoda return 0; 574bd1024b0SYoshihiro Shimoda } 575bd1024b0SYoshihiro Shimoda 576bd1024b0SYoshihiro Shimoda static int sh_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) 577bd1024b0SYoshihiro Shimoda { 578bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 579bd1024b0SYoshihiro Shimoda int port = eth->port; 580bd1024b0SYoshihiro Shimoda 581bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) & ~PIR_MMD, PIR(port)); 582bd1024b0SYoshihiro Shimoda 583bd1024b0SYoshihiro Shimoda return 0; 584bd1024b0SYoshihiro Shimoda } 585bd1024b0SYoshihiro Shimoda 586bd1024b0SYoshihiro Shimoda static int sh_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) 587bd1024b0SYoshihiro Shimoda { 588bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 589bd1024b0SYoshihiro Shimoda int port = eth->port; 590bd1024b0SYoshihiro Shimoda 591bd1024b0SYoshihiro Shimoda if (v) 592bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) | PIR_MDO, PIR(port)); 593bd1024b0SYoshihiro Shimoda else 594bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) & ~PIR_MDO, PIR(port)); 595bd1024b0SYoshihiro Shimoda 596bd1024b0SYoshihiro Shimoda return 0; 597bd1024b0SYoshihiro Shimoda } 598bd1024b0SYoshihiro Shimoda 599bd1024b0SYoshihiro Shimoda static int sh_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) 600bd1024b0SYoshihiro Shimoda { 601bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 602bd1024b0SYoshihiro Shimoda int port = eth->port; 603bd1024b0SYoshihiro Shimoda 604bd1024b0SYoshihiro Shimoda *v = (inl(PIR(port)) & PIR_MDI) >> 3; 605bd1024b0SYoshihiro Shimoda 606bd1024b0SYoshihiro Shimoda return 0; 607bd1024b0SYoshihiro Shimoda } 608bd1024b0SYoshihiro Shimoda 609bd1024b0SYoshihiro Shimoda static int sh_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) 610bd1024b0SYoshihiro Shimoda { 611bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 612bd1024b0SYoshihiro Shimoda int port = eth->port; 613bd1024b0SYoshihiro Shimoda 614bd1024b0SYoshihiro Shimoda if (v) 615bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) | PIR_MDC, PIR(port)); 616bd1024b0SYoshihiro Shimoda else 617bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) & ~PIR_MDC, PIR(port)); 618bd1024b0SYoshihiro Shimoda 619bd1024b0SYoshihiro Shimoda return 0; 620bd1024b0SYoshihiro Shimoda } 621bd1024b0SYoshihiro Shimoda 622bd1024b0SYoshihiro Shimoda static int sh_eth_bb_delay(struct bb_miiphy_bus *bus) 623bd1024b0SYoshihiro Shimoda { 624bd1024b0SYoshihiro Shimoda udelay(10); 625bd1024b0SYoshihiro Shimoda 626bd1024b0SYoshihiro Shimoda return 0; 627bd1024b0SYoshihiro Shimoda } 628bd1024b0SYoshihiro Shimoda 629bd1024b0SYoshihiro Shimoda struct bb_miiphy_bus bb_miiphy_buses[] = { 630bd1024b0SYoshihiro Shimoda { 631bd1024b0SYoshihiro Shimoda .name = "sh_eth", 632bd1024b0SYoshihiro Shimoda .init = sh_eth_bb_init, 633bd1024b0SYoshihiro Shimoda .mdio_active = sh_eth_bb_mdio_active, 634bd1024b0SYoshihiro Shimoda .mdio_tristate = sh_eth_bb_mdio_tristate, 635bd1024b0SYoshihiro Shimoda .set_mdio = sh_eth_bb_set_mdio, 636bd1024b0SYoshihiro Shimoda .get_mdio = sh_eth_bb_get_mdio, 637bd1024b0SYoshihiro Shimoda .set_mdc = sh_eth_bb_set_mdc, 638bd1024b0SYoshihiro Shimoda .delay = sh_eth_bb_delay, 639bd1024b0SYoshihiro Shimoda } 640bd1024b0SYoshihiro Shimoda }; 641bd1024b0SYoshihiro Shimoda int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); 642