Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wake from S3 using any key #27

Merged
merged 4 commits into from Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/board/system76/darp5/include/board/power.h
@@ -1,6 +1,17 @@
#ifndef _BOARD_POWER_H
#define _BOARD_POWER_H

enum PowerState {
POWER_STATE_DEFAULT,
POWER_STATE_DS5,
POWER_STATE_S5,
POWER_STATE_DS3,
POWER_STATE_S3,
POWER_STATE_S0,
};

extern enum PowerState power_state;

void power_event(void);

#endif // _BOARD_POWER_H
8 changes: 8 additions & 0 deletions src/board/system76/darp5/kbscan.c
Expand Up @@ -5,6 +5,7 @@
#include <board/kbscan.h>
#include <board/keymap.h>
#include <board/pmc.h>
#include <board/power.h>
#include <common/debug.h>

bool kbscan_enabled = false;
Expand All @@ -29,6 +30,13 @@ void kbscan_init(void) {
#define DEBOUNCE_DELAY 20

bool kbscan_press(uint16_t key, bool pressed, uint8_t * layer) {
if (pressed &&
(power_state == POWER_STATE_S3 || power_state == POWER_STATE_DS3)) {
gpio_set(&SWI_N, false);
delay_ticks(10); //TODO: find correct delay
gpio_set(&SWI_N, true);
}

switch (key & KT_MASK) {
case (KT_NORMAL):
if (kbscan_enabled) {
Expand Down
14 changes: 7 additions & 7 deletions src/board/system76/darp5/pmc.c
Expand Up @@ -63,7 +63,7 @@ void pmc_event(struct Pmc * pmc) {
if (sts & PMC_STS_IBF) {
uint8_t data = pmc_read(pmc);
if (sts & PMC_STS_CMD) {
DEBUG("pmc cmd: %02X\n", data);
TRACE("pmc cmd: %02X\n", data);

state = PMC_STATE_DEFAULT;
switch (data) {
Expand All @@ -78,22 +78,22 @@ void pmc_event(struct Pmc * pmc) {
pmc_sci_interrupt();
break;
case 0x82:
DEBUG(" burst enable\n");
TRACE(" burst enable\n");
// Set burst bit
pmc_set_status(pmc, sts | (1 << 4));
// Send acknowledgement byte
state = PMC_STATE_WRITE;
state_data = 0x90;
break;
case 0x83:
DEBUG(" burst disable\n");
TRACE(" burst disable\n");
// Clear burst bit
pmc_set_status(pmc, sts & ~(1 << 4));
// Send SCI for IBF=0
pmc_sci_interrupt();
break;
case 0x84:
DEBUG(" SCI queue\n");
TRACE(" SCI queue\n");
// Clear SCI pending bit
pmc_set_status(pmc, sts & ~(1 << 5));
// Send SCI queue
Expand All @@ -104,13 +104,13 @@ void pmc_event(struct Pmc * pmc) {
break;

case 0xEC:
DEBUG(" scratch rom\n");
TRACE(" scratch rom\n");
pmc_write(pmc, 0x76);
scratch_trampoline();
break;
}
} else {
DEBUG("pmc data: %02X\n", data);
TRACE("pmc data: %02X\n", data);

switch (state) {
case PMC_STATE_ACPI_READ:
Expand Down Expand Up @@ -141,7 +141,7 @@ void pmc_event(struct Pmc * pmc) {
if (!(sts & PMC_STS_OBF)) {
switch (state) {
case PMC_STATE_WRITE:
DEBUG("pmc write: %02X\n", state_data);
TRACE("pmc write: %02X\n", state_data);
state = PMC_STATE_DEFAULT;
pmc_write(pmc, state_data);
// Send SCI for OBF=1
Expand Down
31 changes: 14 additions & 17 deletions src/board/system76/darp5/power.c
Expand Up @@ -51,6 +51,8 @@ extern uint8_t main_cycle;
// RSMRST# de-assertion to SUSPWRDNACK valid
#define tPLT01 delay_ms(200)

enum PowerState power_state = POWER_STATE_DEFAULT;

// Enable deep sleep well power
void power_on_ds5() {
DEBUG("%02X: power_on_ds5\n", main_cycle);
Expand Down Expand Up @@ -80,6 +82,8 @@ void power_on_ds5() {
// tPCH04 is the ideal delay
tPCH04;
#endif // DEEP_SX

power_state = POWER_STATE_DS5;
}

// Enable S5 power
Expand Down Expand Up @@ -126,6 +130,8 @@ void power_on_s5() {
// Extra wait - TODO remove
delay_ms(200);
#endif // DEEP_SX

power_state = POWER_STATE_S5;
}

void power_off_s5() {
Expand Down Expand Up @@ -157,24 +163,14 @@ void power_off_s5() {
gpio_set(&PCH_DPWROK_EC, false);
tPCH14;
#endif // DEEP_SX
}

enum PowerState {
POWER_STATE_DEFAULT,
POWER_STATE_DS5,
POWER_STATE_S5,
POWER_STATE_DS3,
POWER_STATE_S3,
POWER_STATE_S0,
};
power_state = POWER_STATE_DS5;
}

void power_event(void) {
static enum PowerState state = POWER_STATE_DEFAULT;

// Always switch to ds5 if EC is running
if (state == POWER_STATE_DEFAULT) {
if (power_state == POWER_STATE_DEFAULT) {
power_on_ds5();
state = POWER_STATE_DS5;
}

// Check if the adapter line goes low
Expand Down Expand Up @@ -223,9 +219,8 @@ void power_event(void) {
DEBUG("%02X: Power switch press\n", main_cycle);

// Enable S5 power if necessary, before sending PWR_BTN
if (state == POWER_STATE_DS5) {
if (power_state == POWER_STATE_DS5) {
power_on_s5();
state = POWER_STATE_S5;
}
}
}
Expand Down Expand Up @@ -286,6 +281,8 @@ void power_event(void) {
//TODO: reset KBC and touchpad states

kbled_reset();

power_state = POWER_STATE_S0;
}
rst_last = rst_new;

Expand Down Expand Up @@ -331,9 +328,9 @@ void power_event(void) {

if (s4_new) {
DEBUG("%02X: entering S3 state\n", main_cycle);
} else if (state == POWER_STATE_S5) {
power_state = POWER_STATE_S3;
} else if (power_state == POWER_STATE_S5) {
power_off_s5();
state = POWER_STATE_DS5;
}
}
#if LEVEL >= LEVEL_DEBUG
Expand Down
11 changes: 11 additions & 0 deletions src/board/system76/galp3-c/include/board/power.h
@@ -1,6 +1,17 @@
#ifndef _BOARD_POWER_H
#define _BOARD_POWER_H

enum PowerState {
POWER_STATE_DEFAULT,
POWER_STATE_DS5,
POWER_STATE_S5,
POWER_STATE_DS3,
POWER_STATE_S3,
POWER_STATE_S0,
};

extern enum PowerState power_state;

void power_event(void);

#endif // _BOARD_POWER_H
8 changes: 8 additions & 0 deletions src/board/system76/galp3-c/kbscan.c
Expand Up @@ -6,6 +6,7 @@
#include <board/kbscan.h>
#include <board/keymap.h>
#include <board/pmc.h>
#include <board/power.h>
#include <common/debug.h>

bool kbscan_enabled = false;
Expand All @@ -30,6 +31,13 @@ void kbscan_init(void) {
#define DEBOUNCE_DELAY 20

bool kbscan_press(uint16_t key, bool pressed, uint8_t * layer) {
if (pressed &&
(power_state == POWER_STATE_S3 || power_state == POWER_STATE_DS3)) {
gpio_set(&SWI_N, false);
delay_ticks(10); //TODO: find correct delay
gpio_set(&SWI_N, true);
}

switch (key & KT_MASK) {
case (KT_NORMAL):
if (kbscan_enabled) {
Expand Down
14 changes: 7 additions & 7 deletions src/board/system76/galp3-c/pmc.c
Expand Up @@ -63,7 +63,7 @@ void pmc_event(struct Pmc * pmc) {
if (sts & PMC_STS_IBF) {
uint8_t data = pmc_read(pmc);
if (sts & PMC_STS_CMD) {
DEBUG("pmc cmd: %02X\n", data);
TRACE("pmc cmd: %02X\n", data);

state = PMC_STATE_DEFAULT;
switch (data) {
Expand All @@ -78,22 +78,22 @@ void pmc_event(struct Pmc * pmc) {
pmc_sci_interrupt();
break;
case 0x82:
DEBUG(" burst enable\n");
TRACE(" burst enable\n");
// Set burst bit
pmc_set_status(pmc, sts | (1 << 4));
// Send acknowledgement byte
state = PMC_STATE_WRITE;
state_data = 0x90;
break;
case 0x83:
DEBUG(" burst disable\n");
TRACE(" burst disable\n");
// Clear burst bit
pmc_set_status(pmc, sts & ~(1 << 4));
// Send SCI for IBF=0
pmc_sci_interrupt();
break;
case 0x84:
DEBUG(" SCI queue\n");
TRACE(" SCI queue\n");
// Clear SCI pending bit
pmc_set_status(pmc, sts & ~(1 << 5));
// Send SCI queue
Expand All @@ -104,13 +104,13 @@ void pmc_event(struct Pmc * pmc) {
break;

case 0xEC:
DEBUG(" scratch rom\n");
TRACE(" scratch rom\n");
pmc_write(pmc, 0x76);
scratch_trampoline();
break;
}
} else {
DEBUG("pmc data: %02X\n", data);
TRACE("pmc data: %02X\n", data);

switch (state) {
case PMC_STATE_ACPI_READ:
Expand Down Expand Up @@ -141,7 +141,7 @@ void pmc_event(struct Pmc * pmc) {
if (!(sts & PMC_STS_OBF)) {
switch (state) {
case PMC_STATE_WRITE:
DEBUG("pmc write: %02X\n", state_data);
TRACE("pmc write: %02X\n", state_data);
state = PMC_STATE_DEFAULT;
pmc_write(pmc, state_data);
// Send SCI for OBF=1
Expand Down
31 changes: 14 additions & 17 deletions src/board/system76/galp3-c/power.c
Expand Up @@ -50,6 +50,8 @@ extern uint8_t main_cycle;
// RSMRST# de-assertion to SUSPWRDNACK valid
#define tPLT01 delay_ms(200)

enum PowerState power_state = POWER_STATE_DEFAULT;

// Enable deep sleep well power
void power_on_ds5() {
DEBUG("%02X: power_on_ds5\n", main_cycle);
Expand Down Expand Up @@ -79,6 +81,8 @@ void power_on_ds5() {
// tPCH04 is the ideal delay
tPCH04;
#endif // DEEP_SX

power_state = POWER_STATE_DS5;
}

// Enable S5 power
Expand Down Expand Up @@ -125,6 +129,8 @@ void power_on_s5() {
// Extra wait - TODO remove
delay_ms(200);
#endif // DEEP_SX

power_state = POWER_STATE_S5;
}

void power_off_s5() {
Expand Down Expand Up @@ -156,24 +162,14 @@ void power_off_s5() {
gpio_set(&PCH_DPWROK_EC, false);
tPCH14;
#endif // DEEP_SX
}

enum PowerState {
POWER_STATE_DEFAULT,
POWER_STATE_DS5,
POWER_STATE_S5,
POWER_STATE_DS3,
POWER_STATE_S3,
POWER_STATE_S0,
};
power_state = POWER_STATE_DS5;
}

void power_event(void) {
static enum PowerState state = POWER_STATE_DEFAULT;

// Always switch to ds5 if EC is running
if (state == POWER_STATE_DEFAULT) {
if (power_state == POWER_STATE_DEFAULT) {
power_on_ds5();
state = POWER_STATE_DS5;
}

// Check if the adapter line goes low
Expand Down Expand Up @@ -222,9 +218,8 @@ void power_event(void) {
DEBUG("%02X: Power switch press\n", main_cycle);

// Enable S5 power if necessary, before sending PWR_BTN
if (state == POWER_STATE_DS5) {
if (power_state == POWER_STATE_DS5) {
power_on_s5();
state = POWER_STATE_S5;
}
}
}
Expand Down Expand Up @@ -283,6 +278,8 @@ void power_event(void) {
// LPC was just reset, enable PNP devices
pnp_enable();
//TODO: reset KBC and touchpad states

power_state = POWER_STATE_S0;
}
rst_last = rst_new;

Expand Down Expand Up @@ -328,9 +325,9 @@ void power_event(void) {

if (s4_new) {
DEBUG("%02X: entering S3 state\n", main_cycle);
} else if (state == POWER_STATE_S5) {
power_state = POWER_STATE_S3;
} else if (power_state == POWER_STATE_S5) {
power_off_s5();
state = POWER_STATE_DS5;
}
}
#if LEVEL >= LEVEL_DEBUG
Expand Down
11 changes: 11 additions & 0 deletions src/board/system76/lemp9/include/board/power.h
@@ -1,6 +1,17 @@
#ifndef _BOARD_POWER_H
#define _BOARD_POWER_H

enum PowerState {
POWER_STATE_DEFAULT,
POWER_STATE_DS5,
POWER_STATE_S5,
POWER_STATE_DS3,
POWER_STATE_S3,
POWER_STATE_S0,
};

extern enum PowerState power_state;

void power_event(void);

#endif // _BOARD_POWER_H