Skip to content

Commit 4bdabec

Browse files
committed
Merge remote-tracking branch 'upstream/hx20' into dh/feature/rorw
2 parents 0fdb698 + c1d06ea commit 4bdabec

11 files changed

+327
-32
lines changed

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
2222
- name: checkpatch
2323
run: |
24-
git diff origin/${{ github.base_ref }} | ./checkpatch.pl --mailback --no-tree --ignore MAINTAINERS,FILE_PATH_CHANGES - > checkpatch.txt || true
24+
git diff origin/${{ github.base_ref }} | ./checkpatch.pl --mailback --no-tree --ignore MAINTAINERS,FILE_PATH_CHANGES,SPDX_LICENSE_TAG - > checkpatch.txt || true
2525
if [ -s checkpatch.txt ]; then
2626
errors=$(cat checkpatch.txt)
2727
errors="${errors//'%'/'%25'}"

board/hx20/board.c

+23-15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "chipset.h"
2222
#include "console.h"
2323
#include "cypress5525.h"
24+
#include "diagnostics.h"
2425
#include "driver/als_opt3001.h"
2526
#include "driver/accel_kionix.h"
2627
#include "driver/accel_kx022.h"
@@ -53,6 +54,7 @@
5354
#include "pwm_chip.h"
5455
#include "spi.h"
5556
#include "spi_chip.h"
57+
#include "spi_flash.h"
5658
#include "switch.h"
5759
#include "system.h"
5860
#include "task.h"
@@ -71,6 +73,7 @@
7173
#include "keyboard_8042.h"
7274
#include "keyboard_8042_sharedlib.h"
7375
#include "host_command_customization.h"
76+
#include "flash_storage.h"
7477

7578
/* Console output macros */
7679
#define CPUTS(outstr) cputs(CC_LPC, outstr)
@@ -360,6 +363,21 @@ void board_reset_pd_mcu(void)
360363

361364
}
362365

366+
void spi_mux_control(int enable)
367+
{
368+
if (enable) {
369+
/* Disable LED drv */
370+
gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 0);
371+
/* Set GPIO56 as SPI for access SPI ROM */
372+
gpio_set_alternate_function(1, 0x4000, 2);
373+
} else {
374+
/* Enable LED drv */
375+
gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 1);
376+
/* Set GPIO56 as SPI for access SPI ROM */
377+
gpio_set_alternate_function(1, 0x4000, 1);
378+
}
379+
}
380+
363381
static int power_button_pressed_on_boot;
364382
int poweron_reason_powerbtn(void)
365383
{
@@ -585,15 +603,15 @@ void charger_psys_enable(uint8_t enable)
585603
static void board_init(void)
586604
{
587605
int version = board_get_version();
588-
uint8_t memcap;
589606

590607
if (version > 6)
591608
gpio_set_flags(GPIO_EN_INVPWR, GPIO_OUT_LOW);
592609

593-
system_get_bbram(SYSTEM_BBRAM_IDX_AC_BOOT, &memcap);
610+
if (flash_storage_get(FLASH_FLAGS_ACPOWERON) && !ac_boot_status())
611+
*host_get_customer_memmap(0x48) = flash_storage_get(FLASH_FLAGS_ACPOWERON);
594612

595-
if (memcap && !ac_boot_status())
596-
*host_get_customer_memmap(0x48) = (memcap & BIT(0));
613+
if (flash_storage_get(FLASH_FLAGS_STANDALONE))
614+
set_standalone_mode(1);
597615

598616
check_chassis_open(1);
599617

@@ -1137,17 +1155,7 @@ static int cmd_spimux(int argc, char **argv)
11371155
if (!parse_bool(argv[1], &enable))
11381156
return EC_ERROR_PARAM1;
11391157

1140-
if (enable){
1141-
/* Disable LED drv */
1142-
gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 0);
1143-
/* Set GPIO56 as SPI for access SPI ROM */
1144-
gpio_set_alternate_function(1, 0x4000, 2);
1145-
} else {
1146-
/* Enable LED drv */
1147-
gpio_set_level(GPIO_TYPEC_G_DRV2_EN, 1);
1148-
/* Set GPIO56 as SPI for access SPI ROM */
1149-
gpio_set_alternate_function(1, 0x4000, 1);
1150-
}
1158+
spi_mux_control(enable);
11511159
}
11521160
return EC_SUCCESS;
11531161
}

board/hx20/board.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,6 @@ void board_reset_pd_mcu(void);
728728
/* P sensor */
729729
void psensor_interrupt(enum gpio_signal signal);
730730

731-
732731
/* SOC */
733732
void soc_signal_interrupt(enum gpio_signal signal);
734733

@@ -770,6 +769,8 @@ void update_me_change(int change);
770769

771770
int poweron_reason_powerbtn(void);
772771

