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
2830static int module_present ;
29- static int gpu_detected ;
3031bool 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
151208static void f75303_disable_alert_mask (void )
152209{
0 commit comments