|
53 | 53 | #include "pwm_chip.h" |
54 | 54 | #include "spi.h" |
55 | 55 | #include "spi_chip.h" |
| 56 | +#include "spi_flash.h" |
56 | 57 | #include "switch.h" |
57 | 58 | #include "system.h" |
58 | 59 | #include "task.h" |
@@ -370,14 +371,68 @@ void board_reset_pd_mcu(void) |
370 | 371 |
|
371 | 372 | } |
372 | 373 |
|
| 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 | + |
373 | 428 | /** |
374 | 429 | * Check the plug-in AC then power on system setting. |
375 | 430 | */ |
376 | 431 | bool ac_poweron_check(void) |
377 | 432 | { |
378 | 433 | uint8_t memcap; |
379 | 434 |
|
380 | | - system_get_bbram(SYSTEM_BBRAM_IDX_AC_BOOT, &memcap); |
| 435 | + board_spi_read_byte(SPI_AC_BOOT_OFFSET, &memcap); |
381 | 436 |
|
382 | 437 | return memcap ? true : false; |
383 | 438 | } |
@@ -648,7 +703,7 @@ static void board_init(void) |
648 | 703 | { |
649 | 704 | uint8_t memcap; |
650 | 705 |
|
651 | | - system_get_bbram(SYSTEM_BBRAM_IDX_AC_BOOT, &memcap); |
| 706 | + board_spi_read_byte(SPI_AC_BOOT_OFFSET, &memcap); |
652 | 707 |
|
653 | 708 | if (memcap && !ac_boot_status()) |
654 | 709 | *host_get_customer_memmap(0x48) = (memcap & BIT(0)); |
@@ -1203,24 +1258,32 @@ static int cmd_spimux(int argc, char **argv) |
1203 | 1258 | if (!parse_bool(argv[1], &enable)) |
1204 | 1259 | return EC_ERROR_PARAM1; |
1205 | 1260 |
|
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); |
1217 | 1262 | } |
1218 | 1263 | return EC_SUCCESS; |
1219 | 1264 | } |
1220 | 1265 | DECLARE_CONSOLE_COMMAND(spimux, cmd_spimux, |
1221 | 1266 | "[enable/disable]", |
1222 | 1267 | "Set if spi CLK is in SPI mode (true) or PWM mode"); |
1223 | 1268 |
|
| 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 | + |
1224 | 1287 | #define FP_LOCKOUT_TIMEOUT (8 * SECOND) |
1225 | 1288 | static void fingerprint_ctrl_detection_deferred(void); |
1226 | 1289 | DECLARE_DEFERRED(fingerprint_ctrl_detection_deferred); |
|
0 commit comments