772+
void spi_mux_control(int enable);
773+
773774
#ifdef CONFIG_LOW_POWER_IDLE
774775
void board_prepare_for_deep_sleep(void);
775776
void board_resume_from_deep_sleep(void);

board/hx20/build.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CHIP_VARIANT:=mec152x_3400
1717

1818
CHIP_SPI_SIZE_KB:=512
1919

20-
board-y=board.o led.o power_sequence.o cypress5525.o ucsi.o diagnostics.o cpu_power.o
20+
board-y=board.o led.o power_sequence.o cypress5525.o ucsi.o diagnostics.o cpu_power.o flash_storage.o
2121
board-$(CONFIG_BATTERY_SMART)+=battery.o
2222
board-$(CONFIG_FANS)+=fan.o
2323
board-$(CONFIG_KEYBOARD_CUSTOMIZATION)+=keyboard_customization.o

board/hx20/diagnostics.c

+22-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ uint8_t bios_complete;
3232
uint8_t fan_seen;
3333
uint8_t s0_seen;
3434
uint8_t run_diagnostics;
35+
36+
int standalone_mode;
37+
38+
void set_standalone_mode(int enable)
39+
{
40+
CPRINTS("set standalone = %d", enable);
41+
standalone_mode = enable;
42+
}
43+
44+
int get_standalone_mode(void)
45+
{
46+
return standalone_mode;
47+
}
48+
3549
void reset_diagnostics(void)
3650
{
3751
hw_diagnostics =0;
@@ -100,9 +114,9 @@ bool diagnostics_tick(void)
100114
set_hw_diagnostic(DIAGNOSTICS_NO_S0, true);
101115
}
102116

103-
if (charge_get_state() == PWR_STATE_ERROR){
104-
set_hw_diagnostic(DIAGNOSTICS_HW_NO_BATTERY, true);
105-
}
117+
if ((charge_get_state() == PWR_STATE_ERROR) && !standalone_mode) {
118+
set_hw_diagnostic(DIAGNOSTICS_HW_NO_BATTERY, true);
119+
}
106120

