diff options
author | Lean Sheng Tan <lean.sheng.tan@intel.com> | 2021-06-16 09:41:37 -0700 |
---|---|---|
committer | Werner Zeh <werner.zeh@siemens.com> | 2021-06-30 07:35:09 +0000 |
commit | bed1b602d0cb6027c1b796cb1e44f335e56e0471 (patch) | |
tree | ce30d40c1db81c2207ffbc1617a82ee9e6e336c6 /src/soc/intel/common/block/pmc | |
parent | 508dc163f183f99f4683365ef3a6443658979846 (diff) |
soc/intel/common: Refine pmc_get_xtal_freq function
1. Remove 'PCH_EPOC_XTAL_FREQ(__epoc)' macro since it only be used
in 1 place.
2. Transform macro into more readable C code.
3. Add additional case check to make sure the returned value is
defined in the 'pch_pmc_xtal' enum.
Signed-off-by: Lean Sheng Tan <lean.sheng.tan@intel.com>
Change-Id: If57a99bf8e837a6eb8f225297399b1f5363cfa85
Reviewed-on: https://review.coreboot.org/c/coreboot/+/55587
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Diffstat (limited to 'src/soc/intel/common/block/pmc')
-rw-r--r-- | src/soc/intel/common/block/pmc/pmclib.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/soc/intel/common/block/pmc/pmclib.c b/src/soc/intel/common/block/pmc/pmclib.c index 64c25ff5fe..81d25e02a0 100644 --- a/src/soc/intel/common/block/pmc/pmclib.c +++ b/src/soc/intel/common/block/pmc/pmclib.c @@ -732,7 +732,22 @@ enum pch_pmc_xtal pmc_get_xtal_freq(void) if (!CONFIG(PMC_EPOC)) dead_code(); - const uintptr_t pmcbase = soc_read_pmc_base(); - - return PCH_EPOC_XTAL_FREQ(read32((uint32_t *)(pmcbase + PCH_PMC_EPOC))); + uint32_t xtal_freq = 0; + const uint32_t epoc = read32p(soc_read_pmc_base() + PCH_PMC_EPOC); + + /* XTAL frequency in bits 21, 20, 17 */ + xtal_freq |= !!(epoc & (1 << 21)) << 2; + xtal_freq |= !!(epoc & (1 << 20)) << 1; + xtal_freq |= !!(epoc & (1 << 17)) << 0; + switch (xtal_freq) { + case 0: + return XTAL_24_MHZ; + case 1: + return XTAL_19_2_MHZ; + case 2: + return XTAL_38_4_MHZ; + default: + printk(BIOS_ERR, "Unknown EPOC XTAL frequency setting %u\n", xtal_freq); + return XTAL_UNKNOWN_FREQ; + } } |