diff --git a/src/drivers/i2c/at24rf08c/Kconfig b/src/drivers/i2c/at24rf08c/Kconfig index a930a46123..219c091a92 100644 --- a/src/drivers/i2c/at24rf08c/Kconfig +++ b/src/drivers/i2c/at24rf08c/Kconfig @@ -3,3 +3,7 @@ config DRIVER_LENOVO_SERIALS bool select SMBIOS_PROVIDED_BY_MOBO + +config DRIVER_LENOVO_SERIALS_EARLY_LOCK + bool + depends on DRIVER_LENOVO_SERIALS diff --git a/src/drivers/i2c/at24rf08c/Makefile.mk b/src/drivers/i2c/at24rf08c/Makefile.mk index 4ef2bc595c..223f6903a4 100644 --- a/src/drivers/i2c/at24rf08c/Makefile.mk +++ b/src/drivers/i2c/at24rf08c/Makefile.mk @@ -3,3 +3,4 @@ ramstage-$(CONFIG_DRIVER_LENOVO_SERIALS) += at24rf08c.c $(call src-to-obj,ramstage,$(dir)/lenovo_serials.c) : $(obj)/build.h ramstage-$(CONFIG_DRIVER_LENOVO_SERIALS) += lenovo_serials.c +romstage-$(CONFIG_DRIVER_LENOVO_SERIALS_EARLY_LOCK) += romstage.c diff --git a/src/drivers/i2c/at24rf08c/at24rf08c.c b/src/drivers/i2c/at24rf08c/at24rf08c.c index 99ea7a47f0..6005f74c4c 100644 --- a/src/drivers/i2c/at24rf08c/at24rf08c.c +++ b/src/drivers/i2c/at24rf08c/at24rf08c.c @@ -11,6 +11,9 @@ static void at24rf08c_init(struct device *dev) if (!dev->enabled) return; + if (CONFIG(DRIVER_LENOVO_SERIALS_EARLY_LOCK)) + return; + /* Ensure that EEPROM/RFID chip is not accessible through RFID. Need to do it only on 5c. */ if (dev->path.type != DEVICE_PATH_I2C || dev->path.i2c.device != 0x5c) diff --git a/src/drivers/i2c/at24rf08c/lenovo.h b/src/drivers/i2c/at24rf08c/lenovo.h index f94b9ee06d..628308d5dd 100644 --- a/src/drivers/i2c/at24rf08c/lenovo.h +++ b/src/drivers/i2c/at24rf08c/lenovo.h @@ -1,3 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-only */ const char *lenovo_mainboard_partnumber(void); + +void lenovo_mainboard_eeprom_lock(void); diff --git a/src/drivers/i2c/at24rf08c/romstage.c b/src/drivers/i2c/at24rf08c/romstage.c new file mode 100644 index 0000000000..00026b7f3f --- /dev/null +++ b/src/drivers/i2c/at24rf08c/romstage.c @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +void lenovo_mainboard_eeprom_lock(void) +{ + printk(BIOS_DEBUG, "Locking EEPROM RFID\n"); + + for (int i = 0; i < 8; i++) { + /* After a register write AT24RF08C sometimes stops responding. + Retry several times in case of failure. */ + for (int j = 0; j < 100; j++) + if (smbus_write_byte(0x5c, i, 0x0f) >= 0) + break; + } +} diff --git a/src/mainboard/lenovo/l520/Kconfig b/src/mainboard/lenovo/l520/Kconfig index 6f7c433828..c3e318e328 100644 --- a/src/mainboard/lenovo/l520/Kconfig +++ b/src/mainboard/lenovo/l520/Kconfig @@ -7,6 +7,7 @@ config BOARD_SPECIFIC_OPTIONS select AZALIA_USE_LEGACY_VERB_TABLE select BOARD_ROMSIZE_KB_4096 select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select EC_LENOVO_H8 select EC_LENOVO_PMH7 select HAVE_ACPI_RESUME diff --git a/src/mainboard/lenovo/l520/Makefile.mk b/src/mainboard/lenovo/l520/Makefile.mk index 7611194339..2afc15156d 100644 --- a/src/mainboard/lenovo/l520/Makefile.mk +++ b/src/mainboard/lenovo/l520/Makefile.mk @@ -2,5 +2,6 @@ bootblock-y += gpio.c romstage-y += gpio.c +romstage-y += early_init.c ramstage-$(CONFIG_MAINBOARD_USE_LIBGFXINIT) += gma-mainboard.ads diff --git a/src/mainboard/lenovo/l520/early_init.c b/src/mainboard/lenovo/l520/early_init.c new file mode 100644 index 0000000000..7d36c4b990 --- /dev/null +++ b/src/mainboard/lenovo/l520/early_init.c @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include + +void mainboard_early_init(bool s3resume) +{ + lenovo_mainboard_eeprom_lock(); +} diff --git a/src/mainboard/lenovo/s230u/Kconfig b/src/mainboard/lenovo/s230u/Kconfig index 5fc7570aa9..ca0a639edd 100644 --- a/src/mainboard/lenovo/s230u/Kconfig +++ b/src/mainboard/lenovo/s230u/Kconfig @@ -7,6 +7,7 @@ config BOARD_SPECIFIC_OPTIONS select AZALIA_USE_LEGACY_VERB_TABLE select BOARD_ROMSIZE_KB_12288 select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select EC_ACPI select EC_COMPAL_ENE932 select GFX_GMA_PANEL_1_ON_LVDS diff --git a/src/mainboard/lenovo/s230u/early_init.c b/src/mainboard/lenovo/s230u/early_init.c index ba52b7e7c9..1f25091620 100644 --- a/src/mainboard/lenovo/s230u/early_init.c +++ b/src/mainboard/lenovo/s230u/early_init.c @@ -2,8 +2,10 @@ #include #include +#include #include #include +#include #include #include "ec.h" @@ -56,3 +58,8 @@ void mb_get_spd_map(struct spd_info *spdi) spdi->addresses[0] = SPD_MEMORY_DOWN; spdi->spd_index = spd_index; } + +void mainboard_early_init(bool s3resume) +{ + lenovo_mainboard_eeprom_lock(); +} diff --git a/src/mainboard/lenovo/t420/Kconfig b/src/mainboard/lenovo/t420/Kconfig index 54d1cda106..b14885eb6a 100644 --- a/src/mainboard/lenovo/t420/Kconfig +++ b/src/mainboard/lenovo/t420/Kconfig @@ -22,6 +22,7 @@ config BOARD_SPECIFIC_OPTIONS select INTEL_INT15 select DRIVERS_RICOH_RCE822 select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select MEMORY_MAPPED_TPM select MAINBOARD_HAS_TPM1 select MAINBOARD_HAS_LIBGFXINIT diff --git a/src/mainboard/lenovo/t420/early_init.c b/src/mainboard/lenovo/t420/early_init.c index b14fea93a6..89e3514316 100644 --- a/src/mainboard/lenovo/t420/early_init.c +++ b/src/mainboard/lenovo/t420/early_init.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include @@ -33,4 +34,5 @@ static void hybrid_graphics_init(void) void mainboard_early_init(bool s3resume) { hybrid_graphics_init(); + lenovo_mainboard_eeprom_lock(); } diff --git a/src/mainboard/lenovo/t420s/Kconfig b/src/mainboard/lenovo/t420s/Kconfig index bbfc9d0ef5..bf8a9cf0f3 100644 --- a/src/mainboard/lenovo/t420s/Kconfig +++ b/src/mainboard/lenovo/t420s/Kconfig @@ -8,6 +8,7 @@ config BOARD_SPECIFIC_OPTIONS select BOARD_ROMSIZE_KB_8192 select DRIVERS_LENOVO_HYBRID_GRAPHICS select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select EC_LENOVO_H8 select EC_LENOVO_PMH7 select GFX_GMA_PANEL_1_ON_LVDS diff --git a/src/mainboard/lenovo/t420s/early_init.c b/src/mainboard/lenovo/t420s/early_init.c index b14fea93a6..89e3514316 100644 --- a/src/mainboard/lenovo/t420s/early_init.c +++ b/src/mainboard/lenovo/t420s/early_init.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include @@ -33,4 +34,5 @@ static void hybrid_graphics_init(void) void mainboard_early_init(bool s3resume) { hybrid_graphics_init(); + lenovo_mainboard_eeprom_lock(); } diff --git a/src/mainboard/lenovo/t430/Kconfig b/src/mainboard/lenovo/t430/Kconfig index fe1d5fcd7b..2b6eb17e9c 100644 --- a/src/mainboard/lenovo/t430/Kconfig +++ b/src/mainboard/lenovo/t430/Kconfig @@ -8,6 +8,7 @@ config BOARD_SPECIFIC_OPTIONS select BOARD_ROMSIZE_KB_12288 select DRIVERS_LENOVO_HYBRID_GRAPHICS select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select DRIVERS_RICOH_RCE822 select EC_LENOVO_H8 select EC_LENOVO_PMH7 diff --git a/src/mainboard/lenovo/t430/early_init.c b/src/mainboard/lenovo/t430/early_init.c index 8306e0e720..d982660856 100644 --- a/src/mainboard/lenovo/t430/early_init.c +++ b/src/mainboard/lenovo/t430/early_init.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -35,4 +36,5 @@ static void hybrid_graphics_init(void) void mainboard_early_init(bool s3resume) { hybrid_graphics_init(); + lenovo_mainboard_eeprom_lock(); } diff --git a/src/mainboard/lenovo/t430s/Kconfig b/src/mainboard/lenovo/t430s/Kconfig index 1e80628384..c7c0ffb347 100644 --- a/src/mainboard/lenovo/t430s/Kconfig +++ b/src/mainboard/lenovo/t430s/Kconfig @@ -29,6 +29,7 @@ config BOARD_SPECIFIC_OPTIONS select MAINBOARD_USES_IFD_GBE_REGION select DRIVERS_RICOH_RCE822 if BOARD_LENOVO_T431S select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select HAVE_SPD_IN_CBFS if BOARD_LENOVO_T431S # Workaround for EC/KBC IRQ1. diff --git a/src/mainboard/lenovo/t430s/variants/t430s/romstage.c b/src/mainboard/lenovo/t430s/variants/t430s/romstage.c index 211ec2d345..c658a34a4d 100644 --- a/src/mainboard/lenovo/t430s/variants/t430s/romstage.c +++ b/src/mainboard/lenovo/t430s/variants/t430s/romstage.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -20,4 +21,6 @@ void mainboard_early_init(bool s3resume) // Hide disabled dGPU device pci_and_config32(HOST_BRIDGE, DEVEN, ~DEVEN_PEG10); } + + lenovo_mainboard_eeprom_lock(); } diff --git a/src/mainboard/lenovo/t430s/variants/t431s/romstage.c b/src/mainboard/lenovo/t430s/variants/t431s/romstage.c index 9a78bac813..e1e5029e7c 100644 --- a/src/mainboard/lenovo/t430s/variants/t431s/romstage.c +++ b/src/mainboard/lenovo/t430s/variants/t431s/romstage.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include +#include void mb_get_spd_map(struct spd_info *spdi) { @@ -9,3 +11,8 @@ void mb_get_spd_map(struct spd_info *spdi) spdi->addresses[2] = 0x51; spdi->spd_index = 0; } + +void mainboard_early_init(bool s3resume) +{ + lenovo_mainboard_eeprom_lock(); +} diff --git a/src/mainboard/lenovo/t520/Kconfig b/src/mainboard/lenovo/t520/Kconfig index ed424ed0a7..cef7750a40 100644 --- a/src/mainboard/lenovo/t520/Kconfig +++ b/src/mainboard/lenovo/t520/Kconfig @@ -27,6 +27,7 @@ config BOARD_LENOVO_BASEBOARD_T520 select INTEL_GMA_HAVE_VBT if BOARD_LENOVO_T520 select MAINBOARD_USES_IFD_GBE_REGION select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK # Workaround for EC/KBC IRQ1. select SERIRQ_CONTINUOUS_MODE diff --git a/src/mainboard/lenovo/t520/early_init.c b/src/mainboard/lenovo/t520/early_init.c index ba98ec700f..198d603ff7 100644 --- a/src/mainboard/lenovo/t520/early_init.c +++ b/src/mainboard/lenovo/t520/early_init.c @@ -1,12 +1,13 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include +#include +#include #include #include -#include -#include static void hybrid_graphics_init(void) { @@ -37,4 +38,5 @@ static void hybrid_graphics_init(void) void mainboard_early_init(bool s3resume) { hybrid_graphics_init(); + lenovo_mainboard_eeprom_lock(); } diff --git a/src/mainboard/lenovo/t530/Kconfig b/src/mainboard/lenovo/t530/Kconfig index a825e1186b..8830c39301 100644 --- a/src/mainboard/lenovo/t530/Kconfig +++ b/src/mainboard/lenovo/t530/Kconfig @@ -6,6 +6,7 @@ config BOARD_LENOVO_BASEBOARD_T530 select BOARD_ROMSIZE_KB_12288 select DRIVERS_LENOVO_HYBRID_GRAPHICS select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select EC_LENOVO_H8 select EC_LENOVO_PMH7 select GFX_GMA_PANEL_1_ON_LVDS diff --git a/src/mainboard/lenovo/t530/early_init.c b/src/mainboard/lenovo/t530/early_init.c index 429ab2857a..b7bc35adbb 100644 --- a/src/mainboard/lenovo/t530/early_init.c +++ b/src/mainboard/lenovo/t530/early_init.c @@ -1,11 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include +#include #include #include -#include static void hybrid_graphics_init(void) { @@ -36,4 +37,5 @@ static void hybrid_graphics_init(void) void mainboard_early_init(bool s3resume) { hybrid_graphics_init(); + lenovo_mainboard_eeprom_lock(); } diff --git a/src/mainboard/lenovo/x131e/Kconfig b/src/mainboard/lenovo/x131e/Kconfig index c59660adf1..3c6d453100 100644 --- a/src/mainboard/lenovo/x131e/Kconfig +++ b/src/mainboard/lenovo/x131e/Kconfig @@ -7,6 +7,7 @@ config BOARD_SPECIFIC_OPTIONS select AZALIA_USE_LEGACY_VERB_TABLE select BOARD_ROMSIZE_KB_12288 select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select EC_LENOVO_H8 select GFX_GMA_PANEL_1_ON_LVDS select HAVE_ACPI_RESUME diff --git a/src/mainboard/lenovo/x131e/Makefile.mk b/src/mainboard/lenovo/x131e/Makefile.mk index 7611194339..2afc15156d 100644 --- a/src/mainboard/lenovo/x131e/Makefile.mk +++ b/src/mainboard/lenovo/x131e/Makefile.mk @@ -2,5 +2,6 @@ bootblock-y += gpio.c romstage-y += gpio.c +romstage-y += early_init.c ramstage-$(CONFIG_MAINBOARD_USE_LIBGFXINIT) += gma-mainboard.ads diff --git a/src/mainboard/lenovo/x131e/early_init.c b/src/mainboard/lenovo/x131e/early_init.c new file mode 100644 index 0000000000..7d36c4b990 --- /dev/null +++ b/src/mainboard/lenovo/x131e/early_init.c @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include + +void mainboard_early_init(bool s3resume) +{ + lenovo_mainboard_eeprom_lock(); +} diff --git a/src/mainboard/lenovo/x1_carbon_gen1/Kconfig b/src/mainboard/lenovo/x1_carbon_gen1/Kconfig index 39daee8b0d..84b8fedaa4 100644 --- a/src/mainboard/lenovo/x1_carbon_gen1/Kconfig +++ b/src/mainboard/lenovo/x1_carbon_gen1/Kconfig @@ -8,6 +8,7 @@ config BOARD_SPECIFIC_OPTIONS select BOARD_ROMSIZE_KB_12288 select DRIVERS_RICOH_RCE822 select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select EC_LENOVO_H8 select EC_LENOVO_PMH7 select GFX_GMA_PANEL_1_ON_LVDS diff --git a/src/mainboard/lenovo/x1_carbon_gen1/early_init.c b/src/mainboard/lenovo/x1_carbon_gen1/early_init.c index 7cfc5d9a0e..880635280e 100644 --- a/src/mainboard/lenovo/x1_carbon_gen1/early_init.c +++ b/src/mainboard/lenovo/x1_carbon_gen1/early_init.c @@ -1,8 +1,10 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include +#include static unsigned int get_spd_index(void) { @@ -40,3 +42,8 @@ void mb_get_spd_map(struct spd_info *spdi) spdi->addresses[2] = SPD_MEMORY_DOWN; spdi->spd_index = get_spd_index(); } + +void mainboard_early_init(bool s3resume) +{ + lenovo_mainboard_eeprom_lock(); +} diff --git a/src/mainboard/lenovo/x220/Kconfig b/src/mainboard/lenovo/x220/Kconfig index 3b4c6ce0ea..8291965976 100644 --- a/src/mainboard/lenovo/x220/Kconfig +++ b/src/mainboard/lenovo/x220/Kconfig @@ -8,6 +8,7 @@ config BOARD_SPECIFIC_OPTIONS select BOARD_ROMSIZE_KB_8192 select DRIVERS_RICOH_RCE822 select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select EC_LENOVO_H8 select EC_LENOVO_PMH7 select GFX_GMA_PANEL_1_ON_LVDS diff --git a/src/mainboard/lenovo/x220/early_init.c b/src/mainboard/lenovo/x220/early_init.c index 826796eddf..492614bdd6 100644 --- a/src/mainboard/lenovo/x220/early_init.c +++ b/src/mainboard/lenovo/x220/early_init.c @@ -2,7 +2,14 @@ #include #include +#include +#include void mainboard_fill_pei_data(struct pei_data *pei_data) { } + +void mainboard_early_init(bool s3resume) +{ + lenovo_mainboard_eeprom_lock(); +} diff --git a/src/mainboard/lenovo/x230/Kconfig b/src/mainboard/lenovo/x230/Kconfig index 2980c91b3a..9b35477c5b 100644 --- a/src/mainboard/lenovo/x230/Kconfig +++ b/src/mainboard/lenovo/x230/Kconfig @@ -24,6 +24,7 @@ config BOARD_SPECIFIC_OPTIONS select INTEL_INT15 select DRIVERS_RICOH_RCE822 select DRIVER_LENOVO_SERIALS + select DRIVER_LENOVO_SERIALS_EARLY_LOCK select MEMORY_MAPPED_TPM select MAINBOARD_HAS_TPM1 if BOARD_LENOVO_X230 || BOARD_LENOVO_X230T || BOARD_LENOVO_X230_EDP select MAINBOARD_HAS_LIBGFXINIT diff --git a/src/mainboard/lenovo/x230/Makefile.mk b/src/mainboard/lenovo/x230/Makefile.mk index 5cbdb7dc1b..5a4ec5c21e 100644 --- a/src/mainboard/lenovo/x230/Makefile.mk +++ b/src/mainboard/lenovo/x230/Makefile.mk @@ -4,6 +4,8 @@ bootblock-y += variants/$(VARIANT_DIR)/gpio.c romstage-y += variants/$(VARIANT_DIR)/gpio.c ramstage-y += variants/$(VARIANT_DIR)/hda_verb.c +romstage-y += early_init.c + ifeq ($(CONFIG_BOARD_LENOVO_X230_EDP),y) ramstage-$(CONFIG_MAINBOARD_USE_LIBGFXINIT) += variants/x230_edp/gma-mainboard.ads else diff --git a/src/mainboard/lenovo/x230/early_init.c b/src/mainboard/lenovo/x230/early_init.c new file mode 100644 index 0000000000..7d36c4b990 --- /dev/null +++ b/src/mainboard/lenovo/x230/early_init.c @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include + +void mainboard_early_init(bool s3resume) +{ + lenovo_mainboard_eeprom_lock(); +}