107121
if (hw_diagnostic_tick & 0x01) {
108122
/*off*/
@@ -163,13 +177,13 @@ static void diagnostic_check_tempsensor_deferred(void)
163177
device_id[0] = get_hardware_id(ADC_TP_BOARD_ID);
164178
device_id[1] = get_hardware_id(ADC_AUDIO_BOARD_ID);
165179

166-
if (device_id[0] <= BOARD_VERSION_1 || device_id[0] >= BOARD_VERSION_14 ||
167-
(high_adc[0] - low_adc[0]) > ADC_NC_DELTA) {
180+
if ((device_id[0] <= BOARD_VERSION_1 || device_id[0] >= BOARD_VERSION_14 ||
181+
(high_adc[0] - low_adc[0]) > ADC_NC_DELTA) && !standalone_mode) {
168182
set_hw_diagnostic(DIAGNOSTICS_TOUCHPAD, true);
169183
}
170184

171-
if (device_id[1] <= BOARD_VERSION_1 || device_id[1] >= BOARD_VERSION_14 ||
172-
(high_adc[1] - low_adc[1]) > ADC_NC_DELTA) {
185+
if ((device_id[1] <= BOARD_VERSION_1 || device_id[1] >= BOARD_VERSION_14 ||
186+
(high_adc[1] - low_adc[1]) > ADC_NC_DELTA) && !standalone_mode) {
173187
set_hw_diagnostic(DIAGNOSTICS_AUDIO_DAUGHTERBOARD, true);
174188
}
175189
CPRINTS("TP Ver %d, delta %d", device_id[0], high_adc[0] - low_adc[0]);
@@ -204,6 +218,6 @@ void set_bios_diagnostic(uint8_t code)
204218

205219
if (code == CODE_DDR_FAIL)
206220
set_hw_diagnostic(DIAGNOSTICS_NO_DDR, true);
207-
if (code == CODE_NO_EDP)
221+
if (code == CODE_NO_EDP && !standalone_mode)
208222
set_hw_diagnostic(DIAGNOSTICS_NO_EDP, true);
209223
}

board/hx20/diagnostics.h

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ enum diagnostics_device_idx {
4343
void set_hw_diagnostic(enum diagnostics_device_idx idx, bool error);
4444
void set_bios_diagnostic(uint8_t code);
4545

46+
void set_standalone_mode(int enable);
47+
int get_standalone_mode(void);
48+
4649
void reset_diagnostics(void);
4750

4851
void cancel_diagnostics(void);

board/hx20/flash_storage.c

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/* Copyright 2022 The Chromium OS Authors. All rights reserved.
2+
* Use of this source code is governed by a BSD-style license that can be
3+
* found in the LICENSE file.
4+
*/
5+
6+
#include "util.h"
7+
#include "hooks.h"
8+
9+
#include "board.h"
10+
#include "gpio.h"
11+
12+
#include "spi.h"
13+
#include "spi_chip.h"
14+
#include "spi_flash.h"
15+
16+
#include "flash_storage.h"
17+
18+
19+
20+
21+
22+
23+
#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
24+
#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
25+
26+
static struct ec_flash_flags_info current_flags;
27+
bool flash_storage_dirty;
28+
29+
bool check_flags_valid_header(void)
30+
{
31+
if (current_flags.magic != FLASH_FLAGS_MAGIC ||
32+
current_flags.length != (sizeof(current_flags) - 8) ||
33+
current_flags.version != FLASH_FLAGS_VERSION) {
34+
return false;
35+
} else {
36+
return true;
37+
}
38+
}
39+
40+
void flash_storage_load_defaults(void)
41+
{
42+
CPRINTS("Init flash storage to defaults");
43+
memset(&current_flags, 0x00, sizeof(current_flags));
44+
current_flags.magic = FLASH_FLAGS_MAGIC;
45+
current_flags.length = (sizeof(current_flags) - 8);
46+
current_flags.version = FLASH_FLAGS_VERSION;
47+
flash_storage_dirty = true;
48+
}
49+
50+
int flash_storage_initialize(void)
51+
{
52+
53+
int rv;
54+
55+
spi_mux_control(1);
56+
57+
rv = spi_flash_read((void *)&current_flags, SPI_FLAGS_REGION, sizeof(current_flags));
58+
if (rv != EC_SUCCESS)
59+
CPRINTS("Could not load flash storage");
60+
61+
spi_mux_control(0);
62+
63+
/*Check structure is valid*/
64+
if (check_flags_valid_header() == false) {
65+
CPRINTS("loading flash default flags");
66+
flash_storage_load_defaults();
67+
}
68+
69+
return rv;
70+
}
71+
72+
int flash_storage_update(enum ec_flash_flags_idx idx, uint8_t v)
73+
{
74+
if (idx >= FLASH_FLAGS_MAX)
75+
return EC_ERROR_PARAM1;
76+
77+
if (check_flags_valid_header() == false)
78+
flash_storage_initialize();
79+
80+
if (current_flags.flags[idx] != v) {
81+
current_flags.flags[idx] = v;
82+
flash_storage_dirty = true;
83+
}
84+
return EC_SUCCESS;
85+
}
86+
87+
int flash_storage_commit(void)
88+
{
89+
int rv = EC_SUCCESS;
90+
91+
if (check_flags_valid_header() == false)
92+
flash_storage_initialize();
93+
94+
if (flash_storage_dirty) {
95+
96+
spi_mux_control(1);
97+
98+
rv = spi_flash_erase(SPI_FLAGS_REGION, 0x1000);
99+
100+
if (rv != EC_SUCCESS) {
101+
CPRINTS("SPI fail to erase");
102+
goto fail;
103+
}
104+
105+
current_flags.update_number += 1;
106+
107+
rv = spi_flash_write(SPI_FLAGS_REGION,
108+
sizeof(current_flags),
109+
(void *)&current_flags);
110+
111+
if (rv != EC_SUCCESS) {
112+
CPRINTS("SPI fail to write");
113+
goto fail;
114+
}
115+
116+
CPRINTS("%s, update:%d", __func__, current_flags.update_number);
117+
118+
spi_mux_control(0);
119+
flash_storage_dirty = false;
120+
}
121+
122+
return rv;
123+
124+
fail:
125+
spi_mux_control(0);
126+
return rv;
127+
}
128+
129+
int flash_storage_get(enum ec_flash_flags_idx idx)
130+
{
131+
if (idx >= FLASH_FLAGS_MAX)
132+
return -1;
133+
134+
if (check_flags_valid_header() == false)
135+
flash_storage_initialize();
136+
137+
return current_flags.flags[idx];
138+
}
139+
140+
static int cmd_flash_flags(int argc, char **argv)
141+
{
142+
int data;
143+
int i, d;
144+
char *e;
145+
146+
147+
if (argc >= 3) {
148+
149+
i = strtoi(argv[2], &e, 0);
150+
151+
if (*e)
152+
return EC_ERROR_PARAM2;
153+
154+
if (!strcasecmp(argv[1], "read")) {
155+
data = flash_storage_get(i);
156+
CPRINTS("Flash data:%d", data);
157+
} else if (argc >= 4 && !strcasecmp(argv[1], "write")) {
158+
159+
d = strtoi(argv[3], &e, 0);
160+
if (*e)
161+
return EC_ERROR_PARAM3;
162+
flash_storage_update(i, d);
163+
flash_storage_commit();
164+
} else {
165+
return EC_ERROR_PARAM3;
166+
}
167+
return EC_SUCCESS;
168+
}
169+
170+
return EC_ERROR_PARAM2;
171+
}
172+
DECLARE_CONSOLE_COMMAND(flashflag, cmd_flash_flags,
173+
"[read/write] i [d]",
174+
"read or write bytes from flags structure");

0 commit comments

Comments
 (0)