19751ee09SNobuhiro Iwamatsu /* 29751ee09SNobuhiro Iwamatsu * sh_eth.c - Driver for Renesas SH7763's ethernet controler. 39751ee09SNobuhiro Iwamatsu * 43bb4cc31SNobuhiro Iwamatsu * Copyright (C) 2008, 2011 Renesas Solutions Corp. 53bb4cc31SNobuhiro 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 47*4ba62c72SNobuhiro Iwamatsu #define TIMEOUT_CNT 1000 48*4ba62c72SNobuhiro 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 */ 83*4ba62c72SNobuhiro Iwamatsu timeout = TIMEOUT_CNT; 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 139bd3980ccSNobuhiro Iwamatsu static int sh_eth_reset(struct sh_eth_dev *eth) 1409751ee09SNobuhiro Iwamatsu { 141bd3980ccSNobuhiro Iwamatsu int port = eth->port; 142903de461SYoshihiro Shimoda #if defined(CONFIG_CPU_SH7763) 143bd3980ccSNobuhiro Iwamatsu int ret = 0, i; 1449751ee09SNobuhiro Iwamatsu 1459751ee09SNobuhiro Iwamatsu /* Start e-dmac transmitter and receiver */ 1469751ee09SNobuhiro Iwamatsu outl(EDSR_ENALL, EDSR(port)); 1479751ee09SNobuhiro Iwamatsu 1489751ee09SNobuhiro Iwamatsu /* Perform a software reset and wait for it to complete */ 1499751ee09SNobuhiro Iwamatsu outl(EDMR_SRST, EDMR(port)); 150*4ba62c72SNobuhiro Iwamatsu for (i = 0; i < TIMEOUT_CNT ; i++) { 1519751ee09SNobuhiro Iwamatsu if (!(inl(EDMR(port)) & EDMR_SRST)) 1529751ee09SNobuhiro Iwamatsu break; 1539751ee09SNobuhiro Iwamatsu udelay(1000); 1549751ee09SNobuhiro Iwamatsu } 1559751ee09SNobuhiro Iwamatsu 156*4ba62c72SNobuhiro Iwamatsu if (i == TIMEOUT_CNT) { 157bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": Software reset timeout\n"); 158bd3980ccSNobuhiro Iwamatsu ret = -EIO; 1599751ee09SNobuhiro Iwamatsu } 1609751ee09SNobuhiro Iwamatsu 161bd3980ccSNobuhiro Iwamatsu return ret; 162903de461SYoshihiro Shimoda #else 163903de461SYoshihiro Shimoda outl(inl(EDMR(port)) | EDMR_SRST, EDMR(port)); 164903de461SYoshihiro Shimoda udelay(3000); 165903de461SYoshihiro Shimoda outl(inl(EDMR(port)) & ~EDMR_SRST, EDMR(port)); 166903de461SYoshihiro Shimoda 167903de461SYoshihiro Shimoda return 0; 168903de461SYoshihiro Shimoda #endif 169bd3980ccSNobuhiro Iwamatsu } 170bd3980ccSNobuhiro Iwamatsu 171bd3980ccSNobuhiro Iwamatsu static int sh_eth_tx_desc_init(struct sh_eth_dev *eth) 1729751ee09SNobuhiro Iwamatsu { 173bd3980ccSNobuhiro Iwamatsu int port = eth->port, i, ret = 0; 1749751ee09SNobuhiro Iwamatsu u32 tmp_addr; 175bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 1769751ee09SNobuhiro Iwamatsu struct tx_desc_s *cur_tx_desc; 1779751ee09SNobuhiro Iwamatsu 178bd3980ccSNobuhiro Iwamatsu /* 179bd3980ccSNobuhiro Iwamatsu * Allocate tx descriptors. They must be TX_DESC_SIZE bytes aligned 180bd3980ccSNobuhiro Iwamatsu */ 181bd3980ccSNobuhiro Iwamatsu port_info->tx_desc_malloc = malloc(NUM_TX_DESC * 1829751ee09SNobuhiro Iwamatsu sizeof(struct tx_desc_s) + 183bd3980ccSNobuhiro Iwamatsu TX_DESC_SIZE - 1); 184bd3980ccSNobuhiro Iwamatsu if (!port_info->tx_desc_malloc) { 185bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": malloc failed\n"); 186bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 187bd3980ccSNobuhiro Iwamatsu goto err; 1889751ee09SNobuhiro Iwamatsu } 189bd3980ccSNobuhiro Iwamatsu 1909751ee09SNobuhiro Iwamatsu tmp_addr = (u32) (((int)port_info->tx_desc_malloc + TX_DESC_SIZE - 1) & 1919751ee09SNobuhiro Iwamatsu ~(TX_DESC_SIZE - 1)); 19268260aabSYoshihiro Shimoda flush_cache_wback(tmp_addr, NUM_TX_DESC * sizeof(struct tx_desc_s)); 1939751ee09SNobuhiro Iwamatsu /* Make sure we use a P2 address (non-cacheable) */ 1949751ee09SNobuhiro Iwamatsu port_info->tx_desc_base = (struct tx_desc_s *)ADDR_TO_P2(tmp_addr); 1959751ee09SNobuhiro Iwamatsu port_info->tx_desc_cur = port_info->tx_desc_base; 1969751ee09SNobuhiro Iwamatsu 1979751ee09SNobuhiro Iwamatsu /* Initialize all descriptors */ 1989751ee09SNobuhiro Iwamatsu for (cur_tx_desc = port_info->tx_desc_base, i = 0; i < NUM_TX_DESC; 1999751ee09SNobuhiro Iwamatsu cur_tx_desc++, i++) { 2009751ee09SNobuhiro Iwamatsu cur_tx_desc->td0 = 0x00; 2019751ee09SNobuhiro Iwamatsu cur_tx_desc->td1 = 0x00; 2029751ee09SNobuhiro Iwamatsu cur_tx_desc->td2 = 0x00; 2039751ee09SNobuhiro Iwamatsu } 2049751ee09SNobuhiro Iwamatsu 2059751ee09SNobuhiro Iwamatsu /* Mark the end of the descriptors */ 2069751ee09SNobuhiro Iwamatsu cur_tx_desc--; 2079751ee09SNobuhiro Iwamatsu cur_tx_desc->td0 |= TD_TDLE; 2089751ee09SNobuhiro Iwamatsu 2099751ee09SNobuhiro Iwamatsu /* Point the controller to the tx descriptor list. Must use physical 2109751ee09SNobuhiro Iwamatsu addresses */ 2119751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(port_info->tx_desc_base), TDLAR(port)); 212903de461SYoshihiro Shimoda #if defined(CONFIG_CPU_SH7763) 2139751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(port_info->tx_desc_base), TDFAR(port)); 2149751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(cur_tx_desc), TDFXR(port)); 2159751ee09SNobuhiro Iwamatsu outl(0x01, TDFFR(port));/* Last discriptor bit */ 216903de461SYoshihiro Shimoda #endif 2179751ee09SNobuhiro Iwamatsu 218bd3980ccSNobuhiro Iwamatsu err: 219bd3980ccSNobuhiro Iwamatsu return ret; 2209751ee09SNobuhiro Iwamatsu } 2219751ee09SNobuhiro Iwamatsu 222bd3980ccSNobuhiro Iwamatsu static int sh_eth_rx_desc_init(struct sh_eth_dev *eth) 2239751ee09SNobuhiro Iwamatsu { 224bd3980ccSNobuhiro Iwamatsu int port = eth->port, i , ret = 0; 225bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 2269751ee09SNobuhiro Iwamatsu struct rx_desc_s *cur_rx_desc; 227bd3980ccSNobuhiro Iwamatsu u32 tmp_addr; 2289751ee09SNobuhiro Iwamatsu u8 *rx_buf; 2299751ee09SNobuhiro Iwamatsu 230bd3980ccSNobuhiro Iwamatsu /* 231bd3980ccSNobuhiro Iwamatsu * Allocate rx descriptors. They must be RX_DESC_SIZE bytes aligned 232bd3980ccSNobuhiro Iwamatsu */ 233bd3980ccSNobuhiro Iwamatsu port_info->rx_desc_malloc = malloc(NUM_RX_DESC * 2349751ee09SNobuhiro Iwamatsu sizeof(struct rx_desc_s) + 235bd3980ccSNobuhiro Iwamatsu RX_DESC_SIZE - 1); 236bd3980ccSNobuhiro Iwamatsu if (!port_info->rx_desc_malloc) { 237bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": malloc failed\n"); 238bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 239bd3980ccSNobuhiro Iwamatsu goto err; 2409751ee09SNobuhiro Iwamatsu } 241bd3980ccSNobuhiro Iwamatsu 2429751ee09SNobuhiro Iwamatsu tmp_addr = (u32) (((int)port_info->rx_desc_malloc + RX_DESC_SIZE - 1) & 2439751ee09SNobuhiro Iwamatsu ~(RX_DESC_SIZE - 1)); 24468260aabSYoshihiro Shimoda flush_cache_wback(tmp_addr, NUM_RX_DESC * sizeof(struct rx_desc_s)); 2459751ee09SNobuhiro Iwamatsu /* Make sure we use a P2 address (non-cacheable) */ 2469751ee09SNobuhiro Iwamatsu port_info->rx_desc_base = (struct rx_desc_s *)ADDR_TO_P2(tmp_addr); 2479751ee09SNobuhiro Iwamatsu 2489751ee09SNobuhiro Iwamatsu port_info->rx_desc_cur = port_info->rx_desc_base; 2499751ee09SNobuhiro Iwamatsu 250bd3980ccSNobuhiro Iwamatsu /* 251bd3980ccSNobuhiro Iwamatsu * Allocate rx data buffers. They must be 32 bytes aligned and in 252bd3980ccSNobuhiro Iwamatsu * P2 area 253bd3980ccSNobuhiro Iwamatsu */ 254bd3980ccSNobuhiro Iwamatsu port_info->rx_buf_malloc = malloc(NUM_RX_DESC * MAX_BUF_SIZE + 31); 255bd3980ccSNobuhiro Iwamatsu if (!port_info->rx_buf_malloc) { 256bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": malloc failed\n"); 257bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 258bd3980ccSNobuhiro Iwamatsu goto err_buf_malloc; 2599751ee09SNobuhiro Iwamatsu } 260bd3980ccSNobuhiro Iwamatsu 2619751ee09SNobuhiro Iwamatsu tmp_addr = (u32)(((int)port_info->rx_buf_malloc + (32 - 1)) & 2629751ee09SNobuhiro Iwamatsu ~(32 - 1)); 2639751ee09SNobuhiro Iwamatsu port_info->rx_buf_base = (u8 *)ADDR_TO_P2(tmp_addr); 2649751ee09SNobuhiro Iwamatsu 2659751ee09SNobuhiro Iwamatsu /* Initialize all descriptors */ 2669751ee09SNobuhiro Iwamatsu for (cur_rx_desc = port_info->rx_desc_base, 2679751ee09SNobuhiro Iwamatsu rx_buf = port_info->rx_buf_base, i = 0; 2689751ee09SNobuhiro Iwamatsu i < NUM_RX_DESC; cur_rx_desc++, rx_buf += MAX_BUF_SIZE, i++) { 2699751ee09SNobuhiro Iwamatsu cur_rx_desc->rd0 = RD_RACT; 2709751ee09SNobuhiro Iwamatsu cur_rx_desc->rd1 = MAX_BUF_SIZE << 16; 2719751ee09SNobuhiro Iwamatsu cur_rx_desc->rd2 = (u32) ADDR_TO_PHY(rx_buf); 2729751ee09SNobuhiro Iwamatsu } 2739751ee09SNobuhiro Iwamatsu 2749751ee09SNobuhiro Iwamatsu /* Mark the end of the descriptors */ 2759751ee09SNobuhiro Iwamatsu cur_rx_desc--; 2769751ee09SNobuhiro Iwamatsu cur_rx_desc->rd0 |= RD_RDLE; 2779751ee09SNobuhiro Iwamatsu 2789751ee09SNobuhiro Iwamatsu /* Point the controller to the rx descriptor list */ 2799751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(port_info->rx_desc_base), RDLAR(port)); 280903de461SYoshihiro Shimoda #if defined(CONFIG_CPU_SH7763) 2819751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(port_info->rx_desc_base), RDFAR(port)); 2829751ee09SNobuhiro Iwamatsu outl(ADDR_TO_PHY(cur_rx_desc), RDFXR(port)); 2839751ee09SNobuhiro Iwamatsu outl(RDFFR_RDLF, RDFFR(port)); 284903de461SYoshihiro Shimoda #endif 2859751ee09SNobuhiro Iwamatsu 286bd3980ccSNobuhiro Iwamatsu return ret; 287bd3980ccSNobuhiro Iwamatsu 288bd3980ccSNobuhiro Iwamatsu err_buf_malloc: 289bd3980ccSNobuhiro Iwamatsu free(port_info->rx_desc_malloc); 290bd3980ccSNobuhiro Iwamatsu port_info->rx_desc_malloc = NULL; 291bd3980ccSNobuhiro Iwamatsu 292bd3980ccSNobuhiro Iwamatsu err: 293bd3980ccSNobuhiro Iwamatsu return ret; 2949751ee09SNobuhiro Iwamatsu } 2959751ee09SNobuhiro Iwamatsu 296bd3980ccSNobuhiro Iwamatsu static void sh_eth_tx_desc_free(struct sh_eth_dev *eth) 2979751ee09SNobuhiro Iwamatsu { 298bd3980ccSNobuhiro Iwamatsu int port = eth->port; 299bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 3009751ee09SNobuhiro Iwamatsu 3019751ee09SNobuhiro Iwamatsu if (port_info->tx_desc_malloc) { 3029751ee09SNobuhiro Iwamatsu free(port_info->tx_desc_malloc); 3039751ee09SNobuhiro Iwamatsu port_info->tx_desc_malloc = NULL; 3049751ee09SNobuhiro Iwamatsu } 305bd3980ccSNobuhiro Iwamatsu } 306bd3980ccSNobuhiro Iwamatsu 307bd3980ccSNobuhiro Iwamatsu static void sh_eth_rx_desc_free(struct sh_eth_dev *eth) 308bd3980ccSNobuhiro Iwamatsu { 309bd3980ccSNobuhiro Iwamatsu int port = eth->port; 310bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 3119751ee09SNobuhiro Iwamatsu 3129751ee09SNobuhiro Iwamatsu if (port_info->rx_desc_malloc) { 3139751ee09SNobuhiro Iwamatsu free(port_info->rx_desc_malloc); 3149751ee09SNobuhiro Iwamatsu port_info->rx_desc_malloc = NULL; 3159751ee09SNobuhiro Iwamatsu } 3169751ee09SNobuhiro Iwamatsu 3179751ee09SNobuhiro Iwamatsu if (port_info->rx_buf_malloc) { 3189751ee09SNobuhiro Iwamatsu free(port_info->rx_buf_malloc); 3199751ee09SNobuhiro Iwamatsu port_info->rx_buf_malloc = NULL; 3209751ee09SNobuhiro Iwamatsu } 3219751ee09SNobuhiro Iwamatsu } 3229751ee09SNobuhiro Iwamatsu 323bd3980ccSNobuhiro Iwamatsu static int sh_eth_desc_init(struct sh_eth_dev *eth) 3249751ee09SNobuhiro Iwamatsu { 325bd3980ccSNobuhiro Iwamatsu int ret = 0; 3269751ee09SNobuhiro Iwamatsu 327bd3980ccSNobuhiro Iwamatsu ret = sh_eth_tx_desc_init(eth); 328bd3980ccSNobuhiro Iwamatsu if (ret) 329bd3980ccSNobuhiro Iwamatsu goto err_tx_init; 330bd3980ccSNobuhiro Iwamatsu 331bd3980ccSNobuhiro Iwamatsu ret = sh_eth_rx_desc_init(eth); 332bd3980ccSNobuhiro Iwamatsu if (ret) 333bd3980ccSNobuhiro Iwamatsu goto err_rx_init; 334bd3980ccSNobuhiro Iwamatsu 335bd3980ccSNobuhiro Iwamatsu return ret; 336bd3980ccSNobuhiro Iwamatsu err_rx_init: 337bd3980ccSNobuhiro Iwamatsu sh_eth_tx_desc_free(eth); 338bd3980ccSNobuhiro Iwamatsu 339bd3980ccSNobuhiro Iwamatsu err_tx_init: 340bd3980ccSNobuhiro Iwamatsu return ret; 3419751ee09SNobuhiro Iwamatsu } 3429751ee09SNobuhiro Iwamatsu 343bd3980ccSNobuhiro Iwamatsu static int sh_eth_phy_config(struct sh_eth_dev *eth) 3449751ee09SNobuhiro Iwamatsu { 345bd1024b0SYoshihiro Shimoda int port = eth->port, ret = 0; 346bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 347bd1024b0SYoshihiro Shimoda struct eth_device *dev = port_info->dev; 348bd1024b0SYoshihiro Shimoda struct phy_device *phydev; 349bd3980ccSNobuhiro Iwamatsu 350bd1024b0SYoshihiro Shimoda phydev = phy_connect(miiphy_get_dev_by_name(dev->name), 351bd1024b0SYoshihiro Shimoda port_info->phy_addr, dev, PHY_INTERFACE_MODE_MII); 352bd1024b0SYoshihiro Shimoda port_info->phydev = phydev; 353bd1024b0SYoshihiro Shimoda phy_config(phydev); 354bd3980ccSNobuhiro Iwamatsu 355bd3980ccSNobuhiro Iwamatsu return ret; 3569751ee09SNobuhiro Iwamatsu } 3579751ee09SNobuhiro Iwamatsu 358bd3980ccSNobuhiro Iwamatsu static int sh_eth_config(struct sh_eth_dev *eth, bd_t *bd) 3599751ee09SNobuhiro Iwamatsu { 360bd3980ccSNobuhiro Iwamatsu int port = eth->port, ret = 0; 361bd1024b0SYoshihiro Shimoda u32 val; 362bd3980ccSNobuhiro Iwamatsu struct sh_eth_info *port_info = ð->port_info[port]; 363c527ce92SMike Frysinger struct eth_device *dev = port_info->dev; 364bd1024b0SYoshihiro Shimoda struct phy_device *phy; 3659751ee09SNobuhiro Iwamatsu 3669751ee09SNobuhiro Iwamatsu /* Configure e-dmac registers */ 3679751ee09SNobuhiro Iwamatsu outl((inl(EDMR(port)) & ~EMDR_DESC_R) | EDMR_EL, EDMR(port)); 3689751ee09SNobuhiro Iwamatsu outl(0, EESIPR(port)); 3699751ee09SNobuhiro Iwamatsu outl(0, TRSCER(port)); 3709751ee09SNobuhiro Iwamatsu outl(0, TFTR(port)); 3719751ee09SNobuhiro Iwamatsu outl((FIFO_SIZE_T | FIFO_SIZE_R), FDR(port)); 3729751ee09SNobuhiro Iwamatsu outl(RMCR_RST, RMCR(port)); 3733bb4cc31SNobuhiro Iwamatsu #if !defined(CONFIG_CPU_SH7757) && !defined(CONFIG_CPU_SH7724) 3749751ee09SNobuhiro Iwamatsu outl(0, RPADIR(port)); 375903de461SYoshihiro Shimoda #endif 3769751ee09SNobuhiro Iwamatsu outl((FIFO_F_D_RFF | FIFO_F_D_RFD), FCFTR(port)); 3779751ee09SNobuhiro Iwamatsu 3789751ee09SNobuhiro Iwamatsu /* Configure e-mac registers */ 379903de461SYoshihiro Shimoda #if defined(CONFIG_CPU_SH7757) 380903de461SYoshihiro Shimoda outl(ECSIPR_BRCRXIP | ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | 381903de461SYoshihiro Shimoda ECSIPR_MPDIP | ECSIPR_ICDIP, ECSIPR(port)); 382903de461SYoshihiro Shimoda #else 3839751ee09SNobuhiro Iwamatsu outl(0, ECSIPR(port)); 384903de461SYoshihiro Shimoda #endif 3859751ee09SNobuhiro Iwamatsu 3869751ee09SNobuhiro Iwamatsu /* Set Mac address */ 387c527ce92SMike Frysinger val = dev->enetaddr[0] << 24 | dev->enetaddr[1] << 16 | 388c527ce92SMike Frysinger dev->enetaddr[2] << 8 | dev->enetaddr[3]; 3899751ee09SNobuhiro Iwamatsu outl(val, MAHR(port)); 3909751ee09SNobuhiro Iwamatsu 391c527ce92SMike Frysinger val = dev->enetaddr[4] << 8 | dev->enetaddr[5]; 3929751ee09SNobuhiro Iwamatsu outl(val, MALR(port)); 3939751ee09SNobuhiro Iwamatsu 3949751ee09SNobuhiro Iwamatsu outl(RFLR_RFL_MIN, RFLR(port)); 3953bb4cc31SNobuhiro Iwamatsu #if !defined(CONFIG_CPU_SH7757) && !defined(CONFIG_CPU_SH7724) 3969751ee09SNobuhiro Iwamatsu outl(0, PIPR(port)); 397903de461SYoshihiro Shimoda #endif 3983bb4cc31SNobuhiro Iwamatsu #if !defined(CONFIG_CPU_SH7724) 3999751ee09SNobuhiro Iwamatsu outl(APR_AP, APR(port)); 4009751ee09SNobuhiro Iwamatsu outl(MPR_MP, MPR(port)); 401903de461SYoshihiro Shimoda #endif 4023bb4cc31SNobuhiro Iwamatsu #if defined(CONFIG_CPU_SH7763) 4033bb4cc31SNobuhiro Iwamatsu outl(TPAUSER_TPAUSE, TPAUSER(port)); 4043bb4cc31SNobuhiro Iwamatsu #elif defined(CONFIG_CPU_SH7757) 4053bb4cc31SNobuhiro Iwamatsu outl(TPAUSER_UNLIMITED, TPAUSER(port)); 4063bb4cc31SNobuhiro Iwamatsu #endif 4073bb4cc31SNobuhiro Iwamatsu 4089751ee09SNobuhiro Iwamatsu /* Configure phy */ 409bd3980ccSNobuhiro Iwamatsu ret = sh_eth_phy_config(eth); 410bd3980ccSNobuhiro Iwamatsu if (ret) { 41188a4c2e7SNobuhiro Iwamatsu printf(SHETHER_NAME ": phy config timeout\n"); 412bd3980ccSNobuhiro Iwamatsu goto err_phy_cfg; 413bd3980ccSNobuhiro Iwamatsu } 414bd1024b0SYoshihiro Shimoda phy = port_info->phydev; 415bd1024b0SYoshihiro Shimoda phy_startup(phy); 4169751ee09SNobuhiro Iwamatsu 4173bb4cc31SNobuhiro Iwamatsu val = 0; 4183bb4cc31SNobuhiro Iwamatsu 4199751ee09SNobuhiro Iwamatsu /* Set the transfer speed */ 420bd1024b0SYoshihiro Shimoda if (phy->speed == 100) { 421bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": 100Base/"); 4223bb4cc31SNobuhiro Iwamatsu #ifdef CONFIG_CPU_SH7763 4239751ee09SNobuhiro Iwamatsu outl(GECMR_100B, GECMR(port)); 4243bb4cc31SNobuhiro Iwamatsu #elif defined(CONFIG_CPU_SH7757) 4253bb4cc31SNobuhiro Iwamatsu outl(1, RTRATE(port)); 4263bb4cc31SNobuhiro Iwamatsu #elif defined(CONFIG_CPU_SH7724) 4273bb4cc31SNobuhiro Iwamatsu val = ECMR_RTM; 4283bb4cc31SNobuhiro Iwamatsu #endif 429bd1024b0SYoshihiro Shimoda } else if (phy->speed == 10) { 430bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": 10Base/"); 4313bb4cc31SNobuhiro Iwamatsu #ifdef CONFIG_CPU_SH7763 4329751ee09SNobuhiro Iwamatsu outl(GECMR_10B, GECMR(port)); 4333bb4cc31SNobuhiro Iwamatsu #elif defined(CONFIG_CPU_SH7757) 434903de461SYoshihiro Shimoda outl(0, RTRATE(port)); 435903de461SYoshihiro Shimoda #endif 4363bb4cc31SNobuhiro Iwamatsu } 4379751ee09SNobuhiro Iwamatsu 4389751ee09SNobuhiro Iwamatsu /* Check if full duplex mode is supported by the phy */ 439bd1024b0SYoshihiro Shimoda if (phy->duplex) { 4409751ee09SNobuhiro Iwamatsu printf("Full\n"); 4413bb4cc31SNobuhiro Iwamatsu outl(val | (ECMR_CHG_DM|ECMR_RE|ECMR_TE|ECMR_DM), ECMR(port)); 4429751ee09SNobuhiro Iwamatsu } else { 4439751ee09SNobuhiro Iwamatsu printf("Half\n"); 4443bb4cc31SNobuhiro Iwamatsu outl(val | (ECMR_CHG_DM|ECMR_RE|ECMR_TE), ECMR(port)); 4459751ee09SNobuhiro Iwamatsu } 446bd3980ccSNobuhiro Iwamatsu 447bd3980ccSNobuhiro Iwamatsu return ret; 448bd3980ccSNobuhiro Iwamatsu 449bd3980ccSNobuhiro Iwamatsu err_phy_cfg: 450bd3980ccSNobuhiro Iwamatsu return ret; 4519751ee09SNobuhiro Iwamatsu } 4529751ee09SNobuhiro Iwamatsu 453bd3980ccSNobuhiro Iwamatsu static void sh_eth_start(struct sh_eth_dev *eth) 4549751ee09SNobuhiro Iwamatsu { 4559751ee09SNobuhiro Iwamatsu /* 4569751ee09SNobuhiro Iwamatsu * Enable the e-dmac receiver only. The transmitter will be enabled when 4579751ee09SNobuhiro Iwamatsu * we have something to transmit 4589751ee09SNobuhiro Iwamatsu */ 459bd3980ccSNobuhiro Iwamatsu outl(EDRRR_R, EDRRR(eth->port)); 460bd3980ccSNobuhiro Iwamatsu } 4619751ee09SNobuhiro Iwamatsu 462bd3980ccSNobuhiro Iwamatsu static void sh_eth_stop(struct sh_eth_dev *eth) 463bd3980ccSNobuhiro Iwamatsu { 464bd3980ccSNobuhiro Iwamatsu outl(~EDRRR_R, EDRRR(eth->port)); 4659751ee09SNobuhiro Iwamatsu } 4669751ee09SNobuhiro Iwamatsu 467bd3980ccSNobuhiro Iwamatsu int sh_eth_init(struct eth_device *dev, bd_t *bd) 4689751ee09SNobuhiro Iwamatsu { 469bd3980ccSNobuhiro Iwamatsu int ret = 0; 470bd3980ccSNobuhiro Iwamatsu struct sh_eth_dev *eth = dev->priv; 471bd3980ccSNobuhiro Iwamatsu 472bd3980ccSNobuhiro Iwamatsu ret = sh_eth_reset(eth); 473bd3980ccSNobuhiro Iwamatsu if (ret) 474bd3980ccSNobuhiro Iwamatsu goto err; 475bd3980ccSNobuhiro Iwamatsu 476bd3980ccSNobuhiro Iwamatsu ret = sh_eth_desc_init(eth); 477bd3980ccSNobuhiro Iwamatsu if (ret) 478bd3980ccSNobuhiro Iwamatsu goto err; 479bd3980ccSNobuhiro Iwamatsu 480bd3980ccSNobuhiro Iwamatsu ret = sh_eth_config(eth, bd); 481bd3980ccSNobuhiro Iwamatsu if (ret) 482bd3980ccSNobuhiro Iwamatsu goto err_config; 483bd3980ccSNobuhiro Iwamatsu 484bd3980ccSNobuhiro Iwamatsu sh_eth_start(eth); 485bd3980ccSNobuhiro Iwamatsu 486bd3980ccSNobuhiro Iwamatsu return ret; 487bd3980ccSNobuhiro Iwamatsu 488bd3980ccSNobuhiro Iwamatsu err_config: 489bd3980ccSNobuhiro Iwamatsu sh_eth_tx_desc_free(eth); 490bd3980ccSNobuhiro Iwamatsu sh_eth_rx_desc_free(eth); 491bd3980ccSNobuhiro Iwamatsu 492bd3980ccSNobuhiro Iwamatsu err: 493bd3980ccSNobuhiro Iwamatsu return ret; 4949751ee09SNobuhiro Iwamatsu } 4959751ee09SNobuhiro Iwamatsu 496bd3980ccSNobuhiro Iwamatsu void sh_eth_halt(struct eth_device *dev) 497bd3980ccSNobuhiro Iwamatsu { 498bd3980ccSNobuhiro Iwamatsu struct sh_eth_dev *eth = dev->priv; 499bd3980ccSNobuhiro Iwamatsu sh_eth_stop(eth); 500bd3980ccSNobuhiro Iwamatsu } 501bd3980ccSNobuhiro Iwamatsu 502bd3980ccSNobuhiro Iwamatsu int sh_eth_initialize(bd_t *bd) 503bd3980ccSNobuhiro Iwamatsu { 504bd3980ccSNobuhiro Iwamatsu int ret = 0; 505bd3980ccSNobuhiro Iwamatsu struct sh_eth_dev *eth = NULL; 506bd3980ccSNobuhiro Iwamatsu struct eth_device *dev = NULL; 507bd3980ccSNobuhiro Iwamatsu 508bd3980ccSNobuhiro Iwamatsu eth = (struct sh_eth_dev *)malloc(sizeof(struct sh_eth_dev)); 509bd3980ccSNobuhiro Iwamatsu if (!eth) { 510bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": %s: malloc failed\n", __func__); 511bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 512bd3980ccSNobuhiro Iwamatsu goto err; 513bd3980ccSNobuhiro Iwamatsu } 514bd3980ccSNobuhiro Iwamatsu 515bd3980ccSNobuhiro Iwamatsu dev = (struct eth_device *)malloc(sizeof(struct eth_device)); 516bd3980ccSNobuhiro Iwamatsu if (!dev) { 517bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": %s: malloc failed\n", __func__); 518bd3980ccSNobuhiro Iwamatsu ret = -ENOMEM; 519bd3980ccSNobuhiro Iwamatsu goto err; 520bd3980ccSNobuhiro Iwamatsu } 521bd3980ccSNobuhiro Iwamatsu memset(dev, 0, sizeof(struct eth_device)); 522bd3980ccSNobuhiro Iwamatsu memset(eth, 0, sizeof(struct sh_eth_dev)); 523bd3980ccSNobuhiro Iwamatsu 524bd3980ccSNobuhiro Iwamatsu eth->port = CONFIG_SH_ETHER_USE_PORT; 525bd3980ccSNobuhiro Iwamatsu eth->port_info[eth->port].phy_addr = CONFIG_SH_ETHER_PHY_ADDR; 526bd3980ccSNobuhiro Iwamatsu 527bd3980ccSNobuhiro Iwamatsu dev->priv = (void *)eth; 528bd3980ccSNobuhiro Iwamatsu dev->iobase = 0; 529bd3980ccSNobuhiro Iwamatsu dev->init = sh_eth_init; 530bd3980ccSNobuhiro Iwamatsu dev->halt = sh_eth_halt; 531bd3980ccSNobuhiro Iwamatsu dev->send = sh_eth_send; 532bd3980ccSNobuhiro Iwamatsu dev->recv = sh_eth_recv; 533bd3980ccSNobuhiro Iwamatsu eth->port_info[eth->port].dev = dev; 534bd3980ccSNobuhiro Iwamatsu 535bd3980ccSNobuhiro Iwamatsu sprintf(dev->name, SHETHER_NAME); 536bd3980ccSNobuhiro Iwamatsu 537bd3980ccSNobuhiro Iwamatsu /* Register Device to EtherNet subsystem */ 538bd3980ccSNobuhiro Iwamatsu eth_register(dev); 5399751ee09SNobuhiro Iwamatsu 540bd1024b0SYoshihiro Shimoda bb_miiphy_buses[0].priv = eth; 541bd1024b0SYoshihiro Shimoda miiphy_register(dev->name, bb_miiphy_read, bb_miiphy_write); 542bd1024b0SYoshihiro Shimoda 543c527ce92SMike Frysinger if (!eth_getenv_enetaddr("ethaddr", dev->enetaddr)) 544c527ce92SMike Frysinger puts("Please set MAC address\n"); 5459751ee09SNobuhiro Iwamatsu 546bd3980ccSNobuhiro Iwamatsu return ret; 5479751ee09SNobuhiro Iwamatsu 5489751ee09SNobuhiro Iwamatsu err: 549bd3980ccSNobuhiro Iwamatsu if (dev) 5509751ee09SNobuhiro Iwamatsu free(dev); 551bd3980ccSNobuhiro Iwamatsu 552bd3980ccSNobuhiro Iwamatsu if (eth) 553bd3980ccSNobuhiro Iwamatsu free(eth); 554bd3980ccSNobuhiro Iwamatsu 555bd3980ccSNobuhiro Iwamatsu printf(SHETHER_NAME ": Failed\n"); 556bd3980ccSNobuhiro Iwamatsu return ret; 5579751ee09SNobuhiro Iwamatsu } 558bd1024b0SYoshihiro Shimoda 559bd1024b0SYoshihiro Shimoda /******* for bb_miiphy *******/ 560bd1024b0SYoshihiro Shimoda static int sh_eth_bb_init(struct bb_miiphy_bus *bus) 561bd1024b0SYoshihiro Shimoda { 562bd1024b0SYoshihiro Shimoda return 0; 563bd1024b0SYoshihiro Shimoda } 564bd1024b0SYoshihiro Shimoda 565bd1024b0SYoshihiro Shimoda static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus) 566bd1024b0SYoshihiro Shimoda { 567bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 568bd1024b0SYoshihiro Shimoda int port = eth->port; 569bd1024b0SYoshihiro Shimoda 570bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) | PIR_MMD, PIR(port)); 571bd1024b0SYoshihiro Shimoda 572bd1024b0SYoshihiro Shimoda return 0; 573bd1024b0SYoshihiro Shimoda } 574bd1024b0SYoshihiro Shimoda 575bd1024b0SYoshihiro Shimoda static int sh_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) 576bd1024b0SYoshihiro Shimoda { 577bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 578bd1024b0SYoshihiro Shimoda int port = eth->port; 579bd1024b0SYoshihiro Shimoda 580bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) & ~PIR_MMD, PIR(port)); 581bd1024b0SYoshihiro Shimoda 582bd1024b0SYoshihiro Shimoda return 0; 583bd1024b0SYoshihiro Shimoda } 584bd1024b0SYoshihiro Shimoda 585bd1024b0SYoshihiro Shimoda static int sh_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) 586bd1024b0SYoshihiro Shimoda { 587bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 588bd1024b0SYoshihiro Shimoda int port = eth->port; 589bd1024b0SYoshihiro Shimoda 590bd1024b0SYoshihiro Shimoda if (v) 591bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) | PIR_MDO, PIR(port)); 592bd1024b0SYoshihiro Shimoda else 593bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) & ~PIR_MDO, PIR(port)); 594bd1024b0SYoshihiro Shimoda 595bd1024b0SYoshihiro Shimoda return 0; 596bd1024b0SYoshihiro Shimoda } 597bd1024b0SYoshihiro Shimoda 598bd1024b0SYoshihiro Shimoda static int sh_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) 599bd1024b0SYoshihiro Shimoda { 600bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 601bd1024b0SYoshihiro Shimoda int port = eth->port; 602bd1024b0SYoshihiro Shimoda 603bd1024b0SYoshihiro Shimoda *v = (inl(PIR(port)) & PIR_MDI) >> 3; 604bd1024b0SYoshihiro Shimoda 605bd1024b0SYoshihiro Shimoda return 0; 606bd1024b0SYoshihiro Shimoda } 607bd1024b0SYoshihiro Shimoda 608bd1024b0SYoshihiro Shimoda static int sh_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) 609bd1024b0SYoshihiro Shimoda { 610bd1024b0SYoshihiro Shimoda struct sh_eth_dev *eth = bus->priv; 611bd1024b0SYoshihiro Shimoda int port = eth->port; 612bd1024b0SYoshihiro Shimoda 613bd1024b0SYoshihiro Shimoda if (v) 614bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) | PIR_MDC, PIR(port)); 615bd1024b0SYoshihiro Shimoda else 616bd1024b0SYoshihiro Shimoda outl(inl(PIR(port)) & ~PIR_MDC, PIR(port)); 617bd1024b0SYoshihiro Shimoda 618bd1024b0SYoshihiro Shimoda return 0; 619bd1024b0SYoshihiro Shimoda } 620bd1024b0SYoshihiro Shimoda 621bd1024b0SYoshihiro Shimoda static int sh_eth_bb_delay(struct bb_miiphy_bus *bus) 622bd1024b0SYoshihiro Shimoda { 623bd1024b0SYoshihiro Shimoda udelay(10); 624bd1024b0SYoshihiro Shimoda 625bd1024b0SYoshihiro Shimoda return 0; 626bd1024b0SYoshihiro Shimoda } 627bd1024b0SYoshihiro Shimoda 628bd1024b0SYoshihiro Shimoda struct bb_miiphy_bus bb_miiphy_buses[] = { 629bd1024b0SYoshihiro Shimoda { 630bd1024b0SYoshihiro Shimoda .name = "sh_eth", 631bd1024b0SYoshihiro Shimoda .init = sh_eth_bb_init, 632bd1024b0SYoshihiro Shimoda .mdio_active = sh_eth_bb_mdio_active, 633bd1024b0SYoshihiro Shimoda .mdio_tristate = sh_eth_bb_mdio_tristate, 634bd1024b0SYoshihiro Shimoda .set_mdio = sh_eth_bb_set_mdio, 635bd1024b0SYoshihiro Shimoda .get_mdio = sh_eth_bb_get_mdio, 636bd1024b0SYoshihiro Shimoda .set_mdc = sh_eth_bb_set_mdc, 637bd1024b0SYoshihiro Shimoda .delay = sh_eth_bb_delay, 638bd1024b0SYoshihiro Shimoda } 639bd1024b0SYoshihiro Shimoda }; 640bd1024b0SYoshihiro Shimoda int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); 641