|
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,6 +371,58 @@ void board_reset_pd_mcu(void) |
370 | 371 |
|
371 | 372 | } |
372 | 373 |
|
| 374 | +#define SPI_BLANK_OFFSET 0x3A000 |
| 375 | + |
| 376 | +void spi_mux_control(int enable) |
| 377 | +{ |
| 378 | + if (enable) { |
| 379 | + CPRINTS("switch to spi mode"); |
| 380 | + /* Disable LED drv */ |
| 381 | + gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 0); |
| 382 | + /* Set GPIO56 as SPI for access SPI ROM */ |
| 383 | + gpio_set_alternate_function(1, 0x4000, 2); |
| 384 | + } else { |
| 385 | + CPRINTS("switch to pwm mode"); |
| 386 | + /* Enable LED drv */ |
| 387 | + gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 1); |
| 388 | + /* Set GPIO56 as SPI for access SPI ROM */ |
| 389 | + gpio_set_alternate_function(1, 0x4000, 1); |
| 390 | + } |
| 391 | +} |
| 392 | + |
| 393 | + |
| 394 | +void board_spi_read_byte(uint8_t offset, uint8_t *data) |
| 395 | +{ |
| 396 | + int rv; |
| 397 | + |
| 398 | + spi_mux_control(1); |
| 399 | + |
| 400 | + rv = spi_flash_read(data, SPI_BLANK_OFFSET + offset, 0x01); |
| 401 | + if (rv != EC_SUCCESS) |
| 402 | + CPRINTS("SPI fail to read"); |
| 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_BLANK_OFFSET, 0x1000); |
| 414 | + |
| 415 | + if (rv != EC_SUCCESS) |
| 416 | + CPRINTS("SPI fail to erase"); |
| 417 | + |
| 418 | + rv = spi_flash_write(SPI_BLANK_OFFSET + offset, 0x01, &data); |
| 419 | + |
| 420 | + if (rv != EC_SUCCESS) |
| 421 | + CPRINTS("SPI fail to write"); |
| 422 | + |
| 423 | + spi_mux_control(0); |
| 424 | +} |
| 425 | + |
373 | 426 | /** |
374 | 427 | * Check the plug-in AC then power on system setting. |
375 | 428 | */ |
@@ -1191,24 +1244,32 @@ static int cmd_spimux(int argc, char **argv) |
1191 | 1244 | if (!parse_bool(argv[1], &enable)) |
1192 | 1245 | return EC_ERROR_PARAM1; |
1193 | 1246 |
|
1194 | | - if (enable) { |
1195 | | - /* Disable LED drv */ |
1196 | | - gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 0); |
1197 | | - /* Set GPIO56 as SPI for access SPI ROM */ |
1198 | | - gpio_set_alternate_function(1, 0x4000, 2); |
1199 | | - } else { |
1200 | | - /* Enable LED drv */ |
1201 | | - gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 1); |
1202 | | - /* Set GPIO56 as SPI for access SPI ROM */ |
1203 | | - gpio_set_alternate_function(1, 0x4000, 1); |
1204 | | - } |
| 1247 | + spi_mux_control(enable); |
1205 | 1248 | } |
1206 | 1249 | return EC_SUCCESS; |
1207 | 1250 | } |
1208 | 1251 | DECLARE_CONSOLE_COMMAND(spimux, cmd_spimux, |
1209 | 1252 | "[enable/disable]", |
1210 | 1253 | "Set if spi CLK is in SPI mode (true) or PWM mode"); |
1211 | 1254 |
|
| 1255 | + |
| 1256 | +static int cmd_boardspicontrol(int argc, char **argv) |
| 1257 | +{ |
| 1258 | + uint8_t data; |
| 1259 | + |
| 1260 | + if (!strcasecmp(argv[1], "read")) { |
| 1261 | + board_spi_read_byte(0x00, &data); |
| 1262 | + CPRINTS("DEBUG: cmd get data:0x%02x", data); |
| 1263 | + } else if (!strcasecmp(argv[1], "write")) { |
| 1264 | + board_spi_write_byte(0x00, 0xAA); |
| 1265 | + } |
| 1266 | + |
| 1267 | + return EC_SUCCESS; |
| 1268 | +} |
| 1269 | +DECLARE_CONSOLE_COMMAND(boardspi, cmd_boardspicontrol, |
| 1270 | + "[read/write]", |
| 1271 | + "test"); |
| 1272 | + |
1212 | 1273 | #define FP_LOCKOUT_TIMEOUT (8 * SECOND) |
1213 | 1274 | static void fingerprint_ctrl_detection_deferred(void); |
1214 | 1275 | DECLARE_DEFERRED(fingerprint_ctrl_detection_deferred); |
|
0 commit comments