1296177Sjhibbits/* Copyright (c) 2008-2011 Freescale Semiconductor, Inc. 2296177Sjhibbits * All rights reserved. 3296177Sjhibbits * 4296177Sjhibbits * Redistribution and use in source and binary forms, with or without 5296177Sjhibbits * modification, are permitted provided that the following conditions are met: 6296177Sjhibbits * * Redistributions of source code must retain the above copyright 7296177Sjhibbits * notice, this list of conditions and the following disclaimer. 8296177Sjhibbits * * Redistributions in binary form must reproduce the above copyright 9296177Sjhibbits * notice, this list of conditions and the following disclaimer in the 10296177Sjhibbits * documentation and/or other materials provided with the distribution. 11296177Sjhibbits * * Neither the name of Freescale Semiconductor nor the 12296177Sjhibbits * names of its contributors may be used to endorse or promote products 13296177Sjhibbits * derived from this software without specific prior written permission. 14296177Sjhibbits * 15296177Sjhibbits * 16296177Sjhibbits * ALTERNATIVELY, this software may be distributed under the terms of the 17296177Sjhibbits * GNU General Public License ("GPL") as published by the Free Software 18296177Sjhibbits * Foundation, either version 2 of that License or (at your option) any 19296177Sjhibbits * later version. 20296177Sjhibbits * 21296177Sjhibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 22296177Sjhibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23296177Sjhibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24296177Sjhibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 25296177Sjhibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26296177Sjhibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27296177Sjhibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28296177Sjhibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29296177Sjhibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30296177Sjhibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31296177Sjhibbits */ 32296177Sjhibbits 33296177Sjhibbits/****************************************************************************** 34296177Sjhibbits @File dtsec_mii_acc.c 35296177Sjhibbits 36296177Sjhibbits @Description FM dtsec MII register access MAC ... 37296177Sjhibbits*//***************************************************************************/ 38296177Sjhibbits 39296177Sjhibbits#include "error_ext.h" 40296177Sjhibbits#include "std_ext.h" 41296177Sjhibbits#include "fm_mac.h" 42296177Sjhibbits#include "dtsec.h" 43296177Sjhibbits 44296177Sjhibbits 45296177Sjhibbits/*****************************************************************************/ 46296177Sjhibbitst_Error DTSEC_MII_WritePhyReg(t_Handle h_Dtsec, 47296177Sjhibbits uint8_t phyAddr, 48296177Sjhibbits uint8_t reg, 49296177Sjhibbits uint16_t data) 50296177Sjhibbits{ 51296177Sjhibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 52296177Sjhibbits t_MiiAccessMemMap *p_MiiAccess; 53296177Sjhibbits uint32_t tmpReg; 54296177Sjhibbits 55296177Sjhibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 56296177Sjhibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MiiMemMap, E_INVALID_HANDLE); 57296177Sjhibbits 58296177Sjhibbits p_MiiAccess = p_Dtsec->p_MiiMemMap; 59296177Sjhibbits 60296177Sjhibbits /* Stop the MII management read cycle */ 61296177Sjhibbits WRITE_UINT32(p_MiiAccess->miimcom, 0); 62296177Sjhibbits /* Dummy read to make sure MIIMCOM is written */ 63296177Sjhibbits tmpReg = GET_UINT32(p_MiiAccess->miimcom); 64296177Sjhibbits 65296177Sjhibbits /* Setting up MII Management Address Register */ 66296177Sjhibbits tmpReg = (uint32_t)((phyAddr << MIIMADD_PHY_ADDR_SHIFT) | reg); 67296177Sjhibbits WRITE_UINT32(p_MiiAccess->miimadd, tmpReg); 68296177Sjhibbits 69296177Sjhibbits /* Setting up MII Management Control Register with data */ 70296177Sjhibbits WRITE_UINT32(p_MiiAccess->miimcon, (uint32_t)data); 71296177Sjhibbits /* Dummy read to make sure MIIMCON is written */ 72296177Sjhibbits tmpReg = GET_UINT32(p_MiiAccess->miimcon); 73296177Sjhibbits 74296177Sjhibbits /* Wait till MII management write is complete */ 75296177Sjhibbits while ((GET_UINT32(p_MiiAccess->miimind)) & MIIMIND_BUSY) ; 76296177Sjhibbits 77296177Sjhibbits return E_OK; 78296177Sjhibbits} 79296177Sjhibbits 80296177Sjhibbits/*****************************************************************************/ 81296177Sjhibbitst_Error DTSEC_MII_ReadPhyReg(t_Handle h_Dtsec, 82296177Sjhibbits uint8_t phyAddr, 83296177Sjhibbits uint8_t reg, 84296177Sjhibbits uint16_t *p_Data) 85296177Sjhibbits{ 86296177Sjhibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 87296177Sjhibbits t_MiiAccessMemMap *p_MiiAccess; 88296177Sjhibbits uint32_t tmpReg; 89296177Sjhibbits 90296177Sjhibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 91296177Sjhibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MiiMemMap, E_INVALID_HANDLE); 92296177Sjhibbits 93296177Sjhibbits p_MiiAccess = p_Dtsec->p_MiiMemMap; 94296177Sjhibbits 95296177Sjhibbits /* Setting up the MII Management Address Register */ 96296177Sjhibbits tmpReg = (uint32_t)((phyAddr << MIIMADD_PHY_ADDR_SHIFT) | reg); 97296177Sjhibbits WRITE_UINT32(p_MiiAccess->miimadd, tmpReg); 98296177Sjhibbits 99296177Sjhibbits /* Perform an MII management read cycle */ 100296177Sjhibbits WRITE_UINT32(p_MiiAccess->miimcom, MIIMCOM_READ_CYCLE); 101296177Sjhibbits /* Dummy read to make sure MIIMCOM is written */ 102296177Sjhibbits tmpReg = GET_UINT32(p_MiiAccess->miimcom); 103296177Sjhibbits 104296177Sjhibbits /* Wait till MII management read is complete */ 105296177Sjhibbits while ((GET_UINT32(p_MiiAccess->miimind)) & MIIMIND_BUSY) ; 106296177Sjhibbits 107296177Sjhibbits /* Read MII management status */ 108296177Sjhibbits *p_Data = (uint16_t)GET_UINT32(p_MiiAccess->miimstat); 109296177Sjhibbits 110296177Sjhibbits WRITE_UINT32(p_MiiAccess->miimcom, 0); 111296177Sjhibbits /* Dummy read to make sure MIIMCOM is written */ 112296177Sjhibbits tmpReg = GET_UINT32(p_MiiAccess->miimcom); 113296177Sjhibbits 114296177Sjhibbits if (*p_Data == 0xffff) 115296177Sjhibbits RETURN_ERROR(MINOR, E_NO_DEVICE, 116296177Sjhibbits ("Read wrong data (0xffff): phyAddr 0x%x, reg 0x%x", 117296177Sjhibbits phyAddr, reg)); 118296177Sjhibbits 119296177Sjhibbits return E_OK; 120296177Sjhibbits} 121