From a76ec0aea4204f572f32e63e9bb1f78c2e5c63df Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 1 Feb 2017 18:13:25 -0800 Subject: [PATCH] cr50: Save properties in long life even when straps are invalid Previously, and invalid strap configuraiton was not updating the copy in the long life register. Since we don't expect to have invalid strap pins, but if they are read, it's not expected to change run to run. Therefore, to have consistent behavior, store the properties determined in the long life register in all cases. BRANCH=none BUG=chrome-os-partner:59833 TEST=manual Tested with Reef/Gru which both have valid table entries and verified that board properties were being saved in the long life register. Tested on Eve which has currently an invalid strap config and repeated the test. Change-Id: I3a018db0e3a88ad33a85125a892b74b44593d5df Signed-off-by: Scott Reviewed-on: https://chromium-review.googlesource.com/436004 Commit-Ready: Scott Collyer Tested-by: Scott Collyer Reviewed-by: Vadim Bendebury --- board/cr50/board.c | 103 +++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 54 deletions(-) diff --git a/board/cr50/board.c b/board/cr50/board.c index 20037f37af..e3ce3609f5 100644 --- a/board/cr50/board.c +++ b/board/cr50/board.c @@ -1030,6 +1030,46 @@ static int get_strap_config(uint8_t *config) return EC_SUCCESS; } +static uint32_t get_properties(void) +{ + int i; + uint8_t config; + uint32_t properties; + + if (get_strap_config(&config) != EC_SUCCESS) { + /* + * No pullups were detected on any of the strap pins so there + * is no point in checking for a matching config table entry. + * For this case use default properties. + */ + CPRINTS("Invalid strap pins! Default properties = 0x%x", + BOARD_PROPERTIES_DEFAULT); + return BOARD_PROPERTIES_DEFAULT; + } + + /* Search board config table to find a matching entry */ + for (i = 0; i < ARRAY_SIZE(board_cfg_table); i++) { + if (board_cfg_table[i].strap_cfg == config) { + properties = board_cfg_table[i].board_properties; + CPRINTS("Valid strap: 0x%x properties: 0x%x", + config, properties); + /* Read board properties for this config */ + return properties; + } + } + + /* + * Reached the end of the table and didn't find a matching config entry. + * However, the SPI vs I2C determination can still be made as + *get_strap_config() returned EC_SUCCESS. + */ + properties = config & 0xa ? BOARD_SLAVE_CONFIG_SPI : + BOARD_PROPERTIES_DEFAULT; + CPRINTS("strap_cfg 0x%x has no table entry, prop = 0x%x", + config, properties); + return properties; +} + static void init_board_properties(void) { uint32_t properties; @@ -1042,67 +1082,22 @@ static void init_board_properties(void) */ if (!(properties & BOARD_ALL_PROPERTIES) || (system_get_reset_flags() & RESET_FLAG_HARD)) { - int i; - uint8_t config; - /* * Mask board properties because following hard reset, they * won't be cleared. */ properties &= ~BOARD_ALL_PROPERTIES; - - if (get_strap_config(&config) != EC_SUCCESS) { - /* - * No pullups were detected on any of the strap pins so - * there is no point in checking for a matching config - * table entry. For this case default to I2C with - * platform reset and don't store in long life register. - */ - /* Save this configuration setting */ - board_properties = BOARD_PROPERTIES_DEFAULT; - CPRINTS("Invalid strap pins! Default properties = 0x%x", - board_properties); - return; - } - - /* Search board config table to find a matching entry */ - i = 0; - while (i < ARRAY_SIZE(board_cfg_table)) { - if (board_cfg_table[i].strap_cfg == config) { - /* Read board properties for this config */ - properties |= - board_cfg_table[i].board_properties; - CPRINTS("Valid strap: 0x%x properties: 0x%x", - config, properties); - /* - * Now save the properties value for future use. - * - * Enable access to LONG_LIFE_SCRATCH1 reg. - */ - GWRITE_FIELD(PMU, LONG_LIFE_SCRATCH_WR_EN, - REG1, 1); - /* Save properties in LONG_LIFE register */ - GREG32(PMU, LONG_LIFE_SCRATCH1) = properties; - /* Disable access to LONG_LIFE_SCRATCH1 reg */ - GWRITE_FIELD(PMU, LONG_LIFE_SCRATCH_WR_EN, - REG1, 0); - /* Save this configuration setting */ - board_properties = properties; - return; - } - i++; - } - + properties |= get_properties(); /* - * Reached the end of the table and didn't find a - * matching config entry. However, the SPI vs I2C - * determination can still be made as get_strap_config() - * returned EC_SUCCESS. + * Now save the properties value for future use. + * + * Enable access to LONG_LIFE_SCRATCH1 reg. */ - properties = config & 0xa ? BOARD_SLAVE_CONFIG_SPI : - BOARD_PROPERTIES_DEFAULT; - CPRINTS("strap_cfg 0x%x has no table entry, prop = 0x%x", - config, properties); + GWRITE_FIELD(PMU, LONG_LIFE_SCRATCH_WR_EN, REG1, 1); + /* Save properties in LONG_LIFE register */ + GREG32(PMU, LONG_LIFE_SCRATCH1) = properties; + /* Disable access to LONG_LIFE_SCRATCH1 reg */ + GWRITE_FIELD(PMU, LONG_LIFE_SCRATCH_WR_EN, REG1, 0); } /* Save this configuration setting */ board_properties = properties;