Skip to content

Commit b307d0f

Browse files
authored
Merge pull request #464 from FrameworkComputer/hx30.save_state_in_spi
Hx30.save state in spi
2 parents 6867bb1 + 0178244 commit b307d0f

3 files changed

Lines changed: 90 additions & 15 deletions

File tree

board/hx30/board.c

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "pwm_chip.h"
5454
#include "spi.h"
5555
#include "spi_chip.h"
56+
#include "spi_flash.h"
5657
#include "switch.h"
5758
#include "system.h"
5859
#include "task.h"
@@ -370,14 +371,68 @@ void board_reset_pd_mcu(void)
370371

371372
}
372373

374+
#define SPI_FLAGS_REGION 0x80000
375+
376+
void spi_mux_control(int enable)
377+
{
378+
if (enable) {
379+
/* Disable LED drv */
380+
gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 0);
381+
/* Set GPIO56 as SPI for access SPI ROM */
382+
gpio_set_alternate_function(1, 0x4000, 2);
383+
} else {
384+
/* Enable LED drv */
385+
gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 1);
386+
/* Set GPIO56 as SPI for access SPI ROM */
387+
gpio_set_alternate_function(1, 0x4000, 1);
388+
}
389+
}
390+
391+
392+
void board_spi_read_byte(uint8_t offset, uint8_t *data)
393+
{
394+
int rv;
395+
396+
spi_mux_control(1);
397+
398+
rv = spi_flash_read(data, SPI_FLAGS_REGION + offset, 0x01);
399+
if (rv != EC_SUCCESS)
400+
CPRINTS("SPI fail to read");
401+
402+
CPRINTS("%s, offset:0x%02x, data:0x%02x", __func__, offset, *data);
403+
404+
spi_mux_control(0);
405+
}
406+
407+
void board_spi_write_byte(uint8_t offset, uint8_t data)
408+
{
409+
int rv;
410+
411+
spi_mux_control(1);
412+
413+
rv = spi_flash_erase(SPI_FLAGS_REGION, 0x1000);
414+
415+
if (rv != EC_SUCCESS)
416+
CPRINTS("SPI fail to erase");
417+
418+
rv = spi_flash_write(SPI_FLAGS_REGION + offset, 0x01, &data);
419+
420+
if (rv != EC_SUCCESS)
421+
CPRINTS("SPI fail to write");
422+
423+
CPRINTS("%s, offset:0x%02x, data:0x%02x", __func__, offset, data);
424+
425+
spi_mux_control(0);
426+
}
427+
373428
/**
374429
* Check the plug-in AC then power on system setting.
375430
*/
376431
bool ac_poweron_check(void)
377432
{
378433
uint8_t memcap;
379434

380-
system_get_bbram(SYSTEM_BBRAM_IDX_AC_BOOT, &memcap);
435+
board_spi_read_byte(SPI_AC_BOOT_OFFSET, &memcap);
381436

382437
return memcap ? true : false;
383438
}
@@ -648,7 +703,7 @@ static void board_init(void)
648703
{
649704
uint8_t memcap;
650705

651-
system_get_bbram(SYSTEM_BBRAM_IDX_AC_BOOT, &memcap);
706+
board_spi_read_byte(SPI_AC_BOOT_OFFSET, &memcap);
652707

653708
if (memcap && !ac_boot_status())
654709
*host_get_customer_memmap(0x48) = (memcap & BIT(0));
@@ -1203,24 +1258,32 @@ static int cmd_spimux(int argc, char **argv)
12031258
if (!parse_bool(argv[1], &enable))
12041259
return EC_ERROR_PARAM1;
12051260

1206-
if (enable) {
1207-
/* Disable LED drv */
1208-
gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 0);
1209-
/* Set GPIO56 as SPI for access SPI ROM */
1210-
gpio_set_alternate_function(1, 0x4000, 2);
1211-
} else {
1212-
/* Enable LED drv */
1213-
gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 1);
1214-
/* Set GPIO56 as SPI for access SPI ROM */
1215-
gpio_set_alternate_function(1, 0x4000, 1);
1216-
}
1261+
spi_mux_control(enable);
12171262
}
12181263
return EC_SUCCESS;
12191264
}
12201265
DECLARE_CONSOLE_COMMAND(spimux, cmd_spimux,
12211266
"[enable/disable]",
12221267
"Set if spi CLK is in SPI mode (true) or PWM mode");
12231268

