Skip to content

Commit

Permalink
common/power.c: use bitfields for PEP hook
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Kopeć <[email protected]>
  • Loading branch information
mkopec committed Nov 16, 2023
1 parent ebfc6b4 commit 3610fe1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
15 changes: 4 additions & 11 deletions src/board/system76/common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,9 @@ uint8_t acpi_read(uint8_t addr) {
break;
#endif // HAVE_LED_AIRPLANE_N

// S0ix hook
// Power engine plug-in hook for S0ix
case 0xE0:
data = pep_in_s0ix;
break;
case 0xE1:
data = pep_display_on;
data = pep_hook;
break;
}

Expand Down Expand Up @@ -175,13 +172,9 @@ void acpi_write(uint8_t addr, uint8_t data) {
gpio_set(&LED_AIRPLANE_N, !(bool)(data & BIT(6)));
break;
#endif
// S0ix hook
// Power engine plug-in hook for S0ix
case 0xE0:
pep_in_s0ix = !!data;
break;
// Display hook
case 0xE1:
pep_display_on = !!data;
pep_hook = data;
break;
}
}
5 changes: 3 additions & 2 deletions src/board/system76/common/include/board/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ extern enum PowerState power_state;
void update_power_state(void);

#if USE_S0IX
extern bool pep_in_s0ix;
extern bool pep_display_on;
#define PEP_S0IX_FLAG BIT(0)
#define PEP_DISPLAY_FLAG BIT(1)
extern uint8_t pep_hook;
#endif

void power_init(void);
Expand Down
7 changes: 3 additions & 4 deletions src/board/system76/common/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ extern uint8_t main_cycle;
enum PowerState power_state = POWER_STATE_OFF;

#if USE_S0IX
bool pep_in_s0ix = false;
bool pep_display_on = true;
uint8_t pep_hook = PEP_DISPLAY_FLAG;
#endif

enum PowerState calculate_power_state(void) {
Expand Down Expand Up @@ -639,7 +638,7 @@ void power_event(void) {
uint32_t time = time_get();
if (power_state == POWER_STATE_S0) {
#if USE_S0IX
if (pep_in_s0ix) {
if (pep_hook & PEP_S0IX_FLAG) {
// Modern suspend, flashing green light
if ((time - last_time) >= 1000) {
gpio_set(&LED_PWR, !gpio_get(&LED_PWR));
Expand All @@ -654,7 +653,7 @@ void power_event(void) {
gpio_set(&LED_PWR, true);
gpio_set(&LED_ACIN, false);

if (gpio_get(&LID_SW_N) && pep_display_on)
if (gpio_get(&LID_SW_N) && (pep_hook & PEP_DISPLAY_FLAG))
kbled_enable(true);
else
kbled_enable(false);
Expand Down

0 comments on commit 3610fe1

Please sign in to comment.