1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 3 #include <baseboard/cbi_ssfc.h> 4 #include <console/console.h> 5 #include <ec/google/chromeec/ec.h> 6 get_ssfc(uint32_t * val)7static int get_ssfc(uint32_t *val) 8 { 9 static uint32_t known_value; 10 static enum { 11 SSFC_NOT_READ, 12 SSFC_AVAILABLE, 13 } ssfc_state = SSFC_NOT_READ; 14 15 if (ssfc_state == SSFC_AVAILABLE) { 16 *val = known_value; 17 return 0; 18 } 19 20 /* 21 * If SSFC field is not in the CBI then the value of SSFC will be 0 for 22 * further processing later since 0 of each bits group means default 23 * component in a variant. For more detail, please refer to cbi_ssfc.h. 24 */ 25 if (google_chromeec_cbi_get_ssfc(&known_value) != 0) { 26 printk(BIOS_DEBUG, "SSFC not set in CBI\n"); 27 return -1; 28 } 29 30 ssfc_state = SSFC_AVAILABLE; 31 *val = known_value; 32 printk(BIOS_INFO, "SSFC 0x%x.\n", known_value); 33 34 return 0; 35 } 36 extract_field(uint32_t mask,int shift)37static unsigned int extract_field(uint32_t mask, int shift) 38 { 39 uint32_t ssfc; 40 41 /* On errors nothing is assumed to be set. */ 42 if (get_ssfc(&ssfc)) 43 return 0; 44 45 return (ssfc >> shift) & mask; 46 } 47 ssfc_get_default_audio_codec(void)48static enum ssfc_audio_codec ssfc_get_default_audio_codec(void) 49 { 50 /* 51 * Octopus has two reference boards; yorp is with DA7219 and bip is with 52 * RT5682. Currently only AMPTON derived from bip so only it uses 53 * RT5682 as the default source in the first MP devices. 54 */ 55 if (CONFIG(BOARD_GOOGLE_AMPTON)) 56 return SSFC_AUDIO_CODEC_RT5682; 57 58 return SSFC_AUDIO_CODEC_DA7219; 59 } 60 ssfc_get_audio_codec(void)61enum ssfc_audio_codec ssfc_get_audio_codec(void) 62 { 63 uint32_t codec = extract_field( 64 SSFC_AUDIO_CODEC_MASK, SSFC_AUDIO_CODEC_OFFSET); 65 66 if (codec != SSFC_AUDIO_CODEC_DEFAULT) 67 return codec; 68 69 return ssfc_get_default_audio_codec(); 70 } 71