| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2011, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bxpt_wakeup.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/1 $ |
|---|
| 12 | * $brcm_Date: 9/30/11 3:10p $ |
|---|
| 13 | * |
|---|
| 14 | * Porting interface code for the data transport core. |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/portinginterface/xpt/base2/bxpt_wakeup.c $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/1 9/30/11 3:10p gmullen |
|---|
| 21 | * SW7425-1183: Merged to Hydra |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/SW7425-1183/1 8/26/11 10:08a gmullen |
|---|
| 24 | * SW7425-1183: Interrupt the power managment unit when a wakeup packet is |
|---|
| 25 | * seen |
|---|
| 26 | * |
|---|
| 27 | * |
|---|
| 28 | ***************************************************************************/ |
|---|
| 29 | |
|---|
| 30 | #include "bstd.h" |
|---|
| 31 | #include "bxpt_priv.h" |
|---|
| 32 | #include "bxpt_wakeup.h" |
|---|
| 33 | #include "bkni.h" |
|---|
| 34 | #include "bchp_xpt_wakeup.h" |
|---|
| 35 | |
|---|
| 36 | #if BCHP_PWR_SUPPORT |
|---|
| 37 | #include "bchp_pwr.h" |
|---|
| 38 | #endif |
|---|
| 39 | |
|---|
| 40 | #if( BDBG_DEBUG_BUILD == 1 ) |
|---|
| 41 | BDBG_MODULE( xpt_wakeup ); |
|---|
| 42 | #endif |
|---|
| 43 | |
|---|
| 44 | void BXPT_Wakeup_GetDefaults( |
|---|
| 45 | BXPT_Wakeup_Settings *Settings |
|---|
| 46 | ) |
|---|
| 47 | { |
|---|
| 48 | BDBG_ASSERT( Settings ); |
|---|
| 49 | BKNI_Memset( (void *)Settings, 0, sizeof(BXPT_Wakeup_Settings)); |
|---|
| 50 | Settings->PacketLength = 188; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | void BXPT_Wakeup_GetSettings( |
|---|
| 54 | BXPT_Handle hXpt, /* [in] Handle for this transport */ |
|---|
| 55 | BXPT_Wakeup_Settings *Settings |
|---|
| 56 | ) |
|---|
| 57 | { |
|---|
| 58 | uint32_t Reg; |
|---|
| 59 | |
|---|
| 60 | BDBG_ASSERT( hXpt ); |
|---|
| 61 | BDBG_ASSERT( Settings ); |
|---|
| 62 | |
|---|
| 63 | Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_WAKEUP_CTRL ); |
|---|
| 64 | Settings->InputBand = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_CTRL, INPUT_SEL ); |
|---|
| 65 | Settings->InputBand |= (BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_CTRL, INPUT_SEL_MSB ) << 4 ); |
|---|
| 66 | Settings->PacketLength = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_CTRL, PKT_LENGTH ); |
|---|
| 67 | Settings->ErrorInputIgnore = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_CTRL, ERROR_INPUT_IGNORE ); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | BERR_Code BXPT_Wakeup_SetSettings( |
|---|
| 71 | BXPT_Handle hXpt, /* [in] Handle for this transport */ |
|---|
| 72 | const BXPT_Wakeup_Settings *Settings |
|---|
| 73 | ) |
|---|
| 74 | { |
|---|
| 75 | uint32_t Reg; |
|---|
| 76 | |
|---|
| 77 | BERR_Code ExitCode = BERR_SUCCESS; |
|---|
| 78 | |
|---|
| 79 | BDBG_ASSERT( hXpt ); |
|---|
| 80 | BDBG_ASSERT( Settings ); |
|---|
| 81 | |
|---|
| 82 | if( Settings->PacketLength > BXPT_WAKEUP_PACKET_SIZE ) |
|---|
| 83 | { |
|---|
| 84 | BDBG_ERR(( "PacketLength %u is out-of-bounds (max is %u).", Settings->PacketLength, BXPT_WAKEUP_PACKET_SIZE )); |
|---|
| 85 | ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER ); |
|---|
| 86 | } |
|---|
| 87 | else if ( Settings->InputBand >= BXPT_NUM_INPUT_BANDS ) |
|---|
| 88 | { |
|---|
| 89 | BDBG_ERR(( "InputBand %u is out-of-bounds (max is %u).", Settings->InputBand, BXPT_NUM_INPUT_BANDS - 1 )); |
|---|
| 90 | ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER ); |
|---|
| 91 | } |
|---|
| 92 | else |
|---|
| 93 | { |
|---|
| 94 | Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_WAKEUP_CTRL ); |
|---|
| 95 | Reg &= ~( |
|---|
| 96 | BCHP_MASK( XPT_WAKEUP_CTRL, PKT_LENGTH ) | |
|---|
| 97 | BCHP_MASK( XPT_WAKEUP_CTRL, ERROR_INPUT_IGNORE ) | |
|---|
| 98 | BCHP_MASK( XPT_WAKEUP_CTRL, INPUT_SEL_MSB ) | |
|---|
| 99 | BCHP_MASK( XPT_WAKEUP_CTRL, INPUT_SEL ) |
|---|
| 100 | ); |
|---|
| 101 | Reg |= ( |
|---|
| 102 | BCHP_FIELD_DATA( XPT_WAKEUP_CTRL, PKT_LENGTH, Settings->PacketLength ) | |
|---|
| 103 | BCHP_FIELD_DATA( XPT_WAKEUP_CTRL, ERROR_INPUT_IGNORE, Settings->ErrorInputIgnore ) | |
|---|
| 104 | BCHP_FIELD_DATA( XPT_WAKEUP_CTRL, INPUT_SEL_MSB, (Settings->InputBand >> 4) & 0x1 ) | |
|---|
| 105 | BCHP_FIELD_DATA( XPT_WAKEUP_CTRL, INPUT_SEL, Settings->InputBand & 0xF) |
|---|
| 106 | ); |
|---|
| 107 | BREG_Write32( hXpt->hRegister, BCHP_XPT_WAKEUP_CTRL, Reg ); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | return ExitCode; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | void BXPT_Wakeup_GetStatus( |
|---|
| 114 | BXPT_Handle hXpt, /* [in] Handle for this transport */ |
|---|
| 115 | BXPT_Wakeup_Status *Status |
|---|
| 116 | ) |
|---|
| 117 | { |
|---|
| 118 | uint32_t Reg; |
|---|
| 119 | |
|---|
| 120 | BDBG_ASSERT( hXpt ); |
|---|
| 121 | BDBG_ASSERT( Status ); |
|---|
| 122 | |
|---|
| 123 | Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_WAKEUP_STATUS ); |
|---|
| 124 | Status->Found = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_STATUS, PKT_FOUND ); |
|---|
| 125 | Status->Type = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_STATUS, PKT_FOUND_TYPE ); |
|---|
| 126 | Status->Count = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_STATUS, PACKET_COUNT ); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | void BXPT_Wakeup_ClearInterruptToPMU( |
|---|
| 130 | BXPT_Handle hXpt /* [in] Handle for this transport */ |
|---|
| 131 | ) |
|---|
| 132 | { |
|---|
| 133 | uint32_t Reg; |
|---|
| 134 | |
|---|
| 135 | BDBG_ASSERT( hXpt ); |
|---|
| 136 | |
|---|
| 137 | Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_WAKEUP_STATUS ); |
|---|
| 138 | Reg &= ~( |
|---|
| 139 | BCHP_MASK( XPT_WAKEUP_STATUS, PKT_FOUND ) |
|---|
| 140 | ); |
|---|
| 141 | BREG_Write32( hXpt->hRegister, BCHP_XPT_WAKEUP_STATUS, Reg ); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | BERR_Code BXPT_Wakeup_SetPacketFilterBytes( |
|---|
| 145 | BXPT_Handle hXpt, /* [in] Handle for this transport */ |
|---|
| 146 | unsigned WhichPacketType, |
|---|
| 147 | const BXPT_Wakeup_PacketFilter *Filter |
|---|
| 148 | ) |
|---|
| 149 | { |
|---|
| 150 | BERR_Code ExitCode = BERR_SUCCESS; |
|---|
| 151 | |
|---|
| 152 | BDBG_ASSERT( hXpt ); |
|---|
| 153 | BDBG_ASSERT( Filter ); |
|---|
| 154 | |
|---|
| 155 | if( WhichPacketType > BXPT_WAKEUP_MAX_PACKET_TYPE ) |
|---|
| 156 | { |
|---|
| 157 | BDBG_ERR(( "WhichPacketType %u is out-of-bounds (max is %u).", WhichPacketType, BXPT_WAKEUP_MAX_PACKET_TYPE )); |
|---|
| 158 | ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER ); |
|---|
| 159 | } |
|---|
| 160 | else |
|---|
| 161 | { |
|---|
| 162 | uint32_t Reg; |
|---|
| 163 | unsigned Index; |
|---|
| 164 | |
|---|
| 165 | uint32_t ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE0_i_ARRAY_BASE; |
|---|
| 166 | |
|---|
| 167 | switch( WhichPacketType ) |
|---|
| 168 | { |
|---|
| 169 | default: |
|---|
| 170 | case 0: ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE0_i_ARRAY_BASE; break; |
|---|
| 171 | case 1: ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE1_i_ARRAY_BASE; break; |
|---|
| 172 | case 2: ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE2_i_ARRAY_BASE; break; |
|---|
| 173 | case 3: ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE3_i_ARRAY_BASE; break; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | for( Index = 0; Index < BXPT_WAKEUP_PACKET_SIZE; Index++ ) |
|---|
| 177 | { |
|---|
| 178 | Reg = BREG_Read32( hXpt->hRegister, ArrayBase + (Index * 4) ); |
|---|
| 179 | Reg &= ~( |
|---|
| 180 | BCHP_MASK( XPT_WAKEUP_PKT_TYPE0_i, COMPARE_BYTE ) | |
|---|
| 181 | BCHP_MASK( XPT_WAKEUP_PKT_TYPE0_i, COMPARE_MASK_TYPE ) | |
|---|
| 182 | BCHP_MASK( XPT_WAKEUP_PKT_TYPE0_i, COMPARE_MASK ) |
|---|
| 183 | ); |
|---|
| 184 | Reg |= ( |
|---|
| 185 | BCHP_FIELD_DATA( XPT_WAKEUP_PKT_TYPE0_i, COMPARE_BYTE, Filter[ Index ].CompareByte ) | |
|---|
| 186 | BCHP_FIELD_DATA( XPT_WAKEUP_PKT_TYPE0_i, COMPARE_MASK_TYPE, Filter[ Index ].MaskType ) | |
|---|
| 187 | BCHP_FIELD_DATA( XPT_WAKEUP_PKT_TYPE0_i, COMPARE_MASK, Filter[ Index ].Mask ) |
|---|
| 188 | ); |
|---|
| 189 | BREG_Write32( hXpt->hRegister, ArrayBase + (Index * 4), Reg ); |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | return ExitCode; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | BERR_Code BXPT_Wakeup_GetPacketFilterBytes( |
|---|
| 198 | BXPT_Handle hXpt, /* [in] Handle for this transport */ |
|---|
| 199 | unsigned WhichPacketType, |
|---|
| 200 | BXPT_Wakeup_PacketFilter *Filter |
|---|
| 201 | ) |
|---|
| 202 | { |
|---|
| 203 | BERR_Code ExitCode = BERR_SUCCESS; |
|---|
| 204 | |
|---|
| 205 | BDBG_ASSERT( hXpt ); |
|---|
| 206 | BDBG_ASSERT( Filter ); |
|---|
| 207 | |
|---|
| 208 | if( WhichPacketType > BXPT_WAKEUP_MAX_PACKET_TYPE ) |
|---|
| 209 | { |
|---|
| 210 | BDBG_ERR(( "WhichPacketType %u is out-of-bounds (max is %u).", WhichPacketType, BXPT_WAKEUP_MAX_PACKET_TYPE )); |
|---|
| 211 | ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER ); |
|---|
| 212 | } |
|---|
| 213 | else |
|---|
| 214 | { |
|---|
| 215 | uint32_t Reg; |
|---|
| 216 | unsigned Index; |
|---|
| 217 | |
|---|
| 218 | uint32_t ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE0_i_ARRAY_BASE; |
|---|
| 219 | |
|---|
| 220 | switch( WhichPacketType ) |
|---|
| 221 | { |
|---|
| 222 | default: |
|---|
| 223 | case 0: ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE0_i_ARRAY_BASE; break; |
|---|
| 224 | case 1: ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE1_i_ARRAY_BASE; break; |
|---|
| 225 | case 2: ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE2_i_ARRAY_BASE; break; |
|---|
| 226 | case 3: ArrayBase = BCHP_XPT_WAKEUP_PKT_TYPE3_i_ARRAY_BASE; break; |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | for( Index = 0; Index < BXPT_WAKEUP_PACKET_SIZE; Index++ ) |
|---|
| 230 | { |
|---|
| 231 | Reg = BREG_Read32( hXpt->hRegister, ArrayBase + (Index * 4) ); |
|---|
| 232 | Filter[ Index ].CompareByte = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_PKT_TYPE0_i, COMPARE_BYTE ); |
|---|
| 233 | Filter[ Index ].MaskType = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_PKT_TYPE0_i, COMPARE_MASK_TYPE ); |
|---|
| 234 | Filter[ Index ].Mask = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_PKT_TYPE0_i, COMPARE_MASK ); |
|---|
| 235 | } |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | return ExitCode; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | void BXPT_Wakeup_GetCapturedPacket( |
|---|
| 242 | BXPT_Handle hXpt, /* [in] Handle for this transport */ |
|---|
| 243 | unsigned char *PacketBuffer |
|---|
| 244 | ) |
|---|
| 245 | { |
|---|
| 246 | uint32_t Reg; |
|---|
| 247 | unsigned Index; |
|---|
| 248 | |
|---|
| 249 | BDBG_ASSERT( hXpt ); |
|---|
| 250 | BDBG_ASSERT( PacketBuffer ); |
|---|
| 251 | |
|---|
| 252 | for( Index = 0; Index < BXPT_WAKEUP_PACKET_SIZE; Index++ ) |
|---|
| 253 | { |
|---|
| 254 | Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_WAKEUP_PKT_MEM_i_ARRAY_BASE + (Index * 4) ); |
|---|
| 255 | PacketBuffer[ Index ] = BCHP_GET_FIELD_DATA( Reg, XPT_WAKEUP_PKT_MEM_i, PKT_BYTE ); |
|---|
| 256 | } |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | void BXPT_Wakeup_Armed( |
|---|
| 260 | BXPT_Handle hXpt, /* [in] Handle for this transport */ |
|---|
| 261 | bool Armed |
|---|
| 262 | ) |
|---|
| 263 | { |
|---|
| 264 | uint32_t Reg; |
|---|
| 265 | |
|---|
| 266 | BDBG_ASSERT( hXpt ); |
|---|
| 267 | |
|---|
| 268 | #ifdef BCHP_PWR_RESOURCE_XPT |
|---|
| 269 | if( Armed && !hXpt->WakeupArmed ) |
|---|
| 270 | { |
|---|
| 271 | BCHP_PWR_AcquireResource( hXpt->hChip, BCHP_PWR_RESOURCE_XPT_XMEMIF ); |
|---|
| 272 | hXpt->WakeupArmed = true; |
|---|
| 273 | } |
|---|
| 274 | #endif |
|---|
| 275 | |
|---|
| 276 | Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_WAKEUP_CTRL ); |
|---|
| 277 | Reg &= ~( |
|---|
| 278 | BCHP_MASK( XPT_WAKEUP_CTRL, PKT_DETECT_EN ) |
|---|
| 279 | ); |
|---|
| 280 | Reg |= ( |
|---|
| 281 | BCHP_FIELD_DATA( XPT_WAKEUP_CTRL, PKT_DETECT_EN, Armed ? 1 : 0 ) |
|---|
| 282 | ); |
|---|
| 283 | BREG_Write32( hXpt->hRegister, BCHP_XPT_WAKEUP_CTRL, Reg ); |
|---|
| 284 | |
|---|
| 285 | #ifdef BCHP_PWR_RESOURCE_XPT |
|---|
| 286 | if( !Armed && hXpt->WakeupArmed ) |
|---|
| 287 | { |
|---|
| 288 | BCHP_PWR_ReleaseResource( hXpt->hChip, BCHP_PWR_RESOURCE_XPT_XMEMIF ); |
|---|
| 289 | hXpt->WakeupArmed = false; |
|---|
| 290 | } |
|---|
| 291 | #endif |
|---|
| 292 | } |
|---|
| 293 | |
|---|