Skip to content

Commit 3ffa896

Browse files
authored
Merge pull request #697 from FrameworkComputer/lotus.smart_access_graphic
Implement smart access graphic feature
2 parents a36844b + 9a77426 commit 3ffa896

File tree

3 files changed

+83
-22
lines changed

3 files changed

+83
-22
lines changed

zephyr/program/lotus/include/customized_shared_memory.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@
7070

7171
#define EC_CUSTOMIZED_MEMMAP_PD_VERSION 0x14C
7272

73+
#define EC_CUSTOMIZED_MEMMAP_GPU_CONTROL 0x150
74+
#define SET_APU_MUX BIT(0)
75+
#define SET_GPU_MUX BIT(1)
76+
#define GPU_MUX BIT(2) /* 0:APU; 1:GPU*/
77+
#define GPU_PRESENT BIT(3) /* 0:gpu no exist; 1:gpu exist*/
78+
#define ASSERTED_EDP_RESET BIT(4)
79+
#define DEASSERTED_EDP_RESET BIT(5)
80+
7381
#define EC_CUSTOMIZED_MEMMAP_DISPLAY_ON 0x153
7482

7583
#endif /* __BOARD_CUSTOMIZED_SHARED_MEMORY_H */

zephyr/program/lotus/include/lotus/gpu.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
#ifndef __BOARD_GPU_H__
77
#define __BOARD_GPU_H__
88

9-
10-
119
bool gpu_present(void);
1210

13-
void gpu_post_power_init(void);
14-
1511
void set_host_dp_ready(int ready);
1612

1713
#endif /* __BOARD_GPU_H__ */

zephyr/program/lotus/lotus/src/gpu.c

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88

99
#include "adc.h"
10+
#include "chipset.h"
11+
#include "customized_shared_memory.h"
1012
#include "gpio/gpio_int.h"
1113
#include "gpio.h"
1214
#include "gpu.h"
@@ -26,7 +28,6 @@ LOG_MODULE_REGISTER(gpu, LOG_LEVEL_INF);
2628
#define GPU_F75303_I2C_ADDR_FLAGS 0x4D
2729

2830
static int module_present;
29-
static int gpu_detected;
3031
bool gpu_present(void)
3132
{
3233
return module_present;
@@ -46,8 +47,15 @@ void check_gpu_module(void)
4647
{
4748
int gpu_id_0 = get_hardware_id(ADC_GPU_BOARD_ID_0);
4849
int gpu_id_1 = get_hardware_id(ADC_GPU_BOARD_ID_1);
50+
int switch_status = 0;
4951

50-
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_chassis_open));
52+
if (board_get_version() >= BOARD_VERSION_7) {
53+
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_beam_open));
54+
switch_status = gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_f_beam_open_l));
55+
} else {
56+
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_chassis_open));
57+
switch_status = gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_chassis_open_l));
58+
}
5159

5260
switch (VALID_BOARDID(gpu_id_1, gpu_id_0)) {
5361
case VALID_BOARDID(BOARD_VERSION_12, BOARD_VERSION_12):
@@ -67,17 +75,23 @@ void check_gpu_module(void)
6775
break;
6876
}
6977

78+
/* The chassis or f_beam is opened, turn off the power */
79+
if (!switch_status)
80+
module_present = 0;
81+
7082
if (module_present) {
7183
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_gpu_3v_5v_en), 1);
7284
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_gpu_vsys_vadp_en), 1);
7385
if (board_get_version() >= BOARD_VERSION_7)
7486
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_ssd_gpu_sel), 0);
87+
*host_get_memmap(EC_CUSTOMIZED_MEMMAP_GPU_CONTROL) |= GPU_PRESENT;
7588
} else {
7689
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_gpu_3v_5v_en), 0);
7790
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_edp_mux_pwm_sw), 0);
7891
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_gpu_vsys_vadp_en), 0);
7992
if (board_get_version() >= BOARD_VERSION_7)
8093
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_ssd_gpu_sel), 1);
94+
*host_get_memmap(EC_CUSTOMIZED_MEMMAP_GPU_CONTROL) &= GPU_PRESENT;
8195
}
8296
update_gpu_ac_power_state();
8397
}
@@ -127,26 +141,69 @@ void beam_open_interrupt(enum gpio_signal signal)
127141
}
128142
}
129143

