Path: blob/main/sys/contrib/ncsw/Peripherals/FM/MAC/dtsec_mii_acc.c
48524 views
/*1* Copyright 2008-2013 Freescale Semiconductor Inc.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5* * Redistributions of source code must retain the above copyright6* notice, this list of conditions and the following disclaimer.7* * Redistributions in binary form must reproduce the above copyright8* notice, this list of conditions and the following disclaimer in the9* documentation and/or other materials provided with the distribution.10* * Neither the name of Freescale Semiconductor nor the11* names of its contributors may be used to endorse or promote products12* derived from this software without specific prior written permission.13*14*15* ALTERNATIVELY, this software may be distributed under the terms of the16* GNU General Public License ("GPL") as published by the Free Software17* Foundation, either version 2 of that License or (at your option) any18* later version.19*20* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY21* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE23* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY24* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/313233/******************************************************************************34@File dtsec_mii_acc.c3536@Description FM dtsec MII register access MAC ...37*//***************************************************************************/3839#include "error_ext.h"40#include "std_ext.h"41#include "fm_mac.h"42#include "dtsec.h"43#include "fsl_fman_dtsec_mii_acc.h"444546/*****************************************************************************/47t_Error DTSEC_MII_WritePhyReg(t_Handle h_Dtsec,48uint8_t phyAddr,49uint8_t reg,50uint16_t data)51{52t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;53struct dtsec_mii_reg *miiregs;54uint16_t dtsec_freq;55t_Error err;5657SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);58SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MiiMemMap, E_INVALID_HANDLE);5960dtsec_freq = (uint16_t)(p_Dtsec->fmMacControllerDriver.clkFreq >> 1);61miiregs = p_Dtsec->p_MiiMemMap;6263err = (t_Error)fman_dtsec_mii_write_reg(miiregs, phyAddr, reg, data, dtsec_freq);6465return err;66}6768/*****************************************************************************/69t_Error DTSEC_MII_ReadPhyReg(t_Handle h_Dtsec,70uint8_t phyAddr,71uint8_t reg,72uint16_t *p_Data)73{74t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;75struct dtsec_mii_reg *miiregs;76uint16_t dtsec_freq;77t_Error err;7879SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);80SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MiiMemMap, E_INVALID_HANDLE);8182dtsec_freq = (uint16_t)(p_Dtsec->fmMacControllerDriver.clkFreq >> 1);83miiregs = p_Dtsec->p_MiiMemMap;8485err = fman_dtsec_mii_read_reg(miiregs, phyAddr, reg, p_Data, dtsec_freq);8687if (*p_Data == 0xffff)88RETURN_ERROR(MINOR, E_NO_DEVICE,89("Read wrong data (0xffff): phyAddr 0x%x, reg 0x%x",90phyAddr, reg));91if (err)92RETURN_ERROR(MINOR, (t_Error)err, NO_MSG);9394return E_OK;95}96979899