1269+
1270+
static int cmd_boardspicontrol(int argc, char **argv)
1271+
{
1272+
uint8_t data;
1273+
1274+
if (!strcasecmp(argv[1], "read")) {
1275+
board_spi_read_byte(0x01, &data);
1276+
CPRINTS("DEBUG: cmd get data:0x%02x", data);
1277+
} else if (!strcasecmp(argv[1], "write")) {
1278+
board_spi_write_byte(0x01, 0xAA);
1279+
}
1280+
1281+
return EC_SUCCESS;
1282+
}
1283+
DECLARE_CONSOLE_COMMAND(boardspi, cmd_boardspicontrol,
1284+
"[read/write]",
1285+
"test");
1286+
12241287
#define FP_LOCKOUT_TIMEOUT (8 * SECOND)
12251288
static void fingerprint_ctrl_detection_deferred(void);
12261289
DECLARE_DEFERRED(fingerprint_ctrl_detection_deferred);

board/hx30/board.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@
336336
*/
337337
#define CONFIG_FLASH_SIZE 0x100000
338338
#define CONFIG_SPI_FLASH_W25Q80
339+
#define SPI_AC_BOOT_OFFSET 0x00
339340

340341
/*
341342
* Enable extra SPI flash and generic SPI
@@ -727,6 +728,8 @@ void board_reset_pd_mcu(void);
727728
/* P sensor */
728729
void psensor_interrupt(enum gpio_signal signal);
729730

731+
void board_spi_read_byte(uint8_t offset, uint8_t *data);
732+
void board_spi_write_byte(uint8_t offset, uint8_t data);
730733

731734
/* SOC */
732735
void soc_signal_interrupt(enum gpio_signal signal);

board/hx30/host_command_customization.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,20 @@ void set_non_acpi_mode(int enable)
5656

5757
static void sci_enable(void)
5858
{
59+
uint8_t dataInSPI;
60+
int dataInEMI;
61+
5962
if (*host_get_customer_memmap(0x00) & BIT(0)) {
6063
/* when host set EC driver ready flag, EC need to enable SCI */
6164
lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, SCI_HOST_EVENT_MASK);
6265
update_soc_power_limit(true, false);
63-
system_set_bbram(SYSTEM_BBRAM_IDX_AC_BOOT, ac_boot_status());
66+
67+
/* check the Flag in EEPROM and EMI, if values are different, write the value in EEPROM */
68+
board_spi_read_byte(SPI_AC_BOOT_OFFSET, &dataInSPI);
69+
dataInEMI = ac_boot_status();
70+
if ((int)dataInSPI != dataInEMI)
71+
board_spi_write_byte(SPI_AC_BOOT_OFFSET, (uint8_t)dataInEMI);
72+
6473
set_non_acpi_mode(0);
6574
} else
6675
hook_call_deferred(&sci_enable_data, 250 * MSEC);
@@ -149,7 +158,7 @@ static enum ec_status factory_mode(struct host_cmd_handler_args *args)
149158
system_set_bbram(STSTEM_BBRAM_IDX_CHASSIS_MAGIC, EC_PARAM_CHASSIS_BBRAM_MAGIC);
150159
system_set_bbram(STSTEM_BBRAM_IDX_CHASSIS_VTR_OPEN, 0);
151160
system_set_bbram(STSTEM_BBRAM_IDX_CHASSIS_WAS_OPEN, 0);
152-
system_set_bbram(SYSTEM_BBRAM_IDX_AC_BOOT, 0);
161+
board_spi_write_byte(SPI_AC_BOOT_OFFSET, 0);
153162
system_set_bbram(STSTEM_BBRAM_IDX_FP_LED_LEVEL, 0);
154163
}
155164

0 commit comments

Comments
 (0)