summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/link/board.c2
-rw-r--r--chip/lm4/power_button.c32
-rw-r--r--chip/lm4/pwm.c11
-rw-r--r--common/x86_power.c7
-rw-r--r--include/pwm.h17
5 files changed, 49 insertions, 20 deletions
diff --git a/board/link/board.c b/board/link/board.c
index 0b69b35d5f..2cb8fe41d0 100644
--- a/board/link/board.c
+++ b/board/link/board.c
@@ -33,7 +33,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"THERMAL_DATA_READYn", LM4_GPIO_B, (1<<4), 0, NULL},
{"AC_PRESENT", LM4_GPIO_H, (1<<3), 0, NULL},
{"PCH_BKLTEN", LM4_GPIO_J, (1<<3), GPIO_INT_BOTH,
- x86_power_interrupt},
+ power_button_interrupt},
{"PCH_SLP_An", LM4_GPIO_G, (1<<5), GPIO_INT_BOTH,
x86_power_interrupt},
{"PCH_SLP_ME_CSW_DEVn", LM4_GPIO_G, (1<<4), GPIO_INT_BOTH,
diff --git a/chip/lm4/power_button.c b/chip/lm4/power_button.c
index 00bf2b8487..d4752f8311 100644
--- a/chip/lm4/power_button.c
+++ b/chip/lm4/power_button.c
@@ -14,6 +14,7 @@
#include "lpc.h"
#include "lpc_commands.h"
#include "power_button.h"
+#include "pwm.h"
#include "system.h"
#include "task.h"
#include "timer.h"
@@ -67,7 +68,7 @@ static uint64_t tdebounce_lid;
static uint64_t tdebounce_pwr;
static uint8_t *memmap_switches;
-
+static int debounced_lid_open;
/* Update status of non-debounced switches */
static void update_other_switches(void)
@@ -110,6 +111,19 @@ static int get_power_button_pressed(void)
}
+static void update_backlight(void)
+{
+ /* Only enable the backlight if the lid is open */
+ if (gpio_get_level(GPIO_PCH_BKLTEN) && debounced_lid_open)
+ gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);
+ else
+ gpio_set_level(GPIO_ENABLE_BACKLIGHT, 0);
+
+ /* Same with keyboard backlight */
+ pwm_enable_keyboard_backlight(debounced_lid_open);
+}
+
+
/* Power button state machine. Passed current time from usec counter. */
static void state_machine(uint64_t tnow)
{
@@ -203,6 +217,7 @@ static void lid_switch_open(uint64_t tnow)
{
uart_printf("[%T PB lid open]\n");
+ debounced_lid_open = 1;
*memmap_switches |= EC_LPC_SWITCH_LID_OPEN;
lpc_set_host_events(EC_LPC_HOST_EVENT_MASK(
@@ -224,6 +239,7 @@ static void lid_switch_close(uint64_t tnow)
{
uart_printf("[%T PB lid close]\n");
+ debounced_lid_open = 0;
*memmap_switches &= ~EC_LPC_SWITCH_LID_OPEN;
lpc_set_host_events(EC_LPC_HOST_EVENT_MASK(
@@ -234,12 +250,12 @@ static void lid_switch_close(uint64_t tnow)
/* Handle debounced lid switch changing state */
static void lid_switch_changed(uint64_t tnow)
{
- int v = gpio_get_level(GPIO_LID_SWITCHn);
-
- if (v)
+ if (gpio_get_level(GPIO_LID_SWITCHn))
lid_switch_open(tnow);
else
lid_switch_close(tnow);
+
+ update_backlight();
}
@@ -253,6 +269,9 @@ void power_button_interrupt(enum gpio_signal signal)
case GPIO_POWER_BUTTONn:
tdebounce_pwr = get_time().val + PWRBTN_DEBOUNCE_US;
break;
+ case GPIO_PCH_BKLTEN:
+ update_backlight();
+ break;
default:
/* Non-debounced switches; we'll update their state
* automatically the next time through the task loop. */
@@ -273,9 +292,12 @@ int power_button_init(void)
/* Set up memory-mapped switch positions */
memmap_switches = lpc_get_memmap_range() + EC_LPC_MEMMAP_SWITCHES;
*memmap_switches = 0;
- if (gpio_get_level(GPIO_LID_SWITCHn) != 0)
+ if (gpio_get_level(GPIO_LID_SWITCHn) != 0) {
+ debounced_lid_open = 1;
*memmap_switches |= EC_LPC_SWITCH_LID_OPEN;
+ }
update_other_switches();
+ update_backlight();
if (system_get_reset_cause() == SYSTEM_RESET_RESET_PIN) {
/* Reset triggered by keyboard-controlled reset, so override
diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c
index 7fa935dbee..7fc95f0124 100644
--- a/chip/lm4/pwm.c
+++ b/chip/lm4/pwm.c
@@ -86,6 +86,17 @@ int pwm_set_fan_target_rpm(int rpm)
}
+int pwm_enable_keyboard_backlight(int enable)
+{
+ if (enable)
+ LM4_FAN_FANCTL |= (1 << FAN_CH_KBLIGHT);
+ else
+ LM4_FAN_FANCTL &= ~(1 << FAN_CH_KBLIGHT);
+
+ return EC_SUCCESS;
+}
+
+
int pwm_get_keyboard_backlight(void)
{
return ((LM4_FAN_FANCMD(FAN_CH_KBLIGHT) >> 16) * 100 +
diff --git a/common/x86_power.c b/common/x86_power.c
index a78d878b9e..f82b4ff0d3 100644
--- a/common/x86_power.c
+++ b/common/x86_power.c
@@ -66,7 +66,6 @@ static const char * const state_names[] = {
#define IN_PCH_SLP_SUSn_DEASSERTED 0x1000
#define IN_PCH_SLP_MEn_DEASSERTED 0x2000
#define IN_PCH_SUSWARNn_DEASSERTED 0x4000
-#define IN_PCH_BKLTEN_ASSERTED 0x8000
/* All always-on supplies */
#define IN_PGOOD_ALWAYS_ON (IN_PGOOD_5VALW)
/* All non-core power rails */
@@ -133,12 +132,6 @@ static void update_in_signals(void)
/* Copy SUSWARN# signal from PCH to SUSACK# */
gpio_set_level(GPIO_PCH_SUSACKn, v);
- v = gpio_get_level(GPIO_PCH_BKLTEN);
- if (v)
- inew |= IN_PCH_BKLTEN_ASSERTED;
- /* Copy backlight enable signal from PCH to BKLTEN */
- gpio_set_level(GPIO_ENABLE_BACKLIGHT, v);
-
in_signals = inew;
}
diff --git a/include/pwm.h b/include/pwm.h
index 022a21399b..26e5fa4686 100644
--- a/include/pwm.h
+++ b/include/pwm.h
@@ -10,29 +10,32 @@
#include "common.h"
-/* Initializes the module. */
+/* Initialize the module. */
int pwm_init(void);
-/* Enables/disables the fan. This should be called by whatever function
+/* Enable/disable the fan. This should be called by whatever function
* enables the power supply to the fan. */
int pwm_enable_fan(int enable);
-/* Gets the current fan RPM. */
+/* Get the current fan RPM. */
int pwm_get_fan_rpm(void);
/* Get the target fan RPM. */
int pwm_get_fan_target_rpm(void);
-/* Sets the target fan RPM. Pass -1 to set fan to maximum. */
+/* Set the target fan RPM. Pass -1 to set fan to maximum. */
int pwm_set_fan_target_rpm(int rpm);
-/* Gets the keyboard backlight percentage (0=off, 100=max). */
+/* Enable/disable the keyboard backlight. */
+int pwm_enable_keyboard_backlight(int enable);
+
+/* Get the keyboard backlight percentage (0=off, 100=max). */
int pwm_get_keyboard_backlight(void);
-/* Sets the keyboard backlight percentage (0=off, 100=max). */
+/* Set the keyboard backlight percentage (0=off, 100=max). */
int pwm_set_keyboard_backlight(int percent);
-/* Sets the power LED brightness to the specified percent (0=off, 100=max). */
+/* Set the power LED brightness to the specified percent (0=off, 100=max). */
int pwm_set_power_led(int percent);
#endif /* __CROS_EC_PWM_H */