Skip to content

Commit d92df0f

Browse files
committed
fwk: dogwood: Make 12V led follow the actual PSU state
12V led should turn on and off when we turn on and off the power supply. Right now it hasn't because the original code was a little too lenient and was checking downstream power supplies for its status (which is always powered due to the 5vsb suspend mechanism). Let's just make led follow ps_on and check in more places for this. BUG=Easier to debug https://app.clickup.com/t/86etqaz6v TEST=Get system to suspend, listen to clicks, led should also change state around that same time TEST=LED2 still follows ERS, turns on in S0, turns off in S5, blinks when there's errors TEST=No new 12V errors or diagnostics BRANCH=fwk-dogwood-27111
1 parent 7d85486 commit d92df0f

File tree

1 file changed

+50
-43
lines changed

1 file changed

+50
-43
lines changed

zephyr/program/framework/dogwood/src/power_sequence.c

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,52 @@ void system_hang_detect(void)
363363
}
364364
DECLARE_DEFERRED(system_hang_detect);
365365

366+
void power_led2_blinking(void);
367+
DECLARE_DEFERRED(power_led2_blinking);
368+
void power_led2_blinking(void)
369+
{
370+
static int tick;
371+
372+
/* blink LED2 with 2 Hz */
373+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_led2_drv), !!(tick++ % 2));
374+
hook_call_deferred(&power_led2_blinking_data, 500 * MSEC);
375+
}
376+
377+
static void power_check_12vb_apu(void)
378+
{
379+
int voltage = ina2xx_get_voltage(0); /* Unit: mV */
380+
bool psu_is_supposed_to_be_on =
381+
gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_ps_on));
382+
383+
/* LED should follow ps_on */
384+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_led2_drv),
385+
psu_is_supposed_to_be_on);
386+
/* Except when there's errors further on... */
387+
388+
/**
389+
* EC read the ina236 bus voltage register to monitor the
390+
* 12VB_APU is present or not to control the debug led2.
391+
*/
392+
if (voltage < 5000) {
393+
if (!psu_is_supposed_to_be_on) {
394+
/* Stop blinking the LED2 (G3) */
395+
hook_call_deferred(&power_led2_blinking_data, -1);
396+
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_led2_drv), 0);
397+
} else {
398+
/* Start blinking the LED2 (S0 but 12V is not detected) */
399+
power_led2_blinking();
400+
set_diagnostic(DIAGNOSTICS_12V_OK, 1);
401+
}
402+
}
403+
}
404+
405+
static void diagnostic_power_glitch_detect(void)
406+
{
407+
if ((hw_diagnostics & (1 << DIAGNOSTICS_PSU_POK)) == 0 &&
408+
power_has_signals(IN_VALW_PGOOD) == 0)
409+
set_diagnostic(DIAGNOSTICS_POWER_GLITCH, 1);
410+
}
411+
366412
void power_5vsb_enter(void)
367413
{
368414
CPRINTS("current was low (<%dmA) for a long time, switching to 5vsb",
@@ -389,6 +435,8 @@ void power_5vsb_enter(void)
389435
/* Set the upper current limit */
390436
power_monitor_set_alert_current(INA236_IDX_PSU_5V,
391437
INA236_MONITOR_5V_UPPER_CURRENT_MA);
438+
439+
power_check_12vb_apu();
392440
}
393441

394442
static void power_5vsb_enter_deferred(void)
@@ -424,50 +472,9 @@ bool power_5vsb_exit(void)
424472
power_monitor_set_alert_current(INA236_IDX_PSU_5V,
425473
INA236_MONITOR_5V_LOWER_CURRENT_MA);
426474

427-
return true;
428-
}
429-
430-
void power_led2_blinking(void);
431-
DECLARE_DEFERRED(power_led2_blinking);
432-
void power_led2_blinking(void)
433-
{
434-
static int tick;
475+
power_check_12vb_apu();
435476

436-
/* blink LED2 with 2 Hz */
437-
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_led2_drv), !!(tick++ % 2));
438-
hook_call_deferred(&power_led2_blinking_data, 500 * MSEC);
439-
}
440-
441-
static void power_check_12vb_apu(void)
442-
{
443-
int voltage = ina2xx_get_voltage(0); /* Unit: mV */
444-
bool psu_is_off = !gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_ps_on));
445-
446-
/**
447-
* EC read the ina236 bus voltage register to monitor the
448-
* 12VB_APU is present or not to control the debug led2.
449-
*/
450-
if (voltage < 5000) {
451-
452-
if (psu_is_off) {
453-
/* Strat blinking the LED2 (G3) */
454-
hook_call_deferred(&power_led2_blinking_data, -1);
455-
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_led2_drv), 0);
456-
} else {
457-
/* Strat blinking the LED2 (S0 but 12V is not detected) */
458-
power_led2_blinking();
459-
set_diagnostic(DIAGNOSTICS_12V_OK, 1);
460-
}
461-
} else
462-
/* Turn on the LED2 (S0 and 12V is detected) */
463-
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_led2_drv), 1);
464-
}
465-
466-
static void diagnostic_power_glitch_detect(void)
467-
{
468-
if ((hw_diagnostics & (1 << DIAGNOSTICS_PSU_POK)) == 0 &&
469-
power_has_signals(IN_VALW_PGOOD) == 0)
470-
set_diagnostic(DIAGNOSTICS_POWER_GLITCH, 1);
477+
return true;
471478
}
472479

473480
enum power_state power_handle_state(enum power_state state)

0 commit comments

Comments
 (0)