phy8806x_tsc_dependencies.c (4428B)
1 /* 2 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 3 * 4 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 5 * 6 */ 7 8 #ifdef LINUX 9 /* #include <stdint.h> */ 10 #endif 11 #include <phymod/phymod.h> 12 #include <phymod/phymod_system.h> 13 #include "phy8806x_tsc_common_err_code.h" 14 #include "phy8806x_tsc_common.h" 15 #include <phymod/acc/phymod_tsc_iblk.h> 16 #include "phy8806x_tsc_dependencies.h" 17 18 #if defined(INCLUDE_PHY_8806X) 19 #include <soc/phy/phymod_ctrl.h> 20 #endif 21 22 23 /** 24 @brief Falcon PMD Modify-Write 25 @param phymod access handle to current Falcon Context 26 @param address 27 @param mask 28 @param lsb 29 @param val 30 @returns The ERR_CODE_NONE upon successful completion, else returns ERR_CODE_DATA_NOTAVAIL 31 */ 32 err_code_t phy8806x_tsc_pmd_mwr_reg(const phymod_access_t *pa, uint16_t addr, uint16_t mask, uint8_t lsb, uint16_t val) { 33 uint32_t mymask = ( uint32_t) mask; 34 phymod_access_t pa_copy; 35 uint32_t i; 36 uint32_t error_code; 37 38 uint32_t data = ((mymask << 16) & 0xffff0000) | val << lsb; 39 40 error_code=0; 41 PHYMOD_MEMCPY(&pa_copy, pa, sizeof(phymod_access_t)); 42 for(i=1; i <= 0x8; i = i << 1) { 43 if ( i & pa->lane_mask ) { 44 pa_copy.lane_mask = i; 45 error_code+=phymod_tsc_iblk_write(&pa_copy, (PHYMOD_REG_ACC_TSC_IBLK | 0x10000 | (uint32_t) addr), data); 46 } 47 } 48 if(error_code) 49 return ERR_CODE_DATA_NOTAVAIL; 50 return ERR_CODE_NONE; 51 } 52 53 /* uint8_t phy8806x_tsc_get_lane(const phymod_access_t *pa) { */ 54 uint8_t phy8806x_tsc_get_lane(const phymod_access_t *pa) { 55 if (pa->lane_mask == 0x1) { 56 return ( 0 ); 57 } else if (pa->lane_mask == 0x2) { 58 return ( 1 ); 59 } else if (pa->lane_mask == 0x4) { 60 return ( 2 ); 61 } else if (pa->lane_mask == 0x8) { 62 return ( 3 ); 63 } else { 64 return ( 0 ); 65 } 66 } 67 68 uint16_t phy8806x_tsc_pmd_rd_reg(const phymod_access_t *pa, uint16_t address){ 69 70 uint32_t data; 71 72 phymod_tsc_iblk_read(pa, (PHYMOD_REG_ACC_TSC_IBLK | 0x10000 | (uint32_t) address), &data); 73 data = data & 0xffff; 74 return ( (uint16_t)data ); 75 } 76 77 err_code_t phy8806x_tsc_delay_ns(uint16_t delay_ns) { 78 uint32_t delay; 79 delay = delay_ns / 1000; 80 if (!delay ) { 81 delay = 1; 82 } 83 PHYMOD_USLEEP(delay); 84 return ( 0 ); 85 } 86 87 /** 88 @brief Falcon PMD Write 89 @param phymod access handle to current Falcon Context 90 @param address 91 @param val 92 @returns The ERR_CODE_NONE upon successful completion, else returns ERR_CODE_DATA_NOTAVAIL 93 */ 94 err_code_t phy8806x_tsc_pmd_wr_reg(const phymod_access_t *pa, uint16_t address, uint16_t val){ 95 uint32_t data = 0xffff & val; 96 uint32_t error_code; 97 98 error_code = phymod_tsc_iblk_write(pa, (PHYMOD_REG_ACC_TSC_IBLK | 0x10000 | (uint32_t) address), data); 99 if(error_code) 100 return ERR_CODE_DATA_NOTAVAIL; 101 return ERR_CODE_NONE; 102 } 103 104 err_code_t phy8806x_tsc_delay_us(uint32_t delay_us){ 105 PHYMOD_USLEEP(delay_us); 106 return ( 0 ); 107 } 108 109 err_code_t phy8806x_tsc_pmd_rdt_reg(const phymod_access_t *pa, uint16_t address, uint16_t *val) { 110 uint32_t data; 111 112 phymod_tsc_iblk_read(pa, (PHYMOD_REG_ACC_TSC_IBLK | 0x10000 | (uint32_t) address), &data); 113 data = data & 0xffff; 114 *val = (uint16_t)data; 115 return ( 0 ); 116 } 117 118 uint8_t phy8806x_tsc_get_core(void) { 119 return(0); 120 } 121 122 err_code_t phy8806x_tsc_uc_lane_idx_to_system_id(char *string , uint8_t uc_lane_idx) { 123 static char info[256]; 124 /* Indicates Falcon Core */ 125 PHYMOD_SPRINTF(info, "%s_%d", "FC_", uc_lane_idx); 126 PHYMOD_STRNCPY(string,info, PHYMOD_STRLEN(info)+1); 127 return ERR_CODE_NONE; 128 } 129 130 err_code_t phy8806x_tsc_set_pll(const phymod_access_t *pa, uint8_t pll_index) { 131 #if defined(INCLUDE_PHY_8806X) 132 soc_phymod_core_t *core = PHYMOD_ACC_USER_ACC(pa); 133 phymod_core_access_t *pm_core = &core->pm_core; 134 phymod_access_t *phyacc = &pm_core->access; 135 136 PHYMOD_ACC_PLLIDX(phyacc) = pll_index; 137 return 0; 138 #else 139 return ERR_CODE_DATA_NOTAVAIL; 140 #endif 141 } 142 143 uint8_t phy8806x_tsc_get_pll(const phymod_access_t *pa) { 144 #if defined(INCLUDE_PHY_8806X) 145 soc_phymod_core_t *core = PHYMOD_ACC_USER_ACC(pa); 146 phymod_core_access_t *pm_core = &core->pm_core; 147 phymod_access_t *phyacc = &pm_core->access; 148 149 return PHYMOD_ACC_PLLIDX(phyacc); 150 #else 151 return ERR_CODE_DATA_NOTAVAIL; 152 #endif 153 } 154 155 err_code_t phy8806x_tsc_set_lane(uint8_t lane_index) { 156 return 0; 157 } 158