reg_cmicx.c (1807B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * Register address and value manipulations for CMICx. 8 */ 9 10 #include <sal/core/libc.h> 11 #include <sal/appl/sal.h> 12 #include <soc/register.h> 13 14 #ifdef BCM_CMICX_SUPPORT 15 #include <soc/mcm/cmicx.h> 16 17 soc_cmicx_reg_t cmicx_regs[] = CMICX_REG_INIT; 18 19 STATIC soc_cmicx_reg_t 20 *soc_cmicx_srch (uint32 addr) { 21 int start = 0; 22 int end = NUM_CMICX_REGS - 1; 23 int mid = (start + end) >> 1; 24 while (start <= end && cmicx_regs[mid].addr != addr) { 25 if (cmicx_regs[mid].addr > addr) { 26 end = mid - 1; 27 } else { 28 start = mid + 1; 29 } 30 mid = (start + end) >> 1; 31 } 32 return (cmicx_regs[mid].addr == addr) ? &(cmicx_regs[mid]) : NULL; 33 } 34 35 soc_cmicx_reg_t 36 *soc_cmicx_reg_get (uint32 idx) { 37 return &(cmicx_regs[idx]); 38 } 39 40 soc_reg_t 41 soc_cmicx_addr_reg (uint32 addr) { 42 soc_cmicx_reg_t *cmreg = soc_cmicx_srch(addr); 43 return (cmreg == NULL)?INVALIDr:cmreg->reg; 44 } 45 46 char * 47 soc_cmicx_addr_name (uint32 addr) { 48 soc_cmicx_reg_t *cmreg = soc_cmicx_srch(addr); 49 return (cmreg == NULL)?"???":cmreg->name; 50 } 51 52 /* 53 * Parse a CMICX register name and return offset. Matching is 54 * case-insensitive and works with or without the "CMIC_" prefix. 55 */ 56 57 int 58 soc_parse_cmicx_regname(int unit, char *name, uint32 *offset_ptr) { 59 char *s; 60 int i; 61 soc_cmicx_reg_t *creg; 62 for (i = 0; i < NUM_CMICX_REGS; i++) { 63 creg = soc_cmicx_reg_get(i); 64 s = creg->name; 65 if (sal_strcasecmp(name, s) == 0 || sal_strcasecmp(name, s + 5) == 0) { 66 *offset_ptr = creg->addr; 67 return 0; 68 } 69 } 70 return -1; 71 } 72 #endif