130-
static void gpu_mux_configure(void)
144+
void gpu_smart_access_graphic(void);
145+
DECLARE_DEFERRED(gpu_smart_access_graphic);
146+
147+
void gpu_smart_access_graphic(void)
131148
{
132-
int rv = 1;
133-
int data;
149+
uint8_t gpu_status = *host_get_memmap(EC_CUSTOMIZED_MEMMAP_GPU_CONTROL);
150+
151+
/**
152+
* Host updated the shared memory to control the mux,
153+
* after switching the mux, clear the shared memory BIT(0) and BIT(1).
154+
*/
155+
if ((gpu_status & 0x03) == SET_GPU_MUX) {
156+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_edp_mux_pwm_sw), 1);
157+
gpu_status &= 0xFC;
158+
gpu_status |= GPU_MUX;
159+
}
134160

135-
if (module_present) {
136-
/* TODO Setup real gpu detection, for now just detect thermal sensor*/
137-
/* Disable gpu detection until mux is fixed */
138-
rv = i2c_read8(I2C_PORT_GPU0, 0x4d, 0x00, &data);
139-
if (rv == EC_SUCCESS && flash_storage_get(FLASH_FLAGS_ENABLE_GPU_MUX)) {
140-
LOG_INF("dGPU detected, enabling mux");
141-
gpu_detected = 1;
142-
143-
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_edp_mux_pwm_sw), 1);
144-
} else {
145-
LOG_INF("dGPU not enabling mux");
146-
}
161+
if ((gpu_status & 0x03) == SET_APU_MUX) {
162+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_edp_mux_pwm_sw), 0);
163+
gpu_status &= 0xFC;
164+
gpu_status &= ~GPU_MUX;
165+
}
166+
167+
/**
168+
* Host updated the shared memory to reset the edp,
169+
* after controlling the reset pin, clear the shared memory BIT(4) and BIT(5).
170+
*/
171+
if ((gpu_status & 0x30) == ASSERTED_EDP_RESET) {
172+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_ec_edp_reset), 0);
173+
gpu_status &= 0xCF;
174+
}
175+
176+
if ((gpu_status & 0x30) == DEASSERTED_EDP_RESET) {
177+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_ec_edp_reset), 1);
178+
gpu_status &= 0xCF;
147179
}
180+
181+
*host_get_memmap(EC_CUSTOMIZED_MEMMAP_GPU_CONTROL) = gpu_status;
182+
183+
/* Polling to check the shared memory of the GPU */
184+
if (chipset_in_state(CHIPSET_STATE_ON))
185+
hook_call_deferred(&gpu_smart_access_graphic_data, 10 * MSEC);
186+
}
187+
188+
189+
static void start_smart_access_graphic(void)
190+
{
191+
/* Check GPU is present then polling the namespace to do the smart access graphic */
192+
if (gpu_present())
193+
hook_call_deferred(&gpu_smart_access_graphic_data, 10 * MSEC);
194+
}
195+
DECLARE_HOOK(HOOK_CHIPSET_RESUME, start_smart_access_graphic, HOOK_PRIO_DEFAULT);
196+
197+
static void reset_mux_status(void)
198+
{
199+
uint8_t gpu_status = *host_get_memmap(EC_CUSTOMIZED_MEMMAP_GPU_CONTROL);
200+
201+
/* When the system shutdown, the gpu mux needs to switch to iGPU */
202+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_edp_mux_pwm_sw), 0);
203+
gpu_status &= 0xFC;
204+
gpu_status &= ~GPU_MUX;
148205
}
149-
DECLARE_HOOK(HOOK_CHIPSET_RESUME, gpu_mux_configure, HOOK_PRIO_DEFAULT);
206+
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, reset_mux_status, HOOK_PRIO_DEFAULT);
150207

151208
static void f75303_disable_alert_mask(void)
152209
{

0 commit comments

Comments
 (0)