system76/common/power: Fix spurious power button enable
This commit is contained in:
		
				
					committed by
					
						 Jeremy Soller
						Jeremy Soller
					
				
			
			
				
	
			
			
			
						parent
						
							c7827e4a7c
						
					
				
				
					commit
					99a0d6861f
				
			| @@ -362,6 +362,11 @@ void power_cpu_reset(void) { | |||||||
|     kbled_reset(); |     kbled_reset(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static bool power_button_disabled(void) { | ||||||
|  |     // Disable power button if lid is closed and AC is disconnected | ||||||
|  |     return !gpio_get(&LID_SW_N) && gpio_get(&ACIN_N); | ||||||
|  | } | ||||||
|  |  | ||||||
| void power_event(void) { | void power_event(void) { | ||||||
|     // Always switch to ds5 if EC is running |     // Always switch to ds5 if EC is running | ||||||
|     if (power_state == POWER_STATE_DEFAULT) { |     if (power_state == POWER_STATE_DEFAULT) { | ||||||
| @@ -411,17 +416,22 @@ void power_event(void) { | |||||||
|     // Read power switch state |     // Read power switch state | ||||||
|     static bool ps_last = true; |     static bool ps_last = true; | ||||||
|     bool ps_new = gpio_get(&PWR_SW_N); |     bool ps_new = gpio_get(&PWR_SW_N); | ||||||
|     // Disable power button if lid is closed and AC is disconnected |  | ||||||
|     if (!lid_state && ac_last) { |  | ||||||
|         ps_new = true; |  | ||||||
|     } |  | ||||||
|     if (!ps_new && ps_last) { |     if (!ps_new && ps_last) { | ||||||
|         // Ensure press is not spurious |         // Ensure press is not spurious | ||||||
|         delay_ms(10); |         for (int i = 0; i < 100; i++) { | ||||||
|  |             delay_ms(1); | ||||||
|             if (gpio_get(&PWR_SW_N) != ps_new) { |             if (gpio_get(&PWR_SW_N) != ps_new) { | ||||||
|                 DEBUG("%02X: Spurious press\n", main_cycle); |                 DEBUG("%02X: Spurious press\n", main_cycle); | ||||||
|                 ps_new = ps_last; |                 ps_new = ps_last; | ||||||
|         } else { |                 break; | ||||||
|  |             } else if (power_button_disabled()) { | ||||||
|  |                 // Ignore press when power button disabled | ||||||
|  |                 ps_new = ps_last; | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (ps_new != ps_last) { | ||||||
|             DEBUG("%02X: Power switch press\n", main_cycle); |             DEBUG("%02X: Power switch press\n", main_cycle); | ||||||
|  |  | ||||||
|             // Enable S5 power if necessary, before sending PWR_BTN |             // Enable S5 power if necessary, before sending PWR_BTN | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user